program BootMkr; (***************************************************************** This program loads the specified binary file onto the boot sector of the diskette placed in drive 'A'. *****************************************************************) USES crt, dos; CONST DiskInt = $13; { Diskette Interrupt } DiskReset = 0; { Reset the Drive Subsystem } DiskStatus = 1; { Get Status of Previous Operation } DiskRead = 2; { Read the Sectors in Memory } DiskWrite = 3; { Write to the Disk Sector } VAR Regs : registers; ByteBuffer : array [0..511] of byte; { 512-byte Data Buffer } Curr_byte : byte; i,j : integer; handle : integer; { File Handling Variable } handle_size : longint; { File Handling Variable } SourceFile : file of byte; { File to Load into the Diskette } BEGIN writeln; writeln('BOOTMKR 1.0B, (c) Jens Laland 2001'); { Check Command Line Parameter } if ParamCount <> 1 then begin writeln; writeln(' USAGE: BOOTMKR filename.ext'); writeln; writeln(' This program loads the specified binary file'); writeln(' onto the boot sector of diskette in drive A.'); halt; end else begin Assign(SourceFile, ParamStr(1)); {$I-} Reset(SourceFile); {$I+} { If file does not exist, or file not found... } if IOresult <> 0 then begin writeln(ParamStr(1), ' not found...'); Halt; end; { Ensure that the file is within 512 bytes } if FileSize(SourceFile) > 512 then begin writeln('File too large to process [',FileSize(SourceFile),' bytes]'); writeln('File cannot be larger than one 512-byte sector...'); Halt; end else begin { Put the file on the Diskette } writeln('Processing ',ParamStr(1),' ',FileSize(SourceFile),' bytes...'); for i := 1 to FileSize(SourceFile) do begin seek(SourceFile,i - 1); read(SourceFile,Curr_byte); ByteBuffer[i - 1] := Curr_byte; end; { Fill rest of 512-byte sector with NOP } for i := FileSize(SourceFile) to 512 do ByteBuffer[i - 1] := $90; { Reset Disk Drive A } Regs.AH := DiskReset; Regs.DL := 0; intr(DiskInt,Regs); if NOT(Regs.AH = 0) then begin writeln('Error writing to Drive A...'); Halt; end else begin { Write File onto Boot Sector } Regs.AH := DiskWrite; { Write the First Sector } Regs.DL := 0; { of Disk A } Regs.DH := 0; { Head 0 } Regs.CH := 0; { Track 0 } Regs.CL := 1; { Sector 1 } Regs.AL := 1; { ONLY 1 Sector } Regs.BX := Ofs(ByteBuffer[0]); { Buffer Offset } Regs.ES := Seg(ByteBuffer[0]); { Buffer Segment } Intr(DiskInt,Regs); if NOT(Regs.AH = 0) then writeln('Error writing to Drive A...'); end; end; end; END.