XボタンでデバイスIDをQRコード表示できるように

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@661 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2012-03-12 07:31:40 +00:00
parent 3f8e0e568a
commit 707ab24a28
9 changed files with 395 additions and 134 deletions

View File

@ -275,18 +275,18 @@ extern "C" void nnMain(void)
renderSystem.SwapBuffers();
// デフォルトで下画面に描画するもの
renderSystem.SetRenderTarget(common::GetRenderTarget(NN_GX_DISPLAY1, flip));
renderSystem.SetRenderTarget(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip));
if(IsBackupSucceeded())
{
renderSystem.SetClearColor(common::GetRenderTarget(NN_GX_DISPLAY1, flip), SUCCESS_COLOR);
renderSystem.SetClearColor(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip), SUCCESS_COLOR);
}
if(IsBackupWarning())
{
renderSystem.SetClearColor(common::GetRenderTarget(NN_GX_DISPLAY1, flip), WARN_COLOR);
renderSystem.SetClearColor(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip), WARN_COLOR);
}
else if(IsBackupFailed())
{
renderSystem.SetClearColor(common::GetRenderTarget(NN_GX_DISPLAY1, flip), FAIL_COLOR);
renderSystem.SetClearColor(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip), FAIL_COLOR);
}
renderSystem.Clear();
renderSystem.SetColor(1.f, 1.f, 1.f);

View File

