1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/Sub_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 GXS_SetVisibleWnd().
29 // 2. Specify planes inside a window by G2S_SetWndxInsidePlane().
30 // 3. Specify planes outside windows by G2S_SetWndOutsidePlane().
31 // 4. Set the size and the position of a window by G2S_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 DEMOInitDisplaySubBG0Only();
58
59 //---------------------------------------------------------------------------
60 // Transmitting the character data and the palette data
61 //---------------------------------------------------------------------------
62 GXS_LoadBG0Char(d_natsunoumi_schDT, 0, sizeof(d_natsunoumi_schDT));
63 GXS_LoadBGPltt(d_natsunoumi_sclDT, 0, sizeof(d_natsunoumi_sclDT));
64 GXS_LoadBG0Scr(d_natsunoumi_sscDT, 0, sizeof(d_natsunoumi_sscDT));
65
66 GXS_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 G2S_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 G2S_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 G2S_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) && win1_y > 0)
95 win1_y--;
96 if (DEMO_IS_PRESS(PAD_KEY_DOWN) && win1_y + size1_y < 192)
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) && win2_y > 0)
106 win2_y--;
107 if (DEMO_IS_PRESS(PAD_KEY_DOWN) && win2_y + size2_y < 192)
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) && size1_y > 0)
117 size1_y--;
118 if (DEMO_IS_PRESS(PAD_KEY_DOWN) && size1_y + win1_y < 192)
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) && size2_y > 0)
128 size2_y--;
129 if (DEMO_IS_PRESS(PAD_KEY_DOWN) && size2_y + win2_y < 192)
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 OS_WaitVBlankIntr(); // Waiting the end of VBlank interrupt
138
139 //---------------------------------------------------------------------------
140 // Specifying the position of the window #0
141 //---------------------------------------------------------------------------
142 G2S_SetWnd0Position(win1_x, win1_y, // the upper left
143 win1_x + size1_x, win1_y + size1_y // the lower right
144 );
145
146 //---------------------------------------------------------------------------
147 // Specifying the position of the window #1
148 //---------------------------------------------------------------------------
149 G2S_SetWnd1Position(win2_x, win2_y, // the upper left
150 win2_x + size2_x, win2_y + size2_y // the lower right
151 );
152 }
153 }
154
155 //---------------------------------------------------------------------------
156 // VBlank interrupt function:
157 //
158 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
159 // OS_EnableIrqMask selects IRQ interrupts to enable, and
160 // OS_EnableIrq enables IRQ interrupts.
161 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a VBlank interrupt.
162 //---------------------------------------------------------------------------
VBlankIntr(void)163 void VBlankIntr(void)
164 {
165 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // checking VBlank interrupt
166 }
167