Skip to content

Commit

Permalink
readd overclocking option
Browse files Browse the repository at this point in the history
  • Loading branch information
RSDuck committed Feb 12, 2021
1 parent 20a8894 commit e65e86a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/frontend/switch/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ void DoGui(BoxGui::Frame& parent)
DoCheckbox(settingsFrame, settingsSkewer, "Boot directly (Skip bios)", bootDirectly);
Config::DirectBoot = bootDirectly;
}
DoCombobox(settingsFrame, settingsSkewer, "Overclocking", "1020 MHz\0" "1224 MHz\0" "1581 MHz\0" "1785 MHz\0", Config::SwitchOverclock);
}
{
bool jitEnable = Config::JIT_Enable;
Expand Down
76 changes: 74 additions & 2 deletions src/frontend/switch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,64 @@ void EndSection()

}

namespace Overclocking
{

bool UsePCV;
ClkrstSession Session;

void ApplyOverclock(int setting)
{
const int clockSpeeds[] = { 1020000000, 1224000000, 1581000000, 1785000000 };
printf("applying overclock %d\n", clockSpeeds[setting]);
if (UsePCV)
pcvSetClockRate(PcvModule_CpuBus, clockSpeeds[setting]);
else
clkrstSetClockRate(&Session, clockSpeeds[setting]);
}

void OnAppletHook(AppletHookType hook)
{
if ((hook == AppletHookType_OnOperationMode
|| hook == AppletHookType_OnPerformanceMode
|| hook == AppletHookType_OnResume
|| hook == AppletHookType_OnExitRequest)
&& Emulation::State == Emulation::emuState_Running)
{
ApplyOverclock(Config::SwitchOverclock);
}
}

void Init()
{
UsePCV = hosversionBefore(8, 0, 0);
if (UsePCV)
{
pcvInitialize();
}
else
{
clkrstInitialize();
clkrstOpenSession(&Session, PcvModuleId_CpuBus, 0);
}
}

void DeInit()
{
ApplyOverclock(0);
if (UsePCV)
{
pcvExit();
}
else
{
clkrstCloseSession(&Session);
clkrstExit();
}
}

}

namespace Emulation
{

Expand Down Expand Up @@ -828,6 +886,8 @@ std::string GetLoadErrorStr(int error)

void LoadROM(const char* file)
{
Overclocking::ApplyOverclock(Config::SwitchOverclock);

assert(State == emuState_Nothing);
mutexLock(&EmuThreadLock);
int res = Frontend::LoadROM(file, 0);
Expand All @@ -847,6 +907,8 @@ void LoadROM(const char* file)

void LoadBIOS()
{
Overclocking::ApplyOverclock(Config::SwitchOverclock);

assert(State == emuState_Nothing);
mutexLock(&EmuThreadLock);
int res = Frontend::LoadBIOS();
Expand All @@ -866,6 +928,8 @@ void LoadBIOS()

void SetPause(bool pause)
{
Overclocking::ApplyOverclock(pause ? 0 : Config::SwitchOverclock);

PlatformKeysHeld = 0;
mutexLock(&EmuThreadLock);
assert(State == (pause ? emuState_Running : emuState_Paused));
Expand Down Expand Up @@ -955,13 +1019,15 @@ extern char ExecutableDir[];
void OnAppletHook(AppletHookType hook, void *param)
{
if (hook == AppletHookType_OnPerformanceMode)
{
Emulation::UpdateScreenLayout();
}

Overclocking::OnAppletHook(hook);
}

int main(int argc, const char* argv[])
{
appletLockExit();

socketInitializeDefault();
nxlinkStdio();

Expand All @@ -975,6 +1041,8 @@ int main(int argc, const char* argv[])

Gfx::Init();

Overclocking::Init();

AppletHookCookie aptCookie;
appletHook(&aptCookie, OnAppletHook, NULL);

Expand Down Expand Up @@ -1062,6 +1130,8 @@ int main(int argc, const char* argv[])
StartMenu::DeInit();
Filebrowser::DeInit();

Overclocking::DeInit();

Config::Save();

appletUnhook(&aptCookie);
Expand All @@ -1073,5 +1143,7 @@ int main(int argc, const char* argv[])

socketExit();

appletUnlockExit();

return 0;
}

0 comments on commit e65e86a

Please sign in to comment.