all repos — mgba @ edc6de046743bfdc777d46eeb9e5ce482b74b9d7

mGBA Game Boy Advance Emulator

Move key mapping into its own function
Jeffrey Pfau jeffrey@endrift.com
Mon, 03 Feb 2014 22:27:58 -0800
commit

edc6de046743bfdc777d46eeb9e5ce482b74b9d7

parent

2eb5a7a6390e053ca6a0b3356400724c04d5533c

2 files changed, 24 insertions(+), 21 deletions(-)

jump to
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -20,6 +20,26 @@ SDL_JoystickClose(context->joystick);

SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } +enum GBAKey GBASDLMapButtonToKey(int button) { + // Sorry, hardcoded to my gamepad for now + switch (button) { + case 2: + return GBA_KEY_A; + case 1: + return GBA_KEY_B; + case 6: + return GBA_KEY_L; + case 7: + return GBA_KEY_R; + case 8: + return GBA_KEY_START; + case 9: + return GBA_KEY_SELECT; + default: + return GBA_KEY_NONE; + } +} + static void _pauseAfterFrame(struct GBAThread* context) { context->frameCallback = 0; GBAThreadPause(context);

@@ -151,27 +171,8 @@ }

static void _GBASDLHandleJoyButton(struct GBAThread* context, const struct SDL_JoyButtonEvent* event) { enum GBAKey key = 0; - // Sorry, hardcoded to my gamepad for now - switch (event->button) { - case 2: - key = GBA_KEY_A; - break; - case 1: - key = GBA_KEY_B; - break; - case 6: - key = GBA_KEY_L; - break; - case 7: - key = GBA_KEY_R; - break; - case 8: - key = GBA_KEY_START; - break; - case 9: - key = GBA_KEY_SELECT; - break; - default: + key = GBASDLMapButtonToKey(event->button); + if (key == GBA_KEY_NONE) { return; }
M src/platform/sdl/sdl-events.hsrc/platform/sdl/sdl-events.h

@@ -14,4 +14,6 @@ void GBASDLDeinitEvents(struct GBASDLEvents*);

void GBASDLHandleEvent(struct GBAThread* context, const union SDL_Event* event); +enum GBAKey GBASDLMapButtonToKey(int button); + #endif