ROMファイルデコーダ:初版。マスターROMファイル名からリマスターバージョンと提出バージョンを取得するプログラム。

perlのほうが楽だけど、cygwin入れるの嫌がられるのでVCで作成。

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlToolsRED@107 7061adef-622a-194b-ae81-725974e89856
This commit is contained in:
nishikawa_takeshi 2009-01-08 10:53:45 +00:00
parent 5c3060a667
commit d0c2672f63
19 changed files with 940 additions and 0 deletions

View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RomFilenameDecoderTWL", "RomFilenameDecoderTWL\RomFilenameDecoderTWL.vcproj", "{366CCEEF-B820-4B00-9129-0BDA482DD939}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{366CCEEF-B820-4B00-9129-0BDA482DD939}.Debug|Win32.ActiveCfg = Debug|Win32
{366CCEEF-B820-4B00-9129-0BDA482DD939}.Debug|Win32.Build.0 = Debug|Win32
{366CCEEF-B820-4B00-9129-0BDA482DD939}.Release|Win32.ActiveCfg = Release|Win32
{366CCEEF-B820-4B00-9129-0BDA482DD939}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,40 @@
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;
//
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
// アセンブリに関連付けられている情報を変更するには、
// これらの属性値を変更してください。
//
[assembly:AssemblyTitleAttribute("RomFilenameDecoderTWL")];
[assembly:AssemblyDescriptionAttribute("")];
[assembly:AssemblyConfigurationAttribute("")];
[assembly:AssemblyCompanyAttribute("任天堂株式会社")];
[assembly:AssemblyProductAttribute("RomFilenameDecoderTWL")];
[assembly:AssemblyCopyrightAttribute("Copyright (c) 任天堂株式会社 2009")];
[assembly:AssemblyTrademarkAttribute("")];
[assembly:AssemblyCultureAttribute("")];
//
// アセンブリのバージョン情報は、以下の 4 つの値で構成されています:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// すべての値を指定するか、下のように '*' を使ってリビジョンおよびビルド番号を
// 既定値にすることができます:
[assembly:AssemblyVersionAttribute("1.0.*")];
[assembly:ComVisible(false)];
[assembly:CLSCompliantAttribute(true)];
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];

View File

