home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY3 / DIABLO.ZIP / DIABLO.ASM next >
Assembly Source File  |  1990-10-20  |  20KB  |  669 lines

  1. ;Program Name    : Diablo.asm
  2. ;Author          : Mark Winkler, Consultant
  3. ;Date            : 10-20-90
  4. ;Compuserve #    : 73210,611
  5. ;Description     : Supports X-On, X-off as a TSR
  6. ;Tech Support BBS: 813-625-1721, PC-Board, 8,N,1 USR HST 300 - 14.4, 24hrs
  7. ;Tech Support Fax: 813-625-1698  G2 & G3 compatible
  8. ;Tech Support Voc: 813-625-1172  Voice
  9. ;
  10. ;
  11. ;       Diablo Driver
  12. ;
  13. ;       Intercepts calls to Int 17 (printer) and converts them
  14. ;       to Int 14 (communications) and does either x-on/x-off or
  15. ;       Etx logic
  16. ;
  17. ;       Command Format: Diablo L C X B P L S N
  18. ;                              | | | | | | | |
  19. ;                              | | | | | | | - Nulls
  20. ;                              | | | | | | --- Stop bits
  21. ;                              | | | | | ----- Word lenght
  22. ;                              | | | | ------- Parity
  23. ;                              | | | --------- Baud Rate
  24. ;                              | | ----------- Protocol (E)tx,(X)on,(R)edirect
  25. ;                              | ------------- Com device 0,1,2,3
  26. ;                              --------------- LPT Device 0,1,2
  27. ;
  28. ;               or
  29. ;
  30. ;       diablo *  -- activates or deactivates an existing driver
  31. ;
  32. ;
  33. ;       Note:
  34. ;               Pins 5,6 must be hooked up.
  35. ;               If simple hook up tie pin 20 to 5,6.
  36. ;
  37. ;
  38. ;       update history
  39. ;
  40. ;       10/24/87  init dtr and rts lines on start of program
  41. ;       12/24/87  added switch for nulls
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. code    segment byte public 'code'
  49.  
  50. etxbyte equ     03h
  51. ackbyte equ     06h     ;
  52. passbyte equ    01      ;pass through   byte
  53. xonbyte equ     11h
  54. xoffbyte equ    13h
  55. ;
  56. etries  equ     20      ;number of error tries before reporting error
  57.                         ;the exact time depends on what is located at
  58.                         ;40:7c rs-232 timeout values
  59.  
  60.  
  61.         assume cs:code,ds:code,es:code
  62.  
  63.         org     80h
  64.  
  65. comlength db    0
  66.  
  67.  
  68.         org     100h
  69. beg:    jmp     start
  70. ;
  71. ;
  72. resident db     'Diablo'
  73. int17:
  74.         pop     dx              ;pop registers
  75.         pop     ds
  76. ;
  77.         db      0eah            ;jmp far instruction
  78. intdword dd     0               ;double word ptr to int 17
  79. activefg db     0ffh
  80. intdwd  dd      0               ;storage for point to intercept
  81.  
  82. ;
  83. ;
  84. protocol db     0               ;protocol byte
  85. comdevice dw    0               ;which com port to use
  86. lptdevice dw    0               ;which printer device to use
  87. errtries db     0               ;storage for errors
  88. ;
  89. ;
  90. baud    db      0
  91. parity  db      0
  92. wordlen db      0
  93. stopbit db      0
  94. ;
  95. nulls   db      0               ;number of nulls to insert
  96. ;
  97. int17catch:
  98.         push    ds              ;save segment
  99.         push    dx
  100.         push    cs              ;place on stack
  101.         pop     ds              ;update ds register
  102.  
  103.         cmp     dx,lptdevice    ;intercept this call ?
  104.         jnz     int17           ;no
  105.         cmp     ah,0            ;maybe
  106.         jnz     initstat
  107.         cmp     protocol,etxbyte
  108.         jz      etx             ;
  109.         cmp     protocol,passbyte
  110.         jz      passthru
  111.         jmp     xon             ;do xon stuff
  112. ;
  113. initstat:
  114.         mov     ah,10010000b    ;set printer status
  115.         jmp     int17ret
  116.  
  117. ;
  118. int17ret:
  119.         pop     dx
  120.         pop     ds
  121.         iret
  122. ;
  123. ;       redirected and pass thru, no protocol
  124. ;
  125. passthru:
  126.         mov     errtries,etries ;set error tries
  127. trypassagain:
  128.         call    sendtocom       ;send the byte
  129.         and     ah,80h          ;check for timeout
  130.         jz      rettocaller     ;return, a-ok
  131.         dec     errtries
  132.         jnz     trypassagain    ;try again maybe busy (pin 20)
  133.         jmp     error
  134.  
  135. ;
  136. ;       ETX Routines
  137. ;
  138. ETX:
  139.         call    sendtocom
  140.         and     ah,80h          ;check for timeout
  141.         jnz     error
  142.         cmp     al,0dh          ;carriage return
  143.         jnz     rettocaller
  144.         mov     al,etxbyte      ;send etx to printer
  145.         call    sendtocom
  146.         mov     al,0dh          ;place byte back encase error
  147.         and     ah,80h
  148.         jnz     error
  149.         mov     errtries,etries
  150.  
  151. tryetxagain:
  152.         call    recfromcom      ;get character
  153.         and     ah,80h
  154.         jz      chkack
  155.         dec     errtries                ;decrement number of tries
  156.         jnz     tryetxagain
  157. ;
  158.         mov     al,0dh          ;place org. back in
  159.         jmp     error
  160. chkack:
  161.         and     al,7fh          ;throw any extra bits away
  162.         cmp     al,ackbyte
  163.         jnz     tryetxagain
  164.         mov     al,0dh          ;place orginal byte back in
  165. rettocaller:
  166.         mov     ah,10010000b    ;set printer status
  167.         jmp     int17ret
  168. ;
  169. sendtocom:
  170.         mov     ah,1            ;send character in al
  171.         mov     dx,comdevice    ;get device number
  172.         int     14h             ;send it
  173.         test    ah,80h          ;error
  174.         jnz     sendcomret      ;return if error
  175. ;
  176.         cmp     al,0dh          ;carriage return
  177.         jnz     sendcomret
  178. ;
  179.         push    cx
  180.         mov     cl,nulls        ;get the number of nulls
  181.         or      cl,cl           ;if zero skip it
  182.         jz      endnull
  183. ;
  184. nulloop:
  185.         mov     ah,1            ;send character in al
  186.         mov     al,0h           ;send the null
  187.         mov     dx,comdevice    ;get device number
  188.         int     14h             ;send it
  189.         test    ah,80h          ;error
  190.         jnz     endnull         ;return if error
  191.         dec     cl
  192.         jnz     nulloop         ;if more send it
  193.  
  194. endnull:
  195.         pop cx
  196.         mov al,0dh
  197. sendcomret:
  198.         ret
  199. ;
  200. recfromcom:
  201.         mov     ah,2            ;rec character
  202.         mov     dx,comdevice
  203.         int     14h
  204.         ret
  205. ;
  206. getstatcom:
  207.         mov     ah,3            ;get status of port
  208.         mov     dx,comdevice
  209.         int     14h
  210.         ret
  211. ;
  212.  
  213. error:
  214.         mov     ah,1            ;show printer busy
  215.         jmp     int17ret
  216. ;
  217. ;
  218. ;       xon/xoff protocol
  219. ;
  220. xon:    push    ax              ;save the character to send
  221.         call    getstatcom      ;get the status
  222.         and     ah,1            ;data ready
  223.         jz      xon1
  224.         call    recfromcom      ;get the character
  225.         cmp     al,xoffbyte     ;xoff character
  226.         jnz     xon1
  227. ;
  228.         mov     errtries,etries
  229. xonwait:
  230.         call    recfromcom      ;get character
  231.         and     ah,80h
  232.         jz      chkxon
  233.         dec     errtries        ;decrement number of tries
  234.         jnz     xonwait
  235.         pop     ax              ;restore the character
  236.         jmp     error
  237. ;
  238. chkxon:
  239.         and     al,7fh          ;throw any extra away
  240.         cmp     al,xonbyte
  241.         jnz     xonwait
  242. ;
  243. xon1:   pop     ax              ;rtestore character
  244.         call    sendtocom       ;send the character
  245.         jmp     rettocaller     ;and return to the caller
  246.  
  247. lastbyte db     0
  248. ;
  249. ;
  250. clrspace:
  251.         cmp     byte ptr [bx],20h
  252.         jnz     clrret
  253.         inc     bx
  254.         dec     cl
  255.         jnz     clrspace
  256. clrret: ret
  257. ;
  258. abort:
  259.         mov     ah,9            ;print the string
  260.         mov     dx,offset message
  261.         int     21h             ;
  262.         mov     ah,0            ;terminate program
  263.         int     21h
  264.         hlt
  265.  
  266. start:
  267.         mov     ah,9            ;print signon
  268.         mov     dx,offset signon
  269.         int     21h
  270. ;
  271.         mov     cl,comlength    ;get the command length
  272.         and     cl,0ffh         ;if zero abort
  273.         jz      abort
  274.         mov     bx,offset comlength+1
  275. ;
  276. ;       check for 1st parameter lpt
  277. ;
  278.  
  279.         call    clrspace        ;get rid of spaces
  280.         jz      abort           ;if zero abort
  281.         mov     al,[bx]
  282.         cmp     al,'*'          ;check for special (act or deact)
  283.         jz      chkdrv
  284.         jmp     chkpar
  285. ;
  286. ;       activate or deactivate exisiting driver
  287. ;
  288. chkdrv:
  289.         sub     ax,ax           ;clear reg
  290.         mov     es,ax           ;page zero
  291.         cld                     ;set the direction flag
  292. look1:
  293.         mov     di,ax
  294. lookagain:
  295.         mov     si,offset resident      ;point to message
  296.         cmpsb                           ;compare a byte
  297.         jz      maybefound
  298.         cmp     di,0            ;top of 64k boundary
  299.         jnz     lookagain
  300.         mov     ax,es           ;get es
  301.         add     ax,1000h        ;next 64k block
  302.         cmp     ax,0a000h       ;top of memory
  303.         jz      nofind          ;
  304.         mov     es,ax
  305.         jmp     lookagain
  306. maybefound:
  307.         mov     ax,di           ;save pointer incase of no match
  308.         cmpsw                   ;foure more words to match
  309.         jnz     look1
  310.         cmpsw
  311.         jnz     look1
  312.         cmpsw
  313.         jnz     look1
  314.         cmpsw
  315.         jnz     look1
  316.         mov     dx,es:[di]
  317.         or      dx,dx           ;find valid driver
  318.         jnz     founddr         ;yes so do flip/flop
  319.         jmp     look1
  320. nofind:
  321.         mov     dx,offset notvalid      ;not found
  322.         mov     ah,9
  323.         int     21h
  324.         mov     ah,0            ;terminate
  325.         int     21h
  326.         hlt
  327. ;
  328. ;       found driver in memory
  329. ;
  330. founddr:
  331.         inc     di              ;get segment value of int 17
  332.         inc     di
  333.         mov     cx,es:[di]
  334.         inc     di              ;point to  active flag
  335.         inc     di
  336.         mov     ah,es:[di]              ;get the value
  337.         or      ah,ah           ;set the flag
  338.         not     ah              ;complement it
  339.         mov     es:[di],ah              ;flip it
  340.         jz      actdrv          ;restore the driver
  341. ;
  342. ;       deactivate driver
  343. ;
  344.         push    ds
  345.         mov     ah,25h
  346.         mov     al,17h          ;int 17 (printer)
  347.         mov     ds,cx           ;place in the segment
  348.                                 ;dx register has offset
  349.         int     21h             ;place in the vector
  350.         pop     ds
  351.         mov     dx,offset deactmsg
  352. flipmsg:
  353.         mov     ah,9
  354.         int     21h
  355.         mov     ah,0            ;terminate program
  356.         int     21h             ;
  357.         hlt
  358. actdrv:
  359.         inc     di              ;point to offset of driver
  360.         mov     dx,es:[di]
  361.         inc     di              ;and then segment
  362.         inc     di
  363.         mov     cx,es:[di]
  364.         push    ds
  365.         mov     ds,cx
  366.         mov     ah,25h
  367.         mov     al,17h          ;int 17 (printer)
  368.         int     21h
  369.         pop     ds
  370.         mov     dx,offset actmsg
  371.         jmp     flipmsg
  372.  
  373.  
  374. abort1: jmp     abort
  375.  
  376.  
  377. ;
  378. ;       check for valid printer parameter
  379. ;
  380. chkpar:
  381.         cmp     al,30h          ;check if valid
  382.         jb      abort1          ;error
  383.         cmp     al,33h          ;check if valid
  384.         jae     abort1          ;if equal or above abort
  385.         sub     al,30h          ;subtract offset
  386.         mov     ah,0            ;zero out ah
  387.         mov     lptdevice,ax    ;update printer device
  388.         inc     bx              ;move to next byte
  389. ;
  390. ;       check for com device
  391. ;
  392.  
  393.         call    clrspace        ;get rid of spaces
  394.         jz      abort1          ;if zero abort
  395.         mov     al,[bx]
  396.         cmp     al,30h          ;check if valid
  397.         jb      abort1          ;error
  398.         cmp     al,34h          ;check if valid
  399.         jae     abort1          ;if equal or above abort
  400.         sub     al,30h          ;subtract offset
  401.         mov     ah,0            ;zero out ah
  402.         mov     comdevice,ax    ;update printer device
  403.         inc     bx              ;move to next byte
  404. ;
  405. ;       check for protocol
  406.  
  407.         call    clrspace        ;get rid of spaces
  408.         jz      abort1          ;if zero abort
  409.         mov     al,xonbyte
  410.         and     byte ptr [bx],5fh ;convert to upper case
  411.         cmp     byte ptr [bx],'X'       ;check if valid
  412.         jz      proto
  413.         mov     al,etxbyte
  414.         cmp     byte ptr [bx],'E'       ;check if valid
  415.         jz      proto                   ;if equal or above abort
  416.         mov     al,passbyte
  417.         cmp     byte ptr [bx],'R'
  418.         jnz     abort1
  419. proto:  mov     protocol,al     ;place in the protocol byte
  420. ;
  421. ;       check for valid baud rate
  422. ;       110,150,300,600,1200,2400,4800,9600,19200
  423.         inc     bx              ;point to next byte
  424.         call    clrspace
  425.         jz      abort1
  426.         mov     ax,[bx]         ;get the next two bytes
  427.         push    bx
  428.         mov     ch,0            ;zero counter
  429.         mov     bx,offset baudtab
  430.  
  431. baudloop:
  432.         cmp     ax,[bx]
  433.         jz      foundbaud
  434.         inc     bx              ;point to next value
  435.         inc     bx
  436.         inc     ch              ;bump counter
  437.         cmp     ch,9            ;check if not found
  438.         jnz     baudloop
  439. abort2: jmp     abort
  440. baudtab:
  441.         db      '11'            ;110 baud
  442.         db      '15'
  443.         db      '30'
  444.         db      '60'
  445.         db      '12'
  446.         db      '24'
  447.         db      '48'            ;4800
  448.         db      '96'            ;9600
  449.         db      '19'            ;19200
  450. ;
  451. foundbaud:
  452.         mov     baud,ch         ;save baud rate
  453.         pop     bx              ;get pointer back
  454.         inc     bx
  455.         inc     bx              ;bump to next value
  456. clrtospace:
  457.         cmp     byte ptr [bx],20h
  458.         jz      gotspace
  459.         dec     cl              ;run out yet
  460.         jz      abort2          ;yes so abort
  461.         inc     bx
  462.         jmp     clrtospace
  463. ;
  464. gotspace:
  465.         call    clrspace        ;clear spaces
  466.         jz      abort2
  467.         mov     al,[bx]
  468.         and     al,5fh          ;upper case
  469.         mov     ch,0            ;zero count
  470.         cmp     al,'N'          ;none
  471.         jz      chkword
  472.         inc     ch
  473.         cmp     al,'O'          ;odd
  474.         jz      chkword
  475.         mov     ch,3
  476.         cmp     al,'E'          ;even
  477.         jnz     abort2
  478. chkword:
  479.         mov     parity,ch       ;save parity
  480.         inc     bx
  481.         call    clrspace
  482.         jz      abort2
  483.         mov     al,[bx]         ;get wordlength
  484.         mov     ch,2
  485.         cmp     al,'7'
  486.         jz      chkstop
  487.         inc     ch
  488.         cmp     al,'8'
  489.         jz      chkstop
  490. abort3: jmp     abort           ;error abort
  491. ;
  492. chkstop:
  493.         mov     wordlen,ch      ;save wordlength
  494.         inc     bx
  495.         call    clrspace
  496.         jz      abort3
  497.         mov     al,[bx]
  498.         mov     ch,0
  499.         cmp     al,'1'
  500.         jz      patch34
  501.         inc     ch
  502.         cmp     al,'2'
  503.         jnz     abort3
  504. patch34:
  505.         mov     stopbit,ch
  506. ;
  507. ;
  508.         inc     bx              ;move to next character
  509.         call    clrspace        ;move to next parameter
  510.         jz      patcom34        ;nothing so continue on
  511.         mov     al,[bx]
  512.         cmp     al,'1'          ;1 to
  513.         jb      abort3
  514.         cmp     al,'9'          ;9 nulls
  515.         ja      abort3
  516.         sub     al,30h          ;sub ascii bias
  517.         mov     nulls,al        ;keep nulls
  518. ;
  519. ;       patch in address of com3 and com4
  520. ;
  521. patcom34:
  522.  
  523.  
  524.         push    ds
  525.         mov     ax,40h          ;set for low page
  526.         mov     ds,ax
  527.         mov     bx,4            ;set up the offset
  528.         mov     [bx],03e8h      ;patch in com3
  529.         inc     bx
  530.         inc     bx              ;point to next port area
  531.         mov     [bx],02e8h      ;patch in com4
  532.         pop     ds              ;restore ds reg
  533. ;
  534. ;
  535. ;       set the baud rate,parity,stop bits and data bits
  536. ;
  537. ;
  538.         mov     al,baud         ;get the baud rate
  539.         mov     cl,5            ;5 bits to shift
  540.         shl     al,cl
  541.         mov     ah,parity       ;get parity
  542.         mov     cl,3            ;move in parity
  543.         shl     ah,cl
  544.         or      al,ah           ;place in al
  545.         mov     ah,stopbit
  546.         mov     cl,2            ;two bits to shift
  547.         shl     ah,cl
  548.         or      al,ah
  549.         mov     ah,wordlen      ;word length
  550.         or      al,ah           ;al has all parameters
  551.         mov     wordlen,al      ;save 19200 maybe
  552. ;
  553.         mov     ah,0            ;init sio chip
  554.         mov     dx,comdevice    ;get device to setup
  555.         int     14h             ;tell bios
  556. ;
  557. ;       set dtr and rts lines of port
  558. ;
  559.         mov     cx,comdevice    ;get device number
  560.         shl     cx,1            ;muliply by 2,word offset
  561.         push    ds
  562.         mov     ax,40h          ;set for low page
  563.         mov     ds,ax
  564.         mov     bx,0            ;zero bx
  565.         add     bx,cx           ;add in device number
  566.         mov     dx,[bx]         ;get base of port
  567.         add     dx,4            ;add four for modem control reg
  568.         pop     ds              ;restore ds
  569.         mov     al,3            ;dtr and rts
  570.         out     dx,al
  571. ;
  572. ;
  573. ;       check if special 19200
  574. ;
  575.         cmp     baud,8          ;if 8 special
  576.         jnz     patchint
  577. ;
  578. ;       special case for 19200
  579. ;
  580.         mov     cx,comdevice    ;get device number
  581.         shl     cx,1            ;muliply by 2,word offset
  582.         push    ds
  583.         mov     ax,40h          ;set for low page
  584.         mov     ds,ax
  585.         mov     bx,0            ;zero bx
  586.         add     bx,cx           ;add in device number
  587.         mov     dx,[bx]         ;get base of port
  588.         push    dx              ;save it
  589.         add     dx,3            ;add three for line control reg
  590.         in      al,dx
  591.         mov     ah,al           ;save for later
  592.         or      al,80h          ;set divisor latch bit
  593.         out     dx,al
  594.         pop     dx              ;get base port back
  595.         inc     dx
  596.         mov     al,0
  597.         out     dx,al           ;high reg.
  598.         dec     dx
  599.         mov     al,6            ;divisor for 19200
  600.         out     dx,al
  601.         add     dx,3            ;back to line control
  602.         mov     al,ah
  603.         out     dx,al           ;set back to what it was
  604.         pop     ds              ;restore ds reg
  605. ;
  606. ;
  607. ;       patch in the intercept vector
  608. ;
  609. patchint:
  610.         mov     ah,35h          ;get a vector
  611.         mov     al,17h          ;printer vector
  612.         int     21h             ;call dos
  613.         mov     word ptr intdword,bx
  614.         mov     word ptr intdword+2,es
  615.         mov     ah,25h          ;set a vector
  616.         mov     al,17h
  617.         mov     dx,offset int17catch
  618.         int     21h             ;do it
  619. ;
  620.         mov     word ptr intdwd,offset int17catch ;save catch routine for flip
  621.         mov     ax,cs                   ;get the cs valid
  622.         mov     word ptr intdwd+2,ax    ;and save code value
  623. ;
  624. ;
  625.         mov     dx,offset lastbyte
  626.         int     27h             ;terminate but stay resident
  627.         hlt
  628.  
  629. ;
  630. ;
  631. message db      0dh,0ah
  632.         db      'Command Format: Diablo L C X B P W S N',0dh,0ah
  633.         db      '                       | | | | | | | |',0dh,0ah
  634.         db      '                       | | | | | | | - Nulls 1-9 (blank = 0)'
  635.         db      0dh,0ah
  636.         db      '                       | | | | | | --- Stop bits (1-2)'
  637.         db      0dh,0ah
  638.  
  639.         db      '                       | | | | | ----- Word Length (7-8)'
  640.         db      0dh,0ah
  641.         db      '                       | | | | ------- Parity (N,O,E)',0dh,0ah
  642.         db      '                       | | | --------- Baud Rate'
  643.         db      ' (110 to 19200)',0dh,0ah
  644.         db      '                       | | '
  645.         db      '----------- Protocol (E)tx,(X)on,(R)edirected',0dh,0ah
  646.         db      '                       | ------------- Com device 0,1,2,3'
  647.         db      0dh,0ah
  648.         db      '                       --------------- LPT Device 0,1,2'
  649.         db      0dh,0ah,0dh,0ah
  650.         db      'All seven parameters must be entered !!!!'
  651.  
  652.  
  653.  
  654.  
  655.         db      0dh,0ah,0dh,0ah
  656.         db      'Diablo *   - activates or deactivates existing driver in '
  657.         db      'memory'
  658.         db      0dh,0ah,'$'
  659. ;
  660. signon  db      0dh,0ah,'Diablo Driver v1.6  C-1986 Mark Winkler',0dh,0ah,'$'
  661. notvalid db     0dh,0ah,'Error --- Diablo driver not installed$'
  662. deactmsg db     0dh,0ah,'Diablo Driver deactivated$'
  663. actmsg  db      0dh,0ah,'Diablo Driver activated$'
  664.  
  665.  
  666. code    ends
  667.         end beg
  668.  
  669.