From 3d3f332d627a742e50b2eab315f4e76befd41e3d Mon Sep 17 00:00:00 2001 From: roee toledano Date: Tue, 19 Mar 2024 20:20:37 +0200 Subject: [PATCH] fixed something with the rom saving, metroid doesnt work though --- src/main.cpp | 2 +- src/mapper_n_cart.cpp | 4 ++-- src/mappers/mmc1_1.cpp | 5 ++++- src/mappers/mmc3_4.cpp | 9 +++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0954b45..cdcbf0c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,7 @@ uint16_t emulator_tick(Bus* bus) { } int main() { - const std::string rom_path = "roms/SMB2.nes"; + const std::string rom_path = "roms/METROID.nes"; const std::string palette_path = "ntscpalette.pal"; Controller* const controller_1 = new Controller(); diff --git a/src/mapper_n_cart.cpp b/src/mapper_n_cart.cpp index efd3376..7632587 100644 --- a/src/mapper_n_cart.cpp +++ b/src/mapper_n_cart.cpp @@ -130,11 +130,11 @@ namespace roee_nes { } uint8_t Save_RAM::mapper_read(const uint16_t addr) { - return save_data[addr % 0x6000]; + return save_data[addr % 0x2000]; } void Save_RAM::mapper_write(const uint16_t addr, const uint8_t data) { - save_data[addr % 0x6000] = data; + save_data[addr % 0x2000] = data; } diff --git a/src/mappers/mmc1_1.cpp b/src/mappers/mmc1_1.cpp index 0343f07..6f4d159 100644 --- a/src/mappers/mmc1_1.cpp +++ b/src/mappers/mmc1_1.cpp @@ -28,6 +28,8 @@ namespace roee_nes { if (cart->header.flag_6.parsed.prg_ram == 1) save_ram = new Save_RAM(cart->rom_path + ".sav"); + else + save_ram = nullptr; } void MMC1_1::cpu_write(uint16_t addr, uint8_t data) { @@ -152,6 +154,7 @@ namespace roee_nes { } void MMC1_1::save() { - save_ram->~Save_RAM(); + if (save_ram != nullptr) + save_ram->~Save_RAM(); } } \ No newline at end of file diff --git a/src/mappers/mmc3_4.cpp b/src/mappers/mmc3_4.cpp index cb98c1d..a077e20 100644 --- a/src/mappers/mmc3_4.cpp +++ b/src/mappers/mmc3_4.cpp @@ -21,7 +21,11 @@ namespace roee_nes { chr_bank_num = (chr_read_mem->size() / (1 * KILOBYTE)) - 2; prg_bank_num = (cart->prg_rom.size() / (8 * KILOBYTE)); - save_ram = new Save_RAM(cart->rom_path + ".sav"); + if (cart->header.flag_6.parsed.prg_ram == 1) + save_ram = new Save_RAM(cart->rom_path + ".sav"); + else + save_ram = nullptr; + prg_bank[0] = 0; prg_bank[1] = 0; chr_bank[0] = 0; @@ -211,6 +215,7 @@ namespace roee_nes { } void MMC3_4::save() { - save_ram->~Save_RAM(); + if (save_ram != nullptr) + save_ram->~Save_RAM(); } } \ No newline at end of file