+;-------------------------------------------------------------------------------\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