-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpad.c
168 lines (138 loc) · 4.21 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
#
# Pad demo app
# Quick and dirty, little or no error checks etc..
# Distributed as is
*/
#include <tamtypes.h>
#include <kernel.h>
#include <sifrpc.h>
#include <loadfile.h>
#include <stdio.h>
#include <libpad.h>
#include <gs_privileged.h>
/*
* Global var's
*/
// pad_dma_buf is provided by the user, one buf for each pad
// contains the pad's current state
// static char padBuf[256] __attribute__((aligned(64)));
static char actAlign[6];
static int actuators;
/*ActAlign
* Local functions
*/
void waitVSync()
{
// Enable the vsync interrupt.
*GS_REG_CSR |= GS_SET_CSR(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
// Wait for the vsync interrupt.
while (!(*GS_REG_CSR & (GS_SET_CSR(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)))) { }
// Disable the vsync interrupt.
*GS_REG_CSR &= ~GS_SET_CSR(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
}
/*
* waitPadReady()
*/
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);
printf("Please wait, pad(%d,%d) is in state %s\n",
port, slot, stateString);
}
lastState = state;
state=padGetState(port, slot);
}
// Were the pad ever 'out of sync'?
if (lastState != -1) {
printf("Pad OK!\n");
}
return 0;
}
/*
* initializePad()
*/
int initializePad(int port, int slot)
{
int ret;
int modes;
int i;
waitPadReady(port, slot);
// How many different modes can this device operate in?
// i.e. get # entrys in the modetable
modes = padInfoMode(port, slot, PAD_MODETABLE, -1);
printf("The device has %d modes\n", modes);
if (modes > 0) {
printf("( ");
for (i = 0; i < modes; i++) {
printf("%d ", padInfoMode(port, slot, PAD_MODETABLE, i));
}
printf(")");
}
printf("It is currently using mode %d\n",
padInfoMode(port, slot, PAD_MODECURID, 0));
// If modes == 0, this is not a Dual shock controller
// (it has no actuator engines)
if (modes == 0) {
printf("This is a digital controller?\n");
return 1;
}
// Verify that the controller has a DUAL SHOCK mode
i = 0;
do {
if (padInfoMode(port, slot, PAD_MODETABLE, i) == PAD_TYPE_DUALSHOCK)
break;
i++;
} while (i < modes);
if (i >= modes) {
printf("This is no Dual Shock controller\n");
return 1;
}
// If ExId != 0x0 => This controller has actuator engines
// This check should always pass if the Dual Shock test above passed
ret = padInfoMode(port, slot, PAD_MODECUREXID, 0);
if (ret == 0) {
printf("This is no Dual Shock controller??\n");
return 1;
}
printf("Enabling dual shock functions\n");
// When using MMODE_LOCK, user cant change mode with Select button
padSetMainMode(port, slot, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK);
waitPadReady(port, slot);
printf("infoPressMode: %d\n", padInfoPressMode(port, slot));
waitPadReady(port, slot);
printf("enterPressMode: %d\n", padEnterPressMode(port, slot));
waitPadReady(port, slot);
actuators = padInfoAct(port, slot, -1, 0);
printf("# of actuators: %d\n",actuators);
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);
printf("padSetActAlign: %d\n",
padSetActAlign(port, slot, actAlign));
}
else {
printf("Did not find any actuators.\n");
}
waitPadReady(port, slot);
return 1;
}