diff --git a/branches/SelfCupExecChecker/CardCup.bsf b/branches/SelfCupExecChecker/CardCup.bsf new file mode 100644 index 0000000..104a94d Binary files /dev/null and b/branches/SelfCupExecChecker/CardCup.bsf differ diff --git a/branches/SelfCupExecChecker/CardCup.rsf b/branches/SelfCupExecChecker/CardCup.rsf new file mode 100644 index 0000000..edf44a5 --- /dev/null +++ b/branches/SelfCupExecChecker/CardCup.rsf @@ -0,0 +1,24 @@ +BasicInfo: + Title: SelfCup + BackupMemoryType: None + Logo: Nintendo + +CardInfo: + CardDevice: None + +TitleInfo: + Use: Evaluation + UniqueId: 0xf802a + Version: 0 + +SystemControlInfo: + AppType : Application + Dependency: + - nwm + - socket + - ssl + - friends + - ac + - cecd + - boss + - ndm diff --git a/branches/SelfCupExecChecker/OMakefile b/branches/SelfCupExecChecker/OMakefile new file mode 100644 index 0000000..4e9b587 --- /dev/null +++ b/branches/SelfCupExecChecker/OMakefile @@ -0,0 +1,44 @@ +#!/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 + +LIBS += lib_demo \ + libnn_am \ + libnn_cup \ + libnn_ns \ + + +DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/SelfCup.desc + +TARGET_PROGRAM = CardCup + +TITLE = CardCup +ROM_SPEC_FILE = CardCup.rsf + +CTR_BANNER_SPEC = $(TARGET_PROGRAM).bsf + +include $(ROOT_OMAKE)/modulerules + +build: $(DEFAULT_TARGETS) diff --git a/branches/SelfCupExecChecker/OMakeroot b/branches/SelfCupExecChecker/OMakeroot new file mode 100644 index 0000000..7ee1cb5 --- /dev/null +++ b/branches/SelfCupExecChecker/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:$ +#---------------------------------------------------------------------------- + +# ディレクトリレイアウトについての説明 +# +# a) ソースコードがルートディレクトリ直下に配置される場合 +# 例: +# /OMakeroot +# /foo/bar/OMakefile +# +# 結果: +# OMakefile と同じディレクトリ以下に objects や images が生成されます。 +# +# /foo/bar/objects/... +# /foo/bar/images/.. +# +# +# b) ソースコードが sources 以下に配置される場合 +# 例: +# /OMakeroot +# /sources/foo/bar/OMakefile +# +# 結果: +# ルートディレクトリ以下に objects や images が生成されます。 +# +# /objects/foo/bar/... +# /images/foo/bar/... +# +# + +# ルート環境変数の取得 +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 が一致しません。同じパスを設定するか、どちらか一方だけを定義して下さい。) + 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/branches/SelfCupExecChecker/Readme.txt b/branches/SelfCupExecChecker/Readme.txt new file mode 100644 index 0000000..b54f3e8 Binary files /dev/null and b/branches/SelfCupExecChecker/Readme.txt differ diff --git a/branches/SelfCupExecChecker/banner/model.cbmd b/branches/SelfCupExecChecker/banner/model.cbmd new file mode 100644 index 0000000..f1c7b62 Binary files /dev/null and b/branches/SelfCupExecChecker/banner/model.cbmd differ diff --git a/branches/SelfCupExecChecker/banner/sound.cbsd b/branches/SelfCupExecChecker/banner/sound.cbsd new file mode 100644 index 0000000..f1c7b62 Binary files /dev/null and b/branches/SelfCupExecChecker/banner/sound.cbsd differ diff --git a/branches/SelfCupExecChecker/banner/unknown24x24.ctpk b/branches/SelfCupExecChecker/banner/unknown24x24.ctpk new file mode 100644 index 0000000..794b136 --- /dev/null +++ b/branches/SelfCupExecChecker/banner/unknown24x24.ctpk @@ -0,0 +1 @@ +スススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススニススススススススススススススススススススススススススススススススススススススニ8ニ8ニ゙銷スス8ニススススス釡゙ニ鍄踟ススススススススススススススススススススススススススススススススススススススススススニススススススススススススススススススススススススススススススススススススススススススyホスyホスススススYホスススススススススススススススススススススススススススススススススス鍄゙yホYホスロ゙ロ゙ススニススロ゙yボスyホ轌ホ釡゙ススススYホ轌ホ銷スススススyホニロ゙鍄躡ホyホスススyホスコヨスススススyホスyホスススススYホスススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススyホ躡ホ銷スススススニスス轌ホ8ニススススニススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススス \ No newline at end of file diff --git a/branches/SelfCupExecChecker/banner/unknown48x48.ctpk b/branches/SelfCupExecChecker/banner/unknown48x48.ctpk new file mode 100644 index 0000000..8c7da16 --- /dev/null +++ b/branches/SelfCupExecChecker/banner/unknown48x48.ctpk @@ -0,0 +1 @@ +スススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススYホススススススススススススススススススススススススススス8ニスス8ニ8ニスススコヨ8ニコヨ釡゙銷スススススススススス8ニ8ニススニススススススススススススススススス鍄逧ヨニ銷スス墮ス逧ヨ銷スススススススススススススススススススススススススススススススススススススススススス8ニススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススロ゙スロ゙ススススス銷ズスススススススススススススススススススススコヨスススススススススス鍄8ニ゙ロ゙スス墮スYホススススス躡ホyホ轌ホニススススススススニススススススススススススロ゙ロ゙釡゙踟スス躡ホ銷スススススロ゙スロ゙銷ススYボ墮釡゙コヨス墮スロ゙ススススス踟ス踟スススススススススススススススススススススロ゙スyホススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススYホス墮銷スロ゙スロ゙銷ススススススススススススススススス8ニススコヨロ゙スススススYホニyホ逧ヨ郤ヨスYホス觝ホススススススススススススススロ゙墮ススススススyホス鍄踟ススニスススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススス踟ス銷ズスYホ鍄銷ススススススススススススススススススススス8ニスススススススススス逧ヨスロ゙ス釡゙墮ススススススススススススススススススス8ニススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススススス \ No newline at end of file diff --git a/branches/SelfCupExecChecker/main.cpp b/branches/SelfCupExecChecker/main.cpp new file mode 100644 index 0000000..eefb523 --- /dev/null +++ b/branches/SelfCupExecChecker/main.cpp @@ -0,0 +1,314 @@ +サソ/*---------------------------------------------------------------------------* + 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 "demo.h" +#include "scrollBuffer.h" + +namespace +{ + const int s_GxHeapSize=0x800000; + nn::fnd::ExpHeap s_appHeap; + uptr s_GxHeap; + + demo::RenderSystemDrawing s_RenderSystem; + ScrollBuffer s_scrollBufferInstance; + ScrollBuffer *s_scrollBuffer; + + char s_updaterBuffer[1<<20] NN_ATTRIBUTE_ALIGN(4096); + + // 繝繝「縺ョ蛻晄悄蛹 + void Initialize() + { + // os 縺ョ蛻晄悄蛹 + nn::os::Initialize(); + + // NuiShell縺ョ蛻晄悄蛹 (CUP縺ォ蠢鬆) + NN_UTIL_PANIC_IF_FAILED(nn::ns::CTR::InitializeForShell()); + + // ndm縺ョ蛻晄悄蛹 + nn::ndm::Initialize(); + + // 蜈ィ繝繝シ繝「繝ウ縺ョ閾ェ蠕句虚菴懊rac縺ョ閾ェ蜍墓磁邯壹b蜷ォ繧√※豁「繧√k + 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 int DEVICE_MEMORY_SIZE = 12*1024 * 1024; + NN_UTIL_PANIC_IF_FAILED(nn::os::SetDeviceMemorySize(DEVICE_MEMORY_SIZE)); + + // 繝偵シ繝励ョ蛻晄悄蛹 + s_appHeap.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize(), nn::os::ALLOCATE_OPTION_LINEAR); + + // 謠冗判繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ョ蛻晄悄蛹 + s_GxHeap = reinterpret_cast(s_appHeap.Allocate(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[]="-\\|/"; + int s_progressIndex=0; + char GetProgressChar() + { + s_progressIndex=(s_progressIndex+1)%(sizeof(s_progress)-1); + return s_progress[s_progressIndex]; + } + + nn::Result UpdateCore() + { + nn::Result result; + nn::cup::ProgressInfo info; + + /********************** 繧「繝繝励ョ繝シ繝*******************/ + SetTick(); + s_scrollBuffer->AppendText("Start Card Update")->Render(); + NN_UTIL_RETURN_IF_FAILED(nn::cup::CTR::DoUpdate()); + + // 繧ケ繝繝シ繧ソ繧ケ縺郡tarted縺ォ縺ェ繧九∪縺ァ縲√励Ο繧ー繝ャ繧ケ縺ッ蜿門セ励〒縺阪↑縺 + s_scrollBuffer->AppendText(""); + do{ + s_scrollBuffer->ReplaceText(" %c Initializing", GetProgressChar())->Render(); + result = nn::cup::CTR::GetProgressInfo(&info); + NN_UTIL_RETURN_IF_FAILED(result); + nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(40)); + }while(info.state==nn::cup::CTR::UPDATE_STATE_INITIALIZING); + + // 謚懊¢縺滄圀縺ョstate縺熊AILED縺九←縺縺狗「コ隱 + if(info.state==nn::cup::CTR::UPDATE_STATE_FAILED){ + NN_UTIL_RETURN_IF_FAILED(info.lastResult); + } + s_scrollBuffer->ReplaceText(" - Initialized (%lldmsec)", GetConsumedMillisec()); + + /********************* 繧「繝繝励ョ繝シ繝井クュ ******************/ + SetTick(); + s_scrollBuffer->AppendText("")->Render(); + do{ + result = nn::cup::CTR::GetProgressInfo(&info); + NN_UTIL_RETURN_IF_FAILED(result); + s_scrollBuffer->ReplaceText(" %c Title %d/%d, size %lld/%lld", + GetProgressChar(), + info.numImportedTitles, info.numTotalTitles, + info.importedSize, info.totalSize)->Render(); + nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(40)); + + }while(info.state==nn::cup::CTR::UPDATE_STATE_STARTED); + // 謚懊¢縺滄圀縺ョstate縺熊AILED縺九←縺縺狗「コ隱 + if(info.state==nn::cup::CTR::UPDATE_STATE_FAILED){ + NN_UTIL_RETURN_IF_FAILED(info.lastResult); + } + s_scrollBuffer->AppendText(" - Imported (%lldmsec)", GetConsumedMillisec())->Render(); + + /***************** 繧「繝繝励ョ繝シ繝育オゆコ荳ュ ******************/ + SetTick(); + s_scrollBuffer->AppendText("")->Render(); + do{ + result = nn::cup::CTR::GetProgressInfo(&info); + NN_UTIL_RETURN_IF_FAILED(result); + s_scrollBuffer->ReplaceText(" %c Update Finalizing", GetProgressChar())->Render(); + nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(40)); + }while(info.state==nn::cup::CTR::UPDATE_STATE_FINALIZING); + // 謚懊¢縺滄圀縺ョstate縺熊AILED縺九←縺縺狗「コ隱 + if(info.state==nn::cup::CTR::UPDATE_STATE_FAILED){ + NN_UTIL_RETURN_IF_FAILED(info.lastResult); + } + + /******************* 繧「繝繝励ョ繝シ繝育オゆコ *******************/ + s_scrollBuffer->AppendText(" - Finalized (%lldmsec)", GetConsumedMillisec())->Render(); + s_scrollBuffer->AppendText(""); + + return nn::ResultSuccess(); + } + + nn::Result UpdateSequence(bool *isHandledError) + { + 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(); + s_scrollBuffer->AppendText("")->Render(); + + lastResult=UpdateCore(); + + // Initialize縺ォ謌仙粥縺励◆蝣エ蜷医ョ縺ソ縲∝阪ウInitialize縺吶k縺溘a縺ォFinalize縺悟ソ隕 + SetTick(); + s_scrollBuffer->AppendText("Finalizing Cup Library")->Render(); + NN_UTIL_RETURN_IF_FAILED(nn::cup::CTR::Finalize()); + s_scrollBuffer->AppendText(" - Complete (%lldmsec)", GetConsumedMillisec())->Render(); + s_scrollBuffer->AppendText("")->Render(); + + return lastResult; + } +} + +extern "C" void nnMain() +{ + NN_LOG("Start cup demo\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); + if (result.IsSuccess()) + { + + /******************** CUP縺ョ螳溯。 *******************/ + bool isHandledError = false; + result = UpdateSequence(&isHandledError); + if (isHandledError == false && result.IsFailure()) + { + { + // 縺昴l莉・螟悶ョ蝣エ蜷医ッ縲ヽesult繧定。ィ遉コ + s_scrollBuffer->AppendText(" - Unhandled Error: 0x%08x", result.GetPrintableBits()); + s_scrollBuffer->AppendText("")->Render(); + } + } + } + else if(result == nn::am::ResultNotFound()) + { + s_scrollBuffer->AppendText("Cannot find Home Menu"); + } + + s_scrollBuffer->AppendText("")->Render(); + + for(;;) + { + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0); + 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(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/branches/SelfCupExecChecker/scrollBuffer.cpp b/branches/SelfCupExecChecker/scrollBuffer.cpp new file mode 100644 index 0000000..54de11e --- /dev/null +++ b/branches/SelfCupExecChecker/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/branches/SelfCupExecChecker/scrollBuffer.h b/branches/SelfCupExecChecker/scrollBuffer.h new file mode 100644 index 0000000..1d3563a --- /dev/null +++ b/branches/SelfCupExecChecker/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(); // 繧ュ繝シ蜈・蜉帙r蜿らァ縺励※縲√せ繧ッ繝ュ繝シ繝ォ縺吶k + ScrollBuffer *AppendText(const char *fmt, ...); // 譁蟄怜励r霑ス蜉縺吶k + ScrollBuffer *ReplaceText(const char *fmt, ...); // 譛譁ー縺ョ譁蟄怜励r鄂ョ謠帙☆繧 + void Render(); // 繝ャ繝ウ繝繝ェ繝ウ繧ー +}; + +#endif // SCROLL_BUFFER_H