mirror of
https://github.com/rvtr/twl_wrapsdk.git
synced 2025-10-31 06:11:10 -04:00
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@194 4ee2a332-4b2b-5046-8439-1ba90f034370
169 lines
4.0 KiB
Perl
169 lines
4.0 KiB
Perl
#!/usr/bin/perl --
|
||
|
||
use strict;
|
||
|
||
# ŒÅ’èƒtƒH<C692>[ƒ}ƒbƒg
|
||
my $file_head_format =<<'EOF';
|
||
/*---------------------------------------------------------------------------*
|
||
Project: TwlSDK - libralies - camera
|
||
File: %1$s
|
||
|
||
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.
|
||
|
||
$Log: $
|
||
$NoKeywords: $
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
//#define PRINT_DEBUG
|
||
|
||
#ifdef PRINT_DEBUG
|
||
#include <nitro/os/common/printf.h>
|
||
#define DBG_PRINTF OS_TPrintf
|
||
#else
|
||
#define DBG_PRINTF( ... ) ((void)0)
|
||
#endif
|
||
|
||
static BOOL CAMERAi_S_Initialize( CameraSelect camera )
|
||
{
|
||
EOF
|
||
|
||
my $file_foot_format =<<'EOF';
|
||
return TRUE;
|
||
}
|
||
EOF
|
||
|
||
my $single_format =<<'EOF';
|
||
if (CAMERAi_S_WriteRegister(camera, 0x%02X, 0x%02X) == FALSE)
|
||
{
|
||
DBG_PRINTF("Failed to write a register! (%%d)\n", __LINE__);
|
||
return FALSE;
|
||
}
|
||
EOF
|
||
|
||
my $multi_head_format =<<'EOF';
|
||
{
|
||
const u8 data[] =
|
||
{
|
||
EOF
|
||
|
||
my $multi_foot_format =<<'EOF';
|
||
};
|
||
if (CAMERAi_S_WriteRegisters(camera, 0x%02X, data, %d) == FALSE)
|
||
{
|
||
DBG_PRINTF("Failed to write registers! (%%d)\n", __LINE__);
|
||
return FALSE;
|
||
}
|
||
}
|
||
EOF
|
||
|
||
sub print_data {
|
||
my $result = "";
|
||
for (my $i = 0; $i < @_; $i++)
|
||
{
|
||
if (($i % 16) == 0) {
|
||
$result .= " " ;
|
||
} else {
|
||
$result .= " " ;
|
||
}
|
||
$result .= sprintf("0x%02X,", $_[$i]);
|
||
if (($i % 16) == 15) {
|
||
$result .= "\r\n";
|
||
}
|
||
}
|
||
if ((@_ % 16) != 0) {
|
||
$result .= "\r\n";
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
sub print_command {
|
||
my($addr, @value) = @_;
|
||
if (@value == 1) {
|
||
return sprintf($single_format, $addr, $value[0]);
|
||
}
|
||
my $result = $multi_head_format;
|
||
for (my $i = 0; $i < @value; $i++)
|
||
{
|
||
if (($i % 16) == 0) {
|
||
$result .= " " ;
|
||
} else {
|
||
$result .= " " ;
|
||
}
|
||
$result .= sprintf("0x%02X,", $value[$i]);
|
||
if (($i % 16) == 15) {
|
||
$result .= "\r\n";
|
||
}
|
||
}
|
||
if ((@value % 16) != 0) {
|
||
$result .= "\r\n";
|
||
}
|
||
$result .= sprintf($multi_foot_format, $addr, scalar(@value));
|
||
return $result;
|
||
}
|
||
|
||
#
|
||
# ƒf<C692>[ƒ^‚Í‚¢‚Á‚½‚ñƒLƒƒƒbƒVƒ…‚µ‚Ä<E2809A>A˜A‘±ƒAƒhƒŒƒX‚ðƒo<C692>[ƒXƒgƒ‰ƒCƒg‚É<E2809A>‘‚«Š·‚¦‚é
|
||
#
|
||
my @cache; # ƒLƒƒƒbƒVƒ…ƒf<C692>[ƒ^
|
||
my $start = -1; # ƒLƒƒƒbƒVƒ…‚Ì<E2809A>擪ƒAƒhƒŒƒX
|
||
my @output; # <20>o—̓f<C692>[ƒ^
|
||
my $comment = ""; # ƒRƒ<52>ƒ“ƒg
|
||
|
||
#‚±‚±‚©‚çƒ<C3A7>ƒCƒ“
|
||
|
||
# ˆø<CB86>”ƒ`ƒFƒbƒN
|
||
die "USAGE: $0 INFILE [OUTFILE]\n" if ($#ARGV != 1 and $#ARGV != 0);
|
||
|
||
# ŠeŽí<C5BD>‰Šú‰»
|
||
my $infile = $ARGV[0];
|
||
my $outfile = $ARGV[1];
|
||
($outfile = $infile) =~ s/\.ini$/.autogen.c/ unless ($outfile);
|
||
|
||
# “ü<E2809C>o—̓tƒ@ƒCƒ‹‚̃I<C692>[ƒvƒ“ (—¼•ûƒI<C692>[ƒvƒ“‚µ‚Ä‚¨‚)
|
||
open IN, $infile or die "Cannot open the input file!\n";
|
||
open OUT, ">", $outfile or die "Cannot open the output file!\n";
|
||
|
||
# “ü—Í<E28094>ˆ—<CB86>
|
||
while (<IN>) {
|
||
s/[\r\n]+$//; # delete \r and/or \n
|
||
s|\#|// |g; # change comment sign
|
||
if (s|(//.*)||) { # ƒRƒ<52>ƒ“ƒg’Š<E28099>o
|
||
$comment .= " $1\r\n";
|
||
}
|
||
|
||
if (/\s*([\w\d]{2})\s+([\w\d]{2})/) { # ƒf<C692>[ƒ^’Š<E28099>o
|
||
my ($addr, $value) = (hex($1), hex($2));
|
||
if ($addr != $start + @cache)
|
||
{
|
||
push @output, print_command($start, @cache) if (@cache);
|
||
@cache = ($value);
|
||
$start = $addr;
|
||
} else {
|
||
push @cache, $value;
|
||
}
|
||
push @output, $comment; # ƒRƒ<52>ƒ“ƒg<C692>o—Í
|
||
$comment = "";
|
||
}
|
||
elsif (/\S+/) { # –¢’m“ü—Í<E28094>sŒŸ<C592>o (ƒRƒ<52>ƒ“ƒgˆµ‚¢ (ƒGƒ‰<C692>[‚É‚·‚ׂ«‚©‚à))
|
||
warn "UNKNOWN STATEMENT: <<", $_, ">>\n";
|
||
}
|
||
}
|
||
# <20>Å<EFBFBD>I<EFBFBD>s<EFBFBD>ˆ—<CB86>
|
||
push @output, print_command($start, @cache);
|
||
# “ü—Í<E28094>ˆ—<CB86><E28094>I—¹
|
||
close IN;
|
||
|
||
# <20>o—Í<E28094>ˆ—<CB86>
|
||
$outfile =~ s/^.*[\\\/]//; # get basename to print
|
||
printf OUT $file_head_format, $outfile; # ƒtƒ@ƒCƒ‹ƒwƒbƒ_<C692>o—Í
|
||
print OUT @output;
|
||
printf OUT $file_foot_format; # ƒtƒ@ƒCƒ‹ƒtƒbƒ^<5E>o—Í
|
||
# <20>o—Í<E28094>ˆ—<CB86><E28094>I—¹
|
||
close OUT;
|