GB Timer: Fix some timing issues
Jeffrey Pfau jeffrey@endrift.com
Sun, 28 Aug 2016 10:04:00 -0700
1 files changed,
5 insertions(+),
5 deletions(-)
jump to
M
src/gb/timer.c
→
src/gb/timer.c
@@ -27,20 +27,20 @@ timer->p->memory.io[REG_TIMA] = timer->p->memory.io[REG_TMA];
timer->p->memory.io[REG_IF] |= (1 << GB_IRQ_TIMER); GBUpdateIRQs(timer->p); timer->irqPending = false; - timer->nextEvent = timer->nextDiv; + timer->nextEvent += timer->nextDiv; } if (timer->nextDiv <= 0) { ++timer->internalDiv; timer->p->memory.io[REG_DIV] = timer->internalDiv >> 4; - timer->nextDiv = GB_DMG_DIV_PERIOD; - timer->nextEvent = timer->nextDiv; + timer->nextDiv += GB_DMG_DIV_PERIOD; + timer->nextEvent += GB_DMG_DIV_PERIOD; // Make sure to trigger when the correct bit is a falling edge - if (timer->timaPeriod == 1 || (timer->internalDiv & (timer->timaPeriod - 1)) == (timer->timaPeriod >> 1) - 1) { + if (timer->timaPeriod > 0 && (timer->internalDiv & (timer->timaPeriod - 1)) == timer->timaPeriod - 1) { ++timer->p->memory.io[REG_TIMA]; if (!timer->p->memory.io[REG_TIMA]) { timer->irqPending = true; - timer->nextEvent = 4; + timer->nextEvent += 4; } } }