loader: try to make input generic, with caanoo support
authornotaz <notaz@pixelinis>
Sat, 12 Feb 2011 21:47:53 +0000 (23:47 +0200)
committernotaz <notaz@pixelinis>
Sat, 12 Feb 2011 21:47:53 +0000 (23:47 +0200)
loader/Makefile
loader/header.h
loader/host.c [new file with mode: 0644]
loader/host_pnd.c
loader/host_wiz.c

index e42d2b2..ad0f9ef 100644 (file)
@@ -24,12 +24,11 @@ OBJ += sys_cacheflush.o emu_arm.o
 endif
 ifdef PND
 CFLAGS += -DPND
 endif
 ifdef PND
 CFLAGS += -DPND
-OBJ += host_pnd.o
 TAG = _pnd
 endif
 ifdef WIZ
 CFLAGS += -DWIZ
 TAG = _pnd
 endif
 ifdef WIZ
 CFLAGS += -DWIZ
-OBJ += host_wiz.o wiz_video_arm.o
+OBJ += wiz_video_arm.o
 TAG = _wiz
 endif
 
 TAG = _wiz
 endif
 
@@ -39,7 +38,7 @@ vpath %.s = ../common/
 TARGET_S = ginge_sloader$(TAG)
 TARGET_D = ginge_dyn$(TAG)
 
 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
 
 OBJ_S += $(OBJ) loader.o loader_$(ARCH).o patches.o
 OBJ_D += $(OBJ) dl.o
 
index 58ef4d9..b5241f6 100644 (file)
@@ -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);
 
 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,
 
 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 (file)
index 0000000..9663964
--- /dev/null
@@ -0,0 +1,51 @@
+// vim:shiftwidth=2:expandtab
+
+#define _GNU_SOURCE // for plat.c
+#include <stdio.h>
+#include <stdarg.h>
+
+#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);
+}
index 32fe95a..f52896d 100644 (file)
@@ -1,4 +1,30 @@
 // vim:shiftwidth=2:expandtab
 // 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 <stdio.h>
 #include <string.h>
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <string.h>
@@ -125,4 +151,4 @@ int host_read_btns(void)
 
   return keystate;
 }
 
   return keystate;
 }
-
+#endif
index dccd841..59b5dec 100644 (file)
@@ -4,13 +4,35 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/mman.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/mman.h>
-
-#include "header.h"
-#include "../common/warm.h"
-#include "realfuncs.h"
-
+#include <linux/input.h>
+
+#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;
 static int gpiodev = -1;
-extern int memdev; // leasing from wiz_video
 
 int host_init(void)
 {
 
 int host_init(void)
 {
@@ -37,12 +59,19 @@ int host_read_btns(void)
 
   return value;
 }
 
   return value;
 }
+#endif
 
 void *host_mmap_upper(void)
 {
   void *ret;
   int r;
 
 
 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
   // <linux mem>        03460000-03ffffff  00ba0000
   // 02aa0000-02dfffff  03100000-0345ffff  00360000
   // Wiz                GP2X
   // <linux mem>        03460000-03ffffff  00ba0000
   // 02aa0000-02dfffff  03100000-0345ffff  00360000
@@ -81,3 +110,21 @@ fail:
   exit(1);
 }
 
   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;
+  }
+}