mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1558 b08762b0-b915-fc4b-9d8c-17b2551a87ff
338 lines
9.3 KiB
C
338 lines
9.3 KiB
C
/*---------------------------------------------------------------------------*
|
||
Project: ImportJump
|
||
File: process_import.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 <nitro/card.h>
|
||
#include <twl/nam.h>
|
||
#include <twl/lcfg.h>
|
||
#include <sysmenu/namut.h>
|
||
#include "kami_font.h"
|
||
#include "import.h"
|
||
#include "TWLHWInfo_api.h"
|
||
#include "graphics.h"
|
||
#include "ImportJump.h"
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Œ^’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
’è<E28099>”’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
#define THREAD_STACK_SIZE (16*1024)
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
“à•”•Ï<E280A2>”’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
static void* spStack;
|
||
static u32 sCurrentProgress;
|
||
static vu8 sNowImport = FALSE;
|
||
static ImportJump sImportJumpSetting;
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
“à•”ŠÖ<C5A0>”<EFBFBD>錾
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
static void ProgressThread(void* arg);
|
||
static void Destructor(void* arg);
|
||
void ProgressDraw(f32 ratio);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
<20>ˆ—<CB86>ŠÖ<C5A0>”’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: kamiImportTad
|
||
|
||
Description: .tad ƒtƒ@ƒCƒ‹ƒCƒ“ƒ|<7C>[ƒg
|
||
|
||
Arguments: no
|
||
|
||
Returns: None.
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
BOOL kamiImportTad(NAMTitleId* pTitleID)
|
||
{
|
||
NAMTadInfo tadInfo;
|
||
NAMTitleInfo titleInfoTmp;
|
||
OSThread thread;
|
||
s32 nam_result;
|
||
FSFile file;
|
||
char savePublicPath[FS_ENTRY_LONGNAME_MAX];
|
||
char savePrivatePath[FS_ENTRY_LONGNAME_MAX];
|
||
char subBannerPath[FS_ENTRY_LONGNAME_MAX];
|
||
|
||
// <20>»•i—pCPU‚ł̓Cƒ“ƒ|<7C>[ƒg•s‰Â‚É
|
||
if ( !((*(u8*)(OS_CHIPTYPE_DEBUGGER_ADDR) & OS_CHIPTYPE_DEBUGGER_MASK)) )
|
||
{
|
||
OS_Warning(" Fail : Production CPU\n");
|
||
return FALSE;
|
||
}
|
||
|
||
// ƒtƒ@ƒCƒ‹<C692>‰Šú‰»
|
||
FS_InitFile(&file);
|
||
|
||
// CARD-ROM —̈æ‚ðˆêŽž“I‚ȃtƒ@ƒCƒ‹‚Ƃ݂Ȃµ‚»‚̃tƒ@ƒCƒ‹‚ðŠJ‚«‚Ü‚·<E2809A>B
|
||
if (!FS_CreateFileFromRom(&file, GetImportJumpSetting()->tadRomOffset, GetImportJumpSetting()->tadLength))
|
||
{
|
||
OS_Warning(" Fail : FS_CreateFileFromRom\n");
|
||
return FALSE;
|
||
}
|
||
|
||
// tadƒtƒ@ƒCƒ‹‚Ì<E2809A>î•ñŽæ“¾
|
||
if (NAM_ReadTadInfoWithFile(&tadInfo, &file) != NAM_OK)
|
||
{
|
||
OS_Warning(" Fail! : NAM_ReadTadInfo\n");
|
||
return FALSE;
|
||
}
|
||
|
||
// titleID‚ð•Û‘¶‚µ‚Ä‚¨‚
|
||
*pTitleID = tadInfo.titleInfo.titleId;
|
||
|
||
// Data Only ‚Ȃ玸”s
|
||
if (tadInfo.titleInfo.titleId & TITLE_ID_DATA_ONLY_FLAG_MASK)
|
||
{
|
||
OS_Warning(" Fail! : DATA_ONLY_FLAG is specified in rsf file\n");
|
||
return FALSE;
|
||
}
|
||
|
||
// freeSoftBoxCount‚ɋ󂫂ª‚È‚¯‚ê‚΃Cƒ“ƒ|<7C>[ƒg‚µ‚È‚¢
|
||
{
|
||
u8 installed, free;
|
||
if (!NAMUT_GetSoftBoxCount(&installed, &free))
|
||
{
|
||
OS_Warning(" Fail! : Can not get soft box count\n");
|
||
return FALSE;
|
||
}
|
||
if (free == 0)
|
||
{
|
||
OS_Warning(" Fail! : NAND FreeSoftBoxCount == 0\n");
|
||
return FALSE;
|
||
}
|
||
}
|
||
|
||
// TADƒtƒ@ƒCƒ‹‚ª<E2809A>X<EFBFBD>V‚³‚ê‚Ä‚¢‚é<E2809A>ê<EFBFBD>‡‚ÉŒÀ‚èƒCƒ“ƒ|<7C>[ƒg<C692>ˆ—<CB86>‚ð<E2809A>s‚¤
|
||
// NandInitializer‚É‚æ‚Á‚Ä<E2809A>Á‹Ž‚³‚ê‚Ä‚¢‚é‰Â”\<5C>«‚à‚ ‚é‚̂Ŋm”F‚·‚é
|
||
if (GetImportJumpSetting()->importTad == 1 || NAM_ReadTitleInfo(&titleInfoTmp, tadInfo.titleInfo.titleId) != NAM_OK)
|
||
{
|
||
/*
|
||
// ES‚ÌŽd—l‚Ō¢ e-ticket ‚ª‚ ‚邯<E2809A>V‚µ‚¢ e-ticket ‚ðŽg‚Á‚½ƒCƒ“ƒ|<7C>[ƒg‚ª‚Å‚«‚È‚¢
|
||
// Žb’è‘Ήž‚Æ‚µ‚ÄŠY“–ƒ^ƒCƒgƒ‹‚ðŠ®‘S<E28098>í<EFBFBD>œ‚µ‚Ä‚©‚çƒCƒ“ƒ|<7C>[ƒg‚·‚é
|
||
nam_result = NAM_DeleteTitleCompletely(tadInfo.titleInfo.titleId);
|
||
if ( nam_result != NAM_OK )
|
||
{
|
||
kamiFontPrintfConsole(CONSOLE_RED, "Fail! RetCode=%x\n", nam_result);
|
||
return FALSE;
|
||
}
|
||
*/
|
||
// ƒCƒ“ƒ|<7C>[ƒgŠJŽnƒtƒ‰ƒO‚ð—§‚Ä‚é
|
||
sNowImport = TRUE;
|
||
|
||
// <20>i’»ƒXƒŒƒbƒh<C692>ì<EFBFBD>¬
|
||
spStack = OS_Alloc(THREAD_STACK_SIZE);
|
||
MI_CpuClear8(spStack, THREAD_STACK_SIZE);
|
||
OS_CreateThread(&thread, ProgressThread, NULL,
|
||
(void*)((u32)spStack + THREAD_STACK_SIZE), THREAD_STACK_SIZE, OS_GetCurrentThread()->priority - 1);
|
||
OS_SetThreadDestructor( &thread, Destructor );
|
||
OS_WakeupThreadDirect(&thread);
|
||
|
||
// ImportŠJŽn
|
||
nam_result = NAM_ImportTadWithFile( &file );
|
||
|
||
// <20>i’»ƒXƒŒƒbƒh‚ÌŽ©—Í<E28094>I—¹‚ð‘Ò‚Â
|
||
while (sNowImport){};
|
||
|
||
if ( nam_result == NAM_OK )
|
||
{
|
||
// InstalledSoftBoxCount, FreeSoftBoxCount ‚Ì’l‚ðŒ»<C592>Ý‚ÌNAND‚Ì<E2809A>ó‘Ô‚É<E2809A>‡‚킹‚Ä<E2809A>X<EFBFBD>V‚µ‚Ü‚·<E2809A>B
|
||
if (!NAMUT_UpdateSoftBoxCount())
|
||
{
|
||
OS_Warning(" Fail! : Update Soft Box Count\n");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
OS_Warning(" Fail! : NAM Result Code = 0x%x\n", nam_result);
|
||
return FALSE;
|
||
}
|
||
}
|
||
|
||
// ƒZ<C692>[ƒuƒf<C692>[ƒ^ƒNƒŠƒA<C692>ˆ—<CB86>
|
||
if (GetImportJumpSetting()->clearPublicSaveData || GetImportJumpSetting()->clearPrivateSaveData)
|
||
{
|
||
// ƒZ<C692>[ƒuƒtƒ@ƒCƒ‹ƒpƒXŽæ“¾
|
||
if ( NAM_GetTitleSaveFilePath(savePublicPath, savePrivatePath, tadInfo.titleInfo.titleId) != NAM_OK )
|
||
{
|
||
OS_Warning(" Fail! NAM_GetTitleSaveFilePath\n");
|
||
}
|
||
else
|
||
{
|
||
// publicƒZ<C692>[ƒuƒf<C692>[ƒ^FFƒNƒŠƒA<C692>•ƒtƒH<C692>[ƒ}ƒbƒg
|
||
if (GetImportJumpSetting()->clearPublicSaveData && tadInfo.titleInfo.publicSaveSize > 0)
|
||
{
|
||
if (NAMUTi_ClearSavedataPublic(savePublicPath, tadInfo.titleInfo.titleId) == FALSE)
|
||
{
|
||
OS_Warning(" Fail! NAMUTi_ClearSavedataPublic\n");
|
||
}
|
||
}
|
||
|
||
// privateƒZ<C692>[ƒuƒf<C692>[ƒ^FFƒNƒŠƒA<C692>•ƒtƒH<C692>[ƒ}ƒbƒg
|
||
if (GetImportJumpSetting()->clearPrivateSaveData && tadInfo.titleInfo.privateSaveSize > 0)
|
||
{
|
||
if (NAMUTi_ClearSavedataPublic(savePrivatePath, tadInfo.titleInfo.titleId) == FALSE)
|
||
{
|
||
OS_Warning(" Fail! NAMUTi_ClearSavedataPrivate\n");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// ƒTƒuƒoƒi<C692>[ƒNƒŠƒA<C692>ˆ—<CB86>
|
||
if (GetImportJumpSetting()->clearSubBannerFile)
|
||
{
|
||
// ƒTƒuƒoƒi<C692>[ƒpƒXŽæ“¾
|
||
if ( NAM_GetTitleBannerFilePath(subBannerPath, tadInfo.titleInfo.titleId) != NAM_OK )
|
||
{
|
||
OS_Warning(" Fail! NAM_GetTitleBannerFilePath\n");
|
||
}
|
||
else
|
||
{
|
||
// ƒTƒuƒoƒi<C692>[”j‰ó
|
||
if (NAMUTi_DestroySubBanner(subBannerPath) == FALSE)
|
||
{
|
||
OS_Warning(" Fail! NAMUTi_DestroySubBanner\n");
|
||
}
|
||
}
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
static void Destructor(void* /*arg*/)
|
||
{
|
||
OS_Free(spStack);
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: ProgressThread
|
||
|
||
Description: .tad ƒtƒ@ƒCƒ‹ƒCƒ“ƒ|<7C>[ƒg‚Ì<E2809A>i’»‚ð•\ަ‚·‚éƒXƒŒƒbƒh<C692>B
|
||
<09>i’»‚ª100%‚É’B‚·‚邯<E2809A>ˆ—<CB86>‚𔲂¯‚é<E2809A>B
|
||
|
||
Arguments: arg - Žg—p‚µ‚È‚¢<E2809A>B
|
||
|
||
Returns: None.
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
static void ProgressThread(void* /*arg*/)
|
||
{
|
||
u32 currentSize;
|
||
u32 totalSize = 0;
|
||
u32 totalSizeBk = 0;
|
||
|
||
kamiFontPrintfMain( 4, 9, 8, "Now Importing...");
|
||
kamiFontLoadScreenData();
|
||
|
||
while (TRUE)
|
||
{
|
||
NAM_GetProgress(¤tSize, &totalSize);
|
||
|
||
if ((totalSize > 0 && totalSize == currentSize) || totalSizeBk > totalSize)
|
||
{
|
||
// Šù‚ɃCƒ“ƒ|<7C>[ƒg‚ª<E2809A>I—¹
|
||
ProgressDraw((f32)1.0);
|
||
break;
|
||
}
|
||
else if (totalSize > 0)
|
||
{
|
||
ProgressDraw((f32)currentSize/totalSize);
|
||
}
|
||
|
||
totalSizeBk = totalSize;
|
||
|
||
// Vƒuƒ‰ƒ“ƒN‘Ò‚¿
|
||
OS_WaitVBlankIntr();
|
||
}
|
||
|
||
sNowImport = FALSE;
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: ProgressDraw
|
||
|
||
Description: ƒCƒ“ƒ|<7C>[ƒg‚Ì<E2809A>i’»‚ð•\ަ‚µ‚Ü‚·
|
||
|
||
Arguments:
|
||
|
||
Returns: None.
|
||
*---------------------------------------------------------------------------*/
|
||
void ProgressDraw(f32 ratio)
|
||
{
|
||
s16 x = (s16)(30 + (226 - 30)*ratio);
|
||
|
||
// 3D<33>‰Šú‰»
|
||
G3X_Reset();
|
||
G3_Identity();
|
||
G3_PolygonAttr(GX_LIGHTMASK_NONE, GX_POLYGONMODE_DECAL, GX_CULL_NONE, 0, 31, 0);
|
||
|
||
// ƒOƒŠ<C692>[ƒ“ƒo<C692>[
|
||
DrawQuad( 30, 90, x, 95, GX_RGB(12, 25, 12));
|
||
|
||
// ƒOƒŒ<C692>[ƒo<C692>[
|
||
DrawQuad( 30, 90, 226, 95, GX_RGB(28, 28, 28));
|
||
|
||
// ƒOƒŒ<C692>[ƒ_ƒCƒAƒ<41>ƒO
|
||
DrawQuad( 20, 60, 236, 110, GX_RGB(25, 25, 25));
|
||
|
||
// 3DƒXƒ<58>ƒbƒv
|
||
G3_SwapBuffers(GX_SORTMODE_AUTO, GX_BUFFERMODE_W);
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: GetImportJumpSetting
|
||
|
||
Description:
|
||
|
||
Arguments: None.
|
||
|
||
Returns: None.
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
ImportJump* GetImportJumpSetting( void )
|
||
{
|
||
static BOOL inited = FALSE;
|
||
|
||
if ( ! inited )
|
||
{
|
||
// ŠJ”—pCPU‚ł̂݃Š<C692>[ƒh
|
||
if ( *(u8*)(OS_CHIPTYPE_DEBUGGER_ADDR) & OS_CHIPTYPE_DEBUGGER_MASK )
|
||
{
|
||
u16 id = (u16)OS_GetLockID();
|
||
CARD_LockRom( id );
|
||
CARD_ReadRom( MI_DMA_NOT_USE, (void*)IMPORT_JUMP_SETTING_OFS, &sImportJumpSetting, sizeof(ImportJump) );
|
||
CARD_UnlockRom( id );
|
||
}
|
||
inited = TRUE;
|
||
}
|
||
|
||
return &sImportJumpSetting;
|
||
}
|