Skip to content

Commit

Permalink
fixed some MMC3 open bus error
Browse files Browse the repository at this point in the history
just returned 0 instead of open bus
  • Loading branch information
Roeegg2 committed Mar 22, 2024
1 parent 3d3f332 commit 5c3e525
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace roee_nes {
this->controller_1 = controller_1;
this->controller_2 = controller_2;
init_palette(palette_path);

cpu->bus = this;
ppu->bus = this;

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uint16_t emulator_tick(Bus* bus) {
}

int main() {
const std::string rom_path = "roms/METROID.nes";
const std::string rom_path = "roms/SMB2.nes";
const std::string palette_path = "ntscpalette.pal";

Controller* const controller_1 = new Controller();
Expand Down
8 changes: 4 additions & 4 deletions src/mapper_n_cart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ namespace roee_nes {
return; // do nothing!
}

Save_RAM::Save_RAM(const std::string& save_file_path)
: save_data({ 0 }), path(save_file_path){
Save_RAM::Save_RAM(const std::string& save_file_path)
: save_data({ 0 }), path(save_file_path) {
if (std::filesystem::exists(path)) {
std::cout << "USER INFO: Save game data found. Reading from save data\n";

Expand All @@ -130,11 +130,11 @@ namespace roee_nes {
}

uint8_t Save_RAM::mapper_read(const uint16_t addr) {
return save_data[addr % 0x2000];
return save_data[addr % 0x6000];
}

void Save_RAM::mapper_write(const uint16_t addr, const uint8_t data) {
save_data[addr % 0x2000] = data;
save_data[addr % 0x6000] = data;
}


Expand Down
22 changes: 10 additions & 12 deletions src/mappers/mmc3_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ namespace roee_nes {
chr_bank_num = (chr_read_mem->size() / (1 * KILOBYTE)) - 2;
prg_bank_num = (cart->prg_rom.size() / (8 * KILOBYTE));

if (cart->header.flag_6.parsed.prg_ram == 1)
if (cart->header.flag_6.parsed.prg_ram == 1) {
std::cout << "USER INFO: Game has PRG RAM\n";
save_ram = new Save_RAM(cart->rom_path + ".sav");
else
} else {
save_ram = nullptr;
}

prg_bank[0] = 0;
prg_bank[1] = 0;
Expand All @@ -38,7 +40,8 @@ namespace roee_nes {

void MMC3_4::cpu_write(uint16_t addr, uint8_t data) {
if ((0x6000 <= addr) && (addr <= 0x7fff)) {
save_ram->mapper_write(addr, data);
if (save_ram != nullptr)
save_ram->mapper_write(addr, data);
} else if ((0x8000 <= addr) && (addr <= 0x9ffe)) {
if ((addr % 2) == 0) { // write to low reg
bank_select.comp.even.select = data & 0b0000'0111;
Expand Down Expand Up @@ -114,18 +117,13 @@ namespace roee_nes {
// << " irq reload: " << (int)irq_reload << " \n"
// << " set irq: " << (int)set_irq << " \n"
// << "-------------------\n";
if ((0x6000 <= addr) && (addr <= 0x7fff)) {
return save_ram->mapper_read(addr);
} else if ((0x6000 <= addr) && (addr <= 0x7fff)) {
if ((prg_ram_protect & 0b1000'0000) == 0)
return open_bus_data;
else
return save_data[addr % 0x6000]; // handle prg_ram
if ((0x6000 <= addr) && (addr <= 0x7fff) && (!(prg_ram_protect & 0b1000'0000)) && (save_ram != nullptr)) {
return save_data[addr % 0x6000]; // handle prg_ram
} else if ((0x8000 <= addr) && (addr <= 0xffff)) {
update_prg(addr);
return cart->prg_rom[(final_bank * 8 * KILOBYTE) + final_addr];
} else {
return open_bus_data;
} else { // otherwise return open bus
return 0; // should return open bus but fuck it, no MMC3 game uses this anyway
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ppu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ namespace roee_nes {
vblank_scanline();

if ((bus->mapper->mapper_number == 4)
// && (!checked)
&& (!checked)
)
((MMC3_4*)bus->mapper)->clock_irq();
check_mmc3_irq_conditions();

increment_cycle(1);
}
Expand Down

0 comments on commit 5c3e525

Please sign in to comment.