Backport Fixed issues with PRG sizes under 256 bytes

This commit is contained in:
vailkyte 2023-05-18 08:42:06 -05:00 committed by GitHub
parent 8b5bfef788
commit 705c291209
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,7 +80,13 @@ void iNesLoader::LoadRom(RomData& romData, vector<uint8_t>& romFile, NESHeader *
MessageManager::Log("[iNes] Warning: File is larger than excepted (based on the file header).");
}
romData.Info.Hash.PrgCrc32 = CRC32::GetCRC(buffer, prgSize);
romData.PrgRom.insert(romData.PrgRom.end(), buffer, buffer + prgSize);
while(romData.PrgRom.size() < 256) {
//Ensure the PRG is at least 256 bytes in size by mirroring as needed (mapper code requires it to be 256 bytes at least)
romData.PrgRom.insert(romData.PrgRom.end(), buffer, buffer + std::min<int>(prgSize, 256 - romData.PrgRom.size()));
}
buffer += prgSize;
romData.ChrRom.insert(romData.ChrRom.end(), buffer, buffer + chrSize);
buffer += chrSize;
@ -90,8 +96,6 @@ void iNesLoader::LoadRom(RomData& romData, vector<uint8_t>& romFile, NESHeader *
romData.MiscRomsData.insert(romData.MiscRomsData.end(), buffer, buffer + (dataSize - (prgSize + chrSize)));
}
romData.Info.Hash.PrgCrc32 = CRC32::GetCRC(romData.PrgRom.data(), romData.PrgRom.size());
Log("PRG CRC32: 0x" + HexUtilities::ToHex(romData.Info.Hash.PrgCrc32, true));
Log("PRG+CHR CRC32: 0x" + HexUtilities::ToHex(romData.Info.Hash.PrgChrCrc32, true));