forked from mbacker80/-PS2-LiveDebug-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pad.c
104 lines (79 loc) · 1.9 KB
/
pad.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#define ROM_PADMAN
#if defined(ROM_PADMAN) && defined(NEW_PADMAN)
#error Only one of ROM_PADMAN & NEW_PADMAN should be defined!
#endif
#if !defined(ROM_PADMAN) && !defined(NEW_PADMAN)
#error ROM_PADMAN or NEW_PADMAN must be defined!
#endif
static char padBuf[256] __attribute__((aligned(64)));
static char actAlign[6];
static int actuators;
int waitPadReady(int port, int slot)
{
int state;
int lastState;
char stateString[16];
state = padGetState(port, slot);
lastState = -1;
while( (state != PAD_STATE_STABLE) && (state != PAD_STATE_FINDCTP1) )
{
if (state != lastState)
{
padStateInt2String(state, stateString);
}
lastState = state;
state = padGetState(port, slot);
}
return 0;
}
int initializePad(int port, int slot)
{
int ret;
int modes;
int i;
waitPadReady(port, slot);
modes = padInfoMode(port, slot, PAD_MODETABLE, -1);
/*
if (modes > 0)
{
for (i = 0; i < modes; i++)
{
ret = padInfoMode(port, slot, PAD_MODETABLE, i);
}
}
*/
if (modes == 0)
return 1;
i = 0;
do
{
if ( padInfoMode(port, slot, PAD_MODETABLE, i) == PAD_TYPE_DUALSHOCK )
break;
i++;
} while (i < modes);
if (i >= modes)
return 1;
ret = padInfoMode(port, slot, PAD_MODECUREXID, 0);
if (ret == 0)
return 1;
padSetMainMode(port, slot, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK);
waitPadReady(port, slot);
ret = padInfoPressMode(port, slot);
waitPadReady(port, slot);
ret = padEnterPressMode(port, slot);
waitPadReady(port, slot);
actuators = padInfoAct(port, slot, -1, 0);
if (actuators != 0)
{
actAlign[0] = 0; // Enable small engine
actAlign[1] = 1; // Enable big engine
actAlign[2] = 0xff;
actAlign[3] = 0xff;
actAlign[4] = 0xff;
actAlign[5] = 0xff;
waitPadReady(port, slot);
ret = padSetActAlign(port, slot, actAlign);
}
waitPadReady(port, slot);
return 1;
}