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