GBA SIO: Allow seamless mode switching if driver supports it

This commit is contained in:
Vicki Pfau 2024-05-24 03:01:44 -07:00
parent ab655db3f8
commit 914d879811
2 changed files with 16 additions and 16 deletions

View File

@ -60,17 +60,25 @@ static void _switchMode(struct GBASIO* sio) {
newMode = (enum GBASIOMode) (mode & 0xC); newMode = (enum GBASIOMode) (mode & 0xC);
} }
if (newMode != sio->mode) { if (newMode != sio->mode) {
if (sio->activeDriver && sio->activeDriver->unload) { struct GBASIODriver* driver = _lookupDriver(sio, newMode);
sio->activeDriver->unload(sio->activeDriver);
}
if (sio->mode != (enum GBASIOMode) -1) { if (sio->mode != (enum GBASIOMode) -1) {
mLOG(GBA_SIO, DEBUG, "Switching mode from %s to %s", _modeName(sio->mode), _modeName(newMode)); mLOG(GBA_SIO, DEBUG, "Switching mode from %s to %s", _modeName(sio->mode), _modeName(newMode));
} }
if (driver != sio->activeDriver || (driver && !driver->setMode)) {
if (sio->activeDriver && sio->activeDriver->unload) {
sio->activeDriver->unload(sio->activeDriver);
}
sio->mode = newMode; sio->mode = newMode;
sio->activeDriver = _lookupDriver(sio, sio->mode); sio->activeDriver = driver;
if (sio->activeDriver && sio->activeDriver->load) { if (sio->activeDriver && sio->activeDriver->load) {
sio->activeDriver->load(sio->activeDriver); sio->activeDriver->load(sio->activeDriver);
} }
} else {
sio->mode = newMode;
if (sio->activeDriver && sio->activeDriver->setMode) {
sio->activeDriver->setMode(sio->activeDriver, newMode);
}
}
int id = 0; int id = 0;
switch (newMode) { switch (newMode) {

View File

@ -15,7 +15,6 @@ static bool GBASIOLockstepNodeInit(struct GBASIODriver* driver);
static void GBASIOLockstepNodeDeinit(struct GBASIODriver* driver); static void GBASIOLockstepNodeDeinit(struct GBASIODriver* driver);
static bool GBASIOLockstepNodeLoad(struct GBASIODriver* driver); static bool GBASIOLockstepNodeLoad(struct GBASIODriver* driver);
static bool GBASIOLockstepNodeUnload(struct GBASIODriver* driver); static bool GBASIOLockstepNodeUnload(struct GBASIODriver* driver);
static void GBASIOLockstepNodeSetMode(struct GBASIODriver* driver, enum GBASIOMode mode);
static bool GBASIOLockstepNodeHandlesMode(struct GBASIODriver* driver, enum GBASIOMode mode); static bool GBASIOLockstepNodeHandlesMode(struct GBASIODriver* driver, enum GBASIOMode mode);
static int GBASIOLockstepNodeConnectedDevices(struct GBASIODriver* driver); static int GBASIOLockstepNodeConnectedDevices(struct GBASIODriver* driver);
static int GBASIOLockstepNodeDeviceId(struct GBASIODriver* driver); static int GBASIOLockstepNodeDeviceId(struct GBASIODriver* driver);
@ -42,7 +41,7 @@ void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode* node) {
node->d.deinit = GBASIOLockstepNodeDeinit; node->d.deinit = GBASIOLockstepNodeDeinit;
node->d.load = GBASIOLockstepNodeLoad; node->d.load = GBASIOLockstepNodeLoad;
node->d.unload = GBASIOLockstepNodeUnload; node->d.unload = GBASIOLockstepNodeUnload;
node->d.setMode = GBASIOLockstepNodeSetMode; node->d.setMode = NULL;
node->d.handlesMode = GBASIOLockstepNodeHandlesMode; node->d.handlesMode = GBASIOLockstepNodeHandlesMode;
node->d.connectedDevices = GBASIOLockstepNodeConnectedDevices; node->d.connectedDevices = GBASIOLockstepNodeConnectedDevices;
node->d.deviceId = GBASIOLockstepNodeDeviceId; node->d.deviceId = GBASIOLockstepNodeDeviceId;
@ -190,13 +189,6 @@ bool GBASIOLockstepNodeUnload(struct GBASIODriver* driver) {
return true; return true;
} }
static void GBASIOLockstepNodeSetMode(struct GBASIODriver* driver, enum GBASIOMode mode) {
struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver;
mLockstepLock(&node->p->d);
node->mode = mode;
mLockstepUnlock(&node->p->d);
}
static bool GBASIOLockstepNodeHandlesMode(struct GBASIODriver* driver, enum GBASIOMode mode) { static bool GBASIOLockstepNodeHandlesMode(struct GBASIODriver* driver, enum GBASIOMode mode) {
UNUSED(driver); UNUSED(driver);
switch (mode) { switch (mode) {