Skip to content

Commit a0d7a32

Browse files
authored
Fix occasional bug in delay() and usleep() (#333)
1 parent 9779b05 commit a0d7a32

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

src/ce/delay.src

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ _delay:
2424
; ^ 13 cc
2525
; Get the start time ASAP.
2626
push hl
27-
call _clock ; a = 0, euhl = start
27+
call _clock ; euhl = start
2828
; ^ 32 + cc(_clock) cc
2929
; 22 + 48 + 13 + 32 + 48 + 75 = 238 cc until start time captured
3030
ex (sp), hl ; hl = millis
3131
push de
3232
; Convert millis to clock ticks.
3333
dec.s hl
34+
xor a, a ; a = 0
3435
ld e, a ; euhl = millis - 1
3536
.multiplier_fp := (256 * 32768 + 1000 - 1) / 1000
3637
assert .multiplier_fp shr 24 = 0

src/ce/sleep.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ _sleep:
2525
; ^ 13 cc
2626
; Get the start time ASAP.
2727
push hl
28-
call _clock ; a = 0, euhl = start
28+
call _clock ; euhl = start
2929
; ^ 32 + cc(_clock) cc
3030
; 22 + 48 + 13 + 32 + 48 + 75 = 238 cc until start time captured
3131
ex (sp), hl ; hl = seconds

src/ce/ticksleep.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ _ticksleep:
3131
; Get the start time ASAP.
3232
push de
3333
push hl
34-
call _clock ; a = 0, euhl = start
34+
call _clock ; euhl = start
3535
; ^ 42 + cc(_clock) cc
3636
; 22 + 103 + 42 + 48 + 75 = 290 cc until start time captured
3737
; Join common code for the rest.

src/ce/usleep.src

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ _usleep:
2626
; ^ 21 cc
2727
; Get the start time ASAP.
2828
push hl
29-
call _clock ; a = 0, euhl = start
29+
call _clock ; euhl = start
3030
; ^ 32 + cc(_clock) cc
3131
; 22 + 48 + 21 + 32 + 48 + 75 = 246 cc until start time captured
3232
ex (sp), hl ; hl = usec
3333
push de
3434
; Convert usec to clock ticks.
3535
; https://docs.google.com/spreadsheets/d/1mZwDn6rEw3-uSQPuy48Ez0UWIvnggLiJxWft4u4OtcU/edit?usp=sharing
36+
xor a, a ; a = 0
3637
ld e, a ; euhl = usec
3738
.multiplier := 114
3839
ld bc, .multiplier ; aubc = multiplier

src/std/shared/clock.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mpTmr2Counter := 0F20010h
66
public _clock
77
_clock:
88
assert mpTmr2Counter shr 8 and $FF = 0
9-
; O: a = 0, euhl = ticks
9+
; O: euhl = ticks
1010
assert mpTmr2Counter and $A7 = 0
1111
; FO: s = 0, z = 0, h = 0, p/v = 0, n = 0, c = 0
1212
; CC: 79 + cc(_atomic_load_increasing_32)

0 commit comments

Comments
 (0)