summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2016-06-10 17:18:55 +0200
committerLeo C2016-06-10 17:18:55 +0200
commitaeb747d4d09db894700b4c7e53323284f20dece2 (patch)
tree64b48228071d99d9b9cbcbfbe8b47d464175c2ef
parentf1710b4798b98078e7d1c8d07691ec1aea03855f (diff)
downloadz180-stamp-cpm3-aeb747d4d09db894700b4c7e53323284f20dece2.zip
sdio, cfio: factor out common error message print routines
-rw-r--r--cbios/bioskrnl.1808
-rw-r--r--cbios/cfio.180166
-rw-r--r--cbios/sdio.180183
-rw-r--r--cbios/utils.180119
4 files changed, 220 insertions, 256 deletions
diff --git a/cbios/bioskrnl.180 b/cbios/bioskrnl.180
index dc04ed1..6c8366f 100644
--- a/cbios/bioskrnl.180
+++ b/cbios/bioskrnl.180
@@ -51,7 +51,7 @@ ccp equ 0100h ; Console Command Processor gets loaded
extrn @dtbl ; table of pointers to XDPHs
public @adrv,@rdrv,@trk,@sect ; parameters for disk I/O
public @dma,@dbnk,@cnt ; '' '' '' ''
- public @xdph
+ public @xdph,@op
; memory control
@@ -434,6 +434,7 @@ seldsk:
ld a,c ; save drive select code
ld (@adrv),a
xor a
+ ld (@op),a
ld (@cnt),a
ld b,a ; create index from drive code
ld hl,@dtbl
@@ -538,6 +539,8 @@ sectrn:
; extended disk parameter header (XDPH).
read:
+ ld a,1
+ ld (@op),a
ld ix,(@xdph) ; get drive descriptor pointer
ld l,(ix-8) ; get read routine entry
ld h,(ix-7)
@@ -550,6 +553,8 @@ read:
; extended disk parameter header (XDPH).
write:
+ ld a,2
+ ld (@op),a
ld ix,(@xdph) ; get drive descriptor pointer
ld l,(ix-10) ; get write routine entry
ld h,(ix- 9)
@@ -578,6 +583,7 @@ flush:
; do not change order. sd driver depends on this
@xdph: ds 2 ; pointer to currently selected drives dph
+@op ds 1 ; current disk operation 0:select, 1:read, 2 write
@adrv: ds 1 ; currently selected disk drive
@rdrv: ds 1 ; controller relative disk drive
@trk: ds 2 ; current track number
diff --git a/cbios/cfio.180 b/cbios/cfio.180
index a237bd6..5dd8a2e 100644
--- a/cbios/cfio.180
+++ b/cbios/cfio.180
@@ -12,26 +12,23 @@
extrn @xdph
extrn @adrv,@rdrv
extrn @trk,@sect,@cnt
- extrn @dma,@dbnk,@cbnk
+ extrn @dma,@dbnk
; System Control Block variables
extrn @ermde ; BDOS error mode
- ; Utility routines in standard BIOS
+ ; Utility routines
extrn ?wboot ; warm boot vector
- extrn ?pmsg,pr.inln ; print message @<HL>, print inline message
- extrn pr.crlf ; print <cr><lf>
- extrn phex2
- extrn pr.decl
- extrn ?pderr ; print BIOS disk error header
- extrn ?conin,?cono ; con in and out
- extrn ?const ; get console status
- extrn ?bnksl
-
- extrn bnk2phy ;
- extrn add_hla
+ extrn ?pmsg ; print message @<HL>
+ extrn pr.idx ; print indexed message
+ extrn pr.inln ; print inline message
+ extrn pr.decl ; print 32 bit decimal number
+ extrn pr.errors ; print BIOS disk error header
+ extrn ?cono ; console out
+ extrn bnk2phy ; translate banked to physical linear address
+ extrn add_hla ; add <A> to <HL>
extrn gstimer ; get timer short (16 bit)
; Port Address Equates
@@ -363,6 +360,8 @@ cfi_error:
ld a,1 ; return with A=1 on error
ret
+;-------------------------------------------------------------------------------
+; print char, skipping leading blanks
pr_char_nlbl:
bit 0,b
@@ -371,6 +370,9 @@ pr_char_nlbl:
ret z
res 0,b
; fall thru
+
+; print character, saving hl, de, bc
+
pr_char:
push hl
push de
@@ -615,24 +617,23 @@ cf$login:
; disk READ and WRITE entry points.
; these entries are called with the following arguments:
;
-; absolute drive number in @adrv (8 bits) +0
-; relative drive number in @rdrv (8 bits) +1
-; disk track address in @trk (16 bits) +2
-; disk sector address in @sect(16 bits) +4
-; multi sector count in @cnt (8 bits) +6
-; disk transfer address in @dma (16 bits) +7
-; disk transfer bank in @dbnk (8 bits) +9
+; operation type (r/w) in @op (8 bits) +0
+; absolute drive number in @adrv (8 bits) +1
+; relative drive number in @rdrv (8 bits) +2
+; disk track address in @trk (16 bits) +3
+; disk sector address in @sect(16 bits) +5
+; multi sector count in @cnt (8 bits) +7
+; disk transfer address in @dma (16 bits) +8
+; disk transfer bank in @dbnk (8 bits) +10
; pointer to XDPH in <DE>
;
; they transfer the appropriate data, perform retries
; if necessary, then return an error code in <A>
cf$read:
- ld de,read$msg ; point at " Read "
ld bc,M_DIM1*256 + CmdRd ; Transfermode: i/o to memory++
jr rw$common
cf$write:
- ld de,write$msg ; point at " Write "
ld bc,0*256 + CmdWr ; Transfermode: memory++ to i/o
rw$common:
@@ -648,7 +649,6 @@ rw$common:
endif
rwc_new_sectors:
- ld (operation$name),de ; save message for errors
in0 a,(dcntl)
and a,~(M_DMS1+M_DIM1+M_DIM0)
or b
@@ -764,114 +764,56 @@ err_out:
and 10001001b ; Busy, DRQ, or Error?
ret z ; Return to BDOS if no error
-; suppress error message if BDOS is returning errors to application...
-
- ld a,(@ermde)
- cp 0ffh
- jr z,hard$error
-
- ; Had permanent error, print message like:
- ; BIOS Err on d: T-nn, S-mm, <operation> <type>, Retry ?
+ ld hl,print_details
+ call pr.errors
+ jp z,retry ; Yes, then retry once more
+ ; otherwise,
+ xor a
+ ld (residual),a
- call ?pderr ; print message header
+ ld a,1 ; return hard error to BDOS
+ ret
- ld hl,(operation$name)
- call ?pmsg ; last function (read or write)
+;-------------------------------------------------------------------------------
+print_details:
ld hl,msg$drq
bit 3,e
call nz,?pmsg
bit 0,e
- jr z,prompt
+ ret z
in a,(IDEErr)
- ld hl,error$table ; point at table of message addresses
+ ld e,8
errm1:
- ld e,(hl)
- inc hl
- ld d,(hl)
- inc hl ; get next message address
- add a,a
- push af ; shift left and push residual bits with status
- ex de,hl
- call c,?pmsg
- ex de,hl ; print message, saving table pointer
- pop af
- jr nz,errm1 ; if any more bits left, continue
-
-prompt:
- call pr.inln
- db ' Retry (Y/N) ? ',0
-
- call u$conin$echo ; get operator response
- cp 'Y'
- jp z,retry ; Yes, then retry
-
-hard$error:
- ; otherwise,
- xor a
- ld (residual),a
-
- ld a,1 ; return hard error to BDOS
- ret
-
-cancel: ; here to abort job
- jp ?wboot ; leap directly to warmstart vector
-
-
-; get console input, echo it, and shift to upper case
-
-u$conin$echo:
- 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
+ ld hl,b0$msg ; point at message[0]
+ dec e ; index of next message
+ add a,a ; shift left and push residual bits with status
push af
- ld c,a
- cp ' '-1
- call nc,?cono
+ ld a,e
+ call c,pr.idx ; print it, if bit is set.
pop af
- pop bc
- cp 'a'
- ret c
- sub 'a'-'A' ; make upper case
+ jr nz,errm1 ; if any more bits left, continue
ret
- ; error message components
+;-------------------------------------------------------------------------------
+; error message components
-operation$name:
- dw read$msg
-read$msg:
- db ', Read, ',0
-write$msg:
- db ', Write, ',0
msg$drq:
db 'DRQ, ',0
-error$table:
- dw b7$msg
- dw b6$msg
- dw b5$msg
- dw b4$msg
- dw b3$msg
- dw b2$msg
- dw b1$msg
- dw b0$msg
-
-b7$msg: db ' Bad Block detected,',0
-b6$msg: db ' Uncorrectable Data Error,',0
-b5$msg: db ' Media Changed,',0
-b4$msg: db ' Sector ID Not Found,',0
-b3$msg: db ' Media Change Requst,',0
-b2$msg: db ' Aborted Command,',0
-b1$msg: db ' Track 0 Not Found,',0
-b0$msg: db ' AM Not Found (or general error),',0
+b7$msg: db ' Bad Block detected,',0
+b6$msg: db ' Uncorrectable Data Error,',0
+b5$msg: db ' Media Changed,',0
+b4$msg: db ' Sector ID Not Found,',0
+b3$msg: db ' Media Change Requst,',0
+b2$msg: db ' Aborted Command,',0
+b1$msg: db ' Track 0 Not Found,',0
+b0$msg: db ' AM Not Found (or general error),',0
+ db 0
+
+;-------------------------------------------------------------------------------
residual:
db 0
diff --git a/cbios/sdio.180 b/cbios/sdio.180
index 774ed12..28ed4dd 100644
--- a/cbios/sdio.180
+++ b/cbios/sdio.180
@@ -10,7 +10,7 @@
; Variables containing parameters passed by BDOS
- extrn @xdph
+ extrn @xdph,@op
extrn @adrv,@rdrv
extrn @trk,@sect,@cnt
extrn @dma,@dbnk
@@ -19,19 +19,17 @@
extrn @ermde ; BDOS error mode
- ; Utility routines in standard BIOS
+ ; Utility routines
extrn ?wboot ; warm boot vector
- extrn ?pmsg,pr.inln ; print message @<HL>, print inline message
- extrn pr.crlf ; print <cr><lf>
- extrn ?pderr ; print BIOS disk error header
- extrn ?conin,?cono ; con in and out
- extrn ?const ; get console status
-
- extrn bnk2phy ;
- extrn msg.sm ;
- extrn msg.recv ;
- extrn add_hla
+ extrn ?pmsg ; print message @<HL>
+ extrn pr.idx ; print indexed message
+ extrn pr.inln,pr.crlf ; print inline message, print <cr><lf>
+ extrn pr.errors ; print BIOS disk error header
+ extrn bnk2phy ; translate banked to physical linear address
+ extrn msg.sm ; send message to AVR
+ extrn msg.recv ; receive message from AVR
+ extrn add_hla ; add <A> to <HL>
; Port Address Equates
@@ -41,7 +39,7 @@
; CP/M 3 Disk definition macros
- include cpm3slr.lib
+ maclib cpm3slr.lib
; Z180 macro library instruction definitions (ignored by slr180)
@@ -207,27 +205,21 @@ sd$login:
; disk READ and WRITE entry points.
; these entries are called with the following arguments:
;
-; absolute drive number in @adrv (8 bits) +0
-; relative drive number in @rdrv (8 bits) +1
-; disk track address in @trk (16 bits) +2
-; disk sector address in @sect(16 bits) +4
-; multi sector count in @cnt (8 bits) +6
-; disk transfer address in @dma (16 bits) +7
-; disk transfer bank in @dbnk (8 bits) +9
+; operation type (r/w) in @op (8 bits) +0
+; absolute drive number in @adrv (8 bits) +1
+; relative drive number in @rdrv (8 bits) +2
+; disk track address in @trk (16 bits) +3
+; disk sector address in @sect(16 bits) +5
+; multi sector count in @cnt (8 bits) +7
+; disk transfer address in @dma (16 bits) +8
+; disk transfer bank in @dbnk (8 bits) +10
; pointer to XDPH in <DE>
;
; they transfer the appropriate data, perform retries
; if necessary, then return an error code in <A>
sd$read:
- ld de,read$msg ; point at " Read "
- ld c,1
- jr rw$common
sd$write:
- ld de,write$msg ; point at " Write "
- ld c,2
-rw$common:
-
ld hl,residual ; remainng sectors from last multi io?
ld a,(hl)
sub a,1
@@ -254,14 +246,10 @@ rwc_new_sectors:
; and send it to AVR.
rwc_doit:
- ld hl,send_msg+1
- ld (hl),c
- inc hl
ld a,b
- ex de,hl
- ld (operation$name),hl ; save message for errors
- ld hl,@adrv ;address of arguments
- ld bc,6
+ ld hl,@op ;address of arguments
+ ld de,send_msg+1
+ ld bc,7
ldir
ld (de),a ;number of sectors
inc de
@@ -294,50 +282,9 @@ retry:
or a
ret z ; check status and return to BDOS if no error
-; suppress error message if BDOS is returning errors to application...
-
- ld a,(@ermde)
- cp 0ffh
- jr z,hard$error
-
- ; Had permanent error, print message like:
- ; BIOS Err on d: T-nn, S-mm, <operation> <type>, Retry ?
-
- call ?pderr ; print message header
-
- ld hl,(operation$name)
- call ?pmsg ; last function (read or write)
-
- ld a,(recv_msg_rc)
- and a,07fh
- jr z,fatfs_err
-
- ld hl,drvmsg0 ; point at first driver error message
- ld c,drvmsg_count
- call pdecoded
-
-fatfs_err:
- ld a,(recv_msg_rc)
- tst 080h
- jr z,prompt ; no fatfs error
-
- call pr.inln
- db 'FatFs: ',0
-
- ld hl,fr$msg0 ; point at first FatFs message
- ld c,fr$msg$count
- ld a,(recv_msg_rc+1)
- call pdecoded
-
-prompt:
- call pr.inln
- db ' Retry (Y/N) ? ',0
-
- call u$conin$echo ; get operator response
- cp 'Y'
+ ld hl,print_details
+ call pr.errors
jr z,retry ; Yes, then retry once more
-
-hard$error:
; otherwise,
xor a
ld (residual),a
@@ -353,59 +300,32 @@ e_exit:
ld a,c
ret
-; Print message to error code in A
-;
+;-------------------------------------------------------------------------------
-pdecoded:
- push bc
- push de
- push hl ; put pointer to first message on stack
- cp c
- jr c,pdc_1
- xor a
-pdc_1:
- ld bc,0
- ld e,a ; save message number
- xor a
- inc e
-pdc_nxt_str:
- dec e
- ex (sp),hl
- jr z,pdc_found
- ex (sp),hl
- cpir
- jr z,pdc_nxt_str
- ; not found (should not happen)
-pdc_found:
- pop hl
- call ?pmsg
- pop de
- pop bc
- ret
+print_details:
+ ld a,(recv_msg_rc)
+ push af
+ and a,07fh
+ jr z,fatfs_err
+ ld hl,drvmsg0 ; point at first driver error message
+ call pr.idx
-; get console input, echo it, and shift to upper case
+fatfs_err:
+ pop af
+ and 080h
+ ret z ; no fatfs error
-u$conin$echo:
+ call pr.inln
+ db 'FatFs: ',0
- call ?const
- or a
- jr z,u$c1 ; see if any char already struck
- call ?conin
- jr u$conin$echo ; yes, eat it and try again
-u$c1:
- call ?conin
- push af
- ld c,a
- cp ' '-1
- call nc,?cono
- pop af
- cp 'a'
- ret c
- sub 'a'-'A' ; make upper case
- ret
+ ld hl,fr$msg0 ; point at first FatFs message
+ ld a,(recv_msg_rc+1)
+ jp pr.idx ; return via print routine
+;-------------------------------------------------------------------------------
+
residual:
db 0
@@ -433,15 +353,8 @@ recv_msg_rc:
recv_msg_len equ $ - recv_msg
- ; error message components
-
-operation$name:
- dw read$msg
-read$msg:
- db ', Read, ',0
-write$msg:
- db ', Write, ',0
-
+;-------------------------------------------------------------------------------
+; error message components
; general driver errors
drvmsg0: db 'Unknown Error, ',0
@@ -451,8 +364,7 @@ drvmsg3: db 'Bus Timeout, ',0
drvmsg4: db 'Access beyond disk size, ',0
drvmsg5: db 'Write protected, ',0
drvmsg6: db 'No media, ',0
-drvmsg_size equ $ - drvmsg0
-drvmsg_count equ 7
+ db 0
; fat file system errors
@@ -477,7 +389,6 @@ fr$msg17: db 'NOT_ENOUGH_CORE,',0
fr$msg18: db 'TOO_MANY_OPEN_FILES,',0
fr$msg19: db 'FR_INVALID_PARAMETER,',0
fr$msg20: db 'short read/write,',0
-fr$msg$size equ $ - fr$msg0
-fr$msg$count equ 21
+ db 0
end
diff --git a/cbios/utils.180 b/cbios/utils.180
index bbe5ac3..4a91641 100644
--- a/cbios/utils.180
+++ b/cbios/utils.180
@@ -12,15 +12,15 @@
; 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
;-------------------------------------------------------------------------------
@@ -222,6 +222,36 @@ pmsg$exit:
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 +409,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