]> cloudbase.mooo.com Git - z180-stamp.git/blob - z180/msgfifo.180
Detect ZRESET polarity
[z180-stamp.git] / z180 / msgfifo.180
1 page 255
2 .z80
3
4 global msg_rx_fifo,msg_tx_fifo
5
6 global msginit,msgi.st,msg.in,msgo.st,msg.out
7 global msg.sout,msg.co
8
9 extrn buf.init
10
11 include config.inc
12 include z180reg.inc
13
14 ;--------------------------------------------------------------
15
16 dseg
17
18 mkbuf mtx.fifo_id, msg_tx_fifo, msg_tx_fifo_len
19 mkbuf mrx.fifo_id, msg_rx_fifo, msg_rx_fifo_len
20
21
22
23 ;--------------------------------------------------------------
24
25 cseg
26
27 ;
28 ; Init buffer
29 ;
30
31 msginit:
32 ld ix,msg_rx_fifo
33 ld a,msg_rx_fifo.mask
34 call buf.init
35 ld ix,msg_tx_fifo
36 ld a,msg_tx_fifo.mask
37 jp buf.init
38
39 ;--------------------------------------------------------------
40
41 msgi.st:
42 push ix
43 ld ix,msg_rx_fifo ;
44
45 buf.empty:
46 ld a,(ix+o.in_idx) ;
47 sub (ix+o.out_idx) ;
48 pop ix
49 ret z
50 or 0ffh
51 ret
52
53 ;--------------------------------------------------------------
54
55 msg.in:
56 push ix
57 ld ix,msg_rx_fifo ;
58
59 buf.get:
60 ld a,(ix+o.out_idx) ;
61 bg.wait:
62 cp (ix+o.in_idx) ;
63 jr z,bg.wait
64
65 push hl ;
66 push ix
67 pop hl
68 add a,l
69 ld l,a
70 jr nc,bg.nc
71 inc h
72 bg.nc:
73 ld l,(hl)
74
75 ld a,(ix+o.out_idx) ;
76 inc a
77 and (ix+o.mask)
78 ld (ix+o.out_idx),a
79
80 ld a,l
81 pop hl
82 pop ix
83 ret
84
85 ;--------------------------------------------------------------
86
87 msgo.st:
88 push ix
89 ld ix,msg_tx_fifo ;
90
91 buf.full:
92 ld a,(ix+o.in_idx) ;
93 inc a
94 and (ix+o.mask)
95 sub (ix+o.out_idx) ;
96 pop ix
97 ret z
98 or 0ffh
99 ret
100
101 ;--------------------------------------------------------------
102
103 msg.out:
104 push ix
105 ld ix,msg_tx_fifo ;
106
107 buf.put:
108 push hl ;
109 push bc
110 push ix
111 pop hl
112 ld c,(ix+o.in_idx) ;
113 ld b,0
114 add hl,bc
115 ld b,a
116
117 ld a,c ;
118 inc a
119 and (ix+o.mask)
120 bp.wait:
121 cp (ix+o.out_idx) ;
122 jr z,bp.wait
123 ld (hl),b
124 ld (ix+o.in_idx),a
125
126 ld a,b
127 out0 (AVRINT5),a
128 pop bc
129 pop hl
130 pop ix
131 ret
132
133
134 ;--------------------------------------------------------------
135 ;--------------------------------------------------------------
136 ;--------------------------------------------------------------
137
138 if 0
139 msg.out:
140 push ix
141 ld ix,msg_fifo ;
142
143 push bc
144 ld b,a ;save char
145 ld a,(ix+o.in_idx) ;
146 inc a
147 and (ix+o.mask)
148 bp.wait:
149 cp (ix+o.out_idx) ;
150 jr z,bp.wait
151 ld c,a
152 ld a,b
153 out (PMSG),a
154 ld (ix+o.in_idx),c
155
156 pop bc
157 pop ix
158 ret
159 endif
160
161 ;--------------------------------------------------------------
162 ;
163 ; (hl): data
164
165 msg.sout:
166 push ix
167 ld ix,msg_tx_fifo ;
168
169 push bc
170 push de
171 ld b,(hl) ;
172 inc hl
173 ex de,hl
174
175 ms.ol:
176 push ix
177 pop hl
178 ld c,(ix+o.in_idx) ;
179 ld a,c
180 add l
181 ld l,a
182 jr nc,ms.on
183 inc h
184 ms.on:
185 ld a,c ;
186 inc a
187 and (ix+o.mask)
188 ms.wait:
189 cp (ix+o.out_idx) ;
190 jr z,ms.wait
191 ld c,a
192 ld a,(de)
193 inc de
194 ld (hl),a
195 ld (ix+o.in_idx),c
196 djnz ms.ol
197 out0 (AVRINT5),a
198 ex de,hl
199 pop de
200 pop bc
201 pop ix
202 ret
203
204 ;--------------------------------------------------------------
205
206 if 0
207 msg.sout:
208 push ix
209 ld ix,msg_fifo ;
210 push bc
211
212 ld b,(hl) ;count
213 inc hl
214 obs_1:
215 ld a,(ix+o.out_idx) ;
216 sub (ix+o.in_idx) ;
217 dec a
218 and (ix+o.mask)
219 cp b
220 jr c,obs_1
221
222 ld c,(hl) ;port address
223 inc hl
224 ld a,b
225 otir
226 add (ix+o.in_idx)
227 and (ix+o.mask)
228 ld (ix+o.in_idx),a
229 pop bc
230 pop ix
231 ret
232
233 ;----------------------------------------------------------------------
234 endif
235
236 msg.co:
237 push af
238 push hl
239 ld (buf_char),a
240 ld hl,buf
241 call msg.sout
242 pop hl
243 pop af
244 ret
245
246
247 buf:
248 db buf_end - $ - 1 ;output string length
249 db 081h ; message start token
250 db buf_end - $ - 1 ; message length
251 db 1 ; command
252 db 1 ; subcommand
253 buf_char:
254 db 0 ; pay load
255 buf_end:
256
257 ;----------------------------------------------------------------------
258
259 end