X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=plugins%2Fdfinput%2Fpad.c;h=7e00a1131fcdb28928883efd63da5c5c221610f2;hp=b01340ab52094dcd70eab9ec4f4224012cc02fa7;hb=8f2bb0cbd20c00475196d1efb72103b65e57bc66;hpb=cdd215d36888fae919ebdf9fe9bd6580d807b8b6 diff --git a/plugins/dfinput/pad.c b/plugins/dfinput/pad.c index b01340ab..7e00a113 100644 --- a/plugins/dfinput/pad.c +++ b/plugins/dfinput/pad.c @@ -21,7 +21,8 @@ #include -#include "../../libpcsxcore/psemu_plugin_defs.h" +#include "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,8 +206,55 @@ static void do_cmd2(unsigned char value) } } -static unsigned char PADpoll_(unsigned char value) { +static void do_vibration(unsigned char value) +{ + int changed = 0; + int i; + + switch (CurCmd) { + case CMD_READ_DATA_AND_VIBRATE: + for (i = 0; i < 2; i++) { + if (padstate[CurPad].pad.Vib[i] == CurByte + && padstate[CurPad].pad.VibF[i] != value) { + padstate[CurPad].pad.VibF[i] = value; + changed = 1; + } + } + + if (!in_enable_vibration || !changed) + break; + + plat_trigger_vibrate(CurPad, + padstate[CurPad].pad.VibF[0], + padstate[CurPad].pad.VibF[1]); + break; + case CMD_VIBRATION_TOGGLE: + for (i = 0; i < 2; i++) { + if (padstate[CurPad].pad.Vib[i] == CurByte) + buf[CurByte] = 0; + } + if (value < 2) { + padstate[CurPad].pad.Vib[value] = CurByte; + if((padstate[CurPad].PadID & 0x0f) < (CurByte - 1) / 2) { + padstate[CurPad].PadID = (padstate[CurPad].PadID & 0xf0) + (CurByte - 1) / 2; + } + } + break; + } +} + +#if 0 +#include +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; CurByte++; @@ -219,66 +266,39 @@ static unsigned char PADpoll_(unsigned char value) { return do_cmd(); } + if (CurByte >= CmdLen) + return 0xff; // verified + if (CurByte == 2) do_cmd2(value); - if (CurByte >= CmdLen) - return 0; + if (padstate[CurPad].pad.controllerType == PSE_PAD_TYPE_ANALOGPAD) + do_vibration(value); return buf[CurByte++]; } -#if 0 -#include -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; + } } -