From 92d86af9552b48d4ce05b13823807131b99b1cce Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 30 Jan 2023 20:48:39 -0800 Subject: [PATCH] GBA SIO: Fix SIOCNT SI pin value after attaching player 2 (fixes #2805) --- CHANGES | 1 + src/gba/sio/lockstep.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGES b/CHANGES index 36e2cefa3..7045e46b6 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,7 @@ Features: Emulation fixes: - GBA Audio: Fix improperly deserializing GB audio registers (fixes mgba.io/i/2793) - GBA Memory: Make VRAM access stalls only apply to BG RAM + - GBA SIO: Fix SIOCNT SI pin value after attaching player 2 (fixes mgba.io/i/2805) - GBA Video: Disable BG target 1 blending when OBJ blending (fixes mgba.io/i/2722) Other fixes: - Core: Allow sending thread requests to a crashed core (fixes mgba.io/i/2784) diff --git a/src/gba/sio/lockstep.c b/src/gba/sio/lockstep.c index bc5a5fd33..a03e88e30 100644 --- a/src/gba/sio/lockstep.c +++ b/src/gba/sio/lockstep.c @@ -111,6 +111,18 @@ bool GBASIOLockstepNodeLoad(struct GBASIODriver* driver) { if (node->id) { node->d.p->rcnt |= 4; node->d.p->siocnt = GBASIOMultiplayerFillSlave(node->d.p->siocnt); + + int try; + for (try = 0; try < 3; ++try) { + uint16_t masterSiocnt; + ATOMIC_LOAD(masterSiocnt, node->p->players[0]->d.p->siocnt); + if (ATOMIC_CMPXCHG(node->p->players[0]->d.p->siocnt, masterSiocnt, GBASIOMultiplayerClearSlave(masterSiocnt))) { + break; + } + } + } else { + node->d.p->rcnt &= ~4; + node->d.p->siocnt = GBASIOMultiplayerClearSlave(node->d.p->siocnt); } break; case SIO_NORMAL_8: