ほぼ日健康手帳削除ツールコミット

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@267 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2205 2011-05-23 12:54:57 +00:00
parent b6147c5266
commit d246b688b8
15 changed files with 1048 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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 <nn.h>
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_ */

Binary file not shown.

View File

@ -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)"

View File

@ -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)

View File

@ -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: .

View File

@ -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 <nn.h>
#include <nn/fs.h>
#include <nn/font.h>
#include <nn/math.h>
#include <nn/util.h>
#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<f32>(width);
f32 l = 0;
f32 r = static_cast<f32>(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 <unnnamed>
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;
}
}

View File

@ -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 <nn/font.h>
namespace common
{
void InitializeResFont();
void DrawResFont(s32 display);
void SetDrawTextHandler(void (*func)());
nn::font::TextWriter* GetTextWriter();
}
#endif /* RESFONT_H_ */

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫фВ╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫ф8ф8фШчГГГГГГВВ╫8фВВВВВГГГГшчфГШФВ╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫фВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВ╫yнВ╫yнВВВВВ╫YнВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВГГГГШчyнYнВ╫шчшчВВфВВ╫шчyнШчВ╫yнГГГГyнШФГГГГГшчВВВВ╫YнГyнГВВВВВ╫yнфшчГШФГYнyнВВВ╫yнВ╫╨жВВВВВ╫yнВ╫yнВВВВВ╫YнВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВ╫yнГYнГВ╫В╫В╫В╫В╫фВ╫В╫ГyнГ8фВВВВфВ╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫

View File

@ -0,0 +1 @@
ВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВ╫YнВВВВВВВВВВВВВВВВВВВВВВВВВВВ╫8фВВ╫8ф8фВВВ╫╨ж8ф╨жГГшчГГГГГГГГГГГГГГГГГГГГГГГВВВВВВВВВВ╫8ф8фВВфВ╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫ГГГГГШФГГГГГГГГГГ жфГГВ╫В╫ жВ╫ГГГГГ жГГВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВ╫8фВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВ╫шчВ╫шчВВВВВГВ╫ШчВ╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫╨жВ╫В╫В╫В╫В╫В╫В╫В╫В╫В╫ГГГГГГГГГГГГГГГГГГШФ8фШчшчВВ жВ╫YнВВВВВГГYнyнГГyнфВ╫В╫В╫В╫В╫В╫В╫В╫фВ╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫шчшчГшчШФВ╫В╫ГГYнГВ╫В╫В╫В╫В╫шчВ╫шчГГГГГГГГГГГГГГГГВВ╫YнШч жГГГГГГГГГГГГГГГГГГГГГГГГшч╨жВ жВ╫шчВВВВВ╫ШФВ╫ШФВВВВВВВВВВВВВВВВВВВВВ╫шчВ╫yнВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВ╫YнВ жГГГГВ╫шчВ╫шчГГГГВВВВВВВВВВВВВВВВВ╫8фВВ╫╨жшчВВВВВ╫YнфyнГГГГГГГГГ жГГГГ╨жВ╫YнВ╫ШФYнВВВВВВВВВВВВВВ╫шч жВВВВВВ╫yнВГШФВ╫В╫фВ╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫В╫ШФВ╫ГГГГГВ╫ШчВ╫YнГГШФГВВВВВВВВВВВВВВВВВВВВВ╫8фВВВВВВВВВВГГГГ жВ╫шчВ╫ГГГшч жВВВВВВВВВВВВВВВВВВВ╫8фВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВВ

329
trunk/KENJEraser/main.cpp Normal file
View File

@ -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 <nn.h>
#include <nn/fnd.h>
#include <nn/am/am_ApiLocalImporter.h>
#include <nn/am/am_ApiSystemMenu.h>
#include <nn/am/am_Result.h>
#include <nn/cfg/CTR/cfg_Api.h>
#include <nn/cfg/CTR/cfg_ApiInit.h>
#include <nn/cfg/CTR/cfg_ApiSys.h>
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
#include <vector>
#include <string>
#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<u64> m_x; //!< 乱数値
nn::util::Int64<u64> m_mul; //!< 乗数
nn::util::Int64<u64> 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<ERASE_THREAD_STACK_SIZE> s_EraseThreadStack;
demo::RenderSystemDrawing s_RenderSystem;
// グラフィックスに割り当てるメモリ
const size_t s_GxHeapSize = 0x800000;
::std::vector<std::string>* 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<std::string>::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<uptr>(common::HeapManager::GetHeap()->Allocate(s_GxHeapSize));
s_RenderSystem.Initialize(heapForGx, s_GxHeapSize);
// ResFontの初期化
common::InitializeResFont();
std::vector<std::string> 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();
}
}
}

Binary file not shown.