delay.s (845B)
1 .include "global.s" 2 3 .title "Delay" 4 .module delay 5 6 .area _CODE 7 8;; hl must contain amount of tstates, which must be >= 141 9wait_hl_tstates:: 10 ld bc, #-141 11 add hl, bc 12 ld bc, #-23 131$: 14 add hl,bc 15 jr c, 1$ 16 ld a, l 17 add a, #15 18 jr nc, 2$ 19 cp #8 20 jr c, 3$ 21 or #0 222$: 23 inc hl 243$: 25 rra 26 jr c, 4$ 27 nop 284$: 29 rra 30 jr nc, 5$ 31 or #0 325$: 33 rra 34 ret nc 35 ret 36 37;; hl = milliseconds (0 = 65536) 38_delay:: 39 ld e, l 40 ld d, h 411$: 42 dec de 43 ld a,d 44 or e 45 jr z, 2$ 46 47 ld hl,#((.CPU_CLOCK / 1000) - 43) 48 call wait_hl_tstates 49 jr 1$ 502$: 51 ld hl,#((.CPU_CLOCK / 1000) - 54) 52 jp wait_hl_tstates 53 ret