all repos — mgba @ f8469822d73580272ffdb388cc6b3f17bf1500b3

mGBA Game Boy Advance Emulator

GB: Fix div timer
Jeffrey Pfau jeffrey@endrift.com
Wed, 20 Jan 2016 22:35:09 -0800
commit

f8469822d73580272ffdb388cc6b3f17bf1500b3

parent

7685bc8b00238224e2af7aa1346f289464c2d9f3

1 files changed, 7 insertions(+), 6 deletions(-)

jump to
M src/gb/timer.csrc/gb/timer.c

@@ -11,16 +11,13 @@

void GBTimerReset(struct GBTimer* timer) { timer->nextDiv = GB_DMG_DIV_PERIOD; // TODO: GBC differences timer->nextTima = INT_MAX; - timer->nextEvent = INT_MAX; + timer->nextEvent = GB_DMG_DIV_PERIOD; } int32_t GBTimerProcessEvents(struct GBTimer* timer, int32_t cycles) { - if (timer->nextEvent == INT_MAX) { - return INT_MAX; - } timer->eventDiff += cycles; timer->nextEvent -= cycles; - if (timer->nextEvent < 0) { + if (timer->nextEvent <= 0) { timer->nextDiv -= timer->eventDiff; if (timer->nextDiv <= 0) { ++timer->p->memory.io[REG_DIV];

@@ -51,7 +48,11 @@ }

void GBTimerDivReset(struct GBTimer* timer) { timer->p->memory.io[REG_DIV] = 0; - // TODO: Do we need to reset the event? + timer->nextDiv = timer->eventDiff + GB_DMG_DIV_PERIOD; + timer->nextEvent = timer->nextTima; + if (timer->nextDiv < timer->nextEvent) { + timer->nextEvent = timer->nextDiv; + } } uint8_t GBTimerUpdateTAC(struct GBTimer* timer, GBRegisterTAC tac) {