diff --git a/CHANGES b/CHANGES index 2b379b0f7..2c307af5d 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,7 @@ Bugfixes: - DS Audio: Fix audio sampling slightly too quickly - Feature: Fix resizing GIF buffer (fixes mgba.io/i/695) - DS GX: Retain translucent polygon ID when drawing opaque fragments (fixes mgba.io/i/661) + - DS Timers: Fix ARM9 timers running too fast Misc: - DS: Set boot complete bit in RAM on boot (fixes mgba.io/i/576, mgba.io/i/580, mgba.io/i/586) - DS Memory: Ensure DS9 I/O is 8-byte aligned diff --git a/include/mgba/internal/gba/timer.h b/include/mgba/internal/gba/timer.h index c20243166..17963df75 100644 --- a/include/mgba/internal/gba/timer.h +++ b/include/mgba/internal/gba/timer.h @@ -25,6 +25,7 @@ struct GBATimer { struct mTimingEvent event; int32_t overflowInterval; GBATimerFlags flags; + int forcedPrescale; }; struct ARMCore; diff --git a/src/ds/timer.c b/src/ds/timer.c index 2cd661b7b..d142dfbd1 100644 --- a/src/ds/timer.c +++ b/src/ds/timer.c @@ -71,18 +71,22 @@ void DSTimerInit(struct DS* ds) { ds->ds9.timers[0].event.callback = DSTimerUpdate0; ds->ds9.timers[0].event.context = &ds->ds9; ds->ds9.timers[0].event.priority = 0x20; + ds->ds9.timers[0].forcedPrescale = 1; ds->ds9.timers[1].event.name = "DS9 Timer 1"; ds->ds9.timers[1].event.callback = DSTimerUpdate1; ds->ds9.timers[1].event.context = &ds->ds9; ds->ds9.timers[1].event.priority = 0x21; + ds->ds9.timers[1].forcedPrescale = 1; ds->ds9.timers[2].event.name = "DS9 Timer 2"; ds->ds9.timers[2].event.callback = DSTimerUpdate2; ds->ds9.timers[2].event.context = &ds->ds9; ds->ds9.timers[2].event.priority = 0x22; + ds->ds9.timers[2].forcedPrescale = 1; ds->ds9.timers[3].event.name = "DS9 Timer 3"; ds->ds9.timers[3].event.callback = DSTimerUpdate3; ds->ds9.timers[3].event.context = &ds->ds9; ds->ds9.timers[3].event.priority = 0x23; + ds->ds9.timers[3].forcedPrescale = 1; } void DSTimerWriteTMCNT_HI(struct GBATimer* timer, struct mTiming* timing, struct ARMCore* cpu, uint16_t* io, uint16_t value) { diff --git a/src/gba/timer.c b/src/gba/timer.c index 0be6b6919..e5016f5ad 100644 --- a/src/gba/timer.c +++ b/src/gba/timer.c @@ -128,16 +128,16 @@ void GBATimerWriteTMCNT_HI(struct GBATimer* timer, struct mTiming* timing, struc unsigned oldPrescale = GBATimerFlagsGetPrescaleBits(timer->flags); switch (control & 0x0003) { case 0x0000: - timer->flags = GBATimerFlagsSetPrescaleBits(timer->flags, 0); + timer->flags = GBATimerFlagsSetPrescaleBits(timer->flags, timer->forcedPrescale); break; case 0x0001: - timer->flags = GBATimerFlagsSetPrescaleBits(timer->flags, 6); + timer->flags = GBATimerFlagsSetPrescaleBits(timer->flags, 6 + timer->forcedPrescale); break; case 0x0002: - timer->flags = GBATimerFlagsSetPrescaleBits(timer->flags, 8); + timer->flags = GBATimerFlagsSetPrescaleBits(timer->flags, 8 + timer->forcedPrescale); break; case 0x0003: - timer->flags = GBATimerFlagsSetPrescaleBits(timer->flags, 10); + timer->flags = GBATimerFlagsSetPrescaleBits(timer->flags, 10 + timer->forcedPrescale); break; } timer->flags = GBATimerFlagsTestFillCountUp(timer->flags, timer > 0 && (control & 0x0004));