GBA Timer: More questionable tweaks
Vicki Pfau vi@endrift.com
Wed, 05 Jul 2017 21:22:47 -0700
1 files changed,
7 insertions(+),
5 deletions(-)
jump to
M
src/gba/timer.c
→
src/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, ¤tTimer->event)) { tickIncrement = (0x10000 - tickIncrement) << prescaleBits; currentTime -= mTimingCurrentTime(&gba->timing) - cyclesLate; - mTimingSchedule(&gba->timing, ¤tTimer->event, tickIncrement + currentTime); + mTimingSchedule(&gba->timing, ¤tTimer->event, TIMER_RELOAD_DELAY + tickIncrement + currentTime); } }@@ -194,14 +196,14 @@ if (!wasEnabled && GBATimerFlagsIsEnable(currentTimer->flags)) {
mTimingDeschedule(&gba->timing, ¤tTimer->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, ¤tTimer->event); } else if (GBATimerFlagsIsEnable(currentTimer->flags) && GBATimerFlagsGetPrescaleBits(currentTimer->flags) != oldPrescale && !GBATimerFlagsIsCountUp(currentTimer->flags)) { mTimingDeschedule(&gba->timing, ¤tTimer->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); } }