@ -0,0 +1,29 @@
===============================================================================
アプリケーション : RomFilenameDecoderTWL プロジェクトの概要
===============================================================================
この RomFilenameDecoderTWL アプリケーションは、AppWizard によって作成されました。
このファイルには、RomFilenameDecoderTWL アプリケーションを構成する各ファイルの
内容の概略が記述されています。
RomFilenameDecoderTWL.vcproj
これは、アプリケーション ウィザードで生成される VC++ プロジェクトのメインの
プロジェクト ファイルです。
ファイルを生成した Visual C++ のバージョン情報と、アプリケーション ウィザー
ドで選択したプラットフォーム、構成、およびプロジェクトの機能に関する情報が
記述されています。
RomFilenameDecoderTWL.cpp
これは、メインのアプリケーション ソース ファイルです。
AssemblyInfo.cpp
アセンブリ メタデータを変更するためのカスタム属性が含まれています。
///////////////////////////////////////////////////////////////////////////////
その他のメモ :
AppWizard では、"TODO:" を使用して、ユーザーが追加またはカスタマイズするソース
部分を示します。
///////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,91 @@
// RomFilenameDecoderTWL.cpp : メイン プロジェクト ファイルです。
#include "stdafx.h"
#include "rfd_context.h"
#include <cstdio>
#include <cstring>
#include <twl/types.h>
#include <twl/os/common/format_rom.h>
using namespace System;
int printResult( RomFilenameDecoderTWL::RCContext ^context,
RomFilenameDecoderTWL::RCFilenameItems ^items );
int main(array<System::String ^> ^args)
{
// 引数解析
RomFilenameDecoderTWL::RCContext ^context
= gcnew RomFilenameDecoderTWL::RCContext( args );
// ファイル名の解析
RomFilenameDecoderTWL::RCFilenameItems ^items
= gcnew RomFilenameDecoderTWL::RCFilenameItems( context->Romfile );
// 比較
items->compareRomHeader();
int retval = printResult( context, items );
return retval;
}
// -------------------------------------------------------
// エラー解析
// -------------------------------------------------------
int printResult( RomFilenameDecoderTWL::RCContext ^context,
RomFilenameDecoderTWL::RCFilenameItems ^items )
{
System::UInt16 tadver = items->RemasterVersion;
tadver = (tadver << 8) | ((System::UInt16)items->SubmissionVersion);
if( context->IsSubmitVersion )
{
if( items->Error != RomFilenameDecoderTWL::ECError::NOERROR )
{
printf( "%d", (int)items->Error );
}
else
{
printf( "%d", (int)items->SubmissionVersion );
}
}
else if( context->IsTadVersion )
{
if( items->Error != RomFilenameDecoderTWL::ECError::NOERROR )
{
printf( "%d", (int)items->Error );
}
else
{
printf( "%d", (int)tadver );
}
}
else
{
System::Console::WriteLine();
System::Console::WriteLine( "Rom Filename: " + context->Romfile );
System::Console::WriteLine();
const char *rhgc = items->Rh->s.game_code;
char fgc[4];
RomFilenameDecoderTWL::setStringToChars( fgc, items->InitialCode, 4, 0 );
printf( " RomHeader Filename\n" );
printf( "----------------------------------------------\n" );
printf( "InitialCode: %c%c%c%c %c%c%c%c\n", rhgc[0], rhgc[1], rhgc[2], rhgc[3], fgc[0], fgc[1], fgc[2], fgc[3] );
printf( "RemasterVersion: %02X %02X\n", items->Rh->s.rom_version, items->RemasterVersion );
printf( "SubmissionVersion: - %d(%02X)\n", items->SubmissionVersion, items->SubmissionVersion );
printf( "----------------------------------------------\n" );
printf( "TAD Version: - %d(%04X)\n", (int)tadver, tadver );
printf( "----------------------------------------------\n" );
printf( "Result: " );
if( items->Error == RomFilenameDecoderTWL::ECError::NOERROR )
{
printf( "OK\n" );
}
else
{
printf( "NG (%d)\n", (int)items->Error );
}
}
return ((int)items->Error);
}

View File

@ -0,0 +1,262 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="RomFilenameDecoderTWL"
ProjectGUID="{366CCEEF-B820-4B00-9129-0BDA482DD939}"
RootNamespace="RomFilenameDecoderTWL"
Keyword="ManagedCProj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
ManagedExtensions="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="C:\twlsdk\include"
PreprocessorDefinitions="WIN32;_DEBUG"
RuntimeLibrary="3"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="$(NoInherit)"
LinkIncremental="2"
GenerateDebugInformation="true"
AssemblyDebug="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
ManagedExtensions="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="C:\twlsdk\include"
PreprocessorDefinitions="WIN32;NDEBUG"
RuntimeLibrary="2"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="$(NoInherit)"
LinkIncremental="1"
GenerateDebugInformation="true"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
<AssemblyReference
RelativePath="System.dll"
AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
MinFrameworkVersion="131072"
/>
<AssemblyReference
RelativePath="System.Data.dll"
AssemblyName="System.Data, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86"
MinFrameworkVersion="131072"
/>
<AssemblyReference
RelativePath="System.XML.dll"
AssemblyName="System.Xml, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
MinFrameworkVersion="131072"
/>
</References>
<Files>
<Filter
Name="ソース ファイル"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\AssemblyInfo.cpp"
>
</File>
<File
RelativePath=".\rfd_util.cpp"
>
</File>
<File
RelativePath=".\RomFilenameDecoderTWL.cpp"
>
</File>
<File
RelativePath=".\stdafx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="ヘッダー ファイル"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\resource.h"
>
</File>
<File
RelativePath=".\rfd_context.h"
>
</File>
<File
RelativePath=".\rfd_util.h"
>
</File>
<File
RelativePath=".\stdafx.h"
>
</File>
</Filter>
<Filter
Name="リソース ファイル"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File
RelativePath=".\app.ico"
>
</File>
<File
RelativePath=".\app.rc"
>
</File>
</Filter>
<File
RelativePath=".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="9.00"
ShowAllFiles="false"
>
<Configurations>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="PC2355"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="PC2355"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,63 @@
// Microsoft Visual C++ で生成されたリソース スクリプトです。
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// 英語 (米国) リソース
/////////////////////////////////////////////////////////////////////////////
//
// アイコン
//
// 最初に配置されたアイコン、または ID 値が最も低いアイコンが、アプリケーション アイコンになります。
LANGUAGE 17, 1
#pragma code_page(932)
1 ICON "app.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
"\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE 3 リソースから生成されました。
//
/////////////////////////////////////////////////////////////////////////////
#endif // APSTUDIO_INVOKED でない場合

