From ab38be1ee23fe47c7ba7867e281288531ce04b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 28 Jan 2017 19:04:33 +0100 Subject: [PATCH] IOS: Clarify Init, Reinit, Reset, Shutdown Some minor changes to make things slightly less confusing: * Reinit doesn't actually init anything. It just adds static devices to the map, so let's give it an actually descriptive name. And let's not expose it in the header when it should not be. * Reset's parameter name was changed from "force" -- which totally does not describe what it does -- to "clear_devices". * Add a reload function which handles the reload process properly (reset all devices, set up memory values, re-add devices) and without publicly exposing implementation details. --- Source/Core/Core/Boot/Boot_BS2Emu.cpp | 2 +- Source/Core/Core/IOS/ES/ES.cpp | 4 +--- Source/Core/Core/IOS/IPC.cpp | 26 ++++++++++++++++++-------- Source/Core/Core/IOS/IPC.h | 17 ++++++----------- Source/Core/Core/State.cpp | 2 +- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index e3ba2536da..61dd1dbb8c 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -275,7 +275,7 @@ bool CBoot::SetupWiiMemory(u64 ios_title_id) Memory::Write_U16(0x8201, 0x000030e6); // Dev console / debug capable Memory::Write_U32(0x00000000, 0x000030f0); // Apploader - if (!IOS::HLE::SetupMemory(ios_title_id)) + if (!IOS::HLE::Reload(ios_title_id)) { return false; } diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index abe00c215a..f956d0824a 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -1176,9 +1176,7 @@ IPCCommandResult ES::Launch(const IOCtlVRequest& request) wiiMoteConnected[i] = s_Usb->m_WiiMotes[i].IsConnected(); } - Reset(true); - Reinit(); - SetupMemory(ios_to_load); + Reload(ios_to_load); bReset = true; if (!SConfig::GetInstance().m_bt_passthrough_enabled) diff --git a/Source/Core/Core/IOS/IPC.cpp b/Source/Core/Core/IOS/IPC.cpp index 1580791a80..cb0876527e 100644 --- a/Source/Core/Core/IOS/IPC.cpp +++ b/Source/Core/Core/IOS/IPC.cpp @@ -421,7 +421,7 @@ u32 GetVersion() return static_cast(s_active_title_id); } -bool SetupMemory(u64 ios_title_id) +static bool SetupMemory(u64 ios_title_id) { auto target_imv = std::find_if( ios_memory_values.begin(), ios_memory_values.end(), @@ -433,8 +433,6 @@ bool SetupMemory(u64 ios_title_id) return false; } - s_active_title_id = ios_title_id; - Memory::Write_U32(target_imv->mem1_physical_size, ADDR_MEM1_SIZE); Memory::Write_U32(target_imv->mem1_simulated_size, ADDR_MEM1_SIM_SIZE); Memory::Write_U32(target_imv->mem1_end, ADDR_MEM1_END); @@ -477,7 +475,7 @@ std::shared_ptr AddDevice(const char* device_name) return device; } -void Reinit() +static void AddStaticDevices() { std::lock_guard lock(s_device_map_mutex); _assert_msg_(IOS, s_device_map.empty(), "Reinit called while already initialized"); @@ -519,13 +517,12 @@ void Reinit() void Init() { - Reinit(); - + AddStaticDevices(); s_event_enqueue = CoreTiming::RegisterEvent("IPCEvent", EnqueueEvent); s_event_sdio_notify = CoreTiming::RegisterEvent("SDIO_EventNotify", SDIO_EventNotify_CPUThread); } -void Reset(bool hard) +void Reset(const bool clear_devices) { CoreTiming::RemoveAllEvents(s_event_enqueue); @@ -538,7 +535,7 @@ void Reset(bool hard) device.reset(); } - if (hard) + if (clear_devices) { std::lock_guard lock(s_device_map_mutex); s_device_map.clear(); @@ -555,6 +552,18 @@ void Shutdown() Reset(true); } +bool Reload(const u64 ios_title_id) +{ + if (!SetupMemory(ios_title_id)) + return false; + + s_active_title_id = ios_title_id; + Reset(true); + + AddStaticDevices(); + return true; +} + void SetDefaultContentFile(const std::string& file_name) { std::lock_guard lock(s_device_map_mutex); @@ -618,6 +627,7 @@ void DoState(PointerWrap& p) p.Do(s_request_queue); p.Do(s_reply_queue); p.Do(s_last_reply_time); + p.Do(s_active_title_id); // We need to make sure all file handles are closed so IOS::HLE::Device::FS::DoState can // successfully save or re-create /tmp diff --git a/Source/Core/Core/IOS/IPC.h b/Source/Core/Core/IOS/IPC.h index 7508be12f9..09b3c1179c 100644 --- a/Source/Core/Core/IOS/IPC.h +++ b/Source/Core/Core/IOS/IPC.h @@ -45,21 +45,16 @@ enum IPCCommandType : u32 IPC_REPLY = 8, }; -// Init +// Init events and devices void Init(); - -// Needs to be called after Reset(true) to recreate the device tree -void Reinit(); - -u32 GetVersion(); - -bool SetupMemory(u64 ios_title_id); - +// Reset all events and devices (and optionally clear them) +void Reset(bool clear_devices = false); // Shutdown void Shutdown(); -// Reset -void Reset(bool hard = false); +// Reload IOS (to a possibly different version); set up memory and devices. +bool Reload(u64 ios_title_id); +u32 GetVersion(); // Do State void DoState(PointerWrap& p); diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 7714659954..0073b9ea4b 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -71,7 +71,7 @@ static Common::Event g_compressAndDumpStateSyncEvent; static std::thread g_save_thread; // Don't forget to increase this after doing changes on the savestate system -static const u32 STATE_VERSION = 76; // Last changed in PR 4829 +static const u32 STATE_VERSION = 77; // Last changed in PR 4784 // Maps savestate versions to Dolphin versions. // Versions after 42 don't need to be added to this list,