From 239921966332f0a749ff35f5daa17f06132643ab Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 28 Jan 2016 01:27:02 -0800 Subject: [PATCH] GB: Fix DIV reseting timing --- src/gb/timer.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gb/timer.c b/src/gb/timer.c index be289f7cc..f9a05beeb 100644 --- a/src/gb/timer.c +++ b/src/gb/timer.c @@ -49,9 +49,11 @@ int32_t GBTimerProcessEvents(struct GBTimer* timer, int32_t cycles) { void GBTimerDivReset(struct GBTimer* timer) { timer->p->memory.io[REG_DIV] = 0; timer->nextDiv = timer->eventDiff + timer->p->cpu->cycles + GB_DMG_DIV_PERIOD; - timer->nextEvent = timer->nextTima; - if (timer->nextDiv < timer->nextEvent) { - timer->nextEvent = timer->nextDiv; + if (timer->eventDiff + GB_DMG_DIV_PERIOD < timer->nextEvent) { + timer->nextEvent = timer->eventDiff + GB_DMG_DIV_PERIOD; + if (timer->nextEvent < timer->p->cpu->nextEvent) { + timer->p->cpu->nextEvent = timer->nextEvent; + } } }