1 /*---------------------------------------------------------------------------*
2 Project: Dolphin GD library
3 File: GDTransform.c
4
5 Copyright 2001 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: GDTransform.c,v $
14 Revision 1.2 02/20/2006 04:24:39 mitu
15 changed include path from dolphin/ to revolution/.
16
17 Revision 1.1.1.1 2005/05/12 02:15:49 yasuh-to
18 transitioned from the Dolphin source tree
19
20
21 4 02/08/05 19:53 Hirose
22 Const type specifier support.
23
24 3 02/05/30 13:40 Hirose
25 Added GDSetTransform.
26
27 2 9/24/01 3:25p Carl
28 Fixed off-by-1 count in GDLoadTexMtxImm.
29
30 1 9/12/01 1:52p Carl
31 Initial revision of GD: Graphics Display List Library.
32
33 $NoKeywords: $
34 *---------------------------------------------------------------------------*/
35
36 #include <revolution/gd.h>
37 #include <revolution/os.h>
38
39 /*---------------------------------------------------------------------------*/
40 // Name: GDLoadPosMtxImm
41 //
42 // Description: Loads position viewing matrix into xfrom block.
43 //
44 // Arguments: mtx viewing matrix
45 // id index of the matrix register file.
46 //
47 // Returns: none
48 //
49 /*---------------------------------------------------------------------------*/
50
GDLoadPosMtxImm(const f32 mtx[3][4],u32 id)51 void GDLoadPosMtxImm ( const f32 mtx[3][4], u32 id )
52 {
53 GDWriteXFCmdHdr(__PosMtxToXFMem(id), (u8)(3*4));
54
55 GDWrite_f32(mtx[0][0]);
56 GDWrite_f32(mtx[0][1]);
57 GDWrite_f32(mtx[0][2]);
58 GDWrite_f32(mtx[0][3]);
59
60 GDWrite_f32(mtx[1][0]);
61 GDWrite_f32(mtx[1][1]);
62 GDWrite_f32(mtx[1][2]);
63 GDWrite_f32(mtx[1][3]);
64
65 GDWrite_f32(mtx[2][0]);
66 GDWrite_f32(mtx[2][1]);
67 GDWrite_f32(mtx[2][2]);
68 GDWrite_f32(mtx[2][3]);
69 }
70
71 /*---------------------------------------------------------------------------*/
72 // Name: GDLoadPosMtxIndx
73 //
74 // Description: Loads viewing matrix directly from memory.
75 //
76 // Arguments: mtx_indx Index into matrix array in main memory.
77 // id Index of the matrix register file.
78 //
79 // Returns:
80 //
81 /*---------------------------------------------------------------------------*/
82
GDLoadPosMtxIndx(u16 mtx_indx,u32 id)83 void GDLoadPosMtxIndx(u16 mtx_indx, u32 id)
84 {
85 GDWriteXFIndxACmd(__PosMtxToXFMem(id), (u8)(3*4), mtx_indx);
86 }
87
88 /*---------------------------------------------------------------------------*/
89 // Name: GDLoadNrmMtxImm
90 //
91 // Description: Loads normal matrix in to xform block
92 //
93 // Arguments: mtx normal matrix data (3x4 matrix).
94 // id Index of the normal matrix register file.
95 //
96 // Returns: none
97 //
98 /*---------------------------------------------------------------------------*/
99
GDLoadNrmMtxImm(const f32 mtx[3][4],u32 id)100 void GDLoadNrmMtxImm ( const f32 mtx[3][4], u32 id )
101 {
102 GDWriteXFCmdHdr(__NrmMtxToXFMem(id), (u8)(3*3));
103
104 GDWrite_f32(mtx[0][0]);
105 GDWrite_f32(mtx[0][1]);
106 GDWrite_f32(mtx[0][2]);
107
108 GDWrite_f32(mtx[1][0]);
109 GDWrite_f32(mtx[1][1]);
110 GDWrite_f32(mtx[1][2]);
111
112 GDWrite_f32(mtx[2][0]);
113 GDWrite_f32(mtx[2][1]);
114 GDWrite_f32(mtx[2][2]);
115 }
116
117 /*---------------------------------------------------------------------------*/
118 // Name: GDLoadNrmMtxImm3x3
119 //
120 // Description: Loads normal matrix in to xform block
121 //
122 // Arguments: mtx normal matrix data (3x3 matrix).
123 // id Index of the normal matrix register file.
124 //
125 // Returns: none
126 //
127 /*---------------------------------------------------------------------------*/
128
GDLoadNrmMtxImm3x3(const f32 mtx[3][3],u32 id)129 void GDLoadNrmMtxImm3x3 ( const f32 mtx[3][3], u32 id )
130 {
131 GDWriteXFCmdHdr(__NrmMtxToXFMem(id), (u8)(3*3));
132
133 GDWrite_f32(mtx[0][0]);
134 GDWrite_f32(mtx[0][1]);
135 GDWrite_f32(mtx[0][2]);
136
137 GDWrite_f32(mtx[1][0]);
138 GDWrite_f32(mtx[1][1]);
139 GDWrite_f32(mtx[1][2]);
140
141 GDWrite_f32(mtx[2][0]);
142 GDWrite_f32(mtx[2][1]);
143 GDWrite_f32(mtx[2][2]);
144 }
145
146 /*---------------------------------------------------------------------------*/
147 // Name: GDLoadNrmMtxIndx3x3
148 //
149 // Description: Load normal matrix directly from external memory.
150 //
151 // Arguments: mtx_indx Index into matrix array in main memory
152 // (3x3 matrices).
153 // id Index of the matrix register file.
154 //
155 // Returns: none
156 //
157 /*---------------------------------------------------------------------------*/
158
GDLoadNrmMtxIndx3x3(u16 mtx_indx,u32 id)159 void GDLoadNrmMtxIndx3x3 ( u16 mtx_indx, u32 id )
160 {
161 GDWriteXFIndxBCmd(__NrmMtxToXFMem(id), (u8)(3*3), mtx_indx);
162 }
163
164 /*---------------------------------------------------------------------------*/
165 // Name: GDLoadTexMtxImm
166 //
167 // Description: Loads texture matrix.
168 //
169 // Arguments: mtx matrix data.
170 // id index of matrix in xf block's matrix array.
171 // type type of matrix (2x4 or 3x4)
172 //
173 // Returns: none.
174 //
175 /*---------------------------------------------------------------------------*/
176
GDLoadTexMtxImm(const f32 mtx[3][4],u32 id,GXTexMtxType type)177 void GDLoadTexMtxImm ( const f32 mtx[3][4], u32 id, GXTexMtxType type )
178 {
179 u16 addr;
180 u8 count;
181
182 if (id >= GX_PTTEXMTX0)
183 {
184 ASSERTMSG(type == GX_MTX3x4, "GDLoadTexMtxImm: invalid matrix type");
185 addr = __DTTMtxToXFMem(id);
186 count = (u8)(3*4);
187 } else {
188 addr = __TexMtxToXFMem(id);
189 count = (u8)((type == GX_MTX2x4) ? (2*4) : (3*4));
190 }
191
192 GDWriteXFCmdHdr(addr, count);
193
194 GDWrite_f32(mtx[0][0]);
195 GDWrite_f32(mtx[0][1]);
196 GDWrite_f32(mtx[0][2]);
197 GDWrite_f32(mtx[0][3]);
198
199 GDWrite_f32(mtx[1][0]);
200 GDWrite_f32(mtx[1][1]);
201 GDWrite_f32(mtx[1][2]);
202 GDWrite_f32(mtx[1][3]);
203
204 if (type == GX_MTX3x4)
205 {
206 GDWrite_f32(mtx[2][0]);
207 GDWrite_f32(mtx[2][1]);
208 GDWrite_f32(mtx[2][2]);
209 GDWrite_f32(mtx[2][3]);
210 }
211 }
212
213 /*---------------------------------------------------------------------------*/
214 // Name: GDLoadTexMtxIndx
215 //
216 // Description: Load texture matrix directly from memory.
217 //
218 // Arguments: mtx_indx Index into matrix array in main memory.
219 // id Index of the matrix register file.
220 // type type of matrix (2x4 or 3x4)
221 //
222 // Returns: None.
223 //
224 /*---------------------------------------------------------------------------*/
225
GDLoadTexMtxIndx(u16 mtx_indx,u32 id,GXTexMtxType type)226 void GDLoadTexMtxIndx ( u16 mtx_indx, u32 id, GXTexMtxType type )
227 {
228 u16 addr;
229 u8 count;
230
231 if (id >= GX_PTTEXMTX0)
232 {
233 ASSERTMSG(type == GX_MTX3x4, "GDLoadTexMtxIndx: invalid matrix type");
234 addr = __DTTMtxToXFMem(id);
235 count = (u8)(3*4);
236 } else {
237 addr = __TexMtxToXFMem(id);
238 count = (u8)((type == GX_MTX2x4) ? (2*4) : (3*4));
239 }
240
241 GDWriteXFIndxCCmd(addr, count, mtx_indx);
242 }
243
244
245
246
247 /*---------------------------------------------------------------------------*/
248 // Name: GDSetCurrentMtx
249 //
250 // Description: Sets the index of default position & normal matrix.
251 //
252 // Arguments: pn...t7 index in the matrix register array in xf block.
253 //
254 // Returns: none
255 //
256 /*---------------------------------------------------------------------------*/
257
GDSetCurrentMtx(u32 pn,u32 t0,u32 t1,u32 t2,u32 t3,u32 t4,u32 t5,u32 t6,u32 t7)258 void GDSetCurrentMtx ( u32 pn, u32 t0, u32 t1, u32 t2, u32 t3,
259 u32 t4, u32 t5, u32 t6, u32 t7 )
260 {
261 u32 regA;
262 u32 regB;
263
264 regA = MATIDX_REG_A(pn, t0, t1, t2, t3);
265 regB = MATIDX_REG_B(t4, t5, t6, t7);
266
267 GDWriteCPCmd( CP_MATINDEX_A, regA ); // W1
268 GDWriteCPCmd( CP_MATINDEX_B, regB ); // W2
269
270 GDWriteXFCmdHdr( XF_MATINDEX_A, 2 );
271 GDWrite_u32( regA ); // W1
272 GDWrite_u32( regB ); // W2
273 }
274
275
276 /*---------------------------------------------------------------------------*/
277 // Name: GDSetProjection
278 //
279 // Description: Sets projection matrix parameters.
280 //
281 // Arguments: mtx Projection Matrix.
282 // type Projection matrix type (ORTHO or PERSP)
283 //
284 // The six values in XF memory (i.e.XF_PROJECTIONA..XF_PROJECTIONF)
285 // corresponds to matrix data as follows:
286 //
287 // Orthographic Matrix: [A 0 0 B]
288 // [0 C 0 D]
289 // [0 0 E F]
290 // [0 0 0 1]
291 //
292 // Perspective Matrix: [A 0 B 0]
293 // [0 C D 0]
294 // [0 0 E F]
295 // [0 0 -1 0]
296 //
297 // Returns: None
298 //
299 /*---------------------------------------------------------------------------*/
300
GDSetProjection(const f32 mtx[4][4],GXProjectionType type)301 void GDSetProjection ( const f32 mtx[4][4], GXProjectionType type )
302 {
303 u32 c;
304
305 c = ( type == GX_ORTHOGRAPHIC ) ? 3u : 2u;
306
307 GDWriteXFCmdHdr( XF_PROJECTION_ID, 7 );
308 GDWrite_f32( mtx[0][0] );
309 GDWrite_f32( mtx[0][c] );
310 GDWrite_f32( mtx[1][1] );
311 GDWrite_f32( mtx[1][c] );
312 GDWrite_f32( mtx[2][2] );
313 GDWrite_f32( mtx[2][3] );
314 GDWrite_u32( type );
315 }
316
317