From 61c4962abc49e430aabea5e565d93436a57cfa0a Mon Sep 17 00:00:00 2001 From: alexis-puska Date: Mon, 9 May 2016 10:33:05 +0100 Subject: Initial multitap support --- libpcsxcore/plugins.c | 125 ++++++++++++++++++++++++++++++++++++++++++++------ libpcsxcore/plugins.h | 2 +- 2 files changed, 113 insertions(+), 14 deletions(-) (limited to 'libpcsxcore') diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index e6d8a11..3f8a09c 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -372,12 +372,86 @@ static unsigned char buf[256]; unsigned char stdpar[10] = { 0x00, 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; unsigned char mousepar[8] = { 0x00, 0x12, 0x5a, 0xff, 0xff, 0xff, 0xff }; unsigned char analogpar[9] = { 0x00, 0xff, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; +unsigned char multitappar[35] = { 0x00, 0x80, 0x5a, 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; static int bufcount, bufc; -PadDataS padd1, padd2; +//PadDataS padd1, padd2; + +unsigned char _PADstartPollPort1(PadDataS padd[4]) { + int i=0; + int decallage=2; + bufc = 0; + PadDataS pad; + for(i=0;i<4;i++){ + decallage = 2 + (i*8); + pad = padd[i]; + switch (pad.controllerType) { + case PSE_PAD_TYPE_MOUSE: + multitappar[decallage+1] = 0x12; + multitappar[decallage+2] = 0x5a; + multitappar[decallage+3] = pad.buttonStatus & 0xff; + multitappar[decallage+4] = pad.buttonStatus >> 8; + multitappar[decallage+5] = pad.moveX; + multitappar[decallage+6] = pad.moveY; + + break; + case PSE_PAD_TYPE_NEGCON: // npc101/npc104(slph00001/slph00069) + multitappar[decallage+1] = 0x23; + multitappar[decallage+2] = 0x5a; + multitappar[decallage+3] = pad.buttonStatus & 0xff; + multitappar[decallage+4] = pad.buttonStatus >> 8; + multitappar[decallage+5] = pad.rightJoyX; + multitappar[decallage+6] = pad.rightJoyY; + multitappar[decallage+7] = pad.leftJoyX; + multitappar[decallage+8] = pad.leftJoyY; + + break; + case PSE_PAD_TYPE_ANALOGPAD: // scph1150 + multitappar[decallage+1] = 0x73; + multitappar[decallage+2] = 0x5a; + multitappar[decallage+3] = pad.buttonStatus & 0xff; + multitappar[decallage+4] = pad.buttonStatus >> 8; + multitappar[decallage+5] = pad.rightJoyX; + multitappar[decallage+6] = pad.rightJoyY; + multitappar[decallage+7] = pad.leftJoyX; + multitappar[decallage+8] = pad.leftJoyY; + + break; + case PSE_PAD_TYPE_ANALOGJOY: // scph1110 + multitappar[decallage+1] = 0x53; + multitappar[decallage+2] = 0x5a; + multitappar[decallage+3] = pad.buttonStatus & 0xff; + multitappar[decallage+4] = pad.buttonStatus >> 8; + multitappar[decallage+5] = pad.rightJoyX; + multitappar[decallage+6] = pad.rightJoyY; + multitappar[decallage+7] = pad.leftJoyX; + multitappar[decallage+8] = pad.leftJoyY; + + break; + case PSE_PAD_TYPE_STANDARD: + default: + multitappar[decallage+1] = 0x41; + multitappar[decallage+2] = 0x5a; + multitappar[decallage+3] = pad.buttonStatus & 0xff; + multitappar[decallage+4] = pad.buttonStatus >> 8; + } + } + + memcpy(buf, multitappar, 35); + bufcount = 34; + + return buf[bufc++]; +} + + + unsigned char _PADstartPoll(PadDataS *pad) { + bufc = 0; switch (pad->controllerType) { @@ -430,35 +504,60 @@ unsigned char _PADstartPoll(PadDataS *pad) { default: stdpar[3] = pad->buttonStatus & 0xff; stdpar[4] = pad->buttonStatus >> 8; - - memcpy(buf, stdpar, 5); - bufcount = 4; + memcpy(buf, stdpar, 5); + bufcount = 4; } + return buf[bufc++]; } + + + unsigned char _PADpoll(unsigned char value) { - if (bufc > bufcount) return 0; + if (bufc > bufcount) return 0; return buf[bufc++]; } +// rafraichissement de l'état des boutons sur port 1, +// int pad dans le code d'origine ne sert a rien... unsigned char CALLBACK PAD1__startPoll(int pad) { - PadDataS padd; - - PAD1_readPort1(&padd); - - return _PADstartPoll(&padd); + int i=0; + PadDataS padd[4]; + for(i=0;i<4;i++){ + PAD1_readPort1(&padd[i],i); + } + return _PADstartPollPort1(padd); } unsigned char CALLBACK PAD1__poll(unsigned char value) { - return _PADpoll(value); + +// if(value !=0){ +// int i; +// printf("%2x %c\n", value, value); +// for (i = 0; i < 35; i++) { +// printf("%2x", buf[i]); +// } +// printf("\n"); +// } + + if(value==42){ + unsigned char bufmultitap[256]; + memcpy(bufmultitap, multitappar, 3); + bufcount = 2; + return bufmultitap[bufc++]; + }else{ + return _PADpoll(value); + } } long CALLBACK PAD1__configure(void) { return 0; } void CALLBACK PAD1__about(void) {} long CALLBACK PAD1__test(void) { return 0; } -long CALLBACK PAD1__query(void) { return 3; } +long CALLBACK PAD1__query(void) { + printf("PAD1__query"); + return 3; } long CALLBACK PAD1__keypressed() { return 0; } #define LoadPad1Sym1(dest, name) \ @@ -500,7 +599,7 @@ static int LoadPAD1plugin(const char *PAD1dll) { unsigned char CALLBACK PAD2__startPoll(int pad) { PadDataS padd; - PAD2_readPort2(&padd); + PAD2_readPort2(&padd); return _PADstartPoll(&padd); } diff --git a/libpcsxcore/plugins.h b/libpcsxcore/plugins.h index 132df90..4f0c4fa 100644 --- a/libpcsxcore/plugins.h +++ b/libpcsxcore/plugins.h @@ -234,7 +234,7 @@ typedef long (CALLBACK* PADshutdown)(void); typedef long (CALLBACK* PADtest)(void); typedef long (CALLBACK* PADclose)(void); typedef long (CALLBACK* PADquery)(void); -typedef long (CALLBACK* PADreadPort1)(PadDataS*); +typedef long (CALLBACK* PADreadPort1)(PadDataS*, int pad_index); typedef long (CALLBACK* PADreadPort2)(PadDataS*); typedef long (CALLBACK* PADkeypressed)(void); typedef unsigned char (CALLBACK* PADstartPoll)(int); -- cgit v1.2.3 From ace14ab3172ad90809a3cc5e8fe67d5cac9e294b Mon Sep 17 00:00:00 2001 From: cbransden Date: Mon, 9 May 2016 10:39:45 +0100 Subject: Added multitap core option & style nits --- libpcsxcore/plugins.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'libpcsxcore') diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index 3f8a09c..372fdd0 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -380,7 +380,6 @@ unsigned char multitappar[35] = { 0x00, 0x80, 0x5a, 0x41, 0x5a, 0xff, 0xff, 0xff static int bufcount, bufc; //PadDataS padd1, padd2; - unsigned char _PADstartPollPort1(PadDataS padd[4]) { int i=0; int decallage=2; @@ -447,9 +446,6 @@ unsigned char _PADstartPollPort1(PadDataS padd[4]) { return buf[bufc++]; } - - - unsigned char _PADstartPoll(PadDataS *pad) { bufc = 0; @@ -508,13 +504,9 @@ unsigned char _PADstartPoll(PadDataS *pad) { bufcount = 4; } - return buf[bufc++]; } - - - unsigned char _PADpoll(unsigned char value) { if (bufc > bufcount) return 0; return buf[bufc++]; @@ -599,7 +591,7 @@ static int LoadPAD1plugin(const char *PAD1dll) { unsigned char CALLBACK PAD2__startPoll(int pad) { PadDataS padd; - PAD2_readPort2(&padd); + PAD2_readPort2(&padd); return _PADstartPoll(&padd); } -- cgit v1.2.3 From 29f3675b9b2f24b8a16db73588b8b04d628eabd8 Mon Sep 17 00:00:00 2001 From: alexis-puska Date: Thu, 12 May 2016 01:45:26 +0200 Subject: second implementation of multitap add game/core option to enabled or disabled multitap. Test with micro machine V3 and 5 devices, 2 multitap enabled, all device react good i can’t test the 6 7 8 select player but i can select 8 gamer. The 2 multitap works fine. i detect a bug, when we change the game pad type to analog, the library crash, see it next time --- libpcsxcore/plugins.c | 104 +++++++++++++++++++++++++++++++++++++++----------- libpcsxcore/plugins.h | 2 +- 2 files changed, 82 insertions(+), 24 deletions(-) (limited to 'libpcsxcore') diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index 372fdd0..3d0ed3c 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -368,7 +368,10 @@ static int LoadSPUplugin(const char *SPUdll) { void *hPAD1Driver = NULL; void *hPAD2Driver = NULL; -static unsigned char buf[256]; +static int multitap1 = -1; +static int multitap2 = -1; + +static unsigned char buf[512]; unsigned char stdpar[10] = { 0x00, 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; unsigned char mousepar[8] = { 0x00, 0x12, 0x5a, 0xff, 0xff, 0xff, 0xff }; unsigned char analogpar[9] = { 0x00, 0xff, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; @@ -380,7 +383,7 @@ unsigned char multitappar[35] = { 0x00, 0x80, 0x5a, 0x41, 0x5a, 0xff, 0xff, 0xff static int bufcount, bufc; //PadDataS padd1, padd2; -unsigned char _PADstartPollPort1(PadDataS padd[4]) { +unsigned char _PADstartPollMultitap(PadDataS padd[4]) { int i=0; int decallage=2; bufc = 0; @@ -515,16 +518,29 @@ unsigned char _PADpoll(unsigned char value) { // rafraichissement de l'état des boutons sur port 1, // int pad dans le code d'origine ne sert a rien... unsigned char CALLBACK PAD1__startPoll(int pad) { - int i=0; - PadDataS padd[4]; - for(i=0;i<4;i++){ - PAD1_readPort1(&padd[i],i); + //first call the pad provide if a multitap is connected between the psx and himself + if(multitap1 == -1){ + PadDataS padd; + PAD1_readPort1(&padd,0); + multitap1 = padd.portMultitap; + } + // just one pad is on port 1 : NO MULTITAP + if (multitap1 == 0){ + PadDataS padd; + PAD1_readPort1(&padd,0); + return _PADstartPoll(&padd); + }else{ + //a multitap is plugged : refresh all pad. + int i=0; + PadDataS padd[4]; + for(i=0;i<4;i++){ + PAD1_readPort1(&padd[i],i); + } + return _PADstartPollMultitap(padd); } - return _PADstartPollPort1(padd); } unsigned char CALLBACK PAD1__poll(unsigned char value) { - // if(value !=0){ // int i; // printf("%2x %c\n", value, value); @@ -533,23 +549,24 @@ unsigned char CALLBACK PAD1__poll(unsigned char value) { // } // printf("\n"); // } - - if(value==42){ - unsigned char bufmultitap[256]; - memcpy(bufmultitap, multitappar, 3); - bufcount = 2; - return bufmultitap[bufc++]; - }else{ + if(multitap1==0){ return _PADpoll(value); + }else{ + if(value==42){ + unsigned char bufmultitap[256]; + memcpy(bufmultitap, multitappar, 3); + bufcount = 2; + return bufmultitap[bufc++]; + }else{ + return _PADpoll(value); + } } } long CALLBACK PAD1__configure(void) { return 0; } void CALLBACK PAD1__about(void) {} long CALLBACK PAD1__test(void) { return 0; } -long CALLBACK PAD1__query(void) { - printf("PAD1__query"); - return 3; } +long CALLBACK PAD1__query(void) { return 3; } long CALLBACK PAD1__keypressed() { return 0; } #define LoadPad1Sym1(dest, name) \ @@ -589,15 +606,56 @@ static int LoadPAD1plugin(const char *PAD1dll) { } unsigned char CALLBACK PAD2__startPoll(int pad) { - PadDataS padd; + int pad_index = 0; + if(multitap1 == 1){ + pad_index+=4; + }else{ + pad_index=1; + } + //first call the pad provide if a multitap is connected between the psx and himself + if(multitap2 == -1){ + PadDataS padd; + PAD2_readPort2(&padd,pad_index); + multitap2 = padd.portMultitap; + } - PAD2_readPort2(&padd); - - return _PADstartPoll(&padd); + // just one pad is on port 2 : NO MULTITAP + if (multitap2 == 0){ + PadDataS padd; + PAD2_readPort2(&padd,pad_index); + return _PADstartPoll(&padd); + }else{ + //a multitap is plugged : refresh all pad. + int i=pad_index; + PadDataS padd[4]; + for(i=0;i<4;i++){ + PAD2_readPort2(&padd[i],i+pad_index); + } + return _PADstartPollMultitap(padd); + } } unsigned char CALLBACK PAD2__poll(unsigned char value) { - return _PADpoll(value); +// if(value !=0){ +// int i; +// printf("%2x %c\n", value, value); +// for (i = 0; i < 35; i++) { +// printf("%2x", buf[i]); +// } +// printf("\n"); +// } + if(multitap2==0){ + return _PADpoll(value); + }else { + if(value==42){ + unsigned char bufmultitap[256]; + memcpy(bufmultitap, multitappar, 3); + bufcount = 2; + return bufmultitap[bufc++]; + }else{ + return _PADpoll(value); + } + } } long CALLBACK PAD2__configure(void) { return 0; } diff --git a/libpcsxcore/plugins.h b/libpcsxcore/plugins.h index 4f0c4fa..626939b 100644 --- a/libpcsxcore/plugins.h +++ b/libpcsxcore/plugins.h @@ -235,7 +235,7 @@ typedef long (CALLBACK* PADtest)(void); typedef long (CALLBACK* PADclose)(void); typedef long (CALLBACK* PADquery)(void); typedef long (CALLBACK* PADreadPort1)(PadDataS*, int pad_index); -typedef long (CALLBACK* PADreadPort2)(PadDataS*); +typedef long (CALLBACK* PADreadPort2)(PadDataS*, int pad_index); typedef long (CALLBACK* PADkeypressed)(void); typedef unsigned char (CALLBACK* PADstartPoll)(int); typedef unsigned char (CALLBACK* PADpoll)(unsigned char); -- cgit v1.2.3 From bebaef4be9a87d92b11bc29a002a531a9d1fa5d7 Mon Sep 17 00:00:00 2001 From: dankcushions Date: Fri, 13 May 2016 16:21:37 +0100 Subject: Defensive code to avoid SEGFAULT --- libpcsxcore/plugins.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libpcsxcore') diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index 3d0ed3c..1369b1c 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -384,8 +384,8 @@ static int bufcount, bufc; //PadDataS padd1, padd2; unsigned char _PADstartPollMultitap(PadDataS padd[4]) { - int i=0; - int decallage=2; + int i=0; + int decallage=2; bufc = 0; PadDataS pad; for(i=0;i<4;i++){ @@ -626,7 +626,7 @@ unsigned char CALLBACK PAD2__startPoll(int pad) { return _PADstartPoll(&padd); }else{ //a multitap is plugged : refresh all pad. - int i=pad_index; + int i=0; PadDataS padd[4]; for(i=0;i<4;i++){ PAD2_readPort2(&padd[i],i+pad_index); -- cgit v1.2.3 From 3b1a5e21b399fcb38c5d8ead3c16603f566d7ffa Mon Sep 17 00:00:00 2001 From: cbransden Date: Fri, 13 May 2016 17:50:34 +0100 Subject: Style nits --- libpcsxcore/plugins.c | 117 ++++++++++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 61 deletions(-) (limited to 'libpcsxcore') diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index 1369b1c..8d3a00e 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -384,62 +384,62 @@ static int bufcount, bufc; //PadDataS padd1, padd2; unsigned char _PADstartPollMultitap(PadDataS padd[4]) { - int i=0; - int decallage=2; + int i = 0; + int offset = 2; bufc = 0; PadDataS pad; - for(i=0;i<4;i++){ - decallage = 2 + (i*8); + for(i = 0; i < 4; i++) { + offset = 2 + (i * 8); pad = padd[i]; switch (pad.controllerType) { case PSE_PAD_TYPE_MOUSE: - multitappar[decallage+1] = 0x12; - multitappar[decallage+2] = 0x5a; - multitappar[decallage+3] = pad.buttonStatus & 0xff; - multitappar[decallage+4] = pad.buttonStatus >> 8; - multitappar[decallage+5] = pad.moveX; - multitappar[decallage+6] = pad.moveY; + multitappar[offset + 1] = 0x12; + multitappar[offset + 2] = 0x5a; + multitappar[offset + 3] = pad.buttonStatus & 0xff; + multitappar[offset + 4] = pad.buttonStatus >> 8; + multitappar[offset + 5] = pad.moveX; + multitappar[offset + 6] = pad.moveY; break; case PSE_PAD_TYPE_NEGCON: // npc101/npc104(slph00001/slph00069) - multitappar[decallage+1] = 0x23; - multitappar[decallage+2] = 0x5a; - multitappar[decallage+3] = pad.buttonStatus & 0xff; - multitappar[decallage+4] = pad.buttonStatus >> 8; - multitappar[decallage+5] = pad.rightJoyX; - multitappar[decallage+6] = pad.rightJoyY; - multitappar[decallage+7] = pad.leftJoyX; - multitappar[decallage+8] = pad.leftJoyY; + multitappar[offset + 1] = 0x23; + multitappar[offset + 2] = 0x5a; + multitappar[offset + 3] = pad.buttonStatus & 0xff; + multitappar[offset + 4] = pad.buttonStatus >> 8; + multitappar[offset + 5] = pad.rightJoyX; + multitappar[offset + 6] = pad.rightJoyY; + multitappar[offset + 7] = pad.leftJoyX; + multitappar[offset + 8] = pad.leftJoyY; break; case PSE_PAD_TYPE_ANALOGPAD: // scph1150 - multitappar[decallage+1] = 0x73; - multitappar[decallage+2] = 0x5a; - multitappar[decallage+3] = pad.buttonStatus & 0xff; - multitappar[decallage+4] = pad.buttonStatus >> 8; - multitappar[decallage+5] = pad.rightJoyX; - multitappar[decallage+6] = pad.rightJoyY; - multitappar[decallage+7] = pad.leftJoyX; - multitappar[decallage+8] = pad.leftJoyY; + multitappar[offset + 1] = 0x73; + multitappar[offset + 2] = 0x5a; + multitappar[offset + 3] = pad.buttonStatus & 0xff; + multitappar[offset + 4] = pad.buttonStatus >> 8; + multitappar[offset + 5] = pad.rightJoyX; + multitappar[offset + 6] = pad.rightJoyY; + multitappar[offset + 7] = pad.leftJoyX; + multitappar[offset + 8] = pad.leftJoyY; break; case PSE_PAD_TYPE_ANALOGJOY: // scph1110 - multitappar[decallage+1] = 0x53; - multitappar[decallage+2] = 0x5a; - multitappar[decallage+3] = pad.buttonStatus & 0xff; - multitappar[decallage+4] = pad.buttonStatus >> 8; - multitappar[decallage+5] = pad.rightJoyX; - multitappar[decallage+6] = pad.rightJoyY; - multitappar[decallage+7] = pad.leftJoyX; - multitappar[decallage+8] = pad.leftJoyY; + multitappar[offset + 1] = 0x53; + multitappar[offset + 2] = 0x5a; + multitappar[offset + 3] = pad.buttonStatus & 0xff; + multitappar[offset + 4] = pad.buttonStatus >> 8; + multitappar[offset + 5] = pad.rightJoyX; + multitappar[offset + 6] = pad.rightJoyY; + multitappar[offset + 7] = pad.leftJoyX; + multitappar[offset + 8] = pad.leftJoyY; break; case PSE_PAD_TYPE_STANDARD: default: - multitappar[decallage+1] = 0x41; - multitappar[decallage+2] = 0x5a; - multitappar[decallage+3] = pad.buttonStatus & 0xff; - multitappar[decallage+4] = pad.buttonStatus >> 8; + multitappar[offset + 1] = 0x41; + multitappar[offset + 2] = 0x5a; + multitappar[offset + 3] = pad.buttonStatus & 0xff; + multitappar[offset + 4] = pad.buttonStatus >> 8; } } @@ -515,49 +515,44 @@ unsigned char _PADpoll(unsigned char value) { return buf[bufc++]; } -// rafraichissement de l'état des boutons sur port 1, -// int pad dans le code d'origine ne sert a rien... +// refresh the button state on port 1. +// int pad is not needed. unsigned char CALLBACK PAD1__startPoll(int pad) { - //first call the pad provide if a multitap is connected between the psx and himself - if(multitap1 == -1){ + // first call the pad provide if a multitap is connected between the psx and himself + if(multitap1 == -1) + { PadDataS padd; - PAD1_readPort1(&padd,0); + PAD1_readPort1(&padd, 0); multitap1 = padd.portMultitap; } // just one pad is on port 1 : NO MULTITAP - if (multitap1 == 0){ + if (multitap1 == 0) + { PadDataS padd; - PAD1_readPort1(&padd,0); + PAD1_readPort1(&padd, 0); return _PADstartPoll(&padd); - }else{ - //a multitap is plugged : refresh all pad. + } else { + // a multitap is plugged : refresh all pad. int i=0; PadDataS padd[4]; - for(i=0;i<4;i++){ - PAD1_readPort1(&padd[i],i); + for(i = 0; i < 4; i++) { + PAD1_readPort1(&padd[i], i); } return _PADstartPollMultitap(padd); } } unsigned char CALLBACK PAD1__poll(unsigned char value) { -// if(value !=0){ -// int i; -// printf("%2x %c\n", value, value); -// for (i = 0; i < 35; i++) { -// printf("%2x", buf[i]); -// } -// printf("\n"); -// } - if(multitap1==0){ + if (multitap1 == 0) + { return _PADpoll(value); - }else{ - if(value==42){ + } else { + if(value == 42) { unsigned char bufmultitap[256]; memcpy(bufmultitap, multitappar, 3); bufcount = 2; return bufmultitap[bufc++]; - }else{ + } else { return _PADpoll(value); } } -- cgit v1.2.3