home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / PCACHSRC.ZIP / DRIVER2.ASM < prev    next >
Assembly Source File  |  1990-07-12  |  12KB  |  417 lines

  1.  
  2.     ;DRIVER2.SYS           B.Kauler,89
  3.     ;simple device driver
  4.     ;.....
  5.     code_seg  segment para    public  'code'
  6.     main_proc proc    far
  7.       assume  cs:code_seg,es:code_seg,ds:code_seg
  8.       org 0   ;required for device drivers.
  9.     begin:
  10.     ;...........................................
  11.     ;this area is the DEVICE HEADER....
  12.     next_dev   dd -1      ;no other device drivers
  13.     attribute  dw 8000h   ;character device.
  14.     strategy   dw dev_str ;addr of 1st DOS call.
  15.     interrupt  dw dev_int ;addr of 2nd DOS call.
  16.     dev_name   db "PRN     " ;name of the driver.
  17.     ;...........................................
  18.     ;this is the LOCAL WORKSPACE AREA....
  19.     rh_off   dw ?  ;Request Header offset.
  20.     rh_seg   dw ?  ;Request Header segment.
  21.     messages db 07h
  22.              db "Simple character device driver"
  23.              db 0Dh,0Ah,07h,"$"
  24.     ;...........................................
  25.     ;this is the STRATEGY procedure area...
  26.     dev_str:
  27.         push   ds         ;save DS.
  28.         push   cs         ;to avoid segment
  29.         pop    ds         ;         override.
  30.         mov    rh_seg,es  ;save Req.Header seg.
  31.         mov    rh_off,bx  ;save Req.Head offset.
  32.         pop    ds         ;restore DS.
  33.         ret
  34.     ;..........................................
  35.     ;this is the INTERRUPT procedure.....
  36.     dev_int:
  37.         push    ds      ;save registers.
  38.         push    es      ;       /
  39.         push    ax      ;       /
  40.         push    bx      ;       /
  41.         push    cx      ;       /
  42.         push    dx      ;       /
  43.         push    di      ;       /
  44.         push    si      ;       /
  45.         push   cs       ;to avoid segment
  46.         pop    ds       ;    override.
  47.     ;.......................
  48.     ;I would like to dump the Req.Hdr
  49.     ;to the printer....
  50.         call dump
  51.     ;.......................
  52.     ;I will not assume that the second call to the
  53.     ;driver will still have the addr. of the Req.
  54.     ;Hdr. in ES:BX. Load it from workspace...
  55.         mov     es,rh_seg
  56.         mov     bx,rh_off
  57.     ;.......................
  58.     ;perform branch based on the command passed in
  59.     ;the Request Header...
  60.         mov     al,es:[bx+2] ;get command code.
  61.         cmp     al,0         ;check for zero.
  62.         je      initialise
  63.         cmp     al,8         ;check for o/p
  64.         jne     nogo
  65.         jmp      data_out
  66.     nogo: cmp   al,10   ;check o/p status.
  67.         je      out_status
  68.     ;just return the DONE-bit set in status
  69.     ;byte of Req.Hdr, for these commands....
  70.         cmp al,1
  71.         je  done
  72.         cmp al,2
  73.         je  done
  74.         cmp al,4
  75.         je  done
  76.         cmp al,5
  77.         je  done
  78.         cmp al,6
  79.         je  done
  80.         cmp al,7
  81.         je  done
  82.         cmp al,11
  83.         je  done
  84.         cmp al,13
  85.         je  done
  86.         cmp al,14
  87.         je  done
  88.     ;for any other command,return error...
  89.         jmp     errors
  90.     done:
  91.       mov es:word ptr [bx+3],0100h ;return status.
  92.       jmp finish
  93.     ;......................................
  94.     out_status:
  95.     ;DOS functions that access the printer
  96.     ;most likely check the output status, so I
  97.     ;had better respond to this command....
  98.     ;Bit-9 in the status-word of the Req.Hdr
  99.     ;=0 if not busy. Bit-8 =1 job done....
  100.      mov es:word ptr [bx+3],0100h
  101.      jmp finish
  102.     ;...............
  103.     initialise:
  104.     ;perform required initialisation action...
  105.         mov     dx,offset messages ;message
  106.         mov     ah,9               ;to screen.
  107.         int     21h                ;/
  108.     ;............
  109.       mov es:word ptr [bx+3],0100h ;return status.
  110.     ;............
  111.     ;it seems that DOS will also require to know
  112.     ;where the driver ends....
  113.         mov     ax,offset the_end ;end prog.
  114.         mov es:[bx+14],ax ;break-addr for DOS.
  115.         mov es:[bx+16],cs ;     /
  116.     ;.......................
  117.     ;I would like to display some info about
  118.     ;where this driver starts and ends in
  119.     ;memory...
  120.         push cs
  121.         pop  dx
  122.         mov  di,offset msga
  123.         call hex2asc
  124.         mov  ah,9
  125.         mov  dx,offset msgb
  126.         int  21h
  127.         jmp  goon1
  128.     msgb db "driver loaded at segment "
  129.     msga db "0000h",0Dh,0Ah,"$"
  130.     goon1: mov  dx,offset begin
  131.         mov  di,offset msgc
  132.         call hex2asc
  133.         mov  ah,9
  134.         mov  dx,offset msgd
  135.         int 21h
  136.         jmp goon2
  137.     msgd db "and starting offset :"
  138.     msgc db "0000h",0Dh,0Ah,"$"
  139.     goon2: mov  dx,offset the_end
  140.         mov  di,offset msge
  141.         call hex2asc
  142.         mov  ah,9
  143.         mov  dx,offset msgf
  144.         int 21h
  145.         jmp goon3
  146.     msgf db "and ending offset :"
  147.     msge db "0000h",0Dh,0Ah,"$"
  148.     goon3:
  149.     ;.......................
  150.     ;also I would like to dump the Req.Hdr
  151.     ;to the printer....
  152.         call dump
  153.     ;...................
  154.         jmp finish
  155.     ;.................................
  156.     data_out:
  157.     ;Processing the OUTPUT command...
  158.     ;note that an offset of 13dec from the
  159.     ;beginning of the Req Hdr is the start of
  160.     ;the dynamic portion.
  161.     ;first get the byte count....
  162.       mov cx,es:[bx+18]
  163.     ;now get the data address....
  164.       mov di,es:[bx+14]
  165.       mov ax,es:[bx+16]
  166.       mov es,ax
  167.     ;now transfer the data....
  168.       push bx           ;save BX.
  169.       push es           ;save ES.
  170.       mov bx,0
  171.     next_char:
  172.       mov al,es:[di]
  173.       inc di
  174.       mov ah,0Eh        ;display char.
  175.       int 10h           ;       /
  176.       loop next_char
  177.       pop es            ;restore ES.
  178.       pop bx            ;restore BX.
  179.  
  180.       mov es:word ptr [bx+3],0100h ;return status.
  181.  
  182.       jmp finish
  183.     ;..................................
  184.     errors:
  185.       ;put an "E" onto screen....
  186.       push bx
  187.       mov bx,0
  188.       mov ax,0E45h
  189.       int 10h
  190.       pop bx
  191.       mov es:word ptr [bx+3],8103h ;return status
  192.     ;......................................
  193.     finish:
  194.         pop si           ;restore all reg's.
  195.         pop di
  196.         pop dx
  197.         pop cx
  198.         pop bx
  199.         pop ax
  200.         pop es
  201.         pop ds
  202.         ret
  203.     ;......................................
  204.     hex2asc proc near
  205.     ;hex to ascii conversion, for display...
  206.     ;requires DX=binary number,DI=addr.ASCII
  207.     ;string. Returns nothing.
  208.         push cx
  209.         push ax
  210.         mov cx,4
  211.     h1: push cx
  212.         mov  cl,4
  213.         rol  dx,cl
  214.         mov  al,dl
  215.         and  al,0Fh
  216.         cmp  al,0Ah
  217.         jge  h2
  218.         add  al,30h
  219.         jmp  h3
  220.     h2: add  al,37h
  221.     h3: mov  cs:[di],al
  222.         inc  di
  223.         pop  cx
  224.         loop h1
  225.         pop  ax
  226.         pop  cx
  227.         ret
  228.     hex2asc  endp
  229.     ;......................................
  230.     dump proc near
  231.     ;a problem I have had with debugging
  232.     ;these drivers is knowing what DOS has
  233.     ;sent to the driver via the Req. Hdr.
  234.     ;This routine will (hopefully) print out
  235.     ;the contents of the Req.Hdr.
  236.     ;Make sure the printer is turned on and
  237.     ;paper inserted.
  238.         mov  ax,cs:rh_seg
  239.         mov  es,ax
  240.         mov  bx,cs:rh_off
  241.         mov  al,es:[bx+2]  ;get command
  242.         mov  ah,0
  243.         rol  al,1
  244.         mov  di,offset cmtab
  245.         add  di,ax
  246.         mov  ax,[di]
  247.         call prtmsg
  248.         ;display the req.Hdr....
  249.         mov  dl,es:[bx]
  250.         mov  dh,0
  251.         mov  di,offset crh1
  252.         call hex2asc
  253.         mov  dl,es:[bx+1]
  254.         mov dh,0
  255.         mov  di,offset crh2
  256.         call hex2asc
  257.         mov  dl,es:[bx+2]
  258.         mov  dh,0
  259.         mov  di,offset crh3
  260.         call hex2asc
  261.         mov  dx,es:word ptr [bx+3]
  262.         mov  di,offset crh4
  263.         call hex2asc
  264.         mov  ax,offset crh
  265.         call prtmsg
  266.         ;display req hdr unique to each
  267.         ;command...
  268.         mov  al,es:[bx+2]
  269.         cmp  al,0
  270.         jne  d1
  271.     d1: cmp  al,1
  272.         jne  d2
  273.         mov  dl,es:[bx+14]
  274.         mov  dh,0
  275.         mov  di,offset cp1a
  276.         call hex2asc
  277.         mov  ax,offset cp1
  278.         call prtmsg
  279.         jmp  dexit
  280.     d2: cmp  al,2
  281.         jne  d3
  282.     d3: cmp  al,3
  283.         jne  d4
  284.     d4: cmp  al,4
  285.         jne  d5
  286.         mov  dx,es:word ptr [bx+18]
  287.         mov  di,offset cp4a
  288.         call hex2asc
  289.         mov  dx,es:word ptr [bx+20]
  290.         mov  di,offset cp4b
  291.         call hex2asc
  292.         mov  ax,offset cp4
  293.         call prtmsg
  294.         jmp  dexit
  295.     d5: cmp  al,5
  296.         jne  d6
  297.     d6: cmp  al,6
  298.         jne  d7
  299.     d7: cmp  al,7
  300.         jne  d8
  301.     d8: cmp  al,8
  302.         jne  d9
  303.         mov  dx,es:word ptr [bx+18]
  304.         mov  di,offset cp4a
  305.         call hex2asc
  306.         mov  dx,es:word ptr [bx+20]
  307.         mov  di,offset cp4b
  308.         call hex2asc
  309.         mov  ax,offset cp4
  310.         call prtmsg
  311.         jmp  dexit
  312.     d9: cmp  al,9
  313.         jne  da
  314.         mov  dx,es:word ptr [bx+18]
  315.         mov  di,offset cp4a
  316.         call hex2asc
  317.         mov  dx,es:word ptr [bx+20]
  318.         mov  di,offset cp4b
  319.         call hex2asc
  320.         mov  ax,offset cp4
  321.         call prtmsg
  322.         jmp  dexit
  323.     da: cmp  al,0Ah
  324.         jne  dbb
  325.     dbb: cmp al,0Bh
  326.         jne  dc
  327.     dc: cmp  al,0Ch
  328.         jne  ddd
  329.     ddd: cmp al,0Dh
  330.         jne  de
  331.     de: cmp  al,0Eh
  332.         jne  dff
  333.     dff: cmp  al,0Fh
  334.         jne  d10
  335.     d10: cmp al,10h
  336.         jne  dexit
  337.     dexit: ret
  338.     dump   endp
  339.     ;.....
  340.     crh db " len "
  341.     crh1  db "0000",0Dh,0Ah
  342.           db " unit "
  343.     crh2  db "0000",0dh,0ah
  344.           db " cmd "
  345.     crh3  db "0000",0dh,0ah
  346.           db " status "
  347.     crh4  db "0000",0dh,0ah,"$"
  348.     cp1   db " media status "
  349.     cp1a  db "0000",0dh,0ah,"$"
  350.     cp4   db " count "
  351.     cp4a  db "0000",0dh,0ah
  352.           db " start "
  353.     cp4b  db "0000",0dh,0ah,"$"
  354.     cm0   db "initialisation",0dh,0ah,"$"
  355.     cm1   db "media_check   ",0dh,0ah,"$"
  356.     cm2   db "get_bpb       ",0dh,0ah,"$"
  357.     cm3   db "ioctl_in      ",0dh,0ah,"$"
  358.     cm4   db "input         ",0dh,0ah,"$"
  359.     cm5   db "nd_input      ",0dh,0ah,"$"
  360.     cm6   db "input_status  ",0dh,0ah,"$"
  361.     cm7   db "input_flush   ",0dh,0ah,"$"
  362.     cm8   db "output        ",0dh,0ah,"$"
  363.     cm9   db "output_verify ",0dh,0ah,"$"
  364.     cma   db "output_status ",0dh,0ah,"$"
  365.     cmb   db "output_flush  ",0dh,0ah,"$"
  366.     cmcc  db "ioctl_out     ",0dh,0ah,"$"
  367.     cmd   db "open          ",0dh,0ah,"$"
  368.     cme   db "close         ",0dh,0ah,"$"
  369.     cmf   db "removable     ",0dh,0ah,"$"
  370.     cm10  db "output_busy   ",0dh,0ah,"$"
  371.     cmtab label word
  372.           dw cm0
  373.           dw cm1
  374.           dw cm2
  375.           dw cm3
  376.           dw cm4
  377.           dw cm5
  378.           dw cm6
  379.           dw cm7
  380.           dw cm8
  381.           dw cm9
  382.           dw cma
  383.           dw cmb
  384.           dw cmcc
  385.           dw cmd
  386.           dw cme
  387.           dw cmf
  388.           dw cm10
  389.     ;...............
  390.     prtmsg proc near
  391.     ;requires AX=address of string to be
  392.     ;printed. Returns nothing.
  393.         push dx
  394.         push si
  395.         mov  dx,0
  396.         mov  si,ax
  397.     prt1: mov ah,0
  398.         mov  al,[si]
  399.         cmp  al,"$"
  400.         je   prt2
  401.         int  17h
  402.         inc  si
  403.         jmp  prt1
  404.     prt2: pop si
  405.         pop  dx
  406.         ret
  407.     prtmsg endp
  408.     ;....................................
  409.     the_end:
  410.     ;..........................................
  411.     main_proc    endp
  412.     code_seg     ends
  413.                  end    begin
  414.     ;*****end of device driver******
  415.     ;..........................................
  416.  
  417.