1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: erreula_demo.cpp
4
5 Copyright (C)2009-2012 Nintendo Co., Ltd. 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 $Rev: 47394 $
14 *---------------------------------------------------------------------------*/
15
16 #include <nn.h>
17 #include <nn/cfg.h>
18
19 #include <nn/erreula.h>
20
21 #include "demo.h"
22
23
24
25 //----------------------------------------------------------------
26
27 namespace
28 {
29 demo::RenderSystemDrawing df;
30
31 s32 loopCnt = 0;
32
SetupRenderSystem()33 void SetupRenderSystem()
34 {
35 demo::RenderBufferDescription colorBufferDesc;
36 {
37 colorBufferDesc.m_Format = GL_RGBA8_OES;
38 colorBufferDesc.m_Width = nn::gx::DISPLAY0_WIDTH;
39 colorBufferDesc.m_Height = nn::gx::DISPLAY0_HEIGHT;
40 colorBufferDesc.m_Area = NN_GX_MEM_VRAMA;
41 colorBufferDesc.m_Attachment = GL_COLOR_ATTACHMENT0;
42 }
43 demo::RenderBufferDescription depthStencilBufferDesc;
44 {
45 depthStencilBufferDesc.m_Format = GL_DEPTH24_STENCIL8_EXT;
46 depthStencilBufferDesc.m_Width = nn::gx::DISPLAY0_WIDTH;
47 depthStencilBufferDesc.m_Height = nn::gx::DISPLAY0_HEIGHT;
48 depthStencilBufferDesc.m_Area = NN_GX_MEM_VRAMB;
49 depthStencilBufferDesc.m_Attachment = GL_DEPTH_STENCIL_ATTACHMENT;
50 }
51
52 demo::FrameBufferDescription frameBufferDesc;
53 {
54 frameBufferDesc.m_RenderBufferDescriptionArray[demo::DEMO_COLOR_BUFFER_INDEX] = colorBufferDesc;
55 frameBufferDesc.m_RenderBufferDescriptionArray[demo::DEMO_DEPTH_STENCIL_BUFFER_INDEX] = depthStencilBufferDesc;
56 }
57
58 demo::DisplayBuffersDescription display0BuffersDesc;
59 {
60 display0BuffersDesc.m_TargetDisplay = NN_GX_DISPLAY0;
61 display0BuffersDesc.m_DisplayBufferNum = demo::DEMO_DISPLAY_BUFFER_NUM;
62 display0BuffersDesc.m_Format = GL_RGB8_OES;
63 display0BuffersDesc.m_Width = nn::gx::DISPLAY0_WIDTH;
64 display0BuffersDesc.m_Height = nn::gx::DISPLAY0_HEIGHT;
65 display0BuffersDesc.m_Area = NN_GX_MEM_FCRAM;
66 // display0BuffersDesc.m_Area = NN_GX_MEM_VRAMA;
67 }
68
69 demo::DisplayBuffersDescription display1BuffersDesc;
70 {
71 display1BuffersDesc.m_TargetDisplay = NN_GX_DISPLAY1;
72 display1BuffersDesc.m_DisplayBufferNum = demo::DEMO_DISPLAY_BUFFER_NUM;
73 display1BuffersDesc.m_Format = GL_RGB8_OES;
74 display1BuffersDesc.m_Width = nn::gx::DISPLAY1_WIDTH;
75 display1BuffersDesc.m_Height = nn::gx::DISPLAY1_HEIGHT;
76 display1BuffersDesc.m_Area = NN_GX_MEM_FCRAM;
77 // display1BuffersDesc.m_Area = NN_GX_MEM_VRAMB;
78 }
79
80 df.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize(),
81 0x40000, 128, true,
82 display0BuffersDesc, display1BuffersDesc,
83 frameBufferDesc
84 );
85 }
86
ReleaseRenderSystem()87 void ReleaseRenderSystem()
88 {
89 df.Finalize();
90 }
91
DrawText()92 void DrawText()
93 {
94 // display 0
95 df.SetRenderTarget(NN_GX_DISPLAY0);
96 df.Clear();
97 {
98 df.SetColor(0.0f, 0.0f, 0.5f);
99 df.FillRectangle( 0, 0, 399, 255 );
100 df.SetColor(0.5f, 0.4f, 0.0f);
101 df.FillRectangle( 0, 0, 399, 40 );
102 df.SetColor(0.5f, 0.0f, 0.4f);
103 df.FillRectangle( 0, 180, 399, 40 );
104 df.SetColor(1.0f, 1.0f, 1.0f);
105 df.DrawText( 100, 50, "** DEMO APPLICATION **" );
106
107 df.SetColor(1.0f, 1.0f, 1.0f);
108 df.DrawText( 30, 80, "[A] error applet." );
109 df.DrawText( 30, 100, "[B] EULA applet." );
110
111 // Show EULA agreement status
112 df.DrawText( 54, 150, "is agreed EULA : %d", nn::cfg::IsAgreedEula() );
113 // Display the current country setting. If this is 0 (undefined) or the country has no EULA, then the EULA will not be displayed.
114 df.DrawText( 54, 160, "country : %d", nn::cfg::GetCountry() );
115
116 // Count
117 df.DrawText( 340, 50, "%d", loopCnt );
118 df.DrawText( 340, 82, "%d", nngxCheckVSync(NN_GX_DISPLAY0) );
119 }
120 df.SwapBuffers();
121
122 // display 1
123 df.SetRenderTarget(NN_GX_DISPLAY1);
124 df.Clear();
125 {
126 df.SetColor(0.0f, 0.5f, 0.0f);
127 df.FillRectangle( 0, 0, 399, 255 );
128 df.SetColor(1.0f, 1.0f, 1.0f);
129 df.DrawText( 80, 50, "** DEMO APPLICATION **" );
130 }
131 df.SwapBuffers();
132 }
DrawDisplay()133 void DrawDisplay()
134 {
135 DrawText();
136 }
137
RestoreGraphics()138 void RestoreGraphics()
139 {
140 // Recover the GPU register settings
141 nngxUpdateState(NN_GX_STATE_ALL);
142 nngxValidateState(NN_GX_STATE_ALL,GL_TRUE);
143 }
144 }
145
146 //----------------------------------------------------------------
myReceiveSleepQueryNotification(uptr arg)147 AppletQueryReply myReceiveSleepQueryNotification( uptr arg )
148 {
149 NN_UNUSED_VAR( arg );
150 NN_LOG("*** Application sleepQuery \n");
151 return /*applet::IsActive()? applet::REPLY_LATER:*/ nn::applet::REPLY_ACCEPT;
152 }
153
154 //----------------------------------------------------------------
myReceiveAwakeNotification(uptr arg)155 void myReceiveAwakeNotification( uptr arg )
156 {
157 NN_UNUSED_VAR( arg );
158 NN_LOG("*** Application awake \n");
159 if ( nn::applet::IsActive() )
160 {
161 nngxStartLcdDisplay();
162 }
163 }
164
165 //----------------------------------------------------------------
nnMain()166 extern "C" void nnMain()
167 {
168 NN_TLOG_("----Application start\n");
169
170 nn::Result result;
171
172 // applet declarations
173 nn::applet::SetSleepQueryCallback( myReceiveSleepQueryNotification, 0 );
174 nn::applet::SetAwakeCallback( myReceiveAwakeNotification, 0 );
175 nn::applet::Enable();
176 if(nn::applet::IsExpectedToCloseApplication())
177 {
178 // Quickly end the application
179 nn::applet::PrepareToCloseApplication();
180 nn::applet::CloseApplication();
181
182 // Never reached
183 return;
184 }
185
186 // hid
187 result = nn::hid::Initialize();
188 NN_UTIL_PANIC_IF_FAILED(result);
189
190 // fs
191 nn::fs::Initialize();
192
193 // cfg
194 nn::cfg::Initialize();
195
196 // Render class initialization
197 SetupRenderSystem();
198
199 nn::hid::PadReader padReader;
200 nn::hid::PadStatus ps;
201
202
203 while(1)
204 {
205 loopCnt++;
206
207 padReader.ReadLatest(&ps);
208
209 // Render
210 DrawDisplay();
211
212 // Start library applet with A button (show error)
213 if ( ps.trigger & nn::hid::BUTTON_A )
214 {
215 nn::applet::AppletWakeupState wstate;
216 nn::erreula::Parameter ere_param; // Error EULA settings struct
217
218 // Initialize settings struct
219 nn::erreula::InitializeConfig( &ere_param.config );
220
221 ere_param.config.errorType = nn::erreula::ERROR_TYPE_ERROR_CODE;
222 ere_param.config.errorCode = 32000;
223 ere_param.config.upperScreenFlag = nn::erreula::UPPER_SCREEN_NORMAL;
224 ere_param.config.homeButton = true;
225 ere_param.config.softwareReset = false;
226 ere_param.config.appJump = false;
227
228 nn::erreula::StartErrEulaApplet( &wstate, &ere_param );
229
230 if(nn::applet::IsExpectedToCloseApplication())
231 {
232 break;
233 }
234
235 // Recover the GPU register settings
236 RestoreGraphics();
237
238 NN_LOG( "Return Code : %d\n", ere_param.config.returnCode );
239 }
240 // Start library applet with B button (show EULA)
241 if ( ps.trigger & nn::hid::BUTTON_B )
242 {
243 nn::applet::AppletWakeupState wstate;
244 nn::erreula::Parameter ere_param; // Error EULA settings struct
245
246 // Initialize settings struct
247 nn::erreula::InitializeConfig( &ere_param.config );
248
249 ere_param.config.errorType = nn::erreula::ERROR_TYPE_EULA;
250 ere_param.config.upperScreenFlag = nn::erreula::UPPER_SCREEN_NORMAL;
251 ere_param.config.homeButton = true;
252 ere_param.config.softwareReset = false;
253 ere_param.config.appJump = false;
254
255 nn::erreula::StartErrEulaApplet( &wstate, &ere_param );
256
257 if(nn::applet::IsExpectedToCloseApplication())
258 {
259 break;
260 }
261
262 // Recover the GPU register settings
263 RestoreGraphics();
264
265 NN_LOG( "Return Code : %d, Eula Version : %d\n",
266 ere_param.config.returnCode, ere_param.config.eulaVersion );
267 }
268
269 // Handle HOME Button on ErrEula
270 if ( nn::applet::IsExpectedToProcessHomeButton() )
271 {
272 NN_LOG("ErrEula HomeBtn.\n");
273 nn::applet::ProcessHomeButtonAndWait();
274
275 if(nn::applet::IsExpectedToCloseApplication())
276 {
277 break;
278 }
279
280 RestoreGraphics();
281
282 }
283
284 // Handle POWER Button on ErrEula
285 if (nn::applet::IsExpectedToProcessPowerButton() )
286 {
287 NN_LOG("ErrEula PowerBtn.\n");
288 nn::applet::ProcessPowerButtonAndWait();
289
290 if(nn::applet::IsExpectedToCloseApplication())
291 {
292 break;
293 }
294
295 RestoreGraphics();
296
297 }
298 }
299
300
301 NN_TLOG_("----Application is to be end\n");
302
303 // Free the render class
304 ReleaseRenderSystem();
305
306 // Finalize cfg
307 nn::cfg::Finalize();
308
309 // Finalize hid
310 nn::hid::Finalize();
311
312 // Exit application
313 nn::applet::PrepareToCloseApplication();
314 nn::applet::CloseApplication();
315
316 // No need to call Finalize on applet
317 // Execution will probably not reach here.
318 NN_TLOG_("----Application end\n");
319 }
320