1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX - demos - UnitTours/3D_Pol_OneTri
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-12-16#$
14   $Rev: 9663 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 #ifdef SDK_TWL
18 #include <twl.h>
19 #else
20 #include <nitro.h>
21 #endif
22 #include "DEMO.h"
23 
24 //---------------------------------------------------------------------------
25 // A sample for drawing a triangle:
26 //
27 // This sample simply draws a triangle.
28 // It does not even set camera.
29 // Also, it does not use DEMOInit(), which sets up 3D hardware.
30 //---------------------------------------------------------------------------
drawTriangle()31 static void drawTriangle()
32 {
33     G3_PolygonAttr(GX_LIGHTMASK_NONE,  // no lights
34                    GX_POLYGONMODE_MODULATE,     // modulation mode
35                    GX_CULL_NONE,       // cull none
36                    0,                  // polygon ID(0 - 63)
37                    31,                 // alpha(0 - 31)
38                    0                   // OR of GXPolygonAttrMisc's value
39         );
40 
41     G3_Begin(GX_BEGIN_TRIANGLES);
42     {
43         G3_Color(GX_RGB(31, 16, 16));
44         G3_Vtx(0, FX16_ONE, 0);
45         G3_Color(GX_RGB(16, 31, 16));
46         G3_Vtx(-FX16_ONE, -FX16_ONE, 0);
47         G3_Color(GX_RGB(16, 16, 31));
48         G3_Vtx(FX16_ONE, -FX16_ONE, 0);
49     }
50     G3_End();
51 }
52 
53 
54 #ifdef SDK_TWL
TwlMain(void)55 void TwlMain(void)
56 #else
57 void NitroMain(void)
58 #endif
59 {
60     //---------------------------------------------------------------------------
61     // Initialization:
62     // They set up interrupt, VRAM banks only.
63     //---------------------------------------------------------------------------
64     DEMOInitCommon();
65     DEMOInitVRAM();
66     // This sample set the basic 3D settings, DEMOInit() not called.
67 
68     //---------------------------------------------------------------------------
69     // Initialize 3D hardware
70     //---------------------------------------------------------------------------
71     G3X_Init();
72 
73     //---------------------------------------------------------------------------
74     // Initialize the matrix stacks and the matrix stack pointers
75     //---------------------------------------------------------------------------
76     G3X_InitMtxStack();
77 
78     //---------------------------------------------------------------------------
79     // After the geometry engine or the rendering one is enabled,
80     // you must issue SwapBuffers geometry command once.
81     //---------------------------------------------------------------------------
82     G3_SwapBuffers(GX_SORTMODE_AUTO, GX_BUFFERMODE_W);
83 
84     //---------------------------------------------------------------------------
85     // Set up graphics mode.
86     // GX_DISPMODE_GRAPHICS must be specified if you display 2D or 3D graphics.
87     // GX_BG0_AS_3D must be specified if you use BG0 as 3D graphics.
88     //---------------------------------------------------------------------------
89     GX_SetGraphicsMode(GX_DISPMODE_GRAPHICS,    // Graphics mode
90                        GX_BGMODE_0,    // BG mode is 0
91                        GX_BG0_AS_3D);  // Set BG0 as 3D
92 
93     GX_DispOff();
94 
95     //---------------------------------------------------------------------------
96     // Set BG0 visible
97     //---------------------------------------------------------------------------
98     GX_SetVisiblePlane(GX_PLANEMASK_BG0);
99 
100     //---------------------------------------------------------------------------
101     // Set priority of BG0 plane
102     //---------------------------------------------------------------------------
103     G2_SetBG0Priority(0);
104 
105     //---------------------------------------------------------------------------
106     // Shading mode is toon(toon shading is not used in this sample)
107     //---------------------------------------------------------------------------
108     G3X_SetShading(GX_SHADING_TOON);
109 
110     //---------------------------------------------------------------------------
111     // No alpha tests
112     //---------------------------------------------------------------------------
113     G3X_AlphaTest(FALSE, 0);
114 
115     //---------------------------------------------------------------------------
116     // Enable alpha blending
117     //---------------------------------------------------------------------------
118     G3X_AlphaBlend(TRUE);
119 
120     //---------------------------------------------------------------------------
121     // Enable anti aliasing
122     //---------------------------------------------------------------------------
123     G3X_AntiAlias(TRUE);
124 
125     //---------------------------------------------------------------------------
126     // No edge marking
127     //---------------------------------------------------------------------------
128     G3X_EdgeMarking(FALSE);
129 
130     //---------------------------------------------------------------------------
131     // No fog
132     //---------------------------------------------------------------------------
133     G3X_SetFog(FALSE, (GXFogBlend)0, (GXFogSlope)0, 0);
134 
135     //---------------------------------------------------------------------------
136     // Set up clear color, depth, and polygon ID.
137     //---------------------------------------------------------------------------
138     G3X_SetClearColor(0, 31, 0x7fff, 63, FALSE);
139 
140     //---------------------------------------------------------------------------
141     // Viewport
142     //---------------------------------------------------------------------------
143     G3_ViewPort(0, 0, 255, 191);
144 
145     //---------------------------------------------------------------------------
146     // Start display
147     //---------------------------------------------------------------------------
148     OS_WaitVBlankIntr();               // Waiting the end of VBlank interrupt
149     GX_DispOn();
150 
151     while (1)
152     {
153         //---------------------------------------------------------------------------
154         // Reset the states of 3D graphics
155         //---------------------------------------------------------------------------
156         G3X_Reset();
157 
158         //---------------------------------------------------------------------------
159         // In this sample, the camera matrix and the projection matrix are set as
160         // an identity matrices for simplicity.
161         //---------------------------------------------------------------------------
162         G3_MtxMode(GX_MTXMODE_PROJECTION);
163         G3_Identity();
164         G3_MtxMode(GX_MTXMODE_POSITION_VECTOR);
165         G3_Identity();
166 
167         drawTriangle();
168 
169         // swapping the polygon list RAM, the vertex RAM, etc.
170         G3_SwapBuffers(GX_SORTMODE_AUTO, GX_BUFFERMODE_W);
171 
172 #ifdef SDK_AUTOTEST
173         GX_SetBankForLCDC(GX_VRAM_LCDC_C);
174         EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
175         EXT_TestScreenShot(100, 0xEC77D136);
176         EXT_TestTickCounter();
177 #endif //SDK_AUTOTEST
178 
179         OS_WaitVBlankIntr();           // Waiting the end of VBlank interrupt
180     }
181 
182 }
183 
184 //---------------------------------------------------------------------------
185 // VBlank interrupt function:
186 //
187 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
188 // OS_EnableIrqMask selects IRQ interrupts to enable, and
189 // OS_EnableIrq enables IRQ interrupts.
190 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a VBlank interrupt.
191 //---------------------------------------------------------------------------
VBlankIntr(void)192 void VBlankIntr(void)
193 {
194     OS_SetIrqCheckFlag(OS_IE_V_BLANK); // checking VBlank interrupt
195 }
196