diff --git a/src/pse-sdl/main.cpp b/src/pse-sdl/main.cpp index 275847068..d3433c004 100644 --- a/src/pse-sdl/main.cpp +++ b/src/pse-sdl/main.cpp @@ -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(); diff --git a/src/pse-sdl/sdl_interface.cpp b/src/pse-sdl/sdl_interface.cpp index 50772a0bd..1adac314b 100644 --- a/src/pse-sdl/sdl_interface.cpp +++ b/src/pse-sdl/sdl_interface.cpp @@ -164,9 +164,6 @@ std::unique_ptr 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 (;;) diff --git a/src/pse-sdl/sdl_interface.h b/src/pse-sdl/sdl_interface.h index 17942179d..51c67e021 100644 --- a/src/pse-sdl/sdl_interface.h +++ b/src/pse-sdl/sdl_interface.h @@ -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: diff --git a/src/pse/host_interface.cpp b/src/pse/host_interface.cpp index f7aeee13f..ffec86c9a 100644 --- a/src/pse/host_interface.cpp +++ b/src/pse/host_interface.cpp @@ -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(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; diff --git a/src/pse/host_interface.h b/src/pse/host_interface.h index c5fdd730f..000727c1a 100644 --- a/src/pse/host_interface.h +++ b/src/pse/host_interface.h @@ -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 m_system; bool m_running = false; }; diff --git a/src/pse/pad.cpp b/src/pse/pad.cpp index 42e692c68..638e77152 100644 --- a/src/pse/pad.cpp +++ b/src/pse/pad.cpp @@ -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; } }