all repos — mgba @ 9ac838d14df205480010d9aa6464ef2c6aa389f2

mGBA Game Boy Advance Emulator

Switch: Option to use built-in brightness sensor for Boktai
Vicki Pfau vi@endrift.com
Tue, 04 Jun 2019 22:32:09 -0700
commit

9ac838d14df205480010d9aa6464ef2c6aa389f2

parent

9b0e4af7b430ee1cd4bbc9b7a37768a820c2b236

2 files changed, 50 insertions(+), 1 deletions(-)

jump to
M CHANGESCHANGES

@@ -12,6 +12,7 @@ - OpenGL renderer with high-resolution upscaling support

- 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
M src/platform/switch/main.csrc/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 @@ runner->core->setPeripheral(runner->core, mPERIPH_RUMBLE, &rumble.d);

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;

@@ -291,6 +297,19 @@

int fakeBool; 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;

@@ -543,6 +562,18 @@ hidSixAxisSensorValuesRead(&sixaxis, CONTROLLER_P1_AUTO, 1);

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 @@ rotation.readTiltX = _readTiltX;

rotation.readTiltY = _readTiltY; rotation.readGyroZ = _readGyroZ; + lightSensor.d.readLuminance = _lightSensorRead; + lightSensor.d.sample = _lightSensorSample; + stream.videoDimensionsChanged = NULL; stream.postVideoFrame = NULL; stream.postAudioFrame = NULL;

@@ -706,6 +740,9 @@ audoutBuffer[i].buffer_size = BUFFER_SIZE;

audoutBuffer[i].data_size = BUFFER_SIZE; audoutBuffer[i].data_offset = 0; } + + bool illuminanceAvailable = false; + appletIsIlluminanceAvailable(&illuminanceAvailable); struct mGUIRunner runner = { .params = {

@@ -829,8 +866,19 @@ GUI_V_U(6),

}, .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,