Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash/exit instead of returning error for unsupported mappers #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions source/quickerNES/core/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Core : private Cpu
return 0;
}

void open(Cart const *new_cart)
const char *open(Cart const *new_cart)
{
close();
init();
Expand All @@ -153,7 +153,7 @@ class Core : private Cpu
if (mapper == nullptr)
{
fprintf(stderr, "Could not find mapper for code: %u\n", mapperCode);
exit(-1);
return "Unsupported mapper";
}

// Assigning backwards pointers to cartdrige and emulator now
Expand All @@ -165,6 +165,8 @@ class Core : private Cpu
cart = new_cart;
memset(impl->unmapped_page, unmapped_fill, sizeof impl->unmapped_page);
reset(true, true);

return nullptr;
}

inline void serializeState(jaffarCommon::serializer::Base &serializer) const
Expand Down
11 changes: 7 additions & 4 deletions source/quickerNES/core/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,19 @@ inline void Emu::clear_sound_buf()
sound_buf->clear();
}

void Emu::set_cart(Cart const *new_cart)
const char *Emu::set_cart(Cart const *new_cart)
{
auto_init();
emu.open(new_cart);
const char *error = emu.open(new_cart);
if (error) return error;

channel_count_ = Apu::osc_count + emu.mapper->channel_count();
sound_buf->set_channel_count(channel_count());
set_equalizer(equalizer_);
enable_sound(true);
reset();

return nullptr;
}

void Emu::reset(bool full_reset, bool erase_battery_ram)
Expand Down Expand Up @@ -167,10 +170,10 @@ const char *Emu::emulate_frame(uint32_t joypad1, uint32_t joypad2, uint32_t arka

// Extras

void Emu::load_ines(const uint8_t *buffer)
const char *Emu::load_ines(const uint8_t *buffer)
{
private_cart.load_ines(buffer);
set_cart(&private_cart);
return set_cart(&private_cart);
}

void Emu::write_chr(void const *p, long count, long offset)
Expand Down