home *** CD-ROM | disk | FTP | other *** search
/ hobbes.nmsu.edu / 2008-06-02_hobbes.nmsu.edu.zip / dos / ihpfs129.zip / killdrv.asm < prev    next >
Assembly Source File  |  1998-03-23  |  5KB  |  213 lines

  1. ;
  2. ; KillDrv - Drive removal utility
  3. ; Copyright (C) 1994-1997 Marcus Better
  4. ;
  5. ; This program is free software; you can redistribute it and/or modify
  6. ; it under the terms of the GNU General Public License as published by
  7. ; the Free Software Foundation; either version 2 of the License, or
  8. ; (at your option) any later version.
  9. ;
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ; GNU General Public License for more details.
  14. ;
  15. ; You should have received a copy of the GNU General Public License
  16. ; along with this program; if not, write to the Free Software
  17. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ;
  19.  
  20.     IDEAL
  21.     MODEL    SMALL
  22.     JUMPS
  23.     LOCALS
  24. ;========================================================= MACROs
  25. MACRO   Abort   Code
  26.     mov     bx, Code
  27.     call    AbortMsg
  28. ENDM
  29.  
  30.     STACK
  31. ;========================================================= CODE segment
  32.     CODESEG
  33.     STARTUPCODE
  34.  
  35. PROC    Main
  36. ; Write hello message
  37.     mov     ah, 09h
  38.     mov     dx, OFFSET MsgHello
  39.     int     21h
  40. ; Check for DR-DOS or Novell DOS
  41.     mov    ax, 4452h
  42.     stc
  43.     int    21h
  44.     jc    @@NotDrDos
  45. ; DR-DOS or Novell DOS found. Check version.
  46.     cmp    ah, 10h
  47.     jne    @@errBadDosVer
  48.     cmp    al, 72h        ; Novell DOS
  49.     je    @@NovellDOS
  50.     mov    [DrDos], al    ; DR-DOS version code
  51.     mov    [CDSSize], 51h    ; CDS size different under DR-DOS
  52.     cmp    al, 65h        ; DR-DOS 5
  53.     je    @@DosVerOk
  54.     cmp    al, 67h        ; DR-DOS 6
  55.     je    @@DosVerOk
  56.     jmp    @@errBadDosVer
  57. @@NovellDOS:
  58. ;    mov    [Novell], 1
  59.     jmp    @@DosVerOk
  60. @@NotDrDos:
  61. ; Check DOS version
  62.     mov     ax, 3000h
  63.     int     21h
  64.     cmp     al, 4
  65.     jb      @@errBadDOSVer
  66.     cmp     al, 10
  67.     jae    @@errBadDOSVer
  68. @@DosVerOk:
  69.  
  70. ;Parse command line
  71.     call    ParseCmdLine
  72.     cmp    [DriveNo], 0FFh
  73.     jne    @@DrvSpecd
  74.     Abort    1            ; Drive not specified
  75. @@DrvSpecd:
  76. ; Get list of lists.
  77.     mov    ah, 52h
  78.     int    21h            ; ES:BX->List of lists
  79. ; Compare drive letter with lastdrive.
  80.     mov    al, [es:bx+21h]    
  81.     cmp    al, [DriveNo]
  82.     ja    @@LastdrvOk
  83.     Abort    2            ; Invalid drive letter
  84. @@LastdrvOk:
  85. ; Find CDS for drive
  86.     les    bx, [es:bx+16h]        ; CDS array
  87.     mov     al, [DriveNo]
  88.     mov     dl, [BYTE CDSSize]
  89.     mul     dl
  90.     add     bx, ax              ; CDS entry for drive
  91.     cmp    [DrDos], 0
  92.     jz    @@DisableMSDOS
  93.     mov    [WORD es:bx+43h], 0
  94.     jmp    @@Disabled
  95. @@DisableMSDOS:
  96.     and    [BYTE PTR es:bx+44h], 03Fh ; Remove drive
  97. @@Disabled:
  98. ; Print message and return
  99.     mov    al, [DriveNo]
  100.     add    [RemovedDrv], al
  101.     mov    dx, OFFSET OkMsg
  102.     mov    ah, 9
  103.     int    21h
  104.     mov    ax, 4C00h
  105.     int    21h
  106.  
  107. @@errBadDosVer:
  108.     Abort   3
  109. ENDP    Main
  110.  
  111. ;---------------------------------------------------------------------
  112. PROC    AbortMsg
  113.     ASSUME  ds:@data,es:NOTHING
  114.     mov     ax, @data
  115.     mov     ds, ax
  116.     shl     bx, 1
  117.     mov     dx, [ErrMsgTbl+bx]
  118.     mov     ah, 9
  119.     int     21h
  120.     mov     ax, bx
  121.     shr     ax, 1
  122.     mov     ah, 4Ch
  123.     int     21h
  124. ENDP    AbortMsg
  125.  
  126. ;---------------------------------------------------------------------
  127. ; Parse command line.
  128. PROC    ParseCmdLine STDCALL
  129.     LOCAL   LastByte
  130.     mov    ah, 51h
  131.     int    21h        ; Get PSP
  132.     mov    es, bx
  133.     mov     al, [BYTE PTR es:80h]
  134.     cmp     al, 2
  135.     jb      @@Done
  136.     add     al, 80h
  137.     xor     ah, ah
  138.     mov     [LastByte], ax
  139. ; Find first non-space character
  140.     mov     di, 81h
  141. @@Next:
  142.     mov     cx, [LastByte]
  143.     sub     cx, di
  144.     jc      @@Done
  145.     inc     cx
  146.     mov     al, ' '
  147.     cmp     al, ' '         ; Set zero flag
  148.     repe scasb
  149.     je      @@Done
  150.     dec     di
  151. ; Get char and convert to upper case
  152.     mov     dl, [es:di]
  153.     mov     ax, 6520h
  154.     int     21h
  155. ; Check for drive spec 'A'..'Z'
  156.     cmp     dl, 'A'
  157.     jb      @@Parse2
  158.     cmp     dl, 'Z'
  159.     ja      @@Parse2
  160. ; Drive spec.
  161.     inc     di
  162.     mov     al, ':'                 ; Match a colon
  163.     scasb
  164.     jne     @@errBadOption
  165.     sub     dl, 'A'                 ; Drive number
  166.     mov     [DriveNo], dl
  167.     jmp     @@Next
  168. @@Parse2:
  169. ; Check for switches
  170.     mov     al, '/'
  171.     scasb
  172.     jne     @@errBadOption
  173. ; Switch
  174.     cmp     di, [LastByte]
  175.     ja      @@errBadOption
  176.     mov     dl, [es:di]
  177.     inc     di
  178.     mov     ax, 6520h        ; Upper case
  179.     int     21h
  180. ; Insert any switches here...
  181.     jmp     @@errBadOption
  182.  
  183. @@errBadOption:
  184.     Abort   0            ; Bad cmdline syntax
  185.  
  186. @@Done:
  187.     ret
  188. ENDP    ParseCmdLine
  189.  
  190. ;========================================================= DATA segment
  191.     DATASEG
  192. DriveNo    DB    0FFh
  193. DrDos    DB    0    ; Nonzero if DR-DOS (zero if Novell DOS)
  194. CDSSize    DW    58h    ; Size of CDS entry
  195. ; Messages
  196. ErrMsgTbl DW    MsgBadOption        ; 0 - Bad cmdline syntax
  197.     DW    MsgNoDriveSpec        ; 1 - No drive specified
  198.     DW    MsgInvalidDrv        ; 2 - Invalid drive letter
  199.     DW    MsgBadDOSVer        ; 3 - Bad DOS version
  200.  
  201. MsgHello DB     "KillDrv            Drive removal utility           "
  202.     DB    "Version 1.01    97-05-03",10,13
  203.     DB      "Copyright (c) 1994-1997 Marcus Better.",10,13,10,13,"$"
  204. MsgBadOption DB "Invalid command line arguments.",10,13,10,13
  205.     DB      "Syntax: KILLDRV d:",10,13
  206.     DB      "where d is the drive letter to be removed.",10,13,"$"
  207. MsgNoDriveSpec DB "No drive letter specified.",10,13,"$"
  208. MsgInvalidDrv DB "Invalid drive letter.",10,13,"$"
  209. MsgBadDOSVer DB    "Wrong DOS version.",10,13,"$"
  210. OkMsg    DB    "Removed drive "
  211. RemovedDrv DB    "A:",10,13,"$"
  212. ;========================================================= 
  213.     END