From 1e774d8e6174a7171dd4c6978997d4ac5508b05e Mon Sep 17 00:00:00 2001 From: notaz Date: Wed, 13 Sep 2023 00:08:56 +0300 Subject: [PATCH] try to cleanup the mess in the input code --- Makefile | 5 - frontend/libretro.c | 5 - include/psemu_plugin_defs.h | 2 +- libpcsxcore/plugins.c | 128 +++++++-------- libpcsxcore/plugins.h | 5 +- libpcsxcore/psxbios.c | 17 +- libpcsxcore/sio.c | 124 ++++----------- plugins/dfinput/externals.h | 19 --- plugins/dfinput/guncon.c | 68 -------- plugins/dfinput/main.c | 71 --------- plugins/dfinput/main.h | 23 --- plugins/dfinput/pad.c | 308 ------------------------------------ 12 files changed, 96 insertions(+), 679 deletions(-) delete mode 100644 plugins/dfinput/externals.h delete mode 100644 plugins/dfinput/guncon.c delete mode 100644 plugins/dfinput/main.c delete mode 100644 plugins/dfinput/main.h delete mode 100644 plugins/dfinput/pad.c diff --git a/Makefile b/Makefile index f1c47e3c..c0a3ab4d 100644 --- a/Makefile +++ b/Makefile @@ -267,11 +267,6 @@ CFLAGS += -DHAVE_CHD -D_7ZIP_ST LDFLAGS += -lm endif -# dfinput -ifneq "$(PLATFORM)" "libretro" -OBJS += plugins/dfinput/main.o plugins/dfinput/pad.o plugins/dfinput/guncon.o -endif - # frontend/gui OBJS += frontend/cspace.o ifeq "$(HAVE_NEON_ASM)" "1" diff --git a/frontend/libretro.c b/frontend/libretro.c index 4fe86376..8d6b5cc7 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -29,7 +29,6 @@ #include "../libpcsxcore/r3000a.h" #include "../plugins/dfsound/out.h" #include "../plugins/dfsound/spu_config.h" -#include "../plugins/dfinput/externals.h" #include "cspace.h" #include "main.h" #include "menu.h" @@ -514,10 +513,6 @@ void plat_trigger_vibrate(int pad, int low, int high) } } -void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in) -{ -} - void pl_gun_byte2(int port, unsigned char byte) { } diff --git a/include/psemu_plugin_defs.h b/include/psemu_plugin_defs.h index 8645eab7..2d688f20 100644 --- a/include/psemu_plugin_defs.h +++ b/include/psemu_plugin_defs.h @@ -141,7 +141,7 @@ typedef struct long PADquery(void); unsigned char PADstartPoll(int); - unsigned char PADpoll(unsigned char); + unsigned char PADpoll(unsigned char, int *); */ diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index 4516b5ce..a34969f4 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -23,7 +23,6 @@ #include "plugins.h" #include "cdriso.h" -#include "../plugins/dfinput/externals.h" static char IsoFile[MAXPATHLEN] = ""; static s64 cdOpenCaseTime = 0; @@ -357,7 +356,7 @@ static int multitap2; //Pad information, keystate, mode, config mode, vibration static PadDataS pad[8]; -static int reqPos, respSize, req; +static int reqPos, respSize; static int ledStateReq44[8]; static int PadMode[8]; /* 0 : digital 1: analog */ @@ -554,8 +553,8 @@ void initBufForRequest(int padIndex, char value){ -void reqIndex2Treatment(int padIndex, char value){ - switch (req){ +static void reqIndex2Treatment(int padIndex, char value) { + switch (pad[padIndex].txData[0]) { case CMD_CONFIG_MODE : //0x43 if (value == 0) { @@ -661,6 +660,14 @@ void _PADstartPoll(PadDataS *pad) { memcpy(buf, stdpar, 8); respSize = 8; break; + case PSE_PAD_TYPE_GUN: // GUN CONTROLLER - gun controller SLPH-00014 from Konami + stdpar[0] = 0x31; + stdpar[1] = 0x5a; + stdpar[2] = pad->buttonStatus & 0xff; + stdpar[3] = pad->buttonStatus >> 8; + memcpy(buf, stdpar, 4); + respSize = 4; + break; case PSE_PAD_TYPE_ANALOGPAD: // scph1150 stdpar[0] = 0x73; stdpar[1] = 0x5a; @@ -690,25 +697,11 @@ void _PADstartPoll(PadDataS *pad) { stdpar[1] = 0x5a; stdpar[2] = pad->buttonStatus & 0xff; stdpar[3] = pad->buttonStatus >> 8; - //avoid analog value in multitap mode if change pad type in game. - stdpar[4] = 0xff; - stdpar[5] = 0xff; - stdpar[6] = 0xff; - stdpar[7] = 0xff; - memcpy(buf, stdpar, 8); - respSize = 8; + memcpy(buf, stdpar, 4); + respSize = 4; break; default: - stdpar[0] = 0xff; - stdpar[1] = 0xff; - stdpar[2] = 0xff; - stdpar[3] = 0xff; - stdpar[4] = 0xff; - stdpar[5] = 0xff; - stdpar[6] = 0xff; - stdpar[7] = 0xff; - memcpy(buf, stdpar, 8); - respSize = 8; + respSize = 0; break; } } @@ -727,63 +720,52 @@ void _PADstartPollMultitap(PadDataS* padd) { respSize = 34; } - -unsigned char _PADpoll(int port, unsigned char value) { - if (reqPos == 0) { - //mem the request number - req = value; - - // Don't enable Analog/Vibration for a standard pad - if (in_type[port] == PSE_PAD_TYPE_STANDARD || - in_type[port] == PSE_PAD_TYPE_NEGCON) { - ; // Pad keystate already in buffer - } - else - { - //copy the default value of request response in buffer instead of the keystate +static void PADpoll_dualshock(int port, unsigned char value) +{ + switch (reqPos) { + case 0: initBufForRequest(port, value); - } + break; + case 2: + reqIndex2Treatment(port, value); + break; + case 3: + if (pad[port].txData[0] == CMD_READ_DATA_AND_VIBRATE) { + // vibration value for the Large motor + pad[port].Vib[1] = value; + + vibrate(port); + } + break; } +} +static unsigned char PADpoll_(int port, unsigned char value, int *more_data) { if (reqPos < sizeof(pad[port].txData)) pad[port].txData[reqPos] = value; - //if no new request the pad return 0xff, for signaling connected - if (reqPos >= respSize) - return 0xff; + if (reqPos == 0 && value != 0x42 && in_type[port] != PSE_PAD_TYPE_ANALOGPAD) + respSize = 1; - if (in_type[port] == PSE_PAD_TYPE_GUN) { - if (reqPos == 2) - pl_gun_byte2(port, value); + switch (in_type[port]) { + case PSE_PAD_TYPE_ANALOGPAD: + PADpoll_dualshock(port, value); + break; + case PSE_PAD_TYPE_GUN: + if (reqPos == 2) + pl_gun_byte2(port, value); + break; } - else - switch(reqPos){ - case 2: - reqIndex2Treatment(port, value); - break; - case 3: - switch(req) { - case CMD_SET_MODE_AND_LOCK : - //change mode on pad - break; - case CMD_READ_DATA_AND_VIBRATE: - //mem the vibration value for Large motor; - pad[port].Vib[1] = value; - if (in_type[port] != PSE_PAD_TYPE_ANALOGPAD) - break; + *more_data = reqPos < respSize - 1; + if (reqPos >= respSize) + return 0xff; // no response/HiZ - //vibration - vibrate(port); - break; - } - break; - } return buf[reqPos++]; } - -unsigned char _PADpollMultitap(int port, unsigned char value) { +static unsigned char PADpollMultitap(int port, unsigned char value, int *more_data) { + *more_data = reqPos < respSize - 1; if (reqPos >= respSize) return 0xff; return bufMulti[reqPos++]; } @@ -811,15 +793,15 @@ unsigned char CALLBACK PAD1__startPoll(int pad) { _PADstartPollMultitap(padd); } //printf("\npad 1 : "); - return 0x00; + return 0xff; } -unsigned char CALLBACK PAD1__poll(unsigned char value) { +unsigned char CALLBACK PAD1__poll(unsigned char value, int *more_data) { char tmp; if (multitap1 == 1) { - tmp = _PADpollMultitap(0, value); + tmp = PADpollMultitap(0, value, more_data); } else { - tmp = _PADpoll(0, value); + tmp = PADpoll_(0, value, more_data); } //printf("%2x:%2x, ",value,tmp); return tmp; @@ -903,15 +885,15 @@ unsigned char CALLBACK PAD2__startPoll(int pad) { _PADstartPollMultitap(padd); } //printf("\npad 2 : "); - return 0x00; + return 0xff; } -unsigned char CALLBACK PAD2__poll(unsigned char value) { +unsigned char CALLBACK PAD2__poll(unsigned char value, int *more_data) { char tmp; if (multitap2 == 2) { - tmp = _PADpollMultitap(1, value); + tmp = PADpollMultitap(1, value, more_data); } else { - tmp = _PADpoll(1, value); + tmp = PADpoll_(1, value, more_data); } //printf("%2x:%2x, ",value,tmp); return tmp; diff --git a/libpcsxcore/plugins.h b/libpcsxcore/plugins.h index f74489f3..c5140cce 100644 --- a/libpcsxcore/plugins.h +++ b/libpcsxcore/plugins.h @@ -216,7 +216,7 @@ typedef long (CALLBACK* PADreadPort1)(PadDataS*); typedef long (CALLBACK* PADreadPort2)(PadDataS*); typedef long (CALLBACK* PADkeypressed)(void); typedef unsigned char (CALLBACK* PADstartPoll)(int); -typedef unsigned char (CALLBACK* PADpoll)(unsigned char); +typedef unsigned char (CALLBACK* PADpoll)(unsigned char, int *); typedef void (CALLBACK* PADsetSensitive)(int); // PAD function pointers @@ -379,6 +379,9 @@ const char *GetIsoFile(void); boolean UsingIso(void); void SetCdOpenCaseTime(s64 time); +extern void pl_gun_byte2(int port, unsigned char byte); +extern void plat_trigger_vibrate(int pad, int low, int high); + #ifdef __cplusplus } #endif diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c index 257ed33a..88f994f8 100644 --- a/libpcsxcore/psxbios.c +++ b/libpcsxcore/psxbios.c @@ -3774,18 +3774,12 @@ void psxBiosCnfLoaded(u32 tcb_cnt, u32 evcb_cnt, u32 stack) { } #define psxBios_PADpoll(pad) { \ - PAD##pad##_startPoll(pad); \ - pad_buf##pad[0] = 0; \ - pad_buf##pad[1] = PAD##pad##_poll(0x42); \ - if (!(pad_buf##pad[1] & 0x0f)) { \ - bufcount = 32; \ - } else { \ - bufcount = (pad_buf##pad[1] & 0x0f) * 2; \ - } \ - PAD##pad##_poll(0); \ + int i, more_data = 0; \ + pad_buf##pad[0] = PAD##pad##_startPoll(pad); \ + pad_buf##pad[1] = PAD##pad##_poll(0x42, &more_data); \ i = 2; \ - while (bufcount--) { \ - pad_buf##pad[i++] = PAD##pad##_poll(0); \ + while (more_data) { \ + pad_buf##pad[i++] = PAD##pad##_poll(0, &more_data); \ } \ } @@ -3970,7 +3964,6 @@ void hleExcPadCard1(void) if (loadRam32(A_PAD_IRQR_ENA)) { u8 *pad_buf1 = loadRam8ptr(A_PAD_INBUF + 0); u8 *pad_buf2 = loadRam8ptr(A_PAD_INBUF + 4); - int i, bufcount; psxBios_PADpoll(1); psxBios_PADpoll(2); diff --git a/libpcsxcore/sio.c b/libpcsxcore/sio.c index 44957d39..ab6baa12 100644 --- a/libpcsxcore/sio.c +++ b/libpcsxcore/sio.c @@ -84,74 +84,43 @@ char McdDisable[2]; #define SIO_CYCLES 535 void sioWrite8(unsigned char value) { -#ifdef PAD_LOG - PAD_LOG("sio write8 %x\n", value); + int more_data = 0; +#if 0 + s32 framec = psxRegs.cycle - rcnts[3].cycleStart; + printf("%d:%03d sio write8 %04x %02x\n", frame_counter, + (s32)(framec / (PSXCLK / 60 / 263.0f)), CtrlReg, value); #endif switch (padst) { - case 1: SIO_INT(SIO_CYCLES); + case 1: if ((value & 0x40) == 0x40) { padst = 2; parp = 1; - if (!Config.UseNet) { - switch (CtrlReg & 0x2002) { - case 0x0002: - buf[parp] = PAD1_poll(value); - break; - case 0x2002: - buf[parp] = PAD2_poll(value); - break; - } - }/* else { -// SysPrintf("%x: %x, %x, %x, %x\n", CtrlReg&0x2002, buf[2], buf[3], buf[4], buf[5]); - }*/ - - if (!(buf[parp] & 0x0f)) { - bufcount = 2 + 32; - } else { - bufcount = 2 + (buf[parp] & 0x0f) * 2; - } - if (buf[parp] == 0x41) { - switch (value) { - case 0x43: - buf[1] = 0x43; - break; - case 0x45: - buf[1] = 0xf3; - break; - } + switch (CtrlReg & 0x2002) { + case 0x0002: + buf[parp] = PAD1_poll(value, &more_data); + break; + case 0x2002: + buf[parp] = PAD2_poll(value, &more_data); + break; } - // NegCon - Wipeout 3 - if( buf[parp] == 0x23 ) { - switch (value) { - // enter config mode - case 0x43: - buf[1] = 0x79; - break; - // get status - case 0x45: - buf[1] = 0xf3; - break; - } + if (more_data) { + bufcount = parp + 1; + SIO_INT(SIO_CYCLES); } } else padst = 0; return; case 2: parp++; -/* if (buf[1] == 0x45) { - buf[parp] = 0; - SIO_INT(SIO_CYCLES); - return; - }*/ - if (!Config.UseNet) { - switch (CtrlReg & 0x2002) { - case 0x0002: buf[parp] = PAD1_poll(value); break; - case 0x2002: buf[parp] = PAD2_poll(value); break; - } + switch (CtrlReg & 0x2002) { + case 0x0002: buf[parp] = PAD1_poll(value, &more_data); break; + case 0x2002: buf[parp] = PAD2_poll(value, &more_data); break; } - if (parp == bufcount) { padst = 0; return; } - SIO_INT(SIO_CYCLES); + if (more_data) { + bufcount = parp + 1; + SIO_INT(SIO_CYCLES); + } return; } @@ -241,44 +210,11 @@ void sioWrite8(unsigned char value) { case 0x01: // start pad StatReg |= RX_RDY; // Transfer is Ready - if (!Config.UseNet) { - switch (CtrlReg & 0x2002) { - case 0x0002: buf[0] = PAD1_startPoll(1); break; - case 0x2002: buf[0] = PAD2_startPoll(2); break; - } - } else { - if ((CtrlReg & 0x2002) == 0x0002) { - int i, j; - - PAD1_startPoll(1); - buf[0] = 0; - buf[1] = PAD1_poll(0x42); - if (!(buf[1] & 0x0f)) { - bufcount = 32; - } else { - bufcount = (buf[1] & 0x0f) * 2; - } - buf[2] = PAD1_poll(0); - i = 3; - j = bufcount; - while (j--) { - buf[i++] = PAD1_poll(0); - } - bufcount+= 3; - - if (NET_sendPadData(buf, bufcount) == -1) - netError(); - - if (NET_recvPadData(buf, 1) == -1) - netError(); - if (NET_recvPadData(buf + 128, 2) == -1) - netError(); - } else { - memcpy(buf, buf + 128, 32); - } + switch (CtrlReg & 0x2002) { + case 0x0002: buf[0] = PAD1_startPoll(1); break; + case 0x2002: buf[0] = PAD2_startPoll(2); break; } - - bufcount = 2; + bufcount = 1; parp = 0; padst = 1; SIO_INT(SIO_CYCLES); @@ -365,8 +301,10 @@ unsigned char sioRead8() { } } -#ifdef PAD_LOG - PAD_LOG("sio read8 ;ret = %x\n", ret); +#if 0 + s32 framec = psxRegs.cycle - rcnts[3].cycleStart; + printf("%d:%03d sio read8 %04x %02x\n", frame_counter, + (s32)((float)framec / (PSXCLK / 60 / 263.0f)), CtrlReg, ret); #endif return ret; } diff --git a/plugins/dfinput/externals.h b/plugins/dfinput/externals.h deleted file mode 100644 index 822fa2c5..00000000 --- a/plugins/dfinput/externals.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __P_EXTERNALS_H__ -#define __P_EXTERNALS_H__ - -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); -extern void pl_gun_byte2(int port, unsigned char byte); - -/* vibration trigger to frontend */ -extern int in_enable_vibration; -extern void plat_trigger_vibrate(int pad, int low, int high); - -#endif /* __P_EXTERNALS_H__ */ diff --git a/plugins/dfinput/guncon.c b/plugins/dfinput/guncon.c deleted file mode 100644 index 981a7574..00000000 --- a/plugins/dfinput/guncon.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * (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 -#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, y, xn = 0, yn = 0, in = 0, xres = 256, yres = 240; - CurByte = 0; - - buf[2] = buf[3] = 0xff; - 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); - y = 0x20 + (yres * yn >> 10); - - 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 deleted file mode 100644 index 5d676c47..00000000 --- a/plugins/dfinput/main.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * (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 CALLBACK PAD1__startPoll(int pad); -extern unsigned char CALLBACK PAD2__startPoll(int pad); -extern unsigned char CALLBACK PAD1__poll(unsigned char value); -extern unsigned char CALLBACK PAD2__poll(unsigned char value); - -#if 0 //ndef HAVE_LIBRETRO - -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_NEGCON: \ - 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; - - pad.portMultitap = -1; - pad.requestPadIndex = 0; - PAD1_readPort1(&pad); - select_pad(1); - - pad.requestPadIndex = 1; - PAD2_readPort2(&pad); - select_pad(2); -} - -#else // use libretro's libpcsxcore/plugins.c code - -void dfinput_activate(void) -{ -} - -#endif diff --git a/plugins/dfinput/main.h b/plugins/dfinput/main.h deleted file mode 100644 index 96cebfac..00000000 --- a/plugins/dfinput/main.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __P_MAIN_H__ -#define __P_MAIN_H__ - -#include "psemu_plugin_defs.h" -#include "externals.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); - -/* get button state and pad type from main emu */ -extern long (*PAD1_readPort1)(PadDataS *pad); -extern long (*PAD2_readPort2)(PadDataS *pad); - -#endif /* __P_MAIN_H__ */ diff --git a/plugins/dfinput/pad.c b/plugins/dfinput/pad.c deleted file mode 100644 index 3e333660..00000000 --- a/plugins/dfinput/pad.c +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (c) 2009, Wei Mingzhi . - * All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - * - * this is only pure emulation code to handle analogs, - * extracted from dfinput. - */ - -#include - -#include "psemu_plugin_defs.h" -#include "main.h" - -enum { - ANALOG_LEFT = 0, - ANALOG_RIGHT, - - ANALOG_TOTAL -}; - -enum { - CMD_READ_DATA_AND_VIBRATE = 0x42, - CMD_CONFIG_MODE = 0x43, - CMD_SET_MODE_AND_LOCK = 0x44, - CMD_QUERY_MODEL_AND_MODE = 0x45, - CMD_QUERY_ACT = 0x46, // ?? - CMD_QUERY_COMB = 0x47, // ?? - CMD_QUERY_MODE = 0x4C, // QUERY_MODE ?? - CMD_VIBRATION_TOGGLE = 0x4D, -}; - -#ifndef HAVE_LIBRETRO -static struct { - uint8_t PadMode; - uint8_t PadID; - uint8_t ConfigMode; - PadDataS pad; -} padstate[2]; - -static uint8_t stdpar[2][8] = { - {0xFF, 0x5A, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80}, - {0xFF, 0x5A, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80} -}; - -static uint8_t unk46[2][8] = { - {0xFF, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A}, - {0xFF, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A} -}; - -static uint8_t unk47[2][8] = { - {0xFF, 0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00}, - {0xFF, 0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00} -}; - -static uint8_t unk4c[2][8] = { - {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} -}; - -static uint8_t unk4d[2][8] = { - {0xFF, 0x5A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, - {0xFF, 0x5A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} -}; - -static uint8_t stdcfg[2][8] = { - {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} -}; - -static uint8_t stdmode[2][8] = { - {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} -}; - -static uint8_t stdmodel[2][8] = { - {0xFF, - 0x5A, - 0x01, // 03 - dualshock2, 01 - dualshock - 0x02, // number of modes - 0x01, // current mode: 01 - analog, 00 - digital - 0x02, - 0x01, - 0x00}, - {0xFF, - 0x5A, - 0x01, // 03 - dualshock2, 01 - dualshock - 0x02, // number of modes - 0x01, // current mode: 01 - analog, 00 - digital - 0x02, - 0x01, - 0x00} -}; - -static uint8_t *buf; - -static uint8_t do_cmd(void) -{ - PadDataS *pad = &padstate[CurPad].pad; - int pad_num = CurPad; - - CmdLen = 8; - switch (CurCmd) { - case CMD_SET_MODE_AND_LOCK: - buf = stdmode[pad_num]; - return 0xF3; - - case CMD_QUERY_MODEL_AND_MODE: - buf = stdmodel[pad_num]; - buf[4] = padstate[pad_num].PadMode; - return 0xF3; - - case CMD_QUERY_ACT: - buf = unk46[pad_num]; - return 0xF3; - - case CMD_QUERY_COMB: - buf = unk47[pad_num]; - return 0xF3; - - case CMD_QUERY_MODE: - buf = unk4c[pad_num]; - return 0xF3; - - case CMD_VIBRATION_TOGGLE: - 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]; - - buf[2] = pad->buttonStatus; - buf[3] = pad->buttonStatus >> 8; - - if (padstate[pad_num].PadMode == 1) { - buf[4] = pad->rightJoyX; - buf[5] = pad->rightJoyY; - buf[6] = pad->leftJoyX; - buf[7] = pad->leftJoyY; - } else { - CmdLen = 4; - } - - return padstate[pad_num].PadID; - } -} - -static void do_cmd2(unsigned char value) -{ - switch (CurCmd) { - case CMD_CONFIG_MODE: - padstate[CurPad].ConfigMode = value; - break; - - case CMD_SET_MODE_AND_LOCK: - padstate[CurPad].PadMode = value; - padstate[CurPad].PadID = value ? 0x73 : 0x41; - break; - - case CMD_QUERY_ACT: - switch (value) { - case 0: // default - buf[5] = 0x02; - buf[6] = 0x00; - buf[7] = 0x0A; - break; - - case 1: // Param std conf change - buf[5] = 0x01; - buf[6] = 0x01; - buf[7] = 0x14; - break; - } - break; - - case CMD_QUERY_MODE: - switch (value) { - case 0: // mode 0 - digital mode - buf[5] = PSE_PAD_TYPE_STANDARD; - break; - - case 1: // mode 1 - analog mode - buf[5] = PSE_PAD_TYPE_ANALOGPAD; - break; - } - break; - } -} - -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; - } -} -#endif - -#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 - -#ifndef HAVE_LIBRETRO -unsigned char PADpoll_pad(unsigned char value) { - if (CurByte == 0) { - CurCmd = value; - CurByte++; - - // Don't enable Analog/Vibration for a standard pad - if (padstate[CurPad].pad.controllerType != PSE_PAD_TYPE_ANALOGPAD) - CurCmd = CMD_READ_DATA_AND_VIBRATE; - - return do_cmd(); - } - - if (CurByte >= CmdLen) - return 0xff; // verified - - if (CurByte == 2) - do_cmd2(value); - - if (padstate[CurPad].pad.controllerType == PSE_PAD_TYPE_ANALOGPAD) - do_vibration(value); - - return buf[CurByte++]; -} - -unsigned char PADstartPoll_pad(int pad) { - CurPad = pad - 1; - CurByte = 0; - - if (pad == 1) - PAD1_readPort1(&padstate[0].pad); - else - PAD2_readPort2(&padstate[1].pad); - - return 0xFF; -} - -void pad_init(void) -{ - int i; - - PAD1_readPort1(&padstate[0].pad); - PAD2_readPort2(&padstate[1].pad); - - 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; - } -} -#endif -- 2.39.2