@ -48,6 +48,7 @@
#include "ResFont.h"
#include "HardwareStateManager.h"
#include "OperationMessage.h"
#include "QrImage.h"
// バージョン表示用
#include "version.h"
@ -179,6 +180,7 @@ extern "C" void nnMain(void)
bool flip = false;
bool qr = false;
InitializeState();
for(;;)
@ -210,6 +212,12 @@ extern "C" void nnMain(void)
flip = !flip;
}
// Xボタンでモード切替
if(padStatus.trigger & nn::hid::BUTTON_X)
{
qr = !qr;
}
// コンソールスクロール
if(padStatus.hold & nn::hid::BUTTON_UP)
{
@ -249,110 +257,100 @@ extern "C" void nnMain(void)
common::OperationMessage operationMessage;
ControlState(manager, operationMessage, nextStep, operateBmsDone, forcePreinstall);
nn::util::FloatColor titleColor;
if(GetRestoreMode() == RESTORE_MODE_RESTORE)
if(qr)
{
titleColor.r = 0.1f;
titleColor.g = 0.25f;
titleColor.b = 0.1f;
}
else if(GetRestoreMode() == RESTORE_MODE_NUP_ONLY)
{
titleColor.r = 0.35f;
titleColor.g = 0.35f;
titleColor.b = 0.f;
}
else if(GetRestoreMode() == RESTORE_MODE_GET_IVS)
{
titleColor.r = 1.0f;
titleColor.g = 0.2f;
titleColor.b = 0.2f;
}
else if(GetRestoreMode() == RESTORE_MODE_CHECK_SD)
{
titleColor.r = 0.2f;
titleColor.g = 0.2f;
titleColor.b = 1.2f;
}
else if(GetRestoreMode() == RESTORE_MODE_DOWNLOAD_PREINSTALL)
{
titleColor.r = 1.0f;
titleColor.g = 0.55f;
titleColor.b = 1.0f;
}
// 上画面表示
common::DrawSystemState("CTR Console Restore",
s_RenderSystem,
titleColor,
flip,
adapterState,
s_HwUtility.GetCupMajorVersion(),
s_HwUtility.GetCupMinorVersion(),
s_HwUtility.GetCupMicroVersion(),
s_HwUtility.GetNupVersion(),
s_HwUtility.GetBatteryRemain(),
s_HwUtility.GetInfraDeviceId(),
s_HwUtility.GetFriendcode(),
GetProgress(),
IsRestoreFailed(),
IsRestoreSucceeded(),
false,
s_HwUtility.GetMacAddress(),
operationMessage,
s_HwUtility.GetRegion(),
s_HwUtility.GetSerialNumber(),
s_HwUtility.HasReadFriendCode()
);
if (GetRestoreMode() != RESTORE_MODE_RESTORE)
{
const u8 spaceSize = 10;
const u8 lineBottom = 23;
const u32 screenWidth = 400;
s_RenderSystem.SetColor(1.f, 1.f, 1.f);
if (GetRestoreMode() == RESTORE_MODE_NUP_ONLY)
{
s_RenderSystem.DrawText(0, lineBottom * spaceSize, "NUP-Only Mode");
}
else if (GetRestoreMode() == RESTORE_MODE_GET_IVS)
{
s_RenderSystem.DrawText(0, lineBottom * spaceSize, "GET-SDCI Mode");
}
else if (GetRestoreMode() == RESTORE_MODE_CHECK_SD)
{
s_RenderSystem.DrawText(0, lineBottom * spaceSize, "CHECK-SD Mode");
}
else if (GetRestoreMode() == RESTORE_MODE_DOWNLOAD_PREINSTALL)
{
s_RenderSystem.DrawText(0, lineBottom * spaceSize, "DL_PREINATALL Mode");
}
s_RenderSystem.SetColor(titleColor.r, titleColor.g, titleColor.b);
s_RenderSystem.FillRectangle(0, lineBottom * spaceSize, screenWidth, spaceSize);
s_RenderSystem.SetColor(1.f, 1.f, 1.f);
}
s_RenderSystem.SwapBuffers();
// デフォルトで下画面に描画するもの
s_RenderSystem.SetRenderTarget(common::GetRenderTarget(NN_GX_DISPLAY1, flip));
if(IsRestoreSucceeded())
{
s_RenderSystem.SetClearColor(common::GetRenderTarget(NN_GX_DISPLAY1, flip), SUCCESS_COLOR);
}
else if(IsRestoreFailed())
{
s_RenderSystem.SetClearColor(common::GetRenderTarget(NN_GX_DISPLAY1, flip), FAIL_COLOR);
common::QrImage::Draw(s_RenderSystem, s_HwUtility.GetInfraDeviceId(), flip);
}
else
{
s_RenderSystem.SetClearColor(common::GetRenderTarget(NN_GX_DISPLAY1, flip), NORMAL_COLOR);
ControlState(manager, operationMessage, nextStep, operateBmsDone, forcePreinstall);
nn::util::FloatColor titleColor;
if (GetRestoreMode() == RESTORE_MODE_RESTORE)
{
titleColor.r = 0.1f;
titleColor.g = 0.25f;
titleColor.b = 0.1f;
}
else if (GetRestoreMode() == RESTORE_MODE_NUP_ONLY)
{
titleColor.r = 0.35f;
titleColor.g = 0.35f;
titleColor.b = 0.f;
}
else if (GetRestoreMode() == RESTORE_MODE_GET_IVS)
{
titleColor.r = 1.0f;
titleColor.g = 0.2f;
titleColor.b = 0.2f;
}
else if (GetRestoreMode() == RESTORE_MODE_CHECK_SD)
{
titleColor.r = 0.2f;
titleColor.g = 0.2f;
titleColor.b = 1.2f;
}
else if (GetRestoreMode() == RESTORE_MODE_DOWNLOAD_PREINSTALL)
{
titleColor.r = 1.0f;
titleColor.g = 0.55f;
titleColor.b = 1.0f;
}
// 上画面表示
common::DrawSystemState("CTR Console Restore", s_RenderSystem, titleColor, flip, adapterState,
s_HwUtility.GetCupMajorVersion(), s_HwUtility.GetCupMinorVersion(),
s_HwUtility.GetCupMicroVersion(), s_HwUtility.GetNupVersion(), s_HwUtility.GetBatteryRemain(),
s_HwUtility.GetInfraDeviceId(), s_HwUtility.GetFriendcode(), GetProgress(), IsRestoreFailed(),
IsRestoreSucceeded(), false, s_HwUtility.GetMacAddress(), operationMessage, s_HwUtility.GetRegion(),
s_HwUtility.GetSerialNumber(), s_HwUtility.HasReadFriendCode());
if (GetRestoreMode() != RESTORE_MODE_RESTORE)
{
const u8 spaceSize = 10;
const u8 lineBottom = 23;
const u32 screenWidth = 400;
s_RenderSystem.SetColor(1.f, 1.f, 1.f);
if (GetRestoreMode() == RESTORE_MODE_NUP_ONLY)
{
s_RenderSystem.DrawText(0, lineBottom * spaceSize, "NUP-Only Mode");
}
else if (GetRestoreMode() == RESTORE_MODE_GET_IVS)
{
s_RenderSystem.DrawText(0, lineBottom * spaceSize, "GET-SDCI Mode");
}
else if (GetRestoreMode() == RESTORE_MODE_CHECK_SD)
{
s_RenderSystem.DrawText(0, lineBottom * spaceSize, "CHECK-SD Mode");
}
else if (GetRestoreMode() == RESTORE_MODE_DOWNLOAD_PREINSTALL)
{
s_RenderSystem.DrawText(0, lineBottom * spaceSize, "DL_PREINATALL Mode");
}
s_RenderSystem.SetColor(titleColor.r, titleColor.g, titleColor.b);
s_RenderSystem.FillRectangle(0, lineBottom * spaceSize, screenWidth, spaceSize);
s_RenderSystem.SetColor(1.f, 1.f, 1.f);
}
}
s_RenderSystem.SwapBuffers();
// デフォルトで下画面に描画するもの
s_RenderSystem.SetRenderTarget(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip));
if(IsRestoreSucceeded())
{
s_RenderSystem.SetClearColor(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip), SUCCESS_COLOR);
}
else if(IsRestoreFailed())
{
s_RenderSystem.SetClearColor(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip), FAIL_COLOR);
}
else
{
s_RenderSystem.SetClearColor(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip), NORMAL_COLOR);
}
s_RenderSystem.Clear();
s_RenderSystem.SetColor(1.f, 1.f, 1.f);

