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
|
page 255
.z80
;
; FIFO channels for communication with avr
;
global ff.init,ff.in,ff.out,ff.i.st,ff.o.st
extrn buf.init
include config.inc
if CPU_Z180
include z180reg.inc
endif
;--------------------------------------------------------------
dseg
mkbuf co.fifo,co.fifo_len
mkbuf ci.fifo,ci.fifo_len
;--------------------------------------------------------------
cseg
; Init Serial I/O for console input and output
;
ff.init:
ld ix,ci.fifo
ld a,ci.fifo.mask
call buf.init
ld ix,co.fifo
ld a,co.fifo.mask
jp buf.init
ff.i.st:
push ix
ld ix,ci.fifo ;
buf.empty:
ld a,(ix+o.in_idx) ;
sub (ix+o.out_idx) ;
pop ix
ret z
or 0ffh
ret
ff.in:
push ix
ld ix,ci.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
ff.o.st:
push ix
ld ix,co.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
if 1
ff.out:
push ix ;15
ld ix,co.fifo ;14
buf.put:
push hl ;11
push bc ;11
push ix ;15
pop hl ;10
ld a,c ;4
ld c,(ix+o.in_idx) ;19
ld b,0 ;7
add hl,bc ;11
ld (hl),a ;7
ld b,a ;4
ld a,c ;4
inc a ;4
and (ix+o.mask) ;19
bp.wait:
cp (ix+o.out_idx) ;19
jr z,bp.wait ;12/7
ld (ix+o.in_idx),a ;19
out (AVRINT6),a ;11
ld a,b ;4
pop bc ;10
pop hl ;10
pop ix ;14
ret ;10
else
ff.out:
push ix ;15
ld ix,co.fifo ;14
buf.put:
push hl ;11
push ix ;15
pop hl ;10
ld a,(ix+o.in_idx) ;19
add a,l ;4
ld l,a ;4
jr nc,bp.1 ;12/7
inc l ;4
ld (hl),c ;7
ld a,(ix+o.in_idx) ;19
inc a ;4
and (ix+o.mask) ;19
bp.wait:
cp (ix+o.out_idx) ;19
jr z,bp.wait ;12/7
ld (ix+o.in_idx),a ;19
out (AVRINT6),a ;11
ld a,c ;4
pop hl ;10
pop ix ;14
ret ;10 |
endif
end
|