REM LASTDRVIVE -- uses only documented DOS
REM $INCLUDE: 'QB.BI'

REM BASIC 6.0 compiler:
REM    bc /o lastdrv.bas;
REM    link lastdrv,,,qb.lib;

REM Quick BASIC (must produce standalone executable!):
REM    qb lastdrv.bas /L qb.qlb

SUB DOSEXIT(errorlevel)
    CLOSE
    DIM Regs AS RegType
    Regs.ax = &H4C00 + errorlevel   ' Terminate Process
    CALL INTERRUPT(&H21, Regs, Regs)
    PRINT "this is never executed"
END SUB

DIM Regs AS RegType
Regs.ax = &H1900                    ' Get Current Disk
CALL INTERRUPT(&H21, Regs, Regs)
Regs.dx = Regs.ax
Regs.ax = &H0E00                    ' Select Disk
CALL INTERRUPT(&H21, Regs, Regs)
lastdrv = Regs.ax AND &HFF
PRINT "LASTDRIVE="; CHR$(ASC("A") - 1 + lastdrv)
CALL DOSEXIT(lastdrv)
END
