all repos — mgba @ 90760a30a3681c99db8b5964e671e4d1ac6d581b

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

90760a30a3681c99db8b5964e671e4d1ac6d581b

parent

5a17030c65e663cd6d3f9be710c658333f207add

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

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

@@ -28,6 +28,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);

@@ -165,27 +185,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

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

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