From 90a3872552de56c4b98945df29feb9f826e9bbb3 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 25 Dec 2014 14:49:06 -0800 Subject: [PATCH] GBA: Fix GPIO being readable when set to write-only --- src/gba/gba-gpio.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/gba/gba-gpio.c b/src/gba/gba-gpio.c index 19192e7df..87d6b00c0 100644 --- a/src/gba/gba-gpio.c +++ b/src/gba/gba-gpio.c @@ -50,11 +50,6 @@ void GBAGPIOWrite(struct GBACartridgeGPIO* gpio, uint32_t address, uint16_t valu case GPIO_REG_DATA: gpio->pinState &= ~gpio->direction; gpio->pinState |= value; - if (gpio->readWrite) { - uint16_t old = gpio->gpioBase[0]; - old &= ~gpio->direction; - gpio->gpioBase[0] = old | gpio->pinState; - } _readPins(gpio); break; case GPIO_REG_DIRECTION: @@ -66,6 +61,13 @@ void GBAGPIOWrite(struct GBACartridgeGPIO* gpio, uint32_t address, uint16_t valu default: GBALog(gpio->p, GBA_LOG_WARN, "Invalid GPIO address"); } + if (gpio->readWrite) { + uint16_t old = gpio->gpioBase[0]; + old &= ~gpio->direction; + gpio->gpioBase[0] = old | gpio->pinState; + } else { + gpio->gpioBase[0] = 0; + } } void GBAGPIOInitRTC(struct GBACartridgeGPIO* gpio) {