diff --git a/build/tools/sctools/Makefile b/build/tools/sctools/Makefile new file mode 100644 index 0000000..ffdb626 --- /dev/null +++ b/build/tools/sctools/Makefile @@ -0,0 +1,30 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: +# File: Makefile +# +# Copyright 2007 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: +#---------------------------------------------------------------------------- + + + +SUBDIRS = copy_org copy_dst + + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + + +#===== End of Makefile ===== diff --git a/build/tools/sctools/common/src/ap_info.h b/build/tools/sctools/common/src/ap_info.h new file mode 100644 index 0000000..7987379 --- /dev/null +++ b/build/tools/sctools/common/src/ap_info.h @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------* + Project: TwlWiFi - demos - netconnect + File: ap_info.h + + Copyright 2005,2006 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:: 2007-10-30#$ + $Rev: 74 $ + $Author: adachi_hiroaki $ + *---------------------------------------------------------------------------*/ + +#ifndef SHARED_AP_INFO_H_ +#define SHARED_AP_INFO_H_ + +#ifdef __cplusplus + +extern "C" { +#endif + +/*===========================================================================*/ +#include + +// AP 情報構造体 型定義 +typedef struct WcmControlApInfo +{ + u8 bssId[WCM_BSSID_SIZE]; + WCMWepDesc wepDesc; + u8 essId[WCM_ESSID_SIZE]; + u32 auth_option; + +} WcmControlApInfo; + +// 固定 AP 情報の参照 +extern const WcmControlApInfo constApInfo; + +/*===========================================================================*/ +#ifdef __cplusplus + +} /* extern "C" */ +#endif + +#endif /* SHARED_AP_INFO_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/tools/sctools/common/src/ecdl.cpp b/build/tools/sctools/common/src/ecdl.cpp new file mode 100644 index 0000000..69c62d0 --- /dev/null +++ b/build/tools/sctools/common/src/ecdl.cpp @@ -0,0 +1,169 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - ecdl + File: main.c + + Copyright 2007 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:: 2008-09-24#$ + $Rev: 8618 $ + $Author: hatamoto_minoru $ + *---------------------------------------------------------------------------*/ + +#include "ecdl.h" + +#ifdef SDK_DEBUG +#define ECDL_LOG(msg) OS_TPrintf("----\nECDL-LOG: %s\n----\n", msg); +#endif +#ifdef SDK_RELEASE +#define ECDL_LOG(msg) OS_TPrintf("ECDL-LOG: %s\n", msg); +#endif + +namespace +{ + char CheckRegistration() + { + s32 progress; + ECError ecError; + ECDeviceInfo di; + + ECDL_LOG("check registeration"); + progress = EC_CheckRegistration(); + WaitEC(progress); + + ecError = EC_GetDeviceInfo(&di); + SDK_ASSERT( ecError == EC_ERROR_OK ); + +#ifdef SDK_DEBUG +#define ECDL_DI_FMT "%-30s" + OS_TPrintf(ECDL_DI_FMT " %d\n", "isKeyPairConfirmed", di.isKeyPairConfirmed); + OS_TPrintf(ECDL_DI_FMT " %d\n", "deviceId", di.deviceId); + OS_TPrintf(ECDL_DI_FMT " %s\n", "serial", di.serial); + OS_TPrintf(ECDL_DI_FMT " %s\n", "originalSerial", di.originalSerial); + OS_TPrintf(ECDL_DI_FMT " %s\n", "accountId", di.accountId); + OS_TPrintf(ECDL_DI_FMT " %s\n", "registrationStatus", di.registrationStatus); + OS_TPrintf(ECDL_DI_FMT " %s\n", "extAccountId", di.extAccountId); + OS_TPrintf(ECDL_DI_FMT " %s\n", "country", di.country); + OS_TPrintf(ECDL_DI_FMT " %s\n", "accountCountry", di.accountCountry); + OS_TPrintf(ECDL_DI_FMT " %s\n", "region", di.region); + OS_TPrintf(ECDL_DI_FMT " %s\n", "language", di.language); + OS_TPrintf(ECDL_DI_FMT " %d\n", "blockSize", di.blockSize); + OS_TPrintf(ECDL_DI_FMT " %d\n", "usedBlocks", di.usedBlocks); + OS_TPrintf(ECDL_DI_FMT " %d\n", "totalBlocks", di.totalBlocks); + OS_TPrintf(ECDL_DI_FMT " %d\n", "netContentRestrictions", di.netContentRestrictions); + OS_TPrintf(ECDL_DI_FMT " %d\n", "userAge", di.userAge); + OS_TPrintf(ECDL_DI_FMT " %d\n", "parentalControlFlags", di.parentalControlFlags); + OS_TPrintf(ECDL_DI_FMT " %d\n", "parentalControlOgn", di.parentalControlOgn); + OS_TPrintf(ECDL_DI_FMT " %d\n", "isParentalControlEnabled", di.isParentalControlEnabled); + OS_TPrintf(ECDL_DI_FMT " %d\n", "isNeedTicketSync", di.isNeedTicketSync); + OS_TPrintf(ECDL_DI_FMT " %d\n", "lastTicketSyncTime", di.lastTicketSyncTime); + OS_TPrintf(ECDL_DI_FMT " %d\n", "wirelessMACAddr", di.wirelessMACAddr); + OS_TPrintf(ECDL_DI_FMT " %d\n", "bluetoothMACAddr", di.bluetoothMACAddr); + OS_TPrintf(ECDL_DI_FMT " %d\n", "titleId", di.titleId); + OS_TPrintf(ECDL_DI_FMT " %d\n", "freeChannelAppCount", di.freeChannelAppCount); + OS_TPrintf(ECDL_DI_FMT " %d\n", "usedUserInodes", di.usedUserInodes); + OS_TPrintf(ECDL_DI_FMT " %d\n", "maxUserInodes", di.maxUserInodes); + OS_TPrintf(ECDL_DI_FMT " %s\n", "deviceCode", di.deviceCode); + OS_TPrintf(ECDL_DI_FMT " %s\n", "accountDeviceCode", di.accountDeviceCode); + OS_TPrintf(ECDL_DI_FMT " %d\n", "isNeedTicketSyncImportAll", di.isNeedTicketSyncImportAll); +#endif + + return di.registrationStatus[0]; + } + + void GetChallenge(char* challenge) + { + s32 progress; + ECError ecError; + + ECDL_LOG("get challenge"); + progress = EC_SendChallengeReq(); + WaitEC(progress); + + ecError = EC_GetChallengeResp(challenge); + SDK_ASSERT( ecError == EC_ERROR_OK ); + } + + void SyncRegistration(const char* challenge) + { + s32 progress; + + ECDL_LOG("sync registration"); + progress = EC_SyncRegistration(challenge); + WaitEC(progress); + } + + void Register(const char* challenge) + { + s32 progress; + + ECDL_LOG("register"); + progress = EC_Register(challenge, NULL, NULL); + WaitEC(progress); + } + + void Transfer(const char* challenge) + { + s32 progress; + + ECDL_LOG("transfer"); + progress = EC_Transfer(challenge); + WaitEC(progress); + } + + void SyncTickets() + { + s32 progress; + + ECDL_LOG("sync tickets"); + progress = EC_SyncTickets(EC_SYNC_TYPE_IMPORT_ALL); + WaitEC(progress); + } + + void DownloadTitles(const NAMTitleId* pTitleIds, u32 numTitleIds) + { + s32 progress; + + ECDL_LOG("download"); + for( u32 i = 0; i < numTitleIds; ++i ) + { + NAMTitleId tid = pTitleIds[i]; + + OS_TPrintf("download %08X %08X\n", (u32)(tid >> 32), (u32)tid); + progress = EC_DownloadTitle(tid, EC_DT_UPDATE_REQUIRED_CONTENTS); + WaitEC(progress); + } + } +} + + +void +ECDownload(const NAMTitleId* pTitleIds, u32 numTitleIds) +{ + char challenge[EC_CHALLENGE_BUF_SIZE]; + char status; + + status = CheckRegistration(); + // U unregistered + // R registered + // P pending + // T transfered + SDK_ASSERTMSG(status != 'U', "acount not transfered yet."); + SDK_ASSERTMSG(status != 'R', "already registered. please delete acount."); + SDK_ASSERTMSG( (status == 'P') || (status == 'T'), "invalid registration status '%c'", status ); + + GetChallenge(challenge); + Transfer(challenge); + + GetChallenge(challenge); + SyncRegistration(challenge); + + SyncTickets(); + DownloadTitles(pTitleIds, numTitleIds); +} + diff --git a/build/tools/sctools/common/src/ecdl.h b/build/tools/sctools/common/src/ecdl.h new file mode 100644 index 0000000..d4f7a47 --- /dev/null +++ b/build/tools/sctools/common/src/ecdl.h @@ -0,0 +1,43 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - ecdl + File: ecdl.h + + Copyright 2007 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:: 2008-09-19#$ + $Rev: 8593 $ + $Author: hatamoto_minoru $ + *---------------------------------------------------------------------------*/ +#ifndef ECDL_H_ +#define ECDL_H_ + +#define EC_NO_JS + +#include +#include +#include +#include "es.h" +#include "ecx.h" + +#define PRINT_LINE OS_TPrintf("%4d\n", __LINE__) + +#ifdef __cplusplus +extern "C" { +#endif + +void ECDownload(const NAMTitleId* pTitleIds, u32 numTitleIds); +void KPSClient(); +void WaitEC(ECOpId opId); + + +#ifdef __cplusplus +} +#endif + +#endif // ECDL_H_ diff --git a/build/tools/sctools/common/src/font.c b/build/tools/sctools/common/src/font.c new file mode 100644 index 0000000..cea8cdc --- /dev/null +++ b/build/tools/sctools/common/src/font.c @@ -0,0 +1,827 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - demos - sio + File: font.c + + Copyright 2003,2004 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. + + $Log: font.c,v $ + Revision 1.1 2004/08/14 11:13:01 Miya + initial check in + + Revision 1.1 2004/06/19 10:36:03 Miya + initial check-in + + Revision 1.1 2004/06/19 05:30:25 Miya + initial check in + + Revision 1.1 2004/03/17 07:25:48 terui + initial upload + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#include +#include "font.h" + +const u32 d_CharData[0xe0 * 8] = { + 0x00000000,0x00000000,0x00000000,0x00000000, //0000 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x11111111,0x11111111,0x11111111,0x11111111, //0001 + 0x11111111,0x11111111,0x11111111,0x11111111, + 0x22222222,0x22222222,0x22222222,0x22222222, //0002 + 0x22222222,0x22222222,0x22222222,0x22222222, + 0x33333333,0x33333333,0x33333333,0x33333333, //0003 + 0x33333333,0x33333333,0x33333333,0x33333333, + 0x00000000,0x03333330,0x03333330,0x03333330, //0004 + 0x03333330,0x03333330,0x03333330,0x00000000, + 0x33333333,0x33333333,0x33333333,0x33333333, //0005 + 0x22222222,0x22222222,0x22222222,0x22222222, + 0x00000000,0x00003330,0x00033330,0x00333330, //0006 + 0x03333330,0x00333330,0x00033330,0x00003330, + 0x00000000,0x00000000,0x00003300,0x00033300, //0007 + 0x00333300,0x00033300,0x00003300,0x00000000, + 0x03333333,0x03333333,0x03333333,0x03333333, //0008 + 0x03333333,0x03333333,0x03333333,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0009 + 0x00000000,0x00000000,0x00000000,0x33333333, + 0x00000000,0x00000000,0x00000000,0x00000000, //000A + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //000B + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //000C + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //000D + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //000E + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //000F + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0010 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0011 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0012 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0013 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0014 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0015 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0016 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0017 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0018 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0019 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //001A + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //001B + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //001C + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //001D + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //001E + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //001F + 0x00000000,0x00000000,0x00000000,0x00000000, + + 0x00000000,0x00000000,0x00000000,0x00000000, //0020 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00011000,0x00011000,0x00011000,0x00011000, //0021 ! + 0x00000000,0x00011000,0x00011000,0x00000000, + 0x00011011,0x00011011,0x00010010,0x00000000, //0022 " + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00010100,0x00111110,0x00010100, //0023 # + 0x00010100,0x00111110,0x00010100,0x00000000, + 0x00001000,0x00111110,0x00001011,0x00111110, //0024 $ + 0x01101000,0x00111110,0x00001000,0x00000000, + 0x01100111,0x00110101,0x00011111,0x00001100, //0025 % + 0x01110110,0x01010011,0x01110001,0x00000000, + 0x00011100,0x00110110,0x00011100,0x00001110, //0026 & + 0x00011011,0x01110011,0x00111110,0x00000000, + 0x00000011,0x00000011,0x00000010,0x00000000, //0027 ' + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00011100,0x00000110,0x00000011,0x00000011, //0028 ( + 0x00000011,0x00000110,0x00011100,0x00000000, + 0x00011100,0x00110000,0x01100000,0x01100000, //0029 ) + 0x01100000,0x00110000,0x00011100,0x00000000, + 0x00000000,0x00000000,0x00001000,0x00101010, //002A * + 0x00011100,0x00101010,0x00001000,0x00000000, + 0x00000000,0x00000000,0x00001000,0x00001000, //002B + + 0x00111110,0x00001000,0x00001000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //002C , + 0x00000000,0x00000011,0x00000011,0x00000010, + 0x00000000,0x00000000,0x00000000,0x00000000, //002D - + 0x00111110,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //002E . + 0x00000000,0x00000011,0x00000011,0x00000000, + 0x01100000,0x00110000,0x00011000,0x00001100, //002F / + 0x00000110,0x00000011,0x00000001,0x00000000, + 0x00011100,0x00110010,0x01100011,0x01100011, //0030 0 + 0x01100011,0x00100110,0x00011100,0x00000000, + 0x00011000,0x00011100,0x00011110,0x00011000, //0031 1 + 0x00011000,0x00011000,0x00011000,0x00000000, + 0x00111110,0x01100011,0x01100011,0x00111000, //0032 2 + 0x00001110,0x00000011,0x01111111,0x00000000, + 0x01111110,0x00110000,0x00011000,0x00111100, //0033 3 + 0x01100000,0x01100011,0x00111110,0x00000000, + 0x00110000,0x00111000,0x00111100,0x00110110, //0034 4 + 0x00110011,0x01111111,0x00110000,0x00000000, + 0x00111111,0x00000011,0x00000011,0x00111111, //0035 5 + 0x01100000,0x01100011,0x00111110,0x00000000, + 0x00111100,0x00000110,0x00000011,0x00111111, //0036 6 + 0x01100011,0x01100011,0x00111110,0x00000000, + 0x01111111,0x01110000,0x00111000,0x00011100, //0037 7 + 0x00001100,0x00001100,0x00001100,0x00000000, + 0x00111110,0x01100011,0x01100011,0x00111110, //0038 8 + 0x01100011,0x01100011,0x00111110,0x00000000, + 0x00111110,0x01100011,0x01100011,0x01111110, //0039 9 + 0x01100000,0x00110000,0x00011110,0x00000000, + 0x00000000,0x00011000,0x00011000,0x00000000, //003A : + 0x00000000,0x00011000,0x00011000,0x00000000, + 0x00000000,0x00011000,0x00011000,0x00000000, //003B ; + 0x00000000,0x00011000,0x00011000,0x00010000, + 0x01100000,0x00111000,0x00001110,0x00000011, //003C < + 0x00001110,0x00111000,0x01100000,0x00000000, + 0x00000000,0x00000000,0x00111110,0x00000000, //003D = + 0x00000000,0x00111110,0x00000000,0x00000000, + 0x00000011,0x00001110,0x00111000,0x01100000, //003E > + 0x00111000,0x00001110,0x00000011,0x00000000, + 0x01111110,0x11000011,0x11000011,0x01111000, //003F ? + 0x00011000,0x00000000,0x00011000,0x00000000, + 0x00111110,0x01100011,0x01011001,0x01010101, //0040 @ + 0x01011101,0x01110011,0x00011110,0x00000000, + 0x00111110,0x01100011,0x01100011,0x01111111, //0041 A + 0x01100011,0x01100011,0x01100011,0x00000000, + 0x00111111,0x01100011,0x01100011,0x00111111, //0042 B + 0x01100011,0x01100011,0x00111111,0x00000000, + 0x00111110,0x01100011,0x01100011,0x00000011, //0043 C + 0x01100011,0x01100011,0x00111110,0x00000000, + 0x00111111,0x01100011,0x01100011,0x01100011, //0044 D + 0x01100011,0x01100011,0x00111111,0x00000000, + 0x01111111,0x00000011,0x00000011,0x00111111, //0045 E + 0x00000011,0x00000011,0x01111111,0x00000000, + 0x01111111,0x00000011,0x00000011,0x00111111, //0046 F + 0x00000011,0x00000011,0x00000011,0x00000000, + 0x00111110,0x01100011,0x00000011,0x01111011, //0047 G + 0x01100011,0x01100011,0x00111110,0x00000000, + 0x01100011,0x01100011,0x01100011,0x01111111, //0048 H + 0x01100011,0x01100011,0x01100011,0x00000000, + 0x00011000,0x00011000,0x00011000,0x00011000, //0049 I + 0x00011000,0x00011000,0x00011000,0x00000000, + 0x01100000,0x01100000,0x01100000,0x01100000, //004A J + 0x01100000,0x01100011,0x00111110,0x00000000, + 0x01100011,0x01110011,0x00111011,0x00011111, //004B K + 0x00111011,0x01110011,0x01100011,0x00000000, + 0x00000011,0x00000011,0x00000011,0x00000011, //004C L + 0x00000011,0x00000011,0x01111111,0x00000000, + 0x01100011,0x01100011,0x01110111,0x01110111, //004D M + 0x01111111,0x01101011,0x01101011,0x00000000, + 0x01100011,0x01100111,0x01101111,0x01111111, //004E N + 0x01111011,0x01110011,0x01100011,0x00000000, + 0x00111110,0x01100011,0x01100011,0x01100011, //004F O + 0x01100011,0x01100011,0x00111110,0x00000000, + 0x00111111,0x01100011,0x01100011,0x00111111, //0050 P + 0x00000011,0x00000011,0x00000011,0x00000000, + 0x00111110,0x01100011,0x01100011,0x01100011, //0051 Q + 0x01100011,0x00111110,0x01110000,0x00000000, + 0x00111111,0x01100011,0x01100011,0x00111111, //0052 R + 0x01100011,0x01100011,0x01100011,0x00000000, + 0x00111110,0x01100011,0x00000011,0x00111110, //0053 S + 0x01100000,0x01100011,0x00111110,0x00000000, + 0x11111111,0x00011000,0x00011000,0x00011000, //0054 T + 0x00011000,0x00011000,0x00011000,0x00000000, + 0x01100011,0x01100011,0x01100011,0x01100011, //0055 U + 0x01100011,0x01100011,0x00111110,0x00000000, + 0x01100011,0x01100011,0x00110110,0x00110110, //0056 V + 0x00011100,0x00011100,0x00001000,0x00000000, + 0x11011011,0x11011011,0x11011011,0x11011011, //0057 W + 0x11011011,0x01111110,0x01100110,0x00000000, + 0x01000001,0x01100011,0x00110110,0x00011100, //0058 X + 0x00011100,0x00110110,0x01100011,0x00000000, + 0x11000011,0x11000011,0x11100111,0x01111110, //0059 Y + 0x00011000,0x00011000,0x00011000,0x00000000, + 0x01111111,0x00110000,0x00011000,0x00001100, //005A Z + 0x00000110,0x00000011,0x01111111,0x00000000, + 0x00001111,0x00000011,0x00000011,0x00000011, //005B [ + 0x00000011,0x00000011,0x00001111,0x00000000, + 0x01100110,0x01100110,0x11111111,0x00011000, //005C \. + 0x11111111,0x00011000,0x00011000,0x00000000, + 0x01111000,0x01100000,0x01100000,0x01100000, //005D ] + 0x01100000,0x01100000,0x01111000,0x00000000, + 0x00011100,0x00110110,0x00100010,0x00000000, //005E ^ + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //005F _ + 0x00000000,0x00000000,0x01111111,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0060 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x01111000,0x01100100, //0061 a + 0x01100110,0x01110110,0x01101110,0x00000000, + 0x00000110,0x00000110,0x00111110,0x01100110, //0062 b + 0x01100110,0x01100110,0x00111110,0x00000000, + 0x00000000,0x00000000,0x00111100,0x01100110, //0063 c + 0x00000110,0x01100110,0x00111100,0x00000000, + 0x01100000,0x01100000,0x01111100,0x01100110, //0064 d + 0x01100110,0x01100110,0x01111100,0x00000000, + 0x00000000,0x00000000,0x00111100,0x01100110, //0065 e + 0x01111110,0x00000110,0x00111100,0x00000000, + 0x01110000,0x00011000,0x01111110,0x00011000, //0066 f + 0x00011000,0x00011000,0x00011000,0x00000000, + 0x00000000,0x00000000,0x00111100,0x01100110, //0067 g + 0x01100110,0x01111100,0x01100000,0x00111110, + 0x00000110,0x00000110,0x00000110,0x00111110, //0068 h + 0x01100110,0x01100110,0x01100110,0x00000000, + 0x00011000,0x00011000,0x00000000,0x00011000, //0069 i + 0x00011000,0x00011000,0x00011000,0x00000000, + 0x00110000,0x00110000,0x00000000,0x00110000, //006A j + 0x00110000,0x00110000,0x00110011,0x00011110, + 0x00000011,0x01100011,0x00110011,0x00011111, //006B k + 0x00011111,0x00110011,0x01100011,0x00000000, + 0x00011000,0x00011000,0x00011000,0x00011000, //006C l + 0x00011000,0x00011000,0x00011000,0x00000000, + 0x00000000,0x00000000,0x01111111,0x11011011, //006D m + 0x11011011,0x11011011,0x11011011,0x00000000, + 0x00000000,0x00000000,0x00111110,0x01100110, //006E n + 0x01100110,0x01100110,0x01100110,0x00000000, + 0x00000000,0x00000000,0x00111100,0x01100110, //006F o + 0x01100110,0x01100110,0x00111100,0x00000000, + 0x00000000,0x00000000,0x00111110,0x01100110, //0070 p + 0x01100110,0x00111110,0x00000110,0x00000110, + 0x00000000,0x00000000,0x01111100,0x01100110, //0071 q + 0x01100110,0x01111100,0x01100000,0x01100000, + 0x00000000,0x00000000,0x00101100,0x00011100, //0072 r + 0x00001100,0x00001100,0x00001100,0x00000000, + 0x00000000,0x00000000,0x00111100,0x00000110, //0073 s + 0x00111100,0x01100000,0x00111100,0x00000000, + 0x00000000,0x00011000,0x00111100,0x00011000, //0074 t + 0x00011000,0x00011000,0x00110000,0x00000000, + 0x00000000,0x00000000,0x01100110,0x01100110, //0075 u + 0x01100110,0x01100110,0x01111100,0x00000000, + 0x00000000,0x00000000,0x01100110,0x01100110, //0076 v + 0x01100110,0x00111100,0x00011000,0x00000000, + 0x00000000,0x00000000,0x11011011,0x11011011, //0077 w + 0x11011011,0x11011011,0x01111110,0x00000000, + 0x00000000,0x00000000,0x01100110,0x00111100, //0078 x + 0x00011000,0x00111100,0x01100110,0x00000000, + 0x00000000,0x00000000,0x01100110,0x01100110, //0079 y + 0x01100110,0x01111100,0x01100000,0x00111110, + 0x00000000,0x00000000,0x01111110,0x00110000, //007A z + 0x00011000,0x00001100,0x01111110,0x00000000, + 0x00011100,0x00000110,0x00000110,0x00000111, //007B { + 0x00000110,0x00000110,0x00011100,0x00000000, + 0x00001000,0x00001000,0x00001000,0x00001000, //007C | + 0x00001000,0x00001000,0x00001000,0x00000000, + 0x00011100,0x00110000,0x00110000,0x01110000, //007D } + 0x00110000,0x00110000,0x00011100,0x00000000, + 0x01101100,0x00111110,0x00011011,0x00000000, //007E ~ + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //007F + 0x00000000,0x00000000,0x00000000,0x00000000, + + 0x00000000,0x00000000,0x00000000,0x00000000, //0080 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0081 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0082 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0083 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0084 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0085 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0086 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0087 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0088 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0089 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //008A + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //008B + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //008C + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //008D + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //008E + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //008F + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0090 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0091 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0092 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0093 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0094 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0095 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0096 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0097 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0098 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //0099 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //009A + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //009B + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //009C + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //009D + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //009E + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //009F + 0x00000000,0x00000000,0x00000000,0x00000000, + + 0x00000000,0x00000000,0x00000000,0x00000000, //00A0 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //00A1 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //00A2 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //00A3 + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, //00A4 + 0x00000000,0x00000000,0x00000000,0x00000000, + + 0x00000000,0x00000000,0x00000000,0x00001100, //00A5 ・ + 0x00001100,0x00000000,0x00000000,0x00000000, + 0x01111110,0x01000000,0x01111110,0x01000000, //00A6 ヲ + 0x01100000,0x00110000,0x00011100,0x00000000, + 0x00000000,0x00000000,0x00111110,0x00101000, //00A7 ァ + 0x00011000,0x00001000,0x00000100,0x00000000, + 0x00000000,0x00000000,0x00100000,0x00011000, //00A8 ィ + 0x00001110,0x00001000,0x00001000,0x00000000, + 0x00000000,0x00000000,0x00001000,0x00111110, //00A9 ゥ + 0x00100010,0x00110000,0x00011100,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00011100, //00AA ェ + 0x00001000,0x00001000,0x00111110,0x00000000, + 0x00000000,0x00000000,0x00010000,0x00111110, //00AB ォ + 0x00011000,0x00010100,0x00010010,0x00000000, + 0x00000000,0x00000000,0x00000100,0x00111110, //00AC ャ + 0x00100100,0x00010100,0x00000100,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00011100, //00AD ュ + 0x00010000,0x00010000,0x01111110,0x00000000, + 0x00000000,0x00000000,0x00111100,0x00100000, //00AE ョ + 0x00111100,0x00100000,0x00111100,0x00000000, + 0x00000000,0x00000000,0x00001010,0x00101010, //00AF ッ + 0x00100000,0x00110000,0x00011100,0x00000000, + 0x00000000,0x00000000,0x00000000,0x01111110, //00B0 ー + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x01111111,0x01000000,0x01100100,0x00111100, //00B1 ア + 0x00000100,0x00000110,0x00000011,0x00000000, + 0x01100000,0x00110000,0x00011100,0x00010111, //00B2 ィ + 0x00010000,0x00010000,0x00010000,0x00000000, + 0x00001000,0x01111111,0x01000001,0x01000001, //00B3 ウ + 0x01100000,0x00110000,0x00011110,0x00000000, + 0x00000000,0x00111110,0x00001000,0x00001000, //00B4 エ + 0x00001000,0x00001000,0x01111111,0x00000000, + 0x00100000,0x01111111,0x00101000,0x00101100, //00B5 オ + 0x00100110,0x00100011,0x00110000,0x00000000, + 0x00000100,0x01111111,0x01000100,0x01000100, //00B6 カ + 0x01000100,0x01100110,0x00110011,0x00000000, + 0x00000100,0x01111111,0x00001000,0x00001000, //00B7 キ + 0x01111111,0x00010000,0x00010000,0x00000000, + 0x01111110,0x01000010,0x01000011,0x01000000, //00B8 ク + 0x01100000,0x00110000,0x00011110,0x00000000, + 0x00000010,0x01111110,0x00010010,0x00010001, //00B9 ケ + 0x00010000,0x00011000,0x00001110,0x00000000, + 0x01111111,0x01000000,0x01000000,0x01000000, //00BA コ + 0x01000000,0x01000000,0x01111111,0x00000000, + 0x00100010,0x01111111,0x00100010,0x00100010, //00BB サ + 0x00100000,0x00110000,0x00011110,0x00000000, + 0x00000011,0x01000000,0x01000011,0x01000000, //00BC シ + 0x01000000,0x01100000,0x00111111,0x00000000, + 0x00111111,0x00100000,0x00100000,0x00010000, //00BD ス + 0x00001000,0x00010100,0x01100011,0x00000000, + 0x00000010,0x01111111,0x01000010,0x01100010, //00BE セ + 0x00100010,0x00000110,0x01111100,0x00000000, + 0x01000001,0x01000011,0x01000010,0x01100000, //00BF ソ. + 0x00110000,0x00011000,0x00001100,0x00000000, + 0x01111110,0x01000010,0x01000011,0x01111000, //00C0 タ + 0x01000000,0x01100000,0x00111110,0x00000000, + 0x00110000,0x00011110,0x00010000,0x01111111, //00C1 チ + 0x00010000,0x00011000,0x00001110,0x00000000, + 0x01000101,0x01000101,0x01000101,0x01000000, //00C2 ツ + 0x01100000,0x00110000,0x00011110,0x00000000, + 0x00111110,0x00000000,0x01111111,0x00001000, //00C3 テ + 0x00001000,0x00001100,0x00000110,0x00000000, + 0x00000010,0x00000010,0x00000010,0x00011110, //00C4 ト + 0x00100010,0x00000010,0x00000010,0x00000000, + 0x00001000,0x00001000,0x01111111,0x00001000, //00C5 ナ + 0x00001000,0x00001100,0x00000111,0x00000000, + 0x00111110,0x00000000,0x00000000,0x00000000, //00C6 ニ + 0x00000000,0x00000000,0x01111111,0x00000000, + 0x00111111,0x00100000,0x00110000,0x00011010, //00C7 ヌ + 0x00001100,0x00010110,0x00100011,0x00000000, + 0x00001000,0x01111111,0x01100000,0x00110000, //00C8 ネ + 0x00011100,0x01101010,0x01001001,0x00000000, + 0x00100000,0x00100000,0x00100000,0x00100000, //00C9 ノ + 0x00110000,0x00011000,0x00001110,0x00000000, + 0x00011000,0x00110000,0x01100001,0x01000001, //00CA ハ + 0x01000001,0x01000001,0x01000001,0x00000000, + 0x00000001,0x00000001,0x00111111,0x00000001, //00CB ヒ + 0x00000001,0x00000011,0x00111110,0x00000000, + 0x01111111,0x01000000,0x01000000,0x01000000, //00CC フ + 0x01100000,0x00110000,0x00011110,0x00000000, + 0x00000000,0x00000000,0x00001110,0x00011001, //00CD ヘ + 0x00110001,0x01100000,0x01000000,0x00000000, + 0x00001000,0x01111111,0x00001000,0x00001000, //00CE ホ + 0x01001001,0x01001001,0x01001001,0x00000000, + 0x01111111,0x01000000,0x01000000,0x01100011, //00CF マ + 0x00111110,0x00001100,0x00011000,0x00000000, + 0x00011111,0x01110000,0x00000110,0x00011100, //00D0 ミ + 0x00110000,0x00000111,0x01111100,0x00000000, + 0x00001100,0x00000110,0x00000010,0x01000011, //00D1 ム + 0x01000001,0x01000001,0x01111111,0x00000000, + 0x01000000,0x01100010,0x00110100,0x00011000, //00D2 メ + 0x00001100,0x00010110,0x00100011,0x00000000, + 0x01111111,0x00000100,0x01111111,0x00000100, //00D3 モ + 0x00000100,0x00001100,0x01111000,0x00000000, + 0x00000100,0x01111111,0x01000100,0x01100100, //00D4 ヤ + 0x00110100,0x00000100,0x00000100,0x00000000, + 0x00011110,0x00010000,0x00010000,0x00010000, //00D5 ユ + 0x00010000,0x00010000,0x01111111,0x00000000, + 0x01111110,0x01000000,0x01000000,0x01111110, //00D6 ヨ + 0x01000000,0x01000000,0x01111110,0x00000000, + 0x01111111,0x00000000,0x01111111,0x01000000, //00D7 ラ + 0x01000000,0x01100000,0x00111110,0x00000000, + 0x01000010,0x01000010,0x01000010,0x01000010, //00D8 リ + 0x01000000,0x01100000,0x00111100,0x00000000, + 0x00001010,0x00001010,0x00001010,0x00001010, //00D9 ル + 0x01001010,0x01101010,0x00111011,0x00000000, + 0x00000001,0x00000001,0x01000001,0x01100001, //00DA レ + 0x00110001,0x00011001,0x00001111,0x00000000, + 0x01111111,0x01000001,0x01000001,0x01000001, //00DB ロ + 0x01000001,0x01000001,0x01111111,0x00000000, + 0x01111111,0x01000001,0x01000001,0x01000000, //00DC ワ + 0x01100000,0x00110000,0x00011110,0x00000000, + 0x00000111,0x01000000,0x01000000,0x01000000, //00DD ン + 0x01100000,0x00110000,0x00011111,0x00000000, + 0x00001001,0x00010010,0x00000000,0x00000000, //00DE ゛ + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00001110,0x00001010,0x00001110,0x00000000, //00DF ゜ + 0x00000000,0x00000000,0x00000000,0x00000000, +}; + +#if 0 +const u32 d_PaletteData[16][16] = { + {0x0000,0x5294,0x0000,0x0000,}, // Black + {0x0000,0x001f,0x7c00,0x001f, + 0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x7c00}, + {0x0000,0x001f,0x7c00,0x001f, + 0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x7fff}, + {0x7fff,0x7c00,0x7c00,0x7c00,}, // Blue + {0x7fff,0x7c1f,0x0000,0x0000,}, // + {0x7fff,0x7fe0,0x0000,0x0000,}, // + {0x7fff,0x03ff,0x0000,0x0000,}, // + { 0x7c00,0x7fff,0x739c,0x6b5a,0x6318,0x5ad6,0x5294,0x4a52, // 0000h + 0x4210,0x39ce,0x318c,0x294a,0x2108,0x18c6,0x1084,0x0842}, + {0x7fff,0x0000,0x0000,0x0000,}, // + {0x7fff,0x0000,0x0000,0x0000,}, // + {0x7fff,0x0000,0x0000,0x0000,}, // + {0x7fff,0x0000,0x0000,0x0000,}, // + {0x7fff,0x0000,0x0000,0x0000,}, // + {0x7fff,0x0000,0x0000,0x0000,}, // + {0x7fff,0x0000,0x0000,0x0000,}, // + {0x7fff,0x001f,0x0000,0x0000,} // +}; + +#else +const u32 d_PaletteData[8 * 16] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // black + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x001f0000, 0x00000000, 0x00000000, 0x00000000, // red + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03e00000, 0x00000000, 0x00000000, 0x00000000, // green + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7c000000, 0x00000000, 0x00000000, 0x00000000, // blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03ff0000, 0x00000000, 0x00000000, 0x00000000, // yellow + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7c1f0000, 0x00000000, 0x00000000, 0x00000000, // purple + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7fe00000, 0x00000000, 0x00000000, 0x00000000, // light blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00180000, 0x00000000, 0x00000000, 0x00000000, // dark red + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03000000, 0x00000000, 0x00000000, 0x00000000, // dark green + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x60000000, 0x00000000, 0x00000000, 0x00000000, // dark blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03180000, 0x00000000, 0x00000000, 0x00000000, // dark yellow + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x60180000, 0x00000000, 0x00000000, 0x00000000, // dark purple + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x63000000, 0x00000000, 0x00000000, 0x00000000, // dark light blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x56b50000, 0x00000000, 0x00000000, 0x00000000, // gray + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x2d6b0000, 0x00000000, 0x00000000, 0x00000000, // dark gray + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7fff0000, 0x00000000, 0x00000000, 0x00000000, // white + 0x00000000, 0x00000000, 0x00000000, 0x00000000 +}; + +#endif + + +const u32 d_IconCharData[0x80 * 8] = { + 0x00000000,0x0003d300,0x32111100,0x111cb100, // 0000h + 0x11b91100,0xb99b1200,0x999c1300,0x99a11000, + 0x00000000,0x00000000,0x00000000,0x00000032, // 0001h + 0x11112211,0x1111111c,0x999abcb9,0x999999a9, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0002h + 0x04321111,0x21111111,0x11cba999,0xba999999, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0003h + 0x00000000,0x00000003,0x00000031,0x00003211, + 0x00000000,0x0003d300,0x32111100,0x111cb100, // 0004h + 0x11b91100,0xb99b1200,0x999c1300,0x99a11000, + 0x00000000,0x00000000,0x00000000,0x00000032, // 0005h + 0x11112211,0x1111111c,0x999abcb9,0x999999a9, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0006h + 0x04321111,0x21111111,0x11cba999,0xba999999, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0007h + 0x00000000,0x00000003,0x00000031,0x00003211, + 0x00000000,0x0003d300,0x32111100,0x111cb100, // 0008h + 0x11b91100,0xb99b1200,0x999c1300,0x99a11000, + 0x00000000,0x00000000,0x00000000,0x00000032, // 0009h + 0x11112211,0x1111111c,0x999abcb9,0x999999a9, + 0x00000000,0x00000000,0x00000000,0x00000000, // 000ah + 0x04321111,0x21111111,0x11cba999,0xba999999, + 0x00000000,0x00000000,0x00000000,0x00000000, // 000bh + 0x00000000,0x00000003,0x00000031,0x00003211, + 0x00000000,0x0003d300,0x32111100,0x111cb100, // 000ch + 0x11b91100,0xb99b1200,0x999c1300,0x99a11000, + 0x00000000,0x00000000,0x00000000,0x00000032, // 000dh + 0x11112211,0x1111111c,0x999abcb9,0x999999a9, + 0x00000000,0x00000000,0x00000000,0x00000000, // 000eh + 0x04321111,0x21111111,0x11cba999,0xba999999, + 0x00000000,0x00000000,0x00000000,0x00000000, // 000fh + 0x00000000,0x00000003,0x00000031,0x00003211, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0010h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0011h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0012h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0013h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0014h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0015h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0016h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0017h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0018h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0019h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 001ah + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 001bh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 001ch + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 001dh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 001eh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 001fh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x99b12000,0x9ab11300,0x999b1130,0x999a1114, // 0020h + 0x9999b113,0x9999a112,0x99999c11,0x99999b11, + 0x55557999,0x55555999,0x99755999,0x99855999, // 0021h + 0x99955999,0x99955999,0x99955999,0x99955999, + 0x99975555,0x99955555,0x99955799,0x99955899, // 0022h + 0x99955999,0x99955899,0x99955799,0x99955799, + 0x0003111b,0x00311ba9,0x0311b999,0x4111a999, // 0023h + 0x311b9999,0x211a9999,0x11c99999,0x11b99999, + 0x99b12000,0x9ab11300,0x999b1130,0x999a1114, // 0024h + 0x9999b113,0x9999a112,0x99999c11,0x99999b11, + 0x79999999,0x59999999,0x59999999,0x59999999, // 0025h + 0x59999999,0x59999999,0x59999999,0x59999999, + 0x99999997,0x99999995,0x99999995,0x99999995, // 0026h + 0x99999995,0x99999985,0x99999975,0x99999965, + 0x0003111b,0x00311ba9,0x0311b999,0x4111a999, // 0027h + 0x311b9999,0x211a9999,0x11c99999,0x11b99999, + 0x99b12000,0x9ab11300,0x999b1130,0x999a1114, // 0028h + 0x9999b113,0x9999a112,0x99999c11,0x99999b11, + 0x55557999,0x55557999,0x89999999,0x99999999, // 0029h + 0x99999999,0x99999999,0x89999999,0x55557999, + 0x99997555,0x99995555,0x99995567,0x99995579, // 002ah + 0x99995589,0x99995579,0x99995567,0x99995555, + 0x0003111b,0x00311ba9,0x0311b999,0x4111a999, // 002bh + 0x311b9999,0x211a9999,0x11c99999,0x11b99999, + 0x99b12000,0x9ab11300,0x999b1130,0x999a1114, // 002ch + 0x9999b113,0x9999a112,0x99999c11,0x99999b11, + 0x55557999,0x55557999,0x99999999,0x99999999, // 002dh + 0x99999999,0x99999999,0x99999999,0x55799999, + 0x99975555,0x99955555,0x99955678,0x99955799, // 002eh + 0x99955899,0x99955799,0x99955678,0x99955555, + 0x0003111b,0x00311ba9,0x0311b999,0x4111a999, // 002fh + 0x311b9999,0x211a9999,0x11c99999,0x11b99999, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0030h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0031h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0032h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0033h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0034h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0035h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0036h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0037h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0038h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0039h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 003ah + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 003bh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 003ch + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 003dh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 003eh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 003fh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x99999b11,0x99999c11,0x9999a112,0x9999b113, // 0040h + 0x999a1114,0x999b1130,0x9ab11300,0xb1113000, + 0x99955999,0x99955999,0x99955999,0x99955999, // 0041h + 0x99855999,0x99755999,0x55555999,0x55557999, + 0x99955579,0x99955559,0x99955559,0x99955559, // 0042h + 0x99955558,0x99955557,0x99955555,0x99975555, + 0x11b99999,0x11c99999,0x211a9999,0x311b9999, // 0043h + 0x4111a999,0x0311b999,0x00311ba9,0x0003111b, + 0x99999b11,0x99999c11,0x9999a112,0x9999b113, // 0044h + 0x999a1114,0x999b1130,0x9ab11300,0xb1113000, + 0x59999999,0x59999999,0x59999999,0x59999999, // 0045h + 0x59999999,0x59999999,0x59999999,0x79999999, + 0x99999755,0x99999555,0x99999555,0x99999555, // 0046h + 0x99999555,0x99999555,0x99999555,0x99999755, + 0x11b99999,0x11c99999,0x211a9999,0x311b9999, // 0047h + 0x4111a999,0x0311b999,0x00311ba9,0x0003111b, + 0x99999b11,0x99999c11,0x9999a112,0x9999b113, // 0048h + 0x999a1114,0x999b1130,0x9ab11300,0xb1113000, + 0x55555999,0x65555999,0x75555999,0x85555999, // 0049h + 0x75555999,0x65555999,0x55555999,0x55557999, + 0x99997555,0x99999987,0x99999999,0x99999999, // 004ah + 0x99999999,0x99999987,0x99975555,0x99975555, + 0x11b99999,0x11c99999,0x211a9999,0x311b9999, // 004bh + 0x4111a999,0x0311b999,0x00311ba9,0x0003111b, + 0x99999b11,0x99999c11,0x9999a112,0x9999b113, // 004ch + 0x999a1114,0x999b1130,0x9ab11300,0xb1113000, + 0x55799999,0x78999999,0x99999999,0x99999999, // 004dh + 0x99999999,0x78999999,0x55557999,0x55557999, + 0x99955555,0x99955556,0x99955557,0x99955558, // 004eh + 0x99955557,0x99955556,0x99955555,0x99975555, + 0x11b99999,0x11c99999,0x211a9999,0x311b9999, // 004fh + 0x4111a999,0x0311b999,0x00311ba9,0x0003111b, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0050h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0051h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0052h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0053h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0054h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0055h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0056h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0057h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0058h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0059h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 005ah + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 005bh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 005ch + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 005dh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 005eh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 005fh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x11230000,0x13000000,0x30000000,0x00000000, // 0060h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x999999ab,0x999abc11,0x11111112,0x11112340, // 0061h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0xba999999,0x11cba999,0x21111111,0x04321111, // 0062h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00003211,0x00000031,0x00000003,0x00000000, // 0063h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x11230000,0x13000000,0x30000000,0x00000000, // 0064h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x999999ab,0x999abc11,0x11111112,0x11112340, // 0065h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0xba999999,0x11cba999,0x21111111,0x04321111, // 0066h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00003211,0x00000031,0x00000003,0x00000000, // 0067h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x11230000,0x13000000,0x30000000,0x00000000, // 0068h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x999999ab,0x999abc11,0x11111112,0x11112340, // 0069h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0xba999999,0x11cba999,0x21111111,0x04321111, // 006ah + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00003211,0x00000031,0x00000003,0x00000000, // 006bh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x11230000,0x13000000,0x30000000,0x00000000, // 006ch + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x999999ab,0x999abc11,0x11111112,0x11112340, // 006dh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0xba999999,0x11cba999,0x21111111,0x04321111, // 006eh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00003211,0x00000031,0x00000003,0x00000000, // 006fh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0070h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0071h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0072h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0073h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0074h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0075h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0076h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0077h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0078h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 0079h + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 007ah + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 007bh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 007ch + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 007dh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 007eh + 0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000, // 007fh + 0x00000000,0x00000000,0x00000000,0x00000000 +}; + + +const u16 d_IconPaletteData[16 * 4] = { + 0x7c1f,0x7fff,0x5ef7,0x3def,0x1ce7,0x0000,0x0007,0x000f, // 0000h + 0x0017,0x001f,0x1cff,0x3dff,0x5eff,0x7fff,0x0000,0x0000, + 0x7c1f,0x7fff,0x5ef7,0x3def,0x1ce7,0x0000,0x00e0,0x01e0, // 0001h + 0x02e0,0x03e0,0x1fe7,0x3fef,0x5ff7,0x7fff,0x0000,0x0000, + 0x7c1f,0x7fff,0x5ef7,0x3def,0x1ce7,0x0000,0x1ce0,0x3de0, // 0002h + 0x5ee0,0x7fe0,0x7fe7,0x7fef,0x7ff7,0x7fff,0x0000,0x0000, + 0x7c1f,0x7fff,0x5ef7,0x3def,0x1ce7,0x0000,0x00e7,0x01ef, // 0003h + 0x02f7,0x03ff,0x1fff,0x3fff,0x5fff,0x7fff,0x0000,0x0000 + +}; + + + + diff --git a/build/tools/sctools/common/src/font.h b/build/tools/sctools/common/src/font.h new file mode 100644 index 0000000..046f655 --- /dev/null +++ b/build/tools/sctools/common/src/font.h @@ -0,0 +1,21 @@ +#ifndef _FONT_H_ +#define _FONT_H_ + +extern const u32 d_CharData[0xe0 * 8]; +extern const u32 d_PaletteData[8*16]; +extern const u32 d_IconCharData[0x80 * 8]; +extern const u16 d_IconPaletteData[16 * 4]; + +extern GXOamAttr g_oam[128]; + + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/build/tools/sctools/common/src/gfx.c b/build/tools/sctools/common/src/gfx.c new file mode 100644 index 0000000..0d7dcd6 --- /dev/null +++ b/build/tools/sctools/common/src/gfx.c @@ -0,0 +1,160 @@ +#include "font.h" +#include "text.h" +#include "mprintf.h" +#include "gfx.h" + +static GXOamAttr g_oam[128]; +#define VRAM_SIZE 2*32*24 + +/* DISPLAY Control */ + +// #define TEXT_HEAPBUF_SIZE 0x16000 +#define TEXT_HEAPBUF_SIZE 0x80000 /* 512KByte */ +static u8 text_heap_buffer[TEXT_HEAPBUF_SIZE]; + +static TEXT_CTRL textctrl[NUM_OF_SCREEN]; +TEXT_CTRL *tc[NUM_OF_SCREEN]; +static int vram_num_main = 1; +static int vram_num_sub = 0; +static void VBlankIntr( void ); +static u32 v_blank_intr_counter = 0; + +static u32 g_screen[MAX_VRAM_NUM][VRAM_SIZE/sizeof(u32)]; + + +void Gfx_Init(void) +{ + int i; + u16 palette_no = 0x0f; + int line_buf_count; + + FX_Init(); + GX_Init(); + GX_DispOff(); + GXS_DispOff(); + + + + line_buf_count = init_text_buf_sys((void *)&(text_heap_buffer[0]), + (void *)&(text_heap_buffer[TEXT_HEAPBUF_SIZE])); + + // OS_TPrintf("Init start 1\n"); + for( i = 0 ; i < NUM_OF_SCREEN ; i++) { + tc[i] = &(textctrl[i]); + init_text(tc[i], (u16 *)&(g_screen[i]), palette_no); + } + + + + + // VRAM初期化 + GX_SetBankForLCDC(GX_VRAM_LCDC_ALL); + MI_CpuClearFast((void*)HW_LCDC_VRAM,HW_LCDC_VRAM_SIZE); + (void)GX_DisableBankForLCDC(); + MI_CpuFillFast((void*)HW_OAM,192,HW_OAM_SIZE); + MI_CpuClearFast((void*)HW_PLTT,HW_PLTT_SIZE); + MI_CpuFillFast((void*)HW_DB_OAM,192,HW_DB_OAM_SIZE); + MI_CpuClearFast((void*)HW_DB_PLTT,HW_DB_PLTT_SIZE); + + + + /* BG0表示設定 */ + GX_SetBankForBG(GX_VRAM_BG_128_A); + G2_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256, + GX_BG_COLORMODE_16, + GX_BG_SCRBASE_0xf000, // SCR base block 31 + GX_BG_CHARBASE_0x00000, // CHR base block 0 + GX_BG_EXTPLTT_01); + G2_SetBG0Priority(0); + G2_BG0Mosaic(FALSE); + // 2D表示設定 + GX_SetGraphicsMode(GX_DISPMODE_GRAPHICS,GX_BGMODE_0,GX_BG0_AS_2D); + GX_LoadBG0Char(d_CharData,0,sizeof(d_CharData)); + GX_LoadBGPltt(d_PaletteData,0,sizeof(d_PaletteData)); + // GX_SetBankForARM7(GX_VRAM_ARM7_128_D); + // OBJ表示設定 + GX_SetBankForOBJ(GX_VRAM_OBJ_128_B); + GX_SetOBJVRamModeChar(GX_OBJVRAMMODE_CHAR_2D); + GX_LoadOBJ(d_IconCharData,0,sizeof(d_IconCharData)); + GX_LoadOBJPltt(d_IconPaletteData,0,sizeof(d_IconPaletteData)); + + GX_SetVisiblePlane(GX_PLANEMASK_BG0 | GX_PLANEMASK_OBJ ); + + + /* BG1表示設定 */ + GX_SetBankForSubBG( GX_VRAM_SUB_BG_48_HI ); + G2S_SetBG0Control( + GX_BG_SCRSIZE_TEXT_256x256 , + GX_BG_COLORMODE_16 , + GX_BG_SCRBASE_0xf800 , // SCR ベースブロック 31 + GX_BG_CHARBASE_0x10000 , // CHR ベースブロック 0 + GX_BG_EXTPLTT_01 + ); + G2S_SetBG0Priority( 0 ); + G2S_BG0Mosaic( FALSE ); + GXS_SetGraphicsMode(GX_BGMODE_0); + GXS_LoadBG0Char(d_CharData,0,sizeof(d_CharData)); + GXS_LoadBGPltt(d_PaletteData,0,sizeof(d_PaletteData)); + + GX_SetBankForSubOBJ(GX_VRAM_SUB_OBJ_128_D); + GXS_SetOBJVRamModeChar(GX_OBJVRAMMODE_CHAR_2D); + + + GXS_LoadOBJ(d_IconCharData,0,sizeof(d_IconCharData)); + GXS_LoadOBJPltt(d_IconPaletteData,0,sizeof(d_IconPaletteData)); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 | GX_PLANEMASK_OBJ ); + + + // LCD表示開始 + GX_DispOn(); + GXS_DispOn(); + + for(i=0;i<128;i++){ + G2_SetOBJPosition(&(g_oam[i]),256,192); + } + + G2_SetBG0Offset( 0, 0 ); + G2S_SetBG0Offset( 0, 0 ); + + + // for V Blank + (void)OS_SetIrqFunction( OS_IE_V_BLANK, VBlankIntr ); + (void)OS_EnableIrqMask( OS_IE_V_BLANK ); + (void)GX_VBlankIntr( TRUE ); + +} + +static void VBlankIntr(void) +{ + if( vram_num_main < NUM_OF_SCREEN ) { + DC_FlushRange( (void *)&(g_screen[vram_num_main]),VRAM_SIZE); + } + GX_LoadBG0Scr( &(g_screen[vram_num_main]),0,VRAM_SIZE); + + if( vram_num_sub < NUM_OF_SCREEN ) { + DC_FlushRange( (void *)&(g_screen[vram_num_sub]),VRAM_SIZE); + } + GXS_LoadBG0Scr( (void *)&(g_screen[vram_num_sub]) , 0 , VRAM_SIZE ); + + // 仮想OAMをVRAMに反映 + DC_FlushRange(g_oam,sizeof(g_oam)); + GX_LoadOAM(g_oam,0,sizeof(g_oam)); + //---- 割り込みチェックフラグ + OS_SetIrqCheckFlag( OS_IE_V_BLANK ); + v_blank_intr_counter++; +} + + + +void Gfx_Render(int main_no, int sub_no) +{ + vram_num_main = main_no; + vram_num_sub = sub_no; + + if( -1 < vram_num_main && vram_num_main < NUM_OF_SCREEN ) { + text_buf_to_vram(tc[vram_num_main]); + } + if( -1 < vram_num_sub && vram_num_sub < NUM_OF_SCREEN ) { + text_buf_to_vram(tc[vram_num_sub]); + } +} diff --git a/build/tools/sctools/common/src/gfx.h b/build/tools/sctools/common/src/gfx.h new file mode 100644 index 0000000..cc8338e --- /dev/null +++ b/build/tools/sctools/common/src/gfx.h @@ -0,0 +1,25 @@ +#ifndef _GFX_H_ +#define _GFX_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +void Gfx_Init(void); +void Gfx_Render(int main_no, int sub_no); + +#ifdef __cplusplus +} +#endif + + + +#define MAX_VRAM_NUM (NUM_OF_SCREEN) + +extern TEXT_CTRL *tc[NUM_OF_SCREEN]; +extern int vram_num_main; +extern int vram_num_sub; + + +#endif /* _GFX_H_ */ diff --git a/build/tools/sctools/common/src/hatamotolib.cpp b/build/tools/sctools/common/src/hatamotolib.cpp new file mode 100644 index 0000000..045feeb --- /dev/null +++ b/build/tools/sctools/common/src/hatamotolib.cpp @@ -0,0 +1,717 @@ +#include "ecdl.h" +#include +#include +#include +#include + +#ifdef USE_DWC +#include +#include +#endif + +#include +#include + +#include "netconnect.h" +#include "sitedefs.h" +#include "wcm_control.h" + +#include "hatamotolib.h" + +static void *Alloc(size_t size) +{ + OSIntrMode old = OS_DisableInterrupts(); + void* p = OS_Alloc(size); + OS_RestoreInterrupts(old); + return p; +} + +static void Free(void* ptr) +{ + if( ptr != NULL ) + { + OSIntrMode old = OS_DisableInterrupts(); + OS_Free(ptr); + OS_RestoreInterrupts(old); + } +} + +#ifdef USE_DWC +static void* AllocForDWC(DWCAllocType name, u32 size, int align) +{ + SDK_ASSERT(align <= 32);(void)name;(void)align; return Alloc(static_cast(size)); +} + +static void FreeForDWC(DWCAllocType name, void* ptr, u32 size) +{ + (void)name;(void)size; Free(ptr); +} +#endif + +static void* AllocForNHTTP(u32 size, int align) { SDK_ASSERT(align <= 32);(void)align; return Alloc(size); } +static void* AllocForEC (u32 size, int align) { SDK_ASSERT(align <= 32);(void)align; return Alloc(size); } +static void* AllocForNSSL (u32 size) { return Alloc(size); } +static void* AllocForNAM (u32 size) { return Alloc(size); } +static void FreeForNHTTP (void* p) { Free(p); } +static void FreeForEC (void* p) { Free(p); } +static void FreeForNSSL (void* p) { Free(p); } +static void FreeForNAM (void* p) { Free(p); } +static void* ReallocForNSSL(void* p, u32 size) +{ + if( p != NULL ) + { + void* newp = Alloc(size); + MI_CpuCopy8(p, newp, size); + Free(p); + return newp; + } + else + { + return Alloc(size); + } +} + + +static void PrintBytes(const void* pv, u32 size) +{ + const u8* p = reinterpret_cast(pv); + + for( u32 i = 0; i < size; ++i ) + { + OS_TPrintf("%02X", p[i]); + } +} + + +struct StringMap +{ + int value; + const char* string; +}; + +static const char* +FindString(const StringMap* pMap, int value) +{ + while( pMap->string != NULL ) + { + if( pMap->value == value ) + { + return pMap->string; + } + + pMap++; + } + + return "unknwon value"; +} + + +static const char* GetECErrorString(ECError err) +{ + static const StringMap STRING_MAP[] = + { +#include "string_map_ec_error.inc" + { 0, NULL } + }; + + return FindString(STRING_MAP, err); +} + +static const char* +GetECOperationString(ECOperation op) +{ + static const StringMap STRING_MAP[] = + { +#include "string_map_ec_op.inc" + { 0, NULL } + }; + + return FindString(STRING_MAP, op); +} + +static const char* +GetECOpPhaseString(ECOpPhase phase) +{ + static const StringMap STRING_MAP[] = + { +#include "string_map_ec_phase.inc" + { 0, NULL } + }; + + return FindString(STRING_MAP, phase); +} + + +#ifdef USE_DWC +static const char* +GetDWCApInfoTypeString(DWCApInfoType type) +{ + static const StringMap STRING_MAP[] = + { +#include "string_map_dwc_apinfo_type.inc" + { 0, NULL } + }; + + return FindString(STRING_MAP, type); +} +#endif + + +static const char* +GetOSTWLRegionString(u8 x) +{ + static const StringMap STRING_MAP[] = + { + { OS_TWL_REGION_JAPAN, "japan" }, + { OS_TWL_REGION_AMERICA, "america" }, + { OS_TWL_REGION_EUROPE, "europe" }, + { OS_TWL_REGION_AUSTRALIA, "australia" }, + { OS_TWL_REGION_CHINA, "china" }, + { OS_TWL_REGION_KOREA, "korea" }, + { 0, NULL } + }; + + return FindString(STRING_MAP, x); +} + + +void SetupUserInfo(void) +{ + BOOL bSuccess; + BOOL bModified = FALSE; + void* pWork; + + // LCFG_ReadTWLSettings を行う前に LCFG_ReadHWSecureInfo が必要 + { + bSuccess = LCFG_ReadHWSecureInfo(); + SDK_ASSERT(bSuccess); + } + + // 設定の読み込み + { + pWork = Alloc(LCFG_READ_TEMP); + SDK_POINTER_ASSERT(pWork); + + bSuccess = LCFG_ReadTWLSettings(reinterpret_cast(pWork)); + SDK_ASSERT(bSuccess); + + Free(pWork); + } + + { + // ニックネームが空なら適当に設定 + if( *LCFG_TSD_GetNicknamePtr() == L'\0' ) + { + LCFG_TSD_SetNickname(reinterpret_cast(L"ecdl")); + bModified = TRUE; + } + + // 国が選択されていないなら適当に設定 + if( LCFG_TSD_GetCountry() == LCFG_TWL_COUNTRY_UNDEFINED ) + { + LCFG_TSD_SetCountry(LCFG_TWL_COUNTRY_JAPAN); + bModified = TRUE; + } + } + + // 設定が変更されているなら書き出す + if( bModified ) + { + pWork = Alloc(LCFG_WRITE_TEMP); + SDK_POINTER_ASSERT(pWork); + + bSuccess = LCFG_WriteTWLSettings(reinterpret_cast(pWork)); + SDK_ASSERT(bSuccess); + + Free(pWork); + } +} + +void SetupVerData(void) +{ + BOOL bSuccess; + + void* pWork = Alloc(NA_VERSION_DATA_WORK_SIZE); + SDK_POINTER_ASSERT(pWork); + + bSuccess = NA_LoadVersionDataArchive(pWork, NA_VERSION_DATA_WORK_SIZE); + + SDK_ASSERT(bSuccess); +} + + + +void PrintDeviceInfo(void) +{ + ESId deviceId; + u8 region; + u32 launcherInitialCode; + const u8* pSerial; + const u8* pMovable; + u32 movableLen1; + u32 movableLen2; + u64 fuseId; + char bmsDeviceId[32]; + + LCFG_ReadHWNormalInfo(); + LCFG_ReadHWSecureInfo(); + + // region + region = LCFG_THW_GetRegion(); + + // launcher initial code + LCFG_THW_GetLauncherTitleID_Lo(reinterpret_cast(&launcherInitialCode)); + + // ES Device ID + ES_GetDeviceId(&deviceId); + snprintf(bmsDeviceId, sizeof(bmsDeviceId), "%lld", ((0x3ull << 32) | deviceId)); + + // serial + pSerial = LCFG_THW_GetSerialNoPtr(); + + // movable id + pMovable = LCFG_THW_GetMovableUniqueIDPtr(); + movableLen1 = LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN / 2; + movableLen2 = LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN - movableLen1; + + // fuse id + fuseId = SCFG_ReadFuseData(); + + OS_TPrintf("Region: %-10s %08X\n", GetOSTWLRegionString(region), launcherInitialCode); + OS_TPrintf("DeviceID: %08X %u\n", deviceId, deviceId); + OS_TPrintf(" %s\n", bmsDeviceId); + OS_TPrintf("Serial: %s\n", pSerial); + OS_TPrintf("MovableID: "); PrintBytes(pMovable, movableLen1); OS_TPrintf("\n"); + OS_TPrintf(" "); PrintBytes(pMovable + movableLen1, movableLen2); OS_TPrintf("\n"); + OS_TPrintf("FuseID: %08X%08X\n", static_cast(fuseId >> 32), static_cast(fuseId)); +} + +void SetupTitlesDataFile(const NAMTitleId* pTitleIds, u32 numTitleIds) +{ + for( u32 i = 0; i < numTitleIds; ++i ) + { + NAMTitleId tid = pTitleIds[i]; + NAM_SetupTitleDataFile(tid); + } +} + +void DeleteECDirectory(void) +{ + char buf[64]; + OSTitleId tid = OS_GetTitleId(); + + STD_TSNPrintf(buf, sizeof(buf), "nand:/title/%08x/%08x", + (u32)(tid >> 32), (u32)(tid >> 0) ); + + FS_DeleteDirectoryAuto(buf); +} + +void SetupShopTitleId(void) +{ + *(u64 *)(HW_TWL_ROM_HEADER_BUF + 0x230) = 0x00030015484E4641ull; +} + + +#ifdef USE_DWC +static u8 sDwcWork[ DWC_INIT_WORK_SIZE ] ATTRIBUTE_ALIGN(32); +static DWCInetControl sDwcInetCtrl; + +static void PollConnection_DWC() +{ + int errCode; + int counter = 0; + while( ! DWC_CheckInet() ) + { + DWC_ProcessInet(); + OS_Sleep(16); + OS_TPrintf("*** %s %d %d\n",__FUNCTION__, __LINE__, counter); + counter++; + } + + OS_TPrintf("*** %s %d\n",__FUNCTION__, __LINE__); + + switch ( DWC_GetInetStatus() ) + { + case DWC_CONNECTINET_STATE_NOT_INITIALIZED: + OS_TPrintf(" DWC_CONNECTINET_STATE_NOT_INITIALIZED\n" ); + break; + case DWC_CONNECTINET_STATE_IDLE: + OS_TPrintf(" DWC_CONNECTINET_STATE_IDLE \n" ); + break; + case DWC_CONNECTINET_STATE_OPERATING: + OS_TPrintf(" DWC_CONNECTINET_STATE_OPERATING \n" ); + break; + case DWC_CONNECTINET_STATE_OPERATED: + OS_TPrintf(" DWC_CONNECTINET_STATE_OPERATED \n" ); + break; + case DWC_CONNECTINET_STATE_CONNECTED: + OS_TPrintf(" DWC_CONNECTINET_STATE_CONNECTED \n" ); + break; + case DWC_CONNECTINET_STATE_DISCONNECTING: + OS_TPrintf(" DWC_CONNECTINET_STATE_DISCONNECTING \n" ); + break; + case DWC_CONNECTINET_STATE_DISCONNECTED: + OS_TPrintf(" DWC_CONNECTINET_STATE_DISCONNECTED %d\n"); + break; + case DWC_CONNECTINET_STATE_ERROR: + DWC_GetLastError(&errCode); + OS_Panic(" DWC_CONNECTINET_STATE_ERROR %d\n", errCode ); + break; + case DWC_CONNECTINET_STATE_FATAL_ERROR: + DWC_GetLastError(&errCode); + OS_Panic(" DWC_CONNECTINET_STATE_FATAL_ERROR %d\n", errCode ); + break; + default: + DWC_GetLastError(&errCode); + OS_Panic(" DWC_CONNECTINET_STATE_UNKNOWN_ERROR %d\n", errCode ); + } +} + +static bool ConnectionResult_DWC() +{ + DWCApInfo apinfo; + + if ( DWC_GetApInfo( &apinfo ) == TRUE ) + { + OS_TPrintf(" AP type: %s\n", GetDWCApInfoTypeString(apinfo.aptype)); + OS_TPrintf(" ESSID : %s\n", &apinfo.essid); + return true; + } + else + { + DWCError error; + int errorCode; + DWCErrorType errorType; + // 接続失敗のエラーコード表示 + error = DWC_GetLastErrorEx( &errorCode, &errorType ); + OS_TPrintf(" error point : %d\n", error ); + OS_TPrintf(" error no : %d\n", -errorCode ); + OS_TPrintf(" error type : %d\n", errorType ); + + return false; + } +} + + + +void NetworkAutoConnect_DWC(void) +{ + + DWC_SetReportLevel(DWC_REPORTFLAG_ALL); + + int result = DWC_Init(sDwcWork); + + if ( result == DWC_INIT_RESULT_DESTROY_OTHER_SETTING ) + { + OS_TPrintf( "Wi-Fi setting might be broken.\n" ); + } + + DWC_SetMemFunc( &AllocForDWC, &FreeForDWC ); + + DWC_InitInet( &sDwcInetCtrl ); + + DWC_SetDisableEulaCheck(); + + DWC_ConnectInetAsync(); + + + PollConnection_DWC(); + + if( ! ConnectionResult_DWC() ) + { + OS_Panic("auto connect failed"); + } +} + +void NetworkShutdown_DWC(void) +{ + DWC_CleanupInet(); +} +#endif + +void SetupNSSL(void) +{ + NSSLConfig conf; + + conf.maxId = 8; + conf.alloc = AllocForNSSL; + conf.free = FreeForNSSL; + conf.realloc = ReallocForNSSL; + conf.fixedHeapSize = 0; + NSSL_Init(&conf); +} + +void SetupNHTTP(void) +{ + int rv; + + rv = NHTTPStartup(AllocForNHTTP, FreeForNHTTP, 18); + NHTTP_SetBuiltinRootCAAsDefault(NSSL_ROOTCA_NINTENDO_2); + + if (rv != NHTTP_ERROR_NONE) + { + OS_Panic("Failed to start NHTTP, rv=%d\n", rv); + } +} + + + +static void +GetDeviceCode(char *deviceCode, u32 bufSize) +{ + u64 eFuseData; + u32 i; + u8 digit; + + /* Fake the device code, seeded from the eFuse data */ + SCFG_Init(); + eFuseData = SCFG_ReadFuseData(); + + for (i = 0; i < (bufSize - 1); i++) { + digit = (u8) (eFuseData % 10); + deviceCode[i] = (char) (digit + 48); + eFuseData /= 10; + } + + deviceCode[bufSize - 1] = '\0'; +} + +static void +Dummy_WWW_AddJSPlugin() +{ +} + +static void +LoadCert(void** ppCert, u32* pSize, const char* name) +{ + FSFile f; + BOOL bSuccess; + s32 readSize; + s32 result; + char path[64]; + + void* pCert; + u32 certSize; + + FS_InitFile(&f); + + STD_TSNPrintf(path, sizeof(path), "verdata:/%s", name); + + bSuccess = FS_OpenFile(&f, path); + if( ! bSuccess ) + { + OS_Panic("Cannot open %s\n", path); + } + + certSize = FS_GetFileLength(&f); + pCert = OS_Alloc(certSize); + if ( pCert == NULL ) + { + OS_Panic("Cannot allocate work memroy\n"); + } + + readSize = FS_ReadFile(&f, pCert, static_cast(certSize)); + if( readSize != certSize ) + { + OS_Panic("fail to read file\n"); + } + + FS_CloseFile(&f); + + result = NA_DecodeVersionData(pCert, certSize, pCert, certSize); + if( result <= 0 ) + { + OS_Panic("fail to decode version info %d\n", result); + } + + *ppCert = pCert; + *pSize = certSize; +} + + +void SetupEC(void) +{ + static u32 logLevel, clientCertSize, clientKeySize; + static char deviceCode[17]; + + ECError rv = EC_ERROR_OK; + void* pClientCert; + void* pClientKey; + + // Initialize the EC library + + logLevel = EC_LOG_FINE; + // logLevel = EC_LOG_NONE; + + LoadCert(&pClientCert, &clientCertSize, ".twl-nup-cert.der"); + LoadCert(&pClientKey, &clientKeySize, ".twl-nup-prvkey.der"); + GetDeviceCode(deviceCode, sizeof(deviceCode)); + + ECNameValue initArgs[] = + { + { EC_ALLOC, &AllocForEC }, + { EC_FREE, &FreeForEC }, + { EC_LOG_LEVEL, &logLevel }, + { EC_CLIENT_CERT, pClientCert }, + { EC_CLIENT_CERT_SIZE, &clientCertSize }, + { EC_CLIENT_KEY, pClientKey }, + { EC_CLIENT_KEY_SIZE, &clientKeySize }, + { EC_DEVICE_CODE, deviceCode }, + { EC_ADD_JS_PLUGIN_CALLBACK, &Dummy_WWW_AddJSPlugin }, + }; + const u32 nInitArgs = sizeof(initArgs) / sizeof(initArgs[0]); + + rv = EC_Init(initArgs, nInitArgs); + SDK_ASSERTMSG(rv == EC_ERROR_OK, "Failed to initialize EC, rv=%d\n", rv); + + rv = EC_SetWebSvcUrls( "https://ecs.t.shop.nintendowifi.net/ecs/services/ECommerceSOAP", + "https://ias.t.shop.nintendowifi.net/ias/services/IdentityAuthenticationSOAP", + "https://cas.t.shop.nintendowifi.net/cas/services/CatalogingSOAP" ); + SDK_ASSERTMSG(rv == EC_ERROR_OK, "Failed to EC_SetWebSvcUrls, rv=%d\n", rv); + + rv = EC_SetContentUrls( "http://ccs.t.shop.nintendowifi.net/ccs/download", + "http://ccs.t.shop.nintendowifi.net/ccs/download" ); + SDK_ASSERTMSG(rv == EC_ERROR_OK, "Failed to EC_SetContentUrls, rv=%d\n", rv); +} + + +void WaitEC(ECOpId opId) +{ + ECError result; + ECProgress progress; + ECProgress progress_prev; + + if( opId < 0 ) + { + OS_TPanic("error %d %s\n", opId, GetECErrorString(opId)); + } + + MI_CpuClear(&progress_prev, sizeof(progress_prev)); + + for(;;) + { + result = EC_GetProgress(opId, &progress); + + if( (result != EC_ERROR_OK) && (result != EC_ERROR_NOT_DONE) ) + { + if( result == EC_ERROR_NOT_ACTIVE ) + { + OS_TPrintf("opId=%d\n", opId); + } + OS_TPanic("Failed to EC_GetProgress, result=%d %s\n", result, GetECErrorString(result)); + } + + //#ifdef SDK_DEBUG + if( MI_CpuComp8(&progress_prev, &progress, sizeof(progress)) != 0 ) + { + OS_TPrintf("---------\n"); + OS_TPrintf("progress report\n"); + OS_TPrintf(" status %5d %s\n", progress.status, GetECErrorString(progress.status)); + OS_TPrintf(" operation %5d %s\n", progress.operation, GetECOperationString(progress.operation)); + OS_TPrintf(" phase %5d %s\n", progress.phase, GetECOpPhaseString(progress.phase)); + OS_TPrintf(" isCancelRequested %5d\n", progress.isCancelRequested); + OS_TPrintf(" totalSize %5d\n", progress.totalSize); + OS_TPrintf(" downloadedSize %5d\n", progress.downloadedSize); + OS_TPrintf(" errCode %5d\n", progress.errCode); + OS_TPrintf(" errInfo %s\n", progress.errInfo); + progress_prev = progress; + } + //#endif + if( progress.phase == EC_PHASE_Done ) + { + break; + } + + OS_Sleep(300); + } +} + + + +void hatamotolib_main(void) +{ + // 不要:デバイス情報の表示 + PrintDeviceInfo(); + + OS_TPrintf("--------------------------------\n"); + + // setup + { + // 必須:タイトル ID の偽装 + SetupShopTitleId(); + + // ?:ユーザ設定がされていないと接続できないので適当に設定 + SetupUserInfo(); + + // 必須:バージョンデータのマウント + SetupVerData(); + + // 必須:ネットワークへの接続 + OS_TPrintf("connecting to AP....\n"); +#ifdef USE_DWC + NetworkAutoConnect_DWC(); +#endif + OS_TPrintf("connected\n"); + + // 必須:HTTP と SSL の初期化 + OS_TPrintf("start NHTTP\n"); + SetupNSSL(); + SetupNHTTP(); + + // 必須:EC の初期化 + OS_TPrintf("start EC\n"); + SetupEC(); + } + + // body + { + // ダウンロードすべきタイトルの指定 + NAMTitleId tids[] = + { + 0x00030004346b6141ull, +// 0x0003000434616141ull, +// 0x0003000434616241ull, +// 0x000300043461644aull, +// 0x0003000434616741ull, +// 0x0003000434616a41ull, +// 0x0003000434617441ull, +// 0x0003000434626141ull, +// 0x0003000434626341ull, +// 0x0003000434626641ull, +// 0x0003000434626841ull, +// 0x0003000434626941ull, +// 0x0003000434636341ull, +// 0x00030004346b6141ull, +// 0x00030004346b6241ull, +// 0x00030004346b6341ull, + }; + + // 必須:デバイス証明書の発行 + KPSClient(); + + // 必須:指定タイトルをダウンロード + ECDownload(tids, sizeof(tids)/sizeof(*tids)); + + // 不要:セーブデータ領域を作成 + SetupTitlesDataFile(tids, sizeof(tids)/sizeof(*tids)); + } + + // cleanup + { + ECError rv = EC_ERROR_OK; + + // EC の終了処理 + rv = EC_Shutdown(); + SDK_WARNING(rv == EC_ERROR_OK, "Failed to shutdown EC, rv=%d\n", rv); + + // ネットワークからの切断 +#ifdef USE_DWC + NetworkShutdown_DWC(); +#endif + } + + // EC が自分の Title ID のディレクトリを作成してしまうため、削除する + DeleteECDirectory(); + +} + diff --git a/build/tools/sctools/common/src/hatamotolib.h b/build/tools/sctools/common/src/hatamotolib.h new file mode 100644 index 0000000..756bde9 --- /dev/null +++ b/build/tools/sctools/common/src/hatamotolib.h @@ -0,0 +1,28 @@ +#ifndef __HATAMOTO_LIB__ +#define __HATAMOTO_LIB__ + +#ifdef __cplusplus +extern "C" { +#endif + +void PrintDeviceInfo(void); +void SetupShopTitleId(void); +void SetupUserInfo(void); +void SetupVerData(void); +void NetworkAutoConnect_DWC(void); +void NetworkShutdown_DWC(void); +void SetupNSSL(void); +void SetupNHTTP(void); +void SetupEC(void); +void WaitEC(ECOpId opId); +void DeleteECDirectory(void); +void SetupTitlesDataFile(const NAMTitleId* pTitleIds, u32 numTitleIds); + +void hatamotolib_main(void); + + +#ifdef __cplusplus +} +#endif + +#endif // __HATAMOTO_LIB__ diff --git a/build/tools/sctools/common/src/hwi.c b/build/tools/sctools/common/src/hwi.c new file mode 100644 index 0000000..1d3006e --- /dev/null +++ b/build/tools/sctools/common/src/hwi.c @@ -0,0 +1,397 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: HWInfoWriterLib.c + + Copyright 2007 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:: 2008-05-09#$ + $Rev: 1309 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +// #include +#include "hwi.h" + +#include "font.h" +#include "text.h" +#include "mprintf.h" + + +/* +// TWL本体設定データリード(関数内でNTR本体設定データのリードも行う。) +extern BOOL LCFG_ReadTWLSettings( u8 (*pTempBuffer)[ LCFG_READ_TEMP ] ); + +// TWL本体設定データライト(関数内でNTR本体設定データへのライトも行う。) +extern BOOL LCFG_WriteTWLSettings( u8 (*pTempBuffer)[ LCFG_WRITE_TEMP ] ); + +*/ + +// TWL設定データのリード +static BOOL ReadTWLSettings( LCFGTWLSettingsData *cfg_data ) +{ + BOOL isReadTSD = FALSE; + u8 *pBuffer; + if( cfg_data == NULL ) { + return FALSE; + } + pBuffer = OS_Alloc( LCFG_TEMP_BUFFER_SIZE * 2 ); + if( pBuffer ) { + isReadTSD = LCFG_ReadTWLSettings( (u8 (*)[ LCFG_TEMP_BUFFER_SIZE * 2 ] )pBuffer ); + if( isReadTSD == TRUE ) { + /* 内部バッファーからダイレクトにコピーする */ + STD_CopyMemory( (void *)cfg_data, (void *)LCFGi_GetTSD(), sizeof(LCFGTWLSettingsData) ); + OS_TPrintf( "TSD read succeeded.\n" ); + }else { + OS_TPrintf( "TSD read failed.\n" ); + } + OS_Free( pBuffer ); + } + return isReadTSD; +} + + +static BOOL WriteTWLSettings( LCFGTWLSettingsData *cfg_data ) +{ + BOOL isWriteTSD = FALSE; + u8 *pBuffer; + if( cfg_data == NULL ) { + return FALSE; + } + pBuffer = OS_Alloc( LCFG_TEMP_BUFFER_SIZE ); + if( pBuffer ) { + /* 内部バッファーにダイレクトにコピーする */ + STD_CopyMemory( (void *)LCFGi_GetTSD(), (void *)cfg_data, sizeof(LCFGTWLSettingsData) ); + isWriteTSD = LCFG_WriteTWLSettings( (u8 (*)[ LCFG_TEMP_BUFFER_SIZE ] )pBuffer ); + if( isWriteTSD == FALSE ) { + OS_TPrintf( "TSD write failed.\n" ); + mprintf( "TSD write failed.\n" ); + } + OS_Free( pBuffer ); + } + return isWriteTSD; +} + +BOOL MiyaBackupTWLSettings(const char *path) +{ + FSFile f; + BOOL bSuccess; + FSResult fsResult; + s32 writtenSize; + LCFGTWLSettingsData cfg_data; + LCFGReadResult retval; + + retval = LCFGi_THW_ReadSecureInfo(); + if( retval != LCFG_TSF_READ_RESULT_SUCCEEDED ) { + OS_TPrintf( "HW Normal Info read failed.\n" ); + mprintf( "HW Normal Info read failed.\n" ); + return FALSE; + } + + if( FALSE == ReadTWLSettings( &cfg_data ) ) { + mprintf("Failed read cfg file 1.\n" ); + return FALSE; + } + + FS_InitFile(&f); + + /* delete file ? */ + + FS_CreateFileAuto(path, (FS_PERMIT_R|FS_PERMIT_W)); + bSuccess = FS_OpenFileEx(&f, path, (FS_FILEMODE_R|FS_FILEMODE_W)); + if (bSuccess == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed open file 1 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + writtenSize = FS_WriteFile(&f, (void *)&cfg_data, (s32)sizeof(LCFGTWLSettingsData) ); + if( writtenSize != sizeof(LCFGTWLSettingsData) ) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed write file 1 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + bSuccess = FS_CloseFile(&f); + if (bSuccess == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed close file 1 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + return TRUE; +} + +BOOL MiyaRestoreTWLSettings(const char *path) +{ + FSFile f; + BOOL bSuccess; + FSResult fsResult; + s32 readSize; + LCFGTWLSettingsData cfg_data; + LCFGReadResult retval; + + retval = LCFGi_THW_ReadSecureInfo(); + if( retval != LCFG_TSF_READ_RESULT_SUCCEEDED ) { + OS_TPrintf( "HW Normal Info read failed.\n" ); + mprintf( "HW Normal Info read failed.\n" ); + return FALSE; + } + + if( FALSE == ReadTWLSettings( &cfg_data ) ) { + mprintf("Failed read cfg file 2.\n" ); + } + + + FS_InitFile(&f); + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_R); + if (bSuccess == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed open file 2 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + readSize = FS_ReadFile(&f, (void *)&cfg_data, (s32)sizeof(LCFGTWLSettingsData) ); + if( readSize != sizeof(LCFGTWLSettingsData) ) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed read file 2 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + bSuccess = FS_CloseFile(&f); + if (bSuccess == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed close file 2 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + + + + + /* 実際に書き出し */ + if( FALSE == WriteTWLSettings( &cfg_data ) ) { + return FALSE; + } + + + return TRUE; +} + + +BOOL MiyaReadHWSecureInfo( LCFGTWLHWSecureInfo *Info ) +{ + LCFGReadResult retval; + + if( Info == NULL ) { + return FALSE; + } + + retval = LCFGi_THW_ReadSecureInfo(); + if( retval != LCFG_TSF_READ_RESULT_SUCCEEDED ) { + OS_TPrintf( "HW Normal Info read failed.\n" ); + mprintf( "HW Normal Info read failed.\n" ); + return FALSE; + } + + /* + c:/twlsdk/include/twl/lcfg/common/TWLHWInfo.h + #define LCFGi_GetHWN() ( &s_hwInfoN ) + */ + + STD_CopyMemory( (void *)Info, (void *)LCFGi_GetHWS() , sizeof(LCFGTWLHWSecureInfo) ); + + OS_TPrintf( "HW Secure Info read succeeded.\n" ); + return TRUE; +} + + +BOOL MiyaReadHWNormalInfo( LCFGTWLHWNormalInfo *Info ) +{ + LCFGReadResult retval; + + if( Info == NULL ) { + return FALSE; + } + + retval = LCFGi_THW_ReadNormalInfo(); + if( retval != LCFG_TSF_READ_RESULT_SUCCEEDED ) { + OS_TPrintf( "HW Normal Info read failed.\n" ); + mprintf( "HW Normal Info read failed.\n" ); + return FALSE; + } + + /* + c:/twlsdk/include/twl/lcfg/common/TWLHWInfo.h + #define LCFGi_GetHWN() ( &s_hwInfoN ) + */ + + STD_CopyMemory( (void *)Info, (void *)LCFGi_GetHWN() , sizeof(LCFGTWLHWNormalInfo) ); + + OS_TPrintf( "HW Normal Info read succeeded.\n" ); + return TRUE; +} + + + +/*---------------------------------------------------------------------------* + Name: HWI_WriteHWNormalInfoFile + + Description: HWノーマルInfoファイルのライト + + Arguments: + + Returns: None. + *---------------------------------------------------------------------------*/ +static BOOL MiyaWriteHWNormalInfoFile( LCFGTWLHWNormalInfo *Info ) +{ + /* + + typedef struct LCFGTWLHWNormalInfo { + u8 rtcAdjust; // RTC調整値 + u8 rsv[ 3 ]; + u8 movableUniqueID[ LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN ]; // 移行可能なユニークID + } LCFGTWLHWNormalInfo; // 20byte + */ + + if (!LCFGi_THW_WriteNormalInfoDirect( Info )) { + OS_TPrintf( "HW Normal Info Write failed.\n" ); + mprintf( "HW Normal Info Write failed.\n" ); + return FALSE; + } + return TRUE; +} + + + + +BOOL MiyaBackupHWNormalInfo(const char *path) +{ + FSFile f; + BOOL bSuccess; + FSResult fsResult; + s32 writtenSize; + + LCFGTWLHWNormalInfo info; + + if( FALSE == MiyaReadHWNormalInfo( &info ) ) { + return FALSE; + } + + FS_InitFile(&f); + + FS_CreateFileAuto(path, (FS_PERMIT_R|FS_PERMIT_W)); + bSuccess = FS_OpenFileEx(&f, path, (FS_FILEMODE_R|FS_FILEMODE_W)); + if (bSuccess == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed open file 1 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + + writtenSize = FS_WriteFile(&f, (void *)&info, (s32)sizeof(LCFGTWLHWNormalInfo) ); + if( writtenSize != sizeof(LCFGTWLHWNormalInfo) ) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed write file 1 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + bSuccess = FS_CloseFile(&f); + if (bSuccess == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed close file 1 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + return TRUE; +} + +BOOL MiyaReadHWNormalInfo_From_SD(const char *path, LCFGTWLHWNormalInfo *info) +{ + FSFile f; + BOOL bSuccess; + FSResult fsResult; + s32 readSize; + + if( info == NULL ) { + return FALSE; + } + + FS_InitFile(&f); + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_R); + if (bSuccess == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed open file 2 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + readSize = FS_ReadFile(&f, (void *)info, (s32)sizeof(LCFGTWLHWNormalInfo) ); + if( readSize != sizeof(LCFGTWLHWNormalInfo) ) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed read file 2 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + bSuccess = FS_CloseFile(&f); + if (bSuccess == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed close file 2 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + return TRUE; +} + + +BOOL MiyaRestoreHWNormalInfo(const char *path) +{ + FSFile f; + BOOL bSuccess; + FSResult fsResult; + s32 readSize; + + LCFGTWLHWNormalInfo info; + LCFGTWLHWNormalInfo info_temp; + + FS_InitFile(&f); + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_R); + if (bSuccess == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed open file 2 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + readSize = FS_ReadFile(&f, (void *)&info, (s32)sizeof(LCFGTWLHWNormalInfo) ); + if( readSize != sizeof(LCFGTWLHWNormalInfo) ) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed read file 2 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + bSuccess = FS_CloseFile(&f); + if (bSuccess == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + mprintf("Failed close file 2 - HWNormal Info.:%d\n", fsResult ); + return FALSE; + } + + + /* RTCの補正値だけはそのまま使う */ + if( FALSE == MiyaReadHWNormalInfo( &info_temp ) ) { + return FALSE; + } + info.rtcAdjust = info_temp.rtcAdjust; + + /* 実際に書き出し */ + if( FALSE == MiyaWriteHWNormalInfoFile( &info ) ) { + return FALSE; + } + + return TRUE; +} + + + diff --git a/build/tools/sctools/common/src/hwi.h b/build/tools/sctools/common/src/hwi.h new file mode 100644 index 0000000..7960c74 --- /dev/null +++ b/build/tools/sctools/common/src/hwi.h @@ -0,0 +1,51 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: DS_Chat.h + + Copyright 2007 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:: 2008-03-31#$ + $Rev: 1019 $ + $Author: kamikawa $ + *---------------------------------------------------------------------------*/ + +#ifndef __HWI_LIB__ +#define __HWI_LIB__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +#include +#include + +#include "TWLHWInfo_api.h" +#include "TWLSettings_api.h" + + +// define data---------------------------------------------------------- + +BOOL MiyaBackupHWNormalInfo(const char *path); +BOOL MiyaRestoreHWNormalInfo(const char *path); +BOOL MiyaBackupTWLSettings(const char *path); +BOOL MiyaRestoreTWLSettings(const char *path); +BOOL MiyaReadHWNormalInfo( LCFGTWLHWNormalInfo *Info ); +BOOL MiyaReadHWSecureInfo( LCFGTWLHWSecureInfo *Info ); +BOOL MiyaReadHWNormalInfo_From_SD(const char *path, LCFGTWLHWNormalInfo *info); + + + +#ifdef __cplusplus +} +#endif + +#endif // __HWI_LIB__ diff --git a/build/tools/sctools/common/src/key.c b/build/tools/sctools/common/src/key.c new file mode 100644 index 0000000..f76b0d8 --- /dev/null +++ b/build/tools/sctools/common/src/key.c @@ -0,0 +1,42 @@ +#include +#include "key.h" + +static u16 old_keydata = 0; +#define REPEAT_ON 1 +#define REPEAT_COUNT 60 +static int repeat_counter[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + +u16 m_get_key_trigger(void) +{ + u16 keydata; + u16 trigger; + int i; + u16 r; + + keydata = (u16)PAD_Read(); + trigger = (u16)(keydata & (keydata ^ old_keydata)); + +#if REPEAT_ON + r = 1; + for( i = 0 ; i < 15 ; i++ ) { + if( r & old_keydata & keydata ) { + repeat_counter[i]++; + if( repeat_counter[i] > REPEAT_COUNT ) { + trigger |= r; + } + } + else { + repeat_counter[i] = 0; + } + r <<= 1; + } +#endif + + old_keydata = keydata; + return trigger; +} + +u16 m_get_key_code(void) +{ + return old_keydata; +} diff --git a/build/tools/sctools/common/src/key.h b/build/tools/sctools/common/src/key.h new file mode 100644 index 0000000..9704195 --- /dev/null +++ b/build/tools/sctools/common/src/key.h @@ -0,0 +1,34 @@ +#ifndef _KEY_H_ +#define _KEY_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + +u16 m_get_key_trigger(void); +u16 m_get_key_code(void); + +/* + u16 keyData; + keyData = m_get_key_code(void); + if ( keyData & PAD_KEY_DOWN ) { + } if ( keyData & PAD_KEY_UP ) { + } if ( keyData & PAD_KEY_LEFT ) { + } if ( keyData & PAD_KEY_RIGHT ) { + } if ( keyData & PAD_BUTTON_R ) { + } if ( keyData & PAD_BUTTON_L ) { + } if( keyData & PAD_BUTTON_A ) { + } if( keyData & PAD_BUTTON_B ) { + } if( keyData & PAD_BUTTON_SELECT ) { + } if( keyData & PAD_BUTTON_START ) { + } + +*/ + +#ifdef __cplusplus +} +#endif + + +#endif /* _KEY_H_ */ diff --git a/build/tools/sctools/common/src/kpsc.cpp b/build/tools/sctools/common/src/kpsc.cpp new file mode 100644 index 0000000..c2b25c7 --- /dev/null +++ b/build/tools/sctools/common/src/kpsc.cpp @@ -0,0 +1,43 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - ecdl + File: kpsc.cpp + + Copyright 2007 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:: 2008-09-22#$ + $Rev: 8604 $ + $Author: hatamoto_minoru $ + *---------------------------------------------------------------------------*/ + +#include "ecdl.h" + + +void +KPSClient() +{ + s32 progress; + + OS_TPrintf("generate key pair\n"); + progress = EC_GenerateKeyPair(); + + OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + + WaitEC(progress); + OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + + OS_TPrintf("confirm key pair\n"); + progress = EC_ConfirmKeyPair(); + OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + + WaitEC(progress); + + OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + +} + diff --git a/build/tools/sctools/common/src/logprintf.c b/build/tools/sctools/common/src/logprintf.c new file mode 100644 index 0000000..96ee18b --- /dev/null +++ b/build/tools/sctools/common/src/logprintf.c @@ -0,0 +1,795 @@ +/************************************************************************** + * Copyright (C) 1997, Nintendo Co.,Ltd. * + *************************************************************************/ + + +#include +#include "text.h" +#include "mprintf.h" +#include "logprintf.h" + +#define __std(ref) ref +// #define __std(ref) ::std::ref + +#include +#include "text.h" +#include "mprintf.h" +#include "logprintf.h" + +#define __fourbytealign(n) ((((unsigned long) (n)) + 3U) & ~3U) +#define __va_start(parm) ((__std(va_list)) ((char*) ((unsigned long)(&parm) & ~3U) + __fourbytealign(sizeof(parm)))) + +#define va_start(ap, parm) ((ap) = __va_start(parm)) + +#define va_arg(ap, type) (*(type *) ((ap += __fourbytealign(sizeof(type))) - __fourbytealign(sizeof(type)))) +#define va_end(ap) ((void) 0) + + +static void *my_memcpy(void *dest, const void *src, size_t n) +{ + unsigned char *s = (unsigned char *)dest; + unsigned char *ss = (unsigned char *)src; + + while(n--) { + *s++ = *ss++ ; + } + return dest; +} + +static const char *strchr(const char *s,int c) +{ + int a; + while( (a = (int)*s) != NULL ) { + if(a == c) + return s; + s++; + } + return (const char *)NULL; +} + +static size_t strlen(const char *s) +{ + size_t n=0; + while( *s != NULL) { + n++; + s++; + } + return n; +} + + +static void *proutPrintf(void *fd, const char *buf, size_t n) +{ + /* write to file */ + /* return (fwrite(buf, 1, n, str) == n ? str : NULL);*/ + int i; + + for (i = 0; i < n; i++) { + OS_PutChar( buf[i] ); + m_putchar( (void *)tc[0], buf[i] ); + } + + if( fd != NULL ) { + (void)FS_WriteFile(fd, (void *)buf, (long)n ); + } + + /* return a fake pointer so that it's not NULL */ + return ((void *)fd); +} + +static int _Printf(void *(*pfn)(void *, const char *, size_t), + void *arg, int len, const char *fmt, va_list ap); + + +void miya_log_fprintf(FSFile *fd, const char *fmt, ...) +{ + int ans; + va_list ap; + va_start(ap, fmt); + ans = _Printf(&proutPrintf, (void *)fd, 0x200, fmt, ap); + va_end(ap); +} + +/**************************************************************/ + + +/*******************************************************/ + +/* _Printf function */ + +#define _YVALS + +/* float properties */ +#define _D0 3 +#define _DBIAS (0x400-1) +#define _DLONG 0 +#define _DOFF 4 +#define _LBIAS (0x400-1) +#define _LONG_DOUBLE 0 + +/* pointer properties */ +#define _NULL (void *) 0 +typedef unsigned int _Sizet; + +/***********************************************************/ +#define _FSP 0x01 +#define _FPL 0x02 +#define _FMI 0x04 +#define _FNO 0x08 +#define _FZE 0x10 +#define _WMAX 999 +#define _WANT (EOF-1) + +#if _LONG_DOUBLE +typedef long double ldouble; +#else +typedef double ldouble; +#endif + +typedef struct { + union { + long long ll; + ldouble ld; + } v; + char *s; + int n0, nz0, n1, nz1, n2, nz2, prec, width; + size_t nchar; + unsigned int flags; + char qual; +} _Pft; + +/* declarations */ +static void miya_Ldtob(_Pft *, char); +static void miya_Litob(_Pft *, char); + + + +/* macros */ + +#if _DLONG +#define LDSIGN(x) (((unsigned short *) &(x))[_D0 ? 4 : 0] & 0x8000) +#else +#define LDSIGN(x) (((unsigned short *) &(x))[_D0] & 0x8000) +#endif + +#define ISDIGIT(c) ((c >= '0') && (c <= '9')) +#define MAX_PAD (sizeof(spaces) - 1) +#define PAD(s, n) \ + if (0 < (n)) { \ + int i, j = (n); \ + for (; 0 < j; j -= i) { \ + i = MAX_PAD < j ? MAX_PAD : j; \ + PUT(s, i); \ + } \ + } +#if 0 // miyamoto +#define PUT(s, n) \ + if( len > n ) {\ + if (0 < (n)) { \ + len -= n; \ + if ((arg = (*pfn)(arg, s, n)) != NULL) \ + x.nchar += (n); \ + else \ + return (x.nchar); \ + } \ + } \ + else { \ + return (x.nchar); \ + } +#else +#define PUT(s, n) \ + if( len > n ) {\ + if (0 < (n)) { \ + len -= n; \ + arg = (*pfn)(arg, s, n); \ + x.nchar += (n); \ + } \ + } \ + else { \ + return (x.nchar); \ + } +#endif + +static char spaces[] = " "; +static char zeroes[] = "00000000000000000000000000000000"; + +static void _Putfld(_Pft *, va_list *, char, char *); + + +typedef struct { + long quot; + long rem; +} miya_ldiv_t; + +typedef struct { + long long quot; + long long rem; +} miya_lldiv_t; + +static miya_lldiv_t miya_lldiv(long long a, long long b) +{ + miya_lldiv_t t; + t.quot = a / b; + t.rem = a % b; + return t; +} + +static miya_ldiv_t miya_ldiv(long a, long b) +{ + miya_ldiv_t t; + t.quot = a / b; + t.rem = a % b; + return t; +} + + +static int _Printf(void *(*pfn)(void *, const char *, size_t), + void *arg, int len, const char *fmt, va_list ap) +{ /* print formatted */ + _Pft x; + + x.nchar = 0; + while (1) { /* scan format string */ + const char *s = fmt; + int c; + const char *t; + static const char fchar[] = {" +-#0"}; + static const unsigned int fbit[] = { + _FSP, _FPL, _FMI, _FNO, _FZE, 0}; + char ac[32]; + + /* copy any literal text */ + while ( (0 < (c = (int)(*s++)) ) && (c != '%')) { + } + --s; +#if 1 + PUT(fmt, s - fmt); +#else + if (0 < (s-fmt)) { + if ((arg = (*pfn)(arg, fmt, s-fmt)) != NULL) + x.nchar += (s-fmt); + else + return (x.nchar); + } + } + else { + return (x.nchar); + } + +#endif + if (c == '\0') + return (x.nchar); + fmt = ++s; + + /* parse a conversion specifier */ + for (x.flags = 0; (t = strchr(fchar, *s)) != NULL; ++s) + x.flags |= fbit[t - fchar]; + if (*s == '*') { /* get width argument */ + x.width = va_arg(ap, int); + if (x.width < 0) { /* same as '-' flag */ + x.width = -x.width; + x.flags |= _FMI; + } + ++s; + } else /* accumulate width digits */ + for (x.width = 0; ISDIGIT((int)*s); ++s) + if (x.width < _WMAX) + x.width = x.width * 10 + *s - '0'; + if (*s != '.') + x.prec = -1; + else if ( *++s == '*') { /* get precision argument */ + x.prec = va_arg(ap, int); + ++s; + } else /* accumulate precision digits */ + for (x.prec = 0; ISDIGIT(*s); ++s) + if (x.prec < _WMAX) + x.prec = x.prec * 10 + *s - '0'; + x.qual = (char)(strchr("hlL", *s) ? *s++ : '\0'); + if (( x.qual == 'l') && ( *s == 'l')) { + x.qual= 'L'; /* the %ll qualifier */ + s++; + } + + /* do the conversion */ + _Putfld(&x, &ap, *s, ac); + x.width -= x.n0 + x.nz0 + x.n1 + x.nz1 + x.n2 + x.nz2; + if (!(x.flags & _FMI)) + PAD(spaces, x.width); + PUT(ac, x.n0); + PAD(zeroes, x.nz0); + PUT(x.s, x.n1); + PAD(zeroes, x.nz1); + PUT(x.s + x.n1, x.n2); + PAD(zeroes, x.nz2); + if (x.flags & _FMI) + PAD(spaces, x.width); + fmt = s + 1; + } + /* shouldn't reach here, only used to eliminate the compiler warning */ + // return 0; +} + +static void _Putfld(_Pft *px, va_list *pap, char code, char *ac) +{ /* convert a field for _Printf */ + + px->n0 = px->nz0 = px->n1 = px->nz1 = px->n2 = px->nz2 = 0; + switch (code) { /* switch on conversion specifier */ + case 'c': + ac[px->n0++] = (char)va_arg(*pap, int); + break; + case 'd': + case 'i': /* convert a signed decimal integer */ + if (px->qual == 'l') + px->v.ll = va_arg(*pap, long); + else if (px->qual == 'L') + px->v.ll = va_arg(*pap, long long); + else + px->v.ll = va_arg(*pap, int); + if ( px->qual == 'h') + px->v.ll = (short) px->v.ll; + if (px->v.ll < 0) /* negate safely in miya_Litob */ + ac[px->n0++] = '-'; + else if (px->flags & _FPL) + ac[px->n0++] = '+'; + else if (px->flags & _FSP) + ac[px->n0++] = ' '; + px->s = &ac[px->n0]; + miya_Litob(px, code); + break; + case 'o': + case 'u': + case 'x': + case 'X': /* convert unsigned */ + if (px->qual == 'l') + px->v.ll = va_arg(*pap, long); + else if (px->qual == 'L') + px->v.ll = va_arg(*pap, long long); + else + px->v.ll = va_arg(*pap, int); + if (px->qual == 'h') + px->v.ll = (unsigned short) px->v.ll; + else if (px->qual == '\0') + px->v.ll = (unsigned int) px->v.ll; + if (px->flags & _FNO) { /* indicate base with prefix */ + ac[px->n0++] = '0'; + if (code == 'x' || code == 'X') + ac[px->n0++] = code; + } + px->s = &ac[px->n0]; + miya_Litob(px, code); + break; + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': /* convert floating */ + px->v.ld = px->qual == 'L' ? + va_arg(*pap, ldouble) : va_arg(*pap, double); + if (LDSIGN(px->v.ld)) + ac[px->n0++] = '-'; + else if (px->flags & _FPL) + ac[px->n0++] = '+'; + else if (px->flags & _FSP) + ac[px->n0++] = ' '; + px->s = &ac[px->n0]; + miya_Ldtob(px, code); + break; + case 'n': /* return output count */ + if (px->qual == 'h') + *va_arg(*pap, short *) = (short)(px->nchar); + else if (px->qual == 'l') + *va_arg(*pap, long *) = px->nchar; + else if (px->qual == 'L') + *va_arg(*pap, long long *) = px->nchar; + else + *va_arg(*pap, int *) = px->nchar; + break; + case 'p': /* convert a pointer, hex long version */ + px->v.ll = (long) va_arg(*pap, void *); + px->s = &ac[px->n0]; + miya_Litob(px, 'x'); + break; + case 's': /* convert a string */ + px->s = va_arg(*pap, char *); + px->n1 = strlen(px->s); + if (0 <= px->prec && px->prec < px->n1) + px->n1 = px->prec; + break; + case '%': /* put a '%' */ + ac[px->n0++] = '%'; + break; + default: /* undefined specifier, print it out */ + ac[px->n0++] = code; + break; + } +} + +/*****************************************************************/ + +/* miya_Litob function */ + + +/* IEEE 754 properties */ +#define _DFRAC ((1<<_DOFF)-1) +#define _DMASK (0x7fff&~_DFRAC) +#define _DMAX ((1<<(15-_DOFF))-1) +#define _DNAN (0x8000|_DMAX<<_DOFF|1<<(_DOFF-1)) +#define _DSIGN 0x8000 +#define DSIGN(x) (((unsigned short *)&(x))[_D0] & _DSIGN) +#define HUGE_EXP (int)(_DMAX * 900L / 1000) +#define HUGE_RAD 3.14e30 +#define SAFE_EXP (_DMAX>>1) + +/* word offsets within double */ +#if _D0==3 +#define _D1 2 /* little-endian order */ +#define _D2 1 +#define _D3 0 +#else +#define _D1 1 /* big-endian order */ +#define _D2 2 +#define _D3 3 +#endif + +/* return values for _D functions */ +#define FINITE -1 +#define INF 1 +#define _NAN 2 + +static char ldigs[] = "0123456789abcdef"; +static char udigs[] = "0123456789ABCDEF"; + +static void miya_Litob(_Pft *px, char code) +{ /* convert unsigned long to text */ + char ac[24]; /* safe for 64-bit integers */ + char *digs = code == 'X' ? udigs : ldigs; + int base = code == 'o' ? 8 : code != 'x' && code != 'X' ? 10 : 16; + int i = sizeof(ac); + unsigned long long ullval = px->v.ll; + + if ((code == 'd' || code == 'i') && px->v.ll < 0) + ullval = -ullval; /* safe against overflow */ + if (ullval || px->prec) + ac[--i] = digs[ullval % base]; + px->v.ll = ullval / base; + while (0 < px->v.ll && 0 < i) { /* convert digits */ + miya_lldiv_t qr = miya_lldiv(px->v.ll, (long long) base); + + px->v.ll = qr.quot; + ac[--i] = digs[qr.rem]; + } + px->n1 = sizeof(ac) - i; + (void)my_memcpy(px->s, &ac[i], px->n1); + if (px->n1 < px->prec) + px->nz0 = px->prec - px->n1; + if (px->prec < 0 && (px->flags & (_FMI | _FZE)) == _FZE + && 0 < (i = px->width - px->n0 - px->nz0 - px->n1)) + px->nz0 += i; + +} + + +/*************************************************/ +/* miya_Ldtob function */ + +#include "float.h" + +/* macros */ +#define NDIG 8 + +/* static data */ +static const ldouble pows[] = { + 1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L, +#if 0x100 < _LBIAS /* assume IEEE 754 8- or 10-byte */ + 1e64L, 1e128L, 1e256L, +#if _DLONG /* assume IEEE 754 10-byte */ + 1e512L, 1e1024L, 1e2048L, 1e4096L, +#endif +#endif +}; + +static short _Ldunscale(short *, ldouble *); +static void _Genld(_Pft *, char, char *, short, short); + +static void miya_Ldtob(_Pft *px, char code) +{ /* convert long double to text */ + char ac[32]; + char *p = ac; + ldouble ldval = px->v.ld; + short errx, nsig, xexp; + + if (px->prec < 0) + px->prec = 6; + else if (px->prec == 0 && (code == 'g' || code == 'G')) + px->prec = 1; + if (0 < (errx = _Ldunscale(&xexp, &px->v.ld))) { + /* x == Nan, x == INF */ + (void)my_memcpy(px->s, errx == _NAN ? "NaN" : "Inf", px->n1 = 3); + return; + } else if (0 == errx) /*x == 0 */ + nsig = 0, xexp = 0; + else { /* 0 < |x|, convert it */ + { /* scale ldval to ~~10^(NDIG/2) */ + int i, n; + + if (ldval < 0.0) + ldval = -ldval; + if ((xexp = (short)(xexp * 30103L / 100000L - NDIG/2)) < 0) { + /* scale up */ + n = (-xexp + (NDIG/2-1)) & ~(NDIG/2-1), xexp = (short)(-n); + for (i = 0; 0 < n; n >>= 1, ++i) + if (n & 1) + ldval *= pows[i]; + } else if (0 < xexp) { /* scale down */ + ldouble factor = 1.0; + + xexp &= ~(NDIG/2-1); + for (n = xexp, i = 0; 0 < n; n >>= 1, ++i) + if (n & 1) + factor *= pows[i]; + ldval /= factor; + } + } + { /* convert significant digits */ + int gen = px->prec + + (code == 'f' ? xexp + 2 + NDIG : 2 + NDIG / 2); + + if (LDBL_DIG + NDIG / 2 < gen) + gen = LDBL_DIG + NDIG / 2; + for ( *p++ = '0' ; 0 < gen && 0.0 < ldval; p += NDIG) { + /* convert NDIG at a time */ + int j; + long lo = (long) ldval; + + if (0 < (gen -= NDIG)) + ldval = (ldval - (ldouble) lo) * 1e8L; + for (p += NDIG, j = NDIG; 0 < lo && 0 <= --j; ) { + /* convert NDIG digits */ + miya_ldiv_t qr; + + qr = miya_ldiv(lo, 10); + *--p = (char)(qr.rem + '0'), lo = qr.quot; + } + while (0 <= --j) + *--p = '0'; + } + gen = p - &ac[1]; + for (p = &ac[1], xexp += NDIG - 1; *p == '0'; ++p) + --gen, --xexp; /* correct xexp */ + + /* miya + char code + int prec + short nsig, xexp; + */ + nsig = (short)(px->prec + (code == 'f' ? xexp + 1 : + code == 'e' || code == 'E' ? 1 : 0)); + if (gen < nsig) + nsig = (short)gen; + if (0 < nsig) { /* round and strip trailing zeros */ + /* const char drop; */ + char drop; + int n; + drop = (char)(nsig < gen && '5' <= p[nsig] ? '9' : '0'); + + for (n = nsig; p[--n] == drop; ) + --nsig; + + if ( drop == '9') { + p[n] = *(&(p[n])+1); + + // ++p[n]; + } + if (n < 0) + --p, ++nsig, ++xexp; + } + } + } + _Genld(px, code, p, nsig, xexp); +} + +#if _DLONG /* 10-byte IEEE format */ +#define _LMASK 0x7fff +#define _LMAX 0x7fff +#define _LSIGN 0x8000 +#if _D0==3 /* little-endian order */ +#define _L0 4 +#define _L1 3 +#define _L2 2 +#define _L3 1 +#define _L4 0 +#else +#define _L0 0 +#define _L1 1 +#define _L2 2 +#define _L3 3 +#define _L4 4 +#endif + +static short dnorm(unsigned short *ps) +{ /* normalize long double fraction */ + short xchar; + + for (xchar = 0; ps[_L1] == 0; xchar -= 16) { /* shift left by 16 */ + ps[_L1] = ps[_L2], ps[_L2] = ps[_L3]; + ps[_L3] = ps[_L4], ps[_L4] = 0; + } + for (; ps[_L1] < 1U<<_LOFF; --xchar) { /* shift left by 1 */ + ps[_L1] = ps[_L1] << 1 | ps[_L2] >> 15; + ps[_L2] = ps[_L2] << 1 | ps[_L3] >> 15; + ps[_L3] = ps[_L3] << 1 | ps[_L4] >> 15; + ps[_L4] <<= 1; + } + return (xchar); +} + +static short _Ldunscale(short *pex, ldouble *px) +{ /* separate *px to |frac| < 1/2 and 2^*pex */ + unsigned short *ps = (unsigned short *) px; + short xchar = ps[_L0] & _LMAX; + + if (xchar == _LMAX) { /* NaN or INF */ + *pex = 0; + return (ps[_L1] & 0x7fff || ps[_L2] || ps[_L3] || ps[_L4] ? + _NAN : INF); + } else if (ps[_L1] == 0 && ps[_L2] == 0 && ps[_L3] == 0 && ps[_L4] == 0) { + /* zero */ + *pex = 0; + return (0); + } else { /* finite, reduce to [1/2, 1) */ + xchar += dnorm(ps); + ps[_L0] = ps[_L0] & _LSIGN | _LBIAS; + *pex = xchar - _LBIAS; + return (FINITE); + } +} + +#else /* long double same as double */ +/* + static short _Dnorm(unsigned short *ps) + { + short xchar; + unsigned short sign = ps[_D0] & _DSIGN; + + xchar = 0; + if ((ps[_D0] &= _DFRAC) != 0 || ps[_D1] || ps[_D2] || ps[_D3]) { + for (; ps[_D0] == 0; xchar -= 16) { + ps[_D0] = ps[_D1], ps[_D1] = ps[_D2]; + ps[_D2] = ps[_D3], ps[_D3] = 0; + } + for (; ps[_D0] < 1<<_DOFF; --xchar) { + ps[_D0] = ps[_D0] << 1 | ps[_D1] >> 15; + ps[_D1] = ps[_D1] << 1 | ps[_D2] >> 15; + ps[_D2] = ps[_D2] << 1 | ps[_D3] >> 15; + ps[_D3] <<= 1; + } + for (; 1<<_DOFF+1 <= ps[_D0]; ++xchar) { + ps[_D3] = ps[_D3] >> 1 | ps[_D2] << 15; + ps[_D2] = ps[_D2] >> 1 | ps[_D1] << 15; + ps[_D1] = ps[_D1] >> 1 | ps[_D0] << 15; + ps[_D0] >>= 1; + } + ps[_D0] &= _DFRAC; + } + ps[_D0] |= sign; + return (xchar); + } + */ +static short _Ldunscale(short *pex, ldouble *px) +{ /* separate *px to |frac| < 1/2 and 2^*pex */ + unsigned short *ps = (unsigned short *) px; + short xchar = (short)((ps[_D0] & _DMASK) >> _DOFF); + + if (xchar == _DMAX) { /* NaN or INF */ + *pex = 0; + return (short)(ps[_D0] & _DFRAC || ps[_D1] || ps[_D2] || ps[_D3] ? + _NAN : INF); + } else if (0 < xchar /* || (xchar = _Dnorm(ps)) != 0 */) { + /* finite, reduce to [1/2, 1) */ + ps[_D0] = (short)(ps[_D0] & ~_DMASK | _DBIAS << _DOFF); +#if _LONG_DOUBLE + *pex = (short)(xchar - _DBIAS); +#else + *pex = (short)(xchar - _DBIAS + 1); /* for SGI */ +#endif + return (FINITE); + } else if (xchar < 0) { /* error! */ + return (_NAN); + } else { /* zero */ + *pex = 0; + return (0); + } +} + +#endif + +static void _Genld(_Pft *px, char code, char *p, short nsig, short xexp) +{ /* generate long double text */ + const char point = '.'; + + if (nsig <= 0) + nsig = 1, p = "0"; + if (code == 'f' || (code == 'g' || code == 'G') && + -4 <= xexp && xexp < px->prec) { /* 'f' format */ + ++xexp; /* change to leading digit count */ + if (code != 'f') { /* fixup for 'g' */ + if (!(px->flags & _FNO) && nsig < px->prec) + px->prec = nsig; + if ((px->prec -= xexp) < 0) + px->prec = 0; + } + if (xexp <= 0) { /* digits only to right of point */ + px->s[px->n1++] = '0'; + + if (0 < px->prec || px->flags & _FNO) + px->s[px->n1++] = point; + if (px->prec < -xexp) + xexp = (short)(-px->prec); + px->nz1 = -xexp; + px->prec += xexp; + if (px->prec < nsig) + nsig = (short)(px->prec); + (void)my_memcpy(&px->s[px->n1], p, px->n2 = nsig); + px->nz2 = px->prec - nsig; + } else if (nsig < xexp) { /* zeros before point */ + (void)my_memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = xexp - nsig; + if (0 < px->prec || px->flags & _FNO) + px->s[px->n1] = point, ++px->n2; + px->nz2 = px->prec; + } else { /* enough digits before point */ + (void)my_memcpy(&px->s[px->n1], p, xexp); + px->n1 += xexp; + nsig -= xexp; + if (0 < px->prec || px->flags & _FNO) + px->s[px->n1++] = point; + if (px->prec < nsig) + nsig = (short)(px->prec); + (void)my_memcpy(&px->s[px->n1], p + xexp, nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + } else { /* 'e' format */ + if (code == 'g' || code == 'G') { /* fixup for 'g' */ + if (nsig < px->prec) + px->prec = nsig; + if (--px->prec < 0) + px->prec = 0; + code = (char)(code == 'g' ? 'e' : 'E'); + } + px->s[px->n1++] = *p++; + if (0 < px->prec || px->flags & _FNO) + px->s[px->n1++] = point; + if (0 < px->prec) { /* put fraction digits */ + if (px->prec < --nsig) + nsig = (short)(px->prec); + (void)my_memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + p = &px->s[px->n1]; /* put exponent */ + *p++ = code; + if (0 <= xexp) + *p++ = '+'; + else { /* negative exponent */ + *p++ = '-'; + xexp = (short)(-xexp); + } + if (100 <= xexp) { /* put oversize exponent */ + if (1000 <= xexp) + *p = (char)(xexp / 1000 + '0'), p++, xexp %= 1000; + *p = (char)(xexp / 100 + '0'), p++, xexp %= 100; + } + *p = (char)(xexp / 10 + '0'),p++, xexp %= 10; + *p = (char)(xexp + '0'); p++; + px->n2 = p - &px->s[px->n1]; + } + if ((px->flags & (_FMI | _FZE)) == _FZE) { /* pad with leading zeros */ + int n = px->n0 + px->n1 + px->nz1 + px->n2 + px->nz2; + + if (n < px->width) + px->nz0 = px->width - n; + } +} + diff --git a/build/tools/sctools/common/src/logprintf.h b/build/tools/sctools/common/src/logprintf.h new file mode 100644 index 0000000..84983ee --- /dev/null +++ b/build/tools/sctools/common/src/logprintf.h @@ -0,0 +1,7 @@ +#ifndef _LOGPRINT_ +#define _LOGPRINT_ + +void miya_log_fprintf(FSFile *fd, const char *fmt, ...); + + +#endif /* _LOGPRINT_ */ diff --git a/build/tools/sctools/common/src/mprintf.c b/build/tools/sctools/common/src/mprintf.c new file mode 100644 index 0000000..720810e --- /dev/null +++ b/build/tools/sctools/common/src/mprintf.c @@ -0,0 +1,817 @@ +/************************************************************************** + * Copyright (C) 1997, Nintendo Co.,Ltd. * + *************************************************************************/ + +/* c:/program files/Metrowerks/CodeWarrior for NITRO V0.4/ARM_EABI_Support/msl/MSL_C/MSL_ARM/Include/ */ + +//#pragma avoid_byte none +//#pragma warn_byte none + +#define __std(ref) ref +// #define __std(ref) ::std::ref + + +#include + + + +#define __fourbytealign(n) ((((unsigned long) (n)) + 3U) & ~3U) +#define __va_start(parm) ((__std(va_list)) ((char*) ((unsigned long)(&parm) & ~3U) + __fourbytealign(sizeof(parm)))) + +#define va_start(ap, parm) ((ap) = __va_start(parm)) + +#define va_arg(ap, type) (*(type *) ((ap += __fourbytealign(sizeof(type))) - __fourbytealign(sizeof(type)))) +#define va_end(ap) ((void) 0) + + +#include "text.h" +#include "mprintf.h" + +#define CODE32 + + +static inline u8 My_ReadByte( const void* address ) +{ + if ( (u32)address & 1 ) + { + return (u8)( *(u16*)((u32)address & ~1) >> 8 ); + } + else + { + return (u8)( *(u16*)address & 0xff ); + } +} + + + +static inline void My_WriteByte( void* address, u8 value ) +{ + u16 val = *(u16*)((u32)address & ~1); + + if ( (u32)address & 1 ) + { + *(u16*)((u32)address & ~1) = (u16)( ((value & 0xff)<< 8) | (val & 0xff) ); + } + else + { + *(u16*)((u32)address & ~1) = (u16)( (val & 0xff00) | (value & 0xff) ); + } +} + + + +void mprintf(const char *fmt, ...); + +static void *memcpy(void *dest, const void *src, size_t n) +{ + unsigned char *s = (unsigned char *)dest; + unsigned char *ss = (unsigned char *)src; + + while(n--) { + My_WriteByte( s++,My_ReadByte(ss++)); + } + return dest; +} + + + +static const char *strchr(const char *s,int c) +{ + int a; + while( (a = (int)My_ReadByte(s)) != NULL ) { + if(a == c) + return s; + s++; + } + return (const char *)NULL; +} + +static size_t strlen(const char *s) +{ + size_t n=0; + while( My_ReadByte(s) != NULL) { + n++; + s++; + } + return n; +} + + + +#define MIYA_PUTCHAR m_putchar + +static int _Printf(void *(*pfn)(void *, const char *, size_t), + void *arg, const char *fmt, va_list ap); + +static void *proutPrintf(void *txb, const char *buf, size_t n) +{ + /* write to file */ + /* return (fwrite(buf, 1, n, str) == n ? str : NULL);*/ + int i; + + for (i = 0; i < n; i++) + MIYA_PUTCHAR( txb, My_ReadByte(&(buf[i]))); + /* return a fake pointer so that it's not NULL */ + return ((void *)txb); +} + + +void mprintf(const char *fmt, ...) +{ + void *tb = (void *)tc[0]; + int ans; + va_list ap; + va_start(ap, fmt); + ans = _Printf(&proutPrintf, tb, fmt, ap); + va_end(ap); +} + +void mfprintf(TEXT_CTRL *tc, const char *fmt, ...) +{ + int ans; + va_list ap; + va_start(ap, fmt); + ans = _Printf(&proutPrintf, (void *)tc, fmt, ap); + va_end(ap); +} + +/*******************************************************/ + +/* _Printf function */ + +#define _YVALS + +/* float properties */ +#define _D0 3 +#define _DBIAS (0x400-1) +#define _DLONG 0 +#define _DOFF 4 +#define _LBIAS (0x400-1) +#define _LONG_DOUBLE 0 + +/* pointer properties */ +#define _NULL (void *) 0 +typedef unsigned int _Sizet; + +/***********************************************************/ +#define _FSP 0x01 +#define _FPL 0x02 +#define _FMI 0x04 +#define _FNO 0x08 +#define _FZE 0x10 +#define _WMAX 999 +#define _WANT (EOF-1) + +#if _LONG_DOUBLE +typedef long double ldouble; +#else +typedef double ldouble; +#endif + +typedef struct { + union { + long long ll; + ldouble ld; + } v; + char *s; + int n0, nz0, n1, nz1, n2, nz2, prec, width; + size_t nchar; + unsigned int flags; + char qual; + char padding0[3]; +} _Pft; + +/* declarations */ +static void miya_Ldtob(_Pft *, char); +static void miya_Litob(_Pft *, char); + + + +/* macros */ + +#if _DLONG +#define LDSIGN(x) (((unsigned short *) &(x))[_D0 ? 4 : 0] & 0x8000) +#else +#define LDSIGN(x) (((unsigned short *) &(x))[_D0] & 0x8000) +#endif + +#define ISDIGIT(c) ((c >= '0') && (c <= '9')) +#define MAX_PAD (sizeof(spaces) - 1) +#define PAD(s, n) \ + if (0 < (n)) { \ + int i, j = (n); \ + for (; 0 < j; j -= i) { \ + i = MAX_PAD < j ? MAX_PAD : j; \ + PUT(s, i); \ + } \ + } +#define PUT(s, n) \ + if (0 < (n)) { \ + if ((arg = (*pfn)(arg, s, n)) != NULL) \ + x.nchar += (n); \ + else \ + return (x.nchar); \ + } + +static char spaces[] = " "; +static char zeroes[] = "00000000000000000000000000000000"; + +static void _Putfld(_Pft *, va_list *, char, char *); + + +typedef struct { + long quot; + long rem; +} miya_ldiv_t; + +typedef struct { + long long quot; + long long rem; +} miya_lldiv_t; + +static miya_lldiv_t miya_lldiv(long long a, long long b) +{ + miya_lldiv_t t; + t.quot = a / b; + t.rem = a % b; + return t; +} + +static miya_ldiv_t miya_ldiv(long a, long b) +{ + miya_ldiv_t t; + t.quot = a / b; + t.rem = a % b; + return t; +} + +// static void *proutPrintf(void *txb, const char *buf, size_t n) +// ans = _Printf(&proutPrintf, tb, (const char *)tc->buffer, ap); + +static int _Printf(void *(*pfn)(void *, const char *, size_t), + void *arg, const char *fmt, va_list ap) +{ /* print formatted */ + _Pft x; + + x.nchar = 0; + while (1) { /* scan format string */ + const char *s = fmt; + int c; + const char *t; + static const char fchar[] = {" +-#0"}; + static const unsigned int fbit[] = { + _FSP, _FPL, _FMI, _FNO, _FZE, 0}; + char ac[32]; + + /* copy any literal text */ + + while ( (0 < (c = (int)My_ReadByte(s++)) ) && (c != '%')) { + } + --s; +#if 1 + PUT(fmt, s - fmt); +#else + if (0 < (s-fmt)) { + if ((arg = (*pfn)(arg, fmt, s-fmt)) != NULL) + x.nchar += (s-fmt); + else + return (x.nchar); + } + +#endif + if (c == '\0') + return (x.nchar); + fmt = ++s; + + /* parse a conversion specifier */ + for (x.flags = 0; (t = strchr(fchar, *s)) != NULL; ++s) + x.flags |= fbit[t - fchar]; + if (My_ReadByte(s) == '*') { /* get width argument */ + x.width = va_arg(ap, int); + if (x.width < 0) { /* same as '-' flag */ + x.width = -x.width; + x.flags |= _FMI; + } + ++s; + } else /* accumulate width digits */ + for (x.width = 0; ISDIGIT((int)*s); ++s) + if (x.width < _WMAX) + x.width = x.width * 10 + *s - '0'; + if (My_ReadByte(s) != '.') + x.prec = -1; + else if ( My_ReadByte(++s) == '*') { /* get precision argument */ + x.prec = va_arg(ap, int); + ++s; + } else /* accumulate precision digits */ + for (x.prec = 0; ISDIGIT(*s); ++s) + if (x.prec < _WMAX) + x.prec = x.prec * 10 + *s - '0'; + My_WriteByte(&(x.qual), + (char)(strchr("hlL", My_ReadByte(s)) ? My_ReadByte(s++) : '\0')); + if ((My_ReadByte(&(x.qual)) == 'l') && (My_ReadByte(s) == 'l')) { + My_WriteByte(&(x.qual), 'L'); /* the %ll qualifier */ + s++; + } + + /* do the conversion */ + _Putfld(&x, &ap, My_ReadByte(s), ac); + x.width -= x.n0 + x.nz0 + x.n1 + x.nz1 + x.n2 + x.nz2; + if (!(x.flags & _FMI)) + PAD(spaces, x.width); + PUT(ac, x.n0); + PAD(zeroes, x.nz0); + PUT(x.s, x.n1); + PAD(zeroes, x.nz1); + PUT(x.s + x.n1, x.n2); + PAD(zeroes, x.nz2); + if (x.flags & _FMI) + PAD(spaces, x.width); + fmt = s + 1; + } + /* shouldn't reach here, only used to eliminate the compiler warning */ + return 0; +} + +static void _Putfld(_Pft *px, va_list *pap, char code, char *ac) +{ /* convert a field for _Printf */ + + px->n0 = px->nz0 = px->n1 = px->nz1 = px->n2 = px->nz2 = 0; + switch (code) { /* switch on conversion specifier */ + case 'c': + My_WriteByte(&(ac[px->n0++]), (char)va_arg(*pap, int)); + break; + case 'd': + case 'i': /* convert a signed decimal integer */ + if (px->qual == 'l') + px->v.ll = va_arg(*pap, long); + else if (px->qual == 'L') + px->v.ll = va_arg(*pap, long long); + else + px->v.ll = va_arg(*pap, int); + if (My_ReadByte(&(px->qual)) == 'h') + px->v.ll = (short) px->v.ll; + if (px->v.ll < 0) /* negate safely in miya_Litob */ + My_WriteByte(&(ac[px->n0++]), '-'); + else if (px->flags & _FPL) + My_WriteByte(&(ac[px->n0++]),'+'); + else if (px->flags & _FSP) + My_WriteByte(&(ac[px->n0++]),' '); + px->s = &ac[px->n0]; + miya_Litob(px, code); + break; + case 'o': + case 'u': + case 'x': + case 'X': /* convert unsigned */ + if (px->qual == 'l') + px->v.ll = va_arg(*pap, long); + else if (px->qual == 'L') + px->v.ll = va_arg(*pap, long long); + else + px->v.ll = va_arg(*pap, int); + if (px->qual == 'h') + px->v.ll = (unsigned short) px->v.ll; + else if (px->qual == '\0') + px->v.ll = (unsigned int) px->v.ll; + if (px->flags & _FNO) { /* indicate base with prefix */ + My_WriteByte(&(ac[px->n0++]),'0'); + if (code == 'x' || code == 'X') + My_WriteByte(&(ac[px->n0++]), code); + } + px->s = &ac[px->n0]; + miya_Litob(px, code); + break; + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': /* convert floating */ + px->v.ld = px->qual == 'L' ? + va_arg(*pap, ldouble) : va_arg(*pap, double); + if (LDSIGN(px->v.ld)) + My_WriteByte(&(ac[px->n0++]), '-'); + else if (px->flags & _FPL) + My_WriteByte(&(ac[px->n0++]), '+'); + else if (px->flags & _FSP) + My_WriteByte(&(ac[px->n0++]), ' '); + px->s = &ac[px->n0]; + miya_Ldtob(px, code); + break; + case 'n': /* return output count */ + if (px->qual == 'h') + *va_arg(*pap, short *) = (short)(px->nchar); + else if (px->qual == 'l') + *va_arg(*pap, long *) = px->nchar; + else if (px->qual == 'L') + *va_arg(*pap, long long *) = px->nchar; + else + *va_arg(*pap, int *) = px->nchar; + break; + case 'p': /* convert a pointer, hex long version */ + px->v.ll = (long) va_arg(*pap, void *); + px->s = &ac[px->n0]; + miya_Litob(px, 'x'); + break; + case 's': /* convert a string */ + px->s = va_arg(*pap, char *); + px->n1 = strlen(px->s); + if (0 <= px->prec && px->prec < px->n1) + px->n1 = px->prec; + break; + case '%': /* put a '%' */ + My_WriteByte(&(ac[px->n0++]),'%'); + break; + default: /* undefined specifier, print it out */ + My_WriteByte(&(ac[px->n0++]), code); + break; + } +} + +/*****************************************************************/ + +/* miya_Litob function */ + + +/* IEEE 754 properties */ +#define _DFRAC ((1<<_DOFF)-1) +#define _DMASK (0x7fff&~_DFRAC) +#define _DMAX ((1<<(15-_DOFF))-1) +#define _DNAN (0x8000|_DMAX<<_DOFF|1<<(_DOFF-1)) +#define _DSIGN 0x8000 +#define DSIGN(x) (((unsigned short *)&(x))[_D0] & _DSIGN) +#define HUGE_EXP (int)(_DMAX * 900L / 1000) +#define HUGE_RAD 3.14e30 +#define SAFE_EXP (_DMAX>>1) + +/* word offsets within double */ +#if _D0==3 +#define _D1 2 /* little-endian order */ +#define _D2 1 +#define _D3 0 +#else +#define _D1 1 /* big-endian order */ +#define _D2 2 +#define _D3 3 +#endif + +/* return values for _D functions */ +#define FINITE -1 +#define INF 1 +#define NAN 2 + +static char ldigs[] = "0123456789abcdef"; +static char udigs[] = "0123456789ABCDEF"; + +static void miya_Litob(_Pft *px, char code) +{ /* convert unsigned long to text */ + char ac[24]; /* safe for 64-bit integers */ + char *digs = code == 'X' ? udigs : ldigs; + int base = code == 'o' ? 8 : code != 'x' && code != 'X' ? 10 : 16; + int i = sizeof(ac); + unsigned long long ullval = px->v.ll; + + if ((code == 'd' || code == 'i') && px->v.ll < 0) + ullval = -ullval; /* safe against overflow */ + if (ullval || px->prec) + My_WriteByte(&(ac[--i]), My_ReadByte(&(digs[ullval % base]))); + px->v.ll = ullval / base; + while (0 < px->v.ll && 0 < i) { /* convert digits */ + miya_lldiv_t qr = miya_lldiv(px->v.ll, (long long) base); + + px->v.ll = qr.quot; + My_WriteByte(&(ac[--i]), My_ReadByte(&(digs[qr.rem]))); + } + px->n1 = sizeof(ac) - i; + (void)memcpy(px->s, &ac[i], px->n1); + if (px->n1 < px->prec) + px->nz0 = px->prec - px->n1; + if (px->prec < 0 && (px->flags & (_FMI | _FZE)) == _FZE + && 0 < (i = px->width - px->n0 - px->nz0 - px->n1)) + px->nz0 += i; + +} + + +/*************************************************/ +/* miya_Ldtob function */ + +#include "float.h" + +/* macros */ +#define NDIG 8 + +/* static data */ +static const ldouble pows[] = { + 1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L, +#if 0x100 < _LBIAS /* assume IEEE 754 8- or 10-byte */ + 1e64L, 1e128L, 1e256L, +#if _DLONG /* assume IEEE 754 10-byte */ + 1e512L, 1e1024L, 1e2048L, 1e4096L, +#endif +#endif +}; + +static short _Ldunscale(short *, ldouble *); +static void _Genld(_Pft *, char, char *, short, short); + +static void miya_Ldtob(_Pft *px, char code) +{ /* convert long double to text */ + char ac[32]; + char *p = ac; + ldouble ldval = px->v.ld; + short errx, nsig, xexp; + + if (px->prec < 0) + px->prec = 6; + else if (px->prec == 0 && (code == 'g' || code == 'G')) + px->prec = 1; + if (0 < (errx = _Ldunscale(&xexp, &px->v.ld))) { + /* x == Nan, x == INF */ + (void)memcpy(px->s, errx == NAN ? "NaN" : "Inf", px->n1 = 3); + return; + } else if (0 == errx) /*x == 0 */ + nsig = 0, xexp = 0; + else { /* 0 < |x|, convert it */ + { /* scale ldval to ~~10^(NDIG/2) */ + int i, n; + + if (ldval < 0.0) + ldval = -ldval; + if ((xexp = (short)(xexp * 30103L / 100000L - NDIG/2)) < 0) { + /* scale up */ + n = (-xexp + (NDIG/2-1)) & ~(NDIG/2-1), xexp = (short)(-n); + for (i = 0; 0 < n; n >>= 1, ++i) + if (n & 1) + ldval *= pows[i]; + } else if (0 < xexp) { /* scale down */ + ldouble factor = 1.0; + + xexp &= ~(NDIG/2-1); + for (n = xexp, i = 0; 0 < n; n >>= 1, ++i) + if (n & 1) + factor *= pows[i]; + ldval /= factor; + } + } + { /* convert significant digits */ + int gen = px->prec + + (code == 'f' ? xexp + 2 + NDIG : 2 + NDIG / 2); + + if (LDBL_DIG + NDIG / 2 < gen) + gen = LDBL_DIG + NDIG / 2; + for (My_WriteByte(p++, '0') ; 0 < gen && 0.0 < ldval; p += NDIG) { + /* convert NDIG at a time */ + int j; + long lo = (long) ldval; + + if (0 < (gen -= NDIG)) + ldval = (ldval - (ldouble) lo) * 1e8L; + for (p += NDIG, j = NDIG; 0 < lo && 0 <= --j; ) { + /* convert NDIG digits */ + miya_ldiv_t qr; + + qr = miya_ldiv(lo, 10); + My_WriteByte(--p , (char)(qr.rem + '0')), lo = qr.quot; + } + while (0 <= --j) + My_WriteByte(--p , '0'); + } + gen = p - &ac[1]; + for (p = &ac[1], xexp += NDIG - 1; My_ReadByte(p) == '0'; ++p) + --gen, --xexp; /* correct xexp */ + + /* miya + char code + int prec + short nsig, xexp; + */ + nsig = (short)(px->prec + (code == 'f' ? xexp + 1 : + code == 'e' || code == 'E' ? 1 : 0)); + if (gen < nsig) + nsig = (short)gen; + if (0 < nsig) { /* round and strip trailing zeros */ + const char drop; + int n; + My_WriteByte((void *)&drop, (char)(nsig < gen && '5' <= My_ReadByte(&(p[nsig])) ? '9' : '0') ); + + for (n = nsig; My_ReadByte(&(p[--n])) == My_ReadByte(&drop); ) + --nsig; + + if (My_ReadByte(&drop) == '9') { + My_WriteByte(&(p[n]), My_ReadByte(&(p[n])+1)); + + // ++p[n]; + } + if (n < 0) + --p, ++nsig, ++xexp; + } + } + } + _Genld(px, code, p, nsig, xexp); +} + +#if _DLONG /* 10-byte IEEE format */ +#define _LMASK 0x7fff +#define _LMAX 0x7fff +#define _LSIGN 0x8000 +#if _D0==3 /* little-endian order */ +#define _L0 4 +#define _L1 3 +#define _L2 2 +#define _L3 1 +#define _L4 0 +#else +#define _L0 0 +#define _L1 1 +#define _L2 2 +#define _L3 3 +#define _L4 4 +#endif + +static short dnorm(unsigned short *ps) +{ /* normalize long double fraction */ + short xchar; + + for (xchar = 0; ps[_L1] == 0; xchar -= 16) { /* shift left by 16 */ + ps[_L1] = ps[_L2], ps[_L2] = ps[_L3]; + ps[_L3] = ps[_L4], ps[_L4] = 0; + } + for (; ps[_L1] < 1U<<_LOFF; --xchar) { /* shift left by 1 */ + ps[_L1] = ps[_L1] << 1 | ps[_L2] >> 15; + ps[_L2] = ps[_L2] << 1 | ps[_L3] >> 15; + ps[_L3] = ps[_L3] << 1 | ps[_L4] >> 15; + ps[_L4] <<= 1; + } + return (xchar); +} + +static short _Ldunscale(short *pex, ldouble *px) +{ /* separate *px to |frac| < 1/2 and 2^*pex */ + unsigned short *ps = (unsigned short *) px; + short xchar = ps[_L0] & _LMAX; + + if (xchar == _LMAX) { /* NaN or INF */ + *pex = 0; + return (ps[_L1] & 0x7fff || ps[_L2] || ps[_L3] || ps[_L4] ? + NAN : INF); + } else if (ps[_L1] == 0 && ps[_L2] == 0 && ps[_L3] == 0 && ps[_L4] == 0) { + /* zero */ + *pex = 0; + return (0); + } else { /* finite, reduce to [1/2, 1) */ + xchar += dnorm(ps); + ps[_L0] = ps[_L0] & _LSIGN | _LBIAS; + *pex = xchar - _LBIAS; + return (FINITE); + } +} + +#else /* long double same as double */ +/* + static short _Dnorm(unsigned short *ps) + { + short xchar; + unsigned short sign = ps[_D0] & _DSIGN; + + xchar = 0; + if ((ps[_D0] &= _DFRAC) != 0 || ps[_D1] || ps[_D2] || ps[_D3]) { + for (; ps[_D0] == 0; xchar -= 16) { + ps[_D0] = ps[_D1], ps[_D1] = ps[_D2]; + ps[_D2] = ps[_D3], ps[_D3] = 0; + } + for (; ps[_D0] < 1<<_DOFF; --xchar) { + ps[_D0] = ps[_D0] << 1 | ps[_D1] >> 15; + ps[_D1] = ps[_D1] << 1 | ps[_D2] >> 15; + ps[_D2] = ps[_D2] << 1 | ps[_D3] >> 15; + ps[_D3] <<= 1; + } + for (; 1<<_DOFF+1 <= ps[_D0]; ++xchar) { + ps[_D3] = ps[_D3] >> 1 | ps[_D2] << 15; + ps[_D2] = ps[_D2] >> 1 | ps[_D1] << 15; + ps[_D1] = ps[_D1] >> 1 | ps[_D0] << 15; + ps[_D0] >>= 1; + } + ps[_D0] &= _DFRAC; + } + ps[_D0] |= sign; + return (xchar); + } + */ +static short _Ldunscale(short *pex, ldouble *px) +{ /* separate *px to |frac| < 1/2 and 2^*pex */ + unsigned short *ps = (unsigned short *) px; + short xchar = (short)((ps[_D0] & _DMASK) >> _DOFF); + + if (xchar == _DMAX) { /* NaN or INF */ + *pex = 0; + return (short)(ps[_D0] & _DFRAC || ps[_D1] || ps[_D2] || ps[_D3] ? + NAN : INF); + } else if (0 < xchar /* || (xchar = _Dnorm(ps)) != 0 */) { + /* finite, reduce to [1/2, 1) */ + ps[_D0] = (short)(ps[_D0] & ~_DMASK | _DBIAS << _DOFF); +#if _LONG_DOUBLE + *pex = (short)(xchar - _DBIAS); +#else + *pex = (short)(xchar - _DBIAS + 1); /* for SGI */ +#endif + return (FINITE); + } else if (xchar < 0) { /* error! */ + return (NAN); + } else { /* zero */ + *pex = 0; + return (0); + } +} + +#endif + +static void _Genld(_Pft *px, char code, char *p, short nsig, short xexp) +{ /* generate long double text */ + const char point = '.'; + + if (nsig <= 0) + nsig = 1, p = "0"; + if (code == 'f' || (code == 'g' || code == 'G') && + -4 <= xexp && xexp < px->prec) { /* 'f' format */ + ++xexp; /* change to leading digit count */ + if (code != 'f') { /* fixup for 'g' */ + if (!(px->flags & _FNO) && nsig < px->prec) + px->prec = nsig; + if ((px->prec -= xexp) < 0) + px->prec = 0; + } + if (xexp <= 0) { /* digits only to right of point */ + My_WriteByte(&(px->s[px->n1++]), '0'); + + if (0 < px->prec || px->flags & _FNO) + My_WriteByte(&(px->s[px->n1++]), point); + if (px->prec < -xexp) + xexp = (short)(-px->prec); + px->nz1 = -xexp; + px->prec += xexp; + if (px->prec < nsig) + nsig = (short)(px->prec); + (void)memcpy(&px->s[px->n1], p, px->n2 = nsig); + px->nz2 = px->prec - nsig; + } else if (nsig < xexp) { /* zeros before point */ + (void)memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = xexp - nsig; + if (0 < px->prec || px->flags & _FNO) + My_WriteByte(&(px->s[px->n1]), point), ++px->n2; + px->nz2 = px->prec; + } else { /* enough digits before point */ + (void)memcpy(&px->s[px->n1], p, xexp); + px->n1 += xexp; + nsig -= xexp; + if (0 < px->prec || px->flags & _FNO) + My_WriteByte(&(px->s[px->n1++]),point); + if (px->prec < nsig) + nsig = (short)(px->prec); + (void)memcpy(&px->s[px->n1], p + xexp, nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + } else { /* 'e' format */ + if (code == 'g' || code == 'G') { /* fixup for 'g' */ + if (nsig < px->prec) + px->prec = nsig; + if (--px->prec < 0) + px->prec = 0; + code = (char)(code == 'g' ? 'e' : 'E'); + } + My_WriteByte(&(px->s[px->n1++]), My_ReadByte(p++)); + if (0 < px->prec || px->flags & _FNO) + My_WriteByte(&(px->s[px->n1++]), point); + if (0 < px->prec) { /* put fraction digits */ + if (px->prec < --nsig) + nsig = (short)(px->prec); + (void)memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + p = &px->s[px->n1]; /* put exponent */ + My_WriteByte(&p, code); + p++; + if (0 <= xexp) + My_WriteByte(p++, '+'); + else { /* negative exponent */ + My_WriteByte(p++, '-'); + xexp = (short)(-xexp); + } + if (100 <= xexp) { /* put oversize exponent */ + if (1000 <= xexp) + My_WriteByte(p, (char)(xexp / 1000 + '0')),p++, xexp %= 1000; + My_WriteByte(p, (char)(xexp / 100 + '0')), p++, xexp %= 100; + } + My_WriteByte(p, (char)(xexp / 10 + '0')),p++, xexp %= 10; + My_WriteByte(p, (char)(xexp + '0')); p++; + px->n2 = p - &px->s[px->n1]; + } + if ((px->flags & (_FMI | _FZE)) == _FZE) { /* pad with leading zeros */ + int n = px->n0 + px->n1 + px->nz1 + px->n2 + px->nz2; + + if (n < px->width) + px->nz0 = px->width - n; + } +} diff --git a/build/tools/sctools/common/src/mprintf.h b/build/tools/sctools/common/src/mprintf.h new file mode 100644 index 0000000..0480313 --- /dev/null +++ b/build/tools/sctools/common/src/mprintf.h @@ -0,0 +1,20 @@ +#ifndef _MPRINT_ +#define _MPRINT_ + +#define NUM_OF_SCREEN 4 + +extern TEXT_CTRL *tc[NUM_OF_SCREEN]; + +#ifdef __cplusplus +extern "C" { +#endif + +void mfprintf(TEXT_CTRL *tc, const char *fmt, ...); +void mprintf(const char *fmt, ...); + +#ifdef __cplusplus +} +#endif + + +#endif /* _MPRINT_ */ diff --git a/build/tools/sctools/common/src/my_fs_util.c b/build/tools/sctools/common/src/my_fs_util.c new file mode 100644 index 0000000..9878ed7 --- /dev/null +++ b/build/tools/sctools/common/src/my_fs_util.c @@ -0,0 +1,1828 @@ +#include +#include "text.h" +#include "mprintf.h" +#include "my_fs_util.h" +#include "logprintf.h" + +/* + NAND -> SDコピーの時、アトリビュートと時間とパーミッションを合わせる必要あり? + + +// ファイル名の最大長 (旧仕様のプロシージャに限定) +#define FS_FILE_NAME_MAX 127 + +// エントリ名の最大長 (旧仕様のプロシージャに限定) +#define FS_ENTRY_SHORTNAME_MAX 16 +#define FS_ENTRY_LONGNAME_MAX 260 + +// ReadDirectoryで使用するエントリ属性 +#define FS_ATTRIBUTE_IS_DIRECTORY 0x00000100UL +#define FS_ATTRIBUTE_IS_PROTECTED 0x00000200UL +// MS-DOS FATベースのアーカイブに限り意味のある属性 +#define FS_ATTRIBUTE_DOS_MASK 0x000000FFUL +#define FS_ATTRIBUTE_DOS_READONLY 0x00000001UL +#define FS_ATTRIBUTE_DOS_HIDDEN 0x00000002UL +#define FS_ATTRIBUTE_DOS_SYSTEM 0x00000004UL +#define FS_ATTRIBUTE_DOS_VOLUME 0x00000008UL +#define FS_ATTRIBUTE_DOS_DIRECTORY 0x00000010UL +#define FS_ATTRIBUTE_DOS_ARCHIVE 0x00000020UL + + +// OpenFileで使用するアクセスモード +#define FS_FILEMODE_R 0x00000001UL +#define FS_FILEMODE_W 0x00000002UL +#define FS_FILEMODE_L 0x00000004UL +#define FS_FILEMODE_RW (FS_FILEMODE_R | FS_FILEMODE_W) +#define FS_FILEMODE_RWL (FS_FILEMODE_R | FS_FILEMODE_W | FS_FILEMODE_L) + +// OpenDirectoryで使用するアクセスモード +#define FS_DIRMODE_SHORTNAME_ONLY 0x00001000UL + +// CreateFileで使用する権限フラグ +#define FS_PERMIT_R 0x00000001UL +#define FS_PERMIT_W 0x00000002UL +#define FS_PERMIT_RW (FS_PERMIT_R | FS_PERMIT_W) + +// ReadDirectoryで使用するエントリ情報 +typedef struct FSDirectoryEntryInfo +{ + char shortname[FS_ENTRY_SHORTNAME_MAX]; + u32 shortname_length; + char longname[FS_ENTRY_LONGNAME_MAX]; + u32 longname_length; + u32 attributes; + FSDateTime atime; + FSDateTime mtime; + FSDateTime ctime; + u32 filesize; + u32 id; +} FSDirectoryEntryInfo; + +typedef struct FSDirectoryEntryInfoW +{ + u32 attributes; + FSDateTime atime; + FSDateTime mtime; + FSDateTime ctime; + u32 filesize; + u32 id; + u32 shortname_length; + u32 longname_length; + char shortname[FS_ENTRY_SHORTNAME_MAX]; + u16 longname[FS_ENTRY_LONGNAME_MAX]; +} FSDirectoryEntryInfoW; + +// GetPathInfo,SetPathInfoで使用するエントリ情報 +typedef struct FSPathInfo +{ + u32 attributes; + FSDateTime ctime; + FSDateTime mtime; + FSDateTime atime; + u32 filesize; + u32 id; +} FSPathInfo; +*/ + + +static const u32 BUF_SIZE = 256; + +typedef struct { + FSResult result; + char string[32]; +} FS_RESUTL_WORD; + +/* c:/twlsdk/include/nitro/fs/types.h */ + +static FS_RESUTL_WORD my_word[] = { + { FS_RESULT_SUCCESS, "FS_RESULT_SUCCESS" }, + { FS_RESULT_FAILURE, "FS_RESULT_FAILURE" }, + { FS_RESULT_BUSY, "FS_RESULT_BUSY" }, + { FS_RESULT_CANCELED, "FS_RESULT_CANCELED" }, + { FS_RESULT_CANCELLED, "FS_RESULT_CANCELLED" }, + { FS_RESULT_UNSUPPORTED, "FS_RESULT_UNSUPPORTED" }, + { FS_RESULT_ERROR, "FS_RESULT_ERROR" }, + { FS_RESULT_INVALID_PARAMETER, "FS_RESULT_INVALID_PARAMETER" }, + { FS_RESULT_NO_MORE_RESOUCE, "FS_RESULT_NO_MORE_RESOUCE" }, + { FS_RESULT_ALREADY_DONE, "FS_RESULT_ALREADY_DONE" }, + { FS_RESULT_PERMISSION_DENIED, "FS_RESULT_PERMISSION_DENIED" }, + { FS_RESULT_MEDIA_FATAL, "FS_RESULT_MEDIA_FATAL" }, + { FS_RESULT_NO_ENTRY, "FS_RESULT_NO_ENTRY" }, + { FS_RESULT_MEDIA_NOTHING, "FS_RESULT_MEDIA_NOTHING" }, + { FS_RESULT_MEDIA_UNKNOWN, "FS_RESULT_MEDIA_UNKNOWN" }, + { FS_RESULT_BAD_FORMAT, "FS_RESULT_BAD_FORMAT" }, + { FS_RESULT_MAX, "FS_RESULT_MAX" }, + // プロシージャ内で使用する一時的な結果値 + { FS_RESULT_PROC_ASYNC, "FS_RESULT_PROC_ASYNC" }, + { FS_RESULT_PROC_DEFAULT, "FS_RESULT_PROC_DEFAULT" }, + { FS_RESULT_PROC_UNKNOWN, "FS_RESULT_PROC_UNKNOW" }, +}; + + +char *my_fs_util_get_fs_result_word( FSResult res ) +{ + int i; + for( i = 0 ; i < 19 ; i++ ) { + if( my_word[i].result == res ) { + return my_word[i].string; + } + } + return my_word[0].string; +} + + +static void PrintAttributes(u32 attributes, FSFile *log_fd) +{ + char buf[7]; + buf[0] = (char)(( attributes & FS_ATTRIBUTE_DOS_DIRECTORY )? 'd' : '-'); + buf[1] = (char)(( attributes & FS_ATTRIBUTE_DOS_VOLUME )? 'v' : '-'); + buf[2] = (char)(( attributes & FS_ATTRIBUTE_DOS_SYSTEM )? 's' : '-'); + buf[3] = (char)(( attributes & FS_ATTRIBUTE_DOS_ARCHIVE )? 'a' : '-'); + buf[4] = (char)(( attributes & FS_ATTRIBUTE_DOS_HIDDEN )? 'h' : '-'); + buf[5] = (char)(( attributes & FS_ATTRIBUTE_DOS_READONLY )? 'R' : '-'); + buf[6] = '\0'; + miya_log_fprintf(log_fd, "%s", buf ); + +} + + +static BOOL Log_File_Open(FSFile *log_fd, const char *log_file_name) +{ + BOOL bSuccess; + FSResult res; + + if( log_file_name == NULL ) { + return FALSE; + } + + FS_InitFile(log_fd); + + bSuccess = FS_OpenFileEx(log_fd, log_file_name, (FS_FILEMODE_W)); + + if( ! bSuccess ) { + FS_CreateFileAuto( log_file_name, FS_PERMIT_W); + bSuccess = FS_OpenFileEx(log_fd, log_file_name, (FS_FILEMODE_W)); + if( ! bSuccess ) { + res = FS_GetArchiveResultCode( log_file_name ); + miya_log_fprintf(NULL, "log file open error %s\n", log_file_name ); + miya_log_fprintf(NULL, " Failed open file:%s\n", my_fs_util_get_fs_result_word( res )); + return FALSE; + } + } + return TRUE; +} + +static void Log_File_Close(FSFile *log_fd) +{ + FS_FlushFile(log_fd); + FS_CloseFile(log_fd); +} + +/*---------------------------------------------------------------------------* + Name: LoadFile + + Description: 内部でメモリを確保しファイルを読み込みます。 + + Arguments: path: 読み込むファイルのパス。 + + Returns: ファイルが存在するならファイルの内容が読み込まれた + 内部で確保したバッファへのポインタを返します。 + このポインタは FS_Free で解放する必要があります。 + *---------------------------------------------------------------------------*/ +static BOOL LoadFile(const char* path, char **alloc_ptr, int *alloc_size, FSFile *log_fd) +{ + FSFile f; + BOOL bSuccess; + char* pBuffer; + u32 fileSize; + s32 readSize = 0; + + if( alloc_ptr == 0 || alloc_size == NULL ) { + miya_log_fprintf(log_fd, "Failed LoadFile argument error\n"); + return FALSE; + } + + FS_InitFile(&f); + + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_R); + if( ! bSuccess ) { + miya_log_fprintf(log_fd, "Failed Open File %s\n",__FUNCTION__); + miya_log_fprintf(log_fd, " path=%s\n", path ); + miya_log_fprintf(log_fd, " res=%s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path) )); + return FALSE; + } + + fileSize = FS_GetFileLength(&f); + pBuffer = (char*)OS_Alloc(fileSize + 1); + if( pBuffer == NULL ) { + miya_log_fprintf(log_fd, "Mem alloc error: %s\n", __FUNCTION__); + return FALSE; + } + + readSize = FS_ReadFile(&f, pBuffer, (s32)fileSize); + if( readSize != fileSize ) { + miya_log_fprintf(log_fd, "Failed Read File: %s\n",path); + } + + *alloc_size = (int)readSize; + + bSuccess = FS_CloseFile(&f); + if( ! bSuccess ) { + miya_log_fprintf(log_fd, "Failed Close File\n"); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path))); + } + + pBuffer[fileSize] = '\0'; + *alloc_ptr = pBuffer; + return TRUE; +} + +static BOOL SaveFile(const char* path, void* pData, u32 size, FSFile *log_fd) +{ + FSFile f; + BOOL bSuccess; + FSResult fsResult; + s32 writtenSize; + + FS_InitFile(&f); + + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_W); + if (bSuccess == FALSE) { + FSResult res = FS_GetArchiveResultCode(path); + if( res == FS_RESULT_NO_ENTRY ) { + /* 本来ここで問題なし */ + } + else { + miya_log_fprintf(log_fd, "Failed open file:%s %d %s %s\n", + __FUNCTION__,__LINE__, path, my_fs_util_get_fs_result_word(res) ); + } + } + else { + FS_CloseFile(&f); + /* backup バックアップを取っておくべき?? */ + FS_DeleteFile(path); + } + + FS_CreateFile(path, (FS_PERMIT_R|FS_PERMIT_W)); + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_W); + if (bSuccess == FALSE) { + FSResult res = FS_GetArchiveResultCode(path); + miya_log_fprintf(log_fd,"Failed open file:%s %d %s %s\n", + __FUNCTION__,__LINE__, path, my_fs_util_get_fs_result_word(res) ); + return FALSE; + } + + fsResult = FS_SetFileLength(&f, 0); + if( fsResult != FS_RESULT_SUCCESS ) { + } + + writtenSize = FS_WriteFile(&f, pData, (s32)size); + if( writtenSize != size ) { + } + + FS_FlushFile(&f); + bSuccess = FS_CloseFile(&f); + if( bSuccess ) { + + } + return TRUE; +} + +static BOOL CopyFile(const char *dst_path, const char *src_path, FSFile *log_fd ) +{ + char *alloc_ptr = NULL; + int alloc_size = 0; + + if( TRUE == LoadFile(src_path, &alloc_ptr, &alloc_size, log_fd) ) { + if( TRUE == SaveFile(dst_path, alloc_ptr, (u32)alloc_size, log_fd) ) { + if( alloc_ptr ) { + OS_Free(alloc_ptr); + } + return TRUE; + } + if( alloc_ptr ) { + OS_Free(alloc_ptr); + } + return FALSE; + } + return FALSE; +} + +static BOOL CompareFsDateTime( FSDateTime *dt1, FSDateTime *dt2) +{ + if( dt1->year != dt2->year ) { + return FALSE; + } + if( dt1->month != dt2->month ) { + return FALSE; + } + if( dt1->day != dt2->day ) { + return FALSE; + } + if( dt1->hour != dt2->hour ) { + return FALSE; + } + if( dt1->minute != dt2->minute ) { + return FALSE; + } + if( dt1->second != dt2->second ) { + return FALSE; + } + return TRUE; +} + +static BOOL restore_entry_list(MY_DIR_ENTRY_LIST **headp, FSFile *log_fd) +{ + MY_DIR_ENTRY_LIST *list_temp; + MY_DIR_ENTRY_LIST *list_temp2; + FSPathInfo path_info; + int count = 0; + /* トップディレクトリの方から順にリストされているので */ + /* リストの後ろ(下位ディレクトリの方)から戻さないといけない */ + /* バックワードで戻していく */ + + if( *headp == NULL ) { + } + else { + for( list_temp = *headp ; list_temp->next != NULL ; list_temp = list_temp->next ) { + ; + } + while( list_temp != NULL ) { + path_info.attributes = list_temp->content.attributes; + path_info.ctime = list_temp->content.ctime; + path_info.mtime = list_temp->content.mtime; + path_info.atime = list_temp->content.atime; + path_info.id = list_temp->content.id; + path_info.filesize = list_temp->content.filesize; + if( FALSE == FS_SetPathInfo( list_temp->src_path, &path_info) ) { + FSResult fsResult = FS_GetArchiveResultCode(list_temp->src_path); + miya_log_fprintf(log_fd, "%s %d: Failed SetPathInfo\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(log_fd, " %s\n", list_temp->src_path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + } + count++; + list_temp2 = list_temp; + list_temp = list_temp->prev; + OS_Free( list_temp2 ); + } + } + return TRUE; +} + + +static BOOL add_entry_list( MY_DIR_ENTRY_LIST **headp, MY_DIR_ENTRY_LIST *entry_list ) +{ + MY_DIR_ENTRY_LIST *list_temp; + MY_DIR_ENTRY_LIST *list_prev_temp; + + if( entry_list == NULL ) { + return FALSE; + } + if( headp == NULL ) { + return FALSE; + } + + if( *headp == NULL ) { + *headp = (MY_DIR_ENTRY_LIST *)OS_Alloc( sizeof(MY_DIR_ENTRY_LIST) ); + STD_CopyMemory( (void *)(*headp), (void *)entry_list , sizeof(MY_DIR_ENTRY_LIST) ); + (*headp)->prev = NULL; + (*headp)->next = NULL; + } + else { + for( list_temp = *headp ; list_temp->next != NULL ; list_temp = list_temp->next ) { + ; + } + list_temp->next = (MY_DIR_ENTRY_LIST *)OS_Alloc( sizeof(MY_DIR_ENTRY_LIST) ); + + list_prev_temp = list_temp; + list_temp = list_temp->next; + STD_CopyMemory( (void *)list_temp, (void *)entry_list , sizeof(MY_DIR_ENTRY_LIST) ); + list_temp->prev = list_prev_temp; + list_temp->next = NULL; + } + return TRUE; +} + +static BOOL my_fs_add_list( MY_DIR_ENTRY_LIST **headp, FSDirectoryEntryInfo *entry, + const char *src_path, const char *dst_path, FSFile *log_fd) +{ + MY_DIR_ENTRY_LIST *list_temp; + MY_DIR_ENTRY_LIST *list_prev_temp; + FSPathInfo path_info; + if( entry == NULL ) { + return FALSE; + } + + /* ファイルの場合 srcがNAND, dstがSD */ + if( !STD_StrCmp( src_path, "nand:" ) ) { + /* nandのルートディレクトリはスルーする。 */ + return TRUE; + } + + + if( FALSE == FS_GetPathInfo(src_path,&path_info) ) { + miya_log_fprintf(log_fd, "%s %d: Failed GetPathInfo\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(log_fd, " %s\n", src_path ); + } + else { + if( FALSE == CompareFsDateTime( &(entry->atime), &(path_info.atime)) ) { + miya_log_fprintf(log_fd, "warning atime\n"); + miya_log_fprintf(log_fd," entry %d/%02d/%02d ", entry->atime.year,entry->atime.month,entry->atime.day); + miya_log_fprintf(log_fd,"%02d:%02d:%02d\n", entry->atime.hour,entry->atime.minute,entry->atime.second); + miya_log_fprintf(log_fd," path_info %d/%02d/%02d ", path_info.atime.year,path_info.atime.month,path_info.atime.day); + miya_log_fprintf(log_fd,"%02d:%02d:%02d\n", path_info.atime.hour,path_info.atime.minute,path_info.atime.second); + + entry->atime = path_info.atime; + + } + + if( FALSE == CompareFsDateTime( &(entry->mtime), &(path_info.mtime)) ) { + miya_log_fprintf(log_fd, "warning mtime\n"); + miya_log_fprintf(log_fd," entry %d/%02d/%02d ", entry->mtime.year,entry->mtime.month,entry->mtime.day); + miya_log_fprintf(log_fd,"%02d:%02d:%02d\n", entry->mtime.hour,entry->mtime.minute,entry->mtime.second); + miya_log_fprintf(log_fd," path_info %d/%02d/%02d ", path_info.mtime.year,path_info.mtime.month,path_info.mtime.day); + miya_log_fprintf(log_fd,"%02d:%02d:%02d\n", path_info.mtime.hour,path_info.mtime.minute,path_info.mtime.second); + + entry->mtime = path_info.mtime; + } + +#if 0 + /* なぜがWarningが出る */ +OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + if( FALSE == CompareFsDateTime( &(entry->ctime), &(path_info.ctime)) ) { + miya_log_fprintf(log_fd, "warning ctime\n"); + miya_log_fprintf(log_fd," entry %d/%02d/%02d ", entry->ctime.year,entry->ctime.month,entry->ctime.day); + miya_log_fprintf(log_fd,"%02d:%02d:%02d\n", entry->ctime.hour,entry->ctime.minute,entry->ctime.second); + miya_log_fprintf(log_fd," path_info %d/%02d/%02d ", path_info.ctime.year,path_info.ctime.month,path_info.ctime.day); + miya_log_fprintf(log_fd,"%02d:%02d:%02d\n", path_info.ctime.hour,path_info.ctime.minute,path_info.ctime.second); + } +OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); +#endif + // OS_TPrintf("path info att=0x%08x\n",path_info.attributes); + if( entry->attributes != path_info.attributes ) { + miya_log_fprintf(log_fd, "Warning: path att = 0x%08x\n",path_info.attributes); + miya_log_fprintf(log_fd, " entry att = 0x%08x\n",entry->attributes); + } + entry->attributes = path_info.attributes; + } + + + if( *headp == NULL ) { + *headp = (MY_DIR_ENTRY_LIST *)OS_Alloc( sizeof(MY_DIR_ENTRY_LIST) ); + STD_MemSet((void *)*headp, 0, sizeof(MY_DIR_ENTRY_LIST) ); + + (*headp)->prev = NULL; + (*headp)->next = NULL; + STD_CopyMemory( (void *)&((*headp)->content), (void *)entry ,sizeof(FSDirectoryEntryInfo) ); + STD_StrCpy((*headp)->src_path, src_path); + if( dst_path ) { + STD_StrCpy((*headp)->dst_path, dst_path); + } + } + else { + for( list_temp = *headp ; list_temp->next != NULL ; list_temp = list_temp->next ) { + ; + } + list_temp->next = (MY_DIR_ENTRY_LIST *)OS_Alloc( sizeof(MY_DIR_ENTRY_LIST) ); + STD_MemSet((void *)list_temp->next, 0, sizeof(MY_DIR_ENTRY_LIST) ); + + list_prev_temp = list_temp; + list_temp = list_temp->next; + list_temp->prev = list_prev_temp; + list_temp->next = NULL; + STD_CopyMemory( (void *)&(list_temp->content), (void *)entry ,sizeof(FSDirectoryEntryInfo) ); + STD_StrCpy(list_temp->src_path, src_path); + if( dst_path ) { + STD_StrCpy(list_temp->dst_path, dst_path); + } + } + + return TRUE; +} + +BOOL ClearDirEntryList( MY_DIR_ENTRY_LIST **headp ) +{ + MY_DIR_ENTRY_LIST *list_temp1 = *headp; + MY_DIR_ENTRY_LIST *list_temp2; + + *headp = NULL; + + while( list_temp1 ) { + list_temp2 = list_temp1->next; + OS_Free( list_temp1 ); + list_temp1 = list_temp2; + } + return TRUE; +} + +void PrintDirEntryListForward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd ) +{ + MY_DIR_ENTRY_LIST *list_temp; + // char *log_file_name = "sdmc:/miya/save_dir_entry_log.txt"; + miya_log_fprintf(log_fd, "PrintDirEntryListForward-----Start\n"); + if( head == NULL ) { + } + else { + for( list_temp = head ; list_temp != NULL ; list_temp = list_temp->next ) { + if( list_temp->src_path ) { + miya_log_fprintf(log_fd, "src name = %s\n", list_temp->src_path ); + } + if( list_temp->dst_path ) { + miya_log_fprintf(log_fd, "dst name = %s\n", list_temp->dst_path ); + } + } + } + miya_log_fprintf(log_fd, "PrintDirEntryListForward-----End\n"); +} + +void PrintDirEntryListBackward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd) +{ + MY_DIR_ENTRY_LIST *list_temp; + // MY_DIR_ENTRY_LIST *list_prev; + miya_log_fprintf(log_fd, "PrintDirEntryListBackword-----Start\n"); + if( head == NULL ) { + } + else { + for( list_temp = head ; list_temp->next != NULL ; list_temp = list_temp->next ) { + ; + } + for( ; list_temp != NULL ; list_temp = list_temp->prev ) { + if( list_temp->src_path ) { + miya_log_fprintf(log_fd, "src name = %s\n", list_temp->src_path ); + } + if( list_temp->dst_path ) { + miya_log_fprintf(log_fd, "dst name = %s\n", list_temp->dst_path ); + } + } + } + miya_log_fprintf(log_fd, "PrintDirEntryListBackward-----End\n"); +} + + +static BOOL CheckSystemApp(char path[]) +{ + char c; + int num; + /* + No. 0 0003000f484e4c41 + No. 1 0003000f484e4841 + No. 2 0003000f484e4341 + No. 3 00030015484e4241 + No. 4 00030017484e4141 launcher + ^ + | ここの最下位ビットが1のやつがシステムアプリ + | + システムアプリはダウンロード対象外 + */ + c = path[19]; + if( ('a' <= c) && (c <= 'f') ) { + num = (int)( c - 'a' + 10 ); + } + else if( ('0' <= c) && (c <= '9') ) { + num = (int)( c - '0' ); + } + else { + num = 0; + } + + if( num & 1 ) { + /* System App. */ + return TRUE; + } + else { + /* User App. */ + return FALSE; + } +} + +void GetDirEntryList( MY_DIR_ENTRY_LIST *head, void **pBuffer, int *size) +{ + int i; + int count = 0; + MY_DIR_ENTRY_LIST *list_temp; + char *buf; + + + if( head == NULL ) { + } + else { + for( list_temp = head ; list_temp->next != NULL ; list_temp = list_temp->next ) { + if( list_temp->src_path ) { + if( FALSE == CheckSystemApp( list_temp->src_path) ) { + count++; + } + } + } + if( count ) { + buf = (char *)OS_Alloc( (u32)(count * 16) ); + STD_MemSet((void *)buf, 0, sizeof(count * 16)); + } + else { + buf = NULL; + } + *pBuffer = (void *)buf; + *size = count; + + + count = 0; + for( ; list_temp != NULL ; list_temp = list_temp->prev ) { + if( list_temp->src_path ) { + /* + No. 0 0003000f484e4c41 + No. 1 0003000f484e4841 + No. 2 0003000f484e4341 + No. 3 00030015484e4241 + No. 4 00030017484e4141 launcher + ^ + | ここの最下位ビットが1のやつがシステムアプリ + | + システムアプリはダウンロード対象外 + */ + if( FALSE == CheckSystemApp( list_temp->src_path ) ) { + count++; + /* User App. */ + for( i = 0 ; i < 8 ; i++ ) { + *buf++ = list_temp->src_path[12 + i]; + } + for( i = 0 ; i < 8 ; i++ ) { + *buf++ = list_temp->src_path[21 + i]; + } + } + OS_TPrintf("User App. count = %d\n", count); + /* + nand:/title/00030017/484e4141 は ランチャー + nand:/title/00030015/484e4641 は shop + nand:/title/00030015/484e4241 は 本体設定 + */ + } + } + } +} + + +void PrintSrcDirEntryListBackward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd) +{ + MY_DIR_ENTRY_LIST *list_temp; + // MY_DIR_ENTRY_LIST *list_prev; + miya_log_fprintf(log_fd, "PrintSrcDirEntryListBackword-----Start\n"); + if( head == NULL ) { + } + else { + for( list_temp = head ; list_temp->next != NULL ; list_temp = list_temp->next ) { + ; + } + for( ; list_temp != NULL ; list_temp = list_temp->prev ) { + if( list_temp->src_path ) { + miya_log_fprintf(log_fd, "%s\n", list_temp->src_path ); + /* + nand:/title/00030017/484e4141 は ランチャー + nand:/title/00030015/484e4641 は shop + nand:/title/00030015/484e4241 は 本体設定 + */ + } + } + } + miya_log_fprintf(log_fd, "PrintSrcDirEntryListBackward-----End\n"); +} + + + + + +BOOL SaveDirEntryList( MY_DIR_ENTRY_LIST *head , char *path ) +{ + FSFile f; + FSFile f_src; + FSFile f_dst; + BOOL bSuccess; + FSResult fsResult; + s32 writtenSize; + MY_DIR_ENTRY_LIST *list_temp; + int list_count = 0; + + FSFile log_fd; + BOOL log_active = FALSE; + // char *log_file_name = "sdmc:/miya/save_dir_entry_log.txt"; + char *log_file_name = NULL; + + /* ここでSDカードがあるかどうか調べる */ + + log_active = Log_File_Open( &log_fd, log_file_name ); + + /* 最初にSD側のルートディレクトリのデータを消しとくべきか? + せっかくファイルリストに記録してるのでもったいない→必要ない */ + FS_InitFile(&f); + FS_InitFile(&f_src); + FS_InitFile(&f_dst); + + if( path == NULL ) { + miya_log_fprintf(&log_fd, "%s %d not specify entry save file\n",__FUNCTION__,__LINE__ ); + return FALSE; + } + FS_CreateFileAuto(path, (FS_PERMIT_R|FS_PERMIT_W)); + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_W); + if (bSuccess == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + miya_log_fprintf(&log_fd, "Failed create file - dir entry list file:%d\n", fsResult ); + return FALSE; + } + + fsResult = FS_SetFileLength(&f, 0); + if( fsResult != FS_RESULT_SUCCESS ) { + miya_log_fprintf(&log_fd, "Failed set file len - dir entry list file:%d\n", fsResult ); + } + + /* バックワードでファイルに保存 */ + if( head == NULL ) { + } + else { + for( list_temp = head ; list_temp->next != NULL ; list_temp = list_temp->next ) { + ; + } + for( ; list_temp != NULL ; list_temp = list_temp->prev ) { + // OS_TPrintf( "name = %s\n", list_temp->src_path ); + /* SDにログを残す場合 */ + if( log_active ) { + miya_log_fprintf(&log_fd, "%s\n", list_temp->src_path); + } + + writtenSize = FS_WriteFile(&f, (void *)list_temp, (s32)sizeof(MY_DIR_ENTRY_LIST) ); + if( writtenSize != sizeof(MY_DIR_ENTRY_LIST) ) { + miya_log_fprintf(&log_fd, "%s %d: Failed write file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path); + miya_log_fprintf(&log_fd, " entry count %d\n", list_count ); + } + + /* SD側にディレクトリの作成とファイルのコピー */ + if( (list_temp->content.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { + /* ディレクトリの場合 */ + bSuccess = FS_CreateDirectoryAuto(list_temp->dst_path, FS_PERMIT_RW); + // bSuccess = FS_CreateDirectory(list_temp->dst_path, FS_PERMIT_RW); + if(!bSuccess) { + fsResult = FS_GetArchiveResultCode(list_temp->dst_path); + if( fsResult != FS_RESULT_ALREADY_DONE ) { + miya_log_fprintf(&log_fd, "%s %d: Failed Create DST Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", list_temp->dst_path); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + return FALSE; + } + } + } + else { + /* ファイルの場合 srcがNAND, dstがSD */ + if( !STD_StrCmp( list_temp->src_path, "nand:" ) ) { + /* nandのルートディレクトリはスルーする。 */ + } + else { + /* NANDからSDにコピーする */ + // CopyFile( dst <= src ); + CopyFile(list_temp->dst_path, list_temp->src_path, &log_fd ); + } + } + list_count++; + } + } + + FS_FlushFile(&f); + + if( FS_CloseFile(&f) == FALSE) { + miya_log_fprintf(&log_fd, "%s %d: Failed Close file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path) ) ); + } + miya_log_fprintf(NULL, "write etnry list count %d\n", list_count); + + if( log_active ) { + Log_File_Close(&log_fd); + } + return TRUE; +} + +/******************************************** + * NANDにディレクトリエントリとファイルを復活させる。 +*********************************************/ +BOOL RestoreDirEntryList( char *path ) +{ + FSFile f; + FSFile f_dir; + BOOL bSuccess; + FSResult fsResult; + s32 readSize; + MY_DIR_ENTRY_LIST list_temp; + FSPathInfo path_info; + int list_count = 0; + MY_DIR_ENTRY_LIST *readonly_list_head = NULL; + + FSFile log_fd; + BOOL log_active = FALSE; + char *log_file_name = "sdmc:/miya/restore_dir_entry_log.txt"; + + /* ここでSDカードがあるかどうか調べる */ + + log_active = Log_File_Open( &log_fd, log_file_name ); + + FS_InitFile(&f); + FS_InitFile(&f_dir); + + if( FS_OpenFileEx(&f, path, FS_FILEMODE_R) == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + miya_log_fprintf(&log_fd, "%s %d: Failed Open file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + return FALSE; + } + + while( 1 ) { + /* リストはルートディレクトリに近い順から入っている */ + readSize = FS_ReadFile(&f, (void *)&list_temp, (s32)sizeof(MY_DIR_ENTRY_LIST) ); + if( readSize == 0 ) { + miya_log_fprintf(&log_fd, "Read entry count %d\n", list_count ); + break; + } + else if( readSize != (s32)sizeof(MY_DIR_ENTRY_LIST) ) { + miya_log_fprintf(&log_fd, "%s %d: Failed Read file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path); + miya_log_fprintf(&log_fd, " read entry count %d\n", list_count ); + break; + } + + list_count++; + + /* NAND側にディレクトリの作成とファイルのコピー */ + if( (list_temp.content.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { + /* ディレクトリの場合 */ + if( TRUE == FS_GetPathInfo(list_temp.src_path, &path_info) ) { + /* 復元される側にすでにディレクトリエントリがある場合 */ + if( (path_info.attributes & FS_ATTRIBUTE_IS_DIRECTORY) == 0 ) { + /* ディレクトリでない場合 エラー */ + /* SDにログを残す場合 */ + if( log_active ) { + miya_log_fprintf(&log_fd, "%s %d: NOT a directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path ); + } + /* require backup file */ + /* パニック?? */ + /* それとも一度デリートする?? */ + } + } + else { + /* 復元される側にディレクトリエントリがない場合 */ + bSuccess = FS_CreateDirectory(list_temp.src_path, FS_PERMIT_RW); + if(!bSuccess) { + fsResult = FS_GetArchiveResultCode(list_temp.src_path); + if( fsResult != FS_RESULT_ALREADY_DONE ) { + if( log_active ) { + miya_log_fprintf(&log_fd, "%s %d: Failed Create NAND Directory\n", __FUNCTION__,__LINE__); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path); + } + } + } + if( FALSE == FS_GetPathInfo(list_temp.src_path, &path_info) ) { + if( log_active ) { + miya_log_fprintf(&log_fd, "%s %d: Failed GetPathInfo\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path ); + } + // return FALSE; + } + } + + /* このディレクトリを記憶しておき、あとで属性をまとめて戻す */ + if( FALSE == add_entry_list( &readonly_list_head, &list_temp ) ) { + miya_log_fprintf(&log_fd, "%s %d: ERROR: add_entry_list\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path ); + } + + if( (path_info.attributes & FS_ATTRIBUTE_DOS_READONLY) != 0 ) { + /* リードオンリーの場合,一度リードライト可能にする */ + path_info.attributes &= ~FS_ATTRIBUTE_DOS_READONLY; + if( FALSE == FS_SetPathInfo( list_temp.src_path, &path_info) ) { + fsResult = FS_GetArchiveResultCode(list_temp.src_path); + miya_log_fprintf(&log_fd, "%s %d: Failed SetPathInfo\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path ); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + } + } + } + else { + /* ファイルの場合 srcがSD, dstがNAND */ + if( !STD_StrCmp( list_temp.src_path, "nand:" ) ) { + /* nandのルートディレクトリはスルーする。 */ + } + else { + + /* とりあえずデスティネーションファイルがあるかどうか確認して + あればSDにバックアップする */ + // CopyFile( dst <= src ); + CopyFile( list_temp.src_path, list_temp.dst_path, &log_fd ); + + path_info.attributes = list_temp.content.attributes; + path_info.ctime = list_temp.content.ctime; + path_info.mtime = list_temp.content.mtime; + path_info.atime = list_temp.content.atime; + path_info.id = list_temp.content.id; + path_info.filesize = list_temp.content.filesize; + if( FALSE == FS_SetPathInfo( list_temp.src_path, &path_info) ) { + fsResult = FS_GetArchiveResultCode(list_temp.src_path); + miya_log_fprintf(&log_fd, "%s %d: Failed SetPathInfo\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path ); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + } + } + } + } + + /* add_entry_list( &readonly_list_head, &list_temp ); + でリストにしたエントリーのアトリビュートを逆順で元に戻す。*/ + if( FALSE == restore_entry_list(&readonly_list_head, &log_fd) ) { + miya_log_fprintf(&log_fd, "%s %d: ERROR: restore_entry_list\n", __FUNCTION__,__LINE__ ); + } + + exit_label: + + // FS_FlushFile(&f); //リードだからいらない + if( FS_CloseFile(&f) == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + miya_log_fprintf(&log_fd, "%s %d: Failed Close file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + } + + if( log_active ) { + Log_File_Close(&log_fd); + } + + return TRUE; +} + +// = "nand:/title"; + +static BOOL my_fs_is_Title_Hi_dir_name(const char *name) +{ + char *str; + int i; + str = (char *)name; + if( STD_StrLen(name) != 8 /* 9 ? */) { + return FALSE; + } + + for( i = 0 ; i < 8 ; i++ ) { + if( (( '0' <= *str ) && (* str <= '9')) || + (( 'a' <= *str ) && (* str <= 'f')) || + (( 'A' <= *str ) && (* str <= 'F')) ) { + } + else { + return FALSE; + } + str++; + } + return TRUE; +} + +static BOOL my_fs_is_Title_Lo_dir_name(const char *name) +{ + char *str; + int i; + str = (char *)name; + if( STD_StrLen(name) != 8 /* 9 ? */) { + return FALSE; + } + + for( i = 0 ; i < 8 ; i++ ) { + if( (( '0' <= *str ) && (* str <= '9')) || + (( 'a' <= *str ) && (* str <= 'f')) || + (( 'A' <= *str ) && (* str <= 'F')) ) { + } + else { + return FALSE; + } + str++; + } + return TRUE; +} + +static BOOL Path_Buffers_Init(const char *path_src, const char *path_dst, + char **path_src_dir, char **path_src_full, + char **path_dst_dir, char **path_dst_full, + FSFile *log_fd) +{ + *path_src_dir = (char *)OS_Alloc( FILE_PATH_LEN ); + if( *path_src_dir == NULL ) { + miya_log_fprintf(log_fd, "Error: alloc error src_dir\n"); + return FALSE; + } + *path_src_full = (char *)OS_Alloc( FILE_PATH_LEN ); + if( *path_src_full == NULL ) { + miya_log_fprintf(log_fd, "Error: alloc error src_full\n"); + return FALSE; + } + *path_dst_dir = (char *)OS_Alloc( FILE_PATH_LEN ); + if( *path_dst_dir == NULL ) { + miya_log_fprintf(log_fd, "Error: alloc error dst_dir\n"); + return FALSE; + } + *path_dst_full = (char *)OS_Alloc( FILE_PATH_LEN ); + if( *path_dst_full == NULL ) { + miya_log_fprintf(log_fd, "Error: alloc error dst_full\n"); + return FALSE; + } + + STD_MemSet((void *)*path_src_dir, 0, FILE_PATH_LEN); + STD_MemSet((void *)*path_src_full, 0, FILE_PATH_LEN); + STD_MemSet((void *)*path_dst_dir, 0, FILE_PATH_LEN); + STD_MemSet((void *)*path_dst_full, 0, FILE_PATH_LEN); + + STD_StrCpy(*path_src_dir, path_src); + STD_StrCat(*path_src_dir, "/"); + STD_StrCpy(*path_dst_dir, path_dst); + STD_StrCat(*path_dst_dir, "/"); + + return TRUE; +} + +static void Path_Buffers_Clean( char *path_src_dir, char *path_src_full, + char *path_dst_dir,char *path_dst_full) +{ + if( path_src_dir != NULL ) { + OS_Free(path_src_dir); + } + if( path_src_full != NULL ) { + OS_Free(path_src_full); + } + if( path_dst_dir != NULL ) { + OS_Free(path_dst_dir); + } + if( path_dst_full != NULL ) { + OS_Free(path_dst_full); + } +} + +BOOL MydataLoad(const char *path, void *pBuffer, int size, FSFile *log_fd) +{ + FSFile f; + BOOL bSuccess; + // u32 fileSize; + s32 readSize = 0; + + FS_InitFile(&f); + + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_R); + if( ! bSuccess ) { + miya_log_fprintf(log_fd, "Failed Open File %s\n",__FUNCTION__); + miya_log_fprintf(log_fd, " path=%s\n", path ); + miya_log_fprintf(log_fd, " res=%s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path) )); + return FALSE; + } + readSize = FS_ReadFile(&f, pBuffer, (s32)size); + if( readSize != size ) { + miya_log_fprintf(log_fd, "Failed Read File: %s\n",path); + } + bSuccess = FS_CloseFile(&f); + if( ! bSuccess ) { + miya_log_fprintf(log_fd, "Failed Close File\n"); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path))); + } + + return TRUE; +} + + +BOOL MydataSave(const char *path, void *pData, int size, FSFile *log_fd) +{ +#pragma unused(log_fd) + + FSFile f; + // BOOL flag; + BOOL bSuccess; + FSResult res; + FSResult fsResult; + s32 writtenSize; + + FS_InitFile(&f); + + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_W); + if( ! bSuccess ) { + FS_CreateFileAuto( path, FS_PERMIT_W); + bSuccess = FS_OpenFileEx(&f, path , FS_FILEMODE_W ); + if( ! bSuccess ) { + res = FS_GetArchiveResultCode( path ); + miya_log_fprintf(NULL, "log file open error %s\n", path ); + miya_log_fprintf(NULL, " Failed open file:%s\n", my_fs_util_get_fs_result_word( res )); + return FALSE; + } + } + + fsResult = FS_SetFileLength(&f, 0); + if( fsResult != FS_RESULT_SUCCESS ) { + } + + writtenSize = FS_WriteFile(&f, pData, (s32)size); + if( writtenSize != size ) { + } + + FS_FlushFile(&f); + bSuccess = FS_CloseFile(&f); + if( bSuccess ) { + + } + return TRUE; +} + +/* SDカードがあるかどうか */ +BOOL SDCardValidation(void) +{ + FSFile f; + BOOL flag; + FS_InitFile(&f); + if(FS_OpenDirectory(&f, "sdmc:/", FS_PERMIT_R) == FALSE ) { + flag = FALSE; + } + else { + flag = TRUE; + } + (void)FS_CloseDirectory(&f); + return flag; +} + + +/* 過去にショップに接続したかどうか */ +BOOL CheckShopRecord(FSFile *log_fd) +{ +#pragma unused(log_fd) + + FSFile f; + BOOL bSuccess; + char path[256]; + + FS_InitFile(&f); + + STD_StrCpy(path, "nand:/sys/dev.kp"); + bSuccess = FS_OpenFileEx(&f, path, (FS_FILEMODE_R)); + if( ! bSuccess ) { + if( FS_RESULT_NO_ENTRY == FS_GetArchiveResultCode(path) ) { + } + return FALSE; + } + (void)FS_CloseFile(&f); + +#if 0 + STD_StrCpy(path, "nand:/sys/log/shop.log"); + bSuccess = FS_OpenFileEx(&f, path, (FS_FILEMODE_R)); + if( ! bSuccess ) { + if( FS_RESULT_NO_ENTRY == FS_GetArchiveResultCode(path) ) { + } + return FALSE; + } + (void)FS_CloseFile(&f); +#endif + + // STD_StrCpy(path, "nand:/title/00030015/484e4641/data/ec.cfg"); /* ショップアカウント情報 */ + STD_StrCpy(path, "nand:/title/00030015/484e464a/data/ec.cfg"); /* ショップアカウント情報 */ + bSuccess = FS_OpenFileEx(&f, path, (FS_FILEMODE_R)); + if( ! bSuccess ) { + if( FS_RESULT_NO_ENTRY == FS_GetArchiveResultCode(path) ) { + } + return FALSE; + } + (void)FS_CloseFile(&f); + + + return TRUE; + +} + + +int get_title_id(MY_DIR_ENTRY_LIST **headp, const char *path_src, int *save_parent_dir_info_flag, char *log_file_name ) +{ + static int recursive_count = 0; + static FSFile log_fd; + static BOOL log_active = FALSE; + // static char *log_file_name = "sdmc:/miya/nandinfo_find_title_save_data.txt"; + + FSFile f_src; + FSDirectoryEntryInfo entry_src; + FSDirectoryEntryInfo entry_current_dir; + int ret_value = 0; + // FSResult fs_ret_value; + int save_parent_dir_info_flag_temp = 0; + + char *path_src_dir = NULL; + char *path_src_full = NULL; + + /* ここでSDカードがあるかどうか調べる */ + + if( recursive_count == 0 ) { + log_active = Log_File_Open( &log_fd, log_file_name ); + } + + recursive_count++; + + // recursive_count 1 2 3 4 + // nand:/title + // nand:/title/00000000/00000000/data/*.sav + if( recursive_count > 4 ) { + ret_value = 0; + goto end_process; + } + + /* ソースディレクトリオープン */ + FS_InitFile(&f_src); + + if(FS_OpenDirectory(&f_src, path_src, FS_PERMIT_R) == FALSE ) { + if( log_active ) { + miya_log_fprintf(&log_fd, "%s %d: Failed Open Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path_src); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src) ) ); + } + ret_value = -1; + goto end_process; + } + + /* ファイル名バッファ初期化 */ + path_src_dir = (char *)OS_Alloc( FILE_PATH_LEN ); + if( path_src_dir == NULL ) { + miya_log_fprintf(&log_fd, "Error: alloc error src_dir\n"); + ret_value = -1; + goto end_process; + } + path_src_full = (char *)OS_Alloc( FILE_PATH_LEN ); + if( path_src_full == NULL ) { + miya_log_fprintf(&log_fd, "Error: alloc error src_full\n"); + ret_value = -1; + goto end_process; + } + STD_MemSet((void *)path_src_dir, 0, FILE_PATH_LEN); + STD_MemSet((void *)path_src_full, 0, FILE_PATH_LEN); + STD_StrCpy(path_src_dir, path_src); + STD_StrCat(path_src_dir, "/"); + + while( FS_ReadDirectory(&f_src, &entry_src) ) { + + if( STD_StrCmp(entry_src.longname, ".") == 0 ) { + /* とりあえずカレントディレクトリエントリを残しておく */ + STD_CopyMemory( (void *)&entry_current_dir, (void *)&entry_src ,sizeof(FSDirectoryEntryInfo) ); + } + else if( STD_StrCmp(entry_src.longname, "..") == 0 ) { + } + else { + STD_StrCpy( path_src_full , path_src_dir ); + STD_StrCat( path_src_full , entry_src.longname ); + + /* SDにログを残す場合 */ + if( log_active ) { + // OS_TPrintf("path = %s len=%d att=0x%08x\n",path_src_full,entry_src.filesize, entry_src.attributes); + PrintAttributes(entry_src.attributes, &log_fd); + miya_log_fprintf(&log_fd, " %8d %s\n", entry_src.filesize, path_src_full ); + } + + if( (entry_src.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { + /* ディレクトリの場合 */ + // recursive_count 1 2 3 4 + // nand:/title + // nand:/title/00000000/00000000/data/*.sav + if( recursive_count == 1 ) { + if( my_fs_is_Title_Hi_dir_name( entry_src.longname ) == TRUE ) { + get_title_id( headp, path_src_full , &save_parent_dir_info_flag_temp, log_file_name ); + } + } + if( recursive_count == 2 ) { + if( my_fs_is_Title_Lo_dir_name( entry_src.longname ) == TRUE ) { + get_title_id( headp, path_src_full , &save_parent_dir_info_flag_temp, log_file_name ); + } + } + else if( (recursive_count == 3) ) { + if( !STD_StrCmp( entry_src.longname, "content" ) ) { + get_title_id( headp, path_src_full , &save_parent_dir_info_flag_temp, log_file_name ); + } + } + } + else { + // recursive_count 1 2 3 4 + // nand:/title + // nand:/title/00000000/00000000/content/title.tmd + if( (recursive_count == 4) ) { + if( !STD_StrCmp( entry_src.longname, "title.tmd" ) ) { + /* 目的のファイルを見つけた。 */ +#if 0 + my_fs_add_list(headp, &entry_src, path_src_full, NULL, &log_fd); +#endif + save_parent_dir_info_flag_temp = 1; + } + } + } + } + } + + if( save_parent_dir_info_flag_temp == 1 ) { + // OS_TPrintf("save dir info = %s\n\n",path_src); + if( recursive_count == 3 ) { + my_fs_add_list( headp, &entry_current_dir, path_src, NULL, &log_fd); + } + else { + /* contentディレクトリなど */ + + } + *save_parent_dir_info_flag = 1; + } + + /* ソースディレクトリクローズ */ + if( FS_CloseDirectory(&f_src) == FALSE) { + miya_log_fprintf(&log_fd, "%s %d: Failed Close Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path_src); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src))); + ret_value = -1; + } + + end_process: + if( path_src_dir != NULL ) { + OS_Free(path_src_dir); + } + if( path_src_full != NULL ) { + OS_Free(path_src_full); + } + + recursive_count--; + + if( recursive_count == 0 ) { + if( log_active ) { + Log_File_Close(&log_fd); + } + } + + return ret_value; +} + + + +int find_title_save_data(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_src, int *save_parent_dir_info_flag, char *log_file_name ) +{ + static int recursive_count = 0; + static FSFile log_fd; + static BOOL log_active = FALSE; + // static char *log_file_name = "sdmc:/miya/nandinfo_find_title_save_data.txt"; + + FSFile f_src; + FSDirectoryEntryInfo entry_src; + FSDirectoryEntryInfo entry_current_dir; + int ret_value = 0; + // FSResult fs_ret_value; + int save_parent_dir_info_flag_temp = 0; + + char *path_src_dir = NULL; + char *path_src_full = NULL; + char *path_dst_dir = NULL; + char *path_dst_full = NULL; + + /* ここでSDカードがあるかどうか調べる */ + + if( recursive_count == 0 ) { + log_active = Log_File_Open( &log_fd, log_file_name ); + } + + recursive_count++; + + // recursive_count 1 2 3 4 + // nand:/title + // nand:/title/00000000/00000000/data/*.sav + if( recursive_count > 4 ) { + ret_value = 0; + goto end_process; + } + + /* ソースディレクトリオープン */ + FS_InitFile(&f_src); + + if(FS_OpenDirectory(&f_src, path_src, FS_PERMIT_R) == FALSE ) { + if( log_active ) { + miya_log_fprintf(&log_fd, "%s %d: Failed Open Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path_src); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src) ) ); + } + ret_value = -1; + goto end_process; + } + + /* ファイル名バッファ初期化 */ + if( FALSE == Path_Buffers_Init(path_src, path_dst, + &path_src_dir, &path_src_full, &path_dst_dir, &path_dst_full, &log_fd ) ) + { + ret_value = -1; + goto end_process; + } + + while( FS_ReadDirectory(&f_src, &entry_src) ) { + + if( STD_StrCmp(entry_src.longname, ".") == 0 ) { + /* とりあえずカレントディレクトリエントリを残しておく */ + STD_CopyMemory( (void *)&entry_current_dir, (void *)&entry_src ,sizeof(FSDirectoryEntryInfo) ); + } + else if( STD_StrCmp(entry_src.longname, "..") == 0 ) { + } + else { + STD_StrCpy( path_src_full , path_src_dir ); + STD_StrCat( path_src_full , entry_src.longname ); + STD_StrCpy( path_dst_full , path_dst_dir ); + STD_StrCat( path_dst_full , entry_src.longname ); + + /* SDにログを残す場合 */ + if( log_active ) { + // OS_TPrintf("path = %s len=%d att=0x%08x\n",path_src_full,entry_src.filesize, entry_src.attributes); + PrintAttributes(entry_src.attributes, &log_fd); + miya_log_fprintf(&log_fd, " %8d %s\n", entry_src.filesize, path_src_full ); + } + + if( (entry_src.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { + /* ディレクトリの場合 */ + // recursive_count 1 2 3 4 + // nand:/title + // nand:/title/00000000/00000000/data/*.sav + if( recursive_count == 1 ) { + if( my_fs_is_Title_Hi_dir_name( entry_src.longname ) == TRUE ) { + find_title_save_data( headp, path_dst_full, path_src_full , &save_parent_dir_info_flag_temp, log_file_name ); + } + } + if( recursive_count == 2 ) { + if( my_fs_is_Title_Lo_dir_name( entry_src.longname ) == TRUE ) { + find_title_save_data( headp, path_dst_full, path_src_full , &save_parent_dir_info_flag_temp, log_file_name ); + } + } + else if( (recursive_count == 3) ) { + if( !STD_StrCmp( entry_src.longname, "data" ) ) { + find_title_save_data( headp, path_dst_full, path_src_full , &save_parent_dir_info_flag_temp, log_file_name ); + } + } + } + else { + // recursive_count 1 2 3 4 + // nand:/title + // nand:/title/00000000/00000000/data/*.sav + if( (recursive_count == 4) ) { + if( !STD_StrCmp( entry_src.longname, "public.sav" ) ) { + /* 目的のファイルを見つけた。 */ + my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, &log_fd); + save_parent_dir_info_flag_temp = 1; + } + else if( !STD_StrCmp( entry_src.longname, "private.sav" ) ) { + my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, &log_fd); + save_parent_dir_info_flag_temp = 1; + } +#if 1 + /* いるのか? */ + else if( !STD_StrCmp( entry_src.longname, "banner.sav" ) ) { + my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, &log_fd); + save_parent_dir_info_flag_temp = 1; + } +#endif + } + } + } + } + + if( save_parent_dir_info_flag_temp == 1 ) { + // OS_TPrintf("save dir info = %s\n\n",path_src); + my_fs_add_list( headp, &entry_current_dir, path_src, path_dst, &log_fd); + *save_parent_dir_info_flag = 1; + } + + /* ソースディレクトリクローズ */ + if( FS_CloseDirectory(&f_src) == FALSE) { + miya_log_fprintf(&log_fd, "%s %d: Failed Close Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path_src); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src))); + ret_value = -1; + } + + end_process: + + Path_Buffers_Clean( path_src_dir, path_src_full, path_dst_dir, path_dst_full ); + + recursive_count--; + + if( recursive_count == 0 ) { + if( log_active ) { + Log_File_Close(&log_fd); + } + } + + return ret_value; +} + + +int find_copy(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_src, + char *extension, int max_recursive_count, int *save_parent_dir_info_flag, char *log_file_name ) +{ + static int recursive_count = 0; + static FSFile log_fd; + static BOOL log_active = FALSE; + // static char *log_file_name = "sdmc:/miya/nandinfo_find_copy.txt"; + + FSFile f_src; + FSDirectoryEntryInfo entry_src; + FSDirectoryEntryInfo entry_current_dir; + int ret_value = 0; + // FSResult fs_ret_value; + int save_parent_dir_info_flag_temp = 0; + + char *path_src_dir = NULL; + char *path_src_full = NULL; + char *path_dst_dir = NULL; + char *path_dst_full = NULL; + + /* ここでSDカードがあるかどうか調べる */ + + if( recursive_count == 0 ) { + log_active = Log_File_Open( &log_fd, log_file_name ); + } + + if( recursive_count > max_recursive_count ) { + ret_value = 0; + goto end_process; + } + + recursive_count++; + + /* ソースディレクトリオープン */ + FS_InitFile(&f_src); + + if( FS_OpenDirectory(&f_src, path_src, FS_PERMIT_R) == FALSE ) { + miya_log_fprintf(&log_fd, "%s %d: Failed Open Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path_src); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src) ) ); + ret_value = -1; + goto end_process; + } + + /* ファイル名バッファ初期化 */ + if( FALSE == Path_Buffers_Init(path_src, path_dst, + &path_src_dir, &path_src_full, &path_dst_dir, &path_dst_full, &log_fd ) ) + { + ret_value = -1; + goto end_process; + } + + while( FS_ReadDirectory(&f_src, &entry_src) ) { + + if( STD_StrCmp(entry_src.longname, ".") == 0 ) { + /* とりあえずカレントディレクトリエントリを残しておく */ + STD_CopyMemory( (void *)&entry_current_dir, (void *)&entry_src ,sizeof(FSDirectoryEntryInfo) ); + } + else if( STD_StrCmp(entry_src.longname, "..") == 0 ) { + } + else { + STD_StrCpy( path_src_full , path_src_dir ); + STD_StrCat( path_src_full , entry_src.longname ); + STD_StrCpy( path_dst_full , path_dst_dir ); + STD_StrCat( path_dst_full , entry_src.longname ); + + /* SDにログを残す場合 */ + if( log_active ) { + PrintAttributes(entry_src.attributes, &log_fd); + miya_log_fprintf(&log_fd, " %8d %s\n", entry_src.filesize, path_src_full ); + } + + if( (entry_src.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { + find_copy( headp, path_dst_full, path_src_full , extension, max_recursive_count, &save_parent_dir_info_flag_temp , log_file_name); + } + else { + /* ここで拡張子比較 */ + { + int len; + int extension_len = STD_StrLen( extension ); + len = STD_StrLen( path_src_full ); + + if( len > (extension_len - 1) ) { + // 123456789012345678901234567890123456789012345678901234567890123 + // ../backup_sample/ARM7.TWL/bin/ARM7-TS.HYB/Release/ltdmain.c.cpp + if( !STD_StrNCmp( &(path_src_full[len - (extension_len )]), extension , extension_len+1 ) ) { + /* 目的のファイルを見つけた。 */ + // OS_TPrintf("%s len=%d att=0x%08x\n", path_src_full, entry_src.filesize, entry_src.attributes); + // OS_TPrintf("%s\n", path_dst_full ); + + my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, &log_fd); + + save_parent_dir_info_flag_temp = 1; + } + } + } + } + } + } + + if( save_parent_dir_info_flag_temp == 1 ) { + // OS_TPrintf("save dir info = %s\n\n",path_src); + my_fs_add_list( headp, &entry_current_dir, path_src, path_dst, &log_fd ); + *save_parent_dir_info_flag = 1; + } + + /* ソースディレクトリクローズ */ + if( FS_CloseDirectory(&f_src) == FALSE) { + miya_log_fprintf(&log_fd, "%s %d: Failed Close Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path_src); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src))); + ret_value = -1; + } + + end_process: + + Path_Buffers_Clean( path_src_dir, path_src_full, path_dst_dir, path_dst_full ); + + recursive_count--; + if( recursive_count == 0 ) { + if( log_active ) { + Log_File_Close(&log_fd); + } + } + + return ret_value; +} + + +int copy_r( MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_src, char *log_file_name ) +{ + static int recursive_count = 0; + static FSFile log_fd; + static BOOL log_active = FALSE; + // static char *log_file_name = "sdmc:/nandinfo_copy_r.txt"; + + FSFile f_src; + FSDirectoryEntryInfo entry_src; + FSDirectoryEntryInfo entry_current_dir; + int ret_value = 0; + + char *path_src_dir = NULL; + char *path_src_full = NULL; + char *path_dst_dir = NULL; + char *path_dst_full = NULL; + + /* ここでSDカードがあるかどうか調べる */ + if( recursive_count == 0 ) { + log_active = Log_File_Open( &log_fd, log_file_name ); + } + + recursive_count++; + + /* ソースディレクトリオープン */ + FS_InitFile(&f_src); + + if( FS_OpenDirectory(&f_src, path_src, FS_PERMIT_R) == FALSE ) { + if( log_active ) { + miya_log_fprintf(&log_fd, "%s %d: Failed Open Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path_src); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src) ) ); + } + + ret_value = -1; + goto end_process; + } + + /* ファイル名バッファ初期化 */ + if( FALSE == Path_Buffers_Init(path_src, path_dst, + &path_src_dir, &path_src_full, &path_dst_dir, &path_dst_full, &log_fd ) ) + { + ret_value = -1; + goto end_process; + } + + while( FS_ReadDirectory(&f_src, &entry_src) ) { + + if( STD_StrCmp(entry_src.longname, ".") == 0 ) { + /* とりあえずカレントディレクトリエントリを残しておく */ + STD_CopyMemory( (void *)&entry_current_dir, (void *)&entry_src ,sizeof(FSDirectoryEntryInfo) ); + } + else if( STD_StrCmp(entry_src.longname, "..") == 0 ) { + + } + else { + STD_StrCpy( path_src_full , path_src_dir ); + STD_StrCat( path_src_full , entry_src.longname ); + STD_StrCpy( path_dst_full , path_dst_dir ); + STD_StrCat( path_dst_full , entry_src.longname ); + /* SDにログを残す場合 */ + if( log_active ) { + miya_log_fprintf(&log_fd, "path = %s len=%d\n",path_src_full,entry_src.filesize); + } + + if( (entry_src.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { + copy_r( headp, path_dst_full, path_src_full, log_file_name ); + } + else { + my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, &log_fd); + } + } + } + + /* ディレクトリエントリをセーブ */ + + my_fs_add_list( headp, &entry_current_dir, path_src, path_dst, &log_fd ); + + /* ディレクトリクローズ */ + if( FS_CloseDirectory(&f_src) == FALSE) { + if( log_active ) { + miya_log_fprintf(&log_fd, "%s %d: Failed Close Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(&log_fd, " %s\n", path_src); + miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src))); + } + ret_value = -1; + } + + end_process: + + Path_Buffers_Clean( path_src_dir, path_src_full, path_dst_dir, path_dst_full ); + + recursive_count--; + if( recursive_count == 0 ) { + if( log_active ) { + Log_File_Close(&log_fd); + } + } + + return ret_value; +} + +void write_debug_data(void) +{ + // CopyFile( dst <= src ); + CopyFile("nand:/tmp/m00.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m01.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m02.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m03.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m04.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m05.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m06.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m07.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m08.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m09.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m10.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m11.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m12.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m13.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m14.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m15.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m16.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m17.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m18.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m19.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m20.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m22.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m23.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m24.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m25.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m26.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m27.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m28.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m29.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m30.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m31.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m32.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m33.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/tmp/m34.sav" , "nand:/sys/log/sysmenu.log", NULL); + CopyFile("nand:/sys/miya.log", "sdmc:/miya.log", NULL); + CopyFile("nand:/shared1/miya.log", "sdmc:/miya.log", NULL); + + + + /* + PrintDirEntryListBackword-----Start + src name = nand:/title + dst name = sdmc:/miya_find_title_save + src name = nand:/title/0003000f + dst name = sdmc:/miya_find_title_save/0003000f + src name = nand:/title/0003000f/484e4341 + dst name = sdmc:/miya_find_title_save/0003000f/484e4341 + src name = nand:/title/0003000f/484e4341/data + dst name = sdmc:/miya_find_title_save/0003000f/484e4341/data +-- src name = nand:/title/0003000f/484e4341/data/private.sav + dst name = sdmc:/miya_find_title_save/0003000f/484e4341/data/private.sav + src name = nand:/title/00030017 + dst name = sdmc:/miya_find_title_save/00030017 + src name = nand:/title/00030017/484e4141 + dst name = sdmc:/miya_find_title_save/00030017/484e4141 + src name = nand:/title/00030017/484e4141/data + dst name = sdmc:/miya_find_title_save/00030017/484e4141/data +-- src name = nand:/title/00030017/484e4141/data/public.sav + dst name = sdmc:/miya_find_title_save/00030017/484e4141/data/public.sav + PrintDirEntryListBackward-----End + */ + +#if 0 + +nand:/title/0003000f +nand:/title/0003000f/484e4341 +nand:/title/0003000f/484e4341/content +nand:/title/0003000f/484e4841 +nand:/title/0003000f/484e4841/data +nand:/title/0003000f/484e4841/content +nand:/title/0003000f/484e4c41 +nand:/title/0003000f/484e4c41/data + +nand:/title/00030015 +nand:/title/00030015/484e4241 +nand:/title/00030015/484e4241/data +nand:/title/00030015/484e4241/content + CopyFile("nand:/title/00030017/ + CopyFile("nand:/ticket/public.sav" , "nand:/sys/log/sysmenu.log"); + CopyFile("nand:/ticket/00030015 + CopyFile("nand:/ticket/00030015/miya.sav" , "nand:/sys/log/sysmenu.log"); +#endif +} + diff --git a/build/tools/sctools/common/src/my_fs_util.h b/build/tools/sctools/common/src/my_fs_util.h new file mode 100644 index 0000000..0b1e45a --- /dev/null +++ b/build/tools/sctools/common/src/my_fs_util.h @@ -0,0 +1,48 @@ +#ifndef _MY_FS_UTIL_H_ +#define _MY_FS_UTIL_H_ + +#define FILE_PATH_LEN 512 + +typedef struct _MY_DIR_ENTRY_LIST { + struct _MY_DIR_ENTRY_LIST *prev; + struct _MY_DIR_ENTRY_LIST *next; + FSDirectoryEntryInfo content; + char src_path[ FILE_PATH_LEN ]; + char dst_path[ FILE_PATH_LEN ]; +} MY_DIR_ENTRY_LIST; + + +#ifdef __cplusplus +extern "C" { +#endif + +char *my_fs_util_get_fs_result_word( FSResult res ); + +int find_title_save_data(MY_DIR_ENTRY_LIST **headp, const char *path_dst, + const char *path_src, int *save_dir_info, char *log_file_name ); +int find_copy( MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_src, + char *extension, int level, int *save_info, char *log_file_name ); +int copy_r( MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_src, char *log_file_name ); +int get_title_id(MY_DIR_ENTRY_LIST **headp, const char *path_src, + int *save_parent_dir_info_flag, char *log_file_name ); + +void PrintDirEntryListForward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd ); +void PrintDirEntryListBackward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd ); +void PrintSrcDirEntryListBackward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd); + +BOOL SaveDirEntryList( MY_DIR_ENTRY_LIST *head , char *path ); +BOOL RestoreDirEntryList( char *path ); +BOOL ClearDirEntryList( MY_DIR_ENTRY_LIST **headp ); +void write_debug_data(void); +BOOL SDCardValidation(void); +BOOL CheckShopRecord(FSFile *log_fd); +BOOL MydataSave(const char *path, void *pData, int size, FSFile *log_fd); +BOOL MydataLoad(const char *path, void *pBuffer, int size, FSFile *log_fd); +void GetDirEntryList( MY_DIR_ENTRY_LIST *head, void **pBuffer, int *size); + +#ifdef __cplusplus +} +#endif + + +#endif /* _MY_FS_UTIL_H_ */ diff --git a/build/tools/sctools/common/src/mynvram.c b/build/tools/sctools/common/src/mynvram.c new file mode 100644 index 0000000..fd02c79 --- /dev/null +++ b/build/tools/sctools/common/src/mynvram.c @@ -0,0 +1,246 @@ + +#include +#include + +#include "font.h" +#include "text.h" +#include "mprintf.h" +#include "mynvram.h" + + +#define NVRAM_PERSONAL_DATA_OFFSET 0x20 + +/* Wifi設定だけなら0x0A00 */ +//#define NVRAM_PERSONAL_DATA_SIZE 0x0C00 +#define NVRAM_PERSONAL_DATA_SIZE 0x0A00 + + +#define NVRAM_INTERNAL_BUF_SIZE 0x100 +static u8 nvram_buffer[NVRAM_INTERNAL_BUF_SIZE] ATTRIBUTE_ALIGN(32); + +static BOOL my_nvram_read( u32 offset, u32 size, void *buf) +{ + u32 internal_size = size; + u32 internal_offset = offset; + void *temp_buf = buf; + u32 temp_size; + int i; + + while( internal_size ) { + if( internal_size > NVRAM_INTERNAL_BUF_SIZE ) { + temp_size = NVRAM_INTERNAL_BUF_SIZE; + } + else { + temp_size = internal_size; + } + + DC_InvalidateRange(nvram_buffer, NVRAM_INTERNAL_BUF_SIZE); + if( NVRAM_RESULT_SUCCESS != NVRAMi_Read( internal_offset , temp_size, (void* )nvram_buffer) ) { + mprintf("nvram read error\n"); + OS_TPrintf( "nvram error: %s %s %d\n",__FILE__,__FUNCTION__,__LINE__); + return FALSE; + } + for( i = 0 ; i < temp_size ; i++ ) { + *(u8 *)temp_buf = nvram_buffer[i]; + ((u8 *)temp_buf)++; + } + + internal_offset += temp_size; + internal_size -= temp_size; + } + // OS_TPrintf( "nvram success: offset = 0x%02x\n", offset); + return TRUE; +} + +static BOOL my_nvram_write( u32 offset, u32 size, void *buf) +{ + u32 internal_size = size; + u32 internal_offset = offset; + void *temp_buf = buf; + u32 temp_size; + int i; + + while( internal_size ) { + + if( internal_size > NVRAM_INTERNAL_BUF_SIZE ) { + temp_size = NVRAM_INTERNAL_BUF_SIZE; + } + else { + temp_size = internal_size; + } + + for( i = 0 ; i < temp_size ; i++ ) { + nvram_buffer[i] = *(u8 *)temp_buf; + ((u8 *)temp_buf)++; + } + + DC_FlushRange(nvram_buffer, NVRAM_INTERNAL_BUF_SIZE); + if( NVRAM_RESULT_SUCCESS != NVRAMi_Write( internal_offset , temp_size, (void* )nvram_buffer) ) { + OS_TPrintf( "nvram write error: %s %s %d\n",__FILE__,__FUNCTION__,__LINE__); + return FALSE; + } + + internal_offset += temp_size; + internal_size -= temp_size; + } + // OS_TPrintf( "nvram success: offset = 0x%02x\n", offset); + return TRUE; +} + + +/* *INDENT-OFF* */ +static const char * const fs_result_strings[] = +{ + "FS_RESULT_SUCCESS", + "FS_RESULT_FAILURE", + "FS_RESULT_BUSY", + "FS_RESULT_CANCELED", + "FS_RESULT_UNSUPPORTED", + "FS_RESULT_ERROR", + "FS_RESULT_INVALID_PARAMETER", + "FS_RESULT_NO_MORE_RESOUCE", + "FS_RESULT_ALREADY_DONE", + "FS_RESULT_PERMISSION_DENIED", + "FS_RESULT_MEDIA_FATAL", +}; +static const size_t fs_result_string_max = sizeof(fs_result_strings) / sizeof(*fs_result_strings); + +static void ReportLastErrorPath(const char *path) +{ + FSResult result = FS_GetArchiveResultCode(path); + + SDK_ASSERT((result >= 0) && (result < fs_result_string_max)); + mprintf("FS error:\n \"%s\"\n %s\n", + path, fs_result_strings[result]); +} + +BOOL nvram_backup(char *path) +{ + BOOL bSuccess; + FSFile nor_fd; + u16 offset; + u32 vol; + int len; + char nor_file_path[FS_FILE_NAME_MAX]; +#define BUF_SIZE 0x100 + u8 nor_buf[BUF_SIZE]; + + + FS_InitFile(&nor_fd); + // STD_TSNPrintf(nor_file_path, sizeof(nor_file_path), "sdmc:/twl_nor.bin"); + STD_TSNPrintf(nor_file_path, sizeof(nor_file_path), path ); + bSuccess = FS_OpenFileEx(&nor_fd, nor_file_path, (FS_FILEMODE_R|FS_FILEMODE_W)); + if( ! bSuccess ) + { + if( !FS_CreateFile(nor_file_path, FS_PERMIT_R | FS_PERMIT_W)) { + ReportLastErrorPath(nor_file_path); + OS_TWarning("2 FS_CreateFile(%s) failed.", nor_file_path); + return FALSE; + } + bSuccess = FS_OpenFileEx(&nor_fd, nor_file_path, (FS_FILEMODE_R|FS_FILEMODE_W)); + if( ! bSuccess ) { + OS_TPrintf("error %s %s %d\n",__FILE__,__FUNCTION__,__LINE__); + return FALSE; + } + } + + if( TRUE != my_nvram_read( NVRAM_PERSONAL_DATA_OFFSET , sizeof(u16), (void* )&offset) ) { + OS_TPrintf( "nvram error: %s %s %d\n",__FILE__,__FUNCTION__,__LINE__); + } + else { + OS_TPrintf( "nvram success: offset = 0x%02x\n", offset); + } + + if( offset == 0 ) { + OS_TPrintf( "nvram error: offset = 0x%02x\n", offset); + return FALSE; + } + + offset *= 8; + offset -= 0xA00; + + for( vol = 0 ; vol < NVRAM_PERSONAL_DATA_SIZE ; vol += BUF_SIZE ) { + OS_TPrintf("."); + if( TRUE != my_nvram_read( offset+vol , BUF_SIZE, (void* )nor_buf) ) { + OS_TPrintf( "nvram error: %s %s %d\n",__FILE__,__FUNCTION__,__LINE__); + } + else { + len = FS_WriteFile(&nor_fd, nor_buf, BUF_SIZE); + if (len != BUF_SIZE) + { + OS_TWarning("FS_WriteFile() failed."); + break; + } + } + } + OS_TPrintf("\n"); + + FS_FlushFile(&nor_fd); + + bSuccess = FS_CloseFile(&nor_fd); + + // OS_TPrintf( "nvram read completed.\n"); + return TRUE; +} + +BOOL nvram_restore(char *path) +{ + BOOL bSuccess; + FSFile nor_fd; + u16 offset; + u32 vol; + int len; + char nor_file_path[FS_FILE_NAME_MAX]; +#define BUF_SIZE 0x100 + u8 nor_buf[BUF_SIZE]; + + FS_InitFile(&nor_fd); + STD_TSNPrintf(nor_file_path, sizeof(nor_file_path), path ); + bSuccess = FS_OpenFileEx(&nor_fd, nor_file_path, FS_FILEMODE_R); + if( ! bSuccess ) { + OS_TPrintf("error %s %s %d\n",__FILE__,__FUNCTION__,__LINE__); + return FALSE; + } + + /* offsetアドレスの取得 */ + if( TRUE != my_nvram_read( NVRAM_PERSONAL_DATA_OFFSET , sizeof(u16), (void* )&offset) ) { + OS_TPrintf( "nvram error: %s %s %d\n",__FILE__,__FUNCTION__,__LINE__); + } + else { + OS_TPrintf( "nvram success: offset = 0x%02x\n", offset); + } + + if( offset == 0 ) { + OS_TPrintf( "nvram error: offset = 0x%02x\n", offset); + return FALSE; + } + + offset *= 8; + offset -= 0xA00; + + for( vol = 0 ; vol < NVRAM_PERSONAL_DATA_SIZE ; vol += BUF_SIZE ) { + OS_TPrintf("."); + + len = FS_ReadFile(&nor_fd, nor_buf, BUF_SIZE); + if (len != BUF_SIZE) { + OS_TWarning("FS_ReadFile() failed."); + break; + } + + if( TRUE != my_nvram_write( offset+vol , BUF_SIZE, (void* )nor_buf) ) { + OS_TPrintf( "nvram write error: %s %s %d\n",__FILE__,__FUNCTION__,__LINE__); + } + else { + } + } + + OS_TPrintf("\n"); + bSuccess = FS_CloseFile(&nor_fd); + + mprintf("nvram write completed.\n"); + OS_TPrintf( "nvram write completed.\n"); + + return TRUE; +} + + diff --git a/build/tools/sctools/common/src/mynvram.h b/build/tools/sctools/common/src/mynvram.h new file mode 100644 index 0000000..514c0ae --- /dev/null +++ b/build/tools/sctools/common/src/mynvram.h @@ -0,0 +1,16 @@ +#ifndef _MY_NVRAM_H_ +#define _MY_NVRAM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// BOOL my_nvram_read( u32 offset, u32 size, void *buf); +BOOL nvram_backup(char *path); +BOOL nvram_restore(char *path); + +#ifdef __cplusplus +} +#endif + +#endif /* _MY_NVRAM_H_ */ diff --git a/build/tools/sctools/common/src/mywlan.c b/build/tools/sctools/common/src/mywlan.c new file mode 100644 index 0000000..0b0f3fd --- /dev/null +++ b/build/tools/sctools/common/src/mywlan.c @@ -0,0 +1,311 @@ +#include +#include + +#include "text.h" +#include "mprintf.h" +#include "logprintf.h" + +#include "mywlan.h" + +static char SSID_STR[256]; +static int SSID_LEN = 0; +static char KEY_STR[256]; +static u8 KEY_BIN[256]; +static int KEY_STR_LEN = 0; +static int KEY_BIN_LEN = 0; +static int MODE = 0; + +char *GetWlanSSID(void) +{ + return SSID_STR; +} + +char *GetWlanKEYSTR(void) +{ + return KEY_STR; +} + +int GetWlanKEYBIN(u8 *buf) +{ + if( KEY_BIN_LEN ) { + STD_CopyMemory((void *)buf, (void *)KEY_BIN, (unsigned long)KEY_BIN_LEN); + } + return KEY_BIN_LEN; +} + +int GetWlanMode(void) +{ + return MODE; +} + +/* +SSID:"001D731A8202" +MODE:"WEP128" +;MODE:"OPEN" +;MODE:"WPA-TKIP" +;MODE:"WPA2-TKIP" +;MODE:"WPA-AES" +;MODE:"WPA2-AES" +KEY-STR:"0123456789red" +KEY-BIN:"0123456789red" +*/ + +static int ReadLine(FSFile *f, char *buf, int buf_size) +{ + char c; + s32 readSize; + int count = 0; + while( 1 ) { + readSize = FS_ReadFile(f, (void *)&c, (s32)1 ); + if( readSize == 0 ) { + /* EOF */ + break; + } + count++; + if( c == '\r' ) { + *buf = '\0'; + break; + } + else if(c == '\n' ) { + *buf = '\0'; + break; + } + + *buf = c; + buf++; + + if( count > buf_size ) { + break; + } + } + return count; +} + + +BOOL LoadWlanConfigFile(char *path) +{ + FSFile f; + FSResult res; + s32 readSize; + BOOL bSuccess; + int count = 0; + int count2; + int count3; + BOOL ssid_flag; + BOOL key_str_flag; + BOOL key_bin_flag; + BOOL mode_flag; + BOOL ret_flag = FALSE; + int lo_hi; + u8 hex; + char c; + +#define LINE_BUF_SIZE 256 + char line_buf[LINE_BUF_SIZE]; + + FS_InitFile(&f); + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_R); + if (bSuccess == FALSE) { + res = FS_GetArchiveResultCode(path); + return FALSE; + } + + + ssid_flag = FALSE; + key_str_flag = FALSE; + key_bin_flag = FALSE; + mode_flag = FALSE; + + + while( 1 ) { + readSize = ReadLine(&f, line_buf, LINE_BUF_SIZE ); + if( readSize == 0 ) { + /* EOF */ + break; + } + + + if( readSize > 5 ) { + if( !ssid_flag && !STD_StrNCmp( line_buf, "SSID:" , STD_StrLen("SSID:")) ) { + count = STD_StrLen("SSID:"); + if( line_buf[count] == '\"' /* 1個目 */) { + count++; + count2 = count; + while( readSize > count ) { + if( line_buf[count] == '\"' /* 2個目 */) { + SSID_LEN = count - 1; + SSID_STR[count - count2] = '\0'; + ssid_flag = TRUE; + break; + } + SSID_STR[count - count2] = line_buf[count]; + count++; + } + } + } + else if( !mode_flag && !STD_StrNCmp( line_buf, "MODE:" , STD_StrLen("MODE:")) ) { + count = STD_StrLen("MODE:"); + if( line_buf[count] == '\"' /* 1個目 */) { + count++; + count2 = count; + if( !STD_StrNCmp( &(line_buf[count2]), "NONE" , STD_StrLen("NONE")) ) { + // ;MODE:"NONE" + if( line_buf[ count2 + STD_StrLen("NONE") ] == '\"' /* 2個目 */) { + MODE = WCM_WEPMODE_NONE; + mode_flag = TRUE; + } + } + else if( !STD_StrNCmp( &(line_buf[count2]), "WEP40" , STD_StrLen("WEP40")) ) { + if( line_buf[ count2 + STD_StrLen("WEP40") ] == '\"' /* 2個目 */) { + MODE = WCM_WEPMODE_40; + mode_flag = TRUE; + } + } + else if( !STD_StrNCmp( &(line_buf[count2]), "WEP104" , STD_StrLen("WEP104")) ) { + if( line_buf[ count2 + STD_StrLen("WEP104") ] == '\"' /* 2個目 */) { + MODE = WCM_WEPMODE_104; + mode_flag = TRUE; + } + } + + else if( !STD_StrNCmp( &(line_buf[count2]), "WEP128" , STD_StrLen("WEP128")) ) { + if( line_buf[ count2 + STD_StrLen("WEP128") ] == '\"' /* 2個目 */) { + MODE = WCM_WEPMODE_128; + mode_flag = TRUE; + } + } + else if( !STD_StrNCmp( &(line_buf[count2]), "WPA-TKIP", STD_StrLen("WPA-TKIP")) ) { + if( line_buf[ count2 + STD_StrLen("WPA-TKIP") ] == '\"' /* 2個目 */) { + MODE = WCM_WEPMODE_WPA_TKIP; + mode_flag = TRUE; + } + } + else if( !STD_StrNCmp( &(line_buf[count2]), "WPA2-TKIP", STD_StrLen("WPA2-TKIP")) ) { + if( line_buf[ count2 + STD_StrLen("WPA2-TKIP") ] == '\"' /* 2個目 */) { + MODE = WCM_WEPMODE_WPA2_TKIP; + mode_flag = TRUE; + } + } + else if( !STD_StrNCmp( &(line_buf[count2]), "WPA-AES", STD_StrLen("WPA-AES")) ) { + if( line_buf[ count2 + STD_StrLen("WPA-AES") ] == '\"' /* 2個目 */) { + MODE = WCM_WEPMODE_WPA_AES; + mode_flag = TRUE; + } + } + else if( !STD_StrNCmp( &(line_buf[count2]), "WPA2-AES" , STD_StrLen("WPA2-AES")) ) { + if( line_buf[ count2 + STD_StrLen("WPA2-AES") ] == '\"' /* 2個目 */) { + MODE = WCM_WEPMODE_WPA2_AES; + mode_flag = TRUE; + } + } + } + + } + else if( !key_str_flag && !STD_StrNCmp( line_buf, "KEY-STR:" , STD_StrLen("KEY-STR:")) ) { + count = STD_StrLen("KEY-STR:"); + if( line_buf[count] == '\"' /* 1個目 */) { + count++; + count2 = count; + while( readSize > count ) { + if( line_buf[count] == '\"' /* 2個目 */) { + KEY_STR_LEN = count - 1; + KEY_STR[count - count2] = '\0'; + /* このときwep128ならcountは(13文字なので) */ + // 0123456789012345678901 + // KEY-STR:"0123456789red" + key_str_flag = TRUE; + break; + } + KEY_STR[count - count2] = line_buf[count]; + count++; + } + } + } + else if( !key_bin_flag && !STD_StrNCmp( line_buf, "KEY-BIN:" , STD_StrLen("KEY-BIN:")) ) { + count = STD_StrLen("KEY-BIN:"); + lo_hi = 0; + hex = 0; + if( line_buf[count] == '\"' /* 1個目 */) { + count++; + count2 = count; + count3 = 0; + while( readSize > count ) { + if( line_buf[count] == '\"' /* 2個目 */) { + if( lo_hi == 0 ) { + KEY_BIN_LEN = count3; + key_bin_flag = TRUE; + } + break; + } + c = line_buf[count]; + + if( ('a' <= c) && (c <= 'f') ) { + if( lo_hi == 0 ) { + hex = (u8)(( c - 'a' + 10 ) * 16); + } + else { + hex += (u8)( c - 'a' + 10 ); + } + } + else if( ('A' <= c) && (c <= 'F') ) { + if( lo_hi == 0 ) { + hex = (u8)(( c - 'a' + 10 ) * 16); + } + else { + hex += (u8)( c - 'a' + 10 ); + } + } + else if( ('0' <= c) && (c <= '9') ) { + if( lo_hi == 0 ) { + hex = (u8)( (c - '0' ) * 16 ); + } + else { + hex += (u8)(c - '0'); + } + } + else { + /* error! */ + break; + } + if( lo_hi == 1 ) { + KEY_BIN[count3] = hex; + count3++; + } + lo_hi ^= 1; + count++; + } + } + } + } + + if( ssid_flag == TRUE && (key_str_flag == TRUE || key_bin_flag == TRUE) && mode_flag == TRUE ) { + ret_flag = TRUE; + break; + } + + /*123456789012345678 + + SSID:"001D731A8202" + MODE:"WEP128" + ;MODE:"NONE" + ;MODE:"WPA-TKIP" + ;MODE:"WPA2-TKIP" + ;MODE:"WPA-AES" + ;MODE:"WPA2-AES" + KEY-STR:"0123456789red" + KEY-BIN:"0123456789red" + */ + + + } + + if( FS_CloseFile(&f) == FALSE) { + res = FS_GetArchiveResultCode(path); + return FALSE; + } + + return ret_flag; +} + + + diff --git a/build/tools/sctools/common/src/mywlan.h b/build/tools/sctools/common/src/mywlan.h new file mode 100644 index 0000000..0563b5a --- /dev/null +++ b/build/tools/sctools/common/src/mywlan.h @@ -0,0 +1,22 @@ +#ifndef _MY_WLAN_H_ +#define _MY_WLAN_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + + +BOOL LoadWlanConfigFile(char *path); + +char *GetWlanSSID(void); +int GetWlanKEYBIN(u8 *buf); +char *GetWlanKEYSTR(void); +int GetWlanMode(void); + +#ifdef __cplusplus +} +#endif + + +#endif /* _MY_WLAN_H_ */ diff --git a/build/tools/sctools/common/src/netconnect.c b/build/tools/sctools/common/src/netconnect.c new file mode 100644 index 0000000..2c8c4be --- /dev/null +++ b/build/tools/sctools/common/src/netconnect.c @@ -0,0 +1,376 @@ +/*---------------------------------------------------------------------------* + Project: TwlWiFi - demos - netconnect + File: netconnect.c + + Copyright 2005,2006 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:: 2008-08-06#$ + $Rev: 880 $ + $Author: adachi_hiroaki $ + *---------------------------------------------------------------------------*/ + +#include +#include + +#include "sitedefs.h" +#include "wcm_control.h" +#include "netconnect.h" +#include "mywlan.h" + +/*---------------------------------------------------------------------------* + 初期化 + *---------------------------------------------------------------------------*/ +static void Heap_Setup(void); +#ifdef SDK_TWL +static void* myAlloc_SOCL(u32 size); +static void myFree_SOCL(void* ptr); +#endif // SDK_TWL + +static void ncStartWiFi(void); +static void ncFinishWiFi(void); +static void ncStartInet(void); +static void ncFinishInet(void); + +static WcmControlApInfo apInfo; +static s32 previousAddr = 0; +static u8 g_deviceId = WCM_DEVICEID_DEFAULT; +static BOOL g_started = FALSE; + +/*---------------------------------------------------------------------------* + Name : NcGlobalInit + Description : + Arguments : なし。 + Returns : + *---------------------------------------------------------------------------*/ +void NcGlobalInit() +{ + OS_Init(); + OS_InitTick(); + OS_InitAlarm(); + RTC_Init(); + Heap_Setup(); + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); +} + +#ifndef SDK_WIFI_INET +static void ncStartWiFi(void) +{ + int result; + if (previousAddr != 0) + { + /* + DHCPサーバに前回取得したアドレスを要求するように設定する。 + アドレスプールを使い切らないようにするために必要。 + */ + SOCL_SetRequestedIP(SOC_NtoHl(previousAddr)); + } + +#ifdef SDK_TWL + if (OS_IsRunOnTwl()) + { + static SOCLConfig socl_config; + MI_CpuClear8(&socl_config, sizeof(socl_config)); + + socl_config.alloc = myAlloc_SOCL; + socl_config.free = myFree_SOCL; + socl_config.use_dhcp = TRUE; + socl_config.cmd_packet_max = SOCL_CMDPACKET_MAX; + socl_config.lan_buffer_size = SOCL_LAN_BUFFER_SIZE_DEFAULT * 8; + socl_config.mtu = 1400; + socl_config.rwin = 65535; + + OS_TPrintf("SOCL_Startup....\n"); + result = SOCL_Startup(&socl_config); + } + else +#endif // SDK_TWL + { + SOCConfig soc_config; + soc_config.alloc = NcAlloc; + soc_config.free = NcFree; + soc_config.flag = SOC_FLAG_DHCP; + soc_config.mtu = 0; + soc_config.rwin = 0; + + OS_TPrintf("SOC_Startup....\n"); + result = SOC_Startup(&soc_config); + } + if (result < 0) + { + OS_Panic("SOC_Startup failed (%d)", result); + } + g_started = TRUE; + OS_TPrintf("DHCP....\n"); + + while (SOC_GetHostID() == 0) + { + OS_Sleep(100); + } + + OS_TPrintf("IP addr = %3d.%3d.%3d.%3d\n", CPS_CV_IPv4(CPSMyIp)); + OS_TPrintf("NetMask = %3d.%3d.%3d.%3d\n", CPS_CV_IPv4(CPSNetMask)); + OS_TPrintf("GW addr = %3d.%3d.%3d.%3d\n", CPS_CV_IPv4(CPSGatewayIp)); + OS_TPrintf("DNS[0] = %3d.%3d.%3d.%3d\n", CPS_CV_IPv4(CPSDnsIp[0])); + OS_TPrintf("DNS[1] = %3d.%3d.%3d.%3d\n", CPS_CV_IPv4(CPSDnsIp[1])); +} + +static void ncFinishWiFi(void) +{ + previousAddr = SOC_GetHostID(); + if (g_started) + { + (void)SOC_Cleanup(); + g_started = FALSE; + } +} + +#else // SDK_WIFI_INET + +static void ncStartInet(void) +{ + int result; + SOConfig soConfig = + { + SO_VENDOR_NINTENDO, // vendor + SO_VERSION, // version + + NcAlloc, // alloc + NcFree, // free + + SO_FLAG_DHCP, // flag + SO_HtoNl(SO_INADDR_ANY),// addr + SO_HtoNl(SO_INADDR_ANY),// netmask + SO_HtoNl(SO_INADDR_ANY),// router + SO_HtoNl(SO_INADDR_ANY),// dns1 + SO_HtoNl(SO_INADDR_ANY),// dns1 + 4096, // timeWaitBuffer + 4096, // reassemblyBuffer + 0, // maximum transmission unit size + + // TCP + 16384, // default TCP receive window size (default 2 x MSS) + 0, // default TCP total retransmit timeout value (default 100 sec) + + // PPP PPP関連機能は未実装 + NULL, + NULL, + + // PPPoE PPP関連機能は未実装 + NULL, + + // DHCP + "NINTENDO-DS", // DHCP host name + 4, // TCP total retransmit times (default 4) + + // UDP + 0, // default UDP send buffer size (default 1472) + 0 // defualt UDP receive buffer size (default 4416) + }; + +#ifdef SDK_TWL + if (OS_IsRunOnTwl()) + { + soConfig.rwin = 65535; + } +#endif // SDK_TWL + + OS_TPrintf("SO_Startup....\n"); + result = SO_Startup(&soConfig); + if (result < 0) + { + OS_Panic("SO_Startup failed (%d)", result); + } + g_started = TRUE; + + OS_TPrintf("DHCP....\n"); + + while (SO_GetHostID() == 0 && IP_GetConfigError(NULL) == 0) + { + OS_Sleep(100); + } + + if (SO_GetHostID() != 0) + { + int retry = 0; + u8 ip[ IP_ALEN ]; + + IP_GetAddr( NULL, ip ); + OS_Printf("IP addr = %3d.%3d.%3d.%3d\n", ip[0], ip[1], ip[2], ip[3] ); + IP_GetNetmask ( NULL, ip ); + OS_Printf("NetMask = %3d.%3d.%3d.%3d\n", ip[0], ip[1], ip[2], ip[3] ); + IP_GetGateway ( NULL, ip ); + OS_Printf("GW addr = %3d.%3d.%3d.%3d\n", ip[0], ip[1], ip[2], ip[3] ); + } + else + { + OS_TPrintf("NO DHCP SERVER or NO LINK....\n"); + + switch (IP_GetConfigError(NULL)) + { + case IP_ERR_DHCP_TIMEOUT: + OS_Panic("IP_ERR_DHCP_TIMEOUT\n"); + break; + + case IP_ERR_LINK_DOWN: + OS_Panic("IP_ERR_LINK_DOWN\n"); + break; + + default: + OS_Panic("Default???\n"); + break; + } + } + +} + +static void ncFinishInet(void) +{ + previousAddr = SO_GetHostID(); + if (g_started) + { + (void)SO_Cleanup(); + g_started = FALSE; + } +} + +#endif // SDK_WIFI_INET + +/*---------------------------------------------------------------------------* + Name : NcStart + Description : + Arguments : apClass - SitDefsに定義されているアクセスポイントのクラス名 + Returns : + *---------------------------------------------------------------------------*/ +void NcStart(const char* apClass) +{ + + SiteDefs_Init(); + + + if( FALSE == ENV_SetBinary("WiFi.LAN.1.AP.1.WEP.KEY", (void *)GetWlanKEYSTR()) ) { + OS_TPrintf("Error %s %d\n", __FUNCTION__,__LINE__); + } + if( FALSE == ENV_SetString("WiFi.LAN.1.AP.1.ESSID", GetWlanSSID()) ) { + OS_TPrintf("Error %s %d\n", __FUNCTION__,__LINE__); + } + + if( FALSE == ENV_SetU8("WiFi.LAN.1.AP.1.WEP.MODE", (u8)GetWlanMode() ) ) { + OS_TPrintf("Error %s %d\n", __FUNCTION__,__LINE__); + } + + if (!InitWcmApInfo(&apInfo, apClass)) + { + OS_Panic("Invalid AP Class...."); + } + + while (WCM_GetPhase() != WCM_PHASE_NULL) + { + OS_Sleep(100); + } + + InitWcmControlByApInfoEx(&apInfo, g_deviceId); + + OS_TPrintf("LINK UP....\n"); + + while (WCM_GetPhase() != WCM_PHASE_DCF) + { + OS_Sleep(100); + } + + +#ifndef SDK_WIFI_INET +OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + + ncStartWiFi(); + +#else // SDK_WIFI_INET +OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + + ncStartInet(); +#endif // SDK_WIFI_INET +} + +void NcFinish() +{ +#ifndef SDK_WIFI_INET + ncFinishWiFi(); +#else // SDK_WIFI_INET + ncFinishInet(); +#endif // SDK_WIFI_INET +} + +void NcSetDevice(u8 deviceId) +{ + g_deviceId = deviceId; +} + +SDK_WEAK_SYMBOL void* NcAlloc(u32 name, s32 size) +{ +#pragma unused(name) + OSIntrMode enable = OS_DisableInterrupts(); + void* ptr = OS_Alloc((u32) size); + (void)OS_RestoreInterrupts(enable); + return ptr; +} + +SDK_WEAK_SYMBOL void NcFree(u32 name, void* ptr, s32 size) +{ +#pragma unused(name, size) + OSIntrMode enable = OS_DisableInterrupts(); + OS_Free(ptr); + (void)OS_RestoreInterrupts(enable); + return; +} + +/*---------------------------------------------------------------------------* + ヒープ関連 + *---------------------------------------------------------------------------*/ + +// MainRAM アリーナに対して メモリ割り当てシステム初期化 +static void Heap_Setup(void) +{ + void* nstart; + OSHeapHandle handle; + + nstart = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1); + OS_SetMainArenaLo(nstart); + handle = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi()); + (void)OS_SetCurrentHeap(OS_ARENA_MAIN, handle); +} + + +#ifdef SDK_TWL +static void* myAlloc_SOCL(u32 size) +{ + s32 msize = (s32) (size + sizeof(s32)); + s32* m = NcAlloc(0U, msize); + + // 呼び出しに必要なパラメータを領域の先頭に隠しておく + if (m) + { + m[0] = (s32) msize; + m++; + } + + return (void*)m; +} + +static void myFree_SOCL(void* ptr) +{ + s32* m = (s32*)ptr; + + // 呼び出しに必要なパラメータを領域の先頭から取り出す + if (m) + { + m--; + NcFree(0U, (void*)m, m[0]); + } +} +#endif // SDK_TWL diff --git a/build/tools/sctools/common/src/netconnect.h b/build/tools/sctools/common/src/netconnect.h new file mode 100644 index 0000000..1b495fb --- /dev/null +++ b/build/tools/sctools/common/src/netconnect.h @@ -0,0 +1,39 @@ +/*---------------------------------------------------------------------------* + Project: TwlWiFi - demos - netconnect + File: netconnect.h + + Copyright 2005,2006 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:: 2008-01-11#$ + $Rev: 212 $ + $Author: adachi_hiroaki $ + *---------------------------------------------------------------------------*/ + +#ifndef NITROWIFI_DEMOS_NETCONNECT_H_ +#define NITROWIFI_DEMOS_NETCONNECT_H_ + +#ifdef __cplusplus + +extern "C" +{ +#endif + +void NcGlobalInit(void); +void NcStart(const char* apClass); +void NcFinish(void); +void NcSetDevice(u8 deviceId); +void* NcAlloc(u32 name, s32 size); +void NcFree(u32 name, void* ptr, s32 size); + +#ifdef __cplusplus + +} /* extern "C" */ +#endif + +#endif /* NITROWIFI_DEMOS_NETCOONECT_H_ */ diff --git a/build/tools/sctools/common/src/nuc.c b/build/tools/sctools/common/src/nuc.c new file mode 100644 index 0000000..253117b --- /dev/null +++ b/build/tools/sctools/common/src/nuc.c @@ -0,0 +1,503 @@ +#include +#include +#include +#include + +#include "netconnect.h" +#include "sitedefs.h" +#include "nuc.h" +#include "nuc_error_msg.h" + +// Network Updateのフェーズを表す +typedef enum{ + + PHASE_INIT, // 初期状態 + PHASE_READY, // 開始 + PHASE_CONNECTING_NETWORK, // ネットワーク接続中 + PHASE_TEST_READY, // 接続テスト開始 + PHASE_TEST_PROCESS, // 接続テスト中 + PHASE_TEST_GETTING_WII_ID, // Wii ID取得処理 + PHASE_TEST_FINISHED, // 接続テスト完了 + PHASE_TEST_CLEANUP, // 接続テスト後処理 + PHASE_NUP_BREAK, // <キー入力待ち>アップデート前確認待ち + PHASE_NUP_READY, // ネットワークアップデート開始 + PHASE_NUP_CHECK, // ネットワークアップデート更新情報取得中 + PHASE_NUP_DOWNLOAD, // ネットワークアップデート ダウンロード開始 + PHASE_NUP_PROCESS, // ネットワークアップデート中 + PHASE_NUP_FINISHED, // ネットワークアップデート完了 + PHASE_NUP_CLEANUP, // ネットワークアップデート後処理 + PHASE_NUP_SKIPPED, // ネットワークアップデートがスキップされた + PHASE_CLEANING_UP, // 後処理 + PHASE_FINISHED, // 完了 + PHASE_ERROR_OCCURRED // エラー発生 +} NucPhaseState; + + +// ネットワーク接続状態 +typedef enum{ + NET_CONNECT_NONE, + NET_CONNECT_OK, + NET_CONNECT_ERROR +} NetConnectState; + +static volatile NetConnectState NetConnect = NET_CONNECT_NONE; + +// state管理 +static struct +{ + NucPhaseState state; + u32 count; +} TestState; + +static inline void ChangeState(NucPhaseState state) +{ + TestState.state = state; + TestState.count = 0; +} + +// titleID 取得用 +static NUCTitleId TitleIds[NUC_MAX_TITLE_UPDATE_COUNT]; +static u32 TitleIdNum; + +static u8 WorkForNA[NA_VERSION_DATA_WORK_SIZE]; + +static BOOL AllocFailTest = FALSE; + +static void *alloc(u32 size, int align) +{ + u32 *ptr = NULL, *realPtr = NULL; + u32 realSize; + OSIntrMode old; + + old = OS_DisableInterrupts(); + + /* realSize is size plus alignment and header */ + if (align < 4) + { + align = 4; + } + realSize = size + align + 4; + + realPtr = (u32 *) OS_Alloc(realSize); + ptr = (u32 *)((((u32) realPtr) + 4 + align - 1) & ~(align - 1)); + + *((u32 *)(((u32)ptr) - 4)) = (u32) realPtr; + (void)OS_RestoreInterrupts( old ); + + end: + SDK_ASSERT(((u32)ptr & (align - 1)) == 0); + return (void *) ptr; +} + +static void free(void *p) +{ + u32 realPtr = *((u32 *)(((u32)p) - 4)); + OS_Free((void *) realPtr); +} + +/*---------------------------------------------------------------------------* + Name: InitNupLib + Description: NUCライブラリを開始します。 + *---------------------------------------------------------------------------*/ +static BOOL InitNupLib() +{ + BOOL ret; + + ret = NUC_Init(alloc, free); + + if (ret == FALSE) { + OS_TPrintf("NUC_Init() failed, error code=%d\n", NUC_GetLastError()); + } + return ret; +} + +/*---------------------------------------------------------------------------* + Name: StartNupCheck + Description: ダウンロードリスト一覧の取得を開始します。 + *---------------------------------------------------------------------------*/ +static BOOL StartNupCheck(void) +{ + BOOL ret; + TitleIdNum = sizeof(TitleIds) / sizeof(TitleIds[0]); + + ret = NUC_CheckAsync(TitleIds, &TitleIdNum); + if (ret == FALSE) + { + OS_TPrintf("NUC_CheckAsync() failed, error code=%d\n", NUC_GetLastError()); + } + + return ret; +} + + +/*---------------------------------------------------------------------------* + Name: ProgressNupCheck + Description: ダウンロードリスト一覧の取得状況を確認します + *---------------------------------------------------------------------------*/ +static NucStatus ProgressNupCheck(void) +{ + u64 CurrentSize, TotalSize; + NucStatus status; + + NUC_GetProgress(&CurrentSize, &TotalSize, &status); + if (status == NUC_STATUS_ERROR) + { + OS_TPrintf("NUC_GetProgress() failed in checking, error code=%d\n", NUC_GetLastError()); + } +#if 0 + if (TestState.count++ % STRING_ANIM_CNT == 0) + { + u32 num = (TestState.count / STRING_ANIM_CNT) % 3; + const char* msg[] = { + "Now checking list. ", + "Now checking list.. ", + "Now checking list... "}; + + PrintString(TEXT_X, TEXT_Y, COLOR_WHITE, msg[num]); + } +#endif + return status; +} + +/*---------------------------------------------------------------------------* + Name: StartNupDownload + Description: ダウンロードを開始します。 + *---------------------------------------------------------------------------*/ +static BOOL StartNupDownload(void) +{ + /* こいつが呼ばれたらFSが切り離されてしまうのでリブートが必要 */ + BOOL ret = NUC_DownloadAsync(TitleIds, TitleIdNum); + + if (ret == FALSE) + { + OS_TPrintf("NUP_DownloadAsync() failed, error code=%d\n", NUC_GetLastError()); + } + + return ret; +} + +/*---------------------------------------------------------------------------* + Name: ProgressNupDownload + Description: ダウンロードの進行状況を表示します。 + *---------------------------------------------------------------------------*/ +static NucStatus ProgressNupDownload(void) +{ + u64 CurrentSize, TotalSize; + NucStatus status; + + NUC_GetProgress(&CurrentSize, &TotalSize, &status); + if (status == NUC_STATUS_ERROR) + { // エラー発生 + OS_TPrintf("NUC_GetProgress() failed in download, error code=%d\n", NUC_GetLastError()); + } + else { +#if 0 + // ダウンロード状況を描画 + int dw = (int)((CurrentSize * BAR_W)/TotalSize); + FillRect(BAR_X, BAR_Y, dw, BAR_H, GX_RGBA(31, 16, 16, 1)); +#endif + } + +#if 0 + if (TestState.count++ % STRING_ANIM_CNT == 0) + { + u32 num = (TestState.count / STRING_ANIM_CNT) % 3; + const char* msg[] = { + "Now downloading. ", + "Now downloading.. ", + "Now downloading... "}; + PrintString(TEXT_X, TEXT_Y, COLOR_WHITE, msg[num]); + } +#endif + return status; +} + +/*---------------------------------------------------------------------------* + Name: CleanNupLib + Description: NUCライブラリを終了します。 + *---------------------------------------------------------------------------*/ +static BOOL CleanNupLib() +{ + BOOL ret = NUC_Cleanup(TitleIds, TitleIdNum); + if (ret == FALSE) + { + OS_TPrintf("NUP_CleanUp() failed, error code=%d\n", NUC_GetLastError()); + } + return ret; +} + +/*---------------------------------------------------------------------------* + Name: ProgressNetConnect + Description: ネットワーク接続を待ちます。 + *---------------------------------------------------------------------------*/ +static void ProgressNetConnect(void) +{ +#if 0 + if (TestState.count++ % STRING_ANIM_CNT == 0) + { + u32 num = (TestState.count / STRING_ANIM_CNT) % 3; + const char* msg[] = { + "Connecting network. ", + "Connecting network.. ", + "Connecting network..."}; + PrintString(TEXT_X, TEXT_Y, COLOR_WHITE, msg[num]); + } +#endif +} + + + +static void ShowErrorMsg(int error_code) +{ +#if 0 + PrintString(TEXT_X, TEXT_Y, COLOR_WHITE, "Error Occurred "); +#endif + if (error_code > 0) + { +#if 0 + PrintString(TEXT_X, TEXT_Y + 10, COLOR_WHITE, "Error Code:%d", error_code); + PrintString(TEXT_X, TEXT_Y + 12, COLOR_WHITE, "%s", GetPublicMsg(error_code)); + PrintString(TEXT_X, TEXT_Y + 15, COLOR_WHITE, "%s", GetPrivateMsg(error_code)); +#endif + OS_TPrintf( "Error Code:%d\n", error_code); + OS_TPrintf( "%s\n", GetPublicMsg(error_code)); + OS_TPrintf( "%s\n", GetPrivateMsg(error_code)); + } + else + { + OS_TPrintf( "%s\n", "Network Error occurred.\nTry again later."); +#if 0 + // ネットワークエラー時の表示メッセージ(暫定) + PrintString(TEXT_X, TEXT_Y + 10, COLOR_WHITE, "%s", "Network Error occurred.\nTry again later."); +#endif + } +} + +// ネットワーク接続関連 +#define STACK_SIZE (1024*4) +static OSThread NetThread; +static u64 NetStack[STACK_SIZE / sizeof(u64)]; +#define THREAD1_PRIO 24 +static volatile BOOL NetHTTPEnd = FALSE; + + +static void NetConnectProc(void *arg) +{ +#pragma unused(arg) + BOOL ret; + NucStatus status; + int error_code = 0; + + + /* Start networking */ + NcStart(SITEDEFS_DEFAULTCLASS); + + NetConnect = NET_CONNECT_OK; + //OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + // 終了の呼び出しを待つ +// OS_SleepThread(NULL); + + while(1) { + OS_Sleep( 16 ); /* OS_WaitVBlankIntrの代わり */ + + switch ( TestState.state ) { + case PHASE_CONNECTING_NETWORK: + ProgressNetConnect(); + if (NetConnect == NET_CONNECT_OK) + { + ChangeState(PHASE_NUP_BREAK); + } + else if (NetConnect == NET_CONNECT_ERROR) + { // ネットワーク接続エラー + error_code = -1; + ChangeState(PHASE_ERROR_OCCURRED); + } + break; + case PHASE_NUP_BREAK: // AボタンでNUPライブラリを初期化します。 + ret = InitNupLib(); + if (ret == FALSE) + { // エラー発生 + ChangeState(PHASE_ERROR_OCCURRED); + error_code = NUC_GetLastError(); + } + else + { + ChangeState(PHASE_NUP_READY); + } + break; + + case PHASE_NUP_READY: // 更新情報の取得を開始します。 + ret = StartNupCheck(); + if (ret == FALSE) + { // エラー発生 + error_code = NUC_GetLastError(); + ChangeState(PHASE_NUP_CLEANUP); + } + else + { + ChangeState(PHASE_NUP_CHECK); + } + break; + + case PHASE_NUP_CHECK: // 更新情報の取得状況を表示します。 + status = ProgressNupCheck(); + if (status == NUC_STATUS_ERROR) + { // エラー発生 + ChangeState(PHASE_NUP_CLEANUP); + error_code = NUC_GetLastError(); + } + else if (status == NUC_STATUS_COMPLETED) + { // 更新リスト 取得終了 + if (TitleIdNum > 0 ) + { // ダウンロードへ + int i; + for (i = 0; i < TitleIdNum; i++) + { + OS_TPrintf("DL list:%3d:0x%llx", i, TitleIds[i]); + } + ChangeState(PHASE_NUP_DOWNLOAD); + } + else + { // 更新すべきものがない + OS_TPrintf("No title to update\n"); + ChangeState(PHASE_NUP_CLEANUP); + } + } + break; + + case PHASE_NUP_DOWNLOAD: // ダウンロードを開始します。 + ret = StartNupDownload(); + if (ret == FALSE) + { // エラー発生 + ChangeState(PHASE_NUP_CLEANUP); + error_code = NUC_GetLastError(); + } + else + { + ChangeState(PHASE_NUP_PROCESS); + } + break; + + case PHASE_NUP_PROCESS: // ダウンロードの進行状況を表示します。 + status = ProgressNupDownload(); + if (status == NUC_STATUS_ERROR) + { // エラー発生 + ChangeState(PHASE_NUP_CLEANUP); + error_code = NUC_GetLastError(); + } + else if (status == NUC_STATUS_COMPLETED) + { // ダウンロード完了 + ChangeState(PHASE_NUP_CLEANUP); + } + break; + + case PHASE_NUP_CLEANUP: // NUPライブラリのクリーンアップ + ret = CleanNupLib(); + if (ret == FALSE && error_code == 0) + { // 他でエラーが起こっていない場合のみ上書きします。 + error_code = NUC_GetLastError(); + } + // ネットの切断と後始末 + OS_WakeupThreadDirect(&NetThread); + ChangeState(PHASE_CLEANING_UP); + break; + + case PHASE_CLEANING_UP: // ネットの切断終了を待ちます + if (NetConnect == NET_CONNECT_NONE) + { // 切断終了 + if (error_code == 0) + { // 正常終了 + ChangeState(PHASE_FINISHED); + } + else + { + ChangeState(PHASE_ERROR_OCCURRED); + } + } + break; + + case PHASE_FINISHED: // ネットワークアップデートが正常終了しました。 + OS_TPrintf("Network Update Completed\n"); + if (TitleIdNum > 0) + { + OS_TPrintf("%d file is updated\n", TitleIdNum); + } + else + { + OS_TPrintf("Nothing is updated\n"); + } + + if (TitleIdNum > 0) + { // 再起動する + OS_TPrintf("再起動します\n"); + } + else + { // メッセージを表示して戻る + OS_TPrintf("アップデートするものがなかったので戻ります\n"); + } + goto end; + + break; + + case PHASE_ERROR_OCCURRED: // エラーが発生しています。 + + ShowErrorMsg(error_code); + goto end; +#if 0 + if (Trg == PAD_BUTTON_A) + { + OS_TPrintf("エラーが発生したので戻ります\n"); + goto end; + } +#endif + break; + + default: +OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + + break; + } + } + + end: + NcFinish(); + NetConnect = NET_CONNECT_NONE; + + OS_TPrintf("Network Connection ended\n"); +} + + +/* ********************** */ +void nuc_main(void) +{ + + ChangeState(PHASE_INIT); + // NcGlobalInit(); in netconnect.c + + /* クライアント証明書の初期化 */ + SEA_Init(); + // あらかじめWRAMにロードしておきます + if (!NA_LoadVersionDataArchive(WorkForNA, NA_VERSION_DATA_WORK_SIZE)) { + OS_TPrintf("NA load error\n"); + goto end; + } + + if (!NUC_LoadCert()) { + // WRAMにロード + OS_TPrintf("Client cert load error\n"); + goto end; + } + + (void)NA_UnloadVersionDataArchive(); + + + /* 接続設定スレッドの作成 */ + OS_CreateThread(&NetThread, NetConnectProc, + NULL, NetStack + STACK_SIZE / sizeof(u64), + STACK_SIZE, THREAD1_PRIO); + OS_WakeupThreadDirect(&NetThread); + ChangeState(PHASE_CONNECTING_NETWORK); + + end: + return; +} diff --git a/build/tools/sctools/common/src/nuc.h b/build/tools/sctools/common/src/nuc.h new file mode 100644 index 0000000..afb2b50 --- /dev/null +++ b/build/tools/sctools/common/src/nuc.h @@ -0,0 +1,14 @@ +#ifndef _NUC_H_ +#define _NUC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +void nuc_main(void); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* _NUC_H_ */ diff --git a/build/tools/sctools/common/src/nuc_error_msg.c b/build/tools/sctools/common/src/nuc_error_msg.c new file mode 100644 index 0000000..66bec8a --- /dev/null +++ b/build/tools/sctools/common/src/nuc_error_msg.c @@ -0,0 +1,277 @@ +/*---------------------------------------------------------------------------* + Project: TwlWiFi - build - demos.TWL - nuc + File: error_msg.c + + Copyright 2007-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:: 2008-09-18#$ + $Rev: 1024 $ + $Author: okubata_ryoma $ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "nuc_error_msg.h" + +/*---------------------------------------------------------------------------* + 内部使用の定数定義 + *---------------------------------------------------------------------------*/ +static const char* PrivateNupError[] = +{ + "[NUP] Unknown Error", + "[NUP] Another NUP operation is in progress", + "[NUP] Unexpected internal error in the NUP library", + "[NUP] Invalid input parameters", + "[NUP] Country code is undefined", + "[NUP] Unable to get version data", + "[NUP] Unable to create data file", + "[NUP] Out of memory" +}; + +static const char* PrivateCheckError[] = +{ + "[CHK] Unknown Error", + "[CHK] No operation started since NUP_Init()", + "[CHK] The check operation is in progress", + "[CHK] Unexpected internal error in the NUP library", + "[CHK] Exceeded memory restriction", + "[CHK] Required system titles not on system", + "[CHK] Failed to parse SOAP response", + "[CHK] Server returned error in SOAP response", + "[CHK] Version of a title is newer on the system than on the server", + "[CHK] Server returned a HTTP status error when downloading content, ticket, or TMD" +}; + +static const char* PrivateDownloadError[] = +{ + "[DL] Unknown Error", + "[DL] No operation started since NUP_Init()", + "[DL] The download operation is in progress", + "[DL] Unexpected internal error in the NUP library", + "[DL] Exceeded memory restriction", + "[DL] Required system titles not on system", + "[DL] Failed to parse SOAP response", + "[DL] Server returned error in SOAP response", + "[DL] Version of a title is newer on the system than on the server", + "[DL] Server returned a HTTP status error when downloading content, ticket, or TMD", + "[DL] One or more specified titles not found on the update list", + "[DL] Invalid TMD downloaded", + "[DL] Invalid ticket downloaded", + "[DL] Failed to import ticket", + "[DL] Failed to initialize title import", + "[DL] Failed to complete title import", + "[DL] Failed to begin content import", + "[DL] Failed to import content data", + "[DL] Failed to end content import", + "[DL] Insufficient space on the file system to download title", + "[DL] Insufficient space on the file system to create backup data" +}; + +static const char* PrivateHTTPError[] = +{ + "[HTTP] Unknown Error", + "[HTTP] Failed to resolve DNS", + "[HTTP] Failed to connect to server", + "[HTTP] Failed to resolve DNS in proxy server", + "[HTTP] Failed to connect to proxy server", + "[HTTP] Invalid handle error", + "[HTTP] Failed to alloc", + "[HTTP] Socket Error", + "[HTTP] Receive buffer is full", + "[HTTP] Failed to parse HTTP header", + "[HTTP] Request is canceled by the caller", + "[HTTP] Failed to create HTTP thread", + "[HTTP] Error in sending, recieving or closing socket", + "[HTTP] Invalid parameter is set in NHTTPCreateConnection", + "[HTTP] request is in progress", + "[HTTP] Failed to set Root CA", + "[HTTP] Failed to set client cert" +}; + +static const char* PrivateSSLError[] = +{ + "[SSL] Unknown Error", + "[SSL] SSL protocol failure", + "[SSL] Read attempted but without waiting for blocking from the caller", + "[SSL] Read attempted but without waiting for blocking from the caller", + "[SSL] System call error", + "[SSL] Read/write system returned 0", + "[SSL] BIO not yet connected", + "[SSL] SSL Descriptor is out of range", + "[SSL] the server name and common name do not match", + "[SSL] verification failed for the root CA", + "[SSL] the certificate chain is incorrect", + "[SSL] the time limit for the certificate has expired", + "[SSL] Cert size is too large to get", + "[SSL] Invalid root CA", + "[SSL] Invalid client cert", + "[SSL] the certificate has been denied", + "[SSL] NSSL library was not initialized" +}; + +static const char* PrivateFSError[] = +{ + "[FS] Unknown Error", + "[FS] Failed to correctly process results", + "[FS] Current command is busy", + "[FS] Command was canceled", + "[FS] Archive is not supported by the specified command", + "[FS] Some arguments are invalid to process the specified command", + "[FS] Some internal resource is not enough to process the specified command", + "[FS] Situation which the specified command will make is already made", + "[FS] Specified command has failed by the problem of access permission.", + "[FS] Detected file system corruption", + "[FS] Failed in the results where a detectable error occurred during processing." +}; + +static const char* PrivateESError[] = +{ + "[ES] Unknown Error", + "[ES] Incorrect cert type", + "[ES] Failed to generate key", + "[ES] Failed to verify signature", + "[ES] Cannot open file", + "[ES] Incorrect public key type", + "[ES] Cert issurer mismatch", + "[ES] Failed to encrypt", + "[ES] Failed to open file", + "[ES] Failed to read file", + "[ES] Failed to write file", + "[ES] TMD contents number error", + "[ES] Incorrect signature length", + "[ES] Incorrect cert length", + "[ES] Device error", + "[ES] File descripter is maximum", + "[ES] Invalid operation", + "[ES] FS connection failure", + "[ES] Unsupported transfer source", + "[ES] Device ID mismatch", + "[ES] Incorrect content size", + "[ES] Hash mismatch", + "[ES] Incorrent content count", + "[ES] Out of memory", + "[ES] No TMD file exists", + "[ES] No right", + "[ES] Issuer not found", + "[ES] No ticket exists", + "[ES] Incorrect ticket", + "[ES] Not enough space", + "[ES] Incorrect boot version", + "[ES] Unknown error", + "[ES] Expired error", + "[ES] Unused error", + "[ES] Incorrect title version", + "[ES] OS Ticket does not exist", + "[ES] OS Content does not exist", + "[ES] Not empty", + "[ES] Disc NAND have no TMD" +}; + +static const char* PublicError[] = +{ + /* エラーが発生しましたため、 + TWL本体の更新ができません。*/ + "Error occurred.\nUnable to update TWL system.", + /* TWL本体保存メモリの空き容量が + 不足しています。 + TWL本体の更新はできませんでした。*/ + "Insufficient memory in TWL\nUnable to update TWL system.", + /* サーバーに接続できません。 + しばらく待ってやり直してください。*/ + "Unable to connect to server\nTry again later.", + /* インターネットのエラーにより、 + TWL本体の更新ができません。 + しばらく待ってやり直してください。*/ + "Network Error occurred.\nTry again later." +}; + +/*---------------------------------------------------------------------------* + 内部使用のワーク領域型定義 + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + グローバル変数 + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 内部使用の関数定義(ローカル) + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 外部公開の関数定義 + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: GetPrivateMsg + + Description: 開発者向けのエラーのメッセージを取得します。 + + Arguments: error_code + + Returns: 文字列へのポインタ + *---------------------------------------------------------------------------*/ +const char* GetPrivateMsg(int error_code) +{ + if (34000 <= error_code && error_code <= 34007) + { // NUPの一般的なエラー + return PrivateNupError[error_code - 34000]; + } + else if (34100 <= error_code && error_code <= 34109) + { // 更新情報取得中のエラー + return PrivateCheckError[error_code - 34100]; + } + else if (34200 <= error_code && error_code <= 34220) + { // ダウンロード中のエラー + return PrivateDownloadError[error_code - 34200]; + } + else if (34300 <= error_code && error_code <= 34316) + { // NHTTPのエラー + return PrivateHTTPError[error_code - 34300]; + } + else if (34400 <= error_code && error_code <= 34417) + { // NSSLのエラー + return PrivateSSLError[error_code - 34400]; + } + else if (34500 <= error_code && error_code <= 34510) + { // FSのエラー + return PrivateFSError[error_code - 34500]; + } + else if (34600 <= error_code && error_code <= 34639) + { // ESのエラー + return PrivateESError[error_code - 34600]; + } + return NULL; +} + +/*---------------------------------------------------------------------------* + Name: GetPublicMsg + + Description: ユーザー向けのエラーのメッセージを取得します。 + + Arguments: error_code + + Returns: 文字列へのポインタ + *---------------------------------------------------------------------------*/ +const char* GetPublicMsg(int error_code) +{ + NucError type = NUC_GetErrorType(error_code); + switch(type) + { + case NUC_ERROR_NO_SPACE: + return PublicError[1]; + case NUC_ERROR_CONNECT: + return PublicError[2]; + case NUC_ERROR_INTERNET: + return PublicError[3]; + case NUC_ERROR_UPDATE: + default: + return PublicError[0]; + } +} + diff --git a/build/tools/sctools/common/src/nuc_error_msg.h b/build/tools/sctools/common/src/nuc_error_msg.h new file mode 100644 index 0000000..9e90d5d --- /dev/null +++ b/build/tools/sctools/common/src/nuc_error_msg.h @@ -0,0 +1,52 @@ +#ifndef _NUC_ERROR_MSG_H_ +#define _NUC_ERROR_MSG_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/*---------------------------------------------------------------------------* + 定数 + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 型 + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 関数 + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: GetPrivateMsg + + Description: 開発者向けのエラーのメッセージを取得します。 + + Arguments: error_code + + Returns: 文字列へのポインタ + *---------------------------------------------------------------------------*/ +const char* GetPrivateMsg(int error_code); + +/*---------------------------------------------------------------------------* + Name: GetPublicMsg + + Description: ユーザー向けのエラーのメッセージを取得します。 + + Arguments: error_code + + Returns: 文字列へのポインタ + *---------------------------------------------------------------------------*/ +const char* GetPublicMsg(int error_code); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* _NUC_ERROR_MSG_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/tools/sctools/common/src/sitedefs.c b/build/tools/sctools/common/src/sitedefs.c new file mode 100644 index 0000000..348ac29 --- /dev/null +++ b/build/tools/sctools/common/src/sitedefs.c @@ -0,0 +1,237 @@ +/*---------------------------------------------------------------------------* + Project: TwlWiFi - demos - netconnect + File: sitedefs.c + + Copyright 2005,2006 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:: 2007-10-30#$ + $Rev: 74 $ + $Author: adachi_hiroaki $ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "sitedefs.h" + + +/* + c:/twlsdk/include/nitro/env/env_system.h +*/ + +BOOL ENV_SetBinary(const char *name, void *ptr) +{ + ENVResource *resSetPtr; + ENVResource *p = ENVi_Search(name, &resSetPtr); + u16 len = 1; + + if (!p) { + return FALSE; + } + + if (p->type != ENV_RESTYPE_BINARY) { + return FALSE; + } + + len = (u16)(p->len - ((p->type == ENV_RESTYPE_STRING) ? 1 : 0)); + OS_TPrintf("env bin len = %d\n", len); + + + if (p->type & ENV_RESTYPE_OFFSET_MASK) + { + // return (void *)((u32)resSetPtr + (u32)(p->ptr)); + // (char *)((u32)resSetPtr + (u32)(p->ptr)) = val; + STD_CopyMemory( (void *)((u32)resSetPtr + (u32)(p->ptr)) , ptr, (u32)STD_StrLen(ptr) ); + } + else + { + // return p->ptr; + // (char *)p->ptr = val; + // STD_CopyMemory( (void *)(p->ptr) , ptr , (u32)len ); + STD_CopyMemory( (void *)(p->ptr) , ptr , (u32)STD_StrLen(ptr) ); + } + return TRUE; +} + +BOOL ENV_SetString(const char *name, char *str) +{ + ENVResource *resSetPtr; + ENVResource *p = ENVi_Search(name, &resSetPtr); + u16 len = 1; + + if (!p) { + return FALSE; + } + + if (p->type != ENV_RESTYPE_STRING) { + return FALSE; + } + + len = (u16)(p->len - ((p->type == ENV_RESTYPE_STRING) ? 1 : 0)); + OS_TPrintf("env str len = %d\n", len); + + + if (p->type & ENV_RESTYPE_OFFSET_MASK) + { + // return (void *)((u32)resSetPtr + (u32)(p->ptr)); + // (char *)((u32)resSetPtr + (u32)(p->ptr)) = val; + STD_CopyMemory( (void *)((u32)resSetPtr + (u32)(p->ptr)) , (void *)str, (u32)STD_StrLen(str) ); + } + else + { + // return p->ptr; + // (char *)p->ptr = val; + STD_CopyMemory( (void *)(p->ptr) , (void *)str , (u32)STD_StrLen(str) ); + } + return TRUE; +} + + + +BOOL ENV_SetU8(const char *name, u8 val) +{ + ENVResource *resSetPtr; + ENVResource *p = ENVi_Search(name, &resSetPtr); + u16 len; + + if (!p) { + return FALSE; + } + + len = (u16)(p->len - ((p->type == ENV_RESTYPE_STRING) ? 1 : 0)); + OS_TPrintf("env u8 len = %d\n", len); + + + // return p->ptr; + p->ptr = (u8 *)val; + return TRUE; +} + + + + +#if 0 +void SitedefsSetWepMode() +{ + ENVResource *ap_wepmode = ENV_Search("WiFi.LAN.1.AP.1.WEP.MODE"); /* U8 */ + "WiFi.LAN.1.AP.1.WEP.KEY" // BINARY -> ENV_GetBinary(const char *name, void **retPtr) + // BOOL ENV_GetBinaryAndSize(const char *name, void **retPtr, int *size) + + "WiFi.LAN.1.AP.1.ESSID" // STRING + static inline BOOL ENV_GetString(const char *name, char **retPtr) + static inline BOOL ENV_GetStringAndLength(const char *name, char **retPtr, int *len) +} +#endif + +/* *INDENT-OFF* */ +static ENVResource myResources[] = +{ + //----------------------------- + // LAN + //----------------------------- + + // LAN:Access Point 1 + // Demos in TwlWiFi use this settings by default. + { "WiFi.LAN.1.AP.1.ISVALID", ENV_BOOL ( TRUE ) }, + { "WiFi.LAN.1.AP.1.DESC", ENV_STRING( "Access Point for Demos" ) }, + { "WiFi.LAN.1.AP.1.ROUTERMODE", ENV_BOOL ( TRUE ) }, + { "WiFi.LAN.1.AP.1.ESSID", ENV_STRING( "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" ) }, /* 最大32バイト */ + { "WiFi.LAN.1.AP.1.BSSID", ENV_BINARY( "\xff\xff\xff\xff\xff\xff" ) }, + { "WiFi.LAN.1.AP.1.AUTHMODE", ENV_U32 ( WCM_OPTION_AUTH_OPENSYSTEM ) }, + { "WiFi.LAN.1.AP.1.WEP.MODE", ENV_U8 ( WCM_WEPMODE_NONE ) }, + { "WiFi.LAN.1.AP.1.WEP.KEYID", ENV_U8 ( 0 ) }, + { "WiFi.LAN.1.AP.1.WEP.KEY", /* 最大80バイト */ + ENV_BINARY("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") }, +#if 0 + // HOST with fixed address on the LAN.1.AP.1 + { "WiFi.LAN.1.AP.1.HOST.1.ISVALID", ENV_BOOL ( TRUE ) }, + { "WiFi.LAN.1.AP.1.HOST.1.NAME", ENV_STRING( "192.168.2.106" ) }, + { "WiFi.LAN.1.AP.1.HOST.1.NETMASK", ENV_STRING( "255.255.255.0" ) }, + { "WiFi.LAN.1.AP.1.HOST.1.GATEWAY", ENV_STRING( "192.168.2.1" ) }, + { "WiFi.LAN.1.AP.1.HOST.1.DNS1", ENV_STRING( "192.168.2.1" ) }, + { "WiFi.LAN.1.AP.1.HOST.1.DNS2", ENV_STRING( "0.0.0.0" ) }, +#else + // HOST with fixed address on the LAN.1.AP.1 + { "WiFi.LAN.1.AP.1.HOST.1.ISVALID", ENV_BOOL ( TRUE ) }, + { "WiFi.LAN.1.AP.1.HOST.1.NAME", ENV_STRING( "10.101.11.91" ) }, + { "WiFi.LAN.1.AP.1.HOST.1.NETMASK", ENV_STRING( "255.255.255.0" ) }, + { "WiFi.LAN.1.AP.1.HOST.1.GATEWAY", ENV_STRING( "10.101.11.230" ) }, + { "WiFi.LAN.1.AP.1.HOST.1.DNS1", ENV_STRING( "10.100.11.1" ) }, + { "WiFi.LAN.1.AP.1.HOST.1.DNS2", ENV_STRING( "10.100.11.5" ) }, + +#endif + // LAN:HTTP Server + { "WiFi.LAN.1.HTTP.1.ISVALID", ENV_BOOL ( TRUE ) }, + { "WiFi.LAN.1.HTTP.1.DESC", ENV_STRING( "linux server" ) }, + { "WiFi.LAN.1.HTTP.1.NAME", ENV_STRING( "192.168.2.2" ) }, + { "WiFi.LAN.1.HTTP.1.PORT.1", ENV_U16 ( 80 ) }, + + // LAN:ECHO Server + { "WiFi.LAN.1.ECHO.1.ISVALID", ENV_BOOL ( TRUE ) }, + { "WiFi.LAN.1.ECHO.1.DESC", ENV_STRING( "linux server" ) }, + { "WiFi.LAN.1.ECHO.1.NAME", ENV_STRING( "192.168.2.2" ) }, + { "WiFi.LAN.1.ECHO.1.PORT.1", ENV_U16 ( 7 ) }, + + // LAN:CHARGEN Server + { "WiFi.LAN.1.CHARGEN.1.ISVALID",ENV_BOOL ( TRUE ) }, + { "WiFi.LAN.1.CHARGEN.1.DESC", ENV_STRING( "linux server" ) }, + { "WiFi.LAN.1.CHARGEN.1.NAME", ENV_STRING( "192.168.2.2" ) }, + { "WiFi.LAN.1.CHARGEN.1.PORT.1", ENV_U16 ( 19 ) }, + + // LAN:Ping Taret + { "WiFi.LAN.1.PING.1.ISVALID", ENV_BOOL ( TRUE ) }, + { "WiFi.LAN.1.PING.1.DESC", ENV_STRING( "default gateway" ) }, + { "WiFi.LAN.1.PING.1.NAME", ENV_STRING( "192.168.2.1" ) }, + + // LAN:FTP Server + { "WiFi.LAN.1.FTP.1.ISVALID", ENV_BOOL ( TRUE ) }, + { "WiFi.LAN.1.FTP.1.DESC", ENV_STRING( "linux server" ) }, + { "WiFi.LAN.1.FTP.1.NAME", ENV_STRING( "192.168.2.2" ) }, + { "WiFi.LAN.1.FTP.1.PORT.1", ENV_U16 ( 21 ) }, + + //---- end mark + ENV_RESOURCE_END, +}; + +ENVResource* resourceArray[]= +{ + myResources, NULL +}; +/* *INDENT-ON* */ + +/*---------------------------------------------------------------------------* + Name: SiteDefs_Init + + Description: main + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void SiteDefs_Init(void) +{ + //---- declaration of using ENV system + //SDK と WIFI の両方に ENV ライブラリが入っているため、以下のように切り替える + //SDKがENVの旧versionを持っているなら、それに合わせて ENV_Init は昔版で。 +#if (SDK_VERSION_DATE <= 20050918) && (SDK_VERSION_DATE >= 20050908) + ENV_Init(myResources); +#else + //SDKにENVの旧versionは含まれていないので、それに合わせて ENV_Init は改良版で。 + ENV_Init(); +#endif +} + +/*====== End of sitedefs.c ======*/ diff --git a/build/tools/sctools/common/src/sitedefs.h b/build/tools/sctools/common/src/sitedefs.h new file mode 100644 index 0000000..fb5ffcd --- /dev/null +++ b/build/tools/sctools/common/src/sitedefs.h @@ -0,0 +1,38 @@ +/*---------------------------------------------------------------------------* + Project: TwlWiFi - demos - netconnect + File: sitedefs.h + + Copyright 2007 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:: 2008-07-14#$ + $Rev: 788 $ + $Author: adachi_hiroaki $ + *---------------------------------------------------------------------------*/ +#ifndef NITROWIFI_SITEDEFS_H_ +#define NITROWIFI_SITEDEFS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + +#define SITEDEFS_DEFAULTCLASS "WiFi.LAN.1.AP.1" +#define SITEDEFS_DEFAULTCLASS_FOR_TEST "WiFi.LAN.1.AP.1" +void SiteDefs_Init(void); +BOOL ENV_SetBinary(const char *name, void *ptr); +BOOL ENV_SetString(const char *name, char *str); +BOOL ENV_SetU8(const char *name, u8 val); + + + +#ifdef __cplusplus +} +#endif + +#endif // NITROWIFI_SITEDEFS_H_ diff --git a/build/tools/sctools/common/src/stream.c b/build/tools/sctools/common/src/stream.c new file mode 100644 index 0000000..834c49d --- /dev/null +++ b/build/tools/sctools/common/src/stream.c @@ -0,0 +1,398 @@ +#include +#include "stream.h" + + +#define MAKE_FOURCC(cc1, cc2, cc3, cc4) (u32)((cc1) | (cc2 << 8) | (cc3 << 16) | (cc4 << 24)) + +#define FOURCC_RIFF MAKE_FOURCC('R', 'I', 'F', 'F') +#define FOURCC_WAVE MAKE_FOURCC('W', 'A', 'V', 'E') +#define FOURCC_fmt MAKE_FOURCC('f', 'm', 't', ' ') +#define FOURCC_data MAKE_FOURCC('d', 'a', 't', 'a') + +#define L_CHANNEL 4 +#define R_CHANNEL 5 +#define ALARM_NUM 0 +#define STREAM_THREAD_PRIO 12 +#define THREAD_STACK_SIZE 1024 +#define STRM_BUF_PAGESIZE 1024*32 +#define STRM_BUF_SIZE STRM_BUF_PAGESIZE*2 + +// WAVフォーマットヘッダ +typedef struct WaveFormat +{ + u16 format; + u16 channels; + s32 sampleRate; + u32 dataRate; + u16 blockAlign; + u16 bitPerSample; +} +WaveFormat; + +// ストリームオブジェクト +typedef struct StreamInfo +{ + FSFile file; + WaveFormat format; + u32 beginPos; + s32 dataSize; + u32 bufPage; + BOOL isPlay; +} +StreamInfo; + +static BOOL ReadWaveFormat(StreamInfo * strm); +static void ReadStrmData(StreamInfo * strm); +static void SoundAlarmHandler(void *arg); +static void StrmThread(void *arg); +static void VBlankIntr(void); +static void PlayStream(StreamInfo * strm, const char *filename); +static void StopStream(StreamInfo * strm); + +static u16 Cont; +static u16 Trg; +static u64 strmThreadStack[THREAD_STACK_SIZE / sizeof(u64)]; +static OSThread strmThread; +static OSMessageQueue msgQ; +static OSMessage msgBuf[1]; + +static u8 strm_lbuf[STRM_BUF_SIZE] ATTRIBUTE_ALIGN(32); +static u8 strm_rbuf[STRM_BUF_SIZE] ATTRIBUTE_ALIGN(32); +static u8 strm_tmp[STRM_BUF_PAGESIZE * 2] ATTRIBUTE_ALIGN(32); + +// ファイル名 +//const char filename2[] = "kart_title.32.wav"; +const char filename1[] = "fanfare.32.wav"; + +static StreamInfo strm; + +void stream_main(void) +{ + strm.isPlay = FALSE; + SND_LockChannel((1 << L_CHANNEL) | (1 << R_CHANNEL), 0); + + /* ストリームスレッドの起動 */ + OS_CreateThread(&strmThread, + StrmThread, + NULL, + strmThreadStack + THREAD_STACK_SIZE / sizeof(u64), + THREAD_STACK_SIZE, STREAM_THREAD_PRIO); + OS_WakeupThreadDirect(&strmThread); +} + +void stream_play1(void) +{ + PlayStream(&strm, filename1); +} + +BOOL stream_is_play1_end(void) +{ + if (strm.dataSize <= 0) { + return TRUE; + } + return FALSE; +} + + + +static void PlayStream(StreamInfo * strm, const char *filename) +{ + int timerValue; + u32 alarmPeriod; + + // 再生中であれば停止する +OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + + + if (strm->isPlay) + { + u32 tag; + StopStream(strm); + tag = SND_GetCurrentCommandTag(); + (void)SND_FlushCommand(SND_COMMAND_NOBLOCK | SND_COMMAND_IMMEDIATE); + SND_WaitForCommandProc(tag); // 停止を待つ + } + + // ファイル走査 + if (FS_IsFile(&strm->file)) + (void)FS_CloseFile(&strm->file); + if ( ! FS_OpenFile(&strm->file, filename) ) { + OS_Panic("Error: failed to open file %s\n", filename); + } + if (!ReadWaveFormat(strm)) + { + OS_Panic("Error: failed to read wavefile\n"); + } + + strm->isPlay = TRUE; + + /* パラメータ設定 */ + timerValue = SND_TIMER_CLOCK / strm->format.sampleRate; + alarmPeriod = timerValue * STRM_BUF_PAGESIZE / 32U; + alarmPeriod /= (strm->format.bitPerSample == 16) ? sizeof(s16) : sizeof(s8); + + // 初期ストリームデータ読み込み + (void)FS_SeekFile(&strm->file, (s32)strm->beginPos, FS_SEEK_SET); + strm->bufPage = 0; + ReadStrmData(strm); + ReadStrmData(strm); + + // チャンネルとアラームをセットアップ + SND_SetupChannelPcm(L_CHANNEL, + (strm->format.bitPerSample == + 16) ? SND_WAVE_FORMAT_PCM16 : SND_WAVE_FORMAT_PCM8, strm_lbuf, + SND_CHANNEL_LOOP_REPEAT, 0, STRM_BUF_SIZE / sizeof(u32), 127, + SND_CHANNEL_DATASHIFT_NONE, timerValue, 0); + SND_SetupChannelPcm(R_CHANNEL, + (strm->format.bitPerSample == + 16) ? SND_WAVE_FORMAT_PCM16 : SND_WAVE_FORMAT_PCM8, + (strm->format.channels == 1) ? strm_lbuf : strm_rbuf, + SND_CHANNEL_LOOP_REPEAT, 0, STRM_BUF_SIZE / sizeof(u32), 127, + SND_CHANNEL_DATASHIFT_NONE, timerValue, 127); + SND_SetupAlarm(ALARM_NUM, alarmPeriod, alarmPeriod, SoundAlarmHandler, strm); + SND_StartTimer((1 << L_CHANNEL) | (1 << R_CHANNEL), 0, 1 << ALARM_NUM, 0); +} + +/*---------------------------------------------------------------------------* + Name: StopStream + + Description: ストリーム再生を停止 + + Arguments: strm - ストリームオブジェクト + + Returns: None. + *---------------------------------------------------------------------------*/ +static void StopStream(StreamInfo * strm) +{ + SND_StopTimer((1 << L_CHANNEL) | (1 << R_CHANNEL), 0, 1 << ALARM_NUM, 0); + if (FS_IsFile(&strm->file)) + (void)FS_CloseFile(&strm->file); + strm->isPlay = FALSE; +} + +/*---------------------------------------------------------------------------* + Name: StrmThread + + Description: ストリームスレッド + + Arguments: arg - ユーザーデータ(未使用) + + Returns: None. + *---------------------------------------------------------------------------*/ +static void StrmThread(void * /*arg */ ) +{ + OSMessage message; + + OS_InitMessageQueue(&msgQ, msgBuf, 1); + + while (1) + { + (void)OS_ReceiveMessage(&msgQ, &message, OS_MESSAGE_BLOCK); + (void)ReadStrmData((StreamInfo *) message); + } +} + +/*---------------------------------------------------------------------------* + Name: SoundAlarmHandler + + Description: アラームコールバック関数 + + Arguments: arg - ストリームオブジェクト + + Returns: None. + *---------------------------------------------------------------------------*/ +static void SoundAlarmHandler(void *arg) +{ + (void)OS_SendMessage(&msgQ, (OSMessage)arg, OS_MESSAGE_NOBLOCK); +} + +/*---------------------------------------------------------------------------* + Name: ReadStrmData + + Description: ストリームデータ読み込み関数 + ファイルからバッファの1ページ分のストリームデータを読み込む + + Arguments: strm - ストリームオブジェクト + + Returns: None. + *---------------------------------------------------------------------------*/ +static void ReadStrmData(StreamInfo * strm) +{ + int i; + s32 readSize; + u8 *lbuf, *rbuf; + + // ストリームが終端に達している + if (strm->dataSize <= 0) + { + StopStream(strm); + // OS_TPrintf("Stop stream\n"); + return; + } + + // バッファのページ設定 + if (strm->bufPage == 0) + { + lbuf = strm_lbuf; + rbuf = strm_rbuf; + strm->bufPage = 1; + } + else + { + lbuf = strm_lbuf + STRM_BUF_PAGESIZE; + rbuf = strm_rbuf + STRM_BUF_PAGESIZE; + strm->bufPage = 0; + } + + // データ読み込み + if (strm->format.channels == 1) + { + // モノラル + readSize = FS_ReadFile(&strm->file, + strm_tmp, + (strm->dataSize < + STRM_BUF_PAGESIZE) ? strm->dataSize : STRM_BUF_PAGESIZE); + if (readSize == -1) + OS_Panic("read file end\n"); + + if (strm->format.bitPerSample == 16) + { + // 16bitデータ + for (i = 0; i < readSize / sizeof(s16); i++) + { + ((s16 *)lbuf)[i] = ((s16 *)strm_tmp)[i]; + } + for (; i < STRM_BUF_PAGESIZE / sizeof(s16); i++) + { + ((s16 *)lbuf)[i] = 0; // ストリームの終端に達した場合、残りを0で埋める + } + } + else + { + // 8bitデータ + for (i = 0; i < readSize / sizeof(s8); i++) + { + ((s8 *)lbuf)[i] = (s8)((s16)strm_tmp[i] - 128); + } + for (; i < STRM_BUF_PAGESIZE / sizeof(s8); i++) + { + ((s8 *)lbuf)[i] = 0; + } + } + } + else + { + // ステレオ + readSize = FS_ReadFile(&strm->file, + strm_tmp, + (strm->dataSize < + STRM_BUF_PAGESIZE * 2) ? strm->dataSize : STRM_BUF_PAGESIZE * 2); + if (readSize == -1) + OS_Panic("read file end\n"); + + if (strm->format.bitPerSample == 16) + { + // 16bitデータ + for (i = 0; i < (readSize / 2) / sizeof(s16); i++) + { + ((s16 *)lbuf)[i] = ((s16 *)strm_tmp)[2 * i]; + ((s16 *)rbuf)[i] = ((s16 *)strm_tmp)[2 * i + 1]; + } + for (; i < STRM_BUF_PAGESIZE / sizeof(s16); i++) + { + ((s16 *)lbuf)[i] = 0; + ((s16 *)rbuf)[i] = 0; + } + } + else + { + // 8bitデータ + for (i = 0; i < (readSize / 2) / sizeof(s8); i++) + { + ((s8 *)lbuf)[i] = (s8)((s16)strm_tmp[2 * i] - 128); + ((s8 *)rbuf)[i] = (s8)((s16)strm_tmp[2 * i + 1] - 128); + } + for (; i < STRM_BUF_PAGESIZE / sizeof(s8); i++) + { + ((s8 *)lbuf)[i] = 0; + ((s8 *)rbuf)[i] = 0; + } + } + } + + strm->dataSize -= readSize; + + return; +} + + +/*---------------------------------------------------------------------------* + Name: ReadWaveFormat + + Description: WAVEフォーマットのデータのヘッダとデータ列の先頭位置、データサイズを取得 + + Arguments: strm - ストリームオブジェクト + + Returns: 読み取りに成功したらTRUE、失敗したらFALSE + *---------------------------------------------------------------------------*/ +static BOOL ReadWaveFormat(StreamInfo * strm) +{ + u32 tag; + s32 size; + BOOL fFmt = FALSE, fData = FALSE; + + (void)FS_SeekFileToBegin(&strm->file); + + (void)FS_ReadFile(&strm->file, &tag, 4); + if (tag != FOURCC_RIFF) + return FALSE; + + (void)FS_ReadFile(&strm->file, &size, 4); + + (void)FS_ReadFile(&strm->file, &tag, 4); + if (tag != FOURCC_WAVE) + return FALSE; + + while (size > 0) + { + s32 chunkSize; + if (FS_ReadFile(&strm->file, &tag, 4) == -1) + { + return FALSE; + } + if (FS_ReadFile(&strm->file, &chunkSize, 4) == -1) + { + return FALSE; + } + + switch (tag) + { + case FOURCC_fmt: + if (FS_ReadFile(&strm->file, (u8 *)&strm->format, chunkSize) == -1) + { + return FALSE; + } + fFmt = TRUE; + break; + case FOURCC_data: + strm->beginPos = FS_GetPosition(&strm->file); + strm->dataSize = chunkSize; + (void)FS_SeekFile(&strm->file, chunkSize, FS_SEEK_CUR); + fData = TRUE; + break; + default: + (void)FS_SeekFile(&strm->file, chunkSize, FS_SEEK_CUR); + break; + } + if (fFmt && fData) + { + return TRUE; // fmt と data を読み終えたら強制終了 + } + + size -= chunkSize; + } + + if (size != 0) + return FALSE; + return TRUE; +} diff --git a/build/tools/sctools/common/src/stream.h b/build/tools/sctools/common/src/stream.h new file mode 100644 index 0000000..50a7f86 --- /dev/null +++ b/build/tools/sctools/common/src/stream.h @@ -0,0 +1,18 @@ +#ifndef _STREAM_H_ +#define _STREAM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + +extern void channel_play(void); +extern void stream_main(void); +extern void stream_play1(void); +extern BOOL stream_is_play1_end(void); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* _STREAM_H_ */ diff --git a/build/tools/sctools/common/src/string_map_dwc_apinfo_type.inc b/build/tools/sctools/common/src/string_map_dwc_apinfo_type.inc new file mode 100644 index 0000000..f7d2576 --- /dev/null +++ b/build/tools/sctools/common/src/string_map_dwc_apinfo_type.inc @@ -0,0 +1,9 @@ +{ DWC_APINFO_TYPE_USER0, "USER 1" }, +{ DWC_APINFO_TYPE_USER1, "USER 2" }, +{ DWC_APINFO_TYPE_USER2, "USER 3" }, +{ DWC_APINFO_TYPE_USER3, "USER 4" }, +{ DWC_APINFO_TYPE_USER4, "USER 5" }, +{ DWC_APINFO_TYPE_USER5, "USER 6" }, +{ DWC_APINFO_TYPE_USB, "NINTENDO-USBAP" }, +{ DWC_APINFO_TYPE_SHOP, "Wi-Fi STATION" }, +{ DWC_APINFO_TYPE_FREESPOT, "FREESPOT" }, diff --git a/build/tools/sctools/common/src/string_map_ec_error.inc b/build/tools/sctools/common/src/string_map_ec_error.inc new file mode 100644 index 0000000..d90190e --- /dev/null +++ b/build/tools/sctools/common/src/string_map_ec_error.inc @@ -0,0 +1,81 @@ +{ EC_ERROR_AGE_RESTRICTED, "EC_ERROR_AGE_RESTRICTED" }, +{ EC_ERROR_ALREADY, "EC_ERROR_ALREADY" }, +{ EC_ERROR_ALREADY_OWN, "EC_ERROR_ALREADY_OWN" }, +{ EC_ERROR_BUSY, "EC_ERROR_BUSY" }, +{ EC_ERROR_CANCELED, "EC_ERROR_CANCELED" }, +{ EC_ERROR_CANCEL_FAILED, "EC_ERROR_CANCEL_FAILED" }, +{ EC_ERROR_CERT_CHAIN, "EC_ERROR_CERT_CHAIN" }, +{ EC_ERROR_CFG_HOME_INODE, "EC_ERROR_CFG_HOME_INODE" }, +{ EC_ERROR_CFG_HOME_SPACE, "EC_ERROR_CFG_HOME_SPACE" }, +{ EC_ERROR_CFG_USER_INODE, "EC_ERROR_CFG_USER_INODE" }, +{ EC_ERROR_CFG_USER_SPACE, "EC_ERROR_CFG_USER_SPACE" }, +{ EC_ERROR_CONFIG, "EC_ERROR_CONFIG" }, +{ EC_ERROR_CONNECT, "EC_ERROR_CONNECT" }, +{ EC_ERROR_CONTENT_SIZE, "EC_ERROR_CONTENT_SIZE" }, +{ EC_ERROR_DEVICE_KEY_PAIR, "EC_ERROR_DEVICE_KEY_PAIR" }, +{ EC_ERROR_ECARD, "EC_ERROR_ECARD" }, +{ EC_ERROR_EULA, "EC_ERROR_EULA" }, +{ EC_ERROR_FAIL, "EC_ERROR_FAIL" }, +{ EC_ERROR_FILE_READ, "EC_ERROR_FILE_READ" }, +{ EC_ERROR_FILE_WRITE, "EC_ERROR_FILE_WRITE" }, +{ EC_ERROR_FIRMWARE, "EC_ERROR_FIRMWARE" }, +{ EC_ERROR_HTTP_HDR_PARSE, "EC_ERROR_HTTP_HDR_PARSE" }, +{ EC_ERROR_INIT, "EC_ERROR_INIT" }, +{ EC_ERROR_INSUFFICIENT_FUNDS, "EC_ERROR_INSUFFICIENT_FUNDS" }, +{ EC_ERROR_INSUFICIENT_RESOURCE, "EC_ERROR_INSUFICIENT_RESOURCE" }, +{ EC_ERROR_INVALID, "EC_ERROR_INVALID" }, +{ EC_ERROR_INVALID_PCPW, "EC_ERROR_INVALID_PCPW" }, +{ EC_ERROR_NAND, "EC_ERROR_NAND" }, +{ EC_ERROR_NET_CONTENT, "EC_ERROR_NET_CONTENT" }, +{ EC_ERROR_NET_NA, "EC_ERROR_NET_NA" }, +{ EC_ERROR_NHTTP_AHF, "EC_ERROR_NHTTP_AHF" }, +{ EC_ERROR_NHTTP_CRX, "EC_ERROR_NHTTP_CRX" }, +{ EC_ERROR_NHTTP_PDE, "EC_ERROR_NHTTP_PDE" }, +{ EC_ERROR_NHTTP_PDR, "EC_ERROR_NHTTP_PDR" }, +{ EC_ERROR_NHTTP_SCA, "EC_ERROR_NHTTP_SCA" }, +{ EC_ERROR_NHTTP_SCCD, "EC_ERROR_NHTTP_SCCD" }, +{ EC_ERROR_NHTTP_SMO, "EC_ERROR_NHTTP_SMO" }, +{ EC_ERROR_NHTTP_SRA, "EC_ERROR_NHTTP_SRA" }, +{ EC_ERROR_NHTTP_SRCD, "EC_ERROR_NHTTP_SRCD" }, +{ EC_ERROR_NHTTP_SVO, "EC_ERROR_NHTTP_SVO" }, +{ EC_ERROR_NOMEM, "EC_ERROR_NOMEM" }, +{ EC_ERROR_NOT_ACTIVE, "EC_ERROR_NOT_ACTIVE" }, +{ EC_ERROR_NOT_BUSY, "EC_ERROR_NOT_BUSY" }, +{ EC_ERROR_NOT_DONE, "EC_ERROR_NOT_DONE" }, +{ EC_ERROR_NOT_FOUND, "EC_ERROR_NOT_FOUND" }, +{ EC_ERROR_NOT_OWNED, "EC_ERROR_NOT_OWNED" }, +{ EC_ERROR_NOT_SUPPORTED, "EC_ERROR_NOT_SUPPORTED" }, +{ EC_ERROR_NO_DEVICE_CODE, "EC_ERROR_NO_DEVICE_CODE" }, +{ EC_ERROR_NO_DEVICE_KEY_PAIR, "EC_ERROR_NO_DEVICE_KEY_PAIR" }, +{ EC_ERROR_NO_TMD, "EC_ERROR_NO_TMD" }, +{ EC_ERROR_OK, "EC_ERROR_OK" }, +{ EC_ERROR_OVERFLOW, "EC_ERROR_OVERFLOW" }, +{ EC_ERROR_PC_DISABLED, "EC_ERROR_PC_DISABLED" }, +{ EC_ERROR_POINTS_RESTRICTED, "EC_ERROR_POINTS_RESTRICTED" }, +{ EC_ERROR_RANGE_END, "EC_ERROR_RANGE_END" }, +{ EC_ERROR_RANGE_START, "EC_ERROR_RANGE_START" }, +{ EC_ERROR_REGISTER, "EC_ERROR_REGISTER" }, +{ EC_ERROR_SHOP_SETUP, "EC_ERROR_SHOP_SETUP" }, +{ EC_ERROR_SYNC, "EC_ERROR_SYNC" }, +{ EC_ERROR_SYS_BLOCKS, "EC_ERROR_SYS_BLOCKS" }, +{ EC_ERROR_SYS_INODES, "EC_ERROR_SYS_INODES" }, +{ EC_ERROR_TICKET, "EC_ERROR_TICKET" }, +{ EC_ERROR_TITLE, "EC_ERROR_TITLE" }, +{ EC_ERROR_TITLE_CONTENT, "EC_ERROR_TITLE_CONTENT" }, +{ EC_ERROR_USER_BLOCKS, "EC_ERROR_USER_BLOCKS" }, +{ EC_ERROR_USER_INODES, "EC_ERROR_USER_INODES" }, +{ EC_ERROR_WS_RECV, "EC_ERROR_WS_RECV" }, +{ EC_ERROR_WS_REPORT, "EC_ERROR_WS_REPORT" }, +{ EC_ERROR_WS_RESP, "EC_ERROR_WS_RESP" }, +{ EC_ES_ERROR_END, "EC_ES_ERROR_END" }, +{ EC_ES_ERROR_START, "EC_ES_ERROR_START" }, +{ EC_HTTP_STATUS_RANGE_END, "EC_HTTP_STATUS_RANGE_END" }, +{ EC_HTTP_STATUS_RANGE_START, "EC_HTTP_STATUS_RANGE_START" }, +{ EC_ISFS_ERROR_END, "EC_ISFS_ERROR_END" }, +{ EC_ISFS_ERROR_START, "EC_ISFS_ERROR_START" }, +{ EC_NHTTP_APIERR_RANGE_END, "EC_NHTTP_APIERR_RANGE_END" }, +{ EC_NHTTP_APIERR_RANGE_START, "EC_NHTTP_APIERR_RANGE_START" }, +{ EC_NHTTP_ERROR_RANGE_END, "EC_NHTTP_ERROR_RANGE_END" }, +{ EC_NHTTP_ERROR_RANGE_START, "EC_NHTTP_ERROR_RANGE_START" }, +{ EC_SSL_ERROR_RANGE_END, "EC_SSL_ERROR_RANGE_END" }, +{ EC_SSL_ERROR_RANGE_START, "EC_SSL_ERROR_RANGE_START" }, diff --git a/build/tools/sctools/common/src/string_map_ec_op.inc b/build/tools/sctools/common/src/string_map_ec_op.inc new file mode 100644 index 0000000..2142f2d --- /dev/null +++ b/build/tools/sctools/common/src/string_map_ec_op.inc @@ -0,0 +1,31 @@ +{ EC_OP_Invalid, "EC_OP_Invalid" }, +{ EC_OP_PurchaseTitle, "EC_OP_PurchaseTitle" }, +{ EC_OP_Unused1, "EC_OP_Unused1" }, +{ EC_OP_SyncTickets, "EC_OP_SyncTickets" }, +{ EC_OP_RefreshCachedBalance, "EC_OP_RefreshCachedBalance" }, +{ EC_OP_PurchasePoints, "EC_OP_PurchasePoints" }, +{ EC_OP_GetTitle, "EC_OP_GetTitle" }, +{ EC_OP_GenerateKeyPair, "EC_OP_GenerateKeyPair" }, +{ EC_OP_ConfirmKeyPair, "EC_OP_ConfirmKeyPair" }, +{ EC_OP_CheckRegistration, "EC_OP_CheckRegistration" }, +{ EC_OP_Register, "EC_OP_Register" }, +{ EC_OP_Unregister, "EC_OP_Unregister" }, +{ EC_OP_Transfer, "EC_OP_Transfer" }, +{ EC_OP_DeleteOwnership, "EC_OP_DeleteOwnership" }, +{ EC_OP_PurchaseGiftTitle, "EC_OP_PurchaseGiftTitle" }, +{ EC_OP_AcceptGiftTitle, "EC_OP_AcceptGiftTitle" }, +{ EC_OP_CheckDeviceStatus, "EC_OP_CheckDeviceStatus" }, +{ EC_OP_SyncRegistration, "EC_OP_SyncRegistration" }, +{ EC_OP_Connect, "EC_OP_Connect" }, +{ EC_OP_DownloadContents, "EC_OP_DownloadContents" }, +{ EC_OP_Subscribe, "EC_OP_Subscribe" }, +{ EC_OP_GetChallenge, "EC_OP_GetChallenge" }, +{ EC_OP_UpdateStatus, "EC_OP_UpdateStatus" }, +{ EC_OP_ListTitles, "EC_OP_ListTitles" }, +{ EC_OP_ListContentSets, "EC_OP_ListContentSets" }, +{ EC_OP_ListSubscriptionPricings, "EC_OP_ListSubscriptionPricings" }, +{ EC_OP_ListPointsPricings, "EC_OP_ListPointsPricings" }, +{ EC_OP_ListECardItems, "EC_OP_ListECardItems" }, +{ EC_OP_ListTitleContents, "EC_OP_ListTitleContents" }, +{ EC_OP_GetTitleResourceRequirement, "EC_OP_GetTitleResourceRequirement" }, +{ EC_OP_GetContentsResourceRequirement, "EC_OP_GetContentsResourceRequirement" }, diff --git a/build/tools/sctools/common/src/string_map_ec_phase.inc b/build/tools/sctools/common/src/string_map_ec_phase.inc new file mode 100644 index 0000000..14309f0 --- /dev/null +++ b/build/tools/sctools/common/src/string_map_ec_phase.inc @@ -0,0 +1,32 @@ +{ EC_PHASE_NoPhase, "EC_PHASE_NoPhase" }, +{ EC_PHASE_Starting, "EC_PHASE_Starting" }, +{ EC_PHASE_Done, "EC_PHASE_Done" }, +{ EC_PHASE_PurchasingTitle, "EC_PHASE_PurchasingTitle" }, +{ EC_PHASE_Unused1, "EC_PHASE_Unused1" }, +{ EC_PHASE_DownloadingContent, "EC_PHASE_DownloadingContent" }, +{ EC_PHASE_GettingTicketsFromServer, "EC_PHASE_GettingTicketsFromServer" }, +{ EC_PHASE_GettingPointsBalance, "EC_PHASE_GettingPointsBalance" }, +{ EC_PHASE_PurchasingPoints, "EC_PHASE_PurchasingPoints" }, +{ EC_PHASE_GeneratingKeyPair, "EC_PHASE_GeneratingKeyPair" }, +{ EC_PHASE_ConfirmingKeyPair, "EC_PHASE_ConfirmingKeyPair" }, +{ EC_PHASE_CheckingRegistrationStatus, "EC_PHASE_CheckingRegistrationStatus" }, +{ EC_PHASE_Registering, "EC_PHASE_Registering" }, +{ EC_PHASE_Unregistering, "EC_PHASE_Unregistering" }, +{ EC_PHASE_Transfer, "EC_PHASE_Transfer" }, +{ EC_PHASE_DeletingOwnership, "EC_PHASE_DeletingOwnership" }, +{ EC_PHASE_AcceptingGiftTitle, "EC_PHASE_AcceptingGiftTitle" }, +{ EC_PHASE_GettingDeviceStatus, "EC_PHASE_GettingDeviceStatus" }, +{ EC_PHASE_SyncingRegistration, "EC_PHASE_SyncingRegistration" }, +{ EC_PHASE_Connecting, "EC_PHASE_Connecting" }, +{ EC_PHASE_UpdatingStatus, "EC_PHASE_UpdatingStatus" }, +{ EC_PHASE_ListingTitles, "EC_PHASE_ListingTitles" }, +{ EC_PHASE_ListingContentSets, "EC_PHASE_ListingContentSets" }, +{ EC_PHASE_ListingSubscriptionPricings, "EC_PHASE_ListingSubscriptionPricings" }, +{ EC_PHASE_ListingPointsPricings, "EC_PHASE_ListingPointsPricings" }, +{ EC_PHASE_ListingECardItems, "EC_PHASE_ListingECardItems" }, +{ EC_PHASE_GettingECardBalance, "EC_PHASE_GettingECardBalance" }, +{ EC_PHASE_Subscribing, "EC_PHASE_Subscribing" }, +{ EC_PHASE_GettingChallenge, "EC_PHASE_GettingChallenge" }, +{ EC_PHASE_ListingTitleContents, "EC_PHASE_ListingTitleContents" }, +{ EC_PHASE_GettingTitleResourceRequirement, "EC_PHASE_GettingTitleResourceRequirement" }, +{ EC_PHASE_GettingContentsResourceRequirement, "EC_PHASE_GettingContentsResourceRequirement" }, diff --git a/build/tools/sctools/common/src/text.c b/build/tools/sctools/common/src/text.c new file mode 100644 index 0000000..0aeee17 --- /dev/null +++ b/build/tools/sctools/common/src/text.c @@ -0,0 +1,412 @@ + +#include +#include "text.h" + +#define TAB_SIZE 8 +/*****************************************************/ + +static LINE_BUF *lb_free_ptr; +static int x_size = X_LINE_MAX; +static int y_size = Y_LINE_MAX; + +void text_display_newline_on(TEXT_CTRL *tc) +{ + tc->text_buf.display_newline = 1; +} + +void text_display_newline_off(TEXT_CTRL *tc) +{ + tc->text_buf.display_newline = 0; +} + + +static void link_line_buf(LINE_BUF *m,LINE_BUF *s) +{ + if( m->next != NULL ) { + s->next = m->next; + (s->next)->prev = s; + } + else + s->next = NULL; + + m->next = s; + s->prev = m; +} + +static void unlink_line_buf(LINE_BUF *s) +{ + if( (s->prev != NULL ) && (s->next != NULL) ) { + (s->prev)->next = s->next; + (s->next)->prev = s->prev; + s->next = NULL; + s->prev = NULL; + } + else if( s->next != NULL) { + s->prev = NULL; + (s->next)->prev = NULL; + s->next = NULL; + } + else if( s->prev != NULL ) { + s->next = NULL; + (s->prev)->next = NULL; + s->prev = NULL; + } +} + +static LINE_BUF *alloc_line_buf(void) +{ + LINE_BUF *tmp; + if( lb_free_ptr == NULL ) { + OS_TPrintf("Error: %s %d\n",__FUNCTION__,__LINE__); + return NULL; + } + if( lb_free_ptr->next == NULL ) { + OS_TPrintf("Error: %s %d\n",__FUNCTION__,__LINE__); + return NULL; + } + tmp = lb_free_ptr; + lb_free_ptr = lb_free_ptr->next; + unlink_line_buf(tmp); + tmp->last_count = 0; + tmp->cur_count = 0; +#if 0 + for(i = 0 ; i < LINE_BUF_X_SIZE ; i++) + tmp->buf[i] = 0x20; +#endif + return(tmp); +} + +static void free_line_buf(LINE_BUF *lb) +{ + lb->next = lb_free_ptr; + lb->prev = NULL; + (lb->next)->prev = lb; + lb_free_ptr = lb; +} + +static int init_lb_heap(void *heap_start, void *heap_end) +{ + int i; + LINE_BUF *lb_heap=(LINE_BUF *)heap_start; + lb_free_ptr = (LINE_BUF *)heap_start; + lb_heap[0].prev = NULL; + + i = 0; + while( (u32)&(lb_heap[i+1]) < (u32)heap_end ) { + link_line_buf(&(lb_heap[i]), &(lb_heap[i+1])); + i++; + } + lb_heap[i].next = NULL; + return i; /* num of line buffer */ +#if 0 + OS_Printf("text_heap s %08x\n",(u32)heap_start); + OS_Printf("text_heap e %08x\n",(u32)heap_end); +#endif + +} + +static void init_text_buf(TEXT_BUF *tb) +{ + tb->num_y = &y_size; + tb->num_x = &x_size; + tb->virtual_x = LINE_BUF_X_SIZE - X_LINE_MAX - 1; + tb->virtual_y = Y_LINE_MAX * 4; + tb->start = tb->cur = alloc_line_buf(); + tb->display_offset_y = 0; + tb->display_offset_x = 0; +} + + +void init_text(TEXT_CTRL *tc, u16 *screen, u16 palette) +{ + tc->screen = screen; + tc->x_line = 0; + tc->y_line = 0; + tc->palette = palette; + init_text_buf(&(tc->text_buf)); +} + + + /* + 0 -> black + 1 -> red + 2 -> green + 3 -> blue + 4 -> yellow + 5 -> purple + 6 -> sky blue + 7 -> red + 8 -> green + 9 -> blue + 0xA -> yellow + 0xB -> purple + 0xC -> sky blue + 0xD -> white + 0xE -> white + 0xF -> white + + */ + +void m_set_palette(TEXT_CTRL *tc, u16 num) +{ + tc->palette = (u16)(0x0f & num); +} + +u16 m_get_palette(TEXT_CTRL *tc) +{ + return tc->palette; +} + +void m_set_display_offset_x(TEXT_CTRL *tc, int offset) +{ + TEXT_BUF *tb = &(tc->text_buf); + if( ( offset >= 0 ) && (offset < tb->virtual_x) ) { + tb->display_offset_x = offset; + } +} + +int m_get_display_offset_x(TEXT_CTRL *tc) +{ + TEXT_BUF *tb = &(tc->text_buf); + return tb->display_offset_x; +} + +void m_set_display_offset_y(TEXT_CTRL *tc, int offset) +{ + TEXT_BUF *tb = &(tc->text_buf); + if( ( offset >= 0 ) && (offset < tb->virtual_y) ) { + tb->display_offset_y = offset; + } +} + +int m_get_display_offset_y(TEXT_CTRL *tc) +{ + TEXT_BUF *tb = &(tc->text_buf); + return tb->display_offset_y; +} + +static void clear_line(TEXT_CTRL *tc) +{ + int i; + i = tc->x_line; + + for( ; i < X_LINE_MAX ; i++) + tc->screen[(tc->y_line * X_LINE_MAX ) + i] = 0; + +} + +static void add_y_line(TEXT_CTRL *tc,u16 num) +{ + tc->y_line += num; + if( tc->y_line > Y_LINE_MAX ) { + tc->y_line = 0; + } +} + +static void add_x_line(TEXT_CTRL *tc,u16 num) +{ + tc->x_line += num; + + if( tc->x_line > X_LINE_MAX ) { + tc->x_line = 0; + tc->y_line++; + if( tc->y_line > Y_LINE_MAX ) { + tc->y_line = 0; + } + } +} + +static void put_char_vram(TEXT_CTRL *tc, int c, u16 col) +{ + + switch( c ) { + case '\0': + break; + case '\n': + clear_line(tc); + tc->x_line = 0; + add_y_line(tc, 1 ); + break; + case '\r': + tc->x_line = 0; + break; + case '\t': + add_x_line(tc, TAB_SIZE ); + break; + case '\f': + tc->x_line = 0; + tc->y_line = 0; + clear_line(tc); + break; + case '\b': /* Back Space */ + case '\v': /* Vertical Tab */ + break; + default: + if( ( c < 0x20 ) || ( 0x7f < c ) ) + c = 0x20; /* white space */ + tc->screen[(tc->y_line * X_LINE_MAX ) + tc->x_line] = (u16)((col << 12) | (0x00ff & c)); + add_x_line(tc, 1 ); + } +} + +/**********************/ + +void m_putchar(TEXT_CTRL *tc, int c) +{ + int i; + LINE_BUF *tmp; + TEXT_BUF *tb = &(tc->text_buf); + + switch( c ) { + case '\0': + break; + case '\n': + if( tb->cur->next == NULL ) { + tmp = tb->cur; /* 表示開始バッファを再計算 */ + for(i = 0 ; (i < *(tb->num_y)-1) && (i < LINE_BUF_Y_SIZE) ; i++) { + if( tmp->prev == NULL ) + break; + tmp = tmp->prev; + } + tb->start = tmp; /* 表示開始バッファ */ + + /* いらないバッファを解放、ただし保存用バーチャル分は残す */ + i = 0; + while(tmp->prev != NULL) { + tmp = tmp->prev; + i++; + if( i > tb->virtual_y-1 ) { + unlink_line_buf( tmp ); + free_line_buf( tmp ); + } + } + + tmp = alloc_line_buf(); /* バッファを1つ取得 */ + if( tmp == NULL ) { + /* ラインバッファがない */ + OS_TPrintf("Free line buffer shortage!!\n"); + return; + } + link_line_buf(tb->cur, tmp); /* 取得したバッファをカレント + バッファの次にリンク */ + tb->cur = tmp; /* カレントバッファを更新 */ + tb->cur->cur_count = 0; + tb->cur->last_count = 0; + } + else { + tb->cur = tb->cur->next; + tb->cur->cur_count = 0; + tb->cur->last_count = 0; + } + break; + case '\r': + tb->cur->cur_count = 0; + break; + case '\t': + tb->cur->cur_count += TAB_SIZE; + if( tb->cur->cur_count > LINE_BUF_X_SIZE ) + tb->cur->cur_count = LINE_BUF_X_SIZE; + if( tb->cur->cur_count > tb->cur->last_count ) + tb->cur->last_count = tb->cur->cur_count; + break; + case '\f': + tb->cur = tb->start; + tb->cur->cur_count = 0; + tb->cur->last_count = 0; + break; + case '\a': /* BELL */ + break; + case '\b': /* Back Space */ + if( tb->cur->cur_count > 0 ) + tb->cur->cur_count--; + break; + case '\v': /* Vertical Tab */ + break; + default: + if( tb->cur->cur_count >= LINE_BUF_X_SIZE ) { + /* add 2008.08.14 */ + /* ラインバッファをオーバーした時の挙動 */ + if( tb->display_newline == 0 ) { + /* 表示しない */ + break; + } + else { + /* 改行して表示する */ + m_putchar(tc, '\n'); + } + } + tb->cur->buf[tb->cur->cur_count] = c; + tb->cur->col[tb->cur->cur_count] = tc->palette; + tb->cur->cur_count++; + if( tb->cur->cur_count > LINE_BUF_X_SIZE ) { + tb->cur->cur_count = LINE_BUF_X_SIZE; + break; + } + if( tb->cur->cur_count > tb->cur->last_count ) + tb->cur->last_count = tb->cur->cur_count; + break; + } +} + + +int init_text_buf_sys(void *heap_start, void *heap_end) +{ + return init_lb_heap(heap_start, heap_end); +} + + +void text_buf_to_vram(TEXT_CTRL *tc) +{ + int x_line,line_no; + int c; + u16 col; + int i; + LINE_BUF *lb; + TEXT_BUF *tb = &(tc->text_buf); + + lb = tb->start; + i = 0; + while( i < tb->display_offset_y ) { + if( lb->prev == NULL ) { + break; + } + lb = lb->prev; + i++; + } + + + put_char_vram(tc, '\f', (u16)0); + + for(line_no = 0 ; line_no < (*tb->num_y + 1) ; line_no++ ){ + //miya x_line = 0; + x_line = tb->display_offset_x; + + if( lb == NULL) + break; + while( x_line < lb->last_count ) { + //miya 2008.09.10 + // if( x_line >= (*tb->num_x + 1)) { + if( x_line >= (*tb->num_x + 1 + tb->display_offset_x)) { + break; + } + else { + c = lb->buf[x_line]; + col = lb->col[x_line]; + put_char_vram(tc, c, col); + } + x_line++; + } + //miya 2008.09.10 + // if( x_line <= *tb->num_x ) { + if( x_line <= *tb->num_x + tb->display_offset_x ) { + put_char_vram(tc, '\n', (u16)0); + } + lb = lb->next; + } + + for( ; line_no <= *tb->num_y ; line_no++ ) { + put_char_vram(tc, '\n', (u16)0); + } +} + + diff --git a/build/tools/sctools/common/src/text.h b/build/tools/sctools/common/src/text.h new file mode 100644 index 0000000..17a5bb0 --- /dev/null +++ b/build/tools/sctools/common/src/text.h @@ -0,0 +1,74 @@ +#ifndef _TEXT_H_ +#define _TEXT_H_ + +#define X_LINE_MAX (32) +#define Y_LINE_MAX (24) + +#define LINE_BUF_X_SIZE 256 +#define LINE_BUF_Y_SIZE 24 + +#define DEFAULT_TEXT_PALETTE_NO 0x0f + +typedef struct LINE_BUF_s { + int buf[LINE_BUF_X_SIZE]; + u16 col[LINE_BUF_X_SIZE]; + int last_count; + int cur_count; + struct LINE_BUF_s *prev; + struct LINE_BUF_s *next; +} LINE_BUF; + +typedef struct { + int *num_x,*num_y; + LINE_BUF *start; + LINE_BUF *cur; + int virtual_x; + int virtual_y; + int display_offset_x; + int display_offset_y; + int display_newline; +} TEXT_BUF; + + + + +// #define TEXT_BUFFER_SIZE 128 +// typedef char (MY_ARRAY)[TEXT_BUFFER_SIZE] ; +// MY_ARRAY buffer; + +typedef struct { + TEXT_BUF text_buf; + u16 *screen; + u16 x_line; + u16 y_line; + u16 palette; + u16 padding; +} TEXT_CTRL; + + + +#ifdef __cplusplus +extern "C" { +#endif + +int init_text_buf_sys(void *heap_start, void *heap_end); + + +void m_putchar(TEXT_CTRL *tc, int c); +void m_set_palette(TEXT_CTRL *tc, u16 num); +u16 m_get_palette(TEXT_CTRL *tc); +void init_text(TEXT_CTRL *tc, u16 *screen, u16 palette); +void m_set_display_offset_y(TEXT_CTRL *tc, int offset); +int m_get_display_offset_y(TEXT_CTRL *tc); +void m_set_display_offset_x(TEXT_CTRL *tc, int offset); +int m_get_display_offset_x(TEXT_CTRL *tc); + +void text_buf_to_vram(TEXT_CTRL *tc); +void text_display_newline_off(TEXT_CTRL *tc); +void text_display_newline_on(TEXT_CTRL *tc); + +#ifdef __cplusplus +} +#endif + +#endif /* _TEXT_H_ */ diff --git a/build/tools/sctools/common/src/wcm_control.c b/build/tools/sctools/common/src/wcm_control.c new file mode 100644 index 0000000..f638951 --- /dev/null +++ b/build/tools/sctools/common/src/wcm_control.c @@ -0,0 +1,917 @@ +/*---------------------------------------------------------------------------* + Project: TwlWiFi - demos - netconnect + File: wcm_control.c + + Copyright 2005,2006 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:: 2008-08-19#$ + $Rev: 931 $ + $Author: adachi_hiroaki $ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "wcm_control.h" +#include "ap_info.h" +#include "sitedefs.h" +#include "netconnect.h" + +/*---------------------------------------------------------------------------* + 定数 定義 + *---------------------------------------------------------------------------*/ + +#define LOCAL_WCM_THREAD_STACK_SIZE 4096 // ( 変更可 ) TWLではDSより大きなスタックを確保する +#define LOCAL_WCM_THREAD_PRIORITY 12 // ( 変更可 ) 低めの優先度で十分 +#define LOCAL_WCM_DMA_NO 3 // ( 変更可 ) 無線機能に使用する DMA 番号 +#define LOCAL_WCM_APLIST_COUNT_MAX 22 // WCM ライブラリ内で管理させる AP 情報リストの数 +#define LOCAL_WCM_APLIST_BUF_SIZE ((LOCAL_WCM_APLIST_COUNT_MAX * WCM_APLIST_BLOCK_SIZE) + 12) +#define LOCAL_WCM_THREAD_MSGQ_CAPACITY 3 // メッセージキューの段数 +#define LOCAL_WCM_MSG_TERMINATE ((void*)0) +#define LOCAL_WCM_MSG_FOUND_AP ((void*)1) +#define LOCAL_WCM_MSG_DISCONNECTED ((void*)2) +#define LOCAL_WCM_MSG_ERROR ((void*)3) +#define LOCAL_WCM_MSG_CONNECT_AP ((void*)4) +#define LOCAL_WCM_MSG_DISCONNECT ((void*)5) + +// WCM ライブラリ操作ログ表示用 文字列定数 +static const char* gWcmResultText[8] = +{ + "SUCCESS" , "FAILURE" , + "PROGRESS" , "ACCEPT" , + "REJECT" , "WMDISABLE" , + "NOT_ENOUGH_MEM" , "FATAL_ERROR" +}; +static const char* gWcmNotifyText[10] = +{ + "COMMON" , "STARTUP" , + "CLEANUP" , "BEGIN_SEARCH" , + "END_SEARCH" , "CONNECT" , + "DISCONNECT" , "FOUND_AP" , + "SEARCH_AROUND" , "TERMINATE" +}; + +// デバッグ文字列表示設定 +#define LOCAL_DEBUG_PRINT 1 +#if LOCAL_DEBUG_PRINT +#define DebugPrintf OS_TPrintf +#else +#define DebugPrintf(...) ((void)0) +#endif + +/*---------------------------------------------------------------------------* + 内部変数 定義 + *---------------------------------------------------------------------------*/ + +// スレッド制御用 +static OSThread gWcmThread; +static u64 gWcmStack[LOCAL_WCM_THREAD_STACK_SIZE / sizeof( u64 ) ]; +static OSMessageQueue gWcmMessageQ; +static OSMessage gWcmMsgArray[LOCAL_WCM_THREAD_MSGQ_CAPACITY]; +static OSThreadQueue gWcmThreadQ; + +// WCM ライブラリ制御用 +static volatile BOOL gWcmTerminateFlag; +static vs32 gWcmResult; +static void* gWcmBuf = NULL; +static WCMConfig gWcmConfig; +static WCMBssDesc gWcmBssDesc ATTRIBUTE_ALIGN(4); +static u32 gWcmScanType = WCM_OPTION_SCANTYPE_ACTIVE; +static u32 gWcmPowerMode = WCM_OPTION_POWER_ACTIVE; + +static BOOL gWcmManualConnect = FALSE; +static u32 gWcmSearchAroundCount = 0; + +static const WcmControlApInfo g_ApInfoAny = +{ + { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + { 0, 0, {0} }, + { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff + } +}; + +static const WcmControlApInfo* constApInfoPtr = NULL; +//static u8 g_deviceId = WCM_DEVICEID_DEFAULT; +static u8 g_deviceId = WCM_DEVICEID_NWM; +/*---------------------------------------------------------------------------* + 内部関数 プロトタイプ + *---------------------------------------------------------------------------*/ +static void ControlThread(void* arg); +static void FreezeThread(void); +static s32 CallFunction(s16 notifyId); +static void ControlCallback(WCMNotice* arg); + +/*---------------------------------------------------------------------------* + Name: SetWcmScanType + + Description: AP を探索する際のスキャン方式を設定する。 + デフォルトではアクティブスキャン方式となっている。 + InitWcmControl() より先に呼び出す必要がある。 + + Arguments: type - WCM_OPTION_SCANTYPE_* の定数を指定する。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void SetWcmScanType(u32 type) +{ + switch (type) + { + case WCM_OPTION_SCANTYPE_PASSIVE: + gWcmScanType = WCM_OPTION_SCANTYPE_PASSIVE; + break; + + default: + gWcmScanType = WCM_OPTION_SCANTYPE_ACTIVE; + } +} + +/*---------------------------------------------------------------------------* + Name: SetWcmPowerMode + + Description: AP と通信する際の電力管理方式を指定する。 + デフォルトでは常時アクティブ方式となっている。 + InitWcmControl() より先に呼び出す必要がある。 + + Arguments: mode - WCM_OPTION_POWER_* の定数を指定する。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void SetWcmPowerMode(u32 mode) +{ + switch (mode) + { + case WCM_OPTION_POWER_SAVE: + gWcmPowerMode = WCM_OPTION_POWER_SAVE; + break; + + default: + gWcmPowerMode = WCM_OPTION_POWER_ACTIVE; + } +} + +/*---------------------------------------------------------------------------* + Name: SetWcmManualConnectMode + + Description: APのリストから手動で選択して接続するよう設定. + デフォルトでは FALSE (自動接続)となっている. + InitWcmControl() より先に呼び出す必要がある. + + Arguments: enable - 手動で接続する場合は TRUE。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void SetWcmManualConnect(BOOL enable) +{ + gWcmManualConnect = enable; +} + +/*---------------------------------------------------------------------------* + Name: ConnectAP + + Description: 指定されたBssDescのAPへ接続する + + Arguments: bd - 接続するAPを示す構造体へのポインタ。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void ConnectAP(const WCMBssDesc* pbd) +{ + SDK_NULL_ASSERT(pbd); + MI_CpuCopy8(pbd, &gWcmBssDesc, /*sizeof(WCMBssDesc)*/ WCM_APLIST_SIZE); + (void)OS_SendMessage(&gWcmMessageQ, LOCAL_WCM_MSG_CONNECT_AP, OS_MESSAGE_NOBLOCK); +} + +/*---------------------------------------------------------------------------* + Name: DisconnectAP + + Description: AP との接続の切断を試みる + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void DisconnectAP(void) +{ + OSIntrMode e = OS_DisableInterrupts(); + if (WCM_GetPhase() == WCM_PHASE_DCF) + { + (void)OS_SendMessage(&gWcmMessageQ, LOCAL_WCM_MSG_DISCONNECT, OS_MESSAGE_NOBLOCK); + } + (void)OS_RestoreInterrupts(e); +} + +/*---------------------------------------------------------------------------* + Name: InitWcmControl/InitWcmControlByApInfo + + Description: 内部変数を初期化し、WCM コントロールスレッドを起動する。 + 既にスレッドが起動している場合は何も行わない。 + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void InitWcmControl(void) +{ + // InitWcmControlEx(WCM_DEVICEID_DEFAULT); + InitWcmControlEx(WCM_DEVICEID_NWM); +} + +void InitWcmControlEx(u8 deviceId) +{ + static WcmControlApInfo apInfo; + InitWcmApInfo(&apInfo, SITEDEFS_DEFAULTCLASS); + InitWcmControlByApInfoEx(&apInfo, deviceId); +} + +void InitWcmControlByApInfo(const WcmControlApInfo* ptr) +{ + InitWcmControlByApInfoEx(ptr, WCM_DEVICEID_DEFAULT); +} + +void InitWcmControlByApInfoEx(const WcmControlApInfo* ptr, u8 deviceId) +{ + // スレッド変数が一回でも初期化されたか? + if (gWcmThread.id != 0) + { + // スレッドは終了状態にあるか? + if (OS_IsThreadTerminated(&gWcmThread) == FALSE) + { + return; + } + } + + if (ptr) + { + constApInfoPtr = ptr; + } + else + { + constApInfoPtr = &g_ApInfoAny; + } + g_deviceId = deviceId; + + // メッセージキューを初期化 + OS_InitMessageQueue(&gWcmMessageQ, gWcmMsgArray, LOCAL_WCM_THREAD_MSGQ_CAPACITY); + + // スレッドキューを初期化 + OS_InitThreadQueue(&gWcmThreadQ); + + // 変数初期化 + MI_CpuClearFast(&gWcmBssDesc, sizeof(WCMBssDesc)); + + // スレッド変数を使って新規にスレッドを作成 + OS_CreateThread(&gWcmThread, ControlThread, NULL, (void*)(gWcmStack + (LOCAL_WCM_THREAD_STACK_SIZE / sizeof(u64))), + LOCAL_WCM_THREAD_STACK_SIZE, LOCAL_WCM_THREAD_PRIORITY); + + // 作成したスレッドを起動 + gWcmTerminateFlag = FALSE; + + OS_WakeupThreadDirect(&gWcmThread); + +} + +/*---------------------------------------------------------------------------* + Name: TerminateWcmControl + + Description: WCM コントロールスレッドを終了する。 + スレッドが起動されていない場合は何も行わない。 + NOTICE: 当関数はスレッドを終了する為のトリガとなるだけなので、スレッド + 自体が終了するまで待たずに戻る点に注意。 + スレッド自体の終了を待ちたい場合は、OS_SendMessage 呼び出しに + 続いて OS_JoinThread を呼び出す必要がある。 + なお、WCM_GetPhase 関数が WCM_PHASE_NULL を返すようになれば + スレッドは終了している。 + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void TerminateWcmControl(void) +{ + // スレッド変数が一回でも初期化されたか? + if (gWcmThread.id != 0) + { + // スレッドは終了状態にあるか? + if (OS_IsThreadTerminated(&gWcmThread) == FALSE) + { + // 既に終了要求を受け付けている状態か? + if (gWcmTerminateFlag == FALSE) + { + gWcmTerminateFlag = TRUE; + (void)OS_SendMessage(&gWcmMessageQ, LOCAL_WCM_MSG_TERMINATE, OS_MESSAGE_NOBLOCK); + } + } + } +} + +/*---------------------------------------------------------------------------* + Name: SetWcmThreadPriority + + Description: WCM ライブラリの状態管理を行うスレッドの優先度を変更する。 + + Arguments: priority - 0 〜 31 のスレッド優先度を指定する。 + + Returns: u8 - 変更する前に設定されていた優先度を返す。 + なんらかの理由で優先度の変更に失敗した場合は 0xff を返す。 + *---------------------------------------------------------------------------*/ +u8 SetWcmThreadPriority(u8 priority) +{ + u8 beforePrio = 0xff; + + if (priority < 32) + { + if ((gWcmThread.id != 0) && (OS_IsThreadTerminated(&gWcmThread) == FALSE)) + { + beforePrio = (u8) OS_GetThreadPriority(&gWcmThread); + if (FALSE == OS_SetThreadPriority(&gWcmThread, (u32) priority)) + { + beforePrio = 0xff; + } + } + } + + return beforePrio; +} + +/*---------------------------------------------------------------------------* + Name: GetWcmSearchAroundCount + + Description: 全チャンネルを何週スキャンしたかを返す。 + StartUp直後は0になる。 + + Arguments: None. + + Returns: 何回スキャンしたか。 + *---------------------------------------------------------------------------*/ +u32 GetWcmSearchAroundCount(void) +{ + return gWcmSearchAroundCount; +} + +/*---------------------------------------------------------------------------* + Name: ControlThread + + Description: WCM ライブラリの状態管理を行うスレッド。 + gWcmTerminateFlag 変数が FALSE の間は指定 AP に接続しようとし、 + また接続完了後はその接続を維持しようとする。 + TerminateWcmControl 関数が呼ばれると gWcmTerminateFlag 変数が + TRUE に変化し、その後は WCM ライブラリを終了して自身のスレッド + も終了しようとする。 + なお、WCM ライブラリ内部で FATAL ERROR が発生した場合には、 + 当スレッドは内部で無限ループに入る。 + + Arguments: arg - 使用しない。 + + Returns: None. + *---------------------------------------------------------------------------*/ +static void ControlThread(void* arg) +{ +#pragma unused(arg) + + void* wcmBuf; + void* wcmAplistBuf; + s32 wcmResult; + OSMessage tempMessage; + s32 workSize = WCM_WORK_SIZE; + + WCM_GetWorkSize(&workSize, g_deviceId); + + // WCM ライブラリが使用するメモリを確保 + wcmBuf = NcAlloc(0, workSize + LOCAL_WCM_APLIST_BUF_SIZE); + + if (wcmBuf == NULL) + { + /* メモリが確保できなかった場合はその後の操作は不可能なので終了 */ + return; + } + + wcmAplistBuf = (void*)((u32) wcmBuf + WCM_WORK_SIZE); + + // WCM ライブラリを初期化 + wcmResult = WCM_InitEx(wcmBuf, workSize, g_deviceId); + DebugPrintf("WCM_InitEx(deviceId = %d) -> %s\n", g_deviceId, gWcmResultText[wcmResult]); + if (wcmResult != WCM_RESULT_SUCCESS) + { + /* + * ここでエラーが返される場合は、ライブラリの使い方が間違っている可能性が高い。 + * 他のスレッドから WCM ライブラリが既に初期化されていることが考えられる。 + */ + NcFree(0, wcmBuf, workSize + LOCAL_WCM_APLIST_BUF_SIZE); + return; + } + + // WCM ライブラリの動作設定 + gWcmConfig.dmano = LOCAL_WCM_DMA_NO; + gWcmConfig.pbdbuffer = wcmAplistBuf; + gWcmConfig.nbdbuffer = LOCAL_WCM_APLIST_BUF_SIZE; + gWcmConfig.nbdmode = WCM_APLIST_MODE_IGNORE; + + // 接続開始 + while (gWcmTerminateFlag == FALSE) + { + switch (WCM_GetPhase()) + { + case WCM_PHASE_WAIT: + // 無線機能の起動 + wcmResult = CallFunction(WCM_NOTIFY_STARTUP); + break; + + case WCM_PHASE_IDLE: + if (gWcmBssDesc.length == 0) + { + // AP の自動探索を開始 + WCM_ClearApList(); + wcmResult = CallFunction(WCM_NOTIFY_BEGIN_SEARCH); + } + else + { + // AP に接続 + wcmResult = CallFunction(WCM_NOTIFY_CONNECT); + if (wcmResult == WCM_RESULT_SUCCESS) + { + // 次に接続しようとする際にサーチからやり直す為に、ここでクリア + MI_CpuClearFast(&gWcmBssDesc, sizeof(WCMBssDesc)); + } + } + break; + + case WCM_PHASE_SEARCH: + // AP が発見されるまで待つ + (void)OS_ReceiveMessage(&gWcmMessageQ, &tempMessage, OS_MESSAGE_BLOCK); + + /* + * メッセージとしては、WCM の停止要求、AP 発見通知、及びエラー通知の3種類を + * 受け取る可能性がある。AP 発見通知の場合は、このサンプルでは発見した AP がすなわち + * 接続すべき AP なので、情報を退避する。 + */ + if (tempMessage == LOCAL_WCM_MSG_FOUND_AP) + { + /* 自動接続モードならここで検索終了 */ + if (!gWcmManualConnect) + { + (void)WCM_LockApList(WCM_APLIST_LOCK); + if (WCM_CountApList() >= 1) + { + // 最初に見つかった AP の情報のみを退避する。 + MI_CpuCopyFast(WCM_PointApList(0), &gWcmBssDesc, WCM_APLIST_SIZE); + DebugPrintf(" BSS-ID: %02x-%02x-%02x-%02x-%02x-%02x\n", gWcmBssDesc.bssid[0], + gWcmBssDesc.bssid[1], gWcmBssDesc.bssid[2], gWcmBssDesc.bssid[3], + gWcmBssDesc.bssid[4], gWcmBssDesc.bssid[5]); + DebugPrintf(" ESS-ID: %s\n", gWcmBssDesc.ssid); + } + (void)WCM_LockApList(WCM_APLIST_UNLOCK); + wcmResult = CallFunction(WCM_NOTIFY_END_SEARCH); + } + } + + /* 接続要求があればまず検索を終了 */ + else if (tempMessage == LOCAL_WCM_MSG_CONNECT_AP) + { + wcmResult = CallFunction(WCM_NOTIFY_END_SEARCH); + } + break; + + case WCM_PHASE_DCF: + // 切断通知まで待つ + (void)OS_ReceiveMessage(&gWcmMessageQ, &tempMessage, OS_MESSAGE_BLOCK); + /* + * メッセージとしては、WCM の停止要求、AP からの切断、及びエラー通知の3種類を + * 受け取る可能性がある。このどれの場合も受け取った時点で行うべき処理は無い。 + */ + if (tempMessage == LOCAL_WCM_MSG_DISCONNECT) + { + wcmResult = CallFunction(WCM_NOTIFY_DISCONNECT); + } + break; + + case WCM_PHASE_IRREGULAR: + // FIFO が溢れた可能性が高いので、少し待つ + OS_Sleep(1); + + // IRREGULAR フェーズ時に有効な処理は強制停止のみ + wcmResult = CallFunction(WCM_NOTIFY_TERMINATE); + break; + + case WCM_PHASE_FATAL_ERROR: + default: + FreezeThread(); + } + } + // 終了処理 + while (gWcmTerminateFlag != FALSE) + { + switch (WCM_GetPhase()) + { + case WCM_PHASE_WAIT: + // ループから抜ける + gWcmTerminateFlag = FALSE; + break; + + case WCM_PHASE_IDLE: + // 無線機能の停止 + wcmResult = CallFunction(WCM_NOTIFY_CLEANUP); + break; + + case WCM_PHASE_SEARCH: + // AP の自動探索を停止 + wcmResult = CallFunction(WCM_NOTIFY_END_SEARCH); + break; + + case WCM_PHASE_DCF: + // AP から切断 + wcmResult = CallFunction(WCM_NOTIFY_DISCONNECT); + break; + + case WCM_PHASE_IRREGULAR: + // 無線機能の強制終了 + wcmResult = CallFunction(WCM_NOTIFY_TERMINATE); + break; + + case WCM_PHASE_FATAL_ERROR: + default: + FreezeThread(); + } + } + + // WCM ライブラリを終了 + wcmResult = WCM_Finish(); + DebugPrintf("WCM_Finish() -> %s\n", gWcmResultText[wcmResult]); + if (wcmResult != WCM_RESULT_SUCCESS) + { + /* + * ここでエラーが返される場合は、ライブラリの使い方が間違っている可能性が高い。 + * 他のスレッドから WCM ライブラリが終了されてしまっていることが考えられる。 + */ + NcFree(0, wcmBuf, workSize + LOCAL_WCM_APLIST_BUF_SIZE); + return; + } + + // 確保していたメモリを解放 + NcFree(0, wcmBuf, workSize + LOCAL_WCM_APLIST_BUF_SIZE); + return; +} + +/*---------------------------------------------------------------------------* + Name: FreezeThread + + Description: スレッドから呼び出され、無限ループに入って固まる。 + + Arguments: None. + + Returns: 当関数からは返らない。 + *---------------------------------------------------------------------------*/ +static void FreezeThread(void) +{ + /* + * FATAL ERROR の場合はどうしようもないので、中で固まることにする。 + * 致命的なメモリが破壊された、ARM7の負荷が高すぎて処理しきれなく + * なった、スレッドのスタックが溢れた、等の原因が考えられる。 + * エンドユーザーに適切なエラー通知をしなければならないが、ソフト的に + * 復旧する方法は無いので、エンドユーザーに電源を切ってもらうしかない。 + */ + while (TRUE) + { + OS_Sleep(10000); + } +} + +/*---------------------------------------------------------------------------* + Name: CallFunction + + Description: WCM 非同期 API をコールし、非同期処理が完了するまで待つ。 + スレッドから呼び出されることを想定しており、非同期処理の完了を + 内部でブロックして待つ点に注意。 + + Arguments: WCM 非同期 API の種別を WCM_NOTIFY_* の形式で指定する。 + 指定可能なパラメータは以下の通り。 + WCM_NOTIFY_STARTUP : WCM_StartupAsync を実行する。 + WCM_NOTIFY_CLEANUP : WCM_CleanupAsync を実行する。 + WCM_NOTIFY_BEGIN_SEARCH : WCM_SearchAsycn(開始) を実行する。 + WCM_NOTIFY_END_SEARCH : WCM_SearchAsync(停止) を実行する。 + WCM_NOTIFY_CONNECT : WCM_ConnectAsync を実行する。 + WCM_NOTIFY_DISCONNECT : WCM_DisconnectAsync を実行する。 + WCM_NOTIFY_TERMINATE : WCM_TerminateAsync を実行する。 + + Returns: 同期的・非同期的な処理結果を返す。 + 返される値は以下の内のいずれかとなる。 + WCM_RESULT_SUCCESS : 処理が正常に完了。 + WCM_RESULT_FAILURE : 処理の途中でなんらかの要因で失敗。 + WCM_RESULT_FATAL_ERROR : パラメータが想定範囲外 + *---------------------------------------------------------------------------*/ +static s32 CallFunction(s16 notifyId) +{ + s32 wcmResult = WCM_RESULT_FATAL_ERROR; + OSIntrMode e = OS_DisableInterrupts(); + void* essId; + + while (TRUE) + { + // 実行すべき API を振り分け + switch (notifyId) + { + case WCM_NOTIFY_STARTUP: + wcmResult = WCM_StartupAsync(&gWcmConfig, ControlCallback); + DebugPrintf("WCM_StartupAsync() -> %s\n", gWcmResultText[wcmResult]); + break; + + case WCM_NOTIFY_CLEANUP: + wcmResult = WCM_CleanupAsync(); + DebugPrintf("WCM_CleanupAsync() -> %s\n", gWcmResultText[wcmResult]); + break; + + case WCM_NOTIFY_BEGIN_SEARCH: + /****************************************************************/ + /* デモでは特別に 0xff で埋められている SSID を WCM_Essid_Any として扱う */ + essId = (void*)constApInfoPtr->essId; + if (WCM_CompareEssID(essId, WCM_Essid_Any)) + { + essId = (void*)WCM_Essid_Any; + } + /* アクセスポイントを探索する際の重要な設定を行っている箇所 */ + wcmResult = WCM_BeginSearchAsync((void*)constApInfoPtr->bssId, essId, (u32) ( + WCM_OPTION_CHANNEL_ALL | gWcmScanType | + (gWcmManualConnect ? WCM_OPTION_ROUNDSCAN_NOTIFY : WCM_OPTION_ROUNDSCAN_IGNORE) + )); + + /****************************************************************/ + DebugPrintf("WCM_BeginSearchAsync -> %s\n", gWcmResultText[wcmResult]); + break; + + case WCM_NOTIFY_END_SEARCH: + wcmResult = WCM_EndSearchAsync(); + DebugPrintf("WCM_EndSearchAsync -> %s\n", gWcmResultText[wcmResult]); + break; + + case WCM_NOTIFY_CONNECT: + /****************************************************************/ + + /* アクセスポイントに接続する際の重要な設定を行っている箇所 */ + wcmResult = WCM_ConnectAsync(&gWcmBssDesc, (void*)(&(constApInfoPtr->wepDesc)), + gWcmPowerMode | constApInfoPtr->auth_option); + + /****************************************************************/ + DebugPrintf("WCM_ConnectAsync() -> %s\n", gWcmResultText[wcmResult]); + break; + + case WCM_NOTIFY_DISCONNECT: + wcmResult = WCM_DisconnectAsync(); + DebugPrintf("WCM_DisconnectAsync() -> %s\n", gWcmResultText[wcmResult]); + break; + + case WCM_NOTIFY_TERMINATE: + wcmResult = WCM_TerminateAsync(); + DebugPrintf("WCM_TerminateAsync() -> %s\n", gWcmResultText[wcmResult]); + break; + + default: + (void)OS_RestoreInterrupts(e); + return wcmResult; + } + + // 同期的な処理結果を確認 + switch (wcmResult) + { + case WCM_RESULT_REJECT: + // 少し待ってからリトライする + OS_Sleep(1); + continue; + + case WCM_RESULT_PROGRESS: + case WCM_RESULT_ACCEPT: + // 非同期処理応答がコールバックされるまで待つ + OS_SleepThread(&gWcmThreadQ); + break; + + case WCM_RESULT_SUCCESS: + case WCM_RESULT_FAILURE: + // 同期的に処理が完了し、非同期処理は行われない場合 + (void)OS_RestoreInterrupts(e); + return wcmResult; + + case WCM_RESULT_WMDISABLE: + /* + * ARM7 側で WM ライブラリが動作していない場合。 + * WCM を使い始める前に WVR ライブラリを使って ARM7 側無線ドライバを + * 起動させる必要があるが、それはアプリケーションの責任で行うべきこと。 + */ + OS_Panic("ARM7 WM library is not ready.\n"); + + case WCM_RESULT_NOT_ENOUGH_MEM: // 非同期関数にこの返り値が返されることは無い + case WCM_RESULT_FATAL_ERROR: + default: + (void)OS_RestoreInterrupts(e); + FreezeThread(); + } + + // 非同期的な処理結果を確認 + switch (gWcmResult) + { + case WCM_RESULT_SUCCESS: + case WCM_RESULT_FAILURE: + wcmResult = gWcmResult; + break; + + case WCM_RESULT_PROGRESS: // 非同期処理結果にこの処理結果が渡されることは無い + case WCM_RESULT_ACCEPT: // 非同期処理結果にこの処理結果が渡されることは無い + case WCM_RESULT_REJECT: // 非同期処理結果にこの処理結果が渡されることは無い + case WCM_RESULT_WMDISABLE: // 非同期処理結果にこの処理結果が渡されることは無い + case WCM_RESULT_NOT_ENOUGH_MEM: // 非同期処理結果にこの処理結果が渡されることは無い + case WCM_RESULT_FATAL_ERROR: + default: + (void)OS_RestoreInterrupts(e); + FreezeThread(); + } + + break; + } + + (void)OS_RestoreInterrupts(e); + return wcmResult; +} + +/*---------------------------------------------------------------------------* + Name: ControlCallback + + Description: WCM 非同期 API の処理結果応答、及び WCM ライブラリからの 不定期 + 通知を受け取るコールバック関数。 + + Arguments: arg - 通知種別や処理結果などを示す構造体へのポインタ。 + + Returns: None. + *---------------------------------------------------------------------------*/ +static void ControlCallback(WCMNotice* arg) +{ + static s16 lastNotify = -1; + static s16 lastResult = -1; + + //前回と結果が違ったら表示 + if (lastNotify != arg->notify || lastResult != arg->result) + { + DebugPrintf(" cb %s %s\n", gWcmNotifyText[arg->notify], gWcmResultText[arg->result]); + lastNotify = arg->notify; + lastResult = arg->result; + } + + switch (arg->notify) + { + case WCM_NOTIFY_STARTUP: + gWcmSearchAroundCount = 0; + + case WCM_NOTIFY_CLEANUP: + case WCM_NOTIFY_BEGIN_SEARCH: + case WCM_NOTIFY_END_SEARCH: + case WCM_NOTIFY_CONNECT: + case WCM_NOTIFY_TERMINATE: + // 要求と 1 対 1 に対応する非同期処理の結果応答 + gWcmResult = arg->result; + OS_WakeupThread(&gWcmThreadQ); + break; + + case WCM_NOTIFY_DISCONNECT: +#ifdef SDK_THREAD_INFINITY + if (gWcmThreadQ.head != NULL) +#else + if (gWcmThreadQ != 0) +#endif + { + // 要求と 1 対 1 に対応する非同期処理の結果応答 + gWcmResult = arg->result; + OS_WakeupThread(&gWcmThreadQ); + } + else + { + // スレッドが稼動中、もしくはメッセージ待ちで停止状態の場合 + if (arg->result == WCM_RESULT_SUCCESS) + { + // DCF 通信中に AP から切断されたことを示す通知 + (void)OS_SendMessage(&gWcmMessageQ, LOCAL_WCM_MSG_DISCONNECTED, OS_MESSAGE_NOBLOCK); + } + else + { + // DCF 通信中になんらかのエラーが発生したことを示す通知 + (void)OS_JamMessage(&gWcmMessageQ, LOCAL_WCM_MSG_ERROR, OS_MESSAGE_NOBLOCK); + } + } + break; + + case WCM_NOTIFY_FOUND_AP: + // 自動探索時の非同期通知 + { + if (arg->result == WCM_RESULT_SUCCESS) + { + OSMessage tempMessage; + + // 自動探索時に AP を発見したことを示す通知 + if (OS_ReadMessage(&gWcmMessageQ, &tempMessage, OS_MESSAGE_NOBLOCK) == FALSE) + { + // 何度も通知されるものなので、メッセージキューが空である場合のみに限定 + (void)OS_SendMessage(&gWcmMessageQ, LOCAL_WCM_MSG_FOUND_AP, OS_MESSAGE_NOBLOCK); + } + } + else + { + // 自動探索時になんらかのエラーが発生したことを示す通知 + (void)OS_JamMessage(&gWcmMessageQ, LOCAL_WCM_MSG_ERROR, OS_MESSAGE_NOBLOCK); + } + } + break; + + case WCM_NOTIFY_SEARCH_AROUND: + // 自動探索時に指定チャンネルを一巡したことを示す不定期通知 + ++gWcmSearchAroundCount; + break; + } +} + +/*---------------------------------------------------------------------------* + Name: InitWcmApInfo + + Description: アクセスポイント接続パラメータを環境設定値から取得して + 初期化する + + Arguments: apinfo 接続パラメータ + apclass アクセスポイントのクラス名 + + Returns: TRUE 成功 + FALSE 失敗 + *---------------------------------------------------------------------------*/ +static BOOL myEnvCopy(const char* name, void* dest, int dest_size); +static BOOL myEnvCopy(const char* name, void* dest, int dest_size) +{ + void* src; + int src_size; + + if (ENV_GetBinaryAndSize(name, &src, &src_size)) + { + MI_CpuCopy8(src, dest, (u32) MATH_MIN(src_size, dest_size)); + return TRUE; + } + + return FALSE; +} + +BOOL InitWcmApInfo(WcmControlApInfo* apinfo, const char* apclass) +{ + BOOL isvalid; + char buf[WCM_ESSID_SIZE + 1]; + + SiteDefs_Init(); + + OS_TPrintf("SiteDef: %s\n", apclass); + ENV_SetClass(apclass); + + if (ENV_GetBOOL(".ISVALID", &isvalid) && isvalid) + { + MI_CpuClear8(apinfo, sizeof(WcmControlApInfo)); + + if (myEnvCopy(".ESSID", apinfo->essId, sizeof(apinfo->essId)) && + myEnvCopy(".BSSID", apinfo->bssId, sizeof(apinfo->bssId)) && ENV_GetU32(".AUTHMODE", &apinfo->auth_option) && + ENV_GetU8(".WEP.MODE", &apinfo->wepDesc.mode) && ENV_GetU8(".WEP.KEYID", &apinfo->wepDesc.keyId) && + myEnvCopy(".WEP.KEY", apinfo->wepDesc.key, sizeof(apinfo->wepDesc.key))) + { +#ifdef SDK_TWL + /* 暗号化方式が WPA の場合はパスフレーズを PSK に変換 */ + if(apinfo->wepDesc.mode > WCM_WEPMODE_128 ) /* WPA */ + { + u8 psk[WCM_WPA_PSK_SIZE]; + if (WCM_GetWPAPSK(apinfo->wepDesc.key, apinfo->essId, (u8)STD_GetStringLength((const char*)apinfo->essId), psk) == FALSE) + { + OS_TWarning("PreSharedKey Calculation Error.\n"); + return FALSE; + } + MI_CpuClear8(apinfo->wepDesc.key, sizeof(apinfo->wepDesc.key)); + MI_CpuCopy8(psk, apinfo->wepDesc.key, WCM_WPA_PSK_SIZE); + + apinfo->wepDesc.keyId = 32; + } +#endif + MI_CpuClear8(buf, sizeof(buf)); + MI_CpuCopy8(apinfo->essId, buf, WCM_ESSID_SIZE); + OS_TPrintf(" essId: %s, bssId: %02x:%02x:%02x:%02x:%02x:%02x\n", buf, + apinfo->bssId[0], apinfo->bssId[1], apinfo->bssId[2], + apinfo->bssId[3], apinfo->bssId[4], apinfo->bssId[5]); + + OS_TPrintf(" wepmode: %d\n", apinfo->wepDesc.mode); + if( apinfo->wepDesc.keyId != 32) { + OS_TPrintf(" wepkey: %s\n", apinfo->wepDesc.key); + } + return TRUE; + } + } + OS_TWarning("This SiteDef name is invalid.\n"); + + return FALSE; +} + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/tools/sctools/common/src/wcm_control.h b/build/tools/sctools/common/src/wcm_control.h new file mode 100644 index 0000000..5cee3ff --- /dev/null +++ b/build/tools/sctools/common/src/wcm_control.h @@ -0,0 +1,171 @@ +/*---------------------------------------------------------------------------* + Project: TwlWiFi - demos - netconnect + File: wcm_control.h + + Copyright 2005,2006 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:: 2007-12-06#$ + $Rev: 156 $ + $Author: okajima_manabu $ + *---------------------------------------------------------------------------*/ +#ifndef SHARED_WCM_CONTROL_H_ +#define SHARED_WCM_CONTROL_H_ + +#include "ap_info.h" + +#ifdef __cplusplus + +extern "C" { +#endif + +/*===========================================================================*/ + +/*---------------------------------------------------------------------------* + Name: InitWcmControl + + Description: 内部変数を初期化し、WCM コントロールスレッドを起動する。 + 既にスレッドが起動している場合は何も行わない。 + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void InitWcmControl(void); +void InitWcmControlEx(u8 deviceId); +void InitWcmControlByApInfo(const WcmControlApInfo* ptr); +void InitWcmControlByApInfoEx(const WcmControlApInfo* ptr, u8 deviceId); + +/*---------------------------------------------------------------------------* + Name: InitWcmApInfo + + Description: アクセスポイント接続パラメータを環境設定値から取得して + 初期化する + + Arguments: apinfo 接続パラメータ + apclass アクセスポイントのクラス名 + + Returns: TRUE 成功 + FALSE 失敗 + *---------------------------------------------------------------------------*/ +BOOL InitWcmApInfo(WcmControlApInfo* apinfo, const char* apclass); + +/*---------------------------------------------------------------------------* + Name: TerminateWcmControl + + Description: WCM コントロールスレッドを終了する。 + スレッドが起動されていない場合は何も行わない。 + NOTICE: 当関数はスレッドを終了する為のトリガとなるだけなので、スレッド + 自体が終了するまで待たずに戻る点に注意。 + スレッド自体の終了を待ちたい場合は、OS_SendMessage 呼び出しに + 続いて OS_JoinThread を呼び出す必要がある。 + なお、WCM_GetPhase 関数が WCM_PHASE_NULL を返すようになれば + スレッドは終了している。 + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void TerminateWcmControl(void); + +/*---------------------------------------------------------------------------* + Name: SetWcmThreadPriority + + Description: WCM ライブラリの状態管理を行うスレッドの優先度を変更する。 + + Arguments: priority - 0 〜 31 のスレッド優先度を指定する。 + + Returns: u8 - 変更する前に設定されていた優先度を返す。 + なんらかの理由で優先度の変更に失敗した場合は 0xff を返す。 + *---------------------------------------------------------------------------*/ +u8 SetWcmThreadPriority(u8 priority); + +/*---------------------------------------------------------------------------* + Name: GetWcmSearchAroundCount + + Description: 全チャンネルを何週スキャンしたかを返す。 + StartUp直後は0になる。 + + Arguments: None. + + Returns: 何回スキャンしたか。 + *---------------------------------------------------------------------------*/ +u32 GetWcmSearchAroundCount(void); + +/*---------------------------------------------------------------------------* + Name: SetWcmManualConnectMode + + Description: APのリストから手動で選択して接続するよう設定. + デフォルトでは FALSE (自動接続)となっている. + InitWcmControl() より先に呼び出す必要がある. + + Arguments: enable - 手動で接続する場合は TRUE。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void SetWcmManualConnect(BOOL enable); + +/*---------------------------------------------------------------------------* + Name: ConnectAP + + Description: 指定されたBssDescのAPへ接続する + + Arguments: bd - 接続するAPを示す構造体へのポインタ。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void ConnectAP(const WCMBssDesc* pbd); + +/*---------------------------------------------------------------------------* + Name: DisconnectAP + + Description: AP との接続の切断を試みる + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void DisconnectAP(void); + +/*---------------------------------------------------------------------------* + Name: SetWcmScanType + + Description: AP を探索する際のスキャン方式を設定する。 + デフォルトではアクティブスキャン方式となっている。 + InitWcmControl() より先に呼び出す必要がある。 + + Arguments: type - WCM_OPTION_SCANTYPE_* の定数を指定する。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void SetWcmScanType(u32 type); + +/*---------------------------------------------------------------------------* + Name: SetWcmPowerMode + + Description: AP と通信する際の電力管理方式を指定する。 + デフォルトでは常時アクティブ方式となっている。 + InitWcmControl() より先に呼び出す必要がある。 + + Arguments: mode - WCM_OPTION_POWER_* の定数を指定する。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void SetWcmPowerMode(u32 mode); + +/*===========================================================================*/ +#ifdef __cplusplus + +} /* extern "C" */ +#endif + +#endif /* SHARED_WCM_CONTROL_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/tools/sctools/copy_dst/Makefile b/build/tools/sctools/copy_dst/Makefile new file mode 100644 index 0000000..8a3f002 --- /dev/null +++ b/build/tools/sctools/copy_dst/Makefile @@ -0,0 +1,90 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - MI - ndma-1 +# File: Makefile +# +# Copyright 2007 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:: 2008-01-17#$ +# $Rev: 3650 $ +# $Author: okubata_ryoma $ +#---------------------------------------------------------------------------- +SUBDIRS = ./banner + +TARGET_PLATFORM := TWL +TWL_ARCHGEN := LIMITED + +SRCDIR = ../common/src ./src + +SRCS = main.c key.c font.c text.c mprintf.c logprintf.c \ + gfx.c hwi.c mynvram.c my_fs_util.c \ + kpsc.cpp ecdl.cpp hatamotolib.cpp \ + sitedefs.c wcm_control.c netconnect.c mywlan.c \ + nuc.c nuc_error_msg.c stream.c + +TARGET_BIN = copy_dst.srl +ROM_SPEC = copy_dst.rsf + + +ES_DIR = $(ROOT)/add-ins/es +ES_LATEST = $(shell ls -d $(ES_DIR)/es-sdk-*|sort|tail -n 1) +ES_ROOT = $(ES_LATEST) + +LINCLUDES = $(TWLSDK_ROOT)/build/libraries/lcfg/ARM9.TWL/include ../common/src \ + $(ES_ROOT)/twl/include $(ES_ROOT)/common/lib/ec/include + +LLIBRARY_DIRS += $(ES_ROOT)/twl/lib/$(TWL_BUILDTYPE) + + +LLIBRARIES += libecx$(TWL_LIBSUFFIX).a \ + liblcfg$(TWL_LIBSUFFIX).a \ + libnhttp.nssl$(TWL_LIBSUFFIX).a \ + libshr$(TWL_LIBSUFFIX).a \ + libnuc$(TWL_LIBSUFFIX).a \ + libnup$(TWL_LIBSUFFIX).a \ + libnam$(TWL_LIBSUFFIX).a \ + libes$(TWL_LIBSUFFIX).a \ + libsea$(TWL_LIBSUFFIX).a \ + libboc$(TWL_LIBSUFFIX).a \ + libsfs$(TWL_LIBSUFFIX).a \ + libna$(TWL_LIBSUFFIX).a \ + + +# libnhttp$(TWL_LIBSUFFIX).a \ + + +MAKEROM_ROMROOT = ../files +MAKEROM_ROMFILES = fanfare.32.wav + + +COMPONENT_NAME = armadillo +MAKEROM_ARM7_BASE = $(TWL_COMPONENTSDIR)/$(COMPONENT_NAME)/$(TWL_BUILDTYPE_ARM7)/$(COMPONENT_NAME) +MAKEROM_ARM7 = $(MAKEROM_ARM7_BASE).$(TWL_ELF_EXT) + + +include $(TWLWIFI_ROOT)/build/buildtools/commondefs +include $(TWLSDK_ROOT)/build/buildtools/commondefs + + +#---------------------------------- +# セキュアアプリ指定 + +MAKEROM := $(TWL_TOOLSDIR)/bin/makerom.TWL.secure.exe + + +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +#---------------------------------------------------------------------------- + +include $(TWLWIFI_ROOT)/build/buildtools/modulerules +include $(TWLSDK_ROOT)/build/buildtools/modulerules diff --git a/build/tools/sctools/copy_dst/banner/Makefile b/build/tools/sctools/copy_dst/banner/Makefile new file mode 100644 index 0000000..4f2a5fc --- /dev/null +++ b/build/tools/sctools/copy_dst/banner/Makefile @@ -0,0 +1,59 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - nandApp - demos - SubBanner +# File: Makefile +# +# Copyright 2007 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:: 2008-06-27#$ +# $Rev: 6887 $ +# $Author: nakasima $ +#---------------------------------------------------------------------------- +TARGET_PLATFORM = TWL + +include $(TWLSDK_ROOT)/build/buildtools/commondefs +MAKEBANNER = $(TWL_TOOLSDIR)/bin/makebanner.TWL.exe + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +SUB_BANNER_ICON = $(ICON_DIR)/subIcon.bmp +SUB_BANNER_SPEC = sub_banner_v3.bsf + + +TARGETS = banner.bnr +SUB_TARGETS = sub_banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) $(SUB_TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) +BANNER_ICON_MIDDLE = $(addprefix $(BANNER_ICON_NAME), .nbfs .nbfc .nbfp) +SUB_BANNER_ICON_NAME = $(basename $(SUB_BANNER_ICON)) +SUB_BANNER_ICON_MIDDLE = $(addprefix $(SUB_BANNER_ICON_NAME), .nbfs .nbfc .nbfp) + +LDIRT_CLEAN = $(TARGETS) $(SUB_TARGETS) \ + $(BANNER_ICON_MIDDLE) \ + $(SUB_BANNER_ICON_MIDDLE) \ + $(TARGETS:.bnr=.srl) + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) $(SUB_TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) $(BANNER_ICON_MIDDLE) + $(MAKEBANNER) -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +$(SUB_TARGETS): $(SUB_BANNER_SPEC) $(SUB_BANNER_ICON) $(SUB_BANNER_ICON_MIDDLE) + $(MAKEBANNER) -s -N $(SUB_BANNER_ICON_NAME) $(SUB_BANNER_SPEC) $(SUB_TARGETS) +# diff --git a/build/tools/sctools/copy_dst/banner/banner_v3.bsf b/build/tools/sctools/copy_dst/banner/banner_v3.bsf new file mode 100644 index 0000000..8e54be0 Binary files /dev/null and b/build/tools/sctools/copy_dst/banner/banner_v3.bsf differ diff --git a/build/tools/sctools/copy_dst/banner/icon/gameIcon.bmp b/build/tools/sctools/copy_dst/banner/icon/gameIcon.bmp new file mode 100644 index 0000000..d094481 Binary files /dev/null and b/build/tools/sctools/copy_dst/banner/icon/gameIcon.bmp differ diff --git a/build/tools/sctools/copy_dst/banner/icon/subIcon.bmp b/build/tools/sctools/copy_dst/banner/icon/subIcon.bmp new file mode 100644 index 0000000..5fc9e3b Binary files /dev/null and b/build/tools/sctools/copy_dst/banner/icon/subIcon.bmp differ diff --git a/build/tools/sctools/copy_dst/banner/sub_banner_v3.bsf b/build/tools/sctools/copy_dst/banner/sub_banner_v3.bsf new file mode 100644 index 0000000..2fd176b Binary files /dev/null and b/build/tools/sctools/copy_dst/banner/sub_banner_v3.bsf differ diff --git a/build/tools/sctools/copy_dst/copy_dst.rsf b/build/tools/sctools/copy_dst/copy_dst.rsf new file mode 100644 index 0000000..be441f2 --- /dev/null +++ b/build/tools/sctools/copy_dst/copy_dst.rsf @@ -0,0 +1,325 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-TS.rsf +# +# Copyright 2007-2008 Nintendo. All rights reserved. +# +# These coded insructions, 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:: 2008-09-26#$ +# $Rev: 8709 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "MY APP NAME" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + MakerCode 01 + + # + # REMASTER VERSION: Mastering version + # + #RemasterVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G/4G] + # + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile "banner/banner.bnr" + + + # + # Permit LandingNormalJump: for TWL "ApplicationJump" function [TRUE/FALSE] + # + #PermitLandingNormalJump FALSE + + # + # Permit LandingTmpJump: for TWL "ApplicationJump" function [TRUE/FALSE] + # + #PermitLandingTmpJump FALSE + + ### + ### Setting for TWL + ### + + # + # ROM HEADER Ltd: Provided to every product by NINTENDO + # + RomHeaderLtd $(TWLSDK_ROOT)/tools/bin/rom_header.LTD.sbin + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD + # MAP2_BB_HYB/MAP2_BB_LTD/MAP2_TS_HYB/MAP2_TS_LTD] + # don't have to edit + # + WramMapping MAP_TS_SCR + + # + # CardRegion: card region [Japan/America/Europe/Australia/China/Korea] + # + CardRegion ALL + + # + # CommonClientKey: launcher deliver common client Key [TRUE/FALSE] + # + CommonClientKey TRUE + + # + # HwAESSlotA_SSLClientCert: launcher deliver HW AES slot A setting [TRUE/FALSE] + # + HwAESSlotA_SSLClientCert TRUE + + # + # HwAESSlotB: launcher deliver HW AES slot B setting [TRUE/FALSE] + # + HwAESSlotB TRUE + + # + # HwAESSlotB for Sign JPEG for Launcher: launcher deliver HW AES slot B setting for Sign JPEG for Launcher [TRUE/FALSE] + # + #HwAESSlotB_SignJPEGForLauncher FALSE + + # + # HwAESSlotB for Sign JPEG for User: launcher deliver HW AES slot B setting for Sign JPEG for User [TRUE/FALSE] + # + #HwAESSlotB_SignJPEGForUser FALSE + + # + # HwAESSlotC: launcher deliver HW AES slot C setting [TRUE/FALSE] + # + #HwAESSlotC FALSE + + # + # SDCardAccess: sd card access control [TRUE/FALSE] + # + SDCardAccess TRUE + + # + # NANDAccess: NAND access control [TRUE/FALSE] + # + NANDAccess TRUE + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + # + # Disp WiFiConnection Icon for Launcher [TRUE/FALSE] + # + #WiFiConnectionIcon FALSE + + # + # Disp DSWireless Icon for Launcher [TRUE/FALSE] + # + #DSWirelessIcon FALSE + + # + # Disable debug [TRUE/FALSE] + # + DisableDebug FALSE + + # + # Agree EULA [TRUE/FALSE] + # + #AgreeEULA FALSE + + # + # Agree EULA version [1 - 255] + # + #AgreeEULAVersion 1 + + ### + #### END +} + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + #Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType System + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + #Launch TRUE + + # + # Boot allowed Media: [GameCard] + # + Media GameCard + + # + # Data only title : [TRUE/FALSE] + # don't have to edit + #DataOnly FALSE + + # + # Secure title : [TRUE/FALSE] + # don't have to edit + Secure TRUE + + # + # InitialCode : Your InitialCode in 4 ascii words + # + #InitialCode ABCJ + + # + # Public save data size: [0-/0K-/0M-] + # + #PublicSaveDataSize 0K + + # + # Private save data size: [0-/0K-/0M-] + # + #PrivateSaveDataSize 0K + + # + # Enable SubBannerFile: [TRUE/FALSE] + # + #SubBannerFile FALSE + + # + # Game card power on: [TRUE/FALSE] + # + GameCardOn FALSE + + # + # Game card transferd to nitro mode: [TRUE/FALSE] + # + #GameCardNitroMode FALSE + + # + # Shared2 file size: [DISABLE/0-4194304/0K-4096K/0M-4M] + # + #Shared2File0Size Disable + #Shared2File1Size Disable + #Shared2File2Size Disable + #Shared2File3Size Disable + #Shared2File4Size Disable + #Shared2File5Size Disable +} + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot $(MAKEROM_ROMROOT) + Root / + File $(MAKEROM_ROMFILES) +} + +Rating +{ + # + # Permited age to play for each rating organization + # + # Supported organization + # - CERO (OGN0) : for Japan + # - ESRB (OGN1) : for North America + # - BBFC (OGN2) : obsolete organization + # - USK (OGN3) : for German + # - PEGI_GEN (OGN4) : for Europe + # - PEGI_FINLAND (OGN5) : obsolete organization + # - PEGI_PRT (OGN6) : for Portugal + # - PEGI_BBFC (OGN7) : for UK + # - OFLC (OGN8) : for Australia and NewZealand + # - GRB (OGN9) : for Korea + # - OGN10 : reserved + # - OGN11 : reserved + # - OGN12 : reserved + # - OGN13 : reserved + # - OGN14 : reserved + # - OGN15 : reserved + # + # Available age [ 0 - 31 / PENDING / FREE ] + + CERO FREE +# ESRB FREE +# USK FREE +# PEGI_GEN FREE +# PEGI_PRT FREE +# PEGI_BBFC FREE +# OFLC FREE +# GRB FREE +} diff --git a/build/tools/sctools/copy_dst/src/main.c b/build/tools/sctools/copy_dst/src/main.c new file mode 100644 index 0000000..f2e193c --- /dev/null +++ b/build/tools/sctools/copy_dst/src/main.c @@ -0,0 +1,548 @@ +/*---------------------------------------------------------------------------* + Project: TWLSDK - demos - MI - ndma-1 + File: main.c + + Copyright 2007 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. + + *---------------------------------------------------------------------------*/ +#include +#include +#include "ecdl.h" +#include +#include +#include +#include + +#include "font.h" +#include "text.h" +#include "mprintf.h" +#include "gfx.h" +#include "key.h" +#include "my_fs_util.h" +#include "mynvram.h" + +#include "stream.h" + +#include "hwi.h" + +#include "hatamotolib.h" +#include "ecdl.h" + +#include "mywlan.h" + +#include "nuc.h" + + + +//#define DEBUG_PRINT 1 + +//================================================================================ + +static FSEventHook sSDHook; +static BOOL sd_card_flag = FALSE; + + +static void SDEvents(void *userdata, FSEvent event, void *arg) +{ + (void)userdata; + (void)arg; + if (event == FS_EVENT_MEDIA_REMOVED) { + sd_card_flag = FALSE; + mprintf("sdmc:removed!\n"); + } + else if (event == FS_EVENT_MEDIA_INSERTED) { + sd_card_flag = TRUE; + mprintf("sdmc:inserted!\n"); + } +} + +typedef struct { + RTCDate rtc_date; + RTCTime rtc_time; + BOOL shop_record_flag; + u8 movableUniqueID[ LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN ]; // 移行可能なユニークID 16byte +} MyData; + +static MyData mydata; + +static int vram_num_main = 1; +static int vram_num_sub = 0; + +void TwlMain(void) +{ + void* newArenaLo; + OSHeapHandle hHeap; + u16 keyData; + int loop_counter = 0; + int save_dir_info = 0; + MY_DIR_ENTRY_LIST *dir_entry_list_head = NULL; + RTCDate rtc_date; + RTCTime rtc_time; + LCFGTWLHWNormalInfo hwn_info; + LCFGTWLHWSecureInfo hws_info; + int i; + int n; + char path_base[256]; + char path_log[256]; + char path[256]; + u8 macAddress[6]; + + OS_Init(); + OS_InitThread(); + + OS_InitTick(); + OS_InitAlarm(); + + + // マスター割り込みフラグを許可に + (void)OS_EnableIrq(); + + // IRQ 割り込みを許可します + (void)OS_EnableInterrupts(); + + + Gfx_Init(); + + /* + 0 -> black + 1 -> red + 2 -> green + 3 -> blue + 4 -> yellow + 5 -> purple + 6 -> sky blue + 7 -> red + 8 -> green + 9 -> blue + 0xA -> yellow + 0xB -> purple + 0xC -> sky blue + 0xD -> white + 0xE -> white + 0xF -> white + + */ + // m_set_palette(tc[0], 0xF); + + + // ARM7との通信FIFO割り込み許可 + (void)OS_EnableIrqMask(OS_IE_SPFIFO_RECV); + + // ファイルシステム初期化 + FS_Init( FS_DMA_NOT_USE ); + + + // メインアリーナのアロケートシステムを初期化 + newArenaLo = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1); + OS_SetMainArenaLo(newArenaLo); + + // メインアリーナ上にヒープを作成 + hHeap = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi()); + OS_SetCurrentHeap(OS_ARENA_MAIN, hHeap); + + RTC_Init(); + + SCFG_Init(); + + NVRAMi_Init(); + + SND_Init(); + stream_main(); + + // 必須;SEA の初期化 + SEA_Init(); + + // 不要:NAM の初期化 + // NAM_Init(&AllocForNAM, &FreeForNAM); + + // 必須:ES の初期化 + ES_InitLib(); + + + if( FALSE == MiyaReadHWNormalInfo( &hwn_info ) ) { + mprintf("HW Normal Info. read error\n"); + } + else { + mprintf("HW Normal Info. read succeeded.\n"); + mprintf("UniqueID\n 0x"); + for( i = 0; i < LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN/2 ; i++ ) { + mprintf("%02X:", hwn_info.movableUniqueID[i]); + } + mprintf("\n 0x"); + for( ; i < LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN ; i++ ) { + mprintf("%02X:", hwn_info.movableUniqueID[i]); + } + mprintf("\n"); + // mprintf(" RTC Adjust data = 0x%02x\n", hwn_info.rtcAdjust ); + } + + mprintf("\n"); + + if( FALSE == MiyaReadHWSecureInfo( &hws_info ) ) { + mprintf("HW Secure Info. - read failed\n"); + } + else { + mprintf("HW Secure Info. - read succeeded.\n"); + + mprintf(" Serial No.\n 0x"); + for( i = 0; i < LCFG_TWL_HWINFO_SERIALNO_LEN_MAX/2 ; i++ ) { + mprintf("%02X:", hws_info.serialNo[i]); + } + mprintf("\n 0x"); + for( ; i < LCFG_TWL_HWINFO_SERIALNO_LEN_MAX ; i++ ) { + if( hws_info.serialNo[i] ) { + mprintf("%02X:", hws_info.serialNo[i]); + } + else { + // #define LCFG_TWL_HWINFO_SERIALNO_LEN_MAX 15 // 本体シリアルNo.長Max(終端付きなので、14bytesまで拡張 + // 終端をみつけたらブレーク + break; + } + } + mprintf("\n"); + mprintf("%s\n", hws_info.serialNo); + + mprintf(" validLang.bmp = 0x%08x\n", hws_info.validLanguageBitmap ); + mprintf(" wifi disable flag = %d\n", hws_info.flags.forceDisableWireless ); + mprintf(" lchr-TitleIDLo = " ); + for( i = 0 ; i < 4 ; i++ ) { + mprintf("%02X:", hws_info.launcherTitleID_Lo[i]); + } + mprintf("\n Region data = 0x%02x\n\n", hws_info.region ); + } + + + + + OS_GetMacAddress( macAddress ); + mprintf("macAddress "); + for ( i = 0 ; i < 6 ; i++ ) { + mprintf("%02X:", macAddress[i]); + } + mprintf("\n"); + + + if( FALSE == SDCardValidation() ) { + sd_card_flag = FALSE; + mprintf("No SD Card\n"); + } + else { + sd_card_flag = TRUE; + mprintf("Detect SD Card\n"); + } + + FS_RegisterEventHook("sdmc", &sSDHook, SDEvents, NULL); + + + STD_StrCpy( path_base , "sdmc:/" ); + STD_StrCat( path_base , (const char *)hws_info.serialNo ); + STD_StrCat( path_base , "/" ); + + + + + while( 1 ) { + OS_WaitVBlankIntr(); + Gfx_Render( vram_num_main , vram_num_sub ); + (void)RTC_GetTime( &rtc_time ); + + keyData = m_get_key_trigger(); + + // ARM7コマンド応答受信 + while (SND_RecvCommandReply(SND_COMMAND_NOBLOCK) != NULL) + { + } + // コマンドフラッシュ(フラッシュして即座に実行を要求) + (void)SND_FlushCommand(SND_COMMAND_NOBLOCK | SND_COMMAND_IMMEDIATE); + + + if ( keyData & PAD_BUTTON_R ) { + } + else if ( keyData & PAD_BUTTON_L ) { + } + else if ( keyData & PAD_BUTTON_A ) { + /* ユーザーデータ吸出しモード */ + if( sd_card_flag == TRUE ) { + + mprintf("BACKUP to SD Card\n"); + /************************************/ + + /* ショップの履歴確認 */ + if( TRUE == CheckShopRecord(NULL) ) { + mydata.shop_record_flag = TRUE; + } + else { + mydata.shop_record_flag = FALSE; + mprintf("no shop record\n"); + } + + + + /* 日時の保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "twl_rtc.dat" ); + if( RTC_RESULT_SUCCESS != RTC_GetDate( &rtc_date ) ) { + mprintf("rtc read date error.\n"); + } + if( RTC_RESULT_SUCCESS != RTC_GetTime( &rtc_time ) ) { + mprintf("rtc read time error.\n"); + } + + STD_CopyMemory( (void *)&(mydata.rtc_date), (void *)&rtc_date, sizeof(RTCDate) ); + STD_CopyMemory( (void *)&(mydata.rtc_time), (void *)&rtc_time, sizeof(RTCTime) ); + STD_CopyMemory( (void *)(mydata.movableUniqueID), (void *)hwn_info.movableUniqueID, LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN ); + if( TRUE == MydataSave(path, (void *)&mydata, sizeof(MyData), NULL) ) { + } + + + + /* nand:/sysディレクトリまわりの保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "twl_ninfo.dat" ); + if( TRUE == MiyaBackupHWNormalInfo( path ) ) { + mprintf("HWInfo Normal backup completed.\n"); + } + + /* Wifi設定の保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "twl_nor.bin" ); + if( TRUE == nvram_backup( path ) ) { + mprintf("nvram backup completed.\n"); + } + + /* nand:/shared1ディレクトリまわりの保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "twl_cfg.dat" ); + if( TRUE == MiyaBackupTWLSettings( path ) ) { + mprintf("TWL CFG backup completed.\n"); + } + + + /* nand:/shared2ディレクトリまわりの保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "shared2" ); + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , "shared2.txt" ); + + if( 0 == copy_r( &dir_entry_list_head, path, "nand:/shared2" , path_log ) ) { + mprintf("copy_r shared2 completed.\n"); + PrintDirEntryListBackward( dir_entry_list_head, NULL ); + STD_StrCpy( path , path_base ); + STD_StrCat( path , "shared2.lst" ); + SaveDirEntryList( dir_entry_list_head, path ); + } + (void)ClearDirEntryList( &dir_entry_list_head ); + + + /* nand2:/photoディレクトリまわりの保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "photo" ); + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , "photolog.txt" ); + + if( 0 == copy_r( &dir_entry_list_head, path , "nand2:/photo" , path_log ) ) { + mprintf("copy_r photo completed.\n"); + PrintDirEntryListBackward( dir_entry_list_head, NULL ); + STD_StrCpy( path , path_base ); + STD_StrCat( path , "photo.lst" ); + SaveDirEntryList( dir_entry_list_head, path ); + } + (void)ClearDirEntryList( &dir_entry_list_head ); + + /* nand:/ticketはチケット同期?でうまいこと合わせてくれるんでバックアップ不要 */ + + /* nand:/titleディレクトリまわりの保存 */ + /* **.savファイルをすべてバックアップ */ + + STD_StrCpy( path , path_base ); + STD_StrCat( path , "title" ); + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , "titlelog.txt" ); + + if( 0 == find_title_save_data( &dir_entry_list_head, path , "nand:/title", &save_dir_info, path_log ) ) { + mprintf("find_title_save_data completed.\n"); + PrintDirEntryListBackward( dir_entry_list_head, NULL ); + STD_StrCpy( path , path_base ); + STD_StrCat( path , "title.lst" ); + + SaveDirEntryList( dir_entry_list_head , path ); + } + (void)ClearDirEntryList( &dir_entry_list_head ); + + + + /* タイトルリストの生成 */ + /* + nand:/title/00030004/ + + nand:/title/00030004/34626241/content/title.tmd + nand:/title/00030004/34626241/content/00000000.app + nand:/title/00030004/34626241/data/ + + nand:/title/00030017/484e4141 は ランチャー + nand:/title/00030015/484e4641 は shop + nand:/title/00030015/484e4241 は 本体設定 + + + No. 0 0003000f484e4c41 + No. 1 0003000f484e4841 + No. 2 0003000f484e4341 + No. 3 00030015484e4241 + No. 4 00030017484e4141 launcher + ^ + | ここの最下位ビットが1のやつがシステムアプリ + | + システムアプリはダウンロード対象外 + */ + + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , "title2log.txt" ); + if( 0 == get_title_id( &dir_entry_list_head, "nand:/title", &save_dir_info, path_log ) ) { + mprintf("get_title_id completed.\n"); + + // STD_StrCpy( path , path_base ); + // STD_StrCat( path , "titlelist.txt" ); + { + void *pBuffer; + int count; + int i,j; + char *ptr; + GetDirEntryList( dir_entry_list_head, &pBuffer, &count); + OS_TPrintf("count = %d\n", count ); + ptr = (char *)pBuffer; + + if( ptr != NULL && count != 0 ) { + for( j = 0 ; j < count ; j++ ) { + OS_TPrintf("No. %d ",j); + for( i = 0 ; i < 16 ; i++ ) { + OS_TPrintf("%c", *ptr); + ptr++; + } + OS_TPrintf("\n"); + } + OS_Free(pBuffer); + } + } + + + + PrintSrcDirEntryListBackward( dir_entry_list_head, NULL ); + } + (void)ClearDirEntryList( &dir_entry_list_head ); + + } + else { + mprintf("insert SD card\n"); + } + } + else if ( keyData & PAD_BUTTON_B ) { + /* ユーザーデータ書き込みモード */ + if( TRUE == LoadWlanConfigFile("sdmc:/wlan_cfg.txt") ) { + OS_TPrintf("SSID = %s\n", GetWlanSSID()); + OS_TPrintf("MODE = "); + switch( GetWlanMode() ) { + case 1: + OS_TPrintf("OPEN\n"); + break; + case 2: + OS_TPrintf("WEP128\n"); + break; + case 3: + OS_TPrintf("WPA-TKIP\n"); + break; + case 4: + OS_TPrintf("WPA2-TKIP\n"); + break; + case 5: + OS_TPrintf("WPA-AES\n"); + break; + case 6: + OS_TPrintf("WPA2-AES\n"); + break; + defalut: + OS_TPrintf("Unknow mode..\n"); + break; + } + OS_TPrintf("KEY STR = %s\n", GetWlanKEYSTR()); + { + u8 buf[256]; + int len; + int i; + len = GetWlanKEYBIN(buf); + if( len ) { + OS_TPrintf("KEY BIN = 0x"); + for( i = 0 ; i < len ; i++ ) { + OS_TPrintf("%02X",buf[i]); + } + OS_TPrintf("\n"); + } + } + } + else { + OS_TPrintf("Invalid wlan cfg file\n"); + } + nuc_main(); + + + } + else if ( keyData & PAD_BUTTON_START ) { + } + else if ( keyData & PAD_BUTTON_SELECT ) { + } + else if ( keyData & PAD_BUTTON_X ) { + OS_TPrintf("stream on\n"); + if( TRUE == stream_is_play1_end() ) { + stream_play1(); + } + } + else if ( keyData & PAD_BUTTON_Y ) { + } + else if ( keyData & PAD_KEY_UP ) { + n = m_get_display_offset_y(tc[0]); + n++; + m_set_display_offset_y(tc[0], n); + } + else if ( keyData & PAD_KEY_DOWN ) { + n = m_get_display_offset_y(tc[0]); + n--; + m_set_display_offset_y(tc[0], n); + } + else if ( keyData & PAD_KEY_RIGHT ) { + n = m_get_display_offset_x(tc[0]); + n++; + m_set_display_offset_x(tc[0], n); + } + else if ( keyData & PAD_KEY_LEFT ) { + n = m_get_display_offset_x(tc[0]); + n--; + m_set_display_offset_x(tc[0], n); + } + + + // mfprintf(tc[1], "\f\ncounter = %d\n\n", loop_counter); + mfprintf(tc[1], "\f\n%4d/%02d/%02d %02d:%02d:%02d\n\n", + rtc_date.year + 2000, rtc_date.month , rtc_date.day, + rtc_time.hour , rtc_time.minute , rtc_time.second ); + + mfprintf(tc[1], "press A -> Store to SD Card\n"); + mfprintf(tc[1], "press B -> Load to NAND Flash\n"); + mfprintf(tc[1], "\n"); + + + + + loop_counter++; + + } + OS_Terminate(); +} + + +/*====== End of main.c ======*/ + diff --git a/build/tools/sctools/copy_org/Makefile b/build/tools/sctools/copy_org/Makefile new file mode 100644 index 0000000..4d2fe34 --- /dev/null +++ b/build/tools/sctools/copy_org/Makefile @@ -0,0 +1,90 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - MI - ndma-1 +# File: Makefile +# +# Copyright 2007 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:: 2008-01-17#$ +# $Rev: 3650 $ +# $Author: okubata_ryoma $ +#---------------------------------------------------------------------------- +SUBDIRS = ./banner + +TARGET_PLATFORM := TWL +TWL_ARCHGEN := LIMITED + +SRCDIR = ../common/src ./src + +SRCS = main.c key.c font.c text.c mprintf.c logprintf.c \ + gfx.c hwi.c mynvram.c my_fs_util.c \ + kpsc.cpp ecdl.cpp hatamotolib.cpp \ + sitedefs.c wcm_control.c netconnect.c mywlan.c \ + nuc.c nuc_error_msg.c stream.c + +TARGET_BIN = copy_org.srl +ROM_SPEC = copy_org.rsf + + +ES_DIR = $(ROOT)/add-ins/es +ES_LATEST = $(shell ls -d $(ES_DIR)/es-sdk-*|sort|tail -n 1) +ES_ROOT = $(ES_LATEST) + +LINCLUDES = $(TWLSDK_ROOT)/build/libraries/lcfg/ARM9.TWL/include ../common/src \ + $(ES_ROOT)/twl/include $(ES_ROOT)/common/lib/ec/include + +LLIBRARY_DIRS += $(ES_ROOT)/twl/lib/$(TWL_BUILDTYPE) + + +LLIBRARIES += libecx$(TWL_LIBSUFFIX).a \ + liblcfg$(TWL_LIBSUFFIX).a \ + libnhttp.nssl$(TWL_LIBSUFFIX).a \ + libshr$(TWL_LIBSUFFIX).a \ + libnuc$(TWL_LIBSUFFIX).a \ + libnup$(TWL_LIBSUFFIX).a \ + libnam$(TWL_LIBSUFFIX).a \ + libes$(TWL_LIBSUFFIX).a \ + libsea$(TWL_LIBSUFFIX).a \ + libboc$(TWL_LIBSUFFIX).a \ + libsfs$(TWL_LIBSUFFIX).a \ + libna$(TWL_LIBSUFFIX).a \ + + +# libnhttp$(TWL_LIBSUFFIX).a \ + + +MAKEROM_ROMROOT = ../files +MAKEROM_ROMFILES = fanfare.32.wav + + +COMPONENT_NAME = armadillo +MAKEROM_ARM7_BASE = $(TWL_COMPONENTSDIR)/$(COMPONENT_NAME)/$(TWL_BUILDTYPE_ARM7)/$(COMPONENT_NAME) +MAKEROM_ARM7 = $(MAKEROM_ARM7_BASE).$(TWL_ELF_EXT) + + +include $(TWLWIFI_ROOT)/build/buildtools/commondefs +include $(TWLSDK_ROOT)/build/buildtools/commondefs + + +#---------------------------------- +# セキュアアプリ指定 + +MAKEROM := $(TWL_TOOLSDIR)/bin/makerom.TWL.secure.exe + + +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +#---------------------------------------------------------------------------- + +include $(TWLWIFI_ROOT)/build/buildtools/modulerules +include $(TWLSDK_ROOT)/build/buildtools/modulerules diff --git a/build/tools/sctools/copy_org/banner/Makefile b/build/tools/sctools/copy_org/banner/Makefile new file mode 100644 index 0000000..4f2a5fc --- /dev/null +++ b/build/tools/sctools/copy_org/banner/Makefile @@ -0,0 +1,59 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - nandApp - demos - SubBanner +# File: Makefile +# +# Copyright 2007 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:: 2008-06-27#$ +# $Rev: 6887 $ +# $Author: nakasima $ +#---------------------------------------------------------------------------- +TARGET_PLATFORM = TWL + +include $(TWLSDK_ROOT)/build/buildtools/commondefs +MAKEBANNER = $(TWL_TOOLSDIR)/bin/makebanner.TWL.exe + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +SUB_BANNER_ICON = $(ICON_DIR)/subIcon.bmp +SUB_BANNER_SPEC = sub_banner_v3.bsf + + +TARGETS = banner.bnr +SUB_TARGETS = sub_banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) $(SUB_TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) +BANNER_ICON_MIDDLE = $(addprefix $(BANNER_ICON_NAME), .nbfs .nbfc .nbfp) +SUB_BANNER_ICON_NAME = $(basename $(SUB_BANNER_ICON)) +SUB_BANNER_ICON_MIDDLE = $(addprefix $(SUB_BANNER_ICON_NAME), .nbfs .nbfc .nbfp) + +LDIRT_CLEAN = $(TARGETS) $(SUB_TARGETS) \ + $(BANNER_ICON_MIDDLE) \ + $(SUB_BANNER_ICON_MIDDLE) \ + $(TARGETS:.bnr=.srl) + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) $(SUB_TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) $(BANNER_ICON_MIDDLE) + $(MAKEBANNER) -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +$(SUB_TARGETS): $(SUB_BANNER_SPEC) $(SUB_BANNER_ICON) $(SUB_BANNER_ICON_MIDDLE) + $(MAKEBANNER) -s -N $(SUB_BANNER_ICON_NAME) $(SUB_BANNER_SPEC) $(SUB_TARGETS) +# diff --git a/build/tools/sctools/copy_org/banner/banner_v3.bsf b/build/tools/sctools/copy_org/banner/banner_v3.bsf new file mode 100644 index 0000000..8e54be0 Binary files /dev/null and b/build/tools/sctools/copy_org/banner/banner_v3.bsf differ diff --git a/build/tools/sctools/copy_org/banner/icon/gameIcon.bmp b/build/tools/sctools/copy_org/banner/icon/gameIcon.bmp new file mode 100644 index 0000000..d094481 Binary files /dev/null and b/build/tools/sctools/copy_org/banner/icon/gameIcon.bmp differ diff --git a/build/tools/sctools/copy_org/banner/icon/subIcon.bmp b/build/tools/sctools/copy_org/banner/icon/subIcon.bmp new file mode 100644 index 0000000..5fc9e3b Binary files /dev/null and b/build/tools/sctools/copy_org/banner/icon/subIcon.bmp differ diff --git a/build/tools/sctools/copy_org/banner/sub_banner_v3.bsf b/build/tools/sctools/copy_org/banner/sub_banner_v3.bsf new file mode 100644 index 0000000..2fd176b Binary files /dev/null and b/build/tools/sctools/copy_org/banner/sub_banner_v3.bsf differ diff --git a/build/tools/sctools/copy_org/copy_org.rsf b/build/tools/sctools/copy_org/copy_org.rsf new file mode 100644 index 0000000..be441f2 --- /dev/null +++ b/build/tools/sctools/copy_org/copy_org.rsf @@ -0,0 +1,325 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-TS.rsf +# +# Copyright 2007-2008 Nintendo. All rights reserved. +# +# These coded insructions, 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:: 2008-09-26#$ +# $Rev: 8709 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "MY APP NAME" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + MakerCode 01 + + # + # REMASTER VERSION: Mastering version + # + #RemasterVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G/4G] + # + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile "banner/banner.bnr" + + + # + # Permit LandingNormalJump: for TWL "ApplicationJump" function [TRUE/FALSE] + # + #PermitLandingNormalJump FALSE + + # + # Permit LandingTmpJump: for TWL "ApplicationJump" function [TRUE/FALSE] + # + #PermitLandingTmpJump FALSE + + ### + ### Setting for TWL + ### + + # + # ROM HEADER Ltd: Provided to every product by NINTENDO + # + RomHeaderLtd $(TWLSDK_ROOT)/tools/bin/rom_header.LTD.sbin + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD + # MAP2_BB_HYB/MAP2_BB_LTD/MAP2_TS_HYB/MAP2_TS_LTD] + # don't have to edit + # + WramMapping MAP_TS_SCR + + # + # CardRegion: card region [Japan/America/Europe/Australia/China/Korea] + # + CardRegion ALL + + # + # CommonClientKey: launcher deliver common client Key [TRUE/FALSE] + # + CommonClientKey TRUE + + # + # HwAESSlotA_SSLClientCert: launcher deliver HW AES slot A setting [TRUE/FALSE] + # + HwAESSlotA_SSLClientCert TRUE + + # + # HwAESSlotB: launcher deliver HW AES slot B setting [TRUE/FALSE] + # + HwAESSlotB TRUE + + # + # HwAESSlotB for Sign JPEG for Launcher: launcher deliver HW AES slot B setting for Sign JPEG for Launcher [TRUE/FALSE] + # + #HwAESSlotB_SignJPEGForLauncher FALSE + + # + # HwAESSlotB for Sign JPEG for User: launcher deliver HW AES slot B setting for Sign JPEG for User [TRUE/FALSE] + # + #HwAESSlotB_SignJPEGForUser FALSE + + # + # HwAESSlotC: launcher deliver HW AES slot C setting [TRUE/FALSE] + # + #HwAESSlotC FALSE + + # + # SDCardAccess: sd card access control [TRUE/FALSE] + # + SDCardAccess TRUE + + # + # NANDAccess: NAND access control [TRUE/FALSE] + # + NANDAccess TRUE + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + # + # Disp WiFiConnection Icon for Launcher [TRUE/FALSE] + # + #WiFiConnectionIcon FALSE + + # + # Disp DSWireless Icon for Launcher [TRUE/FALSE] + # + #DSWirelessIcon FALSE + + # + # Disable debug [TRUE/FALSE] + # + DisableDebug FALSE + + # + # Agree EULA [TRUE/FALSE] + # + #AgreeEULA FALSE + + # + # Agree EULA version [1 - 255] + # + #AgreeEULAVersion 1 + + ### + #### END +} + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + #Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType System + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + #Launch TRUE + + # + # Boot allowed Media: [GameCard] + # + Media GameCard + + # + # Data only title : [TRUE/FALSE] + # don't have to edit + #DataOnly FALSE + + # + # Secure title : [TRUE/FALSE] + # don't have to edit + Secure TRUE + + # + # InitialCode : Your InitialCode in 4 ascii words + # + #InitialCode ABCJ + + # + # Public save data size: [0-/0K-/0M-] + # + #PublicSaveDataSize 0K + + # + # Private save data size: [0-/0K-/0M-] + # + #PrivateSaveDataSize 0K + + # + # Enable SubBannerFile: [TRUE/FALSE] + # + #SubBannerFile FALSE + + # + # Game card power on: [TRUE/FALSE] + # + GameCardOn FALSE + + # + # Game card transferd to nitro mode: [TRUE/FALSE] + # + #GameCardNitroMode FALSE + + # + # Shared2 file size: [DISABLE/0-4194304/0K-4096K/0M-4M] + # + #Shared2File0Size Disable + #Shared2File1Size Disable + #Shared2File2Size Disable + #Shared2File3Size Disable + #Shared2File4Size Disable + #Shared2File5Size Disable +} + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot $(MAKEROM_ROMROOT) + Root / + File $(MAKEROM_ROMFILES) +} + +Rating +{ + # + # Permited age to play for each rating organization + # + # Supported organization + # - CERO (OGN0) : for Japan + # - ESRB (OGN1) : for North America + # - BBFC (OGN2) : obsolete organization + # - USK (OGN3) : for German + # - PEGI_GEN (OGN4) : for Europe + # - PEGI_FINLAND (OGN5) : obsolete organization + # - PEGI_PRT (OGN6) : for Portugal + # - PEGI_BBFC (OGN7) : for UK + # - OFLC (OGN8) : for Australia and NewZealand + # - GRB (OGN9) : for Korea + # - OGN10 : reserved + # - OGN11 : reserved + # - OGN12 : reserved + # - OGN13 : reserved + # - OGN14 : reserved + # - OGN15 : reserved + # + # Available age [ 0 - 31 / PENDING / FREE ] + + CERO FREE +# ESRB FREE +# USK FREE +# PEGI_GEN FREE +# PEGI_PRT FREE +# PEGI_BBFC FREE +# OFLC FREE +# GRB FREE +} diff --git a/build/tools/sctools/copy_org/src/main.c b/build/tools/sctools/copy_org/src/main.c new file mode 100644 index 0000000..f2e193c --- /dev/null +++ b/build/tools/sctools/copy_org/src/main.c @@ -0,0 +1,548 @@ +/*---------------------------------------------------------------------------* + Project: TWLSDK - demos - MI - ndma-1 + File: main.c + + Copyright 2007 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. + + *---------------------------------------------------------------------------*/ +#include +#include +#include "ecdl.h" +#include +#include +#include +#include + +#include "font.h" +#include "text.h" +#include "mprintf.h" +#include "gfx.h" +#include "key.h" +#include "my_fs_util.h" +#include "mynvram.h" + +#include "stream.h" + +#include "hwi.h" + +#include "hatamotolib.h" +#include "ecdl.h" + +#include "mywlan.h" + +#include "nuc.h" + + + +//#define DEBUG_PRINT 1 + +//================================================================================ + +static FSEventHook sSDHook; +static BOOL sd_card_flag = FALSE; + + +static void SDEvents(void *userdata, FSEvent event, void *arg) +{ + (void)userdata; + (void)arg; + if (event == FS_EVENT_MEDIA_REMOVED) { + sd_card_flag = FALSE; + mprintf("sdmc:removed!\n"); + } + else if (event == FS_EVENT_MEDIA_INSERTED) { + sd_card_flag = TRUE; + mprintf("sdmc:inserted!\n"); + } +} + +typedef struct { + RTCDate rtc_date; + RTCTime rtc_time; + BOOL shop_record_flag; + u8 movableUniqueID[ LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN ]; // 移行可能なユニークID 16byte +} MyData; + +static MyData mydata; + +static int vram_num_main = 1; +static int vram_num_sub = 0; + +void TwlMain(void) +{ + void* newArenaLo; + OSHeapHandle hHeap; + u16 keyData; + int loop_counter = 0; + int save_dir_info = 0; + MY_DIR_ENTRY_LIST *dir_entry_list_head = NULL; + RTCDate rtc_date; + RTCTime rtc_time; + LCFGTWLHWNormalInfo hwn_info; + LCFGTWLHWSecureInfo hws_info; + int i; + int n; + char path_base[256]; + char path_log[256]; + char path[256]; + u8 macAddress[6]; + + OS_Init(); + OS_InitThread(); + + OS_InitTick(); + OS_InitAlarm(); + + + // マスター割り込みフラグを許可に + (void)OS_EnableIrq(); + + // IRQ 割り込みを許可します + (void)OS_EnableInterrupts(); + + + Gfx_Init(); + + /* + 0 -> black + 1 -> red + 2 -> green + 3 -> blue + 4 -> yellow + 5 -> purple + 6 -> sky blue + 7 -> red + 8 -> green + 9 -> blue + 0xA -> yellow + 0xB -> purple + 0xC -> sky blue + 0xD -> white + 0xE -> white + 0xF -> white + + */ + // m_set_palette(tc[0], 0xF); + + + // ARM7との通信FIFO割り込み許可 + (void)OS_EnableIrqMask(OS_IE_SPFIFO_RECV); + + // ファイルシステム初期化 + FS_Init( FS_DMA_NOT_USE ); + + + // メインアリーナのアロケートシステムを初期化 + newArenaLo = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1); + OS_SetMainArenaLo(newArenaLo); + + // メインアリーナ上にヒープを作成 + hHeap = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi()); + OS_SetCurrentHeap(OS_ARENA_MAIN, hHeap); + + RTC_Init(); + + SCFG_Init(); + + NVRAMi_Init(); + + SND_Init(); + stream_main(); + + // 必須;SEA の初期化 + SEA_Init(); + + // 不要:NAM の初期化 + // NAM_Init(&AllocForNAM, &FreeForNAM); + + // 必須:ES の初期化 + ES_InitLib(); + + + if( FALSE == MiyaReadHWNormalInfo( &hwn_info ) ) { + mprintf("HW Normal Info. read error\n"); + } + else { + mprintf("HW Normal Info. read succeeded.\n"); + mprintf("UniqueID\n 0x"); + for( i = 0; i < LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN/2 ; i++ ) { + mprintf("%02X:", hwn_info.movableUniqueID[i]); + } + mprintf("\n 0x"); + for( ; i < LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN ; i++ ) { + mprintf("%02X:", hwn_info.movableUniqueID[i]); + } + mprintf("\n"); + // mprintf(" RTC Adjust data = 0x%02x\n", hwn_info.rtcAdjust ); + } + + mprintf("\n"); + + if( FALSE == MiyaReadHWSecureInfo( &hws_info ) ) { + mprintf("HW Secure Info. - read failed\n"); + } + else { + mprintf("HW Secure Info. - read succeeded.\n"); + + mprintf(" Serial No.\n 0x"); + for( i = 0; i < LCFG_TWL_HWINFO_SERIALNO_LEN_MAX/2 ; i++ ) { + mprintf("%02X:", hws_info.serialNo[i]); + } + mprintf("\n 0x"); + for( ; i < LCFG_TWL_HWINFO_SERIALNO_LEN_MAX ; i++ ) { + if( hws_info.serialNo[i] ) { + mprintf("%02X:", hws_info.serialNo[i]); + } + else { + // #define LCFG_TWL_HWINFO_SERIALNO_LEN_MAX 15 // 本体シリアルNo.長Max(終端付きなので、14bytesまで拡張 + // 終端をみつけたらブレーク + break; + } + } + mprintf("\n"); + mprintf("%s\n", hws_info.serialNo); + + mprintf(" validLang.bmp = 0x%08x\n", hws_info.validLanguageBitmap ); + mprintf(" wifi disable flag = %d\n", hws_info.flags.forceDisableWireless ); + mprintf(" lchr-TitleIDLo = " ); + for( i = 0 ; i < 4 ; i++ ) { + mprintf("%02X:", hws_info.launcherTitleID_Lo[i]); + } + mprintf("\n Region data = 0x%02x\n\n", hws_info.region ); + } + + + + + OS_GetMacAddress( macAddress ); + mprintf("macAddress "); + for ( i = 0 ; i < 6 ; i++ ) { + mprintf("%02X:", macAddress[i]); + } + mprintf("\n"); + + + if( FALSE == SDCardValidation() ) { + sd_card_flag = FALSE; + mprintf("No SD Card\n"); + } + else { + sd_card_flag = TRUE; + mprintf("Detect SD Card\n"); + } + + FS_RegisterEventHook("sdmc", &sSDHook, SDEvents, NULL); + + + STD_StrCpy( path_base , "sdmc:/" ); + STD_StrCat( path_base , (const char *)hws_info.serialNo ); + STD_StrCat( path_base , "/" ); + + + + + while( 1 ) { + OS_WaitVBlankIntr(); + Gfx_Render( vram_num_main , vram_num_sub ); + (void)RTC_GetTime( &rtc_time ); + + keyData = m_get_key_trigger(); + + // ARM7コマンド応答受信 + while (SND_RecvCommandReply(SND_COMMAND_NOBLOCK) != NULL) + { + } + // コマンドフラッシュ(フラッシュして即座に実行を要求) + (void)SND_FlushCommand(SND_COMMAND_NOBLOCK | SND_COMMAND_IMMEDIATE); + + + if ( keyData & PAD_BUTTON_R ) { + } + else if ( keyData & PAD_BUTTON_L ) { + } + else if ( keyData & PAD_BUTTON_A ) { + /* ユーザーデータ吸出しモード */ + if( sd_card_flag == TRUE ) { + + mprintf("BACKUP to SD Card\n"); + /************************************/ + + /* ショップの履歴確認 */ + if( TRUE == CheckShopRecord(NULL) ) { + mydata.shop_record_flag = TRUE; + } + else { + mydata.shop_record_flag = FALSE; + mprintf("no shop record\n"); + } + + + + /* 日時の保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "twl_rtc.dat" ); + if( RTC_RESULT_SUCCESS != RTC_GetDate( &rtc_date ) ) { + mprintf("rtc read date error.\n"); + } + if( RTC_RESULT_SUCCESS != RTC_GetTime( &rtc_time ) ) { + mprintf("rtc read time error.\n"); + } + + STD_CopyMemory( (void *)&(mydata.rtc_date), (void *)&rtc_date, sizeof(RTCDate) ); + STD_CopyMemory( (void *)&(mydata.rtc_time), (void *)&rtc_time, sizeof(RTCTime) ); + STD_CopyMemory( (void *)(mydata.movableUniqueID), (void *)hwn_info.movableUniqueID, LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN ); + if( TRUE == MydataSave(path, (void *)&mydata, sizeof(MyData), NULL) ) { + } + + + + /* nand:/sysディレクトリまわりの保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "twl_ninfo.dat" ); + if( TRUE == MiyaBackupHWNormalInfo( path ) ) { + mprintf("HWInfo Normal backup completed.\n"); + } + + /* Wifi設定の保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "twl_nor.bin" ); + if( TRUE == nvram_backup( path ) ) { + mprintf("nvram backup completed.\n"); + } + + /* nand:/shared1ディレクトリまわりの保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "twl_cfg.dat" ); + if( TRUE == MiyaBackupTWLSettings( path ) ) { + mprintf("TWL CFG backup completed.\n"); + } + + + /* nand:/shared2ディレクトリまわりの保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "shared2" ); + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , "shared2.txt" ); + + if( 0 == copy_r( &dir_entry_list_head, path, "nand:/shared2" , path_log ) ) { + mprintf("copy_r shared2 completed.\n"); + PrintDirEntryListBackward( dir_entry_list_head, NULL ); + STD_StrCpy( path , path_base ); + STD_StrCat( path , "shared2.lst" ); + SaveDirEntryList( dir_entry_list_head, path ); + } + (void)ClearDirEntryList( &dir_entry_list_head ); + + + /* nand2:/photoディレクトリまわりの保存 */ + STD_StrCpy( path , path_base ); + STD_StrCat( path , "photo" ); + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , "photolog.txt" ); + + if( 0 == copy_r( &dir_entry_list_head, path , "nand2:/photo" , path_log ) ) { + mprintf("copy_r photo completed.\n"); + PrintDirEntryListBackward( dir_entry_list_head, NULL ); + STD_StrCpy( path , path_base ); + STD_StrCat( path , "photo.lst" ); + SaveDirEntryList( dir_entry_list_head, path ); + } + (void)ClearDirEntryList( &dir_entry_list_head ); + + /* nand:/ticketはチケット同期?でうまいこと合わせてくれるんでバックアップ不要 */ + + /* nand:/titleディレクトリまわりの保存 */ + /* **.savファイルをすべてバックアップ */ + + STD_StrCpy( path , path_base ); + STD_StrCat( path , "title" ); + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , "titlelog.txt" ); + + if( 0 == find_title_save_data( &dir_entry_list_head, path , "nand:/title", &save_dir_info, path_log ) ) { + mprintf("find_title_save_data completed.\n"); + PrintDirEntryListBackward( dir_entry_list_head, NULL ); + STD_StrCpy( path , path_base ); + STD_StrCat( path , "title.lst" ); + + SaveDirEntryList( dir_entry_list_head , path ); + } + (void)ClearDirEntryList( &dir_entry_list_head ); + + + + /* タイトルリストの生成 */ + /* + nand:/title/00030004/ + + nand:/title/00030004/34626241/content/title.tmd + nand:/title/00030004/34626241/content/00000000.app + nand:/title/00030004/34626241/data/ + + nand:/title/00030017/484e4141 は ランチャー + nand:/title/00030015/484e4641 は shop + nand:/title/00030015/484e4241 は 本体設定 + + + No. 0 0003000f484e4c41 + No. 1 0003000f484e4841 + No. 2 0003000f484e4341 + No. 3 00030015484e4241 + No. 4 00030017484e4141 launcher + ^ + | ここの最下位ビットが1のやつがシステムアプリ + | + システムアプリはダウンロード対象外 + */ + + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , "title2log.txt" ); + if( 0 == get_title_id( &dir_entry_list_head, "nand:/title", &save_dir_info, path_log ) ) { + mprintf("get_title_id completed.\n"); + + // STD_StrCpy( path , path_base ); + // STD_StrCat( path , "titlelist.txt" ); + { + void *pBuffer; + int count; + int i,j; + char *ptr; + GetDirEntryList( dir_entry_list_head, &pBuffer, &count); + OS_TPrintf("count = %d\n", count ); + ptr = (char *)pBuffer; + + if( ptr != NULL && count != 0 ) { + for( j = 0 ; j < count ; j++ ) { + OS_TPrintf("No. %d ",j); + for( i = 0 ; i < 16 ; i++ ) { + OS_TPrintf("%c", *ptr); + ptr++; + } + OS_TPrintf("\n"); + } + OS_Free(pBuffer); + } + } + + + + PrintSrcDirEntryListBackward( dir_entry_list_head, NULL ); + } + (void)ClearDirEntryList( &dir_entry_list_head ); + + } + else { + mprintf("insert SD card\n"); + } + } + else if ( keyData & PAD_BUTTON_B ) { + /* ユーザーデータ書き込みモード */ + if( TRUE == LoadWlanConfigFile("sdmc:/wlan_cfg.txt") ) { + OS_TPrintf("SSID = %s\n", GetWlanSSID()); + OS_TPrintf("MODE = "); + switch( GetWlanMode() ) { + case 1: + OS_TPrintf("OPEN\n"); + break; + case 2: + OS_TPrintf("WEP128\n"); + break; + case 3: + OS_TPrintf("WPA-TKIP\n"); + break; + case 4: + OS_TPrintf("WPA2-TKIP\n"); + break; + case 5: + OS_TPrintf("WPA-AES\n"); + break; + case 6: + OS_TPrintf("WPA2-AES\n"); + break; + defalut: + OS_TPrintf("Unknow mode..\n"); + break; + } + OS_TPrintf("KEY STR = %s\n", GetWlanKEYSTR()); + { + u8 buf[256]; + int len; + int i; + len = GetWlanKEYBIN(buf); + if( len ) { + OS_TPrintf("KEY BIN = 0x"); + for( i = 0 ; i < len ; i++ ) { + OS_TPrintf("%02X",buf[i]); + } + OS_TPrintf("\n"); + } + } + } + else { + OS_TPrintf("Invalid wlan cfg file\n"); + } + nuc_main(); + + + } + else if ( keyData & PAD_BUTTON_START ) { + } + else if ( keyData & PAD_BUTTON_SELECT ) { + } + else if ( keyData & PAD_BUTTON_X ) { + OS_TPrintf("stream on\n"); + if( TRUE == stream_is_play1_end() ) { + stream_play1(); + } + } + else if ( keyData & PAD_BUTTON_Y ) { + } + else if ( keyData & PAD_KEY_UP ) { + n = m_get_display_offset_y(tc[0]); + n++; + m_set_display_offset_y(tc[0], n); + } + else if ( keyData & PAD_KEY_DOWN ) { + n = m_get_display_offset_y(tc[0]); + n--; + m_set_display_offset_y(tc[0], n); + } + else if ( keyData & PAD_KEY_RIGHT ) { + n = m_get_display_offset_x(tc[0]); + n++; + m_set_display_offset_x(tc[0], n); + } + else if ( keyData & PAD_KEY_LEFT ) { + n = m_get_display_offset_x(tc[0]); + n--; + m_set_display_offset_x(tc[0], n); + } + + + // mfprintf(tc[1], "\f\ncounter = %d\n\n", loop_counter); + mfprintf(tc[1], "\f\n%4d/%02d/%02d %02d:%02d:%02d\n\n", + rtc_date.year + 2000, rtc_date.month , rtc_date.day, + rtc_time.hour , rtc_time.minute , rtc_time.second ); + + mfprintf(tc[1], "press A -> Store to SD Card\n"); + mfprintf(tc[1], "press B -> Load to NAND Flash\n"); + mfprintf(tc[1], "\n"); + + + + + loop_counter++; + + } + OS_Terminate(); +} + + +/*====== End of main.c ======*/ + diff --git a/build/tools/sctools/files/fanfare.32.wav b/build/tools/sctools/files/fanfare.32.wav new file mode 100644 index 0000000..eb6cc56 Binary files /dev/null and b/build/tools/sctools/files/fanfare.32.wav differ