all repos — mgba @ d3678471f681215765877d4d8be91ac4bbe768ff

mGBA Game Boy Advance Emulator

GBA Timer: More questionable tweaks
Vicki Pfau vi@endrift.com
Wed, 05 Jul 2017 21:22:47 -0700
commit

d3678471f681215765877d4d8be91ac4bbe768ff

parent

c7630a13da378b112d60ddbb8ea75e24726aa9b2

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

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

@@ -9,6 +9,8 @@ #include <mgba/internal/gba/gba.h>

#include <mgba/internal/gba/io.h> #define TIMER_IRQ_DELAY 7 +#define TIMER_RELOAD_DELAY 0 +#define TIMER_STARTUP_DELAY 2 static void GBATimerIrq(struct GBA* gba, int timerId) { struct GBATimer* timer = &gba->timers[timerId];

@@ -157,7 +159,7 @@ gba->memory.io[(REG_TM0CNT_LO + (timer << 2)) >> 1] = tickIncrement;

if (!mTimingIsScheduled(&gba->timing, &currentTimer->event)) { tickIncrement = (0x10000 - tickIncrement) << prescaleBits; currentTime -= mTimingCurrentTime(&gba->timing) - cyclesLate; - mTimingSchedule(&gba->timing, &currentTimer->event, tickIncrement + currentTime); + mTimingSchedule(&gba->timing, &currentTimer->event, TIMER_RELOAD_DELAY + tickIncrement + currentTime); } }

@@ -194,14 +196,14 @@ if (!wasEnabled && GBATimerFlagsIsEnable(currentTimer->flags)) {

mTimingDeschedule(&gba->timing, &currentTimer->event); gba->memory.io[(REG_TM0CNT_LO + (timer << 2)) >> 1] = currentTimer->reload; int32_t tickMask = (1 << prescaleBits) - 1; - currentTimer->lastEvent = (mTimingCurrentTime(&gba->timing)) & ~tickMask; - GBATimerUpdateRegister(gba, timer, 0); + currentTimer->lastEvent = (mTimingCurrentTime(&gba->timing) - TIMER_STARTUP_DELAY) & ~tickMask; + GBATimerUpdateRegister(gba, timer, TIMER_STARTUP_DELAY); } else if (wasEnabled && !GBATimerFlagsIsEnable(currentTimer->flags)) { mTimingDeschedule(&gba->timing, &currentTimer->event); } else if (GBATimerFlagsIsEnable(currentTimer->flags) && GBATimerFlagsGetPrescaleBits(currentTimer->flags) != oldPrescale && !GBATimerFlagsIsCountUp(currentTimer->flags)) { mTimingDeschedule(&gba->timing, &currentTimer->event); int32_t tickMask = (1 << prescaleBits) - 1; - currentTimer->lastEvent = (mTimingCurrentTime(&gba->timing)) & ~tickMask; - GBATimerUpdateRegister(gba, timer, 0); + currentTimer->lastEvent = (mTimingCurrentTime(&gba->timing) - TIMER_STARTUP_DELAY) & ~tickMask; + GBATimerUpdateRegister(gba, timer, TIMER_STARTUP_DELAY); } }