Recover DreamLink hardware after load state (#2003)

This commit is contained in:
James 2025-07-10 12:32:00 -06:00 committed by GitHub
parent d3a46a1e33
commit 54b06a5c34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 16 deletions

View File

@ -2153,9 +2153,6 @@ struct DreamLinkVmu : public maple_sega_vmu
void OnSetup() override
{
// Update useRealVmuMemory in case config changed
useRealVmuMemory = config::UsePhysicalVmuMemory;
// All data must be re-read
memset(mirroredBlocks, 0, sizeof(mirroredBlocks));
@ -2500,7 +2497,7 @@ struct DreamLinkPurupuru : public maple_sega_purupuru
static std::list<std::shared_ptr<DreamLinkVmu>> dreamLinkVmus[2];
static std::list<std::shared_ptr<DreamLinkPurupuru>> dreamLinkPurupurus;
void createDreamLinkDevices(std::shared_ptr<DreamLink> dreamlink, bool gameStart)
void createDreamLinkDevices(std::shared_ptr<DreamLink> dreamlink, bool gameStart, bool stateLoaded)
{
const int bus = dreamlink->getBus();
@ -2522,13 +2519,28 @@ void createDreamLinkDevices(std::shared_ptr<DreamLink> dreamlink, bool gameStart
}
}
if (gameStart || !vmuFound)
if (gameStart || stateLoaded || !vmuFound)
{
if (!vmu)
{
vmu = std::make_shared<DreamLinkVmu>(dreamlink);
}
if (gameStart)
{
// Update useRealVmuMemory in case config changed
vmu->useRealVmuMemory = config::UsePhysicalVmuMemory;
}
else if (stateLoaded)
{
if (vmu->useRealVmuMemory)
{
// Disconnect from real VMU memory when a state is loaded
vmu->useRealVmuMemory = false;
os_notify("WARNING: Disconnected from physical VMU memory due to load state", 6000);
}
}
vmu->Setup(bus, i);
if (!vmuFound && dev && dev->get_device_type() == MDT_SegaVMU && !vmu->useRealVmuMemory) {
@ -2558,12 +2570,13 @@ void createDreamLinkDevices(std::shared_ptr<DreamLink> dreamlink, bool gameStart
}
}
if (gameStart || !rumbleFound)
if (gameStart || stateLoaded || !rumbleFound)
{
if (!rumble)
{
rumble = std::make_shared<DreamLinkPurupuru>(dreamlink);
}
rumble->Setup(bus, i);
if (!rumbleFound) dreamLinkPurupurus.push_back(rumble);

View File

@ -46,7 +46,7 @@
#include <setupapi.h>
#endif
void createDreamLinkDevices(std::shared_ptr<DreamLink> dreamlink, bool gameStart);
void createDreamLinkDevices(std::shared_ptr<DreamLink> dreamlink, bool gameStart, bool stateLoaded);
void tearDownDreamLinkDevices(std::shared_ptr<DreamLink> dreamlink);
bool DreamLinkGamepad::isDreamcastController(int deviceIndex)
@ -146,21 +146,22 @@ void DreamLinkGamepad::registered()
dreamlink->connect();
// Create DreamLink Maple Devices here just in case game is already running
createDreamLinkDevices(dreamlink, false);
createDreamLinkDevices(dreamlink, false, false);
}
}
void DreamLinkGamepad::handleEvent(Event event, void *arg)
{
DreamLinkGamepad *gamepad = static_cast<DreamLinkGamepad*>(arg);
if (gamepad->dreamlink != nullptr && event != Event::Terminate) {
createDreamLinkDevices(gamepad->dreamlink, event == Event::Start);
if (gamepad->dreamlink != nullptr)
{
if (event != Event::Terminate) {
createDreamLinkDevices(gamepad->dreamlink, event == Event::Start, event == Event::LoadState);
}
else {
gamepad->dreamlink->gameTermination();
}
}
if (gamepad->dreamlink != nullptr && event == Event::Terminate)
{
gamepad->dreamlink->gameTermination();
}
}
void DreamLinkGamepad::resetMappingToDefault(bool arcade, bool gamepad) {

View File

@ -23,6 +23,10 @@
#include "vgamepad.h"
#include "oslib/storage.h"
#if defined(USE_SDL)
#include "sdl/dreamlink.h" // For USE_DREAMCASTCONTROLLER
#endif
static float calcComboWidth(const char *biggestLabel) {
return ImGui::CalcTextSize(biggestLabel).x + ImGui::GetStyle().FramePadding.x * 2.0f + ImGui::GetFrameHeight();
}
@ -937,7 +941,8 @@ void gui_settings_controls(bool& maple_devices_changed)
{
DisabledScope scope(game_started);
OptionCheckbox("Use Physical VMU Memory", config::UsePhysicalVmuMemory,
"Enables direct read/write access to physical VMU memory via DreamPicoPort/DreamConn.");
"Enables direct read/write access to physical VMU memory via DreamPicoPort/DreamConn. "
"This is not compatible with load state events.");
}
#endif