Skip to content

Commit

Permalink
Merge pull request #18486 from hrydgard/compat-enforce-default-clock
Browse files Browse the repository at this point in the history
Compat: Enforce [RequireDefaultCPUClock] compat flag by disabling overclocking for these games
  • Loading branch information
hrydgard committed Dec 7, 2023
2 parents 8dab823 + b22e27a commit fc49c10
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
35 changes: 21 additions & 14 deletions Core/HLE/scePower.cpp
Expand Up @@ -16,14 +16,17 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <map>
#include <vector>

#include "Common/Serialize/Serializer.h"
#include "Common/Serialize/SerializeFuncs.h"
#include "Core/HLE/HLE.h"
#include "Core/HLE/FunctionWrappers.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h"
#include "Core/MemMap.h"
#include "Core/Reporting.h"
#include "Core/Config.h"
#include "Core/Compatibility.h"

#include "Core/HLE/scePower.h"
#include "Core/HLE/sceKernelThread.h"
Expand Down Expand Up @@ -63,6 +66,10 @@ static int RealbusFreq = 111000000;
static int pllFreq = 222000000;
static int busFreq = 111000000;

int GetLockedCPUSpeedMhz() {
return PSP_CoreParameter().compat.flags().RequireDefaultCPUClock ? 0 : g_Config.iLockedCPUSpeed;
}

