git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlToolsRED@2 7061adef-622a-194b-ae81-725974e89856

This commit is contained in:
miya 2008-10-16 01:58:27 +00:00
parent dbffb4e813
commit dd3a7523e3
60 changed files with 12472 additions and 0 deletions

View File

@ -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 =====

View File

@ -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 <nitroWiFi/wcm.h>
// 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
*---------------------------------------------------------------------------*/

View File

@ -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);
}

View File

@ -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 <twl.h>
#include <twl/nam.h>
#include <nitro/fs.h>
#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_

View File

@ -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 <twl.h>
#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
};

View File

@ -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

View File

@ -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]);
}
}

View File

@ -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_ */

View File

@ -0,0 +1,717 @@
#include "ecdl.h"
#include <twl/sea.h>
#include <twl/lcfg.h>
#include <twl/na.h>
#include <twl/nam.h>
#ifdef USE_DWC
#include <dwc.h>
#include <ac/dwc_ac.h>
#endif
#include <NitroWiFi/nhttp.h>
#include <NitroWiFi/nssl.h>
#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<u32>(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<const u8*>(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<u8 (*)[LCFG_READ_TEMP]>(pWork));
SDK_ASSERT(bSuccess);
Free(pWork);
}
{
// ニックネームが空なら適当に設定
if( *LCFG_TSD_GetNicknamePtr() == L'\0' )
{
LCFG_TSD_SetNickname(reinterpret_cast<const u16*>(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<u8 (*)[LCFG_WRITE_TEMP]>(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<u8*>(&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<u32>(fuseId >> 32), static_cast<u32>(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<s32>(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();
}

View File

@ -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__

View File

@ -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 <twl.h>
// #include <acsign.h>
#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;
}

View File

@ -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 <twl.h>
#include <twl/lcfg/common/api.h>
#include <twl/lcfg/common/TWLSettings.h>
#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__

View File

@ -0,0 +1,42 @@
#include <twl.h>
#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;
}

View File

@ -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_ */

View File

@ -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__);
}

View File

@ -0,0 +1,795 @@
/**************************************************************************
* Copyright (C) 1997, Nintendo Co.,Ltd. *
*************************************************************************/
#include <twl.h>
#include "text.h"
#include "mprintf.h"
#include "logprintf.h"
#define __std(ref) ref
// #define __std(ref) ::std::ref
#include <twl.h>
#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;
}
}

View File

@ -0,0 +1,7 @@
#ifndef _LOGPRINT_
#define _LOGPRINT_
void miya_log_fprintf(FSFile *fd, const char *fmt, ...);
#endif /* _LOGPRINT_ */

View File

@ -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 <twl.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)
#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;
}
}

View File

@ -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_ */

File diff suppressed because it is too large Load Diff

View File

@ -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_ */

View File

@ -0,0 +1,246 @@
#include <twl.h>
#include <nitro/nvram/nvram.h>
#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;
}

View File

@ -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_ */

View File

@ -0,0 +1,311 @@
#include <twl.h>
#include <nitroWiFi.h>
#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は文字なので */
// 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;
}

View File

@ -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_ */

View File

@ -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 <nitro.h>
#include <nitroWiFi.h>
#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

View File

@ -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_ */

View File

@ -0,0 +1,503 @@
#include <twl.h>
#include <twl/sea.h>
#include <twl/na.h>
#include <TwlWiFi/nuc.h>
#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;
}

View File

@ -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_ */

View File

@ -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 <twl.h>
#include <TwlWiFi/nuc.h>
#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];
}
}

View File

@ -0,0 +1,52 @@
#ifndef _NUC_ERROR_MSG_H_
#define _NUC_ERROR_MSG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <twl/types.h>
/*---------------------------------------------------------------------------*
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*
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
*---------------------------------------------------------------------------*/

View File

@ -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 <nitro.h>
#include <nitroWiFi.h>
#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 ======*/

View File

@ -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_

View File

@ -0,0 +1,398 @@
#include <twl.h>
#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:
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: TRUEFALSE
*---------------------------------------------------------------------------*/
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;
}

View File

@ -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_ */

View File

@ -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" },

View File

@ -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" },

View File

@ -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" },

View File

@ -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" },

View File

@ -0,0 +1,412 @@
#include <twl.h>
#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);
}
}

View File

@ -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_ */

View File

@ -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 <nitro/os.h>
#include <nitroWiFi.h>
#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
* 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
*
*/
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
*---------------------------------------------------------------------------*/

View File

@ -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
*---------------------------------------------------------------------------*/

View File

@ -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
#----------------------------------
# ƒZƒLƒ…ƒAƒAƒvƒŠŽwè
MAKEROM := $(TWL_TOOLSDIR)/bin/makerom.TWL.secure.exe
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
do-build: $(TARGETS)
#----------------------------------------------------------------------------
include $(TWLWIFI_ROOT)/build/buildtools/modulerules
include $(TWLSDK_ROOT)/build/buildtools/modulerules

View File

@ -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)
#

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

View File

@ -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
}

View File

@ -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 <twl.h>
#include <nitro/nvram/nvram.h>
#include "ecdl.h"
#include <twl/sea.h>
#include <twl/lcfg.h>
#include <twl/na.h>
#include <twl/nam.h>
#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
^
|
|
*/
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 ======*/

View File

@ -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
#----------------------------------
# ƒZƒLƒ…ƒAƒAƒvƒŠŽwè
MAKEROM := $(TWL_TOOLSDIR)/bin/makerom.TWL.secure.exe
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
do-build: $(TARGETS)
#----------------------------------------------------------------------------
include $(TWLWIFI_ROOT)/build/buildtools/modulerules
include $(TWLSDK_ROOT)/build/buildtools/modulerules

View File

@ -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)
#

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

View File

@ -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
}

View File

@ -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 <twl.h>
#include <nitro/nvram/nvram.h>
#include "ecdl.h"
#include <twl/sea.h>
#include <twl/lcfg.h>
#include <twl/na.h>
#include <twl/nam.h>
#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
^
|
|
*/
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 ======*/

Binary file not shown.