...Hi All,
This is the ORIGINAL source code (in C) for the
1989 hard disk editor, capable of editing a
FAT32 hard disk under Windows 98:
================
5. Advice Needed
================
Could anyone be kind and please take a look at
the code - and tell me exactly what I should add
to it in order to make it perform its intended
purpose ?
Appreciate any help,
Thanks a lot,
Dan Richardson
==================================================
Following is the Hard Disk Sector Editor's
C source code:
==============
A. All original files appear here with their
filenames, which include:
- DISKEDIT.C
- DEFILES.C
- DEFILES.H
- DEVIDEO.C
- DEVIDEO.H
- DISKS.C
- DISKS.H
- KEYS.C
- KEYS.H
- VIDEO.C
- VIDEO.H
B. ...
...
...
==================================================
filename: DISKEDIT.C (an original file)
____________________
/* diskedit.c - low level disk sector viewer/editor */
/* lrs - 2/13/89 */
#include <stdio.h>
#include <bios.h>
#include <dos.h>
#include "disks.h"
#include "video.h"
#include "keys.h"
#include "devideo.h"
#include "defiles.h"
#define FALSE 0
#define TRUE ~FALSE
char WriteAllowed = FALSE;
int Drive = 0x80;
int HalfDisp = TRUE; int DispOffs = 0;
int Cyl = 0; int Head = 0; int Sec = 1;
int MaxCyl, MaxHead, MaxSec;
int scrrows;
char Done;
unsigned char SecBuf[BYTESPERSECTOR];
==================================================
filename: DEFILES.C (an original file)
____________________
/* defiles.c - disk file read/write for diskedit.c */
/* lrs - 2/13/89 */
#include <stdio.h>
#include "disks.h" /* for BYTESPERSECTOR */
#include "devideo.h" /* for error messages */
#include "defiles.h"
/*-----------------------------------------------------------------------*/
void ReadFile (char filename[], void* buf)
{ /* Read a binary data file into the sector buffer */
FILE* fin;
if ((fin = fopen(filename,"rb")) == NULL)
ErrorMessage("File Not Found");
if (fread(buf, BYTESPERSECTOR, 1, fin) != 1)
ErrorMessage("Error Reading File");
if (fclose(fin))
ErrorMessage("Error Closing File");
} /* GetFile */
/*-----------------------------------------------------------------------*/
void WriteFile (char filename[], void* buf)
{ /* Save the sector buffer as a binary file */
FILE* fout;
if ((fout = fopen(filename,"wb")) == NULL)
ErrorMessage("File Creation Error");
else if (fwrite(buf, BYTESPERSECTOR, 1, fout) != 1)
ErrorMessage("Error Writing File");
else if (fclose(fout))
ErrorMessage("Error Closing File");
} /* GetFile */
==================================================
filename: DEFILES.H (an original file)
____________________
/* defiles.h - lrs - 2/13/89 */
void ReadFile (char filename[], void* buf);
void WriteFile (char filename[], void* buf);
/*---- end of defiles.h ----*/
==================================================
filename: DEVIDEO.C (an original file)
____________________
/* devideo.c - special video routines for diskedit.c */
/* lrs - 2/13/89 */
#include "video.h"
void ErrorMessage(char mess[])
{
at(screenrows()-1,0);
cprintf(mess);
cleareol();
} /* ErrorMessage */
void ClearErrorMessage()
{
at(screenrows()-1,0);
cleareol();
} /* ClearErrorMessage */
void ShowWriteAllowed(int writeallowed)
{
at(14,0);
if (writeallowed)
cprintf("Write Ok ");
else
cprintf("Write Prot");
}
void DisplayFrame()
{
int ct, linect;
in(REVERSE); at(0,79-42);
cprintf(" Laine's Mighty Disk Editor v0.0 02/13/89 ");
in(DIM);
at(2,0); cprintf(" CURRENT");
at(3,0); cprintf("Drive:");
at(4,0); cprintf(" Cyl:");
at(5,0); cprintf(" Head:");
at(6,0); cprintf(" Sec:");
at(8,0); cprintf(" MAXIMUM");
at(9,0); cprintf(" Cyl:");
at(10,0); cprintf(" Head:");
at(11,0); cprintf(" Sec:");
ShowWriteAllowed(0);
at(1,11);
cprintf("?????");
at(2,11);
cprintf("??1 0 1 2 3 4 5 6 7 8 9 A B C D E
Fo0123456789ABCDEFo");
at(3,11);
cprintf("??1");
linect = (screenrows() >= 43) ? 32 : 16;
for (ct = 0; ct < linect; ct++)
{
at(ct+4,11);
cprintf("o o - o
o");
}
at(ct+4,11);
cprintf("?");
at(ct+5,4); in(NORMAL);
cprintf("PgUp/PgDn - Prev/Next Sector, F10 Updates Sector (alt+F10
enables update)");
at(ct+6,2);
cprintf("G - Goto Sec, M - Modify byte, R/W - Read/Write Sec to/from
File, ESC to quit");
} /* DisplayFrame */
/*-----------------------------------------------------------------------*/
void ShowMaxes(int maxcyl, int maxhead, int maxsec)
{
in(DIM);
at(9,7); cprintf("%3d",maxcyl);
at(10,7); cprintf("%3d",maxhead);
at(11,7); cprintf("%3d",maxsec);
}
/*-----------------------------------------------------------------------*/
void DisplaySector (int drive, int cyl, int head, int sec,
void* buf, int offs)
{
int ct, linect;
at(3,8); cprintf("%02x",drive);
at(4,7); cprintf("%3d",cyl);
at(5,7); cprintf("%3d",head);
at(6,7); cprintf("%3d",sec);
linect = (screenrows() >= 43) ? 32 : 16;
buf += offs*16;
for(ct = 0; ct < linect; ct++)
{
at(ct+4,12); in(DIM); cprintf("%02X",ct+offs);
at(ct+4,15); in(NORMAL);
Write16Bytes(buf);
buf+=16;
} /* for(ct = 0 to linect */
at(screenrows()-2,0);
} /* DisplaySector */
/*---- end of devideo.c ----*/
==================================================
filename: DEVIDEO.H (an original file)
____________________
/* devideo.h - lrs - 2/13/89 */
void ErrorMessage(char mess[]);
void ClearErrorMessage();
void ShowWriteAllowed(int writeallowed);
void DisplayFrame();
void ShowMaxes(int maxcyl, int maxhead, int maxsec);
void DisplaySector (int drive, int cyl, int head, int sec,
void* buf, int offs);
/*---- end of devideo.h ----*/
==================================================
filename: DISKS.C (an original file)
____________________
/* disks.c - interface to IBM ROM BIOS disk routines */
/* lrs 2/13/89 */
#include <bios.h>
#include <dos.h>
#include "disks.h"
void InitDisks()
{ /* ROM BIOS "Reset Disks" command */
union REGS reg;
reg.x.ax = 0;
int86(0x13,?,?);
} /* InitDisks */
/*-----------------------------------------------------------------------*/
void GetDiskParams(int drive, int* maxcyl, int* maxhead, int* maxsec)
{ /* get size of disk */
/* (note: this (and the rest) assumes 512 byte sectors */
union REGS reg;
reg.h.ah = 8;
reg.h.dl = drive;
int86(0x13,?,?);
*maxcyl = reg.h.ch + ((reg.h.cl & 0xC0) << 2);
*maxhead = reg.h.dh;
*maxsec = reg.h.cl & 0x3F;
} /* GetDiskParameters */
/*-----------------------------------------------------------------------*/
int ReadSector (int drive, int cyl, int head, int sec, void far* buf)
{ /* read a 512 byte sector from phys location on disk */
/* return TRUE if success */
union REGS reg;
struct SREGS sreg;
int retry = 3;;
do {
reg.x.ax = 0x0201;
reg.x.bx = FP_OFF(buf);
sreg.es = FP_SEG(buf);
reg.h.ch = cyl & 0xFF;
/* top two bits (8 & 9) of cyl # hidden in bits 6 & 7 of sector */
reg.h.cl = sec | ((cyl >> 2) & 0xC0);
reg.h.dh = head;
reg.h.dl = drive;
int86x(0x13,?,?,&sreg);
} while ((reg.x.cflag) && (retry-- > 0));
return(reg.x.cflag == 0);
} /* ReadSector */
/*-----------------------------------------------------------------------*/
int WriteSector (int drive, int cyl, int head, int sec, void far* buf)
{ /* write memory block to specified physical sector on disk */
/* return TRUE if success */
union REGS reg;
struct SREGS sreg;
int retry = 3;
do {
reg.x.ax = 0x0301;
reg.x.bx = FP_OFF(buf); /* THIS MUST BE FIXED !!!! */
sreg.es = FP_SEG(buf);
reg.h.ch = cyl & 0xFF;
/* top two bits (8 & 9) of cyl # hidden in bits 6 & 7 of sector
*/
reg.h.cl = sec | ((cyl >> 2) & 0xC0);
reg.h.dh = head;
reg.h.dl = drive;
int86x(0x13,?,?,&sreg);
} while ((reg.x.cflag) && (retry-- > 0));
return(reg.x.cflag == 0);
} /* WriteSector */
/*---- end of disks.c ----*/
==================================================
filename: DISKS.H (an original file)
____________________
/* disks.h - lrs 2/13/89 */
#define BYTESPERSECTOR 512
void InitDisks(void);
void GetDiskParams(int drive, int* maxcyl, int* maxhead, int* maxsec);
int ReadSector (int drive, int cyl, int head, int sec, void far* buf);
int WriteSector (int drive, int cyl, int head, int sec, void far*
buf);
/*---- end of disks.h ----*/
==================================================
filename: KEYS.C (an original file)
____________________
/* keys.c - keyboard input and function key translation */
/* lrs - 2/13/89 */
#include <stdio.h>
#include <bios.h>
#include <ctype.h>
#include "keys.h"
#include "video.h"
/*-----------------------------------------------------------------------*/
int getcmd(void)
{
int ch;
ch = bioskey(0);
if ((ch & 0xFF) !=0) /* not a function key */
{
ch &= 0xFF;
return (toupper(ch));
}
else
return(ch);
} /* getcmd */
/*-----------------------------------------------------------------------*/
unsigned char getkey(char prompt[])
{
unsigned char ch;
at(screenrows()-2,0); in(REVERSE);
cprintf(prompt);
in(NORMAL); cleareol();
ch = getcmd();
at(screenrows()-2,0); cleareol();
return(ch);
} /* getkey */
/*-----------------------------------------------------------------------*/
void getline(char prompt[], char line[])
{
...