1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX -
3   File:     g3b.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_G3B_H_
19 #define NITRO_G3B_H_
20 
21 #include <nitro/gx/g3.h>
22 #include <nitro/fx/fx_const.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 // no assert on win32
29 #if (defined(SDK_WIN32) || defined(SDK_FROM_TOOL))
30 #define SDK_ASSERT(exp)                         ((void) 0)
31 #define SDK_ALIGN4_ASSERT(exp)                  ((void) 0)
32 #define SDK_MINMAX_ASSERT(exp, min, max)        ((void) 0)
33 #define SDK_NULL_ASSERT(exp)                    ((void) 0)
34 
35 //  VC.net does not support '...'
36 #ifdef  _MSC_VER
37 #define SDK_ASSERTMSG(exp, msg)                 ((void) 0)
38 #ifndef __cplusplus
39 #define inline __inline
40 #endif
41 #else
42 #define SDK_ASSERTMSG(exp, ...)                 ((void) 0)
43 #endif
44 #endif
45 
46 //----------------------------------------------------------------------------
47 // Type definition
48 //----------------------------------------------------------------------------
49 
50 //----------------------------------------------------------------------------
51 // Declaration of function
52 //----------------------------------------------------------------------------
53 
54 // G3BS_*
55 static void G3BS_Direct0(GXDLInfo *info, int op);
56 static void G3BS_Direct1(GXDLInfo *info, int op, u32 param0);
57 static void G3BS_Direct2(GXDLInfo *info, int op, u32 param0, u32 param1);
58 static void G3BS_Direct3(GXDLInfo *info, int op, u32 param0, u32 param1, u32 param2);
59 void    G3BS_DirectN(GXDLInfo *info, int op, int nParams, const u32 *params);
60 
61 static void G3BS_Nop(GXDLInfo *info);
62 static void G3BS_MtxMode(GXDLInfo *info, GXMtxMode mode);
63 static void G3BS_PushMtx(GXDLInfo *info);
64 static void G3BS_PopMtx(GXDLInfo *info, int num);
65 static void G3BS_StoreMtx(GXDLInfo *info, int num);
66 static void G3BS_RestoreMtx(GXDLInfo *info, int num);
67 static void G3BS_Identity(GXDLInfo *info);
68 void    G3BS_LoadMtx44(GXDLInfo *info, const MtxFx44 *m);
69 void    G3BS_LoadMtx43(GXDLInfo *info, const MtxFx43 *m);
70 void    G3BS_MultMtx44(GXDLInfo *info, const MtxFx44 *m);
71 void    G3BS_MultMtx43(GXDLInfo *info, const MtxFx43 *m);
72 void    G3BS_MultMtx33(GXDLInfo *info, const MtxFx33 *m);
73 void    G3BS_MultTransMtx33(GXDLInfo *info, const MtxFx33 *mtx, const VecFx32 *trans);
74 static void G3BS_Scale(GXDLInfo *info, fx32 x, fx32 y, fx32 z);
75 static void G3BS_Translate(GXDLInfo *info, fx32 x, fx32 y, fx32 z);
76 static void G3BS_Color(GXDLInfo *info, GXRgb rgb);
77 static void G3BS_Normal(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
78 static void G3BS_TexCoord(GXDLInfo *info, fx32 s, fx32 t);
79 static void G3BS_Vtx(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
80 static void G3BS_Vtx10(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
81 static void G3BS_VtxXY(GXDLInfo *info, fx16 x, fx16 y);
82 static void G3BS_VtxXZ(GXDLInfo *info, fx16 x, fx16 z);
83 static void G3BS_VtxYZ(GXDLInfo *info, fx16 y, fx16 z);
84 static void G3BS_VtxDiff(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
85 static void G3BS_PolygonAttr(GXDLInfo *info, int light, GXPolygonMode polyMode, GXCull cullMode, int polygonID, int alpha, int misc     // GXPolygonAttrMisc
86     );
87 static void G3BS_TexImageParam(GXDLInfo *info,
88                                GXTexFmt texFmt,
89                                GXTexGen texGen,
90                                GXTexSizeS s,
91                                GXTexSizeT t,
92                                GXTexRepeat repeat, GXTexFlip flip, GXTexPlttColor0 pltt0, u32 addr);
93 static void G3BS_TexPlttBase(GXDLInfo *info, u32 addr, GXTexFmt texfmt);
94 static void G3BS_MaterialColorDiffAmb(GXDLInfo *info, GXRgb diffuse, GXRgb ambient,
95                                       BOOL IsSetVtxColor);
96 static void G3BS_MaterialColorSpecEmi(GXDLInfo *info, GXRgb specular, GXRgb emission,
97                                       BOOL IsShininess);
98 static void G3BS_LightVector(GXDLInfo *info, GXLightId lightID, fx16 x, fx16 y, fx16 z);
99 static void G3BS_LightColor(GXDLInfo *info, GXLightId lightID, GXRgb rgb);
100 static void G3BS_Shininess(GXDLInfo *info, const u32 *table);
101 static void G3BS_Begin(GXDLInfo *info, GXBegin primitive);
102 static void G3BS_End(GXDLInfo *info);
103 static void G3BS_SwapBuffers(GXDLInfo *info, GXSortMode am, GXBufferMode zw);
104 static void G3BS_ViewPort(GXDLInfo *info, int x1, int y1, int x2, int y2);
105 static void G3BS_BoxTest(GXDLInfo *info, const GXBoxTestParam *box);
106 static void G3BS_PositionTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
107 static void G3BS_VectorTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
108 
109 
110 // G3B_*
111 static void G3B_UpdateGXDLInfo(GXDLInfo *info, int n);
112 void    G3B_Direct0(GXDLInfo *info, int op);
113 void    G3B_Direct1(GXDLInfo *info, int op, u32 param0);
114 void    G3B_Direct2(GXDLInfo *info, int op, u32 param0, u32 param1);
115 void    G3B_Direct3(GXDLInfo *info, int op, u32 param0, u32 param1, u32 param2);
116 void    G3B_DirectN(GXDLInfo *info, int op, int nParams, const u32 *params);
117 
118 void    G3B_Nop(GXDLInfo *info);
119 void    G3B_MtxMode(GXDLInfo *info, GXMtxMode mode);
120 void    G3B_PushMtx(GXDLInfo *info);
121 void    G3B_PopMtx(GXDLInfo *info, int num);
122 void    G3B_StoreMtx(GXDLInfo *info, int num);
123 void    G3B_RestoreMtx(GXDLInfo *info, int num);
124 void    G3B_Identity(GXDLInfo *info);
125 void    G3B_LoadMtx44(GXDLInfo *info, const MtxFx44 *m);
126 void    G3B_LoadMtx43(GXDLInfo *info, const MtxFx43 *m);
127 void    G3B_MultMtx44(GXDLInfo *info, const MtxFx44 *m);
128 void    G3B_MultMtx43(GXDLInfo *info, const MtxFx43 *m);
129 void    G3B_MultMtx33(GXDLInfo *info, const MtxFx33 *m);
130 void    G3B_Scale(GXDLInfo *info, fx32 x, fx32 y, fx32 z);
131 void    G3B_Translate(GXDLInfo *info, fx32 x, fx32 y, fx32 z);
132 void    G3B_MultTransMtx33(GXDLInfo *info, const MtxFx33 *mtx, const VecFx32 *trans);
133 void    G3B_Color(GXDLInfo *info, GXRgb rgb);
134 void    G3B_Normal(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
135 void    G3B_TexCoord(GXDLInfo *info, fx32 s, fx32 t);
136 void    G3B_Vtx(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
137 void    G3B_Vtx10(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
138 void    G3B_VtxXY(GXDLInfo *info, fx16 x, fx16 y);
139 void    G3B_VtxXZ(GXDLInfo *info, fx16 x, fx16 z);
140 void    G3B_VtxYZ(GXDLInfo *info, fx16 y, fx16 z);
141 void    G3B_VtxDiff(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
142 void    G3B_PolygonAttr(GXDLInfo *info, int light, GXPolygonMode polyMode, GXCull cullMode, int polygonID, int alpha, int misc  // GXPolygonAttrMisc
143     );
144 void    G3B_TexImageParam(GXDLInfo *info,
145                           GXTexFmt texFmt,
146                           GXTexGen texGen,
147                           GXTexSizeS s,
148                           GXTexSizeT t,
149                           GXTexRepeat repeat, GXTexFlip flip, GXTexPlttColor0 pltt0, u32 addr);
150 void    G3B_TexPlttBase(GXDLInfo *info, u32 addr, GXTexFmt texfmt);
151 void    G3B_MaterialColorDiffAmb(GXDLInfo *info, GXRgb diffuse, GXRgb ambient, BOOL IsSetVtxColor);
152 void    G3B_MaterialColorSpecEmi(GXDLInfo *info, GXRgb specular, GXRgb emission, BOOL IsShininess);
153 void    G3B_LightVector(GXDLInfo *info, GXLightId lightID, fx16 x, fx16 y, fx16 z);
154 void    G3B_LightColor(GXDLInfo *info, GXLightId lightID, GXRgb rgb);
155 void    G3B_Shininess(GXDLInfo *info, const u32 *table);
156 void    G3B_Begin(GXDLInfo *info, GXBegin primitive);
157 void    G3B_End(GXDLInfo *info);
158 void    G3B_SwapBuffers(GXDLInfo *info, GXSortMode am, GXBufferMode zw);
159 void    G3B_ViewPort(GXDLInfo *info, int x1, int y1, int x2, int y2);
160 void    G3B_BoxTest(GXDLInfo *info, const GXBoxTestParam *box);
161 void    G3B_PositionTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
162 void    G3B_VectorTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
163 
164 //----------------------------------------------------------------------------
165 // Implementation of inline function
166 //----------------------------------------------------------------------------
167 
168 // G3BS_*
169 #define GXBS_CURR_ALIGNMENT_ASSERT(x)            SDK_ASSERT(((u32)x->curr_cmd & 0x03) == 0)
170 
171 
172 /*---------------------------------------------------------------------------*
173   Name:         G3BS_Direct0
174 
175   Description:  Makes a geometry command with no parameters on a display list.
176                 Note that the command is not packed.
177 
178   Arguments:    info       a pointer to GXDLInfo
179                 op         a geometry command(GXOP_xxxxxxx)
180 
181   Returns:      none
182  *---------------------------------------------------------------------------*/
G3BS_Direct0(GXDLInfo * info,int op)183 static inline void G3BS_Direct0(GXDLInfo *info, int op)
184 {
185     SDK_NULL_ASSERT(info);
186     GXBS_CURR_ALIGNMENT_ASSERT(info);
187     GX_VALID_OPCODE_ASSERT(op);
188 
189     *(u32 *)info->curr_cmd = (u32)op;
190 }
191 
192 
193 /*---------------------------------------------------------------------------*
194   Name:         G3BS_Direct1
195 
196   Description:  Makes a geometry command with a parameter on a display list.
197                 Note that the command is not packed.
198 
199   Arguments:    info       a pointer to GXDLInfo
200                 op         a geometry command(GXOP_xxxxxxx)
201                 param0     a parameter
202 
203   Returns:      none
204  *---------------------------------------------------------------------------*/
G3BS_Direct1(GXDLInfo * info,int op,u32 param0)205 static inline void G3BS_Direct1(GXDLInfo *info, int op, u32 param0)
206 {
207     SDK_NULL_ASSERT(info);
208     GXBS_CURR_ALIGNMENT_ASSERT(info);
209     GX_VALID_OPCODE_ASSERT(op);
210 
211     *(u32 *)info->curr_cmd = (u32)op;
212     *info->curr_param = param0;
213 }
214 
215 
216 /*---------------------------------------------------------------------------*
217   Name:         G3BS_Direct2
218 
219   Description:  Makes a geometry command with two parameters on a display list.
220                 Note that the command is not packed.
221 
222   Arguments:    info       a pointer to GXDLInfo
223                 op         a geometry command(GXOP_xxxxxxx)
224                 param0     a parameter
225                 param1     a parameter
226 
227   Returns:      none
228  *---------------------------------------------------------------------------*/
G3BS_Direct2(GXDLInfo * info,int op,u32 param0,u32 param1)229 static inline void G3BS_Direct2(GXDLInfo *info, int op, u32 param0, u32 param1)
230 {
231     SDK_NULL_ASSERT(info);
232     GXBS_CURR_ALIGNMENT_ASSERT(info);
233     GX_VALID_OPCODE_ASSERT(op);
234 
235     *(u32 *)info->curr_cmd = (u32)op;
236     *(info->curr_param + 0) = param0;
237     *(info->curr_param + 1) = param1;
238 }
239 
240 
241 /*---------------------------------------------------------------------------*
242   Name:         G3BS_Direct3
243 
244   Description:  Makes a geometry command with three parameters on a display list.
245                 Note that the command is not packed.
246 
247   Arguments:    info       a pointer to GXDLInfo
248                 op         a geometry command(GXOP_xxxxxxx)
249                 param0     a parameter
250                 param1     a parameter
251                 param2     a parameter
252 
253   Returns:      none
254  *---------------------------------------------------------------------------*/
G3BS_Direct3(GXDLInfo * info,int op,u32 param0,u32 param1,u32 param2)255 static inline void G3BS_Direct3(GXDLInfo *info, int op, u32 param0, u32 param1, u32 param2)
256 {
257     SDK_NULL_ASSERT(info);
258     GXBS_CURR_ALIGNMENT_ASSERT(info);
259     GX_VALID_OPCODE_ASSERT(op);
260 
261     *(u32 *)info->curr_cmd = (u32)op;
262     *(info->curr_param + 0) = param0;
263     *(info->curr_param + 1) = param1;
264     *(info->curr_param + 2) = param2;
265 }
266 
267 
268 /*---------------------------------------------------------------------------*
269   Name:         G3BS_Nop
270 
271   Description:  Makes a geometry command which does nothing on a display list.
272                 Note that the command is not packed.
273 
274   Arguments:    info       a pointer to GXDLInfo
275 
276   Returns:      none
277  *---------------------------------------------------------------------------*/
G3BS_Nop(GXDLInfo * info)278 static inline void G3BS_Nop(GXDLInfo *info)
279 {
280     G3BS_Direct0(info, G3OP_NOP);
281 }
282 
283 
284 /*---------------------------------------------------------------------------*
285   Name:         G3BS_MtxMode
286 
287   Description:  Makes a geometry command, which sets a matrix mode,
288                 on a display list. Note that the command is not packed.
289 
290   Arguments:    info       a pointer to GXDLInfo
291                 mode       a matrix mode
292 
293   Returns:      none
294  *---------------------------------------------------------------------------*/
G3BS_MtxMode(GXDLInfo * info,GXMtxMode mode)295 static inline void G3BS_MtxMode(GXDLInfo *info, GXMtxMode mode)
296 {
297     GX_MTXMODE_ASSERT(mode);
298 
299     G3BS_Direct1(info, G3OP_MTX_MODE, GX_PACK_MTXMODE_PARAM(mode));
300 }
301 
302 
303 /*---------------------------------------------------------------------------*
304   Name:         G3BS_PushMtx
305 
306   Description:  Makes a geometry command, which stores a current matrix to
307                 the top of the matrix stack and increments the stack pointer,
308                 on a display list. Note that the command is not packed.
309 
310   Arguments:    info       a pointer to GXDLInfo
311 
312   Returns:      none
313  *---------------------------------------------------------------------------*/
G3BS_PushMtx(GXDLInfo * info)314 static inline void G3BS_PushMtx(GXDLInfo *info)
315 {
316     G3BS_Direct0(info, G3OP_MTX_PUSH);
317 }
318 
319 
320 /*---------------------------------------------------------------------------*
321   Name:         G3BS_PopMtx
322 
323   Description:  Makes a geometry command, which pops the num'th matrix
324                 from the matrix stack pointer on the stack,
325                 and adds num to the pointer. Note that the command is not packed.
326 
327   Arguments:    info       a pointer to GXDLInfo
328                 num        an offset to the stack pointer
329 
330   Returns:      none
331  *---------------------------------------------------------------------------*/
G3BS_PopMtx(GXDLInfo * info,int num)332 static inline void G3BS_PopMtx(GXDLInfo *info, int num)
333 {
334     GX_MTX_POP_NUM_ASSERT(num);
335 
336     G3BS_Direct1(info, G3OP_MTX_POP, GX_PACK_POPMTX_PARAM(num));
337 }
338 
339 
340 /*---------------------------------------------------------------------------*
341   Name:         G3BS_StoreMtx
342 
343   Description:  Makes a geometry command, which stores a current matrix
344                 to the num'th matrix from the matrix stack pointer on the stack,
345                 on a display list. Note that the command is not packed.
346 
347   Arguments:    info       a pointer to GXDLInfo
348                 num        an offset to the stack pointer
349 
350   Returns:      none
351  *---------------------------------------------------------------------------*/
G3BS_StoreMtx(GXDLInfo * info,int num)352 static inline void G3BS_StoreMtx(GXDLInfo *info, int num)
353 {
354     GX_MTX_STORE_NUM_ASSERT(num);
355 
356     G3BS_Direct1(info, G3OP_MTX_STORE, GX_PACK_STOREMTX_PARAM(num));
357 }
358 
359 
360 /*---------------------------------------------------------------------------*
361   Name:         G3BS_RestoreMtx
362 
363   Description:  Makes a geometry command, which gets the num'th matrix from
364                 the matrix stack pointer on the stack, on a display list.
365                 Note that the command is not packed.
366 
367   Arguments:    info       a pointer to GXDLInfo
368                 num        an offset to the stack pointer
369 
370   Returns:      none
371  *---------------------------------------------------------------------------*/
G3BS_RestoreMtx(GXDLInfo * info,int num)372 static inline void G3BS_RestoreMtx(GXDLInfo *info, int num)
373 {
374     GX_MTX_RESTORE_NUM_ASSERT(num);
375 
376     G3BS_Direct1(info, G3OP_MTX_RESTORE, GX_PACK_RESTOREMTX_PARAM(num));
377 }
378 
379 
380 /*---------------------------------------------------------------------------*
381   Name:         G3BS_Identity
382 
383   Description:  Makes a geometry command, which sets an identity matrix
384                 to the current matrix, on a display list.
385                 Note that the command is not packed.
386 
387   Arguments:    info       a pointer to GXDLInfo
388 
389   Returns:      none
390  *---------------------------------------------------------------------------*/
G3BS_Identity(GXDLInfo * info)391 static inline void G3BS_Identity(GXDLInfo *info)
392 {
393     G3BS_Direct0(info, G3OP_MTX_IDENTITY);
394 }
395 
396 
397 /*---------------------------------------------------------------------------*
398   Name:         G3BS_Scale
399 
400   Description:  Makes a geometry command, which multiplies the current matrix
401                 by a scale matrix. Note that the command is not packed.
402 
403   Arguments:    info       a pointer to GXDLInfo
404                 x          X coordinate of a scale
405                 y          Y coordinate of a scale
406                 z          Z coordinate of a scale
407 
408   Returns:      none
409  *---------------------------------------------------------------------------*/
G3BS_Scale(GXDLInfo * info,fx32 x,fx32 y,fx32 z)410 static inline void G3BS_Scale(GXDLInfo *info, fx32 x, fx32 y, fx32 z)
411 {
412     G3BS_Direct3(info, G3OP_MTX_SCALE, (u32)x, (u32)y, (u32)z);
413 }
414 
415 
416 /*---------------------------------------------------------------------------*
417   Name:         G3BS_Translate
418 
419   Description:  Makes a geometry command, which multiplies the current matrix
420                 by a translation matrix. Note that the command is not packed.
421 
422   Arguments:    info       a pointer to GXDLInfo
423                 x          X coordinate of a translation vector
424                 y          Y coordinate of a translation vector
425                 z          Z coordinate of a translation vector
426 
427   Returns:      none
428  *---------------------------------------------------------------------------*/
G3BS_Translate(GXDLInfo * info,fx32 x,fx32 y,fx32 z)429 static inline void G3BS_Translate(GXDLInfo *info, fx32 x, fx32 y, fx32 z)
430 {
431     G3BS_Direct3(info, G3OP_MTX_TRANS, (u32)x, (u32)y, (u32)z);
432 }
433 
434 
435 /*---------------------------------------------------------------------------*
436   Name:         G3BS_Color
437 
438   Description:  Makes a geometry command, which sends a vertex color.
439 
440   Arguments:    info       a pointer to GXDLInfo
441                 rgb        a vertex color(R:5, G:5, B:5)
442 
443   Returns:      none
444  *---------------------------------------------------------------------------*/
G3BS_Color(GXDLInfo * info,GXRgb rgb)445 static inline void G3BS_Color(GXDLInfo *info, GXRgb rgb)
446 {
447     GXRGB_ASSERT(rgb);
448     G3BS_Direct1(info, G3OP_COLOR, GX_PACK_COLOR_PARAM(rgb));
449 }
450 
451 
452 /*---------------------------------------------------------------------------*
453   Name:         G3BS_Normal
454 
455   Description:  Makes a geometry command, which sends a normal vector.
456 
457   Arguments:    info       a pointer to GXDLInfo
458                 x          X coordinate of a normal vector
459                 y          Y coordinate of a normal vector
460                 z          Z coordinate of a normal vector
461 
462   Returns:      none
463  *---------------------------------------------------------------------------*/
G3BS_Normal(GXDLInfo * info,fx16 x,fx16 y,fx16 z)464 static inline void G3BS_Normal(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
465 {
466     SDK_MINMAX_ASSERT(x, -FX16_ONE, FX16_ONE - 1);
467     SDK_MINMAX_ASSERT(y, -FX16_ONE, FX16_ONE - 1);
468     SDK_MINMAX_ASSERT(z, -FX16_ONE, FX16_ONE - 1);
469 
470     G3BS_Direct1(info, G3OP_NORMAL, GX_PACK_NORMAL_PARAM(x, y, z));
471 }
472 
473 
474 /*---------------------------------------------------------------------------*
475   Name:         G3BS_TexCoord
476 
477   Description:  Makes a geometry command, which sends a texture coordinate.
478 
479   Arguments:    info       a pointer to GXDLInfo
480                 s          an S of a texture coordinate
481                 t          a T of a texture coordinate
482 
483   Returns:      none
484  *---------------------------------------------------------------------------*/
G3BS_TexCoord(GXDLInfo * info,fx32 s,fx32 t)485 static inline void G3BS_TexCoord(GXDLInfo *info, fx32 s, fx32 t)
486 {
487     SDK_MINMAX_ASSERT(s, -2048 * FX32_ONE, 2048 * FX32_ONE - 1);
488     SDK_MINMAX_ASSERT(t, -2048 * FX32_ONE, 2048 * FX32_ONE - 1);
489 
490     G3BS_Direct1(info, G3OP_TEXCOORD, GX_PACK_TEXCOORD_PARAM(s, t));
491 }
492 
493 
494 /*---------------------------------------------------------------------------*
495   Name:         G3BS_Vtx
496 
497   Description:  Makes a geometry command, which sends a vertex as a fx16 vector.
498 
499   Arguments:    info       a pointer to GXDLInfo
500                 x          X coordinate of a vertex
501                 y          Y coordinate of a vertex
502                 z          Z coordinate of a vertex
503 
504   Returns:      none
505  *---------------------------------------------------------------------------*/
G3BS_Vtx(GXDLInfo * info,fx16 x,fx16 y,fx16 z)506 static inline void G3BS_Vtx(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
507 {
508     G3BS_Direct2(info, G3OP_VTX_16, GX_FX16PAIR(x, y), (u32)(u16)z);
509 }
510 
511 
512 /*---------------------------------------------------------------------------*
513   Name:         G3BS_Vtx10
514 
515   Description:  Makes a geometry command, which sends a vertex as a s3.6 vector.
516 
517   Arguments:    info       a pointer to GXDLInfo
518                 x          X coordinate of a vertex
519                 y          Y coordinate of a vertex
520                 z          Z coordinate of a vertex
521 
522   Returns:      none
523  *---------------------------------------------------------------------------*/
G3BS_Vtx10(GXDLInfo * info,fx16 x,fx16 y,fx16 z)524 static inline void G3BS_Vtx10(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
525 {
526     G3BS_Direct1(info, G3OP_VTX_10, GX_PACK_VTX10_PARAM(x, y, z));
527 }
528 
529 
530 /*---------------------------------------------------------------------------*
531   Name:         G3BS_VtxXY
532 
533   Description:  Makes a geometry command, which sends XY components of a vertex.
534                 The Z coordinate is the same to the vertex sent just before.
535 
536   Arguments:    info       a pointer to GXDLInfo
537                 x          X coordinate of a vertex
538                 y          Y coordinate of a vertex
539 
540   Returns:      none
541  *---------------------------------------------------------------------------*/
G3BS_VtxXY(GXDLInfo * info,fx16 x,fx16 y)542 static inline void G3BS_VtxXY(GXDLInfo *info, fx16 x, fx16 y)
543 {
544     G3BS_Direct1(info, G3OP_VTX_XY, GX_PACK_VTXXY_PARAM(x, y));
545 }
546 
547 
548 /*---------------------------------------------------------------------------*
549   Name:         G3BS_VtxXZ
550 
551   Description:  Makes a geometry command, which sends XZ components of a vertex.
552                 The Y coordinate is the same to the vertex sent just before.
553 
554   Arguments:    info       a pointer to GXDLInfo
555                 x          X coordinate of a vertex
556                 z          Z coordinate of a vertex
557 
558   Returns:      none
559  *---------------------------------------------------------------------------*/
G3BS_VtxXZ(GXDLInfo * info,fx16 x,fx16 z)560 static inline void G3BS_VtxXZ(GXDLInfo *info, fx16 x, fx16 z)
561 {
562     G3BS_Direct1(info, G3OP_VTX_XZ, GX_PACK_VTXXZ_PARAM(x, z));
563 }
564 
565 
566 /*---------------------------------------------------------------------------*
567   Name:         G3BS_VtxYZ
568 
569   Description:  Makes a geometry command, which sends YZ components of a vertex.
570                 The X component is the same to the vertex sent just before.
571 
572   Arguments:    info       a pointer to GXDLInfo
573                 y          Y coordinate of a vertex
574                 z          Z coordinate of a vertex
575 
576   Returns:      none
577  *---------------------------------------------------------------------------*/
G3BS_VtxYZ(GXDLInfo * info,fx16 y,fx16 z)578 static inline void G3BS_VtxYZ(GXDLInfo *info, fx16 y, fx16 z)
579 {
580     G3BS_Direct1(info, G3OP_VTX_YZ, GX_PACK_VTXYZ_PARAM(y, z));
581 }
582 
583 
584 /*---------------------------------------------------------------------------*
585   Name:         G3BS_VtxDiff
586 
587   Description:  Makes a geometry commnad, which sends a vector as an offset
588                 to the last vertex sent.
589 
590   Arguments:    info       a pointer to GXDLInfo
591                 x          X coordinate of an offset
592                 y          Y coordinate of an offset
593                 z          Z coordinate of an offset
594 
595   Returns:      none
596  *---------------------------------------------------------------------------*/
G3BS_VtxDiff(GXDLInfo * info,fx16 x,fx16 y,fx16 z)597 static inline void G3BS_VtxDiff(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
598 {
599     SDK_MINMAX_ASSERT(x, (fx16)0xfe00, (fx16)0x1ff);
600     SDK_MINMAX_ASSERT(y, (fx16)0xfe00, (fx16)0x1ff);
601     SDK_MINMAX_ASSERT(z, (fx16)0xfe00, (fx16)0x1ff);
602 
603     G3BS_Direct1(info, G3OP_VTX_DIFF, GX_PACK_VTXDIFF_PARAM(x, y, z));
604 }
605 
606 
607 /*---------------------------------------------------------------------------*
608   Name:         G3BS_PolygonAttr
609 
610   Description:  Makes a geometry command, which sends attributes for polygons.
611 
612   Arguments:    info       a pointer to GXDLInfo
613                 light      a 4bits field specifying light enable/disable
614                 polyMode   a polygon mode
615                 cullMode   a cull mode
616                 polygonID  a polygon ID
617                 alpha      an alpha value
618                 misc       miscellaneous flags
619 
620   Returns:      none
621  *---------------------------------------------------------------------------*/
G3BS_PolygonAttr(GXDLInfo * info,int light,GXPolygonMode polyMode,GXCull cullMode,int polygonID,int alpha,int misc)622 static inline void G3BS_PolygonAttr(GXDLInfo *info, int light, GXPolygonMode polyMode, GXCull cullMode, int polygonID, int alpha, int misc      // GXPolygonAttrMisc
623     )
624 {
625     GX_LIGHTMASK_ASSERT(light);
626     GX_POLYGONMODE_ASSERT(polyMode);
627     GX_CULL_ASSERT(cullMode);
628     GX_POLYGON_ATTR_POLYGONID_ASSERT(polygonID);
629     GX_POLYGON_ATTR_ALPHA_ASSERT(alpha);
630 
631     G3BS_Direct1(info,
632                  G3OP_POLYGON_ATTR,
633                  GX_PACK_POLYGONATTR_PARAM(light, polyMode, cullMode, polygonID, alpha, misc));
634 }
635 
636 
637 /*---------------------------------------------------------------------------*
638   Name:         G3BS_TexImageParam
639 
640   Description:  Makes a geometry command, which sends parameters for a texture.
641 
642   Arguments:    info       a pointer to GXDLInfo
643                 texFmt     format of a texture
644                 texGen     selects the source of a texture coordinate
645                 s          the size of a texture in the direction of the S-axis
646                 t          the size of a texture in the direction of the T-axis
647                 repeat     repeat
648                 flip       flip
649                 pltt0      use/not use the color of pltt. 0
650                 addr       the offset address in the texture image slots
651                            (shift 3bits internally)
652 
653   Returns:      none
654  *---------------------------------------------------------------------------*/
G3BS_TexImageParam(GXDLInfo * info,GXTexFmt texFmt,GXTexGen texGen,GXTexSizeS s,GXTexSizeT t,GXTexRepeat repeat,GXTexFlip flip,GXTexPlttColor0 pltt0,u32 addr)655 static inline void G3BS_TexImageParam(GXDLInfo *info,
656                                       GXTexFmt texFmt,
657                                       GXTexGen texGen,
658                                       GXTexSizeS s,
659                                       GXTexSizeT t,
660                                       GXTexRepeat repeat,
661                                       GXTexFlip flip, GXTexPlttColor0 pltt0, u32 addr)
662 {
663     GX_TEXREPEAT_ASSERT(repeat);
664     GX_TEXFLIP_ASSERT(flip);
665     GX_TEXSIZE_S_ASSERT(s);
666     GX_TEXSIZE_T_ASSERT(t);
667     GX_TEXFMT_ASSERT(texFmt);
668     GX_TEXPLTTCOLOR0_ASSERT(pltt0);
669     GX_TEXGEN_ASSERT(texGen);
670     GX_TEXIMAGE_PARAM_ADDR_ASSERT(addr);
671 
672     G3BS_Direct1(info,
673                  G3OP_TEXIMAGE_PARAM,
674                  GX_PACK_TEXIMAGE_PARAM(texFmt, texGen, s, t, repeat, flip, pltt0, addr));
675 }
676 
677 
678 /*---------------------------------------------------------------------------*
679   Name:         G3BS_TexPlttBase
680 
681   Description:  Makes a geometry command, which sends a base address of
682                 a texture palette.
683 
684   Arguments:    info       a pointer to GXDLInfo
685                 addr       the offset address in the texture palette slots
686                 texFmt     format of a texture
687 
688   Returns:      none
689  *---------------------------------------------------------------------------*/
G3BS_TexPlttBase(GXDLInfo * info,u32 addr,GXTexFmt texfmt)690 static inline void G3BS_TexPlttBase(GXDLInfo *info, u32 addr, GXTexFmt texfmt)
691 {
692     u32     param = GX_PACK_TEXPLTTBASE_PARAM(addr, texfmt);
693     GX_TEXPLTTBASEPARAM_ASSERT(param);
694 
695     G3BS_Direct1(info, G3OP_TEXPLTT_BASE, param);
696 }
697 
698 
699 /*---------------------------------------------------------------------------*
700   Name:         G3BS_MaterialColorDiffAmb
701 
702   Description:  Makes a geometry command, which sends diffuse and ambient.
703 
704   Arguments:    info           a pointer to GXDLInfo
705                 diffuse        a diffuse color
706                 ambient        an ambient color
707                 IsSetVtxColor  sets a diffuse color as a vertex color if TRUE
708 
709   Returns:      none
710  *---------------------------------------------------------------------------*/
G3BS_MaterialColorDiffAmb(GXDLInfo * info,GXRgb diffuse,GXRgb ambient,BOOL IsSetVtxColor)711 static inline void G3BS_MaterialColorDiffAmb(GXDLInfo *info,
712                                              GXRgb diffuse, GXRgb ambient, BOOL IsSetVtxColor)
713 {
714     GXRGB_ASSERT(diffuse);
715     GXRGB_ASSERT(ambient);
716 
717     G3BS_Direct1(info, G3OP_DIF_AMB, GX_PACK_DIFFAMB_PARAM(diffuse, ambient, IsSetVtxColor));
718 }
719 
720 
721 /*---------------------------------------------------------------------------*
722   Name:         G3BS_MaterialColorSpecEmi
723 
724   Description:  Makes a geometry command, which sends specular and emission.
725 
726   Arguments:    info           a pointer to GXDLInfo
727                 specular       a specular color
728                 emission       an emission color
729                 IsShininess    use the shininess table to change a specular
730                                color if TRUE
731 
732   Returns:      none
733  *---------------------------------------------------------------------------*/
G3BS_MaterialColorSpecEmi(GXDLInfo * info,GXRgb specular,GXRgb emission,BOOL IsShininess)734 static inline void G3BS_MaterialColorSpecEmi(GXDLInfo *info,
735                                              GXRgb specular, GXRgb emission, BOOL IsShininess)
736 {
737     GXRGB_ASSERT(specular);
738     GXRGB_ASSERT(emission);
739 
740     G3BS_Direct1(info, G3OP_SPE_EMI, GX_PACK_SPECEMI_PARAM(specular, emission, IsShininess));
741 }
742 
743 
744 /*---------------------------------------------------------------------------*
745   Name:         G3BS_LightVector
746 
747   Description:  Makes a geometry command, which sends a light vector.
748 
749   Arguments:    info       a pointer to GXDLInfo
750                 lightID    light ID
751                 x          X coordinate of a light vector
752                 y          Y coordinate of a light vector
753                 z          Z coordinate of a light vector
754 
755   Returns:      none
756  *---------------------------------------------------------------------------*/
G3BS_LightVector(GXDLInfo * info,GXLightId lightID,fx16 x,fx16 y,fx16 z)757 static inline void G3BS_LightVector(GXDLInfo *info, GXLightId lightID, fx16 x, fx16 y, fx16 z)
758 {
759     GX_LIGHTID_ASSERT(lightID);
760     SDK_MINMAX_ASSERT(x, -FX16_ONE, FX16_ONE - 1);
761     SDK_MINMAX_ASSERT(y, -FX16_ONE, FX16_ONE - 1);
762     SDK_MINMAX_ASSERT(z, -FX16_ONE, FX16_ONE - 1);
763 
764     G3BS_Direct1(info, G3OP_LIGHT_VECTOR, GX_PACK_LIGHTVECTOR_PARAM(lightID, x, y, z));
765 }
766 
767 
768 /*---------------------------------------------------------------------------*
769   Name:         G3BS_LightColor
770 
771   Description:  Makes a geometry command, which sends a light color.
772 
773   Arguments:    info       a pointer to GXDLInfo
774                 lightID    light ID
775                 rgb        a light color(R:5, G:5, B:5)
776 
777   Returns:      none
778  *---------------------------------------------------------------------------*/
G3BS_LightColor(GXDLInfo * info,GXLightId lightID,GXRgb rgb)779 static inline void G3BS_LightColor(GXDLInfo *info, GXLightId lightID, GXRgb rgb)
780 {
781     GX_LIGHTID_ASSERT(lightID);
782     GXRGB_ASSERT(rgb);
783 
784     G3BS_Direct1(info, G3OP_LIGHT_COLOR, GX_PACK_LIGHTCOLOR_PARAM(lightID, rgb));
785 }
786 
787 
788 /*---------------------------------------------------------------------------*
789   Name:         G3BS_Shininess
790 
791   Description:  Makes a geometry command, which sets up the shininess table.
792 
793   Arguments:    info       a pointer to GXDLInfo
794                 table      a pointer to the shininess data(32 words)
795 
796   Returns:      none
797  *---------------------------------------------------------------------------*/
G3BS_Shininess(GXDLInfo * info,const u32 * table)798 static inline void G3BS_Shininess(GXDLInfo *info, const u32 *table)
799 {
800     G3BS_DirectN(info, G3OP_SHININESS, 32, table);
801 }
802 
803 
804 /*---------------------------------------------------------------------------*
805   Name:         G3BS_Begin
806 
807   Description:  Makes a geometry command, which starts sending primitives.
808 
809   Arguments:    info       a pointer to GXDLInfo
810                 primitive  the type of primitives
811 
812   Returns:      none
813  *---------------------------------------------------------------------------*/
G3BS_Begin(GXDLInfo * info,GXBegin primitive)814 static inline void G3BS_Begin(GXDLInfo *info, GXBegin primitive)
815 {
816     GX_BEGIN_ASSERT(primitive);
817 
818     G3BS_Direct1(info, G3OP_BEGIN, GX_PACK_BEGIN_PARAM(primitive));
819 }
820 
821 
822 /*---------------------------------------------------------------------------*
823   Name:         G3BS_End
824 
825   Description:  Makes a geometry command, which ends sending primitives.
826 
827   Arguments:    info       a pointer to GXDLInfo
828 
829   Returns:      none
830  *---------------------------------------------------------------------------*/
G3BS_End(GXDLInfo * info)831 static inline void G3BS_End(GXDLInfo *info)
832 {
833     G3BS_Direct0(info, G3OP_END);
834 }
835 
836 
837 /*---------------------------------------------------------------------------*
838   Name:         G3BS_SwapBuffers
839 
840   Description:  Makes a geometry command, which swaps the polygon list RAM,
841                 the vertex RAM, etc.
842 
843   Arguments:    info       a pointer to GXDLInfo
844                 am         auto sort/manual sort
845                 zw         Z buffer/W buffer
846 
847   Returns:      none
848  *---------------------------------------------------------------------------*/
G3BS_SwapBuffers(GXDLInfo * info,GXSortMode am,GXBufferMode zw)849 static inline void G3BS_SwapBuffers(GXDLInfo *info, GXSortMode am, GXBufferMode zw)
850 {
851     GX_SORTMODE_ASSERT(am);
852     GX_BUFFERMODE_ASSERT(zw);
853 
854     G3BS_Direct1(info, G3OP_SWAP_BUFFERS, GX_PACK_SWAPBUFFERS_PARAM(am, zw));
855 }
856 
857 
858 /*---------------------------------------------------------------------------*
859   Name:         G3BS_ViewPort
860 
861   Description:  Makes a geometry command, which specifies viewport.
862 
863   Arguments:    info       a pointer to GXDLInfo
864                 x1         the X coordinate of the lower left
865                 y1         the Y coordinate of the lower left
866                 x2         the X coordinate of the upper right
867                 y2         the Y coordinate of the upper right
868 
869   Returns:      none
870  *---------------------------------------------------------------------------*/
G3BS_ViewPort(GXDLInfo * info,int x1,int y1,int x2,int y2)871 static inline void G3BS_ViewPort(GXDLInfo *info, int x1, int y1, int x2, int y2)
872 {
873     GX_VIEWPORT_ASSERT(x1, y1, x2, y2);
874 
875     G3BS_Direct1(info, G3OP_VIEWPORT, GX_PACK_VIEWPORT_PARAM(x1, y1, x2, y2));
876 }
877 
878 
879 /*---------------------------------------------------------------------------*
880   Name:         G3BS_BoxTest
881 
882   Description:  Makes a geometry command, which tests if a box is
883                 in the frustum or not.
884 
885   Arguments:    info       a pointer to GXDLInfo
886                 box        a pointer to GXBoxTestParam
887 
888   Returns:      none
889  *---------------------------------------------------------------------------*/
G3BS_BoxTest(GXDLInfo * info,const GXBoxTestParam * box)890 static inline void G3BS_BoxTest(GXDLInfo *info, const GXBoxTestParam *box)
891 {
892     G3BS_Direct3(info, G3OP_BOX_TEST, box->val[0], box->val[1], box->val[2]);
893 }
894 
895 
896 /*---------------------------------------------------------------------------*
897   Name:         G3BS_PositionTest
898 
899   Description:  Makes a geometry command, which applies a position vector
900                 to the current clip matrix.
901 
902   Arguments:    info       a pointer to GXDLInfo
903                 x          X coordinate of a position
904                 y          Y coordinate of a position
905                 z          Z coordinate of a position
906 
907   Returns:      none
908  *---------------------------------------------------------------------------*/
G3BS_PositionTest(GXDLInfo * info,fx16 x,fx16 y,fx16 z)909 static inline void G3BS_PositionTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
910 {
911     G3BS_Direct2(info, G3OP_POS_TEST, GX_FX16PAIR(x, y), (u32)(u16)z);
912 }
913 
914 
915 /*---------------------------------------------------------------------------*
916   Name:         G3BS_VectorTest
917 
918   Description:  Makes a geometry command, which applies a vector
919                 to the current vector matrix.
920 
921   Arguments:    info       a pointer to GXDLInfo
922                 x          X coordinate of a vector
923                 y          Y coordinate of a vector
924                 z          Z coordinate of a vector
925 
926   Returns:      none
927  *---------------------------------------------------------------------------*/
G3BS_VectorTest(GXDLInfo * info,fx16 x,fx16 y,fx16 z)928 static inline void G3BS_VectorTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
929 {
930     SDK_MINMAX_ASSERT(x, -FX16_ONE, FX16_ONE - 1);
931     SDK_MINMAX_ASSERT(y, -FX16_ONE, FX16_ONE - 1);
932     SDK_MINMAX_ASSERT(z, -FX16_ONE, FX16_ONE - 1);
933 
934     G3BS_Direct1(info, G3OP_VEC_TEST, GX_PACK_VECTORTEST_PARAM(x, y, z));
935 }
936 
937 
938 /*---------------------------------------------------------------------------*
939   Name:         G3B_UpdateGXDLInfo
940 
941   Description:  Updates a display list pointer of '*info'.
942 
943   Arguments:    info       a pointer to GXDLInfo
944                 n          an index to proceed
945 
946   Returns:      none
947  *---------------------------------------------------------------------------*/
G3B_UpdateGXDLInfo(GXDLInfo * info,int n)948 static inline void G3B_UpdateGXDLInfo(GXDLInfo *info, int n)
949 {
950     info->curr_cmd = (u8 *)(info->curr_param + n);
951     info->curr_param = (u32 *)(info->curr_cmd + 4);
952 
953     SDK_ASSERTMSG(((u32)(info->curr_cmd) - (u32)info->bottom <= info->length),
954                   "Buffer overflow ! : Current DL buffer doesn't have enough capacity for new commands\n");
955 }
956 
957 #if (defined(_MSC_VER) && !defined(_cplusplus))
958 #undef inline
959 #endif
960 
961 #ifdef __cplusplus
962 }/* extern "C" */
963 #endif
964 
965 /* NITRO_G3B_H_ */
966 #endif
967