diff --git a/source/quickerNES/core/cart.hpp b/source/quickerNES/core/cart.hpp index ccd61f4..75d025c 100644 --- a/source/quickerNES/core/cart.hpp +++ b/source/quickerNES/core/cart.hpp @@ -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; } diff --git a/source/quickerNES/core/emu.cpp b/source/quickerNES/core/emu.cpp index a706be2..751b12a 100644 --- a/source/quickerNES/core/emu.cpp +++ b/source/quickerNES/core/emu.cpp @@ -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 \ No newline at end of file +} // namespace quickerNES