Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
JUTGamePad.h
Go to the documentation of this file.
1#ifndef JUTGAMEPAD_H
2#define JUTGAMEPAD_H
3
6#include <dolphin.h>
7
8typedef void (*callbackFn)(int, void*);
9
16 virtual void getStatus(PADStatus* pad) = 0;
17 virtual void write(PADStatus* pad) = 0;
18
19 bool isActive() const { return mActive; }
20
21 /* 0x4 */ bool mActive;
22};
23
28struct JUTGamePad : public JKRDisposer {
29public:
32 };
33
38
46
52
54 virtual ~JUTGamePad();
55
56 void initList();
57 static BOOL init();
58 void clear();
59 static u32 read();
60 void assign();
62 void update();
64
65 static void checkResetSwitch();
66 static void clearForReset();
67 static JUTGamePad* getGamePad(int port);
68 static bool recalibrate(u32 mask);
69
70 static void setAnalogMode(u32 mode) {
71 sAnalogMode = mode;
72 PADSetAnalogMode(mode);
73 }
74
76
77 static void setResetCallback(callbackFn callback, void* arg) {
78 C3ButtonReset::sCallback = callback;
80 }
81
82 u32 getButton() const { return mButton.mButton; }
83 u32 getTrigger() const { return mButton.mTrigger; }
84 f32 getMainStickX() const { return mMainStick.mPosX; }
85 f32 getMainStickY() const { return mMainStick.mPosY; }
88 f32 getSubStickX() const { return mSubStick.mPosX; }
89 f32 getSubStickY() const { return mSubStick.mPosY; }
92 u8 getAnalogA() const { return mButton.mAnalogA; }
93 u8 getAnalogB() const { return mButton.mAnalogB; }
94 u8 getAnalogL() const { return mButton.mAnalogL; }
95 u8 getAnalogR() const { return mButton.mAnalogR; }
96 s8 getErrorStatus() const { return mErrorStatus; }
97
98 s16 getPortNum() const { return mPortNum; }
99
102
103 u32 testTrigger(u32 button) const { return mButton.mTrigger & button; }
104
106 return mPortNum != EPortInvalid && mButtonReset.mReset != false;
107 }
108
112
114
115 struct CButton {
116 CButton() { clear(); }
117 void clear();
119 void setRepeat(u32 mask, u32 delay, u32 rate);
120
121 /* 0x00 */ u32 mButton;
122 /* 0x04 */ u32 mTrigger; // Pressed Buttons
123 /* 0x08 */ u32 mRelease; // Released Buttons
124 /* 0x0C */ u8 mAnalogA;
125 /* 0x0D */ u8 mAnalogB;
126 /* 0x0E */ u8 mAnalogL;
127 /* 0x0F */ u8 mAnalogR;
128 /* 0x10 */ f32 mAnalogLf;
129 /* 0x14 */ f32 mAnalogRf;
130 /* 0x18 */ u32 mRepeat;
131 /* 0x1C */ u32 mRepeatCount;
132 /* 0x20 */ u32 mRepeatStart;
133 /* 0x24 */ u32 mRepeatMask;
134 /* 0x28 */ u32 mRepeatDelay;
135 /* 0x2C */ u32 mRepeatRate;
136 }; // Size: 0x30
137
139 C3ButtonReset() { mReset = false; }
140
144 static void* sCallbackArg;
147 static bool sResetOccurred;
149
150 /* 0x0 */ bool mReset;
151 }; // Size: 0x4
152
153 struct CStick {
156
157 CStick() { clear(); }
158 void clear();
159 void clear(JUTGamePad* pad);
161 u32 buttons);
163
164 /* 0x0 */ f32 mPosX;
165 /* 0x4 */ f32 mPosY;
166 /* 0x8 */ f32 mValue;
167 /* 0xC */ s16 mAngle;
168 /* 0xE */ s8 mRawX;
169 /* 0xF */ s8 mRawY;
170 }; // Size: 0x10
171
173
174 struct CRumble {
175 CRumble(JUTGamePad* pad) { clear(pad); }
176
177 static u32 sChannelMask[4];
178 static bool mStatus[4];
179 static u32 mEnabled;
180
181 enum ERumble {
182 VAL_0 = 0,
183 VAL_1 = 1,
184 VAL_2 = 2,
185 };
186
187 void clear();
188 void clear(JUTGamePad* pad);
189 static void startMotor(int port);
190 static void stopMotor(int port, bool hard_stop);
191 void update(s16 port);
192 void triggerPatternedRumble(u32 length);
193 void startPatternedRumble(void* data, ERumble rumble, u32 length);
196 static void setEnabled(u32 mask);
197
198 void stopMotorHard(int port) { stopMotor(port, true); }
199
200 static bool isEnabled(u32 mask) { return mEnabled & mask; }
201
202 static bool isEnabledPort(int port) {
203 JUT_ASSERT(250, 0 <= port && port < 4);
204 return isEnabled(sChannelMask[port]);
205 }
206
207 /* 0x00 */ u32 mFrame;
208 /* 0x04 */ u32 mLength;
209 /* 0x08 */ u8* mPattern;
210 /* 0x0C */ u32 mFrameCount;
211 /* 0x10 */ u8* field_0x10;
212 }; // Size: 0x14
213
214 void startMotorWave(void* data, CRumble::ERumble rumble, u32 length) {
215 mRumble.startPatternedRumble(data, rumble, length);
216 }
217
219 static bool mListInitialized;
225 static int sClampMode;
226 static u8 mPadAssign[4];
230
231 /* 0x18 */ CButton mButton;
232 /* 0x48 */ CStick mMainStick;
233 /* 0x58 */ CStick mSubStick;
234 /* 0x68 */ CRumble mRumble;
235 /* 0x7C */ s16 mPortNum;
236 /* 0x7E */ s8 mErrorStatus;
241 /* 0x9C */ u8 field_0x9c[4];
243 /* 0xA8 */ u8 field_0xa8;
244};
245
252 void checkCallback(int port, u32 hold_time);
253
254 u32 getMaskPattern() const { return mMaskPattern; }
255 u32 getPattern() const { return mPattern; }
256 bool isValid() const { return mValid; }
257
258 /* 0x00 */ u8 field_0x0[0x10];
259 /* 0x10 */ bool mValid;
260 /* 0x11 */ bool field_0x11;
261 /* 0x14 */ u32 mPattern;
262 /* 0x18 */ u32 mMaskPattern;
263 /* 0x1C */ u32 mThreshold;
264 /* 0x20 */ bool mLongPressStatus[4];
265 /* 0x28 */ OSTime mStartHoldTime[4];
266 /* 0x48 */ bool field_0x48[4];
268 /* 0x50 */ s32 field_0x50;
269};
270
271#endif /* JUTGAMEPAD_H */
void(* callbackFn)(int, void *)
Definition JUTGamePad.h:8
s64 OSTime
Definition OSTime.h:10
void PADSetAnalogMode(u32 mode)
Definition Pad.c:736
T cLib_calcTimer(T *value)
Definition c_lib.h:79
Definition JKRDisposer.h:12
Definition JSUList.h:96
static void stick(b_gos_class *i_this)
Definition d_a_b_gos.cpp:136
double x double x
Definition e_atan2.c:58
double u
Definition e_pow.c:163
Definition JUTGamePad.h:250
u32 getPattern() const
Definition JUTGamePad.h:255
static JSUList< JUTGamePadLongPress > sPatternList
Definition JUTGamePad.h:251
bool field_0x48[4]
Definition JUTGamePad.h:266
bool mLongPressStatus[4]
Definition JUTGamePad.h:264
bool field_0x11
Definition JUTGamePad.h:260
void checkCallback(int port, u32 hold_time)
Definition JUTGamePad.cpp:648
u32 mThreshold
Definition JUTGamePad.h:263
u8 field_0x0[0x10]
Definition JUTGamePad.h:258
bool mValid
Definition JUTGamePad.h:259
u32 mPattern
Definition JUTGamePad.h:261
u32 mMaskPattern
Definition JUTGamePad.h:262
bool isValid() const
Definition JUTGamePad.h:256
OSTime mStartHoldTime[4]
Definition JUTGamePad.h:265
void(* mCallback)(s32, JUTGamePadLongPress *, s32)
Definition JUTGamePad.h:267
u32 getMaskPattern() const
Definition JUTGamePad.h:254
s32 field_0x50
Definition JUTGamePad.h:268
Definition JUTGamePad.h:14
virtual void getStatus(PADStatus *pad)=0
virtual void write(PADStatus *pad)=0
virtual ~JUTGamePadRecordBase()
Definition JUTGamePad.h:15
bool mActive
Definition JUTGamePad.h:21
bool isActive() const
Definition JUTGamePad.h:19
Definition JUTGamePad.h:138
static s32 sResetOccurredPort
Definition JUTGamePad.h:146
static OSTime sThreshold
Definition JUTGamePad.h:145
static u32 sResetMaskPattern
Definition JUTGamePad.h:142
static callbackFn sCallback
Definition JUTGamePad.h:143
static bool sResetSwitchPushing
Definition JUTGamePad.h:148
C3ButtonReset()
Definition JUTGamePad.h:139
static bool sResetOccurred
Definition JUTGamePad.h:147
static u32 sResetPattern
Definition JUTGamePad.h:141
static void * sCallbackArg
Definition JUTGamePad.h:144
bool mReset
Definition JUTGamePad.h:150
Definition JUTGamePad.h:115
u32 mRepeatStart
Definition JUTGamePad.h:132
u32 mRepeatRate
Definition JUTGamePad.h:135
u32 mButton
Definition JUTGamePad.h:121
u8 mAnalogL
Definition JUTGamePad.h:126
void clear()
Definition JUTGamePad.cpp:315
u8 mAnalogB
Definition JUTGamePad.h:125
u32 mRepeatCount
Definition JUTGamePad.h:131
u32 mRepeatMask
Definition JUTGamePad.h:133
f32 mAnalogRf
Definition JUTGamePad.h:129
u32 mTrigger
Definition JUTGamePad.h:122
u8 mAnalogR
Definition JUTGamePad.h:127
f32 mAnalogLf
Definition JUTGamePad.h:128
u32 mRepeat
Definition JUTGamePad.h:130
void setRepeat(u32 mask, u32 delay, u32 rate)
Definition JUTGamePad.cpp:628
u8 mAnalogA
Definition JUTGamePad.h:124
u32 mRelease
Definition JUTGamePad.h:123
u32 mRepeatDelay
Definition JUTGamePad.h:134
CButton()
Definition JUTGamePad.h:116
Definition JUTGamePad.h:174
static void stopMotor(int port, bool hard_stop)
Definition JUTGamePad.cpp:495
CRumble(JUTGamePad *pad)
Definition JUTGamePad.h:175
static bool isEnabled(u32 mask)
Definition JUTGamePad.h:200
static u32 mEnabled
Definition JUTGamePad.h:179
void stopMotorHard(int port)
Definition JUTGamePad.h:198
static bool isEnabledPort(int port)
Definition JUTGamePad.h:202
void stopPatternedRumble(s16 port)
Definition JUTGamePad.cpp:585
u8 * field_0x10
Definition JUTGamePad.h:211
void startPatternedRumble(void *data, ERumble rumble, u32 length)
Definition JUTGamePad.cpp:565
static void startMotor(int port)
Definition JUTGamePad.cpp:487
u32 mLength
Definition JUTGamePad.h:208
ERumble
Definition JUTGamePad.h:181
@ VAL_1
Definition JUTGamePad.h:183
@ VAL_2
Definition JUTGamePad.h:184
@ VAL_0
Definition JUTGamePad.h:182
u8 * mPattern
Definition JUTGamePad.h:209
u32 mFrameCount
Definition JUTGamePad.h:210
void stopPatternedRumbleAtThePeriod()
Definition JUTGamePad.cpp:592
static bool mStatus[4]
Definition JUTGamePad.h:178
static u32 sChannelMask[4]
Definition JUTGamePad.h:5
static void setEnabled(u32 mask)
Definition JUTGamePad.cpp:610
void clear()
Definition JUTGamePad.cpp:467
u32 mFrame
Definition JUTGamePad.h:207
void triggerPatternedRumble(u32 length)
Definition JUTGamePad.cpp:556
Definition JUTGamePad.h:153
f32 mValue
Definition JUTGamePad.h:166
void clear()
Definition JUTGamePad.cpp:388
void clear(JUTGamePad *pad)
s8 mRawY
Definition JUTGamePad.h:169
f32 mPosY
Definition JUTGamePad.h:165
f32 mPosX
Definition JUTGamePad.h:164
static f32 sPressPoint
Definition JUTGamePad.h:154
CStick()
Definition JUTGamePad.h:157
s16 mAngle
Definition JUTGamePad.h:167
static f32 sReleasePoint
Definition JUTGamePad.h:155
s8 mRawX
Definition JUTGamePad.h:168
Definition JUTGamePad.h:28
void stopMotor()
Definition JUTGamePad.h:110
void stopPatternedRumble()
Definition JUTGamePad.h:63
static bool mListInitialized
Definition JUTGamePad.h:219
static u32 sRumbleSupported
Definition JUTGamePad.h:229
static u8 mPadAssign[4]
Definition JUTGamePad.h:226
static BOOL init()
Definition JUTGamePad.cpp:65
static JUTGamePad * getGamePad(int port)
Definition JUTGamePad.cpp:597
f32 getMainStickX() const
Definition JUTGamePad.h:84
void startMotorWave(void *data, CRumble::ERumble rumble, u32 length)
Definition JUTGamePad.h:214
void checkResetCallback(OSTime holdTime)
Definition JUTGamePad.cpp:213
f32 getMainStickValue() const
Definition JUTGamePad.h:86
u8 field_0xa8
Definition JUTGamePad.h:243
u8 getAnalogR() const
Definition JUTGamePad.h:95
s16 getMainStickAngle() const
Definition JUTGamePad.h:87
EPadPort
Definition JUTGamePad.h:39
@ EPort4
Definition JUTGamePad.h:44
@ EPort2
Definition JUTGamePad.h:42
@ EPort3
Definition JUTGamePad.h:43
@ EPort1
Definition JUTGamePad.h:41
@ EPortInvalid
Definition JUTGamePad.h:40
JSULink< JUTGamePad > mLink
Definition JUTGamePad.h:237
static CButton mPadButton[4]
Definition JUTGamePad.h:221
void assign()
Definition JUTGamePad.cpp:173
JUTGamePadRecordBase * getPadReplay() const
Definition JUTGamePad.h:100
EWhichStick
Definition JUTGamePad.h:34
@ EMainStick
Definition JUTGamePad.h:35
@ ESubStick
Definition JUTGamePad.h:36
u8 getAnalogB() const
Definition JUTGamePad.h:93
virtual ~JUTGamePad()
Definition JUTGamePad.cpp:41
static u32 read()
Definition JUTGamePad.cpp:99
CStick mSubStick
Definition JUTGamePad.h:233
static void setAnalogMode(u32 mode)
Definition JUTGamePad.h:70
f32 getSubStickValue() const
Definition JUTGamePad.h:90
s16 mPortNum
Definition JUTGamePad.h:235
static u32 sSuppressPadReset
Definition JUTGamePad.h:227
CRumble mRumble
Definition JUTGamePad.h:234
static bool recalibrate(u32 mask)
Definition JUTGamePad.cpp:637
JUTGamePadRecordBase * mPadRecord
Definition JUTGamePad.h:238
void stopMotorWaveHard()
Definition JUTGamePad.h:172
void clear()
Definition JUTGamePad.cpp:72
EClampMode
Definition JUTGamePad.h:47
@ EClampNone
Definition JUTGamePad.h:48
@ EClampStick
Definition JUTGamePad.h:49
@ EClampCircle
Definition JUTGamePad.h:50
s16 getPortNum() const
Definition JUTGamePad.h:98
static void checkResetSwitch()
Definition JUTGamePad.cpp:290
static PADStatus mPadStatus[4]
Definition JUTGamePad.h:220
f32 getMainStickY() const
Definition JUTGamePad.h:85
JUTGamePadRecordBase * getPadRecord() const
Definition JUTGamePad.h:101
u8 field_0x9c[4]
Definition JUTGamePad.h:241
static s8 getPortStatus(u32 port)
Definition JUTGamePad.h:113
C3ButtonReset mButtonReset
Definition JUTGamePad.h:240
CButton mButton
Definition JUTGamePad.h:231
u32 testTrigger(u32 button) const
Definition JUTGamePad.h:103
void stopMotorHard()
Definition JUTGamePad.h:111
static JSUList< JUTGamePad > mPadList
Definition JUTGamePad.h:218
void update()
Definition JUTGamePad.cpp:240
EStickMode
Definition JUTGamePad.h:30
@ EStickMode1
Definition JUTGamePad.h:31
f32 getSubStickX() const
Definition JUTGamePad.h:88
s8 getErrorStatus() const
Definition JUTGamePad.h:96
bool isPushing3ButtonReset() const
Definition JUTGamePad.h:105
CStick mMainStick
Definition JUTGamePad.h:232
static EStickMode sStickMode
Definition JUTGamePad.h:224
static void clearResetOccurred()
Definition JUTGamePad.h:75
u32 getButton() const
Definition JUTGamePad.h:82
static CStick mPadMStick[4]
Definition JUTGamePad.h:222
static CStick mPadSStick[4]
Definition JUTGamePad.h:223
static void setResetCallback(callbackFn callback, void *arg)
Definition JUTGamePad.h:77
s16 getSubStickAngle() const
Definition JUTGamePad.h:91
void stopMotorWave()
Definition JUTGamePad.h:109
f32 getSubStickY() const
Definition JUTGamePad.h:89
u32 getTrigger() const
Definition JUTGamePad.h:83
s8 mErrorStatus
Definition JUTGamePad.h:236
JUTGamePadRecordBase * mPadReplay
Definition JUTGamePad.h:239
static void clearForReset()
Definition JUTGamePad.cpp:309
static s32 sAnalogMode
Definition JUTGamePad.h:228
u8 getAnalogL() const
Definition JUTGamePad.h:94
u8 getAnalogA() const
Definition JUTGamePad.h:92
OSTime mResetHoldStartTime
Definition JUTGamePad.h:242
static int sClampMode
Definition JUTGamePad.h:225
void initList()
Definition JUTGamePad.cpp:51
Definition pad.h:47
s8 error
Definition pad.h:57
int BOOL
Definition types.h:27
signed char s8
Definition types.h:4
unsigned long u32
Definition types.h:10
float f32
Definition types.h:22
signed short s16
Definition types.h:5
signed long s32
Definition types.h:6
unsigned char u8
Definition types.h:8