X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp-cpm3.git/blobdiff_plain/2fe29e36e1b50e55fd64776a4eb68bcdd9433611..e8a98308cd28da296993a9085df28dc5957de86d:/cbios/cfio.180 diff --git a/cbios/cfio.180 b/cbios/cfio.180 index d7d6697..c5960cb 100644 --- a/cbios/cfio.180 +++ b/cbios/cfio.180 @@ -12,32 +12,29 @@ 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 @, print inline message - extrn pr.crlf ; print - 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 @ + 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 ?pchar ; console out + extrn bnk2phy ; translate banked to physical linear address + extrn add_hla ; add to extrn gstimer ; get timer short (16 bit) ; Port Address Equates - include config.inc - include z180reg.inc + maclib z180reg.inc + maclib config.inc ; CP/M 3 Disk definition macros @@ -45,7 +42,7 @@ ; Z180 macro library instruction definitions (ignored by slr180) - include z180.lib + maclib z180.lib DEBUG equ false ; not used MULTIIO equ true ; Multi I/O currently not fully implemented. @@ -196,7 +193,7 @@ dpbsimhd512: cf$init0: call pr.inln ; - db 'cfio: CompactFlash Memory Card driver',0 + dc 'cfio: CompactFlash Memory Card driver' ld hl,parttbl ; Clear partition table ld b,PARTENTRY_SIZE*MAXDISKS @@ -266,7 +263,7 @@ pend: nocard: call pr.inln - db ": No Card",cr,lf,0 + dc ': No Card',cr,lf ret @@ -324,30 +321,33 @@ ptab_read: ret cf_init: - ld hl,25600 ;32000/1.25 ms - call wait_nbsy_to + ld hl,25600 ; 32000/1.25 ms + call wait_nbsy_to ; wait for BSY == 0 jr c,cfi_error ; return error on timeout - in a,(IDESCnt) - dec a - jr nz,cfi_error - in a,(IDESNum) - dec a - jr nz,cfi_error - in a,(IDECLo) - or a - jr nz,cfi_error - in a,(IDECHi) - or a - jr nz,cfi_error - in a,(IDESDH) - or a - jr nz,cfi_error - ld hl,25600 ;32000/1.25 ms - call wait_rdy_to + + ld hl,25600 ; 32000/1.25 ms + call wait_rdy_to ; wait for RDY == 1 jr c,cfi_error ; return error on timeout ld a,0E0h ; assume unit 0, lba mode out (IdeSDH),a ; + + xor a ; execute NOP command + out (IdeCmd),a ; + ld hl,100 + call wait_rdy_to + jr c,cfi_error + and 11111001b ; + cp 01010001b ; should return error + jr nz,cfi_error ; + ld a,10h ; execute RECALIBRATE command + out (IdeCmd),a ; + ld hl,100 + call wait_rdy_to + and 11111001b ; + cp 01010000b ; should return ok + jr nz,cfi_error ; + ld a,1 ; Enable 8-bit data transfer. out (IDEFeat),a ld a,CmdSF ; Set feature command @@ -360,24 +360,16 @@ cfi_error: ld a,1 ; return with A=1 on error ret +;------------------------------------------------------------------------------- +; print char, skipping leading blanks pr_char_nlbl: bit 0,b - jr z,pr_char + jp z,?pchar cp ' ' ret z res 0,b - ; fall thru -pr_char: - push hl - push de - push bc - ld c,a - call ?cono - pop bc - pop de - pop hl - ret + jp ?pchar ;------------------------------------------------------------------------------- @@ -408,7 +400,9 @@ chk_1: ; Wait while device is busy with time out ; hl: timer tics (1.25ms) to wait -; return carry flag set, if time out +; return: +; a: IDE status register +; carry flag set, if time out wait_nbsy_to: ld a,1 @@ -421,11 +415,14 @@ wnb_l: call chk_to jr nc,wnb_l wnb_e: + in a,(IdeCmd) ret ; Wait for ready signal with time out ; hl: timer tics (1.25ms) to wait -; return carry flag set, if time out +; return: +; a: IDE status register +; carry flag set, if time out wait_rdy_to: ld a,1 @@ -439,6 +436,7 @@ wrdy_l: call chk_to jr nc,wrdy_l wrdy_e: + in a,(IdeCmd) ret ;------------------------------------------------------------------------------- @@ -491,23 +489,23 @@ prn_lp1: prnt_info: call pr.inln - db cr,lf,' Model: ',0 + dc cr,lf,' Model: ' ld hl,tmpsecbuf + 27*2 ; Model number ld c,20*2 ; max character count call pr_id ; call pr.inln - db ', S/N: ',0 + dc ', S/N: ' ld hl,tmpsecbuf + 10*2 ; Serial number ld c, 10*2 call pr_id call pr.inln - db ', Rev: ',0 + dc ', Rev: ' ld hl,tmpsecbuf + 23*2 ; Firmware revision ld c, 4*2 call pr_id call pr.inln - db cr,lf,' Size: ',0 + dc cr,lf,' Size: ' ld hl,(tmpsecbuf+60*2) ;Total Sectors Addressable in LBA Mode ld de,(tmpsecbuf+61*2) ; push hl @@ -515,7 +513,7 @@ prnt_info: ld bc,1 call pr.decl call pr.inln - db ' Sectors (',0 + dc ' Sectors (' pop de pop hl srl d @@ -525,7 +523,7 @@ prnt_info: ld bc,1 call pr.decl call pr.inln - db ' KiB)',cr,lf,0 + dc ' KiB)',cr,lf ret ; Print partition table info @@ -542,14 +540,14 @@ prp_lp: ret z push bc - call pr.inln - db ' ',0 ld a,(@adrv) add a,c add a,'A' - call pr_char + ld (prp_dm),a call pr.inln - db ': CP/M partition at: ',0 + db ' ' +prp_dm: db 'A' + dc ': CP/M partition at: ' ld l,(ix+PTAB_START+0) ld h,(ix+PTAB_START+1) ld e,(ix+PTAB_START+2) @@ -557,7 +555,7 @@ prp_lp: ld bc,1 call pr.decl call pr.inln - db ', size: ',0 + dc ', size: ' ld l,(ix+PTAB_SIZE+0) ld h,(ix+PTAB_SIZE+1) ld e,(ix+PTAB_SIZE+2) @@ -569,7 +567,7 @@ prp_lp: ld bc,1 call pr.decl call pr.inln - db 'KiB',cr,lf,0 + dc 'KiB',cr,lf ld bc,PARTENTRY_SIZE add ix,bc pop bc @@ -606,24 +604,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 ; ; they transfer the appropriate data, perform retries ; if necessary, then return an error code in 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: @@ -639,7 +636,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 @@ -691,9 +687,8 @@ retry: ld e,(iy+PTAB_SIZE+0) ld d,(iy+PTAB_SIZE+1) sbc hl,de - ld l,a + ld e,a sbc a,(iy+PTAB_SIZE+2) - ld a,l pop hl jr c,lba_ok ld a,1 ; block# >= partition size, return error @@ -701,8 +696,7 @@ retry: lba_ok: WAITREADY - ld e,a ; add partition start - ld a,(iy+PTAB_START+0) + ld a,(iy+PTAB_START+0) ; add partition start add a,l out (IdeSNum),a ld a,(iy+PTAB_START+1) @@ -757,114 +751,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, , 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 + dc 'DRQ, ' + +b0$msg: dc ' AM Not Found (or general error),' +b1$msg: dc ' Track 0 Not Found,' +b2$msg: dc ' Aborted Command,' +b3$msg: dc ' Media Change Requst,' +b4$msg: dc ' Sector ID Not Found,' +b5$msg: dc ' Media Changed,' +b6$msg: dc ' Uncorrectable Data Error,' +b7$msg: dc ' Bad Block detected,' + db 0 +;------------------------------------------------------------------------------- residual: db 0