From 3c0633839fae4fe9e083eb6be31a9d65169568ca Mon Sep 17 00:00:00 2001 From: AKuHAK Date: Sun, 24 Jan 2021 01:04:04 +0200 Subject: [PATCH] (PS2) added Multitap support (up to 8 players) (#11928) * (PS2) added Multitap support (up to 8 players) * (PS2) revert some identation changes * (PS2) fix for non-analog controllers * fix for not recognized digital and other non-standart controllers * fixed ps2_joypad_destroy --- Makefile.ps2 | 12 +++--- frontend/drivers/platform_ps2.c | 9 +++- input/drivers_joypad/ps2_joypad.c | 70 +++++++++++++++++++++---------- input/input_driver.h | 2 +- ps2/include/ps2_irx_variables.h | 4 +- ps2/irx/Makefile | 2 +- 6 files changed, 67 insertions(+), 32 deletions(-) diff --git a/Makefile.ps2 b/Makefile.ps2 index d1f2f41fc0..d8f89dda88 100644 --- a/Makefile.ps2 +++ b/Makefile.ps2 @@ -35,7 +35,7 @@ RARCH_DEFINES += -DHAVE_VIDEO_FILTER LDFLAGS += -L$(PS2DEV)/gsKit/lib -L$(PS2SDK)/ports/lib -L. # Lib cdvd is needed to get proper time -LIBS += -lretro_ps2 -lpatches -lgskit -ldmakit -laudsrv -lpadx -lmtap -lz -lcdvd -lelf-loader +LIBS += -lretro_ps2 -lpatches -lgskit -ldmakit -laudsrv -lmtap -lpadx -lz -lcdvd -lelf-loader ifeq ($(BUILD_FOR_PCSX2), 1) RARCH_DEFINES += -DBUILD_FOR_PCSX2 @@ -48,13 +48,15 @@ endif CFLAGS += $(RARCH_DEFINES) # All the IRX objects -EE_OBJS += $(IRX_DIR)/sio2man_irx.o $ $(IRX_DIR)/iomanX_irx.o $(IRX_DIR)/fileXio_irx.o -EE_OBJS += $(IRX_DIR)/mcman_irx.o $(IRX_DIR)/mcserv_irx.o $(IRX_DIR)/usbd_irx.o $(IRX_DIR)/usbhdfsd_irx.o +EE_OBJS += $(IRX_DIR)/sio2man_irx.o $ $(IRX_DIR)/iomanX_irx.o $(IRX_DIR)/fileXio_irx.o +EE_OBJS += $(IRX_DIR)/mcman_irx.o $(IRX_DIR)/mcserv_irx.o +EE_OBJS += $(IRX_DIR)/usbd_irx.o $(IRX_DIR)/usbhdfsd_irx.o EE_OBJS += $(IRX_DIR)/libsd_irx.o $(IRX_DIR)/audsrv_irx.o -EE_OBJS += $(IRX_DIR)/cdfs_irx.o $(IRX_DIR)/padman_irx.o +EE_OBJS += $(IRX_DIR)/cdfs_irx.o +EE_OBJS += $(IRX_DIR)/mtapman_irx.o $(IRX_DIR)/padman_irx.o # Missing objecst on the PS2SDK -EE_OBJS += ps2/compat_files/ps2_devices.o +EE_OBJS += ps2/compat_files/ps2_devices.o EE_OBJS += griffin/griffin.o diff --git a/frontend/drivers/platform_ps2.c b/frontend/drivers/platform_ps2.c index 3cf7752a06..4129fb502e 100644 --- a/frontend/drivers/platform_ps2.c +++ b/frontend/drivers/platform_ps2.c @@ -48,7 +48,7 @@ static void create_path_names(void) * rootDevicePath(bootDeviceID) */ strlcpy(user_path, rootDevicePath(bootDeviceID), sizeof(user_path)); strlcat(user_path, "RETROARCH", sizeof(user_path)); - + /* Content in the same folder */ fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE], cwd, "cores", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE])); @@ -164,6 +164,7 @@ static void frontend_ps2_init(void *data) #ifndef IS_SALAMANDER /* Controllers */ + SifExecModuleBuffer(&mtapman_irx, size_mtapman_irx, 0, NULL, NULL); SifExecModuleBuffer(&padman_irx, size_padman_irx, 0, NULL, NULL); /* Audio */ @@ -176,7 +177,11 @@ static void frontend_ps2_init(void *data) RARCH_ERR("audsrv library not initalizated\n"); } - /* Initializes pad library */ + /* Initializes pad un multitap libraries */ + if (mtapInit() != 1) + { + RARCH_ERR("mtapInit library not initalizated\n"); + } if (padInit(0) != 1) { RARCH_ERR("padInit library not initalizated\n"); diff --git a/input/drivers_joypad/ps2_joypad.c b/input/drivers_joypad/ps2_joypad.c index 5957743e6c..e6edc72070 100644 --- a/input/drivers_joypad/ps2_joypad.c +++ b/input/drivers_joypad/ps2_joypad.c @@ -21,14 +21,16 @@ #include "../input_driver.h" +#include "libmtap.h" #include "libpad.h" -#define PS2_PAD_SLOT 0 /* Always zero if not using multitap */ +#define PS2_MAX_PORT 2 /* each ps2 has 2 ports */ +#define PS2_MAX_SLOT 4 /* maximum - 4 slots in one multitap */ #define PS2_ANALOG_STICKS 2 #define PS2_ANALOG_AXIS 2 /* TODO/FIXME - static globals */ -static unsigned char padBuf[2][256] ALIGNED(64); +static unsigned char padBuf[PS2_MAX_PORT][PS2_MAX_SLOT][256] ALIGNED(64); static uint64_t pad_state[DEFAULT_MAX_PADS]; static int16_t analog_state[DEFAULT_MAX_PADS][PS2_ANALOG_STICKS][PS2_ANALOG_AXIS]; @@ -48,21 +50,39 @@ static void *ps2_joypad_init(void *data) { unsigned ret = 0; unsigned port = 0; + unsigned slot = 0; + unsigned pad = 0; - for (port = 0; port < DEFAULT_MAX_PADS; port++) + for (port = 0; port < PS2_MAX_PORT; port++) + mtapPortOpen(port); + /* it can fail - we dont care, we will check it more strictly when padPortOpen */ + + for (slot = 0; slot < PS2_MAX_SLOT; slot++) { - input_autoconfigure_connect( ps2_joypad_name(port), - NULL, - ps2_joypad.ident, - port, - 0, - 0); + for (port = 0; port < PS2_MAX_PORT; port++) + { + input_autoconfigure_connect( ps2_joypad_name(pad), /* name */ + NULL, /* display name */ + ps2_joypad.ident, /* driver */ + pad, /* idx */ + 0, /* vid */ + 0); /* pid */ + pad++; + /* 2 main controller ports acts the same with and without multitap + Port 0,0 -> Connector 1 - the same as Port 0 + Port 1,0 -> Connector 2 - the same as Port 1 + Port 0,1 -> Connector 3 + Port 1,1 -> Connector 4 + Port 0,2 -> Connector 5 + Port 1,2 -> Connector 6 + Port 0,3 -> Connector 7 + Port 1,3 -> Connector 8 + */ - /* Port 0 -> Connector 1, Port 1 -> Connector 2 */ - if((ret = padPortOpen(port, PS2_PAD_SLOT, padBuf[port])) == 0) - return NULL; + if((ret = padPortOpen(port, slot, padBuf[port][slot])) == 0) + return NULL; + } } - return (void*)-1; } @@ -132,12 +152,12 @@ static int16_t ps2_joypad_state( const uint32_t joyaxis = (binds[i].joyaxis != AXIS_NONE) ? binds[i].joyaxis : joypad_info->auto_binds[i].joyaxis; if ( - (uint16_t)joykey != NO_BTN + (uint16_t)joykey != NO_BTN && pad_state[port_idx] & (UINT64_C(1) << joykey) ) ret |= ( 1 << i); else if (joyaxis != AXIS_NONE && - ((float)abs(ps2_joypad_axis_state(port_idx, joyaxis)) + ((float)abs(ps2_joypad_axis_state(port_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) ret |= (1 << i); } @@ -154,7 +174,7 @@ static int16_t ps2_joypad_axis(unsigned port_num, uint32_t joyaxis) static void ps2_joypad_get_buttons(unsigned port_num, input_bits_t *state) { - BIT256_CLEAR_ALL_PTR(state); + BIT256_CLEAR_ALL_PTR(state); } static void ps2_joypad_poll(void) @@ -164,10 +184,13 @@ static void ps2_joypad_poll(void) for (player = 0; player < DEFAULT_MAX_PADS; player++) { - int state = padGetState(player, PS2_PAD_SLOT); - if (state == PAD_STATE_STABLE) + int ps2_slot = player >> 1; + int ps2_port = player & 0x1; + + int state = padGetState(ps2_port, ps2_slot); + if (state != PAD_STATE_DISCONN || state != PAD_STATE_EXECCMD || state != PAD_STATE_ERROR) { - int ret = padRead(player, PS2_PAD_SLOT, &buttons); /* port, slot, buttons */ + int ret = padRead(ps2_port, ps2_slot, &buttons); /* port, slot, buttons */ if (ret != 0) { int32_t state_tmp = 0xffff ^ buttons.btns; @@ -219,8 +242,13 @@ static bool ps2_joypad_rumble(unsigned pad, static void ps2_joypad_destroy(void) { unsigned port; - for (port = 0; port < DEFAULT_MAX_PADS; port++) - padPortClose(port, PS2_PAD_SLOT); + unsigned slot; + for (port = 0; port < PS2_MAX_PORT; port++) + { + for (slot = 0; slot < PS2_MAX_SLOT; slot++) + padPortClose(port, slot); + mtapPortClose(port); + } } input_device_driver_t ps2_joypad = { diff --git a/input/input_driver.h b/input/input_driver.h index d7b90c7d01..dd4e22b02f 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -224,7 +224,7 @@ struct rarch_joypad_driver #elif defined(PSP) #define DEFAULT_MAX_PADS 1 #elif defined(PS2) -#define DEFAULT_MAX_PADS 2 +#define DEFAULT_MAX_PADS 8 #elif defined(GEKKO) || defined(HW_RVL) #define DEFAULT_MAX_PADS 4 #elif defined(HAVE_ODROIDGO2) diff --git a/ps2/include/ps2_irx_variables.h b/ps2/include/ps2_irx_variables.h index ea32be1e9b..5696213422 100644 --- a/ps2/include/ps2_irx_variables.h +++ b/ps2/include/ps2_irx_variables.h @@ -24,8 +24,8 @@ extern unsigned int size_mcman_irx; extern unsigned char mcserv_irx; extern unsigned int size_mcserv_irx; -extern unsigned char freemtap_irx; -extern unsigned int size_freemtap_irx; +extern unsigned char mtapman_irx; +extern unsigned int size_mtapman_irx; extern unsigned char padman_irx; extern unsigned int size_padman_irx; diff --git a/ps2/irx/Makefile b/ps2/irx/Makefile index 8fac6db1b1..26997ee593 100644 --- a/ps2/irx/Makefile +++ b/ps2/irx/Makefile @@ -4,7 +4,7 @@ IRX_DIR = $(PS2SDK)/iop/irx #IRX modules # IRX modules - modules have to be in IRX_DIR -IRX_FILES += iomanX.irx fileXio.irx sio2man.irx padman.irx mcman.irx mcserv.irx usbd.irx usbhdfsd.irx +IRX_FILES += iomanX.irx fileXio.irx sio2man.irx mtapman.irx padman.irx mcman.irx mcserv.irx usbd.irx usbhdfsd.irx IRX_FILES += libsd.irx audsrv.irx cdfs.irx IRX_C_FILES = $(IRX_FILES:.irx=_irx.c)