fix gun handling in enhancement mode
[pcsx_rearmed.git] / frontend / pl_gun_ts.c
index 3ee9c25..661792c 100644 (file)
 #include "plugin_lib.h"
 #include "pl_gun_ts.h"
 #include "menu.h"
 #include "plugin_lib.h"
 #include "pl_gun_ts.h"
 #include "menu.h"
-#include "../plugins/dfinput/main.h"
+#include "../plugins/dfinput/externals.h"
 
 static int gun_x, gun_y, gun_in;
 static int ts_multiplier_x, ts_multiplier_y, ts_offs_x, ts_offs_y;
 static int (*pts_read)(struct tsdev *dev, struct ts_sample *sample, int nr);
 
 static int gun_x, gun_y, gun_in;
 static int ts_multiplier_x, ts_multiplier_y, ts_offs_x, ts_offs_y;
 static int (*pts_read)(struct tsdev *dev, struct ts_sample *sample, int nr);
+static int (*pts_fd)(struct tsdev *dev);
 
 #define limit(v, min, max) \
        if (v < min) v = min; \
        else if (v > max) v = max
 
 
 #define limit(v, min, max) \
        if (v < min) v = min; \
        else if (v > max) v = max
 
-void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in)
+int pl_gun_ts_update_raw(struct tsdev *ts, int *x, int *y, int *p)
 {
        struct ts_sample sample;
        int sx = 0, sy = 0, sp = 0, updated = 0;
 {
        struct ts_sample sample;
        int sx = 0, sy = 0, sp = 0, updated = 0;
@@ -50,6 +51,21 @@ void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in)
                }
        }
 
                }
        }
 
+       if (updated) {
+               if (x) *x = sx;
+               if (y) *y = sy;
+               if (p) *p = sp;
+               return 1;
+       }
+
+       return 0;
+}
+
+/* returns x, y in range 0..1023 (normalized to visible layer) */
+void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in)
+{
+       pl_gun_ts_update_raw(ts, NULL, NULL, NULL);
+
        *x = gun_x;
        *y = gun_y;
        *in = gun_in | in_state_gun;
        *x = gun_x;
        *y = gun_y;
        *in = gun_in | in_state_gun;
@@ -63,6 +79,14 @@ void pl_set_gun_rect(int x, int y, int w, int h)
        ts_multiplier_y = (1<<20) / h;
 }
 
        ts_multiplier_y = (1<<20) / h;
 }
 
+int pl_gun_ts_get_fd(struct tsdev *ts)
+{
+       if (ts != NULL && pts_fd != NULL)
+               return pts_fd(ts);
+
+       return -1;
+}
+
 struct tsdev *pl_gun_ts_init(void)
 {
        struct tsdev *(*pts_open)(const char *dev_name, int nonblock) = NULL;
 struct tsdev *pl_gun_ts_init(void)
 {
        struct tsdev *(*pts_open)(const char *dev_name, int nonblock) = NULL;
@@ -77,9 +101,11 @@ struct tsdev *pl_gun_ts_init(void)
                tsdevname = "/dev/input/touchscreen0";
 
        // avoid hard dep on tslib
                tsdevname = "/dev/input/touchscreen0";
 
        // avoid hard dep on tslib
-       ltsh = dlopen("/usr/lib/libts-1.0.so.0", RTLD_LAZY);
+       ltsh = dlopen("/usr/lib/libts-1.0.so.0", RTLD_NOW|RTLD_GLOBAL);
+       if (ltsh == NULL)
+               ltsh = dlopen("/usr/lib/libts-0.0.so.0", RTLD_NOW|RTLD_GLOBAL);
        if (ltsh == NULL)
        if (ltsh == NULL)
-               ltsh = dlopen("/usr/lib/libts-0.0.so.0", RTLD_LAZY);
+               ltsh = dlopen("/lib/libts-0.0.so.0", RTLD_NOW|RTLD_GLOBAL);
        if (ltsh == NULL) {
                fprintf(stderr, "%s\n", dlerror());
                goto fail;
        if (ltsh == NULL) {
                fprintf(stderr, "%s\n", dlerror());
                goto fail;
@@ -88,8 +114,10 @@ struct tsdev *pl_gun_ts_init(void)
        pts_open = dlsym(ltsh, "ts_open");
        pts_config = dlsym(ltsh, "ts_config");
        pts_read = dlsym(ltsh, "ts_read");
        pts_open = dlsym(ltsh, "ts_open");
        pts_config = dlsym(ltsh, "ts_config");
        pts_read = dlsym(ltsh, "ts_read");
+       pts_fd = dlsym(ltsh, "ts_fd");
        pts_close = dlsym(ltsh, "ts_close");
        pts_close = dlsym(ltsh, "ts_close");
-       if (pts_open == NULL || pts_config == NULL || pts_read == NULL || pts_close == NULL) {
+       if (pts_open == NULL || pts_config == NULL || pts_read == NULL
+           || pts_fd == NULL || pts_close == NULL) {
                fprintf(stderr, "%s\n", dlerror());
                goto fail_dlsym;
        }
                fprintf(stderr, "%s\n", dlerror());
                goto fail_dlsym;
        }
@@ -102,7 +130,11 @@ struct tsdev *pl_gun_ts_init(void)
 
        // FIXME: we should be able to get this somewhere
        // the problem is this doesn't always match resolution due to different display modes
 
        // FIXME: we should be able to get this somewhere
        // the problem is this doesn't always match resolution due to different display modes
+#ifdef __ARM_ARCH_7A__
        pl_set_gun_rect(0, 0, 800, 480);
        pl_set_gun_rect(0, 0, 800, 480);
+#else
+       pl_set_gun_rect(0, 0, 320, 240);
+#endif
        return ts;
 
 fail_config:
        return ts;
 
 fail_config: