#include #define VB_PWR 0x0001 #define VB_SGN 0x0002 #define VB_A 0x0004 #define VB_B 0x0008 #define VB_RT 0x0010 #define VB_LT 0x0020 #define VB_RU 0x0040 #define VB_RR 0x0080 #define VB_LR 0x0100 #define VB_LL 0x0200 #define VB_LD 0x0400 #define VB_LU 0x0800 #define VB_STA 0x1000 #define VB_SEL 0x2000 #define VB_RL 0x4000 #define VB_RD 0x8000 static uint16_t symToMask(SDL_Keycode sym) { switch (sym) { default: return 0; case SDLK_A: return VB_SEL; case SDLK_S: return VB_STA; case SDLK_D: return VB_B; case SDLK_F: return VB_A; case SDLK_E: return VB_LT; case SDLK_R: return VB_RT; case SDLK_I: return VB_RU; case SDLK_J: return VB_RL; case SDLK_K: return VB_RD; case SDLK_L: return VB_RR; case SDLK_UP: return VB_LU; case SDLK_LEFT: return VB_LL; case SDLK_DOWN: return VB_LD; case SDLK_RIGHT: return VB_LR; } } void ctrlInit(ControllerState *ctrl) { ctrl->keys = VB_SGN; } void ctrlKeyDown(ControllerState *ctrl, SDL_Keycode sym) { ctrl->keys |= symToMask(sym); } void ctrlKeyUp(ControllerState *ctrl, SDL_Keycode sym) { ctrl->keys &= ~symToMask(sym); } uint16_t ctrlKeys(ControllerState *ctrl) { return ctrl->keys; }