From 109fbe60f5fd983af394c8e518e97d9a88a304cd Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 11 Dec 2024 16:24:51 -0800 Subject: [PATCH] GBA Hardware: Fix loading states unconditionally overwriting GPIO memory --- CHANGES | 1 + include/mgba/gba/interface.h | 4 +++- src/gba/cart/gpio.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 08d9526ff..f3a8cc539 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,7 @@ Other fixes: - Core: Fix inconsistencies with setting game-specific overrides (fixes mgba.io/i/2963) - Debugger: Fix writing to specific segment in command-line debugger - GB Serialize: Prevent loading invalid states where LY >= 144 in modes other than 1 + - GBA Hardware: Fix loading states unconditionally overwriting GPIO memory - GBA: Fix getting game info for multiboot ROMs - Qt: Fix savestate preview sizes with different scales (fixes mgba.io/i/2560) - Qt: Fix potential crash when configuring shortcuts diff --git a/include/mgba/gba/interface.h b/include/mgba/gba/interface.h index cbbb4d23a..298292dd3 100644 --- a/include/mgba/gba/interface.h +++ b/include/mgba/gba/interface.h @@ -68,7 +68,9 @@ enum GBAHardwareDevice { HW_TILT = 16, HW_GB_PLAYER = 32, HW_GB_PLAYER_DETECTION = 64, - HW_EREADER = 128 + HW_EREADER = 128, + + HW_GPIO = HW_RTC | HW_RUMBLE | HW_LIGHT_SENSOR | HW_GYRO | HW_TILT, }; struct Configuration; diff --git a/src/gba/cart/gpio.c b/src/gba/cart/gpio.c index 0bffbc088..48cb8c340 100644 --- a/src/gba/cart/gpio.c +++ b/src/gba/cart/gpio.c @@ -502,7 +502,7 @@ void GBAHardwareDeserialize(struct GBACartridgeHardware* hw, const struct GBASer LOAD_16(hw->direction, 0, &state->hw.pinDirection); hw->devices = state->hw.devices; - if (hw->gpioBase) { + if ((hw->devices & HW_GPIO) && hw->gpioBase) { if (hw->readWrite) { STORE_16(hw->pinState, 0, hw->gpioBase); STORE_16(hw->direction, 2, hw->gpioBase);