{ LASTDRV2.PAS }

program LastDrv;
uses dos;

var
    r : registers;
    lastdrv_ofs : Word;
    lastdrive : Word;
    vers : Word;

begin
    { determine offset of LASTDRIVE within DOS List Of Lists }
    lastdrv_ofs := $21;
    vers := DosVersion;
    case Lo(vers) of
        0 : Halt(0); { DOS 1 }
        2 : lastdrv_ofs := $10;
        3 : if Hi(vers) = 0 then lastdrv_ofs := $1B;
    end;

    { Get pointer to DOS List Of Lists }
    with r do begin
        ah := $52;
        es := 0; bx := 0;
        MsDos(r);
        if (es = 0) and (bx = 0) then 
            Halt(0);
        lastdrive := Mem[es:bx+lastdrv_ofs];
    end;
    if lastdrive = $FF then 
        Halt(0);

    { Print LASTDRIVE letter; return LASTDRIVE value }
    Writeln('LASTDRIVE=', Chr(Ord('A') - 1 + lastdrive));
    Halt(lastdrive);
end.
