aboutsummaryrefslogtreecommitdiff
path: root/src/core/core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/core.cpp')
-rw-r--r--src/core/core.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index f3d224b1ce..3728ccf8f7 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -2,11 +2,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include <array>
+#include <cstdlib>
#include <atomic>
#include <memory>
#include <utility>
#include "game_settings.h"
+#include "common/cpu_features.h"
#include "audio_core/audio_core.h"
#include "common/fs/fs.h"
#include "common/logging.h"
@@ -313,16 +315,33 @@ struct System::Impl {
fs_controller.InitTempStorage();
}
+ const bool switch2_program =
+ virtual_filesystem != nullptr &&
+ IsSwitch2Program(GetGameFileFromPath(virtual_filesystem, filepath));
+
// Switch 2 titles size their heap from the total memory and need the 12 GiB layout. Set it
// as a per-game value, so RestoreGlobalState brings back the configured layout afterwards.
- if (virtual_filesystem != nullptr &&
- Settings::values.memory_layout_mode.GetValue() != Settings::MemoryLayout::Memory_12Gb &&
- IsSwitch2Program(GetGameFileFromPath(virtual_filesystem, filepath))) {
+ if (switch2_program &&
+ Settings::values.memory_layout_mode.GetValue() != Settings::MemoryLayout::Memory_12Gb) {
LOG_INFO(Core, "Switch 2 program: using the 12 GiB memory layout");
Settings::values.memory_layout_mode.SetGlobal(false);
Settings::values.memory_layout_mode.SetValue(Settings::MemoryLayout::Memory_12Gb);
}
+ // The Switch 2 counter runs at 31.25 MHz and its SDK converts ticks with that constant
+ // (nn::os::GetSystemTickFrequency, TickManager::ConvertToTimeSpan/ConvertToTick). At 19.2 MHz
+ // every tick-based time in the game was off by 1.63x: elapsed times read short and a frame
+ // deadline in ticks waited ~27 ms. EDEN_NX2_CNTFRQ=<Hz> overrides it (A/B tests).
+ static const u64 forced_cntfrq = [] {
+ const char* value = std::getenv("EDEN_NX2_CNTFRQ");
+ return value != nullptr ? std::strtoull(value, nullptr, 10) : 0ULL;
+ }();
+ const u64 cntfrq = forced_cntfrq != 0 ? forced_cntfrq
+ : switch2_program ? Common::WallClock::Switch2CNTFRQ
+ : Common::WallClock::CNTFRQ;
+ Common::g_wall_clock.SetGuestCNTFRQ(cntfrq);
+ LOG_INFO(Core, "Guest counter frequency: {} Hz", cntfrq);
+
InitializeKernel(system);
if (params.applet_type == Service::AM::AppletType::Application) {