aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTwinaphex2016-06-18 19:15:13 +0200
committerGitHub2016-06-18 19:15:13 +0200
commit10ed51a07184f5235e1c85cd9995aaa1481e0dca (patch)
treef973933600949b9c5e4bc63f63bc2df075c08a33
parent05311a18fb23799776f9552614ef4c5fb5d852fa (diff)
parent73d32d69496795050589cb845ddbd1a074ca3955 (diff)
downloadpcsx_rearmed-10ed51a07184f5235e1c85cd9995aaa1481e0dca.tar.gz
pcsx_rearmed-10ed51a07184f5235e1c85cd9995aaa1481e0dca.tar.bz2
pcsx_rearmed-10ed51a07184f5235e1c85cd9995aaa1481e0dca.zip
Merge pull request #47 from alexis-puska/master
Suppress segmentation fault and crazy integer value.
-rw-r--r--frontend/plugin.c12
-rw-r--r--include/psemu_plugin_defs.h1
-rw-r--r--libpcsxcore/plugins.c34
-rw-r--r--libpcsxcore/plugins.h4
-rw-r--r--plugins/dfinput/main.c3
5 files changed, 31 insertions, 23 deletions
diff --git a/frontend/plugin.c b/frontend/plugin.c
index 5663e6d..8914519 100644
--- a/frontend/plugin.c
+++ b/frontend/plugin.c
@@ -49,7 +49,8 @@ extern void CALLBACK SPUasync(unsigned int, unsigned int);
extern int CALLBACK SPUplayCDDAchannel(short *, int);
/* PAD */
-static long PADreadPort1(PadDataS *pad, int pad_index) {
+static long PADreadPort1(PadDataS *pad) {
+ int pad_index = pad->requestPadIndex;
pad->controllerType = in_type[pad_index];
pad->buttonStatus = ~in_keystate[pad_index];
if (multitap1 == 1)
@@ -67,12 +68,9 @@ static long PADreadPort1(PadDataS *pad, int pad_index) {
return 0;
}
-static long PADreadPort2(PadDataS *pad, int pad_index) {
- /* Temporary hack to avoid segfault when pad_index is a crazy number */
- if (pad_index <= 1 || pad_index > 8) {
- pad_index = 1;
- }
-
+static long PADreadPort2(PadDataS *pad) {
+ int pad_index = pad->requestPadIndex;
+
pad->controllerType = in_type[pad_index];
pad->buttonStatus = ~in_keystate[pad_index];
if (multitap2 ==1 )
diff --git a/include/psemu_plugin_defs.h b/include/psemu_plugin_defs.h
index 034f21b..09e950a 100644
--- a/include/psemu_plugin_defs.h
+++ b/include/psemu_plugin_defs.h
@@ -198,6 +198,7 @@ typedef struct
//1 : multitap between psx and pad on port 1
//2 : multitap between psx and pad on port 2
int portMultitap;
+ int requestPadIndex;
// status of buttons - every controller fills this field
unsigned short buttonStatus;
diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c
index 8d3a00e..c9ccd2a 100644
--- a/libpcsxcore/plugins.c
+++ b/libpcsxcore/plugins.c
@@ -205,7 +205,7 @@ void CALLBACK GPU__vBlank(int val) {}
#define LoadGpuSym1(dest, name) \
LoadSym(GPU_##dest, GPU##dest, name, TRUE);
-
+
#define LoadGpuSym0(dest, name) \
LoadSym(GPU_##dest, GPU##dest, name, FALSE); \
if (GPU_##dest == NULL) GPU_##dest = (GPU##dest) GPU__##dest;
@@ -371,7 +371,7 @@ void *hPAD2Driver = NULL;
static int multitap1 = -1;
static int multitap2 = -1;
-static unsigned char buf[512];
+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 };
@@ -521,22 +521,25 @@ 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)
{
- PadDataS padd;
- PAD1_readPort1(&padd, 0);
+ PadDataS padd;
+ padd.requestPadIndex = 0;
+ PAD1_readPort1(&padd);
multitap1 = padd.portMultitap;
}
// just one pad is on port 1 : NO MULTITAP
if (multitap1 == 0)
{
- PadDataS padd;
- PAD1_readPort1(&padd, 0);
+ PadDataS padd;
+ padd.requestPadIndex = 0;
+ PAD1_readPort1(&padd);
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);
+ for(i = 0; i < 4; i++) {
+ padd[i].requestPadIndex = i;
+ PAD1_readPort1(&padd[i]);
}
return _PADstartPollMultitap(padd);
}
@@ -609,22 +612,25 @@ unsigned char CALLBACK PAD2__startPoll(int pad) {
}
//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);
+ PadDataS padd;
+ padd.requestPadIndex = pad_index;
+ PAD2_readPort2(&padd);
multitap2 = padd.portMultitap;
}
// just one pad is on port 2 : NO MULTITAP
if (multitap2 == 0){
- PadDataS padd;
- PAD2_readPort2(&padd,pad_index);
+ PadDataS padd;
+ padd.requestPadIndex = pad_index;
+ PAD2_readPort2(&padd);
return _PADstartPoll(&padd);
}else{
//a multitap is plugged : refresh all pad.
int i=0;
PadDataS padd[4];
- for(i=0;i<4;i++){
- PAD2_readPort2(&padd[i],i+pad_index);
+ for(i=0;i<4;i++){
+ padd[i].requestPadIndex = i+pad_index;
+ PAD2_readPort2(&padd[i]);
}
return _PADstartPollMultitap(padd);
}
diff --git a/libpcsxcore/plugins.h b/libpcsxcore/plugins.h
index 626939b..132df90 100644
--- a/libpcsxcore/plugins.h
+++ b/libpcsxcore/plugins.h
@@ -234,8 +234,8 @@ 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*, int pad_index);
-typedef long (CALLBACK* PADreadPort2)(PadDataS*, int pad_index);
+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);
diff --git a/plugins/dfinput/main.c b/plugins/dfinput/main.c
index c3adedd..ee4625c 100644
--- a/plugins/dfinput/main.c
+++ b/plugins/dfinput/main.c
@@ -58,9 +58,12 @@ 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);
}