home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / 22RSX / 22RSX-20.ARK / CONSOLE.ASM < prev    next >
Assembly Source File  |  1984-10-13  |  6KB  |  271 lines

  1. ;
  2. ; Module name : CONSOLE.ASM
  3. ; Author      : James Whorton
  4. ; Date written: 09/26/84
  5. ;
  6. ;
  7. ; This sample module illustrates how to write an RSX for the 22RSX
  8. ; environment. While it is rather simple, it does give you an idea
  9. ; on how to proceed with your own modules. Have fun. JHW <--
  10. ; This module records the number of times that the following BDOS
  11. ; functions have been called since last check: 1,2,5,6,9 and 10.
  12. ; When a request is made by using the accompanying program CONSTAT,
  13. ; the recorded
  14. ;
  15. cin:    equ    1
  16. cout:    equ    2
  17. lst:    equ    5
  18. dio:    equ    6
  19. lout:    equ    9
  20. lin:    equ    10
  21. request:equ    255        ;this is the request character that
  22.                 ;causes a display of the recorded
  23.                 ;values.
  24. fcb:    equ    05Ch        ;FCB address
  25. ;
  26. ; RSX prefix (standard DRI format)
  27. ;
  28. serial:    db    0,0,0,0,0,0    ;Space for serial # (CP/M 3.0)
  29. start:    jmp    rsxstrt        ;Jump to beginning of actual module
  30. next:    jmp    $-$        ;Jump to next RSX in line or BDOS jump table
  31. prev:    dw    0        ;The loader will patch the address of the
  32.                 ;previous module here.
  33. remove:    db    0        ;Remove flag (0=remain, 0FFh=remove at warm boot)
  34. nonbank:db    0        ;Nonbank flag
  35. name:    db    'CONSOLE '    ;This is the name of the RSX. It MUST be
  36. ;         ^^^^^^^^    ;8 bytes, pad with blanks if needed.
  37. loader:    db    0        ;Loader flag
  38.     db    0,0        ;Reserved for system use
  39. ;
  40. ;Module starts here
  41. ;
  42. rsxstrt:mov    a,c        ;save function #
  43.     sta    fnc
  44.     lxi    h,0        ;save user's stack pointer
  45.     dad    sp
  46.     shld    userstk
  47.     lxi    sp,rstack    ;set local stack
  48.     push    d        ;save regs.
  49.     push    b
  50. ;
  51. ;check function and branch if one of ours
  52. ;
  53.     cpi    cin        ;input?
  54.     jz    input        ;yes
  55.     cpi    cout        ;output?
  56.     jz    output        ;yes
  57.     cpi    lst        ;list output?
  58.     jz    list        ;yes
  59.     cpi    dio        ;direct I/O?
  60.     jz    direct        ;yes
  61.     cpi    lout        ;line out?
  62.     jz    linout        ;yes
  63.     cpi    lin        ;line in?
  64.     jz    linin        ;yes
  65.     jmp    passon        ;the function call wasn't one of ours,
  66. ;
  67. ;BDOS function 1 (console in)
  68. ;
  69. input:    lhld    incnt        ;get counter
  70.     inx    h        ;bump it one
  71.     shld    incnt        ;put it back
  72.     jmp    passon        ;continue
  73. ;
  74. ;BDOS function 2 (console out)
  75. ;
  76. output:    lhld    outcnt        ;get pointer
  77.     inx    h        ;bump it one
  78.     shld    outcnt        ;update it
  79. ;
  80. ;check for a status request
  81. ;
  82.     lda    fcb        ;get check char
  83.     cpi    request        ;is it a request?
  84.     jnz    passon        ;no, so pass call on
  85. ;
  86. ;A request has been made, so report stats...
  87. ;
  88. report:    lxi    h,in$msg    ;console in
  89.     call    ilprnt
  90.     lhld    incnt
  91.     call    outhex
  92.     lxi    h,out$msg    ;console out
  93.     call    ilprnt
  94.     lhld    outcnt
  95.     call    outhex
  96.     lxi    h,lst$msg    ;list out
  97.     call    ilprnt
  98.     lhld    lstcnt
  99.     call    outhex
  100.     lxi    h,din$msg    ;direct I/O in
  101.     call    ilprnt
  102.     lhld    dincnt
  103.     call    outhex
  104.     lxi    h,dout$msg    ;direct I/O out
  105.     call    ilprnt
  106.     lhld    doutcnt
  107.     call    outhex
  108.     lxi    h,lout$msg    ;line out
  109.     call    ilprnt
  110.     lhld    loutcnt
  111.     call    outhex
  112.     lxi    h,lin$msg    ;line in
  113.     call    ilprnt
  114.     lhld    lincnt
  115.     call    outhex
  116. ;now reset our counters and exit
  117.     lxi    h,0
  118.     shld    incnt
  119.     shld    outcnt
  120.     shld    lstcnt
  121.     shld    dincnt
  122.     shld    doutcnt
  123.     shld    loutcnt
  124.     shld    lincnt
  125.     mvi    a,0        ;set FCB to something innocent
  126.     sta    fcb
  127. exit:    pop    b        ;restore regs
  128.     pop    d
  129.     lhld    userstk        ;restore stack
  130.     sphl
  131.     ret            ;back to caller
  132. ;
  133. ;BDOS function 5 (list out)
  134. ;
  135. list:    lhld    lstcnt        ;get counter
  136.     inx    h        ;bump on
  137.     shld    lstcnt        ;update it
  138.     jmp    passon        ;continue
  139. ;
  140. ;BDOS function 6
  141. ;
  142. direct:    pop    b        ;get regs for compar.
  143.     pop    d
  144.     push    d        ;put them back
  145.     push    b
  146. ;determine whether in or out and act accordingly
  147.     mov    a,e
  148.     cpi    0FFh        ;direct I/O in?
  149.     jnz    direct2        ;no, must be out
  150.     lhld    dincnt        ;get counter
  151.     inx    h        ;bump one
  152.     shld    dincnt        ;update it
  153.     jmp    passon        ;continue
  154. ;
  155. direct2:lhld    doutcnt        ;get counter
  156.     inx    h        ;bump one
  157.     shld    doutcnt        ;update it
  158.     jmp    passon        ;continue
  159. ;
  160. ;BDOS function 9 (line out)
  161. ;
  162. linout:    lhld    loutcnt        ;get counter
  163.     inx    h        ;bump one
  164.     shld    loutcnt        ;update it
  165.     jmp    passon        ;continue
  166. ;
  167. ;BDOS function 10 (line in)
  168. ;
  169. linin:    lhld    lincnt        ;get counter
  170.     inx    h        ;bump one
  171.     shld    lincnt        ;update it
  172. ;
  173. ;Restore all regs. and stack pointer and pass call up the line
  174. ;
  175. passon:    pop    b        ;restore regs.
  176.     pop    d
  177.     lhld    userstk        ;restore stack
  178.     sphl
  179.     jmp    next        ;later...
  180. ;
  181. ; Data storage area
  182. ;
  183. fnc:    ds    1        ;function call
  184. incnt:    dw    0        ;console in counter
  185. outcnt:    dw    0        ;console out counter
  186. lstcnt:    dw    0        ;list counter
  187. dincnt:    dw    0        ;direct I/O in counter
  188. doutcnt:dw    0        ;direct I/O out counter
  189. loutcnt:dw    0        ;line output counter
  190. lincnt:    dw    0        ;line input counter
  191. temp:    ds    1        ;temp. storage
  192. userstk:dw    0        ;old stack pointer
  193.     ds    20        ;local stack space
  194. rstack:    dw    0
  195. in$msg:    db    cr,lf,'    1        Console In         ',0
  196. out$msg:db    cr,lf,'    2        Console Out        ',0
  197. lst$msg:db    cr,lf,'    5        List Out           ',0
  198. din$msg:db    cr,lf,'    6        Direct I/O In      ',0
  199. dout$msg:db    cr,lf,'    6        Direct I/O Out     ',0
  200. lout$msg:db    cr,lf,'    9        Line Out           ',0
  201. lin$msg:db    cr,lf,'   10        Line In            ',0
  202. ;
  203. ;== Utility Routines ==
  204. ;
  205. ;This routine outputs the contents of <hl> in hex format
  206. ;
  207. outhex:    push    h        ;save value
  208.     mov    a,h        ;get MSB
  209.     call    outhex1        ;print it
  210.     pop    h        ;get value back
  211.     push    h
  212.     mov    a,l        ;get LSB
  213.     call    outhex1        ;print it
  214.     mvi    e,'h'        ;put h on end of address
  215.     mvi    c,cout
  216.     call    next
  217.     pop    h
  218.     ret
  219. outhex1:mov    b,a        ;save number
  220.     rar
  221.     rar
  222.     rar
  223.     rar
  224.     call    outhex2        ;print half of it
  225.     mov    a,b        ;get number back
  226. outhex2:ani    0Fh        ;get LSN to send out
  227.     adi    090h        ;convert to ASCII
  228.     daa
  229.     aci    040h
  230.     daa
  231.     push    b
  232.     mvi    c,cout
  233.     mov    e,a
  234.     call    next
  235.     pop    b
  236.     ret
  237. ;
  238. ;
  239. ;Inline print routine
  240. ;
  241. ilprnt:    push    psw
  242.     push    h
  243.     push    d
  244.     push    b
  245. ;
  246. ilp:    mov    e,m
  247.     mvi    c,cout
  248.     push    h
  249. ilp1:    call    next
  250.     pop    h
  251.     inx    h
  252.     mov    a,m
  253.     ora    a
  254.     jnz    ilp
  255.     pop    b
  256.     pop    d
  257.     pop    h
  258.     pop    psw
  259.     ret
  260. ;
  261.     link    '22INSTB'
  262.  
  263.     h
  264. ilp1:    call    next
  265.     pop    h
  266.     inx    h
  267.     mov    a,m
  268.     ora    a
  269.     jnz    ilp
  270.     pop    b
  271.     pop