;Copyright 2000 - Mark McDonald All rights reserved
; DECLARE: FUNCTION getBootDrive$()
; GETBOOTDRIVE
;     Returns the drive letter of the boot disk.
;     EXAMPLE:  T$ = GETBOOTDRIVE  'C:'
; GETBOOTDRIVE()
;     Returns the drive letter of the boot disk.
;     EXAMPLE:  T$ = GETBOOTDRIVE  'C:'

Extrn   Get$Alloc: Far
Extrn   Get$Loc: Far

MCODE   Segment Byte Public
        Assume  CS: MCODE

        Public  getBootDrive

getBootDrive Proc Far
        push    DS                      ;

        mov     AH,30h                  ; Get DOS version
        int     21h                     ; AL = Major, AH = Minor
        cmp     AL,4                    ; do we have at least DOS 4.0?
        xor     AX,AX                   ; assume not
        jb      Exit                    ; no, exit
        mov     AX,2                    ; we need a 2 byte string
        push    AX                      ; push it on the stack
        call    Get$Alloc               ; allocate a string
        or      AX,AX                   ; did we get a string?
        jz      Exit                    ; no, exit
        push    AX                      ; save for exit
        push    AX                      ; push for Get$Loc
        call    Get$Loc                 ; find it
        mov     ES,DX                   ; put segment in ES
        mov     DI,AX                   ; put offset in DI
        mov     AX,3305h                ; DOS function 3305h, get boot drive
        int     21h                     ; DL = boot drive
        mov     AL,DL                   ; put boot drive in AL
        add     AL,64                   ; convert to letter
        stosb                           ; save it in the string
        mov     AL,':'                  ; add a colon
        stosb                           ; save it in the string
        pop     AX                      ; get the string handle
Exit:
        pop     DS                      ;
        retf                            ;
GETBootDrive EndP
MCODE   EndS
        End