home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l440 / 2.ddi / CHAP2 / LASTDRV3.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-09-25  |  2.2 KB  |  93 lines

  1. { LASTDRV3.PAS }
  2.  
  3. program LastDrv;
  4. uses dos;
  5.  
  6. type 
  7.     Dos20 = record
  8.         numdrives : Byte;
  9.         maxbytes : Word;
  10.         first_diskbuff : Longint;
  11.         nul : array [1..18] of Byte;
  12.     end;
  13.  
  14.     Dos30 = record
  15.         numblkdev : Byte;
  16.         maxbytes : Word;
  17.         first_diskbuff : Longint;
  18.         currdir : Longint;
  19.         lastdrive : Byte;
  20.         stringarea : Longint;
  21.         size_stringarea : Word;
  22.         fcbtab : Longint;
  23.         fcb_y : Word;
  24.         nul : array [1..18] of Byte;
  25.     end;
  26.  
  27.     Dos31 = record      { DOS 3.1 and higher }
  28.         maxbytes : Word;
  29.         diskbuff : Longint;
  30.         currdir : Longint;
  31.         fcb : Longint;
  32.         numprotfcb : Word;
  33.         numblkdev : Byte;
  34.         lastdrive : Byte;
  35.         nul : array [1..18] of Byte;
  36.         numjoin : Word;
  37.     end;
  38.  
  39.     ListOfLists = record
  40.         shareretrycount : Word;
  41.         shareretrydelay : Word;
  42.         currdiskbuf : Longint;
  43.         unreadcon : Word;
  44.         mcb : Word;
  45.         dpb : Longint;
  46.         filetable : Longint;
  47.         clock : Longint;
  48.         con : Longint;
  49.         case Word of
  50.             20 : (dos20 : Dos20);
  51.             30 : (dos30 : Dos30);
  52.             31 : (dos31 : Dos31);
  53. end;
  54.  
  55. var
  56.     lastdrive : Word;
  57.  
  58. function GetLastDrive : Word;
  59. var
  60.     doslist : ^ListOfLists;
  61.     r : registers;
  62.     vers : Word;
  63. begin
  64.     { Get pointer to DOS List Of Lists }
  65.     with r do begin
  66.         ah := $52;
  67.         es := 0; bx := 0;
  68.         MsDos(r);
  69.         if (es = 0) and (bx = 0) then begin
  70.             GetLastDrive := 0;
  71.             Exit;
  72.         end;
  73.         doslist := Ptr(es, bx - 12);
  74.     end;
  75.     { LASTDRIVE offset depends on DOS version }
  76.     GetLastDrive := doslist^.dos31.lastdrive;
  77.     vers := DosVersion;
  78.     case Lo(vers) of 
  79.         0 : GetLastDrive := 0; { DOS 1 }
  80.         2 : GetLastDrive := doslist^.dos20.numdrives;
  81.         3 : if Hi(vers) = 0 then 
  82.                GetLastDrive := doslist^.dos30.lastdrive;
  83.     end;
  84. end;    
  85.  
  86. begin
  87.     lastdrive := GetLastDrive;
  88.     if lastdrive = 0 then 
  89.         Halt(0);
  90.     Writeln('LASTDRIVE=', Chr(Ord('A') - 1 + lastdrive));
  91.     Halt(lastdrive);
  92. end.
  93.