switch over to libretro input code

too much trouble with 2 separate codebases
This commit is contained in:
notaz
2023-09-14 00:41:27 +03:00
parent 1351a8fbef
commit 2db412ade2
18 changed files with 1343 additions and 1436 deletions
-3
View File
@@ -174,9 +174,6 @@ libchdr/src/%.o: CFLAGS += -Wno-unused -Ilibchdr/deps/lzma-19.00/include
libchdr/deps/lzma-19.00/src/%.o: CFLAGS += -Wno-unused -D_7ZIP_ST -Ilibchdr/deps/lzma-19.00/include
#endif
# dfinput
OBJS += plugins/dfinput/main.o plugins/dfinput/pad.o plugins/dfinput/guncon.o
# frontend/gui
OBJS += frontend/cspace.o
ifeq "$(HAVE_NEON_ASM)" "1"
+9 -8
View File
@@ -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,7 +513,7 @@ 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)
{
}
@@ -2468,17 +2467,19 @@ static void update_input_guncon(int port, int ret)
//Mouse range is -32767 -> 32767
//1% is about 655
//Use the left analog stick field to store the absolute coordinates
//Fix cursor to top-left when gun is detected as "offscreen"
int gunx = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X);
int guny = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y);
//Have the Libretro API let /libpcsxcore/plugins.c know when the lightgun is pointed offscreen
//Offscreen value is chosen to be well out of range of any possible scaling done via core options
if (input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN) || input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD))
{
in_analog_left[port][0] = -32767;
in_analog_left[port][1] = -32767;
in_analog_left[port][0] = (65536 - 512) * 64;
in_analog_left[port][1] = (65536 - 512) * 64;
}
else
{
int gunx = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X);
int guny = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y);
in_analog_left[port][0] = (gunx * GunconAdjustRatioX) + (GunconAdjustX * 655);
in_analog_left[port][1] = (guny * GunconAdjustRatioY) + (GunconAdjustY * 655);
}
-3
View File
@@ -36,7 +36,6 @@
#include "../libpcsxcore/cdriso.h"
#include "../libpcsxcore/cheat.h"
#include "../libpcsxcore/new_dynarec/new_dynarec.h"
#include "../plugins/dfinput/externals.h"
#include "../plugins/dfsound/spu_config.h"
#include "psemu_plugin_defs.h"
#include "arm_features.h"
@@ -2696,8 +2695,6 @@ void menu_prepare_emu(void)
if (ret)
fprintf(stderr, "Warning: GPU_open returned %d\n", ret);
}
dfinput_activate();
}
void menu_update_msg(const char *msg)
+2 -4
View File
@@ -15,8 +15,6 @@
#include "plugin_lib.h"
#include "pl_gun_ts.h"
#include "menu.h"
#include "../plugins/dfinput/externals.h"
#include "../plugins/dfinput/main.h"
#ifdef MAEMO
#define N900_TSMAX_X 4096
@@ -57,9 +55,9 @@ int pl_gun_ts_update_raw(struct tsdev *ts, int *x, int *y, int *p)
limit(gun_x, 0, 1023);
limit(gun_y, 0, 1023);
if (sp && !(g_opts & OPT_TSGUN_NOTRIGGER))
gun_in |= GUNIN_TRIGGER;
gun_in |= 1;
else
gun_in &= ~GUNIN_TRIGGER;
gun_in &= ~1;
}
}
+55 -13
View File
@@ -68,23 +68,65 @@ static long CALLBACK PADshutdown(void) { return 0; }
static long CALLBACK PADclose(void) { return 0; }
static void CALLBACK PADsetSensitive(int _) { return; }
static long CALLBACK PADreadPort1(PadDataS *pad)
{
pad->controllerType = in_type[0];
pad->buttonStatus = ~in_keystate[0];
if (in_type[0] == PSE_PAD_TYPE_ANALOGPAD) {
pad->leftJoyX = in_analog_left[0][0];
pad->leftJoyY = in_analog_left[0][1];
pad->rightJoyX = in_analog_right[0][0];
pad->rightJoyY = in_analog_right[0][1];
static long CALLBACK PADreadPort1(PadDataS *pad) {
int pad_index = pad->requestPadIndex;
pad->controllerType = in_type[pad_index];
pad->buttonStatus = ~in_keystate[pad_index];
if (multitap1 == 1)
pad->portMultitap = 1;
else
pad->portMultitap = 0;
if (in_type[pad_index] == PSE_PAD_TYPE_ANALOGJOY || in_type[pad_index] == PSE_PAD_TYPE_ANALOGPAD || in_type[pad_index] == PSE_PAD_TYPE_NEGCON || in_type[pad_index] == PSE_PAD_TYPE_GUNCON)
{
pad->leftJoyX = in_analog_left[pad_index][0];
pad->leftJoyY = in_analog_left[pad_index][1];
pad->rightJoyX = in_analog_right[pad_index][0];
pad->rightJoyY = in_analog_right[pad_index][1];
pad->absoluteX = in_analog_left[pad_index][0];
pad->absoluteY = in_analog_left[pad_index][1];
}
if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE)
{
pad->moveX = in_mouse[pad_index][0];
pad->moveY = in_mouse[pad_index][1];
}
return 0;
}
static long CALLBACK PADreadPort2(PadDataS *pad)
{
pad->controllerType = in_type[1];
pad->buttonStatus = ~in_keystate[0] >> 16;
static long CALLBACK PADreadPort2(PadDataS *pad) {
int pad_index = pad->requestPadIndex;
pad->controllerType = in_type[pad_index];
pad->buttonStatus = ~in_keystate[pad_index];
if (multitap2 == 1)
pad->portMultitap = 2;
else
pad->portMultitap = 0;
if (in_type[pad_index] == PSE_PAD_TYPE_ANALOGJOY || in_type[pad_index] == PSE_PAD_TYPE_ANALOGPAD || in_type[pad_index] == PSE_PAD_TYPE_NEGCON || in_type[pad_index] == PSE_PAD_TYPE_GUNCON)
{
pad->leftJoyX = in_analog_left[pad_index][0];
pad->leftJoyY = in_analog_left[pad_index][1];
pad->rightJoyX = in_analog_right[pad_index][0];
pad->rightJoyY = in_analog_right[pad_index][1];
pad->absoluteX = in_analog_left[pad_index][0];
pad->absoluteY = in_analog_left[pad_index][1];
}
if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE)
{
pad->moveX = in_mouse[pad_index][0];
pad->moveY = in_mouse[pad_index][1];
}
return 0;
}
+6 -7
View File
@@ -33,7 +33,6 @@
#include "psemu_plugin_defs.h"
#include "../libpcsxcore/new_dynarec/new_dynarec.h"
#include "../libpcsxcore/psxmem_map.h"
#include "../plugins/dfinput/externals.h"
#define HUD_HEIGHT 10
@@ -620,18 +619,18 @@ static void update_input(void)
emu_set_action(emu_act);
in_keystate[0] = actions[IN_BINDTYPE_PLAYER12];
// fixme
//if (in_type[0] == PSE_PAD_TYPE_GUNCON && tsdev)
// pl_gun_ts_update(tsdev, xn, yn, in);
// in_analog_left[0][0] = xn
}
#else /* MAEMO */
extern void update_input(void);
#endif
void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
void pl_gun_byte2(int port, unsigned char byte)
{
if (tsdev)
pl_gun_ts_update(tsdev, xn, yn, in);
*xres = psx_w;
*yres = psx_h;
}
#define MAX_LAG_FRAMES 3
+4 -2
View File
@@ -141,7 +141,7 @@ typedef struct
long PADquery(void);
unsigned char PADstartPoll(int);
unsigned char PADpoll(unsigned char);
unsigned char PADpoll(unsigned char, int *);
*/
@@ -222,7 +222,9 @@ typedef struct
//configuration mode Request 0x43
int configMode;
unsigned char reserved[87];
unsigned char txData[32];
unsigned char reserved[56];
//Lightgun values
int absoluteX,absoluteY;
+1225 -811
View File
File diff suppressed because it is too large Load Diff
+4 -1
View File
@@ -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
+6 -13
View File
@@ -1,6 +1,6 @@
/***************************************************************************
* Copyright (C) 2019 Ryan Schultz, PCSX-df Team, PCSX team, gameblabla, *
* dmitrysmagin, senquack *
* dmitrysmagin, senquack *
* *
* 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 *
@@ -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);
+32 -80
View File
@@ -84,60 +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;
switch (CtrlReg & 0x2002) {
case 0x0002:
buf[parp] = PAD1_poll(value, &more_data);
break;
case 0x2002:
buf[parp] = PAD2_poll(value, &more_data);
break;
}
if (buf[parp] == 0x41) {
switch (value) {
case 0x43:
buf[1] = 0x43;
break;
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;
}
@@ -227,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);
@@ -351,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;
}
-1
View File
@@ -13,7 +13,6 @@
#include "../include/psemu_plugin_defs.h"
#include "../libpcsxcore/cdrom.h"
#include "../libpcsxcore/cdriso.h"
#include "../plugins/dfinput/main.h"
#include "../frontend/libpicofe/readpng.h"
#include "maemo_common.h"
#include <libosso.h>
-2
View File
@@ -17,7 +17,6 @@
#include "../libpcsxcore/misc.h"
#include "../libpcsxcore/cdriso.h"
#include "../libpcsxcore/new_dynarec/new_dynarec.h"
#include "../plugins/dfinput/main.h"
#include "../plugins/dfsound/spu_config.h"
#include "maemo_common.h"
@@ -393,7 +392,6 @@ int main(int argc, char **argv)
if (Config.HLE)
printf("Note: running without BIOS, expect compatibility problems\n");
dfinput_activate();
pl_timing_prepare(Config.PsxType);
while (1)
-18
View File
@@ -1,18 +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);
/* vibration trigger to frontend */
extern int in_enable_vibration;
extern void plat_trigger_vibrate(int pad, int low, int high);
#endif /* __P_EXTERNALS_H__ */
-68
View File
@@ -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 <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, 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;
}
-71
View File
@@ -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);
#ifndef 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
-23
View File
@@ -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__ */
-308
View File
@@ -1,308 +0,0 @@
/*
* Copyright (c) 2009, Wei Mingzhi <[email protected]>.
* 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 <http://www.gnu.org/licenses>.
*
* this is only pure emulation code to handle analogs,
* extracted from dfinput.
*/
#include <stdint.h>
#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 <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
#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