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