home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / DISPATCH.AZM / DISPATCH.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  5.3 KB  |  174 lines

  1. ;----------------------------------------------------------------
  2. ;         This is a module in the ASMLIB library.
  3. ;
  4. ; Dispatch characters to one or both of COE LOE device drivers.
  5. ; This section works by using the dispatching byte that is loaded
  6. ; by the consout/listout/echolst routines. This allows some
  7. ; quite nice features and the table of addresses that is used allows
  8. ; the user to add drivers at will.
  9. ;
  10. ; This module also allows the user to select an external set of i/o
  11. ; drivers which are to be user for all further console I/O until any of
  12. ; consout/echolst/lstout the routines is called. This is called the USERIO 
  13. ; and it expects DE -> address table pointing to the console input, output
  14. ; and status routines respectively in that order. They must also
  15. ; preserve any registers.
  16. ;
  17. ;            Written         R.C.H.     16/08/83
  18. ;            Last Update    R.C.H.       11/02/84
  19. ;
  20. ; Added userio etc code for more re-direction             R.C.H.  21/9/83
  21. ; Aded flushloe code to flush line printer buffer         R.C.H.  17/10/83
  22. ; Shifted device drivers to external I/O module              R.C.H.  22/10/83
  23. ; Added X-on / X-off to dispatch                 R.C.H.  30/11/83
  24. ; Added ? to destbyte extrn name                 R.C.H.  31/12/83
  25. ; Added X-on / X-off equate                     R.C.H.  11/02/84
  26. ;----------------------------------------------------------------
  27. ;
  28.     name    'dispatch'
  29. ;
  30.     public    dispatch,userio,flushloe
  31.     extrn    coe,loe,cie,cst
  32.     extrn    ?destbyte
  33.     maclib    z80
  34. ;
  35. true    equ    0ffffh
  36. false    equ    not true
  37. ;
  38. xon    equ    false            ; if true then handshaking is done
  39. ;
  40. ; DESTBYTE is used to send characters to output devices. The current
  41. ; assignments are
  42. ; 00    Standard console output
  43. ; 01    Standard printer output
  44. ; 02    Printer and console (echolst) output.
  45. ; 03    User output via custom driver
  46. ; At present the output devices are not table driven since there are
  47. ; not enough of them. In the future then maybe.
  48. ;
  49. dispatch:
  50.     push    psw            ; Save the character
  51.     lda    ?destbyte        ; Get the destination device
  52.     ora    a
  53.     jrz    docoe
  54.     cpi    1
  55.     jrz    doloe
  56.     cpi    3
  57.     jrz    usr$conout        ; Send to users output routine
  58. ; Echo list output driver
  59.     pop    psw            ; Restore character
  60.     call    coe            ; Send to screen
  61.     jmp    loe            ; Send to printer
  62. ;
  63. docoe:    ; Do console output.
  64.     pop    psw            ; Restore
  65. ;
  66. ; If handshaking is required then we do X-on / X-off 'ing
  67.     if    xon
  68.     call    coe            ; Send the character
  69.     push    psw            ; Preserve the character
  70.     call    cst            ; X-off ??
  71.     jrz    docoe1
  72.     call    cie
  73.     cpi    19            ; control S ??
  74.     jrnz    docoe1
  75. docoe$wait:
  76.     call    cie
  77.     cpi    17            ; control Q ??
  78.     jrnz    docoe$wait
  79. ;
  80. docoe1:
  81.     pop    psw
  82.     ret                ; return to the user
  83. ; If no handshaking then just send the character and return
  84.     else
  85.     jmp    coe
  86.     endif
  87. ;
  88. doloe:
  89.     pop    psw
  90.     jmp    loe            ; Same as above.
  91. ;
  92. ;----------------------------------------------------------------
  93. ; This routine allows the user to patch a set of custom I/O driver
  94. ; routines for all console I/O. This allows the user to programatically
  95. ; alter program I/O.
  96. ; This is done by setting the DESTBYTE to 3 which indicates USERIO
  97. ; and by saving the addresses of the rouines in dseg memory.
  98. ;----------------------------------------------------------------
  99. ;
  100. userio:
  101.     push    psw
  102.     push    h
  103.     push    b            ; Save a byte count
  104.     mvi    a,3            ; Indicate user i/o
  105.     sta    ?destbyte
  106.     xchg                ; HL -> address table
  107.     lxi    d,usrcie        ; Point to first byte of dest'n
  108.     lxi    b,6            ; Shift only 6 bytes
  109.     ldir                ; Move the table
  110.     pop    b
  111.     pop    h
  112.     pop    psw            ; Restore all registers.
  113.     ret
  114. ;
  115. ;----------------------------------------------------------------
  116. ; Goto the users console input routine. This only has to 
  117. ; read a console character into the accumulator and return 
  118. ; with it.
  119. ;----------------------------------------------------------------
  120. ;
  121. usr$conin:
  122.     pop    psw            ; Restore the users character
  123.     push    h            ; Save register
  124.     lhld    usrcie            ; get the address
  125.     xthl
  126.     ret
  127. ;
  128. ;----------------------------------------------------------------
  129. ; User the USRCOE routine to send a character to the output device.
  130. ;----------------------------------------------------------------
  131. ;
  132. usr$conout:
  133.     pop    psw            ; Restore ascii character
  134.     push    h            ; Save from predators
  135.     lhld    usrcoe            ; Load address of the routine
  136. ; The next two instructions put the address of the users I/O output
  137. ; routine onto the stack, restore the HL register then goto the routine.
  138. ;
  139.     xthl                ; Restore HL. Load address
  140.     ret                ; All done.
  141. ;
  142. ;----------------------------------------------------------------
  143. ;     Goto the users Console status routine.
  144. ;----------------------------------------------------------------
  145. ;
  146. usr$constat:
  147.     push    h
  148.     lhld    usrcst            ; Get the address
  149.     xthl
  150.     ret                ; Goto it without waiting.
  151. ;
  152. ;----------------------------------------------------------------
  153. ; This routine flushes the printer buffer (if it has one) by sending a 
  154. ; backspace then a space so the the printer sends all its contents
  155. ; to paper before printing the backspace/space.
  156. ;----------------------------------------------------------------
  157. ;
  158. flushloe:
  159.     push    psw            ; save this only all else auto
  160.     mvi    a,08            ; do a backspace
  161.     call    loe
  162.     mvi    a,' '            ; space
  163.     call    loe
  164.     pop    psw
  165.     ret
  166. ;
  167.     dseg
  168. usrcie    db    00,00            ; Filled in by userio
  169. usrcoe    db    00,00
  170. usrcst    db    00,00
  171. ;
  172.     end
  173.  
  174.