]> cloudbase.mooo.com Git - z180-stamp.git/blob - z180/conbuf-a.180
new fifos msg in, msg out, console in, console out
[z180-stamp.git] / z180 / conbuf-a.180
1 page 255
2 .z80
3
4 ;
5 ; FIFO channels for communication with avr
6 ;
7 global ff.init,ff.in,ff.out,ff.i.st
8
9 extrn buf.init
10
11 include config.inc
12 include z180reg.inc
13
14
15 ;--------------------------------------------------------------
16
17 dseg
18
19
20 mkbuf co.fifo,co.fifo_len
21 mkbuf ci.fifo,ci.fifo_len
22
23
24 ;--------------------------------------------------------------
25
26 cseg
27
28 ; Init Serial I/O for console input and output
29 ;
30
31 ff.init:
32 ld ix,ci.fifo
33 ld a,ci.fifo.mask
34 call buf.init
35 ld ix,co.fifo
36 ld a,co.fifo.mask
37 jp buf.init
38
39
40 ff.i.st:
41 push ix
42 ld ix,ci.fifo ;
43
44 buf.empty:
45 ld a,(ix+o.in_idx) ;
46 sub (ix+o.out_idx) ;
47 pop ix
48 ret z
49 or 0ffh
50 ret
51
52
53 ff.in:
54 push ix
55 ld ix,ci.fifo ;
56
57 buf.get:
58 ld a,(ix+o.out_idx) ;
59 bg.wait:
60 cp (ix+o.in_idx) ;
61 jr z,bg.wait
62
63 push hl ;
64 push ix
65 pop hl
66 add a,l
67 ld l,a
68 jr nc,bg.nc
69 inc h
70 bg.nc:
71 ld l,(hl)
72
73 ld a,(ix+o.out_idx) ;
74 inc a
75 and (ix+o.mask)
76 ld (ix+o.out_idx),a
77
78 ld a,l
79 pop hl
80 pop ix
81 ret
82
83
84 ff.o.st:
85 push ix
86 ld ix,co.fifo ;
87
88 buf.full:
89 ld a,(ix+o.in_idx) ;
90 inc a
91 and (ix+o.mask)
92 sub (ix+o.out_idx) ;
93 pop ix
94 ret z
95 or 0ffh
96 ret
97
98
99 ff.out:
100 push ix
101 ld ix,co.fifo ;
102
103 buf.put:
104 push hl ;
105 push bc
106 push ix
107 pop hl
108 ld c,(ix+o.in_idx) ;
109 ld b,0
110 add hl,bc
111 ld b,a
112
113 ld a,c ;
114 inc a
115 and (ix+o.mask)
116 bp.wait:
117 cp (ix+o.out_idx) ;
118 jr z,bp.wait
119 ld (hl),b
120 ld (ix+o.in_idx),a
121
122 out (AVRINT6),a
123 ld a,b
124 pop bc
125 pop hl
126 pop ix
127 ret
128
129 end
130