fix gun handling in enhancement mode
authornotaz <notasas@gmail.com>
Tue, 13 Nov 2012 17:19:36 +0000 (19:19 +0200)
committernotaz <notasas@gmail.com>
Sat, 17 Nov 2012 23:40:00 +0000 (01:40 +0200)
12 files changed:
frontend/libretro.c
frontend/menu.c
frontend/pl_gun_ts.c
frontend/plugin_lib.c
frontend/plugin_lib.h
maemo/main.c
plugins/dfinput/externals.h [new file with mode: 0644]
plugins/dfinput/guncon.c
plugins/dfinput/main.h
plugins/dfxvideo/draw_pl.c
plugins/gpu_unai/gpu.cpp
plugins/gpulib/vout_pl.c

index 82e6f65..b832a4e 100644 (file)
@@ -43,7 +43,7 @@ static int vout_open(void)
        return 0;
 }
 
        return 0;
 }
 
-static void vout_set_mode(int w, int h, int bpp)
+static void vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp)
 {
 }
 
 {
 }
 
@@ -132,7 +132,7 @@ void plat_trigger_vibrate(int is_strong)
 {
 }
 
 {
 }
 
-void pl_update_gun(int *xn, int *xres, int *y, int *in)
+void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
 {
 }
 
 {
 }
 
index f77bc9d..f3d4d63 100644 (file)
@@ -34,7 +34,7 @@
 #include "../libpcsxcore/cheat.h"
 #include "../libpcsxcore/psemu_plugin_defs.h"
 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
 #include "../libpcsxcore/cheat.h"
 #include "../libpcsxcore/psemu_plugin_defs.h"
 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
-#include "../plugins/dfinput/main.h"
+#include "../plugins/dfinput/externals.h"
 #include "../plugins/gpulib/cspace.h"
 #include "revision.h"
 
 #include "../plugins/gpulib/cspace.h"
 #include "revision.h"
 
index de7fe11..661792c 100644 (file)
@@ -15,7 +15,7 @@
 #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 gun_x, gun_y, gun_in;
 static int ts_multiplier_x, ts_multiplier_y, ts_offs_x, ts_offs_y;
@@ -61,6 +61,7 @@ int pl_gun_ts_update_raw(struct tsdev *ts, int *x, int *y, int *p)
        return 0;
 }
 
        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);
 void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in)
 {
        pl_gun_ts_update_raw(ts, NULL, NULL, NULL);
index 6cce912..9cbfe59 100644 (file)
@@ -31,6 +31,7 @@
 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
 #include "../libpcsxcore/psemu_plugin_defs.h"
 #include "../plugins/gpulib/cspace.h"
 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
 #include "../libpcsxcore/psemu_plugin_defs.h"
 #include "../plugins/gpulib/cspace.h"
+#include "../plugins/dfinput/externals.h"
 
 int in_type1, in_type2;
 int in_a1[2] = { 127, 127 }, in_a2[2] = { 127, 127 };
 
 int in_type1, in_type2;
 int in_a1[2] = { 127, 127 }, in_a2[2] = { 127, 127 };
@@ -199,7 +200,7 @@ static int resolution_ok(int w, int h)
        return w <= 1024 && h <= 512;
 }
 
        return w <= 1024 && h <= 512;
 }
 
