nesfuzz/src/cartridge/nrom.rs

61 lines
1.6 KiB
Rust
Raw Normal View History

2020-01-10 04:04:10 +00:00
use super::{Cartridge, Mapper, Mirror};
2020-01-10 02:26:45 +00:00
pub struct Nrom {
cart: Cartridge,
chr_ram: Vec<u8>,
2020-01-10 02:26:45 +00:00
}
2020-01-10 04:04:10 +00:00
impl Nrom {
pub fn new(cart: Cartridge) -> Self {
Nrom{
cart: cart,
chr_ram: vec![0; 0x2000],
2020-01-10 04:04:10 +00:00
}
2019-11-12 00:04:07 +00:00
}
}
2020-01-10 04:04:10 +00:00
impl Mapper for Nrom {
fn read(&mut self, address: usize) -> u8 {
let addr = address % 0x4000;
match address {
0x0000..=0x1FFF => {
if self.cart.chr_rom_size > 0 {
self.cart.chr_rom[0][address]
2020-01-10 04:04:10 +00:00
} else {
self.chr_ram[address]
2020-01-10 04:04:10 +00:00
}
},
0x8000..=0xBFFF => {
self.cart.prg_rom[0][addr]
},
0xC000..=0xFFFF => {
self.cart.prg_rom[self.cart.prg_rom_size - 1][addr]
2020-01-10 04:04:10 +00:00
},
_ => {println!("bad address read from NROM mapper: 0x{:X}", address); 0},
2020-01-10 04:04:10 +00:00
}
}
fn write(&mut self, address: usize, value: u8) {
match address {
0x0000..=0x1FFF => {
// ROM isn't written to
if self.cart.chr_rom_size == 0 {
self.chr_ram[address] = value;
2020-01-10 04:04:10 +00:00
}
},
0x8000..=0xBFFF => (),
0xC000..=0xFFFF => (),
_ => println!("bad address written to NROM mapper: 0x{:X}", address),
2020-01-10 04:04:10 +00:00
}
2019-11-12 00:04:07 +00:00
}
2020-01-10 04:04:10 +00:00
fn get_mirroring(&mut self) -> Mirror {
self.cart.mirroring
2019-11-12 00:04:07 +00:00
}
fn load_battery_backed_ram(&mut self) {}
fn save_battery_backed_ram(&self) {}
2020-01-17 02:57:17 +00:00
fn clock(&mut self) {}
fn check_irq(&mut self) -> bool {false}
2019-11-12 00:04:07 +00:00
}