all repos — mgba @ 70e01030d1f96b048170abe3fed216ac9c1aded1

mGBA Game Boy Advance Emulator

GB Timer: Fix some timing issues
Jeffrey Pfau jeffrey@endrift.com
Sun, 28 Aug 2016 10:04:00 -0700
commit

70e01030d1f96b048170abe3fed216ac9c1aded1

parent

24bb93085022595d6935b2fc5749eb92c7a3b00a

1 files changed, 5 insertions(+), 5 deletions(-)

jump to
M src/gb/timer.csrc/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; } } }