NstCartridgeInes: Improve iNES header parsing for official releases

This commit is contained in:
Rupert Carmichael
2024-06-22 10:43:13 -04:00
parent 20a545b6e4
commit 2faefc52d7
2 changed files with 4 additions and 4 deletions

View File

@@ -188,7 +188,7 @@ namespace Nes
// This might be a VC/NES Remix game, seek to end of container and re-read header // This might be a VC/NES Remix game, seek to end of container and re-read header
stream.Seek(32); stream.Seek(32);
stream.Read( header ); stream.Read( header );
result = ReadHeader( setup, header, 16, 0x00 ); result = ReadHeader( setup, header, 16, false );
if (NES_FAILED(result)) if (NES_FAILED(result))
throw RESULT_ERR_CORRUPT_FILE; throw RESULT_ERR_CORRUPT_FILE;
@@ -622,7 +622,7 @@ namespace Nes
loader.Load(); loader.Load();
} }
Result Cartridge::Ines::ReadHeader(Header& setup,const byte* const file,const ulong length,const byte lbyte) Result Cartridge::Ines::ReadHeader(Header& setup,const byte* const file,const ulong length,const bool lbyte)
{ {
if (file == NULL) if (file == NULL)
return RESULT_ERR_INVALID_PARAM; return RESULT_ERR_INVALID_PARAM;
@@ -633,7 +633,7 @@ namespace Nes
file[0] != Ascii<'N'>::V || file[0] != Ascii<'N'>::V ||
file[1] != Ascii<'E'>::V || file[1] != Ascii<'E'>::V ||
file[2] != Ascii<'S'>::V || file[2] != Ascii<'S'>::V ||
(file[3] != 0x1A && file[3] != lbyte) (file[3] != 0x1A && lbyte) // Last byte may be ignored for "official" ROMs
) )
return RESULT_ERR_INVALID_FILE; return RESULT_ERR_INVALID_FILE;

View File

@@ -55,7 +55,7 @@ namespace Nes
const ImageDatabase* const ImageDatabase*
); );
static Result ReadHeader(Header&,const byte*,ulong,const byte=0x1A); static Result ReadHeader(Header&,const byte*,ulong,const bool=true);
static Result WriteHeader(const Header&,byte*,ulong); static Result WriteHeader(const Header&,byte*,ulong);
}; };
} }