/* fmthard - physically format the hard disk on drive 0 */

#include <cuser.inc>

#define DRIVE 0		/* hard disk drive 0 */
#define INTERLEAVE 4	/* Mindset interleave */

main()
{
struct regs disk_regs;
char sector_buf[16 * 512];
char input_string[80];
int status;

puts("Mindset Hard Disk Physical Format V1.00");
puts("\nThis program will perform a physical reformating");
printf("of the hard disk attached as drive %d,\n",(DRIVE));
printf("using an interleave factor of %d.\n", (INTERLEAVE) );
printf("ALL DATA ON HARD DISK DRIVE %d WILL BE DESTROYED!\n",(DRIVE));
puts("If you wish to proceed, type GO<cr>. Enter anything");
puts("else to abort this program. No other user input is required.");

input_string[0] = '\0';		/* init to null string */
gets(input_string);			/* get user input */

if( (strcmp(input_string,"GO") * strcmp(input_string,"go")) != 0 )
	{
	puts("\007Program Aborted - Format Not Performed.");
	return;
	}

/* Off we go */
puts("Formatting (takes a while)...");
/*
	AH	= function code (0x87 for format disk)
	AL	= interleave value for format
	DL	= drive number (must be 80h for drive 0)
		  < 80h = diskette, >= 80h = hard disk
	DH:CX = sector
		(assume dh = 0 - our drive is too small)
	ES:[BX]	= address of buffer for reads and writes

	interrupt 41h points to drive characteristics table
*/

disk_regs.ax = (256 * 0x87) + INTERLEAVE;
disk_regs.cx = 0;
disk_regs.dx = (DRIVE | 0x80);
disk_regs.bx = get_off(&sector_buf[0]);
disk_regs.es = get_seg(&sector_buf[0]);
callbios(0x13, &disk_regs);

if (status = (disk_regs.ax >> 8) & 0xff)
	{
	printf("\007Error During Format. Status = %-x\n", status);
	switch (status)
		{
		case 0xff:
			puts("(Sense operation failed.)");
			break;
		case 0xbb:
			puts("(Undefined error occurred.)");
			break;
		case 0x80:
			puts("(Attachment failed to respond--timeout.)");
			break;
		case 0x40:
			puts("(Seek operation failed.)");
			break;
		case 0x20:
			puts("(Controller has failed.)");
			break;
		case 0x11:
			puts("(ECC corrected data error.)");
			break;
		case 0x10:
			puts("(Bad ECC on disk read.)");
			break;
		case 0x0b:
			puts("(Bad track flag detected.)");
			break;
		case 0x09:
			puts("(Attempt to DMA across 64k boundary.)");
			break;
		case 0x07:
			puts("(Drive parameter activity failed.)");
			break;
		case 0x05:
			puts("(Reset failed.)");
			break;
		case 0x04:
			puts("(Requested sector not found.)");
			break;
		case 0x02:
			puts("(Address mark not found.)");
			break;
		case 0x01:
			puts("(Bad command passed to Disk I/O.)");
			puts("(Do you have a hard disk BIOS?)");
			break;
		default:
			puts("(Unknown error code)");
			break;
		}
	}
else
	puts("Format Completed Successfully.");

}/* end fmthard */
