From ad439e71e25f709a1e2b6f72f36119432593f34a Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 12 Feb 2011 23:47:53 +0200 Subject: [PATCH] loader: try to make input generic, with caanoo support --- loader/Makefile | 5 ++-- loader/header.h | 1 + loader/host.c | 51 ++++++++++++++++++++++++++++++++++++++++ loader/host_pnd.c | 28 +++++++++++++++++++++- loader/host_wiz.c | 59 ++++++++++++++++++++++++++++++++++++++++++----- 5 files changed, 134 insertions(+), 10 deletions(-) create mode 100644 loader/host.c diff --git a/loader/Makefile b/loader/Makefile index e42d2b2..ad0f9ef 100644 --- a/loader/Makefile +++ b/loader/Makefile @@ -24,12 +24,11 @@ OBJ += sys_cacheflush.o emu_arm.o endif ifdef PND CFLAGS += -DPND -OBJ += host_pnd.o TAG = _pnd endif ifdef WIZ CFLAGS += -DWIZ -OBJ += host_wiz.o wiz_video_arm.o +OBJ += wiz_video_arm.o TAG = _wiz endif @@ -39,7 +38,7 @@ vpath %.s = ../common/ TARGET_S = ginge_sloader$(TAG) TARGET_D = ginge_dyn$(TAG) -OBJ += emu.o host_fb.o cmn.o +OBJ += emu.o host.o host_fb.o cmn.o OBJ_S += $(OBJ) loader.o loader_$(ARCH).o patches.o OBJ_D += $(OBJ) dl.o diff --git a/loader/header.h b/loader/header.h index 58ef4d9..b5241f6 100644 --- a/loader/header.h +++ b/loader/header.h @@ -50,6 +50,7 @@ int emu_do_execve(const char *filename, char *const argv[], char *const envp[] int host_init(void); int host_read_btns(void); +void host_forced_exit(void); enum { GP2X_UP = 0, GP2X_LEFT = 2, GP2X_DOWN = 4, GP2X_RIGHT = 6, GP2X_START = 8, GP2X_SELECT = 9, GP2X_L = 10, GP2X_R = 11, diff --git a/loader/host.c b/loader/host.c new file mode 100644 index 0000000..9663964 --- /dev/null +++ b/loader/host.c @@ -0,0 +1,51 @@ +// vim:shiftwidth=2:expandtab + +#define _GNU_SOURCE // for plat.c +#include +#include + +#include "header.h" +#include "realfuncs.h" + +#define IN_EVDEV +#include "../common/common/input.c" +#include "../common/linux/plat.c" +#include "../common/linux/in_evdev.c" + +#ifdef PND +#include "host_pnd.c" +#elif defined(WIZ) +#include "host_wiz.c" +#endif + +// for plat.c +char **g_argv; + +int host_init(void) +{ + in_init(); + in_probe(); + + return 0; +} + +int host_read_btns(void) +{ + int actions[IN_BINDTYPE_COUNT] = { 0, }; + + in_update(actions); + host_actions(actions); + + return actions[IN_BINDTYPE_PLAYER12]; +} + +void host_forced_exit(void) +{ + // exit() might not be enough because loader and app data is out of sync, + // and other threads (which are really processes on this old glibc used) + // might not exit properly. + system("killall ginge_sloader"); + usleep(300000); + system("killall -9 ginge_sloader"); + exit(1); +} diff --git a/loader/host_pnd.c b/loader/host_pnd.c index 32fe95a..f52896d 100644 --- a/loader/host_pnd.c +++ b/loader/host_pnd.c @@ -1,4 +1,30 @@ // vim:shiftwidth=2:expandtab + +struct in_default_bind in_evdev_defbinds[] = { + { KEY_UP, IN_BINDTYPE_PLAYER12, GP2X_UP }, + { KEY_PAGEUP, IN_BINDTYPE_PLAYER12, GP2X_Y }, + { KEY_END, IN_BINDTYPE_PLAYER12, GP2X_B }, + { KEY_PAGEDOWN, IN_BINDTYPE_PLAYER12, GP2X_X }, + { KEY_HOME, IN_BINDTYPE_PLAYER12, GP2X_A }, + { KEY_RIGHTSHIFT, IN_BINDTYPE_PLAYER12, GP2X_L }, + { KEY_RIGHTCTRL, IN_BINDTYPE_PLAYER12, GP2X_R }, + { KEY_LEFTALT, IN_BINDTYPE_PLAYER12, GP2X_START }, + { KEY_LEFTCTRL, IN_BINDTYPE_PLAYER12, GP2X_SELECT }, + { KEY_COMMA, IN_BINDTYPE_PLAYER12, GP2X_VOL_DOWN }, + { KEY_DOT, IN_BINDTYPE_PLAYER12, GP2X_VOL_UP }, + { KEY_1, IN_BINDTYPE_PLAYER12, GP2X_PUSH }, + { KEY_Q, IN_BINDTYPE_EMU, 0 }, + { 0, 0, 0 }, +}; + +static void host_actions(int actions[IN_BINDTYPE_COUNT]) +{ + if (actions[IN_BINDTYPE_EMU] & 1) + host_forced_exit(); +} + +// todo: rm when generic code works +#if 0 #define _GNU_SOURCE #include #include @@ -125,4 +151,4 @@ int host_read_btns(void) return keystate; } - +#endif diff --git a/loader/host_wiz.c b/loader/host_wiz.c index dccd841..59b5dec 100644 --- a/loader/host_wiz.c +++ b/loader/host_wiz.c @@ -4,13 +4,35 @@ #include #include #include - -#include "header.h" -#include "../common/warm.h" -#include "realfuncs.h" - +#include + +#include "../common/warm/warm.h" + +extern int memdev, probably_caanoo; // leasing from wiz_video + +#define BTN_JOY BTN_JOYSTICK + +struct in_default_bind in_evdev_defbinds[] = { + { KEY_UP, IN_BINDTYPE_PLAYER12, GP2X_UP }, + { KEY_DOWN, IN_BINDTYPE_PLAYER12, GP2X_DOWN }, + { KEY_LEFT, IN_BINDTYPE_PLAYER12, GP2X_LEFT }, + { KEY_RIGHT, IN_BINDTYPE_PLAYER12, GP2X_RIGHT }, + { BTN_JOY + 0, IN_BINDTYPE_PLAYER12, GP2X_A }, + { BTN_JOY + 1, IN_BINDTYPE_PLAYER12, GP2X_X }, + { BTN_JOY + 2, IN_BINDTYPE_PLAYER12, GP2X_B }, + { BTN_JOY + 3, IN_BINDTYPE_PLAYER12, GP2X_Y }, + { BTN_JOY + 4, IN_BINDTYPE_PLAYER12, GP2X_L }, + { BTN_JOY + 5, IN_BINDTYPE_PLAYER12, GP2X_R }, + { BTN_JOY + 8, IN_BINDTYPE_PLAYER12, GP2X_START }, + { BTN_JOY + 9, IN_BINDTYPE_PLAYER12, GP2X_SELECT }, + { BTN_JOY + 10, IN_BINDTYPE_PLAYER12, GP2X_PUSH }, + { BTN_JOY + 6, IN_BINDTYPE_EMU, 0 }, + { 0, 0, 0 } +}; + +// todo: rm when generic code works on Wiz +#if 0 static int gpiodev = -1; -extern int memdev; // leasing from wiz_video int host_init(void) { @@ -37,12 +59,19 @@ int host_read_btns(void) return value; } +#endif void *host_mmap_upper(void) { void *ret; int r; + // make sure this never happens on Caanoo + if (probably_caanoo) { + err("Wiz mmap code called on Caanoo?"); + return MAP_FAILED; + } + // Wiz GP2X // 03460000-03ffffff 00ba0000 // 02aa0000-02dfffff 03100000-0345ffff 00360000 @@ -81,3 +110,21 @@ fail: exit(1); } +static void host_actions(int actions[IN_BINDTYPE_COUNT]) +{ + if (probably_caanoo && (actions[IN_BINDTYPE_EMU] & 1)) { + // 'home key as Fn' handling + int act = actions[IN_BINDTYPE_PLAYER12]; + if (act & (1 << GP2X_START)) { + act &= ~(1 << GP2X_START); + act |= 1 << GP2X_VOL_UP; + } + if (act & (1 << GP2X_SELECT)) { + act &= ~(1 << GP2X_SELECT); + act |= 1 << GP2X_VOL_DOWN; + } + if (act & (1 << GP2X_Y)) + host_forced_exit(); + actions[IN_BINDTYPE_PLAYER12] = act; + } +} -- 2.39.5