diff --git a/CHANGES b/CHANGES index ae38339f6..a96f51dcb 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,7 @@ Features: - Experimental high level "XQ" audio for most GBA games - Interframe blending for games that use flicker effects - Frame inspector for dissecting and debugging rendering + - Switch: Option to use built-in brightness sensor for Boktai Emulation fixes: - GBA: All IRQs have 7 cycle delay (fixes mgba.io/i/539, mgba.io/i/1208) - GBA: Reset now reloads multiboot ROMs diff --git a/src/platform/switch/main.c b/src/platform/switch/main.c index 86d6abdfb..3b5124e83 100644 --- a/src/platform/switch/main.c +++ b/src/platform/switch/main.c @@ -99,6 +99,8 @@ static u8 vmode; static u32 vwidth; static u32 vheight; static bool interframeBlending = false; +static bool useLightSensor = true; +static struct mGUIRunnerLux lightSensor; static enum ScreenMode { SM_PA, @@ -268,6 +270,10 @@ static void _setup(struct mGUIRunner* runner) { runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation); runner->core->setAVStream(runner->core, &stream); + if (runner->core->platform(runner->core) == PLATFORM_GBA && useLightSensor) { + runner->core->setPeripheral(runner->core, mPERIPH_GBA_LUMINANCE, &lightSensor.d); + } + unsigned mode; if (mCoreConfigGetUIntValue(&runner->config, "screenMode", &mode) && mode < SM_MAX) { screenMode = mode; @@ -292,6 +298,19 @@ static void _gameLoaded(struct mGUIRunner* runner) { if (mCoreConfigGetIntValue(&runner->config, "interframeBlending", &fakeBool)) { interframeBlending = fakeBool; } + if (mCoreConfigGetIntValue(&runner->config, "useLightSensor", &fakeBool)) { + if (useLightSensor != fakeBool) { + useLightSensor = fakeBool; + + if (runner->core->platform(runner->core) == PLATFORM_GBA) { + if (useLightSensor) { + runner->core->setPeripheral(runner->core, mPERIPH_GBA_LUMINANCE, &lightSensor.d); + } else { + runner->core->setPeripheral(runner->core, mPERIPH_GBA_LUMINANCE, &runner->luminanceSource.d); + } + } + } + } rumble.up = 0; rumble.down = 0; @@ -543,6 +562,18 @@ int32_t _readGyroZ(struct mRotationSource* source) { return sixaxis.gyroscope.z * -1.1e9f; } +static void _lightSensorSample(struct GBALuminanceSource* lux) { + struct mGUIRunnerLux* runnerLux = (struct mGUIRunnerLux*) lux; + float luxLevel = 0; + appletGetCurrentIlluminance(&luxLevel); + runnerLux->luxLevel = cbrtf(luxLevel) * 8; +} + +static uint8_t _lightSensorRead(struct GBALuminanceSource* lux) { + struct mGUIRunnerLux* runnerLux = (struct mGUIRunnerLux*) lux; + return 0xFF - runnerLux->luxLevel; +} + static int _batteryState(void) { u32 charge; int state = 0; @@ -690,6 +721,9 @@ int main(int argc, char* argv[]) { rotation.readTiltY = _readTiltY; rotation.readGyroZ = _readGyroZ; + lightSensor.d.readLuminance = _lightSensorRead; + lightSensor.d.sample = _lightSensorSample; + stream.videoDimensionsChanged = NULL; stream.postVideoFrame = NULL; stream.postAudioFrame = NULL; @@ -707,6 +741,9 @@ int main(int argc, char* argv[]) { audoutBuffer[i].data_offset = 0; } + bool illuminanceAvailable = false; + appletIsIlluminanceAvailable(&illuminanceAvailable); + struct mGUIRunner runner = { .params = { 1280, 720, @@ -829,8 +866,19 @@ int main(int argc, char* argv[]) { }, .nStates = 6 }, + { + .title = "Use built-in brightness sensor for Boktai", + .data = "useLightSensor", + .submenu = 0, + .state = illuminanceAvailable, + .validStates = (const char*[]) { + "Off", + "On", + }, + .nStates = 2 + }, }, - .nConfigExtra = 4, + .nConfigExtra = 5, .setup = _setup, .teardown = NULL, .gameLoaded = _gameLoaded,