]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/conbuf.180
75741e0ebd50bdca7488a3097df5b6f5541e68d5
[z180-stamp-cpm3.git] / cbios / conbuf.180
1 page 255
2 .z80
3
4 ;
5 ; FIFO channels for communication with avr
6 ;
7 global ff.init,ff.in,ff.ist,ff.out,ff.ost
8
9 extrn bufinit,fifolst
10
11 include config.inc
12 if CPU_Z180
13 include z180reg.inc
14 endif
15
16 dseg
17 mkbuf ci.fifo_id, ci.fifo, ci.fifo_len
18 mkbuf co.fifo_id, co.fifo, co.fifo_len
19
20 ici equ ci.fifo_id * 2
21 ico equ co.fifo_id * 2
22
23
24 ;--------------------------------------------------------------
25
26 ; Init Serial I/O for console input and output
27 ;
28 dseg
29 ff.init:
30 ld a,(INIDONE)
31 cp INIDONEVAL
32 ret z
33
34 ld ix,ci.fifo
35 call bufinit
36 ld ix,co.fifo
37 jp bufinit
38
39 ;--------------------------------------------------------------
40 ; Input status
41 ; buffer is empty, if output index and input index are the same
42
43 dseg
44 ff.ist:
45 push ix
46 ld ix,(fifolst+ici) ;
47
48 buf.empty:
49 ld a,(ix+o.in_idx) ;
50 sub (ix+o.out_idx) ;
51 pop ix
52 ret z
53 or 0ffh
54 ret
55
56
57 ;--------------------------------------------------------------
58 ; Output status
59 ; buffer is full, if output index is one behind input index
60
61 ff.in:
62 push ix
63 ld ix,(fifolst+ici) ;
64
65 buf.get:
66 push ix
67 pop hl
68 ld c,(ix+o.out_idx) ;
69 ld b,0
70 add hl,bc
71 ld a,c
72 bg.wait:
73 cp (ix+o.in_idx) ;
74 jr z,bg.wait
75 ld b,(hl)
76 ld a,c ;
77 inc a
78 and (ix+o.mask)
79 ld (ix+o.out_idx),a
80 ld a,b
81 pop ix
82 ret
83
84 ;--------------------------------------------------------------
85 ; Output status
86 ; buffer is full, if output index is one behind input index
87
88 ff.ost:
89 push ix
90 ld ix,(fifolst+ico) ;
91
92 buf.full:
93 ld a,(ix+o.in_idx) ;
94 inc a
95 and (ix+o.mask)
96 sub (ix+o.out_idx) ;
97 pop ix
98 ret z
99 or 0ffh
100 ret
101
102
103 ;--------------------------------------------------------------
104 ; put character in c in buffer
105 ; destroys hl, bc
106 ; returns output char in a
107
108 ff.out:
109 push ix ;
110 ld ix,(fifolst+ico) ;
111 buf.put:
112 push ix ;
113 pop hl ; get buffer start address
114
115 ld a,c ;
116 ld c,(ix+o.in_idx) ; add input index
117 ld b,0 ;
118 add hl,bc ;
119 ld (hl),a ; one place is allways free
120 ld b,a ;
121
122 ld a,c ; bump input index
123 inc a ;
124 and (ix+o.mask) ;
125 bp.wait: ; do
126 cp (ix+o.out_idx) ;
127 jr z,bp.wait ; while new input idx == ouput idx
128 ld (ix+o.in_idx),a ;
129
130 out (AVRINT6),a ; tell monitor
131 ld a,b ;
132 pop ix ;
133 ret ;
134
135 end