From ea70b592ce00193dabd55b1bc7a903949930b7a3 Mon Sep 17 00:00:00 2001 From: Theron Spiegl Date: Sun, 19 Jan 2020 11:30:51 -0600 Subject: [PATCH] put chr-ram back in mmc1 --- src/cartridge/mmc1.rs | 32 ++++++++++++++++++-------------- src/cpu/mod.rs | 1 - 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/cartridge/mmc1.rs b/src/cartridge/mmc1.rs index cbb07c0..3d7c936 100644 --- a/src/cartridge/mmc1.rs +++ b/src/cartridge/mmc1.rs @@ -114,21 +114,25 @@ impl Mapper for Mmc1 { fn read(&mut self, address: usize) -> u8 { match address { 0x0000..=0x1FFF => { - let offset = address % 0x1000; - if self.chr_bank_mode { - // if 4K bank mode, $0000-$0FFF will be a 4K-indexed section of some CHR-ROM chunk referred to by chr_low_bank - // and $1000-$1FFF will be the one referred to by chr_high_bank - let bank = match address { - 0x0000..=0x0FFF => self.chr_low_bank, - 0x1000..=0x1FFF => self.chr_high_bank, - _ => panic!("bad address read from MMC1: 0x{:X}", address), - }; - let chunk_num = bank / 2; - let chunk_half = if bank % 2 == 0 {0x0} else {0x1000}; - self.cart.chr_rom[chunk_num][chunk_half + offset] + if self.cart.chr_rom_size == 0 { + self.chr_ram_bank[address] } else { - // if we're in 8K bank mode, the whole $0000-$1FFF region will be the 8K range referred to by chr_low_bank - self.cart.chr_rom[self.chr_low_bank][address] + let offset = address % 0x1000; + if self.chr_bank_mode { + // if 4K bank mode, $0000-$0FFF will be a 4K-indexed section of some CHR-ROM chunk referred to by chr_low_bank + // and $1000-$1FFF will be the one referred to by chr_high_bank + let bank = match address { + 0x0000..=0x0FFF => self.chr_low_bank, + 0x1000..=0x1FFF => self.chr_high_bank, + _ => panic!("bad address read from MMC1: 0x{:X}", address), + }; + let chunk_num = bank / 2; + let chunk_half = if bank % 2 == 0 {0x0} else {0x1000}; + self.cart.chr_rom[chunk_num][chunk_half + offset] + } else { + // if we're in 8K bank mode, the whole $0000-$1FFF region will be the 8K range referred to by chr_low_bank + self.cart.chr_rom[self.chr_low_bank][address] + } } }, 0x6000..=0x7FFF => self.prg_ram_bank[address % 0x2000], diff --git a/src/cpu/mod.rs b/src/cpu/mod.rs index 3e9a3a8..42d6203 100644 --- a/src/cpu/mod.rs +++ b/src/cpu/mod.rs @@ -156,7 +156,6 @@ impl Cpu { self.apu.trigger_irq = false; // and mapper MMC3 if self.mapper.borrow_mut().check_irq() && (self.P & INTERRUPT_DISABLE_FLAG == 0) { - // println!("firing IRQ from mapper"); self.irq(); }