]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blobdiff - cbios/utils.180
add ioctl data
[z180-stamp-cpm3.git] / cbios / utils.180
index f682d443e70c5b1b633fbb993c06c012357099a2..a84d2171ec14e4fed661969c729e223226057c01 100644 (file)
@@ -1,3 +1,4 @@
+==== BASE ====
        title 'general utility routines'
 
        ; i/o port init routines
@@ -6,21 +7,24 @@
 
        ; math
 
+       public ijphl                    ; vectored CALL point
        public add_hla                  ; add a to hl
        public div32_16,div32_r         ; divide 32 bit by 16 bit number (rounded)
 
        ; print utils
 
        public ?pmsg                    ; print message
+       public pr.idx                   ; print message from table indexed by <A>
        public pr.inln,pr.crlf          ; print message inline, print newline
-       public phex2,phex4              ; print 2 digit hex (A) or 4 digit hex (HL)
+       public phex2,phex4              ; print 2 digit hex <A> or 4 digit hex <HL>
        public pr.dec,pr.decl           ; print 16 or 32 bit decimal number
-       public ?pderr                   ; print BIOS disk error message header
+       public pr.errors                ; print BIOS disk error message header
 
 
 
-       extrn ?cono
+       extrn ?const,?conin,?cono
        extrn @adrv,@trk,@sect          ; used by disk error message
+       extrn @op,@ermde
 
 ;-------------------------------------------------------------------------------
 
@@ -81,6 +85,11 @@ io1_nxt:
 
        pop     bc
        ret
+;--------------------------------------------------------------------
+; vectored CALL point
+
+ijphl:
+       jp      (hl)
 
 ;--------------------------------------------------------------------
 ; add a to hl
@@ -99,7 +108,7 @@ add_hla:
 ;--------------------------------------------------------------------
 ; rounded div 32 by 16 bit
 ;
-;      HLDE:   Dividend (x)
+;      DEHL:   Dividend (x)
 ;      BC:     Divisor  (y)
 ;    return:
 ;      HLDE:   Rounded Quotient (q)
@@ -112,7 +121,7 @@ div32_r:
        add     hl,bc           ;low x + y/2
        pop     bc
        jr      nc,div_r1
-       inc     hl
+       inc     de
 div_r1:
        ;fall thru
 
@@ -208,19 +217,49 @@ div_no_restore:                   ;
        push    de
 pmsg$loop:
        ld      a,(hl)
+       inc     hl
        or      a
        jr      z,pmsg$exit
        ld      c,a
        push    hl
        call    ?cono
        pop     hl
-       inc     hl
        jr      pmsg$loop
 pmsg$exit:
        pop     de
        pop     bc
        ret
 
+;-------------------------------------------------------------------------------
+; print message from table @<HL>, indexed by <A>
+; saves <BC> & <DE>
+
+pr.idx:
+       push    bc
+       push    de
+       push    hl              ; put pointer to first message on stack
+       ld      e,a             ; save message number
+       xor     a
+       ld      b,a
+       ld      c,a
+       inc     e
+pdc_nxt_str:
+       dec     e
+       ex      (sp),hl
+       jr      z,pdc_found
+       ex      (sp),hl
+       cpir
+       cp      (hl)
+       jr      nz,pdc_nxt_str
+                               ; End of List, msg not found.
+                               ; Print first msg.
+pdc_found:
+       pop     hl
+       call    ?pmsg
+       pop     de
+       pop     bc
+       ret
+
 ;-------------------------------------------------------------------------------
 ; print message inline up to a null
 ; saves all registers
@@ -379,10 +418,85 @@ prd_out:
        ld      hl,sector$msg
        call    ?pmsg           ; sector header
        ld      hl,(@sect)
-       call    pr.dec          ; sector number
-       ret
+       jp      pr.dec          ; sector number
 
        ; error message components
 drive$msg:     db      cr,lf,bell,'BIOS Error on ',0
 track$msg:     db      ': T-',0
 sector$msg:    db      ', S-',0
+
+
+;-------------------------------------------------------------------------------
+; get console input, echo it, and shift to upper case
+; save hl,de,bc
+
+uciecho:
+       push    hl
+       push    de
+       push    bc
+u$c0:
+       call    ?const
+       or      a
+       jr      z,u$c1          ; see if any char already struck
+       call    ?conin
+       jr      u$c0            ; yes, eat it and try again
+u$c1:
+       call    ?conin
+       push    af
+       ld      c,a
+       cp      ' '-1
+       call    nc,?cono
+       pop     af
+       pop     bc
+       pop     de
+       pop     hl
+       cp      'a'
+       ret     c
+       sub     'a'-'A'         ; make upper case
+       ret
+
+;-------------------------------------------------------------------------------
+;
+
+pr.errors:
+
+       ; suppress error message if BDOS
+       ; is returning errors to application...
+
+       ld      a,(@ermde)
+       inc     a
+       jr      nz,pre1
+       dec     a               ;return NZ, if @ermde == 0FFH
+       ret
+pre1:
+       push    hl
+       ld      hl,pre2
+       ex      (sp),hl
+       push    hl
+
+       ; Had permanent error, print message like:
+       ; BIOS Err on d: T-nn, S-mm, <operation> <type>, Retry ?
+
+       call    ?pderr          ; print message header
+
+       ld      hl,op$msg
+       ld      a,(@op)
+       jp      pr.idx          ; last function (read or write)
+
+pre2:
+                               ; prompt for retry
+       call    pr.inln
+       db      ' Retry (Y/N) ? ',0
+
+       call    uciecho         ; get operator response
+       cp      'Y'
+       ret                     ; return Z-flag for yes
+
+
+op$msg:
+       db      ', Unknown op, ',0
+       db      ', Read, ',0
+       db      ', Write, ',0
+       db      0
+
+       end