1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - demos - os - reset-1
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-26#$
14 $Rev: 8698 $
15 $Author: yada $
16 *---------------------------------------------------------------------------*/
17 #include <nitro.h>
18 #include <nitro/rtc.h>
19 #include "font.h"
20 #include "screen.h"
21
22 //---- For RTC
23 static RTCTime myCurrentTime;
24 static int myResult;
25
26 static void myInit(void);
27 static void myVBlankIntr(void);
28
29 /*---------------------------------------------------------------------------*
30 Name: NitroMain
31
32 Description: Main.
33
34 Arguments: None.
35
36 Returns: None.
37 *---------------------------------------------------------------------------*/
NitroMain(void)38 void NitroMain(void)
39 {
40 u32 param = OS_GetResetParameter();
41 u16 trigger;
42 u16 preButton = PAD_Read();
43 u16 button;
44
45 //---------------- Initialize
46 myInit();
47 RTC_Init();
48
49 //---------------- Main loop
50 while (TRUE)
51 {
52 button = PAD_Read();
53 trigger = (u16)((button ^ preButton) & button);
54 preButton = button;
55
56 //---- Clear screen buffer
57 ClearScreen();
58
59 //---- Display key description
60 PrintString(3, 2, 15, "test sample");
61 PrintString(3, 3, 15, "parameter is %d", param);
62 PrintString(3, 5, 15, "Push [A] or [B] to reset");
63 PrintString(3, 6, 15, "[A] to reset immediately");
64 PrintString(3, 7, 15, "[B] to clear screen and");
65 PrintString(3, 8, 15, " reset");
66
67 //---- Display time
68 myResult = RTC_GetTime(&myCurrentTime);
69 if (myResult == 0 /*No error */ )
70 {
71 PrintString(5, 20, 8, "%02d:%02d:%02d",
72 myCurrentTime.hour, myCurrentTime.minute, myCurrentTime.second);
73 }
74
75
76 //---- Display counter
77 PrintString(18, 20, 4, "%08X", OS_GetVBlankCount());
78
79
80 //---- Push A to reset (reset immediately)
81 if (trigger & PAD_BUTTON_A)
82 {
83 OS_ResetSystem(param + 1);
84 }
85
86 //---- Push B to reset (clear screen and reset)
87 if (trigger & PAD_BUTTON_B)
88 {
89 //---- Clear screen
90 OS_WaitVBlankIntr();
91 ClearScreen();
92 OS_WaitVBlankIntr();
93 OS_WaitVBlankIntr();
94 (void)PM_SetLCDPower(PM_LCD_POWER_OFF);
95
96 //---- Wait a moment
97 OS_Sleep(300);
98
99 OS_ResetSystem(param + 1);
100 }
101
102
103 OS_WaitVBlankIntr();
104 }
105 }
106
107 //----------------------------------------------------------------
108 // myInit
109 //
myInit(void)110 void myInit(void)
111 {
112 //---- Init
113 OS_Init();
114 OS_InitTick();
115 OS_InitAlarm();
116 FX_Init();
117 GX_Init();
118 GX_DispOff();
119 GXS_DispOff();
120
121 //---- Display init
122 GX_SetBankForLCDC(GX_VRAM_LCDC_ALL);
123 MI_CpuClearFast((void *)HW_LCDC_VRAM, HW_LCDC_VRAM_SIZE);
124 (void)GX_DisableBankForLCDC();
125
126 MI_CpuFillFast((void *)HW_OAM, 192, HW_OAM_SIZE);
127 MI_CpuClearFast((void *)HW_PLTT, HW_PLTT_SIZE);
128 MI_CpuFillFast((void *)HW_DB_OAM, 192, HW_DB_OAM_SIZE);
129 MI_CpuClearFast((void *)HW_DB_PLTT, HW_DB_PLTT_SIZE);
130
131 //---- Setting 2D for top screen
132 GX_SetBankForBG(GX_VRAM_BG_128_A);
133
134 G2_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256,
135 GX_BG_COLORMODE_16,
136 GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01);
137 G2_SetBG0Priority(0);
138 G2_BG0Mosaic(FALSE);
139 GX_SetGraphicsMode(GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BG0_AS_2D);
140 GX_SetVisiblePlane(GX_PLANEMASK_BG0);
141
142 GX_LoadBG0Char(d_CharData, 0, sizeof(d_CharData));
143 GX_LoadBGPltt(d_PaletteData, 0, sizeof(d_PaletteData));
144
145
146
147 //---- Setting 2D for bottom screen
148 GX_SetBankForSubBG(GX_VRAM_SUB_BG_128_C);
149
150 G2S_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256,
151 GX_BG_COLORMODE_16,
152 GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01);
153 G2S_SetBG0Priority(0);
154 G2S_BG0Mosaic(FALSE);
155 GXS_SetGraphicsMode(GX_BGMODE_0);
156 GXS_SetVisiblePlane(GX_PLANEMASK_BG0);
157
158 GXS_LoadBG0Char(d_CharData, 0, sizeof(d_CharData));
159 GXS_LoadBGPltt(d_PaletteData, 0, sizeof(d_PaletteData));
160
161
162 //---- Screen
163 MI_CpuFillFast((void *)gScreen, 0, sizeof(gScreen));
164 DC_FlushRange(gScreen, sizeof(gScreen));
165 /* I/O register is accessed using DMA operation, so cache wait is not needed */
166 // DC_WaitWriteBufferEmpty();
167 GX_LoadBG0Scr(gScreen, 0, sizeof(gScreen));
168 GXS_LoadBG0Scr(gScreen, 0, sizeof(gScreen));
169
170 //---- Init interrupt
171 OS_SetIrqFunction(OS_IE_V_BLANK, myVBlankIntr);
172 (void)OS_EnableIrqMask(OS_IE_V_BLANK);
173 (void)GX_VBlankIntr(TRUE);
174 (void)OS_EnableIrq();
175 (void)OS_EnableInterrupts();
176
177 //---- Start displaying
178 GX_DispOn();
179 GXS_DispOn();
180 }
181
182 //----------------------------------------------------------------
183 // myVBlankIntr
184 // V-Blank interrupt handler
185 //
myVBlankIntr(void)186 static void myVBlankIntr(void)
187 {
188 //---- Upload pseudo screen to VRAM
189 DC_FlushRange(gScreen, sizeof(gScreen));
190 /* I/O register is accessed using DMA operation, so cache wait is not needed */
191 // DC_WaitWriteBufferEmpty();
192 GX_LoadBG0Scr(gScreen, 0, sizeof(gScreen));
193 GXS_LoadBG0Scr(gScreen, 0, sizeof(gScreen));
194
195
196 OS_SetIrqCheckFlag(OS_IE_V_BLANK);
197 }
198