diff --git a/tags/SelfCupExecChecker/1.1NUP/HeapManager.cpp b/tags/SelfCupExecChecker/1.1NUP/HeapManager.cpp new file mode 100644 index 0000000..8e95885 --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/HeapManager.cpp @@ -0,0 +1,59 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: HeapManager.cpp + + Copyright 2009 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 "HeapManager.h" + +nn::fnd::ThreadSafeExpHeap s_AppHeap; + + +HeapManager::HeapManager(size_t byteSize, s32 alignment, bit8 groupId, nn::fnd::ExpHeapBase::AllocationMode mode, bool reuse) +{ + m_Ptr = s_AppHeap.Allocate(byteSize, alignment, groupId, mode, reuse); +} + +HeapManager::~HeapManager() +{ + if(m_Ptr != NULL) + { + s_AppHeap.Free(m_Ptr); + } +} +void* HeapManager::GetAddr() +{ + return m_Ptr; +} + +void InitializeHeap() +{ + s_AppHeap.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize(), nn::os::ALLOCATE_OPTION_LINEAR); +} + +size_t GetAllocatableSize(s32 alignment) +{ + return s_AppHeap.GetAllocatableSize(alignment); +} + +void* ForceAllocate(size_t byteSize, s32 alignment, bit8 groupId, nn::fnd::ExpHeapBase::AllocationMode mode, bool reuse) +{ + return s_AppHeap.Allocate(byteSize, alignment, groupId, mode, reuse); +} + +void ForceFree(void* ptr) +{ + if(ptr != NULL) + { + s_AppHeap.Free(ptr); + } +} diff --git a/tags/SelfCupExecChecker/1.1NUP/HeapManager.h b/tags/SelfCupExecChecker/1.1NUP/HeapManager.h new file mode 100644 index 0000000..f50f3fe --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/HeapManager.h @@ -0,0 +1,46 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: HeapManager.h + + Copyright 2009 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$ + *---------------------------------------------------------------------------*/ + +#ifndef HEAPMANAGER_H_ +#define HEAPMANAGER_H_ + +#include +#include + +class HeapManager +{ +public: + explicit HeapManager(size_t byteSize, s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT, bit8 groupId = 0, + nn::fnd::ExpHeapBase::AllocationMode mode = nn::fnd::ExpHeapBase::ALLOCATION_MODE_FIRST_FIT, bool reuse = false); + virtual ~HeapManager(); + + void* GetAddr(); + +private: + void* m_Ptr; + +}; + +void InitializeHeap(); +size_t GetAllocatableSize(s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT); + +// HeapManagerを使わず確保する場合のみ +void* ForceAllocate(size_t byteSize, s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT, bit8 groupId = 0, + nn::fnd::ExpHeapBase::AllocationMode mode = nn::fnd::ExpHeapBase::ALLOCATION_MODE_FIRST_FIT, bool reuse = false); + +// HeapManagerを使わず解放する場合のみ +void ForceFree(void* ptr); + +#endif /* HEAPMANAGER_H_ */ diff --git a/tags/SelfCupExecChecker/1.1NUP/OMakefile b/tags/SelfCupExecChecker/1.1NUP/OMakefile new file mode 100644 index 0000000..fd964c1 --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/OMakefile @@ -0,0 +1,47 @@ +#!/usr/bin/env omake +#---------------------------------------------------------------------------- +# Project: Horizon +# File: OMakefile +# +# Copyright (C)2009 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$ +#---------------------------------------------------------------------------- +CTR_APPTYPE=CARD + +SUPPORTED_TARGETS = CTR-T*.Process.MPCore.* + +SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/common/include) +INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) + +SOURCES[] = + main.cpp + scrollBuffer.cpp + VersionDetect.cpp + HeapManager.cpp + +LIBS += lib_demo \ + libnn_am \ + libnn_cup \ + libnn_ns \ + +ROMFS_ROOT = romfiles + +DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/SelfCup.desc + +TARGET_PROGRAM = SelfCupExecChecker + +TITLE = SelfCupExecChecker +ROM_SPEC_FILE = SelfCupExecChecker.rsf + +CTR_BANNER_SPEC = $(TARGET_PROGRAM).bsf + +include $(ROOT_OMAKE)/modulerules + +build: $(DEFAULT_TARGETS) diff --git a/tags/SelfCupExecChecker/1.1NUP/OMakeroot b/tags/SelfCupExecChecker/1.1NUP/OMakeroot new file mode 100644 index 0000000..7ee1cb5 --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/OMakeroot @@ -0,0 +1,73 @@ +#!/usr/bin/env omake +#---------------------------------------------------------------------------- +# Project: Horizon +# File: OMakeroot +# +# Copyright (C)2009 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:$ +#---------------------------------------------------------------------------- + +# fBNgCAEgɂ‚Ă̐ +# +# a) \[XR[h[gfBNgɔzuꍇ +# : +# /OMakeroot +# /foo/bar/OMakefile +# +# : +# OMakefile ƓfBNgȉ objects images ܂B +# +# /foo/bar/objects/... +# /foo/bar/images/.. +# +# +# b) \[XR[h sources ȉɔzuꍇ +# : +# /OMakeroot +# /sources/foo/bar/OMakefile +# +# : +# [gfBNgȉ objects images ܂B +# +# /objects/foo/bar/... +# /images/foo/bar/... +# +# + +# [g‹ϐ̎擾 +public.HORIZON_ROOT = +if $(defined-env HORIZON_ROOT) + HORIZON_ROOT = $(absname $(getenv HORIZON_ROOT)) + export + +if $(defined-env CTRSDK_ROOT) + CTRSDK_ROOT = $(absname $(getenv CTRSDK_ROOT)) + if $(and $(defined-env HORIZON_ROOT), $(not $(equal $(HORIZON_ROOT), $(CTRSDK_ROOT)))) + eprintln(HORIZON_ROOT CTRSDK_ROOT v܂BpXݒ肷邩Aǂ炩`ĉB) + exit(1) + HORIZON_ROOT = $(CTRSDK_ROOT) + export + +if $(not $(HORIZON_ROOT)) + eprintln($"$$CTRSDK_ROOT `Ă܂") + exit(1) + +include $(HORIZON_ROOT)/build/omake/commondefs + +DefineCommandVars() + +.PHONY: all build clean clobber +.PHONY: run run-scripts run-emumem + +# +# OMakefile ̓ǂݍ +# +.SUBDIRS: . + diff --git a/tags/SelfCupExecChecker/1.1NUP/Readme.txt b/tags/SelfCupExecChecker/1.1NUP/Readme.txt new file mode 100644 index 0000000..01dd48d --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/Readme.txt @@ -0,0 +1,4 @@ +rh‹ +ESDK + Horizon 2.3 branch r38025 + r38091 SelfCup.desc + + trunk r38944 pl_SharedDataTitleId.h diff --git a/tags/SelfCupExecChecker/1.1NUP/SelfCupExecChecker.bsf b/tags/SelfCupExecChecker/1.1NUP/SelfCupExecChecker.bsf new file mode 100644 index 0000000..104a94d Binary files /dev/null and b/tags/SelfCupExecChecker/1.1NUP/SelfCupExecChecker.bsf differ diff --git a/tags/SelfCupExecChecker/1.1NUP/SelfCupTool.bsf b/tags/SelfCupExecChecker/1.1NUP/SelfCupTool.bsf new file mode 100644 index 0000000..104a94d Binary files /dev/null and b/tags/SelfCupExecChecker/1.1NUP/SelfCupTool.bsf differ diff --git a/tags/SelfCupExecChecker/1.1NUP/SelfCupTool.rsf b/tags/SelfCupExecChecker/1.1NUP/SelfCupTool.rsf new file mode 100644 index 0000000..4a361c9 --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/SelfCupTool.rsf @@ -0,0 +1,26 @@ +BasicInfo: + Title: SelfCupTool + ProductCode: CTR-P-234A + BackupMemoryType: None + Logo: Nintendo + +CardInfo: + CardDevice: None + +TitleInfo: + Use: Evaluation + UniqueId: 0xf802a + Version: 0 + +SystemControlInfo: + AppType : Application + StackSize : 65536 + Dependency: + - nwm + - socket + - ssl + - friends + - ac + - cecd + - boss + - ndm diff --git a/tags/SelfCupExecChecker/1.1NUP/SelfcupExecChecker.rsf b/tags/SelfCupExecChecker/1.1NUP/SelfcupExecChecker.rsf new file mode 100644 index 0000000..564bb22 --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/SelfcupExecChecker.rsf @@ -0,0 +1,25 @@ +BasicInfo: + Title: SelfCupExecChecker + ProductCode: CTR-P-24UA + BackupMemoryType: None + Logo: Nintendo + +CardInfo: + CardDevice: None + +TitleInfo: + Use: Evaluation + UniqueId: 0xf8043 + Version: 0 + +SystemControlInfo: + AppType : Application + Dependency: + - nwm + - socket + - ssl + - friends + - ac + - cecd + - boss + - ndm diff --git a/tags/SelfCupExecChecker/1.1NUP/VersionDetect.cpp b/tags/SelfCupExecChecker/1.1NUP/VersionDetect.cpp new file mode 100644 index 0000000..203e80c --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/VersionDetect.cpp @@ -0,0 +1,109 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: VersionDetect.cpp + + Copyright 2009 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 "VersionDetect.h" +#include "HeapManager.h" + + +void GetCupVersion(nn::pl::CTR::CardUpdateVersion* cup, nn::cfg::CTR::CfgRegionCode region) +{ + nn::Result result; + const size_t BUF_SIZE = 1024; + u8 buf[BUF_SIZE]; + // CUPバージョン + { + result = nn::fs::MountContent("cver:", nn::fs::MEDIA_TYPE_NAND, cCupVerId[region], 0, 1, 1, buf, + BUF_SIZE); + + nn::fs::FileInputStream fis; + + result = fis.TryInitialize(L"cver:/version.bin"); + if (result.IsSuccess()) + { + s64 fileSize = fis.GetSize(); + NN_LOG("version.bin size = %lld\n", fileSize); + s32 ret; + void* addr = NULL; + HeapManager heap(fileSize); + addr = heap.GetAddr(); + if (addr != NULL) + { + result = fis.TryRead(&ret, addr, fileSize); + if (result.IsSuccess()) + { + nn::pl::CTR::CardUpdateVersion* ver_buf = reinterpret_cast (addr); + + std::memcpy(cup, ver_buf, sizeof(nn::pl::CTR::CardUpdateVersion)); + } + } + } + fis.Finalize(); + + nn::fs::Unmount("cver:"); + } + +} + + +void GetNupVersion(nn::pl::CTR::NetworkUpdateVersion* nup, nn::cfg::CTR::CfgRegionCode region) +{ + nn::Result result; + const size_t BUF_SIZE = 1024; + u8 buf[BUF_SIZE]; + + // NUPバージョン + { + result = nn::fs::MountContent("nver:", nn::fs::MEDIA_TYPE_NAND, cNupVerId[region], 0, 1, 1, buf, + BUF_SIZE); + + nn::fs::FileInputStream fis; + + result = fis.TryInitialize(L"nver:/version.bin"); + if (result.IsSuccess()) + { + s64 fileSize = fis.GetSize(); + NN_LOG("version.bin size = %lld\n", fileSize); + s32 ret; + void* addr = NULL; + HeapManager heap(fileSize); + addr = heap.GetAddr(); + if (addr != NULL) + { + result = fis.TryRead(&ret, addr, fileSize); + if (result.IsSuccess()) + { + nn::pl::CTR::NetworkUpdateVersion* ver_buf = + reinterpret_cast (addr); + + std::memcpy(nup, ver_buf, sizeof(nn::pl::CTR::NetworkUpdateVersion)); + } + } + } + + fis.Finalize(); + nn::fs::Unmount("nver:"); + } + +} + +void GetSystemVersion(VerDef* mVerData, nn::cfg::CTR::CfgRegionCode region) +{ + GetCupVersion(&mVerData->cup, region); + GetNupVersion(&mVerData->nup, region); +} diff --git a/tags/SelfCupExecChecker/1.1NUP/VersionDetect.h b/tags/SelfCupExecChecker/1.1NUP/VersionDetect.h new file mode 100644 index 0000000..7f94174 --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/VersionDetect.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: VersionDetect.h + + Copyright 2009 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$ + *---------------------------------------------------------------------------*/ + +#ifndef VERSIONDETECT_H_ +#define VERSIONDETECT_H_ + +#include +#include +#include + +struct VerDef +{ + nn::pl::CTR::CardUpdateVersion cup; + nn::pl::CTR::NetworkUpdateVersion nup; +}; + +// TODO:リージョン追加時に範囲外アクセスにならないよう注意 +const nn::ProgramId cCupVerId[] = +{ + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_JP, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_US, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_EU, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_EU, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_CN, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_KR, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_TW, +}; + +const nn::ProgramId cNupVerId[] = +{ + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_JP, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_US, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_EU, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_EU, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_CN, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_KR, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_TW, +}; + +// リージョンコードに基づいてバージョン情報を取得する +void GetSystemVersion(VerDef* mVerData, nn::cfg::CTR::CfgRegionCode region); + +#endif /* VERSIONDETECT_H_ */ diff --git a/tags/SelfCupExecChecker/1.1NUP/banner/model.cbmd b/tags/SelfCupExecChecker/1.1NUP/banner/model.cbmd new file mode 100644 index 0000000..f1c7b62 Binary files /dev/null and b/tags/SelfCupExecChecker/1.1NUP/banner/model.cbmd differ diff --git a/tags/SelfCupExecChecker/1.1NUP/banner/sound.cbsd b/tags/SelfCupExecChecker/1.1NUP/banner/sound.cbsd new file mode 100644 index 0000000..f1c7b62 Binary files /dev/null and b/tags/SelfCupExecChecker/1.1NUP/banner/sound.cbsd differ diff --git a/tags/SelfCupExecChecker/1.1NUP/banner/unknown24x24.ctpk b/tags/SelfCupExecChecker/1.1NUP/banner/unknown24x24.ctpk new file mode 100644 index 0000000..794b136 --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/banner/unknown24x24.ctpk @@ -0,0 +1 @@ +888yyYyYyyyYyyYyyyyYyYy8 \ No newline at end of file diff --git a/tags/SelfCupExecChecker/1.1NUP/banner/unknown48x48.ctpk b/tags/SelfCupExecChecker/1.1NUP/banner/unknown48x48.ctpk new file mode 100644 index 0000000..8c7da16 --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/banner/unknown48x48.ctpk @@ -0,0 +1 @@ +Y8888ƺ8888YYyyYYޚ޺yY8YyYYޚyY8ޚ8 \ No newline at end of file diff --git a/tags/SelfCupExecChecker/1.1NUP/main.cpp b/tags/SelfCupExecChecker/1.1NUP/main.cpp new file mode 100644 index 0000000..bc66cb5 --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/main.cpp @@ -0,0 +1,274 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: main.cpp + + Copyright (C)2009 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$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "demo.h" +#include "scrollBuffer.h" +#include "VersionDetect.h" +#include "HeapManager.h" + +namespace +{ +const s32 s_GxHeapSize = 0x800000; +uptr s_GxHeap; + +demo::RenderSystemDrawing s_RenderSystem; +ScrollBuffer s_scrollBufferInstance; +ScrollBuffer *s_scrollBuffer; + +char s_updaterBuffer[1 << 20] NN_ATTRIBUTE_ALIGN(4096); + +// デモの初期化 +void Initialize() +{ + // NuiShellの初期化 (CUPに必須) + NN_UTIL_PANIC_IF_FAILED(nn::ns::CTR::InitializeForShell()); + + // ndmの初期化 + nn::ndm::Initialize(); + + // 全デーモンの自律動作をacの自動接続も含めて止める + nn::ndm::SuspendScheduler(); + + // amの初期化 + nn::am::InitializeForSystemMenu(); + + // fsの初期化 (カード確認用) + nn::fs::Initialize(); + + // appletの初期化 + //nn::applet::InitializeForSystem( nn::applet::PHOME_MENU_APPLET_ID, nn::applet::TYPE_SYS ); + //nn::applet::Initialize( nn::applet::TEST2_APPLET_ID); + //nn::applet::SetAppletMode(); + nn::applet::Enable(); + + nn::cfg::Initialize(); + + // デバイスメモリの設定 + const s32 DEVICE_MEMORY_SIZE = 32 * 1024 * 1024; + NN_UTIL_PANIC_IF_FAILED(nn::os::SetDeviceMemorySize(DEVICE_MEMORY_SIZE)); + + // ヒープの初期化 + InitializeHeap(); + + // 描画インスタンスの初期化 + s_GxHeap = reinterpret_cast(ForceAllocate(s_GxHeapSize)); + s_RenderSystem.Initialize(s_GxHeap, s_GxHeapSize); + + // 描画インスタンスの初期化 + s_scrollBufferInstance.Initialize(&s_RenderSystem); + s_scrollBuffer = &s_scrollBufferInstance; + + // GPU利用宣言 + nn::applet::AssignGpuRight(); +} + +// 消費時間取得用関数群 +s64 s_StartTick; +void SetTick() +{ + s_StartTick = nn::os::Tick::GetSystemCurrent(); +} +s64 GetConsumedMillisec() +{ + s64 endTick = nn::os::Tick::GetSystemCurrent(); + nn::os::Tick consumed(endTick - s_StartTick); + return ((nn::fnd::TimeSpan) consumed).GetMilliSeconds(); +} + +// 動いていることを知らせるための、くるくる画面表示取得用メソッド +const char s_progress[] = "-\\|/"; +s32 s_progressIndex = 0; +char GetProgressChar() +{ + s_progressIndex = (s_progressIndex + 1) % (sizeof(s_progress) - 1); + return s_progress[s_progressIndex]; +} + +nn::Result UpdateSequence(bool *isHandledError, bool* needUpdate) +{ + nn::Result result; + nn::Result lastResult = nn::ResultSuccess(); + + /********************* CUPの初期化 *******************/ + s_scrollBuffer->AppendText("Initializing Cup Library")->Render(); + SetTick(); // 初期化開始前の時間をセット + result = nn::cup::CTR::Initialize(s_updaterBuffer, sizeof(s_updaterBuffer)); + if (result == nn::cup::CTR::ResultUpdatePartitionNotFound()) + { + s_scrollBuffer->AppendText(" - Update Partition Not Found (%lldmsec)", GetConsumedMillisec())->Render(); + s_scrollBuffer->AppendText("")->Render(); + *isHandledError = true; + return result; + } + if (result == nn::cup::CTR::ResultUpdateNotRequired()) + { + s_scrollBuffer->AppendText(" - Already Updated (%lldmsec)", GetConsumedMillisec())->Render(); + s_scrollBuffer->AppendText("")->Render(); + *isHandledError = true; + return result; + } + if (result == nn::cup::CTR::ResultInvalidUpdatePartitionFormat()) + { + s_scrollBuffer->AppendText(" - Invalid Update Partition (%lldmsec)", GetConsumedMillisec())->Render(); + s_scrollBuffer->AppendText("")->Render(); + *isHandledError = true; + return result; + } + NN_UTIL_RETURN_IF_FAILED(result); + + s_scrollBuffer->AppendText(" - Need Update (%lldmsec)", GetConsumedMillisec())->Render(); + *needUpdate = true; + s_scrollBuffer->AppendText("")->Render(); + + // Initializeに成功した場合のみ、再びInitializeするためにFinalizeが必要 + SetTick(); + s_scrollBuffer->AppendText("Finalizing Cup Library")->Render(); + NN_UTIL_RETURN_IF_FAILED(nn::cup::CTR::Finalize()); + + return lastResult; +} +} + +nn::Result ExecuteCup(ScrollBuffer* scrollBuf, bool* needUpdte) +{ + nn::Result result; + bool isHandledError = false; + result = UpdateSequence(&isHandledError, needUpdte); + if (isHandledError == false && result.IsFailure()) + { + { + // それ以外の場合は、Resultを表示 + scrollBuf->AppendText(" - Unhandled Error: 0x%08x", result.GetPrintableBits()); + scrollBuf->AppendText("")->Render(); + } + } + + return result; +} + +extern "C" void nnMain() +{ + NN_LOG("Start Self Cup\n"); + nn::Result result; + Initialize(); + + nn::ProgramId MMEN_PROGRAM_ID = 0x0004003000008202; + + nn::cfg::CfgRegionCode region = nn::cfg::GetRegion(); + switch(region) + { + case nn::cfg::CFG_REGION_AMERICA: + { + MMEN_PROGRAM_ID = 0x0004003000008f02; + } + break; + + case nn::cfg::CFG_REGION_EUROPE: + case nn::cfg::CFG_REGION_AUSTRALIA: + { + MMEN_PROGRAM_ID = 0x0004003000009802; + } + break; + + case nn::cfg::CFG_REGION_JAPAN: + { + MMEN_PROGRAM_ID = 0x0004003000008202; + } + break; + } + + nn::am::ProgramInfo outInfos; + result = nn::am::GetProgramInfos(&outInfos, nn::fs::MEDIA_TYPE_NAND, &MMEN_PROGRAM_ID, 1); + bool needUpdate = false; + if (result.IsSuccess()) + { + result = ExecuteCup(s_scrollBuffer, &needUpdate); + } + else if(result == nn::am::ResultNotFound()) + { + s_scrollBuffer->AppendText("Cannot find Home Menu"); + } + + if(needUpdate) + { + s_scrollBuffer->AppendText("Need to execute Self Cup"); + } + + s_scrollBuffer->AppendText("")->Render(); + VerDef versionData; + GetSystemVersion(&versionData, region); + + s_scrollBuffer->AppendText("Version: %d.%d.%d-%d%c", versionData.cup.majorVersion, versionData.cup.minorVersion, + versionData.cup.microVersion, versionData.nup.majorVersion, nn::cfg::GetRegionCodeA3(region)[0]); + + s_scrollBuffer->AppendText("")->Render(); + + for(;;) + { + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0); + if(needUpdate) + { + s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 1, 0, 0, 1); + } + else if(result.IsSuccess() || result == nn::cup::CTR::ResultUpdateNotRequired()) + { + s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 0, 1, 0, 1); + } + else + { + s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 1, 0, 0, 1); + } + s_RenderSystem.Clear(); + s_RenderSystem.SwapBuffers(); + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1); + if(needUpdate) + { + s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 1, 0, 0, 1); + } + else if(result.IsSuccess() || result == nn::cup::CTR::ResultUpdateNotRequired()) + { + s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 0, 1, 0, 1); + } + else + { + s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 1, 0, 0, 1); + } + s_scrollBuffer->ReplaceText("%c Finished", GetProgressChar())->Render(); + + if ( nn::applet::IsExpectedToCloseApplication() ) + { + nn::applet::PrepareToCloseApplication(); + nn::applet::CloseApplication(); + } + + } +} diff --git a/tags/SelfCupExecChecker/1.1NUP/romfiles/nup_version.bin b/tags/SelfCupExecChecker/1.1NUP/romfiles/nup_version.bin new file mode 100644 index 0000000..45a8ca0 --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/romfiles/nup_version.bin @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tags/SelfCupExecChecker/1.1NUP/scrollBuffer.cpp b/tags/SelfCupExecChecker/1.1NUP/scrollBuffer.cpp new file mode 100644 index 0000000..54de11e --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/scrollBuffer.cpp @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: scrollBuffer.cpp + + Copyright (C)2009 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$ + *---------------------------------------------------------------------------*/ + +#include +#include "scrollBuffer.h" + +using namespace std; + +char ScrollBuffer::s_buffers[MAX_BUFFER_LINE][MAX_BUFFER_CHARS]; + +char *ScrollBuffer::GetFormattedString(const char *fmt, va_list arg) +{ + static char formattedBuffer[MAX_BUFFER_CHARS]; + vsnprintf(formattedBuffer, MAX_BUFFER_CHARS, fmt, arg); + return formattedBuffer; +} + +ScrollBuffer *ScrollBuffer::Update() +{ + return this; +} + +ScrollBuffer *ScrollBuffer::AppendText(const char *fmt, ...) +{ + va_list vlist; + va_start(vlist, fmt); + + int nextPosition=(m_tail+1)%MAX_BUFFER_LINE; + if(nextPosition==m_head){ + // ヘッドとビューの移動 + if(m_head==m_currentView){ + m_currentView=(m_head+1)%MAX_BUFFER_LINE; + } + m_head=(m_head+1)%MAX_BUFFER_LINE; + + } + strlcpy(s_buffers[m_tail], GetFormattedString(fmt, vlist), MAX_BUFFER_CHARS); + m_tail=nextPosition; + NN_LOG("cup: %s\n", GetFormattedString(fmt, vlist)); + + // ビューの移動 + if((m_currentView+MAX_DISPLAY_LINES)%MAX_BUFFER_LINE==m_tail){ + m_currentView=(m_currentView+1)%MAX_BUFFER_LINE; + } + + return this; +} +ScrollBuffer *ScrollBuffer::ReplaceText(const char *fmt, ...) +{ + va_list vlist; + va_start(vlist, fmt); + + NN_ASSERT(m_tail!=m_head); + strlcpy(s_buffers[(m_tail-1)%MAX_BUFFER_LINE], GetFormattedString(fmt, vlist), MAX_BUFFER_CHARS); + + return this; +} + +void ScrollBuffer::Render() +{ + // 描画前処理 + m_render->SetRenderTarget(NN_GX_DISPLAY1); + m_render->Clear(); + m_render->SetColor(1.0f, 1.0f, 1.0f, 1.0f); + + // リングバッファなので、終端条件を調整 + int tail=(m_tailDrawText(0, (i-m_currentView)*FONT_SIZE, s_buffers[i%MAX_BUFFER_LINE]); + } + } + + // 描画転送 + m_render->SwapBuffers(); +} diff --git a/tags/SelfCupExecChecker/1.1NUP/scrollBuffer.h b/tags/SelfCupExecChecker/1.1NUP/scrollBuffer.h new file mode 100644 index 0000000..1d3563a --- /dev/null +++ b/tags/SelfCupExecChecker/1.1NUP/scrollBuffer.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: scrollBuffer.h + + Copyright (C)2009 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$ + *---------------------------------------------------------------------------*/ + +#ifndef SCROLL_BUFFER_H_ +#define SCROLL_BUFFER_H_ + +#include "demo.h" +class ScrollBuffer +{ +private: + enum + { + MAX_BUFFER_LINE=128, + MAX_BUFFER_CHARS=80, + MAX_DISPLAY_LINES=20, + FONT_SIZE=12 + }; + // 表示文字のバッファ (リングバッファ) + static char s_buffers[MAX_BUFFER_LINE][MAX_BUFFER_CHARS]; + int m_head; + int m_tail; + int m_currentView; + + demo::RenderSystemDrawing *m_render; + + char *GetFormattedString(const char *fmt, va_list arg); + +public: + ScrollBuffer() : + m_head(0), m_tail(0), m_currentView(0) + {} + void Initialize(demo::RenderSystemDrawing *render) + { + m_render=render; + } + + ScrollBuffer *Update(); // キー入力を参照して、スクロールする + ScrollBuffer *AppendText(const char *fmt, ...); // 文字列を追加する + ScrollBuffer *ReplaceText(const char *fmt, ...); // 最新の文字列を置換する + void Render(); // レンダリング +}; + +#endif // SCROLL_BUFFER_H