-static void pl_vout_set_mode(int w, int h, int bpp)
+static void pl_vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp)
 {
        int vout_w, vout_h, vout_bpp;
 
 {
        int vout_w, vout_h, vout_bpp;
 
@@ -209,8 +210,10 @@ static void pl_vout_set_mode(int w, int h, int bpp)
                h = (h + 7) & ~7;
        vsync_cnt_ms_prev = vsync_cnt;
 
                h = (h + 7) & ~7;
        vsync_cnt_ms_prev = vsync_cnt;
 
-       vout_w = psx_w = w;
-       vout_h = psx_h = h;
+       psx_w = raw_w;
+       psx_h = raw_h;
+       vout_w = w;
+       vout_h = h;
        vout_bpp = psx_bpp = bpp;
 
        pl_vout_scale = 1;
        vout_bpp = psx_bpp = bpp;
 
        pl_vout_scale = 1;
@@ -237,7 +240,7 @@ static void pl_vout_set_mode(int w, int h, int bpp)
        pl_vout_buf = plat_gvideo_set_mode(&vout_w, &vout_h, &vout_bpp);
        if (pl_vout_buf == NULL)
                fprintf(stderr, "failed to set mode %dx%d@%d\n",
        pl_vout_buf = plat_gvideo_set_mode(&vout_w, &vout_h, &vout_bpp);
        if (pl_vout_buf == NULL)
                fprintf(stderr, "failed to set mode %dx%d@%d\n",
-                       psx_w, psx_h, psx_bpp);
+                       vout_w, vout_h, psx_bpp);
        else {
                pl_vout_w = vout_w;
                pl_vout_h = vout_h;
        else {
                pl_vout_w = vout_w;
                pl_vout_h = vout_h;
@@ -390,7 +393,7 @@ int dispmode_doubleres(void)
 
 int dispmode_scale2x(void)
 {
 
 int dispmode_scale2x(void)
 {
-       if (psx_bpp != 16)
+       if (!resolution_ok(psx_w * 2, psx_h * 2) || psx_bpp != 16)
                return 0;
 
        dispmode_default();
                return 0;
 
        dispmode_default();
@@ -401,7 +404,7 @@ int dispmode_scale2x(void)
 
 int dispmode_eagle2x(void)
 {
 
 int dispmode_eagle2x(void)
 {
-       if (psx_bpp != 16)
+       if (!resolution_ok(psx_w * 2, psx_h * 2) || psx_bpp != 16)
                return 0;
 
        dispmode_default();
                return 0;
 
        dispmode_default();
@@ -441,7 +444,7 @@ void pl_switch_dispmode(void)
  * more square-like analogs in PSX */
 static void update_analog_nub_adjust(int *x_, int *y_)
 {
  * more square-like analogs in PSX */
 static void update_analog_nub_adjust(int *x_, int *y_)
 {
-       const int d = 16;
+       #define d 16
        static const int scale[] =
                { 0 - d*2,  0 - d*2,  0 - d*2, 12 - d*2,
                 30 - d*2, 60 - d*2, 75 - d*2, 60 - d*2, 60 - d*2 };
        static const int scale[] =
                { 0 - d*2,  0 - d*2,  0 - d*2, 12 - d*2,
                 30 - d*2, 60 - d*2, 75 - d*2, 60 - d*2, 60 - d*2 };
@@ -463,6 +466,7 @@ static void update_analog_nub_adjust(int *x_, int *y_)
 
        *x_ = x;
        *y_ = y;
 
        *x_ = x;
        *y_ = y;
+       #undef d
 }
 
 static void update_analogs(void)
 }
 
 static void update_analogs(void)
@@ -526,13 +530,13 @@ static void update_input(void)
 }
 #endif
 
 }
 #endif
 
-void pl_update_gun(int *xn, int *xres, int *y, int *in)
+void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
 {
        if (tsdev)
 {
        if (tsdev)
-               pl_gun_ts_update(tsdev, xn, y, in);
+               pl_gun_ts_update(tsdev, xn, yn, in);
 
 
-       *xres = pl_vout_w;
-       *y = *y * pl_vout_h >> 10;
+       *xres = psx_w;
+       *yres = psx_h;
 }
 
 #define MAX_LAG_FRAMES 3
 }
 
 #define MAX_LAG_FRAMES 3
index a7c48bb..2f6c680 100644 (file)
@@ -37,12 +37,10 @@ void  pl_switch_dispmode(void);
 void  pl_timing_prepare(int is_pal);
 void  pl_frame_limit(void);
 
 void  pl_timing_prepare(int is_pal);
 void  pl_frame_limit(void);
 
-void  pl_update_gun(int *xn, int *xres, int *y, int *in);
-
 struct rearmed_cbs {
        void  (*pl_get_layer_pos)(int *x, int *y, int *w, int *h);
        int   (*pl_vout_open)(void);
 struct rearmed_cbs {
        void  (*pl_get_layer_pos)(int *x, int *y, int *w, int *h);
        int   (*pl_vout_open)(void);
-       void  (*pl_vout_set_mode)(int w, int h, int bpp);
+       void  (*pl_vout_set_mode)(int w, int h, int raw_w, int raw_h, int bpp);
        void  (*pl_vout_flip)(const void *vram, int stride, int bgr24,
                              int w, int h);
        void  (*pl_vout_close)(void);
        void  (*pl_vout_flip)(const void *vram, int stride, int bgr24,
                              int w, int h);
        void  (*pl_vout_close)(void);
index eb757f0..24db87a 100644 (file)
@@ -16,7 +16,7 @@
 #include "plugin_lib.h"
 #include "../libpcsxcore/misc.h"
 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
 #include "plugin_lib.h"
 #include "../libpcsxcore/misc.h"
 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
-#include "../plugins/dfinput/main.h"
+#include "../plugins/dfinput/externals.h"
 #include "maemo_common.h"
 
 int g_opts = OPT_SHOWFPS;
 #include "maemo_common.h"
 
 int g_opts = OPT_SHOWFPS;
diff --git a/plugins/dfinput/externals.h b/plugins/dfinput/externals.h
new file mode 100644 (file)
index 0000000..5419977
--- /dev/null
@@ -0,0 +1,14 @@
+
+void dfinput_activate(void);
+
+/* get gunstate from emu frontend,
+ * xn, yn - layer position normalized to 0..1023 */
+#define GUNIN_TRIGGER  (1<<0)
+#define GUNIN_BTNA     (1<<1)
+#define GUNIN_BTNB     (1<<2)
+#define GUNIN_TRIGGER2 (1<<3)  /* offscreen trigger */
+extern void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in);
+
+/* vibration trigger to frontend */
+extern int in_enable_vibration;
+extern void plat_trigger_vibrate(int is_strong);
index b4f103c..981a757 100644 (file)
@@ -29,17 +29,17 @@ unsigned char PADpoll_guncon(unsigned char value)
 
 unsigned char PADstartPoll_guncon(int pad)
 {
 
 unsigned char PADstartPoll_guncon(int pad)
 {
-       int x, xn = 0, y = 0, in = 0, xres = 256;
+       int x, y, xn = 0, yn = 0, in = 0, xres = 256, yres = 240;
        CurByte = 0;
 
        buf[2] = buf[3] = 0xff;
        CurByte = 0;
 
        buf[2] = buf[3] = 0xff;
-       pl_update_gun(&xn, &xres, &y, &in);
+       pl_update_gun(&xn, &yn, &xres, &yres, &in);
 
        // while y = const + line counter, what is x?
        // for 256 mode, hw dumped offsets x, y: 0x5a, 0x20
        //x = 0x5a + (356 * xn >> 10);
        x = 0x5a - (xres - 256) / 3 + (((xres - 256) / 3 + 356) * xn >> 10);
 
        // while y = const + line counter, what is x?
        // for 256 mode, hw dumped offsets x, y: 0x5a, 0x20
        //x = 0x5a + (356 * xn >> 10);
        x = 0x5a - (xres - 256) / 3 + (((xres - 256) / 3 + 356) * xn >> 10);
-       y = 0x20 + y;
+       y = 0x20 + (yres * yn >> 10);
 
        if (in & GUNIN_TRIGGER)
                buf[3] &= ~0x20;
 
        if (in & GUNIN_TRIGGER)
                buf[3] &= ~0x20;
index 8e2d5ae..15d05e7 100644 (file)
@@ -1,4 +1,5 @@
 #include "../../libpcsxcore/psemu_plugin_defs.h"
 #include "../../libpcsxcore/psemu_plugin_defs.h"
+#include "externals.h"
 
 extern unsigned char CurPad, CurByte, CurCmd, CmdLen;
 
 
 extern unsigned char CurPad, CurByte, CurCmd, CmdLen;
 
@@ -12,19 +13,6 @@ unsigned char PADpoll_guncon(unsigned char value);
 unsigned char PADstartPoll_guncon(int pad);
 void guncon_init(void);
 
 unsigned char PADstartPoll_guncon(int pad);
 void guncon_init(void);
 
-void dfinput_activate(void);
-
 /* get button state and pad type from main emu */
 extern long (*PAD1_readPort1)(PadDataS *pad);
 extern long (*PAD2_readPort2)(PadDataS *pad);
 /* get button state and pad type from main emu */
 extern long (*PAD1_readPort1)(PadDataS *pad);
 extern long (*PAD2_readPort2)(PadDataS *pad);
-
-/* get gunstate from emu frontend, x range 0-1023 */
-#define GUNIN_TRIGGER  (1<<0)
-#define GUNIN_BTNA     (1<<1)
-#define GUNIN_BTNB     (1<<2)
-#define GUNIN_TRIGGER2 (1<<3)  /* offscreen trigger */
-extern void pl_update_gun(int *xn, int *xres, int *y, int *in);
-
-/* vibration trigger to frontend */
-extern int in_enable_vibration;
-extern void plat_trigger_vibrate(int is_strong);
index 06a635d..ed07e75 100644 (file)
@@ -50,7 +50,7 @@ void DoBufferSwap(void)
   fbw = PreviousPSXDisplay.DisplayMode.x;
   fbh = PreviousPSXDisplay.DisplayMode.y;
   fb24bpp = PSXDisplay.RGB24;
   fbw = PreviousPSXDisplay.DisplayMode.x;
   fbh = PreviousPSXDisplay.DisplayMode.y;
   fb24bpp = PSXDisplay.RGB24;
-  rcbs->pl_vout_set_mode(fbw, fbh, fb24bpp ? 24 : 16);
+  rcbs->pl_vout_set_mode(fbw, fbh, fbw, fbh, fb24bpp ? 24 : 16);
  }
 
  pcnt_start(PCNT_BLIT);
  }
 
  pcnt_start(PCNT_BLIT);
index c111d78..df5e0cf 100644 (file)
@@ -850,7 +850,7 @@ static void blit(void)
                old_res_horz = w0;
                old_res_vert = h1;
                old_rgb24 = (s16)isRGB24;
                old_res_horz = w0;
                old_res_vert = h1;
                old_rgb24 = (s16)isRGB24;
-               cbs->pl_vout_set_mode(w0, h1, isRGB24 ? 24 : 16);
+               cbs->pl_vout_set_mode(w0, h1, w0, h1, isRGB24 ? 24 : 16);
        }
 
        cbs->pl_vout_flip(base, 1024, isRGB24, w0, h1);
        }
 
        cbs->pl_vout_flip(base, 1024, isRGB24, w0, h1);
index 7b229db..a49371a 100644 (file)
@@ -32,14 +32,16 @@ static void check_mode_change(int force)
   static int old_h;
   int w = gpu.screen.hres;
   int h = gpu.screen.h;
   static int old_h;
   int w = gpu.screen.hres;
   int h = gpu.screen.h;
+  int w_out = w;
+  int h_out = h;
 
   gpu.state.enhancement_active =
     gpu.get_enhancement_bufer != NULL && gpu.state.enhancement_enable
     && w <= 512 && h <= 256 && !gpu.status.rgb24;
 
   if (gpu.state.enhancement_active) {
 
   gpu.state.enhancement_active =
     gpu.get_enhancement_bufer != NULL && gpu.state.enhancement_enable
     && w <= 512 && h <= 256 && !gpu.status.rgb24;
 
   if (gpu.state.enhancement_active) {
-    w *= 2;
-    h *= 2;
+    w_out *= 2;
+    h_out *= 2;
   }
 
   // width|rgb24 change?
   }
 
   // width|rgb24 change?
@@ -48,7 +50,7 @@ static void check_mode_change(int force)
     old_status = gpu.status.reg;
     old_h = h;
 
     old_status = gpu.status.reg;
     old_h = h;
 
-    cbs->pl_vout_set_mode(w, h,
+    cbs->pl_vout_set_mode(w_out, h_out, w, h,
       (gpu.status.rgb24 && !cbs->only_16bpp) ? 24 : 16);
   }
 }
       (gpu.status.rgb24 && !cbs->only_16bpp) ? 24 : 16);
   }
 }