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.
This commit is contained in:
Léo Lam 2017-01-28 19:04:33 +01:00
parent a2750a82dd
commit ab38be1ee2
5 changed files with 27 additions and 24 deletions

View File

@ -275,7 +275,7 @@ bool CBoot::SetupWiiMemory(u64 ios_title_id)
Memory::Write_U16(0x8201, 0x000030e6); // Dev console / debug capable Memory::Write_U16(0x8201, 0x000030e6); // Dev console / debug capable
Memory::Write_U32(0x00000000, 0x000030f0); // Apploader Memory::Write_U32(0x00000000, 0x000030f0); // Apploader
if (!IOS::HLE::SetupMemory(ios_title_id)) if (!IOS::HLE::Reload(ios_title_id))
{ {
return false; return false;
} }

View File

@ -1176,9 +1176,7 @@ IPCCommandResult ES::Launch(const IOCtlVRequest& request)
wiiMoteConnected[i] = s_Usb->m_WiiMotes[i].IsConnected(); wiiMoteConnected[i] = s_Usb->m_WiiMotes[i].IsConnected();
} }
Reset(true); Reload(ios_to_load);
Reinit();
SetupMemory(ios_to_load);
bReset = true; bReset = true;
if (!SConfig::GetInstance().m_bt_passthrough_enabled) if (!SConfig::GetInstance().m_bt_passthrough_enabled)

View File

@ -421,7 +421,7 @@ u32 GetVersion()
return static_cast<u32>(s_active_title_id); return static_cast<u32>(s_active_title_id);
} }
bool SetupMemory(u64 ios_title_id) static bool SetupMemory(u64 ios_title_id)
{ {
auto target_imv = std::find_if( auto target_imv = std::find_if(
ios_memory_values.begin(), ios_memory_values.end(), ios_memory_values.begin(), ios_memory_values.end(),
@ -433,8 +433,6 @@ bool SetupMemory(u64 ios_title_id)
return false; 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_physical_size, ADDR_MEM1_SIZE);
Memory::Write_U32(target_imv->mem1_simulated_size, ADDR_MEM1_SIM_SIZE); Memory::Write_U32(target_imv->mem1_simulated_size, ADDR_MEM1_SIM_SIZE);
Memory::Write_U32(target_imv->mem1_end, ADDR_MEM1_END); Memory::Write_U32(target_imv->mem1_end, ADDR_MEM1_END);
@ -477,7 +475,7 @@ std::shared_ptr<T> AddDevice(const char* device_name)
return device; return device;
} }
void Reinit() static void AddStaticDevices()
{ {
std::lock_guard<std::mutex> lock(s_device_map_mutex); std::lock_guard<std::mutex> lock(s_device_map_mutex);
_assert_msg_(IOS, s_device_map.empty(), "Reinit called while already initialized"); _assert_msg_(IOS, s_device_map.empty(), "Reinit called while already initialized");
@ -519,13 +517,12 @@ void Reinit()
void Init() void Init()
{ {
Reinit(); AddStaticDevices();
s_event_enqueue = CoreTiming::RegisterEvent("IPCEvent", EnqueueEvent); s_event_enqueue = CoreTiming::RegisterEvent("IPCEvent", EnqueueEvent);
s_event_sdio_notify = CoreTiming::RegisterEvent("SDIO_EventNotify", SDIO_EventNotify_CPUThread); 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); CoreTiming::RemoveAllEvents(s_event_enqueue);
@ -538,7 +535,7 @@ void Reset(bool hard)
device.reset(); device.reset();
} }
if (hard) if (clear_devices)
{ {
std::lock_guard<std::mutex> lock(s_device_map_mutex); std::lock_guard<std::mutex> lock(s_device_map_mutex);
s_device_map.clear(); s_device_map.clear();
@ -555,6 +552,18 @@ void Shutdown()
Reset(true); 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) void SetDefaultContentFile(const std::string& file_name)
{ {
std::lock_guard<std::mutex> lock(s_device_map_mutex); std::lock_guard<std::mutex> lock(s_device_map_mutex);
@ -618,6 +627,7 @@ void DoState(PointerWrap& p)
p.Do(s_request_queue); p.Do(s_request_queue);
p.Do(s_reply_queue); p.Do(s_reply_queue);
p.Do(s_last_reply_time); 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 // We need to make sure all file handles are closed so IOS::HLE::Device::FS::DoState can
// successfully save or re-create /tmp // successfully save or re-create /tmp

View File

@ -45,21 +45,16 @@ enum IPCCommandType : u32
IPC_REPLY = 8, IPC_REPLY = 8,
}; };
// Init // Init events and devices
void Init(); void Init();
// Reset all events and devices (and optionally clear them)
// Needs to be called after Reset(true) to recreate the device tree void Reset(bool clear_devices = false);
void Reinit();
u32 GetVersion();
bool SetupMemory(u64 ios_title_id);
// Shutdown // Shutdown
void Shutdown(); void Shutdown();
// Reset // Reload IOS (to a possibly different version); set up memory and devices.
void Reset(bool hard = false); bool Reload(u64 ios_title_id);
u32 GetVersion();
// Do State // Do State
void DoState(PointerWrap& p); void DoState(PointerWrap& p);

View File

@ -71,7 +71,7 @@ static Common::Event g_compressAndDumpStateSyncEvent;
static std::thread g_save_thread; static std::thread g_save_thread;
// Don't forget to increase this after doing changes on the savestate system // 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. // Maps savestate versions to Dolphin versions.
// Versions after 42 don't need to be added to this list, // Versions after 42 don't need to be added to this list,