Add dual shop request/response
authoralexis-puska <a.puska@ile-noire.com>
Sat, 2 Jul 2016 11:57:35 +0000 (13:57 +0200)
committeralexis-puska <a.puska@ile-noire.com>
Sat, 2 Jul 2016 11:57:35 +0000 (13:57 +0200)
Add dualshock request/response to declare Analog pad correctly and
retrieved the vibration information.

include/psemu_plugin_defs.h
libpcsxcore/plugins.c

index 09e950a..5c2fefe 100644 (file)
@@ -213,7 +213,9 @@ typedef struct
 
        unsigned char Vib[2];
        unsigned char VibF[2];
-
+       
+       //configuration mode Request 0x43
+       boolean configMode;
        unsigned char reserved[87];
 
 } PadDataS;
index c9ccd2a..64996b2 100644 (file)
@@ -370,169 +370,411 @@ void *hPAD2Driver = NULL;
 \r
 static int multitap1 = -1;\r
 static int multitap2 = -1;\r
+//Pad information, keystate, mode, config mode, vibration\r
+static PadDataS pad[8];
+
+static int reqPos, respSize, req, ledStateReq44;\r
 \r
 static unsigned char buf[256];\r
-unsigned char stdpar[10] = { 0x00, 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };\r
-unsigned char mousepar[8] = { 0x00, 0x12, 0x5a, 0xff, 0xff, 0xff, 0xff };\r
-unsigned char analogpar[9] = { 0x00, 0xff, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };\r
-unsigned char multitappar[35] = { 0x00, 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
-\r
-static int bufcount, bufc;\r
-\r
-//PadDataS padd1, padd2;\r
-unsigned char _PADstartPollMultitap(PadDataS padd[4]) {\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
+                                                                       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
+                                                                       \r
+//response for request 44, 45, 46, 47, 4C, 4D\r
+static unsigned char resp45[8]    = {0xF3, 0x5A, 0x01, 0x02, 0x00, 0x02, 0x01, 0x00};\r
+static unsigned char resp46_00[8] = {0xF3, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A};\r
+static unsigned char resp46_01[8] = {0xF3, 0x5A, 0x00, 0x00, 0x01, 0x01, 0x01, 0x14};\r
+static unsigned char resp47[8]    = {0xF3, 0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00};\r
+static unsigned char resp4C_00[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00};\r
+static unsigned char resp4C_01[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00};\r
+static unsigned char resp4D[8]    = {0xF3, 0x5A, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF};\r
+
+//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 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};
+static unsigned char resp4B[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char resp4E[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char resp4F[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+// Resquest of psx core
+enum {
+       // REQUEST
+       // first call of this request for the pad, the pad is configured as an digital pad.
+       // 0x0X, 0x42, 0x0Y, 0xZZ, 0xAA, 0x00, 0x00, 0x00, 0x00
+       // X pad number (used for the multitap, first request response 0x00, 0x80, 0x5A, (8 bytes pad A), (8 bytes pad B), (8 bytes pad C), (8 bytes pad D)
+       // Y if 1 : psx request the full length response for the multitap, 3 bytes header and 4 block of 8 bytes per pad
+       // Y if 0 : psx request a pad key state
+       // ZZ rumble small motor 00-> OFF, 01 -> ON
+       // AA rumble large motor speed 0x00 -> 0xFF
+       // RESPONSE
+       // header 3 Bytes
+       // 0x00 
+       // PadId -> 0x41 for digital pas, 0x73 for analog pad 
+       // 0x5A mode has not change (no press on analog button on the center of pad), 0x00 the analog button have been pressed and the mode switch
+       // 6 Bytes for keystates
+       CMD_READ_DATA_AND_VIBRATE = 0x42,
+       
+       // REQUEST
+       // Header
+       // 0x0N, 0x43, 0x00, XX, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+       // XX = 00 -> Normal mode : Seconde bytes of response = padId
+       // XX = 01 -> Configuration mode : Seconde bytes of response = 0xF3
+       // RESPONSE
+       // enter in config mode example : 
+       // req : 01 43 00 01 00 00 00 00 00 00
+       // res : 00 41 5A buttons state, analog states
+       // exit config mode : 
+       // req : 01 43 00 00 00 00 00 00 00 00
+       // res : 00 F3 5A buttons state, analog states
+       CMD_CONFIG_MODE = 0x43,
+       
+       // Set led State
+       // REQUEST
+       // 0x0N, 0x44, 0x00, VAL, SEL, 0x00, 0x00, 0x00, 0x00
+       // If sel = 2 then
+       // VAL = 00 -> OFF
+       // VAL = 01 -> ON
+       // RESPONSE
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+       CMD_SET_MODE_AND_LOCK = 0x44,
+       
+       // Get Analog Led state
+       // REQUEST
+       // 0x0N, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+       // RESPONSE
+       // 0x00, 0xF3, 0x5A, 0x01, 0x02, VAL, 0x02, 0x01, 0x00
+       // VAL = 00 Led OFF
+       // VAL = 01 Led ON
+       CMD_QUERY_MODEL_AND_MODE = 0x45,
+       
+       //Get Variable A
+       // REQUEST
+       // 0x0N, 0x46, 0x00, 0xXX, 0x00, 0x00, 0x00, 0x00, 0x00
+       // RESPONSE
+       // XX=00
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A
+       // XX=01
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x01, 0x01, 0x01, 0x14
+       CMD_QUERY_ACT = 0x46,
+       
+       // REQUEST
+       // 0x0N, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+       // RESPONSE
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00
+       CMD_QUERY_COMB = 0x47,
+       
+       // REQUEST
+       // 0x0N, 0x4C, 0x00, 0xXX, 0x00, 0x00, 0x00, 0x00, 0x00
+       // RESPONSE
+       // XX = 0
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00
+       // XX = 1
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00
+       CMD_QUERY_MODE = 0x4C,
+       
+       // REQUEST
+       // 0x0N, 0x4D, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
+       // RESPONSE
+       // 0x00, 0xF3, 0x5A, old value or
+       // AA = 01 unlock large motor (and swap VAL1 and VAL2)
+       // BB = 01 unlock large motor (default)
+       // CC, DD, EE, FF = all FF -> unlock small motor
+       //
+       // default repsonse for analog pad with 2 motor : 0x00 0xF3 0x5A 0x00 0x01 0xFF 0xFF 0xFF 0xFF
+       //
+       CMD_VIBRATION_TOGGLE = 0x4D,
+       REQ40 = 0x40,
+       REQ41 = 0x41,
+       REQ49 = 0x49,
+       REQ4A = 0x4A,
+       REQ4B = 0x4B,
+       REQ4E = 0x4E,
+       REQ4F = 0x4F
+};
+
+void initBufForRequest(int padIndex, char value){
+       switch (value){\r
+               //Pad keystate already in buffer\r
+               //case CMD_READ_DATA_AND_VIBRATE :\r
+               //      break;\r
+               case CMD_CONFIG_MODE :\r
+                       if(pad[padIndex].configMode == TRUE){\r
+                               buf[0] = 0xF3;
+                               buf[1] = 0x53;\r
+                       }\r
+                       //else, not in config mode, pad keystate return (already in the buffer)\r
+                       break;\r
+               case CMD_SET_MODE_AND_LOCK :\r
+                       memcpy(buf, resp44, 8);\r
+                       break;\r
+               case CMD_QUERY_MODEL_AND_MODE :\r
+                       memcpy(buf, resp45, 8);\r
+                       break;\r
+               case CMD_QUERY_ACT :\r
+                       memcpy(buf, resp46_00, 8);\r
+                       break;\r
+               case CMD_QUERY_COMB :\r
+                       memcpy(buf, resp47, 8);\r
+                       break;\r
+               case CMD_QUERY_MODE :\r
+                       memcpy(buf, resp4C_00, 8);\r
+                       break;\r
+               case CMD_VIBRATION_TOGGLE :\r
+                       memcpy(buf, resp4D, 8);\r
+                       break;\r
+               case REQ40 :\r
+                       memcpy(buf, resp40, 8);\r
+                       break;\r
+               case REQ41 :\r
+                       memcpy(buf, resp41, 8);\r
+                       break;\r
+               case REQ49 :\r
+                       memcpy(buf, resp49, 8);\r
+                       break;\r
+               case REQ4A :\r
+                       memcpy(buf, resp4A, 8);\r
+                       break;\r
+               case REQ4B :\r
+                       memcpy(buf, resp4B, 8);\r
+                       break;\r
+               case REQ4E :\r
+                       memcpy(buf, resp4E, 8);\r
+                       break;\r
+               case REQ4F :\r
+                       memcpy(buf, resp4F, 8);\r
+                       break;\r
+       }
+}\r
+\r
+void reqIndex2Treatment(int padIndex, char value){\r
+       switch (value){\r
+               case CMD_CONFIG_MODE :\r
+                       //0x43\r
+                       if(value == 0){\r
+                               pad[padIndex].configMode = FALSE;\r
+                       }else{\r
+                               pad->configMode = TRUE;\r
+                       }\r
+                       break;\r
+               case CMD_SET_MODE_AND_LOCK :\r
+                       //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
+                       break;\r
+               case CMD_QUERY_ACT :\r
+                       //0x46\r
+                       if(value==1){\r
+                               memcpy(buf, resp46_01, 8);\r
+                       }\r
+                       break;\r
+               \r
+               case CMD_QUERY_MODE :\r
+                       if(value==1){\r
+                               memcpy(buf, resp4C_01, 8);\r
+                       }\r
+                       break;\r
+               case CMD_VIBRATION_TOGGLE :\r
+                       //0x4D\r
+                       memcpy(buf, resp4D, 8);\r
+                       break;\r
+               case CMD_READ_DATA_AND_VIBRATE:\r
+                       //mem the vibration value for small motor;\r
+                       pad[padIndex].Vib[0] = value;
+       }\r
+}\r
+       
+void vibrate(int padIndex){
+       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);
+       }
+}\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
-    bufc = 0;\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 + 1] = 0x12;\r
-                               multitappar[offset + 2] = 0x5a;\r
-                               multitappar[offset + 3] = pad.buttonStatus & 0xff;\r
-                               multitappar[offset + 4] = pad.buttonStatus >> 8;\r
-                               multitappar[offset + 5] = pad.moveX;\r
-                               multitappar[offset + 6] = pad.moveY;\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 + 1] = 0x23;\r
-                               multitappar[offset + 2] = 0x5a;\r
-                               multitappar[offset + 3] = pad.buttonStatus & 0xff;\r
-                               multitappar[offset + 4] = pad.buttonStatus >> 8;\r
-                               multitappar[offset + 5] = pad.rightJoyX;\r
-                               multitappar[offset + 6] = pad.rightJoyY;\r
-                               multitappar[offset + 7] = pad.leftJoyX;\r
-                               multitappar[offset + 8] = pad.leftJoyY;\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 + 1] = 0x73;\r
-                               multitappar[offset + 2] = 0x5a;\r
-                               multitappar[offset + 3] = pad.buttonStatus & 0xff;\r
-                               multitappar[offset + 4] = pad.buttonStatus >> 8;\r
-                               multitappar[offset + 5] = pad.rightJoyX;\r
-                               multitappar[offset + 6] = pad.rightJoyY;\r
-                               multitappar[offset + 7] = pad.leftJoyX;\r
-                               multitappar[offset + 8] = pad.leftJoyY;\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 + 1] = 0x53;\r
-                               multitappar[offset + 2] = 0x5a;\r
-                               multitappar[offset + 3] = pad.buttonStatus & 0xff;\r
-                               multitappar[offset + 4] = pad.buttonStatus >> 8;\r
-                               multitappar[offset + 5] = pad.rightJoyX;\r
-                               multitappar[offset + 6] = pad.rightJoyY;\r
-                               multitappar[offset + 7] = pad.leftJoyX;\r
-                               multitappar[offset + 8] = pad.leftJoyY;\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 + 1] = 0x41;\r
-                               multitappar[offset + 2] = 0x5a;\r
-                               multitappar[offset + 3] = pad.buttonStatus & 0xff;\r
-                               multitappar[offset + 4] = pad.buttonStatus >> 8;\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
-\r
-    memcpy(buf, multitappar, 35);\r
-    bufcount = 34;\r
-\r
-    return buf[bufc++];\r
+    memcpy(buf, multitappar, 34);\r
+    respSize = 34;\r
 }\r
