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 {
mPERIPH_GBA_LUMINANCE = 0x1000,
mPERIPH_GBA_BATTLECHIP_GATE,
mPERIPH_GBA_LINK_PORT,
};
struct GBACartridgeOverride {

View File

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

View File

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

View File

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