From 9aeb8c65d729bb5a5fc2bdf9d048f04b9512bb1a Mon Sep 17 00:00:00 2001 From: sum2012 Date: Fri, 30 Dec 2016 07:01:37 +0800 Subject: [PATCH] Fix scePowerSetClockFrequency --- Core/HLE/scePower.cpp | 54 +++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/Core/HLE/scePower.cpp b/Core/HLE/scePower.cpp index ab1a23a46d..bd0db2bf49 100644 --- a/Core/HLE/scePower.cpp +++ b/Core/HLE/scePower.cpp @@ -57,6 +57,8 @@ static int powerCbSlots[numberOfCBPowerSlots]; static std::vector volatileWaitingThreads; // Should this belong here, or in CoreTiming? +static int RealpllFreq = 222; +static int RealbusFreq = 111; static int pllFreq = 222; static int busFreq = 111; @@ -73,13 +75,32 @@ void __PowerInit() { pllFreq = 222; busFreq = 111; } + RealpllFreq = 222; + RealbusFreq = 111; } void __PowerDoState(PointerWrap &p) { - auto s = p.Section("scePower", 1); + auto s = p.Section("scePower",1,2); if (!s) return; + if (s >= 2) { + p.Do(RealpllFreq); + p.Do(RealbusFreq); + } + else { + RealpllFreq = 222; + RealbusFreq = 111; + } + if (g_Config.iLockedCPUSpeed > 0) { + CoreTiming::SetClockFrequencyMHz(g_Config.iLockedCPUSpeed); + pllFreq = g_Config.iLockedCPUSpeed; + busFreq = g_Config.iLockedCPUSpeed / 2; + } + else { + pllFreq = RealpllFreq; + busFreq = RealbusFreq; + } p.DoArray(powerCbSlots, ARRAY_SIZE(powerCbSlots)); p.Do(volatileMemLocked); p.Do(volatileWaitingThreads); @@ -354,21 +375,30 @@ static int sceKernelVolatileMemLock(int type, u32 paddr, u32 psize) { static u32 scePowerSetClockFrequency(u32 pllfreq, u32 cpufreq, u32 busfreq) { + if (cpufreq == 0 || cpufreq > 333) { + WARN_LOG(HLE,"scePowerSetClockFrequency(%i,%i,%i): invalid frequency", pllfreq, cpufreq, busfreq); + return SCE_KERNEL_ERROR_INVALID_VALUE; + } + // TODO: More restrictions. if (g_Config.iLockedCPUSpeed > 0) { - INFO_LOG(HLE,"scePowerSetClockFrequency(%i,%i,%i): locked by user config at %i, %i, %i", pllfreq, cpufreq, busfreq, g_Config.iLockedCPUSpeed, g_Config.iLockedCPUSpeed, busFreq); + INFO_LOG(HLE, "scePowerSetClockFrequency(%i,%i,%i): locked by user config at %i, %i, %i", pllfreq, cpufreq, busfreq, g_Config.iLockedCPUSpeed, g_Config.iLockedCPUSpeed, busFreq); } else { - if (cpufreq == 0 || cpufreq > 333) { - WARN_LOG(HLE,"scePowerSetClockFrequency(%i,%i,%i): invalid frequency", pllfreq, cpufreq, busfreq); - return SCE_KERNEL_ERROR_INVALID_VALUE; - } - // TODO: More restrictions. - CoreTiming::SetClockFrequencyMHz(cpufreq); - pllFreq = pllfreq; - busFreq = busfreq; - INFO_LOG(HLE,"scePowerSetClockFrequency(%i,%i,%i)", pllfreq, cpufreq, busfreq); + INFO_LOG(HLE, "scePowerSetClockFrequency(%i,%i,%i)", pllfreq, cpufreq, busfreq); } - return hleDelayResult(0, "scepower set clockFrequency", 150000); + if (RealpllFreq != pllfreq || RealbusFreq != busfreq) { + RealpllFreq = pllfreq; + RealbusFreq = busfreq; + if (g_Config.iLockedCPUSpeed <= 0) { + pllFreq = pllfreq; + busFreq = busfreq; + CoreTiming::SetClockFrequencyMHz(cpufreq); + } + return hleDelayResult(0, "scepower set clockFrequency", 150000); + } + if (g_Config.iLockedCPUSpeed <= 0) + CoreTiming::SetClockFrequencyMHz(cpufreq); + return 0; } static u32 scePowerSetCpuClockFrequency(u32 cpufreq) {