diff --git a/trunk/KENJEraser/HeapManager.cpp b/trunk/KENJEraser/HeapManager.cpp new file mode 100644 index 0000000..29f4367 --- /dev/null +++ b/trunk/KENJEraser/HeapManager.cpp @@ -0,0 +1,39 @@ +/*---------------------------------------------------------------------------* + 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" + +namespace common +{ + +nn::fnd::ThreadSafeExpHeap HeapManager::s_AppHeap; + +HeapManager::HeapManager() +{ + // TODO 自動生成されたコンストラクター・スタブ + +} + +HeapManager::~HeapManager() +{ + // TODO Auto-generated destructor stub +} + +nn::fnd::ThreadSafeExpHeap* HeapManager::GetHeap() +{ + return &s_AppHeap; +} + +} diff --git a/trunk/KENJEraser/HeapManager.h b/trunk/KENJEraser/HeapManager.h new file mode 100644 index 0000000..b9fc469 --- /dev/null +++ b/trunk/KENJEraser/HeapManager.h @@ -0,0 +1,40 @@ +/*---------------------------------------------------------------------------* + 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 + +namespace common +{ + +class HeapManager +{ +public: + HeapManager(); + virtual ~HeapManager(); + + static nn::fnd::ThreadSafeExpHeap* GetHeap(); + +private: + // デバイスメモリ管理用拡張ヒープ + static nn::fnd::ThreadSafeExpHeap s_AppHeap; + +}; + +} // namespace common + +#endif /* HEAPMANAGER_H_ */ diff --git a/trunk/KENJEraser/KENJEraser.bsf b/trunk/KENJEraser/KENJEraser.bsf new file mode 100644 index 0000000..87bd279 Binary files /dev/null and b/trunk/KENJEraser/KENJEraser.bsf differ diff --git a/trunk/KENJEraser/KENJEraser.rsf b/trunk/KENJEraser/KENJEraser.rsf new file mode 100644 index 0000000..d52e186 --- /dev/null +++ b/trunk/KENJEraser/KENJEraser.rsf @@ -0,0 +1,47 @@ +BasicInfo: + Title : KENJEraser + ProductCode: CTR-P-24HA + BackupMemoryType: None + +TitleInfo: + Use: Evaluation + Category: Application + UniqueId: 0xF8037 + Version: 0 + +SystemControlInfo: + AppType : Application + StackSize : 0x4000 + Dependency : + - gpio + - pdn + - spi + - i2c + - mcu + - ptm + - codec + - cfg + - hid + - gsp + - friends + - nim + - ac + - ndm + +AccessControlInfo: + Priority : 16 + DisableDebug : true + + FileSystemAccess: + - Core + + IoAccessControl: + - FsMountTwln + +Option: + FreeProductCode: true + + +Rom: + # ROM に含めるファイルシステムのルートパスを指定します。 + HostRoot: "$(ROMFS_ROOT)" \ No newline at end of file diff --git a/trunk/KENJEraser/OMakefile b/trunk/KENJEraser/OMakefile new file mode 100644 index 0000000..ff50eef --- /dev/null +++ b/trunk/KENJEraser/OMakefile @@ -0,0 +1,68 @@ +#!/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$ +#---------------------------------------------------------------------------- +SUPPORTED_TARGETS = CTR-T*.Process.MPCore.* +CTR_APPTYPE = BOTH +CTR_MAKE_DEVELOPMENT_IMAGE = true + +TARGET_PROGRAM = KENJEraser + +SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/common/include) +INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \ + +SOURCES[] = + main.cpp + ResFont.cpp + HeapManager.cpp + +CTR_BANNER_SPEC = $(TARGET_PROGRAM).bsf + +ROMFS_ROOT = romfiles + +SHADER_BIN = nnfont_RectDrawerShader.shbin +SHADER_PATH = $(ROMFS_ROOT)/$(SHADER_BIN) + +ROMFS_DEPENDENCIES = $(SHADER_PATH) + +LIBS += libnn_cfg \ + libnn_driversEeprom \ + libnn_driversi2c \ + libnn_driversCal \ + libnn_crypto \ + libnn_driversCodec \ + libnn_spi \ + libnn_gpio \ + libnn_pdn \ + libnn_mcu \ + libnn_i2c \ + libnn_driversCamera \ + libnn_ps \ + libnn_driversRsa \ + lib_demo \ + libnn_nwm \ + libnn_friends \ + libnn_ns \ + libnn_am \ + +INSTALL_SDK_TOOL = true + +ROM_SPEC_FILE = $(TARGET_PROGRAM).rsf +DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/RepairTool.desc + +include $(ROOT_OMAKE)/modulerules + +VERSION_H = $(file version.h) + +build: $(DEFAULT_TARGETS) diff --git a/trunk/KENJEraser/OMakeroot b/trunk/KENJEraser/OMakeroot new file mode 100644 index 0000000..875e083 --- /dev/null +++ b/trunk/KENJEraser/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/trunk/KENJEraser/ResFont.cpp b/trunk/KENJEraser/ResFont.cpp new file mode 100644 index 0000000..b0183df --- /dev/null +++ b/trunk/KENJEraser/ResFont.cpp @@ -0,0 +1,417 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: ResFont.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$ + *---------------------------------------------------------------------------*/ + +//------------------------------------------------------------------ +// デモ: ResFont +// +// 概要 +// nn::font::ResFont の構築と破棄のサンプルです。 +// +// 操作 +// なし。 +// +//------------------------------------------------------------------ + +#include +#include +#include +#include +#include + +#include "ResFont.h" +#include "demo.h" +#include "HeapManager.h" + +namespace common +{ + +namespace +{ +const char s_ShaderBinaryFilePath[] = "rom:/nnfont_RectDrawerShader.shbin"; +const char s_FontFilePath[] = "rom:/lc.bcfnt"; + +const u8 s_Color = 255; + +nn::font::RectDrawer s_Drawer; +void* s_DrawerBuf; +nn::font::ResFont s_Font; +nn::font::DispStringBuffer *s_pDrawStringBuf0; +nn::font::TextWriter s_TextWriter; +void (*s_DrawTextFunc)() = NULL; + +//--------------------------------------------------------------------------- +//! @brief シェーダの初期化を行います。 +//! +//! @param[in,out] pResource 描画用リソースを管理するオブジェクトへのポインタ。 +//--------------------------------------------------------------------------- +void* +InitShaders(nn::font::RectDrawer* pDrawer) +{ + nn::fs::FileReader shaderReader(s_ShaderBinaryFilePath); + + const u32 fileSize = (u32)shaderReader.GetSize(); + + void* shaderBinary = HeapManager::GetHeap()->Allocate(fileSize); + NN_NULL_ASSERT(shaderBinary); + +#ifndef NN_BUILD_RELEASE + s32 read = +#endif // NN_BUILD_RELEASE + shaderReader.Read(shaderBinary, fileSize); + NN_ASSERT(read == fileSize); + + const u32 vtxBufCmdBufSize = + nn::font::RectDrawer::GetVertexBufferCommandBufferSize(shaderBinary, fileSize); + void *const vtxBufCmdBuf = HeapManager::GetHeap()->Allocate(vtxBufCmdBufSize); + NN_NULL_ASSERT(vtxBufCmdBuf); + pDrawer->Initialize(vtxBufCmdBuf, shaderBinary, fileSize); + + HeapManager::GetHeap()->Free(shaderBinary); + + return vtxBufCmdBuf; + +} + +//--------------------------------------------------------------------------- +//! @brief 描画の初期設定を行います。 +//! +//! @param[in] width 画面の幅。 +//! @param[in] height 画面の高さ。 +//--------------------------------------------------------------------------- +void +InitDraw( + s32 width, + s32 height +) +{ + // カラーバッファ情報 + // LCDの向きに合わせて、幅と高さを入れ替えています。 + const nn::font::ColorBufferInfo colBufInfo = { width, height, PICA_DATA_DEPTH24_STENCIL8_EXT }; + + const u32 screenSettingCommands[] = + { + + // ビューポートの設定 + NN_FONT_CMD_SET_VIEWPORT( 0, 0, colBufInfo.width, colBufInfo.height ), + + // シザー処理を無効 + NN_FONT_CMD_SET_DISABLE_SCISSOR( colBufInfo ), + + // wバッファの無効化 + // デプスレンジの設定 + // ポリゴンオフセットの無効化 + NN_FONT_CMD_SET_WBUFFER_DEPTHRANGE_POLYGONOFFSET( + 0.0f, // wScale : 0.0 でWバッファが無効 + 0.0f, // depth range near + 1.0f, // depth range far + 0, // polygon offset units : 0.0 で ポリゴンオフセットが無効 + colBufInfo), + }; + + nngxAdd3DCommand(screenSettingCommands, sizeof(screenSettingCommands), true); + + static const u32 s_InitCommands[] = + { + // カリングを無効 + NN_FONT_CMD_SET_CULL_FACE( NN_FONT_CMD_CULL_FACE_DISABLE ), + + // ステンシルテストを無効 + NN_FONT_CMD_SET_DISABLE_STENCIL_TEST(), + + // デプステストを無効 + // カラーバッファの全ての成分を書き込み可 + NN_FONT_CMD_SET_DEPTH_FUNC_COLOR_MASK( + false, // isDepthTestEnabled + 0, // depthFunc + true, // depthMask + true, // red + true, // green + true, // blue + true), // alpha + + // アーリーデプステストを無効 + NN_FONT_CMD_SET_ENABLE_EARLY_DEPTH_TEST( false ), + + // フレームバッファアクセス制御 + NN_FONT_CMD_SET_FBACCESS( + true, // colorRead + true, // colorWrite + false, // depthRead + false, // depthWrite + false, // stencilRead + false), // stencilWrite + }; + + nngxAdd3DCommand(s_InitCommands, sizeof(s_InitCommands), true); +} + +//--------------------------------------------------------------------------- +//! @brief ResFontを構築します。 +//! +//! @param[out] pFont 構築するフォントへのポインタ。 +//! @param[in] filePath ロードするフォントリソースファイル名。 +//! +//! @return ResFont構築の成否を返します。 +//--------------------------------------------------------------------------- +bool +InitFont( + nn::font::ResFont* pFont, + const char* filePath +) +{ + // フォントリソースをロードします + nn::fs::FileReader fontReader(filePath); + + s32 fileSize = (s32)fontReader.GetSize(); + if ( fileSize <= 0 ) + { + return false; + } + + void* buffer = HeapManager::GetHeap()->Allocate(fileSize, nn::font::GlyphDataAlignment); + if (buffer == NULL) + { + return false; + } + + s32 readSize = fontReader.Read(buffer, fileSize); + if (readSize != fileSize) + { + HeapManager::GetHeap()->Free(buffer); + return false; + } + + // フォントリソースをセットします + bool bSuccess = pFont->SetResource(buffer); + NN_ASSERT(bSuccess); + + //--- 既にリソースをセット済みであるか,ロード済みであるか、リソースが不正な場合に失敗します。 + if (! bSuccess) + { + HeapManager::GetHeap()->Free(buffer); + } + + // 描画用バッファを設定します。 + const u32 drawBufferSize = nn::font::ResFont::GetDrawBufferSize(buffer); + void* drawBuffer = HeapManager::GetHeap()->Allocate(drawBufferSize, 4); + NN_NULL_ASSERT(drawBuffer); + pFont->SetDrawBuffer(drawBuffer); + + return bSuccess; +} + +//--------------------------------------------------------------------------- +//! @brief ResFontを破棄します。 +//! +//! @param[in] pFont 破棄するフォントへのポインタ。 +//--------------------------------------------------------------------------- +void +CleanupFont(nn::font::ResFont* pFont) +{ + // 描画用バッファの無効化 + // 描画用バッファがセットされているなら 構築時に SetDrawBuffer に渡したバッファへの + // ポインタが返ってきます。 + void *const drawBuffer = pFont->SetDrawBuffer(NULL); + if (drawBuffer != NULL) + { + HeapManager::GetHeap()->Free(drawBuffer); + } + + // フォントがセットされているなら SetResource 時に渡したリソースへの + // ポインタが返ってきます。 + void *const resource = pFont->RemoveResource(); + if (resource != NULL) + { + HeapManager::GetHeap()->Free(resource); + } + + // RemoveResource 後は再度 SetResource するまでフォントとして使用できません。 +} + +//--------------------------------------------------------------------------- +//! @brief 表示文字列用バッファを確保します。 +//! +//! @param[in] charMax 表示する文字列の最大文字数。 +//! +//! @return 確保した表示文字列用バッファへのポインタを返します。 +//--------------------------------------------------------------------------- +nn::font::DispStringBuffer* +AllocDispStringBuffer(s32 charMax) +{ + const u32 DrawBufferSize = nn::font::CharWriter::GetDispStringBufferSize(charMax); + void *const bufMem = HeapManager::GetHeap()->Allocate(DrawBufferSize); + NN_NULL_ASSERT(bufMem); + + return nn::font::CharWriter::InitDispStringBuffer(bufMem, charMax); +} + +//--------------------------------------------------------------------------- +//! @brief 文字列表示用にモデルビュー行列と射影行列を設定します。 +//! +//! @param[in] pDrawer RectDrawerオブジェクトへのポインタ。 +//! @param[in] width 画面の幅。 +//! @param[in] height 画面の高さ。 +//--------------------------------------------------------------------------- +void +SetupTextCamera( + nn::font::RectDrawer* pDrawer, + s32 width, + s32 height +) +{ + // 射影行列を正射影に設定 + { + // 左上原点とし、Y軸とZ軸の向きが逆になるように設定します。 + nn::math::MTX44 proj; + f32 znear = 0.0f; + f32 zfar = -1.0f; + f32 t = 0; + f32 b = static_cast(width); + f32 l = 0; + f32 r = static_cast(height); + nn::math::MTX44OrthoPivot(&proj, l, r, b, t, znear, zfar, nn::math::PIVOT_UPSIDE_TO_TOP); + pDrawer->SetProjectionMtx(proj); + } + + // モデルビュー行列を単位行列に設定 + { + nn::math::MTX34 mv; + nn::math::MTX34Identity(&mv); + pDrawer->SetViewMtxForText(mv); + } +} + +//--------------------------------------------------------------------------- +//! @brief ASCII文字列を描画します。 +//! +//! @param[in] pDrawer RectDrawerオブジェクトへのポインタ。 +//! @param[in] pDrawStringBuf DispStringBufferオブジェクトへのポインタ。 +//! @param[in] pFont フォントへのポインタ。 +//! @param[in] width 画面の幅。 +//! @param[in] height 画面の高さ。 +//--------------------------------------------------------------------------- +void +DrawAscii( + nn::font::RectDrawer* pDrawer, + nn::font::DispStringBuffer* pDrawStringBuf, + nn::font::ResFont* pFont, + s32 width, + s32 height +) +{ + s_TextWriter.SetDispStringBuffer(pDrawStringBuf); + s_TextWriter.SetFont(pFont); + + s_TextWriter.SetCursor(0, 0, 1.f); + + s_TextWriter.StartPrint(); + if(s_DrawTextFunc != NULL) + { + s_DrawTextFunc(); + } + + s_TextWriter.EndPrint(); + pDrawer->BuildTextCommand(&s_TextWriter); + + + // 文字の色は、文字列の描画コマンドを再作成しなくても変更できます。 + s_TextWriter.SetTextColor(nn::util::Color8(s_Color, s_Color, s_Color, s_Color)); + + pDrawer->DrawBegin(); + + SetupTextCamera(pDrawer, width, height); + s_TextWriter.UseCommandBuffer(); + + pDrawer->DrawEnd(); +} + +} // namespace + +void SetDrawTextHandler(void (*func)()) +{ + s_DrawTextFunc = func; +} + + +//--------------------------------------------------------------------------- +//! @brief サンプルのメイン関数です。 +//--------------------------------------------------------------------------- +void +InitializeResFont() +{ + 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)); + + // フォントの構築 + { +#ifndef NN_BUILD_RELEASE + bool bSuccess = +#endif // NN_BUILD_RELEASE + InitFont(&s_Font, s_FontFilePath); + NN_ASSERTMSG(bSuccess, "Fail to load ResFont."); + } + + // 描画リソースの構築 + s_DrawerBuf = InitShaders(&s_Drawer); + + // 描画文字列用バッファの確保 + s_pDrawStringBuf0 = AllocDispStringBuffer(512); + + nn::fs::Unmount("rom:"); + +} + +void DrawResFont(s32 display) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if(display == NN_GX_DISPLAY0) + { + InitDraw(NN_GX_DISPLAY0_WIDTH, NN_GX_DISPLAY0_HEIGHT); + + DrawAscii(&s_Drawer, s_pDrawStringBuf0, &s_Font, NN_GX_DISPLAY0_WIDTH, NN_GX_DISPLAY0_HEIGHT); + } + else if(display == NN_GX_DISPLAY1) + { + InitDraw(NN_GX_DISPLAY1_WIDTH, NN_GX_DISPLAY1_HEIGHT); + + DrawAscii(&s_Drawer, s_pDrawStringBuf0, &s_Font, NN_GX_DISPLAY1_WIDTH, NN_GX_DISPLAY1_HEIGHT); + } + + nngxUpdateState(NN_GX_STATE_ALL); +} + +void FinalizeResFont() +{ + s_Drawer.Finalize(); + + // 描画リソースの破棄 + HeapManager::GetHeap()->Free(s_DrawerBuf); + + // フォントの破棄 + CleanupFont(&s_Font); + + // 描画文字列用バッファの解放 + HeapManager::GetHeap()->Free(s_pDrawStringBuf0); +} + +nn::font::TextWriter* GetTextWriter() +{ + return &s_TextWriter; +} + +} diff --git a/trunk/KENJEraser/ResFont.h b/trunk/KENJEraser/ResFont.h new file mode 100644 index 0000000..ca53420 --- /dev/null +++ b/trunk/KENJEraser/ResFont.h @@ -0,0 +1,33 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: ResFont.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 RESFONT_H_ +#define RESFONT_H_ + +#include + +namespace common +{ + +void InitializeResFont(); +void DrawResFont(s32 display); +void SetDrawTextHandler(void (*func)()); +nn::font::TextWriter* GetTextWriter(); + + +} + + +#endif /* RESFONT_H_ */ diff --git a/trunk/KENJEraser/banner/model.cbmd b/trunk/KENJEraser/banner/model.cbmd new file mode 100644 index 0000000..f1c7b62 Binary files /dev/null and b/trunk/KENJEraser/banner/model.cbmd differ diff --git a/trunk/KENJEraser/banner/sound.cbsd b/trunk/KENJEraser/banner/sound.cbsd new file mode 100644 index 0000000..f1c7b62 Binary files /dev/null and b/trunk/KENJEraser/banner/sound.cbsd differ diff --git a/trunk/KENJEraser/banner/unknown24x24.ctpk b/trunk/KENJEraser/banner/unknown24x24.ctpk new file mode 100644 index 0000000..794b136 --- /dev/null +++ b/trunk/KENJEraser/banner/unknown24x24.ctpk @@ -0,0 +1 @@ +888yyYyYyyyYyyYyyyyYyYy8 \ No newline at end of file diff --git a/trunk/KENJEraser/banner/unknown48x48.ctpk b/trunk/KENJEraser/banner/unknown48x48.ctpk new file mode 100644 index 0000000..8c7da16 --- /dev/null +++ b/trunk/KENJEraser/banner/unknown48x48.ctpk @@ -0,0 +1 @@ +Y8888ƺ8888YYyyYYޚ޺yY8YyYYޚyY8ޚ8 \ No newline at end of file diff --git a/trunk/KENJEraser/main.cpp b/trunk/KENJEraser/main.cpp new file mode 100644 index 0000000..ac8f7e2 --- /dev/null +++ b/trunk/KENJEraser/main.cpp @@ -0,0 +1,329 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: main.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 +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "demo.h" +#include "ResFont.h" +#include "HeapManager.h" + +#define UTIL_RETURN_IF_NOT_AM_NOT_FOUND(result) \ + if(result.IsFailure()) \ + { \ + if(result != nn::am::ResultNotFound()) \ + { \ + return result; \ + } \ + nn::dbg::PrintResult(result); \ +} \ + +namespace { + const char* const NAND_TWL_ARCHIVE_NAME = "twln:"; + const char* const NAND_TWL_KENJ_DIR_PATHNAME = "twln:/title/00030004/4b454e4a"; + const char* const NAND_TWL_KENJ_SAVE_DATA_PATHNAME = "twln:/title/00030004/4b454e4a/data/Public.sav"; + + // 乱数生成クラス + // 線形合同法を用いて乱数を生成する。 + class Random + { + private: + nn::util::Int64 m_x; //!< 乱数値 + nn::util::Int64 m_mul; //!< 乗数 + nn::util::Int64 m_add; //!< 加算する数 + + public: + Random(u64 seed = 0) + { + SetSeed(seed); + } + + void SetSeed(u64 seed) + { + m_x = seed; + m_mul = (1566083941LL << 32) + 1812433253LL; + m_add = 2531011; + } + + u32 Get32(u32 max = 0xFFFFFFFFU) + { + m_x = m_mul * m_x + m_add; + + if (max != 0) + { + return (u32)(((m_x >> 32) * max) >> 32); + } + return 0; + } + }; + + nn::Result DeleteKENJ(void); + void FatalDrawing(nn::Result result); + + const size_t ERASE_THREAD_STACK_SIZE = 0x1000; + nn::os::Thread s_EraseThread; + nn::os::StackBuffer s_EraseThreadStack; + + demo::RenderSystemDrawing s_RenderSystem; + + // グラフィックスに割り当てるメモリ + const size_t s_GxHeapSize = 0x800000; + + ::std::vector* s_pOperationMessage; + + + void EraseThreadFunc(void) + { + nn::Result result; + + s_pOperationMessage->push_back(std::string("")); + + // ほぼ日健康手帳を消去する + result = DeleteKENJ(); + + if(result.IsFailure()) + { + nn::dbg::PrintResult(result); + s_pOperationMessage->push_back(std::string("Failed Delete Program")); + FatalDrawing(result); + } + + s_pOperationMessage->push_back(std::string("")); + s_pOperationMessage->push_back(std::string("Finished.")); + s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 0, 1, 0, 0); + s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 0, 1, 0, 0); + } + + + nn::Result FillRandamDataToKENJSaveData(void) + { + nn::Result result; + nn::fs::FileStream file; + s64 file_size; + + // セーブデータオープン + result = file.TryInitialize( NAND_TWL_KENJ_SAVE_DATA_PATHNAME, nn::fs::OPEN_MODE_WRITE ); + if( result.IsFailure() ) + { + return result; + } + + // セーブデータファイルのサイズを読む + result = file.TryGetSize( &file_size ); + NN_LOG("save data size : %d\n", file_size); + if( result.IsFailure() ) + { + file.Finalize(); + return result; + } + + nn::fnd::TimeSpan ts; + nn::fnd::DateTime tm; + nn::os::Tick tick; + Random rand; + u64 seed; + s32 sizeResult = 0; + + // バッファの確保 + void *buf = std::malloc( file_size ); + NN_TPANIC_IF_NULL_( buf ); + + // 乱数のシードを設定 + // [TODO]シードをちゃんと決める + seed = (u64)(ts.GetMilliSeconds() ^ tick.GetSystemCurrent()); + // NN_LOG("Time Span MilliSec : %x\n", ts.GetMilliSeconds()); + // NN_LOG("Get System Current Tick : %x\n", tick.GetSystemCurrent()); + NN_LOG("seed : %d\n", seed); + rand.SetSeed( seed ); + + // バッファを乱数で埋める + u8 *p = (u8 *)buf; + for (s32 loopSizeFile = 0; loopSizeFile < file_size; loopSizeFile++) + { + p[loopSizeFile] = (u8)rand.Get32(0xff); + } + + // 書き込み + result = file.TryWrite( &sizeResult, buf, file_size); + if( file_size != sizeResult ) + { + NN_LOG("Write Failed...\n"); + NN_LOG("File Size : %d\n", file_size); + NN_LOG("Write Size : %d\n", sizeResult); + } + + NN_LOG("Save Data Fill Success!\n"); + + file.Finalize(); + + return result; + } + + + nn::Result DeleteKENJ(void) + { + nn::Result result; + + // TWl領域をマウントする + result = nn::fs::MountSpecialArchive( NAND_TWL_ARCHIVE_NAME, nn::fs::CTR::ARCHIVE_TYPE_TWL_NAND ); + if( result.IsFailure() ) + { + NN_LOG("Twl NAND Mount Failed...\n"); + return result; + } + + // アプリが存在するかどうか確かめる + nn::fs::Directory dir; + if( dir.TryInitialize(NAND_TWL_KENJ_DIR_PATHNAME).IsFailure() ) + { + s_pOperationMessage->push_back(std::string("KENJ is not Exist\n")); + dir.Finalize(); + } + else + { + s_pOperationMessage->push_back(std::string("Deleting...")); + + // ここでfinalizeしておかないと、DeleteProgramでフェータルになる。 + dir.Finalize(); + + // ほぼ日健康手帳のセーブデータを乱数で埋める + result = FillRandamDataToKENJSaveData(); + + // ほぼ日健康手帳を消す + result = nn::am::DeleteProgram(nn::fs::MEDIA_TYPE_NAND, 0x000480044b454e4aULL); + UTIL_RETURN_IF_NOT_AM_NOT_FOUND(result); + } + + nn::fs::Unmount( "twln:" ); + + return result; + } + + + void SetTextWriterCore() + { + using namespace common; + + GetTextWriter()->Print("KENJ Eraser\n\n"); + ::std::vector::iterator it; + for (it = s_pOperationMessage->begin(); it != s_pOperationMessage->end(); it++) + { + GetTextWriter()->Printf("%s\n", it->c_str()); + } + + } + + void FatalDrawing(nn::Result result) + { + char resultStr[32]; + std::snprintf(resultStr, sizeof(resultStr), "%X", result.GetPrintableBits()); + s_pOperationMessage->push_back(resultStr); + + for(;;) + { + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0); + s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 1.f, 0, 0, 0); + s_RenderSystem.Clear(); + + common::SetDrawTextHandler(SetTextWriterCore); + common::DrawResFont(NN_GX_DISPLAY0); + s_RenderSystem.SwapBuffers(); + + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1); + s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 1.f, 0, 0, 0); + s_RenderSystem.Clear(); + + s_RenderSystem.SwapBuffers(); + } + } +} + +extern "C" void nnMain(void) +{ + // os の初期化 + nn::os::Initialize(); + + // fs の初期化 + nn::fs::Initialize(); + + // appletの初期化 + nn::applet::Enable( false ); + + // hid の初期化 + nn::Result result = nn::hid::Initialize(); + NN_UTIL_PANIC_IF_FAILED(result); + + // cfg の初期化 + nn::cfg::CTR::init::Initialize(); + + // am の初期化 + nn::am::InitializeForLocalImporter(); + + // ヒープの確保 + common::HeapManager::GetHeap()->Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize(), nn::os::ALLOCATE_OPTION_LINEAR); + + // RenderSystem の準備 + uptr heapForGx = reinterpret_cast(common::HeapManager::GetHeap()->Allocate(s_GxHeapSize)); + s_RenderSystem.Initialize(heapForGx, s_GxHeapSize); + + // ResFontの初期化 + common::InitializeResFont(); + + std::vector operationMessage; + s_pOperationMessage = &operationMessage; + + s_EraseThread.Start(EraseThreadFunc, s_EraseThreadStack); + + // ボタン入力 + nn::hid::PadReader padReader; + nn::hid::PadStatus padStatus; + + s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 0, 0, 0, 0); + s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 0, 0, 0, 0); + + for(;;) + { + padReader.ReadLatest(&padStatus); + + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0); + s_RenderSystem.Clear(); + + common::SetDrawTextHandler(SetTextWriterCore); + common::DrawResFont(NN_GX_DISPLAY0); + s_RenderSystem.SwapBuffers(); + + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1); + s_RenderSystem.Clear(); + s_RenderSystem.SwapBuffers(); + nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(10)); + + if ( nn::applet::IsExpectedToCloseApplication() ) + { + nn::applet::PrepareToCloseApplication(); + nn::applet::CloseApplication(); + } + } +} diff --git a/trunk/KENJEraser/romfiles/lc.bcfnt b/trunk/KENJEraser/romfiles/lc.bcfnt new file mode 100644 index 0000000..28d1db0 Binary files /dev/null and b/trunk/KENJEraser/romfiles/lc.bcfnt differ diff --git a/trunk/KENJEraser/romfiles/nnfont_RectDrawerShader.shbin b/trunk/KENJEraser/romfiles/nnfont_RectDrawerShader.shbin new file mode 100644 index 0000000..4290c2c Binary files /dev/null and b/trunk/KENJEraser/romfiles/nnfont_RectDrawerShader.shbin differ