-\r
-unsigned char _PADstartPoll(PadDataS *pad) {\r
-\r
-    bufc = 0;\r
-\r
+
+//Build response for 0x42 request Pad in port\r
+void _PADstartPoll(PadDataS *pad) {\r
     switch (pad->controllerType) {\r
         case PSE_PAD_TYPE_MOUSE:\r
-            mousepar[3] = pad->buttonStatus & 0xff;\r
-            mousepar[4] = pad->buttonStatus >> 8;\r
-            mousepar[5] = pad->moveX;\r
-            mousepar[6] = pad->moveY;\r
-\r
-            memcpy(buf, mousepar, 7);\r
-            bufcount = 6;\r
+                       stdpar[0] = 0x12;\r
+            stdpar[2] = pad->buttonStatus & 0xff;\r
+            stdpar[3] = pad->buttonStatus >> 8;\r
+            stdpar[4] = pad->moveX;\r
+            stdpar[5] = pad->moveY;\r
+            memcpy(buf, stdpar, 6);\r
+            respSize = 6;\r
             break;\r
         case PSE_PAD_TYPE_NEGCON: // npc101/npc104(slph00001/slph00069)\r
-            analogpar[1] = 0x23;\r
-            analogpar[3] = pad->buttonStatus & 0xff;\r
-            analogpar[4] = pad->buttonStatus >> 8;\r
-            analogpar[5] = pad->rightJoyX;\r
-            analogpar[6] = pad->rightJoyY;\r
-            analogpar[7] = pad->leftJoyX;\r
-            analogpar[8] = pad->leftJoyY;\r
-\r
-            memcpy(buf, analogpar, 9);\r
-            bufcount = 8;\r
+            stdpar[0] = 0x23;\r
+            stdpar[2] = pad->buttonStatus & 0xff;\r
+            stdpar[3] = pad->buttonStatus >> 8;\r
+            stdpar[4] = pad->rightJoyX;\r
+            stdpar[5] = pad->rightJoyY;\r
+            stdpar[6] = pad->leftJoyX;\r
+            stdpar[7] = pad->leftJoyY;\r
+            memcpy(buf, stdpar, 8);\r
+            respSize = 8;\r
             break;\r
         case PSE_PAD_TYPE_ANALOGPAD: // scph1150\r
-            analogpar[1] = 0x73;\r
-            analogpar[3] = pad->buttonStatus & 0xff;\r
-            analogpar[4] = pad->buttonStatus >> 8;\r
-            analogpar[5] = pad->rightJoyX;\r
-            analogpar[6] = pad->rightJoyY;\r
-            analogpar[7] = pad->leftJoyX;\r
-            analogpar[8] = pad->leftJoyY;\r
-\r
-            memcpy(buf, analogpar, 9);\r
-            bufcount = 8;\r
+            stdpar[0] = 0x73;\r
+            stdpar[2] = pad->buttonStatus & 0xff;\r
+            stdpar[3] = pad->buttonStatus >> 8;\r
+            stdpar[4] = pad->rightJoyX;\r
+            stdpar[5] = pad->rightJoyY;\r
+            stdpar[6] = pad->leftJoyX;\r
+            stdpar[7] = pad->leftJoyY;\r
+            memcpy(buf, stdpar, 8);\r
+            respSize = 8;\r
             break;\r
         case PSE_PAD_TYPE_ANALOGJOY: // scph1110\r
-            analogpar[1] = 0x53;\r
-            analogpar[3] = pad->buttonStatus & 0xff;\r
-            analogpar[4] = pad->buttonStatus >> 8;\r
-            analogpar[5] = pad->rightJoyX;\r
-            analogpar[6] = pad->rightJoyY;\r
-            analogpar[7] = pad->leftJoyX;\r
-            analogpar[8] = pad->leftJoyY;\r
-\r
-            memcpy(buf, analogpar, 9);\r
-            bufcount = 8;\r
+            stdpar[0] = 0x53;\r
+            stdpar[2] = pad->buttonStatus & 0xff;\r
+            stdpar[3] = pad->buttonStatus >> 8;\r
+            stdpar[4] = pad->rightJoyX;\r
+            stdpar[5] = pad->rightJoyY;\r
+            stdpar[6] = pad->leftJoyX;\r
+            stdpar[7] = pad->leftJoyY;\r
+            memcpy(buf, stdpar, 8);\r
+            respSize = 8;\r
             break;\r
         case PSE_PAD_TYPE_STANDARD:\r
         default:\r
-            stdpar[3] = pad->buttonStatus & 0xff;\r
-            stdpar[4] = pad->buttonStatus >> 8;\r
-               memcpy(buf, stdpar, 5);\r
-               bufcount = 4;\r
+            stdpar[2] = pad->buttonStatus & 0xff;\r
+            stdpar[3] = pad->buttonStatus >> 8;\r
+               memcpy(buf, stdpar, 4);\r
+               respSize = 8;\r
     }\r
-\r
-    return buf[bufc++];\r
 }\r
 \r
-unsigned char _PADpoll(unsigned char value) {\r
-       if (bufc > bufcount) return 0;\r
-    return buf[bufc++];\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
+               \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
+       }\r
+       return buf[reqPos++];\r
 }\r
 \r
 // refresh the button state on port 1.\r
 // int pad is not needed.\r
