home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / SECDUM.ZIP / SECDUMP.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1993-01-04  |  7.1 KB  |  197 lines

  1.                                                                         PROGRAM SECDUMP;
  2. (* Sector dump program by Bruce J. Savaglio (c) 1986 *)
  3. (* This program is given away freely -- enjoy
  4. This program will read the sectors on any disk -- even one that is unformatted.
  5. I use it to see if there is something on a disk the operating system
  6. won't read before I reformat it and lose it forever.
  7. It will read The sectors on a CP/M disk, on anything(haven't tried Commodore,
  8. but I think it will work). Don't forget, reading sectors doesn't mean you
  9. can read a file into your IBM compatible. But you can look at what is
  10. on the disk. The program uses Dos Interrupt 25h (read sector). Be careful if
  11. you decide to modify the program to change sectors and include your own INT 26h
  12. procedure. Modifying sectors indiscrimintately can cause errors from which even
  13. Peter Norton can't save you.
  14.  
  15. To use this program simply answer the responses. The sector bytes are given in
  16. decimal relative to 0 byte which is the first byte of 0 sector all the way to
  17. sector 711 the first byte of which is 364,032.  The actual byte values of
  18. the sectors (the DATA) is in hex. Fell Free to mess with this pro-
  19. gram. If you come up with something nifty let me know. *)
  20.  
  21. (* Turbo Pascal if you haven't guessed *)
  22.  
  23. uses crt,dos;
  24. {**** Ascii tables below contains position for the 127 characters. The table
  25.  is used to quickly translate a byte into a printable character. The first
  26.  32 numbers are the ASCII number for a period "." because the first 32 are
  27.  not printable (escape, null, LF, ect.). }
  28.  
  29. const ASCII : array[0..127] OF BYTE =
  30.                             (46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,
  31.                              46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,
  32.                              32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
  33.                              48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
  34.                              64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
  35.                              80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
  36.                              96,97,98,99,100,101,102,103,104,105,106,107,108,
  37.                              109,110,111,112,113,114,115,116,117,118,119,120,
  38.                              121,122,123,124,125,126,127);
  39.  
  40. CONST HEXCHR: ARRAY[0..15] OF CHAR = '0123456789ABCDEF';
  41.  
  42.    VAR
  43.      NUM_SECS  :INTEGER; {The number of sectors to look at (only 1)}
  44.      InSec_num : integer; {The sector input by the user also the starting sector}
  45.      SECTOR    : ARRAY[0..511] OF BYTE; {Buffer to hold sector}
  46.      ASCI_TAB  : ARRAY[0..15] OF CHAR; {Holds a line of ASCII bytes}
  47.   BPHOLD,SPHOLD: INTEGER; {Used to hold Stack and Base pointer for
  48.                           inline assembler code because Interrupt 25 doesn't
  49.                           clear the stack}
  50.      INDX      : INTEGER; {INDEX into hex table and contains a byte of
  51.                            data from sector}
  52.      Sec_loc   :real; {Sector offset printed on each line }
  53.      Inchar    : char;
  54.      drive     : byte; {must be global variable to work with inline code}
  55.      drive_char: char;
  56.      ATTR:BYTE;
  57. {$I BOXMAKER.PAS}
  58.  
  59. Procedure top_line;
  60.  
  61. BEGIN
  62. gotoxy(2,2);
  63. writeLN('   S E C D U M P (c) 1988  B.J. SAVAGLIO ')
  64. END;
  65.  
  66. PROCEDURE GET_SEC;
  67.  
  68.   BEGIN
  69.        top_line;
  70.      NUM_SECS := 1;
  71.      gotoxy(2,4);
  72.      WRITE('Enter sector number: ');
  73.      readLN(inSec_num);
  74.      write('Now enter drive letter (one character no ":" )');
  75.      READLN(drive_char);
  76.    end; {get_sec}
  77.  
  78.  Procedure read_sec;
  79.    begin
  80.      drive_char := upcase(drive_char);
  81.      drive := ord(drive_char);
  82.  
  83.      drive := drive - 65; {Ascii A starts at 65}
  84.      Sec_loc := inSec_num;
  85.      Sec_loc := 512 * Sec_loc;
  86.      {inSec_num := inSec_num * 512;}
  87.  
  88. (* THIS IS THE ASSEMBLER PROCEDURE THAT READS THE RAW SECTORS *)
  89. {Dos Interrupt 25h !!! NOT function 25h of interrupt 21h!!!!}
  90.            INLINE
  91.             ($89/$2E/BPHOLD/                {MOV BPHOLD,BP}
  92.              $89/$26/SPHOLD/                 {MOV SPHOLD,SP}
  93.             $A0/drive/                          {MOV AL,drive -- drive b: 00 is A,
  94.                                                          2 is c, etc.}
  95.              $8D/$1E/inSec_num/                {LEA BX,[inSec_num]}
  96.              $8B/$17/                       {MOV DX,[BX]}
  97.              $8D/$1E/NUM_SECS/              {LEA BX,[NUM_SECS]}
  98.              $8B/$0F/                       {MOV CX,[BX]}
  99.              $8D/$1E/SECTOR/               {LEA BX,SECTOR}                           {LEA BX,SECTOR}
  100.              $CD/$25/                      {INT 25}
  101.              $8B/$2E/BPHOLD/            {MOV BP,BPHOLD if you don't restore these}
  102.              $8B/$26/SPHOLD);           {MOV SP,SPHOLD two the stack grows un-}
  103.           END; {get_sec}                     {controllably }
  104.  
  105. PROCEDURE DISPLAY_SEC;
  106.  
  107.  VAR PASS_2,INDSEC_NUM,SEC_NUM,LIN_NUM: INTEGER;
  108.   second_half : integer; {to look at second 256 bytes}
  109.   INDXR : REAL;
  110.   INSTR :CHAR;
  111.  
  112.  BEGIN {******* Display_Sec starts here *****************}
  113.   PASS_2 := 0;
  114.   second_half := 0;
  115.   SEC_NUM := 0;
  116.   LIN_NUM := 0;
  117.   CLRSCR;
  118.  
  119.  
  120.  
  121.    While Pass_2  < 2 do
  122.   begin
  123.   gotoxy(2,3);
  124.  
  125.    writeln;
  126.    WRITELN(' Sector Number: ',inSec_num,'       Drive: ',drive_char,':');
  127.    writeln;
  128.    WRITELN('  BYTE: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15');
  129.    WRITELN;
  130.    WHILE LIN_NUM < 256 DO { do for entire screen}
  131.     BEGIN
  132.      WRITE(Sec_loc:06:0,': ');
  133.       WHILE SEC_NUM <> 16 DO {do for a single line}
  134.        BEGIN
  135.         INDSEC_NUM := SEC_NUM + LIN_NUM + second_half;
  136.         INDX := SECTOR[INDSEC_NUM];
  137.         IF INDX < 128 THEN
  138.          ASCI_TAB[SEC_NUM] := CHR(ASCII[INDX])
  139.         ELSE
  140.          ASCI_TAB[SEC_NUM] := '.';
  141.         INDX := INDX AND $F0;
  142.         INDXR := INDX / 16;
  143.         INDX := TRUNC(INDXR);
  144.         WRITE(HEXCHR[INDX]);
  145.         INDX := SECTOR[INDSEC_NUM];
  146.         INDX := INDX AND $0F;
  147.         WRITE(HEXCHR[INDX]);
  148.          WRITE(' ');
  149.         SEC_NUM := SEC_NUM + 1;
  150.        END; {While}
  151.       WRITE(ASCI_TAB);
  152.       WRITELN;
  153.       LIN_NUM := LIN_NUM + SEC_NUM;
  154.       Sec_loc := Sec_loc + 16;
  155.       SEC_NUM := 0;
  156.      END;{while}
  157.    IF PASS_2 = 0 THEN
  158.     BEGIN
  159.      WRITE('press any key to see second half of Sector ');
  160.      instr := readkey;
  161.      second_half := lin_num;
  162.     end
  163.    else
  164.     begin
  165.      write('Press "N" or "n" to see next sector or any key to continue');
  166.      instr := readkey;
  167.      if (instr = 'n') or (instr = 'N') then
  168.       begin
  169.        Pass_2 := -1;
  170.         InSec_num := InSec_num +1;
  171.         second_half := 0;
  172.          read_sec;
  173.        end;
  174.     end; {else}
  175.    CLRSCR;
  176.    PASS_2 := pass_2 +1;
  177.    LIN_NUM :=0;
  178.   END; {while}
  179.    END; {Display Sec}
  180.  
  181.  BEGIN  {************* Begin Program **************}
  182.   window(1,1,80,25);
  183.   BOXMAKER(1,1,79,23,blue);
  184.     WINDOW(2,3,76,23);
  185.  inchar := ' ';
  186.  while (inchar <> 'q') and (inchar <> 'Q') do
  187.  begin
  188.   inSec_num := inSec_num + 1;
  189.   GET_SEC;
  190.   read_sec;
  191.   DISPLAY_SEC;
  192.   Write('Enter "Q" or "q" to quit (any key to go again)');
  193.   inchar := readkey;
  194.   clrscr;
  195.  end;
  196. WINDOW(1,1,80,24);
  197. END. {Secdump}