forked from LemonHaze420/UEFAStriker96
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPAD.C
236 lines (169 loc) · 4.94 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
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
/************************************************************************
* *
* *
* PSX Control pad initialisation & read *
* *
* *
************************************************************************/
#include "incs.h"
#include "pad_hw.c"
#ifdef PSX
#include "..\..\global\striker.def" // defs for PSX striker
#include "..\..\global\s01.h" // structs used by scene "s01" format
#include "..\..\striker\frontend\mod.def"
#include "..\..\striker\src\anim.def"
#include "teamedit.h"
#include "preset.h"
#include "sod.h"
#include "scene.h"
#include "datafile.h"
#include "sprite.h"
#include "frontend.h"
#include "gadget.h"
#include "hardware.h"
#include "polydraw.h" //psx structs
#include "text.h"
#include "font.h"
#include "plasma.h"
#include "render.h"
#include "mem.h"
#include "fvars.h"
#include "pad.h"
#include "utils.h"
#include "entname.h"
#include "skindraw.h"
#include "..\..\global\image.h"
#include "psxmacro.h"
#endif
/************************************************************************
* *
* prototypes *
* *
************************************************************************/
void read_a_pad ( WORD num );
void joy_repeat( Padstruct *joy_ptr, WORD pad_bit, WORD bit_num );
/************************************************************************
* *
* vars *
* *
************************************************************************/
WORD joy_curr; /* Specify pad to read. -1 = read current pad pressed */
WORD joy_curr_output; /* num of last pad pressed */
WORD joy_curr_store;
WORD initial_repeat_speed, initial_repeat_wait;
Padstruct joy[8];
Padstruct *cjoy; // addr of current pad. Set joy_curr
// as 0-n for pad or -1 to use current pad pressed.
volatile WORD pads_inactive_cnt;
WORD pads_connected;
WORD pads_connected_list[8]; // 0,1,2,3 = left side ; 4,5,6,7=right side
WORD multitaps_connected_list[2]; // 0 = left side ; 1=right side
void initialise_control_pads( WORD repeat_wait, WORD repeat_speed )
{
WORD cnt;
init_pad_hardware();
pads_inactive_cnt=0;
// for ( cnt=0;cnt<8;cnt++)
// share->pad_disabled[cnt]=NO;
set_pad_repeat_speed( repeat_wait, repeat_speed );
//***** store rep wait and speed *****
initial_repeat_wait = repeat_wait;
initial_repeat_speed = repeat_speed;
}
void read_pads( void )
{
WORD cnt;
// FntPrint("reading pads\n");
/* joy1-4 = pad data */
/* joy1-4_last = last frame pad data */
/* joy_curr_output = pad num 0-3 of pad currently pressed */
if ( pads_inactive_cnt )
{
pads_inactive_cnt--;
}
read_machine_pad_data(); // read pad data from hardware to joydata array
// dump joydata into joy[] arrays
for ( cnt=0;cnt<8;cnt++)
{
// if ( share->pad_disabled[cnt]==NO )
read_a_pad ( cnt ); // output into pad structs
// FntPrint("lxy=%d %d rxy=%d %d dig=%d\n",joy[cnt].alx, joy[cnt].aly,joy[cnt].arx, joy[cnt].ary,joy[cnt].c );
}
if ( joy_curr == -1 )
cjoy=&joy[ joy_curr_output ];
else
cjoy=&joy[ joy_curr ];
}
void read_a_pad ( WORD num )
{
Padstruct *joy_ptr;
joy_ptr = &joy[num];
joy_ptr->last_b = joy_ptr->last_a;
joy_ptr->last_a = joy_ptr->c;
if ( pads_inactive_cnt == 0 )
{
joy_ptr->c = joydata[num]; //only read pads if inactive cnt=0
joy_ptr->alx = analog_lx[num];
joy_ptr->aly = analog_ly[num];
joy_ptr->arx = analog_rx[num];
joy_ptr->ary = analog_ry[num];
}
joy_ptr->last = joy_ptr->last_a | joy_ptr->last_b;
joy_ptr->db = joy_ptr->c & (~joy_ptr->last);
if ( pads_inactive_cnt )
return;
if ( joy_ptr->c )
{
joy_curr_output=num;
}
//buttons that have pad repeat feature....
joy_repeat ( joy_ptr, PAD_LT,0 );
joy_repeat ( joy_ptr, PAD_RT,1 );
joy_repeat ( joy_ptr, PAD_UP,2 );
joy_repeat ( joy_ptr, PAD_DN,3 );
joy_repeat ( joy_ptr, PAD_L1,4 );
joy_repeat ( joy_ptr, PAD_R1,5 );
joy_repeat ( joy_ptr, PAD_L2,6 );
joy_repeat ( joy_ptr, PAD_R2,7 );
joy_repeat ( joy_ptr, PAD_X ,8 );
joy_repeat ( joy_ptr, PAD_SQU ,9 );
joy_repeat ( joy_ptr, PAD_TRI ,10 );
joy_repeat ( joy_ptr, PAD_CIR ,11 );
}
void joy_repeat( Padstruct *joy_ptr, WORD pad_bit, WORD bit_num )
{
if ( joy_ptr->c & pad_bit )
{
if ( joy_ptr->r_cnt[bit_num] == 0 )
{
joy_ptr->r_cnt[bit_num] = joy_ptr->r_delay;
joy_ptr->r |= pad_bit;
}
else
{
joy_ptr->r_cnt[bit_num]--;
joy_ptr->r &= ~pad_bit;
}
}
else
{
joy_ptr->r_cnt[bit_num] = joy_ptr->r_wait;
joy_ptr->r&=~pad_bit;
}
if ( joy_ptr->db & pad_bit )
joy_ptr->r |= joy_ptr->db & pad_bit;
}
void set_pad_repeat_speed( WORD repeat_wait, WORD repeat_speed )
{
WORD cnt;
for ( cnt=0;cnt<8;cnt++)
{
joy[cnt].r_wait = repeat_wait; //initial wait before repeat occurs
joy[cnt].r_delay = repeat_speed;
}
}
void restore_repeat_speed()
{
set_pad_repeat_speed( initial_repeat_wait, initial_repeat_speed );
}