-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTRLLER.H
306 lines (224 loc) · 12.5 KB
/
CTRLLER.H
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/************************************************************
* *
* ctrller.h *
* *
* *
* Allan J. Murphy 09/02/95 *
* *
* Copyright (C) 1995 Sony Computer Entertainment Inc. *
* All Rights Reserved *
* *
***********************************************************/
/*+--------+----------+----------+----------+----------+----------+---------+*/
/* */
/* Description: */
/* */
/* An attempt to build a tidy header for accessing the pads, after SCE */
/* Japan reversed the bytes in the packet buffer; and the bit organisation */
/* to 1 = not pressed, 0 = pressed (for pads at least). */
/* This header includes macros to make it easier to deal with the raw */
/* packet data, which you have to if you are using anything other than a */
/* plain pad. */
/* */
/* Updated 20/4/95 to include multi-tap data - not complete or tested. */
/* Updated 30/5/95 to include mouse data. */
/* Updated 31/5/95 to include negcon data. */
/* Updated 12/6/95 to include tested multi-tap data. */
/*
** 20-nov-1995 (pholman)
** Added Analog Joystick
** **
**+--------+----------+----------+----------+----------+----------+---------+*/
#ifndef __CTRLLER_H_
#define __CTRLLER_H_
/*+--------+----------+----------+----------+----------+----------+---------+*/
/* #defines for recognising the contents of the controller packet. */
#define BAD_TRANSMISSION 0xff /* No pad or bad transmission. */
#define NOKEY 0xffff /* No digital key pressed */
#define MAX_CONTROLLER_BYTES 34 /* Size of the biggest packet */
/* You can possible have. */
#define STD_PAD_DATA 1 /* Defines for the amount of */
#define MOUSE_DATA 2 /* data controllers return. */
#define NEGCON_DATA 3
#define ANALOG_JOY_DATA 8
#define MULTI_TAP_DATA 16
#define MOUSE 1 /* Defines for recognising the */
#define NEGCON 2 /* different controllers. */
//#define JUSTIFIER 3
#define STD_PAD 4
#define ANALOG_JOY 5
//#define GUNCON 6
#define DUAL_SHOCK 7
#define MULTI_TAP 8
/*+--------+----------+----------+----------+----------+----------+---------+*/
/* Pad controller data structure. */
/* The data returned by a pad is just a short bit mask for each key. */
typedef unsigned short PadData;
/* Pad Controller Macros and masks. */
/* #defines for the keys on the pad. The best way to use these is to do */
/* for example, if (!(buffer1.data.pad & PAD_SEL)) { <handle select key> } */
/* Or use the PadKeyIsPressed(&buffer,PAD_SEL). */
/* Front or shoulder buttons - F for front, L/R for left/right, T/B for */
/* top or bottom, U/D for up/down. */
#define PAD_FRB 0x0200
#define PAD_FLB 0x0100
#define PAD_FRT 0x0800
#define PAD_FLT 0x0400
/* Right directional; RU = right up, RD = right down, and so on. */
#define PAD_RU 0x1000
#define PAD_RD 0x4000
#define PAD_RL 0x8000
#define PAD_RR 0x2000
/* Left directional; LU = left up, LD = left down, and so on. */
#define PAD_LU 0x0010
#define PAD_LD 0x0040
#define PAD_LL 0x0080
#define PAD_LR 0x0020
/* The other two keys. */
#define PAD_SEL 0x0001
#define PAD_START 0x0008
// Dragon's Lair stuff.
#define PAD_L3 0x0002
#define PAD_R3 0x0004
/* Controller packet processing (pass in address of packet) for pads. */
#define PadKeyIsPressed(x,y) (!((x)->data.pad & (y)))
#define PadKeyPressed(x) ((x)->data.pad != NOKEY)
#define NoPadKeyPressed(x) ((x)->data.pad == NOKEY)
/*+--------+----------+----------+----------+----------+----------+---------+*/
/* Mouse data packet returns. You can use the routines from mouse.obj to */
/* work with the mouse packets if you like, but its not that tough to deal */
/* with the raw data yourself by working with the x and y offsets. */
typedef struct
{
unsigned short buttons;
signed char xOffset;
signed char yOffset;
}
MouseData;
/* Mouse Controller macros and masks. */
#define MOUSE_LEFT 0x0800 /* Left Mouse button. */
#define MOUSE_RIGHT 0x0400 /* Right Mouse button. */
#define MOUSE_NOKEY 0xfcff /* No buttons pressed. */
/* Mouse packet handling macros (pass address of packet). */
#define MouseXOffset(x) ((x)->data.mouse.xOffset)
#define MouseYOffset(x) ((x)->data.mouse.yOffset)
#define MouseMoving(x) ((x)->data.mouse.xOffset || \
(x)->data.mouse.yOffset)
#define MouseKeyIsPressed(x,y) (!((x)->data.mouse.buttons & (y)))
#define MouseKeyPressed(x) ((x)->data.mouse.buttons != MOUSE_NOKEY)
#define NoMouseKeyPressed(x) ((x)->data.mouse.buttons == MOUSE_NOKEY)
/*+--------+----------+----------+----------+----------+----------+---------+*/
/* Negcon controller packet structure. The Negcon has several different */
/* buttons / analogue inputs; there is the 4 way directional pad on the left */
/* of the controller, the start button on the left, the B and A buttons on */
/* the right, two analogue buttons (I and II), the central twisting analogue */
/* input, and two top buttons - the top left is analogue, the top right is */
/* digital (strangely enough). Bit masks and locations are given for these. */
typedef struct
{
unsigned short digitalButtons; /* Bit mask of plain keys. */
char centralTwist; /* Analogue twisting thing.*/
char buttonI; /* The I analogue button. */
char buttonII; /* The II analogue button. */
char topLeft; /* The analogue tl button. */
}
NegconData;
/* Negcon handling macros and masks. */
#define NEGCON_UP 0x0010
#define NEGCON_RIGHT 0x0020
#define NEGCON_DOWN 0x0040
#define NEGCON_LEFT 0x0080
#define NEGCON_START 0x0008
#define NEGCON_A 0x2000
#define NEGCON_B 0x1000
#define NEGCON_TR 0x0800
#define TZP_UPPER 128
#define TZP_LOWER 125
#define NegconKeyIsPressed(x,y) (!((x)->data.negcon.digitalButtons & (y)))
#define NegconKeyPressed(x) ((x)->data.negcon.digitalButtons != NOKEY)
#define NoNegconKeyPressed(x) ((x)->data.negcon.digitalButtons == NOKEY)
#define NegconTopLeft(x) ((x)->data.negcon.topLeft)
#define NegconI(x) ((x)->data.negcon.buttonI)
#define NegconII(x) ((x)->data.negcon.buttonII)
#define NegconTwisting(x) ((x)->data.negcon.centralTwist < TZP_LOWER || \
(x)->data.negcon.centralTwist > TZP_UPPER)
#define NegconTwist(x) ((x)->data.negcon.centralTwist)
/*
** Analog Joystick
*/
typedef struct
{
unsigned short digitalButtons; /* Bit mask of plain keys. */
unsigned char right_x;
unsigned char right_y;
unsigned char left_x;
unsigned char left_y;
} AnalogjoyData;
#define LEFT_MAIN_FIRE 0x0100
#define RIGHT_MAIN_FIRE 0x8000
#define JoystickRightX(x) ( (x)->data.joystick.right_x)
#define JoystickRightY(x) ( (x)->data.joystick.right_y)
#define JoystickLeftX(x) ( (x)->data.joystick.left_x)
#define JoystickLeftY(x) ( (x)->data.joystick.left_y)
#define JoystickKeyIsPressed(x,y) (!((x)->data.joystick.digitalButtons & (y)))
#define JoystickKeyPressed(x) ((x)->data.joystick.digitalButtons != NOKEY)
#define NojoystickKeyPressed(x) ((x)->data.joystick.digitalButtons == NOKEY)
/*+--------+----------+----------+----------+----------+----------+---------+*/
/* The data returned by the multi-tap is a set of controller returns. */
/* Each of the controllers connected to the multi-tap can return up to 6 */
/* bytes of information; each of the controllers returns its own packet. */
/* This means you can have 4 pads or NegCons connected, but not 4 mice, and */
/* not 4 multi-taps (surprisingly). The packet for each of the multi-tap */
/* controllers is just the same as the packet for a plain controller apart */
/* from this, so you can handle the controller packet from the multi-tap */
/* with the same macros as for the normal controller packets. */
typedef struct
{
unsigned char transStatus; /* 0xff = no pad, bad pad, bad transmission */
unsigned char dataFormat; /* Top 4 bits = type of controller */
union /* Controller data union. */ /* Controller data union. */
{
PadData pad; /* Plain pad. */
NegconData negcon; /* Namco controller.*/
}
data;
}
TapCtrllerData;
/* Now the multi-tap return structure, which is an array of the above. */
typedef struct
{
TapCtrllerData ctrllers[4]; /* Just 4 controller packets. */
}
MultiTapData;
#define GetTapData(x,y) (&((x)->data.tap.ctrllers[(y)]))
/*+--------+----------+----------+----------+----------+----------+---------+*/
/* Controller packet structure. */
typedef struct
{
unsigned char transStatus; /* 0xff = no pad, bad pad, bad transmission */
unsigned char dataFormat; /* Top 4 bits = type of controller */
/* Bottom 4 == shorts of data written */
union /* Controller data union. */
{
PadData pad; /* Plain pad. */
MouseData mouse; /* Mouse. */
NegconData negcon; /* Namco controller.*/
AnalogjoyData joystick; /* Anlog Joystick */
MultiTapData tap; /* 4-way multi-tap. */
}
data;
}
ControllerPacket;
/* Packet macros. */
/* Macros for handling the controller packets; pass in the packet address. */
#define GoodData(x) ((x)->transStatus != 0xff)
#define GetType(x) (((x)->dataFormat & 0xf0) >> 4)
#define DataShortsReturned(x) ((x)->dataFormat & 0xf)
#define DataBytesReturned(x) (((x)->dataFormat & 0xf) << 1 )
#define ControllerDataAddress(x) (&((x)->dataFormat)+1)
/*+--------+----------+----------+----------+----------+----------+---------+*/
#endif
/*+--------+----------+----------+----------+----------+----------+---------+*/
/* End ctrller.h */
/*+--------+----------+----------+----------+----------+----------+---------+*/