forked from LemonHaze420/UEFAStriker96
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPAD_HW.C
286 lines (209 loc) · 6.6 KB
/
PAD_HW.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*****************************************************
* *
* *
* Pad read stuff *
* *
* *
*****************************************************/
/*
how pad read works...
inittap is setup to read 2 packets ( one for left and one for right port )
this reads 34 bytes ( a packet ) into port_packet[0] and [1]
if pad is connected directly to a port,
data is read as a Pad_data structure....
if a multitap is connected to a port,
data is read as a multitap_packet structure
This holds the data for upto four pads connected
to the multitap...
if Transstatus != 0xff, packet can be read.
dataFormat top 4 bits = controller type
eg std_pad, analog_joy, multitap etc
Data output is as follows....
[0-3] are for left port regardless of whether Tap connected or not
[4-7] are for right port
joydata[8] = digital pad presses
analog_lx[8] = analog controller left stick x pos
analog_rx[8] = analog controller right stick x pos
analog_ly[8] = analog controller left stick y pos
analog_ry[8] = analog controller right stick y pos
*/
extern WORD pads_connected;
extern WORD pads_connected_list[];
extern WORD multitaps_connected_list[];
#include "pad_hw.h"
#define DUALSHOCK 7 //ctrller.h does not contain any ref to pad type 7 as yet so i'll put my own in.Nah
// structure for an analog pad
typedef struct
{
UBYTE transStatus; /* 0xff = no pad, bad pad, bad transmission */
UBYTE dataFormat; /* Top 4 bits = type of controller */
UWORD digital_buttons; /* Bit mask of plain keys. */
UBYTE right_x;
UBYTE right_y;
UBYTE left_x;
UBYTE left_y;
}Single_pad_packet;
typedef struct
{
UBYTE transStatus; /* 0xff = no pad, bad pad, bad transmission */
UBYTE dataFormat; /* Top 4 bits = type of controller */
Single_pad_packet single_pad_packet[4];
}Multitap_packet;
typedef struct
{
union
{
Multitap_packet multitap_packet;
Single_pad_packet pad_direct_packet;
}data;
}Controller_packet;
Controller_packet lt_port_packet;
Controller_packet rt_port_packet;
WORD cur_pad;
void setup_pads(void);
void read_controllers();
WORD joydata[8];
WORD analog_lx[8];
WORD analog_ly[8];
WORD analog_rx[8];
WORD analog_ry[8];
void init_pad_hardware()
{
printf("doing inittap\n");
InitTAP(<_port_packet,MAX_CONTROLLER_BYTES, &rt_port_packet,MAX_CONTROLLER_BYTES);
StartTAP();
pads_connected=0;
}
void read_machine_pad_data()
{
WORD cnt,type;
//Pad_data *pad_direct;
Single_pad_packet *single_pad;
//*** Check left port for controller or multitap ***
pads_connected=0;
for ( cnt=0;cnt<8;cnt++)
{
analog_lx[cnt] = analog_ly[cnt] = analog_rx[cnt] = analog_ry[cnt] = 0;
pads_connected_list[cnt]=NO;
}
multitaps_connected_list[0] =
multitaps_connected_list[1] = 0;
//******** LEFT PORT **************
if ( lt_port_packet.data.pad_direct_packet.transStatus != 0xff )
{
// can now read packet data for left port
// find out what is plugged into directly into left port....
type = (lt_port_packet.data.pad_direct_packet.dataFormat &0xf0) >> 4;
//FntPrint("joy type=%d\n",type);
if ( type == MULTI_TAP )
{
multitaps_connected_list[0] = YES;
//** Found a multi tap plugged into left port **
for ( cnt=0;cnt<4;cnt++ )
{
//*** Check all controllers plugged into multitap ***
single_pad = <_port_packet.data.multitap_packet.single_pad_packet[cnt];
if ( lt_port_packet.data.multitap_packet.transStatus != 0xff )
{
if ( single_pad->transStatus != 0xff )
{
//** Get type of pad in this controller port **
type = (single_pad->dataFormat &0xf0) >> 4;
if ( (type == STD_PAD) || (type == DUALSHOCK ) )
{
//lt_port_pad_types[cnt] = type;
pads_connected++;
joydata [ cnt ] =~single_pad->digital_buttons;
pads_connected_list[cnt] = 1;
if ( (type == DUALSHOCK) )
{
analog_lx[ 0+cnt ] = single_pad->left_x;
analog_ly[ 0+cnt ] = single_pad->left_y;
analog_rx[ 0+cnt ] = single_pad->right_x;
analog_ry[ 0+cnt ] = single_pad->right_y;
}
}
}
}
}
}
else
{
if ( (type == STD_PAD) || (type == DUALSHOCK) )
{
pads_connected++;
pads_connected_list[0] = 1;
//** Found an analog or standard pad plugged directly into playstation **
single_pad = <_port_packet.data.pad_direct_packet;
//lt_port_pad_types[0] = (single_pad->dataFormat &0xf0) >> 4;
joydata [ 0 ] =~single_pad->digital_buttons;
if ( (type == DUALSHOCK) )
{
analog_lx[ 0 ] = single_pad->left_x;
analog_ly[ 0 ] = single_pad->left_y;
analog_rx[ 0 ] = single_pad->right_x;
analog_ry[ 0 ] = single_pad->right_y;
}
}
}
}
//******** RIGHT PORT **************
if ( rt_port_packet.data.pad_direct_packet.transStatus != 0xff )
{
// can now read packet data for left port
// find out what is plugged into directly into left port....
type = (rt_port_packet.data.pad_direct_packet.dataFormat &0xf0) >> 4;
if ( type == MULTI_TAP )
{
multitaps_connected_list[1] = YES;
//** Found a multi tap plugged into left port **
for ( cnt=0;cnt<4;cnt++ )
{
//*** Check all controllers plugged into multitap ***
single_pad = &rt_port_packet.data.multitap_packet.single_pad_packet[cnt];
if ( rt_port_packet.data.multitap_packet.transStatus != 0xff )
{
if ( single_pad->transStatus != 0xff )
{
//** Get type of pad in this controller port **
type = (single_pad->dataFormat &0xf0) >> 4;
if ( (type == STD_PAD) || (type == DUALSHOCK))
{
pads_connected++;
pads_connected_list[cnt+4] = 1;
//rt_port_pad_types[cnt] = type;
joydata [ 4+cnt ] =~single_pad->digital_buttons;
if ( (type == DUALSHOCK) )
{
analog_lx[ 4+cnt ] = single_pad->left_x;
analog_ly[ 4+cnt ] = single_pad->left_y;
analog_rx[ 4+cnt ] = single_pad->right_x;
analog_ry[ 4+cnt ] = single_pad->right_y;
}
}
}
}
}
}
else
{
if ( (type == STD_PAD) || (type == DUALSHOCK) )
{
//** Found an analog or standard pad plugged directly into playstation **
pads_connected++;
pads_connected_list[4] = 1;
single_pad = &rt_port_packet.data.pad_direct_packet;
//rt_port_pad_types[4] = (single_pad->dataFormat &0xf0) >> 4;
joydata [ 4 ] =~single_pad->digital_buttons;
if ( (type == DUALSHOCK))
{
analog_lx[ 4 ] = single_pad->left_x;
analog_ly[ 4 ] = single_pad->left_y;
analog_rx[ 4 ] = single_pad->right_x;
analog_ry[ 4 ] = single_pad->right_y;
}
}
}
}
}