GBA Context: Adjustable solar sensor, map to N3DS c-stick
Jeffrey Pfau jeffrey@endrift.com
Tue, 01 Sep 2015 23:09:48 -0700
9 files changed,
62 insertions(+),
15 deletions(-)
M
src/gba/gui/gui-runner.c
→
src/gba/gui/gui-runner.c
@@ -5,6 +5,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "gui-runner.h" +#include "gba/interface.h" #include "gba/serialize.h" #include "util/gui/file-select.h" #include "util/gui/font.h"@@ -36,9 +37,26 @@ gbaBackground->p->drawFrame(gbaBackground->p, true);
} } +static void _updateLux(struct GBALuminanceSource* lux) { + UNUSED(lux); +} + +static uint8_t _readLux(struct GBALuminanceSource* lux) { + struct GBAGUIRunnerLux* runnerLux = (struct GBAGUIRunnerLux*) lux; + int value = 0x16; + if (runnerLux->luxLevel > 0) { + value += GBA_LUX_LEVELS[runnerLux->luxLevel - 1]; + } + return 0xFF - value; +} + void GBAGUIInit(struct GBAGUIRunner* runner, const char* port) { GUIInit(&runner->params); GBAContextInit(&runner->context, port); + runner->luminanceSource.d.readLuminance = _readLux; + runner->luminanceSource.d.sample = _updateLux; + runner->luminanceSource.luxLevel = 0; + runner->context.gba->luminanceSource = &runner->luminanceSource.d; runner->background.d.draw = _drawBackground; runner->background.p = runner; if (runner->setup) {@@ -139,10 +157,21 @@ }
bool running = true; while (running) { while (true) { - int guiKeys = runner->params.pollInput(); + uint32_t guiKeys; + GUIPollInput(&runner->params, &guiKeys, 0); if (guiKeys & (1 << GUI_INPUT_CANCEL)) { break; } + if (guiKeys & (1 << GBA_GUI_INPUT_INCREASE_BRIGHTNESS)) { + if (runner->luminanceSource.luxLevel < 10) { + ++runner->luminanceSource.luxLevel; + } + } + if (guiKeys & (1 << GBA_GUI_INPUT_DECREASE_BRIGHTNESS)) { + if (runner->luminanceSource.luxLevel > 0) { + --runner->luminanceSource.luxLevel; + } + } uint16_t keys = runner->pollGameInput(runner); if (runner->prepareForFrame) { runner->prepareForFrame(runner);@@ -156,7 +185,7 @@ }
} GUIInvalidateKeys(&runner->params); - int keys = -1; // Huge hack to avoid an extra variable! + uint32_t keys = 0xFFFFFFFF; // Huge hack to avoid an extra variable! struct GUIMenuItem item; enum GUIMenuExitReason reason = GUIShowMenu(&runner->params, &pauseMenu, &item); if (reason == GUI_MENU_EXIT_ACCEPT) {
M
src/gba/gui/gui-runner.h
→
src/gba/gui/gui-runner.h
@@ -9,17 +9,27 @@
#include "gba/context/context.h" #include "util/gui.h" +enum GBAGUIInput { + GBA_GUI_INPUT_INCREASE_BRIGHTNESS = GUI_INPUT_USER_START, + GBA_GUI_INPUT_DECREASE_BRIGHTNESS +}; struct GBAGUIBackground { struct GUIBackground d; struct GBAGUIRunner* p; }; +struct GBAGUIRunnerLux { + struct GBALuminanceSource d; + int luxLevel; +}; + struct GBAGUIRunner { struct GBAContext context; struct GUIParams params; struct GBAGUIBackground background; + struct GBAGUIRunnerLux luminanceSource; void (*setup)(struct GBAGUIRunner*); void (*teardown)(struct GBAGUIRunner*);
M
src/platform/3ds/main.c
→
src/platform/3ds/main.c
@@ -126,9 +126,9 @@ activeKeys |= activeKeys >> 24;
return activeKeys; } -static int _pollInput(void) { +static uint32_t _pollInput(void) { hidScanInput(); - int keys = 0; + uint32_t keys = 0; int activeKeys = hidKeysHeld(); if (activeKeys & KEY_X) { keys |= 1 << GUI_INPUT_CANCEL;@@ -150,6 +150,12 @@ keys |= 1 << GUI_INPUT_UP;
} if (activeKeys & KEY_DOWN) { keys |= 1 << GUI_INPUT_DOWN; + } + if (activeKeys & KEY_CSTICK_UP) { + keys |= 1 << GBA_GUI_INPUT_INCREASE_BRIGHTNESS; + } + if (activeKeys & KEY_CSTICK_DOWN) { + keys |= 1 << GBA_GUI_INPUT_DECREASE_BRIGHTNESS; } return keys; }
M
src/platform/psp2/main.c
→
src/platform/psp2/main.c
@@ -30,7 +30,7 @@ vita2d_end_drawing();
vita2d_swap_buffers(); } -static int _pollInput(void) { +static uint32_t _pollInput(void) { SceCtrlData pad; sceCtrlPeekBufferPositive(0, &pad, 1); int input = 0;
M
src/platform/wii/main.c
→
src/platform/wii/main.c
@@ -33,7 +33,7 @@ static int32_t _readGyroZ(struct GBARotationSource* source);
static void _drawStart(void); static void _drawEnd(void); -static int _pollInput(void); +static uint32_t _pollInput(void); static void _guiPrepare(void); static void _guiFinish(void);@@ -224,7 +224,7 @@ VIDEO_SetNextFramebuffer(framebuffer[whichFb]);
VIDEO_Flush(); } -static int _pollInput(void) { +static uint32_t _pollInput(void) { PAD_ScanPads(); u16 padkeys = PAD_ButtonsHeld(0);
M
src/util/gui.c
→
src/util/gui.c
@@ -10,9 +10,9 @@ memset(params->inputHistory, 0, sizeof(params->inputHistory));
strncpy(params->currentPath, params->basePath, PATH_MAX); } -void GUIPollInput(struct GUIParams* params, int* newInputOut, int* heldInput) { - int input = params->pollInput(); - int newInput = 0; +void GUIPollInput(struct GUIParams* params, uint32_t* newInputOut, uint32_t* heldInput) { + uint32_t input = params->pollInput(); + uint32_t newInput = 0; for (int i = 0; i < GUI_INPUT_MAX; ++i) { if (input & (1 << i)) { ++params->inputHistory[i];
M
src/util/gui.h
→
src/util/gui.h
@@ -23,7 +23,9 @@ GUI_INPUT_DOWN,
GUI_INPUT_LEFT, GUI_INPUT_RIGHT, - GUI_INPUT_MAX + GUI_INPUT_USER_START = 0x10, + + GUI_INPUT_MAX = 0x20 }; struct GUIBackground {@@ -38,7 +40,7 @@ const char* basePath;
void (*drawStart)(void); void (*drawEnd)(void); - int (*pollInput)(void); + uint32_t (*pollInput)(void); void (*guiPrepare)(void); void (*guiFinish)(void);@@ -53,7 +55,7 @@
#define GUI_PARAMS_TRAIL {}, "", 0 void GUIInit(struct GUIParams* params); -void GUIPollInput(struct GUIParams* params, int* newInput, int* heldInput); +void GUIPollInput(struct GUIParams* params, uint32_t* newInput, uint32_t* heldInput); void GUIInvalidateKeys(struct GUIParams* params); #endif
M
src/util/gui/file-select.c
→
src/util/gui/file-select.c
@@ -56,7 +56,7 @@ struct VDirEntry* de;
while ((de = dir->listNext(dir))) { ++i; if (!(i % SCANNING_THRESHOLD)) { - int input = 0; + uint32_t input = 0; GUIPollInput(params, &input, 0); if (input & (1 << GUI_INPUT_CANCEL)) { return false;