From a085cd431dbaed77349d1e1e2f41be1b94b84535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Wed, 8 Feb 2017 16:22:27 +0100 Subject: [PATCH] Adjust event times after a PPC clock change This likely doesn't change much, but it makes events trigger at the correct time after a clock change. --- Source/Core/Core/CoreTiming.cpp | 10 ++++++++++ Source/Core/Core/CoreTiming.h | 2 ++ Source/Core/Core/HW/SystemTimers.cpp | 2 ++ 3 files changed, 14 insertions(+) diff --git a/Source/Core/Core/CoreTiming.cpp b/Source/Core/Core/CoreTiming.cpp index 803cd76fec..0780d93ca4 100644 --- a/Source/Core/Core/CoreTiming.cpp +++ b/Source/Core/Core/CoreTiming.cpp @@ -364,6 +364,16 @@ void LogPendingEvents() } } +// Should only be called from the CPU thread after the PPC clock has changed +void AdjustEventQueueTimes(u32 new_ppc_clock, u32 old_ppc_clock) +{ + for (Event& ev : s_event_queue) + { + const s64 ticks = (ev.time - g_global_timer) * new_ppc_clock / old_ppc_clock; + ev.time = g_global_timer + ticks; + } +} + void Idle() { if (SConfig::GetInstance().bSyncGPUOnSkipIdleHack) diff --git a/Source/Core/Core/CoreTiming.h b/Source/Core/Core/CoreTiming.h index 28263be94c..2cdee0c6cf 100644 --- a/Source/Core/Core/CoreTiming.h +++ b/Source/Core/Core/CoreTiming.h @@ -91,6 +91,8 @@ void LogPendingEvents(); std::string GetScheduledEventsSummary(); +void AdjustEventQueueTimes(u32 new_ppc_clock, u32 old_ppc_clock); + u32 GetFakeDecStartValue(); void SetFakeDecStartValue(u32 val); u64 GetFakeDecStartTicks(); diff --git a/Source/Core/Core/HW/SystemTimers.cpp b/Source/Core/Core/HW/SystemTimers.cpp index eb72f6de47..4b3a9fda8a 100644 --- a/Source/Core/Core/HW/SystemTimers.cpp +++ b/Source/Core/Core/HW/SystemTimers.cpp @@ -228,10 +228,12 @@ void PreInit() void ChangePPCClock(Mode mode) { + const u32 previous_clock = s_cpu_core_clock; if (mode == Mode::Wii) s_cpu_core_clock = 729000000u; else s_cpu_core_clock = 486000000u; + CoreTiming::AdjustEventQueueTimes(s_cpu_core_clock, previous_clock); } void Init()