NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
WPADInternal.h
1#ifndef RVL_SDK_WPAD_INTERNAL_H
2#define RVL_SDK_WPAD_INTERNAL_H
3#include <types.h>
4
5// Public API
6#include <revolution/WPAD/WPAD.h>
7#include <revolution/WPAD/WPADHIDParser.h>
8#include <revolution/WPAD/WPADMem.h>
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#define RX_BUFFER_SIZE ROUND_UP(sizeof(WPADStatusEx), 32)
14
15#define WPAD_CONFIG_BLOCK_CHECKSUM_BIAS 0x55
16#define WPAD_MAX_CONFIG_BLOCKS 2
17
18#define WPAD_DPD_CONFIG_BLOCK_CHECKSUM 10
19#define WPAD_DPD_CONFIG_BLOCK_SIZE 11
20
21#define WPAD_DEV_CONFIG_BLOCK_CHECKSUM 9
22#define WPAD_DEV_CONFIG_BLOCK_SIZE 10
23
24#define DPD_CFG_OBJ_BL 0
25#define DPD_CFG_OBJ_BR 1
26#define DPD_CFG_OBJ_TR 2
27#define DPD_CFG_OBJ_TL 3
28
29/*
30 * Wiimote memory addresses
31 */
32// clang-format off
33#define WM_ADDR_MEM_DEV_CONFIG_0 WM_MEM_ADDR(0x0000)
34#define WM_ADDR_MEM_GAME_INFO_0 WM_MEM_ADDR(0x002A)
35#define WM_ADDR_MEM_GAME_INFO_1 WM_MEM_ADDR(0x0062)
36#define WM_ADDR_MEM_176C WM_MEM_ADDR(0x176C)
37#define WM_ADDR_MEM_1770 WM_MEM_ADDR(0x1770)
38// clang-format on
39
40/*
41 * Wiimote extension register addresses
42 */
43// clang-format off
44// Speaker register addresses
45#define WM_REG_SPEAKER_01 WM_EXT_REG_ADDR(SPEAKER, 0x01)
46#define WM_REG_SPEAKER_08 WM_EXT_REG_ADDR(SPEAKER, 0x08)
47#define WM_REG_SPEAKER_09 WM_EXT_REG_ADDR(SPEAKER, 0x09)
48
49// Extension register addresses
50#define WM_REG_EXTENSION_CONFIG WM_EXT_REG_ADDR(EXTENSION, 0x20)
51#define WM_REG_EXTENSION_40 WM_EXT_REG_ADDR(EXTENSION, 0x40)
52#define WM_REG_EXTENSION_CERT_PARAM WM_EXT_REG_ADDR(EXTENSION, 0x50)
53#define WM_REG_EXTENSION_F0 WM_EXT_REG_ADDR(EXTENSION, 0xF0)
54#define WM_REG_EXTENSION_CERT_CHALLENGE WM_EXT_REG_ADDR(EXTENSION, 0xF1)
55#define WM_REG_EXTENSION_F2 WM_EXT_REG_ADDR(EXTENSION, 0xF2)
56#define WM_REG_EXTENSION_F3 WM_EXT_REG_ADDR(EXTENSION, 0xF3)
57#define WM_REG_EXTENSION_EXT_TYPE_2 WM_EXT_REG_ADDR(EXTENSION, 0xF6)
58#define WM_REG_EXTENSION_CERT_PROBE WM_EXT_REG_ADDR(EXTENSION, 0xF7)
59#define WM_REG_EXTENSION_FA WM_EXT_REG_ADDR(EXTENSION, 0xFA)
60#define WM_REG_EXTENSION_FB WM_EXT_REG_ADDR(EXTENSION, 0xFB)
61#define WM_REG_EXTENSION_DEV_MODE WM_EXT_REG_ADDR(EXTENSION, 0xFE)
62#define WM_REG_EXTENSION_ID_BYTE WM_EXT_REG_ADDR(EXTENSION, 0xFF)
63
64// IR camera register addresses
65#define WM_REG_DPD_CONFIG_BLOCK_1 WM_EXT_REG_ADDR(DPD, 0x00)
66#define WM_REG_DPD_CONFIG_BLOCK_2 WM_EXT_REG_ADDR(DPD, 0x1A)
67#define WM_REG_DPD_30 WM_EXT_REG_ADDR(DPD, 0x30)
68#define WM_REG_DPD_DATA_FORMAT WM_EXT_REG_ADDR(DPD, 0x33)
69// clang-format on
70
71#define WM_EXTENSION_CONFIG_SIZE 0x20 // 0xA40020 - 0xA4003F
72
73typedef enum {
74 WPAD_STATE_EXT_UNINITIALIZED,
75 WPAD_STATE_EXT_INITIALIZED,
76 WPAD_STATE_EXT_ENCRYPTED,
77 WPAD_STATE_EXT_ENCRYPTED_3RD,
78} WPADExtensionState;
79
80typedef enum {
81 WPAD_RADIO_QUALITY_GOOD, // 80+
82 WPAD_RADIO_QUALITY_BAD // 80-
83 // if radioQuality calculation == 80, state stays the same
84} WPADRadioQuality;
85
86typedef enum {
87 WPAD_ILBUF_NONE = 0,
88
89 WPAD_ILBUF_BUF3E = (1 << 0),
90 WPAD_ILBUF_BUF3F = (1 << 1),
91
92 WPAD_ILBUF_ALL = WPAD_ILBUF_BUF3E | WPAD_ILBUF_BUF3F,
93} WPADInterleaveBufferFlags;
94
95typedef struct WPADCommand {
96 u32 reportID; // at 0x0
97 u8 dataBuf[RPT_MAX_SIZE]; // at 0x4
98 u16 dataLength; // at 0x1A
99 void* dstBuf; // at 0x1C
100 u16 readLength; // at 0x20
101 u32 readAddress; // at 0x24
102 WPADInfo* statusReportOut; // at 0x28
103 WPADCallback cmdCB; // at 0x2C
105
106typedef struct WPADCommandQueue {
107 s8 front; // at 0x1
108 s8 back; // at 0x0
109 WPADCommand* buffer; // at 0x4
110 u32 capacity; // at 0x8
112
113typedef struct WPADDevConfig {
114 DPDObject dpd[WPAD_MAX_DPD_OBJECTS]; // at 0x0
115
116 s16 accX0g; // at 0x20
117 s16 accY0g; // at 0x22
118 s16 accZ0g; // at 0x24
119
120 s16 accX1g; // at 0x26
121 s16 accY1g; // at 0x28
122 s16 accZ1g; // at 0x2A
123
124 u8 motor; // at 0x2C
125 u8 volume; // at 0x2D
127
128typedef struct WPADExtConfig {
129 union {
130 struct { /* WPADFSConfig */
131 s16 stickXCenter; // at 0x0
132 s16 at_0x02; // at 0x2
133 s16 at_0x04; // at 0x4
134 s16 stickYCenter; // at 0x6
135 s16 at_0x08; // at 0x8
136 s16 at_0x0a; // at 0xA
137
138 s16 accX0g; // at 0xC
139 s16 accY0g; // at 0xE
140 s16 accZ0g; // at 0x10
141
142 s16 accX1g; // at 0x12
143 s16 accY1g; // at 0x14
144 s16 accZ1g; // at 0x16
145 } fs;
146
147 struct { /* WPADCLConfig */
148 s16 lStickXCenter; // at 0x0
149 s16 at_0x02; // at 0x2
150 s16 at_0x04; // at 0x4
151 s16 lStickYCenter; // at 0x6
152 s16 at_0x08; // at 0x8
153 s16 at_0x0a; // at 0xA
154
155 s16 rStickXCenter; // at 0xC
156 s16 at_0x0e; // at 0xE
157 s16 at_0x10; // at 0x10
158 s16 rStickYCenter; // at 0x12
159 s16 at_0x14; // at 0x14
160 s16 at_0x16; // at 0x16
161
162 u8 triggerLZero; // at 0x18
163 u8 triggerRZero; // at 0x19
164 } cl;
165 };
167
168typedef struct WPADCB {
169 WPADGameInfo gameInfo; // at 0x0
170 s32 UNK_0x38[2];
171 u8 rxBufMain[RX_BUFFER_SIZE]; // at 0x40
172 u8 rxBufs[2][RX_BUFFER_SIZE]; // at 0xA0
173 WPADCommandQueue stdCmdQueue; // at 0x160
174 WPADCommand stdCmdQueueList[24]; // at 0x16C
175 WPADCommandQueue extCmdQueue; // at 0x5EC
176 WPADCommand extCmdQueueList[12]; // at 0x5F8
177 WPADInfo wpInfo; // at 0x838
178 WPADInfo* wpInfoOut; // at 0x850
179 WPADDevConfig devConfig; // at 0x854
180 WPADExtConfig extConfig; // at 0x882
181 WPADCallback cmdBlkCB; // at 0x89C
182 WPADExtensionCallback extensionCB; // at 0x8A0
183 WPADConnectCallback connectCB; // at 0x8A4
184 WPADSamplingCallback samplingCB; // at 0x8A8
185 union {
186 WPADStatus* samplingBuf;
187 WPADStatusEx* samplingBufEx;
188 WPADFSStatus* samplingBufFS;
189 WPADCLStatus* samplingBufCL;
190 }; // at 0x8AC
191 u32 samplingBufIndex; // at 0x8B0
192 u32 samplingBufSize; // at 0x8B4
193 u32 dataFormat; // at 0x8B8
194 s32 status; // at 0x8BC
195 u8 statusReqBusy; // at 0x8C0
196 u8 devType; // at 0x8C1
197 u8 devMode; // at 0x8C2
198 s8 devHandle; // at 0x8C3
199 s32 UNK_0x8C4;
200 u8 rxBufIndex; // at 0x8C8
201 s8 UNK_0x8C9;
202 u8 defaultDpdSize; // at 0x8CA
203 u8 currentDpdCommand; // at 0x8CB
204 u8 pendingDpdCommand; // at 0x8CC
205 u8 radioQuality; // at 0x8CD
206 u8 radioQualityOkMs; // at 0x8CE
207 u8 audioFrames; // at 0x8CF
208 u32 motorBusy; // at 0x8D0
209 BOOL motorRunning; // at 0x8D4
210 BOOL used; // at 0x8D8
211 BOOL handshakeFinished; // at 0x8DC
212 s32 configIndex; // at 0x8E0
213 OSThreadQueue threadQueue; // at 0x8E4
214 s64 lastControllerDataUpdate; // at 0x8F0
215 u16 filterDiffDpd; // at 0x8F8
216 u16 filterSameDpd; // at 0x8FA
217 u16 filterDiffAcc; // at 0x8FC
218 u16 filterSameAcc; // at 0x8FE
219 u16 filterDiffExt; // at 0x900
220 u16 filterSameExt; // at 0x902
221 s64 lastReportSendTime; // at 0x908
222 u8 UNK_0x910;
223 u8 calibrated; // at 0x911
224 u16 comboHeld; // at 0x912
225 u8 encryptionKey[16]; // at 0x914
226 u8 decryptAddTable[8]; // at 0x924
227 u8 decryptXorTable[8]; // at 0x92C
228 u8 wmReadDataBuf[64]; // at 0x934
229 u8* wmReadDataPtr; // at 0x974
230 u32 wmReadAddress; // at 0x978
231 int wmReadHadError; // at 0x97C
232 u16 wmReadLength; // at 0x980
233 s8 UNK_0x982;
234 u8 radioSensitivity; // at 0x983
235 u16 copyOutCount; // at 0x984
236 u8 sleeping; // at 0x986
237 u8 lastReportID; // at 0x987
238 WPADCallback getInfoCB; // at 0x988
239 u8 getInfoBusy; // at 0x98C
240 u8 UNK_0x98F[0x9A0 - 0x990];
241} WPADCB;
242
243extern WPADCB _wpd[WPAD_MAX_CONTROLLERS];
244extern WPADCB* _wpdcb[WPAD_MAX_CONTROLLERS];
245
246void WPADiInitSub(void);
247
248void WPADiExcludeButton(s32 chan);
249void WPADiCopyOut(s32 chan);
250
251BOOL WPADiSendSetPort(WPADCommandQueue* pQueue, u8 port,
252 WPADCallback pCallback);
253BOOL WPADiSendSetReportType(WPADCommandQueue* pQueue, s32 format,
254 WPADCallback pCallback);
255BOOL WPADiSendEnableDPD(WPADCommandQueue* pQueue, BOOL enable,
256 WPADCallback pCallback);
257BOOL WPADiSendEnableSpeaker(WPADCommandQueue* pQueue, BOOL enable,
258 WPADCallback pCallback);
259BOOL WPADiSendGetContStat(WPADCommandQueue* pQueue, WPADInfo* pInfo,
260 WPADCallback pCallback);
261BOOL WPADiSendWriteDataCmd(WPADCommandQueue* pQueue, u8 cmd, u32 addr,
262 WPADCallback pCallback);
263BOOL WPADiSendWriteData(WPADCommandQueue* pQueue, const void* pSrc, u16 len,
264 u32 addr, WPADCallback pCallback);
265BOOL WPADiSendReadData(WPADCommandQueue* pQueue, void* pDst, u16 len, u32 addr,
266 WPADCallback pCallback);
267BOOL WPADiSendStreamData(WPADCommandQueue* pQueue, const void* pData, u16 len);
268BOOL WPADiSendMuteSpeaker(WPADCommandQueue* pQueue, BOOL mute,
269 WPADCallback pCallback);
270BOOL WPADiSendDPDCSB(WPADCommandQueue* pQueue, BOOL enable,
271 WPADCallback pCallback);
272
273void WPADiClearQueue(WPADCommandQueue* pQueue);
274BOOL WPADiPushCommand(WPADCommandQueue* pQueue, WPADCommand command);
275BOOL WPADiGetCommand(const WPADCommandQueue* pQueue, WPADCommand* pCommand);
276BOOL WPADiPopCommand(WPADCommandQueue* pQueue);
277
278u16 _WPADGetStackBufferStatus(s32 chan);
279u16 _WPADGetModuleBufferStatus(s32 chan);
280
281void __WPADShutdown(void);
282void __WPADReconnect(void);
283
284#ifdef __cplusplus
285}
286#endif
287#endif