public bufinit public ff_empty,ff_get,ff_full,ff_put, ff_cnt public fifolst extrn msg.sm,hwl2phy include config.inc include z180reg.inc ;-------------------------------------------------------------------- dseg fifolst: rept 4 dw 0 endm ;-------------------------------------------------------------------- dseg bufinit: ld (ix+o.in_idx),0 ;reset pointers (empty fifo) ld (ix+o.out_idx),0 ld a,(ix+o.id) ld hl,fifolst ld e,a ld d,0 add hl,de add hl,de push ix pop de cp 4 jr nc,bfi_skip ld (hl),e inc hl ld (hl),d bfi_skip: ex de,hl call hwl2phy ;get phys. address of fifo ld c,a ld a,(ix+o.id) ;fifo id or a ;test if fifo 0 ret z cp 4 ret nc ; TODO: move to better place ld b,a push bc ;c: bank-addr, b: ignored push hl ;address ld c,0 push bc ;c: function, b:subf ld b,5 ld h,c ld l,c add hl,sp call msg.sm pop hl pop hl pop hl ret ;-------------------------------------------------------------- ; Check if characters in fifo ; Fifo is empty, if output index and input index are the same ff_empty: ld a,(ix+o.in_idx) ; sub (ix+o.out_idx) ; ret z or 0ffh ret ;-------------------------------------------------------------- ff_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 ret ;-------------------------------------------------------------- ; Check if room in fifo ; buffer is full, if output index is one behind input index ff_full: ld a,(ix+o.in_idx) ; inc a and (ix+o.mask) sub (ix+o.out_idx) ; ret z or 0ffh ret ;-------------------------------------------------------------- ; put character in c in buffer ; destroys hl, bc ; returns output char in a ff_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 ; ld a,b ; ret ; ;-------------------------------------------------------------- ; Return number of characters in fifo ; ff_cnt: ld a,(ix+o.in_idx) ; sub (ix+o.out_idx) ; ret nc add (ix+o.mask) inc a ret end