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@2576 b08762b0-b915-fc4b-9d8c-17b2551a87ff
254 lines
6.5 KiB
C
254 lines
6.5 KiB
C
/*---------------------------------------------------------------------------*
|
||
Project: SystemUpdater
|
||
File: main.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/os/common/format_rom.h>
|
||
#include <sysmenu/namut.h>
|
||
#include <twl/nam.h>
|
||
#include "kami_pxi.h"
|
||
#include "kami_font.h"
|
||
#include "kami_copy_file.h"
|
||
#include "graphics.h"
|
||
#include "hwi.h"
|
||
#include "keypad.h"
|
||
#include "debugger_hw_reset_control.h"
|
||
#include "debugger_card_rom.h"
|
||
#include "font.h"
|
||
#include "kami_global.h"
|
||
|
||
#define SCRAMBLE_MASK 0x00406000
|
||
|
||
extern void InitFont(void);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Œ^’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
“à•”’è<E28099>”’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
“à•”•Ï<E280A2>”’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
s32 gLockId;
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
“à•”ŠÖ<C5A0>”’è‹`
|
||
*---------------------------------------------------------------------------*/
|
||
static void VBlankIntr(void);
|
||
static void InitAllocation(void);
|
||
static BOOL IgnoreRemoval(void);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: TwlMain
|
||
|
||
Description: main
|
||
|
||
Arguments: None
|
||
|
||
Returns: None
|
||
*---------------------------------------------------------------------------*/
|
||
void
|
||
TwlMain()
|
||
{
|
||
BOOL result;
|
||
|
||
// <20>»•iƒrƒ‹ƒhƒ‰ƒ“ƒ`ƒƒ<C692>[<5B>•ƒfƒoƒbƒK<C692>ã‚ł̋N“®‘Ήž
|
||
if ( OS_GetRunningConsoleType() & OS_CONSOLE_TWLDEBUGGER )
|
||
{
|
||
ROM_Header *dh = (void *)HW_ROM_HEADER_BUF;
|
||
dh->s.game_cmd_param &= ~SCRAMBLE_MASK;
|
||
}
|
||
|
||
OS_Init();
|
||
OS_InitThread();
|
||
OS_InitTick();
|
||
OS_InitAlarm();
|
||
OS_InitArena();
|
||
PXI_Init();
|
||
OS_InitLock();
|
||
OS_InitArenaEx();
|
||
OS_InitIrqTable();
|
||
OS_SetIrqStackChecker();
|
||
MI_Init();
|
||
OS_InitVAlarm();
|
||
OSi_InitVramExclusive();
|
||
OS_InitThread();
|
||
OS_InitReset();
|
||
GX_Init();
|
||
FX_Init();
|
||
SND_Init();
|
||
SNDEX_Init();
|
||
TP_Init();
|
||
RTC_Init();
|
||
|
||
KamiPxiInit(); /* “ÆŽ©PXI<58>‰Šú‰» */
|
||
|
||
// Vƒuƒ‰ƒ“ƒNŠ„‚è<E2809A>ž‚Ý<E2809A>Ý’è
|
||
OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
|
||
(void)OS_EnableIrqMask(OS_IE_V_BLANK);
|
||
(void)OS_EnableIrqMask(OS_IE_FIFO_RECV);
|
||
(void)OS_EnableIrq();
|
||
(void)GX_VBlankIntr(TRUE);
|
||
|
||
// initialize file-system
|
||
FS_Init(FS_DMA_NOT_USE);
|
||
|
||
InitAllocation();
|
||
|
||
// NAMƒ‰ƒCƒuƒ‰ƒŠ<C692>‰Šú‰»
|
||
NAM_Init( OS_AllocFromMain, OS_FreeToMain );
|
||
NAMUT_Init( OS_AllocFromMain, OS_FreeToMain ); // SoftBoxCount‚ÌŒvŽZ‚É•K—v
|
||
|
||
// •\ަŠÖ˜A<CB9C>‰Šú‰»
|
||
InitGraphics();
|
||
kamiFontInit();
|
||
kamiFontPrintfConsole(FONT_COLOR_GREEN, "Log Window:\n");
|
||
|
||
// ƒ<>ƒCƒ“ƒXƒŒƒbƒh‚̃J<C692>[ƒhƒ<68>ƒbƒNIDŽæ“¾
|
||
gLockId = OS_GetLockID();
|
||
|
||
/* always preload FS table for faster directory access. */
|
||
{
|
||
u32 need_size = FS_GetTableSize();
|
||
void *p_table = OS_Alloc(need_size);
|
||
SDK_ASSERT(p_table != NULL);
|
||
(void)FS_LoadTable(p_table, need_size);
|
||
}
|
||
|
||
// ƒtƒHƒ“ƒg<C692>‰Šú‰»
|
||
InitFont();
|
||
|
||
// ƒRƒ“ƒ\<5C>[ƒ‹ƒ`ƒFƒbƒN
|
||
ProcessCheckConsole();
|
||
|
||
// ƒ<>ƒO<C692>î•ñŠm”F
|
||
ProcessCheckLog();
|
||
|
||
// ƒŠ<C692>[ƒWƒ‡ƒ“‘I‘ð
|
||
ProcessSelectRegion();
|
||
|
||
// Note•\ަ
|
||
ProcessNote();
|
||
|
||
// TWL‚Ì<E2809A>X<EFBFBD>V<EFBFBD>ˆ—<CB86>‚ðŽÀ<C5BD>s’†‚Å‚·
|
||
CARD_LockRom((u16)gLockId);
|
||
(void)CARDi_ReadRomIDCoreEx(DEBUGGER_COMMAND_NOW_UPDATE);
|
||
CARD_UnlockRom((u16)gLockId);
|
||
|
||
// ISƒfƒoƒbƒK‚̃n<C692>[ƒhƒEƒFƒAƒŠƒZƒbƒg‚ð‹ÖŽ~‚·‚é
|
||
DEBUGGER_HwResetDisable();
|
||
|
||
// HWInfoŠÖ˜A‚Ì‘O<E28098>€”õ
|
||
switch (HWI_Init( OS_AllocFromMain, OS_FreeToMain ))
|
||
{
|
||
case HWI_INIT_FAILURE:
|
||
kamiFontPrintfConsole(FONT_COLOR_RED, " Fail! : HWI_INIT()\n");
|
||
break;
|
||
case HWI_INIT_SUCCESS_PRO_SIGNATURE_MODE:
|
||
break;
|
||
case HWI_INIT_SUCCESS_DEV_SIGNATURE_MODE:
|
||
break;
|
||
case HWI_INIT_SUCCESS_NO_SIGNATRUE_MODE:
|
||
break;
|
||
}
|
||
|
||
result = TRUE;
|
||
|
||
// NAND‚̃tƒH<C692>[ƒ}ƒbƒg‚ªŒÃ‚¯‚ê‚΃tƒH<C692>[ƒ}ƒbƒg
|
||
result &= ProcessFormat();
|
||
|
||
// ‘Sƒn<C692>[ƒhƒEƒFƒA<C692>î•ñ‚Ì<E2809A>X<EFBFBD>V
|
||
result &= ProcessHwinfo();
|
||
|
||
// ƒtƒHƒ“ƒg‚Ì<E2809A>‘‚«<E2809A>ž‚Ý
|
||
result &= ProcessWriteFont();
|
||
|
||
// cert.sys‚Ì<E2809A>‘‚«<E2809A>ž‚Ý
|
||
result &= ProcessWriteCert();
|
||
|
||
// ƒ_ƒ~<7E>[ƒtƒ@ƒCƒ‹‚Ì<E2809A>¶<EFBFBD>¬
|
||
result &= ProcessWriteDummy();
|
||
|
||
// TAD‚̃Cƒ“ƒ|<7C>[ƒgŠJŽn
|
||
result &= ProcessImport();
|
||
|
||
// ‘I‘ðƒŠ<C692>[ƒWƒ‡ƒ“ˆÈŠO‚ÌSystemMenu‚Ì<E2809A>Á‹Ž‚ð<E2809A>s‚¤
|
||
result &= ProcessDeleteOtherResionSysmenu();
|
||
|
||
// NANDƒtƒ@<40>[ƒ€‚̃Cƒ“ƒXƒg<C692>[ƒ‹ŠJŽn
|
||
result &= ProcessNandfirm();
|
||
|
||
// –{‘Ì<E28098>‰Šú‰»‚ð<E2809A>s‚¤
|
||
result &= ProcessNamutFormat();
|
||
|
||
// <20>X<EFBFBD>Vƒ<56>ƒO‚ð<E2809A>ì<EFBFBD>¬‚µ‚ÄVersionDown‚ð–h‚®
|
||
if (result)
|
||
{
|
||
ProcessLog();
|
||
}
|
||
|
||
// ISƒfƒoƒbƒK‚̃n<C692>[ƒhƒEƒFƒAƒŠƒZƒbƒg‚ð‹–‰Â‚·‚é
|
||
DEBUGGER_HwResetEnable();
|
||
|
||
// Œ‹‰Ê•\ަ
|
||
ProcessFinish( result );
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: VBlankIntr
|
||
|
||
Description: VBlankŠ„‚è<E2809A>ž‚Ý<E2809A>ˆ—<CB86>
|
||
|
||
Arguments: None.
|
||
|
||
Returns: None.
|
||
*---------------------------------------------------------------------------*/
|
||
static void
|
||
VBlankIntr(void)
|
||
{
|
||
// kamiFontLoadScreenData();
|
||
OS_SetIrqCheckFlag(OS_IE_V_BLANK); // checking VBlank interrupt
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: InitAllocation
|
||
|
||
Description: ƒq<C692>[ƒv‚Ì<E2809A>‰Šú‰».
|
||
|
||
Arguments: None.
|
||
|
||
Returns: None.
|
||
*---------------------------------------------------------------------------*/
|
||
static void InitAllocation(void)
|
||
{
|
||
void *tmp;
|
||
OSHeapHandle hh;
|
||
|
||
/* ƒAƒŠ<C692>[ƒi‚Ì<E2809A>‰Šú‰» */
|
||
tmp = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1);
|
||
OS_SetArenaLo(OS_ARENA_MAIN, tmp);
|
||
hh = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi());
|
||
if (hh < 0)
|
||
OS_Panic("ARM9: Fail to create heap...\n");
|
||
hh = OS_SetCurrentHeap(OS_ARENA_MAIN, hh);
|
||
}
|