X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fplugins.c;h=4937975bf986e21a87c009ef790036d20002aff3;hb=abaa8b9e916f689ba162a684c2e23890cea7d6da;hp=74b1925088a755d75e81f4ce243b39e6d42d8c4a;hpb=ef29671582c0ce9236a8ea96c5c07f04da8dab85;p=pcsx_rearmed.git diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index 74b19250..4937975b 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -374,9 +374,15 @@ static int multitap2 = -1; static PadDataS pad[8]; static int reqPos, respSize, req; -static int ledStateReq44[8]; +static int ledStateReq44[8]; -static unsigned char buf[256]; +static unsigned char buf[256]; +static unsigned char bufMulti[34] = { 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}; + unsigned char stdpar[8] = { 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; unsigned char multitappar[34] = { 0x80, 0x5a, 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -395,7 +401,8 @@ static unsigned char resp4D[8] = {0xF3, 0x5A, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0 //fixed reponse of request number 41, 48, 49, 4A, 4B, 4E, 4F static unsigned char resp40[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static unsigned char resp41[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static unsigned char resp41[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static unsigned char resp43[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; static unsigned char resp44[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; static unsigned char resp49[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; static unsigned char resp4A[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -499,15 +506,20 @@ enum { REQ4F = 0x4F }; + + + +//NO MULTITAP + void initBufForRequest(int padIndex, char value){ switch (value){ //Pad keystate already in buffer //case CMD_READ_DATA_AND_VIBRATE : // break; case CMD_CONFIG_MODE : - if(pad[padIndex].configMode == TRUE){ - buf[0] = 0xF3; - buf[1] = 0x53; + if (pad[padIndex].configMode == 1) { + memcpy(buf, resp43, 8); + break; } //else, not in config mode, pad keystate return (already in the buffer) break; @@ -551,16 +563,19 @@ void initBufForRequest(int padIndex, char value){ memcpy(buf, resp4F, 8); break; } -} +} + + + void reqIndex2Treatment(int padIndex, char value){ - switch (value){ + switch (req){ case CMD_CONFIG_MODE : //0x43 - if(value == 0){ - pad[padIndex].configMode = FALSE; - }else{ - pad->configMode = TRUE; + if (value == 0) { + pad[padIndex].configMode = 0; + } else { + pad[padIndex].configMode = 1; } break; case CMD_SET_MODE_AND_LOCK : @@ -571,13 +586,12 @@ void reqIndex2Treatment(int padIndex, char value){ break; case CMD_QUERY_ACT : //0x46 - if(value==1){ + if (value == 1) { memcpy(buf, resp46_01, 8); } break; - case CMD_QUERY_MODE : - if(value==1){ + if (value == 1) { memcpy(buf, resp4C_01, 8); } break; @@ -588,82 +602,20 @@ void reqIndex2Treatment(int padIndex, char value){ case CMD_READ_DATA_AND_VIBRATE: //mem the vibration value for small motor; pad[padIndex].Vib[0] = value; + break; } } void vibrate(int padIndex){ - if(pad[padIndex].Vib[0] != pad[padIndex].VibF[0] || pad[padIndex].Vib[1] != pad[padIndex].VibF[1]){ + if (pad[padIndex].Vib[0] != pad[padIndex].VibF[0] || pad[padIndex].Vib[1] != pad[padIndex].VibF[1]) { //value is different update Value and call libretro for vibration pad[padIndex].VibF[0] = pad[padIndex].Vib[0]; pad[padIndex].VibF[1] = pad[padIndex].Vib[1]; plat_trigger_vibrate(padIndex, pad[padIndex].VibF[0], pad[padIndex].VibF[1]); - printf("new value for vibration pad %i", padIndex); + //printf("vibration pad %i", padIndex); } } -//OLD FUNCTION -> DELETE if working -//Build response for 0x42 request Multitap in port -//void _PADstartPollMultitap(PadDataS padd[4]) { -// int i = 0; -// int offset = 2; -// PadDataS pad; -// for(i = 0; i < 4; i++) { -// offset = 2 + (i * 8); -// pad = padd[i]; -// switch (pad.controllerType) { -// case PSE_PAD_TYPE_MOUSE: -// multitappar[offset] = 0x12; -// multitappar[offset + 1] = 0x5a; -// multitappar[offset + 2] = pad.buttonStatus & 0xff; -// multitappar[offset + 3] = pad.buttonStatus >> 8; -// multitappar[offset + 4] = pad.moveX; -// multitappar[offset + 5] = pad.moveY; -// -// break; -// case PSE_PAD_TYPE_NEGCON: // npc101/npc104(slph00001/slph00069) -// multitappar[offset] = 0x23; -// multitappar[offset + 1] = 0x5a; -// multitappar[offset + 2] = pad.buttonStatus & 0xff; -// multitappar[offset + 3] = pad.buttonStatus >> 8; -// multitappar[offset + 4] = pad.rightJoyX; -// multitappar[offset + 5] = pad.rightJoyY; -// multitappar[offset + 6] = pad.leftJoyX; -// multitappar[offset + 7] = pad.leftJoyY; -// -// break; -// case PSE_PAD_TYPE_ANALOGPAD: // scph1150 -// multitappar[offset] = 0x73; -// multitappar[offset + 1] = 0x5a; -// multitappar[offset + 2] = pad.buttonStatus & 0xff; -// multitappar[offset + 3] = pad.buttonStatus >> 8; -// multitappar[offset + 4] = pad.rightJoyX; -// multitappar[offset + 5] = pad.rightJoyY; -// multitappar[offset + 6] = pad.leftJoyX; -// multitappar[offset + 7] = pad.leftJoyY; -// -// break; -// case PSE_PAD_TYPE_ANALOGJOY: // scph1110 -// multitappar[offset] = 0x53; -// multitappar[offset + 1] = 0x5a; -// multitappar[offset + 2] = pad.buttonStatus & 0xff; -// multitappar[offset + 3] = pad.buttonStatus >> 8; -// multitappar[offset + 4] = pad.rightJoyX; -// multitappar[offset + 5] = pad.rightJoyY; -// multitappar[offset + 6] = pad.leftJoyX; -// multitappar[offset + 7] = pad.leftJoyY; -// -// break; -// case PSE_PAD_TYPE_STANDARD: -// default: -// multitappar[offset] = 0x41; -// multitappar[offset + 1] = 0x5a; -// multitappar[offset + 2] = pad.buttonStatus & 0xff; -// multitappar[offset + 3] = pad.buttonStatus >> 8; -// } -// } -// memcpy(buf, multitappar, 34); -// respSize = 34; -//} @@ -722,7 +674,7 @@ void _PADstartPoll(PadDataS *pad) { stdpar[5] = 0xff; stdpar[6] = 0xff; stdpar[7] = 0xff; - memcpy(buf, stdpar, 4); + memcpy(buf, stdpar, 8); respSize = 8; } } @@ -730,77 +682,77 @@ void _PADstartPoll(PadDataS *pad) { //Build response for 0x42 request Multitap in port //Response header for multitap : 0x80, 0x5A, (Pad information port 1-2A), (Pad information port 1-2B), (Pad information port 1-2C), (Pad information port 1-2D) -void _PADstartPollMultitap(PadDataS padd[4]) { - int i = 0; - int offset = 2; - PadDataS pad; +void _PADstartPollMultitap(PadDataS* padd) { + int i, offset; for(i = 0; i < 4; i++) { offset = 2 + (i * 8); - pad = padd[i]; - _PADstartPoll(&pad); - memcpy(multitappar+offset, stdpar,pad.controllerType == PSE_PAD_TYPE_STANDARD ?4 : 8); + _PADstartPoll(&padd[i]); + memcpy(multitappar+offset, stdpar, 8); } - memcpy(buf, multitappar, 34); + memcpy(bufMulti, multitappar, 34); respSize = 34; -} +} -unsigned char _PADpoll(int padIndex, unsigned char value) { - - //If no multitap on the port, we made the full implementation of dualshock protocol - if(multitap1 == 0){ - if(reqPos==0){ - //mem the request number - req = value; - //copy the default value of request response in buffer instead of the keystate - initBufForRequest(padIndex,value); - } - - //if no new request the pad return 0xff, for signaling connected - if ( reqPos >= respSize) return 0xff; - - switch(reqPos){ - case 2: - reqIndex2Treatment(padIndex, value); - break; - case 3: - switch(req) { - case CMD_SET_MODE_AND_LOCK : - //change mode on pad - break; - case CMD_READ_DATA_AND_VIBRATE: - //mem the vibration value for Large motor; - pad[padIndex].Vib[1] = value; - //vibration - vibrate(padIndex); - break; - - break; + +unsigned char _PADpoll(int port, unsigned char value) { + if (reqPos == 0) { + //mem the request number + req = value; + //copy the default value of request response in buffer instead of the keystate + initBufForRequest(port, value); + } + + //if no new request the pad return 0xff, for signaling connected + if (reqPos >= respSize) return 0xff; + + switch(reqPos){ + case 2: + reqIndex2Treatment(port, value); + break; + case 3: + switch(req) { + case CMD_SET_MODE_AND_LOCK : + //change mode on pad + break; + case CMD_READ_DATA_AND_VIBRATE: + //mem the vibration value for Large motor; + pad[port].Vib[1] = value; + //vibration + vibrate(port); + break; } - } + break; } return buf[reqPos++]; -} +} + + +unsigned char _PADpollMultitap(int port, unsigned char value) { + if (reqPos >= respSize) return 0xff; + return bufMulti[reqPos++]; +} + // refresh the button state on port 1. // int pad is not needed. unsigned char CALLBACK PAD1__startPoll(int pad) { reqPos = 0; // first call the pad provide if a multitap is connected between the psx and himself - if(multitap1 == -1){ + if (multitap1 == -1) { PadDataS padd; padd.requestPadIndex = 0; PAD1_readPort1(&padd); multitap1 = padd.portMultitap; } // just one pad is on port 1 : NO MULTITAP - if (multitap1 == 0){ + if (multitap1 == 0) { PadDataS padd; padd.requestPadIndex = 0; PAD1_readPort1(&padd); _PADstartPoll(&padd); } else { // a multitap is plugged : refresh all pad. - int i=0; + int i; PadDataS padd[4]; for(i = 0; i < 4; i++) { padd[i].requestPadIndex = i; @@ -808,13 +760,18 @@ unsigned char CALLBACK PAD1__startPoll(int pad) { } _PADstartPollMultitap(padd); } - printf("\n"); + //printf("\npad 1 : "); return 0x00; } unsigned char CALLBACK PAD1__poll(unsigned char value) { - char tmp = _PADpoll(0, value); - printf("%2x:%2x, ",value,tmp); + char tmp; + if (multitap1 == 1) { + tmp = _PADpollMultitap(0, value); + } else { + tmp = _PADpoll(0, value); + } + //printf("%2x:%2x, ",value,tmp); return tmp; } @@ -863,15 +820,19 @@ static int LoadPAD1plugin(const char *PAD1dll) { } unsigned char CALLBACK PAD2__startPoll(int pad) { + int pad_index; + reqPos = 0; - int pad_index = 0; - if(multitap1 == 1){ - pad_index+=4; - }else{ - pad_index=1; + if (multitap1 == 0 && (multitap2 == 0 || multitap2 == 2)) { + pad_index = 1; + } else if(multitap1 == 1 && (multitap2 == 0 || multitap2 == 2)) { + pad_index = 4; + } else { + pad_index = 0; } + //first call the pad provide if a multitap is connected between the psx and himself - if(multitap2 == -1){ + if (multitap2 == -1) { PadDataS padd; padd.requestPadIndex = pad_index; PAD2_readPort2(&padd); @@ -879,27 +840,34 @@ unsigned char CALLBACK PAD2__startPoll(int pad) { } // just one pad is on port 1 : NO MULTITAP - if (multitap2 == 0){ + if (multitap2 == 0) { PadDataS padd; padd.requestPadIndex = pad_index; PAD2_readPort2(&padd); _PADstartPoll(&padd); } else { // a multitap is plugged : refresh all pad. - //a multitap is plugged : refresh all pad. - int i=0; + int i; PadDataS padd[4]; - for(i=0;i<4;i++){ + for(i = 0; i < 4; i++) { padd[i].requestPadIndex = i+pad_index; PAD2_readPort2(&padd[i]); } _PADstartPollMultitap(padd); } + //printf("\npad 2 : "); return 0x00; } unsigned char CALLBACK PAD2__poll(unsigned char value) { - return _PADpoll(1,value); + char tmp; + if (multitap2 == 2) { + tmp = _PADpollMultitap(1, value); + } else { + tmp = _PADpoll(1, value); + } + //printf("%2x:%2x, ",value,tmp); + return tmp; } long CALLBACK PAD2__configure(void) { return 0; }