home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l440 / 2.ddi / CHAP2 / LASTDRV2.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-05-14  |  2.3 KB  |  84 lines

  1. ; LASTDRV2.ASM -- uses undocumented DOS
  2. ; this version fixes a misprint in the first and second printings of
  3. ; UNDOCUMENTED DOS, p. 45
  4.  
  5.         assume cs:_TEXT, ds:_DATA, ss:_STACK
  6.  
  7. _STACK  segment para stack 'STACK'
  8. _STACK  ends
  9.  
  10. _DATA   segment word public 'DATA'
  11. msg     db      'LASTDRIVE='
  12. dletter db      (?)
  13.         db      0dh, 0ah, '$'
  14. _DATA   ends
  15.  
  16. _TEXT   segment word public 'CODE'
  17.  
  18.         public  _lstdrv
  19.  
  20. _lstdrv proc    far
  21.         push    si
  22.         push    bx
  23.         push    cx
  24.  
  25.         mov     si, 1Bh         ; assume DOS 3.0
  26.  
  27.         mov     ax, 3000h       ; Get MS-DOS version number
  28.         int     21h             ; major=AL, minor=AH
  29.         cmp     al, 2
  30.         jl      fail            ; Requires DOS 2+
  31.  
  32.         jne     dos3up          ; DOS 3+
  33.         mov     si, 10h         ; DOS 2.x
  34.         jmp     short get
  35. dos3up: cmp     al, 3
  36.         jne     ofs21
  37.         and     ah, ah          ; DOS 3.0
  38.         jz      get
  39. ofs21:  mov     si, 21h         ; DOS 3.1+, DOS 4.x
  40.         
  41. get:    mov     ah, 52h         ; Get List of Lists
  42.         xor     bx, bx          ; Zero out ES:BX so we can check
  43.         mov     es, bx          ;   for NULL after INT 21h
  44.         int     21h             ; list=ES:BX
  45.         mov     cx, es
  46.         or      cx, bx          ; Is ES:BX NULL?
  47.         jz      fail            ; Function 52h not supported
  48.  
  49.         mov     al, byte ptr es:[bx+si]
  50.         xor     ah, ah          ; return LASTDRIVE in AX
  51.         jmp     short leave
  52.  
  53. fail:   xor     ax, ax          ; return 0 in AX
  54. leave:  pop     cx
  55.         pop     bx
  56.         pop     si
  57.         ret
  58. _lstdrv endp
  59.  
  60. main    proc    near
  61.         mov     ax, _DATA
  62.         mov     ds, ax
  63.  
  64.         call    _lstdrv
  65.         and     ax, ax          ; test for failure
  66.         jz      done
  67.  
  68.         mov     bl, al          ; save LASTDRIVE in BL
  69.         add     al, ('A' - 1)   ; convert LASTDRIVE to drive letter
  70.         mov     dletter, al     ; insert into string
  71.  
  72.         mov     ah, 9           ; Display String
  73.         mov     dx, offset msg
  74.         int     21h
  75.  
  76. done:   mov     ah, 4Ch         ; Return to DOS
  77.         mov     al, bl          ; exit code
  78.         int     21h
  79. main    endp
  80.  
  81. _TEXT   ends
  82.  
  83.         END     main
  84.