\r
extrn bnk2phy ;\r
extrn add_hla\r
-\r
+ extrn gstimer ; get timer short (16 bit)\r
\r
; Port Address Equates\r
\r
jr c,wait\r
endm\r
\r
- ; Macro: wait while device is busy\r
+ ; Macro: wait until device is ready\r
\r
WAITREADY macro\r
local wait\r
ret\r
\r
cf_init:\r
- WAITREADY\r
+ ld hl,25600 ;32000/1.25 ms\r
+ call wait_nbsy_to\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
+ jr c,cfi_error ; return error on timeout\r
+\r
ld a,0E0h ; assume unit 0, lba mode\r
out (IdeSDH),a ;\r
ld a,1 ; Enable 8-bit data transfer.\r
out (IDEFeat),a\r
- ld a,CmdSF\r
- out (IdeCmd),a ; command: read sector data\r
+ ld a,CmdSF ; Set feature command\r
+ out (IdeCmd),a ;\r
WAITNOTBUSY\r
in a,(IdeCmd) ; check final drive status\r
and 10001001b ; Busy, DRQ, or Error?\r
ret z ; no: everything is ok\r
+cfi_error:\r
ld a,1 ; return with A=1 on error\r
ret\r
\r
pop hl\r
ret\r
\r
+;-------------------------------------------------------------------------------\r
+\r
+reftime:dw 2\r
+to: dw 2\r
+\r
+chk_to:\r
+ or a\r
+ jr z,chk_1\r
+ ld (to),hl\r
+ ld hl,0\r
+ call gstimer\r
+ ld (reftime),hl\r
+ ret\r
+chk_1:\r
+ push hl\r
+ push de\r
+ ld hl,(reftime)\r
+ call gstimer\r
+ ex de,hl\r
+ ld hl,(to)\r
+ or a\r
+ sbc hl,de\r
+ pop de\r
+ pop hl\r
+ ret\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
+\r
+wait_nbsy_to:\r
+ ld a,1\r
+ call chk_to\r
+wnb_l:\r
+ in a,(IdeCmd)\r
+ rla\r
+ jr nc,wnb_e\r
+ xor a\r
+ call chk_to\r
+ jr nc,wnb_l\r
+wnb_e:\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
+\r
+wait_rdy_to:\r
+ ld a,1\r
+ call chk_to\r
+wrdy_l:\r
+ in a,(IdeCmd)\r
+ xor 01000000b\r
+ and 11000000b ; clears carry\r
+ jr z,wrdy_e\r
+ xor a\r
+ call chk_to\r
+ jr nc,wrdy_l\r
+wrdy_e:\r
+ ret\r
+\r
+;-------------------------------------------------------------------------------\r
+\r
; Print an id string\r
; Remove leading and trailing spaces\r
\r
public ?time, gs_rtc
public prt0ini
-
+ public gtimer,gstimer
extrn @date,@hour,@min,@sec
extrn f_cpu
pop hl
ret
+;----------------------------------------------------------------------
+
+;uint32_t get_timer(uint32_t base)
+;{
+; uint32_t ret;
+; ATOMIC_BLOCK(ATOMIC_FORCEON)
+; {
+; ret = timestamp;
+; }
+; return ret - base;
+;}
+
+ dseg ; called from banked only
+gstimer:
+ push de
+ ex de,hl
+ ld hl,(uptime)
+ or a
+ sbc hl,de
+ pop de
+ ret
+
+;----------------------------------------------------------------------
+
+gtimer:
+ push bc
+ ld b,h
+ ld c,l
+ or a
+ di
+ ld hl,(uptime)
+ sbc hl,bc
+ push hl
+ ei
+ ld hl,(uptime+2)
+ sbc hl,de
+ ex de,hl
+ pop hl
+ pop bc
+ ret
;----------------------------------------------------------------------
; intit timer interrupt