1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX -
3   File:     g3imm.h
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-18#$
14   $Rev: 8573 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NITRO_G3IMM_H_
19 #define NITRO_G3IMM_H_
20 
21 #ifdef SDK_NITRO
22 #include <nitro/hw/ARM9/mmap_global.h>
23 #else
24 #include <twl/hw/ARM9/mmap_global.h>
25 #endif
26 
27 #include <nitro/gx/g3.h>
28 #include <nitro/fx/fx_const.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 //----------------------------------------------------------------------------
35 // Type definition
36 //----------------------------------------------------------------------------
37 
38 //----------------------------------------------------------------------------
39 // Declaration of function
40 //----------------------------------------------------------------------------
41 
42 static void G3_Direct0(int op);
43 static void G3_Direct1(int op, u32 param0);
44 static void G3_Direct2(int op, u32 param0, u32 param1);
45 static void G3_Direct3(int op, u32 param0, u32 param1, u32 param2);
46 
47 static void G3_MtxMode(GXMtxMode mode);
48 static void G3_PushMtx(void);
49 static void G3_PopMtx(int num);
50 static void G3_StoreMtx(int num);
51 static void G3_RestoreMtx(int num);
52 static void G3_Identity(void);
53 void    G3_LoadMtx44(const MtxFx44 *m);
54 void    G3_LoadMtx43(const MtxFx43 *m);
55 void    G3_MultMtx44(const MtxFx44 *m);
56 void    G3_MultMtx43(const MtxFx43 *m);
57 void    G3_MultMtx33(const MtxFx33 *m);
58 void    G3_MultTransMtx33(const MtxFx33 *mtx, const VecFx32 *trans);
59 static void G3_Scale(fx32 x, fx32 y, fx32 z);
60 static void G3_Translate(fx32 x, fx32 y, fx32 z);
61 static void G3_Color(GXRgb rgb);
62 static void G3_Normal(fx16 x, fx16 y, fx16 z);
63 static void G3_TexCoord(fx32 s, fx32 t);
64 static void G3_Vtx(fx16 x, fx16 y, fx16 z);
65 static void G3_Vtx10(fx16 x, fx16 y, fx16 z);
66 static void G3_VtxXY(fx16 x, fx16 y);
67 static void G3_VtxXZ(fx16 x, fx16 z);
68 static void G3_VtxYZ(fx16 y, fx16 z);
69 static void G3_VtxDiff(fx16 x, fx16 y, fx16 z);
70 static void G3_PolygonAttr(int light, GXPolygonMode polyMode, GXCull cullMode, int polygonID, int alpha, int misc       // GXPolygonAttrMisc
71     );
72 static void G3_TexImageParam(GXTexFmt texFmt,
73                              GXTexGen texGen,
74                              GXTexSizeS s,
75                              GXTexSizeT t,
76                              GXTexRepeat repeat, GXTexFlip flip, GXTexPlttColor0 pltt0, u32 addr);
77 static void G3_TexPlttBase(u32 addr, GXTexFmt texfmt);
78 static void G3_MaterialColorDiffAmb(GXRgb diffuse, GXRgb ambient, BOOL IsSetVtxColor);
79 static void G3_MaterialColorSpecEmi(GXRgb specular, GXRgb emission, BOOL IsShininess);
80 static void G3_LightVector(GXLightId lightID, fx16 x, fx16 y, fx16 z);
81 static void G3_LightColor(GXLightId lightID, GXRgb rgb);
82 void    G3_Shininess(const u32 *table);
83 static void G3_Begin(GXBegin primitive);
84 static void G3_End(void);
85 static void G3_SwapBuffers(GXSortMode am, GXBufferMode zw);
86 static void G3_ViewPort(int x1, int y1, int x2, int y2);
87 static void G3_BoxTest(const GXBoxTestParam *box);
88 static void G3_PositionTest(fx16 x, fx16 y, fx16 z);
89 static void G3_VectorTest(fx16 x, fx16 y, fx16 z);
90 
91 //----------------------------------------------------------------------------
92 // Implementation of inline function
93 //----------------------------------------------------------------------------
94 
95 
96 /*---------------------------------------------------------------------------*
97   Name:         G3_Direct0
98 
99   Description:  Sends a geometry command with no parameters.
100 
101   Arguments:    op         A geometry command(GXOP_xxxxxxx)
102 
103   Returns:      none
104  *---------------------------------------------------------------------------*/
G3_Direct0(int op)105 static inline void G3_Direct0(int op)
106 {
107     *(REGType32v *)(REG_MTX_MODE_ADDR + ((op - G3OP_MTX_MODE) * 4)) = 0;
108 }
109 
110 
111 /*---------------------------------------------------------------------------*
112   Name:         G3_Direct1
113 
114   Description:  Sends a geometry command with a parameter.
115 
116   Arguments:    op         A geometry command(GXOP_xxxxxxx)
117                 param0     A parameter
118 
119   Returns:      none
120  *---------------------------------------------------------------------------*/
G3_Direct1(int op,u32 param0)121 static inline void G3_Direct1(int op, u32 param0)
122 {
123     *(REGType32v *)(REG_MTX_MODE_ADDR + ((op - G3OP_MTX_MODE) * 4)) = param0;
124 }
125 
126 
127 /*---------------------------------------------------------------------------*
128   Name:         G3_Direct2
129 
130   Description:  Sends a geometry command with two parameters.
131 
132   Arguments:    op         A geometry command(GXOP_xxxxxxx)
133                 param0     A parameter
134                 param1     A parameter
135 
136   Returns:      none
137  *---------------------------------------------------------------------------*/
G3_Direct2(int op,u32 param0,u32 param1)138 static inline void G3_Direct2(int op, u32 param0, u32 param1)
139 {
140     *(REGType32v *)(REG_MTX_MODE_ADDR + ((op - G3OP_MTX_MODE) * 4)) = param0;
141     *(REGType32v *)(REG_MTX_MODE_ADDR + ((op - G3OP_MTX_MODE) * 4)) = param1;
142 }
143 
144 
145 /*---------------------------------------------------------------------------*
146   Name:         G3_Direct3
147 
148   Description:  Sends a geometry command with three parameters.
149 
150   Arguments:    op         A geometry command(GXOP_xxxxxxx)
151                 param0     A parameter
152                 param1     A parameter
153                 param2     A parameter
154 
155   Returns:      none
156  *---------------------------------------------------------------------------*/
G3_Direct3(int op,u32 param0,u32 param1,u32 param2)157 static inline void G3_Direct3(int op, u32 param0, u32 param1, u32 param2)
158 {
159     *(REGType32v *)(REG_MTX_MODE_ADDR + ((op - G3OP_MTX_MODE) * 4)) = param0;
160     *(REGType32v *)(REG_MTX_MODE_ADDR + ((op - G3OP_MTX_MODE) * 4)) = param1;
161     *(REGType32v *)(REG_MTX_MODE_ADDR + ((op - G3OP_MTX_MODE) * 4)) = param2;
162 }
163 
164 
165 /*---------------------------------------------------------------------------*
166   Name:         G3_MtxMode
167 
168   Description:  Sets a matrix mode.
169 
170   Arguments:    mode       A matrix mode
171 
172   Returns:      none
173  *---------------------------------------------------------------------------*/
G3_MtxMode(GXMtxMode mode)174 static inline void G3_MtxMode(GXMtxMode mode)
175 {
176     GX_MTXMODE_ASSERT(mode);
177 
178     reg_G3_MTX_MODE = GX_PACK_MTXMODE_PARAM(mode);
179 }
180 
181 
182 /*---------------------------------------------------------------------------*
183   Name:         G3_PushMtx
184 
185   Description:  Stores a current matrix to the top of the matrix stack,
186                 and increments the stack pointer
187 
188   Arguments:    none
189 
190   Returns:      none
191  *---------------------------------------------------------------------------*/
G3_PushMtx()192 static inline void G3_PushMtx()
193 {
194     reg_G3_MTX_PUSH = 0;
195 }
196 
197 
198 /*---------------------------------------------------------------------------*
199   Name:         G3_PopMtx
200 
201   Description:  Pops the num'th matrix from the matrix stack pointer
202                 on the stack, and adds num to the pointer.
203 
204   Arguments:    num        an offset to the stack pointer
205 
206   Returns:      none
207  *---------------------------------------------------------------------------*/
G3_PopMtx(int num)208 static inline void G3_PopMtx(int num)
209 {
210     GX_MTX_POP_NUM_ASSERT(num);
211 
212     reg_G3_MTX_POP = GX_PACK_POPMTX_PARAM(num);
213 }
214 
215 
216 /*---------------------------------------------------------------------------*
217   Name:         G3_StoreMtx
218 
219   Description:  Stores a current matrix to the num'th matrix from the matrix
220                 stack pointer on the stack.
221 
222   Arguments:    num        an offset to the stack pointer
223 
224   Returns:      none
225  *---------------------------------------------------------------------------*/
G3_StoreMtx(int num)226 static inline void G3_StoreMtx(int num)
227 {
228     GX_MTX_STORE_NUM_ASSERT(num);
229 
230     reg_G3_MTX_STORE = GX_PACK_STOREMTX_PARAM(num);
231 }
232 
233 
234 /*---------------------------------------------------------------------------*
235   Name:         G3_RestoreMtx
236 
237   Description:  Gets the num'th matrix from the matrix stack pointer
238                 on the stack.
239 
240   Arguments:    num        an offset to the stack pointer
241 
242   Returns:      none
243  *---------------------------------------------------------------------------*/
G3_RestoreMtx(int num)244 static inline void G3_RestoreMtx(int num)
245 {
246     GX_MTX_RESTORE_NUM_ASSERT(num);
247 
248     reg_G3_MTX_RESTORE = GX_PACK_RESTOREMTX_PARAM(num);
249 }
250 
251 
252 /*---------------------------------------------------------------------------*
253   Name:         G3_Identity
254 
255   Description:  Sets an identity matrix to the current matrix.
256 
257   Arguments:    none
258 
259   Returns:      none
260  *---------------------------------------------------------------------------*/
G3_Identity()261 static inline void G3_Identity()
262 {
263     reg_G3_MTX_IDENTITY = 0;
264 }
265 
266 
267 /*---------------------------------------------------------------------------*
268   Name:         G3_Scale
269 
270   Description:  Multiplies the current matrix by a scale matrix.
271 
272   Arguments:    x          X coordinate of a scale
273                 y          Y coordinate of a scale
274                 z          Z coordinate of a scale
275 
276   Returns:      none
277  *---------------------------------------------------------------------------*/
G3_Scale(fx32 x,fx32 y,fx32 z)278 static inline void G3_Scale(fx32 x, fx32 y, fx32 z)
279 {
280     reg_G3_MTX_SCALE = (u32)x;
281     reg_G3_MTX_SCALE = (u32)y;
282     reg_G3_MTX_SCALE = (u32)z;
283 }
284 
285 
286 /*---------------------------------------------------------------------------*
287   Name:         G3_Translate
288 
289   Description:  Multiplies the current matrix by a translation matrix.
290 
291   Arguments:    x          X coordinate of a translation vector
292                 y          Y coordinate of a translation vector
293                 z          Z coordinate of a translation vector
294 
295   Returns:      none
296  *---------------------------------------------------------------------------*/
G3_Translate(fx32 x,fx32 y,fx32 z)297 static inline void G3_Translate(fx32 x, fx32 y, fx32 z)
298 {
299     reg_G3_MTX_TRANS = (u32)x;
300     reg_G3_MTX_TRANS = (u32)y;
301     reg_G3_MTX_TRANS = (u32)z;
302 }
303 
304 
305 /*---------------------------------------------------------------------------*
306   Name:         G3_Color
307 
308   Description:  Sends a vertex color.
309 
310   Arguments:    rgb        a vertex color(R:5, G:5, B:5)
311 
312   Returns:      none
313  *---------------------------------------------------------------------------*/
G3_Color(GXRgb rgb)314 static inline void G3_Color(GXRgb rgb)
315 {
316     GXRGB_ASSERT(rgb);
317 
318     reg_G3_COLOR = GX_PACK_COLOR_PARAM(rgb);
319 }
320 
321 
322 /*---------------------------------------------------------------------------*
323   Name:         G3_Normal
324 
325   Description:  Sends a normal vector.
326 
327   Arguments:    x          X coordinate of a normal vector
328                 y          Y coordinate of a normal vector
329                 z          Z coordinate of a normal vector
330 
331   Returns:      none
332  *---------------------------------------------------------------------------*/
G3_Normal(fx16 x,fx16 y,fx16 z)333 static inline void G3_Normal(fx16 x, fx16 y, fx16 z)
334 {
335     SDK_MINMAX_ASSERT(x, -FX16_ONE, FX16_ONE - 1);
336     SDK_MINMAX_ASSERT(y, -FX16_ONE, FX16_ONE - 1);
337     SDK_MINMAX_ASSERT(z, -FX16_ONE, FX16_ONE - 1);
338 
339     reg_G3_NORMAL = GX_PACK_NORMAL_PARAM(x, y, z);
340 }
341 
342 
343 /*---------------------------------------------------------------------------*
344   Name:         G3_TexCoord
345 
346   Description:  Sends a texture coordinate.
347 
348   Arguments:    s          an S of a texture coordinate
349                 t          a T of a texture coordinate
350 
351   Returns:      none
352  *---------------------------------------------------------------------------*/
G3_TexCoord(fx32 s,fx32 t)353 static inline void G3_TexCoord(fx32 s, fx32 t)
354 {
355     SDK_MINMAX_ASSERT(s, -2048 * FX32_ONE, 2048 * FX32_ONE - 1);
356     SDK_MINMAX_ASSERT(t, -2048 * FX32_ONE, 2048 * FX32_ONE - 1);
357 
358     reg_G3_TEXCOORD = GX_PACK_TEXCOORD_PARAM(s, t);
359 }
360 
361 
362 /*---------------------------------------------------------------------------*
363   Name:         G3_Vtx
364 
365   Description:  Sends a vertex as a fx16 vector.
366 
367   Arguments:    x          X coordinate of a vertex
368                 y          Y coordinate of a vertex
369                 z          Z coordinate of a vertex
370 
371   Returns:      none
372  *---------------------------------------------------------------------------*/
G3_Vtx(fx16 x,fx16 y,fx16 z)373 static inline void G3_Vtx(fx16 x, fx16 y, fx16 z)
374 {
375     reg_G3_VTX_16 = GX_FX16PAIR(x, y);
376     reg_G3_VTX_16 = (u32)(u16)z;
377 }
378 
379 /*---------------------------------------------------------------------------*
380   Name:         G3_Vtx10
381 
382   Description:  Sends a vertex as a s3.6 vector.
383 
384   Arguments:    x          X coordinate of a vertex
385                 y          Y coordinate of a vertex
386                 z          Z coordinate of a vertex
387 
388   Returns:      none
389  *---------------------------------------------------------------------------*/
G3_Vtx10(fx16 x,fx16 y,fx16 z)390 static inline void G3_Vtx10(fx16 x, fx16 y, fx16 z)
391 {
392     reg_G3_VTX_10 = GX_PACK_VTX10_PARAM(x, y, z);
393 }
394 
395 
396 /*---------------------------------------------------------------------------*
397   Name:         G3_VtxXY
398 
399   Description:  Sends XY components of a vertex.
400                 The Z coordinate is the same to the vertex sent just before.
401 
402   Arguments:    x          X coordinate of a vertex
403                 y          Y coordinate of a vertex
404 
405   Returns:      none
406  *---------------------------------------------------------------------------*/
G3_VtxXY(fx16 x,fx16 y)407 static inline void G3_VtxXY(fx16 x, fx16 y)
408 {
409     reg_G3_VTX_XY = GX_PACK_VTXXY_PARAM(x, y);
410 }
411 
412 
413 /*---------------------------------------------------------------------------*
414   Name:         G3_VtxXZ
415 
416   Description:  Sends XZ components of a vertex.
417                 The Y coordinate is the same to the vertex sent just before.
418 
419   Arguments:    x          X coordinate of a vertex
420                 z          Z coordinate of a vertex
421 
422   Returns:      none
423  *---------------------------------------------------------------------------*/
G3_VtxXZ(fx16 x,fx16 z)424 static inline void G3_VtxXZ(fx16 x, fx16 z)
425 {
426     reg_G3_VTX_XZ = GX_PACK_VTXXZ_PARAM(x, z);
427 }
428 
429 
430 /*---------------------------------------------------------------------------*
431   Name:         G3_VtxYZ
432 
433   Description:  Sends YZ components of a vertex.
434                 The X component is the same to the vertex sent just before.
435 
436   Arguments:    x          X coordinate of a vertex
437                 y          Y coordinate of a vertex
438 
439   Returns:      none
440  *---------------------------------------------------------------------------*/
G3_VtxYZ(fx16 y,fx16 z)441 static inline void G3_VtxYZ(fx16 y, fx16 z)
442 {
443     reg_G3_VTX_YZ = GX_PACK_VTXYZ_PARAM(y, z);
444 }
445 
446 
447 /*---------------------------------------------------------------------------*
448   Name:         G3_VtxDiff
449 
450   Description:  Sends a vector as an offset to the last vertex sent.
451 
452   Arguments:    x          X coordinate of an offset
453                 y          Y coordinate of an offset
454                 z          Z coordinate of an offset
455 
456   Returns:      none
457  *---------------------------------------------------------------------------*/
G3_VtxDiff(fx16 x,fx16 y,fx16 z)458 static inline void G3_VtxDiff(fx16 x, fx16 y, fx16 z)
459 {
460     SDK_MINMAX_ASSERT(x, (fx16)0xfe00, (fx16)0x1ff);
461     SDK_MINMAX_ASSERT(y, (fx16)0xfe00, (fx16)0x1ff);
462     SDK_MINMAX_ASSERT(z, (fx16)0xfe00, (fx16)0x1ff);
463 
464     reg_G3_VTX_DIFF = GX_PACK_VTXDIFF_PARAM(x, y, z);
465 }
466 
467 
468 /*---------------------------------------------------------------------------*
469   Name:         G3_PolygonAttr
470 
471   Description:  Sends attributes for polygons.
472 
473   Arguments:    light      a 4bits field specifying light enable/disable
474                 polyMode   a polygon mode
475                 cullMode   a cull mode
476                 polygonID  a polygon ID
477                 alpha      an alpha value
478                 misc       miscellaneous flags
479 
480   Returns:      none
481  *---------------------------------------------------------------------------*/
G3_PolygonAttr(int light,GXPolygonMode polyMode,GXCull cullMode,int polygonID,int alpha,int misc)482 static inline void G3_PolygonAttr(int light, GXPolygonMode polyMode, GXCull cullMode, int polygonID, int alpha, int misc        // GXPolygonAttrMisc
483     )
484 {
485     GX_LIGHTMASK_ASSERT(light);
486     GX_POLYGONMODE_ASSERT(polyMode);
487     GX_CULL_ASSERT(cullMode);
488     GX_POLYGON_ATTR_POLYGONID_ASSERT(polygonID);
489     GX_POLYGON_ATTR_ALPHA_ASSERT(alpha);
490 
491     reg_G3_POLYGON_ATTR = GX_PACK_POLYGONATTR_PARAM(light,
492                                                     polyMode, cullMode, polygonID, alpha, misc);
493 }
494 
495 
496 /*---------------------------------------------------------------------------*
497   Name:         G3_TexImageParam
498 
499   Description:  Sends parameters for a texture.
500 
501   Arguments:    texFmt     format of a texture
502                 texGen     selects the source of a texture coordinate
503                 s          the size of a texture in the direction of the S-axis
504                 t          the size of a texture in the direction of the T-axis
505                 repeat     repeat
506                 flip       flip
507                 pltt0      use/not use the color of pltt. 0
508                 addr       the offset address in the texture image slots
509                            (shift 3bits internally)
510 
511   Returns:      none
512  *---------------------------------------------------------------------------*/
G3_TexImageParam(GXTexFmt texFmt,GXTexGen texGen,GXTexSizeS s,GXTexSizeT t,GXTexRepeat repeat,GXTexFlip flip,GXTexPlttColor0 pltt0,u32 addr)513 static inline void G3_TexImageParam(GXTexFmt texFmt,
514                                     GXTexGen texGen,
515                                     GXTexSizeS s,
516                                     GXTexSizeT t,
517                                     GXTexRepeat repeat,
518                                     GXTexFlip flip, GXTexPlttColor0 pltt0, u32 addr)
519 {
520     GX_TEXREPEAT_ASSERT(repeat);
521     GX_TEXFLIP_ASSERT(flip);
522     GX_TEXSIZE_S_ASSERT(s);
523     GX_TEXSIZE_T_ASSERT(t);
524     GX_TEXFMT_ASSERT(texFmt);
525     GX_TEXPLTTCOLOR0_ASSERT(pltt0);
526     GX_TEXGEN_ASSERT(texGen);
527     GX_TEXIMAGE_PARAM_ADDR_ASSERT(addr);
528 
529     reg_G3_TEXIMAGE_PARAM = GX_PACK_TEXIMAGE_PARAM(texFmt, texGen, s, t, repeat, flip, pltt0, addr);
530 }
531 
532 
533 /*---------------------------------------------------------------------------*
534   Name:         G3_TexPlttBase
535 
536   Description:  Sends a base address of a texture palette.
537 
538   Arguments:    addr       the offset address in the texture palette slots
539                 texFmt     format of a texture
540 
541   Returns:      none
542  *---------------------------------------------------------------------------*/
G3_TexPlttBase(u32 addr,GXTexFmt texfmt)543 static inline void G3_TexPlttBase(u32 addr, GXTexFmt texfmt)
544 {
545     u32     param = GX_PACK_TEXPLTTBASE_PARAM(addr, texfmt);
546     GX_TEXPLTTBASEPARAM_ASSERT(param);
547 
548     reg_G3_TEXPLTT_BASE = param;
549 }
550 
551 /*---------------------------------------------------------------------------*
552   Name:         G3_MaterialColorDiffAmb
553 
554   Description:  Sends diffuse and ambient.
555 
556   Arguments:    diffuse        a diffuse color
557                 ambient        an ambient color
558                 IsSetVtxColor  sets a diffuse color as a vertex color if TRUE
559 
560   Returns:      none
561  *---------------------------------------------------------------------------*/
G3_MaterialColorDiffAmb(GXRgb diffuse,GXRgb ambient,BOOL IsSetVtxColor)562 static inline void G3_MaterialColorDiffAmb(GXRgb diffuse, GXRgb ambient, BOOL IsSetVtxColor)
563 {
564     GXRGB_ASSERT(diffuse);
565     GXRGB_ASSERT(ambient);
566 
567     reg_G3_DIF_AMB = GX_PACK_DIFFAMB_PARAM(diffuse, ambient, IsSetVtxColor);
568 }
569 
570 
571 /*---------------------------------------------------------------------------*
572   Name:         G3_MaterialColorSpecEmi
573 
574   Description:  Sends specular and emission.
575 
576   Arguments:    specular       a specular color
577                 emission       an emission color
578                 IsShininess    use the shininess table to change a specular
579                                color if TRUE
580 
581   Returns:      none
582  *---------------------------------------------------------------------------*/
G3_MaterialColorSpecEmi(GXRgb specular,GXRgb emission,BOOL IsShininess)583 static inline void G3_MaterialColorSpecEmi(GXRgb specular, GXRgb emission, BOOL IsShininess)
584 {
585     GXRGB_ASSERT(specular);
586     GXRGB_ASSERT(emission);
587 
588     reg_G3_SPE_EMI = GX_PACK_SPECEMI_PARAM(specular, emission, IsShininess);
589 }
590 
591 
592 /*---------------------------------------------------------------------------*
593   Name:         G3_LightVector
594 
595   Description:  Sends a light vector.
596 
597   Arguments:    lightID    light ID
598                 x          X coordinate of a light vector
599                 y          Y coordinate of a light vector
600                 z          Z coordinate of a light vector
601 
602   Returns:      none
603  *---------------------------------------------------------------------------*/
G3_LightVector(GXLightId lightID,fx16 x,fx16 y,fx16 z)604 static inline void G3_LightVector(GXLightId lightID, fx16 x, fx16 y, fx16 z)
605 {
606     GX_LIGHTID_ASSERT(lightID);
607     SDK_MINMAX_ASSERT(x, -FX16_ONE, FX16_ONE - 1);
608     SDK_MINMAX_ASSERT(y, -FX16_ONE, FX16_ONE - 1);
609     SDK_MINMAX_ASSERT(z, -FX16_ONE, FX16_ONE - 1);
610 
611     reg_G3_LIGHT_VECTOR = GX_PACK_LIGHTVECTOR_PARAM(lightID, x, y, z);
612 }
613 
614 
615 /*---------------------------------------------------------------------------*
616   Name:         G3_LightColor
617 
618   Description:  Sends a light color.
619 
620   Arguments:    lightID    light ID
621                 rgb        a light color(R:5, G:5, B:5)
622 
623   Returns:      none
624  *---------------------------------------------------------------------------*/
G3_LightColor(GXLightId lightID,GXRgb rgb)625 static inline void G3_LightColor(GXLightId lightID, GXRgb rgb)
626 {
627     GX_LIGHTID_ASSERT(lightID);
628     GXRGB_ASSERT(rgb);
629 
630     reg_G3_LIGHT_COLOR = GX_PACK_LIGHTCOLOR_PARAM(lightID, rgb);
631 }
632 
633 
634 /*---------------------------------------------------------------------------*
635   Name:         G3_Begin
636 
637   Description:  Starts sending primitives.
638 
639   Arguments:    primitive  the type of primitives
640 
641   Returns:      none
642  *---------------------------------------------------------------------------*/
G3_Begin(GXBegin primitive)643 static inline void G3_Begin(GXBegin primitive)
644 {
645     GX_BEGIN_ASSERT(primitive);
646 
647     reg_G3_BEGIN_VTXS = GX_PACK_BEGIN_PARAM(primitive);
648 }
649 
650 
651 /*---------------------------------------------------------------------------*
652   Name:         G3_End
653 
654   Description:  Ends sending primitives.
655 
656   Arguments:    none
657 
658   Returns:      none
659  *---------------------------------------------------------------------------*/
G3_End()660 static inline void G3_End()
661 {
662     reg_G3_END_VTXS = 0;
663 }
664 
665 
666 /*---------------------------------------------------------------------------*
667   Name:         G3_SwapBuffers
668 
669   Description:  Swaps the polygon list RAM, the vertex RAM, etc.
670 
671   Arguments:    am         auto sort/manual sort
672                 zw         Z buffer/W buffer
673 
674   Returns:      none
675  *---------------------------------------------------------------------------*/
G3_SwapBuffers(GXSortMode am,GXBufferMode zw)676 static inline void G3_SwapBuffers(GXSortMode am, GXBufferMode zw)
677 {
678     GX_SORTMODE_ASSERT(am);
679     GX_BUFFERMODE_ASSERT(zw);
680 
681     reg_G3_SWAP_BUFFERS = GX_PACK_SWAPBUFFERS_PARAM(am, zw);
682 }
683 
684 
685 /*---------------------------------------------------------------------------*
686   Name:         G3_ViewPort
687 
688   Description:  Specifies viewport.
689 
690   Arguments:    x1         the X coordinate of the lower left
691                 y1         the Y coordinate of the lower left
692                 x2         the X coordinate of the upper right
693                 y2         the Y coordinate of the upper right
694 
695   Returns:      none
696  *---------------------------------------------------------------------------*/
G3_ViewPort(int x1,int y1,int x2,int y2)697 static inline void G3_ViewPort(int x1, int y1, int x2, int y2)
698 {
699     GX_VIEWPORT_ASSERT(x1, y1, x2, y2);
700 
701     reg_G3_VIEWPORT = GX_PACK_VIEWPORT_PARAM(x1, y1, x2, y2);
702 }
703 
704 
705 /*---------------------------------------------------------------------------*
706   Name:         G3_BoxTest
707 
708   Description:  Tests if a box is in the frustum or not.
709 
710   Arguments:    box        a pointer to GXBoxTestParam
711 
712   Returns:      none
713  *---------------------------------------------------------------------------*/
G3_BoxTest(const GXBoxTestParam * box)714 static inline void G3_BoxTest(const GXBoxTestParam *box)
715 {
716     reg_G3_BOX_TEST = box->val[0];
717     reg_G3_BOX_TEST = box->val[1];
718     reg_G3_BOX_TEST = box->val[2];
719 }
720 
721 
722 /*---------------------------------------------------------------------------*
723   Name:         G3_PositionTest
724 
725   Description:  Applies a position vector to the current clip matrix.
726 
727   Arguments:    x          X coordinate of a position
728                 y          Y coordinate of a position
729                 z          Z coordinate of a position
730 
731   Returns:      none
732  *---------------------------------------------------------------------------*/
G3_PositionTest(fx16 x,fx16 y,fx16 z)733 static inline void G3_PositionTest(fx16 x, fx16 y, fx16 z)
734 {
735     reg_G3_POS_TEST = GX_FX16PAIR(x, y);
736     reg_G3_POS_TEST = (u32)(u16)z;
737 }
738 
739 
740 /*---------------------------------------------------------------------------*
741   Name:         G3_VectorTest
742 
743   Description:  Applies a vector to the current vector matrix.
744 
745   Arguments:    x          X coordinate of a vector
746                 y          Y coordinate of a vector
747                 z          Z coordinate of a vector
748 
749   Returns:      none
750  *---------------------------------------------------------------------------*/
G3_VectorTest(fx16 x,fx16 y,fx16 z)751 static inline void G3_VectorTest(fx16 x, fx16 y, fx16 z)
752 {
753     SDK_MINMAX_ASSERT(x, -FX16_ONE, FX16_ONE - 1);
754     SDK_MINMAX_ASSERT(y, -FX16_ONE, FX16_ONE - 1);
755     SDK_MINMAX_ASSERT(z, -FX16_ONE, FX16_ONE - 1);
756 
757     reg_G3_VEC_TEST = GX_PACK_VECTORTEST_PARAM(x, y, z);
758 }
759 
760 
761 
762 #ifdef __cplusplus
763 }/* extern "C" */
764 #endif
765 
766 /* NITRO_G3IMM_H_ */
767 #endif
768