# HG changeset patch # User Michael Pavone # Date 1459786394 25200 # Node ID 3b7910575a00d8672d7b3e45c48bae5b024157af # Parent 44c057a640b2d3d4722ce79938ebb478aac72275 Implemented basic keyboard support diff -r 44c057a640b2 -r 3b7910575a00 src/system_sdl.c --- a/src/system_sdl.c Sun Apr 03 21:27:27 2016 -0700 +++ b/src/system_sdl.c Mon Apr 04 09:13:14 2016 -0700 @@ -173,7 +173,7 @@ return NULL; } -const uint16_t mapping[SDL_CONTROLLER_BUTTON_MAX] = { +static const uint16_t mapping[SDL_CONTROLLER_BUTTON_MAX] = { [SDL_CONTROLLER_BUTTON_LEFTSHOULDER] = 0x001, [SDL_CONTROLLER_BUTTON_Y] = 0x002, [SDL_CONTROLLER_BUTTON_X] = 0x004, @@ -188,6 +188,38 @@ [SDL_CONTROLLER_BUTTON_DPAD_UP] = 0x800, }; +static uint16_t keycode_to_bit(SDL_Keycode keycode) +{ + switch(keycode) + { + case SDLK_a: + return 0x020; + case SDLK_s: + return 0x010; + case SDLK_d: + return 0x008; + case SDLK_q: + return 0x004; + case SDLK_w: + return 0x002; + case SDLK_e: + return 0x001; + case SDLK_f: + return 0x040; + case SDLK_RETURN: + return 0x080; + case SDLK_UP: + return 0x800; + case SDLK_DOWN: + return 0x400; + case SDLK_LEFT: + return 0x200; + case SDLK_RIGHT: + return 0x100; + } + return 0; +} + void system_poll_events() { SDL_Event event; @@ -204,7 +236,12 @@ case SDL_CONTROLLERBUTTONUP: controller_released(event.cbutton.which, mapping[event.cbutton.button]); break; - //TODO: Keyboard input + case SDL_KEYDOWN: + controller_pressed(0, keycode_to_bit(event.key.keysym.sym)); + break; + case SDL_KEYUP: + controller_released(0, keycode_to_bit(event.key.keysym.sym)); + break; //TODO: Controller hotplug } }