shrooms-vb-native/controller.c

65 lines
1.3 KiB
C
Raw Normal View History

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