From 337ca2cfaf4c5dee0ce8c2de86bfb29507040735 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 5 Sep 2021 12:20:46 -0700 Subject: [PATCH] GB I/O: Fix incrementing SGB controller when P14 is low (fixes #2202) --- CHANGES | 1 + src/gb/io.c | 14 +++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 0356ef0c8..a90532f6c 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,7 @@ Features: - Discord Rich Presence now supports time elapsed - Additional scaling shaders Emulation fixes: + - GB I/O: Fix incrementing SGB controller when P14 is low (fixes mgba.io/i/2202) - GB Memory: Add cursory cartridge open bus emulation (fixes mgba.io/i/2032) - GB Video: Render SGB border when unmasking with ATTR/PAL_SET (fixes mgba.io/i/2261) - GBA: Improve timing when not booting from BIOS diff --git a/src/gb/io.c b/src/gb/io.c index 00f75ffd7..74ce4caee 100644 --- a/src/gb/io.c +++ b/src/gb/io.c @@ -119,19 +119,15 @@ static void _writeSGBBits(struct GB* gb, int bits) { if (bits == gb->currentSgbBits) { return; } - switch (bits) { - case 0: - case 1: - if (gb->currentSgbBits & 2) { - gb->sgbIncrement = !gb->sgbIncrement; - } - break; - case 3: + if (bits & 2) { if (gb->sgbIncrement) { gb->sgbIncrement = false; gb->sgbCurrentController = (gb->sgbCurrentController + 1) & gb->sgbControllers; } - break; + } else { + if (gb->currentSgbBits & 2) { + gb->sgbIncrement = !gb->sgbIncrement; + } } gb->currentSgbBits = bits; if (gb->sgbBit == 128 && bits == 2) {