all repos — mgba @ d7ec20900c0855b8e55bea1d80138b1ba2bb2d20

mGBA Game Boy Advance Emulator

Switch: Default map left stick to d-pad if no other bindings found
Vicki Pfau vi@endrift.com
Thu, 20 Sep 2018 11:19:54 -0700
commit

d7ec20900c0855b8e55bea1d80138b1ba2bb2d20

parent

1b9e1e8268fd292332a8ea132bb044e87d73e1e6

1 files changed, 36 insertions(+), 5 deletions(-)

jump to
M src/platform/switch/main.csrc/platform/switch/main.c

@@ -20,6 +20,7 @@ #define AUTO_INPUT 0x4E585031

#define SAMPLES 0x400 #define BUFFER_SIZE 0x1000 #define N_BUFFERS 4 +#define ANALOG_DEADZONE 0x4000 TimeType __nx_time_type = TimeType_UserSystemClock;

@@ -162,6 +163,40 @@ int keys = 0;

hidScanInput(); u32 padkeys = hidKeysHeld(CONTROLLER_P1_AUTO); keys |= mInputMapKeyBits(map, AUTO_INPUT, padkeys, 0); + + JoystickPosition jspos; + hidJoystickRead(&jspos, CONTROLLER_P1_AUTO, JOYSTICK_LEFT); + + int l = mInputMapKey(map, AUTO_INPUT, __builtin_ctz(KEY_LSTICK_LEFT)); + int r = mInputMapKey(map, AUTO_INPUT, __builtin_ctz(KEY_LSTICK_RIGHT)); + int u = mInputMapKey(map, AUTO_INPUT, __builtin_ctz(KEY_LSTICK_UP)); + int d = mInputMapKey(map, AUTO_INPUT, __builtin_ctz(KEY_LSTICK_DOWN)); + + if (l == -1) { + l = mInputMapKey(map, AUTO_INPUT, __builtin_ctz(KEY_DLEFT)); + } + if (r == -1) { + r = mInputMapKey(map, AUTO_INPUT, __builtin_ctz(KEY_DRIGHT)); + } + if (u == -1) { + u = mInputMapKey(map, AUTO_INPUT, __builtin_ctz(KEY_DUP)); + } + if (d == -1) { + d = mInputMapKey(map, AUTO_INPUT, __builtin_ctz(KEY_DDOWN)); + } + + if (jspos.dx < -ANALOG_DEADZONE && l != -1) { + keys |= 1 << l; + } + if (jspos.dx > ANALOG_DEADZONE && r != -1) { + keys |= 1 << r; + } + if (jspos.dy < -ANALOG_DEADZONE && d != -1) { + keys |= 1 << d; + } + if (jspos.dy > ANALOG_DEADZONE && u != -1) { + keys |= 1 << u; + } return keys; }

@@ -275,11 +310,7 @@ _drawTex(runner, width, height, faded);

} static uint16_t _pollGameInput(struct mGUIRunner* runner) { - int keys = 0; - hidScanInput(); - u32 padkeys = hidKeysHeld(CONTROLLER_P1_AUTO); - keys |= mInputMapKeyBits(&runner->core->inputMap, AUTO_INPUT, padkeys, 0); - return keys; + return _pollInput(&runner->core->inputMap); } static void _setFrameLimiter(struct mGUIRunner* runner, bool limit) {