home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol236 / chario.mqc / CHARIO.MAC
Encoding:
Text File  |  1986-02-11  |  16.0 KB  |  498 lines

  1.         TITLE IO SYSTEM MODULE          ; USE M80 TO COMPILE
  2.  
  3. true    equ -1
  4. false   equ 0
  5.  
  6. banked  equ true
  7.  
  8.         .Z80
  9.  
  10.         entry ?cinit,?ci,?co,?cist,?cost,@ctbl
  11.                        if banked
  12.         extrn ?bank,?rbank,?bank0
  13.                        endif
  14.  
  15. .COMMENT *
  16.         DEVICE NUMBER IN B
  17.         CHARACTER FOR OUTPUT IN C - CHARACTER RETURNED TO A
  18.         ?cinit  INITIALIZE DEVICE - DEVICE NUMBER IN C
  19.         ?ci     CHARACTER IN
  20.         ?co     CHARACTER OUT
  21.         ?cist   INPUT STATUS
  22.         ?cost   OUTPUT STATUS
  23.         ?bank   BANK CHANGE
  24.         ?rbank  RESTORE BANK
  25.         ?bank0  SET BANK 0
  26.  
  27.         @ctbl   CHARACTER DEVICE TABLE
  28.      *
  29.  
  30. mbin            equ  1          ; device may do input
  31. mbout           equ  2          ; device may do output
  32. mbio            equ  3          ; both input and output
  33. mbsb            equ  4          ; software selectable baud rates
  34. mbser           equ  8          ; serial device
  35. mbx             equ  16         ; xon/xoff protocol      
  36. bnone        equ 0        ; no baud rate associated
  37. b50        equ 1        ; 50 baud
  38. b75        equ 2        ; 75 baud
  39. b110        equ 3        ; 110 baud
  40. b134        equ 4        ; 134.5 baud
  41. b150        equ 5        ; 150 baud
  42. b300        equ 6        ; 300 baud
  43. b600        equ 7        ; 600 baud
  44. b1200        equ 8        ; 1200 baud
  45. b1800        equ 9        ; 1800 baud
  46. b2400        equ 10        ; 2400 baud
  47. b3600        equ 11        ; 3600 baud
  48. b4800        equ 12        ; 4800 baud
  49. b7200        equ 13        ; 7200 baud
  50. b9600        equ 14        ; 9600 baud
  51. b19200        equ 15        ; 19.2k baud
  52.  
  53.                        if banked
  54. maxdev  equ 8                   ; 8 devices defined
  55.                        else
  56. maxdev  equ 7                   ; 7 if unbanked - exclude double size
  57.                        endif
  58.  
  59.     cseg
  60.  
  61. ?cinit:                         ; initialize devices
  62.         ld b,c                  ; device number is in c
  63.         call jump
  64. inittb: db init0-inittb         ; screen
  65.         db indev-inittb         ; keyboard & tv monitor
  66.         db noinit-inittb        ; printer
  67.         db indev-inittb         ; modem
  68.         db noinit-inittb        ; mouse
  69.         db noinit-inittb        ; screen - graphics
  70.         db indev-inittb         ; tape
  71.                        if banked
  72.         db noinit-inittb        ; screen - double size
  73.                        endif
  74. noinit: ret                     ; no initializing
  75. init0:  ld a,1                  ; reset micro-angelo
  76.         out (0e1h),a
  77.         ld a,0
  78.         out (0e1h),a
  79.         ld a,'A'
  80.         ld (mahndl),a           ; handler 'A' setup
  81.         ld hl,maalp             ; send setup chars to a
  82.         ld bc,04e0h             ; count and port
  83.         jp macyc                ; jump to macycle and return
  84.  
  85. indev:                          ; clear input device
  86.         call ?cist              ; input status
  87.         and a                   ; set flags
  88.         ret z                   ; return if buffer clear
  89.         call ?ci                ; get character
  90.         jr indev                ; try again
  91.  
  92. ?ci:                            ; character input
  93. icyc:   call ?cist              ; get input status
  94.         and a                   ; set flags
  95.         jr z,icyc
  96.         call jump
  97. itb:    db nullin-itb
  98.         db i1-itb               ; keyboard
  99.         db nullin-itb
  100.         db i3-itb               ; modem
  101.         db i4-itb               ; mouse
  102.         db i5-itb               ; graphics board input
  103.         db i6-itb               ; tape
  104.                        if banked
  105.         db nullin-itb
  106.                        endif
  107. nullin: ld a,1ah                ; return a cntl-z for no device
  108.         ret
  109. i1:
  110.                        if banked
  111.         call ?bank0             ; bank 0
  112.                        endif
  113.         ld a,(0e3f8h)           ; get this straight from the dj
  114.                        if banked
  115.         call ?rbank             ; restore bank
  116.                        endif
  117.         cpl                     ; dj requires this
  118.         ret
  119. i3:     in a,(1)
  120.         ret
  121. i4:     in a,(0)
  122.         ret
  123. i5:     in a,(0e0h)
  124.         ret
  125. i6:     in a,(6fh)
  126.         ret
  127.  
  128. ?co:                            ; character output
  129. ocyc:   call ?cost              ; get status
  130.         and a                   ; get flags
  131.         jr z,ocyc               ; wait till clear
  132.         call jump
  133. otb:    db o0-otb               ; screen - alpha mode
  134.         db o1-otb               ; TV monitor
  135.         db o2-otb               ; printer
  136.         db o3-otb               ; modem
  137.         db o4-otb               ; sw serial port 1
  138.         db o5-otb               ; screen - graphics mode
  139.         db o6-otb               ; tape
  140.                        if banked
  141.         db o7-otb               ; screen - double size
  142.                        endif
  143. nullou: ret                     ; no device
  144. o0:     ld a,(mahndl)           ; check handler being used
  145.         cp 'A'
  146.         jr z,o0e                ; jump if set up for alpha handler
  147.         ld a,'A'                ; update handler code
  148.         ld (mahndl),a
  149.         push bc
  150.         ld hl,maalp             ; send setup chars to a
  151.         ld bc,06e0h             ; count and port
  152.         call macyc
  153.         pop bc
  154. o0e:    ld a,c
  155.         cp 7                    ; check for bell character
  156.         jr z,o1                 ; send bell char to dj
  157.         cp 8                    ; check for backspace character
  158.         jr z,bs1
  159.         and 7fh                 ; truncate to 7 bits
  160. bs2:    out (0e0h),a            ; output character
  161.         ret
  162. bs1:    ld a,13h                ; backspace without deleting
  163.         jr bs2
  164. o1:
  165.                        if banked
  166.         call ?bank0
  167.                        endif
  168.         call 0e006h
  169.                        if banked
  170.         call ?rbank
  171.                        endif
  172.         ret
  173. o2:     ld a,c
  174.         out (4),a               ; output character
  175.         xor a                   ; clear a
  176.         out (3),a               ; strobe
  177.         ret
  178. o3:     ld a,c
  179.         out (1),a
  180.         ret
  181. o4:     ld a,c
  182.         out (0),a
  183.         ret
  184. o5:     ld a,(mahndl)           ; check graphics handler
  185.         cp 'G'
  186.         jr z,o5e
  187.         ld a,'G'
  188.         ld (mahndl),a
  189. o5e:    ld a,c
  190.         out (0e0h),a
  191.         ret
  192. o6:     ld a,c
  193.         out (6fh),a
  194.         ret
  195.                        if banked
  196. o7:
  197.         call ?bank0             ; work in banked memory
  198.         jp o7b                  ; jump to banked memory
  199.  
  200.         dseg
  201.  
  202. o7b:    ld a,(mahndl)           ; check double size handler
  203.         cp 'D'
  204.         jr z,o7e
  205.         ld a,'D'
  206.         ld (mahndl),a
  207.         push bc
  208.         ld hl,madou             ; send setup chars to ma board
  209.         ld bc,0Ce0h             ; count and port
  210.         call macyc
  211.         pop bc
  212.  
  213. o7e:    ld a,c
  214.         cp 7                    ; bell code
  215.         jp z,bell
  216.         cp 8                    ; back space
  217.         jp z,bksp
  218.         cp 0ah                  ; linefeed
  219.         jp z,o7c                ; ignore
  220.         cp 0dh                  ; carriage ret
  221.         jp z,carr
  222.         ld a,98h                ; code to send character
  223.         call maout
  224.         ld a,c                  ; send character
  225.         call maout
  226.                                 ; now to jump to new line if reqd
  227.         call getcur
  228.         ld a,d                  ; high x
  229.         and a                   ; set flags
  230.         jr z,o7x                ; must be 1 for eol
  231.         ld a,e                  ; low x
  232.         cp 248                  ; check at last location
  233.         jr nz,o7x
  234.                                 ; at end of line
  235. o7f:    ld a,h                  ; high y
  236.         and a                   ; set flags
  237.         jr nz,o7j               ; must be 0 for bottom line
  238.         ld a,l                  ; low y
  239.         and a                   ; set flags
  240.         jr nz,o7j               ; 0 for bottom line
  241.         push hl
  242.         ld hl,mascr             ; force scroll using alpha cursor
  243.         ld bc,04e0h
  244.         call macyc              ; to send stream of chars
  245.         pop hl
  246.         jr o7k
  247. o7j:                            ; advance cursor by one line
  248.         ld de,-24               ; line spacing
  249.         add hl,de               ; next line
  250. o7k:                            ; output new cursor position
  251.         ld a,84h                ; to set location
  252.         call maout
  253.         ld de,0
  254.         call maoutx             ; output de & hl
  255.         
  256. o7x:    ld a,95h
  257.         call undlin             ; to underline next location
  258.         jp o7c
  259.  
  260. bell:                           ; bell
  261.         call 0e006h             ; dj output (ok since we are in bank 0)
  262.         jp o7c
  263. carr:                           ; carriage return
  264.         call getcur             ; get cursor location
  265.         ld a,94h
  266.         call undlin             ; to clear cursor
  267.         jp o7f                  ; jump to main routine
  268.  
  269. bksp:                           ; backspace
  270.         call getcur             ; get cursor location
  271.         xor a                   ; clear a
  272.         or d                    ; check de = 0
  273.         or e
  274.         jp z,o7c                ; do nothing if at left margin
  275.         ld a,94h
  276.         call undlin             ; to delete current underline
  277.         push hl
  278.         ld hl,-12               ; column spacing
  279.         add hl,de               ; hl contains x location
  280.         ld a,84h                ; to set location
  281.         call maout
  282.         ex de,hl
  283.         pop hl
  284.         call maoutx             ; output de and hl
  285.         jp o7x                  ; jump to main routine
  286.  
  287. undlin:                         ; to set or reset underline
  288.         call maout
  289.         call maoutx             ; output de & hl
  290.         push de
  291.         push hl
  292.         ld hl,9                 ; underline 10 units long
  293.         add hl,de
  294.         ex de,hl
  295.         pop hl
  296.         push hl
  297.         inc hl                  ; to form double line
  298.         call maoutx             ; output de & hl
  299.         pop hl
  300.         pop de
  301.         ret
  302.  
  303. maoutx:                         ; send de and hl to ma board
  304.         ld a,d
  305.         call maout
  306.         ld a,e
  307.         call maout
  308.         ld a,h
  309.         call maout
  310.         ld a,l
  311.         call maout
  312.         ret
  313.  
  314. getcur: ld a,85h                ; to get location of g-cursor
  315.         call maout
  316.         call main
  317.         ld d,a                  ; high x
  318.         call main
  319.         ld e,a                  ; low x
  320.         call main
  321.         ld h,a                  ; high y
  322.         call main
  323.         ld l,a                  ; low y
  324.         ret
  325.  
  326. main:                           ; get char from ma board
  327.         in a,(0e1h)
  328.         and 2
  329.         jr z,main
  330.         in a,(0e0h)
  331.         ret
  332. maout:                          ; output char to micro angelo board
  333.         push af
  334. maoutc: in a,(0e1h)
  335.         and 1
  336.         jr nz,maoutc
  337.         pop af
  338.         out (0e0h),a
  339.         ret
  340.  
  341. ; characters to initialize ma board for double size
  342.  
  343. madou:  db 84h,0,0,1,200        ; set graphics cursor
  344.         db 0ch                  ; clear screen
  345.         db 99h,4                ; double size
  346.         db 83h,2                ; pop up two alpha lines
  347.         db 80h,16               ; turn off alpha cursor
  348.  
  349. mascr:  db 81h,39,0             ; set alpha cursor to bot line
  350.         db 0dh                  ; carriage return
  351.  
  352.         cseg
  353.  
  354. o7c:
  355.         call ?rbank
  356.         ret
  357.                        endif
  358.  
  359. ?cist:                          ; character input status
  360.         call jump
  361. isttb:  db nullis-isttb
  362.         db ist1-isttb           ; keyboard
  363.         db nullis-isttb
  364.         db ist3-isttb           ; modem
  365.         db ist4-isttb           ; mouse
  366.         db ist5-isttb           ; graphics board
  367.         db ist6-isttb           ; tape
  368.                        if banked
  369.         db nullis-isttb
  370.                        endif
  371. nullis: ld a,0ffh               ; return 0ffh for no device
  372.         ret                     ;   to prevent waiting forever for
  373.                                 ;   device to clear
  374. ist1:
  375.                        if banked
  376.         call ?bank0
  377.                        endif
  378.         call 0e021h             ; dj status routine
  379.                        if banked
  380.         call ?rbank
  381.                        endif
  382.         jr zrrd                 ; zero = ready
  383. ist3:   in a,(2)                ; switch board status
  384.         and 64                  ; serial input device 2 status
  385.         jr nzrd
  386. ist4:   in a,(2)                ; switch board status
  387.         and 4                   ; serial input device 1 status
  388.         jr nzrd
  389. ist5:   in a,(0e1h)             ; get status
  390.         and 2                   ; zero = not ready
  391.         jr nzrd
  392. ist6:   in a,(6eh)              ; tarbell status
  393.         and 16                  ; input status
  394.         jr zrrd
  395.  
  396. ?cost:                          ; output status
  397.         call jump
  398. osttb:  db ost0-osttb           ; screen - alpha mode
  399.         db ost1-osttb           ; tv monitor
  400.         db ost2-osttb           ; printer
  401.         db ost3-osttb           ; modem
  402.         db ost4-osttb           ; sw serial port 1
  403.         db ost0-osttb           ; screen - graphics mode
  404.         db ost6-osttb           ; tape
  405.                        if banked
  406.         db ost0-osttb           ; screen - double size
  407.                        endif
  408. nullos: jp nullis               ; same as input status
  409. ost0:   in a,(0e1h)             ; get status
  410.         and 1                   ; 0 = ready
  411.         jr zrrd
  412. ost1:   ld a,0ffh               ; dj doesn't provide routine so
  413.                                 ; don't implement this
  414.         ret
  415. ost2:   in a,(5)                ; get status
  416.         and 2                   ; 0 = ready
  417.         jr zrrd
  418. ost3:   in a,(2)                ; serial port status
  419.         and 128                 ; serial output device 2
  420.         jr nzrd
  421. ost4:   in a,(2)                ; serial port status
  422.         and 8                   ; serial output device 1
  423.         jr nzrd
  424. ost6:   in a,(6eh)              ; tarbell status
  425.         and 32                  ; bit 5
  426.         jr zrrd
  427.  
  428. zrrd:   jr z,nz1                ; 0 = ready
  429. zr1:    xor a                   ; return 0
  430.         ret
  431. nzrd:   jr z,zr1                ; 0 = not ready
  432. nz1:    ld a,0ffh               ; return -1
  433.         ret
  434.  
  435. jump:                           ; jump to device instruction
  436.         pop de                  ; get location of jump vector
  437.         ld a,b
  438.         cp maxdev               ; check if defined device
  439.         ret nc
  440.         ld h,0
  441.         ld l,a
  442.         add hl,de               ; points to rel address of device routine
  443.         ld a,(hl)               ; relative address
  444.         ld h,0
  445.         ld l,a
  446.         add hl,de               ; absolute address
  447.         jp (hl)
  448.  
  449. ; send stream of bytes to ma board
  450.  
  451. macyc:  in a,(0e1h)             ; status
  452.         and 1
  453.         jr nz,macyc             ; cycle if not ready
  454.         outi                    ; output with increment
  455.         jr nz,macyc                                                     
  456.         ret
  457.  
  458. mahndl: ds 1                    ; to show which ma handler is being used
  459.  
  460. ; code to initialize ma board for alphabetic entry
  461.  
  462. maalp:  db 80h,60h              ; set special & hi-speed modes
  463.         db 83h,4                ; 4 line scroll
  464.         db 0ch,0ch              ; clear screen (twice)
  465.  
  466. ; table of device characteristics
  467.  
  468. @ctbl:  db 'MA-ALP'     ; device 0, screen - alphabetic
  469.         db mbout
  470.         db bnone
  471.         db 'KEY/TV'     ; device 1, keyboard & TV monitor
  472.         db mbio+mbser+mbx
  473.         db b300
  474.         db 'EPSON '     ; device 2, printer
  475.         db mbout
  476.         db bnone
  477.         db 'MODEM '     ; device 3, modem
  478.         db mbio+mbser
  479.         db b300
  480.         db 'MOUSE '     ; device 4, mouse & serial port
  481.         db mbio+mbser
  482.         db b1200
  483.         db 'MA-GRA'     ; device 5, screen - graphics mode
  484.         db mbio
  485.         db bnone
  486.         db 'TAPE  '     ; device 6, cassette tape
  487.         db mbio
  488.         db bnone
  489.                        if banked
  490.         db 'MA-DOU'     ; device 7, screen - double size print
  491.         db mbout
  492.         db bnone
  493.                        endif
  494.         db 0            ; table end
  495.  
  496.     end
  497. ll maout
  498.         ld a,c