mirror of https://github.com/mgba-emu/mgba.git
GBA: Hook up light sensor API
This commit is contained in:
parent
9b1769d67d
commit
ca51098ca0
|
@ -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 @@ void _lightReadPins(struct GBACartridgeGPIO* gpio) {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -104,7 +104,8 @@ struct GBACartridgeGPIO {
|
|||
uint16_t gyroSample;
|
||||
bool gyroEdge;
|
||||
|
||||
int lightCounter : 12;
|
||||
unsigned lightCounter : 12;
|
||||
uint8_t lightSample;
|
||||
bool lightEdge;
|
||||
};
|
||||
|
||||
|
|
|
@ -17,4 +17,10 @@ struct GBARotationSource {
|
|||
int32_t (*readGyroZ)(struct GBARotationSource*);
|
||||
};
|
||||
|
||||
struct GBALuminanceSource {
|
||||
void (*sample)(struct GBALuminanceSource*);
|
||||
|
||||
uint8_t (*readLuminance)(struct GBALuminanceSource*);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -732,6 +732,10 @@ void _checkOverrides(struct GBA* gba, uint32_t id) {
|
|||
GBAGPIOInitRumble(&gba->memory.gpio);
|
||||
}
|
||||
|
||||
if (_overrides[i].gpio & GPIO_LIGHT_SENSOR) {
|
||||
GBAGPIOInitLightSensor(&gba->memory.gpio);
|
||||
}
|
||||
|
||||
gba->busyLoop = _overrides[i].busyLoop;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -115,7 +115,9 @@ struct GBA {
|
|||
int* keySource;
|
||||
uint32_t busyLoop;
|
||||
struct GBARotationSource* rotationSource;
|
||||
struct GBALuminanceSource* luminanceSource;
|
||||
struct GBARumble* rumble;
|
||||
|
||||
struct GBARRContext* rr;
|
||||
void* pristineRom;
|
||||
size_t pristineRomSize;
|
||||
|
|
Loading…
Reference in New Issue