Category : C Source Code
Archive   : READFLOP.ZIP
Filename : READFLOP.C

 
Output of file : READFLOP.C contained in archive : READFLOP.ZIP

#include
#include /* MSC 5.0 include file with REGS definition */



/*
*
* Read sectors from a floppy disk and write them to a file.
*
* The list of sectors is read from a text file.
*
* Uses the BIOS interrupt 19 (0x13) to read the sectors
* one at a time.
*
* This code is placed in the public domain.
* Ken Brown
* 6/9/88
*
*/



char sector_buffer[512];

main(argc,argv)
int argc;
char *argv[];
{
int track_number,
sector_number,
side_number,
drive_number;

char line_buffer[256];
FILE *sector_file,
*output_file;

if(argc < 3) {
printf("syntax: readflop sector_list_file output_file\n");
exit(1);
}

if((sector_file = fopen(argv[1],"r")) == NULL) {
printf("can not read sector list file: %s\n",argv[1]);
exit(1);
}

if((output_file = fopen(argv[2],"wb")) == NULL) {
printf("can not open output file: %s\n",argv[2]);
exit(1);
}

while(fgets(line_buffer, 255, sector_file) != NULL) {

if(*line_buffer == '\n') {
continue;
}

sscanf(line_buffer,"%d %d %d %d",
&drive_number,
&track_number,
§or_number,
&side_number);

printf("Reading drive %d, track %d, sector %d, side %d\n",
drive_number,
track_number,
sector_number,
side_number);

read_sector(drive_number,track_number,sector_number,side_number);

fwrite(sector_buffer,sizeof(char),512,output_file);

}

fclose(output_file);
fclose(sector_file);

printf("Done\n\n");

exit(0);

}

read_sector(drive_number,track_number,sector_number,side_number)
int drive_number, track_number, sector_number, side_number;
{
union REGS inregs, outregs;
struct SREGS segregs;

inregs.h.ah = 2;
inregs.h.al = 1;
inregs.x.bx = sector_buffer;
inregs.h.ch = track_number;
inregs.h.cl = sector_number;
inregs.h.dh = side_number;
inregs.h.dl = drive_number;


/* Assumes that the program is compiled for the SMALL model */
segread(&segregs);
segregs.es = segregs.ds;

int86x(19, &inregs, &outregs, &segregs);

if(outregs.x.cflag) {
printf("a problem occured reading this sector\n");
}

return 0;
}