summaryrefslogtreecommitdiff
path: root/sys/src/games
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2021-02-10 09:00:05 +0000
committerMichael Forney <mforney@mforney.org>2022-03-18 17:25:43 -0700
commitd5368b0799a2a335f4accac2027617c433db4fef (patch)
tree19ba2d967ce6dd3ab8162d0fe48b4d06de1137e4 /sys/src/games
parent638b82129e750940b4d886c17c7c0ba9d8dbceac (diff)
games/gb: various RTC fixes
MBC3 write switches on a>>13, so the RTC register is 5 (0xA000-0xBFFF). Mask off upper bits of DH register when updating the timer. Only the lowest bit is part of the day counter. Use uint for x in timerforward() so that we don't set negative values for timer registers if it happens to overflow. Update timer and then latch rather than the other way around. Otherwise, timer remains static and will overflow after 512 days.
Diffstat (limited to 'sys/src/games')
-rw-r--r--sys/src/games/gb/mem.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/sys/src/games/gb/mem.c b/sys/src/games/gb/mem.c
index 05e4754ea..c299c66f5 100644
--- a/sys/src/games/gb/mem.c
+++ b/sys/src/games/gb/mem.c
@@ -329,7 +329,7 @@ void
timerforward(MBC3Timer *t)
{
vlong n, nd;
- int x;
+ uint x;
n = nsec();
nd = n - t->ns;
@@ -340,7 +340,7 @@ timerforward(MBC3Timer *t)
return;
}
t->ns = n - nd % BILLION;
- x = t->sec + t->min * 60 + t->hr * 3600 + t->dl * 86400 + t->dh * (256 * 86400);
+ x = t->sec + t->min * 60 + t->hr * 3600 + ((t->dh & 1) << 8 | t->dl) * 86400;
x += nd / BILLION;
t->sec = x % 60;
x /= 60;
@@ -398,12 +398,12 @@ mbc3(int a, int v)
case 2: b1 = v & 15; break;
case 3:
if(latch == 0 && v == 1){
+ timerforward(&timer);
timerl = timer;
- timerforward(&timerl);
}
latch = v;
break;
- case 0xa:
+ case 5:
if(!ramen)
return 0;
switch(b1){