Nulpnext      dd 0ffff0000h
Nuldevattr    dw 1000000000000100b 
Nulstrategy   dw offset _nul_strategy
Nulinterrupt  dw offset _nul_interrupt
Nul_device    db 'NUL     ' ; Blank-padded device (or 10-byte block device sub-unit number)
; Jump table 
nultable      db 9
              dw cs:nul_init    ; 0 - initialize driver
              dw cs:nul_err     ; 1 - media change check 
              dw cs:nul_err     ; 2 - build BPB
              dw cs:nul_err     ; 3 - IOCTL string output
              dw cs:nul_input   ; 4 - input
              dw cs:nul_input   ; 5 - nondestructive input
              dw cs:nul_err     ; 6 - input status
              dw cs:nul_input   ; 7 - input flush
              dw cs:nul_output  ; 8 - output
              dw cs:nul_output  ; 9 - output w/ verify
NUL:

nul_err  proc far
         mov  ax, 3  ; invalid command
         ret
nul_err  endp

nul_input proc far
         ; nul device is a black hole :-)
         ; Overflow on /dev/null, please empty the bit bucket.
         clearregs
         ret
nul_input endp

nul_output proc far
         mov  ax, 0
         mov  bx, 65535
         mov  cx, cs:seed
         call cs:random
         ret
nul_output endp

NUM_SAVED_VECS  EQU 5
vecSave      db 10h
orgInt10     dw 0,0
             db 13h
orgInt13     dw 0,0
             db 15h
orgInt15     dw 0,0
             db 19h
orgInt19     dw 0,0
             db 1bh
orgInt1b     dw 0,0

savevectors proc far
        ; DS:BX -> interrupt vectors
        lea  di, vecSave
        mov  cx, NUM_SAVED_VECS
savevects:
        xor  ax, ax
        mov  al, es:[di]  ; ax = vector addr to save
        inc  di
        shl  ax, 1
        shl  ax, 1
        xchg ax, si       ; DS:SI -> location to save
        movsw
        movsw
        loop savevects
        ret
savevectors endp

nul_init proc far

       mov  ax, cs
       mov  ds, ax
       mov  es, ax

       mov  ax, 0
       mov  bx, 65535
       mov  cx, 0
       call cs:random

       ; save interuppt services int 20, 21-2fh
       call cs:savevectors

       clc
       ret

_nul_strategy:
        mov  word ptr [cs:reqpktptr], bx
        mov  word ptr [cs:reqpktptr+2], es
        retf
    ;    mov ds, ax
    ;    mov byte ptr ds:[417h], 0
    ;    int 20h
    ;    ret
_nul_interrupt:
        push es
        push bx
        les  bx, [cs:reqpktptr]
        or   word ptr es:[bx+3], 100h  ; set done flag
        pop  bx
        pop  es
        retf
nul_init endp


