diff --git a/build/tests/compressSharedFontLoad/README.txt b/build/tests/compressSharedFontLoad/README.txt new file mode 100644 index 00000000..5fed4e21 --- /dev/null +++ b/build/tests/compressSharedFontLoad/README.txt @@ -0,0 +1,60 @@ +# ------------------------------------------ +# 共有フォント圧縮時のロード速度実験 +# +# 作成者 : nishikawa_takeshi +# ------------------------------------------ + +実験は以下の2ステップから構成されます。 + +1. 共有フォントの圧縮とインポート +2. ロード速度の測定 + +以下、各ステップについて説明します。 + + +# ------------------------------------------ +# ステップ1 共有フォントの圧縮とインポート +# ------------------------------------------ + +(1)共有フォントの圧縮 + +compSharedFont ディレクトリに移動して make してください。 + % cd compSharedFont + % make + +(2)圧縮したフォントのインポート + +圧縮された共有フォントを NandInitializerRed でインポートする必要がありますが、 +NandInitializerRed は、SDからではなく、ROMアーカイブからインポートします。 +(つまり、自身のSRL内部に共有フォントを持ちます。) +そのため、NandInitializerRed を再度、ビルドする必要があります。 +圧縮フォントは(1)の処理によって、NandInitializerRed のディレクトリに自動的にコピーされますので、 +コピーする必要はありません。 + + % cd $(TWL_IPL_RED_ROOT)/build/systemMenu_tools/NandIntializerRed + % make clean; make + +再ビルドされた NandInitializerRed.srl (ARM9.TWL/bin/以下にあります) をSDカードにコピーして、 +SDカードブートすると、メニューからフォントをインポートする項目を選択できます。 + +# ------------------------------------------ +# ステップ2 ロード速度の測定 +# ------------------------------------------ + +ロード速度の測定プログラムは、testLoadSpeed ディレクトリにあります。 +ここで、OS ライブラリの共有フォント関連の関数を変更し、 +されに、TWLSDK を SYSMENU パッケージとしてビルドしなおす必要があります。 +これらの変更とテストプログラムのビルドは、make にオプションをつけると自動的に実行されます。 +(お好みで、TWL_WITHOUT_DEMOS=TRUE や TWL_FINALROM=TRUE オプションをおつけください。) + + % cd testLoadSpeed + % make TEST_TWLSDK_REBUILD=TRUE + +上記の TWLSDK の変更をしないときには、テストプログラムのビルドが正常にできません。 + +テストプログラムを変更する場合、毎回 TWLSDK をビルドするのは時間がかかりますので、 +オプションをつけずに make すると、テストプログラムのビルドのみ実行します。 + + % make + +作成されたテストプログラムを実行すれば、圧縮した共有フォントのロード時間を測定できます。 diff --git a/build/tests/compressSharedFontLoad/compSharedFont/Makefile b/build/tests/compressSharedFontLoad/compSharedFont/Makefile new file mode 100644 index 00000000..bb6fe80b --- /dev/null +++ b/build/tests/compressSharedFontLoad/compSharedFont/Makefile @@ -0,0 +1,61 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL +# 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: +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU + +SUBDIRS = compBLZ_modified + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +FONT_TIMESTAMP = 08061300 +FONT_DIR = WW +FONTS = TBF1_l.NFTR \ + TBF1_m.NFTR \ + TBF1_s.NFTR +FONT_RSC = $(addprefix $(FONT_DIR)/, $(FONTS)) + +FONT_ORG_DIR = $(TWL_IPL_RED_ROOT)/build/systemMenu_RED/sharedFont/WW +FONT_ORG_RSC = $(addprefix $(FONT_ORG_DIR)/, $(FONTS)) + +ifneq ($(TWL_IPL_RED_PRIVATE_ROOT),) +FONT_TABLE = TWLFontTable.dat +endif + +GEN_FONT_TABLE = ./genFontTable.plx + +#---------------------------------------------------------------------------- +INSTALL_TARGETS = $(FONT_TABLE) +INSTALL_DIR = $(TWL_IPL_RED_ROOT)/build/systemMenu_tools/NandInitializerRed/data + +LDIRT_CLEAN = $(FONT_TABLE) $(FONT_RSC) + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +do-build : $(FONT_TABLE) + +# step1 : copy sharedFonts into local directory for work +$(FONT_RSC): + cp $(FONT_ORG_RSC) $(FONT_DIR) + +# step2 : compress sharedFonts and them in local directory +$(FONT_TABLE): $(FONT_RSC) + $(GEN_FONT_TABLE) $(FONT_TIMESTAMP) $(FONT_RSC) + +#===== End of Makefile ===== diff --git a/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/Makefile b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/Makefile new file mode 100644 index 00000000..89101f6e --- /dev/null +++ b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/Makefile @@ -0,0 +1,73 @@ +#! make -f +#--------------------------------------------------------------------------- +# Project: TwlSDK - tools - compBLZ +# File: Makefile +# +# Copyright 2008 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#--------------------------------------------------------------------------- + +TARGET_PLATFORM = TWL NITRO + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#--------------------------------------------------------------------------- + +TARGET_BIN = compBLZ.exe +TARGETS = $(BINDIR)/$(TARGET_BIN) + +SRCS = main.c \ + compress.c \ + file.c \ + version.c + +HEADERS = common.h \ + compress.h \ + file.h + +INCDIR += ../../../include +OBJDIR = obj +BINDIR = bin + +OBJS = $(addprefix $(OBJDIR)/,$(SRCS:.c=.o)) + +MACROS += -DSDK_TWL $(addprefix -I,$(INCDIR)) +NEWDIRS = $(OBJDIR) $(BINDIR) +LDIRT_CLEAN += $(NEWDIRS) version.c + +#INSTALL_DIR = $(TWL_INSTALL_TOOLSDIR)/bin +#INSTALL_TARGETS = $(TARGETS) + +#--------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules.x86 + +do-build: $(TARGETS) + +$(TARGETS): $(OBJS) $(LIBDGT) $(MAKEFILE) + $(CC_X86) $(OBJS) $(LIBDGT) -o $@ + +$(OBJS):%.o: + $(COMPILE_C) + +$(OBJDIR)/main.o: main.c file.h version.c +$(OBJDIR)/compress.o: compress.c compress.h +$(OBJDIR)/file.o: file.c file.h +$(OBJDIR)/version.o: version.c + +version.c: $(filter-out version.c,$(SRCS)) $(HEADERS) $(MAKEFILE) + @for i in $^ ; \ + do \ + date -r $$i +'const unsigned long SDK_DATE_OF_LATEST_FILE=%Y%m%dUL;'; \ + done | sort | tail -1 > $@ + +#===== End of Makefile ===== diff --git a/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/_ b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/_ new file mode 100644 index 00000000..95665859 --- /dev/null +++ b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/_ @@ -0,0 +1 @@ +SDK_CONFIDENTIAL diff --git a/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/common.h b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/common.h new file mode 100644 index 00000000..9f60ce54 --- /dev/null +++ b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/common.h @@ -0,0 +1,42 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - compstatic + File: common.h + + Copyright 2003 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$ + *---------------------------------------------------------------------------*/ +#ifndef COMMON_H__ +#define COMMON_H__ + +typedef enum +{ + TRUE = 1, + FALSE = 0 +} +BOOL; + +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned long u32; +typedef signed char s8; +typedef signed short s16; +typedef signed long s32; + +// macro +#define MIN(a,b) ((a)<(b)?(a):(b)) +#define ROUNDUP4(x) (((x)+3)&~3) +#define LE(a) ((((a)<<24)&0xff000000)|(((a)<<8)&0x00ff0000)|\ + (((a)>>8)&0x0000ff00)|(((a)>>24)&0x000000ff)) +#define FREE(x) do { if (x){ free(x); x = NULL; } } while(0) + + +#endif //COMMON_H__ diff --git a/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/compress.c b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/compress.c new file mode 100644 index 00000000..57f4b5bc --- /dev/null +++ b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/compress.c @@ -0,0 +1,374 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - compstatic + File: compress.c + + Copyright 2003 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include +#include "file.h" +#include "compress.h" + +static int LZCompressRV(u8 *src_buffer, int src_size, u8 *dst_buffer, int dst_size); +static int FindMatched(u8 *src_buffer, int src_size, u8 *dic_buffer, int dic_size, int *index); +static int HowManyMatched(u8 *src_buffer, u8 *dic_buffer, int max_len); +static int CheckOverwrite(int orig_size, u8 *cmprs_buffer, int cmprs_buffer_size, + int *orig_safe, int *cmprs_safe); + + +/*---------------------------------------------------------------------------* + Name: Compress + + Description: Buffer の逆順の圧縮を行なう. + ただし圧縮データと展開データがメモリ空間を共有できるように + 調整する + + buffer : 被圧縮データ + buffer_size : 被圧縮データサイズ + + Return: >=0: 圧縮後のサイズ + < 0: 失敗 + *---------------------------------------------------------------------------*/ +int Compress(u8 *buffer_original, int buffer_original_size) +{ + u8 *buffer; + int buffer_size; + int buffer_start; + u8 *temp_buffer_original; + u8 *temp_buffer; + int temp_buffer_size; + int temp_buffer_start; + int compressed_size; + int aligned_size; + int total_size; + int reduced; + int i; + CompFooter *footer; + + // 前準備 + if (NULL == (temp_buffer_original = (u8 *)malloc(buffer_original_size))) + { + ErrorPrintf("Cannot allocate memory size=%d\n", buffer_original_size); + return COMPRESS_FATAL_ERROR; + } + + if ((u32)buffer_original % 4 != 0) + { + ErrorPrintf("Top of buffer is not aligned by 4.\n"); + return COMPRESS_FATAL_ERROR; + } + + buffer = buffer_original; + buffer_size = buffer_original_size; + temp_buffer = temp_buffer_original; + temp_buffer_size = buffer_original_size; + + // 圧縮を行なう + reduced = LZCompressRV(buffer, buffer_size, temp_buffer, temp_buffer_size); + if (reduced < 0) + { + DebugPrintf("Compressed buffer size exceeds original data size.\n"); + free(temp_buffer_original); + return COMPRESS_LARGER_ORIGINAL; + } + + temp_buffer_size -= reduced; + temp_buffer += reduced; + + DebugPrintf("1: source size = %d compressed = %d\n", buffer_size, temp_buffer_size); + + // 展開不能な上書きが発生するか確認 + if (!CheckOverwrite + (buffer_size, temp_buffer, temp_buffer_size, &buffer_start, &temp_buffer_start)) + { + // 上書きが発生するなら圧縮範囲を変更する + buffer += buffer_start; + buffer_size -= buffer_start; + temp_buffer += temp_buffer_start; + temp_buffer_size -= temp_buffer_start; + + DebugPrintf(" !! Shrink back Compressed region to avoid overwriting.\n" + " !! Expand non-compressed region = +%d\n" + "2: source size = %d compressed = %d\n", + buffer_start, buffer_size, temp_buffer_size); + } + + // PADDING とパラメータ領域を加えても超えないかどうか判定 + compressed_size = buffer_start + temp_buffer_size; // header+body + aligned_size = ROUNDUP4(compressed_size); // +padding + total_size = aligned_size + sizeof(CompFooter); // +footer + + if (buffer_original_size <= total_size) + { + DebugPrintf("Compressed buffer size exceeds or equals original data size.\n"); + free(temp_buffer_original); + return COMPRESS_LARGER_ORIGINAL; + } + + // データをテンポラリバッファから元データへ上書きする + CopyBuffer(temp_buffer, buffer, temp_buffer_size); + free(temp_buffer_original); + + // サイズが 4 の倍数になるように PADDING + // LZ の実装上圧縮領域の最初のバイト値は 0xff にならない(最初は圧縮 + // フラグであり、最初のデータは圧縮なしで格納されるから)ので 0xff で + // 埋める + for (i = compressed_size; i < aligned_size; i++) + { + buffer_original[i] = 0xff; + } + + // サイズ設定 + // compressBottom は sizeof(PAD)+sizeof(footer) なので 1バイトで十分 + footer = (CompFooter *) (buffer_original + aligned_size); + footer->bufferTop = total_size - buffer_start; // 正の値 + footer->compressBottom = total_size - compressed_size; // 正の値 + footer->originalBottom = buffer_original_size - total_size; // 正の値 + + return total_size; +} + + +/*---------------------------------------------------------------------------* + Name: LZCompressRV + + Description: LZ 圧縮を行なう.ただしデータの後方から圧縮開始する + 圧縮結果も後ろ詰めになる + + Returns: 圧縮データの先頭 index + 圧縮データは dst_buffer+index から dst_buffer+dst_size-1 まで + -1: 圧縮失敗(圧縮した結果の方が大きい場合) + *---------------------------------------------------------------------------*/ +static int LZCompressRV(u8 *src_buffer, int src_size, u8 *dst_buffer, int dst_size) +{ + int src_index = src_size; + int dst_index = dst_size; + int compflag; + int compflag_index; + int i; + + while (src_index > 0) + { + if (dst_index < 1) + return -1; // Buffer Overflow + + // 8bit の圧縮フラグの挿入位置を予約 + compflag = 0x00; + compflag_index = --dst_index; + + // フラグ系列が8ビットデータとして格納されるため、8回ループ + for (i = 0; i < 8; i++) + { + compflag <<= 1; + + if (src_index > 0) // src が残っているか判定 + { + u8 *dic_buffer; + int dic_size; + u8 *ref_buffer; + int ref_size; + int index; + int len; + + dic_buffer = src_buffer + src_index; + dic_size = src_size - src_index; + ref_size = MIN(src_index, LZ_MAX_COPY); + ref_buffer = dic_buffer - ref_size; + + len = FindMatched(ref_buffer, ref_size, + dic_buffer, MIN(dic_size, LZ_MAX_DIC_LENGTH), &index); + + if (len >= LZ_MIN_COPY) + { + u16 half; + + // Offset/Len の記録が可能かどうか確認 + if (dst_index < 2) + return -1; // Buffer Overflow + + // src index 進める + src_index -= len; + + // len >= LZ_MIN_COPY なのでその分減算し値域を節約する + index -= (LZ_MIN_COPY - 1); + len -= (LZ_MIN_COPY - 0); + + // 16bit データとしてたたむ + half = (u16)((index & (LZ_MAX_INDEX - 1)) | (len << LZ_BIT_INDEX)); + dst_buffer[--dst_index] = (half >> 8) & 0xff; + dst_buffer[--dst_index] = (half >> 0) & 0xff; + + // flag セット + compflag |= 0x01; + } + else + { + // 値そのままを記録する & src index 進める + if (dst_index < 1) + return -1; // Buffer Overflow + dst_buffer[--dst_index] = src_buffer[--src_index]; + } + } + } + // 圧縮フラグの保存 + dst_buffer[compflag_index] = compflag; + } + return dst_index; +} + + +/*---------------------------------------------------------------------------* + Name: FindMatched + + Description: 一致するパターンの検索を行なう.ただしデータの後方から前方への + 検索 + + src_buffer[0...src_size-1] のパターンを src_buffer の後方から + dic_buffer[0...dic_size-1] のパターンと最大一致する部分を + 検索する. + + Returns: 一致したサイズ + *index 一致した位置 + *---------------------------------------------------------------------------*/ +static int FindMatched(u8 *src_buffer, int src_size, u8 *dic_buffer, int dic_size, int *index) +{ + u8 *src_bottom = src_buffer + src_size - 1; + u8 char_src_bottom = *src_bottom; + int n, len, max_len; + + // 返値初期化 + max_len = 0; + + for (n = 0; n < dic_size; n++) + { + // 高速化のためのキャッシュ + if (char_src_bottom == dic_buffer[n]) + { + len = HowManyMatched(src_bottom, dic_buffer + n, MIN(n + 1, src_size)); + if (max_len < len) + { + max_len = len; + *index = n; + } + } + } + + // 最小サイズ以上なら成功 + return max_len; +} + + +/*---------------------------------------------------------------------------* + Name: HowManyMatched + + Description: 2つのパターンが逆順にどこまで一致しているかを調査する + + src_buffer, dic_buffer 比較パターンのアドレス + (このアドレスから逆方向へ検索する) + max_len 最大調査する長さ + + Returns: 一致した長さ + *---------------------------------------------------------------------------*/ +static int HowManyMatched(u8 *src_buffer, u8 *dic_buffer, int max_len) +{ + int i; + + // パターン一致検索(逆順) + for (i = 0; i < max_len; i++) + { + if (*src_buffer != *dic_buffer) + { + break; + } + src_buffer--; + dic_buffer--; + } + return i; +} + + +/*---------------------------------------------------------------------------* + Name: CheckOverwrite + + Description: LZ 展開で展開先と展開元を同じアドレスに置いた場合に、どこまで + 正常に展開が可能かをチェックする + + Returns: 最後まで展開可能なら TRUE 途中までなら FALSE + *---------------------------------------------------------------------------*/ +static int CheckOverwrite(int orig_size, u8 *cmprs_buffer, int cmprs_buffer_size, + int *orig_safe, int *cmprs_safe) +{ + int src = cmprs_buffer_size; + int dst = orig_size; + int flag; + int i; + +//#define DETAIL + while (dst > 0) + { + flag = cmprs_buffer[--src]; // 圧縮非圧縮フラグ 8 ループ分 + +#ifdef DETAIL + DebugPrintf("%08x %08x FLG=0x%02x\n", src, dst, flag); +#endif + for (i = 0; i < 8; i++) + { + if (dst > 0) + { + if (flag & 0x80) // 圧縮データか? + { + u16 half; + int len; + + // 展開長を計算 + src -= 2; + half = (u16)(cmprs_buffer[src] | (cmprs_buffer[src + 1] << 8)); + len = ((half >> LZ_BIT_INDEX) & (LZ_MAX_LENGTH - 1)) + LZ_MIN_COPY; +#ifdef DETAIL + DebugPrintf("%08x %08x-%08x LEN=%d\n", src, dst - 1, dst - len, len); +#endif + // ソースデータを上書きしてしまうかチェック + dst -= len; + + if (dst < 0) + { + ErrorPrintf("System error in CheckOverwrite???\n"); + exit(-1); // Panic!! + } + + if (dst < src) + { + // 上書きしてしまうなら圧縮は現在のところまでで止める + *orig_safe = dst; + *cmprs_safe = src; + return FALSE; + } + } + else + { + // 非圧縮データならそのままコピーなので + // 破壊を伴なう上書きは起こらない + src--; + dst--; +#ifdef DETAIL + DebugPrintf("%08x %08x CHR=0x%02x\n", src, dst, cmprs_buffer[src]); +#endif + } + flag <<= 1; + } + } + } + *orig_safe = 0; + *cmprs_safe = 0; + return TRUE; +} diff --git a/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/compress.h b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/compress.h new file mode 100644 index 00000000..9b141d6c --- /dev/null +++ b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/compress.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - compstatic + File: compress.h + + Copyright 2003 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$ + *---------------------------------------------------------------------------*/ +#ifndef COMPRESS_H__ +#define COMPRESS_H__ +#include "common.h" + +//--------------------------------------------------------- +typedef struct +{ + u32 bufferTop:24; // 圧縮領域終端 - 先頭 + u32 compressBottom:8; // 圧縮領域終端 - データ終端 + u32 originalBottom; // 展開領域終端 - 圧縮領域終端 +} +CompFooter; + +//--------------------------------------------------------- +int Compress(u8 *buffer, int buffer_size); + +#define COMPRESS_LARGER_ORIGINAL (-1) +#define COMPRESS_FATAL_ERROR (-2) + + +// loader area +#define LOADER_SIZE_ARM9 (16*1024) +#define LOADER_SIZE_ARM7 ( 1*1024) + +// LZ compress parameters +#define LZ_BIT_INDEX 12 // 12bit offset +#define LZ_BIT_LENGTH 4 // 4bit length +#define LZ_MAX_INDEX (1 << LZ_BIT_INDEX) +#define LZ_MAX_LENGTH (1 << LZ_BIT_LENGTH) + +#define LZ_MIN_COPY 3 +#define LZ_MAX_COPY (LZ_MIN_COPY+LZ_MAX_LENGTH-1) +#define LZ_MAX_DIC_LENGTH (LZ_MIN_COPY+LZ_MAX_INDEX-1) + +// macro +#define MIN(a,b) ((a)<(b)?(a):(b)) +#define ROUNDUP4(x) (((x)+3)&~3) + +#endif diff --git a/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/file.c b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/file.c new file mode 100644 index 00000000..871c6e46 --- /dev/null +++ b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/file.c @@ -0,0 +1,314 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - compstatic + File: file.c + + Copyright 2003 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include // calloc() +#include // free(), exit() +#include // stat() +#include // strlen/strdup/strcpy +#include // va_start(),va_end() +#include // unlink() +#include "file.h" + + +/*---------------------------------------------------------------------------* + Name: ReadFile + + Description: ファイルの読み込み バッファの確保 + *---------------------------------------------------------------------------*/ +int ReadFile(const char *filename, u8 **buffer) +{ + FILE *fp; + struct stat filestat; + int filesize; + + fp = NULL; + *buffer = NULL; + + if (filename == NULL) + { + ErrorPrintf("Not specified filename\n"); + goto error; + } + + /* Open file */ + if (stat(filename, &filestat) || !S_ISREG(filestat.st_mode) || + NULL == (fp = fopen(filename, "rb"))) + { + ErrorPrintf("Cannot open file '%s'\n", filename); + goto error; + } + + /* Read file */ + filesize = filestat.st_size; + if (NULL == (*buffer = malloc(filesize))) + { + ErrorPrintf("Cannot allocate memory size=%d\n", filesize); + goto error; + } + + if (filesize != fread(*buffer, sizeof(u8), filesize, fp)) + { + ErrorPrintf("Cannot read file '%s'\n", filename); + goto error; + } + + DebugPrintf("%p %8d bytes ReadFile \'%s\'\n", *buffer, filesize, filename); + + /* Close file */ + fclose(fp); + return filesize; + + error: + if (*buffer) + free(*buffer); + if (fp) + fclose(fp); + return -1; +} + + +/*---------------------------------------------------------------------------* + Name: WriteFile + + Description: ファイルの作成書き込み + *---------------------------------------------------------------------------*/ +int WriteFile(const char *filename, u8 *buffer, int size) +{ + FILE *fp; + + DebugPrintf("%p %8d bytes WriteFile \'%s\'\n", buffer, size, filename); + + /* Open file */ + if (NULL == (fp = fopen(filename, "wb"))) + { + ErrorPrintf("Cannot open file '%s'\n", filename); + return -1; + } + + /* Write file */ + if (size != fwrite(buffer, sizeof(u8), size, fp)) + { + ErrorPrintf("Cannot write file '%s'\n", filename); + (void)fclose(fp); + (void)unlink(filename); + return -1; + } + + /* Close file */ + if (0 > fclose(fp)) + { + ErrorPrintf("Cannot close file '%s'\n", filename); + (void)unlink(filename); + return -1; + } + return size; +} + +/*---------------------------------------------------------------------------* + Name: CopyBuffer + + Description: バッファのコピー + *---------------------------------------------------------------------------*/ +void CopyBuffer(const u8 *src, u8 *dst, int size) +{ + int i; + + if ((unsigned int)src > (unsigned int)dst) + { + for (i = 0; i < size; i++) + { + dst[i] = src[i]; + } + } + else + { + for (i = size - 1; i >= 0; i--) + { + dst[i] = src[i]; + } + } + return; +} + +/*---------------------------------------------------------------------------* + Name: GetDirName + + Description: ファイル名のディレクトリ名を取得する + *---------------------------------------------------------------------------*/ +char *GetDirName(const char *path) +{ + int i; + char *new_path; + + for (i = strlen(path) - 1; i >= 0; i--) + { + if (path[i] == '/' || path[i] == '\\') + { + if (NULL != (new_path = strdup(path))) + { + new_path[i] = '\0'; + } + return new_path; + } + if (path[i] == ':') + { + if (NULL != (new_path = malloc(i + 3))) + { + strncpy(new_path, path, i); + strcpy(new_path + i, ":."); + } + return new_path; + } + } + + return strdup("."); +} + +/*---------------------------------------------------------------------------* + Name: DebugPrintf + + Description: Debug 出力用 Printf + *---------------------------------------------------------------------------*/ +BOOL bDebugMode = FALSE; + +void DebugPrintf(const char *fmt, ...) +{ + va_list va; + + if (bDebugMode) + { + va_start(va, fmt); + vfprintf(stderr, fmt, va); + va_end(va); + } +} + +/*---------------------------------------------------------------------------* + Name: ConsolePrintf + + Description: 通常コンソール出力用 Printf + *---------------------------------------------------------------------------*/ +void ConsolePrintf(const char *fmt, ...) +{ + va_list va; + + va_start(va, fmt); + vfprintf(stdout, fmt, va); + va_end(va); +} + +/*---------------------------------------------------------------------------* + Name: ErrorPrintf + + Description: Error 出力用 Printf + *---------------------------------------------------------------------------*/ +void ErrorPrintf(const char *fmt, ...) +{ + va_list va; + + fprintf(stderr, "Error: "); + va_start(va, fmt); + vfprintf(stderr, fmt, va); + va_end(va); +} + + +/*---------------------------------------------------------------------------* + Name: StrDup + + Description: エラーハンドリング&古い値の free 付き strdup 関数 + *---------------------------------------------------------------------------*/ +char *StrDup(char *old, char *new) +{ + if (old) + { + free(old); + } + if (new && NULL == (new = strdup(new))) + { + ErrorPrintf("Cannot allocate memory\n"); + exit(1); + } + return new; +} + + +/*---------------------------------------------------------------------------* + Name: StrCat + + Description: 文字列の連結 + *---------------------------------------------------------------------------*/ +char *StrCat(int num, ...) +{ + va_list va; + int i; + int size; + char *result; + + va_start(va, num); + size = 0; + for (i = 0; i < num; i++) + { + size += strlen(va_arg(va, char *)); + } + va_end(va); + + if (NULL == (result = malloc(size + 1))) + { + ErrorPrintf("Cannot allocate memory\n"); + exit(1); + } + + va_start(va, num); + result[0] = '\0'; + for (i = 0; i < num; i++) + { + (void)strcat(result, va_arg(va, char *)); + } + va_end(va); + + return result; +} + +//--------------------------------------------------------------------------- +// パス文字列からファイル名部分のポインタを取得し、拡張子を削る +// @param path パス +// @return ファイル名のポインタ +//--------------------------------------------------------------------------- +char *StrCutFname(char *path) +{ + char *search_tmp; + + if (path == NULL) + { + return NULL; + } + + if ((search_tmp = strrchr(path, '/')) != NULL) + { + path = (search_tmp + 1); + } + if ((search_tmp = strrchr(path, '\\')) != NULL) + { + path = (search_tmp + 1); + } + if ((search_tmp = strrchr(path, '.')) != NULL) + { + *search_tmp = '\0'; + } + return path; +} diff --git a/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/file.h b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/file.h new file mode 100644 index 00000000..b266b0ff --- /dev/null +++ b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/file.h @@ -0,0 +1,35 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - compstatic + File: file.h + + Copyright 2003 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$ + *---------------------------------------------------------------------------*/ +#ifndef FILE_H__ +#define FILE_H__ + +#include "common.h" + +int ReadFile(const char *filename, u8 **buffer); +int WriteFile(const char *filename, u8 *buffer, int size); +void CopyBuffer(const u8 *src, u8 *dst, int size); +char *GetDirName(const char *filename); +void DebugPrintf(const char *fmt, ...); +void ErrorPrintf(const char *fmt, ...); +void ConsolePrintf(const char *fmt, ...); +char *StrDup(char *old, char *new); +char *StrCat(int num, ...); +char *StrCutFname(char *path); + +extern BOOL bDebugMode; + +#endif //FILE_H__ diff --git a/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/main.c b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/main.c new file mode 100644 index 00000000..f7ec6980 --- /dev/null +++ b/build/tests/compressSharedFontLoad/compSharedFont/compBLZ_modified/main.c @@ -0,0 +1,171 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - compBLZ + File: main.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include +#include +#include // getopt() +#include "file.h" +#include "compress.h" + +extern const unsigned long SDK_DATE_OF_LATEST_FILE; + +static void usage(void); + +/*---------------------------------------------------------------------------* + Name: main + + Description: + *---------------------------------------------------------------------------*/ +int main(int argc, char *argv[]) +{ + int n; + int result; + int iptfilesize; + + char* optfilename; + char* suffix; + u8* filebuf; + + BOOL optfname_flag = FALSE; // if optfilename input, this flag is true. + + optfilename = suffix = NULL; + + while ((n = getopt(argc, argv, "o:e:dhv")) != -1) + { + switch (n) + { + case 'o': // output file name + optfilename = optarg; + optfname_flag = TRUE; + break; + + case 'e': + suffix = optarg; + break; + + case 'd': // Show debug message + bDebugMode = TRUE; + break; + + case 'h': + case 'v': + default: + usage(); // Never returns + break; + } + + DebugPrintf("option -%c: %s\n", n, optarg ? optarg : "No ARG"); + } + + argc -= optind; + argv += optind; + + if (bDebugMode) + { + int i; + + DebugPrintf("argc=%d optind=%d\n", argc, optind); + for (i = 0; i < argc; i++) + { + DebugPrintf("argv[%d] = [%s]\n", i, argv[i]); + } + } + + if (argc == 1) + { + if (optfilename == NULL) + { + optfilename = argv[0]; + } + iptfilesize = ReadFile(argv[0], &filebuf); + } + else + { + usage(); // Never returns + } + + if (iptfilesize < 0) + { + ConsolePrintf("exit...\n"); + return 1; + } + + if ((result = Compress(filebuf, iptfilesize)) < 0) + { + switch (result) + { + case COMPRESS_LARGER_ORIGINAL: + ConsolePrintf("Inputdata ..... Not compressed (enlarged or same size as before)\n"); + break; + case COMPRESS_FATAL_ERROR: + ConsolePrintf("Fatal error occured\n"); + break; + } + ConsolePrintf("exit...\n"); + return 1; + } + + // cut file path and suffix of input file + if (!optfname_flag) + { + optfilename = StrCutFname(optfilename); + } + + // create output filename + if (suffix == NULL) + { + optfilename = StrCat(2, optfilename, "_BLZ.bin"); + } + else + { + optfilename = StrCat(2, optfilename, suffix); + } + + // output file + if (WriteFile(optfilename, filebuf, result) < 0) + { + ConsolePrintf("exit...\n\n"); + return 1; + } + + ConsolePrintf("Inputdata ..... Compressed ... %9d -> %9d\n", iptfilesize, result); + + return 0; +} + +/*---------------------------------------------------------------------------* + Name: usage + + Description: + *---------------------------------------------------------------------------*/ +static void usage(void) +{ + fprintf(stderr, + "TWL-SDK Development Tool - compBLZ - Compress data\n" + "Build %lu\n" + "\n" + "Usage: compBLZ [-d] [-o outputFile] [-e suffix] inputFile\n" + "\n" + " Compress data (backward LZ)\n" + "\n" + " -o outputFile FILENAME for output file (default:input filename)\n" + " -e suffix SUFFIX for output file (default:\"_BLZ\")\n" + " -d Show debug messages (for test purpose)\n" + " -h Show this message\n" "\n", SDK_DATE_OF_LATEST_FILE); + + exit(1); +} diff --git a/build/tests/compressSharedFontLoad/compSharedFont/genFontTable.plx b/build/tests/compressSharedFontLoad/compSharedFont/genFontTable.plx new file mode 100644 index 00000000..1a9ceab0 --- /dev/null +++ b/build/tests/compressSharedFontLoad/compSharedFont/genFontTable.plx @@ -0,0 +1,260 @@ +#!/usr/bin/perl + +# +# To Do +# ・Font info table の padding を圧縮後ファイルサイズを格納するエントリに変更 +# ・ファイルサイズを取得して詰め込む処理を追加 +# ・SHA-1ハッシュをつける前に圧縮する +# + +###################################################################### +# genFontTable.pl +# +# generate Secure Shared Font Data Table +# +# [[ HEADER FORMAT ]] +# security code (128 bytes) : RSA signature of Header +# +# Header ( 32 bytes) +# TimeStamp ( 4 bytes) : date %y%m%d%H +# number ( 2 bytes) : number of font files +# padding ( 6 bytes) : +# padding ( 20 bytes) : SHA1 digest of Font info table +# +# Font info table ( 64 bytes * number) +# fileName ( 32 bytes) : font file name +# comp_length ( 4 bytes) : length of the compression file +# file offset ( 4 bytes) : file offset of Font data +# length ( 4 bytes) : length of file (bytes) +# digest ( 20 bytes) : SHA1 digest of Font data +# +# note: each section image is aligned to 32 bytes. +# +###################################################################### + +use POSIX 'strftime'; +use File::Basename; + +if ($#ARGV < 2) { + printf STDOUT ("Usage: %s [genFontTable] timestamp [Target font files...]\n", $0); + exit(-1); +} + +my $outFile = "TWLFontTable.dat"; +my $infoFile = "info.bin"; +my $headerFile = "header.bin"; +my $digestFile = "sha1.bin"; +my $signFile = "sign.bin"; +my $tempFile = "temp.bin"; +my $compprog = "compBLZ.exe"; # 圧縮プログラム +my $compoption = "-e \"\""; + +# 後始末 +sub deleteTemp { + system ("rm -f $infoFile"); + system ("rm -f $headerFile"); + system ("rm -f $digestFile"); + system ("rm -f $signFile"); + system ("rm -f $tempFile"); +} + +# 環境変数からSDKのルートをサーチして(ntrcompの場所特定に必要) +#foreach ( sort keys ( %ENV ) ){ +# if ($_ =~ m/TWLSDK_ROOT/s) { +# $SDKROOT = $ENV{$_}; +# } +#} +#printf "TWLSDK_ROOT is ${SDKROOT}\n"; + +my $signSize = 0x80; +my $headerSize = 0x20; +my @files; + +# 要素数算出 +my $num = 0; +foreach ( @ARGV ) { + next if( $_ eq $ARGV[0] ); + $files[ $num ] = $_; + $num++; +} + +# 情報テーブルの出力 +{ + my $elementSize = 0x40; + my $fileNameMax = 0x20; + my $padLen = 0x04; + # offset length = 0x04; + # file length = 0x04; + my $sha1Len = 0x14; + + open INFO, ">$infoFile" or die; + binmode INFO; + + # オフセット算出 + my $offset = $signSize + $headerSize + $num * $elementSize; + if( ( $offset % 32 ) > 0 ) { $offset += 32 - ( $offset % 32 ); } + + printf "---------------------------------------------------------------\n"; + printf "filename\toffset \torig_size\tcompressed_size\n"; + foreach ( @files ) { + # NULL指定時は、NULL出力 + if( "NULL" eq basename( $_ ) ) { + syswrite( INFO, pack( "x$elementSize") ); + next; + } + + # ファイルネームの出力 + if( !( -e $_ ) ) { + close( INFO ); + deleteTemp(); + die "file not exist. : $_\n"; + } + my $name = basename( $_ ); + if( length $name >= $fileNameMax ) { + close( INFO ); + deleteTemp(); + die "file name length must be smaller than $fileNameMax. : $_\n"; + } + my $data = pack( "a$fileNameMax", $name ); + syswrite( INFO, $data, $fileNameMax ); + + # 圧縮 + # SDKのcompBLZ.exeは引数バグがあるためローカルに修正版を入れておく + my $compfile = "$_.comp"; + #system ("${SDKROOT}/tools/bin/${compprog} $compoption $_ -o $compfile"); + system ("./compBLZ_modified/bin/${compprog} $compoption $_ -o $compfile"); + + # パディングの出力 + #syswrite( INFO, pack( "x$padLen") ); + + # 圧縮ファイル長を出力(もともとはpadding) + $data = pack( "L", -s $compfile ); + syswrite( INFO, $data, 4 ); + + # ファイルオフセットの出力 + $data = pack( "L", $offset ); + syswrite( INFO, $data, 4 ); + + # ファイル長の出力 + $data = pack( "L", -s $_ ); + syswrite( INFO, $data, 4 ); + + # ファイルのSHA1ハッシュの出力 + { + my $digest; + #system ("openssl dgst -sha1 -binary -out $digestFile $_"); + system ("openssl dgst -sha1 -binary -out $digestFile $compfile"); # 圧縮後のファイルにハッシュをつける + open DIGEST, $digestFile or die; + binmode DIGEST; + sysread( DIGEST, $digest, $sha1Len ); + close DIGEST; + syswrite( INFO, $digest, $sha1Len ); + } + + printf "%s\t0x%08x\t0x%08x\t0x%08x\n", $_, $offset, -s $_, -s $compfile; + + # オフセット加算 + #$offset += -s $_; + $offset += -s $compfile; + if( ( $offset % 32 ) > 0 ) { $offset += 32 - ( $offset % 32 ); } + } + close INFO; + printf "---------------------------------------------------------------\n"; +} + +# ヘッダの出力 +{ + # timestampLen = 0x08; + # elementNumLen = 0x02; + my $padLen = 0x06; + my $sha1Len = 0x14; + + open HEADER, ">$headerFile" or die; + binmode HEADER; + + # タイムスタンプの出力 +# my $timestamp = strftime "%y%m%d%H", localtime; + my $timestamp = $ARGV[ 0 ]; + printf "timestamp = %s\n", $timestamp; + syswrite( HEADER, pack( "N", unpack( "L", pack( "H8", $timestamp ) ) ) ); + + # 要素数の出力 + syswrite( HEADER, pack( "S", $num ) ); + + # パディングの出力 + syswrite( HEADER, pack( "x$padLen") ); + + # 情報テーブルのSHA1ハッシュの出力 + { + my $digest; + system ("openssl dgst -sha1 -binary -out $digestFile $infoFile"); + open DIGEST, $digestFile or die; + binmode DIGEST; + sysread( DIGEST, $digest, $sha1Len ); + close DIGEST; + syswrite( HEADER, $digest, $sha1Len ); + } + close HEADER; +} + +# 環境変数サーチ +foreach ( sort keys ( %ENV ) ){ + if ($_ =~ m/TWL_IPL_RED_PRIVATE_ROOT/s) { + $KEYROOT = $ENV{$_}; + } +} +if (!$KEYROOT) { + deleteTemp(); + die "No TWL_IPL_RED_PRIVATE_ROOT is found.\n"; +} + +# ヘッダへの署名付加 +{ + system ( "openssl dgst -sha1 -binary -out $digestFile $headerFile" ); + system ( "openssl rsautl -sign -in $digestFile -inkey $KEYROOT/keys/rsa/private_sharedFont.der -keyform DER -out $signFile" ); + system ( "cat $signFile $headerFile >$tempFile" ); + system ( "cat $tempFile $infoFile >$outFile" ); + deleteTemp(); +} + + +# フォントの出力 +{ + open FONTTABLE, ">>$outFile" or die; + binmode FONTTABLE; + + { + # パディング出力 + my $fileLen = -s $outFile; + my $padNum = ( $fileLen % 32 ) ? ( 32 - ( $fileLen % 32 ) ) : 0; + my $padding = pack( "x$padNum" ); + syswrite( FONTTABLE, $padding, $padNum ); + } + + foreach ( @files ) { + # NULL指定時はスキップ + if( "NULL" eq basename( $_ ) ) { + next; + } + + # フォント出力 + #my $fileLen = -s $_; + #open TEST, $_ or die; + my $compfile = "$_.comp"; # 圧縮ファイルを出力 + $fileLen = -s $compfile; + open TEST, $compfile or die; + binmode TEST; + sysread ( TEST, $buffer, $fileLen ); + close TEST; + syswrite( FONTTABLE, $buffer, $fileLen ); + + # パディング出力 + my $padNum = ( $fileLen % 32 ) ? ( 32 - ( $fileLen % 32 ) ) : 0; + my $padding = pack( "x$padNum" ); + syswrite( FONTTABLE, $padding, $padNum ); + + # 圧縮ファイルを削除 + system ("rm -rf $compfile"); + } + close FONTTABLE; +} diff --git a/build/tests/compressSharedFontLoad/testLoadSpeed/Makefile b/build/tests/compressSharedFontLoad/testLoadSpeed/Makefile new file mode 100644 index 00000000..4f394d4f --- /dev/null +++ b/build/tests/compressSharedFontLoad/testLoadSpeed/Makefile @@ -0,0 +1,54 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - FS - overlay +# 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$ +#---------------------------------------------------------------------------- +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + + +ifeq ($(TEST_TWLSDK_REBUILD),TRUE) +export TWLSDK_SYSMENU_PRIVATE = TRUE +SUBDIRS = copy_to_sdk \ + $(ROOT) +endif # ifeq ($(TEST_TWLSDK_REBUILD),TRUE) + +#---------------------------------------------------------------------------- + +TARGET_BIN = main.srl + +SRCS = main.c loadSharedFont.c + +LLIBRARIES += libsharedfont$(TWL_LIBSUFFIX).a + +ROM_SPEC = ROM-TS_nand.rsf + +include $(TWLSDK_ROOT)/build/buildtools/commondefs +include $(TWLSDK_ROOT)/build/buildtools/commondefs.gx.demolib + +MAKEROM_ARM7_BASE = $(TWL_COMPONENTSDIR)/armadillo/$(TWL_BUILDTYPE_ARM7)/armadillo +MAKEROM_ARM7 = $(MAKEROM_ARM7_BASE).$(TWL_ELF_EXT) +MAKEROM = $(TWL_TOOLSDIR)/bin/makerom.TWL.secure.exe + +#---------------------------------------------------------------------------- + +do-build: oslib $(TARGETS) + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +oslib: + touch $(ROOT)/build/libraries/os/ARM9.TWL/src/os_sharedFont.c + +#===== End of Makefile ===== diff --git a/build/tests/compressSharedFontLoad/testLoadSpeed/ROM-TS_nand.rsf b/build/tests/compressSharedFontLoad/testLoadSpeed/ROM-TS_nand.rsf new file mode 100644 index 00000000..8cb68fb1 --- /dev/null +++ b/build/tests/compressSharedFontLoad/testLoadSpeed/ROM-TS_nand.rsf @@ -0,0 +1,277 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-TS.rsf +# +# Copyright 2007 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:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- +# +# 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 "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #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 ./etc/myGameBanner.bnr + BannerFile $(TWLSDK_ROOT)/include/twl/specfiles/default.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 + + # + # 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 [0 - 255] + # + #AgreeEULAVersion 0 + + ### + #### END +} + +AppendProperty +{ + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType System + + # + # Boot allowed Media: [GameCard] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + #GameCode ABCJ + + # + # Secure title : [TRUE/FALSE] + # don't have to edit + Secure TRUE + + # + # Public save data size: [0K/16K/32K/64K/128K/256K/512K/1M/2M/4M] + # + #PublicSaveDataSize 0K + + # + # Private save data size: [0K/16K/32K/64K/128K/256K/512K/1M/2M/4M] + # + #PrivateSaveDataSize 0K + + # + # Enable SubBannerFile + #SubBannerFile TRUE + + # + # Use Shared2 file index: [0-65535] + #Shared2FileIndex 0 + + # + # Use Shared2 file size: [0K/16K/32K/64K/128K/256K/512K/1M/2M/4M] + #Shared2FileSize 0K + + # + # Game card power on: [TRUE/FALSE] + # + #GameCardOn FALSE +} + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot $(MAKEROM_ROMROOT) + Root / + File $(MAKEROM_ROMFILES) +} + +Rating +{ + # + # Permited age to play for each rating organization [0 - 31, ALWAYS, FREE] + # + # 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 / ALWAYS / FREE ] + + CERO FREE +# ESRB FREE +# USK FREE +# PEGI_GEN FREE +# PEGI_PRT FREE +# PEGI_BBFC FREE +# OFLC FREE +# GRB FREE +} diff --git a/build/tests/compressSharedFontLoad/testLoadSpeed/copy_to_sdk/Makefile b/build/tests/compressSharedFontLoad/testLoadSpeed/copy_to_sdk/Makefile new file mode 100644 index 00000000..a859f4e3 --- /dev/null +++ b/build/tests/compressSharedFontLoad/testLoadSpeed/copy_to_sdk/Makefile @@ -0,0 +1,39 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL +# 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: +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +ORG_H = sharedFont.h +ORG_C = os_sharedFont.c + +CP_H_DIR = $(TWLSDK_ROOT)/include/twl/os/common +CP_C_DIR = $(TWLSDK_ROOT)/build/libraries/os/ARM9.TWL/src/ + +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +do-build: + cp $(ORG_H) $(CP_H_DIR) + cp $(ORG_C) $(CP_C_DIR) + +#===== End of Makefile ===== diff --git a/build/tests/compressSharedFontLoad/testLoadSpeed/copy_to_sdk/os_sharedFont.c b/build/tests/compressSharedFontLoad/testLoadSpeed/copy_to_sdk/os_sharedFont.c new file mode 100644 index 00000000..d6f94dd1 --- /dev/null +++ b/build/tests/compressSharedFontLoad/testLoadSpeed/copy_to_sdk/os_sharedFont.c @@ -0,0 +1,352 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - OS + File: os_sharedFont.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:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include + +#ifdef USE_FONT_WRAM_LOAD +#include "fs_wram.h" +#endif // USE_FONT_WRAM_LOAD + +// compile switch-------------------------------------------------------------- +//#define DISABLE_HASH_CHECK + +// extern data----------------------------------------------------------------- +// define data----------------------------------------------------------------- +#ifdef USE_FONT_WRAM_LOAD +#define THREAD_PRIO_FS_FRAM 3 +#define WRAM_TOP_SLOT_FOR_FS 4 +#define WRAM_SIZE_FOR_FS MI_WRAM_SIZE_96KB +#endif // USE_FONT_WRAM_LOAD + +#define OS_SHARED_FONT_TABLE_PATH "nand:/" +#define OS_SHARED_FONT_FILE_NAME_LENGTH 0x20 +#define OS_SHARED_FONT_SIGN_SIZE 0x80 + +// 共有フォントテーブルヘッダ +typedef struct OSSharedFontHeader { + u32 timestamp; + u16 fontNum; + u8 pad[ 6 ]; + u8 digest[ SVC_SHA1_DIGEST_SIZE ]; +}OSSharedFontHeader; + +// 共有フォントテーブル +typedef struct OSSharedFontEntry { + u8 fileName[ OS_SHARED_FONT_FILE_NAME_LENGTH ]; +// u8 pad[ 4 ]; + u32 compLength; // 圧縮後サイズ + u32 offset; + u32 origLength; // 元のサイズ + u8 digest[ SVC_SHA1_DIGEST_SIZE ]; +}OSSharedFontEntry; + +// 共有フォントライブラリワーク +typedef struct OSSharedFontWork { + OSSharedFontHeader header; + OSSharedFontEntry *pInfoTable; +}OSSharedFontWork; + +#ifdef USE_FONT_WRAM_LOAD +// SHA1コールバック引数 +typedef struct CalcSHA1CallbackArg +{ + SVCSHA1Context ctx; + u32 hash_length; +} CalcSHA1CallbackArg; +#endif // USE_FONT_WRAM_LOAD + +// function's prototype------------------------------------------------------- +#ifdef USE_FONT_WRAM_LOAD +static void CalcSHA1Callback(const void* addr, const void* orig_addr, u32 len, MIWramPos wram, s32 slot, void* arg); +#endif // USE_FONT_WRAM_LOAD + +// global variable------------------------------------------------------------- +// static variable------------------------------------------------------------- +static OSSharedFontWork s_work; +static BOOL s_isInitialized = FALSE; + +// const data------------------------------------------------------------------ +// 共有フォント署名確認用公開鍵 +static const u8 s_sharedFontPubKey[] = { + 0x9f, 0x80, 0xbc, 0x5f, 0xb6, 0xb6, 0x1d, 0x2a, 0x46, 0x02, 0x52, 0x64, 0xb2, 0xa3, 0x86, 0xce, + 0xe6, 0x54, 0xd3, 0xa9, 0x70, 0x5b, 0xe3, 0xc2, 0x10, 0xa9, 0xb5, 0x2f, 0x38, 0xc5, 0x51, 0xfb, + 0xb5, 0xd1, 0x80, 0xfd, 0xff, 0x20, 0x65, 0xc1, 0x28, 0x4d, 0x56, 0xbe, 0xfb, 0xbd, 0x3f, 0xe4, + 0xba, 0xf7, 0x9c, 0x3a, 0x33, 0x74, 0x74, 0x9d, 0xdb, 0xdd, 0x9e, 0x86, 0x05, 0x2c, 0xad, 0xfc, + 0x93, 0xfa, 0xfb, 0x08, 0xea, 0x71, 0x18, 0x36, 0xc5, 0xdc, 0x4c, 0x06, 0x34, 0x57, 0xa7, 0x8f, + 0x4e, 0x82, 0xf7, 0xb3, 0xe2, 0x9c, 0xe4, 0x72, 0xe3, 0xdc, 0x60, 0xaf, 0xcc, 0x18, 0xe2, 0xd4, + 0xef, 0xd2, 0x76, 0x47, 0x31, 0xe6, 0x14, 0x0e, 0x1d, 0x26, 0xb5, 0x85, 0x97, 0xbc, 0xc6, 0xb6, + 0xd8, 0xe7, 0x69, 0x2d, 0x2c, 0x26, 0xfb, 0x5f, 0x70, 0x9e, 0x19, 0x9c, 0x6b, 0x02, 0x6d, 0x97 +}; + +// 共有フォント初期化 +BOOL OS_InitSharedFont( void ) +{ + FSFile file[1]; + u8 signature[ OS_SHARED_FONT_SIGN_SIZE ]; + + if( s_isInitialized ) { + return TRUE; + } + + MI_CpuClear32( &s_work, sizeof(s_work) ); + + if( !FS_OpenFileEx( file, OS_SHARED_FONT_TABLE_PATH, FS_FILEMODE_R ) ) { + return FALSE; + } + + // 署名リード + if( FS_ReadFile( file, signature, OS_SHARED_FONT_SIGN_SIZE ) != OS_SHARED_FONT_SIGN_SIZE ){ + goto ERROR; + } + + // ヘッダリード + if( FS_ReadFile( file, &s_work.header, sizeof(OSSharedFontHeader) ) != sizeof(OSSharedFontHeader) ){ + goto ERROR; + } + + FS_CloseFile( file ); + +#ifndef DISABLE_HASH_CHECK + // ヘッダ署名チェック + { + u8 calc_digest[ SVC_SHA1_DIGEST_SIZE ]; + u8 sign_digest[ SVC_SHA1_DIGEST_SIZE ]; + static u32 heap[ 4096 / sizeof(u32) ]; + + SVCSignHeapContext acmemoryPool; + SVC_CalcSHA1( calc_digest, &s_work.header, sizeof(OSSharedFontHeader) ); + SVC_InitSignHeap( &acmemoryPool, heap, 4096 ); + if( !SVC_DecryptSign( &acmemoryPool, sign_digest, signature, s_sharedFontPubKey ) ) { + return FALSE; + } + if( !SVC_CompareSHA1( calc_digest, sign_digest ) ) { + return FALSE; + } + } +#endif + +#ifdef USE_FONT_WRAM_LOAD + // WRAM利用Read関数の準備、WRAMCの後半だけ解放しておく + FS_InitWramTransfer( THREAD_PRIO_FS_FRAM ); + MI_FreeWramSlot_C( WRAM_TOP_SLOT_FOR_FS, WRAM_SIZE_FOR_FS, MI_WRAM_ARM7 ); + MI_FreeWramSlot_C( WRAM_TOP_SLOT_FOR_FS, WRAM_SIZE_FOR_FS, MI_WRAM_ARM9 ); + MI_FreeWramSlot_C( WRAM_TOP_SLOT_FOR_FS, WRAM_SIZE_FOR_FS, MI_WRAM_DSP ); + MI_CancelWramSlot_C( WRAM_TOP_SLOT_FOR_FS, WRAM_SIZE_FOR_FS, MI_WRAM_ARM7 ); + MI_CancelWramSlot_C( WRAM_TOP_SLOT_FOR_FS, WRAM_SIZE_FOR_FS, MI_WRAM_ARM9 ); + MI_CancelWramSlot_C( WRAM_TOP_SLOT_FOR_FS, WRAM_SIZE_FOR_FS, MI_WRAM_DSP ); +#endif // USE_FONT_WRAM_LOAD + + s_isInitialized = TRUE; + return TRUE; + +ERROR: + FS_CloseFile( file ); + return FALSE; +} + + +// 共有フォント テーブルサイズ取得 +int OS_GetSharedFontTableSize( void ) +{ + if( s_isInitialized ) { + return (int)( s_work.header.fontNum * sizeof(OSSharedFontEntry) ); + }else { + return -1; + } +} + + +// 共有フォント テーブルロード +BOOL OS_LoadSharedFontTable( void *pBuffer ) +{ + FSFile file[1]; + u32 tableLen = sizeof(OSSharedFontEntry) * s_work.header.fontNum; + + if( ( !s_isInitialized ) || + ( s_work.header.fontNum == 0 ) || + ( pBuffer == NULL ) || + ( s_work.pInfoTable ) ) { + return FALSE; + } + + // フォントテーブルリード + if( !FS_OpenFileEx( file, OS_SHARED_FONT_TABLE_PATH, FS_FILEMODE_R ) ) { + return FALSE; + } + if( !FS_SeekFile( file, OS_SHARED_FONT_SIGN_SIZE + sizeof(OSSharedFontHeader), FS_SEEK_SET ) ){ + goto ERROR; + } + if( FS_ReadFile( file, pBuffer, (int)tableLen ) != tableLen ){ + goto ERROR; + } + FS_CloseFile( file ); + +#ifndef DISABLE_HASH_CHECK + // フォントテーブル ハッシュチェック + { + u8 calc_digest[ SVC_SHA1_DIGEST_SIZE ]; + SVC_CalcSHA1( calc_digest, pBuffer, tableLen ); + if( !SVC_CompareSHA1( calc_digest, s_work.header.digest ) ) { + return FALSE; + } + } +#endif + + s_work.pInfoTable = pBuffer; + return TRUE; + +ERROR: + FS_CloseFile( file ); + return FALSE; +} + + +// 共有フォント フォントサイズ取得 +int OS_GetSharedFontSize( OSSharedFontIndex index ) +{ + if( ( s_isInitialized == NULL ) || + ( s_work.pInfoTable == NULL ) || + ( index >= s_work.header.fontNum ) || + ( index < 0 ) || + ( index >= OS_SHARED_FONT_MAX ) ) { + return -1; + } + + return (int)s_work.pInfoTable[ index ].origLength; +} + + +// 共有フォント 圧縮後フォントサイズ取得 +int OS_GetSharedFontCompressedSize( OSSharedFontIndex index ) +{ + if( ( s_isInitialized == NULL ) || + ( s_work.pInfoTable == NULL ) || + ( index >= s_work.header.fontNum ) || + ( index < 0 ) || + ( index >= OS_SHARED_FONT_MAX ) ) { + return -1; + } + + return (int)s_work.pInfoTable[ index ].compLength; +} + + +// 共有フォント フォントネーム取得 +const u8 *OS_GetSharedFontName( OSSharedFontIndex index ) +{ + if( ( s_isInitialized == NULL ) || + ( s_work.pInfoTable == NULL ) || + ( index >= s_work.header.fontNum ) || + ( index < 0 ) || + ( index >= OS_SHARED_FONT_MAX ) ) { + return NULL; + } + + return s_work.pInfoTable[ index ].fileName; +} + + +// 共有フォント タイムスタンプ取得 +u32 OS_GetSharedFontTimestamp( void ) +{ + if( ( s_isInitialized == NULL ) ) { + return 0; + } + return s_work.header.timestamp; +} + + +// 共有フォント フォントロード +BOOL OS_LoadSharedFont( OSSharedFontIndex index, void *pBuffer ) +{ + FSFile file[1]; + OSSharedFontEntry *pInfo = &s_work.pInfoTable[ index ]; + u8 calc_digest[ SVC_SHA1_DIGEST_SIZE ]; + + if( ( s_isInitialized == NULL ) || + ( s_work.pInfoTable == NULL ) || + ( index >= s_work.header.fontNum ) || + ( index < 0 ) || + ( index >= OS_SHARED_FONT_MAX ) ) { + return FALSE; + } + + // フォント リード + if( !FS_OpenFileEx( file, OS_SHARED_FONT_TABLE_PATH, FS_FILEMODE_R ) ) { + return FALSE; + } + if( !FS_SeekFile( file, (int)pInfo->offset, FS_SEEK_SET ) ){ + goto ERROR; + } +#ifdef USE_FONT_WRAM_LOAD + { + CalcSHA1CallbackArg arg; + SVC_SHA1Init( &arg.ctx ); + arg.hash_length = pInfo->compLength; + if( !FS_ReadFileViaWram( file, pBuffer, (s32)MATH_ROUNDUP( pInfo->compLength, 0x20 ), MI_WRAM_C, + WRAM_TOP_SLOT_FOR_FS, WRAM_SIZE_FOR_FS, +#ifndef DISABLE_HASH_CHECK + CalcSHA1Callback, +#else + NULL, +#endif // DISABLE_HASH_CHECK + &arg ) ) { + goto ERROR; + } + SVC_SHA1GetHash( &arg.ctx, &calc_digest ); + } +#else + if( FS_ReadFile( file, pBuffer, (int)pInfo->compLength ) != pInfo->compLength ){ + goto ERROR; + } +#ifndef DISABLE_HASH_CHECK + SVC_CalcSHA1( calc_digest, pBuffer, pInfo->compLength ); +#endif // DISABLE_HASH_CHECK +#endif // USE_FONT_WRAM_LOAD + + FS_CloseFile( file ); + +#ifndef DISABLE_HASH_CHECK + // フォント ハッシュチェック + if( !SVC_CompareSHA1( calc_digest, pInfo->digest ) ) { + return FALSE; + } +#endif // DISABLE_HASH_CHECK + + return TRUE; + +ERROR: + FS_CloseFile( file ); + return FALSE; +} + + +#ifdef USE_FONT_WRAM_LOAD +// FS-WRAM転送時のSHA1計算コールバック +static void CalcSHA1Callback(const void* addr, const void* orig_addr, u32 len, MIWramPos wram, s32 slot, void* arg) +{ +#pragma unused(orig_addr) +#pragma unused(wram) +#pragma unused(slot) + CalcSHA1CallbackArg *cba = (CalcSHA1CallbackArg *)arg; + u32 calc_len = ( cba->hash_length < len ? cba->hash_length : len ); + if( calc_len == 0 ) return; + cba->hash_length -= calc_len; + SVC_SHA1Update( &cba->ctx, addr, calc_len ); +} +#endif // USE_FONT_WRAM_LOAD diff --git a/build/tests/compressSharedFontLoad/testLoadSpeed/copy_to_sdk/sharedFont.h b/build/tests/compressSharedFontLoad/testLoadSpeed/copy_to_sdk/sharedFont.h new file mode 100644 index 00000000..b29a5ea0 --- /dev/null +++ b/build/tests/compressSharedFontLoad/testLoadSpeed/copy_to_sdk/sharedFont.h @@ -0,0 +1,69 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - OS - include + File: sharedFont.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:: $ + $Rev$ + $Author$ + + *---------------------------------------------------------------------------*/ + +#ifndef TWL_OS_SHARED_FONT_H_ +#define TWL_OS_SHARED_FONT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SDK_ARM9 + +// 共有フォントインデックス +typedef enum OSSharedFontIndex { + OS_SHARED_FONT_WW_S = 0, + OS_SHARED_FONT_WW_M = 1, + OS_SHARED_FONT_WW_L = 2, + OS_SHARED_FONT_MAX = 3 +}OSSharedFontIndex; + + +// 共有フォント初期化 +BOOL OS_InitSharedFont( void ); + +// 共有フォント テーブルサイズ取得 +int OS_GetSharedFontTableSize( void ); + +// 共有フォント テーブルロード +BOOL OS_LoadSharedFontTable( void *pBuffer ); + +// 共有フォント フォントサイズ取得 +int OS_GetSharedFontSize( OSSharedFontIndex index ); + +// 共有フォント 圧縮後サイズ取得 +int OS_GetSharedFontCompressedSize( OSSharedFontIndex index ); + +// 共有フォント フォントネーム取得 +const u8 *OS_GetSharedFontName( OSSharedFontIndex index ); + +// 共有フォント タイムスタンプ取得 +u32 OS_GetSharedFontTimestamp( void ); + +// 共有フォント フォントロード +BOOL OS_LoadSharedFont( OSSharedFontIndex index, void *pBuffer ); + +#endif // SDK_ARM9 + +#ifdef __cplusplus +} +#endif + +#endif // TWL_OS_SHARED_FONT_H_ diff --git a/build/tests/compressSharedFontLoad/testLoadSpeed/src/loadSharedFont.c b/build/tests/compressSharedFontLoad/testLoadSpeed/src/loadSharedFont.c new file mode 100644 index 00000000..20e46f24 --- /dev/null +++ b/build/tests/compressSharedFontLoad/testLoadSpeed/src/loadSharedFont.c @@ -0,0 +1,186 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: loadSharedFont.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:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "loadSharedFont.h" + +// 圧縮フォントを解凍するときは1にする +#define UNCOMPRESS_FONTS 1 + +// extern data----------------------------------------------------------------- + +// function's prototype------------------------------------------------------- +BOOL g_isSucceededLoad[ OS_SHARED_FONT_MAX ]; + +// static variable------------------------------------------------------------- +static u8 *s_pFontBuffer[ OS_SHARED_FONT_MAX ]; // 読み込みはテストなのでロード先はstatic変数にしている。 +static BOOL s_isStarted = FALSE; +static u8 *s_pCompressedBuffer[ OS_SHARED_FONT_MAX ]; // 圧縮用TempBuffer + +// const data------------------------------------------------------------------ + + +// ============================================================================ +// 共有フォントロード +// ============================================================================ +void LoadSharedFont( STicks *pTicks ) +{ + u8 *pBuffer; + int size; + OSSharedFontIndex i; + OSTick starttick; + + pTicks->all = 0; + pTicks->comp = 0; + + if( s_isStarted ) return; + + starttick = OS_GetTick(); + + // フォントロード準備 + if( !OS_InitSharedFont() ) { + OS_TPrintf( "OS_InitSharedFont failed.\n" ); + return; + } + size = OS_GetSharedFontTableSize(); + if( size < 0 ) { + OS_TPrintf( "OS_GetSharedTableSize failed.\n" ); + return; + } + + pBuffer = OS_Alloc( (u32)size ); + if( pBuffer == NULL ) { + OS_TPrintf( "malloc failed.\n" ); + return; + } + if( !OS_LoadSharedFontTable( pBuffer ) ) { + OS_TPrintf( "OS_LoadSharedTable failed.\n" ); + return; + } + + for( i = OS_SHARED_FONT_WW_S; i < OS_SHARED_FONT_MAX; i++ ) + { + int origsize; +#if (UNCOMPRESS_FONTS==1) + int compsize; + int comperr; + OSTick comptick; +#endif + + OS_TPrintf( "%s read.\n", OS_GetSharedFontName( i ) ); + + // フォントの元の(解凍後の)サイズ + origsize = OS_GetSharedFontSize( i ); + if( origsize < 0 ) + { + OS_TPrintf( " get font size failed.\n" ); + } + origsize = MATH_ROUNDUP( origsize, 32 ); // FSのキャッシュが怪しそうなので、とりあえずアラインメントをとっておく。 + OS_TPrintf( " original size = %d\n", origsize ); + +#if (UNCOMPRESS_FONTS==1) + compsize = OS_GetSharedFontCompressedSize( i ); + if( compsize < 0 ) + { + OS_TPrintf( " get compressed font size failed.\n" ); + } + OS_TPrintf( " compressed size = %d\n", compsize ); +#endif + + s_pFontBuffer[ i ] = OS_Alloc( (u32)origsize ); // 元のフォントサイズでバッファ確保 + if( s_pFontBuffer[ i ] == NULL ) + { + OS_TPrintf( " malloc failed.\n" ); + } + + // 圧縮後のフォントをロード +// s_pCompressedBuffer[i] = OS_Alloc( (u32)MATH_ROUNDUP( compsize, 32 ) ); +// if( OS_LoadSharedFont( i, s_pCompressedBuffer[ i ] ) ) + if( OS_LoadSharedFont( i, s_pFontBuffer[ i ] ) ) + { + OS_TPrintf( " load succeeded.\n" ); + g_isSucceededLoad[ i ] = TRUE; + } + else + { + OS_TPrintf( " load failed.\n" ); + g_isSucceededLoad[ i ] = FALSE; + } + + // 解凍 +#if (UNCOMPRESS_FONTS==1) + comptick = OS_GetTick(); + OS_TPrintf( " uncompress font\n" ); +// comperr = MI_SecureUncompressLZ( s_pCompressedBuffer[i], (u32)compsize, s_pFontBuffer[i], (u32)origsize ); + comperr = MI_SecureUncompressBLZ( s_pFontBuffer[i], (u32)compsize, (u32)origsize ); + if( MI_ERR_SUCCESS == comperr ) + { + OS_TPrintf( " uncompression succeeded\n" ); + } + else + { + OS_TPrintf( " uncompression failed %d\n", comperr ); + } + pTicks->comp += (OS_GetTick() - comptick); // 解凍にかかった時間 +#endif + } + + // 全部の処理にかかった時間 + pTicks->all = OS_GetTick() - starttick; + + s_isStarted = TRUE; +} + +void WriteFontIntoSD( void ) +{ + u8 *pFont = NULL; + int size; + OSSharedFontIndex i; + char str[100]; + FSFile fp[1]; + + FS_InitFile( fp ); + + for( i = OS_SHARED_FONT_WW_S; i < OS_SHARED_FONT_MAX; i++ ) + { + pFont = s_pFontBuffer[i]; + size = OS_GetSharedFontSize(i); + if( pFont != NULL) + { + STD_TSPrintf( str, "sdmc:/%s.uncomp", OS_GetSharedFontName(i) ); + FS_DeleteFile( str ); + if( !FS_CreateFile( str, FS_PERMIT_R|FS_PERMIT_W ) ) + { + OS_TPrintf( "sd create failed %d\n", FS_GetArchiveResultCode(str) ); + } + if( FS_OpenFileEx( fp, str, FS_FILEMODE_W ) ) + { + FS_WriteFile( fp, pFont, size ); + FS_CloseFile( fp ); + OS_TPrintf( "%s is written\n", str ); + } + else + { + OS_TPrintf( "sd write failed %d\n", FS_GetArchiveResultCode(str) ); + } + } + } +} + + + + diff --git a/build/tests/compressSharedFontLoad/testLoadSpeed/src/loadSharedFont.h b/build/tests/compressSharedFontLoad/testLoadSpeed/src/loadSharedFont.h new file mode 100644 index 00000000..4095ee9c --- /dev/null +++ b/build/tests/compressSharedFontLoad/testLoadSpeed/src/loadSharedFont.h @@ -0,0 +1,46 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: loadSharedFont.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:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef __LOAD_SHARED_FONT_H__ +#define __LOAD_SHARED_FONT_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// define data------------------------------------------------------- +typedef struct _STicks +{ + OSTick all; // 全部の時間 + OSTick comp; // 解凍の時間 +} STicks; + +// global variables-------------------------------------------------- +extern BOOL g_isSucceededLoad[ OS_SHARED_FONT_MAX ]; + +// function---------------------------------------------------------- +void LoadSharedFont( STicks *pTicks ); +void WriteFontIntoSD( void ); + +#ifdef __cplusplus +} +#endif + +#endif // __LOAD_SHARED_FONT_H__ diff --git a/build/tests/compressSharedFontLoad/testLoadSpeed/src/main.c b/build/tests/compressSharedFontLoad/testLoadSpeed/src/main.c new file mode 100644 index 00000000..ce1781e3 --- /dev/null +++ b/build/tests/compressSharedFontLoad/testLoadSpeed/src/main.c @@ -0,0 +1,101 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - demos - FS - overlay + 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:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + + +#include +#include + +#include "DEMO.h" +#include "loadSharedFont.h" + +/*---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: NitroMain + + Description: アプリケーションメインエントリ + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void NitroMain(void) +{ + STicks ticks; + + OS_Init(); + OS_InitTick(); + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + { + OSHeapHandle hh; + void *tmp; + tmp = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1); + OS_SetArenaLo(OS_ARENA_MAIN, tmp); + hh = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi()); + if (hh < 0) + { + OS_TPanic("ARM9: Fail to create heap...\n"); + } + (void)OS_SetCurrentHeap(OS_ARENA_MAIN, hh); + } + + DEMOInitCommon(); + DEMOInitVRAM(); + DEMOInitDisplayBitmap(); + DEMOHookConsole(); + + DEMOSetBitmapTextColor(GX_RGBA(31, 31, 0, 1)); + DEMOSetBitmapGroundColor(DEMO_RGB_CLEAR); + DEMOStartDisplay(); + + FS_Init(FS_DMA_NOT_USE); + + OS_TPrintf("--------------------------------\n" + "Shared Font sample.\n"); + + LoadSharedFont( &ticks ); + + // 結果表示 + { + int i; + int ox = 10; + int oy = 60; + + DEMOFillRect(0, 0, GX_LCD_SIZE_X, GX_LCD_SIZE_Y, DEMO_RGB_CLEAR); + DEMOSetBitmapTextColor(GX_RGBA(0, 31, 0, 1)); + DEMOSetBitmapTextColor(GX_RGBA(31, 31, 31, 1)); + DEMODrawFrame(ox, oy, 240, 10 + OS_SHARED_FONT_MAX * 10 + 20, GX_RGBA( 0, 31, 0, 1)); + for (i = 0; i < OS_SHARED_FONT_MAX; ++i) + { + DEMODrawText(ox + 10, oy + 5 + i * 10, "%s load %s", + OS_GetSharedFontName( (OSSharedFontIndex)i ), g_isSucceededLoad[ i ] ? "suceeded" : "failed"); + } + DEMODrawText(ox + 10, oy + 5 + OS_SHARED_FONT_MAX * 10, "all time %d msec", OS_TicksToMilliSeconds(ticks.all) ); + DEMODrawText(ox + 10, oy + 5 + OS_SHARED_FONT_MAX * 10 + 10, "comp time %d msec", OS_TicksToMilliSeconds(ticks.comp) ); + } + DEMO_DrawFlip(); + + WriteFontIntoSD(); + OS_TPrintf( "end\n" ); + OS_WaitVBlankIntr(); + + OS_Terminate(); +} + +