home *** CD-ROM | disk | FTP | other *** search
/ BBS 1 / BBS#1.iso / document / mn195.ha / RABEC.TXT < prev    next >
Text File  |  1994-10-24  |  7KB  |  161 lines

  1. ï¿ßΓ¿¡ú
  2.  
  3. {$A+,B-,D+,E-,F-,G-,I-,L+,N-,O-,P-,Q+,R+,S+,T+,V+,X-,Y+}
  4. {$M 2048,65536,65536}
  5. { #H#C#S, (C) V.S.Rabets, 1994. Edition 09.07.94 }
  6. uses DOS;
  7.  
  8. type tPartEntry = record Boot     : byte;
  9.                          BegHead  : byte;
  10.                          BegSecCyl: word;
  11.                          Sys      : byte;
  12.                          EndHead  : byte;
  13.                          EndSecCyl: word;
  14.                          OtherInfo: array [1..2*4] of byte;
  15.                   end;
  16.      tPartitionTable = record BootCode: array [1..$1BE] of byte;
  17.                               PE: array [1..4] of tPartEntry;
  18.                        end;
  19. var PT: ^tPartitionTable absolute HeapOrg;
  20.  
  21. const Drive: byte = $80;                              { êßß½ÑñπѼδ⌐ ñ¿ß¬ }
  22.       MaxHeadP: byte = 0;{Max º¡áτÑ¡¿∩ Head, Cyl ¿ Sec ¿º Partition table}
  23.       MaxCylP : word = 0;
  24.       MaxSecP : byte = 1;
  25.       ParamInt: byte = $41;  {éÑ¬Γ«α, π¬áºδóáεΘ¿⌐ ¡á Γáí½¿µπ »áαá¼ÑΓα«ó
  26.                                                                     ñ¿ß¬á}
  27. var ParamTable: record CylCnt : word;         { Æáí½¿µá »áαá¼ÑΓα«ó ñ¿ß¬á }
  28.                        HeadCnt: byte;
  29.                        SomeInfo: array [3..$D] of byte;
  30.                        SecPerTrack: byte;
  31.                        OtherInfo: byte;
  32.                 end;
  33. var  SaveParamAddr,            { ÇñαÑß ¿ßσ«ñ¡«⌐ Γáí½¿µδ »áαá¼ÑΓα«ó ñ¿ß¬á }
  34.      SaveExitProc: pointer;
  35.      R: registers;
  36.      Start,
  37.      i,w: word;
  38.                                             { ôßΓá¡«ó¬á »áαá¼ÑΓα«ó ñ¿ß¬á }
  39. function SetDriveParams (ParamAddr: pointer): boolean;
  40.                                                     {ParamAddr - @Γáí½¿µδ}
  41. begin
  42.   SetIntVec (ParamInt, ParamAddr);           { ôßΓá¡«ó¬á int $41 ¿½¿ $46 }
  43.   with R do begin
  44.        DL:=Drive;
  45.        AH:=9;                       { ôßΓá¡«ó¬á Γáí½¿µδ »áαá¼ÑΓα«ó ñ¿ß¬á }
  46.        intr ($13, R);
  47.        SetDriveParams:=(Flags and fCarry)=0;
  48.   end;
  49. end;
  50.  
  51. function SetBigDisk: boolean;   { ôßΓá¡«ó¬á max º¡áτÑ¡¿⌐ Head, Cyl, Sect }
  52. begin
  53.   move ( (pointer(MemL[0:ParamInt*4]))^, ParamTable, SizeOf(ParamTable) );
  54.   with ParamTable do begin           { è«»¿α«óá¡¿Ñ ¿ ¼«ñ¿Σ¿¬áµ¿∩ Γáí½¿µδ }
  55.        CylCnt :=1024;
  56.        if HeadCnt<16 then HeadCnt:=16;
  57.        SecPerTrack:=64;
  58.   end;
  59.   SetBigDisk:=SetDriveParams(@ParamTable);
  60.                                        {ôßΓá¡«ó¬á ¡«óδσ »áαá¼ÑΓα«ó ñ¿ß¬á}
  61. end;
  62.  
  63. function ReadSector (Head:byte; Cyl:word; Sec:byte): boolean;
  64. begin
  65.   with R do begin
  66.        ES:=seg(HeapOrg^);                      { ÉẼÑα heap ºáñá¡ 64¬í }
  67.        BX:=ofs(HeapOrg^);
  68.        DL:=Drive;
  69.        DH:=Head;
  70.        CH:=lo(Cyl);
  71.        CL:=Sec + (hi(Cyl) shl 6);
  72.        AL:=1;                     { ù¿ΓáΓ∞ 1 ßÑ¬Γ«α }
  73.        AH:=2;                       { ù¿ΓáΓ∞ ßÑ¬Γ«α }
  74.        intr ($13, R);
  75.        ReadSector:=(Flags and fCarry)=0;
  76.   end;
  77. end;
  78.  
  79. function MaxWord (W1, W2, W3: word): word;         { Max ¿º ΓαÑσ τ¿ßѽ }
  80. var Max: word;
  81. begin
  82.    Max:=W1; if W2>Max then Max:=W2; if W3>Max then Max:=W3;  MaxWord:=Max;
  83. end;
  84.  
  85. procedure ExitProcedure; far;
  86. begin
  87.   ExitProc:=SaveExitProc;
  88.   if not SetDriveParams (SaveParamAddr)
  89.      then writeln (#10'Restore disk parameters error'#7);
  90. end;
  91.  
  92. { =========================================================== MAIN === }
  93. begin
  94.   writeln (#10'#H#C#S, ver. 1.00. (C) V.S.Rabets, 1994'#10);
  95.   writeln ('The program try to determine number of Heads, Cylinders and Sectors_per_track');
  96.   writeln ('                      on hard disk. It is useful in the case of CMOS trouble.');
  97.   writeln ('The program analyzes Partition table, then it reads some sectors and displays');
  98.   writeln ('                        the last readable Head, Cylinder and Sector_on_track.');
  99.   writeln ('Syntax:');
  100.   writeln ('       #H#C#S /? - to get Help screen without work');
  101.   writeln ('       #H#C#S    - to explore 1st hard disk');
  102.   writeln ('       #H#C#S /2 - to explore 2nd hard disk');
  103.  
  104.   if ParamStr(1)=''   then                                     else
  105.   if ParamStr(1)='/?' then halt                                else
  106.   if ParamStr(1)='/2' then begin Drive:=$81; ParamInt:=$46 end else
  107.      begin writeln (#10'Invalid parameters'#7); halt end;
  108.  
  109.   for w:=1 to 80 do write ('=');
  110.   write ('Hard disk #',Drive-($80-1),':    ');
  111.   { ------------------------------------------- ùΓÑ¡¿Ñ αáºñѽá: --- }
  112.   if not ReadSector (0,0,1) {Head=0,Cyl=0,Sec=1}
  113.      then writeln ('Error reading Partition table'#7)
  114.      else begin
  115.           for i:=1 to 4 do with PT^.PE[i] do begin
  116.               MaxHeadP:=MaxWord (MaxHeadP,BegHead,EndHead);
  117.               MaxCylP :=MaxWord (MaxCylP,
  118.                                  hi(BegSecCyl) + (lo(BegSecCyl) shr 6)*256,
  119.                                  hi(EndSecCyl) + (lo(EndSecCyl) shr 6)*256 );
  120.               MaxSecP :=MaxWord (MaxSecP, lo(BegSecCyl) and $3F,
  121.                                           lo(EndSecCyl) and $3F);
  122.           end;
  123.           writeln ('Max values from Partition table: Head-', MaxHeadP,
  124.                    ', Cyl-', MaxCylP, ', Sector-', MaxSecP);
  125.      end;
  126.   { --------------------------- ôßΓá¡«ó¬á ¡«óδσ »áαá¼ÑΓα«ó ñ¿ß¬á: --- }
  127.   GetIntVec (ParamInt, SaveParamAddr);   {æ«σαá¡Ñ¡¿Ñ áñαÑßá ¿ßσ«ñ¡«⌐ Γáí½¿µδ}
  128.   SaveExitProc:=ExitProc;
  129.   ExitProc:=@ExitProcedure;
  130.   if not SetBigDisk then begin     { ôßΓá¡«ó¬á max º¡áτÑ¡¿⌐ Head, Cyl, Sect }
  131.      writeln (#10'Change disk parameters error'#7); halt end;
  132.   { -------------------------------------------- ùΓÑ¡¿Ñ ñ¿ß¬á: --- }
  133.   Start:=0; writeln;      { Å«¿ß¬ »«ß½Ññ¡Ñ⌐ ú«½«ó¬¿ }
  134.   for i:=0 to 1 do
  135.   for w:=Start to $FF do
  136.       if ReadSector(w,i,1) then begin    { Head=w, Cyl=0|1, Sec=1 }
  137.          Start:=w;
  138.          write (#13'Read Cylinder ',i,', Sector 1: last readable Head - ',w);
  139.       end else begin writeln; break end;
  140.  
  141.   Start:=0; writeln;      { Å«¿ß¬ »«ß½Ññ¡Ñú« µ¿½¿¡ñαá }
  142.   while ( Start<1024-10 ) and ( ReadSector(0,Start+10,1) ) do begin
  143.         inc (Start,10);
  144.         write (#13'Read Head 0, Sector 1: last readable Cylinder - ',Start);
  145.   end;
  146.   for i:=0 to 1 do
  147.   for w:=Start to 1023 do
  148.       if ReadSector(i,w,1) then begin    { Head=0|1, Cyl=w, Sec=1 }
  149.          Start:=w;
  150.          write (#13'Read Head ',i,', Sector 1: last readable Cylinder - ',w);
  151.       end else begin writeln; break end;
  152.  
  153.   Start:=1; writeln;      { Å«¿ß¬ »«ß½Ññ¡Ñú« ßÑ¬Γ«αá }
  154.   for i:=0 to 1 do
  155.   for w:=Start to 64 do
  156.       if ReadSector(i,0,w) then begin    { Head=0|1, Cyl=0, Sec=w }
  157.          Start:=w;
  158.          write (#13'Read Head ',i,', Cylinder 0: last readable Sector - ',w);
  159.       end else begin writeln; break end;
  160. end.
  161.