/*---------------------------------------------------------------------------* Project: Horizon File: main.cpp Copyright 2011 Nintendo. 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$ *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include "demo.h" #define HANDLE_ERROR(result) \ if(result.IsFailure()) \ { \ DrawError(result); \ } \ namespace { demo::RenderSystemDrawing s_RenderSystem; } extern "C" void nninitSetupDaemons(void) { } void DrawError(nn::Result result) { s_RenderSystem.SetClearColor(NN_GX_DISPLAY_BOTH, 1, 0, 0, 1); s_RenderSystem.SetColor(1, 1, 1); for(;;) { s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0); s_RenderSystem.Clear(); s_RenderSystem.DrawText(0, 0, "Error: %08X", result.GetPrintableBits()); s_RenderSystem.SwapBuffers(); s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1); s_RenderSystem.Clear(); s_RenderSystem.SwapBuffers(); s_RenderSystem.WaitVsync(NN_GX_DISPLAY_BOTH); } } extern "C" void nnMain() { nn::Result result; nn::applet::Enable(); nn::cfg::CTR::init::Initialize(); // RenderSystem の準備 nn::fnd::ExpHeap appHeap; appHeap.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize()); const size_t s_GxHeapSize = 8 * 1024 * 1024; void* heapForGx = appHeap.Allocate(s_GxHeapSize); s_RenderSystem.Initialize(reinterpret_cast(heapForGx), s_GxHeapSize); s_RenderSystem.SetClearColor(NN_GX_DISPLAY_BOTH, 0, 1, 0, 1); result = nn::ns::InitializeForShell(); HANDLE_ERROR(result); nn::cfg::detail::FirstLaunchInfoCfgData firstLaunch; firstLaunch.mmen = 1; firstLaunch.internet = 0; firstLaunch.rsv = 0; result = nn::cfg::CTR::init::SetConfig( GET_CFG_KEY(nn::cfg::CTR::detail::NN_CFG_MENU, nn::cfg::CTR::detail::NN_CFG_MENU_FIRST_LAUNCH), &firstLaunch, sizeof(firstLaunch)); HANDLE_ERROR(result); result = nn::cfg::CTR::init::FlushConfig(); HANDLE_ERROR(result); nn::cfg::CTR::init::Finalize(); for(;;) { // 電源ボタン短押しでシステムにシャットダウン通知を投げる if( nn::applet::IsExpectedToProcessPowerButton()) { result = nn::ns::ShutdownAsync(); HANDLE_ERROR(result); } // シャットダウンが始まったらアプリを終了させる if ( nn::applet::IsExpectedToCloseApplication()) { NN_LOG("Close Application\n"); result = nn::ns::FinalizeForShell(); HANDLE_ERROR(result); s_RenderSystem.Finalize(); appHeap.Free(heapForGx); appHeap.Finalize(); result = nn::applet::PrepareToCloseApplication(); HANDLE_ERROR(result); result = nn::applet::CloseApplication(); HANDLE_ERROR(result); } s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0); s_RenderSystem.Clear(); s_RenderSystem.SwapBuffers(); s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1); s_RenderSystem.Clear(); s_RenderSystem.SwapBuffers(); s_RenderSystem.WaitVsync(NN_GX_DISPLAY_BOTH); } }