1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX - demos - UnitTours/3D_Pol_Simple2
3   File:     main.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 //---------------------------------------------------------------------------
19 // A sample that uses G3_VtxXY, G3_VtxYZ, G3_VtxXZ:
20 //
21 // You can reduce the amount of the data transferred to the FIFO
22 // by G3_VtxXY, G3_VtxYZ, and G3_VtxXZ.
23 // They can be used if one of the coordinates of the point is same
24 // to the previous one.
25 //---------------------------------------------------------------------------
26 
27 #ifdef SDK_TWL
28 #include <twl.h>
29 #else
30 #include <nitro.h>
31 #endif
32 #include "DEMO.h"
33 
34 #ifdef SDK_TWL
TwlMain(void)35 void TwlMain(void)
36 #else
37 void NitroMain(void)
38 #endif
39 {
40     u16     Rotate = 0;                // for rotating cubes(0-65535)
41 
42     //---------------------------------------------------------------------------
43     // Initialize:
44     // They enable IRQ interrupts, initialize VRAM, and set BG #0 for 3D mode.
45     //---------------------------------------------------------------------------
46     DEMOInitCommon();
47     DEMOInitVRAM();
48     DEMOInitDisplay3D();
49 
50     DEMOStartDisplay();
51     while (1)
52     {
53         G3X_Reset();
54         Rotate += 256;
55 
56         {
57             VecFx32 Eye = { 0, 0, FX32_ONE };   // Eye position
58             VecFx32 at = { 0, 0, 0 };  // Viewpoint
59             VecFx32 vUp = { 0, FX32_ONE, 0 };   // Up
60 
61             // Matrix mode is changed to GX_MTXMODE_POSITION_VECTOR internally,
62             // and the camera matrix is loaded to the current matrix.
63             G3_LookAt(&Eye, &vUp, &at, NULL);
64         }
65 
66         G3_PushMtx();
67 
68         {
69             fx16    s = FX_SinIdx(Rotate);
70             fx16    c = FX_CosIdx(Rotate);
71 
72             G3_Translate(0, 0, -5 * FX32_ONE);
73 
74             G3_RotX(s, c);
75             G3_RotY(s, c);
76             G3_RotZ(s, c);
77 
78             // The current matrix is Rz * Ry * Rx * Trns * Cam.
79         }
80 
81         G3_MaterialColorDiffAmb(GX_RGB(31, 31, 31),     // diffuse
82                                 GX_RGB(16, 16, 16),     // ambient
83                                 TRUE   // use diffuse as vtx color if TRUE
84             );
85 
86         G3_MaterialColorSpecEmi(GX_RGB(16, 16, 16),     // specular
87                                 GX_RGB(0, 0, 0),        // emission
88                                 FALSE  // use shininess table if TRUE
89             );
90 
91         G3_PolygonAttr(GX_LIGHTMASK_NONE,       // no lights
92                        GX_POLYGONMODE_MODULATE, // modulation mode
93                        GX_CULL_BACK,   // cull back
94                        0,              // polygon ID(0 - 63)
95                        31,             // alpha(0 - 31)
96                        0               // OR of GXPolygonAttrMisc's value
97             );
98 
99         G3_Begin(GX_BEGIN_QUADS);
100 
101         {
102             G3_Vtx(FX16_ONE, -FX16_ONE, FX16_ONE);
103             G3_VtxXY(FX16_ONE, FX16_ONE);
104             G3_VtxXY(-FX16_ONE, FX16_ONE);
105             G3_VtxXY(-FX16_ONE, -FX16_ONE);
106 
107             G3_Vtx(-FX16_ONE, -FX16_ONE, -FX16_ONE);
108             G3_VtxXY(-FX16_ONE, FX16_ONE);
109             G3_VtxXY(FX16_ONE, FX16_ONE);
110             G3_VtxXY(FX16_ONE, -FX16_ONE);
111 
112             G3_Vtx(-FX16_ONE, -FX16_ONE, FX16_ONE);
113             G3_VtxYZ(FX16_ONE, FX16_ONE);
114             G3_VtxYZ(FX16_ONE, -FX16_ONE);
115             G3_VtxYZ(-FX16_ONE, -FX16_ONE);
116 
117             G3_Vtx(FX16_ONE, -FX16_ONE, -FX16_ONE);
118             G3_VtxYZ(FX16_ONE, -FX16_ONE);
119             G3_VtxYZ(FX16_ONE, FX16_ONE);
120             G3_VtxYZ(-FX16_ONE, FX16_ONE);
121 
122             G3_Vtx(-FX16_ONE, FX16_ONE, -FX16_ONE);
123             G3_VtxXZ(-FX16_ONE, FX16_ONE);
124             G3_VtxXZ(FX16_ONE, FX16_ONE);
125             G3_VtxXZ(FX16_ONE, -FX16_ONE);
126 
127             G3_Vtx(-FX16_ONE, -FX16_ONE, FX16_ONE);
128             G3_VtxXZ(-FX16_ONE, -FX16_ONE);
129             G3_VtxXZ(FX16_ONE, -FX16_ONE);
130             G3_VtxXZ(FX16_ONE, FX16_ONE);
131         }
132 
133         G3_End();
134 
135         G3_PopMtx(1);
136 
137         // swapping the polygon list RAM, the vertex RAM, etc.
138         G3_SwapBuffers(GX_SORTMODE_AUTO, GX_BUFFERMODE_W);
139 
140 #ifdef SDK_AUTOTEST
141         GX_SetBankForLCDC(GX_VRAM_LCDC_C);
142         EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
143         EXT_TestScreenShot(100, 0xF34A239D);
144         EXT_TestTickCounter();
145 #endif //SDK_AUTOTEST
146 
147         OS_WaitVBlankIntr();           // Waiting the end of VBlank interrupt
148     }
149 }
150 
151 //---------------------------------------------------------------------------
152 // VBlank interrupt function:
153 //
154 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
155 // OS_EnableIrqMask selects IRQ interrupts to enable, and
156 // OS_EnableIrq enables IRQ interrupts.
157 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a VBlank interrupt.
158 //---------------------------------------------------------------------------
VBlankIntr(void)159 void VBlankIntr(void)
160 {
161     OS_SetIrqCheckFlag(OS_IE_V_BLANK); // checking VBlank interrupt
162 }
163