1 #define RC_INVOKED // we only need defines
6 #include "../common/input.h"
7 #include "../common/emu.h" // array_size
10 #define IN_VK_PREFIX "vk:"
11 #define IN_VK_NKEYS 0x100
13 static const char * const in_vk_prefix = IN_VK_PREFIX;
14 static const char * const in_vk_keys[IN_VK_NKEYS] = {
15 [0 ... (IN_VK_NKEYS - 1)] = NULL,
16 [VK_LBUTTON] = "LBUTTON", [VK_RBUTTON] = "RBUTTON",
17 [VK_TAB] = "TAB", [VK_RETURN] = "RETURN",
18 [VK_SHIFT] = "SHIFT", [VK_CONTROL] = "CONTROL",
19 [VK_LEFT] = "LEFT", [VK_UP] = "UP",
20 [VK_RIGHT] = "RIGHT", [VK_DOWN] = "DOWN",
24 // additional player12 keys
27 // up to 4, keyboards rarely allow more
28 static int in_vk_keys_down[4];
35 #define VK_NUMPAD0 0x60
36 #define VK_NUMPAD1 0x61
37 #define VK_NUMPAD2 0x62
38 #define VK_NUMPAD3 0x63
39 #define VK_NUMPAD4 0x64
40 #define VK_NUMPAD5 0x65
41 #define VK_NUMPAD6 0x66
42 #define VK_NUMPAD7 0x67
43 #define VK_NUMPAD8 0x68
44 #define VK_NUMPAD9 0x69
45 #define VK_MULTIPLY 0x6A
47 #define VK_SEPARATOR 0x6C
48 #define VK_SUBTRACT 0x6D
49 #define VK_DECIMAL 0x6E
50 #define VK_DIVIDE 0x6F
65 static void in_vk_probe(void)
67 memset(in_vk_keys_down, 0, sizeof(in_vk_keys_down));
68 in_register(IN_VK_PREFIX "vk", IN_DRVID_VK, -1, (void *)1, IN_VK_NKEYS, 0);
71 static int in_vk_get_bind_count(void)
76 /* ORs result with pressed buttons */
77 int in_vk_update(void *drv_data, const int *binds, int *result)
81 for (i = 0; i < array_size(in_vk_keys_down); i++) {
82 k = in_vk_keys_down[i];
86 for (t = 0; t < IN_BINDTYPE_COUNT; t++)
87 result[t] |= binds[IN_BIND_OFFS(k, t)];
90 result[IN_BINDTYPE_PLAYER12] |= in_vk_add_pl12;
95 void in_vk_keydown(int kc)
100 for (i = 0; i < array_size(in_vk_keys_down); i++)
101 if (in_vk_keys_down[i] == kc)
105 for (i = 0; i < array_size(in_vk_keys_down); i++) {
106 if (in_vk_keys_down[i] == 0) {
107 in_vk_keys_down[i] = kc;
113 void in_vk_keyup(int kc)
116 for (i = 0; i < array_size(in_vk_keys_down); i++)
117 if (in_vk_keys_down[i] == kc)
118 in_vk_keys_down[i] = 0;
121 static int in_vk_update_keycode(void *data, int *is_down)
126 static const struct {
132 { VK_DOWN, PBTN_DOWN },
133 { VK_LEFT, PBTN_LEFT },
134 { VK_RIGHT, PBTN_RIGHT },
135 { VK_RETURN, PBTN_MOK },
137 { BTN_X, PBTN_MBACK },
142 { BTN_SELECT, PBTN_MENU },
146 #define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
148 static int in_vk_menu_translate(int keycode)
155 for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
156 if (key_pbtn_map[i].pbtn == keycode)
157 return key_pbtn_map[i].key;
161 for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
162 if (key_pbtn_map[i].key == keycode)
163 return key_pbtn_map[i].pbtn;
169 static int in_vk_get_key_code(const char *key_name)
173 if (key_name[1] == 0 && 'A' <= key_name[0] && key_name[0] <= 'Z')
176 for (i = 0; i < IN_VK_NKEYS; i++) {
177 const char *k = in_vk_keys[i];
178 if (k != NULL && strcasecmp(k, key_name) == 0)
185 static const char *in_vk_get_key_name(int keycode)
187 const char *name = NULL;
190 if ('A' <= keycode && keycode < 'Z') {
196 if (0 <= keycode && keycode < IN_VK_NKEYS)
197 name = in_vk_keys[keycode];
204 static const struct {
208 } in_vk_def_binds[] =
211 { VK_UP, IN_BINDTYPE_PLAYER12, 0 },
212 { VK_DOWN, IN_BINDTYPE_PLAYER12, 1 },
213 { VK_LEFT, IN_BINDTYPE_PLAYER12, 2 },
214 { VK_RIGHT, IN_BINDTYPE_PLAYER12, 3 },
215 { 'S', IN_BINDTYPE_PLAYER12, 4 }, /* B */
216 { 'D', IN_BINDTYPE_PLAYER12, 5 }, /* C */
217 { 'A', IN_BINDTYPE_PLAYER12, 6 }, /* A */
218 { VK_RETURN, IN_BINDTYPE_PLAYER12, 7 },
219 { 'E', IN_BINDTYPE_PLAYER12, 8 }, /* Z */
220 { 'W', IN_BINDTYPE_PLAYER12, 9 }, /* Y */
221 { 'Q', IN_BINDTYPE_PLAYER12,10 }, /* X */
222 { 'R', IN_BINDTYPE_PLAYER12,11 }, /* M */
224 { BTN_SELECT, IN_BINDTYPE_EMU, PEVB_MENU },
225 // { BTN_Y, IN_BINDTYPE_EMU, PEVB_SWITCH_RND },
226 { BTN_L, IN_BINDTYPE_EMU, PEVB_STATE_SAVE },
227 { BTN_R, IN_BINDTYPE_EMU, PEVB_STATE_LOAD },
228 { BTN_VOL_UP, IN_BINDTYPE_EMU, PEVB_VOL_UP },
229 { BTN_VOL_DOWN, IN_BINDTYPE_EMU, PEVB_VOL_DOWN },
233 #define DEF_BIND_COUNT (sizeof(in_vk_def_binds) / sizeof(in_vk_def_binds[0]))
235 static void in_vk_get_def_binds(int *binds)
239 for (i = 0; i < DEF_BIND_COUNT; i++)
240 binds[IN_BIND_OFFS(in_vk_def_binds[i].code, in_vk_def_binds[i].btype)] =
241 1 << in_vk_def_binds[i].bit;
244 /* remove binds of missing keys, count remaining ones */
245 static int in_vk_clean_binds(void *drv_data, int *binds, int *def_binds)
249 for (i = 0; i < IN_VK_NKEYS; i++) {
251 for (t = 0; t < IN_BINDTYPE_COUNT; t++) {
252 offs = IN_BIND_OFFS(i, t);
253 if (strcmp(in_vk_get_key_name(i), "Unkn") == 0)
254 binds[offs] = def_binds[offs] = 0;
263 void in_vk_init(void *vdrv)
265 in_drv_t *drv = vdrv;
267 drv->prefix = in_vk_prefix;
268 drv->probe = in_vk_probe;
269 drv->get_bind_count = in_vk_get_bind_count;
270 drv->get_def_binds = in_vk_get_def_binds;
271 drv->clean_binds = in_vk_clean_binds;
272 drv->menu_translate = in_vk_menu_translate;
273 drv->get_key_code = in_vk_get_key_code;
274 drv->get_key_name = in_vk_get_key_name;
275 drv->update_keycode = in_vk_update_keycode;