/*---------------------------------------------------------------------------* Project: Horizon File: demo1.cpp Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 47228 $ *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include #include "device.h" #include "gx.h" #include "rtc.h" #include "pad.h" #include "tp.h" #include "acc.h" #include "mic.h" #include "snd.h" #include "camera.h" #include "fs.h" #include "savedata.h" #include "kbd.h" #include "applet.h" #include "demo.h" bool StartDemo() { // Description of Operations NN_LOG("X + A : Run Optional Device Demo (Ex. Card Backup Device..)\n"); NN_LOG("R + A : Run Software Keyboard Applet \n"); // ####################################################################################################### // Application initialization sequence // ####################################################################################################### const u32 s_GxHeapSize = 0x800000; // fs initialization nn::fs::Initialize(); const size_t ROMFS_BUFFER_SIZE = 1024 * 64; static char buffer[ROMFS_BUFFER_SIZE]; NN_UTIL_PANIC_IF_FAILED( nn::fs::MountRom(16, 16, buffer, ROMFS_BUFFER_SIZE)); // Initialize hid nn::hid::Initialize(); // Allocate heap nn::fnd::ExpHeap appHeap; appHeap.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize() ); // Prepare RenderSystem uptr heapForGx = reinterpret_cast(appHeap.Allocate(s_GxHeapSize)); demo::RenderSystemDrawing s_RenderSystem; s_RenderSystem.Initialize(heapForGx, s_GxHeapSize); // Graphics demo initialization GraphicsDemo graphicsDemo; graphicsDemo.Initialize(&s_RenderSystem); // Camera demo initialization CameraDemo cameraDemo; cameraDemo.Initialize(&s_RenderSystem, &appHeap); // System clock demo initialization RtcDemo rtcDemo; rtcDemo.Initialize(&s_RenderSystem); // Pad demo initialization PadDemo padDemo; padDemo.Initialize(&s_RenderSystem); // Touch panel demo initialization TouchPanelDemo touchPanelDemo; touchPanelDemo.Initialize(&s_RenderSystem); // Accelerometer demo initialization AccDemo accDemo; accDemo.Initialize(&s_RenderSystem); // Mic demo initialization MicDemo micDemo; micDemo.Initialize(&s_RenderSystem); // Sound demo initialization SndDemo sndDemo; sndDemo.Initialize(&s_RenderSystem, &appHeap); // File system demo initialization FsDemo fsDemo; fsDemo.Initialize(&s_RenderSystem, &appHeap); // Software keyboard demo initialization SwkbdDemo kbdDemo; kbdDemo.Initialize(&s_RenderSystem); // Save data SaveDataDemo saveDataDemo; // Device list Device* deviceList[] = { &graphicsDemo, &cameraDemo, &rtcDemo, &padDemo, &touchPanelDemo, &accDemo, &micDemo, &sndDemo, &fsDemo, &kbdDemo }; int deviceNum = sizeof(deviceList) / sizeof(Device*); Device* optionalDeviceList[] = { &saveDataDemo }; int optionalDeviceNum = sizeof(optionalDeviceList) / sizeof(Device*); bool isOptionalDeviceTest = false; // Start each device for(int i = 0; i < deviceNum; i++) { deviceList[i]->Start(); } // After this, the application itself handles sleep TransitionHandler::EnableSleep(); bool restartFlag = false; // ####################################################################################################### // Main loop // ####################################################################################################### while(1) { s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0); s_RenderSystem.Clear(); deviceList[0]->Draw(); s_RenderSystem.SwapBuffers(); s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1); s_RenderSystem.Clear(); for(int i = 1; i < deviceNum; i++) { deviceList[i]->Draw(); } s_RenderSystem.SwapBuffers(); // Restart if START + L + R are pressed if ( padDemo.GetLatestPadStatus().hold == (nn::hid::BUTTON_START | nn::hid::BUTTON_L | nn::hid::BUTTON_R) ) { restartFlag = true; break; } if(padDemo.GetLatestPadStatus().hold == (nn::hid::BUTTON_X | nn::hid::BUTTON_A) && !isOptionalDeviceTest) { //Additional device demo initialization saveDataDemo.Initialize(&s_RenderSystem, &appHeap); for(int i = 0; i < optionalDeviceNum; i++) { optionalDeviceList[i]->Start(); } isOptionalDeviceTest = true; NN_LOG("Run Optional Device Demo.\n"); } if(padDemo.GetLatestPadStatus().hold == (nn::hid::BUTTON_R | nn::hid::BUTTON_A)) { // Start the software keyboard if( kbdDemo.Exec() ) { break; } } for(int i = 0; i < optionalDeviceNum&&isOptionalDeviceTest; i++) { optionalDeviceList[i]->Draw(); } s_RenderSystem.WaitVsync(NN_GX_DISPLAY_BOTH); // Run sleep, HOME Menu, and POWER Menu transitions. TransitionHandler::Process(); // Determine whether there has been an exit notification. if (TransitionHandler::IsExitRequired()) { break; } } // ####################################################################################################### // Application termination processing // ####################################################################################################### // If nn::applet::IsExpectedToCloseApplication() == true, then sleep-related callbacks are not called automatically. // //Stop and terminate added devices if( isOptionalDeviceTest == true ) { for(int i = 0; i < optionalDeviceNum; i++) { optionalDeviceList[i]->End(); optionalDeviceList[i]->Finalize(); } } // Stop each device for(int i = 0; i < deviceNum; i++) { deviceList[i]->End(); } // Terminate each device for(int i = 0; i < deviceNum; i++) { deviceList[i]->Finalize(); } // Exit RenderSystem s_RenderSystem.Finalize(); // Destroy heap appHeap.Free(reinterpret_cast(heapForGx)); appHeap.Finalize(); return restartFlag; } void nnMain() { NN_LOG("Demo1 Start\n"); bool restartFlag = false; u8 restartCount = 0; // Initialize via the applet. // Sleep Mode is rejected automatically until TransitionHandler::EnableSleep is called. TransitionHandler::Initialize(); // Receive values passed with RestartApplication { u8 dBuf[ NN_APPLET_PARAM_BUF_SIZE ]; bool r = nn::applet::GetStartupArgument( dBuf ); if ( r ) { if (dBuf[NN_APPLET_PARAM_BUF_SIZE - 1] == 0xFF) { NN_LOG("----demo1 received StartupArgument.\n"); NN_LOG(" jump count = %d\n", dBuf[0] ); restartCount = dBuf[0]; } } else { NN_LOG("----demo1 cannot receive startupArgument.\n"); } } // Here we need to check for exit notifications. if (!TransitionHandler::IsExitRequired()) { restartFlag = StartDemo(); } // Finalize via the applet. TransitionHandler::Finalize(); NN_LOG("Demo1 End\n"); // Performs application restart or finalization. if ( restartFlag ) { u8 startupArgBuf[NN_APPLET_PARAM_BUF_SIZE]; startupArgBuf[0] = restartCount + 1; startupArgBuf[NN_APPLET_PARAM_BUF_SIZE - 1] = 0xFF; // Restarts the application. The call to nn::applet::RestartApplication does not return. nn::applet::RestartApplication(startupArgBuf); } else { // Finalize the application. The call to nn::applet::CloseApplication does not return. nn::applet::CloseApplication(); } } /*---------------------------------------------------------------------------* End of file *---------------------------------------------------------------------------*/