Core: Move Emulation IOS instance to System.

This commit is contained in:
Admiral H. Curtiss
2024-02-06 03:31:34 +01:00
parent ca81d8b8a6
commit e6ee217a7c
21 changed files with 65 additions and 51 deletions

View File

@@ -64,8 +64,6 @@
namespace IOS::HLE
{
static std::unique_ptr<EmulationKernel> s_ios;
constexpr u64 ENQUEUE_REQUEST_FLAG = 0x100000000ULL;
static CoreTiming::EventType* s_event_enqueue;
static CoreTiming::EventType* s_event_finish_ppc_bootstrap;
@@ -284,7 +282,7 @@ Kernel::Kernel(IOSC::ConsoleType console_type) : m_iosc(console_type)
{
// Until the Wii root and NAND path stuff is entirely managed by IOS and made non-static,
// using more than one IOS instance at a time is not supported.
ASSERT(GetIOS() == nullptr);
ASSERT(Core::System::GetInstance().GetIOS() == nullptr);
m_is_responsible_for_nand_root = !Core::WiiRootIsInitialized();
if (m_is_responsible_for_nand_root)
@@ -477,8 +475,8 @@ private:
static void FinishIOSBoot(Core::System& system, u64 ios_title_id)
{
// Shut down the active IOS first before switching to the new one.
s_ios.reset();
s_ios = std::make_unique<EmulationKernel>(system, ios_title_id);
system.SetIOS(nullptr);
system.SetIOS(std::make_unique<EmulationKernel>(system, ios_title_id));
}
static constexpr SystemTimers::TimeBaseTick GetIOSBootTicks(u32 version)
@@ -959,8 +957,9 @@ void Init(Core::System& system)
s_event_enqueue =
core_timing.RegisterEvent("IPCEvent", [](Core::System& system_, u64 userdata, s64) {
if (s_ios)
s_ios->HandleIPCEvent(userdata);
auto* ios = system_.GetIOS();
if (ios)
ios->HandleIPCEvent(userdata);
});
ESDevice::InitializeEmulationState(core_timing);
@@ -976,7 +975,7 @@ void Init(Core::System& system)
core_timing.RegisterEvent("FinishDICommand", DIDevice::FinishDICommandCallback);
// Start with IOS80 to simulate part of the Wii boot process.
s_ios = std::make_unique<EmulationKernel>(system, Titles::SYSTEM_MENU_IOS);
system.SetIOS(std::make_unique<EmulationKernel>(system, Titles::SYSTEM_MENU_IOS));
// On a Wii, boot2 launches the system menu IOS, which then launches the system menu
// (which bootstraps the PPC). Bootstrapping the PPC results in memory values being set up.
// This means that the constants in the 0x3100 region are always set up by the time
@@ -985,17 +984,12 @@ void Init(Core::System& system)
SetupMemory(system.GetMemory(), Titles::SYSTEM_MENU_IOS, MemorySetupType::Full);
}
void Shutdown()
void Shutdown(Core::System& system)
{
s_ios.reset();
system.SetIOS(nullptr);
ESDevice::FinalizeEmulationState();
}
EmulationKernel* GetIOS()
{
return s_ios.get();
}
// Based on a hardware test, a device takes at least ~2700 ticks to reply to an IPC request.
// Depending on how much work a command performs, this can take much longer (10000+)
// especially if the NAND filesystem is accessed.