refactor some code + bug fix
authoralexis-puska <a.puska@ile-noire.com>
Sun, 3 Jul 2016 15:42:25 +0000 (17:42 +0200)
committeralexis-puska <a.puska@ile-noire.com>
Sun, 3 Jul 2016 15:42:25 +0000 (17:42 +0200)
libpcsxcore/plugins.c

index 6f5852b..9b6de03 100644 (file)
@@ -374,9 +374,15 @@ static int multitap2 = -1;
 static PadDataS pad[8];
 
 static int reqPos, respSize, req;
-static int ledStateReq44[8];\r
+static int ledStateReq44[8];
 \r
-static unsigned char buf[256];\r
+static unsigned char buf[256];
+static unsigned char bufMulti[34] = { 0x80, 0x5a, 
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+                                                                       \r
 unsigned char stdpar[8] = { 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\r
 unsigned char multitappar[34] = { 0x80, 0x5a, 
                                                                        0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
@@ -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};\r
+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};\r
 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,6 +506,11 @@ enum {
        REQ4F = 0x4F
 };
 
+
+
+
+//NO MULTITAP
+
 void initBufForRequest(int padIndex, char value){
        switch (value){\r
                //Pad keystate already in buffer\r
@@ -506,8 +518,8 @@ void initBufForRequest(int padIndex, char value){
                //      break;\r
                case CMD_CONFIG_MODE :\r
                        if(pad[padIndex].configMode == 1){\r
-                               buf[0] = 0xF3;
-                               buf[1] = 0x53;\r
+                               memcpy(buf, resp43, 8);\r
+                               break;\r
                        }\r
                        //else, not in config mode, pad keystate return (already in the buffer)\r
                        break;\r
@@ -551,16 +563,19 @@ void initBufForRequest(int padIndex, char value){
                        memcpy(buf, resp4F, 8);\r
                        break;\r
        }
-}\r
+}
+
+
+\r
 \r
 void reqIndex2Treatment(int padIndex, char value){\r
-       switch (value){\r
+       switch (req){\r
                case CMD_CONFIG_MODE :\r
                        //0x43\r
                        if(value == 0){\r
                                pad[padIndex].configMode = 0;\r
                        }else{\r
-                               pad->configMode = 1;\r
+                               pad[padIndex].configMode = 1;\r
                        }\r
                        break;\r
                case CMD_SET_MODE_AND_LOCK :\r
@@ -597,73 +612,10 @@ void vibrate(int padIndex){
                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;\r
-               memcpy(buf, stdpar, 4);\r
+               memcpy(buf, stdpar, 8);\r
                respSize = 8;\r
     }\r
 }\r
@@ -738,48 +690,52 @@ void _PADstartPollMultitap(PadDataS padd[4]) {
        offset = 2 + (i * 8);\r
        pad = padd[i];\r
                _PADstartPoll(&pad);
-               memcpy(multitappar+offset, stdpar,pad.controllerType == PSE_PAD_TYPE_STANDARD ?4 : 8);\r
+               memcpy(multitappar+offset, stdpar, 8);\r
     }\r
-    memcpy(buf, multitappar, 34);\r
+    memcpy(bufMulti, multitappar, 34);\r
     respSize = 34;\r
-}\r
+}
 \r
-unsigned char _PADpoll(int padIndex, unsigned char value) {
-               \r
-       //If no multitap on the port, we made the full implementation of dualshock protocol\r
-       if(multitap1 == 0){
-               if(reqPos==0){
-                       //mem the request number
-                       req = value;\r
-                       //copy the default value of request response in buffer instead of the keystate\r
-                       initBufForRequest(padIndex,value);
+\r
+unsigned char _PADpoll(int port, unsigned char value) {
+       if(reqPos==0){
+               //mem the request number
+               req = value;\r
+               //copy the default value of request response in buffer instead of the keystate\r
+               initBufForRequest(port,value);
+       }\r
+       \r
+       //if no new request the pad return 0xff, for signaling connected\r
+       if ( reqPos >= respSize) return 0xff;\r
+       \r
+       switch(reqPos){\r
+               case 2:\r
+                       reqIndex2Treatment(port, value);\r
+               break;\r
+               case 3:\r
+                       switch(req) {\r
+                               case CMD_SET_MODE_AND_LOCK :\r
+                                       //change mode on pad\r
+                               break;\r
+                               case CMD_READ_DATA_AND_VIBRATE:\r
+                               //mem the vibration value for Large motor;\r
+                               pad[port].Vib[1] = value;\r
+                               //vibration
+                               vibrate(port);\r
+                               break;\r
+                       \r
+               break;\r
                }\r
-               \r
-               //if no new request the pad return 0xff, for signaling connected\r
-               if ( reqPos >= respSize) return 0xff;\r
-               \r
-               switch(reqPos){\r
-                       case 2:\r
-                               reqIndex2Treatment(padIndex, value);\r
-                       break;\r
-                       case 3:\r
-                               switch(req) {\r
-                                       case CMD_SET_MODE_AND_LOCK :\r
-                                               //change mode on pad\r
-                                       break;\r
-                                       case CMD_READ_DATA_AND_VIBRATE:\r
-                                       //mem the vibration value for Large motor;\r
-                                       pad[padIndex].Vib[1] = value;\r
-                                       //vibration
-                                       vibrate(padIndex);\r
-                                       break;\r
-                               \r
-                       break;\r
-                       }\r
-               }
        }\r
        return buf[reqPos++];\r
-}\r
+}
+
+
+unsigned char _PADpollMultitap(int port, unsigned char value) {
+       if ( reqPos >= respSize) return 0xff;\r
+       return bufMulti[reqPos++];\r
+}
+\r
 \r
 // refresh the button state on port 1.\r
 // int pad is not needed.\r
@@ -808,12 +764,17 @@ unsigned char CALLBACK PAD1__startPoll(int pad) {
                }
                _PADstartPollMultitap(padd);\r
        }
-       printf("\n");
+       printf("\npad 1 : ");
        return 0x00;\r
 }\r
 \r
 unsigned char CALLBACK PAD1__poll(unsigned char value) {
-       char tmp = _PADpoll(0, value);
+       char tmp;
+       if(multitap1 == 1){
+               tmp = _PADpollMultitap(0, value);
+       }else{
+               tmp = _PADpoll(0, value);
+       }
        printf("%2x:%2x, ",value,tmp);\r
        return tmp;\r
        \r
@@ -865,10 +826,10 @@ static int LoadPAD1plugin(const char *PAD1dll) {
 unsigned char CALLBACK PAD2__startPoll(int pad) {
        reqPos = 0;\r
        int pad_index = 0;
-       if(multitap1 == 1){
-               pad_index+=4;
+       if(multitap2 == 2){
+               pad_index += 4;
        }else{
-               pad_index=1;
+               pad_index = 1;
        }
        //first call the pad provide if a multitap is connected between the psx and himself
        if(multitap2 == -1){
@@ -895,11 +856,19 @@ unsigned char CALLBACK PAD2__startPoll(int pad) {
                }
                _PADstartPollMultitap(padd);\r
        }
+       printf("\npad 2 : ");
        return 0x00;\r
 }\r
 \r
 unsigned char CALLBACK PAD2__poll(unsigned char value) {\r
-       return _PADpoll(1,value);\r
+       char tmp;
+       if(multitap2 == 2){
+               tmp = _PADpollMultitap(1, value);
+       }else{
+               tmp = _PADpoll(1, value);
+       }
+       printf("%2x:%2x, ",value,tmp);\r
+       return tmp;\r
 }\r
 \r
 long CALLBACK PAD2__configure(void) { return 0; }\r