TwlIPL/build/systemMenu_tools/ImportJump/ARM9.TWL/src/import.c
kamikawa bac39e78df NAMUT_Init関数を追加しました。(Alloc/Free)を渡します。
ImportJump がうまく動作しない問題を修正。

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1376 b08762b0-b915-fc4b-9d8c-17b2551a87ff
2008-05-16 06:08:34 +00:00

353 lines
10 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*---------------------------------------------------------------------------*
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);
static void UpdateNandBoxCount( void );
/*---------------------------------------------------------------------------*
<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;
}
// NOT_LAUNCH_FLAG ‚Ü‚½‚Í DATA_ONLY_FLAG ‚ª—§‚Á‚Ä‚¢‚È‚¢ƒ^ƒCƒgƒÌ<E2809A>ê<EFBFBD>
// freeSoftBoxCountÉó«ªÈ¯ê΃Cƒ“ƒ|<7C>[ƒgµÈ¢
if (NAMUT_SearchInstalledSoftBoxCount() == LCFG_TWL_FREE_SOFT_BOX_COUNT_MAX)
{
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)
{
// ƒ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
UpdateNandBoxCount();
}
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(&currentSize, &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: UpdateNandBoxCount
Description: InstalledSoftBoxCount, FreeSoftBoxCount Ìlð
Œ»<C592>ÝÌNANDÌ<E2809A>óÔÉ<E2809A>í¹Ä<E2809A>X<EFBFBD>VµÜ·<E2809A>B
Arguments: None.
Returns: None.
*---------------------------------------------------------------------------*/
static void UpdateNandBoxCount( void )
{
u32 installedSoftBoxCount;
u32 freeSoftBoxCount;
// InstalledSoftBoxCount, FreeSoftBoxCount ð<E2809A>¦È¨·
installedSoftBoxCount = NAMUT_SearchInstalledSoftBoxCount();
freeSoftBoxCount = LCFG_TWL_FREE_SOFT_BOX_COUNT_MAX - installedSoftBoxCount;
// LCFGƒ‰ƒCƒuƒ‰ƒŠÌ<E2809A>ÓI•Ï<E280A2>Éηé<E2809A>X<EFBFBD>V
LCFG_TSD_SetInstalledSoftBoxCount( (u8)installedSoftBoxCount );
LCFG_TSD_SetFreeSoftBoxCount( (u8)freeSoftBoxCount );
// LCFGƒ‰ƒCƒuƒ‰ƒŠÌ<E2809A>ÓI•Ï<E280A2>ÌlðNANDÉ”½‰f
{
u8 *pBuffer = OS_Alloc( LCFG_WRITE_TEMP );
if( pBuffer ) {
(void)LCFG_WriteTWLSettings( (u8 (*)[ LCFG_WRITE_TEMP ] )pBuffer );
OS_Free( pBuffer );
}
}
}
/*---------------------------------------------------------------------------*
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;
}