2024-10-20 04:08:37 +00:00
|
|
|
#include <controller.h>
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2024-10-23 23:01:54 +00:00
|
|
|
static uint16_t symToMask(SDL_KeyCode sym) {
|
2024-10-20 04:08:37 +00:00
|
|
|
switch (sym) {
|
|
|
|
default: return 0;
|
2024-10-23 23:01:54 +00:00
|
|
|
case SDLK_a:
|
2024-10-20 04:08:37 +00:00
|
|
|
return VB_SEL;
|
2024-10-23 23:01:54 +00:00
|
|
|
case SDLK_s:
|
2024-10-20 04:08:37 +00:00
|
|
|
return VB_STA;
|
2024-10-23 23:01:54 +00:00
|
|
|
case SDLK_d:
|
2024-10-20 04:08:37 +00:00
|
|
|
return VB_B;
|
2024-10-23 23:01:54 +00:00
|
|
|
case SDLK_f:
|
2024-10-20 04:08:37 +00:00
|
|
|
return VB_A;
|
2024-10-23 23:01:54 +00:00
|
|
|
case SDLK_e:
|
2024-10-20 04:08:37 +00:00
|
|
|
return VB_LT;
|
2024-10-23 23:01:54 +00:00
|
|
|
case SDLK_r:
|
2024-10-20 04:08:37 +00:00
|
|
|
return VB_RT;
|
2024-10-23 23:01:54 +00:00
|
|
|
case SDLK_i:
|
2024-10-20 04:08:37 +00:00
|
|
|
return VB_RU;
|
2024-10-23 23:01:54 +00:00
|
|
|
case SDLK_j:
|
2024-10-20 04:08:37 +00:00
|
|
|
return VB_RL;
|
2024-10-23 23:01:54 +00:00
|
|
|
case SDLK_k:
|
2024-10-20 04:08:37 +00:00
|
|
|
return VB_RD;
|
2024-10-23 23:01:54 +00:00
|
|
|
case SDLK_l:
|
2024-10-20 04:08:37 +00:00
|
|
|
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;
|
|
|
|
}
|