NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
GXHardware.h
1/**
2 * For more details, see:
3 * https://www.gc-forever.com/yagcd/chap8.html#sec8
4 * https://www.gc-forever.com/yagcd/chap5.html#sec5
5 * https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/VideoCommon/BPMemory.h
6 * https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/VideoCommon/XFMemory.h
7 * https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/VideoCommon/OpcodeDecoding.h
8 * https://patents.google.com/patent/US6700586B1/en
9 * https://patents.google.com/patent/US6639595B1/en
10 * https://patents.google.com/patent/US7002591
11 * https://patents.google.com/patent/US6697074
12 */
13
14#ifndef RVL_SDK_GX_HARDWARE_H
15#define RVL_SDK_GX_HARDWARE_H
16#include <types.h>
17
18#include <revolution/GX/GXTypes.h>
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/************************************************************
24 *
25 *
26 * GX FIFO
27 *
28 *
29 ***********************************************************/
30
31/**
32 * FIFO write/gather pipe
33 */
34extern volatile union {
35 // 1-byte
36 char c;
37 unsigned char uc;
38 // 2-byte
39 short s;
40 unsigned short us;
41 // 4-byte
42 int i;
43 unsigned int ui;
44 void* p;
45 float f;
46} WGPIPE AT_ADDRESS(0xCC008000);
47
48/**
49 * FIFO commands
50 */
51typedef enum {
52 GX_FIFO_CMD_NOOP = 0x00,
53
54 GX_FIFO_CMD_LOAD_BP_REG = 0x61,
55 GX_FIFO_CMD_LOAD_CP_REG = 0x08,
56 GX_FIFO_CMD_LOAD_XF_REG = 0x10,
57
58 GX_FIFO_CMD_LOAD_INDX_A = 0x20,
59 GX_FIFO_CMD_LOAD_INDX_B = 0x28,
60 GX_FIFO_CMD_LOAD_INDX_C = 0x30,
61 GX_FIFO_CMD_LOAD_INDX_D = 0x38,
62
63 GX_FIFO_CMD_CALL_DL = 0x40,
64 GX_FIFO_CMD_INVAL_VTX = 0x48,
65
66 GX_FIFO_CMD_DRAW_POINTS = GX_POINTS,
67 GX_FIFO_CMD_DRAW_LINES = GX_LINES,
68 GX_FIFO_CMD_DRAW_LINESTRIP = GX_LINESTRIP,
69 GX_FIFO_CMD_DRAW_TRIANGLES = GX_TRIANGLES,
70 GX_FIFO_CMD_DRAW_TRIANGLESTRIP = GX_TRIANGLESTRIP,
71 GX_FIFO_CMD_DRAW_TRIANGLEFAN = GX_TRIANGLEFAN,
72 GX_FIFO_CMD_DRAW_QUADS = GX_QUADS,
73} GXFifoCmd;
74
75/**
76 * FIFO command sizes
77 */
78#define GX_FIFO_CMD_LOAD_INDX_SIZE 5
79#define GX_FIFO_CMD_DRAW_SIZE 3
80
81#define __GX_FIFO_SET_LOAD_INDX_DST(reg, x) ((reg) = GX_BITSET(reg, 20, 12, x))
82#define __GX_FIFO_SET_LOAD_INDX_NELEM(reg, x) ((reg) = GX_BITSET(reg, 16, 4, x))
83#define __GX_FIFO_SET_LOAD_INDX_INDEX(reg, x) ((reg) = GX_BITSET(reg, 0, 16, x))
84
85#define __GX_FIFO_LOAD_INDX(reg, dst, nelem, index) \
86 { \
87 u32 cmd = 0; \
88 __GX_FIFO_SET_LOAD_INDX_DST(cmd, dst); \
89 __GX_FIFO_SET_LOAD_INDX_NELEM(cmd, nelem); \
90 __GX_FIFO_SET_LOAD_INDX_INDEX(cmd, index); \
91 WGPIPE.c = reg; \
92 WGPIPE.i = cmd; \
93 }
94
95#define GX_FIFO_LOAD_INDX_A(dst, nelem, index) \
96 __GX_FIFO_LOAD_INDX(GX_FIFO_CMD_LOAD_INDX_A, dst, nelem, index)
97
98#define GX_FIFO_LOAD_INDX_B(dst, nelem, index) \
99 __GX_FIFO_LOAD_INDX(GX_FIFO_CMD_LOAD_INDX_B, dst, nelem, index)
100
101#define GX_FIFO_LOAD_INDX_C(dst, nelem, index) \
102 __GX_FIFO_LOAD_INDX(GX_FIFO_CMD_LOAD_INDX_C, dst, nelem, index)
103
104#define GX_FIFO_LOAD_INDX_D(dst, nelem, index) \
105 __GX_FIFO_LOAD_INDX(GX_FIFO_CMD_LOAD_INDX_D, dst, nelem, index)
106
107/************************************************************
108 *
109 *
110 * GX Blitting Processor (BP)
111 *
112 *
113 ***********************************************************/
114
115/**
116 * Load immediate value into BP register
117 */
118#define GX_BP_LOAD_REG(data) \
119 WGPIPE.c = GX_FIFO_CMD_LOAD_BP_REG; \
120 WGPIPE.i = (data);
121
122/**
123 * Set BP command opcode (first 8 bits)
124 */
125#define GX_BP_SET_OPCODE(cmd, opcode) (cmd) = GX_BITSET(cmd, 0, 8, (opcode))
126
127#define GX_BP_OPCODE_SHIFT 24
128#define GX_BP_CMD_SZ (sizeof(u8) + sizeof(u32))
129
130/************************************************************
131 *
132 *
133 * GX Command Processor (CP)
134 *
135 *
136 ***********************************************************/
137
138/**
139 * Load immediate value into CP register
140 */
141#define GX_CP_LOAD_REG(addr, data) \
142 WGPIPE.c = GX_FIFO_CMD_LOAD_CP_REG; \
143 WGPIPE.c = (addr); \
144 WGPIPE.i = (data);
145
146#define GX_CP_CMD_SZ (sizeof(u8) + sizeof(u8) + sizeof(u32))
147
148/************************************************************
149 *
150 *
151 * GX Transform Unit (XF)
152 *
153 *
154 ***********************************************************/
155
156/**
157 * XF memory
158 */
159typedef enum {
160 GX_XF_MEM_POSMTX = 0x0000,
161 GX_XF_MEM_NRMMTX = 0x0400,
162 GX_XF_MEM_DUALTEXMTX = 0x0500,
163 GX_XF_MEM_LIGHTOBJ = 0x0600
164} GXXfMem;
165
166/**
167 * Header for an XF register load
168 */
169#define GX_XF_LOAD_REG_HDR(addr) \
170 WGPIPE.c = GX_FIFO_CMD_LOAD_XF_REG; \
171 WGPIPE.i = (addr);
172
173/**
174 * Load immediate value into XF register
175 */
176#define GX_XF_LOAD_REG(addr, data) \
177 GX_XF_LOAD_REG_HDR(addr); \
178 WGPIPE.i = (data);
179
180#define GX_XF_CMD_SZ (sizeof(u8) + sizeof(u32) + sizeof(u32))
181
182/**
183 * Load immediate values into multiple XF registers
184 */
185#define GX_XF_LOAD_REGS(size, addr) \
186 { \
187 u32 cmd = 0; \
188 cmd |= (addr); \
189 cmd |= (size) << 16; \
190 GX_XF_LOAD_REG_HDR(cmd); \
191 }
192
193/**
194 * Enums for Tex0-Tex7 register fields
195 */
196typedef enum {
197 GX_XF_TEX_PROJ_ST, // (s,t): texmul is 2x4
198 GX_XF_TEX_PROJ_STQ // (s,t,q): texmul is 3x4
199} GXXfTexProj;
200
201typedef enum {
202 GX_XF_TEX_FORM_AB11, // (A, B, 1.0, 1.0) (used for regular texture source)
203 GX_XF_TEX_FORM_ABC1 // (A, B, C, 1.0) (used for geometry or normal source)
204} GXXfTexForm;
205
206typedef enum {
207 GX_XF_TG_REGULAR, // Regular transformation (transform incoming data)
208 GX_XF_TG_BUMP, // Texgen bump mapping
209
210 GX_XF_TG_CLR0, // Color texgen: (s,t)=(r,g:b) (g and b are concatenated),
211 // color0
212
213 GX_XF_TG_CLR1 // Color texgen: (s,t)=(r,g:b) (g and b are concatenated),
214 // color1
215} GXXfTexGen;
216
217/**
218 * Misc. hardware enums
219 */
220typedef enum {
221 GX_RAS_COLOR0A0,
222 GX_RAS_COLOR1A1,
223 GX_RAS_ALPHA_BUMP = 5,
224 GX_RAS_ALPHA_BUMPN,
225 GX_RAS_COLOR_ZERO,
226
227 GX_RAS_MAX_CHANNEL
228} GXRasChannelID;
229
230typedef enum {
231 GX_TEVREG_COLOR,
232 GX_TEVREG_KONST,
233} GXTevRegType;
234
235#ifdef __cplusplus
236}
237#endif
238#endif