X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp-cpm3.git/blobdiff_plain/b43b466252b6733ba9d76a5858d5afa2a6313ad1..3ba537752998f2d8554cecee5d586fd1a70256b6:/cbios/conbuf.180 diff --git a/cbios/conbuf.180 b/cbios/conbuf.180 index ef11813..75741e0 100644 --- a/cbios/conbuf.180 +++ b/cbios/conbuf.180 @@ -13,35 +13,34 @@ include z180reg.inc endif - - cseg - + dseg mkbuf ci.fifo_id, ci.fifo, ci.fifo_len mkbuf co.fifo_id, co.fifo, co.fifo_len -ici equ ci.fifo_id * 3 -ico equ co.fifo_id * 3 +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 - ld a,ci.fifo.mask call bufinit ld ix,co.fifo - ld a,co.fifo.mask 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) ; @@ -55,41 +54,40 @@ buf.empty: ret +;-------------------------------------------------------------- +; Output status +; buffer is full, if output index is one behind input index + ff.in: push ix ld ix,(fifolst+ici) ; buf.get: - ld a,(ix+o.out_idx) ; + 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 - - 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) ; + ld b,(hl) + ld a,c ; inc a and (ix+o.mask) ld (ix+o.out_idx),a - - ld a,l - pop hl + 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) ; + ld ix,(fifolst+ico) ; buf.full: ld a,(ix+o.in_idx) ; @@ -102,70 +100,36 @@ buf.full: ret - if 1 -ff.out: - push ix ;15 - ld ix,(fifolst+ico) ; - -buf.put: - push hl ;11 - push bc ;11 - push ix ;15 - pop hl ;10 - ld a,c ;4 - ld c,(ix+o.in_idx) ;19 - ld b,0 ;7 - add hl,bc ;11 - ld (hl),a ;7 - ld b,a ;4 - - ld a,c ;4 - inc a ;4 - and (ix+o.mask) ;19 -bp.wait: - cp (ix+o.out_idx) ;19 - jr z,bp.wait ;12/7 - ld (ix+o.in_idx),a ;19 - - out (AVRINT6),a ;11 - ld a,b ;4 - pop bc ;10 - pop hl ;10 - pop ix ;14 - ret ;10 - - else +;-------------------------------------------------------------- +; put character in c in buffer +; destroys hl, bc +; returns output char in a ff.out: - push ix ;15 - ld ix,co.fifo ;14 - + push ix ; + ld ix,(fifolst+ico) ; buf.put: - push hl ;11 - push ix ;15 - pop hl ;10 - ld a,(ix+o.in_idx) ;19 - add a,l ;4 - ld l,a ;4 - jr nc,bp.1 ;12/7 - inc l ;4 - ld (hl),c ;7 - ld a,(ix+o.in_idx) ;19 - inc a ;4 - and (ix+o.mask) ;19 -bp.wait: - cp (ix+o.out_idx) ;19 - jr z,bp.wait ;12/7 - ld (ix+o.in_idx),a ;19 - - out (AVRINT6),a ;11 - ld a,c ;4 - pop hl ;10 - pop ix ;14 - ret ;10 | - - endif - -;-------------------------------------------------------------- + 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