Pad: Fix loading save state issues with memory cards

This commit is contained in:
Connor McLaughlin 2019-09-30 14:22:30 +10:00
parent 9fc608aa34
commit 1667da66dd
6 changed files with 35 additions and 16 deletions

View File

@ -61,13 +61,18 @@ static int Run(int argc, char* argv[])
}
// 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();
SDL_Quit();
return -1;
}
host_interface->ConnectDevices();
if (!state_filename.IsEmpty())
host_interface->LoadState(state_filename);
// run
host_interface->Run();

View File

@ -164,9 +164,6 @@ std::unique_ptr<SDLInterface> SDLInterface::Create()
if (!intf->CreateSDLWindow() || !intf->CreateGLContext() || !intf->CreateImGuiContext() || !intf->CreateGLResources())
return nullptr;
intf->m_controller = DigitalController::Create();
intf->m_memory_card = MemoryCard::Create();
return intf;
}
@ -592,11 +589,17 @@ void SDLInterface::DoSaveState(u32 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()
{
m_system->SetController(0, m_controller);
m_system->SetMemoryCard(0, m_memory_card);
while (m_running)
{
for (;;)

View File

@ -31,6 +31,8 @@ public:
// Adds OSD messages, duration is in seconds.
void AddOSDMessage(const char* message, float duration = 2.0f) override;
void ConnectDevices();
void Run();
private:

View File

@ -8,7 +8,7 @@ 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);
if (!m_system->Initialize())
@ -45,9 +45,6 @@ bool HostInterface::InitializeSystem(const char* filename, const char* exp1_file
if (exp1_filename)
m_system->SetExpansionROM(exp1_filename);
if (save_state_filename)
LoadState(save_state_filename);
// Resume execution.
m_running = true;
return true;

View File

@ -14,7 +14,7 @@ public:
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 ReportMessage(const char* message) = 0;
@ -22,10 +22,10 @@ public:
// Adds OSD messages, duration is in seconds.
virtual void AddOSDMessage(const char* message, float duration = 2.0f) = 0;
protected:
bool LoadState(const char* filename);
bool SaveState(const char* filename);
protected:
std::unique_ptr<System> m_system;
bool m_running = false;
};

View File

@ -38,13 +38,23 @@ bool Pad::DoState(StateWrapper& sw)
if (m_controllers[i])
{
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 (!sw.DoMarker("MemortCard") || !m_memory_cards[i]->DoState(sw))
continue;
if (!sw.DoMarker("MemoryCard") || !m_memory_cards[i]->DoState(sw))
return false;
}
else
{
if (!sw.DoMarker("NoController"))
return false;
}
}
@ -334,5 +344,7 @@ void Pad::ResetDeviceTransferState()
m_controllers[i]->ResetTransferState();
if (m_memory_cards[i])
m_memory_cards[i]->ResetTransferState();
m_active_device = ActiveDevice::None;
}
}