home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / probe12.lbr / PROBE2.PZS / PROBE2.PAS
Encoding:
Pascal/Delphi Source File  |  1993-10-25  |  9.6 KB  |  348 lines

  1.  
  2. { Include file PROBE2.PAS          (c) Copyright September 1985 by Rick Ryall }
  3.  
  4. PROCEDURE DisplaySector( Track, Sector: integer );
  5. begin
  6.   gotoXY(1,5);
  7.   BlockNumber:= Block( Track, Sector );
  8.   write( CursorOff,'Track: ', Track,'   Logical Sector: ' );
  9.   write( Sector, '   Logical Block: ' );
  10.   if BlockNumber >= 0 then
  11.   begin
  12.     write( BlockNumber,'   [', hex( hi( BlockNumber )));
  13.     write( hex( lo( BlockNumber )),' hex]' );
  14.   end else write( 'not defined.' );
  15.   writeln( LineErase );
  16.   writeln;
  17.   for Row:= 0 to 7 do
  18.   begin
  19.     for i:= 0 to 15 do
  20.     begin
  21.       write( Hex( Sectr.Buffer[i+Row shl 4] ), Space );
  22.       if i mod 8 = 7 then write( Space );
  23.     end;
  24.     for i:= 0 to 15 do write( ASCII( Sectr.Buffer[i+Row shl 4] ));
  25.     writeln;
  26.   end;
  27.   writeln( CursorOn );
  28.   if BlockNumber >= 0 then
  29.   begin
  30.     write('Logical block ', BlockNumber,' is ' );
  31.     if Allocated( BlockNumber ) then write('reserved.') else write('free.    ');
  32.   end;
  33.   ClrEol;
  34.   if ReadError then Accent('    (READ ERROR: data displayed is invalid.)' );
  35. end;  { DisplaySector }
  36.  
  37. PROCEDURE ComputeSector( var Track, Sector: integer; Direction: boolean );
  38. begin
  39.   with DPB^ do
  40.   begin
  41.     if MoveBySectors then
  42.     begin
  43.       if Direction = Forwards then Sector:= succ( Sector )
  44.         else Sector:= pred( Sector );
  45.     end else  { move by blocks }
  46.     begin
  47.       if Direction = Forwards then BlockNumber:= succ( BlockNumber )
  48.         else BlockNumber:= pred( BlockNumber );
  49.       if BlockNumber < 0 then BlockNumber:= MaxBlock
  50.         else if BlockNumber > MaxBlock then BlockNumber:= 0;
  51.       BlockToSector( BlockNumber, Track, Sector );
  52.     end;
  53.     if  ( Sector >= SectorsPerTrack ) or ( Block( Track, Sector ) > MaxBlock ) then
  54.     begin
  55.       Sector:= 0;
  56.       Track:= succ( Track );
  57.       if  Track >= MaxTracks then Track:= 0;
  58.     end else
  59.     if  Sector < 0 then
  60.     begin
  61.       Sector:= pred( SectorsPerTrack );
  62.       Track:= pred( Track );
  63.       if  Track < 0 then
  64.       begin
  65.         Track:= pred( MaxTracks );
  66.         while Block( Track, Sector ) <> MaxBlock do Sector:= pred( Sector );
  67.       end;
  68.     end;
  69.   end;
  70. end;  { ComputeSector }
  71.  
  72. PROCEDURE FlushSector( Track, Sector: integer );
  73. begin
  74.   WriteSector( Track, Sector );
  75.   if WriteError then
  76.   begin
  77.     EraseLine(20);
  78.     write('Write error at track ', Track, ', sector ', Sector,'.' );
  79.     Pause( NoEscape );
  80.   end;
  81.   for i:= 1 to 16 do
  82.   begin
  83.     ComputeSector( Track, Sector, Forwards );
  84.     ReadSector( Track, Sector );
  85.   end;
  86.   for i:= 1 to 16 do
  87.   begin
  88.     ComputeSector( Track, Sector, Reverse );
  89.     ReadSector( Track, Sector );
  90.   end;
  91. end;  { FlushSector }
  92.  
  93. PROCEDURE SelectSector;
  94. label Exit;
  95. begin
  96.   with DPB^ do
  97.   begin
  98.     ClrScr;
  99.     if MoveBySectors then
  100.     begin
  101.       ReadInteger( Track, 0, pred( MaxTracks ), 'What is the track number' );
  102.       if Interrupted then goto Exit;
  103.       GetSector( Track, Sector );
  104.       if Interrupted then goto Exit;
  105.     end else { move by blocks }
  106.     begin
  107.       ReadInteger( BlockNumber, 0, MaxBlock, 'Which block' );
  108.       if Interrupted then goto Exit;
  109.       BlockToSector( BlockNumber, Track, Sector );
  110.     end;
  111.   end;
  112.   ReadSector( Track, Sector );
  113.   Exit:
  114. end;  { SelectSector }
  115.  
  116. PROCEDURE ChangeSector;
  117. const
  118.   FirstHexColumn    = 0;
  119.   MidHexColumn      = 25;
  120.   LastHexColumn     = 47;
  121.   FirstASCIIcolumn  = 50;
  122.   LastASCIIcolumn   = 65;
  123.   FirstRow          = 0;
  124.   LastRow           = 7;
  125. var
  126.   Key: char;
  127.  
  128.   PROCEDURE MoveRight;
  129.   begin
  130.     if Column < pred( FirstASCIIcolumn ) then
  131.     begin
  132.       write( CursorRight );
  133.       Column:= succ( Column );
  134.       ScreenPosition:= succ( ScreenPosition );
  135.       if ScreenPosition = 2 then
  136.       begin
  137.         write( CursorRight );
  138.         ScreenPosition:= 0;
  139.         Column:= succ( Column );
  140.       end;
  141.       if Column in [ pred( MidHexColumn ), pred( FirstASCIIcolumn ) ] then
  142.       begin
  143.         write( CursorRight );
  144.         Column:= succ( Column );
  145.       end;
  146.     end else { column > FirstASCIIcolumn - 2 } if Column < LastASCIIcolumn then
  147.     begin
  148.       write( CursorRight );
  149.       Column:= succ( Column );
  150.     end else  { column = LastASCIIcolumn }
  151.     begin
  152.       Tab( FirstHexColumn );
  153.       Column:= FirstHexColumn;
  154.       ScreenPosition:= 0;
  155.     end;
  156.   end;  { MoveRight }
  157.  
  158.   PROCEDURE MoveLeft;
  159.   begin
  160.     if Column > FirstASCIIcolumn then
  161.     begin
  162.       write( BackSpace );
  163.       Column:= pred( Column );
  164.     end else  { column <= FirstASCIIcolumn }  if Column > FirstHexColumn then
  165.     begin
  166.       write( BackSpace );
  167.       Column:= pred( Column );
  168.       ScreenPosition:= pred( ScreenPosition );
  169.       if ScreenPosition < 0 then
  170.       begin
  171.         write( BackSpace );
  172.         ScreenPosition:= 1;
  173.         Column:= pred( Column );
  174.       end;
  175.       if Column in [ MidHexColumn - 2, FirstASCIIcolumn - 2 ] then
  176.       begin
  177.         write( BackSpace );
  178.         Column:= pred( Column );
  179.       end;
  180.     end else  { column = FirstHexColumn }
  181.     begin
  182.       Tab( LastASCIIcolumn );
  183.       ScreenPosition:= 0;
  184.       Column:= LastASCIIcolumn;
  185.     end;
  186.   end;  { MoveLeft }
  187.  
  188.   PROCEDURE MoveDown;
  189.   begin
  190.     if Row < LastRow then
  191.     begin
  192.       write( CursorDown );
  193.       Row:= succ( Row );
  194.     end else  { row = LastRow }
  195.     begin
  196.       write( TabUp );
  197.       Row:= FirstRow;
  198.     end;
  199.   end;  { MoveDown }
  200.  
  201.   PROCEDURE MoveUp;
  202.   begin
  203.     if Row > FirstRow then
  204.     begin
  205.       write( CursorUp );
  206.       Row:= pred( Row );
  207.     end else  {  row = FirstRow }
  208.     begin
  209.       write( TabDown );
  210.       Row:= LastRow;
  211.     end;
  212.   end;  { MoveUp }
  213.  
  214.   PROCEDURE ChangeASCIIValue( Key : char );
  215.   var
  216.     ByteNumber, NewColumn: byte;
  217.   begin
  218.     write( CursorOff, Key );
  219.     ByteNumber:= ( Row*16 ) + ( Column - FirstASCIIcolumn );
  220.     NewColumn:= ( Column - FirstASCIIcolumn ) * 3;
  221.     if NewColumn >= MidHexColumn - 2 then NewColumn:= succ( NewColumn );
  222.     Tab( NewColumn );
  223.     write( Hex( ord( Key )));
  224.     Tab( Column );
  225.     MoveRight;
  226.     write( CursorOn );
  227.     Sectr.Buffer[ ByteNumber]:= ord( Key );
  228.     SectorChanged:= true;
  229.   end;  { ChangeASCIIValue }
  230.  
  231.   PROCEDURE ChangeHexValue( Key : char );
  232.   label Exit;
  233.   var
  234.     HexString: string[2];
  235.     ErrorCode, Value: integer;
  236.     Offset, ByteNumber, NewColumn: byte;
  237.   begin
  238.     Key:= Upcase( Key );
  239.     if not( Key in ['0'..'9','A'..'F'] ) then goto Exit;
  240.     write( CursorOff, Key );
  241.     if Column > pred( MidHexColumn ) then Offset:= 1 else Offset:= 0;
  242.     ByteNumber:= ( Row*16 ) + ( Column - Offset ) div 3;
  243.     HexString:= Hex( Sectr.Buffer[ ByteNumber] );
  244.     HexString[ succ( ScreenPosition )]:= Key;
  245.     val( '$' + HexString, Value, ErrorCode );
  246.     Sectr.Buffer[ ByteNumber]:= Value;
  247.     NewColumn:= ( Column - Offset ) div 3 + FirstASCIIcolumn;
  248.     Tab( NewColumn );
  249.     write( ASCII( Sectr.Buffer[ ByteNumber] ));
  250.     Tab( Column );
  251.     MoveRight;
  252.     write( CursorOn );
  253.     SectorChanged:= true;
  254.     Exit:
  255.   end;  { ChangeHexValue }
  256.  
  257. begin  { ChangeSector }
  258.   Row:= FirstRow;
  259.   Column:= FirstHexColumn;
  260.   ScreenPosition:= 0;
  261.   EraseLine(20);
  262.   write( 'Use arrow keys to move cursor over the byte you wish to change, ESC to exit.');
  263.   gotoXY(1,7);
  264.   repeat
  265.     read( Kbd, Key );
  266.     case Key of
  267.       Space..'~'  :
  268.         if Column > pred( FirstASCIIcolumn ) then ChangeASCIIValue( Key )
  269.           else ChangeHexValue( Key );
  270.       CursorRight :  MoveRight;
  271.       Backspace   :  MoveLeft;
  272.       CursorDown  :  MoveDown;
  273.       CursorUp    :  MoveUp;
  274.       ScreenPrint :  PrintScreen;
  275.     end;  { of case statement }
  276.   until Key = ESC;
  277.   if SectorChanged then
  278.   begin
  279.     EraseLine(20);
  280.     write('Do you wish to write these changes to disk (Y or N)?  ' );
  281.     if Response = 'Y' then FlushSector( Track, Sector ) else ReadSector( Track, Sector );
  282.     DisplaySector( Track, Sector );
  283.   end;
  284.   SectorChanged:= false;
  285. end;  { ChangeSector }
  286.  
  287. PROCEDURE ViewSector;
  288. label Exit;
  289. var
  290.   Key : char;
  291.   Displays : integer;
  292. begin
  293.   Range:= 1;
  294.   Key:= Space;
  295.   SelectSector;
  296.   if Interrupted then goto Exit;
  297.   ClrScr;
  298.   DisplaySector( Track, Sector );
  299.   while Key <> ESC do
  300.   begin
  301.     Interrupted:= false;
  302.     gotoXY(1,20);
  303.     Accent('(F)orward, (B)ackward, (R)ange, (J)ump, (C)hange, (M)ovement, (ESC)ape?  ');
  304.     ClrEol;
  305.     repeat
  306.       read( Kbd, Key );
  307.       if Key = ScreenPrint then PrintScreen;
  308.     until UpCase( Key ) in ['B','C','F','J','M','R',ESC];
  309.     Key:= UpCase( Key );
  310.     case Key of
  311.       'B': Direction:= Reverse;
  312.       'C': ChangeSector;
  313.       'F': Direction:= Forwards;
  314.       'J': begin
  315.              SelectSector;
  316.              if Interrupted then goto Exit;
  317.              EraseLine(1);
  318.              EraseLine(2);
  319.              DisplaySector( Track, Sector );
  320.            end;
  321.       'M': begin
  322.              EraseLine(1);
  323.              MoveBySectors:= not( MoveBySectors );
  324.              write( 'Viewing movement is now in ' );
  325.              if MoveBySectors then write( 'sector' ) else write( 'block' );
  326.              write(' increments.' );
  327.            end;
  328.       'R': begin
  329.              EraseLine(20);
  330.              ReadInteger( Range, 1, 600, 'How many sectors or blocks displayed each time' );
  331.              EraseLine(20);
  332.            end;
  333.     end;
  334.     Displays:= 0;
  335.     if Key in ['F','B'] then while ( Displays < Range ) and not Interrupted do
  336.     begin
  337.       Displays:= succ( Displays );
  338.       ComputeSector( Track, Sector, Direction );
  339.       ReadSector( Track, Sector );
  340.       DisplaySector( Track, Sector );
  341.       if KeyPressed and ( Range > 4 ) then AbortCommand;
  342.     end;
  343.   end;
  344.   Exit:
  345.   MoveBySectors:= true;
  346. end;  { ViewSector }
  347.  
  348.