Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
gte.h
Go to the documentation of this file.
1#ifndef GTE_H
2#define GTE_H
3
4/* The GTE instructions that C can't say, as the SDK's inline_c.h has them
5 but with the real encodings in place of the ones DMPSX patches. The SDK's
6 gtemac.h builds its larger macros (gte_MulMatrix0, gte_CompMatrix...)
7 from these. */
8
9/* the interpolation factor (IR0) */
10#define gte_lddp(r0) __asm__ volatile( \
11 "mtc2 %0, $8" \
12 : \
13 : "r"(r0))
14
15/* an SVECTOR into IR1-IR3 */
16#define gte_ldsv(r0) __asm__ volatile( \
17 "lhu $12, 0(%0);" \
18 "lhu $13, 2(%0);" \
19 "lhu $14, 4(%0);" \
20 "mtc2 $12, $9;" \
21 "mtc2 $13, $10;" \
22 "mtc2 $14, $11" \
23 : \
24 : "r"(r0) \
25 : "$12", "$13", "$14")
26
27/* IR1-IR3 = IR0 * IR1-IR3 >> 12 */
28#define gte_gpf12() __asm__ volatile( \
29 "nop;" \
30 "nop;" \
31 ".word 0x4B98003D")
32
33/* IR1-IR3 into an SVECTOR */
34#define gte_stsv(r0) __asm__ volatile( \
35 "mfc2 $12, $9;" \
36 "mfc2 $13, $10;" \
37 "mfc2 $14, $11;" \
38 "sh $12, 0(%0);" \
39 "sh $13, 2(%0);" \
40 "sh $14, 4(%0)" \
41 : \
42 : "r"(r0) \
43 : "$12", "$13", "$14", "memory")
44
45/* a MATRIX's rotation into the GTE (RT) */
46#define gte_SetRotMatrix(r0) __asm__ volatile( \
47 "lw $12, 0(%0);" \
48 "lw $13, 4(%0);" \
49 "ctc2 $12, $0;" \
50 "ctc2 $13, $1;" \
51 "lw $12, 8(%0);" \
52 "lw $13, 12(%0);" \
53 "lw $14, 16(%0);" \
54 "ctc2 $12, $2;" \
55 "ctc2 $13, $3;" \
56 "ctc2 $14, $4" \
57 : \
58 : "r"(r0) \
59 : "$12", "$13", "$14")
60
61/* an SVECTOR into V0 */
62#define gte_ldv0(r0) __asm__ volatile( \
63 "lwc2 $0, 0(%0);" \
64 "lwc2 $1, 4(%0)" \
65 : \
66 : "r"(r0))
67
68/* an SVECTOR that may not be word aligned into V0 */
69#define gte_ldv0_unaligned(r0) __asm__ volatile( \
70 "lwl $12, 3(%0);" \
71 "lwr $12, 0(%0);" \
72 "lhu $13, 4(%0);" \
73 "mtc2 $12, $0;" \
74 "mtc2 $13, $1" \
75 : \
76 : "r"(r0) \
77 : "$12", "$13")
78
79/* V0 through RT and TR, then the perspective (SXY2, SZ3) */
80#define gte_rtps() __asm__ volatile( \
81 "nop;" \
82 "nop;" \
83 ".word 0x4A180001")
84
85/* MAC1-MAC3 = RT * V0 >> 12 */
86#define gte_rtv0() __asm__ volatile( \
87 "nop;" \
88 "nop;" \
89 ".word 0x4A486012")
90
91/* SXY2 into a word */
92#define gte_stsxy(r0) __asm__ volatile( \
93 "swc2 $14, 0(%0)" \
94 : \
95 : "r"(r0) \
96 : "memory")
97
98/* the flags into a word */
99#define gte_stflg(r0) __asm__ volatile( \
100 "cfc2 $12, $31;" \
101 "nop;" \
102 "sw $12, 0(%0)" \
103 : \
104 : "r"(r0) \
105 : "$12", "memory")
106
107/* MAC1-MAC3 into a VECTOR */
108#define gte_stlvnl(r0) __asm__ volatile( \
109 "swc2 $25, 0(%0);" \
110 "swc2 $26, 4(%0);" \
111 "swc2 $27, 8(%0)" \
112 : \
113 : "r"(r0) \
114 : "memory")
115
116/* SZ3 / 4 into a word, the depth in the ordering table */
117#define gte_stszotz(r0) __asm__ volatile( \
118 "mfc2 $12, $19;" \
119 "nop;" \
120 "sra $12, $12, 2;" \
121 "sw $12, 0(%0)" \
122 : \
123 : "r"(r0) \
124 : "$12", "memory")
125
126/* a MATRIX's translation into the GTE (TR) */
127#define gte_SetTransMatrix(r0) __asm__ volatile( \
128 "lw $12, 20(%0);" \
129 "lw $13, 24(%0);" \
130 "ctc2 $12, $5;" \
131 "lw $14, 28(%0);" \
132 "ctc2 $13, $6;" \
133 "ctc2 $14, $7" \
134 : \
135 : "r"(r0) \
136 : "$12", "$13", "$14")
137
138/* a VECTOR's low halves into V0 */
139#define gte_ldlv0(r0) __asm__ volatile( \
140 "lhu $13, 4(%0);" \
141 "lhu $12, 0(%0);" \
142 "sll $13, $13, 16;" \
143 "or $12, $12, $13;" \
144 "mtc2 $12, $0;" \
145 "lwc2 $1, 8(%0)" \
146 : \
147 : "r"(r0) \
148 : "$12", "$13")
149
150/* a MATRIX's column into IR1-IR3 */
151#define gte_ldclmv(r0) __asm__ volatile( \
152 "lhu $12, 0(%0);" \
153 "lhu $13, 6(%0);" \
154 "lhu $14, 12(%0);" \
155 "mtc2 $12, $9;" \
156 "mtc2 $13, $10;" \
157 "mtc2 $14, $11" \
158 : \
159 : "r"(r0) \
160 : "$12", "$13", "$14")
161
162/* MAC1-MAC3 = RT * V0 + TR */
163#define gte_rt() __asm__ volatile( \
164 "nop;" \
165 "nop;" \
166 ".word 0x4A480012")
167
168/* MAC1-MAC3 = RT * IR1-IR3 >> 12 */
169#define gte_rtir() __asm__ volatile( \
170 "nop;" \
171 "nop;" \
172 ".word 0x4A49E012")
173
174/* IR1-IR3 into a MATRIX's column */
175#define gte_stclmv(r0) __asm__ volatile( \
176 "mfc2 $12, $9;" \
177 "mfc2 $13, $10;" \
178 "mfc2 $14, $11;" \
179 "sh $12, 0(%0);" \
180 "sh $13, 6(%0);" \
181 "sh $14, 12(%0)" \
182 : \
183 : "r"(r0) \
184 : "$12", "$13", "$14", "memory")
185
186/* a MATRIX's rotation into the GTE's light matrix (L) */
187#define gte_SetLightMatrix(r0) __asm__ volatile( \
188 "lw $12, 0(%0);" \
189 "lw $13, 4(%0);" \
190 "ctc2 $12, $8;" \
191 "ctc2 $13, $9;" \
192 "lw $12, 8(%0);" \
193 "lw $13, 12(%0);" \
194 "lw $14, 16(%0);" \
195 "ctc2 $12, $10;" \
196 "ctc2 $13, $11;" \
197 "ctc2 $14, $12" \
198 : \
199 : "r"(r0) \
200 : "$12", "$13", "$14")
201
202/* the color of V0 as a normal under the lights (RGB2) */
203#define gte_ncs() __asm__ volatile( \
204 "nop;" \
205 "nop;" \
206 ".word 0x4AC8041E")
207
208/* RGB2 into a word */
209#define gte_strgb(r0) __asm__ volatile( \
210 "swc2 $22, 0(%0)" \
211 : \
212 : "r"(r0) \
213 : "memory")
214
215/* three screen points (SXY0-SXY2) */
216#define gte_ldsxy3(r0, r1, r2) __asm__ volatile( \
217 "mtc2 %0, $12;" \
218 "mtc2 %2, $14;" \
219 "mtc2 %1, $13" \
220 : \
221 : "r"(r0), "r"(r1), "r"(r2))
222
223/* MAC0 = the winding of SXY0-SXY2, which side of a polygon faces us */
224#define gte_nclip() __asm__ volatile( \
225 "nop;" \
226 "nop;" \
227 ".word 0x4B400006")
228
229/* MAC0 into a word */
230#define gte_stopz(r0) __asm__ volatile( \
231 "swc2 $24, 0(%0)" \
232 : \
233 : "r"(r0) \
234 : "memory")
235
236/* three depths (SZ1-SZ3) */
237#define gte_ldsz3(r0, r1, r2) __asm__ volatile( \
238 "mtc2 %0, $17;" \
239 "mtc2 %1, $18;" \
240 "mtc2 %2, $19" \
241 : \
242 : "r"(r0), "r"(r1), "r"(r2))
243
244/* four depths (SZ0-SZ3) */
245#define gte_ldsz4(r0, r1, r2, r3) __asm__ volatile( \
246 "mtc2 %0, $16;" \
247 "mtc2 %1, $17;" \
248 "mtc2 %2, $18;" \
249 "mtc2 %3, $19" \
250 : \
251 : "r"(r0), "r"(r1), "r"(r2), "r"(r3))
252
253/* OTZ = the average of SZ1-SZ3 */
254#define gte_avsz3() __asm__ volatile( \
255 "nop;" \
256 "nop;" \
257 ".word 0x4B58002D")
258
259/* OTZ = the average of SZ0-SZ3 */
260#define gte_avsz4() __asm__ volatile( \
261 "nop;" \
262 "nop;" \
263 ".word 0x4B68002E")
264
265/* OTZ into a word */
266#define gte_stotz(r0) __asm__ volatile( \
267 "swc2 $7, 0(%0)" \
268 : \
269 : "r"(r0) \
270 : "memory")
271
272#include <gtemac.h>
273
274#endif /* GTE_H */