-unsigned char CALLBACK PAD1__startPoll(int pad) {\r
+unsigned char CALLBACK PAD1__startPoll(int pad) {
+       reqPos = 0;\r
        // first call the pad provide if a multitap is connected between the psx and himself\r
-       if(multitap1 == -1)\r
-       {\r
+       if(multitap1 == -1){\r
                PadDataS padd;
                padd.requestPadIndex = 0;\r
                PAD1_readPort1(&padd);\r
                multitap1 = padd.portMultitap;\r
        }\r
        // just one pad is on port 1 : NO MULTITAP\r
-       if (multitap1 == 0)\r
-       {\r
+       if (multitap1 == 0){\r
                PadDataS padd;
                padd.requestPadIndex = 0;\r
                PAD1_readPort1(&padd);\r
-               return _PADstartPoll(&padd);\r
+               _PADstartPoll(&padd);\r
        } else {\r
                // a multitap is plugged : refresh all pad.\r
                int i=0;\r
@@ -540,27 +782,21 @@ unsigned char CALLBACK PAD1__startPoll(int pad) {
                for(i = 0; i < 4; i++) {
                        padd[i].requestPadIndex = i;\r
                        PAD1_readPort1(&padd[i]);\r
-               }\r
-               return _PADstartPollMultitap(padd);\r
-       }\r
+               }
+               _PADstartPollMultitap(padd);\r
+       }
+       printf("\n");
+       return 0x00;\r
 }\r
 \r
-unsigned char CALLBACK PAD1__poll(unsigned char value) {\r
-       if (multitap1 == 0)\r
-       {\r
-               return _PADpoll(value);\r
-       } else {\r
-               if(value == 42) {\r
-                       unsigned char bufmultitap[256];\r
-                       memcpy(bufmultitap, multitappar, 3);\r
-                       bufcount = 2;\r
-                       return bufmultitap[bufc++];\r
-               } else {\r
-                       return _PADpoll(value);\r
-               }\r
-       }\r
+unsigned char CALLBACK PAD1__poll(unsigned char value) {
+       char tmp = _PADpoll(0, value);
+       printf("%2x:%2x , ",value,tmp);\r
+       return tmp;\r
+       \r
 }\r
 \r
+\r
 long CALLBACK PAD1__configure(void) { return 0; }\r
 void CALLBACK PAD1__about(void) {}\r
 long CALLBACK PAD1__test(void) { return 0; }\r
@@ -603,60 +839,44 @@ static int LoadPAD1plugin(const char *PAD1dll) {
        return 0;\r
 }\r
 \r
-unsigned char CALLBACK PAD2__startPoll(int pad) {\r
-       int pad_index = 0;\r
-       if(multitap1 == 1){\r
-               pad_index+=4;\r
-       }else{\r
-               pad_index=1;\r
-       }\r
-       //first call the pad provide if a multitap is connected between the psx and himself\r
-       if(multitap2 == -1){\r
+unsigned char CALLBACK PAD2__startPoll(int pad) {
+       reqPos = 0;\r
+       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;
-               padd.requestPadIndex = pad_index;\r
-               PAD2_readPort2(&padd);\r
-               multitap2 = padd.portMultitap;\r
-       }\r
-\r
-       // just one pad is on port 2 : NO MULTITAP\r
-       if (multitap2 == 0){\r
+               padd.requestPadIndex = pad_index;
+               PAD2_readPort2(&padd);
+               multitap2 = padd.portMultitap;
+       }
+       \r
+       // just one pad is on port 1 : NO MULTITAP\r
+       if (multitap2 == 0){
                PadDataS padd;
-               padd.requestPadIndex = pad_index;\r
+               padd.requestPadIndex = pad_index;
                PAD2_readPort2(&padd);\r
-               return _PADstartPoll(&padd);\r
-       }else{\r
-               //a multitap is plugged : refresh all pad.\r
-               int i=0;\r
-               PadDataS padd[4];\r
+               _PADstartPoll(&padd);\r
+       } else {\r
+               // a multitap is plugged : refresh all pad.\r
+       //a multitap is plugged : refresh all pad.
+               int i=0;
+               PadDataS padd[4];
                for(i=0;i<4;i++){
-                       padd[i].requestPadIndex = i+pad_index;\r
-                       PAD2_readPort2(&padd[i]);\r
-               }\r
-               return _PADstartPollMultitap(padd);\r
-       }\r
+                       padd[i].requestPadIndex = i+pad_index;
+                       PAD2_readPort2(&padd[i]);
+               }
+               _PADstartPollMultitap(padd);\r
+       }
+       return 0x00;\r
 }\r
 \r
 unsigned char CALLBACK PAD2__poll(unsigned char value) {\r
-//     if(value !=0){\r
-//             int i;\r
-//             printf("%2x  %c\n", value, value);\r
-//             for (i = 0; i < 35; i++) {\r
-//               printf("%2x", buf[i]);\r
-//             }\r
-//             printf("\n");\r
-//             }\r
-       if(multitap2==0){\r
-               return _PADpoll(value);\r
-       }else {\r
-               if(value==42){\r
-                       unsigned char bufmultitap[256];\r
-                       memcpy(bufmultitap, multitappar, 3);\r
-                       bufcount = 2;\r
-                       return bufmultitap[bufc++];\r
-               }else{\r
-                       return _PADpoll(value);\r
-               }\r
-       }\r
+       return _PADpoll(1,value);\r
 }\r
 \r
 long CALLBACK PAD2__configure(void) { return 0; }\r