1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX -
3   File:     g3b.c
4 
5   Copyright 2003-2008 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   $Date:: 2008-09-17#$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #include <nitro/gx/g3imm.h>
19 #include <nitro/mi/dma.h>
20 #include "../include/gxasm.h"
21 
22 #ifdef SDK_NITRO
23 #include <nitro/hw/ARM9/ioreg_G3X.h>
24 #else
25 #include <twl/hw/ARM9/ioreg_G3X.h>
26 #endif
27 
28 /*---------------------------------------------------------------------------*
29   Name:         G3_LoadMtx44
30 
31   Description:  Loads a 4x4 matrix to the current matrix.
32 
33   Arguments:    m            a pointer to a constant 4x4 matrix
34 
35   Returns:      none
36  *---------------------------------------------------------------------------*/
G3_LoadMtx44(const MtxFx44 * m)37 void G3_LoadMtx44(const MtxFx44 *m)
38 {
39     SDK_NULL_ASSERT(m);
40 #if 1
41     reg_G3X_GXFIFO = G3OP_MTX_LOAD_4x4;
42     GX_SendFifo64B(&m->_00, (void *)&reg_G3X_GXFIFO);
43 #else
44     reg_G3_MTX_LOAD_4x4 = (u32)m->_00;
45     reg_G3_MTX_LOAD_4x4 = (u32)m->_01;
46     reg_G3_MTX_LOAD_4x4 = (u32)m->_02;
47     reg_G3_MTX_LOAD_4x4 = (u32)m->_03;
48 
49     reg_G3_MTX_LOAD_4x4 = (u32)m->_10;
50     reg_G3_MTX_LOAD_4x4 = (u32)m->_11;
51     reg_G3_MTX_LOAD_4x4 = (u32)m->_12;
52     reg_G3_MTX_LOAD_4x4 = (u32)m->_13;
53 
54     reg_G3_MTX_LOAD_4x4 = (u32)m->_20;
55     reg_G3_MTX_LOAD_4x4 = (u32)m->_21;
56     reg_G3_MTX_LOAD_4x4 = (u32)m->_22;
57     reg_G3_MTX_LOAD_4x4 = (u32)m->_23;
58 
59     reg_G3_MTX_LOAD_4x4 = (u32)m->_30;
60     reg_G3_MTX_LOAD_4x4 = (u32)m->_31;
61     reg_G3_MTX_LOAD_4x4 = (u32)m->_32;
62     reg_G3_MTX_LOAD_4x4 = (u32)m->_33;
63 #endif
64 }
65 
66 
67 /*---------------------------------------------------------------------------*
68   Name:         G3_LoadMtx43
69 
70   Description:  Loads a 4x3 matrix to the current matrix.
71 
72   Arguments:    m            a pointer to a constant 4x3 matrix
73 
74   Returns:      none
75  *---------------------------------------------------------------------------*/
G3_LoadMtx43(const MtxFx43 * m)76 void G3_LoadMtx43(const MtxFx43 *m)
77 {
78     SDK_NULL_ASSERT(m);
79 #if 1
80     reg_G3X_GXFIFO = G3OP_MTX_LOAD_4x3;
81     GX_SendFifo48B(&m->_00, (void *)&reg_G3X_GXFIFO);
82 #else
83     reg_G3_MTX_LOAD_4x3 = (u32)m->_00;
84     reg_G3_MTX_LOAD_4x3 = (u32)m->_01;
85     reg_G3_MTX_LOAD_4x3 = (u32)m->_02;
86 
87     reg_G3_MTX_LOAD_4x3 = (u32)m->_10;
88     reg_G3_MTX_LOAD_4x3 = (u32)m->_11;
89     reg_G3_MTX_LOAD_4x3 = (u32)m->_12;
90 
91     reg_G3_MTX_LOAD_4x3 = (u32)m->_20;
92     reg_G3_MTX_LOAD_4x3 = (u32)m->_21;
93     reg_G3_MTX_LOAD_4x3 = (u32)m->_22;
94 
95     reg_G3_MTX_LOAD_4x3 = (u32)m->_30;
96     reg_G3_MTX_LOAD_4x3 = (u32)m->_31;
97     reg_G3_MTX_LOAD_4x3 = (u32)m->_32;
98 #endif
99 }
100 
101 
102 /*---------------------------------------------------------------------------*
103   Name:         G3_MultMtx44
104 
105   Description:  Multiplies the current matrix by a 4x4 matrix from the left.
106 
107   Arguments:    m            a pointer to a constant 4x4 matrix
108 
109   Returns:      none
110  *---------------------------------------------------------------------------*/
G3_MultMtx44(const MtxFx44 * m)111 void G3_MultMtx44(const MtxFx44 *m)
112 {
113     SDK_NULL_ASSERT(m);
114 #if 1
115     reg_G3X_GXFIFO = G3OP_MTX_MULT_4x4;
116     GX_SendFifo64B(&m->_00, (void *)&reg_G3X_GXFIFO);
117 #else
118     reg_G3_MTX_MULT_4x4 = (u32)m->_00;
119     reg_G3_MTX_MULT_4x4 = (u32)m->_01;
120     reg_G3_MTX_MULT_4x4 = (u32)m->_02;
121     reg_G3_MTX_MULT_4x4 = (u32)m->_03;
122 
123     reg_G3_MTX_MULT_4x4 = (u32)m->_10;
124     reg_G3_MTX_MULT_4x4 = (u32)m->_11;
125     reg_G3_MTX_MULT_4x4 = (u32)m->_12;
126     reg_G3_MTX_MULT_4x4 = (u32)m->_13;
127 
128     reg_G3_MTX_MULT_4x4 = (u32)m->_20;
129     reg_G3_MTX_MULT_4x4 = (u32)m->_21;
130     reg_G3_MTX_MULT_4x4 = (u32)m->_22;
131     reg_G3_MTX_MULT_4x4 = (u32)m->_23;
132 
133     reg_G3_MTX_MULT_4x4 = (u32)m->_30;
134     reg_G3_MTX_MULT_4x4 = (u32)m->_31;
135     reg_G3_MTX_MULT_4x4 = (u32)m->_32;
136     reg_G3_MTX_MULT_4x4 = (u32)m->_33;
137 #endif
138 }
139 
140 
141 /*---------------------------------------------------------------------------*
142   Name:         G3_MultMtx43
143 
144   Description:  Multiplies the current matrix by a 4x3 matrix from the left.
145 
146   Arguments:    m            a pointer to a constant 4x3 matrix
147 
148   Returns:      none
149  *---------------------------------------------------------------------------*/
G3_MultMtx43(const MtxFx43 * m)150 void G3_MultMtx43(const MtxFx43 *m)
151 {
152     SDK_NULL_ASSERT(m);
153 #if 1
154     reg_G3X_GXFIFO = G3OP_MTX_MULT_4x3;
155     GX_SendFifo48B(&m->_00, (void *)&reg_G3X_GXFIFO);
156 #else
157     reg_G3_MTX_MULT_4x3 = (u32)m->_00;
158     reg_G3_MTX_MULT_4x3 = (u32)m->_01;
159     reg_G3_MTX_MULT_4x3 = (u32)m->_02;
160 
161     reg_G3_MTX_MULT_4x3 = (u32)m->_10;
162     reg_G3_MTX_MULT_4x3 = (u32)m->_11;
163     reg_G3_MTX_MULT_4x3 = (u32)m->_12;
164 
165     reg_G3_MTX_MULT_4x3 = (u32)m->_20;
166     reg_G3_MTX_MULT_4x3 = (u32)m->_21;
167     reg_G3_MTX_MULT_4x3 = (u32)m->_22;
168 
169     reg_G3_MTX_MULT_4x3 = (u32)m->_30;
170     reg_G3_MTX_MULT_4x3 = (u32)m->_31;
171     reg_G3_MTX_MULT_4x3 = (u32)m->_32;
172 #endif
173 }
174 
175 
176 /*---------------------------------------------------------------------------*
177   Name:         G3_MultMtx33
178 
179   Description:  Multiplies the current matrix by a 3x3 matrix from the left.
180 
181   Arguments:    m            a pointer to a constant 3x3 matrix
182 
183   Returns:      none
184  *---------------------------------------------------------------------------*/
G3_MultMtx33(const MtxFx33 * m)185 void G3_MultMtx33(const MtxFx33 *m)
186 {
187     SDK_NULL_ASSERT(m);
188 #if 1
189     reg_G3X_GXFIFO = G3OP_MTX_MULT_3x3;
190     GX_SendFifo36B(&m->_00, (void *)&reg_G3X_GXFIFO);
191 #else
192     reg_G3_MTX_MULT_3x3 = (u32)m->_00;
193     reg_G3_MTX_MULT_3x3 = (u32)m->_01;
194     reg_G3_MTX_MULT_3x3 = (u32)m->_02;
195 
196     reg_G3_MTX_MULT_3x3 = (u32)m->_10;
197     reg_G3_MTX_MULT_3x3 = (u32)m->_11;
198     reg_G3_MTX_MULT_3x3 = (u32)m->_12;
199 
200     reg_G3_MTX_MULT_3x3 = (u32)m->_20;
201     reg_G3_MTX_MULT_3x3 = (u32)m->_21;
202     reg_G3_MTX_MULT_3x3 = (u32)m->_22;
203 #endif
204 }
205 
206 
207 /*---------------------------------------------------------------------------*
208   Name:         G3_Shininess
209 
210   Description:  Sets up the shininess table.
211 
212   Arguments:    table        a pointer to the shininess data(32 words)
213 
214   Returns:      none
215  *---------------------------------------------------------------------------*/
G3_Shininess(const u32 * table)216 void G3_Shininess(const u32 *table)
217 {
218 #if 1
219     SDK_NULL_ASSERT(table);
220 
221     reg_G3X_GXFIFO = G3OP_SHININESS;
222     GX_SendFifo128B(&table[0], (void *)&reg_G3X_GXFIFO);
223 #else
224     int     i;
225     SDK_NULL_ASSERT(table);
226     for (i = 0; i < 32; ++i)
227     {
228         reg_G3_SHININESS = *(table + i);
229     }
230 #endif
231 }
232 
233 
234 /*---------------------------------------------------------------------------*
235   Name:         G3_MultTransMtx33
236 
237   Description:  multiple and translate matrix together to current matrix.
238 
239   Arguments:    mtx        a constant 3x3 matrix
240                 trans      a pointer to a constant transration vector.
241 
242   Returns:      none
243  *---------------------------------------------------------------------------*/
G3_MultTransMtx33(const MtxFx33 * mtx,const VecFx32 * trans)244 void G3_MultTransMtx33(const MtxFx33 *mtx, const VecFx32 *trans)
245 {
246     SDK_NULL_ASSERT(mtx);
247     SDK_NULL_ASSERT(trans);
248 
249     reg_G3X_GXFIFO = G3OP_MTX_MULT_4x3;
250     GX_SendFifo36B(&mtx->_00, (void *)&reg_G3X_GXFIFO);
251     reg_G3X_GXFIFO = (u32)trans->x;
252     reg_G3X_GXFIFO = (u32)trans->y;
253     reg_G3X_GXFIFO = (u32)trans->z;
254 }
255