home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / docum / dos-ref.doc / examples / chap2.arj / LASTDRV2.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-09-25  |  2.2 KB  |  82 lines

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