mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-18 06:25:37 +00:00
Pad: Fix loading save state issues with memory cards
This commit is contained in:
parent
9fc608aa34
commit
1667da66dd
|
@ -61,13 +61,18 @@ static int Run(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// create system
|
// create system
|
||||||
if (!host_interface->InitializeSystem(filename, exp1_filename, state_filename.IsEmpty() ? nullptr : state_filename.GetCharArray()))
|
if (!host_interface->InitializeSystem(filename, exp1_filename))
|
||||||
{
|
{
|
||||||
host_interface.reset();
|
host_interface.reset();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host_interface->ConnectDevices();
|
||||||
|
|
||||||
|
if (!state_filename.IsEmpty())
|
||||||
|
host_interface->LoadState(state_filename);
|
||||||
|
|
||||||
// run
|
// run
|
||||||
host_interface->Run();
|
host_interface->Run();
|
||||||
|
|
||||||
|
|
|
@ -164,9 +164,6 @@ std::unique_ptr<SDLInterface> SDLInterface::Create()
|
||||||
if (!intf->CreateSDLWindow() || !intf->CreateGLContext() || !intf->CreateImGuiContext() || !intf->CreateGLResources())
|
if (!intf->CreateSDLWindow() || !intf->CreateGLContext() || !intf->CreateImGuiContext() || !intf->CreateGLResources())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
intf->m_controller = DigitalController::Create();
|
|
||||||
intf->m_memory_card = MemoryCard::Create();
|
|
||||||
|
|
||||||
return intf;
|
return intf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,11 +589,17 @@ void SDLInterface::DoSaveState(u32 index)
|
||||||
SaveState(GetSaveStateFilename(index));
|
SaveState(GetSaveStateFilename(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDLInterface::ConnectDevices()
|
||||||
|
{
|
||||||
|
m_controller = DigitalController::Create();
|
||||||
|
m_system->SetController(0, m_controller);
|
||||||
|
|
||||||
|
m_memory_card = MemoryCard::Create();
|
||||||
|
m_system->SetMemoryCard(0, m_memory_card);
|
||||||
|
}
|
||||||
|
|
||||||
void SDLInterface::Run()
|
void SDLInterface::Run()
|
||||||
{
|
{
|
||||||
m_system->SetController(0, m_controller);
|
|
||||||
m_system->SetMemoryCard(0, m_memory_card);
|
|
||||||
|
|
||||||
while (m_running)
|
while (m_running)
|
||||||
{
|
{
|
||||||
for (;;)
|
for (;;)
|
||||||
|
|
|
@ -31,6 +31,8 @@ public:
|
||||||
// Adds OSD messages, duration is in seconds.
|
// Adds OSD messages, duration is in seconds.
|
||||||
void AddOSDMessage(const char* message, float duration = 2.0f) override;
|
void AddOSDMessage(const char* message, float duration = 2.0f) override;
|
||||||
|
|
||||||
|
void ConnectDevices();
|
||||||
|
|
||||||
void Run();
|
void Run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -8,7 +8,7 @@ HostInterface::HostInterface() = default;
|
||||||
|
|
||||||
HostInterface::~HostInterface() = default;
|
HostInterface::~HostInterface() = default;
|
||||||
|
|
||||||
bool HostInterface::InitializeSystem(const char* filename, const char* exp1_filename, const char* save_state_filename)
|
bool HostInterface::InitializeSystem(const char* filename, const char* exp1_filename)
|
||||||
{
|
{
|
||||||
m_system = std::make_unique<System>(this);
|
m_system = std::make_unique<System>(this);
|
||||||
if (!m_system->Initialize())
|
if (!m_system->Initialize())
|
||||||
|
@ -45,9 +45,6 @@ bool HostInterface::InitializeSystem(const char* filename, const char* exp1_file
|
||||||
if (exp1_filename)
|
if (exp1_filename)
|
||||||
m_system->SetExpansionROM(exp1_filename);
|
m_system->SetExpansionROM(exp1_filename);
|
||||||
|
|
||||||
if (save_state_filename)
|
|
||||||
LoadState(save_state_filename);
|
|
||||||
|
|
||||||
// Resume execution.
|
// Resume execution.
|
||||||
m_running = true;
|
m_running = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -14,7 +14,7 @@ public:
|
||||||
HostInterface();
|
HostInterface();
|
||||||
virtual ~HostInterface();
|
virtual ~HostInterface();
|
||||||
|
|
||||||
bool InitializeSystem(const char* filename, const char* exp1_filename, const char* save_state_filename);
|
bool InitializeSystem(const char* filename, const char* exp1_filename);
|
||||||
|
|
||||||
virtual void SetDisplayTexture(GL::Texture* texture, u32 offset_x, u32 offset_y, u32 width, u32 height, float aspect_ratio) = 0;
|
virtual void SetDisplayTexture(GL::Texture* texture, u32 offset_x, u32 offset_y, u32 width, u32 height, float aspect_ratio) = 0;
|
||||||
virtual void ReportMessage(const char* message) = 0;
|
virtual void ReportMessage(const char* message) = 0;
|
||||||
|
@ -22,10 +22,10 @@ public:
|
||||||
// Adds OSD messages, duration is in seconds.
|
// Adds OSD messages, duration is in seconds.
|
||||||
virtual void AddOSDMessage(const char* message, float duration = 2.0f) = 0;
|
virtual void AddOSDMessage(const char* message, float duration = 2.0f) = 0;
|
||||||
|
|
||||||
protected:
|
|
||||||
bool LoadState(const char* filename);
|
bool LoadState(const char* filename);
|
||||||
bool SaveState(const char* filename);
|
bool SaveState(const char* filename);
|
||||||
|
|
||||||
|
protected:
|
||||||
std::unique_ptr<System> m_system;
|
std::unique_ptr<System> m_system;
|
||||||
bool m_running = false;
|
bool m_running = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,13 +38,23 @@ bool Pad::DoState(StateWrapper& sw)
|
||||||
if (m_controllers[i])
|
if (m_controllers[i])
|
||||||
{
|
{
|
||||||
if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw))
|
if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw))
|
||||||
continue;
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!sw.DoMarker("NoController"))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_memory_cards[i])
|
if (m_memory_cards[i])
|
||||||
{
|
{
|
||||||
if (!sw.DoMarker("MemortCard") || !m_memory_cards[i]->DoState(sw))
|
if (!sw.DoMarker("MemoryCard") || !m_memory_cards[i]->DoState(sw))
|
||||||
continue;
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!sw.DoMarker("NoController"))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,5 +344,7 @@ void Pad::ResetDeviceTransferState()
|
||||||
m_controllers[i]->ResetTransferState();
|
m_controllers[i]->ResetTransferState();
|
||||||
if (m_memory_cards[i])
|
if (m_memory_cards[i])
|
||||||
m_memory_cards[i]->ResetTransferState();
|
m_memory_cards[i]->ResetTransferState();
|
||||||
|
|
||||||
|
m_active_device = ActiveDevice::None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue