mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
両方をメンテナンスすることが手間であるため、HWInfoWriterのコードの一部をライブラリ化し、 一元管理できるようにしました。ただ、Makefileの記述も合わせる必要があることに注意が必要です。 git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@652 b08762b0-b915-fc4b-9d8c-17b2551a87ff
390 lines
11 KiB
C
390 lines
11 KiB
C
/*---------------------------------------------------------------------------*
|
||
Project: TwlSDK - NandInitializer
|
||
File: process_hw_info.c
|
||
|
||
Copyright 2008 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.
|
||
|
||
$Date:: $
|
||
$Rev$
|
||
$Author$
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
#include <twl.h>
|
||
#include <nitro/snd.h>
|
||
#include <twl/fatfs.h>
|
||
#include <twl/lcfg.h>
|
||
#include <nitro/card.h>
|
||
#include "kami_font.h"
|
||
#include "kami_pxi.h"
|
||
#include "process_topmenu.h"
|
||
#include "process_hw_info.h"
|
||
#include "process_auto.h"
|
||
#include "process_fade.h"
|
||
#include "cursor.h"
|
||
#include "keypad.h"
|
||
#include "hwi.h"
|
||
|
||
//
|
||
#include "TWLHWInfo_api.h"
|
||
#include "TWLSettings_api.h"
|
||
//
|
||
/*---------------------------------------------------------------------------*
|
||
Œ^’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
’è<E28099>”’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
#define NUM_OF_MENU_SELECT 8
|
||
#define DOT_OF_MENU_SPACE 16
|
||
#define CHAR_OF_MENU_SPACE 2
|
||
#define CURSOR_ORIGIN_X 32
|
||
#define CURSOR_ORIGIN_Y 56
|
||
|
||
static const u32 s_langBitmapList[ LCFG_TWL_REGION_MAX ] = {
|
||
LCFG_TWL_LANG_BITMAP_JAPAN,
|
||
LCFG_TWL_LANG_BITMAP_AMERICA,
|
||
LCFG_TWL_LANG_BITMAP_EUROPE,
|
||
LCFG_TWL_LANG_BITMAP_AUSTRALIA,
|
||
LCFG_TWL_LANG_BITMAP_CHINA,
|
||
LCFG_TWL_LANG_BITMAP_KOREA,
|
||
};
|
||
|
||
static char *strLanguage[] = {
|
||
(char *)"LANG_JAPANESE",
|
||
(char *)"LANG_ENGLISH",
|
||
(char *)"LANG_FRENCH",
|
||
(char *)"LANG_GERMAN",
|
||
(char *)"LANG_ITALIAN",
|
||
(char *)"LANG_SPANISH",
|
||
(char *)"LANG_CHINESE",
|
||
(char *)"LANG_KOREAN",
|
||
};
|
||
|
||
static const char *strRegion[] = {
|
||
"JAPAN",
|
||
"AMERICA",
|
||
"EUROPE",
|
||
"AUSTRALIA",
|
||
"CHINA",
|
||
"KOREA",
|
||
};
|
||
|
||
static const char *strLauncherGameCode[] = {
|
||
"LNCJ",
|
||
"LNCE",
|
||
"LNCP",
|
||
"LNCO",
|
||
"LNCC",
|
||
"LNCK",
|
||
};
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
“à•”•Ï<E280A2>”’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
static s8 sMenuSelectNo;
|
||
|
||
static u8 *s_pPrivKeyBuffer = NULL;
|
||
static LCFGReadResult (*s_pReadSecureInfoFunc)( void );
|
||
static BOOL s_isReadTSD;
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
“à•”ŠÖ<C5A0>”<EFBFBD>錾
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
void HWInfoWriterInit( void );
|
||
static void ReadTWLSettings( void );
|
||
static void ModifyLanguage( u8 region );
|
||
static void ReadPrivateKey( void );
|
||
static void ReadHWInfoFile( void );
|
||
static void VerifyHWInfo( void );
|
||
static BOOL WriteHWInfoFile( u8 region );
|
||
static BOOL WriteHWNormalInfoFile( void );
|
||
static BOOL WriteHWSecureInfoFile( u8 region );
|
||
static BOOL DeleteHWInfoFile( void );
|
||
|
||
const LCFGTWLHWNormalInfo *LCFG_THW_GetDefaultNormalInfo( void );
|
||
const LCFGTWLHWSecureInfo *LCFG_THW_GetDefaultSecureInfo( void );
|
||
const LCFGTWLHWNormalInfo *LCFG_THW_GetNormalInfo( void );
|
||
const LCFGTWLHWSecureInfo *LCFG_THW_GetSecureInfo( void );
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
ƒvƒ<76>ƒZƒXŠÖ<C5A0>”’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: HWInfo ƒvƒ<76>ƒZƒX‚O
|
||
|
||
Description:
|
||
|
||
Arguments: None.
|
||
|
||
Returns: next sequence
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
void* HWInfoProcess0(void)
|
||
{
|
||
HwiInitResult initResult;
|
||
int i;
|
||
|
||
// •¶Žš—ñ‘SƒNƒŠƒA
|
||
kamiFontClear();
|
||
|
||
// ƒo<C692>[ƒWƒ‡ƒ“•\ަ
|
||
kamiFontPrintf(2, 1, FONT_COLOR_BLACK, "Write Hardware Information ");
|
||
kamiFontPrintf(0, 2, FONT_COLOR_BLACK, "--------------------------------");
|
||
|
||
// ƒ<>ƒjƒ…<C692>[ˆê——
|
||
kamiFontPrintf(3, 6, FONT_COLOR_BLACK, "+--------------------+----+");
|
||
kamiFontPrintf(3, 7, FONT_COLOR_BLACK, "l REGION JAPAN l l");
|
||
kamiFontPrintf(3, 8, FONT_COLOR_BLACK, "+--------------------+----+");
|
||
kamiFontPrintf(3, 9, FONT_COLOR_BLACK, "l REGION AMERICA l l");
|
||
kamiFontPrintf(3, 10, FONT_COLOR_BLACK, "+--------------------+----+");
|
||
kamiFontPrintf(3, 11, FONT_COLOR_BLACK, "l REGION EUROPE l l");
|
||
kamiFontPrintf(3, 12, FONT_COLOR_BLACK, "+--------------------+----+");
|
||
kamiFontPrintf(3, 13, FONT_COLOR_BLACK, "l REGION AUSTRALIA l l");
|
||
kamiFontPrintf(3, 14, FONT_COLOR_BLACK, "+--------------------+----+");
|
||
kamiFontPrintf(3, 15, FONT_COLOR_BLACK, "l REGION CHINA l l");
|
||
kamiFontPrintf(3, 16, FONT_COLOR_BLACK, "+--------------------+----+");
|
||
kamiFontPrintf(3, 17, FONT_COLOR_BLACK, "l REGION KOREA l l");
|
||
kamiFontPrintf(3, 18, FONT_COLOR_BLACK, "+--------------------+----+");
|
||
kamiFontPrintf(3, 19, FONT_COLOR_BLACK, "l DELETE l l");
|
||
kamiFontPrintf(3, 20, FONT_COLOR_BLACK, "+--------------------+----+");
|
||
kamiFontPrintf(3, 21, FONT_COLOR_BLACK, "l RETURN l l");
|
||
kamiFontPrintf(3, 22, FONT_COLOR_BLACK, "+--------------------+----+");
|
||
|
||
// ”wŒi‘SƒNƒŠƒA
|
||
for (i=0;i<24;i++)
|
||
{
|
||
kamiFontFillChar( i, BG_COLOR_TRANS, BG_COLOR_TRANS );
|
||
}
|
||
|
||
// ”wŒi<C592>ã•”
|
||
kamiFontFillChar( 0, BG_COLOR_PURPLE, BG_COLOR_PURPLE );
|
||
kamiFontFillChar( 1, BG_COLOR_PURPLE, BG_COLOR_PURPLE );
|
||
kamiFontFillChar( 2, BG_COLOR_PURPLE, BG_COLOR_TRANS );
|
||
|
||
// ƒJ<C692>[ƒ\ƒ‹<C692>œŠO
|
||
SetCursorPos((u16)200, (u16)200);
|
||
|
||
// ‘O<E28098>€”õ
|
||
initResult = HWI_Init( OS_AllocFromMain, OS_FreeToMain );
|
||
switch (initResult)
|
||
{
|
||
case HWI_INIT_FAILURE:
|
||
kamiFontPrintfConsoleEx(CONSOLE_RED, "HWI_INIT() Failure!\n" );
|
||
break;
|
||
case HWI_INIT_SUCCESS_SIGNATURE_MODE:
|
||
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, "[Signature MODE]\n" );
|
||
break;
|
||
case HWI_INIT_SUCCESS_NO_SIGNATRUE_MODE:
|
||
kamiFontPrintfConsoleEx(CONSOLE_RED, "[No Signature MODE]\n" );
|
||
break;
|
||
}
|
||
|
||
FADE_IN_RETURN( HWInfoProcess1 );
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: HWInfo ƒvƒ<76>ƒZƒX‚P
|
||
|
||
Description:
|
||
|
||
Arguments: None.
|
||
|
||
Returns: next sequence
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
void* HWInfoProcess1(void)
|
||
{
|
||
// ƒI<C692>[ƒgŽÀ<C5BD>s—p
|
||
if (gAutoFlag)
|
||
{
|
||
sMenuSelectNo = 0;
|
||
return HWInfoProcess2;
|
||
}
|
||
|
||
// ‘I‘ðƒ<C3B0>ƒjƒ…<C692>[‚Ì•Ï<E280A2>X
|
||
if ( kamiPadIsRepeatTrigger(PAD_KEY_UP) )
|
||
{
|
||
if (--sMenuSelectNo < 0) sMenuSelectNo = NUM_OF_MENU_SELECT -1;
|
||
}
|
||
else if ( kamiPadIsRepeatTrigger(PAD_KEY_DOWN) )
|
||
{
|
||
if (++sMenuSelectNo >= NUM_OF_MENU_SELECT) sMenuSelectNo = 0;
|
||
}
|
||
|
||
// ƒJ<C692>[ƒ\ƒ‹”z’u
|
||
SetCursorPos((u16)CURSOR_ORIGIN_X, (u16)(CURSOR_ORIGIN_Y + sMenuSelectNo * DOT_OF_MENU_SPACE));
|
||
|
||
// Œˆ’è
|
||
if (kamiPadIsTrigger(PAD_BUTTON_A))
|
||
{
|
||
return HWInfoProcess2;
|
||
}
|
||
// ƒgƒbƒvƒ<76>ƒjƒ…<C692>[‚Ö–ß‚é
|
||
else if (kamiPadIsTrigger(PAD_BUTTON_B))
|
||
{
|
||
FADE_OUT_RETURN( TopmenuProcess0 );
|
||
}
|
||
|
||
return HWInfoProcess1;
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: HWInfo ƒvƒ<76>ƒZƒX‚Q
|
||
|
||
Description:
|
||
|
||
Arguments: None.
|
||
|
||
Returns: next sequence
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
void* HWInfoProcess2(void)
|
||
{
|
||
int i;
|
||
BOOL result;
|
||
|
||
switch( sMenuSelectNo )
|
||
{
|
||
case 0:
|
||
case 1:
|
||
case 2:
|
||
case 3:
|
||
case 4:
|
||
case 5:
|
||
OS_TPrintf( "Write Start.\n" );
|
||
result = WriteHWInfoFile( (u8)sMenuSelectNo );
|
||
break;
|
||
case 6:
|
||
OS_TPrintf( "Delete start.\n" );
|
||
result = DeleteHWInfoFile();
|
||
break;
|
||
case 7:
|
||
FADE_OUT_RETURN( TopmenuProcess0 );
|
||
}
|
||
|
||
// ‘SŒ‹‰Ê‚ðƒNƒŠƒA
|
||
for (i=0;i<NUM_OF_MENU_SELECT;i++)
|
||
{
|
||
kamiFontPrintf(26, (s16)(7+i*CHAR_OF_MENU_SPACE), FONT_COLOR_BLACK, " ");
|
||
}
|
||
// <20>¡‰ñ‚ÌŒ‹‰Ê‚ð•\ަ
|
||
if ( result == TRUE )
|
||
{
|
||
kamiFontPrintf(26, (s16)(7+sMenuSelectNo*CHAR_OF_MENU_SPACE), FONT_COLOR_GREEN, "OK");
|
||
}
|
||
else
|
||
{
|
||
kamiFontPrintf(26, (s16)(7+sMenuSelectNo*CHAR_OF_MENU_SPACE), FONT_COLOR_RED, "NG");
|
||
}
|
||
|
||
// Auto—p
|
||
if (gAutoFlag)
|
||
{
|
||
if (result) { FADE_OUT_RETURN( AutoProcess1 ); }
|
||
else { FADE_OUT_RETURN( AutoProcess2 ); }
|
||
}
|
||
|
||
return HWInfoProcess1;
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
<20>ˆ—<CB86>ŠÖ<C5A0>”’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: HW<48>î•ñ‘S‘̂̃‰ƒCƒg
|
||
|
||
Description:
|
||
|
||
Arguments: None.
|
||
|
||
Returns: None.
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
static BOOL WriteHWInfoFile( u8 region )
|
||
{
|
||
static const char *pMsgNormalWriting = "Writing Normal File...";
|
||
static const char *pMsgSecureWriting = "Writing Secure File...";
|
||
static const char *pMsgSucceeded = "Succeeded!";
|
||
static const char *pMsgFailed = "Failed!";
|
||
BOOL result = TRUE;
|
||
|
||
// ƒm<C692>[ƒ}ƒ‹ƒtƒ@ƒCƒ‹‚̃‰ƒCƒg
|
||
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgNormalWriting );
|
||
|
||
if( HWI_WriteHWNormalInfoFile() ) {
|
||
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSucceeded );
|
||
}else {
|
||
kamiFontPrintfConsoleEx(CONSOLE_RED, pMsgFailed );
|
||
result = FALSE;
|
||
}
|
||
|
||
// ƒZƒLƒ…ƒAƒtƒ@ƒCƒ‹‚̃‰ƒCƒg
|
||
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSecureWriting );
|
||
|
||
if( HWI_WriteHWSecureInfoFile( region ) ) {
|
||
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSucceeded );
|
||
}else {
|
||
kamiFontPrintfConsoleEx(CONSOLE_RED, pMsgFailed );
|
||
result = FALSE;
|
||
}
|
||
|
||
HWI_ModifyLanguage( region );
|
||
|
||
return result;
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: HWInfoƒtƒ@ƒCƒ‹‚Ì<E2809A>í<EFBFBD>œ
|
||
|
||
Description:
|
||
|
||
Arguments: None.
|
||
|
||
Returns: None.
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
static BOOL DeleteHWInfoFile( void )
|
||
{
|
||
static const char *pMsgNormalDeleting = "Deleting Normal File...";
|
||
static const char *pMsgSecureDeleting = "Deteting Secure File...";
|
||
static const char *pMsgSucceeded = "Succeeded!";
|
||
static const char *pMsgFailed = "Failed!";
|
||
BOOL result = TRUE;
|
||
|
||
// ƒm<C692>[ƒ}ƒ‹ƒtƒ@ƒCƒ‹
|
||
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgNormalDeleting );
|
||
if( HWI_DeleteHWNormalInfoFile() ) {
|
||
OS_TPrintf( "%s delete succeeded.\n", (char *)LCFG_TWL_HWINFO_NORMAL_PATH );
|
||
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSucceeded );
|
||
}else {
|
||
OS_TPrintf( "%s delete failed.\n", (char *)LCFG_TWL_HWINFO_NORMAL_PATH );
|
||
kamiFontPrintfConsoleEx(CONSOLE_RED, pMsgFailed );
|
||
result = FALSE;
|
||
}
|
||
|
||
// ƒZƒLƒ…ƒAƒtƒ@ƒCƒ‹
|
||
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSecureDeleting );
|
||
if( HWI_DeleteHWSecureInfoFile() ) {
|
||
OS_TPrintf( "%s delete succeeded.\n", (char *)LCFG_TWL_HWINFO_SECURE_PATH );
|
||
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSucceeded );
|
||
}else {
|
||
OS_TPrintf( "%s delete failed.\n", (char *)LCFG_TWL_HWINFO_SECURE_PATH );
|
||
kamiFontPrintfConsoleEx(CONSOLE_RED, pMsgFailed );
|
||
result = FALSE;
|
||
}
|
||
|
||
return result;
|
||
}
|