1 /*---------------------------------------------------------------------------*
2   Project:  Gamecube controller(PAD) library
3   File:     pad.h
4 
5   Copyright (C) 1998-2006 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Log: pad.h,v $
14   Revision 1.3  02/06/2006 01:06:15  yasuh-to
15   Restored the APIs
16 
17 
18     33    1/09/04 10:52 Shiki
19     Added PADIsBarrel().
20 
21     32    7/22/03 13:22 Shiki
22     Declared __PADDisableRumble().
23 
24     30     8/22/02 11:58:00 Shiki
25     Clean up.
26 
27     29     8/20/02 10:28:00 Shiki
28     Added PADClampCircle().
29 
30     28    8/19/02 21:42 Shiki
31     Set #pragma warn_padding off around the PADStatus{} definition.
32 
33     27    8/12/02 15:27 Shiki
34     Added __padding field to PADStatus{}.
35 
36     26     8/05/02 18:11:00 Shiki
37     Added const keyword to the PADControlAllMotors() function prototype.
38 
39     25    10/29/01 11:57 Shiki
40     Modified __PADDisableRecalibration() to make it return the previous
41     state.
42 
43     24    10/12/01 16:29 Shiki
44     Modified PADSetSamplingCallback() to make it return the previous
45     callback pointer.
46 
47     23    9/05/01 16:25 Shiki
48     Added __PADDisableRecalibration() and __PADDisableXPatch().
49 
50     22     9/03/01 14:46:00 Shiki
51     Added PADSetSamplingCallback().
52 
53     21    7/30/01 11:01 Shiki
54     Modified PADRead() to return OR-ed bit mask of controllers that support
55     rumble motors.
56 
57     20    01/03/21 18:55 Shiki
58     Fixed not to define PAD_USESPEC for EMU builds.
59 
60     19    01/03/21 18:32 Shiki
61     Added PADGetSpec().
62 
63     18    01/03/21 17:22 Shiki
64     Added PADSetAnalogMode().
65 
66     17    01/01/30 14:17 Shiki
67     Removed __PADWirelessIDCheck().
68 
69     16    11/20/00 6:03p Shiki
70     Added more PAD_SPEC_*.
71 
72     15    10/17/00 10:14a Hashida
73     From IRD: Added PADRecalibrate and PADSync
74 
75     14    10/02/00 10:18a Hashida
76     From Shiki: Added PAD_WIRELESS_FIX_ID define name.
77 
78     13    9/05/00 9:12p Shiki
79     Added PAD_TYPE_* define names.
80 
81     12    9/05/00 9:04p Shiki
82     Added PADGetType().
83 
84     11    8/29/00 10:18p Shiki
85     Added __PADWirelessIDCheck().
86 
87     10    8/24/00 7:32p Shiki
88     Revised PAD_BUTTON/TRIGGER_* define names for the final controller.
89 
90     9     3/23/00 4:34p Shiki
91     Clean up.
92 
93     8     3/23/00 4:31p Shiki
94     Added PADSetSpec().
95 
96     7     3/22/00 8:11p Shiki
97     Revised PAD_TRIGGER_* defines for the final controller IC.
98 
99     6     3/10/00 2:56p Shiki
100     Revised motor control functions.
101 
102     5     3/09/00 8:28p Shiki
103     Added PADControlMotor().
104 
105     4     2/24/00 7:48p Shiki
106     Added PAD_TRIGGER_*.
107 
108     3     2/24/00 5:49p Shiki
109     Updated to the final spec.
110 
111     2     12/15/99 8:25p Shiki
112     Added substickX/Y into PADStatus.
113 
114     10    9/23/99 4:55p Shiki
115     Renamed 'errno' of PADStatus to 'err'.
116 
117     9     9/13/99 6:26p Shiki
118     Inserted (u16) casts in PADButtonUp/Down macros.
119 
120     7     5/11/99 4:42p Shiki
121     Refreshed include tree.
122 
123     5     5/06/99 8:18p Shiki
124     Renamed PADNormalize() to PADClamp()
125 
126     4     5/06/99 6:12p Shiki
127     Added PADNormalize().
128 
129     3     5/05/99 5:42p Shiki
130     Added PADButtonDown and PADButtonUp macros.
131 
132     2     5/04/99 8:46p Shiki
133     Fixed comment.
134 
135     1     5/04/99 8:32p Shiki
136 
137   $NoKeywords: $
138  *---------------------------------------------------------------------------*/
139 
140 #ifndef __PAD_H__
141 #define __PAD_H__
142 
143 #include <revolution/types.h>
144 #include <revolution/os.h>
145 
146 #ifdef __cplusplus
147 extern "C" {
148 #endif
149 
150 // CAUTION: Define PAD_USESPEC as long as bread boards or prototype
151 //          controllers (including DS4) are in use.
152 #ifndef EMU
153 #define PAD_USESPEC
154 #endif  // EMU
155 
156 #ifdef  __MWERKS__
157 #pragma warn_padding off
158 #endif
159 
160 typedef struct PADStatus
161 {
162     u16 button;                 // Or-ed PAD_BUTTON_* bits
163     s8  stickX;                 // -128 <= stickX    <= 127
164     s8  stickY;                 // -128 <= stickY    <= 127
165     s8  substickX;              // -128 <= substickX    <= 127
166     s8  substickY;              // -128 <= substickY    <= 127
167     u8  triggerLeft;            //    0 <= triggerLeft  <= 255
168     u8  triggerRight;           //    0 <= triggerRight <= 255
169     u8  analogA;                //    0 <= analogA      <= 255
170     u8  analogB;                //    0 <= analogB      <= 255
171     s8  err;                    // one of PAD_ERR_* number
172 } PADStatus;
173 
174 #ifdef  __MWERKS__
175 #pragma warn_padding reset
176 #endif
177 
178 #define PAD_MAX_CONTROLLERS     4
179 
180 #define PAD_BUTTON_LEFT         0x0001
181 #define PAD_BUTTON_RIGHT        0x0002
182 #define PAD_BUTTON_DOWN         0x0004
183 #define PAD_BUTTON_UP           0x0008
184 #define PAD_TRIGGER_Z           0x0010
185 #define PAD_TRIGGER_R           0x0020
186 #define PAD_TRIGGER_L           0x0040
187 #define PAD_BUTTON_A            0x0100
188 #define PAD_BUTTON_B            0x0200
189 #define PAD_BUTTON_X            0x0400
190 #define PAD_BUTTON_Y            0x0800
191 #define PAD_BUTTON_MENU         0x1000
192 #define PAD_BUTTON_START        0x1000
193 
194 #define PAD_CHAN0               0
195 #define PAD_CHAN1               1
196 #define PAD_CHAN2               2
197 #define PAD_CHAN3               3
198 
199 #define PAD_CHAN0_BIT           0x80000000
200 #define PAD_CHAN1_BIT           0x40000000
201 #define PAD_CHAN2_BIT           0x20000000
202 #define PAD_CHAN3_BIT           0x10000000
203 
204 #define PAD_ERR_NONE            0
205 #define PAD_ERR_NO_CONTROLLER   -1
206 #define PAD_ERR_NOT_READY       -2
207 #define PAD_ERR_TRANSFER        -3
208 
209 #define PAD_MOTOR_STOP          0
210 #define PAD_MOTOR_RUMBLE        1
211 #define PAD_MOTOR_STOP_HARD     2
212 
213 #ifdef  PAD_USESPEC
214 #define PAD_SPEC_0              0       // bread board    (ver 0.x)
215 #define PAD_SPEC_1              1       // 1st prototypes (ver 1.0)
216 #define PAD_SPEC_2              2       // 2nd prototypes (ver 3.0 FPGA)
217 #define PAD_SPEC_3              3       // DS3
218 #define PAD_SPEC_4              4       // DS4
219 #define PAD_SPEC_5              5       // DS5 (production version)
220 #endif  // PAD_USESPEC
221 
222 // PADSetAnalogMode() param
223 #define PAD_MODE_0              0
224 #define PAD_MODE_1              1
225 #define PAD_MODE_2              2
226 #define PAD_MODE_3              3
227 #define PAD_MODE_4              4
228 #define PAD_MODE_5              5
229 #define PAD_MODE_6              6
230 #define PAD_MODE_7              7
231 
232 #define PADButtonDown(buttonLast, button)   \
233     ((u16) (((buttonLast) ^ (button)) & (button)))
234 
235 #define PADButtonUp(buttonLast, button)     \
236     ((u16) (((buttonLast) ^ (button)) & (buttonLast)))
237 
238 #define PADStartMotor(chan)     PADControlMotor((chan), PAD_MOTOR_RUMBLE)
239 #define PADStopMotorHard(chan)  PADControlMotor((chan), PAD_MOTOR_STOP_HARD)
240 #define PADStopMotor(chan)      PADControlMotor((chan), PAD_MOTOR_STOP)
241 
242 BOOL PADInit             ( void );
243 BOOL PADReset            ( u32 mask );
244 u32  PADRead             ( PADStatus* status );
245 void PADSetSamplingRate  ( u32 msec );
246 void PADClamp            ( PADStatus* status );
247 void PADClampCircle      ( PADStatus* status );
248 void PADControlAllMotors ( const u32* command );
249 void PADControlMotor     ( int chan, u32 command );
250 BOOL PADRecalibrate      ( u32 mask );
251 BOOL PADSync             ( void );
252 void PADSetAnalogMode    ( u32 mode );
253 BOOL PADIsBarrel         ( s32 chan );
254 
255 typedef void (* PADSamplingCallback )(void);
256 
257 PADSamplingCallback PADSetSamplingCallback( PADSamplingCallback callback );
258 
259 // obsolete. Use SIProbe() instead.
260 BOOL PADGetType          ( s32 chan, u32* type );
261 
262 #ifdef  PAD_USESPEC
263 void PADSetSpec          ( u32 model );
264 u32  PADGetSpec          ( void );
265 #endif  // PAD_USESPEC
266 
267 #ifdef  _DEBUG
268 void __PADTestSamplingRate( u32 tvmode );
269 #endif  // _DEBUG
270 
271 /* #ifdef  MACOS
272  * void PADConfigure( void );
273  * #endif  // MACOS
274  */
275 
276 //
277 // System internal use only (do not use/touch)
278 //
279 
280 BOOL __PADDisableRecalibration( BOOL disable );
281 BOOL __PADDisableRumble       ( BOOL disable );
282 void __PADDisableXPatch       ( void );
283 
284 extern u32 __PADFixBits;
285 
286 //
287 //
288 //
289 
290 #ifdef __cplusplus
291 }
292 #endif
293 
294 #endif  // __PAD_H__
295