Change detection of copier headers

This commit is contained in:
Dwedit 2018-08-28 13:53:09 -05:00
parent 443270021e
commit d044d370f8
2 changed files with 26 additions and 3 deletions

View File

@ -1380,6 +1380,20 @@ int CMemory::ScoreLoROM (bool8 skip_header, int32 romoff)
return (score); return (score);
} }
int CMemory::First512BytesCountZeroes() const
{
const uint8 *buf = ROM;
int zeroCount = 0;
for (int i = 0; i < 512; i++)
{
if (buf[i] == 0)
{
zeroCount++;
}
}
return zeroCount;
}
uint32 CMemory::HeaderRemove (uint32 size, uint8 *buf) uint32 CMemory::HeaderRemove (uint32 size, uint8 *buf)
{ {
uint32 calc_size = (size / 0x2000) * 0x2000; uint32 calc_size = (size / 0x2000) * 0x2000;
@ -1590,13 +1604,21 @@ bool8 CMemory::LoadROMInt (int32 ROMfillSize)
ExtendedFormat = NOPE; ExtendedFormat = NOPE;
int hi_score, lo_score; int hi_score, lo_score;
int score_headered;
int score_nonheadered;
hi_score = ScoreHiROM(FALSE); hi_score = ScoreHiROM(FALSE);
lo_score = ScoreLoROM(FALSE); lo_score = ScoreLoROM(FALSE);
score_nonheadered = max(hi_score, lo_score);
score_headered = max(ScoreHiROM(TRUE), ScoreLoROM(TRUE));
if (HeaderCount == 0 && !Settings.ForceNoHeader && bool size_is_likely_headered = ((ROMfillSize - 512) & 0xFFFF) == 0;
((hi_score > lo_score && ScoreHiROM(TRUE) > hi_score) || if (size_is_likely_headered) { score_headered += 2; } else { score_headered -= 2; }
(hi_score <= lo_score && ScoreLoROM(TRUE) > lo_score))) if (First512BytesCountZeroes() >= 0x1E0) { score_headered += 2; } else { score_headered -= 2; }
bool headered_score_highest = score_headered > score_nonheadered;
if (HeaderCount == 0 && !Settings.ForceNoHeader && headered_score_highest)
{ {
memmove(ROM, ROM + 512, ROMfillSize - 512); memmove(ROM, ROM + 512, ROMfillSize - 512);
ROMfillSize -= 512; ROMfillSize -= 512;

View File

@ -286,6 +286,7 @@ struct CMemory
int ScoreHiROM (bool8, int32 romoff = 0); int ScoreHiROM (bool8, int32 romoff = 0);
int ScoreLoROM (bool8, int32 romoff = 0); int ScoreLoROM (bool8, int32 romoff = 0);
int First512BytesCountZeroes() const;
uint32 HeaderRemove (uint32, uint8 *); uint32 HeaderRemove (uint32, uint8 *);
uint32 FileLoader (uint8 *, const char *, uint32); uint32 FileLoader (uint8 *, const char *, uint32);
uint32 MemLoader (uint8 *, const char*, uint32); uint32 MemLoader (uint8 *, const char*, uint32);