home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / turbopas / dskrd_wr.pas < prev    next >
Pascal/Delphi Source File  |  1994-03-05  |  4KB  |  97 lines

  1. Date:  Mon, 16 Nov 87 09:39:01 EST
  2. From: nelson @ clutx.clarkson.edu
  3. Subject:  Absolute disk read/write from Turbo Pascal v6.68
  4.  
  5. Yes, you CAN use INT 13 to read/write disks instead of INT 25 and INT 26.
  6. Unfortunately, if you do, then your program will not work with installed
  7. device drivers, like a ramdisk.  I found this out the hard way when the
  8. disk recovery program that I wrote couldn't recover my ramdisk.  Ouch!
  9.  
  10. { module rwsector.inc -- module to read and write absolute sectors }
  11. { Copyright 1986, Russell Nelson.  Freely copyable for all uses so long
  12.   as this copyright message and following authorship notice are retained.
  13.  
  14. Author:
  15.  
  16.   Russell Nelson
  17.   11 Grant St.
  18.   Potsdam, N.Y. 13676
  19.   GEnie:    BH01                    Compu$erve: 70441,205
  20.   BITNET:   NELSON@CLUTX            Internet: nelson@clutx.clarkson.edu
  21.  
  22. Usage:
  23.  
  24.   If, for any reason, you want to read/write an absolute sector, this code
  25.   will do it for you.  Note that the count must be a variable, not an
  26.   expression.  The count is set to the number of sectors not read/written.
  27.  
  28. Exports:
  29. function read_sector(unit, sectno : integer; var count : integer; var buffer)
  30.   : integer;
  31. function write_sector(unit, sectno : integer; var count : integer; var buffer)
  32.   : integer;
  33.  
  34. Example:
  35.  
  36. var
  37.   sector : array[0..511];
  38.   error : integer;
  39.   count : integer;
  40. begin
  41.   count := 1;
  42.   error := read_sector(0, 0, count, sector);
  43.   end.
  44.  
  45. }
  46.  
  47. { return -1 if no errors, or error number if error. }
  48. function read_sector(unit, sectno : integer; var count : integer; var buffer)
  49.   : integer;
  50. begin
  51.   inline(
  52.     $1E/                      {         push  ds                  }
  53.     $C5/ $5E/ $04/            {         lds   bx,dword ptr 4[bp]  }
  54.     $8B/ $56/ $0C/            {         mov   dx,12[bp]           }
  55.     $8B/ $46/ $0E/            {         mov   ax,14[bp]           }
  56.     $C4/ $7E/ $08/            {         les   di,8[bp]            }
  57.     $26/ $8B/ $0D/            {         mov   cx,es:[di]          }
  58.     $55/                      {         push  bp                  }
  59.     $CD/ $25/                 {         int   25h                 }
  60.     $5D/                      {         pop   bp                  }
  61.     $5D/                      {         pop   bp                  }
  62.     $72/ $02/                 {         jc    rsect_1             }
  63.     $B0/ $FF/                 {         mov   al,-1               }
  64.     $98/                      {rsect_1: cbw                       }
  65.     $89/ $46/ $10/            {         mov   16[bp],ax           }
  66.     $C4/ $7E/ $08/            {         les   di,8[bp]            }
  67.     $26/ $89/ $0D/            {         mov   es:[di],cx          }
  68.     $1F                       {         pop   ds                  }
  69.     );
  70.   end;
  71.  
  72.  
  73. { return -1 if no errors, or error number if error. }
  74. function write_sector(unit, sectno : integer; var count : integer; var buffer)
  75.   : integer;
  76. begin
  77.   inline(
  78.     $1E/                      {         push  ds                  }
  79.     $C5/ $5E/ $04/            {         lds   bx,dword ptr 4[bp]  }
  80.     $8B/ $56/ $0C/            {         mov   dx,12[bp]           }
  81.     $8B/ $46/ $0E/            {         mov   ax,14[bp]           }
  82.     $C4/ $7E/ $08/            {         les   di,8[bp]            }
  83.     $26/ $8B/ $0D/            {         mov   cx,es:[di]          }
  84.     $55/                      {         push  bp                  }
  85.     $CD/ $26/                 {         int   26h                 }
  86.     $5D/                      {         pop   bp                  }
  87.     $5D/                      {         pop   bp                  }
  88.     $72/ $02/                 {         jc    wsect_1             }
  89.     $B0/ $FF/                 {         mov   al,-1               }
  90.     $98/                      {wsect_1: cbw                       }
  91.     $89/ $46/ $10/            {         mov   16[bp],ax           }
  92.     $C4/ $7E/ $08/            {         les   di,8[bp]            }
  93.     $26/ $89/ $0D/            {         mov   es:[di],cx          }
  94.     $1F                       {         pop   ds                  }
  95.     );
  96.   end;
  97.