home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / dos_ency / 15 / template.asm next >
Encoding:
Assembly Source File  |  1988-08-11  |  8.5 KB  |  330 lines

  1.         name    template
  2.         title   'TEMPLATE --- installable driver template'
  3.  
  4. ;
  5. ; TEMPLATE.ASM:  A program skeleton for an installable
  6. ;                device driver (MS-DOS 2.0 or later)
  7. ;
  8. ; The driver command-code routines are stubs only and have
  9. ; no effect but to return a nonerror "Done" status.
  10. ; Ray Duncan, July 1987
  11. ;
  12.  
  13. _TEXT   segment byte public 'CODE'
  14.  
  15.         assume  cs:_TEXT,ds:_TEXT,es:NOTHING
  16.  
  17.         org     0
  18.  
  19. MaxCmd  equ     24              ; maximum allowed command code
  20.                                 ; 12 for MS-DOS 2.x
  21.                                 ; 16 for MS-DOS 3.0-3.1
  22.                                 ; 24 for MS-DOS 3.2-3.3
  23.  
  24. cr      equ     0dh             ; ASCII carriage return
  25. lf      equ     0ah             ; ASCII linefeed
  26. eom     equ     '$'             ; end-of-message signal
  27.  
  28.  
  29. Header:                         ; device driver header
  30.         dd      -1              ; link to next device driver
  31.         dw      c840h           ; device attribute word
  32.         dw      Strat           ; "Strategy" routine entry point
  33.         dw      Intr            ; "Interrupt" routine entry point
  34.         db      'TEMPLATE'      ; logical device name
  35.  
  36.  
  37. RHPtr   dd      ?               ; pointer to request header, passed
  38.                                 ; by MS-DOS kernel to Strategy routine
  39.  
  40.  
  41. Dispatch:                       ; Interrupt routine command code
  42.                                 ; dispatch table
  43.         dw      Init            ; 0  = initialize driver
  44.         dw      MediaChk        ; 1  = media check on block device
  45.         dw      BuildBPB        ; 2  = build BIOS parameter block
  46.         dw      IoctlRd         ; 3  = I/O control read
  47.         dw      Read            ; 4  = read (input) from device
  48.         dw      NdRead          ; 5  = nondestructive read
  49.         dw      InpStat         ; 6  = return current input status
  50.         dw      InpFlush        ; 7  = flush device input buffers
  51.         dw      Write           ; 8  = write (output) to device
  52.         dw      WriteVfy        ; 9  = write with verify
  53.         dw      OutStat         ; 10 = return current output status
  54.         dw      OutFlush        ; 11 = flush output buffers
  55.         dw      IoctlWt         ; 12 = I/O control write
  56.         dw      DevOpen         ; 13 = device open       (MS-DOS 3.0+)
  57.         dw      DevClose        ; 14 = device close      (MS-DOS 3.0+)
  58.         dw      RemMedia        ; 15 = removable media   (MS-DOS 3.0+)
  59.         dw      OutBusy         ; 16 = output until busy (MS-DOS 3.0+)
  60.         dw      Error           ; 17 = not used
  61.         dw      Error           ; 18 = not used
  62.         dw      GenIOCTL        ; 19 = generic IOCTL     (MS-DOS 3.2+)
  63.         dw      Error           ; 20 = not used
  64.         dw      Error           ; 21 = not used
  65.         dw      Error           ; 22 = not used
  66.         dw      GetLogDev       ; 23 = get logical device (MS-DOS 3.2+)
  67.         dw      SetLogDev       ; 24 = set logical device (MS-DOS 3.2+)
  68.  
  69.  
  70. Strat   proc    far             ; device driver Strategy routine,
  71.                                 ; called by MS-DOS kernel with
  72.                                 ; ES:BX = address of request header
  73.  
  74.                                 ; save pointer to request header
  75.         mov     word ptr cs:[RHPtr],bx
  76.         mov     word ptr cs:[RHPtr+2],es
  77.  
  78.         ret                     ; back to MS-DOS kernel
  79.  
  80. Strat   endp
  81.  
  82.  
  83. Intr    proc    far             ; device driver Interrupt routine,
  84.                                 ; called by MS-DOS kernel immediately
  85.                                 ; after call to Strategy routine
  86.  
  87.         push    ax              ; save general registers
  88.         push    bx
  89.         push    cx
  90.         push    dx
  91.         push    ds
  92.         push    es
  93.         push    di
  94.         push    si
  95.         push    bp
  96.  
  97.         push    cs              ; make local data addressable
  98.         pop     ds              ; by setting DS = CS
  99.  
  100.         les     di,[RHPtr]      ; let ES:DI = request header
  101.  
  102.                                 ; get BX = command code
  103.         mov     bl,es:[di+2]
  104.         xor     bh,bh
  105.         cmp     bx,MaxCmd       ; make sure it's valid
  106.         jle     Intr1           ; jump, function code is ok
  107.         call    Error           ; set error bit, "Unknown Command" code
  108.         jmp     Intr2
  109.  
  110. Intr1:  shl     bx,1            ; form index to dispatch table
  111.                                 ; and branch to command-code routine
  112.         call    word ptr [bx+Dispatch]
  113.  
  114.         les     di,[RHPtr]      ; ES:DI = address of request header
  115.  
  116. Intr2:  or      ax,0100h        ; merge Done bit into status and
  117.         mov     es:[di+3],ax    ; store status into request header
  118.  
  119.         pop     bp              ; restore general registers
  120.         pop     si
  121.         pop     di
  122.         pop     es
  123.         pop     ds
  124.         pop     dx
  125.         pop     cx
  126.         pop     bx
  127.         pop     ax
  128.         ret                     ; return to MS-DOS kernel
  129.  
  130.  
  131. ; Command-code routines are called by the Interrupt routine
  132. ; via the dispatch table with ES:DI pointing to the request
  133. ; header. Each routine should return AX = 00H if function was
  134. ; completed successfully or AX = 8000H + error code if
  135. ; function failed.
  136.  
  137.  
  138. MediaChk proc   near            ; function 1 = Media Check
  139.  
  140.         xor     ax,ax
  141.         ret
  142.  
  143. MediaChk endp
  144.  
  145.  
  146. BuildBPB proc   near            ; function 2 = Build BPB
  147.  
  148.         xor     ax,ax
  149.         ret
  150.  
  151. BuildBPB endp
  152.  
  153.  
  154. IoctlRd proc    near            ; function 3 = I/O Control Read
  155.  
  156.         xor     ax,ax
  157.         ret
  158.  
  159. IoctlRd endp
  160.  
  161.  
  162. Read    proc    near            ; function 4 = Read (Input)
  163.  
  164.         xor     ax,ax
  165.         ret
  166.  
  167. Read    endp
  168.  
  169.  
  170. NdRead  proc    near            ; function 5 = Nondestructive Read
  171.  
  172.         xor     ax,ax
  173.         ret
  174.  
  175. NdRead  endp
  176.  
  177.  
  178. InpStat proc    near            ; function 6 = Input Status
  179.  
  180.         xor     ax,ax
  181.         ret
  182.  
  183. InpStat endp
  184.  
  185.  
  186. InpFlush proc   near            ; function 7 = Flush Input Buffers
  187.  
  188.         xor     ax,ax
  189.         ret
  190.  
  191. InpFlush endp
  192.  
  193.  
  194. Write   proc    near            ; function 8 = Write (Output)
  195.  
  196.         xor     ax,ax
  197.         ret
  198.  
  199. Write   endp
  200.  
  201.  
  202. WriteVfy proc   near            ; function 9 = Write with Verify
  203.  
  204.         xor     ax,ax
  205.         ret
  206.  
  207. WriteVfy endp
  208.  
  209.  
  210. OutStat proc    near            ; function 10 = Output Status
  211.  
  212.         xor     ax,ax
  213.         ret
  214.  
  215. OutStat endp
  216.  
  217.  
  218. OutFlush proc   near            ; function 11 = Flush Output Buffers
  219.  
  220.         xor     ax,ax
  221.         ret
  222.  
  223. OutFlush endp
  224.  
  225.  
  226. IoctlWt proc    near            ; function 12 = I/O Control Write
  227.  
  228.         xor     ax,ax
  229.         ret
  230.  
  231. IoctlWt endp
  232.  
  233.  
  234. DevOpen proc    near            ; function 13 = Device Open
  235.  
  236.         xor     ax,ax
  237.         ret
  238.  
  239. DevOpen endp
  240.  
  241.  
  242. DevClose proc   near            ; function 14 = Device Close
  243.  
  244.         xor     ax,ax
  245.         ret
  246.  
  247. DevClose endp
  248.  
  249.  
  250. RemMedia proc   near            ; function 15 = Removable Media
  251.  
  252.         xor     ax,ax
  253.         ret
  254.  
  255. RemMedia endp
  256.  
  257.  
  258. OutBusy proc    near            ; function 16 = Output Until Busy
  259.  
  260.         xor     ax,ax
  261.         ret
  262.  
  263. OutBusy endp
  264.  
  265.  
  266. GenIOCTL proc   near            ; function 19 = Generic IOCTL
  267.  
  268.         xor     ax,ax
  269.         ret
  270.  
  271. GenIOCTL endp
  272.  
  273.  
  274. GetLogDev proc  near            ; function 23 = Get Logical Device
  275.  
  276.         xor     ax,ax
  277.         ret
  278.  
  279. GetLogDev endp
  280.  
  281.  
  282. SetLogDev proc  near            ; function 24 = Set Logical Device
  283.  
  284.         xor     ax,ax
  285.         ret
  286.  
  287. SetLogDev endp
  288.  
  289.  
  290. Error   proc    near            ; bad command code in request header
  291.  
  292.         mov     ax,8003h        ; error bit + "Unknown Command" code
  293.         ret
  294.  
  295. Error   endp
  296.  
  297.  
  298. Init    proc    near            ; function 0 = initialize driver
  299.  
  300.         push    es              ; save address of request header
  301.         push    di
  302.  
  303.         mov     ah,9            ; display driver sign-on message
  304.         mov     dx,offset Ident
  305.         int     21h
  306.  
  307.         pop     di              ; restore request header address
  308.         pop     es
  309.  
  310.                                 ; set address of free memory 
  311.                                 ; above driver (break address)
  312.         mov     word ptr es:[di+14],offset Init
  313.         mov     word ptr es:[di+16],cs
  314.  
  315.         xor     ax,ax           ; return status
  316.         ret
  317.  
  318. Init    endp
  319.  
  320. Ident   db      cr,lf,lf
  321.         db      'TEMPLATE Example Device Driver'
  322.         db      cr,lf,eom
  323.  
  324. Intr    endp
  325.  
  326. _TEXT   ends
  327.  
  328.         end
  329.