2014-04-09 01:19:26 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-04-09 01:19:26 +02:00
|
|
|
// Refer to the license.txt file included.
|
2013-09-06 00:33:46 +02:00
|
|
|
|
2020-03-07 22:23:08 +01:00
|
|
|
#include <stdexcept>
|
2017-03-09 02:21:31 +01:00
|
|
|
#include <utility>
|
2019-12-27 19:52:33 +01:00
|
|
|
#include <boost/serialization/array.hpp>
|
2017-12-20 19:44:32 +01:00
|
|
|
#include "audio_core/dsp_interface.h"
|
|
|
|
#include "audio_core/hle/hle.h"
|
2018-12-06 17:13:13 +01:00
|
|
|
#include "audio_core/lle/lle.h"
|
2023-01-06 16:28:02 +01:00
|
|
|
#include "common/arch.h"
|
2015-05-06 09:06:12 +02:00
|
|
|
#include "common/logging/log.h"
|
2023-06-17 01:06:18 +02:00
|
|
|
#include "common/settings.h"
|
2014-12-22 07:30:09 +01:00
|
|
|
#include "core/arm/arm_interface.h"
|
2022-06-21 20:59:36 +02:00
|
|
|
#include "core/arm/exclusive_monitor.h"
|
2023-06-30 12:39:38 +02:00
|
|
|
#include "core/hle/service/cam/cam.h"
|
2023-08-01 02:57:38 +02:00
|
|
|
#include "core/hle/service/hid/hid.h"
|
|
|
|
#include "core/hle/service/ir/ir_user.h"
|
2023-01-06 16:28:02 +01:00
|
|
|
#if CITRA_ARCH(x86_64) || CITRA_ARCH(arm64)
|
2016-09-02 05:18:01 +02:00
|
|
|
#include "core/arm/dynarmic/arm_dynarmic.h"
|
2018-01-08 17:58:24 +01:00
|
|
|
#endif
|
2014-10-25 21:54:44 +02:00
|
|
|
#include "core/arm/dyncom/arm_dyncom.h"
|
2018-11-17 02:01:10 +01:00
|
|
|
#include "core/cheats/cheats.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "core/core.h"
|
2016-09-02 05:18:01 +02:00
|
|
|
#include "core/core_timing.h"
|
2019-01-26 15:36:39 +01:00
|
|
|
#include "core/dumping/backend.h"
|
2023-04-27 06:38:28 +02:00
|
|
|
#include "core/frontend/image_interface.h"
|
2016-09-02 05:18:01 +02:00
|
|
|
#include "core/gdbstub/gdbstub.h"
|
2019-12-25 19:51:56 +01:00
|
|
|
#include "core/global.h"
|
2016-12-16 01:01:48 +01:00
|
|
|
#include "core/hle/kernel/kernel.h"
|
2017-09-27 01:17:47 +02:00
|
|
|
#include "core/hle/kernel/process.h"
|
2014-05-23 04:54:07 +02:00
|
|
|
#include "core/hle/kernel/thread.h"
|
2020-11-24 20:10:31 +01:00
|
|
|
#include "core/hle/service/apt/applet_manager.h"
|
|
|
|
#include "core/hle/service/apt/apt.h"
|
2023-06-30 12:39:38 +02:00
|
|
|
#include "core/hle/service/cam/cam.h"
|
2018-09-29 18:39:31 +02:00
|
|
|
#include "core/hle/service/fs/archive.h"
|
2020-01-04 01:40:32 +01:00
|
|
|
#include "core/hle/service/gsp/gsp.h"
|
2023-06-30 12:39:38 +02:00
|
|
|
#include "core/hle/service/ir/ir_rst.h"
|
2023-08-02 00:37:56 +02:00
|
|
|
#include "core/hle/service/mic/mic_u.h"
|
2023-06-30 12:39:38 +02:00
|
|
|
#include "core/hle/service/plgldr/plgldr.h"
|
2016-12-16 06:37:38 +01:00
|
|
|
#include "core/hle/service/service.h"
|
2018-04-13 05:06:21 +02:00
|
|
|
#include "core/hle/service/sm/sm.h"
|
2019-08-07 03:53:56 +02:00
|
|
|
#include "core/hw/gpu.h"
|
2014-10-25 21:54:44 +02:00
|
|
|
#include "core/hw/hw.h"
|
2019-08-07 03:53:56 +02:00
|
|
|
#include "core/hw/lcd.h"
|
2016-12-16 01:01:48 +01:00
|
|
|
#include "core/loader/loader.h"
|
2017-12-17 04:43:09 +01:00
|
|
|
#include "core/movie.h"
|
2023-08-06 21:23:53 +02:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
2023-07-14 01:29:54 +02:00
|
|
|
#include "core/rpc/server.h"
|
2023-08-06 21:23:53 +02:00
|
|
|
#endif
|
2023-08-01 02:57:38 +02:00
|
|
|
#include "core/telemetry_session.h"
|
2017-08-19 19:14:33 +02:00
|
|
|
#include "network/network.h"
|
2023-04-27 06:38:28 +02:00
|
|
|
#include "video_core/custom_textures/custom_tex_manager.h"
|
2020-04-11 11:28:52 +02:00
|
|
|
#include "video_core/renderer_base.h"
|
2016-12-16 01:01:48 +01:00
|
|
|
#include "video_core/video_core.h"
|
2015-09-02 14:56:38 +02:00
|
|
|
|
2013-09-06 00:33:46 +02:00
|
|
|
namespace Core {
|
|
|
|
|
2023-06-24 17:30:13 +02:00
|
|
|
/*static*/ System System::s_instance;
|
|
|
|
|
2019-12-25 19:51:56 +01:00
|
|
|
template <>
|
2019-12-27 22:07:29 +01:00
|
|
|
Core::System& Global() {
|
|
|
|
return System::GetInstance();
|
|
|
|
}
|
2019-12-25 19:51:56 +01:00
|
|
|
|
|
|
|
template <>
|
2019-12-27 22:07:29 +01:00
|
|
|
Kernel::KernelSystem& Global() {
|
|
|
|
return System::GetInstance().Kernel();
|
|
|
|
}
|
2019-12-25 19:51:56 +01:00
|
|
|
|
2020-03-28 16:47:36 +01:00
|
|
|
template <>
|
|
|
|
Core::Timing& Global() {
|
|
|
|
return System::GetInstance().CoreTiming();
|
|
|
|
}
|
|
|
|
|
2023-08-01 02:57:38 +02:00
|
|
|
System::System() : movie{*this} {}
|
|
|
|
|
2020-02-18 06:19:52 +01:00
|
|
|
System::~System() = default;
|
|
|
|
|
2017-12-03 03:57:08 +01:00
|
|
|
System::ResultStatus System::RunLoop(bool tight_loop) {
|
2017-06-02 23:03:38 +02:00
|
|
|
status = ResultStatus::Success;
|
2023-03-30 13:24:49 +02:00
|
|
|
if (!IsPoweredOn()) {
|
2016-12-16 01:01:48 +01:00
|
|
|
return ResultStatus::ErrorNotInitialized;
|
|
|
|
}
|
2013-09-06 00:33:46 +02:00
|
|
|
|
2016-12-15 22:19:30 +01:00
|
|
|
if (GDBStub::IsServerEnabled()) {
|
2020-04-06 22:24:54 +02:00
|
|
|
Kernel::Thread* thread = kernel->GetCurrentThreadManager().GetCurrentThread();
|
|
|
|
if (thread && running_core) {
|
|
|
|
running_core->SaveContext(thread->context);
|
|
|
|
}
|
2023-08-02 00:40:39 +02:00
|
|
|
GDBStub::HandlePacket(*this);
|
2015-09-02 14:56:38 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
// If the loop is halted and we want to step, use a tiny (1) number of instructions to
|
2016-09-19 03:01:46 +02:00
|
|
|
// execute. Otherwise, get out of the loop function.
|
2015-09-02 14:56:38 +02:00
|
|
|
if (GDBStub::GetCpuHaltFlag()) {
|
|
|
|
if (GDBStub::GetCpuStepFlag()) {
|
2018-08-16 11:40:52 +02:00
|
|
|
tight_loop = false;
|
2015-09-02 14:56:38 +02:00
|
|
|
} else {
|
2016-12-16 01:01:48 +01:00
|
|
|
return ResultStatus::Success;
|
2015-09-02 14:56:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-11 23:25:57 +02:00
|
|
|
Signal signal{Signal::None};
|
|
|
|
u32 param{};
|
|
|
|
{
|
|
|
|
std::lock_guard lock{signal_mutex};
|
|
|
|
if (current_signal != Signal::None) {
|
|
|
|
signal = current_signal;
|
|
|
|
param = signal_param;
|
|
|
|
current_signal = Signal::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (signal) {
|
|
|
|
case Signal::Reset:
|
|
|
|
Reset();
|
|
|
|
return ResultStatus::Success;
|
|
|
|
case Signal::Shutdown:
|
|
|
|
return ResultStatus::ShutdownRequested;
|
|
|
|
case Signal::Load: {
|
2023-04-05 19:50:51 +02:00
|
|
|
const u32 slot = param;
|
|
|
|
LOG_INFO(Core, "Begin load of slot {}", slot);
|
2020-04-13 00:12:15 +02:00
|
|
|
try {
|
2023-04-05 19:50:51 +02:00
|
|
|
System::LoadState(slot);
|
2020-04-13 00:12:15 +02:00
|
|
|
LOG_INFO(Core, "Load completed");
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
LOG_ERROR(Core, "Error loading: {}", e.what());
|
|
|
|
status_details = e.what();
|
|
|
|
return ResultStatus::ErrorSavestate;
|
|
|
|
}
|
2020-04-11 23:25:57 +02:00
|
|
|
frame_limiter.WaitOnce();
|
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
case Signal::Save: {
|
2023-04-05 19:50:51 +02:00
|
|
|
const u32 slot = param;
|
|
|
|
LOG_INFO(Core, "Begin save to slot {}", slot);
|
2020-04-13 00:12:15 +02:00
|
|
|
try {
|
2023-04-05 19:50:51 +02:00
|
|
|
System::SaveState(slot);
|
2020-04-13 00:12:15 +02:00
|
|
|
LOG_INFO(Core, "Save completed");
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
LOG_ERROR(Core, "Error saving: {}", e.what());
|
|
|
|
status_details = e.what();
|
|
|
|
return ResultStatus::ErrorSavestate;
|
|
|
|
}
|
2020-04-11 23:25:57 +02:00
|
|
|
frame_limiter.WaitOnce();
|
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-21 19:31:32 +01:00
|
|
|
// All cores should have executed the same amount of ticks. If this is not the case an event was
|
|
|
|
// scheduled with a cycles_into_future smaller then the current downcount.
|
|
|
|
// So we have to get those cores to the same global time first
|
|
|
|
u64 global_ticks = timing->GetGlobalTicks();
|
|
|
|
s64 max_delay = 0;
|
2020-04-22 07:44:58 +02:00
|
|
|
ARM_Interface* current_core_to_execute = nullptr;
|
2020-02-21 19:31:32 +01:00
|
|
|
for (auto& cpu_core : cpu_cores) {
|
2020-04-22 07:44:58 +02:00
|
|
|
if (cpu_core->GetTimer().GetTicks() < global_ticks) {
|
|
|
|
s64 delay = global_ticks - cpu_core->GetTimer().GetTicks();
|
2020-05-12 22:48:30 +02:00
|
|
|
kernel->SetRunningCPU(cpu_core.get());
|
|
|
|
cpu_core->GetTimer().Advance();
|
|
|
|
cpu_core->PrepareReschedule();
|
|
|
|
kernel->GetThreadManager(cpu_core->GetID()).Reschedule();
|
|
|
|
cpu_core->GetTimer().SetNextSlice(delay);
|
2020-02-21 19:31:32 +01:00
|
|
|
if (max_delay < delay) {
|
|
|
|
max_delay = delay;
|
2020-04-22 07:44:58 +02:00
|
|
|
current_core_to_execute = cpu_core.get();
|
2020-02-21 19:31:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 22:48:30 +02:00
|
|
|
// jit sometimes overshoot by a few ticks which might lead to a minimal desync in the cores.
|
|
|
|
// This small difference shouldn't make it necessary to sync the cores and would only cost
|
|
|
|
// performance. Thus we don't sync delays below min_delay
|
|
|
|
static constexpr s64 min_delay = 100;
|
|
|
|
if (max_delay > min_delay) {
|
2020-02-21 19:31:32 +01:00
|
|
|
LOG_TRACE(Core_ARM11, "Core {} running (delayed) for {} ticks",
|
2020-05-29 01:53:14 +02:00
|
|
|
current_core_to_execute->GetID(),
|
|
|
|
current_core_to_execute->GetTimer().GetDowncount());
|
2020-04-22 07:44:58 +02:00
|
|
|
if (running_core != current_core_to_execute) {
|
|
|
|
running_core = current_core_to_execute;
|
|
|
|
kernel->SetRunningCPU(running_core);
|
|
|
|
}
|
2020-02-21 19:31:32 +01:00
|
|
|
if (kernel->GetCurrentThreadManager().GetCurrentThread() == nullptr) {
|
|
|
|
LOG_TRACE(Core_ARM11, "Core {} idling", current_core_to_execute->GetID());
|
2020-04-22 07:44:58 +02:00
|
|
|
current_core_to_execute->GetTimer().Idle();
|
2020-02-21 19:31:32 +01:00
|
|
|
PrepareReschedule();
|
2017-12-03 03:57:08 +01:00
|
|
|
} else {
|
2020-02-21 19:31:32 +01:00
|
|
|
if (tight_loop) {
|
|
|
|
current_core_to_execute->Run();
|
|
|
|
} else {
|
|
|
|
current_core_to_execute->Step();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Now all cores are at the same global time. So we will run them one after the other
|
|
|
|
// with a max slice that is the minimum of all max slices of all cores
|
|
|
|
// TODO: Make special check for idle since we can easily revert the time of idle cores
|
|
|
|
s64 max_slice = Timing::MAX_SLICE_LENGTH;
|
|
|
|
for (const auto& cpu_core : cpu_cores) {
|
2020-05-12 22:48:30 +02:00
|
|
|
kernel->SetRunningCPU(cpu_core.get());
|
|
|
|
cpu_core->GetTimer().Advance();
|
|
|
|
cpu_core->PrepareReschedule();
|
|
|
|
kernel->GetThreadManager(cpu_core->GetID()).Reschedule();
|
2020-04-22 07:44:58 +02:00
|
|
|
max_slice = std::min(max_slice, cpu_core->GetTimer().GetMaxSliceLength());
|
2020-02-21 19:31:32 +01:00
|
|
|
}
|
|
|
|
for (auto& cpu_core : cpu_cores) {
|
2020-05-12 22:48:30 +02:00
|
|
|
cpu_core->GetTimer().SetNextSlice(max_slice);
|
|
|
|
auto start_ticks = cpu_core->GetTimer().GetTicks();
|
2020-02-21 19:31:32 +01:00
|
|
|
LOG_TRACE(Core_ARM11, "Core {} running for {} ticks", cpu_core->GetID(),
|
2020-04-22 07:44:58 +02:00
|
|
|
cpu_core->GetTimer().GetDowncount());
|
2020-02-21 19:31:32 +01:00
|
|
|
running_core = cpu_core.get();
|
2020-04-22 07:44:58 +02:00
|
|
|
kernel->SetRunningCPU(running_core);
|
2020-02-21 19:31:32 +01:00
|
|
|
// If we don't have a currently active thread then don't execute instructions,
|
|
|
|
// instead advance to the next event and try to yield to the next thread
|
|
|
|
if (kernel->GetCurrentThreadManager().GetCurrentThread() == nullptr) {
|
|
|
|
LOG_TRACE(Core_ARM11, "Core {} idling", cpu_core->GetID());
|
2020-04-22 07:44:58 +02:00
|
|
|
cpu_core->GetTimer().Idle();
|
2020-02-21 19:31:32 +01:00
|
|
|
PrepareReschedule();
|
|
|
|
} else {
|
|
|
|
if (tight_loop) {
|
|
|
|
cpu_core->Run();
|
|
|
|
} else {
|
|
|
|
cpu_core->Step();
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 22:48:30 +02:00
|
|
|
max_slice = cpu_core->GetTimer().GetTicks() - start_ticks;
|
2017-12-03 03:57:08 +01:00
|
|
|
}
|
2015-01-07 16:10:58 +01:00
|
|
|
}
|
|
|
|
|
2018-08-16 11:40:52 +02:00
|
|
|
if (GDBStub::IsServerEnabled()) {
|
|
|
|
GDBStub::SetCpuStepFlag(false);
|
|
|
|
}
|
|
|
|
|
2014-08-30 05:24:32 +02:00
|
|
|
HW::Update();
|
2016-12-16 06:37:38 +01:00
|
|
|
Reschedule();
|
2013-09-27 04:01:09 +02:00
|
|
|
|
2017-06-02 23:03:38 +02:00
|
|
|
return status;
|
2013-09-06 00:33:46 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 06:19:52 +01:00
|
|
|
bool System::SendSignal(System::Signal signal, u32 param) {
|
|
|
|
std::lock_guard lock{signal_mutex};
|
|
|
|
if (current_signal != signal && current_signal != Signal::None) {
|
|
|
|
LOG_ERROR(Core, "Unable to {} as {} is ongoing", signal, current_signal);
|
2020-01-12 01:24:44 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-02-18 06:19:52 +01:00
|
|
|
current_signal = signal;
|
|
|
|
signal_param = param;
|
2020-01-12 01:24:44 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-16 01:01:48 +01:00
|
|
|
System::ResultStatus System::SingleStep() {
|
2017-12-03 03:57:08 +01:00
|
|
|
return RunLoop(false);
|
2013-09-27 04:01:09 +02:00
|
|
|
}
|
|
|
|
|
2022-11-17 16:37:30 +01:00
|
|
|
System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath,
|
|
|
|
Frontend::EmuWindow* secondary_window) {
|
2020-04-05 01:20:59 +02:00
|
|
|
FileUtil::SetCurrentRomPath(filepath);
|
2016-12-16 01:01:48 +01:00
|
|
|
app_loader = Loader::GetLoader(filepath);
|
|
|
|
if (!app_loader) {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
|
2016-12-16 01:01:48 +01:00
|
|
|
return ResultStatus::ErrorGetLoader;
|
|
|
|
}
|
|
|
|
|
2023-07-29 09:26:16 +02:00
|
|
|
auto memory_mode = app_loader->LoadKernelMemoryMode();
|
|
|
|
if (memory_mode.second != Loader::ResultStatus::Success) {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_CRITICAL(Core, "Failed to determine system mode (Error {})!",
|
2023-07-29 09:26:16 +02:00
|
|
|
static_cast<int>(memory_mode.second));
|
2017-03-08 22:28:30 +01:00
|
|
|
|
2023-07-29 09:26:16 +02:00
|
|
|
switch (memory_mode.second) {
|
2017-03-08 22:28:30 +01:00
|
|
|
case Loader::ResultStatus::ErrorEncrypted:
|
|
|
|
return ResultStatus::ErrorLoader_ErrorEncrypted;
|
|
|
|
case Loader::ResultStatus::ErrorInvalidFormat:
|
|
|
|
return ResultStatus::ErrorLoader_ErrorInvalidFormat;
|
2023-01-23 10:51:57 +01:00
|
|
|
case Loader::ResultStatus::ErrorGbaTitle:
|
|
|
|
return ResultStatus::ErrorLoader_ErrorGbaTitle;
|
2017-03-08 22:28:30 +01:00
|
|
|
default:
|
|
|
|
return ResultStatus::ErrorSystemMode;
|
|
|
|
}
|
2016-12-16 01:01:48 +01:00
|
|
|
}
|
|
|
|
|
2023-07-29 09:26:16 +02:00
|
|
|
ASSERT(memory_mode.first);
|
|
|
|
auto n3ds_hw_caps = app_loader->LoadNew3dsHwCapabilities();
|
|
|
|
ASSERT(n3ds_hw_caps.first);
|
2020-04-12 23:26:24 +02:00
|
|
|
u32 num_cores = 2;
|
|
|
|
if (Settings::values.is_new_3ds) {
|
|
|
|
num_cores = 4;
|
|
|
|
}
|
2022-11-17 16:37:30 +01:00
|
|
|
ResultStatus init_result{
|
2023-07-29 09:26:16 +02:00
|
|
|
Init(emu_window, secondary_window, *memory_mode.first, *n3ds_hw_caps.first, num_cores)};
|
2016-12-16 01:01:48 +01:00
|
|
|
if (init_result != ResultStatus::Success) {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_CRITICAL(Core, "Failed to initialize system (Error {})!",
|
2018-06-29 15:56:12 +02:00
|
|
|
static_cast<u32>(init_result));
|
2016-12-16 01:01:48 +01:00
|
|
|
System::Shutdown();
|
|
|
|
return init_result;
|
|
|
|
}
|
|
|
|
|
2019-05-29 03:12:23 +02:00
|
|
|
telemetry_session->AddInitialInfo(*app_loader);
|
2019-03-23 21:04:19 +01:00
|
|
|
std::shared_ptr<Kernel::Process> process;
|
2018-10-17 21:23:56 +02:00
|
|
|
const Loader::ResultStatus load_result{app_loader->Load(process)};
|
2017-06-02 23:03:38 +02:00
|
|
|
if (Loader::ResultStatus::Success != load_result) {
|
2020-12-29 06:39:21 +01:00
|
|
|
LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result);
|
2016-12-16 01:01:48 +01:00
|
|
|
System::Shutdown();
|
|
|
|
|
|
|
|
switch (load_result) {
|
|
|
|
case Loader::ResultStatus::ErrorEncrypted:
|
|
|
|
return ResultStatus::ErrorLoader_ErrorEncrypted;
|
|
|
|
case Loader::ResultStatus::ErrorInvalidFormat:
|
|
|
|
return ResultStatus::ErrorLoader_ErrorInvalidFormat;
|
2023-01-23 10:51:57 +01:00
|
|
|
case Loader::ResultStatus::ErrorGbaTitle:
|
|
|
|
return ResultStatus::ErrorLoader_ErrorGbaTitle;
|
2016-12-16 01:01:48 +01:00
|
|
|
default:
|
|
|
|
return ResultStatus::ErrorLoader;
|
|
|
|
}
|
|
|
|
}
|
2023-01-23 10:51:57 +01:00
|
|
|
kernel->SetCurrentProcess(process);
|
2020-02-18 06:19:52 +01:00
|
|
|
title_id = 0;
|
2019-08-13 06:15:00 +02:00
|
|
|
if (app_loader->ReadProgramId(title_id) != Loader::ResultStatus::Success) {
|
|
|
|
LOG_ERROR(Core, "Failed to find title id for ROM (Error {})",
|
|
|
|
static_cast<u32>(load_result));
|
|
|
|
}
|
2023-04-30 16:36:02 +02:00
|
|
|
cheat_engine = std::make_unique<Cheats::CheatEngine>(title_id, *this);
|
2019-08-13 06:15:00 +02:00
|
|
|
perf_stats = std::make_unique<PerfStats>(title_id);
|
2020-04-21 04:50:16 +02:00
|
|
|
|
2023-08-01 19:38:51 +02:00
|
|
|
if (Settings::values.dump_textures) {
|
|
|
|
custom_tex_manager->PrepareDumping(title_id);
|
|
|
|
}
|
2019-08-14 07:04:50 +02:00
|
|
|
if (Settings::values.custom_textures) {
|
2023-04-27 06:38:28 +02:00
|
|
|
custom_tex_manager->FindCustomTextures();
|
2020-04-21 04:50:16 +02:00
|
|
|
}
|
|
|
|
|
2017-03-08 22:28:30 +01:00
|
|
|
status = ResultStatus::Success;
|
2018-07-18 14:07:00 +02:00
|
|
|
m_emu_window = &emu_window;
|
2022-11-17 16:37:30 +01:00
|
|
|
m_secondary_window = secondary_window;
|
2018-07-18 14:07:00 +02:00
|
|
|
m_filepath = filepath;
|
2022-10-20 23:14:57 +02:00
|
|
|
self_delete_pending = false;
|
2019-08-17 05:33:16 +02:00
|
|
|
|
|
|
|
// Reset counters and set time origin to current frame
|
2022-09-21 18:36:12 +02:00
|
|
|
[[maybe_unused]] const PerfStats::Results result = GetAndResetPerfStats();
|
2019-08-17 05:33:16 +02:00
|
|
|
perf_stats->BeginSystemFrame();
|
2017-06-02 23:03:38 +02:00
|
|
|
return status;
|
2013-09-06 00:33:46 +02:00
|
|
|
}
|
|
|
|
|
2016-12-16 06:37:38 +01:00
|
|
|
void System::PrepareReschedule() {
|
2020-02-21 19:31:32 +01:00
|
|
|
running_core->PrepareReschedule();
|
2016-12-16 06:37:38 +01:00
|
|
|
reschedule_pending = true;
|
|
|
|
}
|
|
|
|
|
2017-02-19 23:34:47 +01:00
|
|
|
PerfStats::Results System::GetAndResetPerfStats() {
|
2020-04-01 23:50:19 +02:00
|
|
|
return (perf_stats && timing) ? perf_stats->GetAndResetStats(timing->GetGlobalTimeUs())
|
|
|
|
: PerfStats::Results{};
|
2017-02-19 23:34:47 +01:00
|
|
|
}
|
|
|
|
|
2016-12-16 06:37:38 +01:00
|
|
|
void System::Reschedule() {
|
|
|
|
if (!reschedule_pending) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
reschedule_pending = false;
|
2020-02-21 19:31:32 +01:00
|
|
|
for (const auto& core : cpu_cores) {
|
|
|
|
LOG_TRACE(Core_ARM11, "Reschedule core {}", core->GetID());
|
|
|
|
kernel->GetThreadManager(core->GetID()).Reschedule();
|
|
|
|
}
|
2016-12-16 06:37:38 +01:00
|
|
|
}
|
|
|
|
|
2022-11-17 16:37:30 +01:00
|
|
|
System::ResultStatus System::Init(Frontend::EmuWindow& emu_window,
|
2023-07-29 09:26:16 +02:00
|
|
|
Frontend::EmuWindow* secondary_window,
|
|
|
|
Kernel::MemoryMode memory_mode,
|
|
|
|
const Kernel::New3dsHwCapabilities& n3ds_hw_caps, u32 num_cores) {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(HW_Memory, "initialized OK");
|
2016-12-16 01:01:48 +01:00
|
|
|
|
2023-08-02 00:40:39 +02:00
|
|
|
memory = std::make_unique<Memory::MemorySystem>(*this);
|
2018-11-21 04:38:47 +01:00
|
|
|
|
2022-12-08 12:27:25 +01:00
|
|
|
timing = std::make_unique<Timing>(num_cores, Settings::values.cpu_clock_percentage.GetValue());
|
2017-12-20 19:44:32 +01:00
|
|
|
|
2020-02-21 19:31:32 +01:00
|
|
|
kernel = std::make_unique<Kernel::KernelSystem>(
|
2023-08-01 02:57:38 +02:00
|
|
|
*memory, *timing, [this] { PrepareReschedule(); }, memory_mode, num_cores, n3ds_hw_caps,
|
|
|
|
movie.GetOverrideInitTime());
|
2018-11-05 16:38:35 +01:00
|
|
|
|
2022-06-21 20:59:36 +02:00
|
|
|
exclusive_monitor = MakeExclusiveMonitor(*memory, num_cores);
|
2023-05-03 17:24:10 +02:00
|
|
|
cpu_cores.reserve(num_cores);
|
2016-09-02 05:18:01 +02:00
|
|
|
if (Settings::values.use_cpu_jit) {
|
2023-01-06 16:28:02 +01:00
|
|
|
#if CITRA_ARCH(x86_64) || CITRA_ARCH(arm64)
|
2020-03-28 10:59:45 +01:00
|
|
|
for (u32 i = 0; i < num_cores; ++i) {
|
2022-10-23 08:25:00 +02:00
|
|
|
cpu_cores.push_back(std::make_shared<ARM_Dynarmic>(
|
2023-11-07 02:55:30 +01:00
|
|
|
*this, *memory, i, timing->GetTimer(i), *exclusive_monitor));
|
2020-02-21 19:31:32 +01:00
|
|
|
}
|
2018-01-08 17:58:24 +01:00
|
|
|
#else
|
2020-03-28 10:59:45 +01:00
|
|
|
for (u32 i = 0; i < num_cores; ++i) {
|
2020-02-21 19:31:32 +01:00
|
|
|
cpu_cores.push_back(
|
|
|
|
std::make_shared<ARM_DynCom>(this, *memory, USER32MODE, i, timing->GetTimer(i)));
|
|
|
|
}
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
|
2018-01-08 17:58:24 +01:00
|
|
|
#endif
|
2016-09-02 05:18:01 +02:00
|
|
|
} else {
|
2020-03-28 10:59:45 +01:00
|
|
|
for (u32 i = 0; i < num_cores; ++i) {
|
2020-02-21 19:31:32 +01:00
|
|
|
cpu_cores.push_back(
|
2023-11-07 02:55:30 +01:00
|
|
|
std::make_shared<ARM_DynCom>(*this, *memory, USER32MODE, i, timing->GetTimer(i)));
|
2020-02-21 19:31:32 +01:00
|
|
|
}
|
2016-12-16 01:01:48 +01:00
|
|
|
}
|
2020-02-21 19:31:32 +01:00
|
|
|
running_core = cpu_cores[0].get();
|
2016-12-16 01:01:48 +01:00
|
|
|
|
2020-02-21 19:31:32 +01:00
|
|
|
kernel->SetCPUs(cpu_cores);
|
2020-04-22 07:44:58 +02:00
|
|
|
kernel->SetRunningCPU(cpu_cores[0].get());
|
2019-02-01 17:23:39 +01:00
|
|
|
|
2022-12-08 12:27:25 +01:00
|
|
|
const auto audio_emulation = Settings::values.audio_emulation.GetValue();
|
|
|
|
if (audio_emulation == Settings::AudioEmulation::HLE) {
|
2023-05-14 06:27:29 +02:00
|
|
|
dsp_core = std::make_unique<AudioCore::DspHle>(*memory, *timing);
|
2022-12-08 12:27:25 +01:00
|
|
|
} else {
|
|
|
|
const bool multithread = audio_emulation == Settings::AudioEmulation::LLEMultithreaded;
|
2023-05-14 06:27:29 +02:00
|
|
|
dsp_core = std::make_unique<AudioCore::DspLle>(*memory, *timing, multithread);
|
2018-12-06 17:13:13 +01:00
|
|
|
}
|
|
|
|
|
2019-02-04 03:33:20 +01:00
|
|
|
memory->SetDSP(*dsp_core);
|
|
|
|
|
2023-05-01 21:17:45 +02:00
|
|
|
dsp_core->SetSink(Settings::values.output_type.GetValue(),
|
|
|
|
Settings::values.output_device.GetValue());
|
2022-12-08 12:27:25 +01:00
|
|
|
dsp_core->EnableStretching(Settings::values.enable_audio_stretching.GetValue());
|
2017-12-20 19:44:32 +01:00
|
|
|
|
2017-05-02 06:09:15 +02:00
|
|
|
telemetry_session = std::make_unique<Core::TelemetrySession>();
|
2018-09-24 00:16:57 +02:00
|
|
|
|
2023-08-06 21:23:53 +02:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
2023-07-14 01:29:54 +02:00
|
|
|
rpc_server = std::make_unique<RPC::Server>(*this);
|
2023-08-06 21:23:53 +02:00
|
|
|
#endif
|
2018-09-24 00:16:57 +02:00
|
|
|
|
2019-12-23 12:41:07 +01:00
|
|
|
service_manager = std::make_unique<Service::SM::ServiceManager>(*this);
|
2018-10-13 22:11:20 +02:00
|
|
|
archive_manager = std::make_unique<Service::FS::ArchiveManager>(*this);
|
2017-05-02 06:09:15 +02:00
|
|
|
|
2018-11-21 17:53:10 +01:00
|
|
|
HW::Init(*memory);
|
2018-10-12 22:11:51 +02:00
|
|
|
Service::Init(*this);
|
2020-02-23 21:33:49 +01:00
|
|
|
GDBStub::DeferStart();
|
2016-12-16 01:01:48 +01:00
|
|
|
|
2023-04-27 06:38:28 +02:00
|
|
|
if (!registered_image_interface) {
|
|
|
|
registered_image_interface = std::make_shared<Frontend::ImageInterface>();
|
|
|
|
}
|
|
|
|
|
|
|
|
custom_tex_manager = std::make_unique<VideoCore::CustomTexManager>(*this);
|
|
|
|
|
2023-03-27 13:29:17 +02:00
|
|
|
VideoCore::Init(emu_window, secondary_window, *this);
|
2014-10-25 21:54:44 +02:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(Core, "Initialized OK");
|
2016-12-16 01:01:48 +01:00
|
|
|
|
2023-03-30 13:24:49 +02:00
|
|
|
is_powered_on = true;
|
2020-02-21 19:31:32 +01:00
|
|
|
|
2016-12-16 01:01:48 +01:00
|
|
|
return ResultStatus::Success;
|
2014-04-01 04:26:50 +02:00
|
|
|
}
|
|
|
|
|
2023-03-27 13:29:17 +02:00
|
|
|
VideoCore::RendererBase& System::Renderer() {
|
2019-09-08 00:13:10 +02:00
|
|
|
return *VideoCore::g_renderer;
|
|
|
|
}
|
|
|
|
|
2018-04-13 05:06:21 +02:00
|
|
|
Service::SM::ServiceManager& System::ServiceManager() {
|
|
|
|
return *service_manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Service::SM::ServiceManager& System::ServiceManager() const {
|
|
|
|
return *service_manager;
|
|
|
|
}
|
|
|
|
|
2018-09-29 18:39:31 +02:00
|
|
|
Service::FS::ArchiveManager& System::ArchiveManager() {
|
|
|
|
return *archive_manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Service::FS::ArchiveManager& System::ArchiveManager() const {
|
|
|
|
return *archive_manager;
|
|
|
|
}
|
|
|
|
|
2018-10-11 20:49:52 +02:00
|
|
|
Kernel::KernelSystem& System::Kernel() {
|
|
|
|
return *kernel;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Kernel::KernelSystem& System::Kernel() const {
|
|
|
|
return *kernel;
|
|
|
|
}
|
|
|
|
|
2022-12-11 09:08:58 +01:00
|
|
|
bool System::KernelRunning() {
|
|
|
|
return kernel != nullptr;
|
|
|
|
}
|
|
|
|
|
2018-10-27 21:53:20 +02:00
|
|
|
Timing& System::CoreTiming() {
|
|
|
|
return *timing;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Timing& System::CoreTiming() const {
|
|
|
|
return *timing;
|
|
|
|
}
|
|
|
|
|
2018-11-21 04:38:47 +01:00
|
|
|
Memory::MemorySystem& System::Memory() {
|
|
|
|
return *memory;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Memory::MemorySystem& System::Memory() const {
|
|
|
|
return *memory;
|
|
|
|
}
|
|
|
|
|
2018-11-17 02:01:10 +01:00
|
|
|
Cheats::CheatEngine& System::CheatEngine() {
|
|
|
|
return *cheat_engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Cheats::CheatEngine& System::CheatEngine() const {
|
|
|
|
return *cheat_engine;
|
|
|
|
}
|
|
|
|
|
2023-06-17 01:06:18 +02:00
|
|
|
void System::RegisterVideoDumper(std::shared_ptr<VideoDumper::Backend> dumper) {
|
|
|
|
video_dumper = std::move(dumper);
|
2019-08-06 18:24:07 +02:00
|
|
|
}
|
|
|
|
|
2023-04-27 06:38:28 +02:00
|
|
|
VideoCore::CustomTexManager& System::CustomTexManager() {
|
|
|
|
return *custom_tex_manager;
|
2019-08-06 14:43:24 +02:00
|
|
|
}
|
|
|
|
|
2023-04-27 06:38:28 +02:00
|
|
|
const VideoCore::CustomTexManager& System::CustomTexManager() const {
|
|
|
|
return *custom_tex_manager;
|
2019-01-26 15:36:39 +01:00
|
|
|
}
|
|
|
|
|
2023-08-01 02:57:38 +02:00
|
|
|
Core::Movie& System::Movie() {
|
|
|
|
return movie;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Core::Movie& System::Movie() const {
|
|
|
|
return movie;
|
|
|
|
}
|
|
|
|
|
2019-02-09 17:00:57 +01:00
|
|
|
void System::RegisterMiiSelector(std::shared_ptr<Frontend::MiiSelector> mii_selector) {
|
|
|
|
registered_mii_selector = std::move(mii_selector);
|
|
|
|
}
|
|
|
|
|
2018-06-20 14:01:50 +02:00
|
|
|
void System::RegisterSoftwareKeyboard(std::shared_ptr<Frontend::SoftwareKeyboard> swkbd) {
|
|
|
|
registered_swkbd = std::move(swkbd);
|
|
|
|
}
|
|
|
|
|
2019-08-07 04:56:56 +02:00
|
|
|
void System::RegisterImageInterface(std::shared_ptr<Frontend::ImageInterface> image_interface) {
|
|
|
|
registered_image_interface = std::move(image_interface);
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:06:22 +02:00
|
|
|
void System::Shutdown(bool is_deserializing) {
|
2017-07-13 04:19:34 +02:00
|
|
|
// Log last frame performance stats
|
2019-03-02 21:17:40 +01:00
|
|
|
const auto perf_results = GetAndResetPerfStats();
|
2020-08-18 20:21:50 +02:00
|
|
|
constexpr auto performance = Common::Telemetry::FieldType::Performance;
|
|
|
|
|
|
|
|
telemetry_session->AddField(performance, "Shutdown_EmulationSpeed",
|
2019-03-02 21:17:40 +01:00
|
|
|
perf_results.emulation_speed * 100.0);
|
2020-08-18 20:21:50 +02:00
|
|
|
telemetry_session->AddField(performance, "Shutdown_Framerate", perf_results.game_fps);
|
|
|
|
telemetry_session->AddField(performance, "Shutdown_Frametime", perf_results.frametime * 1000.0);
|
2023-01-23 10:51:57 +01:00
|
|
|
telemetry_session->AddField(performance, "Mean_Frametime_MS",
|
|
|
|
perf_stats ? perf_stats->GetMeanFrametime() : 0);
|
2017-07-13 04:19:34 +02:00
|
|
|
|
|
|
|
// Shutdown emulation session
|
2023-03-30 13:24:49 +02:00
|
|
|
is_powered_on = false;
|
|
|
|
|
2016-12-16 01:01:48 +01:00
|
|
|
VideoCore::Shutdown();
|
|
|
|
HW::Shutdown();
|
2020-04-01 23:06:22 +02:00
|
|
|
if (!is_deserializing) {
|
2020-04-11 20:47:31 +02:00
|
|
|
GDBStub::Shutdown();
|
2020-04-01 23:06:22 +02:00
|
|
|
perf_stats.reset();
|
|
|
|
cheat_engine.reset();
|
|
|
|
app_loader.reset();
|
|
|
|
}
|
2023-05-07 01:34:14 +02:00
|
|
|
custom_tex_manager.reset();
|
2018-04-13 05:06:21 +02:00
|
|
|
telemetry_session.reset();
|
2023-08-06 21:23:53 +02:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
2018-09-11 22:00:12 +02:00
|
|
|
rpc_server.reset();
|
2023-08-06 21:23:53 +02:00
|
|
|
#endif
|
2020-02-07 16:45:02 +01:00
|
|
|
archive_manager.reset();
|
2018-04-13 05:06:21 +02:00
|
|
|
service_manager.reset();
|
|
|
|
dsp_core.reset();
|
2019-03-13 00:06:20 +01:00
|
|
|
kernel.reset();
|
2019-08-24 22:56:17 +02:00
|
|
|
cpu_cores.clear();
|
2022-06-21 20:59:36 +02:00
|
|
|
exclusive_monitor.reset();
|
2018-10-27 21:53:20 +02:00
|
|
|
timing.reset();
|
2017-12-20 19:44:32 +01:00
|
|
|
|
2019-08-24 22:56:17 +02:00
|
|
|
if (video_dumper && video_dumper->IsDumping()) {
|
2019-01-26 15:36:39 +01:00
|
|
|
video_dumper->StopDumping();
|
|
|
|
}
|
|
|
|
|
2017-08-19 19:14:33 +02:00
|
|
|
if (auto room_member = Network::GetRoomMember().lock()) {
|
|
|
|
Network::GameInfo game_info{};
|
|
|
|
room_member->SendGameInfo(game_info);
|
|
|
|
}
|
2014-04-05 21:26:03 +02:00
|
|
|
|
2020-04-22 05:36:16 +02:00
|
|
|
memory.reset();
|
|
|
|
|
2022-10-20 23:14:57 +02:00
|
|
|
if (self_delete_pending)
|
|
|
|
FileUtil::Delete(m_filepath);
|
|
|
|
self_delete_pending = false;
|
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(Core, "Shutdown OK");
|
2013-09-06 00:33:46 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 14:07:00 +02:00
|
|
|
void System::Reset() {
|
|
|
|
// This is NOT a proper reset, but a temporary workaround by shutting down the system and
|
|
|
|
// reloading.
|
|
|
|
// TODO: Properly implement the reset
|
|
|
|
|
2020-11-24 20:10:31 +01:00
|
|
|
// Since the system is completely reinitialized, we'll have to store the deliver arg manually.
|
2023-02-28 13:09:54 +01:00
|
|
|
boost::optional<Service::APT::DeliverArg> deliver_arg;
|
2020-11-24 20:10:31 +01:00
|
|
|
if (auto apt = Service::APT::GetModule(*this)) {
|
|
|
|
deliver_arg = apt->GetAppletManager()->ReceiveDeliverArg();
|
|
|
|
}
|
|
|
|
|
2018-07-18 14:07:00 +02:00
|
|
|
Shutdown();
|
2022-09-21 18:36:12 +02:00
|
|
|
|
2022-10-23 22:55:50 +02:00
|
|
|
if (!m_chainloadpath.empty()) {
|
|
|
|
m_filepath = m_chainloadpath;
|
|
|
|
m_chainloadpath.clear();
|
2022-10-21 01:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 14:07:00 +02:00
|
|
|
// Reload the system with the same setting
|
2022-11-17 16:37:30 +01:00
|
|
|
[[maybe_unused]] const System::ResultStatus result =
|
|
|
|
Load(*m_emu_window, m_filepath, m_secondary_window);
|
2020-11-24 20:10:31 +01:00
|
|
|
|
|
|
|
// Restore the deliver arg.
|
|
|
|
if (auto apt = Service::APT::GetModule(*this)) {
|
|
|
|
apt->GetAppletManager()->SetDeliverArg(std::move(deliver_arg));
|
|
|
|
}
|
2018-07-18 14:07:00 +02:00
|
|
|
}
|
|
|
|
|
2023-06-30 12:39:38 +02:00
|
|
|
void System::ApplySettings() {
|
|
|
|
GDBStub::SetServerPort(Settings::values.gdbstub_port.GetValue());
|
|
|
|
GDBStub::ToggleServer(Settings::values.use_gdbstub.GetValue());
|
|
|
|
|
|
|
|
VideoCore::g_shader_jit_enabled = Settings::values.use_shader_jit.GetValue();
|
|
|
|
VideoCore::g_hw_shader_enabled = Settings::values.use_hw_shader.GetValue();
|
|
|
|
VideoCore::g_hw_shader_accurate_mul = Settings::values.shaders_accurate_mul.GetValue();
|
|
|
|
|
|
|
|
#ifndef ANDROID
|
|
|
|
if (VideoCore::g_renderer) {
|
|
|
|
VideoCore::g_renderer->UpdateCurrentFramebufferLayout();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (VideoCore::g_renderer) {
|
|
|
|
auto& settings = VideoCore::g_renderer->Settings();
|
|
|
|
settings.bg_color_update_requested = true;
|
|
|
|
settings.shader_update_requested = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsPoweredOn()) {
|
|
|
|
CoreTiming().UpdateClockSpeed(Settings::values.cpu_clock_percentage.GetValue());
|
2023-08-02 00:40:39 +02:00
|
|
|
dsp_core->SetSink(Settings::values.output_type.GetValue(),
|
|
|
|
Settings::values.output_device.GetValue());
|
|
|
|
dsp_core->EnableStretching(Settings::values.enable_audio_stretching.GetValue());
|
2023-06-30 12:39:38 +02:00
|
|
|
|
|
|
|
auto hid = Service::HID::GetModule(*this);
|
|
|
|
if (hid) {
|
|
|
|
hid->ReloadInputDevices();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto apt = Service::APT::GetModule(*this);
|
|
|
|
if (apt) {
|
|
|
|
apt->GetAppletManager()->ReloadInputDevices();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ir_user = service_manager->GetService<Service::IR::IR_USER>("ir:USER");
|
|
|
|
if (ir_user)
|
|
|
|
ir_user->ReloadInputDevices();
|
|
|
|
auto ir_rst = service_manager->GetService<Service::IR::IR_RST>("ir:rst");
|
|
|
|
if (ir_rst)
|
|
|
|
ir_rst->ReloadInputDevices();
|
|
|
|
|
|
|
|
auto cam = Service::CAM::GetModule(*this);
|
|
|
|
if (cam) {
|
|
|
|
cam->ReloadCameraDevices();
|
|
|
|
}
|
|
|
|
|
|
|
|
Service::MIC::ReloadMic(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Service::PLGLDR::PLG_LDR::SetEnabled(Settings::values.plugin_loader_enabled.GetValue());
|
|
|
|
Service::PLGLDR::PLG_LDR::SetAllowGameChangeState(
|
|
|
|
Settings::values.allow_plugin_loader.GetValue());
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:07:29 +01:00
|
|
|
template <class Archive>
|
|
|
|
void System::serialize(Archive& ar, const unsigned int file_version) {
|
2020-04-12 23:26:24 +02:00
|
|
|
|
|
|
|
u32 num_cores;
|
|
|
|
if (Archive::is_saving::value) {
|
|
|
|
num_cores = this->GetNumCores();
|
|
|
|
}
|
|
|
|
ar& num_cores;
|
|
|
|
|
2020-04-06 22:23:39 +02:00
|
|
|
if (Archive::is_loading::value) {
|
|
|
|
// When loading, we want to make sure any lingering state gets cleared out before we begin.
|
|
|
|
// Shutdown, but persist a few things between loads...
|
|
|
|
Shutdown(true);
|
|
|
|
|
|
|
|
// Re-initialize everything like it was before
|
2023-07-29 09:26:16 +02:00
|
|
|
auto memory_mode = this->app_loader->LoadKernelMemoryMode();
|
|
|
|
auto n3ds_hw_caps = this->app_loader->LoadNew3dsHwCapabilities();
|
2022-11-17 16:37:30 +01:00
|
|
|
[[maybe_unused]] const System::ResultStatus result = Init(
|
2023-07-29 09:26:16 +02:00
|
|
|
*m_emu_window, m_secondary_window, *memory_mode.first, *n3ds_hw_caps.first, num_cores);
|
2020-04-06 22:23:39 +02:00
|
|
|
}
|
|
|
|
|
2020-01-17 07:17:55 +01:00
|
|
|
// flush on save, don't flush on load
|
|
|
|
bool should_flush = !Archive::is_loading::value;
|
|
|
|
Memory::RasterizerClearAll(should_flush);
|
2020-01-12 21:01:29 +01:00
|
|
|
ar&* timing.get();
|
2020-03-28 10:59:45 +01:00
|
|
|
for (u32 i = 0; i < num_cores; i++) {
|
2020-03-07 22:23:08 +01:00
|
|
|
ar&* cpu_cores[i].get();
|
|
|
|
}
|
2019-12-27 22:07:29 +01:00
|
|
|
ar&* service_manager.get();
|
2020-03-29 19:56:25 +02:00
|
|
|
ar&* archive_manager.get();
|
2019-12-27 22:07:29 +01:00
|
|
|
ar& GPU::g_regs;
|
|
|
|
ar& LCD::g_regs;
|
2020-03-28 10:59:45 +01:00
|
|
|
|
|
|
|
// NOTE: DSP doesn't like being destroyed and recreated. So instead we do an inline
|
|
|
|
// serialization; this means that the DSP Settings need to match for loading to work.
|
|
|
|
auto dsp_hle = dynamic_cast<AudioCore::DspHle*>(dsp_core.get());
|
|
|
|
if (dsp_hle) {
|
|
|
|
ar&* dsp_hle;
|
2020-03-31 18:54:28 +02:00
|
|
|
} else {
|
|
|
|
throw std::runtime_error("LLE audio not supported for save states");
|
2020-03-27 22:48:58 +01:00
|
|
|
}
|
2020-03-28 10:59:45 +01:00
|
|
|
|
2019-12-27 22:07:29 +01:00
|
|
|
ar&* memory.get();
|
|
|
|
ar&* kernel.get();
|
2020-04-06 22:23:39 +02:00
|
|
|
VideoCore::serialize(ar, file_version);
|
2023-09-17 00:22:10 +02:00
|
|
|
ar& movie;
|
2020-01-04 01:40:32 +01:00
|
|
|
|
|
|
|
// This needs to be set from somewhere - might as well be here!
|
2020-01-17 02:01:18 +01:00
|
|
|
if (Archive::is_loading::value) {
|
2021-02-08 04:24:05 +01:00
|
|
|
timing->UnlockEventQueue();
|
2020-01-17 02:01:18 +01:00
|
|
|
Service::GSP::SetGlobalModule(*this);
|
2020-04-01 23:06:22 +02:00
|
|
|
memory->SetDSP(*dsp_core);
|
2020-04-06 22:23:39 +02:00
|
|
|
cheat_engine->Connect();
|
2020-04-11 11:28:52 +02:00
|
|
|
VideoCore::g_renderer->Sync();
|
2020-01-17 02:01:18 +01:00
|
|
|
}
|
2019-08-07 03:53:56 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 06:19:52 +01:00
|
|
|
SERIALIZE_IMPL(System)
|
2019-08-07 03:53:56 +02:00
|
|
|
|
2017-09-27 01:17:47 +02:00
|
|
|
} // namespace Core
|