From 1f1b7dfac87235698d333e7078e8bd28397b0315 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 7 Jun 2016 09:47:46 +0200 Subject: [PATCH] cf_init: do not depend on reset state of the ide command block registers. --- cbios/cfio.180 | 57 ++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/cbios/cfio.180 b/cbios/cfio.180 index d7d6697..a237bd6 100644 --- a/cbios/cfio.180 +++ b/cbios/cfio.180 @@ -324,30 +324,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 @@ -408,7 +411,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 +426,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 +447,7 @@ wrdy_l: call chk_to jr nc,wrdy_l wrdy_e: + in a,(IdeCmd) ret ;------------------------------------------------------------------------------- @@ -691,9 +700,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 +709,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) -- 2.39.2