From: notaz Date: Mon, 23 Apr 2012 22:48:17 +0000 (+0300) Subject: frontend: input: pass default binds as argument X-Git-Tag: r15~49 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b07c18e8645a17be916266820ae564e0d320cc1a;p=pcsx_rearmed.git frontend: input: pass default binds as argument allows to get rid of some hacks --- diff --git a/frontend/common/in_sdl.c b/frontend/common/in_sdl.c index 27c183b1..ed136105 100644 --- a/frontend/common/in_sdl.c +++ b/frontend/common/in_sdl.c @@ -302,8 +302,8 @@ static const in_drv_t in_sdl_drv = { .menu_translate = in_sdl_menu_translate, }; -void in_sdl_init(void) +void in_sdl_init(const struct in_default_bind *defbinds) { - in_register_driver(&in_sdl_drv); + in_register_driver(&in_sdl_drv, defbinds); } diff --git a/frontend/common/in_sdl.h b/frontend/common/in_sdl.h index 9c9d4065..47f7a832 100644 --- a/frontend/common/in_sdl.h +++ b/frontend/common/in_sdl.h @@ -1 +1,3 @@ -void in_sdl_init(void); +struct in_default_bind; + +void in_sdl_init(const struct in_default_bind *defbinds); diff --git a/frontend/common/input.c b/frontend/common/input.c index 0b1984bd..2f8a8673 100644 --- a/frontend/common/input.c +++ b/frontend/common/input.c @@ -52,15 +52,27 @@ static int menu_last_used_dev = 0; static int *in_alloc_binds(int drv_id, int key_count) { + const struct in_default_bind *defbinds; int *binds; + int i; binds = calloc(key_count * IN_BINDTYPE_COUNT * 2, sizeof(binds[0])); if (binds == NULL) return NULL; - DRV(drv_id).get_def_binds(binds + key_count * IN_BINDTYPE_COUNT); - memcpy(binds, binds + key_count * IN_BINDTYPE_COUNT, - sizeof(binds[0]) * key_count * IN_BINDTYPE_COUNT); + defbinds = DRV(drv_id).defbinds; + if (defbinds != NULL) { + for (i = 0; ; i++) { + if (defbinds[i].bit == 0 && defbinds[i].code == 0) + break; + binds[IN_BIND_OFFS(defbinds[i].code, defbinds[i].btype)] = + 1 << defbinds[i].bit; + } + + /* always have a copy of defbinds */ + memcpy(binds + key_count * IN_BINDTYPE_COUNT, binds, + sizeof(binds[0]) * key_count * IN_BINDTYPE_COUNT); + } return binds; } @@ -891,7 +903,6 @@ void in_debug_dump(void) /* stubs for drivers that choose not to implement something */ static void in_def_free(void *drv_data) {} -static void in_def_get_def_binds(int *binds) {} static int in_def_clean_binds(void *drv_data, int *b, int *db) { return 1; } static int in_def_get_config(void *drv_data, int what, int *val) { return -1; } static int in_def_set_config(void *drv_data, int what, int val) { return -1; } @@ -905,7 +916,7 @@ static const char *in_def_get_key_name(int keycode) { return NULL; } if (d.f == NULL) d.f = in_def_##f /* to be called by drivers */ -int in_register_driver(const in_drv_t *drv) +int in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbinds) { int count_new = in_driver_count + 1; in_drv_t *new_drivers; @@ -919,7 +930,6 @@ int in_register_driver(const in_drv_t *drv) memcpy(&new_drivers[in_driver_count], drv, sizeof(new_drivers[0])); CHECK_ADD_STUB(new_drivers[in_driver_count], free); - CHECK_ADD_STUB(new_drivers[in_driver_count], get_def_binds); CHECK_ADD_STUB(new_drivers[in_driver_count], clean_binds); CHECK_ADD_STUB(new_drivers[in_driver_count], get_config); CHECK_ADD_STUB(new_drivers[in_driver_count], set_config); @@ -928,6 +938,8 @@ int in_register_driver(const in_drv_t *drv) CHECK_ADD_STUB(new_drivers[in_driver_count], menu_translate); CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_code); CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_name); + if (defbinds != NULL) + new_drivers[in_driver_count].defbinds = defbinds; in_drivers = new_drivers; in_driver_count = count_new; diff --git a/frontend/common/input.h b/frontend/common/input.h index 524366f2..1f904250 100644 --- a/frontend/common/input.h +++ b/frontend/common/input.h @@ -79,7 +79,6 @@ typedef struct { void (*free)(void *drv_data); const char * const * (*get_key_names)(int *count); - void (*get_def_binds)(int *binds); int (*clean_binds)(void *drv_data, int *binds, int *def_finds); int (*get_config)(void *drv_data, int what, int *val); int (*set_config)(void *drv_data, int what, int val); @@ -90,6 +89,8 @@ typedef struct { int (*menu_translate)(void *drv_data, int keycode); int (*get_key_code)(const char *key_name); const char * (*get_key_name)(int keycode); + + const struct in_default_bind *defbinds; } in_drv_t; struct in_default_bind { @@ -99,7 +100,7 @@ struct in_default_bind { }; /* to be called by drivers */ -int in_register_driver(const in_drv_t *drv); +int in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbinds); void in_register(const char *nname, int drv_fd_hnd, void *drv_data, int key_count, const char * const *key_names, int combos); void in_combos_find(const int *binds, int last_key, int *combo_keys, int *combo_acts); diff --git a/frontend/gp2x/in_gp2x.c b/frontend/gp2x/in_gp2x.c index b750e688..196f1218 100644 --- a/frontend/gp2x/in_gp2x.c +++ b/frontend/gp2x/in_gp2x.c @@ -244,18 +244,6 @@ static const struct { }; #endif -static void in_gp2x_get_def_binds(int *binds) -{ - int i; - - for (i = 0; 1; i++) { - if (in_gp2x_defbinds[i].bit == 0 && in_gp2x_defbinds[i].code == 0) - break; - binds[IN_BIND_OFFS(in_gp2x_defbinds[i].code, in_gp2x_defbinds[i].btype)] = - 1 << in_gp2x_defbinds[i].bit; - } -} - /* remove binds of missing keys, count remaining ones */ static int in_gp2x_clean_binds(void *drv_data, int *binds, int *def_binds) { @@ -305,20 +293,19 @@ static const in_drv_t in_gp2x_drv = { .probe = in_gp2x_probe, .free = in_gp2x_free, .get_key_names = in_gp2x_get_key_names, - .get_def_binds = in_gp2x_get_def_binds, .clean_binds = in_gp2x_clean_binds, .update = in_gp2x_update, .update_keycode = in_gp2x_update_keycode, .menu_translate = in_gp2x_menu_translate, }; -void in_gp2x_init(void) +void in_gp2x_init(const struct in_default_bind *defbinds) { if (gp2x_dev_id == GP2X_DEV_WIZ) in_gp2x_keys[GP2X_BTN_START] = "MENU"; in_gp2x_combo_keys = in_gp2x_combo_acts = 0; - in_register_driver(&in_gp2x_drv); + in_register_driver(&in_gp2x_drv, defbinds); } diff --git a/frontend/gp2x/in_gp2x.h b/frontend/gp2x/in_gp2x.h index 6428a63a..035cdedc 100644 --- a/frontend/gp2x/in_gp2x.h +++ b/frontend/gp2x/in_gp2x.h @@ -1,8 +1,7 @@ -void in_gp2x_init(void); +struct in_default_bind; -/* to be set somewhere in platform code */ -extern struct in_default_bind in_gp2x_defbinds[]; +void in_gp2x_init(const struct in_default_bind *defbinds); enum { GP2X_BTN_UP = 0, GP2X_BTN_LEFT = 2, GP2X_BTN_DOWN = 4, GP2X_BTN_RIGHT = 6, GP2X_BTN_START = 8, GP2X_BTN_SELECT = 9, GP2X_BTN_L = 10, GP2X_BTN_R = 11, diff --git a/frontend/in_tsbutton.c b/frontend/in_tsbutton.c index 84d6895c..80c9c585 100644 --- a/frontend/in_tsbutton.c +++ b/frontend/in_tsbutton.c @@ -133,6 +133,6 @@ static const in_drv_t in_tsbutton_drv = { void in_tsbutton_init(void) { tsbutton_down_id = last_tsbutton_id = -1; - in_register_driver(&in_tsbutton_drv); + in_register_driver(&in_tsbutton_drv, NULL); } diff --git a/frontend/linux/in_evdev.c b/frontend/linux/in_evdev.c index 23d2e2a3..c6150612 100644 --- a/frontend/linux/in_evdev.c +++ b/frontend/linux/in_evdev.c @@ -586,18 +586,6 @@ static int in_evdev_menu_translate(void *drv_data, int keycode) return 0; } -static void in_evdev_get_def_binds(int *binds) -{ - int i; - - for (i = 0; ; i++) { - if (in_evdev_defbinds[i].bit == 0 && in_evdev_defbinds[i].code == 0) - break; - binds[IN_BIND_OFFS(in_evdev_defbinds[i].code, in_evdev_defbinds[i].btype)] = - 1 << in_evdev_defbinds[i].bit; - } -} - /* remove binds of missing keys, count remaining ones */ static int in_evdev_clean_binds(void *drv_data, int *binds, int *def_binds) { @@ -637,7 +625,6 @@ static const in_drv_t in_evdev_drv = { .probe = in_evdev_probe, .free = in_evdev_free, .get_key_names = in_evdev_get_key_names, - .get_def_binds = in_evdev_get_def_binds, .clean_binds = in_evdev_clean_binds, .get_config = in_evdev_get_config, .set_config = in_evdev_set_config, @@ -647,8 +634,8 @@ static const in_drv_t in_evdev_drv = { .menu_translate = in_evdev_menu_translate, }; -void in_evdev_init(void) +void in_evdev_init(const struct in_default_bind *defbinds) { - in_register_driver(&in_evdev_drv); + in_register_driver(&in_evdev_drv, defbinds); } diff --git a/frontend/linux/in_evdev.h b/frontend/linux/in_evdev.h index 6141b2b4..c5aef9bb 100644 --- a/frontend/linux/in_evdev.h +++ b/frontend/linux/in_evdev.h @@ -1,7 +1,5 @@ +struct in_default_bind; extern int in_evdev_allow_abs_only; -void in_evdev_init(void); - -/* to be set somewhere in platform code */ -extern struct in_default_bind in_evdev_defbinds[]; +void in_evdev_init(const struct in_default_bind *defbinds); diff --git a/frontend/main.c b/frontend/main.c index d3df7147..dc5be3cf 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -364,9 +364,9 @@ int main(int argc, char *argv[]) return 1; // frontend stuff + // init input but leave probing to platform code, + // they add input drivers and may need to modify them after probe in_init(); - in_evdev_init(); - //in_probe(); pl_init(); plat_init(); menu_init(); // loads config diff --git a/frontend/plat_dummy.c b/frontend/plat_dummy.c index 9a325498..26cd3a22 100644 --- a/frontend/plat_dummy.c +++ b/frontend/plat_dummy.c @@ -5,13 +5,8 @@ * See the COPYING file in the top-level directory. */ -#include "common/input.h" #include "plat.h" -struct in_default_bind in_evdev_defbinds[] = { - { 0, 0, 0 }, -}; - void plat_video_menu_enter(int is_rom_loaded) { } diff --git a/frontend/plat_pandora.c b/frontend/plat_pandora.c index 1c079243..2522b0b0 100644 --- a/frontend/plat_pandora.c +++ b/frontend/plat_pandora.c @@ -38,7 +38,7 @@ static const char * const pandora_gpio_keys[KEY_MAX + 1] = { [KEY_MENU] = "Pandora", }; -struct in_default_bind in_evdev_defbinds[] = { +static const struct in_default_bind in_evdev_defbinds[] = { { KEY_UP, IN_BINDTYPE_PLAYER12, DKEY_UP }, { KEY_DOWN, IN_BINDTYPE_PLAYER12, DKEY_DOWN }, { KEY_LEFT, IN_BINDTYPE_PLAYER12, DKEY_LEFT }, @@ -66,6 +66,7 @@ struct in_default_bind in_evdev_defbinds[] = { int plat_pandora_init(void) { + in_evdev_init(in_evdev_defbinds); in_probe(); in_set_config(in_name_to_id("evdev:gpio-keys"), IN_CFG_KEY_NAMES, pandora_gpio_keys, sizeof(pandora_gpio_keys)); diff --git a/frontend/plat_pollux.c b/frontend/plat_pollux.c index 3cf3a9b1..80e7a1b8 100644 --- a/frontend/plat_pollux.c +++ b/frontend/plat_pollux.c @@ -16,9 +16,11 @@ #include #include #include +#include #include "common/input.h" #include "gp2x/in_gp2x.h" +#include "linux/in_evdev.h" #include "common/menu.h" #include "warm/warm.h" #include "plugin_lib.h" @@ -50,7 +52,25 @@ static int psx_offset_x, psx_offset_y, psx_src_width, psx_src_height; static int fb_offset_x, fb_offset_y; static void caanoo_init(void); +static void wiz_init(void); + +static const struct in_default_bind in_evdev_defbinds[] = { + { KEY_UP, IN_BINDTYPE_PLAYER12, DKEY_UP }, + { KEY_DOWN, IN_BINDTYPE_PLAYER12, DKEY_DOWN }, + { KEY_LEFT, IN_BINDTYPE_PLAYER12, DKEY_LEFT }, + { KEY_RIGHT, IN_BINDTYPE_PLAYER12, DKEY_RIGHT }, + { BTN_TOP, IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE }, + { BTN_THUMB, IN_BINDTYPE_PLAYER12, DKEY_CROSS }, + { BTN_THUMB2, IN_BINDTYPE_PLAYER12, DKEY_CIRCLE }, + { BTN_TRIGGER, IN_BINDTYPE_PLAYER12, DKEY_SQUARE }, + { BTN_BASE3, IN_BINDTYPE_PLAYER12, DKEY_START }, + { BTN_BASE4, IN_BINDTYPE_PLAYER12, DKEY_SELECT }, + { BTN_TOP2, IN_BINDTYPE_PLAYER12, DKEY_L1 }, + { BTN_PINKIE, IN_BINDTYPE_PLAYER12, DKEY_R1 }, + { BTN_BASE, IN_BINDTYPE_EMU, SACTION_ENTER_MENU }, + { 0, 0, 0 }, +}; static void *fb_flip(void) { @@ -587,13 +607,14 @@ void plat_init(void) else { printf("detected Wiz\n"); gp2x_dev_id = GP2X_DEV_WIZ; - in_gp2x_init(); } in_tsbutton_init(); - in_probe(); + in_evdev_init(in_evdev_defbinds); if (gp2x_dev_id == GP2X_DEV_CAANOO) caanoo_init(); + else + wiz_init(); mixerdev = open("/dev/mixer", O_RDWR); if (mixerdev == -1) @@ -632,25 +653,6 @@ void plat_finish(void) } /* Caanoo stuff, perhaps move later */ -#include - -struct in_default_bind in_evdev_defbinds[] = { - { KEY_UP, IN_BINDTYPE_PLAYER12, DKEY_UP }, - { KEY_DOWN, IN_BINDTYPE_PLAYER12, DKEY_DOWN }, - { KEY_LEFT, IN_BINDTYPE_PLAYER12, DKEY_LEFT }, - { KEY_RIGHT, IN_BINDTYPE_PLAYER12, DKEY_RIGHT }, - { BTN_TOP, IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE }, - { BTN_THUMB, IN_BINDTYPE_PLAYER12, DKEY_CROSS }, - { BTN_THUMB2, IN_BINDTYPE_PLAYER12, DKEY_CIRCLE }, - { BTN_TRIGGER, IN_BINDTYPE_PLAYER12, DKEY_SQUARE }, - { BTN_BASE3, IN_BINDTYPE_PLAYER12, DKEY_START }, - { BTN_BASE4, IN_BINDTYPE_PLAYER12, DKEY_SELECT }, - { BTN_TOP2, IN_BINDTYPE_PLAYER12, DKEY_L1 }, - { BTN_PINKIE, IN_BINDTYPE_PLAYER12, DKEY_R1 }, - { BTN_BASE, IN_BINDTYPE_EMU, SACTION_ENTER_MENU }, - { 0, 0, 0 }, -}; - static const char * const caanoo_keys[KEY_MAX + 1] = { [0 ... KEY_MAX] = NULL, [KEY_UP] = "Up", @@ -776,8 +778,15 @@ void plat_trigger_vibrate(int is_strong) ioctl(hapticdev, HAPTIC_PLAY_PATTERN, &haptic_seq[!!is_strong]); } +static void caanoo_init(void) +{ + in_probe(); + in_set_config(in_name_to_id("evdev:pollux-analog"), IN_CFG_KEY_NAMES, + caanoo_keys, sizeof(caanoo_keys)); +} + /* Wiz stuff */ -struct in_default_bind in_gp2x_defbinds[] = +static const struct in_default_bind in_gp2x_defbinds[] = { /* MXYZ SACB RLDU */ { GP2X_BTN_UP, IN_BINDTYPE_PLAYER12, DKEY_UP }, @@ -824,8 +833,8 @@ void plat_step_volume(int is_up) // unused dummy for in_gp2x volatile unsigned short *gp2x_memregs; -static void caanoo_init(void) +static void wiz_init(void) { - in_set_config(in_name_to_id("evdev:pollux-analog"), IN_CFG_KEY_NAMES, - caanoo_keys, sizeof(caanoo_keys)); + in_gp2x_init(in_gp2x_defbinds); + in_probe(); } diff --git a/frontend/plat_sdl.c b/frontend/plat_sdl.c index 015450d8..19d7ac07 100644 --- a/frontend/plat_sdl.c +++ b/frontend/plat_sdl.c @@ -13,11 +13,27 @@ #include "common/input.h" #include "common/in_sdl.h" #include "common/menu.h" +#include "plugin_lib.h" +#include "main.h" #include "plat.h" #include "revision.h" -// XXX -struct in_default_bind in_evdev_defbinds[] = { +static const struct in_default_bind in_sdl_defbinds[] = { + { SDLK_UP, IN_BINDTYPE_PLAYER12, DKEY_UP }, + { SDLK_DOWN, IN_BINDTYPE_PLAYER12, DKEY_DOWN }, + { SDLK_LEFT, IN_BINDTYPE_PLAYER12, DKEY_LEFT }, + { SDLK_RIGHT, IN_BINDTYPE_PLAYER12, DKEY_RIGHT }, + { SDLK_d, IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE }, + { SDLK_z, IN_BINDTYPE_PLAYER12, DKEY_CROSS }, + { SDLK_x, IN_BINDTYPE_PLAYER12, DKEY_CIRCLE }, + { SDLK_s, IN_BINDTYPE_PLAYER12, DKEY_SQUARE }, + { SDLK_v, IN_BINDTYPE_PLAYER12, DKEY_START }, + { SDLK_c, IN_BINDTYPE_PLAYER12, DKEY_SELECT }, + { SDLK_w, IN_BINDTYPE_PLAYER12, DKEY_L1 }, + { SDLK_r, IN_BINDTYPE_PLAYER12, DKEY_R1 }, + { SDLK_e, IN_BINDTYPE_PLAYER12, DKEY_L2 }, + { SDLK_t, IN_BINDTYPE_PLAYER12, DKEY_R2 }, + { SDLK_ESCAPE, IN_BINDTYPE_EMU, SACTION_ENTER_MENU }, { 0, 0, 0 } }; @@ -62,7 +78,7 @@ void plat_init(void) } SDL_WM_SetCaption("PCSX-ReARMed " REV, NULL); - in_sdl_init(); + in_sdl_init(in_sdl_defbinds); in_probe(); return;