diff --git a/CHANGES b/CHANGES index 505d35896..f25fd61b6 100644 --- a/CHANGES +++ b/CHANGES @@ -55,6 +55,7 @@ Other fixes: - GBA Cheats: Fix value incrementing in CB slide codes (fixes mgba.io/i/1501) - Qt: Only show emulator restart warning once per settings saving - Qt: Improve cheat view UX + - GB: Fix SGB controller selection initialization (fixes mgba.io/i/1104) Misc: - GBA Savedata: EEPROM performance fixes - GBA Savedata: Automatically map 1Mbit Flash files as 1Mbit Flash diff --git a/src/gb/gb.c b/src/gb/gb.c index 06ceddc64..4cff00c9a 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -435,7 +435,7 @@ void GBReset(struct LR35902Core* cpu) { gb->sgbBit = -1; gb->sgbControllers = 0; - gb->sgbCurrentController = 0; + gb->sgbCurrentController = 3; gb->currentSgbBits = 0; memset(gb->sgbPacket, 0, sizeof(gb->sgbPacket)); diff --git a/src/gb/io.c b/src/gb/io.c index 2c4b9b4b3..f75e5b83b 100644 --- a/src/gb/io.c +++ b/src/gb/io.c @@ -535,13 +535,13 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) { static uint8_t _readKeys(struct GB* gb) { uint8_t keys = *gb->keySource; - if (gb->sgbCurrentController != 0) { + if (gb->sgbCurrentController & gb->sgbControllers) { keys = 0; } uint8_t joyp = gb->memory.io[REG_JOYP]; switch (joyp & 0x30) { case 0x30: - keys = gb->sgbCurrentController; + keys = gb->sgbCurrentController & gb->sgbControllers; break; case 0x20: keys >>= 4; diff --git a/src/gb/video.c b/src/gb/video.c index 020889ca9..329174e02 100644 --- a/src/gb/video.c +++ b/src/gb/video.c @@ -702,7 +702,7 @@ void GBVideoWriteSGBPacket(struct GBVideo* video, uint8_t* data) { break; case SGB_MLT_REQ: video->p->sgbControllers = video->sgbPacketBuffer[1] & 0x3; - video->p->sgbCurrentController = 0; + video->p->sgbCurrentController &= video->p->sgbControllers; return; case SGB_MASK_EN: video->renderer->sgbRenderMode = video->sgbPacketBuffer[1] & 0x3;