View File

@ -20,6 +20,7 @@ TARGET_PROGRAM = ConsoleRestore
SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/common/include)
INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \
$(dir $(CTRMW_QRE_ROOT)/include/mw/qre) \
../common
SOURCES[] =
@ -50,6 +51,7 @@ SOURCES[] =
../common/HardwareStateManager.cpp
../common/SaveDataMover.cpp
../common/OperationMessage.cpp
../common/QrImage.cpp
include $(ROOT)/common/BuildSwitch.om
@ -74,6 +76,9 @@ LIBS += libnn_cfg \
libnn_nim \
libnn_xml_simple \
QRE_LIBRARIES[] = libmw_qre
LIBFILES += $`(addprefix $(CTRMW_QRE_ROOT)$(DIRSEP)$(SUBDIR_LIBRARIES)$(DIRSEP)$(config.getTargetSubDirectory true)$(DIRSEP), $(QRE_LIBRARIES)) \
INSTALL_SDK_TOOL = true
ROM_SPEC_FILE = $(TARGET_NAME).rsf

View File

@ -44,25 +44,6 @@ bool s_ReadFriendCode;
}
u32 GetRenderTarget(u32 target, bool flip)
{
if(flip)
{
if(target == NN_GX_DISPLAY0)
{
return NN_GX_DISPLAY1;
}
else
{
return NN_GX_DISPLAY0;
}
}
else
{
return target;
}
}
void SetTextWriterCore()
{
GetTextWriter()->SetTextColor(nn::util::Color8(255, 255, 255, 255));
@ -142,22 +123,22 @@ void DrawSystemState
// デフォルトで上画面に描画するもの
renderSystem.SetRenderTarget(GetRenderTarget(NN_GX_DISPLAY0, flip));
renderSystem.SetRenderTarget(Util::GetRenderTarget(NN_GX_DISPLAY0, flip));
if (isProcessSucceeded)
{
renderSystem.SetClearColor(GetRenderTarget(NN_GX_DISPLAY0, flip), SUCCESS_COLOR);
renderSystem.SetClearColor(Util::GetRenderTarget(NN_GX_DISPLAY0, flip), SUCCESS_COLOR);
}
else if (isProcessWarning)
{
renderSystem.SetClearColor(GetRenderTarget(NN_GX_DISPLAY0, flip), WARN_COLOR);
renderSystem.SetClearColor(Util::GetRenderTarget(NN_GX_DISPLAY0, flip), WARN_COLOR);
}
else if (isProcessFailed)
{
renderSystem.SetClearColor(GetRenderTarget(NN_GX_DISPLAY0, flip), FAIL_COLOR);
renderSystem.SetClearColor(Util::GetRenderTarget(NN_GX_DISPLAY0, flip), FAIL_COLOR);
}
else
{
renderSystem.SetClearColor(GetRenderTarget(NN_GX_DISPLAY0, flip), NORMAL_COLOR);
renderSystem.SetClearColor(Util::GetRenderTarget(NN_GX_DISPLAY0, flip), NORMAL_COLOR);
}
@ -169,7 +150,7 @@ void DrawSystemState
size_t fontheight = fontwidth + 2;
SetDrawTextHandler(SetTextWriterCore);
DrawResFont(GetRenderTarget(NN_GX_DISPLAY0, flip));
DrawResFont(Util::GetRenderTarget(NN_GX_DISPLAY0, flip));
renderSystem.SetFontSize(fontwidth);

View File

@ -45,11 +45,6 @@
namespace common
{
// 現在の描画先ディスプレイを返す
// target NN_GX_DISPLAY0 または NN_GX_DISPLAY1
// flip 上下画面を入れ替えているかどうか
u32 GetRenderTarget(u32 target, bool flip = false);
// システム状態を描画する
// InitializeResFont()、demo::RenderSystemDrawing.Initializeが呼び出されている必要がある
void DrawSystemState

View File

@ -0,0 +1,213 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: QrImage.cpp
Copyright 2009-2011 Nintendo. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Rev$
*---------------------------------------------------------------------------*/
#include "QrImage.h"
#include "HeapManager.h"
#include "Util.h"
#include <qre.h>
namespace common
{
QrImage::QrImage()
{
// TODO 自動生成されたコンストラクター・スタブ
}
QrImage::~QrImage()
{
// TODO Auto-generated destructor stub
}
void QrImage::Draw(demo::RenderSystemDrawing& renderSystem, bit64 deviceId, bool flip)
{
using namespace mw::qre;
char deviceIdStr[32];
QREncoder *encoder = new QREncoder;
nn::nstd::TSNPrintf(deviceIdStr, sizeof(deviceIdStr), "%llu", deviceId);
u32 dataSize = std::strlen(deviceIdStr);
u32 requiredMemorySize = QREncoder::GetEncodeBufferSize(dataSize, 3, 1);
common::HeapManager heap(requiredMemorySize);
if(!heap.GetAddr())
{
NN_LOG("not enough memory\n");
return;
}
encoder->InitMemory(heap.GetAddr(), requiredMemorySize);
/* 作成するQRコードの情報を設定 */
EncodeData info;
/* バージョンは15とする */
info.version = 12;
/* 誤り訂正レベルH */
info.ecc_level = ECC_LEVEL_H;
/* コンテンツ文字列の情報 */
info.size = dataSize;
info.data = reinterpret_cast<u8*>(deviceIdStr);
/*
*
*
*/
info.total = 0;
/* セルのサイズ設定 */
info.cell_size = 3;
/* エンコード実行 */
if (!encoder->Encode(&info))
{
/* エンコードに失敗 */
NN_LOG("QR encode failed...\n");
}
int qr_size = encoder->GetQRSize(0, false);
ImageInfo QRImage;
QRImage.rgb888Data = reinterpret_cast<u8*>(common::ForceAllocate(qr_size));
if (!QRImage.rgb888Data) {
NN_LOG("Memory allocation failed...\n");
return;
}
if(!encoder->GetQRData(&QRImage, 0))
{
NN_LOG("Get QRData Failed\n");
return;
}
delete encoder;
renderSystem.SetRenderTarget(Util::GetRenderTarget(NN_GX_DISPLAY0, flip));
renderSystem.Clear();
DrawImage(renderSystem, QRImage.rgb888Data, QRImage.width, QRImage.height, flip);
common::ForceFree(QRImage.rgb888Data);
}
void QrImage::DrawImage(demo::RenderSystemDrawing& renderSystem, u8* textureDataPtr, u32 width, u32 height, bool flip)
{
static GLuint textureId = 0;
if (textureId != 0)
{
renderSystem.DeleteTexture(textureId);
}
GLenum target = GL_TEXTURE_2D;
GLenum internalFormat = GL_RGB_NATIVE_DMP;
GLenum format = GL_RGB_NATIVE_DMP;
GLenum type = GL_UNSIGNED_BYTE;
u32 textureWidth = width;
u32 textureHeight = height;
u8* textureDataBuffer = GetTextureDataFromRawData(width, height,
textureDataPtr,
textureWidth,
textureHeight);
renderSystem.GenerateTexture(target, internalFormat, textureWidth, textureHeight,
format, type, textureDataBuffer, textureId);
common::ForceFree(textureDataBuffer);
f32 windowPositionX = 0.0f;
f32 windowPositionY = 0.0f;
if (!flip)
{
windowPositionX = (nn::gx::DISPLAY0_HEIGHT / 2) - (width / 2);
if (height < nn::gx::DISPLAY0_WIDTH)
{
windowPositionY = (nn::gx::DISPLAY0_WIDTH / 2) - (height / 2);
}
}
else
{
windowPositionX = (nn::gx::DISPLAY1_HEIGHT / 2) - (width / 2);
if (height < nn::gx::DISPLAY1_WIDTH)
{
windowPositionY = (nn::gx::DISPLAY1_WIDTH / 2) - (height / 2);
}
}
f32 rectangleWidth = static_cast<f32>(width);
f32 rectangleHeight = static_cast<f32>(height);
renderSystem.FillTexturedRectangle(textureId,
windowPositionX, windowPositionY,
rectangleWidth, rectangleHeight,
static_cast<f32>(width),
static_cast<f32>(height),
static_cast<f32>(textureWidth),
static_cast<f32>(textureHeight));
}
u8* QrImage::GetTextureDataFromRawData(const u32& width,
const u32& height,
u8* rawDataBuffer,
u32& textureWidth,
u32& textureHeight)
{
textureWidth = GetTextureLength(width);
textureHeight = GetTextureLength(height);
u32 textureSize = textureWidth * textureHeight * 3;
u8* textureGLDataBuffer = reinterpret_cast<u8*>(common::ForceAllocate(textureSize));
u8* dstPtr = textureGLDataBuffer;
u32 y = 0;
for (; y < height; y++) {
// FLIP対応
// ConvertGLTextureToNative()にてFLIPしている。
u8* srcPtr = rawDataBuffer + width * (height - y - 1) * 3;
u32 x = 0;
for (; x < width; x++) {
dstPtr[0] = srcPtr[2];
dstPtr[1] = srcPtr[1];
dstPtr[2] = srcPtr[0];
dstPtr += 3;
srcPtr += 3;
}
for (; x < textureWidth; x++) {
dstPtr[0] = dstPtr[1] = dstPtr[2] = 0x00;
dstPtr += 3;
}
}
for (; y < textureHeight; y++) {
for (u32 x = 0; x < textureWidth; x++) {
dstPtr[0] = dstPtr[1] = dstPtr[2] = 0x00;
dstPtr += 3;
}
}
u8* textureDataBuffer = reinterpret_cast<u8*>(common::ForceAllocate(textureSize));
GLenum format = GL_RGB_NATIVE_DMP;
bool result = demo::ConvertGLTextureToNative(format, textureWidth, textureHeight,
textureGLDataBuffer, textureDataBuffer);
if (!result) {
NN_LOG(" Convert to GL_RGB_NATIVE_DMP failed.\n");
NN_ASSERT(0);
}
common::ForceFree(textureGLDataBuffer);
return textureDataBuffer;
}
u32 QrImage::GetTextureLength(const u32& imageLength)
{
u32 textureLength = 8;
// 8, 16, 32, 64, 128, 256, 512, 1024
for (u32 i = 0; i < 7; i++) {
if (imageLength < textureLength)
return textureLength;
textureLength *= 2;
}
return 1024;
}
} /* namespace common */

View File

@ -0,0 +1,45 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: QrImage.h
Copyright 2009-2011 Nintendo. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Rev$
*---------------------------------------------------------------------------*/
#ifndef QRIMAGE_H_
#define QRIMAGE_H_
#include <nn.h>
#include "demo.h"
namespace common
{
class QrImage
{
public:
QrImage();
virtual ~QrImage();
static void Draw(demo::RenderSystemDrawing& renderSystem, bit64 deviceId, bool flip);
private:
static void DrawImage(demo::RenderSystemDrawing& renderSystem, u8* textureDataPtr, u32 width, u32 height, bool flip);
static u8* GetTextureDataFromRawData(const u32& width,
const u32& height,
u8* rawDataBuffer,
u32& textureWidth,
u32& textureHeight);
static u32 GetTextureLength(const u32& imageLength);
};
} /* namespace common */
#endif /* QRIMAGE_H_ */

View File

@ -386,6 +386,25 @@ void Util::SplitDeviceidWithSpace(std::string& deviceIdStr)
}while( i < tmp.size());
}
u32 Util::GetRenderTarget(u32 target, bool flip)
{
if(flip)
{
if(target == NN_GX_DISPLAY0)
{
return NN_GX_DISPLAY1;
}
else
{
return NN_GX_DISPLAY0;
}
}
else
{
return target;
}
}
nn::Result PrintNetworkSetting()
{
nn::Result result;

View File

@ -114,6 +114,11 @@ public:
// デバイスIDを4文字ごとに空白で区切る
static void SplitDeviceidWithSpace(std::string& deviceIdStr);
// 現在の描画先ディスプレイを返す
// target NN_GX_DISPLAY0 または NN_GX_DISPLAY1
// flip 上下画面を入れ替えているかどうか
static u32 GetRenderTarget(u32 target, bool flip = false);
private:
void Initialize();
void Finalize();