Skip to content

Commit 38b5ad8

Browse files
Henrique194slouken
authored andcommitted
Fixed PS2 joystick analog sticks not enabled
(cherry picked from commit 8fa8c33)
1 parent d90c07a commit 38b5ad8

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/joystick/ps2/SDL_sysjoystick.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,66 @@ static SDL_JoystickID PS2_JoystickGetDeviceInstanceID(int device_index)
191191
return device_index + 1;
192192
}
193193

194+
static void PS2_WaitPadReady(int port, int slot)
195+
{
196+
int state = padGetState(port, slot);
197+
while ((state != PAD_STATE_STABLE) && (state != PAD_STATE_FINDCTP1)) {
198+
SDL_Delay(1);
199+
state = padGetState(port, slot);
200+
}
201+
}
202+
203+
static void PS2_InitializePad(int port, int slot)
204+
{
205+
int modes;
206+
int i;
207+
char actAlign[6];
208+
209+
PS2_WaitPadReady(port, slot);
210+
211+
// How many different modes can this device operate in?
212+
modes = padInfoMode(port, slot, PAD_MODETABLE, -1);
213+
214+
// Verify that the controller has a DUAL SHOCK mode
215+
for (i = 0; i < modes; i++) {
216+
if (padInfoMode(port, slot, PAD_MODETABLE, i) == PAD_TYPE_DUALSHOCK) {
217+
break;
218+
}
219+
}
220+
if (i >= modes) {
221+
// This is no Dual Shock controller
222+
return;
223+
}
224+
225+
// If ExId != 0x0 => This controller has actuator engines
226+
// This check should always pass if the Dual Shock test above passed
227+
if (!padInfoMode(port, slot, PAD_MODECUREXID, 0)) {
228+
// This is no Dual Shock controller??
229+
return;
230+
}
231+
232+
// When using MMODE_LOCK, user cant change mode with Select button
233+
padSetMainMode(port, slot, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK);
234+
235+
PS2_WaitPadReady(port, slot);
236+
padEnterPressMode(port, slot);
237+
238+
PS2_WaitPadReady(port, slot);
239+
if (padInfoAct(port, slot, -1, 0)) {
240+
actAlign[0] = 0; // Enable small engine
241+
actAlign[1] = 1; // Enable big engine
242+
actAlign[2] = 0xff;
243+
actAlign[3] = 0xff;
244+
actAlign[4] = 0xff;
245+
actAlign[5] = 0xff;
246+
247+
PS2_WaitPadReady(port, slot);
248+
padSetActAlign(port, slot, actAlign);
249+
}
250+
251+
PS2_WaitPadReady(port, slot);
252+
}
253+
194254
/* Function to open a joystick for use.
195255
The joystick to open is specified by the device index.
196256
This should fill the nbuttons and naxes fields of the joystick structure.
@@ -208,6 +268,8 @@ static bool PS2_JoystickOpen(SDL_Joystick *joystick, int device_index)
208268
return false;
209269
}
210270
}
271+
PS2_InitializePad(info->port, info->slot);
272+
211273
joystick->nbuttons = PS2_BUTTONS;
212274
joystick->naxes = PS2_TOTAL_AXIS;
213275
joystick->nhats = 0;

0 commit comments

Comments
 (0)