home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / FLOPPIES / FDFORM16.ZIP / READBOOT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-10-26  |  3.4 KB  |  128 lines

  1. {$A+,B-,D+,E-,F-,I-,L+,N-,O-,R-,S-,V-}
  2. {$M 4096,0,655360}
  3. PROGRAM READBOOT;
  4.  
  5.   {READBOOT - Get Boot Sector from file/Write File to Boot-Sector - Ver 1.10}
  6.   {Compiled with Turbo-Pascal Ver 5.5}
  7.   {Does not compile with earlier versions of Turbo-Pascal}
  8.  
  9. USES dos,diskio;
  10.  
  11. VAR para   : String[50];
  12.   fn       : String[50];
  13.   f        : FILE;
  14.   lw       : Byte;
  15.   ok       : Boolean;
  16.   written  : Word;
  17.   readdisk : Boolean;
  18.   FileBoot : ^bpbtyp;
  19.   ysec     : LongInt;
  20.  
  21.   PROCEDURE SyntaxError;
  22.   BEGIN
  23.     WriteLn('Syntax Error.');
  24.     WriteLn;
  25.     WriteLn('Syntax is:  READBOOT <drive>: <file>  (write Boot-Sector to file)');
  26.     WriteLn('            READBOOT <file> <drive>:  (read Boot-Sector from file)');
  27.     WriteLn;
  28.     WriteLn('Exapmles: READBOOT A: C:\DISKS\BOOT1.SYS');
  29.     WriteLn('          READBOOT C:\DISKS\BOOT1.SYS A:');
  30.     WriteLn;
  31.     Halt(1);
  32.   END;
  33.  
  34.   PROCEDURE BootError;
  35.   BEGIN
  36.     WriteLn('File ',fn,' is no Boot-Sector image.');
  37.     Close(f);
  38.     Halt(9);
  39.   END;
  40.  
  41.   PROCEDURE DosError;
  42.   BEGIN
  43.     WriteLn('This program requires DOS 3.20 or higher.');
  44.     Halt(10);
  45.   END;
  46.  
  47. BEGIN
  48.   WriteLn;
  49.   WriteLn('READBOOT-Read/Write Boot-Sector from/to File  V1.10');
  50.   WriteLn('Copyright (c) 1988 - 1989, Christoph H. Hochstätter');
  51.   WriteLn;
  52.   IF Swap(DosVersion)<$314 THEN DosError;
  53.   IF (Length(ParamStr(1))=2) AND (Length(ParamStr(2))=2) THEN SyntaxError;
  54.   IF Length(ParamStr(1))=2 THEN BEGIN
  55.     para:=ParamStr(1);
  56.     fn:=ParamStr(2);
  57.     readdisk:=True;
  58.   END ELSE IF Length(ParamStr(2))=2 THEN BEGIN
  59.     para:=ParamStr(2);
  60.     fn:=ParamStr(1);
  61.     readdisk:=False;
  62.   END ELSE
  63.     SyntaxError;
  64.   IF fn='' THEN SyntaxError;
  65.   FOR lw:=1 TO Length(fn) DO fn[lw]:=Upcase(fn[lw]);
  66.   IF para[2]<>':' THEN SyntaxError;
  67.   lw:=Ord(Upcase(para[1]))-$40;
  68.   BootSec.init(ok);
  69.   IF NOT(ok) THEN BEGIN
  70.     WriteLn('Not enough Memory.');
  71.     Halt(4);
  72.   END;
  73.   BootSec.Readx(lw);
  74.   IF BootSec.UnknownDrive THEN BEGIN
  75.     WriteLn('Drive does not exist.');
  76.     Halt(3);
  77.   END;
  78.   IF (BootSec.Status AND $9200) <> 0 THEN BEGIN
  79.     WriteLn('READBOOT does not work with a SUBST/ASSIGN/NETWORK Drive.');
  80.     Halt(2);
  81.   END;
  82.   WITH BootSec.bpb^ DO BEGIN
  83.     WriteLn('Information from the floppy:');
  84.     WriteLn('Sectors/Track: ',spt);
  85.     WriteLn('Sides        : ',hds);
  86.     WriteLn('Bytes total  : ',DiskSize(lw));
  87.     WriteLn('Bytes free   : ',DiskFree(lw));
  88.     WriteLn;
  89.     Assign(f,fn);
  90.     IF readdisk THEN
  91.       Rewrite(f,1)
  92.     ELSE
  93.       Reset(f,1);
  94.     IF IoResult<>0 THEN BEGIN
  95.       WriteLn('File ',fn,' cannot be openend.');
  96.       Close(f);
  97.       Halt(6);
  98.     END;
  99.     IF NOT(readdisk) THEN BEGIN
  100.       IF FileSize(f)<>512 THEN BootError;
  101.       GetMem(FileBoot,512);
  102.       BlockRead(f,FileBoot^,512,written);
  103.       IF (written<>512) OR
  104.       (FileBoot^.boot_code[511]<>$AA) OR
  105.       (FileBoot^.boot_code[510]<>$55) THEN BEGIN
  106.         BootError;
  107.       END;
  108.       WriteLn('Sector-Type  : ',FileBoot^.oem);
  109.       WriteLn;
  110.       Seek(f,0);
  111.     END;
  112.     IF readdisk THEN BEGIN
  113.       BlockWrite(f,BootSec.bpb^,512,written);
  114.       IF written<>512 THEN BEGIN
  115.         WriteLn('Disk full - File: ',fn);
  116.         Close(f);
  117.         Halt(19);
  118.       END;
  119.     END ELSE BEGIN
  120.       jmp:=FileBoot^.jmp;
  121.       boot_code:=FileBoot^.boot_code;
  122.       oem:=FileBoot^.oem;
  123.       BootSec.writex(lw);
  124.     END;
  125.     Close(f);
  126.   END;
  127. END.
  128.