mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
WiFiアイコン確認アプリ をコミット git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@2026 b08762b0-b915-fc4b-9d8c-17b2551a87ff
287 lines
7.5 KiB
C++
287 lines
7.5 KiB
C++
/*---------------------------------------------------------------------------*
|
||
Project: TwlSDK - tools - NandFiler
|
||
File: main.cpp
|
||
|
||
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/fs.h>
|
||
#include <nitro/std.h>
|
||
|
||
#include <string>
|
||
#include <list>
|
||
#include "suffix.h"
|
||
|
||
inline void* operator new(size_t size) { return OS_Alloc(size); }
|
||
inline void* operator new[](size_t size) { return OS_Alloc(size); }
|
||
inline void operator delete(void* ptr) { OS_Free(ptr); }
|
||
inline void operator delete[](void* ptr) { OS_Free(ptr); }
|
||
|
||
typedef std::list<std::string> PathList;
|
||
|
||
namespace
|
||
{
|
||
void
|
||
InitInterrupt(void)
|
||
{
|
||
OS_EnableIrq();
|
||
OS_EnableInterrupts();
|
||
}
|
||
|
||
void
|
||
InitAlloc(void)
|
||
{
|
||
OSHeapHandle hHeap;
|
||
void* lo = OS_GetMainArenaLo();
|
||
void* hi = OS_GetMainArenaHi();
|
||
|
||
lo = OS_InitAlloc(OS_ARENA_MAIN, lo, hi, 1);
|
||
OS_SetArenaLo(OS_ARENA_MAIN, lo);
|
||
|
||
hHeap = OS_CreateHeap(OS_ARENA_MAIN, lo, hi);
|
||
SDK_ASSERT( hHeap >= 0 );
|
||
|
||
OS_SetCurrentHeap(OS_ARENA_MAIN, hHeap);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
static void InitInteruptSystem();
|
||
static void InitFileSystem();
|
||
|
||
static void PickupTargetPath(const char* root, const char* suffix, PathList& out);
|
||
static void CopyTarget(const char* to, const char* header, PathList& out);
|
||
static void CopyFile(const char* src, const char* dest);
|
||
|
||
void
|
||
TwlStartUp()
|
||
{
|
||
OS_Init();
|
||
InitAlloc();
|
||
}
|
||
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: TwlMain
|
||
|
||
Description: <20><><EFBFBD>C<EFBFBD><43><EFBFBD><EFBFBD><D690>ł<EFBFBD><C582>B
|
||
|
||
Arguments: <20>Ȃ<EFBFBD><C882>B
|
||
|
||
Returns: <20>Ȃ<EFBFBD><C882>B
|
||
*---------------------------------------------------------------------------*/
|
||
void TwlMain(void)
|
||
{
|
||
InitInteruptSystem();
|
||
InitFileSystem();
|
||
|
||
GX_DispOn();
|
||
GXS_DispOn();
|
||
|
||
// SD<53><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĂȂ<C482><C882><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>h<EFBFBD><68><EFBFBD><EFBFBD><EFBFBD>܂ő҂<C591>
|
||
{
|
||
FSArchiveResource res;
|
||
while(!FS_GetArchiveResource("sdmc:/", &res))
|
||
{
|
||
*(u16*)HW_PLTT = static_cast<u16>(0x001f);
|
||
*(u16*)HW_DB_PLTT = static_cast<u16>(0x001f);
|
||
}
|
||
}
|
||
|
||
PathList path;
|
||
|
||
for(u32 i = 0; i < sizeof(SUFFIX) / sizeof(char*); ++i)
|
||
{
|
||
PickupTargetPath("sdmc:/", SUFFIX[i], path);
|
||
}
|
||
CopyTarget("nand2:/photo", "sdmc:", path);
|
||
|
||
|
||
*(u16*)HW_PLTT = 0x001f << 10;
|
||
*(u16*)HW_DB_PLTT = 0x001f << 10;
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD>`<60><><EFBFBD>[<5B>ɖ߂<C996><DF82><EFBFBD><EFBFBD>悤<EFBFBD>ɁA <20>I<EFBFBD><49><EFBFBD><EFBFBD><EFBFBD>Ȃ<EFBFBD>
|
||
for (;;)
|
||
{
|
||
// <20>t<EFBFBD><74><EFBFBD>[<5B><><EFBFBD>X<EFBFBD>V<EFBFBD>B
|
||
{
|
||
OS_WaitVBlankIntr();
|
||
}
|
||
}
|
||
|
||
OS_Terminate();
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: InitInteruptSystem
|
||
|
||
Description: <20><><EFBFBD>荞<EFBFBD>݂<EFBFBD><DD82><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>܂<EFBFBD><DC82>B
|
||
|
||
Arguments: <20>Ȃ<EFBFBD><C882>B
|
||
|
||
Returns: <20>Ȃ<EFBFBD><C882>B
|
||
*---------------------------------------------------------------------------*/
|
||
static void InitInteruptSystem()
|
||
{
|
||
// <20>ʊ<C295><CA8A>荞<EFBFBD>݃t<DD83><74><EFBFBD>O<EFBFBD><4F><EFBFBD>S<EFBFBD>ĕs<C495><73><EFBFBD><EFBFBD>
|
||
(void)OS_SetIrqMask(0);
|
||
|
||
// <20>}<7D>X<EFBFBD>^<5E>[<5B><><EFBFBD>荞<EFBFBD>݃t<DD83><74><EFBFBD>O<EFBFBD><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
(void)OS_EnableIrq();
|
||
|
||
// IRQ <20><><EFBFBD>荞<EFBFBD>݂<EFBFBD><DD82><EFBFBD><EFBFBD><EFBFBD><C282>܂<EFBFBD>
|
||
(void)OS_EnableInterrupts();
|
||
|
||
(void)OS_EnableIrqMask(OS_IE_SPFIFO_RECV);
|
||
}
|
||
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: InitFileSystem
|
||
|
||
Description: FS <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> rom <20>ɃA<C983>N<EFBFBD>Z<EFBFBD>X<EFBFBD>ł<EFBFBD><C582><EFBFBD><EFBFBD>悤<EFBFBD>ɂ<EFBFBD><C982>܂<EFBFBD><DC82>B
|
||
<20><><EFBFBD>̊<CC8A><D690><EFBFBD><EFBFBD>Ăяo<D18F><6F><EFBFBD>O<EFBFBD><4F> InitInteruptSystem() <20><>
|
||
<20>Ă<C482><CE82>Ă<EFBFBD><C482><EFBFBD><EFBFBD>K<EFBFBD>v<EFBFBD><76><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>܂<EFBFBD><DC82>B
|
||
|
||
Arguments: <20>Ȃ<EFBFBD><C882>B
|
||
|
||
Returns: <20>Ȃ<EFBFBD><C882>B
|
||
*---------------------------------------------------------------------------*/
|
||
static void InitFileSystem()
|
||
{
|
||
// ARM7<4D>Ƃ̒ʐMFIFO<46><4F><EFBFBD>荞<EFBFBD><EFBFBD><DD8B><EFBFBD>
|
||
(void)OS_EnableIrqMask(OS_IE_SPFIFO_RECV);
|
||
|
||
// <20>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD>V<EFBFBD>X<EFBFBD>e<EFBFBD><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
FS_Init( FS_DMA_NOT_USE );
|
||
}
|
||
|
||
|
||
static void PickupTargetPath(const char* root, const char* suffix, PathList& out)
|
||
{
|
||
FSFile fp;
|
||
FSDirectoryEntryInfo fdei;
|
||
BOOL result;
|
||
|
||
FS_InitFile(&fp);
|
||
// <20>f<EFBFBD>B<EFBFBD><42><EFBFBD>N<EFBFBD>g<EFBFBD><67><EFBFBD>̃I<CC83>[<5B>v<EFBFBD><76>
|
||
result = FS_OpenDirectory(&fp, root, NULL);
|
||
if(!result)
|
||
{
|
||
OS_TPrintf("%s: Fail Open\nErrorCode:%d\n", root, FS_GetArchiveResultCode(root));
|
||
return;
|
||
}
|
||
|
||
while(FS_ReadDirectory(&fp, &fdei))
|
||
{
|
||
if(STD_StrCmp(fdei.longname, ".") == 0 || STD_StrCmp(fdei.longname, "..") == 0)
|
||
continue;
|
||
|
||
OS_TPrintf("%s:\n", fdei.longname);
|
||
// <20>f<EFBFBD>B<EFBFBD><42><EFBFBD>N<EFBFBD>g<EFBFBD><67><EFBFBD>Ȃ<EFBFBD><C882>q<EFBFBD><71><EFBFBD>ǂ<EFBFBD>
|
||
if(fdei.attributes & FS_ATTRIBUTE_IS_DIRECTORY)
|
||
{
|
||
PickupTargetPath((std::string(root) + fdei.longname + "/").c_str(), suffix, out);
|
||
}
|
||
else // <20>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD>Ȃ<EFBFBD>out<75>ɒlj<C992>
|
||
{
|
||
// <20>g<EFBFBD><67><EFBFBD>q<EFBFBD><EFBFBD>
|
||
if(std::string(fdei.longname).rfind(suffix) + STD_StrLen(suffix) == STD_StrLen(fdei.longname))
|
||
{
|
||
out.push_back(std::string(root) + fdei.longname);
|
||
}
|
||
}
|
||
}
|
||
|
||
FS_CloseDirectory(&fp);
|
||
|
||
}
|
||
|
||
static void CopyTarget(const char* to, const char* header, PathList& list)
|
||
{
|
||
PathList::iterator itr = list.begin(), end = list.end();
|
||
u16 color = 0;
|
||
for(; itr != end; ++itr)
|
||
{
|
||
std::string dest = std::string(to) + (*itr).substr(static_cast<u32>(STD_StrLen(header)));
|
||
|
||
CopyFile((*itr).c_str(), dest.c_str());
|
||
color = static_cast<u16>((color + 2) & 0x001f);
|
||
*(u16*)HW_PLTT = static_cast<u16>(color << 5);
|
||
*(u16*)HW_DB_PLTT = static_cast<u16>(color << 5);
|
||
}
|
||
}
|
||
|
||
static void CopyFile(const char* src, const char* dest)
|
||
{
|
||
FSFile sfp, dfp;
|
||
BOOL result;
|
||
std::string tmp_name = dest;
|
||
|
||
tmp_name += "___tmp";
|
||
|
||
OS_TPrintf("Copying %s...", dest);
|
||
|
||
// <20>e<EFBFBD><65><EFBFBD>|<7C><><EFBFBD><EFBFBD><EFBFBD>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD>ɃR<C983>s<EFBFBD>[
|
||
FS_DeleteFile(tmp_name.c_str());
|
||
result = FS_CreateFileAuto(tmp_name.c_str(), FS_PERMIT_R | FS_PERMIT_W);
|
||
// result = FS_CreateFileAuto(dest, FS_PERMIT_R | FS_PERMIT_W);
|
||
if(!result)
|
||
{
|
||
OS_TPrintf("%s:Cant create\n", tmp_name.c_str());
|
||
return;
|
||
}
|
||
|
||
result = FS_OpenFileEx(&sfp, src, FS_FILEMODE_R);
|
||
if(!result)
|
||
{
|
||
OS_TPrintf("%s:Cant open\n", src);
|
||
return;
|
||
}
|
||
|
||
result = FS_OpenFileEx(&dfp, tmp_name.c_str(), FS_FILEMODE_W);
|
||
if(!result)
|
||
{
|
||
OS_TPrintf("%s:Cant open\n", src);
|
||
FS_CloseFile(&sfp);
|
||
return;
|
||
}
|
||
|
||
const u32 BUFSIZE = 4096;
|
||
u8 buf[BUFSIZE];
|
||
s32 count = 0;
|
||
while((count = FS_ReadFile(&sfp, buf, BUFSIZE)) > 0)
|
||
{
|
||
s32 write = FS_WriteFile(&dfp, buf, count);
|
||
if(write <= 0)
|
||
{
|
||
OS_TPrintf("Cant Write\n");
|
||
FS_CloseFile(&sfp);
|
||
FS_CloseFile(&dfp);
|
||
FS_DeleteFile(tmp_name.c_str());
|
||
return;
|
||
}
|
||
}
|
||
|
||
FS_CloseFile(&sfp);
|
||
FS_CloseFile(&dfp);
|
||
|
||
// <20>e<EFBFBD><65><EFBFBD>|<7C><><EFBFBD><EFBFBD><EFBFBD>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>l<EFBFBD>[<5B><>
|
||
// <20><><EFBFBD>łɃt<C983>@<40>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>݂<EFBFBD><DD82><EFBFBD><EFBFBD>Ȃ<EFBFBD><C882>폜
|
||
FS_DeleteFileAuto(dest);
|
||
FS_RenameFile(tmp_name.c_str(), dest);
|
||
|
||
OS_TPrintf("...ok\n");
|
||
}
|
||
|