From 34d27bad4ae80af70c4be37a1232001c31992cb9 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 10 Jun 2020 01:37:11 +1000 Subject: [PATCH] Timers: Add missing event update after resetting count/target --- src/core/timers.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/core/timers.cpp b/src/core/timers.cpp index 85e1b820a..c7e62d4e4 100644 --- a/src/core/timers.cpp +++ b/src/core/timers.cpp @@ -115,11 +115,20 @@ void Timers::AddTicks(u32 timer, TickCount count) { interrupt_request |= cs.mode.irq_at_target; cs.mode.reached_target = true; + + if (cs.mode.reset_at_target) + { + if (cs.target > 0) + cs.counter %= cs.target; + else + cs.counter = 0; + } } if (cs.counter >= 0xFFFF) { interrupt_request |= cs.mode.irq_on_overflow; cs.mode.reached_overflow = true; + cs.counter %= 0xFFFFu; } if (interrupt_request) @@ -137,18 +146,6 @@ void Timers::AddTicks(u32 timer, TickCount count) UpdateIRQ(timer); } } - - if (cs.mode.reset_at_target) - { - if (cs.target > 0) - cs.counter %= cs.target; - else - cs.counter = 0; - } - else - { - cs.counter %= 0xFFFF; - } } void Timers::AddSysClkTicks(TickCount sysclk_ticks) @@ -242,6 +239,8 @@ void Timers::WriteRegister(u32 offset, u32 value) { Log_DebugPrintf("Timer %u write counter %u", timer_index, value); cs.counter = value & u32(0xFFFF); + if (timer_index == 2 || !cs.external_counting_enabled) + UpdateSysClkEvent(); } break; @@ -265,6 +264,8 @@ void Timers::WriteRegister(u32 offset, u32 value) { Log_DebugPrintf("Timer %u write target 0x%04X", timer_index, ZeroExtend32(Truncate16(value))); cs.target = value & u32(0xFFFF); + if (timer_index == 2 || !cs.external_counting_enabled) + UpdateSysClkEvent(); } break;