all repos — mgba @ ca51098ca0ac23d88f5b9235c0cc0244521175b8

mGBA Game Boy Advance Emulator

GBA: Hook up light sensor API
Jeffrey Pfau jeffrey@endrift.com
Thu, 25 Dec 2014 02:53:43 -0800
commit

ca51098ca0ac23d88f5b9235c0cc0244521175b8

parent

9b1769d67dae4a1f02f146265411c68171e031d3

5 files changed, 23 insertions(+), 2 deletions(-)

jump to
M src/gba/gba-gpio.csrc/gba/gba-gpio.c

@@ -322,6 +322,7 @@ void GBAGPIOInitLightSensor(struct GBACartridgeGPIO* gpio) {

gpio->gpioDevices |= GPIO_LIGHT_SENSOR; gpio->lightCounter = 0; gpio->lightEdge = false; + gpio->lightSample = 0xFF; } void _lightReadPins(struct GBACartridgeGPIO* gpio) {

@@ -330,15 +331,22 @@ // Boktai chip select

return; } if (gpio->p1) { + struct GBALuminanceSource* lux = gpio->p->luminanceSource; GBALog(0, GBA_LOG_DEBUG, "[SOLAR] Got reset"); gpio->lightCounter = 0; + if (lux) { + lux->sample(lux); + gpio->lightSample = lux->readLuminance(lux); + } else { + gpio->lightSample = 0xFF; + } } if (gpio->p0 && gpio->lightEdge) { ++gpio->lightCounter; } gpio->lightEdge = !gpio->p0; - bool sendBit = gpio->lightCounter >= 0x80; + bool sendBit = gpio->lightCounter >= gpio->lightSample; _outputPins(gpio, sendBit << 3); GBALog(0, GBA_LOG_DEBUG, "[SOLAR] Output %u with pins %u", gpio->lightCounter, gpio->pinState); }
M src/gba/gba-gpio.hsrc/gba/gba-gpio.h

@@ -104,7 +104,8 @@

uint16_t gyroSample; bool gyroEdge; - int lightCounter : 12; + unsigned lightCounter : 12; + uint8_t lightSample; bool lightEdge; };
M src/gba/gba-sensors.hsrc/gba/gba-sensors.h

@@ -17,4 +17,10 @@

int32_t (*readGyroZ)(struct GBARotationSource*); }; +struct GBALuminanceSource { + void (*sample)(struct GBALuminanceSource*); + + uint8_t (*readLuminance)(struct GBALuminanceSource*); +}; + #endif
M src/gba/gba.csrc/gba/gba.c

@@ -732,6 +732,10 @@ if (_overrides[i].gpio & GPIO_RUMBLE) {

GBAGPIOInitRumble(&gba->memory.gpio); } + if (_overrides[i].gpio & GPIO_LIGHT_SENSOR) { + GBAGPIOInitLightSensor(&gba->memory.gpio); + } + gba->busyLoop = _overrides[i].busyLoop; return; }
M src/gba/gba.hsrc/gba/gba.h

@@ -115,7 +115,9 @@ uint32_t biosChecksum;

int* keySource; uint32_t busyLoop; struct GBARotationSource* rotationSource; + struct GBALuminanceSource* luminanceSource; struct GBARumble* rumble; + struct GBARRContext* rr; void* pristineRom; size_t pristineRomSize;