View File

@ -0,0 +1,3 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by app.rc

View File

@ -0,0 +1,272 @@
#pragma once
#include <twl/types.h>
#include <twl/os/common/format_rom.h>
#include <cstdio>
#include <cstring>
#include "rfd_util.h"
namespace RomFilenameDecoderTWL
{
// -----------------------------------------------------------
// エラーコード
// -----------------------------------------------------------
enum class ECError
{
NOERROR = 0,
ERROR_READ_FILE = -1,
ERROR_FILE_NAME = -2,
// -3..-7 予約
ERROR_INITIAL_CODE = -8,
ERROR_REMASTER_VERSION = -9,
};
// -----------------------------------------------------------
// 実行context
// -----------------------------------------------------------
ref class RCContext
{
private:
// 引数の解析結果
System::String ^romfile; // 入力ファイル名
System::Int32 argc; // 引数の数
// オプションを表すフラグ
System::Boolean isSubmitVersion;
System::Boolean isTadVersion;
public:
// ReadOnlyにする
property System::String^ Romfile
{
System::String^ get(void)
{
if( !romfile )
{
return nullptr;
}
return System::String::Copy( this->romfile );
}
}
property System::Int32 Argc
{
System::Int32 get(void){ return this->argc; }
}
property System::Boolean IsSubmitVersion
{
System::Boolean get(void){ return this->isSubmitVersion; }
}
property System::Boolean IsTadVersion
{
System::Boolean get(void){ return this->isTadVersion; }
}
private:
RCContext(){} // 封じる
public:
// コンストラクタでは引数をもらってフラグを解析する
RCContext( cli::array<System::String ^> ^args )
{
this->parseArgs( args );
}
private:
// 引数解析
void parseArgs( cli::array<System::String ^> ^args )
{
System::Collections::Generic::List<System::Int32> ^indexList
= gcnew System::Collections::Generic::List<System::Int32>;
int numopt = 0;
int i;
for( i=0; i < args->Length; i++ )
{
if( args[i]->StartsWith( "-s" ) )
{
this->isSubmitVersion = true;
numopt++;
}
else if( args[i]->StartsWith( "-t" ) )
{
this->isTadVersion = true;
numopt++;
}
else if( !args[i]->StartsWith( "-" ) ) // オプションでない引数のindexを記録
{
indexList->Add(i);
}
}
i=0;
for each( System::Int32 index in indexList ) // オプションでない引数を前につめていく
{
args[i] = args[index];
i++;
}
this->argc = args->Length - numopt; // 引数の数からオプションの数を除く
if( this->argc > 0 )
{
this->romfile = System::String::Copy( args[0] );
}
else
{
this->romfile = nullptr;
}
}
}; //ref class RCContext
// -----------------------------------------------------------
// ファイル名から取得できる情報
// -----------------------------------------------------------
ref class RCFilenameItems
{
private:
// ファイル名から取得できる情報
System::String^ initialCode;
System::Byte remasterVersion;
System::Byte submissionVersion;
// ファイルから読み込んだROMヘッダ
ROM_Header *rh;
// エラー情報
RomFilenameDecoderTWL::ECError error;
public:
property System::String^ InitialCode
{
System::String^ get(void){ return System::String::Copy(this->initialCode); }
}
property System::Byte RemasterVersion
{
System::Byte get(void){ return this->remasterVersion; }
}
property System::Byte SubmissionVersion
{
System::Byte get(void){ return this->submissionVersion; }
}
property const ROM_Header* Rh
{
const ROM_Header* get(void){ return this->rh; }
}
property RomFilenameDecoderTWL::ECError Error
{
RomFilenameDecoderTWL::ECError get(void){ return this->error; }
}
private:
RCFilenameItems(){}
public:
RCFilenameItems( System::String ^filepath )
{
this->initialCode = gcnew System::String("");
this->remasterVersion = 0;
this->submissionVersion = 0;
this->rh = new ROM_Header;
memset( this->rh, 0, sizeof(ROM_Header) );
this->error = RomFilenameDecoderTWL::ECError::NOERROR;
this->parseFilename( filepath );
if( this->error == RomFilenameDecoderTWL::ECError::NOERROR )
{
this->readRomHeader( filepath );
}
}
~RCFilenameItems()
{
this->!RCFilenameItems();
}
!RCFilenameItems()
{
delete this->rh;
}
private:
// ROMヘッダを読み込む
void readRomHeader( System::String ^filepath )
{
if( !RomFilenameDecoderTWL::readRomHeader( filepath, this->rh ) )
{
this->error = RomFilenameDecoderTWL::ECError::ERROR_READ_FILE;
}
}
// ファイル名を解析してメンバ変数を設定する
void parseFilename( System::String ^filepath )
{
if( !filepath ) // 指定されていない場合
{
this->error = RomFilenameDecoderTWL::ECError::ERROR_FILE_NAME;
return;
}
System::String^ prefix = System::IO::Path::GetFileNameWithoutExtension( filepath ); // 拡張子とディレクトリパスを除く
if( prefix->Length < 7 ) // T****@#.SRL / T****0#E.SRL のいずれか
{
this->error = RomFilenameDecoderTWL::ECError::ERROR_FILE_NAME;
return;
}
this->initialCode = prefix->Substring(1,4);
this->remasterVersion = this->parseStrToByte( prefix->Substring(5,1) );
if( prefix->Length >= 8 )
{
if( ((char)prefix[7] == 'E') && (this->remasterVersion == 0) )
{
this->remasterVersion = 0xE0;
}
}
this->submissionVersion = this->parseStrToByte( prefix->Substring(6,1) );
} //void parseFilename()
public:
// 1桁の数字を数値に変換
System::Byte parseStrToByte( System::String ^str )
{
if( str->Length > 1 )
{
return 0xff;
}
System::Byte val;
// 通常 0..F だが その上を G..Z で表す可能性がある
char c = (char)str[0];
if( ('G' <= c) && (c <= 'Z') ) // Fより上はG..Zで表現されていく(可能性あり)
{
val = c - 'G' + 16;
}
else if( ('g' <= c) && (c <= 'z') )
{
val = c - 'g' + 16;
}
else
{
try
{
val = System::Byte::Parse( str, System::Globalization::NumberStyles::AllowHexSpecifier );
}
catch(System::Exception ^e )
{
(void)e;
val = 0xff;
}
}
return val;
} //parseStrToByte()
public:
// ROMヘッダの情報と自身の情報を比較(エラー情報はメンバ変数に設定)
void compareRomHeader()
{
// すでにエラーがある場合には何もしない
if( this->error != RomFilenameDecoderTWL::ECError::NOERROR )
{
return;
}
// イニシャルコードの比較
char inicode[4];
RomFilenameDecoderTWL::setStringToChars( inicode, this->initialCode, 4, 0 );
if( memcmp( this->rh->s.game_code, inicode, 4 ) != 0 )
{
this->error = RomFilenameDecoderTWL::ECError::ERROR_INITIAL_CODE;
return;
}
// リマスターバージョンの比較
if( this->rh->s.rom_version != this->remasterVersion )
{
this->error = RomFilenameDecoderTWL::ECError::ERROR_REMASTER_VERSION;
return;
}
// 提出バージョンはROMヘッダにないので比較できない
this->error = RomFilenameDecoderTWL::ECError::NOERROR;
return;
} //void compareRomHeader()
}; //ref class RCFilenameItems
} //namespace RomFilenameDecoderTWL

