2 * GINGE - GINGE Is Not Gp2x Emulator
3 * (C) notaz, 2010-2011,2015
5 * This work is licensed under the MAME license, see COPYING file for details.
7 #define _GNU_SOURCE 1 // for plat.c
12 #include <sys/types.h>
16 #include <linux/input.h>
18 #include "../common/libpicofe/input.h"
19 #include "../common/libpicofe/linux/in_evdev.h"
20 #include "../common/host_fb.h"
23 #include "realfuncs.h"
25 // must be affected by realfuncs.h
26 #include "../common/libpicofe/input.c"
27 #include "../common/libpicofe/linux/plat.c"
28 #include "../common/libpicofe/linux/in_evdev.c"
37 static int ts_fd = -1;
39 /* touscreen. Could just use tsblib, but it's LGPL... */
42 static int host_ts_init(void)
44 static const char name_def[] = "/dev/input/touchscreen0";
49 f = fopen("/etc/pointercal", "r");
51 perror("fopen pointercal");
54 ret = fscanf(f, "%d %d %d %d %d %d %d", &tsc[0], &tsc[1],
55 &tsc[2], &tsc[3], &tsc[4], &tsc[5], &tsc[6]);
58 fprintf(stderr, "could not parse pointercal\n");
62 name = getenv("TSLIB_TSDEVICE");
65 ts_fd = open(name, O_RDONLY | O_NONBLOCK);
67 fprintf(stderr, "open %s", name);
74 // returns ranges 0-1023
75 int host_read_ts(int *pressure, int *x1024, int *y1024)
77 static int raw_x, raw_y, raw_p;
78 struct input_event ev;
86 ret = read(ts_fd, &ev, sizeof(ev));
87 if (ret != sizeof(ev)) {
93 if (ev.type == EV_ABS) {
95 case ABS_X: raw_x = ev.value; break;
96 case ABS_Y: raw_y = ev.value; break;
97 case ABS_PRESSURE: raw_p = ev.value; break;
103 *x1024 = (tsc[0] * raw_x + tsc[1] * raw_y + tsc[2]) / tsc[6];
104 *y1024 = (tsc[3] * raw_x + tsc[4] * raw_y + tsc[5]) / tsc[6];
106 host_video_normalize_ts(x1024, y1024);
121 int host_read_btns(void)
123 int actions[IN_BINDTYPE_COUNT] = { 0, };
126 host_actions(actions);
128 return actions[IN_BINDTYPE_PLAYER12];
131 void host_forced_exit(int status)
133 // exit() might not be enough because loader and app data is out of sync,
134 // and other threads (which are really processes on this old glibc used)
135 // might not exit properly.
138 printf("forced exit...\n");
140 if (g_argv != NULL) {
141 unsetenv("LD_PRELOAD");
142 unsetenv("LD_LIBRARY_PATH");
144 snprintf(cmd, sizeof(cmd), "killall %s", g_argv[0]);
147 snprintf(cmd, sizeof(cmd), "killall -9 %s", g_argv[0]);
153 // vim:shiftwidth=2:expandtab