1 /*---------------------------------------------------------------------------*
2 
3   Copyright (C) 2010-2012 Nintendo.  All rights reserved.
4 
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law.  They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10 
11  *---------------------------------------------------------------------------*/
12 // -----------------------------------------------------------------------------
13 //  demoPad.h
14 //
15 // -----------------------------------------------------------------------------
16 
17 #ifndef __DEMO_PAD_H__
18 #define __DEMO_PAD_H__
19 
20 #include <cafe/demo.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /// @addtogroup demoPad Demo Pad
27 /// @{
28 
29 #define DEMO_PAD_MAX_CONTROLLERS 4
30 
31 #define DEMO_PAD_BUTTON_LEFT          0x0001 ///< Button Left (Win: Left or A key.)
32 #define DEMO_PAD_BUTTON_RIGHT         0x0002 ///< Button Right (Win: Right or D key.)
33 #define DEMO_PAD_BUTTON_DOWN          0x0004 ///< Button Down (Win: Down or S key.)
34 #define DEMO_PAD_BUTTON_UP            0x0008 ///< Button Up (Win: Up or W key.)
35 #define DEMO_PAD_TRIGGER_Z            0x0010 ///< Trigger Z (Win: End or Z key.)
36 #define DEMO_PAD_TRIGGER_R            0x0020 ///< Trigger R (Win: Mouse R button.)
37 #define DEMO_PAD_TRIGGER_L            0x0040 ///< Trigger L (Win: Mouse L button.)
38 #define DEMO_PAD_BUTTON_A             0x0100 ///< Button A (Win: Enter or Space key.)
39 #define DEMO_PAD_BUTTON_B             0x0200 ///< Button B (Win: BackSpace key.)
40 #define DEMO_PAD_BUTTON_X             0x0400 ///< Button X (Win: Shift key.)
41 #define DEMO_PAD_BUTTON_Y             0x0800 ///< Button Y (Win: Control key.)
42 #define DEMO_PAD_BUTTON_START         0x1000 ///< Button Start (Win: Home or Esc key.)
43 
44 #define DEMO_STICK_THRESHOLD         0x0030 ///< Stick threshold
45 #define DEMO_STICK_UP                0x1000 ///< Stick up
46 #define DEMO_STICK_DOWN              0x2000 ///< Stick down
47 #define DEMO_STICK_LEFT              0x4000 ///< Stick left
48 #define DEMO_STICK_RIGHT             0x8000 ///< Stick right
49 #define DEMO_SUBSTICK_UP             0x0100 ///< Substick up
50 #define DEMO_SUBSTICK_DOWN           0x0200 ///< Substick down
51 #define DEMO_SUBSTICK_LEFT           0x0400 ///< Substick left
52 #define DEMO_SUBSTICK_RIGHT          0x0800 ///< Substick right
53 
54 /// extended pad status structure
55 typedef struct
56 {
57     u16         button;          ///< Or-ed DEMO_PAD_BUTTON_* and DEMO_PAD_TRIGGER_* bits
58     s8          stickX;          ///< -128 <= stickX       <= 127 (Win: Emulated from mouse cursor with mouse L button.)
59     s8          stickY;          ///< -128 <= stickY       <= 127 (Win: Emulated from mouse cursor with mouse L button.)
60     s8          substickX;       ///< -128 <= substickX    <= 127 (Win: Emulated from mouse cursor with mouse R button.)
61     s8          substickY;       ///< -128 <= substickY    <= 127 (Win: Emulated from mouse cursor with mouse R button.)
62     u8          triggerLeft;     ///< 0 <= triggerLeft  <= 255 (Win: Mouse L button. Not analog value. 0 or 255)
63     u8          triggerRight;    ///< 0 <= triggerRight <= 255 (Win: Mouse R button. Not analog value. 0 or 255)
64     u8          analogA;         ///< 0 <= analogA      <= 255 (Win: Enter button. Not analog value. 0 or 255)
65     u8          analogB;         ///< 0 <= analogB      <= 255 (Win: BackSpace button. Not analog value. 0 or 255)
66     s8          err;             ///< one of PAD_ERR_* number
67     u16         lastButton;      ///< Last button;
68 
69     u16         buttonDown;       ///< Button down
70     u16         buttonUp;         ///< Button up
71     u16         dirs;             ///< Directions
72     u16         dirsNew;          ///< New directions
73     u16         dirsReleased;     ///< Released directions
74     s16         stickDeltaX;      ///< Stick delta x
75     s16         stickDeltaY;      ///< Stick delta y
76     s16         substickDeltaX;   ///< Substick delta x
77     s16         substickDeltaY;   ///< Substick delta y
78 } DemoPadStatus;
79 
80 extern DemoPadStatus  g_DemoPad[ DEMO_PAD_MAX_CONTROLLERS ]; ///< the entity which keeps current pad status
81 extern u32              g_DemoNumValidPads;             ///< the entity which keeps current pad status
82 
83 
84 /// \brief Initializes the controllers.
85 ///
86 /// This function initializes the controllers.
87 /// The PADInit function enables the controller sampling performed by hardware.
88 ///
89 void DEMOPadInit (void);
90 
91 
92 /// \brief Shutdown the controllers.
93 ///
94 /// This function shuts down the controllers.
95 void DEMOPadShutdown (void);
96 
97 
98 /// \brief Gets the status of all controllers at once.
99 ///
100 /// This function is used to sample the current complete set of Controller inputs.
101 /// Once a sample has been read, the individual values can be examined.
102 ///
103 /// \return Return logical OR of all the controllers
104 u32 DEMOPadRead (void);
105 
106 /// \brief Return bit field that indicates the button.
107 ///
108 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
109 /// \return Bit field that indicates the button.
DEMOPadGetButton(u32 i)110 DEMO_INLINE u16 DEMOPadGetButton (u32 i)  {return g_DemoPad[i].button;}
111 
112 /// \brief Return bit field that indicates the button up state.
113 ///
114 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
115 /// \return Bit field that indicates the button state.
DEMOPadGetButtonUp(u32 i)116 DEMO_INLINE u16 DEMOPadGetButtonUp (u32 i)  {return g_DemoPad[i].buttonUp;}
117 
118 /// \brief Return bit field that indicates the button down state.
119 ///
120 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
121 /// \return Bit field that indicates the button state.
DEMOPadGetButtonDown(u32 i)122 DEMO_INLINE u16 DEMOPadGetButtonDown (u32 i)  {return g_DemoPad[i].buttonDown;}
123 
124 /// \brief Return bit field that specifies the directional state of the stick.
125 ///
126 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
127 /// \return Bit field that specifies the directional state of the stick.
DEMOPadGetDirs(u32 i)128 DEMO_INLINE u16 DEMOPadGetDirs (u32 i)  {return g_DemoPad[i].dirs;}
129 
130 /// \brief Return bit field that specifies the directional state of the stick.
131 ///
132 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
133 /// \return Bit field that specifies the directional state of the stick.
DEMOPadGetDirsNew(u32 i)134 DEMO_INLINE u16 DEMOPadGetDirsNew (u32 i)  {return g_DemoPad[i].dirsNew;}
135 
136 /// \brief Return bit field that specifies the directional state of the stick.
137 ///
138 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
139 /// \return Bit field that specifies the directional state of the stick.
DEMOPadGetDirsReleased(u32 i)140 DEMO_INLINE u16 DEMOPadGetDirsReleased (u32 i)  {return g_DemoPad[i].dirsReleased;}
141 
142 /// \brief Return the input value of the stick X.
143 ///
144 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
145 /// \return The input value of the stick X.
DEMOPadGetStickX(u32 i)146 DEMO_INLINE s8 DEMOPadGetStickX (u32 i)  {return g_DemoPad[i].stickX;}
147 
148 /// \brief Return the input value of the stick Y.
149 ///
150 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
151 /// \return The input value of the stick Y.
DEMOPadGetStickY(u32 i)152 DEMO_INLINE s8  DEMOPadGetStickY(u32 i)  {return g_DemoPad[i].stickY;}
153 
154 /// \brief Return the input value of the sub stick X.
155 ///
156 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
157 /// \return The input value of the sub stick X.
DEMOPadGetSubStickX(u32 i)158 DEMO_INLINE s8  DEMOPadGetSubStickX(u32 i)  {return g_DemoPad[i].substickX;}
159 
160 /// \brief Return the input value of the sub stick Y.
161 ///
162 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
163 /// \return The input value of the sub stick Y.
DEMOPadGetSubStickY(u32 i)164 DEMO_INLINE s8  DEMOPadGetSubStickY(u32 i)  {return g_DemoPad[i].substickY;}
165 
166 /// \brief Return analog value of L that indicates how long the trigger or analog button has been pressed.
167 ///
168 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
169 /// \return Analog value that indicates how long the trigger or analog button has been pressed.
DEMOPadGetTriggerL(u32 i)170 DEMO_INLINE u8  DEMOPadGetTriggerL(u32 i)  {return g_DemoPad[i].triggerLeft;}
171 
172 /// \brief Return analog value of R that indicates how long the trigger or analog button has been pressed.
173 ///
174 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
175 /// \return Analog value that indicates how long the trigger or analog button has been pressed.
DEMOPadGetTriggerR(u32 i)176 DEMO_INLINE u8  DEMOPadGetTriggerR(u32 i)  {return g_DemoPad[i].triggerRight;}
177 
178 /// \brief Return analog value of A that indicates how long the trigger or analog button has been pressed.
179 ///
180 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
181 /// \return Analog value that indicates how long the trigger or analog button has been pressed.
DEMOPadGetAnalogA(u32 i)182 DEMO_INLINE u8  DEMOPadGetAnalogA(u32 i)  {return g_DemoPad[i].analogA;}
183 
184 /// \brief Return analog value of B that indicates how long the trigger or analog button has been pressed.
185 ///
186 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
187 /// \return Analog value that indicates how long the trigger or analog button has been pressed.
DEMOPadGetAnalogB(u32 i)188 DEMO_INLINE u8  DEMOPadGetAnalogB(u32 i)  {return g_DemoPad[i].analogB;}
189 
190 /// \brief Return the state of the various Controller inputs.
191 ///
192 /// \param i Specifies Controller to read. The first Controller is 0, the second Controller is 1, etc.
193 /// \return A PAD_ERR* value.
DEMOPadGetErr(u32 i)194 DEMO_INLINE s8  DEMOPadGetErr(u32 i)  {return g_DemoPad[i].err;}
195 
196 
197 /// @} // demoPad
198 
199 
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 #endif /// __DEMO_PAD_H__
205