SRLが常に16の倍数になるようにした

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1166 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
yutaka 2008-04-17 01:32:55 +00:00
parent 4a70df1404
commit 5776995e29

View File

@ -10,9 +10,9 @@
not be disclosed to third parties or copied or duplicated in any form, 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. in whole or in part, without the prior written consent of Nintendo.
$Date:: $Date::
$Rev: $Rev:
$Author: $Author:
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
#include <unistd.h> #include <unistd.h>
@ -60,30 +60,30 @@ int main(int argc, char *argv[])
switch (n) { switch (n) {
case 'h': case 'h':
printf("Usage:\n" printf("Usage:\n"
" %s -s -l -c -i inputfile -o outputfile\n" " %s -s -l -c -i inputfile -o outputfile\n"
" -s (Systemfile) \n" " -s (Systemfile) \n"
" -l (Not Launch) \n" " -l (Not Launch) \n"
" -c XXXX ( GameCode )\n" " -c XXXX ( GameCode )\n"
" -i XXXX ( input file )\n" " -i XXXX ( input file )\n"
" -o XXXX ( output file )\n\n", " -o XXXX ( output file )\n\n",
argv[0]); argv[0]);
return 0; return 0;
case 'i': case 'i':
binFile = strdup( argv[optind] ); binFile = strdup( argv[optind] );
printf("input file = %s\n", binFile); printf("input file = %s\n", binFile);
break; break;
case 'o': case 'o':
srlFile = strdup( argv[optind] ); srlFile = strdup( argv[optind] );
printf("srl file = %s\n", srlFile); printf("srl file = %s\n", srlFile);
break; break;
case 'c': case 'c':
g_code = strdup( argv[optind] ); g_code = strdup( argv[optind] );
printf("game code = %s\n", g_code); printf("game code = %s\n", g_code);
if( 4 != strlen(g_code) ) { if( 4 != strlen(g_code) ) {
fprintf(stderr,"Error: invalid game code %s\n",g_code); fprintf(stderr,"Error: invalid game code %s\n",g_code);
return -1; return -1;
} }
break; break;
@ -100,7 +100,7 @@ int main(int argc, char *argv[])
} }
} }
if( binFile && srlFile ) { if( binFile && srlFile ) {
if( NULL == (bin_fp = fopen(binFile, "rb")) ) { if( NULL == (bin_fp = fopen(binFile, "rb")) ) {
fprintf(stderr,"Error:binFile open error %s\n",binFile); fprintf(stderr,"Error:binFile open error %s\n",binFile);
@ -128,30 +128,30 @@ int main(int argc, char *argv[])
rom_header.s.maker_code[0] = 0; // Maker code rom_header.s.maker_code[0] = 0; // Maker code
rom_header.s.maker_code[1] = 3; // Maker code rom_header.s.maker_code[1] = 3; // Maker code
rom_header.s.platform_code = 0x03; /* Platform code bit0: not support NTR, bit1: support TWL rom_header.s.platform_code = 0x03; /* Platform code bit0: not support NTR, bit1: support TWL
( NTR_only=0x00, NTR/TWL=0x03, TWL_only=0x02 ) */ ( NTR_only=0x00, NTR/TWL=0x03, TWL_only=0x02 ) */
// rom_header.s.rom_type; // rom_header.s.rom_type;
// rom_header.s.rom_size; /* Rom size (2のrom_size乗 Mbit: ex. 128Mbitのときrom_size = 7) */ // rom_header.s.rom_size; /* Rom size (2のrom_size乗 Mbit: ex. 128Mbitのときrom_size = 7) */
// rom_header.s.enable_signature:1; // enable ROM Header signature // rom_header.s.enable_signature:1; // enable ROM Header signature
// rom_header.s.enable_aes:1; // enable AES encryption // rom_header.s.enable_aes:1; // enable AES encryption
// rom_header.s.developer_encrypt:1; // 開発用セキュリティがかかっている場合に"1"。製品版では"0" // rom_header.s.developer_encrypt:1; // 開発用セキュリティがかかっている場合に"1"。製品版では"0"
// u32 arm7_scfg_ext; // SCFG-EXT // u32 arm7_scfg_ext; // SCFG-EXT
// u8 arm7_scfg_clk; // SCFG-CLK // u8 arm7_scfg_clk; // SCFG-CLK
// 0x1BF - TWL expansion flags // 0x1BF - TWL expansion flags
// u8 codec_mode:1; // 0:NTR mode, 1:TWL mode // undeveloped // u8 codec_mode:1; // 0:NTR mode, 1:TWL mode // undeveloped
// u8 otherParentalControls:1; // 1: Enable OtherParentalControls // u8 otherParentalControls:1; // 1: Enable OtherParentalControls
// u8 subBannerFile:1; // 1: Enable SubBannerFile // u8 subBannerFile:1; // 1: Enable SubBannerFile
rom_header.s.codec_mode = 1; // 0:NTR mode, 1:TWL mode // undeveloped rom_header.s.codec_mode = 1; // 0:NTR mode, 1:TWL mode // undeveloped
rom_header.s.otherParentalControls = 0; // 1: Enable OtherParentalControls rom_header.s.otherParentalControls = 0; // 1: Enable OtherParentalControls
rom_header.s.subBannerFile = 0; // 1: Enable SubBannerFile rom_header.s.subBannerFile = 0; // 1: Enable SubBannerFile
// u8 titleID_Lo[ 4 ]; // u8 titleID_Lo[ 4 ];
// u32 titleID_Hi; // u32 titleID_Hi;
rom_header.s.titleID_Lo[ 3 ] = *(g_code); rom_header.s.titleID_Lo[ 3 ] = *(g_code);
rom_header.s.titleID_Lo[ 2 ] = *(g_code+1); rom_header.s.titleID_Lo[ 2 ] = *(g_code+1);
@ -168,15 +168,15 @@ int main(int argc, char *argv[])
*/ */
rom_header.s.titleID_Hi = ( 3 /* Nintendo */ << 16) | rom_header.s.titleID_Hi = ( 3 /* Nintendo */ << 16) |
CHANNEL_CARD_BIT | CHANNEL_CARD_BIT |
CHANNEL_DATA_ONLY_BIT | CHANNEL_DATA_ONLY_BIT |
(isLaunch? 2:0) | (isLaunch? 2:0) |
(isSystem? 1:0); (isSystem? 1:0);
printf("titleID = 0x%08X%08x\n", (unsigned int)rom_header.s.titleID_Hi, (unsigned int)*((u32 *)&(rom_header.s.titleID_Lo[0]))); printf("titleID = 0x%08X%08x\n", (unsigned int)rom_header.s.titleID_Hi, (unsigned int)*((u32 *)&(rom_header.s.titleID_Lo[0])));
// 0x02f0 - 0x0300 Parental Controls Rating Info // 0x02f0 - 0x0300 Parental Controls Rating Info
// u8 ParentalControlsRatingInfo[ 0x10 ]; // u8 ParentalControlsRatingInfo[ 0x10 ];
rom_header.s.parental_control_rating_info[ 0x0 ] = 0; rom_header.s.parental_control_rating_info[ 0x0 ] = 0;
rom_header.s.parental_control_rating_info[ 0x1 ] = 1; rom_header.s.parental_control_rating_info[ 0x1 ] = 1;
@ -200,20 +200,32 @@ int main(int argc, char *argv[])
fprintf(stderr,"Error:file write error(ROM_Header)\n"); fprintf(stderr,"Error:file write error(ROM_Header)\n");
return -1; return -1;
} }
while( 1 ) { while( 1 ) {
read_size = fread((void *)file_read_buffer, 1, FILE_READ_BUFFER_LENGTH, bin_fp); read_size = fread((void *)file_read_buffer, 1, FILE_READ_BUFFER_LENGTH, bin_fp);
if( read_size ) { if( read_size ) {
if( 1 != fwrite((void *)&file_read_buffer, read_size, 1, srl_fp) ) { if( 1 != fwrite((void *)&file_read_buffer, read_size, 1, srl_fp) ) {
fprintf(stderr,"Error:file write error(bin file)\n"); fprintf(stderr,"Error:file write error(bin file)\n");
return -1; return -1;
} }
} }
else { else {
break; break;
} }
} }
/* SRLファイルは最低16バイトの倍数にしておく */
#define PADDING_TARGET 16
{
long fraction = ftell(srl_fp) % PADDING_TARGET;
if( fraction ) {
long zero[4] = { 0, 0, 0, 0 };
if( 1 != fwrite((void*)zero, PADDING_TARGET - fraction, 1, srl_fp) ) {
fprintf(stderr,"Error:file write error(padding)\n");
return -1;
}
}
}
fclose(bin_fp); fclose(bin_fp);
fclose(srl_fp); fclose(srl_fp);