diff --git a/src/gba/gba-gpio.c b/src/gba/gba-gpio.c index ee073c53d..68f28019b 100644 --- a/src/gba/gba-gpio.c +++ b/src/gba/gba-gpio.c @@ -16,6 +16,8 @@ static unsigned _rtcBCD(unsigned value); static void _gyroReadPins(struct GBACartridgeGPIO* gpio); +static void _rumbleReadPins(struct GBACartridgeGPIO* gpio); + static const int RTC_BYTES[8] = { 0, // Force reset 0, // Empty @@ -80,6 +82,10 @@ void _readPins(struct GBACartridgeGPIO* gpio) { if (gpio->gpioDevices & GPIO_GYRO) { _gyroReadPins(gpio); } + + if (gpio->gpioDevices & GPIO_RUMBLE) { + _rumbleReadPins(gpio); + } } void _outputPins(struct GBACartridgeGPIO* gpio, unsigned pins) { @@ -252,7 +258,6 @@ void GBAGPIOInitGyro(struct GBACartridgeGPIO* gpio) { gpio->gyroEdge = 0; } - void _gyroReadPins(struct GBACartridgeGPIO* gpio) { struct GBARotationSource* gyro = gpio->p->rotationSource; if (!gyro) { @@ -278,3 +283,18 @@ void _gyroReadPins(struct GBACartridgeGPIO* gpio) { gpio->gyroEdge = gpio->p1; } + +// == Rumble + +void GBAGPIOInitRumble(struct GBACartridgeGPIO* gpio) { + gpio->gpioDevices |= GPIO_RUMBLE; +} + +void _rumbleReadPins(struct GBACartridgeGPIO* gpio) { + struct GBARumble* rumble = gpio->p->rumble; + if (!rumble) { + return; + } + + rumble->setRumble(rumble, gpio->p3); +} diff --git a/src/gba/gba-gpio.h b/src/gba/gba-gpio.h index 075c34d85..75e8d8f6f 100644 --- a/src/gba/gba-gpio.h +++ b/src/gba/gba-gpio.h @@ -63,6 +63,10 @@ struct GBARTC { uint8_t time[7]; }; +struct GBARumble { + void (*setRumble)(struct GBARumble*, int enable); +}; + struct GBACartridgeGPIO { struct GBA* p; int gpioDevices; @@ -102,4 +106,6 @@ void GBAGPIOInitRTC(struct GBACartridgeGPIO* gpio); void GBAGPIOInitGyro(struct GBACartridgeGPIO* gpio); +void GBAGPIOInitRumble(struct GBACartridgeGPIO* gpio); + #endif diff --git a/src/gba/gba.c b/src/gba/gba.c index eb7bae1a9..9cbebeaa1 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -534,6 +534,10 @@ void _checkOverrides(struct GBA* gba, uint32_t id) { if (_overrides[i].gpio & GPIO_GYRO) { GBAGPIOInitGyro(&gba->memory.gpio); } + + if (_overrides[i].gpio & GPIO_RUMBLE) { + GBAGPIOInitRumble(&gba->memory.gpio); + } return; } } diff --git a/src/gba/gba.h b/src/gba/gba.h index 355f836f7..bc3561be5 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h @@ -88,6 +88,7 @@ struct GBA { int springIRQ; int* keySource; struct GBARotationSource* rotationSource; + struct GBARumble* rumble; const char* activeFile; const char* savefile;