#include "main.h" void main(int argc, void ** argv){ struct stat CHSfileStats; unsigned int status = 0x0000; unsigned int count = 0x0000; unsigned int localCount = 0x0000; /* lets get the statistics of the CHS file like size etc */ if( stat(argv[0x01], &CHSfileStats) != 0x0000 ){ printf("Unable to stat %s.\n",argv[0x01]); return; } /* open the CHS file */ if((CHSfileHandle = open(argv[0x01], O_RDONLY | O_BINARY)) < 0x0000){ printf("Unable to open file, %s.", argv[0x01]); return; } /* allocating memory for the CHS file */ if( (CHSbuffer = malloc(CHSfileStats.st_size)) == NULL){ printf("Memory allocation error for the CHS file.\n"); close(CHSfileHandle); return; } /* read the file which has the CHS data */ if( read(CHSfileHandle, CHSbuffer, CHSfileStats.st_size) < 0x0000){ printf("Unable to read %s.", argv[0x01]); close(CHSfileHandle); return; } /* close the file which has the CHS data */ close(CHSfileHandle); /* allocating memory for the data read from the sectors */ if( (buffer = malloc((CHSfileStats.st_size/0x03)*0x0200)) == NULL){ printf("Memory allocation error for the CHS data.\n"); return; } for(count = 0x0000; count < (CHSfileStats.st_size/0x03);){ /* far *, DRIVE+HEAD , CYLINDER+STARTING-SECTOR, SECTOR-COUNT, (void near *)&staus */ readSectors(((void far *)((unsigned char *)buffer + (count * 0x0200))), DRIVE_A | *((unsigned char *)CHSbuffer + (count * 0x03) + 2), *((unsigned int *)((unsigned char *)CHSbuffer + (count * 0x03)) ), 0x0001, (void near *)&status); if((status & 0xff00) > 0x0000){ printf("\n"); printf("Error %.2x",((status & 0xff00) >> 0x08)); parseError(((status & 0xff00) >> 0x08), *((unsigned int *)((unsigned char *)CHSbuffer + (count * 0x03)) )); return; } for(localCount = 0x0000; localCount<0x0200; localCount++) printf("%c",((unsigned char *)buffer + (count * 0x0200))[localCount]); /*printf("%s\n", buffer);*/ count++; } } void parseError(unsigned char statusCode, unsigned int cyl){ switch(statusCode){ case 0x01: printf(", bad command.\n"); printf("Invalid service number for the respective requested interrupt.\n"); break; case 0x02: printf(", address mark not found.\n"); break; case 0x03: printf(", write attempted on write protected disk.\n"); break; case 0x04: printf(", sector not found.\n"); printf("Cyl + Sector = %.4x\n", cyl); printf("Sectors should be in the range of 1 to max sectors/track\n"); break; case 0x06: printf(", diskette removed.\n"); printf("Please re-run this programm.\n"); break; case 0x08: printf(", DMA overrun.\n"); break; case 0x80: printf(", time out or drive not ready.\n"); printf("Either disk is out of the drive so put it back in.\n"); printf("Or the disk drive was not ready so re-run this programm.\n"); break; } return; }