ctr_Repair/trunk/FlickerCfgChanger/main.cpp
N2614 5bc638d35a cfgのLCDフリッカ値を変更するツールを追加
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@425 385bec56-5757-e545-9c3a-d8741f4650f1
2011-09-08 05:46:14 +00:00

302 lines
9.3 KiB
C++

/*---------------------------------------------------------------------------*
Project: Horizon
File: main.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 <nn.h>
#include <nn/hid/CTR/hid_ApiWithPrivilege.h>
#include <nn/srv.h>
#include <nn/applet.h>
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
#include <nn/drivers/cal/CTR/cal_Api.h>
#include <nn/cfg.h>
#include <nn/cfg/CTR/cfg_Api.h>
#include <nn/cfg/CTR/cfg_ApiInit.h>
#include <nn/cfg/CTR/cfg_ApiSys.h>
#include <nn/cfg/CTR/detail/cfg_SecureInfo.h>
#include <nn/cfg/CTR/detail/cfg_Keys.h>
#include <nn/nstd.h>
#include "demo.h"
#define HANDLE_ERROR(result) \
if(result.IsFailure()) \
{ \
DrawError(result, __LINE__); \
} \
namespace
{
nn::drivers::cal::CTR::LcdFlickerInfo s_LcdFlickerInfo;
bool s_LcdFlickerInfoIsValid = false;
u8 s_SerialNo[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN];
bit64 s_TranferableId;
bool s_CanReadSerialNumber = false;
u32 s_CalVersion = 0;
void* heapForGx;
nn::fnd::ExpHeap s_AppHeap;
demo::RenderSystemDrawing s_RenderSystem;
}
void DrawError(nn::Result result, s32 line)
{
s_RenderSystem.SetColor(1, 0, 0);
for(;;)
{
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0);
s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 0, 0, 0, 1);
s_RenderSystem.Clear();
s_RenderSystem.DrawText(0, 0, "line %d: Error = %X", line, result.GetPrintableBits());
s_RenderSystem.SwapBuffers();
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1);
s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 1, 0, 0, 1);
s_RenderSystem.Clear();
s_RenderSystem.SwapBuffers();
nngxWaitVSync(NN_GX_DISPLAY_BOTH);
}
}
void Finalize()
{
s_RenderSystem.Finalize();
s_AppHeap.Free(heapForGx);
s_AppHeap.Finalize();
nn::applet::DisableSleep();
nn::hid::Finalize();
nn::cfg::init::Finalize();
nn::fs::Finalize();
nn::applet::PrepareToCloseApplication();
nn::applet::CloseApplication();
}
extern "C" void nnMain()
{
nn::Result result;
// os の初期化
nn::os::Initialize();
// ServiceManagerプロセスの初期化
result = nn::srv::Initialize();
HANDLE_ERROR(result);
nn::applet::Enable();
NN_LOG("FlickerCalCollector start\n");
const u32 s_GxHeapSize = 0x800000;
// ヒープの確保
s_AppHeap.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize(), nn::os::ALLOCATE_OPTION_LINEAR);
// RenderSystem の準備
heapForGx = s_AppHeap.Allocate(s_GxHeapSize);
s_RenderSystem.Initialize(reinterpret_cast<uptr>(heapForGx), s_GxHeapSize);
s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 0, 0, 0, 1);
s_RenderSystem.SetColor(1, 1, 1);
// fs の初期化
nn::fs::Initialize();
// NAND マウント
// nand:/ro/ のマウント
result = nn::fs::MountSpecialArchive("nandro:", nn::fs::CTR::ARCHIVE_TYPE_CTR_NAND_RO);
if ( result.IsFailure() )
{
NN_LOG_WARN("[CFG] Mount nand:/ro failed.\n");
nn::dbg::PrintResult(result);
}
NN_LOG("Before %d, %d\n", s_LcdFlickerInfo.vcomTop, s_LcdFlickerInfo.vcomBottom);
// cal の情報取得
{
nn::drivers::cal::CTR::Calibration calibration;
nn::drivers::cal::CTR::Type currentCalType;
// Cal の初期化
calibration.Initialize();
//----- バージョンを取得
s_CalVersion = calibration.GetVersion();
//----- LCD FLICKER
currentCalType = nn::drivers::cal::CTR::CAL_DATA_LCD_FLICKER;
s_LcdFlickerInfoIsValid = calibration.Get(&s_LcdFlickerInfo, currentCalType);
if(!s_LcdFlickerInfoIsValid)
{
DrawError(nn::ResultSuccess(), __LINE__);
}
}
result = nn::fs::Unmount("nandro");
HANDLE_ERROR(result);
// cfg の初期化
nn::cfg::CTR::init::Initialize();
// シリアルナンバーの取得
std::memset(s_SerialNo, '\0',
nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN);
result = nn::cfg::CTR::init::GetSerialNo(s_SerialNo);
HANDLE_ERROR(result);
if(result.IsSuccess())
{
s_CanReadSerialNumber = true;
}
// 移行可能IDの取得
s_TranferableId = nn::cfg::CTR::GetTransferableId(0);
nn::hid::InitializeWithPrivilege();
u32 count = 0;
s32 flushCount = -1;
nn::hid::PadReader padReader;
nn::hid::PadStatus padStatus;
using namespace nn::cfg::CTR::detail;
LcdFlickerCfgData flicker;
// 現在のcfg値の取得
result = nn::cfg::CTR::init::GetConfig(&flicker, sizeof(LcdFlickerCfgData),
GET_CFG_KEY(NN_CFG_LCD, NN_CFG_LCD_CAL_FLICKER));
HANDLE_ERROR(result);
for (;;)
{
padReader.ReadLatest(&padStatus);
// キーの反映
if(padStatus.trigger & nn::hid::BUTTON_A ||
padStatus.hold & nn::hid::BUTTON_X)
{
flicker.vcomTop++;
}
if(padStatus.trigger & nn::hid::BUTTON_B ||
padStatus.hold & nn::hid::BUTTON_Y)
{
flicker.vcomTop--;
}
if(padStatus.trigger & nn::hid::BUTTON_RIGHT ||
padStatus.hold & nn::hid::BUTTON_R)
{
flicker.vcomBottom++;
}
if(padStatus.trigger & nn::hid::BUTTON_LEFT ||
padStatus.hold & nn::hid::BUTTON_L)
{
flicker.vcomBottom--;
}
if(padStatus.trigger & nn::hid::BUTTON_START)
{
NN_LOG("update\n");
// 書き込み
result = nn::cfg::CTR::init::SetConfig(GET_CFG_KEY(NN_CFG_LCD, NN_CFG_LCD_CAL_FLICKER), &flicker,
sizeof(LcdFlickerCfgData));
HANDLE_ERROR(result);
result = nn::cfg::CTR::init::FlushConfig();
HANDLE_ERROR(result);
flushCount = count;
// 現在のcfg値の取得
result = nn::cfg::CTR::init::GetConfig(&flicker, sizeof(LcdFlickerCfgData),
GET_CFG_KEY(NN_CFG_LCD, NN_CFG_LCD_CAL_FLICKER));
HANDLE_ERROR(result);
}
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0);
s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 0, 0, 0, 1);
s_RenderSystem.Clear();
s_RenderSystem.DrawText(0, 0, "count = %d", count++);
if(s_CanReadSerialNumber)
{
s_RenderSystem.DrawText(0, 10, "serial = %s", s_SerialNo);
}
s_RenderSystem.DrawText(0, 20, "TransferableId = %llx\n", s_TranferableId);
s_RenderSystem.DrawText(0, 30, "calVersion = %d\n", s_CalVersion);
s_RenderSystem.DrawText(0, 40, "Flicker = %0x, %0x", s_LcdFlickerInfo.vcomTop, s_LcdFlickerInfo.vcomBottom);
s_RenderSystem.DrawText(0, 50, "cfg = %0x, %0x", flicker.vcomTop, flicker.vcomBottom);
s_RenderSystem.DrawText(0, 60, "flush = %d", flushCount);
s_RenderSystem.DrawText(0, 80, "A : VcomTop++");
s_RenderSystem.DrawText(0, 90, "B : VcomTop--");
s_RenderSystem.DrawText(0, 100, "Right: VcomBottom++");
s_RenderSystem.DrawText(0, 110, "Left : VcomBottom--");
s_RenderSystem.DrawText(0, 120, "Start: Flush data to Nand");
s_RenderSystem.SwapBuffers();
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1);
s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 0, 0, 0, 1);
s_RenderSystem.Clear();
s_RenderSystem.SwapBuffers();
nngxWaitVSync(NN_GX_DISPLAY_BOTH);
// Homeボタン
if (nn::applet::IsExpectedToProcessHomeButton())
{
nn::applet::ProcessHomeButton();
nn::applet::WaitForStarting();
// 待ちうけからの戻り終了チェック
if (nn::applet::IsExpectedToCloseApplication())
{
break;
}
// GPU レジスタ設定の復帰
nngxUpdateState(NN_GX_STATE_ALL);
nngxValidateState(NN_GX_STATE_ALL, GL_TRUE);
}
// 電源ボタン
if (nn::applet::IsExpectedToProcessPowerButton())
{
nn::applet::ProcessPowerButton();
nn::applet::WaitForStarting();
// 待ちうけからの戻り終了チェック
if (nn::applet::IsExpectedToCloseApplication())
{
break;
}
// GPU レジスタ設定の復帰
nngxUpdateState(NN_GX_STATE_ALL);
nngxValidateState(NN_GX_STATE_ALL, GL_TRUE);
}
if (nn::applet::IsExpectedToCloseApplication())
{
break;
}
}
Finalize();
}