summaryrefslogtreecommitdiff
path: root/z180/fifoio.180
diff options
context:
space:
mode:
Diffstat (limited to 'z180/fifoio.180')
-rw-r--r--z180/fifoio.180128
1 files changed, 128 insertions, 0 deletions
diff --git a/z180/fifoio.180 b/z180/fifoio.180
new file mode 100644
index 0000000..27745d4
--- /dev/null
+++ b/z180/fifoio.180
@@ -0,0 +1,128 @@
+ page 255
+ .z80
+
+ global f.init,f.in,f.out,f.i.st
+
+ extrn buf.init
+
+ include config.inc
+ include z180reg.inc
+
+
+;--------------------------------------------------------------
+
+ dseg
+
+
+ mkbuf rx.buf,rx.buf_len
+ mkbuf tx.buf,tx.buf_len
+
+
+;--------------------------------------------------------------
+
+ cseg
+;
+; FIFO channels for communication with stm32
+;
+; Init Serial I/O for console input and output
+;
+
+f.init:
+ ld ix,rx.buf
+ ld a,rx.buf.mask
+ call buf.init
+ ld ix,tx.buf
+ ld a,tx.buf.mask
+ jp buf.init
+
+
+f.i.st:
+ push ix
+ ld ix,rx.buf ;
+
+buf.empty:
+ ld a,(ix+o.in_idx) ;
+ sub (ix+o.out_idx) ;
+ pop ix
+ ret z
+ or 0ffh
+ ret
+
+
+f.in:
+ push ix
+ ld ix,rx.buf ;
+
+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
+
+
+f.o.st:
+ push ix
+ ld ix,tx.buf ;
+
+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
+
+
+f.out:
+ push ix
+ ld ix,tx.buf ;
+
+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
+ pop bc
+ pop hl
+ pop ix
+ ret
+
+ end
+