page 255 .z80 ; ; FIFO channels for communication with avr ; global ff.init,ff.in,ff.ist,ff.out,ff.ost extrn bufinit,fifolst include config.inc if CPU_Z180 include z180reg.inc endif dseg mkbuf ci.fifo_id, ci.fifo, ci.fifo_len mkbuf co.fifo_id, co.fifo, co.fifo_len ici equ ci.fifo_id * 2 ico equ co.fifo_id * 2 ;-------------------------------------------------------------- ; Init Serial I/O for console input and output ; dseg ff.init: ld a,(INIDONE) cp INIDONEVAL ret z ld ix,ci.fifo call bufinit ld ix,co.fifo jp bufinit ;-------------------------------------------------------------- ; Input status ; buffer is empty, if output index and input index are the same dseg ff.ist: push ix ld ix,(fifolst+ici) ; buf.empty: ld a,(ix+o.in_idx) ; sub (ix+o.out_idx) ; pop ix ret z or 0ffh ret ;-------------------------------------------------------------- ; Output status ; buffer is full, if output index is one behind input index ff.in: push ix ld ix,(fifolst+ici) ; buf.get: push ix pop hl ld c,(ix+o.out_idx) ; ld b,0 add hl,bc ld a,c bg.wait: cp (ix+o.in_idx) ; jr z,bg.wait ld b,(hl) ld a,c ; inc a and (ix+o.mask) ld (ix+o.out_idx),a ld a,b pop ix ret ;-------------------------------------------------------------- ; Output status ; buffer is full, if output index is one behind input index ff.ost: push ix ld ix,(fifolst+ico) ; 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 ;-------------------------------------------------------------- ; put character in c in buffer ; destroys hl, bc ; returns output char in a ff.out: push ix ; ld ix,(fifolst+ico) ; buf.put: push ix ; pop hl ; get buffer start address ld a,c ; ld c,(ix+o.in_idx) ; add input index ld b,0 ; add hl,bc ; ld (hl),a ; one place is allways free ld b,a ; ld a,c ; bump input index inc a ; and (ix+o.mask) ; bp.wait: ; do cp (ix+o.out_idx) ; jr z,bp.wait ; while new input idx == ouput idx ld (ix+o.in_idx),a ; out (AVRINT6),a ; tell monitor ld a,b ; pop ix ; ret ; end