]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blobdiff - cbios/conbuf.180
time and date allways from server. 1.25ms interrupt
[z180-stamp-cpm3.git] / cbios / conbuf.180
index e8dfe31f38bf6d04922571bb8c4fcf1df9407342..75741e0ebd50bdca7488a3097df5b6f5541e68d5 100644 (file)
        include z180reg.inc\r
        endif\r
 \r
-\r
-       cseg\r
-\r
-       mkbuf   co.fifo_id, co.fifo, co.fifo_len\r
+       dseg\r
        mkbuf   ci.fifo_id, ci.fifo, ci.fifo_len\r
+       mkbuf   co.fifo_id, co.fifo, co.fifo_len\r
 \r
-ico    equ     co.fifo_id * 3\r
-ici    equ     ci.fifo_id * 3\r
+ici    equ     ci.fifo_id * 2\r
+ico    equ     co.fifo_id * 2\r
 \r
 \r
 ;--------------------------------------------------------------\r
 \r
 ; Init Serial I/O for console input and output\r
 ;\r
-\r
+       dseg\r
 ff.init:\r
        ld      a,(INIDONE)\r
        cp      INIDONEVAL\r
        ret     z\r
 \r
        ld      ix,ci.fifo\r
-       ld      a,ci.fifo.mask\r
        call    bufinit\r
        ld      ix,co.fifo\r
-       ld      a,co.fifo.mask\r
        jp      bufinit\r
 \r
 ;--------------------------------------------------------------\r
+; Input status\r
+; buffer is empty, if output index and input index are the same\r
 \r
+       dseg\r
 ff.ist:\r
        push    ix\r
        ld      ix,(fifolst+ici)        ;\r
@@ -55,41 +54,40 @@ buf.empty:
        ret\r
 \r
 \r
+;--------------------------------------------------------------\r
+; Output status\r
+; buffer is full, if output index is one behind input index\r
+\r
 ff.in:\r
        push    ix\r
        ld      ix,(fifolst+ici)        ;\r
 \r
 buf.get:\r
-       ld      a,(ix+o.out_idx)        ;\r
+       push    ix\r
+       pop     hl\r
+       ld      c,(ix+o.out_idx)        ;\r
+       ld      b,0\r
+       add     hl,bc\r
+       ld      a,c\r
 bg.wait:\r
        cp      (ix+o.in_idx)           ;\r
        jr      z,bg.wait\r
-\r
-       push    hl                      ;\r
-       push    ix\r
-       pop     hl\r
-       add     a,l\r
-       ld      l,a\r
-       jr      nc,bg.nc\r
-       inc     h\r
-bg.nc:\r
-       ld      l,(hl)\r
-\r
-       ld      a,(ix+o.out_idx)        ;\r
+       ld      b,(hl)\r
+       ld      a,c                     ;\r
        inc     a\r
        and     (ix+o.mask)\r
        ld      (ix+o.out_idx),a\r
-\r
-       ld      a,l\r
-       pop     hl\r
+       ld      a,b\r
        pop     ix\r
        ret\r
 \r
 ;--------------------------------------------------------------\r
+; Output status\r
+; buffer is full, if output index is one behind input index\r
 \r
 ff.ost:\r
        push    ix\r
-       ld      ix,(fifolst+ico)                ;\r
+       ld      ix,(fifolst+ico)        ;\r
 \r
 buf.full:\r
        ld      a,(ix+o.in_idx)         ;\r
@@ -102,70 +100,36 @@ buf.full:
        ret\r
 \r
 \r
-       if 1\r
-ff.out:\r
-       push    ix                      ;15\r
-       ld      ix,(fifolst+ico)        ;\r
-\r
-buf.put:\r
-       push    hl                      ;11\r
-       push    bc                      ;11\r
-       push    ix                      ;15\r
-       pop     hl                      ;10\r
-       ld      a,c                     ;4\r
-       ld      c,(ix+o.in_idx)         ;19\r
-       ld      b,0                     ;7\r
-       add     hl,bc                   ;11\r
-       ld      (hl),a                  ;7\r
-       ld      b,a                     ;4\r
-\r
-       ld      a,c                     ;4\r
-       inc     a                       ;4\r
-       and     (ix+o.mask)             ;19\r
-bp.wait:\r
-       cp      (ix+o.out_idx)          ;19\r
-       jr      z,bp.wait               ;12/7\r
-       ld      (ix+o.in_idx),a         ;19\r
-\r
-       out     (AVRINT6),a             ;11\r
-       ld      a,b                     ;4\r
-       pop     bc                      ;10\r
-       pop     hl                      ;10\r
-       pop     ix                      ;14\r
-       ret                             ;10\r
-\r
-       else\r
+;--------------------------------------------------------------\r
+; put character in c in buffer\r
+; destroys hl, bc\r
+; returns output char in a\r
 \r
 ff.out:\r
-       push    ix                      ;15\r
-       ld      ix,co.fifo              ;14\r
-\r
+       push    ix                      ;\r
+       ld      ix,(fifolst+ico)        ;\r
 buf.put:\r
-       push    hl                      ;11\r
-       push    ix                      ;15\r
-       pop     hl                      ;10\r
-       ld      a,(ix+o.in_idx)         ;19\r
-       add     a,l                     ;4\r
-       ld      l,a                     ;4\r
-       jr      nc,bp.1                 ;12/7\r
-       inc     l                       ;4\r
-       ld      (hl),c                  ;7\r
-       ld      a,(ix+o.in_idx)         ;19\r
-       inc     a                       ;4\r
-       and     (ix+o.mask)             ;19\r
-bp.wait:\r
-       cp      (ix+o.out_idx)          ;19\r
-       jr      z,bp.wait               ;12/7\r
-       ld      (ix+o.in_idx),a         ;19\r
-\r
-       out     (AVRINT6),a             ;11\r
-       ld      a,c                     ;4\r
-       pop     hl                      ;10\r
-       pop     ix                      ;14\r
-       ret                             ;10             |\r
-\r
-       endif\r
-\r
-;--------------------------------------------------------------\r
+       push    ix                      ;\r
+       pop     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
+\r
+       ld      a,c                     ; bump input index\r
+       inc     a                       ;\r
+       and     (ix+o.mask)             ;\r
+bp.wait:                               ; do\r
+       cp      (ix+o.out_idx)          ;\r
+       jr      z,bp.wait               ; while new input idx == ouput idx\r
+       ld      (ix+o.in_idx),a         ;\r
+\r
+       out     (AVRINT6),a             ; tell monitor\r
+       ld      a,b                     ;\r
+       pop     ix                      ;\r
+       ret                             ;\r
 \r
        end\r