GBA: Expose setting the link port device as a peripheral

This commit is contained in:
Vicki Pfau 2024-09-12 02:44:26 -07:00
parent 5db42e83c9
commit 1d584edb77
4 changed files with 10 additions and 11 deletions

View File

@ -81,7 +81,7 @@ extern MGBA_EXPORT const int GBA_LUX_LEVELS[10];
enum { enum {
mPERIPH_GBA_LUMINANCE = 0x1000, mPERIPH_GBA_LUMINANCE = 0x1000,
mPERIPH_GBA_BATTLECHIP_GATE, mPERIPH_GBA_LINK_PORT,
}; };
struct GBACartridgeOverride { struct GBACartridgeOverride {

View File

@ -962,7 +962,7 @@ static void _GBACoreSetPeripheral(struct mCore* core, int type, void* periph) {
case mPERIPH_GBA_LUMINANCE: case mPERIPH_GBA_LUMINANCE:
gba->luminanceSource = periph; gba->luminanceSource = periph;
break; break;
case mPERIPH_GBA_BATTLECHIP_GATE: case mPERIPH_GBA_LINK_PORT:
GBASIOSetDriver(&gba->sio, periph); GBASIOSetDriver(&gba->sio, periph);
break; break;
default: default:

View File

@ -423,8 +423,8 @@ bool CoreController::attachDolphin(const Address& address) {
return false; return false;
} }
if (GBASIODolphinConnect(&m_dolphin, &address, 0, 0)) { if (GBASIODolphinConnect(&m_dolphin, &address, 0, 0)) {
GBA* gba = static_cast<GBA*>(m_threadContext.core->board); clearMultiplayerController();
GBASIOSetDriver(&gba->sio, &m_dolphin.d); m_threadContext.core->setPeripheral(m_threadContext.core, mPERIPH_GBA_LINK_PORT, &m_dolphin.d);
return true; return true;
} }
return false; return false;
@ -432,9 +432,8 @@ bool CoreController::attachDolphin(const Address& address) {
void CoreController::detachDolphin() { void CoreController::detachDolphin() {
if (platform() == mPLATFORM_GBA) { if (platform() == mPLATFORM_GBA) {
GBA* gba = static_cast<GBA*>(m_threadContext.core->board);
// TODO: Reattach to multiplayer controller // TODO: Reattach to multiplayer controller
GBASIOSetDriver(&gba->sio, nullptr); m_threadContext.core->setPeripheral(m_threadContext.core, mPERIPH_GBA_LINK_PORT, NULL);
} }
GBASIODolphinDestroy(&m_dolphin); GBASIODolphinDestroy(&m_dolphin);
} }
@ -1095,7 +1094,7 @@ void CoreController::attachBattleChipGate() {
Interrupter interrupter(this); Interrupter interrupter(this);
clearMultiplayerController(); clearMultiplayerController();
GBASIOBattlechipGateCreate(&m_battlechip); GBASIOBattlechipGateCreate(&m_battlechip);
m_threadContext.core->setPeripheral(m_threadContext.core, mPERIPH_GBA_BATTLECHIP_GATE, &m_battlechip); m_threadContext.core->setPeripheral(m_threadContext.core, mPERIPH_GBA_LINK_PORT, &m_battlechip);
} }
void CoreController::detachBattleChipGate() { void CoreController::detachBattleChipGate() {
@ -1103,7 +1102,7 @@ void CoreController::detachBattleChipGate() {
return; return;
} }
Interrupter interrupter(this); Interrupter interrupter(this);
m_threadContext.core->setPeripheral(m_threadContext.core, mPERIPH_GBA_BATTLECHIP_GATE, nullptr); m_threadContext.core->setPeripheral(m_threadContext.core, mPERIPH_GBA_LINK_PORT, nullptr);
} }
void CoreController::setBattleChipId(uint16_t id) { void CoreController::setBattleChipId(uint16_t id) {

View File

@ -327,9 +327,9 @@ bool MultiplayerController::attachGame(CoreController* controller) {
if (player.attached) { if (player.attached) {
continue; continue;
} }
GBA* gba = static_cast<GBA*>(player.controller->thread()->core->board); struct mCore* core = player.controller->thread()->core;
GBASIOLockstepCoordinatorAttach(&m_gbaCoordinator, player.node.gba); GBASIOLockstepCoordinatorAttach(&m_gbaCoordinator, player.node.gba);
GBASIOSetDriver(&gba->sio, &player.node.gba->d); core->setPeripheral(core, mPERIPH_GBA_LINK_PORT, &player.node.gba->d);
player.attached = true; player.attached = true;
} }
} }
@ -371,7 +371,7 @@ void MultiplayerController::detachGame(CoreController* controller) {
Player& p = m_pids.find(pid).value(); Player& p = m_pids.find(pid).value();
GBASIODriver* node = gba->sio.driver; GBASIODriver* node = gba->sio.driver;
if (node == &p.node.gba->d) { if (node == &p.node.gba->d) {
GBASIOSetDriver(&gba->sio, nullptr); thread->core->setPeripheral(thread->core, mPERIPH_GBA_LINK_PORT, NULL);
} }
if (p.attached) { if (p.attached) {
GBASIOLockstepCoordinatorDetach(&m_gbaCoordinator, p.node.gba); GBASIOLockstepCoordinatorDetach(&m_gbaCoordinator, p.node.gba);