aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authornotaz2011-08-09 01:16:59 +0300
committernotaz2011-08-13 00:56:33 +0300
commit4c08b9e7dd350a48fc3e0515913d6ccc8b15e5ae (patch)
tree22f29a06fda180d8269878b3cdb413044a5e351e /plugins
parent19e57cbf170d1ce49f00097f3cc3a4ed96d77374 (diff)
downloadpcsx_rearmed-4c08b9e7dd350a48fc3e0515913d6ccc8b15e5ae.tar.gz
pcsx_rearmed-4c08b9e7dd350a48fc3e0515913d6ccc8b15e5ae.tar.bz2
pcsx_rearmed-4c08b9e7dd350a48fc3e0515913d6ccc8b15e5ae.zip
add guncon support
a bit basic but works
Diffstat (limited to 'plugins')
-rw-r--r--plugins/dfinput/guncon.c68
-rw-r--r--plugins/dfinput/main.c57
-rw-r--r--plugins/dfinput/main.h26
-rw-r--r--plugins/dfinput/pad.c71
-rw-r--r--plugins/dfinput/pad.h2
5 files changed, 177 insertions, 47 deletions
diff --git a/plugins/dfinput/guncon.c b/plugins/dfinput/guncon.c
new file mode 100644
index 0000000..b4f103c
--- /dev/null
+++ b/plugins/dfinput/guncon.c
@@ -0,0 +1,68 @@
+/*
+ * (C) Gražvydas "notaz" Ignotas, 2011
+ *
+ * This work is licensed under the terms of any of these licenses
+ * (at your option):
+ * - GNU GPL, version 2 or later.
+ * - GNU LGPL, version 2.1 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include <string.h>
+#include "main.h"
+
+static unsigned char buf[8];
+
+unsigned char PADpoll_guncon(unsigned char value)
+{
+ if (CurByte == 0) {
+ CurCmd = value;
+ CurByte++;
+ return 0x63; // regardless of cmd
+ }
+
+ if (CurCmd != 0x42 || CurByte >= 8)
+ return 0xff; // verified
+
+ return buf[CurByte++];
+}
+
+unsigned char PADstartPoll_guncon(int pad)
+{
+ int x, xn = 0, y = 0, in = 0, xres = 256;
+ CurByte = 0;
+
+ buf[2] = buf[3] = 0xff;
+ pl_update_gun(&xn, &xres, &y, &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);
+ y = 0x20 + y;
+
+ if (in & GUNIN_TRIGGER)
+ buf[3] &= ~0x20;
+ if (in & GUNIN_BTNA)
+ buf[2] &= ~0x08;
+ if (in & GUNIN_BTNB)
+ buf[3] &= ~0x40;
+ if (in & GUNIN_TRIGGER2) {
+ buf[3] &= ~0x20;
+ x = 1;
+ y = 10;
+ }
+ buf[4] = x;
+ buf[5] = x >> 8;
+ buf[6] = y;
+ buf[7] = y >> 8;
+
+ return 0xff;
+}
+
+void guncon_init(void)
+{
+ memset(buf, 0xff, sizeof(buf));
+ buf[1] = 0x5a;
+}
+
diff --git a/plugins/dfinput/main.c b/plugins/dfinput/main.c
new file mode 100644
index 0000000..73b2bda
--- /dev/null
+++ b/plugins/dfinput/main.c
@@ -0,0 +1,57 @@
+/*
+ * (C) Gražvydas "notaz" Ignotas, 2011
+ *
+ * This work is licensed under the terms of any of these licenses
+ * (at your option):
+ * - GNU GPL, version 2 or later.
+ * - GNU LGPL, version 2.1 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "main.h"
+
+unsigned char CurPad, CurByte, CurCmd, CmdLen;
+
+/* since this is not a proper plugin, so we'll hook emu internals in a hackish way like this */
+extern void *PAD1_startPoll, *PAD1_poll;
+extern void *PAD2_startPoll, *PAD2_poll;
+extern unsigned char PAD1__startPoll(int pad);
+extern unsigned char PAD2__startPoll(int pad);
+extern unsigned char PAD1__poll(unsigned char value);
+extern unsigned char PAD2__poll(unsigned char value);
+
+static int old_controller_type1 = -1, old_controller_type2 = -1;
+
+#define select_pad(n) \
+ if (pad.controllerType != old_controller_type##n) \
+ { \
+ switch (pad.controllerType) \
+ { \
+ case PSE_PAD_TYPE_ANALOGPAD: \
+ PAD##n##_startPoll = PADstartPoll_pad; \
+ PAD##n##_poll = PADpoll_pad; \
+ pad_init(); \
+ break; \
+ case PSE_PAD_TYPE_GUNCON: \
+ PAD##n##_startPoll = PADstartPoll_guncon; \
+ PAD##n##_poll = PADpoll_guncon; \
+ guncon_init(); \
+ break; \
+ case PSE_PAD_TYPE_GUN: \
+ default: \
+ PAD##n##_startPoll = PAD##n##__startPoll; \
+ PAD##n##_poll = PAD##n##__poll; \
+ break; \
+ } \
+ }
+
+void dfinput_activate(void)
+{
+ PadDataS pad;
+
+ PAD1_readPort1(&pad);
+ select_pad(1);
+
+ PAD2_readPort2(&pad);
+ select_pad(2);
+}
diff --git a/plugins/dfinput/main.h b/plugins/dfinput/main.h
new file mode 100644
index 0000000..ee30165
--- /dev/null
+++ b/plugins/dfinput/main.h
@@ -0,0 +1,26 @@
+#include "../../libpcsxcore/psemu_plugin_defs.h"
+
+extern unsigned char CurPad, CurByte, CurCmd, CmdLen;
+
+/* analog pad */
+unsigned char PADpoll_pad(unsigned char value);
+unsigned char PADstartPoll_pad(int pad);
+void pad_init(void);
+
+/* GunCon */
+unsigned char PADpoll_guncon(unsigned char value);
+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 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);
diff --git a/plugins/dfinput/pad.c b/plugins/dfinput/pad.c
index 9a09563..90fde88 100644
--- a/plugins/dfinput/pad.c
+++ b/plugins/dfinput/pad.c
@@ -22,6 +22,7 @@
#include <stdint.h>
#include "../../libpcsxcore/psemu_plugin_defs.h"
+#include "main.h"
enum {
ANALOG_LEFT = 0,
@@ -102,7 +103,6 @@ static uint8_t stdmodel[2][8] = {
0x00}
};
-static uint8_t CurPad = 0, CurByte = 0, CurCmd = 0, CmdLen = 0;
static uint8_t *buf;
static uint8_t do_cmd(void)
@@ -206,7 +206,18 @@ static void do_cmd2(unsigned char value)
}
}
-static unsigned char PADpoll_(unsigned char value) {
+#if 0
+#include <stdio.h>
+unsigned char PADpoll_(unsigned char value);
+unsigned char PADpoll(unsigned char value) {
+ unsigned char b = CurByte, r = PADpoll_(value);
+ printf("poll[%d] %02x %02x\n", b, value, r);
+ return r;
+}
+#define PADpoll PADpoll_
+#endif
+
+unsigned char PADpoll_pad(unsigned char value) {
if (CurByte == 0) {
CurCmd = value;
@@ -228,57 +239,27 @@ static unsigned char PADpoll_(unsigned char value) {
return buf[CurByte++];
}
-#if 0
-#include <stdio.h>
-static unsigned char PADpoll(unsigned char value) {
- unsigned char b = CurByte, r = PADpoll_(value);
- printf("poll[%d] %02x %02x\n", b, value, r);
- return r;
-}
-#else
-#define PADpoll PADpoll_
-#endif
-
-/* hack.. */
-extern long (*PAD1_readPort1)(PadDataS *pad);
-
-static unsigned char PADstartPoll1(int pad) {
- CurPad = 0;
+unsigned char PADstartPoll_pad(int pad) {
+ CurPad = pad - 1;
CurByte = 0;
- PAD1_readPort1(&padstate[0].pad);
+ if (pad == 1)
+ PAD1_readPort1(&padstate[0].pad);
+ else
+ PAD2_readPort2(&padstate[1].pad);
return 0xFF;
}
-/* some more hacks here but oh well */
-extern void *PAD1_startPoll, *PAD1_poll;
-
-void dfinput_activate(int yes)
+void pad_init(void)
{
- static void *old_start, *old_poll;
-
- if (!yes) {
- if (PAD1_startPoll == PADstartPoll1)
- PAD1_startPoll = old_start;
- if (PAD1_poll == PADpoll)
- PAD1_poll = old_poll;
- return;
- }
-
- if (PAD1_startPoll == PADstartPoll1 && PAD1_poll == PADpoll)
- return;
-
- old_start = PAD1_startPoll;
- old_poll = PAD1_poll;
- PAD1_startPoll = PADstartPoll1;
- PAD1_poll = PADpoll;
+ int i;
PAD1_readPort1(&padstate[0].pad);
- padstate[0].PadID = padstate[0].pad.controllerType == PSE_PAD_TYPE_ANALOGPAD ? 0x73 : 0x41;
- padstate[0].PadMode = padstate[0].pad.controllerType == PSE_PAD_TYPE_ANALOGPAD;
+ PAD2_readPort2(&padstate[1].pad);
- padstate[1].PadID = 0x41;
- padstate[1].PadMode = 0;
+ for (i = 0; i < 2; i++) {
+ padstate[i].PadID = padstate[i].pad.controllerType == PSE_PAD_TYPE_ANALOGPAD ? 0x73 : 0x41;
+ padstate[i].PadMode = padstate[i].pad.controllerType == PSE_PAD_TYPE_ANALOGPAD;
+ }
}
-
diff --git a/plugins/dfinput/pad.h b/plugins/dfinput/pad.h
deleted file mode 100644
index 60a46f0..0000000
--- a/plugins/dfinput/pad.h
+++ /dev/null
@@ -1,2 +0,0 @@
-void dfinput_activate(int yes);
-