#include <stdint.h>
#include "../../libpcsxcore/psemu_plugin_defs.h"
+#include "main.h"
enum {
ANALOG_LEFT = 0,
static struct {
uint8_t PadMode;
uint8_t PadID;
+ uint8_t ConfigMode;
PadDataS pad;
} padstate[2];
0x00}
};
-static uint8_t CurPad = 0, CurByte = 0, CurCmd = 0, CmdLen = 0;
static uint8_t *buf;
static uint8_t do_cmd(void)
CmdLen = 8;
switch (CurCmd) {
- case CMD_CONFIG_MODE:
- buf = stdcfg[pad_num];
- if (stdcfg[pad_num][3] == 0xFF) return 0xF3;
- else return padstate[pad_num].PadID;
-
case CMD_SET_MODE_AND_LOCK:
buf = stdmode[pad_num];
return 0xF3;
buf = unk4d[pad_num];
return 0xF3;
+ case CMD_CONFIG_MODE:
+ if (padstate[pad_num].ConfigMode) {
+ buf = stdcfg[pad_num];
+ return 0xF3;
+ }
+ // else FALLTHROUGH
+
case CMD_READ_DATA_AND_VIBRATE:
default:
buf = stdpar[pad_num];
{
switch (CurCmd) {
case CMD_CONFIG_MODE:
- switch (value) {
- case 0:
- buf[2] = 0;
- buf[3] = 0;
- break;
-
- case 1:
- buf[2] = 0xFF;
- buf[3] = 0xFF;
- break;
- }
+ padstate[CurPad].ConfigMode = value;
break;
case CMD_SET_MODE_AND_LOCK:
break;
}
break;
+
+ case CMD_READ_DATA_AND_VIBRATE:
+ if (value == 1 && CurPad == 0 && in_enable_vibration)
+ plat_trigger_vibrate(0);
+ break;
+ }
+}
+
+static void do_cmd3(unsigned char value)
+{
+ if (in_enable_vibration && CurCmd == CMD_READ_DATA_AND_VIBRATE && CurPad == 0) {
+ if (value >= 0xf0)
+ plat_trigger_vibrate(1);
+ else if (value > 0x40)
+ plat_trigger_vibrate(0);
}
}
-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) {
+ switch (CurByte) {
+ case 0:
CurCmd = value;
CurByte++;
CurCmd = CMD_READ_DATA_AND_VIBRATE;
return do_cmd();
- }
-
- if (CurByte == 2)
+ case 2:
do_cmd2(value);
+ break;
+ case 3:
+ do_cmd3(value);
+ break;
+ }
if (CurByte >= CmdLen)
- return 0;
+ return 0xff; // verified
return buf[CurByte++];
}
-#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;
-}
-
-/* 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;
+ }
}
-