Merge pull request #7928 from fjtrujy/feature/PS2Controller

[PS2] Input Driver - 2 Player
This commit is contained in:
Twinaphex 2019-01-08 01:13:56 +01:00 committed by GitHub
commit 983e0a900f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 62 deletions

View File

@ -24,7 +24,7 @@
#include <iopcontrol.h> #include <iopcontrol.h>
#include <libpwroff.h> #include <libpwroff.h>
#include <audsrv.h> #include <audsrv.h>
#include <libpad.h>
enum BootDeviceIDs{ enum BootDeviceIDs{
BOOT_DEVICE_UNKNOWN = -1, BOOT_DEVICE_UNKNOWN = -1,
@ -361,11 +361,15 @@ static void frontend_ps2_init(void *data)
SifExecModuleBuffer(audsrv_irx_start, audsrv_irx_size, 0, NULL, NULL); SifExecModuleBuffer(audsrv_irx_start, audsrv_irx_size, 0, NULL, NULL);
/* Initializes audsrv library */ /* Initializes audsrv library */
if (audsrv_init()) if (audsrv_init()) {
{
RARCH_ERR("audsrv library not initalizated\n"); RARCH_ERR("audsrv library not initalizated\n");
} }
/* Initializes pad library
Must be init with 0 as parameter*/
if (padInit(0) != 1) {
RARCH_ERR("padInit library not initalizated\n");
}
#if defined(HAVE_FILE_LOGGER) #if defined(HAVE_FILE_LOGGER)
retro_main_log_file_init("retroarch.log"); retro_main_log_file_init("retroarch.log");
@ -383,6 +387,10 @@ static void frontend_ps2_deinit(void *data)
#endif #endif
#endif #endif
padEnd();
audsrv_quit();
fileXioUmount("pfs0:"); fileXioUmount("pfs0:");
fileXioExit(); fileXioExit();

View File

@ -204,8 +204,7 @@ static void *ps2_gfx_init(const video_info_t *video,
ps2->core_filter = video->smooth ? GS_FILTER_LINEAR : GS_FILTER_NEAREST; ps2->core_filter = video->smooth ? GS_FILTER_LINEAR : GS_FILTER_NEAREST;
ps2->force_aspect = video->force_aspect; ps2->force_aspect = video->force_aspect;
if (input && input_data) if (input && input_data) {
{
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
ps2input = input_ps2.init(settings->arrays.input_joypad_driver); ps2input = input_ps2.init(settings->arrays.input_joypad_driver);
*input = ps2input ? &input_ps2 : NULL; *input = ps2input ? &input_ps2 : NULL;

View File

@ -58,11 +58,9 @@ static void ps2_upload_font(GSGLOBAL *gsGlobal, GSFONTM *gsFontM) {
int pgindx; int pgindx;
int TexSize = gsKit_texture_size(gsFontM->Texture->Width, gsFontM->Texture->Height, gsFontM->Texture->PSM); int TexSize = gsKit_texture_size(gsFontM->Texture->Width, gsFontM->Texture->Height, gsFontM->Texture->PSM);
free(gsFontM->Texture->VramClut);
gsFontM->Texture->VramClut = gsKit_vram_alloc(gsGlobal, FONTM_VRAM_SIZE, GSKIT_ALLOC_USERBUFFER); gsFontM->Texture->VramClut = gsKit_vram_alloc(gsGlobal, FONTM_VRAM_SIZE, GSKIT_ALLOC_USERBUFFER);
for (pgindx = 0; pgindx < GS_FONTM_PAGE_COUNT; ++pgindx) { for (pgindx = 0; pgindx < GS_FONTM_PAGE_COUNT; ++pgindx) {
free(gsFontM->Vram[pgindx]);
gsFontM->Vram[pgindx] = gsKit_vram_alloc(gsGlobal, TexSize, GSKIT_ALLOC_USERBUFFER); gsFontM->Vram[pgindx] = gsKit_vram_alloc(gsGlobal, TexSize, GSKIT_ALLOC_USERBUFFER);
gsFontM->LastPage[pgindx] = (u32) -1; gsFontM->LastPage[pgindx] = (u32) -1;
} }

View File

@ -21,14 +21,10 @@
#include "libpad.h" #include "libpad.h"
#define PS2_MAX_PADS 1 #define PS2_MAX_PADS 2
#define PS2_PAD_SLOT 0 /* Always zero if not using multitap */
/* static unsigned char padBuf[2][256] ALIGNED(64);
* Global var's
*/
// pad_dma_buf is provided by the user, one buf for each pad
// contains the pad's current state
static char padBuf[256] __attribute__((aligned(64)));
static uint64_t pad_state[PS2_MAX_PADS]; static uint64_t pad_state[PS2_MAX_PADS];
@ -41,40 +37,32 @@ static const char *ps2_joypad_name(unsigned pad)
static bool ps2_joypad_init(void *data) static bool ps2_joypad_init(void *data)
{ {
unsigned i; unsigned ret, port;
unsigned players_count = PS2_MAX_PADS; bool init = true;
for (i = 0; i < players_count; i++) printf("PortMax: %d\n", padGetPortMax());
{ printf("SlotMax: %d\n", padGetSlotMax(port));
int ret, port, slot;
bool auto_configure = input_autoconfigure_connect( ps2_joypad_name(i), for (port = 0; port < PS2_MAX_PADS; port++) {
bool auto_configure = input_autoconfigure_connect( ps2_joypad_name(port),
NULL, NULL,
ps2_joypad.ident, ps2_joypad.ident,
i, port,
0, 0,
0); 0);
if (!auto_configure) { if (!auto_configure) {
input_config_set_device_name(i, ps2_joypad_name(i)); input_config_set_device_name(port, ps2_joypad_name(port));
} }
padInit(i); /* Port 0 -> Connector 1, Port 1 -> Connector 2 */
if((ret = padPortOpen(port, PS2_PAD_SLOT, padBuf[port])) == 0) {
port = 0; // 0 -> Connector 1, 1 -> Connector 2
slot = 0; // Always zero if not using multitap
printf("PortMax: %d\n", padGetPortMax());
printf("SlotMax: %d\n", padGetSlotMax(port));
if((ret = padPortOpen(port, slot, padBuf)) == 0) {
printf("padOpenPort failed: %d\n", ret); printf("padOpenPort failed: %d\n", ret);
init = false;
break;
} }
} }
return true; return init;
} }
static bool ps2_joypad_button(unsigned port_num, uint16_t joykey) static bool ps2_joypad_button(unsigned port_num, uint16_t joykey)
@ -98,36 +86,34 @@ static int16_t ps2_joypad_axis(unsigned port_num, uint32_t joyaxis)
static void ps2_joypad_poll(void) static void ps2_joypad_poll(void)
{ {
unsigned player; unsigned player;
unsigned players_count = PS2_MAX_PADS;
struct padButtonStatus buttons; struct padButtonStatus buttons;
for (player = 0; player < players_count; player++) { for (player = 0; player < PS2_MAX_PADS; player++) {
unsigned j, k; int state = padGetState(player, PS2_PAD_SLOT);
unsigned i = player; if (state == PAD_STATE_STABLE) {
unsigned p = player; int ret = padRead(player, PS2_PAD_SLOT, &buttons); /* port, slot, buttons */
if (ret != 0) {
int ret = padRead(player, player, &buttons); // port, slot, buttons int32_t state_tmp = 0xffff ^ buttons.btns;
if (ret != 0) { pad_state[player] = 0;
int32_t state_tmp = 0xffff ^ buttons.btns;
pad_state[i] = 0; pad_state[player] |= (state_tmp & PAD_LEFT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
pad_state[player] |= (state_tmp & PAD_DOWN) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
pad_state[i] |= (state_tmp & PAD_LEFT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; pad_state[player] |= (state_tmp & PAD_RIGHT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
pad_state[i] |= (state_tmp & PAD_DOWN) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; pad_state[player] |= (state_tmp & PAD_UP) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
pad_state[i] |= (state_tmp & PAD_RIGHT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; pad_state[player] |= (state_tmp & PAD_START) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START) : 0;
pad_state[i] |= (state_tmp & PAD_UP) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0; pad_state[player] |= (state_tmp & PAD_SELECT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
pad_state[i] |= (state_tmp & PAD_START) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START) : 0; pad_state[player] |= (state_tmp & PAD_TRIANGLE) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X) : 0;
pad_state[i] |= (state_tmp & PAD_SELECT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0; pad_state[player] |= (state_tmp & PAD_SQUARE) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
pad_state[i] |= (state_tmp & PAD_TRIANGLE) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X) : 0; pad_state[player] |= (state_tmp & PAD_CROSS) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B) : 0;
pad_state[i] |= (state_tmp & PAD_SQUARE) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y) : 0; pad_state[player] |= (state_tmp & PAD_CIRCLE) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A) : 0;
pad_state[i] |= (state_tmp & PAD_CROSS) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B) : 0; pad_state[player] |= (state_tmp & PAD_R1) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R) : 0;
pad_state[i] |= (state_tmp & PAD_CIRCLE) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A) : 0; pad_state[player] |= (state_tmp & PAD_L1) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L) : 0;
pad_state[i] |= (state_tmp & PAD_R1) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R) : 0; pad_state[player] |= (state_tmp & PAD_R2) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R2) : 0;
pad_state[i] |= (state_tmp & PAD_L1) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L) : 0; pad_state[player] |= (state_tmp & PAD_L2) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
pad_state[i] |= (state_tmp & PAD_R2) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R2) : 0; pad_state[player] |= (state_tmp & PAD_R3) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R3) : 0;
pad_state[i] |= (state_tmp & PAD_L2) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L2) : 0; pad_state[player] |= (state_tmp & PAD_L3) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L3) : 0;
pad_state[i] |= (state_tmp & PAD_R3) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R3) : 0;
pad_state[i] |= (state_tmp & PAD_L3) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L3) : 0; }
} }
} }
@ -147,6 +133,10 @@ static bool ps2_joypad_rumble(unsigned pad,
static void ps2_joypad_destroy(void) static void ps2_joypad_destroy(void)
{ {
unsigned port;
for (port = 0; port < PS2_MAX_PADS; port++) {
padPortClose(port, PS2_PAD_SLOT);
}
} }
input_device_driver_t ps2_joypad = { input_device_driver_t ps2_joypad = {