mirror of https://github.com/mgba-emu/mgba.git
GBA Context: Adjustable solar sensor, map to N3DS c-stick
This commit is contained in:
parent
5e759afada
commit
ed46d63ebd
|
@ -5,6 +5,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#include "gui-runner.h"
|
#include "gui-runner.h"
|
||||||
|
|
||||||
|
#include "gba/interface.h"
|
||||||
#include "gba/serialize.h"
|
#include "gba/serialize.h"
|
||||||
#include "util/gui/file-select.h"
|
#include "util/gui/file-select.h"
|
||||||
#include "util/gui/font.h"
|
#include "util/gui/font.h"
|
||||||
|
@ -36,9 +37,26 @@ static void _drawBackground(struct GUIBackground* background) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
void GBAGUIInit(struct GBAGUIRunner* runner, const char* port) {
|
||||||
GUIInit(&runner->params);
|
GUIInit(&runner->params);
|
||||||
GBAContextInit(&runner->context, port);
|
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.d.draw = _drawBackground;
|
||||||
runner->background.p = runner;
|
runner->background.p = runner;
|
||||||
if (runner->setup) {
|
if (runner->setup) {
|
||||||
|
@ -139,10 +157,21 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
|
||||||
bool running = true;
|
bool running = true;
|
||||||
while (running) {
|
while (running) {
|
||||||
while (true) {
|
while (true) {
|
||||||
int guiKeys = runner->params.pollInput();
|
uint32_t guiKeys;
|
||||||
|
GUIPollInput(&runner->params, &guiKeys, 0);
|
||||||
if (guiKeys & (1 << GUI_INPUT_CANCEL)) {
|
if (guiKeys & (1 << GUI_INPUT_CANCEL)) {
|
||||||
break;
|
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);
|
uint16_t keys = runner->pollGameInput(runner);
|
||||||
if (runner->prepareForFrame) {
|
if (runner->prepareForFrame) {
|
||||||
runner->prepareForFrame(runner);
|
runner->prepareForFrame(runner);
|
||||||
|
@ -156,7 +185,7 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GUIInvalidateKeys(&runner->params);
|
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;
|
struct GUIMenuItem item;
|
||||||
enum GUIMenuExitReason reason = GUIShowMenu(&runner->params, &pauseMenu, &item);
|
enum GUIMenuExitReason reason = GUIShowMenu(&runner->params, &pauseMenu, &item);
|
||||||
if (reason == GUI_MENU_EXIT_ACCEPT) {
|
if (reason == GUI_MENU_EXIT_ACCEPT) {
|
||||||
|
|
|
@ -9,17 +9,27 @@
|
||||||
#include "gba/context/context.h"
|
#include "gba/context/context.h"
|
||||||
#include "util/gui.h"
|
#include "util/gui.h"
|
||||||
|
|
||||||
|
enum GBAGUIInput {
|
||||||
|
GBA_GUI_INPUT_INCREASE_BRIGHTNESS = GUI_INPUT_USER_START,
|
||||||
|
GBA_GUI_INPUT_DECREASE_BRIGHTNESS
|
||||||
|
};
|
||||||
|
|
||||||
struct GBAGUIBackground {
|
struct GBAGUIBackground {
|
||||||
struct GUIBackground d;
|
struct GUIBackground d;
|
||||||
struct GBAGUIRunner* p;
|
struct GBAGUIRunner* p;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct GBAGUIRunnerLux {
|
||||||
|
struct GBALuminanceSource d;
|
||||||
|
int luxLevel;
|
||||||
|
};
|
||||||
|
|
||||||
struct GBAGUIRunner {
|
struct GBAGUIRunner {
|
||||||
struct GBAContext context;
|
struct GBAContext context;
|
||||||
struct GUIParams params;
|
struct GUIParams params;
|
||||||
|
|
||||||
struct GBAGUIBackground background;
|
struct GBAGUIBackground background;
|
||||||
|
struct GBAGUIRunnerLux luminanceSource;
|
||||||
|
|
||||||
void (*setup)(struct GBAGUIRunner*);
|
void (*setup)(struct GBAGUIRunner*);
|
||||||
void (*teardown)(struct GBAGUIRunner*);
|
void (*teardown)(struct GBAGUIRunner*);
|
||||||
|
|
|
@ -126,9 +126,9 @@ static uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
|
||||||
return activeKeys;
|
return activeKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _pollInput(void) {
|
static uint32_t _pollInput(void) {
|
||||||
hidScanInput();
|
hidScanInput();
|
||||||
int keys = 0;
|
uint32_t keys = 0;
|
||||||
int activeKeys = hidKeysHeld();
|
int activeKeys = hidKeysHeld();
|
||||||
if (activeKeys & KEY_X) {
|
if (activeKeys & KEY_X) {
|
||||||
keys |= 1 << GUI_INPUT_CANCEL;
|
keys |= 1 << GUI_INPUT_CANCEL;
|
||||||
|
@ -151,6 +151,12 @@ static int _pollInput(void) {
|
||||||
if (activeKeys & KEY_DOWN) {
|
if (activeKeys & KEY_DOWN) {
|
||||||
keys |= 1 << GUI_INPUT_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;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ static void _drawEnd(void) {
|
||||||
vita2d_swap_buffers();
|
vita2d_swap_buffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _pollInput(void) {
|
static uint32_t _pollInput(void) {
|
||||||
SceCtrlData pad;
|
SceCtrlData pad;
|
||||||
sceCtrlPeekBufferPositive(0, &pad, 1);
|
sceCtrlPeekBufferPositive(0, &pad, 1);
|
||||||
int input = 0;
|
int input = 0;
|
||||||
|
|
|
@ -33,7 +33,7 @@ static int32_t _readGyroZ(struct GBARotationSource* source);
|
||||||
|
|
||||||
static void _drawStart(void);
|
static void _drawStart(void);
|
||||||
static void _drawEnd(void);
|
static void _drawEnd(void);
|
||||||
static int _pollInput(void);
|
static uint32_t _pollInput(void);
|
||||||
static void _guiPrepare(void);
|
static void _guiPrepare(void);
|
||||||
static void _guiFinish(void);
|
static void _guiFinish(void);
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ static void _drawEnd(void) {
|
||||||
VIDEO_Flush();
|
VIDEO_Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _pollInput(void) {
|
static uint32_t _pollInput(void) {
|
||||||
PAD_ScanPads();
|
PAD_ScanPads();
|
||||||
u16 padkeys = PAD_ButtonsHeld(0);
|
u16 padkeys = PAD_ButtonsHeld(0);
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,9 @@ void GUIInit(struct GUIParams* params) {
|
||||||
strncpy(params->currentPath, params->basePath, PATH_MAX);
|
strncpy(params->currentPath, params->basePath, PATH_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIPollInput(struct GUIParams* params, int* newInputOut, int* heldInput) {
|
void GUIPollInput(struct GUIParams* params, uint32_t* newInputOut, uint32_t* heldInput) {
|
||||||
int input = params->pollInput();
|
uint32_t input = params->pollInput();
|
||||||
int newInput = 0;
|
uint32_t newInput = 0;
|
||||||
for (int i = 0; i < GUI_INPUT_MAX; ++i) {
|
for (int i = 0; i < GUI_INPUT_MAX; ++i) {
|
||||||
if (input & (1 << i)) {
|
if (input & (1 << i)) {
|
||||||
++params->inputHistory[i];
|
++params->inputHistory[i];
|
||||||
|
|
|
@ -23,7 +23,9 @@ enum GUIInput {
|
||||||
GUI_INPUT_LEFT,
|
GUI_INPUT_LEFT,
|
||||||
GUI_INPUT_RIGHT,
|
GUI_INPUT_RIGHT,
|
||||||
|
|
||||||
GUI_INPUT_MAX
|
GUI_INPUT_USER_START = 0x10,
|
||||||
|
|
||||||
|
GUI_INPUT_MAX = 0x20
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GUIBackground {
|
struct GUIBackground {
|
||||||
|
@ -38,7 +40,7 @@ struct GUIParams {
|
||||||
|
|
||||||
void (*drawStart)(void);
|
void (*drawStart)(void);
|
||||||
void (*drawEnd)(void);
|
void (*drawEnd)(void);
|
||||||
int (*pollInput)(void);
|
uint32_t (*pollInput)(void);
|
||||||
void (*guiPrepare)(void);
|
void (*guiPrepare)(void);
|
||||||
void (*guiFinish)(void);
|
void (*guiFinish)(void);
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ struct GUIParams {
|
||||||
#define GUI_PARAMS_TRAIL {}, "", 0
|
#define GUI_PARAMS_TRAIL {}, "", 0
|
||||||
|
|
||||||
void GUIInit(struct GUIParams* params);
|
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);
|
void GUIInvalidateKeys(struct GUIParams* params);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -56,7 +56,7 @@ static bool _refreshDirectory(struct GUIParams* params, const char* currentPath,
|
||||||
while ((de = dir->listNext(dir))) {
|
while ((de = dir->listNext(dir))) {
|
||||||
++i;
|
++i;
|
||||||
if (!(i % SCANNING_THRESHOLD)) {
|
if (!(i % SCANNING_THRESHOLD)) {
|
||||||
int input = 0;
|
uint32_t input = 0;
|
||||||
GUIPollInput(params, &input, 0);
|
GUIPollInput(params, &input, 0);
|
||||||
if (input & (1 << GUI_INPUT_CANCEL)) {
|
if (input & (1 << GUI_INPUT_CANCEL)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -21,7 +21,7 @@ enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* men
|
||||||
|
|
||||||
GUIInvalidateKeys(params);
|
GUIInvalidateKeys(params);
|
||||||
while (true) {
|
while (true) {
|
||||||
int newInput = 0;
|
uint32_t newInput = 0;
|
||||||
GUIPollInput(params, &newInput, 0);
|
GUIPollInput(params, &newInput, 0);
|
||||||
|
|
||||||
if (newInput & (1 << GUI_INPUT_UP) && menu->index > 0) {
|
if (newInput & (1 << GUI_INPUT_UP) && menu->index > 0) {
|
||||||
|
|
Loading…
Reference in New Issue