]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blobdiff - cbios/fifo.180
Update IXON flag from character device table (@ctbl)
[z180-stamp-cpm3.git] / cbios / fifo.180
index ebcecd9c0e473b9d80abbb4b6860e489ee7de601..ded979a6db09cec39402a565fe16b22c5bafce48 100644 (file)
@@ -1,13 +1,14 @@
 \r
        public  bufinit\r
-       public  ff_empty,ff_get,ff_full,ff_put, ff_cnt\r
+       public  ff_empty,ff_get,ff_full,ff_put\r
+       public  ff_puth,ff_cnt,ff_gech\r
 \r
        public  fifolst\r
 \r
        extrn   msg.sm,hwl2phy\r
 \r
-       include config.inc\r
-       include z180reg.inc\r
+       maclib z180reg.inc\r
+       maclib config.inc\r
 \r
 \r
 ;--------------------------------------------------------------------\r
@@ -81,6 +82,11 @@ ff_empty:
        ret\r
 \r
 ;--------------------------------------------------------------\r
+; get character from fifo\r
+; destroys hl,b\r
+;\r
+; return:\r
+;      c,a: next character\r
 \r
 ff_get:\r
        push    ix\r
@@ -92,22 +98,58 @@ ff_get:
 bg.wait:\r
        cp      (ix+o.in_idx)           ;\r
        jr      z,bg.wait\r
-       ld      b,(hl)\r
-       ld      a,c                     ;\r
        inc     a\r
        and     (ix+o.mask)\r
+       ld      c,(hl)\r
+       ld      (ix+o.out_idx),a\r
+       ld      a,c\r
+       ret\r
+\r
+;--------------------------------------------------------------\r
+; get character and ramaining count from fifo\r
+; halt cpu, while buffer is empty\r
+; destroys hl\r
+;\r
+; return:\r
+;      c,a: next character\r
+;      b:   number of charachters in fifo\r
+\r
+ff_gech:\r
+       push    ix\r
+       pop     hl\r
+       ld      c,(ix+o.out_idx)        ;\r
+       ld      b,0\r
+       add     hl,bc\r
+gech.wait:\r
+       ld      a,(ix+o.in_idx)         ;\r
+       sub     c\r
+       jr      nz,gech.cont\r
+       halt\r
+       jr      gech.wait\r
+gech.cont:\r
+       and     (ix+o.mask)             ;\r
+       dec     a\r
+       ld      b,a\r
+       ld      a,c\r
+       inc     a\r
+       and     (ix+o.mask)\r
+       ld      c,(hl)\r
        ld      (ix+o.out_idx),a\r
-       ld      a,b\r
+       ld      a,c\r
        ret\r
 \r
 ;--------------------------------------------------------------\r
 ; Check if room in fifo\r
 ; buffer is full, if output index is one behind input index\r
+;\r
+; return\r
+;   a = 0 and z    if buffer full\r
+;   a = ff and nz  if buffer not full\r
 \r
 ff_full:\r
        ld      a,(ix+o.in_idx)         ;\r
-       inc     a\r
-       and     (ix+o.mask)\r
+       inc     a                       ;\r
+       and     (ix+o.mask)             ;\r
        sub     (ix+o.out_idx)          ;\r
        ret     z\r
        or      0ffh\r
@@ -116,19 +158,18 @@ ff_full:
 \r
 ;--------------------------------------------------------------\r
 ; put character in c in buffer\r
-; destroys hl, bc\r
-; returns output char in a\r
+; destroys bc\r
 \r
 ff_put:\r
        push    ix                      ;\r
-       pop     hl                      ; get buffer start address\r
+       ex      (sp),hl                 ; get buffer start address\r
 \r
        ld      a,c                     ;\r
        ld      c,(ix+o.in_idx)         ; add input index\r
        ld      b,0                     ;\r
        add     hl,bc                   ;\r
        ld      (hl),a                  ; one place is allways free\r
-       ld      b,a                     ;\r
+       pop     hl                      ; restore hl\r
 \r
        ld      a,c                     ; bump input index\r
        inc     a                       ;\r
@@ -137,7 +178,33 @@ bp.wait:                           ; do
        cp      (ix+o.out_idx)          ;\r
        jr      z,bp.wait               ; while new input idx == ouput idx\r
        ld      (ix+o.in_idx),a         ;\r
-       ld      a,b                     ;\r
+       ret                             ;\r
+\r
+;--------------------------------------------------------------\r
+; put character in c in buffer\r
+; halt cpu, while buffer is is full\r
+; destroys bc\r
+\r
+ff_puth:\r
+       push    ix                      ;\r
+       ex      (sp),hl                 ; get buffer start address\r
+\r
+       ld      a,c                     ;\r
+       ld      c,(ix+o.in_idx)         ; add input index\r
+       ld      b,0                     ;\r
+       add     hl,bc                   ;\r
+       ld      (hl),a                  ; one place is allways free\r
+       pop     hl                      ; restore hl\r
+\r
+       ld      a,c                     ; bump input index\r
+       inc     a                       ;\r
+       and     (ix+o.mask)             ;\r
+       jr      $+3\r
+bph.wait:                              ; do\r
+       halt                            ;   halt cpu\r
+       cp      (ix+o.out_idx)          ;\r
+       jr      z,bph.wait              ; while new input idx == ouput idx\r
+       ld      (ix+o.in_idx),a         ;\r
        ret                             ;\r
 \r
 ;--------------------------------------------------------------\r
@@ -147,10 +214,9 @@ bp.wait:                           ; do
 ff_cnt:\r
        ld      a,(ix+o.in_idx)         ;\r
        sub     (ix+o.out_idx)          ;\r
-       ret     nc\r
-       add     (ix+o.mask)\r
-       inc     a\r
+       and     (ix+o.mask)             ;\r
        ret\r
 \r
+;--------------------------------------------------------------\r
 \r
        end\r