1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/Sub_CharBg_7
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 blends two text BG planes
20 //
21 // USAGE:
22 // UP, DOWN, LEFT, RIGHT: Controls blending coefficients
23 //
24 // HOWTO:
25 // 1. Set up the character/palette/screen data the same as Sub_CharBg_1
26 // 2. Specify the planes blended and blend ratio with G2S_SetBlendAlpha
27 // 3. You can also control the blend ratio with G2S_ChangeBlendAlpha
28 //---------------------------------------------------------------------------
29
30 #ifdef SDK_TWL
31 #include <twl.h>
32 #else
33 #include <nitro.h>
34 #endif
35 #include "DEMO.h"
36 #include "data.h"
37
38 static u16 sScrnBuf1[SCREEN_SIZE]; // Buffer for screen data (BG #0)
39 static u16 sScrnBuf2[SCREEN_SIZE]; // Buffer for screen data (BG #1)
40
41 #ifdef SDK_TWL
TwlMain(void)42 void TwlMain(void)
43 #else
44 void NitroMain(void)
45 #endif
46 {
47
48 int eva = 0, evb = 0;
49
50 //---------------------------------------------------------------------------
51 // Initialize:
52 // Enables IRQ interrupts, initializes VRAM, and sets BG #0 for text mode
53 //---------------------------------------------------------------------------
54 DEMOInitCommon();
55 DEMOInitVRAM();
56 DEMOInitDisplaySubBG0Only();
57
58 //---------------------------------------------------------------------------
59 // Setting up BG #0 controls
60 //---------------------------------------------------------------------------
61 G2S_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256,
62 GX_BG_COLORMODE_256,
63 GX_BG_SCRBASE_0x0000, GX_BG_CHARBASE_0x04000, GX_BG_EXTPLTT_01);
64 G2S_SetBG0Priority(0);
65 G2S_BG0Mosaic(FALSE);
66
67 //---------------------------------------------------------------------------
68 // Setting up BG #1 controls
69 //---------------------------------------------------------------------------
70 G2S_SetBG1Control(GX_BG_SCRSIZE_TEXT_256x256,
71 GX_BG_COLORMODE_256,
72 GX_BG_SCRBASE_0x0800, GX_BG_CHARBASE_0x0c000, GX_BG_EXTPLTT_01);
73
74 G2S_SetBG1Priority(1);
75 G2S_BG1Mosaic(FALSE);
76
77 //---------------------------------------------------------------------------
78 // Transmitting the character data and the palette data
79 //---------------------------------------------------------------------------
80 GXS_LoadBG0Char(d_al_1_schDT, 0, sizeof(d_al_1_schDT));
81 GXS_LoadBG1Char(d_al_2_schDT, 0, sizeof(d_al_2_schDT));
82 GXS_LoadBGPltt(d_al_1_sclDT, 0, sizeof(d_al_1_sclDT));
83
84 GXS_SetVisiblePlane(GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1); // Displays BG #0 and BG #1
85
86 {
87 int i, j;
88
89 for (i = 0; i < 18; i++)
90 {
91 for (j = 0; j < 12; j++)
92 {
93 sScrnBuf1[((i + 3) * 32) + (j + 11)] = (u16)((i * 0x10) + j);
94 }
95 }
96 // Store the data in main memory, and invalidate the cache
97 DC_FlushRange(sScrnBuf1, sizeof(sScrnBuf1));
98
99 MI_CpuFill16(sScrnBuf2, 0xffff, SCREEN_SIZE * sizeof(u16));
100
101 for (i = 0; i < 13; i++)
102 {
103 for (j = 0; j < 16; j++)
104 {
105 sScrnBuf2[((i + 6) * 32) + (j + 9)] = (u16)((i * 0x10) + j);
106 }
107 }
108 // Store the data in main memory, and invalidate the cache
109 DC_FlushRange(sScrnBuf2, sizeof(sScrnBuf2));
110 }
111
112 // DMA Transfer to BG0 and BG1 screen
113 /* I/O register is accessed using DMA operation, so cache wait is not needed */
114 // DC_WaitWriteBufferEmpty();
115 GXS_LoadBG0Scr(sScrnBuf1, 0, sizeof(sScrnBuf1));
116 GXS_LoadBG1Scr(sScrnBuf2, 0, sizeof(sScrnBuf2));
117
118 //---------------------------------------------------------------------------
119 // Setting up alpha blending
120 //
121 // The first plane is BG #0 and the second one is BG #1.
122 // Alpha blending occurs if and only if BG #1 is just behind BG #0.
123 //---------------------------------------------------------------------------
124 G2S_SetBlendAlpha(GX_BLEND_PLANEMASK_BG0, // Specifies only BG #0
125 GX_BLEND_PLANEMASK_BG1, // Specifies only BG #1
126 0, // eva
127 0 // evb
128 );
129
130 DEMOStartDisplay();
131 //---------------------------------------------------------------------------
132 // Main Loop
133 //---------------------------------------------------------------------------
134 while (1)
135 {
136 DEMOReadKey();
137
138 if (DEMO_IS_PRESS(PAD_KEY_UP))
139 eva++;
140 if (DEMO_IS_PRESS(PAD_KEY_DOWN))
141 eva--;
142 if (DEMO_IS_PRESS(PAD_KEY_RIGHT))
143 evb++;
144 if (DEMO_IS_PRESS(PAD_KEY_LEFT))
145 evb--;
146 if (eva < 0x00)
147 eva = 0x00;
148 if (eva > 0x10)
149 eva = 0x10;
150 if (evb < 0x00)
151 evb = 0x00;
152 if (evb > 0x10)
153 evb = 0x10;
154
155 OS_WaitVBlankIntr(); // Waiting for the end of the V-Blank interrupt
156
157 //---------------------------------------------------------------------------
158 // Change the coefficients for alpha blending
159 //---------------------------------------------------------------------------
160 G2S_ChangeBlendAlpha(eva, evb);
161 }
162
163 }
164
165 //---------------------------------------------------------------------------
166 // V-Blank interrupt function:
167 //
168 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
169 // OS_EnableIrqMask selects IRQ interrupts to enable, and
170 // OS_EnableIrq enables IRQ interrupts.
171 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt
172 //---------------------------------------------------------------------------
VBlankIntr(void)173 void VBlankIntr(void)
174 {
175 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
176 }
177