Merge pull request #3 from Morilli/fix-ines-header

Add error check in ines_load
This commit is contained in:
Sergio Martin 2025-02-28 11:48:35 +01:00 committed by GitHub
commit 098ad274bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -39,7 +39,7 @@ class Cart
static_assert(sizeof(ines_header_t) == 16);
// Load iNES file
void load_ines(const uint8_t *buffer)
const char *load_ines(const uint8_t *buffer)
{
ines_header_t h;
@ -50,6 +50,9 @@ class Cart
bufferPos += copySize;
}
if (memcmp(h.signature, "NES\x1A", 4) != 0)
return "Not an iNES file";
set_mapper(h.flags, h.flags2);
// skip trainer
@ -73,6 +76,8 @@ class Cart
memcpy(chr(), &buffer[bufferPos], copySize);
bufferPos += copySize;
}
return nullptr;
}
inline bool has_battery_ram() const { return mapper & 0x02; }

View File

@ -172,7 +172,9 @@ const char *Emu::emulate_frame(uint32_t joypad1, uint32_t joypad2, uint32_t arka
const char *Emu::load_ines(const uint8_t *buffer)
{
private_cart.load_ines(buffer);
const char *error = private_cart.load_ines(buffer);
if (error) return error;
return set_cart(&private_cart);
}
@ -842,4 +844,4 @@ void Emu::RestoreAudioBufferState()
sound_buf->RestoreAudioBufferState();
}
} // namespace quickerNES
} // namespace quickerNES