changeset 2734:6fff3906385c default tip

Fix handling of wraparound for timer comparison interrupts
author Michael Pavone <pavone@retrodev.com>
date Fri, 18 Jul 2025 23:36:18 -0700
parents d823e02fdae5
children
files upd78k2_util.c
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/upd78k2_util.c	Fri Jul 18 23:25:07 2025 -0700
+++ b/upd78k2_util.c	Fri Jul 18 23:36:18 2025 -0700
@@ -38,11 +38,13 @@
 	diff >>= 3;
 	if (upd->tmc0 & CE0) {
 		uint32_t tmp = upd->tm0 + diff;
+		uint32_t cr00 = upd->cr00 | (tmp > 0xFFFF ? 0x10000 : 0);
+		uint32_t cr01 = upd->cr01 | (tmp > 0xFFFF ? 0x10000 : 0);
 		//TODO: the rest of the CR00/CR01 stuff
-		if (upd->tm0 < upd->cr00 && tmp >= upd->cr00) {
+		if (upd->tm0 < cr00 && tmp >= cr00) {
 			upd->if0 |= CIF00;
 		}
-		if (upd->tm0 < upd->cr01 && tmp >= upd->cr01) {
+		if (upd->tm0 < cr01 && tmp >= cr01) {
 			upd->if0 |= CIF01;
 			if (upd->crc0 & 8) {
 				//CR01 clear is enabled