mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@653 385bec56-5757-e545-9c3a-d8741f4650f1
150 lines
4.3 KiB
C++
150 lines
4.3 KiB
C++
/*---------------------------------------------------------------------------*
|
|
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 <nn.h>
|
|
#include <nn/applet.h>
|
|
#include <nn/cfg.h>
|
|
#include <nn/cfg/CTR/cfg_ApiInit.h>
|
|
#include <nn/cfg/CTR/detail/cfg_Keys.h>
|
|
#include <nn/ns.h>
|
|
#include <nn/news/CTR/system/news_BossUtil.h>
|
|
#include <nn/hid/CTR/hid_ApiWithPrivilege.h>
|
|
|
|
#include "HeapManager.h"
|
|
#include "syokaikidou.h"
|
|
#include "CfgChanger.h"
|
|
|
|
#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 の準備
|
|
common::InitializeHeap();
|
|
|
|
const size_t s_GxHeapSize = 8 * 1024 * 1024;
|
|
common::HeapManager gxHeap(s_GxHeapSize);
|
|
void* heapForGx = gxHeap.GetAddr();
|
|
s_RenderSystem.Initialize(reinterpret_cast<uptr>(heapForGx), s_GxHeapSize);
|
|
s_RenderSystem.SetClearColor(NN_GX_DISPLAY_BOTH, 0, 1, 0, 1);
|
|
|
|
result = nn::ns::InitializeForShell();
|
|
HANDLE_ERROR(result);
|
|
|
|
nn::fs::Initialize();
|
|
|
|
nn::hid::InitializeWithPrivilege();
|
|
nn::hid::PadReader padReader;
|
|
nn::hid::PadStatus padStatus;
|
|
|
|
bool updateSaveData = false;
|
|
padReader.ReadLatest(&padStatus);
|
|
if(padStatus.hold & nn::hid::BUTTON_Y)
|
|
{
|
|
NN_LOG("Updating SaveData\n");
|
|
updateSaveData = true;
|
|
CfgChanger changer;
|
|
result = changer.ImportToBackup();
|
|
if(result.IsFailure())
|
|
{
|
|
NN_DBG_PRINT_RESULT(result);
|
|
}
|
|
else
|
|
{
|
|
NN_LOG("Updating SaveData done.\n");
|
|
}
|
|
}
|
|
|
|
if(!updateSaveData)
|
|
{
|
|
NN_LOG("Set SaveData");
|
|
CfgChanger changer;
|
|
if(changer.RestoreFromBackup().IsSuccess())
|
|
{
|
|
nn::news::CTR::boss::Initialize();
|
|
fnc_1st_setting();
|
|
fnc_starting_set();
|
|
}
|
|
}
|
|
|
|
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();
|
|
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);
|
|
}
|
|
}
|