From 81ba3c8469440da99c8f9ff70457a8e2f05398b7 Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 2 Nov 2015 16:56:18 +0100 Subject: [PATCH] working again. rx status fifo. loop asci0 int till asci0 rx fifo empty --- cbios/ascii.180 | 77 +++++++++++++++++++++------------------- cbios/bioskrnl.180 | 19 ++++++++++ cbios/fifo.180 | 87 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 140 insertions(+), 43 deletions(-) diff --git a/cbios/ascii.180 b/cbios/ascii.180 index 54ee706..7d6afbf 100644 --- a/cbios/ascii.180 +++ b/cbios/ascii.180 @@ -10,7 +10,8 @@ global as1osta,as1out extrn as_init - extrn ff_empty,ff_get,ff_full,ff_put,ff_cnt + extrn ff_empty,ff_get,ff_full,ff_put + extrn ff_puth,ff_cnt,ff_gech extrn bufinit extrn isv_sw @@ -26,9 +27,11 @@ dseg mkbuf s0.rx_id, s0.inbuf, s0.rx_len + mkbuf 0, s0.instatbuf, s0.rx_len mkbuf s0.tx_id, s0.outbuf,s0.tx_len mkbuf s1.rx_id, s1.inbuf, s1.rx_len - mkbuf s1.tx_id, s1.outbuf, s1.tx_len + mkbuf 0, s1.instatbuf, s1.rx_len + mkbuf s1.tx_id, s1.outbuf,s1.tx_len @@ -120,8 +123,9 @@ as1ista: as0inp: push ix ld ix,s0.inbuf ; - call ff_cnt - cp 32 + call ff_gech + ld a,b + cp s0.rx_len/4 jr nc,a0i_1 di in0 a,(cntla0) @@ -130,7 +134,7 @@ as0inp: ei out0 (cntla0),a a0i_1: - call ff_get + ld a,c pop ix ret @@ -140,7 +144,7 @@ a0i_1: as1inp: push ix ld ix,s1.inbuf ; - call ff_get + call ff_gech pop ix ret @@ -172,13 +176,13 @@ as1osta: as0out: push ix ; ld ix,s0.outbuf ; - call ff_put + call ff_puth + pop ix ; di ; in0 c,(stat0) ; set TIE,c ; out0 (stat0),c ; ei ; - pop ix ; ret ;-------------------------------------------------------------- @@ -189,13 +193,13 @@ as0out: as1out: push ix ; ld ix,s1.outbuf ; - call ff_put + call ff_puth + pop ix ; di ; in0 c,(stat1) ; set TIE,c ; out0 (stat1),c ; ei ; - pop ix ; ret @@ -205,9 +209,10 @@ as1out: dseg rxtxi0: push ix -rxtxi0_0: +rxtxi0_loop: in0 e,(stat0) ;receive flag set? - jp p,rxtxi0_1 ; + jp p,rxtxi0_1 ;RDRF == Bit 7 + rxi_0 in0 a,(asext0) ;todo: break detection @@ -219,39 +224,41 @@ rxi_0 res EFR,d ; ld ix,s0.inbuf ; - ld hl,s0.inbuf ; - ld c,(ix+o.in_idx) ;-2 + ld c,(ix+o.in_idx) ; ld b,0 + ld hl,s0.inbuf ; add hl,bc in0 a,(rdr0) ; ld (hl),a - bit FE,e ;framing error? - jr nz,?0ri_1 + ld hl,s0.instatbuf ;save error status + add hl,bc + ld (hl),e + ;todo: error handling and break detection ld a,c ;increment buffer in pointer inc a ; - and (ix+o.mask) ;-3 + ld b,(ix+o.mask) ; + and b ; ld c,a - inc hl - jr z,$+5 - ld hl,s0.inbuf ; - sub (ix+o.out_idx) ;-1 + + sub (ix+o.out_idx) ; jr z,$+5 ;skip if buffer is full - ld (ix+o.in_idx),c ;-2 - jr nc,$+6 - add (ix+o.mask) ;-3 - inc a - cp 96 + ld (ix+o.in_idx),c ; + jr nc,$+3 ; + adc b ; + cp s0.tx_len*3/4 jr c,$+4 set RTS0,d ;RTS inactive ?0ri_1: out0 (cntla0),d ; - jr rxtxi0_0 + jr rxtxi0_loop + rxtxi0_1: bit TDRE,e ;TX int? - jr z,rxtxi0_e + jr z,rxtxi0_e ; + ld ix,s0.outbuf ; @@ -263,30 +270,30 @@ rxtxi0_1: ld c,a ld b,0 add hl,bc - ld l,(hl) - out0 (tdr0),l ; 7 + ld b,(hl) + out0 (tdr0),b ; 7 inc a and (ix+o.mask) ld (ix+o.out_idx),a - jr ?0ti_3 + jr rxtxi0_loop + ?0ti_2: res TIE,e ;disable tx-int out0 (stat0),e ; 5 -?0ti_3: - jr rxtxi0_0 rxtxi0_e: pop ix ret + ;------------------------------------------ ; ASCI 1 Transmit/Receive interupt routines dseg rxtxi1: in0 e,(stat1) ;receive flag set? 5 - jp p,txisv1 ; + jp p,txi1_0 ; in0 d,(rdr1) ;todo: break detection 9 bit FE,e ;framing error? @@ -313,7 +320,7 @@ rxtxi1: out0 (cntla1),a ; 1 ret -txisv1: +txi1_0: push ix ld ix,s1.outbuf ; diff --git a/cbios/bioskrnl.180 b/cbios/bioskrnl.180 index 6c8366f..2a63494 100644 --- a/cbios/bioskrnl.180 +++ b/cbios/bioskrnl.180 @@ -381,12 +381,31 @@ auxin: conin: ld hl,(@civec) + ;check if only one device assigned + + push hl ; save bit vector + ld b,0 +insc_0: + or a ; clear carry + adc hl,hl ; shift out next bit + jr nc,insc_1 ; + jr z,ci$rdy ; single device + jr ci$check ; + +insc_1: + inc b ; else, next device + ld a,h + or l ; see if any more devices + jr nz,insc_0 ; no, + pop hl + in$scan: push hl ; save bit vector ld b,0 ci$next: xor a ; assume next device not ready add hl,hl ; shift out next bit +ci$check: call c,cist1 ; see if the device has a character jr nz,ci$rdy ; this device has a character inc b ; else, next device diff --git a/cbios/fifo.180 b/cbios/fifo.180 index ebcecd9..290eb00 100644 --- a/cbios/fifo.180 +++ b/cbios/fifo.180 @@ -1,6 +1,7 @@ public bufinit - public ff_empty,ff_get,ff_full,ff_put, ff_cnt + public ff_empty,ff_get,ff_full,ff_put + public ff_puth,ff_cnt,ff_gech public fifolst @@ -81,6 +82,11 @@ ff_empty: ret ;-------------------------------------------------------------- +; get character from fifo +; destroys hl,b +; +; return: +; c,a: next character ff_get: push ix @@ -92,22 +98,58 @@ ff_get: bg.wait: cp (ix+o.in_idx) ; jr z,bg.wait - ld b,(hl) - ld a,c ; inc a and (ix+o.mask) + ld c,(hl) ld (ix+o.out_idx),a - ld a,b + ld a,c + ret + +;-------------------------------------------------------------- +; get character and ramaining count from fifo +; halt cpu, while buffer is empty +; destroys hl +; +; return: +; c,a: next character +; b: number of charachters in fifo + +ff_gech: + push ix + pop hl + ld c,(ix+o.out_idx) ; + ld b,0 + add hl,bc + jr $+3 +gech.wait: + halt + ld a,(ix+o.in_idx) ; + sub c + jr z,gech.wait + jr nc,$+5 + adc (ix+o.mask) ; mask+carry == buffer size + dec a + ld b,a + ld a,c + inc a + and (ix+o.mask) + ld c,(hl) + ld (ix+o.out_idx),a + ld a,c ret ;-------------------------------------------------------------- ; Check if room in fifo ; buffer is full, if output index is one behind input index +; +; return +; a = 0 and z if buffer full +; a = ff and nz if buffer not full ff_full: ld a,(ix+o.in_idx) ; - inc a - and (ix+o.mask) + inc a ; + and (ix+o.mask) ; sub (ix+o.out_idx) ; ret z or 0ffh @@ -140,6 +182,35 @@ bp.wait: ; do ld a,b ; ret ; +;-------------------------------------------------------------- +; put character in c in buffer +; halt cpu, while buffer is is full +; destroys hl, bc +; returns output char in a + +ff_puth: + 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) ; + jr $+3 +bph.wait: ; do + halt ; halt cpu + cp (ix+o.out_idx) ; + jr z,bph.wait ; while new input idx == ouput idx + ld (ix+o.in_idx),a ; + ld a,b ; + ret ; + ;-------------------------------------------------------------- ; Return number of characters in fifo ; @@ -148,9 +219,9 @@ ff_cnt: ld a,(ix+o.in_idx) ; sub (ix+o.out_idx) ; ret nc - add (ix+o.mask) - inc a + adc (ix+o.mask) ; mask+carry == buffer size ret +;-------------------------------------------------------------- end -- 2.39.2