code refactor
authoralexis-puska <a.puska@ile-noire.com>
Sat, 2 Jul 2016 12:47:36 +0000 (14:47 +0200)
committeralexis-puska <a.puska@ile-noire.com>
Sat, 2 Jul 2016 12:47:36 +0000 (14:47 +0200)
Code refactor to build the response of request 0x42 read the pad key
state

libpcsxcore/plugins.c

index 64996b2..74b1925 100644 (file)
@@ -373,7 +373,8 @@ static int multitap2 = -1;
 //Pad information, keystate, mode, config mode, vibration\r
 static PadDataS pad[8];
 
-static int reqPos, respSize, req, ledStateReq44;\r
+static int reqPos, respSize, req;
+static int ledStateReq44[8];\r
 \r
 static unsigned char buf[256];\r
 unsigned char stdpar[8] = { 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\r
@@ -566,7 +567,7 @@ void reqIndex2Treatment(int padIndex, char value){
                        //0x44 store the led state for change mode if the next value = 0x02\r
                        //0x01 analog ON\r
                        //0x00 analog OFF\r
-                       ledStateReq44 = value;\r
+                       ledStateReq44[padIndex] = value;\r
                        break;\r
                case CMD_QUERY_ACT :\r
                        //0x46\r
@@ -598,72 +599,73 @@ void vibrate(int padIndex){
                plat_trigger_vibrate(padIndex, pad[padIndex].VibF[0], pad[padIndex].VibF[1]);
                printf("new value for vibration pad %i", padIndex);
        }
-}\r
-       
-\r
-\r
-//Build response for 0x42 request Multitap in port\r
-void _PADstartPollMultitap(PadDataS padd[4]) {\r
-    int i = 0;\r
-    int offset = 2;\r
-    PadDataS pad;\r
-    for(i = 0; i < 4; i++) {\r
-       offset = 2 + (i * 8);\r
-       pad = padd[i];\r
-               switch (pad.controllerType) {\r
-                       case PSE_PAD_TYPE_MOUSE:\r
-                               multitappar[offset] = 0x12;\r
-                               multitappar[offset + 1] = 0x5a;\r
-                               multitappar[offset + 2] = pad.buttonStatus & 0xff;\r
-                               multitappar[offset + 3] = pad.buttonStatus >> 8;\r
-                               multitappar[offset + 4] = pad.moveX;\r
-                               multitappar[offset + 5] = pad.moveY;\r
-\r
-                               break;\r
-                       case PSE_PAD_TYPE_NEGCON: // npc101/npc104(slph00001/slph00069)\r
-                               multitappar[offset] = 0x23;\r
-                               multitappar[offset + 1] = 0x5a;\r
-                               multitappar[offset + 2] = pad.buttonStatus & 0xff;\r
-                               multitappar[offset + 3] = pad.buttonStatus >> 8;\r
-                               multitappar[offset + 4] = pad.rightJoyX;\r
-                               multitappar[offset + 5] = pad.rightJoyY;\r
-                               multitappar[offset + 6] = pad.leftJoyX;\r
-                               multitappar[offset + 7] = pad.leftJoyY;\r
-\r
-                               break;\r
-                       case PSE_PAD_TYPE_ANALOGPAD: // scph1150\r
-                               multitappar[offset] = 0x73;\r
-                               multitappar[offset + 1] = 0x5a;\r
-                               multitappar[offset + 2] = pad.buttonStatus & 0xff;\r
-                               multitappar[offset + 3] = pad.buttonStatus >> 8;\r
-                               multitappar[offset + 4] = pad.rightJoyX;\r
-                               multitappar[offset + 5] = pad.rightJoyY;\r
-                               multitappar[offset + 6] = pad.leftJoyX;\r
-                               multitappar[offset + 7] = pad.leftJoyY;\r
-\r
-                               break;\r
-                       case PSE_PAD_TYPE_ANALOGJOY: // scph1110\r
-                               multitappar[offset] = 0x53;\r
-                               multitappar[offset + 1] = 0x5a;\r
-                               multitappar[offset + 2] = pad.buttonStatus & 0xff;\r
-                               multitappar[offset + 3] = pad.buttonStatus >> 8;\r
-                               multitappar[offset + 4] = pad.rightJoyX;\r
-                               multitappar[offset + 5] = pad.rightJoyY;\r
-                               multitappar[offset + 6] = pad.leftJoyX;\r
-                               multitappar[offset + 7] = pad.leftJoyY;\r
-\r
-                               break;\r
-                       case PSE_PAD_TYPE_STANDARD:\r
-                       default:\r
-                               multitappar[offset] = 0x41;\r
-                               multitappar[offset + 1] = 0x5a;\r
-                               multitappar[offset + 2] = pad.buttonStatus & 0xff;\r
-                               multitappar[offset + 3] = pad.buttonStatus >> 8;\r
-               }\r
-    }\r
-    memcpy(buf, multitappar, 34);\r
-    respSize = 34;\r
-}\r
+}
+
+//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;
+//}
+
+
 
 //Build response for 0x42 request Pad in port\r
 void _PADstartPoll(PadDataS *pad) {\r
@@ -711,15 +713,36 @@ void _PADstartPoll(PadDataS *pad) {
             respSize = 8;\r
             break;\r
         case PSE_PAD_TYPE_STANDARD:\r
-        default:\r
+        default:
+               stdpar[0] = 0x41;\r
             stdpar[2] = pad->buttonStatus & 0xff;\r
-            stdpar[3] = pad->buttonStatus >> 8;\r
+            stdpar[3] = pad->buttonStatus >> 8;
+            //avoid analog value in multitap mode if change pad type in game.
+            stdpar[4] = 0xff;
+            stdpar[5] = 0xff;
+            stdpar[6] = 0xff;
+            stdpar[7] = 0xff;\r
                memcpy(buf, stdpar, 4);\r
                respSize = 8;\r
     }\r
 }\r
 \r
-\r
+
+//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)\r
+void _PADstartPollMultitap(PadDataS padd[4]) {\r
+    int i = 0;\r
+    int offset = 2;\r
+    PadDataS pad;\r
+    for(i = 0; i < 4; i++) {\r
+       offset = 2 + (i * 8);\r
+       pad = padd[i];\r
+               _PADstartPoll(&pad);
+               memcpy(multitappar+offset, stdpar,pad.controllerType == PSE_PAD_TYPE_STANDARD ?4 : 8);\r
+    }\r
+    memcpy(buf, multitappar, 34);\r
+    respSize = 34;\r
+}\r
 \r
 unsigned char _PADpoll(int padIndex, unsigned char value) {
                \r
@@ -753,7 +776,7 @@ unsigned char _PADpoll(int padIndex, unsigned char value) {
                                \r
                        break;\r
                        }\r
-               }\r
+               }
        }\r
        return buf[reqPos++];\r
 }\r
@@ -791,7 +814,7 @@ unsigned char CALLBACK PAD1__startPoll(int pad) {
 \r
 unsigned char CALLBACK PAD1__poll(unsigned char value) {
        char tmp = _PADpoll(0, value);
-       printf("%2x:%2x , ",value,tmp);\r
+       printf("%2x:%2x, ",value,tmp);\r
        return tmp;\r
        \r
 }\r