1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - build - demos - tips - DisplayLogo
3 File: main.c
4
5 Copyright 2009 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:: 2009-11-24#$
14 $Rev: 11184 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 //---------------------------------------------------------------------------
19 // This demo sample displays the Licensed by Nintendo logo.
20 // It fades in (0.27 sec), then displays the logo for 1 second, then fades out (0.27 sec).
21 //
22 // Press the A button during logo display to cancel the 1-second logo display and start the fade-out.
23 //
24 //---------------------------------------------------------------------------
25
26 #ifdef SDK_TWL
27 #include <twl.h>
28 #else
29 #include <nitro.h>
30 #endif
31 #include "data.h"
32
33 /* Constants */
34 #define SCREEN_SIZE 256 * 192 * 2 // Data size (in bytes)
35 #define DISP_FRAME_NUM 60 // Constant used in the timer that measures 1 second (60 frames)
36 #define BRIGHTNESS_MAX 16 // Maximum brightness. Used as the initial value
37
38 typedef enum
39 {
40 FADE_IN = 0,
41 DISPLAY = 1,
42 FADE_OUT = 2,
43 END = 3
44 }
45 DISP_STATE;
46
47 typedef struct
48 {
49 u16 trigger;
50 u16 press;
51 }
52 KeyWork;
53
54 /* Function Prototypes */
55 void Init(void); // General initialization
56 void VBlankIntr(void); // V-Blank interrupt definition
57 void ReadKey(KeyWork*);
58 void TwlMain(void);
59
60 /*---------------------------------------------------------------------------*
61 Name: Init
62
63 Description: Performs general initialization. Goes as far as loading the image data.
64
65 Arguments: None.
66
67 Returns: None.
68 *---------------------------------------------------------------------------*/
69
Init(void)70 void Init(void)
71 {
72 // Initialize each library
73 OS_Init();
74 FX_Init();
75
76 GX_Init();
77
78 GX_DispOff();
79 GXS_DispOff();
80
81 OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
82 (void)OS_EnableIrqMask(OS_IE_V_BLANK);
83 (void)OS_EnableIrq();
84
85 (void)GX_VBlankIntr(TRUE);
86
87 //VRAM initialization
88 GX_SetBankForLCDC(GX_VRAM_LCDC_ALL); //Assign all VRAM banks to LCDC
89 MI_CpuClearFast((void *)HW_LCDC_VRAM, HW_LCDC_VRAM_SIZE); //Zero-clear the memory
90 (void)GX_DisableBankForLCDC(); //Deallocate the VRAM banks
91
92
93 /* Initialize the upper screen (this screen displays the Licensed by Nintendo logo in this demo)*/
94
95 GX_SetBankForBG(GX_VRAM_BG_128_A); // VRAM-A for BG
96
97 GX_SetGraphicsMode(GX_DISPMODE_GRAPHICS, // Graphics mode
98 GX_BGMODE_0, // BGMODE is 0
99 GX_BG0_AS_2D); // BG #0 is for 2D
100
101 G2_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256, // 256pix x 256pix text
102 GX_BG_COLORMODE_16, // Logo can be expressed in 16 colors
103 GX_BG_SCRBASE_0x0000, // Screen base offset setting
104 GX_BG_CHARBASE_0x04000, // Character base offset setting
105 GX_BG_EXTPLTT_01 // When using the BG extended palette, use slot 0
106 );
107
108 GX_SetVisiblePlane(GX_PLANEMASK_BG0); // Select BG0 for display
109 G2_SetBG0Priority(0); // Set BG0 priority to top
110 G2_BG0Mosaic(FALSE); // Do not apply mosaic effects to BG0
111
112 GX_LoadBG0Char(data_Char, 0, sizeof(data_Char)); // Load logo images
113 GX_LoadBGPltt(data_Palette, 0, sizeof(data_Palette));
114 GX_LoadBG0Scr(data_Screen, 0, sizeof(data_Screen));
115
116 GX_SetMasterBrightness(BRIGHTNESS_MAX); // Fade in from a blank, white screen
117
118 /* Initialization of upper screen comes here and no further */
119
120 OS_WaitVBlankIntr();
121 GX_DispOn();
122
123 }
124
125 // V-Blank interrupt settings
VBlankIntr(void)126 void VBlankIntr(void)
127 {
128 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Set V-Blank interrupt confirmation flag
129 }
130
131 // Key reading settings
ReadKey(KeyWork * key)132 void ReadKey(KeyWork* key)
133 {
134 u16 readData = PAD_Read();
135 key->trigger = (u16)(readData & (readData ^ key->press));
136 key->press = readData;
137 }
138
139 /*---------------------------------------------------------------------------*
140 Name: Twl/NitroMain
141
142 Description: Main
143
144 Arguments: None.
145
146 Returns: None.
147 *---------------------------------------------------------------------------*/
148
149 #ifdef SDK_TWL
TwlMain(void)150 void TwlMain(void)
151 #else
152 void NitroMain(void)
153 #endif
154 {
155 KeyWork Key; // Variable for pressed buttons or keys
156 DISP_STATE State = FADE_IN; // Variable expressing state
157 int DispFrame = DISP_FRAME_NUM; // Variable to measure 1 second of display time
158 int Brightness = BRIGHTNESS_MAX; // Variable expressing brightness
159
160 Init(); // Initialization
161 OS_Printf("***********************************************\n");
162 OS_Printf("* Start Displaying the Logo. *\n"); // Display message
163 OS_Printf("* A BUTTON : Stop displaying the Logo. *\n");
164 OS_Printf("***********************************************\n");
165
166 while(1)
167 {
168 ReadKey(&Key); // Read keys
169 switch (State)
170 {
171 case FADE_IN:
172 if ( (Brightness = GX_GetMasterBrightness()) > 0) // Fade-in before display
173 {
174 GX_SetMasterBrightness( Brightness - 1);
175 }
176 else
177 {
178 State = DISPLAY;
179 }
180 break;
181 case DISPLAY: // Displaying. By default, display for 60 frames (1 second).
182 if ( DispFrame > 0 )
183 {
184 if ( Key.trigger & PAD_BUTTON_A ) // Press A Button to cancel (input of this button not accepted during fade-in or fade-out)
185 {
186 State = FADE_OUT;
187 }
188 else
189 {
190 DispFrame--;
191 }
192 }
193 else
194 {
195 State = FADE_OUT;
196 }
197 break;
198 case FADE_OUT: // Fade out when display ends. Also fade out if display is canceled by button input.
199 if ( (Brightness = GX_GetMasterBrightness()) < BRIGHTNESS_MAX )
200 {
201 GX_SetMasterBrightness( Brightness + 1);
202 }
203 else
204 {
205 State = END;
206 }
207 break;
208 case END:
209 break;
210 default:
211 break;
212 }
213
214 if ( State == END )
215 {
216 break;
217 }
218
219 OS_WaitVBlankIntr();
220 }
221
222 OS_Printf( "==== Finish sample ====\n" );
223 OS_Terminate();
224 }
225