1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/2D_CharBg_8
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-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 //---------------------------------------------------------------------------
19 // A sample that controls two built-in windows:
20 //
21 // USAGE:
22 // A + [UP, DOWN, LEFT, RIGHT]: Move the position of the window 1.
23 // B + [UP, DOWN, LEFT, RIGHT]: Move the position of the window 2.
24 // L + [UP, DOWN, LEFT, RIGHT]: Change the size of the window 1.
25 // R + [UP, DOWN, LEFT, RIGHT]: Change the size of the window 2.
26 //
27 // HOWTO:
28 // 1. Set windows visible by GX_SetVisibleWnd().
29 // 2. Specify planes inside a window by G2_SetWndxInsidePlane().
30 // 3. Specify planes outside windows by G2_SetWndOutsidePlane().
31 // 4. Set the size and the position of a window by G2_SetWnd0Position().
32 //---------------------------------------------------------------------------
33
34 #ifdef SDK_TWL
35 #include <twl.h>
36 #else
37 #include <nitro.h>
38 #endif
39 #include "DEMO.h"
40 #include "data.h"
41
42 #ifdef SDK_TWL
TwlMain(void)43 void TwlMain(void)
44 #else
45 void NitroMain(void)
46 #endif
47 {
48 int win1_x = 0, win2_x = 50, size1_x = 60, size2_x = 110;
49 int win1_y = 0, win2_y = 50, size1_y = 60, size2_y = 110;
50
51 //---------------------------------------------------------------------------
52 // Initialization:
53 // They enable IRQ interrupts, initialize VRAM, and set BG #0 for text mode.
54 //---------------------------------------------------------------------------
55 DEMOInitCommon();
56 DEMOInitVRAM();
57 DEMOInitDisplayBG0Only();
58
59 //---------------------------------------------------------------------------
60 // Transmitting the character data and the palette data
61 //---------------------------------------------------------------------------
62 GX_LoadBG0Char(d_natsunoumi_schDT, 0, sizeof(d_natsunoumi_schDT));
63 GX_LoadBGPltt(d_natsunoumi_sclDT, 0, sizeof(d_natsunoumi_sclDT));
64 GX_LoadBG0Scr(d_natsunoumi_sscDT, 0, sizeof(d_natsunoumi_sscDT));
65
66 GX_SetVisibleWnd(GX_WNDMASK_W0 | GX_WNDMASK_W1); // makes window #0 and window #1 visible
67
68 //---------------------------------------------------------------------------
69 // Setting the visible plane inside each window
70 //---------------------------------------------------------------------------
71 G2_SetWnd0InsidePlane(GX_WND_PLANEMASK_BG0, // BG #0 is visible inside window #0
72 FALSE // you can limit the zone of alpha blending applied if TRUE
73 );
74
75 G2_SetWnd1InsidePlane(GX_WND_PLANEMASK_BG0, // BG #0 is visible inside window #1
76 FALSE // you can limit the zone of alpha blending applied if TRUE
77 );
78
79 //---------------------------------------------------------------------------
80 // Setting the visible plane outside the windows
81 //---------------------------------------------------------------------------
82 G2_SetWndOutsidePlane(GX_WND_PLANEMASK_NONE, FALSE); // not visible
83
84 DEMOStartDisplay();
85 //---------------------------------------------------------------------------
86 // Main Loop
87 //---------------------------------------------------------------------------
88 while (1)
89 {
90 DEMOReadKey();
91
92 if (DEMO_IS_PRESS(PAD_BUTTON_A))
93 {
94 if (DEMO_IS_PRESS(PAD_KEY_UP))
95 win1_y--;
96 if (DEMO_IS_PRESS(PAD_KEY_DOWN))
97 win1_y++;
98 if (DEMO_IS_PRESS(PAD_KEY_RIGHT))
99 win1_x++;
100 if (DEMO_IS_PRESS(PAD_KEY_LEFT))
101 win1_x--;
102 }
103 else if (DEMO_IS_PRESS(PAD_BUTTON_B))
104 {
105 if (DEMO_IS_PRESS(PAD_KEY_UP))
106 win2_y--;
107 if (DEMO_IS_PRESS(PAD_KEY_DOWN))
108 win2_y++;
109 if (DEMO_IS_PRESS(PAD_KEY_RIGHT))
110 win2_x++;
111 if (DEMO_IS_PRESS(PAD_KEY_LEFT))
112 win2_x--;
113 }
114 else if (DEMO_IS_PRESS(PAD_BUTTON_L))
115 {
116 if (DEMO_IS_PRESS(PAD_KEY_UP))
117 size1_y--;
118 if (DEMO_IS_PRESS(PAD_KEY_DOWN))
119 size1_y++;
120 if (DEMO_IS_PRESS(PAD_KEY_RIGHT))
121 size1_x++;
122 if (DEMO_IS_PRESS(PAD_KEY_LEFT))
123 size1_x--;
124 }
125 else if (DEMO_IS_PRESS(PAD_BUTTON_R))
126 {
127 if (DEMO_IS_PRESS(PAD_KEY_UP))
128 size2_y--;
129 if (DEMO_IS_PRESS(PAD_KEY_DOWN))
130 size2_y++;
131 if (DEMO_IS_PRESS(PAD_KEY_RIGHT))
132 size2_x++;
133 if (DEMO_IS_PRESS(PAD_KEY_LEFT))
134 size2_x--;
135 }
136
137 if (size1_y > 192)
138 size1_y = 192;
139 if (size1_x > 255)
140 size1_x = 255;
141 if (size1_y < 0)
142 size1_y = 0;
143 if (size1_x < 0)
144 size1_x = 0;
145 if (size2_y > 192)
146 size2_y = 192;
147 if (size2_x > 255)
148 size2_x = 255;
149 if (size2_y < 0)
150 size2_y = 0;
151 if (size2_x < 0)
152 size2_x = 0;
153
154 if (win1_y < 0)
155 win1_y = 0;
156 if (win1_y + size1_y > 192)
157 win1_y = 192 - size1_y;
158 if (win2_y < 0)
159 win2_y = 0;
160 if (win2_y + size2_y > 192)
161 win2_y = 192 - size2_y;
162
163
164 #ifdef SDK_AUTOTEST
165 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
166 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
167 EXT_TestScreenShot(100, 0x61C32E25);
168 EXT_TestTickCounter();
169 #endif //SDK_AUTOTEST
170
171 OS_WaitVBlankIntr(); // Waiting the end of VBlank interrupt
172
173 //---------------------------------------------------------------------------
174 // Specifying the position of the window #0
175 //---------------------------------------------------------------------------
176 G2_SetWnd0Position(win1_x, win1_y, // the upper left
177 win1_x + size1_x, win1_y + size1_y // the lower right
178 );
179
180 //---------------------------------------------------------------------------
181 // Specifying the position of the window #1
182 //---------------------------------------------------------------------------
183 G2_SetWnd1Position(win2_x, win2_y, // the upper left
184 win2_x + size2_x, win2_y + size2_y // the lower right
185 );
186 }
187 }
188
189 //---------------------------------------------------------------------------
190 // VBlank interrupt function:
191 //
192 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
193 // OS_EnableIrqMask selects IRQ interrupts to enable, and
194 // OS_EnableIrq enables IRQ interrupts.
195 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a VBlank interrupt.
196 //---------------------------------------------------------------------------
VBlankIntr(void)197 void VBlankIntr(void)
198 {
199 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // checking VBlank interrupt
200 }
201