94a126e3f178 — Laurens Holst 7 years ago
System: Do not return values in the past from GetHighResTimerValue.

If an interrupt would occur between reading the timer LSB and MSB, it could
result in incorrect results. E.g. when the timer is 1FFH before the interrupt
and it is 280H after, the value returned would be 180H and time would run

With this fix, if the MSB between two reads differs, it always returns 0 as the
LSB which must have been true somewhere between the MSB reads.
1 files changed, 3 insertions(+), 2 deletions(-)

M src/System.asm
M src/System.asm +3 -2
@@ 166,10 166,11 @@ System_GetHighResTimerValue:
 	ld h,a
 	in a,(0E6H)
 	ld l,a
-	and a
-	ret m
 	in a,(0E7H)
+	cp h
+	ret z
 	ld h,a
+	ld l,0