View File

@ -0,0 +1,55 @@
#include "stdafx.h"
#include <cstdio>
#include <cstring>
#include <twl/types.h>
#include <twl/os/common/format_rom.h>
#include "rfd_util.h"
// ------------------------------------------------------------------
// ROMヘッダの読み込み
// ------------------------------------------------------------------
System::Boolean RomFilenameDecoderTWL::readRomHeader( System::String ^srlfile, ROM_Header *rh )
{
FILE *fp = NULL;
const char *pchFilename =
(const char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi( srlfile ).ToPointer();
// ファイルを開いてROMヘッダのみ読み出す
if( fopen_s( &fp, pchFilename, "rb" ) != NULL )
{
return false;
}
(void)fseek( fp, 0, SEEK_SET ); // ROMヘッダはsrlの先頭から
// 1バイトをsizeof(~)だけリード (逆だと返り値がsizeof(~)にならないので注意)
if( fread( (void*)rh, 1, sizeof(ROM_Header), fp ) != sizeof(ROM_Header) )
{
fclose( fp );
return false;
}
fclose( fp );
return true;
}
// ------------------------------------------------------------------
// String を char 配列に格納
// ------------------------------------------------------------------
// @arg [out] 格納先
// @arg [in] 格納元
// @arg [in] 文字列長
// @arg [in] 余りを埋める padding
void RomFilenameDecoderTWL::setStringToChars(
char *pDst, System::String ^hSrc,
const System::Int32 nMax, const System::SByte pad )
{
System::Int32 i;
memset( pDst, pad, nMax );
for( i=0; (i < hSrc->Length) && (i < nMax); i++ )
{
pDst[i] = (char)hSrc[i];
}
}

View File

@ -0,0 +1,25 @@
#pragma once
#include <twl/types.h>
#include <twl/os/common/format_rom.h>
namespace RomFilenameDecoderTWL
{
// ------------------------------------------------------------------
// ROMヘッダの読み込み
// ------------------------------------------------------------------
System::Boolean readRomHeader( System::String ^srlfile, ROM_Header *rh );
// ------------------------------------------------------------------
// String を char 配列に格納
// ------------------------------------------------------------------
// @arg [out] 格納先
// @arg [in] 格納元
// @arg [in] 文字列長
// @arg [in] 余りを埋める padding
void setStringToChars( char *pDst, System::String ^hSrc,
const System::Int32 nMax, const System::SByte pad );
} //namespace RomFilenameDecoderTWL

View File

@ -0,0 +1,7 @@
// stdafx.cpp : 標準インクルード RomFilenameDecoderTWL.pch のみを
// 含むソース ファイルは、プリコンパイル済みヘッダーになります。
// stdafx.obj にはプリコンパイル済み型情報が含まれます。
#include "stdafx.h"

View File

@ -0,0 +1,8 @@
// stdafx.h : 標準のシステム インクルード ファイルのインクルード ファイル、または
// 参照回数が多く、かつあまり変更されない、プロジェクト専用のインクルード ファイル
// を記述します。
//
#pragma once
// TODO: プログラムに必要な追加ヘッダーをここで参照してください。