// The CPU mhz can only be a multiple of the PLL divided by 511.
int PowerCpuMhzToHz(int desired, int pllHz) {
double maxfreq = desired * 1000000.0;
Expand Down Expand Up @@ -115,10 +122,10 @@ void __PowerInit() {
volatileMemLocked = false;
volatileWaitingThreads.clear();

if (g_Config.iLockedCPUSpeed > 0) {
pllFreq = PowerPllMhzToHz(g_Config.iLockedCPUSpeed);
if (GetLockedCPUSpeedMhz() > 0) {
pllFreq = PowerPllMhzToHz(GetLockedCPUSpeedMhz());
busFreq = PowerBusMhzToHz(pllFreq / 2000000);
CoreTiming::SetClockFrequencyHz(PowerCpuMhzToHz(g_Config.iLockedCPUSpeed, pllFreq));
CoreTiming::SetClockFrequencyHz(PowerCpuMhzToHz(GetLockedCPUSpeedMhz(), pllFreq));
} else {
pllFreq = PowerPllMhzToHz(222);
busFreq = PowerBusMhzToHz(111);
Expand All @@ -144,10 +151,10 @@ void __PowerDoState(PointerWrap &p) {
RealpllFreq = PowerPllMhzToHz(222);
RealbusFreq = PowerBusMhzToHz(111);
}
if (g_Config.iLockedCPUSpeed > 0) {
pllFreq = PowerPllMhzToHz(g_Config.iLockedCPUSpeed);
if (GetLockedCPUSpeedMhz() > 0) {
pllFreq = PowerPllMhzToHz(GetLockedCPUSpeedMhz());
busFreq = PowerBusMhzToHz(pllFreq / 2000000);
CoreTiming::SetClockFrequencyHz(PowerCpuMhzToHz(g_Config.iLockedCPUSpeed, pllFreq));
CoreTiming::SetClockFrequencyHz(PowerCpuMhzToHz(GetLockedCPUSpeedMhz(), pllFreq));
} else {
pllFreq = RealpllFreq;
busFreq = RealbusFreq;
Expand Down Expand Up @@ -443,8 +450,8 @@ static u32 scePowerSetClockFrequency(u32 pllfreq, u32 cpufreq, u32 busfreq) {
return hleLogWarning(SCEMISC, SCE_KERNEL_ERROR_INVALID_VALUE, "invalid bus frequency");
}
// 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);
if (GetLockedCPUSpeedMhz() > 0) {
INFO_LOG(HLE, "scePowerSetClockFrequency(%i,%i,%i): locked by user config at %i, %i, %i", pllfreq, cpufreq, busfreq, GetLockedCPUSpeedMhz(), GetLockedCPUSpeedMhz(), busFreq);
} else {
INFO_LOG(HLE, "scePowerSetClockFrequency(%i,%i,%i)", pllfreq, cpufreq, busfreq);
}
Expand All @@ -455,7 +462,7 @@ static u32 scePowerSetClockFrequency(u32 pllfreq, u32 cpufreq, u32 busfreq) {

RealpllFreq = PowerPllMhzToHz(pllfreq);
RealbusFreq = PowerBusMhzToHz(RealpllFreq / 2000000);
if (g_Config.iLockedCPUSpeed <= 0) {
if (GetLockedCPUSpeedMhz() <= 0) {
pllFreq = RealpllFreq;
busFreq = RealbusFreq;
CoreTiming::SetClockFrequencyHz(PowerCpuMhzToHz(cpufreq, pllFreq));
Expand All @@ -471,7 +478,7 @@ static u32 scePowerSetClockFrequency(u32 pllfreq, u32 cpufreq, u32 busfreq) {

return hleDelayResult(0, "scepower set clockFrequency", usec);
}
if (g_Config.iLockedCPUSpeed <= 0)
if (GetLockedCPUSpeedMhz() <= 0)
CoreTiming::SetClockFrequencyHz(PowerCpuMhzToHz(cpufreq, pllFreq));
return 0;
}
Expand All @@ -480,8 +487,8 @@ static u32 scePowerSetCpuClockFrequency(u32 cpufreq) {
if (cpufreq == 0 || cpufreq > 333) {
return hleLogWarning(SCEMISC, SCE_KERNEL_ERROR_INVALID_VALUE, "invalid frequency");
}
if (g_Config.iLockedCPUSpeed > 0) {
return hleLogDebug(SCEMISC, 0, "locked by user config at %i", g_Config.iLockedCPUSpeed);
if (GetLockedCPUSpeedMhz() > 0) {
return hleLogDebug(SCEMISC, 0, "locked by user config at %i", GetLockedCPUSpeedMhz());
}
CoreTiming::SetClockFrequencyHz(PowerCpuMhzToHz(cpufreq, pllFreq));
return hleLogSuccessI(SCEMISC, 0);
Expand All @@ -491,8 +498,8 @@ static u32 scePowerSetBusClockFrequency(u32 busfreq) {
if (busfreq == 0 || busfreq > 111) {
return hleLogWarning(SCEMISC, SCE_KERNEL_ERROR_INVALID_VALUE, "invalid frequency");
}
if (g_Config.iLockedCPUSpeed > 0) {
return hleLogDebug(SCEMISC, 0, "locked by user config at %i", g_Config.iLockedCPUSpeed / 2);
if (GetLockedCPUSpeedMhz() > 0) {
return hleLogDebug(SCEMISC, 0, "locked by user config at %i", GetLockedCPUSpeedMhz() / 2);
}

// The value passed is validated, but then doesn't seem to matter for the result.
Expand Down
3 changes: 3 additions & 0 deletions Core/HLE/scePower.h
Expand Up @@ -27,3 +27,6 @@ void Register_sceSuspendForUser();

int KernelVolatileMemLock(int type, u32 paddr, u32 psize);
int KernelVolatileMemUnlock(int type);

// Returns 0 for default.
int GetLockedCPUSpeedMhz();
14 changes: 8 additions & 6 deletions Core/Reporting.cpp
Expand Up @@ -16,6 +16,7 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include "ppsspp_config.h"

#include <deque>
#include <thread>
#include <mutex>
Expand All @@ -37,25 +38,26 @@ extern "C" {
#include "Common/StringUtils.h"
#include "Common/System/OSD.h"
#include "Common/Data/Text/I18n.h"
#include "Common/Net/HTTPClient.h"
#include "Common/Net/Resolve.h"
#include "Common/Net/URL.h"
#include "Common/Thread/ThreadUtil.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h"
#include "Core/Config.h"
#include "Core/CwCheat.h"
#include "Core/Loaders.h"
#include "Core/SaveState.h"
#include "Core/System.h"
#include "Core/ELF/ParamSFO.h"
#include "Core/FileSystems/BlockDevices.h"
#include "Core/FileSystems/MetaFileSystem.h"
#include "Core/HLE/Plugins.h"
#include "Core/HLE/sceKernelMemory.h"
#include "Core/HLE/scePower.h"
#include "Core/HW/Display.h"
#include "Core/ELF/ParamSFO.h"
#include "GPU/GPUInterface.h"
#include "GPU/GPUState.h"
#include "Common/Net/HTTPClient.h"
#include "Common/Net/Resolve.h"
#include "Common/Net/URL.h"
#include "Common/Thread/ThreadUtil.h"

namespace Reporting
{
Expand Down Expand Up @@ -584,7 +586,7 @@ namespace Reporting
// Disabled when using certain hacks, because they make for poor reports.
if (CheatsInEffect() || HLEPlugins::HasEnabled())
return false;
if (g_Config.iLockedCPUSpeed != 0)
if (GetLockedCPUSpeedMhz() != 0)
return false;
if (g_Config.uJitDisableFlags != 0)
return false;
Expand Down
3 changes: 2 additions & 1 deletion UI/EmuScreen.cpp
Expand Up @@ -72,6 +72,7 @@ using namespace std::placeholders;
#include "Core/RetroAchievements.h"
#include "Core/SaveState.h"
#include "Core/MIPS/MIPS.h"
#include "Core/HLE/scePower.h"
#include "Core/HLE/__sceAudio.h"
#include "Core/HLE/proAdhoc.h"
#include "Core/HLE/Plugins.h"
Expand Down Expand Up @@ -1366,7 +1367,7 @@ Invalid / Unknown (%d)
"Locked CPU freq: %d MHz\n"
"Cheats: %s, Plugins: %s\n",
CPUCoreAsString(g_Config.iCpuCore), g_Config.uJitDisableFlags,
g_Config.iLockedCPUSpeed,
GetLockedCPUSpeedMhz(),
CheatsInEffect() ? "Y" : "N", HLEPlugins::HasEnabled() ? "Y" : "N");

ctx->Draw()->DrawTextShadow(ubuntu24, statbuf, x, y, 0xFFFFFFFF);
Expand Down

0 comments on commit fc49c10

Please sign in to comment.