]> cloudbase.mooo.com Git - z180-stamp.git/blame - z180/conbuf-a.180
switch fifos conin,conout
[z180-stamp.git] / z180 / conbuf-a.180
CommitLineData
6a4e9540
L
1 page 255\r
2 .z80\r
e4c4b148 3\r
6a4e9540
L
4;\r
5; FIFO channels for communication with avr\r
6;\r
30d1329e 7 global ff.init,ff.in,ff.out,ff.i.st,ff.o.st\r
6a4e9540
L
8\r
9 extrn buf.init\r
10\r
11 include config.inc\r
64cc2207 12 if CPU_Z180\r
6a4e9540 13 include z180reg.inc\r
64cc2207 14 endif\r
6a4e9540
L
15\r
16\r
17;--------------------------------------------------------------\r
18\r
19 dseg\r
6a4e9540 20\r
e4c4b148 21\r
e4c4b148 22 mkbuf ci.fifo_id, ci.fifo, ci.fifo_len\r
ad9bc17c 23 mkbuf co.fifo_id, co.fifo, co.fifo_len\r
6a4e9540
L
24\r
25\r
26;--------------------------------------------------------------\r
27\r
28 cseg\r
29\r
30; Init Serial I/O for console input and output\r
31;\r
32\r
33ff.init:\r
34 ld ix,ci.fifo\r
35 ld a,ci.fifo.mask\r
36 call buf.init\r
37 ld ix,co.fifo\r
38 ld a,co.fifo.mask\r
39 jp buf.init\r
40\r
41\r
42ff.i.st:\r
43 push ix\r
44 ld ix,ci.fifo ;\r
45\r
46buf.empty:\r
47 ld a,(ix+o.in_idx) ;\r
48 sub (ix+o.out_idx) ;\r
49 pop ix\r
50 ret z\r
51 or 0ffh\r
52 ret\r
e4c4b148 53\r
6a4e9540
L
54\r
55ff.in:\r
56 push ix\r
57 ld ix,ci.fifo ;\r
58\r
59buf.get:\r
60 ld a,(ix+o.out_idx) ;\r
61bg.wait:\r
62 cp (ix+o.in_idx) ;\r
63 jr z,bg.wait\r
64\r
65 push hl ;\r
66 push ix\r
67 pop hl\r
68 add a,l\r
69 ld l,a\r
70 jr nc,bg.nc\r
71 inc h\r
72bg.nc:\r
73 ld l,(hl)\r
e4c4b148 74\r
6a4e9540
L
75 ld a,(ix+o.out_idx) ;\r
76 inc a\r
77 and (ix+o.mask)\r
78 ld (ix+o.out_idx),a\r
e4c4b148 79\r
6a4e9540
L
80 ld a,l\r
81 pop hl\r
82 pop ix\r
83 ret\r
84\r
85\r
86ff.o.st:\r
87 push ix\r
88 ld ix,co.fifo ;\r
89\r
90buf.full:\r
91 ld a,(ix+o.in_idx) ;\r
92 inc a\r
93 and (ix+o.mask)\r
94 sub (ix+o.out_idx) ;\r
95 pop ix\r
96 ret z\r
97 or 0ffh\r
98 ret\r
99\r
100\r
64cc2207 101 if 1\r
6a4e9540 102ff.out:\r
64cc2207
L
103 push ix ;15\r
104 ld ix,co.fifo ;14\r
6a4e9540
L
105\r
106buf.put:\r
64cc2207
L
107 push hl ;11\r
108 push bc ;11\r
109 push ix ;15\r
110 pop hl ;10\r
111 ld a,c ;4\r
112 ld c,(ix+o.in_idx) ;19\r
113 ld b,0 ;7\r
114 add hl,bc ;11\r
115 ld (hl),a ;7\r
116 ld b,a ;4\r
117\r
118 ld a,c ;4\r
119 inc a ;4\r
120 and (ix+o.mask) ;19\r
6a4e9540 121bp.wait:\r
64cc2207
L
122 cp (ix+o.out_idx) ;19\r
123 jr z,bp.wait ;12/7\r
124 ld (ix+o.in_idx),a ;19\r
e4c4b148 125\r
64cc2207
L
126 out (AVRINT6),a ;11\r
127 ld a,b ;4\r
128 pop bc ;10\r
129 pop hl ;10\r
130 pop ix ;14\r
131 ret ;10\r
132\r
133 else\r
134\r
135ff.out:\r
136 push ix ;15\r
137 ld ix,co.fifo ;14\r
138\r
139buf.put:\r
140 push hl ;11\r
141 push ix ;15\r
142 pop hl ;10\r
143 ld a,(ix+o.in_idx) ;19\r
144 add a,l ;4\r
145 ld l,a ;4\r
146 jr nc,bp.1 ;12/7\r
147 inc l ;4\r
148 ld (hl),c ;7\r
149 ld a,(ix+o.in_idx) ;19\r
150 inc a ;4\r
151 and (ix+o.mask) ;19\r
152bp.wait:\r
153 cp (ix+o.out_idx) ;19\r
154 jr z,bp.wait ;12/7\r
155 ld (ix+o.in_idx),a ;19\r
156\r
157 out (AVRINT6),a ;11\r
158 ld a,c ;4\r
159 pop hl ;10\r
160 pop ix ;14\r
161 ret ;10 |\r
162\r
163 endif\r
6a4e9540
L
164\r
165 end\r