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

  1. ;
  2. ; DumbDrv - Dummy DOS Device Driver
  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. JUMPS
  22. LOCALS
  23.  
  24. ;========================================================= CONSTANTS
  25. ; Status codes
  26. stSuccess     EQU    0100h
  27. stError        EQU    8100h
  28. stUnknownCmd    EQU    8103h
  29. stDrvNotReady    EQU    8102h
  30.  
  31. MediaID        EQU    0F0h    ; Media ID byte - "other"
  32.  
  33. ;========================================================= Driver segment
  34. SEGMENT DrvSeg
  35.     ASSUME cs:DrvSeg,ds:NOTHING,es:NOTHING,ss:NOTHING
  36. ; Device header
  37.     DW    0FFFFh, 0    ; Link to next driver
  38.     DW    0        ; Attributes
  39.     DW    Strategy, Interrupt
  40.     DB    1, 7 DUP (0)    ; Number of units
  41.  
  42. ;========================================================= Resident DATA area
  43. ; Data area
  44. ReqHdrOfs DW    0        ; Offset ot request header
  45. ReqHdrSeg DW    0        ; Segment of request header
  46. VolumeID DB    "DUMBDRV", 0
  47. ; BIOS Parameter Block
  48. LABEL    BPB
  49. BytesPerSec    DW    512
  50. SecPerClust    DB    2
  51. ResSectors    DW    1
  52. FATs        DB    1
  53. RootDirEnts    DW    32
  54. Sectors        DW    512
  55. Media        DB    0F0h
  56. FATsecs        DW    4
  57. SecPerTrack    DW    9
  58. Heads        DW    2
  59. HiddenSecs    DD    0
  60. HugeSectors    DD    0
  61. pBPB    DW    26 DUP(OFFSET BPB) ; Array of BPB pointers
  62.  
  63. JmpTbl    DW    Init, MediaChk, BuildBPB, 0
  64.     DW    NotReady, 0, 0, 0
  65.     DW    NotReady, NotReady
  66.  
  67. ;========================================================= STRATEGY routine
  68. PROC    Strategy FAR
  69.     mov    [ReqHdrOfs], bx
  70.     mov    [ReqHdrSeg], es
  71.     ret
  72. ENDP    Strategy
  73.  
  74. ;========================================================= INTERRUPT routine
  75. PROC    Interrupt FAR
  76.     push    ax bx cx dx si di bp ds es
  77.     pushf
  78.  
  79.     push    cs
  80.     pop    ds
  81.     ASSUME    ds:DrvSeg
  82.     les    bx, [DWORD ReqHdrOfs]
  83.     mov    al, [es:bx+2]    ; Function number
  84.     cmp    al, 09h
  85.     ja    @@errUnknownCommand
  86.     xor    ah, ah
  87.     mov    si, ax
  88.     shl    si, 1
  89.     mov    cx, [JmpTbl+si]
  90.     jcxz    @@errUnknownCommand
  91.     call    cx
  92.     jmp    @@Exit
  93.  
  94. @@errUnknownCommand:
  95.     mov    [WORD es:bx+3], stUnknownCmd
  96. @@Exit:    popf
  97.     pop    es ds bp di si dx cx bx ax
  98.     ret
  99. ENDP    Interrupt
  100.  
  101. ;========================================================= Functions
  102. ; Media check
  103. PROC    MediaChk
  104.     mov    [WORD es:bx+3], stSuccess    ; Status
  105.     mov    [BYTE es:bx+14], 1        ; Media unchanged
  106.     mov    [WORD es:bx+15], OFFSET VolumeID
  107.     mov    [es:bx+17], cs
  108.     ret
  109. ENDP    MediaChk
  110.  
  111. ; Build BPB
  112. PROC    BuildBPB
  113.     mov    [WORD es:bx+3], stSuccess    ; Status
  114.     mov    [WORD es:bx+18], OFFSET BPB
  115.     mov    [es:bx+20], cs
  116.     ret
  117. ENDP    BuildBPB
  118.  
  119. ; Return "Drive not ready" error for Read or Write req.
  120. PROC    NotReady
  121.     mov    [WORD es:bx+3], stDrvNotReady
  122.     mov    [WORD es:bx+18], 0        ; Sectors read/written
  123.     mov    [WORD es:bx+22], OFFSET VolumeID
  124.     mov    [WORD es:bx+24], cs
  125.     ret    
  126. ENDP    NotReady
  127.  
  128. LABEL    EndResCode
  129. ;========================================================= INIT Code
  130. PROC    Init
  131. ; Say hello
  132.     mov    ah, 09h
  133.     mov    dx, OFFSET HelloMsg
  134.     int    21h
  135. ; Parse command line
  136.     call    ParseCmdLine
  137.     jc    @@CmdLineError
  138.     or    al, al
  139.     jz    @@CmdLineError            ; Zero drives specified
  140.     mov    ah, [es:bx+22]            ; First drive number
  141.     add    ah, al
  142.     cmp    ah, 25                ; Maximum number of drives
  143.     jna    @@DrivesOk
  144.     mov    al, 26
  145.     sub    al, [es:bx+22]
  146. @@DrivesOk:
  147.     mov    [Drives], al
  148. ; Set fields
  149.     mov    [BYTE es:bx+13], al        ; Number of units
  150.     mov    [WORD es:bx+3], stSuccess    ; Status
  151.     mov    [WORD es:bx+14], OFFSET EndResCode
  152.     mov    [es:bx+16], cs
  153.     mov    [WORD es:bx+18], OFFSET pBPB
  154.     mov    [es:bx+20], cs
  155.     mov    [WORD es:bx+23], 1        ; Error message flag
  156. ; Print message
  157.     mov    ah, [es:bx+22]            ; Drive number
  158.     add    [DrvLetter], ah
  159.     mov    ah, 09h
  160.     mov    dx, OFFSET InstallMsg
  161.     int    21h
  162.     mov    al, [Drives]
  163.     cmp    al, 1
  164.     je    @@Msg1
  165.     add    al, [es:bx+22]
  166.     dec    al
  167.     add    [DrvLetter2], al
  168.     mov    ah, 09h
  169.     mov    dx, OFFSET InstMsg2
  170.     int    21h
  171.     ret
  172. @@Msg1:
  173.     mov    ah, 09h
  174.     mov    dx, OFFSET MsgEnd
  175.     int    21h
  176.     ret
  177. ; Bad cmd line syntax - fail init
  178. @@CmdLineError:
  179.     mov    ah, 09h
  180.     mov    dx, OFFSET Syntax
  181.     int    21h
  182.     mov    [BYTE es:bx+13], 0
  183.     mov    [WORD es:bx+14], 0
  184.     mov    [WORD es:bx+13], stError
  185.     ret
  186. ENDP    Init
  187.  
  188. ;---------------------------------------------------------------------
  189. ; Parse command line.
  190. PROC    ParseCmdLine
  191.     push    ds
  192.     push    bx cx dx si di
  193.     cld
  194.     lds    si, [es:bx+18]
  195.     ASSUME    ds:NOTHING
  196. ; Scan past the filename to the first space
  197. @@EatFilename:
  198.     lodsb
  199.     cmp    al, 0Dh
  200.     je    @@NoParams
  201.     cmp    al, 0Ah
  202.     je    @@NoParams
  203.     cmp    al, ' '
  204.     jne    @@EatFilename
  205. ; Eat spaces
  206. @@EatSpaces:
  207.     lodsb
  208.     cmp    al, ' '
  209.     je    @@EatSpaces
  210.     cmp    al, 0Ah
  211.     je    @@NoParams
  212.     cmp    al, 0Dh
  213.     je    @@NoParams
  214.     xor    dx, dx
  215. ; Parse one- or two-digit number
  216.     cmp    al, '0'
  217.     jb    @@Error
  218.     cmp    al, '9'
  219.     ja    @@Error
  220.     mov    dl, al
  221.     sub    dl, '0'
  222.     lodsb
  223.     cmp    al, 0Ah
  224.     je    @@Done
  225.     cmp    al, 0Dh
  226.     je    @@Done
  227.     cmp    al, ' '
  228.     je    @@EndParams
  229.     cmp    al, '0'
  230.     jb    @@Error
  231.     cmp    al, '9'
  232.     ja    @@Error
  233.     sub    al, '0'
  234.     mov    dh, dl
  235.     mov    cl, 3
  236.     shl    dh, cl
  237.     shl    dl, 1
  238.     add    dl, dh
  239.     add    dl, al
  240. ; Make sure command line ends here
  241. @@EndParams:
  242.     lodsb
  243.     cmp    al, 0Ah
  244.     je    @@Done
  245.     cmp    al, 0Dh
  246.     je    @@Done
  247.     cmp    al, ' '
  248.     je    @@EndParams
  249.  
  250. @@Error:
  251.     stc
  252.     jmp    @@Exit
  253. @@NoParams:
  254.     mov    ax, 1
  255.     clc
  256.     jmp    @@Exit
  257. @@Done:
  258.     mov    al, dl
  259.     xor    ah, ah
  260.     clc
  261.     jmp    @@Exit
  262.  
  263. @@Exit:
  264.     pop    di si dx cx bx
  265.     pop    ds
  266.     ret
  267. ENDP    ParseCmdLine
  268.  
  269. ;========================================================= INIT data
  270. HelloMsg DB    10,13,"DumbDrv     Version 1.10     96-01-03", 10, 13
  271.     DB      "Copyright (c) 1994-96, Marcus Better.",10,13,10,13,"$"
  272. InstallMsg DB    "DumbDrv installed as "
  273. DrvLetter DB    "A:","$"
  274. InstMsg2 DB    " - "
  275. DrvLetter2 DB    "A:"
  276. MsgEnd    DB    10,13,"$"
  277.  
  278. Syntax    DB    "Invalid arguments.",10,13,"$"
  279. Drives    DB    1    ; Number of drives to support
  280.  
  281. ENDS    DrvSeg
  282.     END