lemur/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
2024-10-22 03:31:55 +00:00
static uint16_t symToMask(SDL_Keycode sym) {
2024-10-20 04:08:37 +00:00
switch (sym) {
default: return 0;
2024-10-22 03:31:55 +00:00
case SDLK_A:
2024-10-20 04:08:37 +00:00
return VB_SEL;
2024-10-22 03:31:55 +00:00
case SDLK_S:
2024-10-20 04:08:37 +00:00
return VB_STA;
2024-10-22 03:31:55 +00:00
case SDLK_D:
2024-10-20 04:08:37 +00:00
return VB_B;
2024-10-22 03:31:55 +00:00
case SDLK_F:
2024-10-20 04:08:37 +00:00
return VB_A;
2024-10-22 03:31:55 +00:00
case SDLK_E:
2024-10-20 04:08:37 +00:00
return VB_LT;
2024-10-22 03:31:55 +00:00
case SDLK_R:
2024-10-20 04:08:37 +00:00
return VB_RT;
2024-10-22 03:31:55 +00:00
case SDLK_I:
2024-10-20 04:08:37 +00:00
return VB_RU;
2024-10-22 03:31:55 +00:00
case SDLK_J:
2024-10-20 04:08:37 +00:00
return VB_RL;
2024-10-22 03:31:55 +00:00
case SDLK_K:
2024-10-20 04:08:37 +00:00
return VB_RD;
2024-10-22 03:31:55 +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;
}