home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / MISCTI10.ZIP / TI235.ASC < prev    next >
Encoding:
Text File  |  1988-04-18  |  7.2 KB  |  227 lines

  1. R 65
  2. PAGEFOOTING
  3. BEGIN PAGEHEADING
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11. PRODUCT : TURBO PASCAL@>( )NUMBER : 232
  12. VERSION : ALL
  13.      OS : PC-DOS
  14.    DATE : August 1, 1986@>( )PAGE : 1/6
  15. 
  16.   TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  17. END PAGEHEADING
  18.  
  19. 
  20.  
  21.  
  22. The  following example routines are public domain  programs  that have  been uploaded to our Forum on CompuServe.  As a courtesy to our  users  that  do not have  immediate  access  to  CompuServe, Technical Support distributes these routines free of charge.
  23.  
  24. However,  because these routines are public domain programs,  not developed by Borland International,  we are unable to provide any technical support or assistance using these routines. If you need assistance   using   these   routines,    or   are   experiencing difficulties,  we  recommend  that you log  onto  CompuServe  and request  assistance  from the Forum members that developed  these routines.
  25.  
  26. Turbo  Pascal's Intr procedure cannot call MS-DOS interrupts  25H and  26H  because they do not leave the CPU flags on  the  stack. This set of functions allows you to call those interrupts,  which are  Absolute  Disk Read and Absolute Disk Write,  by  using  the following functions ReadSectors and WriteSectors, respectively. 
  27.  
  28. Both functions are called with the same parameters:
  29.          Buffer:  a buffer large enough to hold NumberSectors 512                   byte sectors.
  30.           Drive: the drive number.  0 is A:, 1 is B:, and so on.
  31.   NumberSectors: the number of sectors to transfer.
  32.   LogicalSector: the first logical sector number to transfer.
  33.  
  34. Be  sure  that  the  Buffer is large enough  to  hold  512  times NumberSectors bytes of data.   Failure to do so will surely  lead to bugs that are difficult to solve.
  35.  
  36. The  integer  return value is the error code returned by  MS-DOS. "0" indicates a successful transfer, all other values are errors.  See a DOS Technical Reference Manual for translations.
  37.  
  38. A small sample program is provided.  It is a minimal disk editor 
  39. and is intended as an example only,  though it provides the basis for a complete disk editor/utility.  The example is commented out -- you must remove the line with the "(*" on it.
  40.  
  41. USE WITH CAUTION!
  42.  
  43. }
  44. @newpage
  45.  
  46. {$C-}
  47. {  Remove  the  leading  * for better keyboard  response  in  the    example program }
  48.  
  49. Function __ReadWriteSectors(Var Buffer;
  50.                Drive, NumberSectors, LogicalSector: Integer;
  51.                WriteFlag: Byte): Integer;
  52. Var Result: Integer;
  53. Begin
  54.   Result:=0;
  55.   Inline($8A/$86/ Drive /      { MOV  AL,[BP+Drive]            }
  56.     $8B/$8E/ NumberSectors /   { MOV  CX,[BP+NumberSectors]    }
  57.     $8B/$96/ LogicalSector /   { MOV  DX,[BP+LogicalSector]    }
  58.     $55/                       { PUSH BP                       }
  59.     $1E/                       { PUSH DS                       }
  60.     $C5/$9E/ Buffer /          { LDS  BX,[BP+Buffer]           }
  61.     $80/$BE/ WriteFlag /$01/   { CMP  BYTE PTR [BP+WriteFlag],1 }
  62.     $74/$04/                   { JE   Write                     }
  63.     $CD/$25/                   { INT  25H                       }
  64.     $EB/$02/                   { JMP  WrapUp                    }
  65.     $CD/$26/                   {Write: INT 26H                  }
  66.     $5B/                       
  67.                         {WrapUp:POP  BX ;Dispose of flags }
  68.     $1F/                       {       POP  DS                 }
  69.     $5D/                       {       POP  BP                 }
  70.     $73/$04/                   {       JNB  Ok                 }
  71.     $89/$86/ Result            {       MOV  [BP+Result],AX     }
  72.     );                         {Ok:                            }
  73.   __ReadWriteSectors:=Result;
  74. End;
  75.  
  76. Function ReadSectors(Var Buffer; Drive, NumberSectors, 
  77.                      LogicalSector: Integer): Integer;
  78.   Begin
  79.     ReadSectors:=
  80.    __ReadWriteSectors(Buffer,Drive,NumberSectors,
  81.                       LogicalSector,0);
  82.   End;
  83.  
  84. Function WriteSectors(Var Buffer; Drive, NumberSectors, 
  85.                       LogicalSector: Integer): Integer;
  86.   Begin
  87.     WriteSectors:=
  88.       __ReadWriteSectors(Buffer,Drive,NumberSectors,
  89.                          LogicalSector,1);
  90.   End;
  91.  
  92. { Example program.  Delete next line to enable it: }
  93. (*
  94.  
  95. {$R+}
  96.  
  97. Type
  98.   Str=String[4];
  99.  
  100. Function Int2Hex2(B: Byte): Str;
  101.   Const H: Array [0..15] Of Char='0123456789ABCDEF';
  102.   Begin
  103.     Int2Hex2:=H[B Shr 4]+H[B And 15];
  104.   End;
  105.  
  106. Function Int2Hex4(I: Integer): Str;
  107.   Const H: Array [0..15] Of Char='0123456789ABCDEF';
  108.   Begin
  109.     Int2Hex4:=H[I Shr 12]+H[(I Shr 8) And 15]+
  110.               H[(I Shr 4) And 15]+H[I And 15];
  111.   End;
  112.  
  113. Function Hex2Int1(C: Char): Byte;
  114.   Begin
  115.     Case Upcase(C) Of
  116.       '0'..'9': Hex2Int1:=Ord(C) And 15;
  117.       'A'..'F': Hex2Int1:=Ord(C) And 15+9;
  118.       Else Hex2Int1:=0;
  119.      End;
  120.   End;
  121.  
  122. Function Hex2Int4(S: Str; Default: Integer): Integer;
  123.   Var I: Integer;
  124.   Begin
  125.     If S='' Then Hex2Int4:=Default
  126.     Else
  127.      Begin
  128.       I:=0;
  129.       While S<>'' Do
  130.        Begin
  131.         I:=I Shl 4 + Hex2Int1(S[1]);
  132.         Delete(S,1,1);
  133.        End;
  134.       Hex2Int4:=I;
  135.      End;
  136.   End;
  137. @newpage
  138.  
  139. Procedure ShowSector(Var S);
  140.   Var Buffer: Array [0..31,0..15] Of Byte Absolute S;
  141.       I,J: Integer;
  142.       B: Byte;
  143.   Begin
  144.     For I:=0 To 31 Do
  145.      Begin
  146.       Write(Int2Hex4(I Shl 4),' |  ');
  147.       For J:=0 To 15 Do
  148.        Begin
  149.         Write(Int2Hex2(Buffer[I,J]),' ');
  150.         If J And 3=3 Then Write(' ');
  151.        End;
  152.       Write('| ');
  153.       For J:=0 To 15 Do
  154.        Begin
  155.         B:=Buffer[I,J];
  156.         If B<127 Then NormVideo
  157.         Else LowVideo;
  158.         B:=B And $7F;
  159.         If B<32 Then B:=Ord('.');
  160.         Write(Chr(B));
  161.        End;
  162.       NormVideo;
  163.       WriteLn;
  164.      End;
  165.   End;
  166.  
  167. @newpage
  168.  
  169. Var
  170.   Buffer: Array [0..511] Of Byte;
  171.   DR,LS,Result,C: Integer;
  172.   W: Char;
  173.   V: Str;
  174.   Changed: Boolean;
  175.  
  176. Begin
  177.   FillChar(Buffer,SizeOf(Buffer),'z');
  178.   Repeat
  179.     DR:=-1;
  180.     Write('Enter the drive # to read (CR to end): ');
  181.     ReadLn(DR);
  182.     If DR In [0..25] Then
  183.      Begin
  184.       Write('Enter the logical sector # to read: ');
  185.       ReadLn(LS);
  186.       Result:=ReadSectors(Buffer,DR,1,LS);
  187.       WriteLn('Result code = ',Result);
  188.       Changed:=False;
  189.       Repeat
  190.         ShowSector(Buffer);
  191.         Write('Enter the number of the byte to change ');
  192.         Write(' (0-1FF, CR to end): ');
  193.         ReadLn(V);
  194.         C:=Hex2Int4(V,-1);
  195.         If (C>0) And (C<512) Then
  196.          Begin
  197.           Write('Enter new value [',Int2Hex2(Buffer[C]),']: ');
  198.           ReadLn(V);
  199.           If Length(V)>1 Then
  200.             If V[1] In ['''','"'] Then Buffer[C]:=Ord(V[2])
  201.             Else Buffer[C]:=Hex2Int4(V,Buffer[C])
  202.           Else Buffer[C]:=Hex2Int4(V,Buffer[C]);
  203.           Changed:=True;
  204.          End
  205.         Else C:=-1;
  206.       Until C=-1;
  207. @newpage
  208.  
  209.       If Changed Then
  210.        Begin
  211.         Write('Write changes back to drive ',DR,',');
  212.         Write ('logical sector #',LS,' (Y/N)? ');
  213.         ReadLn(W);
  214.         If Upcase(W)='Y' Then
  215.          Begin
  216.           Result:=WriteSectors(Buffer,DR,1,LS);
  217.           WriteLn('Result code = ',Result);
  218.          End;
  219.        End;
  220.      End
  221.     Else DR:=-1;
  222.   Until DR=-1;
  223. End.
  224. (**)
  225.  
  226.  
  227.