extrn @xdph\r
extrn @adrv,@rdrv\r
extrn @trk,@sect,@cnt\r
- extrn @dma,@dbnk,@cbnk\r
+ extrn @dma,@dbnk\r
\r
; System Control Block variables\r
\r
extrn @ermde ; BDOS error mode\r
\r
- ; Utility routines in standard BIOS\r
+ ; Utility routines\r
\r
extrn ?wboot ; warm boot vector\r
- extrn ?pmsg,pr.inln ; print message @<HL>, print inline message\r
- extrn pr.crlf ; print <cr><lf>\r
- extrn phex2\r
- extrn pr.decl\r
- extrn ?pderr ; print BIOS disk error header\r
- extrn ?conin,?cono ; con in and out\r
- extrn ?const ; get console status\r
- extrn ?bnksl\r
-\r
- extrn bnk2phy ;\r
- extrn add_hla\r
+ extrn ?pmsg ; print message @<HL>\r
+ extrn pr.idx ; print indexed message\r
+ extrn pr.inln ; print inline message\r
+ extrn pr.decl ; print 32 bit decimal number\r
+ extrn pr.errors ; print BIOS disk error header\r
+ extrn ?pchar ; console out\r
+ extrn bnk2phy ; translate banked to physical linear address\r
+ extrn add_hla ; add <A> to <HL>\r
extrn gstimer ; get timer short (16 bit)\r
\r
; Port Address Equates\r
\r
- include config.inc\r
- include z180reg.inc\r
+ maclib z180reg.inc\r
+ maclib config.inc\r
\r
; CP/M 3 Disk definition macros\r
\r
\r
; Z180 macro library instruction definitions (ignored by slr180)\r
\r
- include z180.lib\r
+ maclib z180.lib\r
\r
DEBUG equ false ; not used\r
MULTIIO equ true ; Multi I/O currently not fully implemented.\r
\r
cf$init0:\r
call pr.inln ;\r
- db 'cfio: CompactFlash Memory Card driver'cr,lf,0\r
+ dc 'cfio: CompactFlash Memory Card driver'\r
\r
ld hl,parttbl ; Clear partition table\r
ld b,PARTENTRY_SIZE*MAXDISKS\r
djnz ini_clrtbl\r
\r
call cf_init ; init ide interface / cf card\r
- jr nz,pend\r
-\r
+ jr nz,nocard\r
call ident_read ; identify drive\r
- jr nz,pend\r
+ jr nz,nocard\r
\r
call prnt_info ; print device information\r
call ptab_read ; read the partition table\r
+ jr nz,pend\r
\r
ld c,0 ; number of found disks (paritions)\r
jr nz,pend\r
call prnt_ptab ; Print partition table info\r
ret\r
\r
+nocard:\r
+ call pr.inln\r
+ dc ': No Card',cr,lf\r
+ ret\r
+\r
\r
cf$init1:\r
cf$init2:\r
ret\r
\r
cf_init:\r
- ld hl,25600 ;32000/1.25 ms\r
- call wait_nbsy_to\r
+ ld hl,25600 ; 32000/1.25 ms\r
+ call wait_nbsy_to ; wait for BSY == 0\r
jr c,cfi_error ; return error on timeout\r
- in a,(IDESCnt)\r
- dec a\r
- jr nz,cfi_error\r
- in a,(IDESNum)\r
- dec a\r
- jr nz,cfi_error\r
- in a,(IDECLo)\r
- or a\r
- jr nz,cfi_error\r
- in a,(IDECHi)\r
- or a\r
- jr nz,cfi_error\r
- in a,(IDESDH)\r
- or a\r
- jr nz,cfi_error\r
- ld hl,25600 ;32000/1.25 ms\r
- call wait_rdy_to\r
+\r
+ ld hl,25600 ; 32000/1.25 ms\r
+ call wait_rdy_to ; wait for RDY == 1\r
jr c,cfi_error ; return error on timeout\r
\r
ld a,0E0h ; assume unit 0, lba mode\r
out (IdeSDH),a ;\r
+\r
+ xor a ; execute NOP command\r
+ out (IdeCmd),a ;\r
+ ld hl,100\r
+ call wait_rdy_to\r
+ jr c,cfi_error\r
+ and 11111001b ;\r
+ cp 01010001b ; should return error\r
+ jr nz,cfi_error ;\r
+ ld a,10h ; execute RECALIBRATE command\r
+ out (IdeCmd),a ;\r
+ ld hl,100\r
+ call wait_rdy_to\r
+ and 11111001b ;\r
+ cp 01010000b ; should return ok\r
+ jr nz,cfi_error ;\r
+\r
ld a,1 ; Enable 8-bit data transfer.\r
out (IDEFeat),a\r
ld a,CmdSF ; Set feature command\r
ld a,1 ; return with A=1 on error\r
ret\r
\r
+;-------------------------------------------------------------------------------\r
+; print char, skipping leading blanks\r
\r
pr_char_nlbl:\r
bit 0,b\r
- jr z,pr_char\r
+ jp z,?pchar\r
cp ' '\r
ret z\r
res 0,b\r
- ; fall thru\r
-pr_char:\r
- push hl\r
- push de\r
- push bc\r
- ld c,a\r
- call ?cono\r
- pop bc\r
- pop de\r
- pop hl\r
- ret\r
+ jp ?pchar\r
\r
;-------------------------------------------------------------------------------\r
\r
\r
; Wait while device is busy with time out\r
; hl: timer tics (1.25ms) to wait\r
-; return carry flag set, if time out\r
+; return:\r
+; a: IDE status register\r
+; carry flag set, if time out\r
\r
wait_nbsy_to:\r
ld a,1\r
call chk_to\r
jr nc,wnb_l\r
wnb_e:\r
+ in a,(IdeCmd)\r
ret\r
\r
; Wait for ready signal with time out\r
; hl: timer tics (1.25ms) to wait\r
-; return carry flag set, if time out\r
+; return:\r
+; a: IDE status register\r
+; carry flag set, if time out\r
\r
wait_rdy_to:\r
ld a,1\r
call chk_to\r
jr nc,wrdy_l\r
wrdy_e:\r
+ in a,(IdeCmd)\r
ret\r
\r
;-------------------------------------------------------------------------------\r
\r
prnt_info:\r
call pr.inln\r
- db ' Model: ',0\r
+ dc cr,lf,' Model: '\r
ld hl,tmpsecbuf + 27*2 ; Model number\r
ld c,20*2 ; max character count\r
call pr_id ;\r
call pr.inln\r
- db ', S/N: ',0\r
+ dc ', S/N: '\r
ld hl,tmpsecbuf + 10*2 ; Serial number\r
ld c, 10*2\r
call pr_id\r
call pr.inln\r
- db ', Rev: ',0\r
+ dc ', Rev: '\r
ld hl,tmpsecbuf + 23*2 ; Firmware revision\r
ld c, 4*2\r
call pr_id\r
\r
call pr.inln\r
- db cr,lf,' Size: ',0\r
+ dc cr,lf,' Size: '\r
ld hl,(tmpsecbuf+60*2) ;Total Sectors Addressable in LBA Mode\r
ld de,(tmpsecbuf+61*2) ;\r
push hl\r
ld bc,1\r
call pr.decl\r
call pr.inln\r
- db ' Sectors (',0\r
+ dc ' Sectors ('\r
pop de\r
pop hl\r
srl d\r
ld bc,1\r
call pr.decl\r
call pr.inln\r
- db ' KiB)',cr,lf,0\r
+ dc ' KiB)',cr,lf\r
ret\r
\r
; Print partition table info\r
ret z\r
\r
push bc\r
- call pr.inln\r
- db ' ',0\r
ld a,(@adrv)\r
add a,c\r
add a,'A'\r
- call pr_char\r
+ ld (prp_dm),a\r
call pr.inln\r
- db ': CP/M partition at: ',0\r
+ db ' '\r
+prp_dm: db 'A'\r
+ dc ': CP/M partition at: '\r
ld l,(ix+PTAB_START+0)\r
ld h,(ix+PTAB_START+1)\r
ld e,(ix+PTAB_START+2)\r
ld bc,1\r
call pr.decl\r
call pr.inln\r
- db ', size: ',0\r
+ dc ', size: '\r
ld l,(ix+PTAB_SIZE+0)\r
ld h,(ix+PTAB_SIZE+1)\r
ld e,(ix+PTAB_SIZE+2)\r
ld bc,1\r
call pr.decl\r
call pr.inln\r
- db 'KiB',cr,lf,0\r
+ dc 'KiB',cr,lf\r
ld bc,PARTENTRY_SIZE\r
add ix,bc\r
pop bc\r
; disk READ and WRITE entry points.\r
; these entries are called with the following arguments:\r
;\r
-; absolute drive number in @adrv (8 bits) +0\r
-; relative drive number in @rdrv (8 bits) +1\r
-; disk track address in @trk (16 bits) +2\r
-; disk sector address in @sect(16 bits) +4\r
-; multi sector count in @cnt (8 bits) +6\r
-; disk transfer address in @dma (16 bits) +7\r
-; disk transfer bank in @dbnk (8 bits) +9\r
+; operation type (r/w) in @op (8 bits) +0\r
+; absolute drive number in @adrv (8 bits) +1\r
+; relative drive number in @rdrv (8 bits) +2\r
+; disk track address in @trk (16 bits) +3\r
+; disk sector address in @sect(16 bits) +5\r
+; multi sector count in @cnt (8 bits) +7\r
+; disk transfer address in @dma (16 bits) +8\r
+; disk transfer bank in @dbnk (8 bits) +10\r
; pointer to XDPH in <DE>\r
;\r
; they transfer the appropriate data, perform retries\r
; if necessary, then return an error code in <A>\r
\r
cf$read:\r
- ld de,read$msg ; point at " Read "\r
ld bc,M_DIM1*256 + CmdRd ; Transfermode: i/o to memory++\r
jr rw$common\r
cf$write:\r
- ld de,write$msg ; point at " Write "\r
ld bc,0*256 + CmdWr ; Transfermode: memory++ to i/o\r
rw$common:\r
\r
endif\r
\r
rwc_new_sectors:\r
- ld (operation$name),de ; save message for errors\r
in0 a,(dcntl)\r
and a,~(M_DMS1+M_DIM1+M_DIM0)\r
or b\r
ld e,(iy+PTAB_SIZE+0)\r
ld d,(iy+PTAB_SIZE+1)\r
sbc hl,de\r
- ld l,a\r
+ ld e,a\r
sbc a,(iy+PTAB_SIZE+2)\r
- ld a,l\r
pop hl\r
jr c,lba_ok\r
ld a,1 ; block# >= partition size, return error\r
\r
lba_ok:\r
WAITREADY\r
- ld e,a ; add partition start\r
- ld a,(iy+PTAB_START+0)\r
+ ld a,(iy+PTAB_START+0) ; add partition start\r
add a,l\r
out (IdeSNum),a\r
ld a,(iy+PTAB_START+1)\r
and 10001001b ; Busy, DRQ, or Error?\r
ret z ; Return to BDOS if no error\r
\r
-; suppress error message if BDOS is returning errors to application...\r
-\r
- ld a,(@ermde)\r
- cp 0ffh\r
- jr z,hard$error\r
-\r
- ; Had permanent error, print message like:\r
- ; BIOS Err on d: T-nn, S-mm, <operation> <type>, Retry ?\r
+ ld hl,print_details\r
+ call pr.errors\r
+ jp z,retry ; Yes, then retry once more\r
+ ; otherwise,\r
+ xor a\r
+ ld (residual),a\r
\r
- call ?pderr ; print message header\r
+ ld a,1 ; return hard error to BDOS\r
+ ret\r
\r
- ld hl,(operation$name)\r
- call ?pmsg ; last function (read or write)\r
+;-------------------------------------------------------------------------------\r
\r
+print_details:\r
ld hl,msg$drq\r
bit 3,e\r
call nz,?pmsg\r
\r
bit 0,e\r
- jr z,prompt\r
+ ret z\r
\r
in a,(IDEErr)\r
- ld hl,error$table ; point at table of message addresses\r
+ ld e,8\r
errm1:\r
- ld e,(hl)\r
- inc hl\r
- ld d,(hl)\r
- inc hl ; get next message address\r
- add a,a\r
- push af ; shift left and push residual bits with status\r
- ex de,hl\r
- call c,?pmsg\r
- ex de,hl ; print message, saving table pointer\r
- pop af\r
- jr nz,errm1 ; if any more bits left, continue\r
-\r
-prompt:\r
- call pr.inln\r
- db ' Retry (Y/N) ? ',0\r
-\r
- call u$conin$echo ; get operator response\r
- cp 'Y'\r
- jp z,retry ; Yes, then retry\r
-\r
-hard$error:\r
- ; otherwise,\r
- xor a\r
- ld (residual),a\r
-\r
- ld a,1 ; return hard error to BDOS\r
- ret\r
-\r
-cancel: ; here to abort job\r
- jp ?wboot ; leap directly to warmstart vector\r
-\r
-\r
-; get console input, echo it, and shift to upper case\r
-\r
-u$conin$echo:\r
- push bc\r
-u$c0:\r
- call ?const\r
- or a\r
- jr z,u$c1 ; see if any char already struck\r
- call ?conin\r
- jr u$c0 ; yes, eat it and try again\r
-u$c1:\r
- call ?conin\r
+ ld hl,b0$msg ; point at message[0]\r
+ dec e ; index of next message\r
+ add a,a ; shift left and push residual bits with status\r
push af\r
- ld c,a\r
- cp ' '-1\r
- call nc,?cono\r
+ ld a,e\r
+ call c,pr.idx ; print it, if bit is set.\r
pop af\r
- pop bc\r
- cp 'a'\r
- ret c\r
- sub 'a'-'A' ; make upper case\r
+ jr nz,errm1 ; if any more bits left, continue\r
ret\r
\r
- ; error message components\r
+;-------------------------------------------------------------------------------\r
+; error message components\r
\r
-operation$name:\r
- dw read$msg\r
-read$msg:\r
- db ', Read, ',0\r
-write$msg:\r
- db ', Write, ',0\r
msg$drq:\r
- db 'DRQ, ',0\r
-error$table:\r
- dw b7$msg\r
- dw b6$msg\r
- dw b5$msg\r
- dw b4$msg\r
- dw b3$msg\r
- dw b2$msg\r
- dw b1$msg\r
- dw b0$msg\r
-\r
-b7$msg: db ' Bad Block detected,',0\r
-b6$msg: db ' Uncorrectable Data Error,',0\r
-b5$msg: db ' Media Changed,',0\r
-b4$msg: db ' Sector ID Not Found,',0\r
-b3$msg: db ' Media Change Requst,',0\r
-b2$msg: db ' Aborted Command,',0\r
-b1$msg: db ' Track 0 Not Found,',0\r
-b0$msg: db ' AM Not Found (or general error),',0\r
+ dc 'DRQ, '\r
+\r
+b0$msg: dc ' AM Not Found (or general error),'\r
+b1$msg: dc ' Track 0 Not Found,'\r
+b2$msg: dc ' Aborted Command,'\r
+b3$msg: dc ' Media Change Requst,'\r
+b4$msg: dc ' Sector ID Not Found,'\r
+b5$msg: dc ' Media Changed,'\r
+b6$msg: dc ' Uncorrectable Data Error,'\r
+b7$msg: dc ' Bad Block detected,'\r
+ db 0\r
\r
+;-------------------------------------------------------------------------------\r
\r
residual:\r
db 0\r