#include <unistd.h>
#endif
#include "config.h"
+#include "input.h"
#include "lprintf.h"
static char *mystrip(char *str);
};
#endif
-static void keys_write(FILE *fn, const char *bind_str, const int binds[32],
- const int def_binds[32], const char * const names[32], int key_count, int no_defaults)
+static void keys_write(FILE *fn, const char *bind_str, int dev_id, const int *binds, int no_defaults)
{
- int t, i;
- char act[48], name[32];
+ char act[48];
+ int key_count, t, i;
+ const int *def_binds;
+
+ key_count = in_get_dev_bind_count(dev_id);
+ def_binds = in_get_dev_def_binds(dev_id);
for (t = 0; t < key_count; t++)
{
+ const char *name;
act[0] = act[31] = 0;
+
if (no_defaults && binds[t] == def_binds[t])
continue;
+
+ name = in_get_key_name(dev_id, t);
#ifdef __GP2X__
- if (strcmp(names[t], "SELECT") == 0) continue;
+ if (strcmp(name, "SELECT") == 0) continue;
#endif
- if (t >= 32 || names[t] == NULL || strcmp(names[t], "???") == 0) {
- if ((t >= '0' && t <= '9') || (t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))
- sprintf(name, "%c", t);
- else
- sprintf(name, "\\x%02x", t);
- }
- else
- strcpy(name, names[t]);
if (binds[t] == 0 && def_binds[t] != 0) {
- fprintf(fn, "%s %s =" NL, bind_str, name); // no binds
+ fprintf(fn, "%s %s =" NL, bind_str, name);
continue;
}
}
}
- // save key config
+ /* input: save device names */
+ for (t = 0; t < IN_MAX_DEVS; t++)
+ {
+ const int *binds = in_get_dev_binds(t);
+ const char *name = in_get_dev_name(t);
+ if (binds == NULL || name == NULL)
+ continue;
+
+ fprintf(fn, "input%d = %s" NL, t, name);
+ }
+
+ /* input: save binds */
+ for (t = 0; t < IN_MAX_DEVS; t++)
+ {
+ const int *binds = in_get_dev_binds(t);
+ const char *name = in_get_dev_name(t);
+ char strbind[16];
+ int count;
+
+ if (binds == NULL || name == NULL)
+ continue;
+
+ sprintf(strbind, "bind%d", t);
+ if (t == 0) strbind[4] = 0;
+
+ count = in_get_dev_bind_count(t);
+ keys_write(fn, strbind, t, binds, no_defaults);
+ }
+
+#if 0
+ /* old stuff */
keys_write(fn, "bind", currentConfig.KeyBinds, defaultConfig.KeyBinds, keyNames, PLAT_MAX_KEYS, no_defaults);
#if PLAT_HAVE_JOY
keys_write(fn, "bind_joy0", currentConfig.JoyBinds[0], defaultConfig.JoyBinds[0], joyKeyNames, 32, 1);
keys_write(fn, "bind_joy2", currentConfig.JoyBinds[2], defaultConfig.JoyBinds[2], joyKeyNames, 32, 1);
keys_write(fn, "bind_joy3", currentConfig.JoyBinds[3], defaultConfig.JoyBinds[3], joyKeyNames, 32, 1);
#endif
+#endif
#ifndef PSP
if (section == NULL)
static unsigned int keys_encountered = 0;
-static void keys_parse(const char *var, const char *val, int binds[32],
- const char * const names[32], int max_keys)
+static int parse_bind_val(const char *val)
+{
+ int i;
+
+ if (val[0] == 0)
+ return 0;
+
+ if (strncasecmp(val, "player", 6) == 0)
+ {
+ unsigned int player;
+ player = atoi(val + 6) - 1;
+ if (player > 1)
+ return -1;
+
+ for (i = 0; i < sizeof(me_ctrl_actions) / sizeof(me_ctrl_actions[0]); i++) {
+ if (strncasecmp(me_ctrl_actions[i].name, val + 8, strlen(val + 8)) == 0)
+ return me_ctrl_actions[i].mask | (player<<16);
+ }
+ }
+ for (i = 0; emuctrl_actions[i].name != NULL; i++) {
+ if (strncasecmp(emuctrl_actions[i].name, val, strlen(val)) == 0)
+ return emuctrl_actions[i].mask;
+ }
+
+ return -1;
+}
+
+static void keys_parse(const char *key, const char *val, int dev_id)
{
- int t, i;
- unsigned int player;
+ int binds;
+ binds = parse_bind_val(val);
+ if (binds == -1) {
+ lprintf("config: unhandled action \"%s\"\n", val);
+ return;
+ }
+
+ in_config_bind_key(dev_id, key, binds);
+/*
for (t = 0; t < 32; t++)
{
if (names[t] && strcmp(names[t], var) == 0) break;
binds[t] = 0;
keys_encountered |= 1<<t;
}
- if (val[0] == 0)
- return;
- if (strncasecmp(val, "player", 6) == 0)
- {
- player = atoi(val + 6) - 1;
- if (player > 1) goto fail;
- for (i = 0; i < sizeof(me_ctrl_actions) / sizeof(me_ctrl_actions[0]); i++) {
- if (strncasecmp(me_ctrl_actions[i].name, val + 8, strlen(val + 8)) == 0) {
- binds[t] |= me_ctrl_actions[i].mask | (player<<16);
- return;
- }
- }
- }
- for (i = 0; emuctrl_actions[i].name != NULL; i++) {
- if (strncasecmp(emuctrl_actions[i].name, val, strlen(val)) == 0) {
- binds[t] |= emuctrl_actions[i].mask;
- return;
- }
- }
-
-fail:
- lprintf("unhandled action \"%s\"\n", val);
- return;
+*/
}
} \
}
+static int get_numvar_num(const char *var)
+{
+ char *p = NULL;
+ int num;
+
+ if (var[0] == ' ')
+ return 0;
+
+ num = strtoul(var, &p, 10);
+ if (*p == 0 || *p == ' ')
+ return num;
+
+ return -1;
+}
+
+/* map dev number in confing to input dev number */
+static unsigned char input_dev_map[IN_MAX_DEVS];
+
static void parse(const char *var, const char *val)
{
menu_entry *me;
return;
}
+ /* input: device name */
+ if (strncasecmp(var, "input", 5) == 0) {
+ int num = get_numvar_num(var + 5);
+ if (num >= 0 && num < IN_MAX_DEVS)
+ input_dev_map[num] = in_config_parse_dev(val);
+ else
+ printf("failed to parse: %s\n", var);
+ return;
+ }
+
// key binds
- if (strncasecmp(var, "bind ", 5) == 0) {
- keys_parse(var + 5, val, currentConfig.KeyBinds, keyNames, PLAT_MAX_KEYS);
+ if (strncasecmp(var, "bind", 4) == 0) {
+ const char *p = var + 4;
+ int num = get_numvar_num(p);
+ if (num < 0 || num >= IN_MAX_DEVS) {
+ printf("failed to parse: %s\n", var);
+ return;
+ }
+
+ num = input_dev_map[num];
+ if (num < 0 || num >= IN_MAX_DEVS) {
+ printf("invalid device id: %s\n", var);
+ return;
+ }
+
+ while (*p && *p != ' ') p++;
+ while (*p && *p == ' ') p++;
+ keys_parse(p, val, num);
return;
}
-#if PLAT_HAVE_JOY
+
+#if 0//PLAT_HAVE_JOY
try_joy_parse(0)
try_joy_parse(1)
try_joy_parse(2)
}
keys_encountered = 0;
+ memset(input_dev_map, 0xff, sizeof(input_dev_map));
+ in_config_start();
while (!feof(f))
{
ret = config_get_var_val(f, line, sizeof(line), &var, &val);
parse(var, val);
}
+ in_config_end();
fclose(f);
return 0;
#include "../common/menu.h"\r
#include "../common/arm_utils.h"\r
#include "../common/readpng.h"\r
+#include "../common/common.h"\r
+#include "../common/input.h"\r
#include "version.h"\r
\r
#include <pico/pico_int.h>\r
void menu_darken_bg(void *dst, int pixels, int darker);\r
static void menu_prepare_bg(int use_game_bg);\r
\r
-static unsigned long inp_prev = 0;\r
-static int inp_prevjoy = 0;\r
-\r
-unsigned long wait_for_input(unsigned long interesting)\r
+/* wait for input, do autorepeat */\r
+int wait_for_input(int interesting)\r
{\r
- unsigned long ret;\r
+ static int inp_prev = 0;\r
static int repeats = 0, wait = 20;\r
- int release = 0, i;\r
+ int ret, release = 0, i;\r
\r
if (repeats == 2) wait = 3;\r
else if (repeats == 4) wait = 2;\r
else if (repeats == 6) wait = 1;\r
\r
- for (i = 0; i < wait && inp_prev == gp2x_joystick_read(1); i++) {\r
+ for (i = 0; i < wait; i++) {\r
+ ret = in_update_menu(30);\r
+ if (ret != inp_prev) break;\r
if (i == 0) repeats++;\r
- usleep(30000);\r
}\r
\r
- while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {\r
- usleep(50000);\r
+ while (!(ret & interesting)) {\r
+ ret = in_update_menu(0);\r
release = 1;\r
}\r
\r
repeats = 0;\r
wait = 20;\r
}\r
- if (wait > 6 && (ret&(GP2X_UP|GP2X_LEFT|GP2X_DOWN|GP2X_RIGHT|GP2X_L|GP2X_R)))\r
+ if (wait > 6 && (ret & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)))\r
wait = 6;\r
inp_prev = ret;\r
- inp_prevjoy = 0;\r
\r
// we don't need diagonals in menus\r
- if ((ret&GP2X_UP) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;\r
- if ((ret&GP2X_UP) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;\r
- if ((ret&GP2X_DOWN) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;\r
- if ((ret&GP2X_DOWN) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;\r
-\r
- return ret;\r
-}\r
-\r
-static unsigned long input2_read(unsigned long interesting, int *joy)\r
-{\r
- unsigned long ret;\r
- int i;\r
-\r
- do\r
- {\r
- *joy = 0;\r
- if ((ret = gp2x_joystick_read(0) & interesting)) break;\r
- usbjoy_update();\r
- for (i = 0; i < num_of_joys; i++) {\r
- ret = usbjoy_check2(i);\r
- if (ret) { *joy = i + 1; break; }\r
- }\r
- if (ret) break;\r
- }\r
- while(0);\r
-\r
- return ret;\r
-}\r
-\r
-// similar to wait_for_input(), but returns joy num\r
-static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)\r
-{\r
- unsigned long ret;\r
- const int wait = 300*1000;\r
- int i;\r
-\r
- if (inp_prevjoy == 0) inp_prev &= interesting;\r
- for (i = 0; i < 6; i++) {\r
- ret = input2_read(interesting, joy);\r
- if (*joy != inp_prevjoy || ret != inp_prev) break;\r
- usleep(wait/6);\r
- }\r
-\r
- while ( !(ret = input2_read(interesting, joy)) ) {\r
- usleep(50000);\r
- }\r
-\r
- inp_prev = ret;\r
- inp_prevjoy = *joy;\r
-\r
- // handle only 1 event at a time\r
- for (i = 1; i != 0; i <<= 1)\r
- if (ret & i) { ret &= i; break; }\r
- // ... but allow select\r
- ret |= inp_prev & GP2X_SELECT;\r
+ if ((ret & PBTN_UP) && (ret & PBTN_LEFT)) ret &= ~PBTN_LEFT;\r
+ if ((ret & PBTN_UP) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;\r
+ if ((ret & PBTN_DOWN) && (ret & PBTN_LEFT)) ret &= ~PBTN_LEFT;\r
+ if ((ret & PBTN_DOWN) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;\r
\r
return ret;\r
}\r
\r
static char *action_binds(int player_idx, int action_mask)\r
{\r
- static char strkeys[32*5];\r
- int joy, i;\r
+ static char strkeys[32];\r
+ int d, k, d_prev = -1;\r
\r
strkeys[0] = 0;\r
+\r
+ for (d = 0; d < IN_MAX_DEVS; d++)\r
+ {\r
+ const int *binds;\r
+ int count;\r
+\r
+ binds = in_get_dev_binds(d);\r
+ if (binds == NULL)\r
+ continue;\r
+\r
+ count = in_get_dev_bind_count(d);\r
+ for (k = 0; k < count; k++)\r
+ {\r
+ const char *xname;\r
+ char prefix[16];\r
+ if (!(binds[k] & action_mask))\r
+ continue;\r
+\r
+ if (player_idx >= 0 && ((binds[k] >> 16) & 3) != player_idx)\r
+ continue;\r
+\r
+ xname = in_get_key_name(d, k);\r
+ if (strkeys[0])\r
+ strncat(strkeys, d == d_prev ? " + " : ", ", sizeof(strkeys));\r
+ if (d) sprintf(prefix, "%d: ", d);\r
+ if (d) strncat(strkeys, prefix, sizeof(strkeys));\r
+ strncat(strkeys, xname, sizeof(strkeys));\r
+ d_prev = d;\r
+ }\r
+ }\r
+#if 0\r
for (i = 0; i < 32; i++) // i is key index\r
{\r
if (currentConfig.KeyBinds[i] & action_mask)\r
}\r
}\r
}\r
+#endif\r
+\r
\r
// limit..\r
strkeys[20] = 0;\r
}\r
}\r
\r
-static int count_bound_keys(int action, int pl_idx, int joy)\r
+static int count_bound_keys(int dev_id, int action_mask, int player_idx)\r
{\r
- int i, keys = 0;\r
+ const int *binds;\r
+ int k, keys = 0;\r
+ int count;\r
\r
- if (joy)\r
- {\r
- for (i = 0; i < 32; i++) {\r
- if (pl_idx >= 0 && (currentConfig.JoyBinds[joy-1][i]&0x30000) != (pl_idx<<16)) continue;\r
- if (currentConfig.JoyBinds[joy-1][i] & action) keys++;\r
- }\r
- }\r
- else\r
+ binds = in_get_dev_binds(dev_id);\r
+ if (binds == NULL)\r
+ return 0;\r
+\r
+ count = in_get_dev_bind_count(dev_id);\r
+ for (k = 0; k < count; k++)\r
{\r
- for (i = 0; i < 32; i++) {\r
- if (pl_idx >= 0 && (currentConfig.KeyBinds[i]&0x30000) != (pl_idx<<16)) continue;\r
- if (currentConfig.KeyBinds[i] & action) keys++;\r
- }\r
+ if (!(binds[k] & action_mask))\r
+ continue;\r
+\r
+ if (player_idx >= 0 && ((binds[k] >> 16) & 3) != player_idx)\r
+ continue;\r
+\r
+ keys++;\r
}\r
+\r
return keys;\r
}\r
\r
-static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx, int sel)\r
+static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx,\r
+ int sel, int is_bind)\r
{\r
int x, y, tl_y = 30, i;\r
\r
text_out16(x, y, "Done");\r
\r
if (sel < opt_cnt) {\r
- text_out16(30, 195, "Press a button to bind/unbind");\r
- text_out16(30, 205, "Use SELECT to clear");\r
- text_out16(30, 215, "To bind UP/DOWN, hold SELECT");\r
+ text_out16(30, 205, is_bind ? "Press a button to bind/unbind" : "Press B to define");\r
text_out16(30, 225, "Select \"Done\" to exit");\r
} else {\r
text_out16(30, 205, "Use Options -> Save cfg");\r
\r
static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)\r
{\r
- int joy = 0, sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i;\r
- unsigned long inp = 0;\r
+ int sel = 0, menu_sel_max = opt_cnt;\r
+ int kc, dev_id, is_down, mkey, unbind;\r
\r
for (;;)\r
{\r
- draw_key_config(opts, opt_cnt, player_idx, sel);\r
- inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);\r
- // printf("got %08lX from joy %i\n", inp, joy);\r
- if (joy == 0)\r
- {\r
- if (!(inp & GP2X_SELECT)) {\r
- prev_select = 0;\r
- if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }\r
- if(inp & GP2X_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }\r
- }\r
- if (sel >= opt_cnt) {\r
- if (inp & (GP2X_B|GP2X_X)) break;\r
- else continue;\r
- }\r
- // if we are here, we want to bind/unbind something\r
- if ((inp & GP2X_SELECT) && !prev_select)\r
- unbind_action(opts[sel].mask, player_idx, -1);\r
- prev_select = inp & GP2X_SELECT;\r
- inp &= CONFIGURABLE_KEYS;\r
- inp &= ~GP2X_SELECT;\r
- for (i = 0; i < 32; i++)\r
- if (inp & (1 << i)) {\r
- if (count_bound_keys(opts[sel].mask, player_idx, 0) >= 2)\r
- currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only\r
- else currentConfig.KeyBinds[i] ^= opts[sel].mask;\r
- if (player_idx >= 0 && (currentConfig.KeyBinds[i] & opts[sel].mask)) {\r
- currentConfig.KeyBinds[i] &= ~(3 << 16);\r
- currentConfig.KeyBinds[i] |= player_idx << 16;\r
- }\r
- }\r
+ draw_key_config(opts, opt_cnt, player_idx, sel, 0);\r
+ mkey = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_SOUTH|PBTN_EAST);\r
+ switch (mkey) {\r
+ case PBTN_UP: sel--; if (sel < 0) sel = menu_sel_max; continue;\r
+ case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue;\r
+ case PBTN_SOUTH:\r
+ if (sel >= opt_cnt)\r
+ return;\r
+ continue;\r
+ case PBTN_EAST:\r
+ if (sel >= opt_cnt)\r
+ return;\r
+ break;\r
+ default:continue;\r
}\r
- else if (sel < opt_cnt)\r
- {\r
- for (i = 0; i < 32; i++)\r
- if (inp & (1 << i)) {\r
- int *bind = ¤tConfig.JoyBinds[joy-1][i];\r
- if ((*bind & opts[sel].mask) && (player_idx < 0 || player_idx == ((*bind>>16)&3)))\r
- *bind &= ~opts[sel].mask;\r
- else {\r
- // override\r
- unbind_action(opts[sel].mask, player_idx, joy);\r
- *bind = opts[sel].mask;\r
- if (player_idx > 0) *bind |= player_idx << 16;\r
- }\r
- }\r
+\r
+ draw_key_config(opts, opt_cnt, player_idx, sel, 1);\r
+ //inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);\r
+ for (is_down = 0; is_down == 0; )\r
+ kc = in_update_keycode(&dev_id, &is_down, 0);\r
+\r
+ unbind = count_bound_keys(dev_id, opts[sel].mask, player_idx) >= 2;\r
+\r
+ in_bind_key(dev_id, kc, opts[sel].mask, unbind);\r
+ if (player_idx >= 0) {\r
+ /* FIXME */\r
+ in_bind_key(dev_id, kc, 3 << 16, 1);\r
+ in_bind_key(dev_id, kc, player_idx << 16, 0);\r
}\r
}\r
}\r
\r
void menu_loop(void)\r
{\r
+ in_set_blocking(1);\r
menu_gfx_prepare();\r
\r
menu_loop_root();\r
\r
+ in_set_blocking(0);\r
menuErrorMsg[0] = 0;\r
}\r
\r