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,
|
|
|
|
}
|
|
|
|
|
2020-01-10 04:04:10 +00:00
|
|
|
impl Nrom {
|
|
|
|
pub fn new(cart: Cartridge) -> Self {
|
|
|
|
Nrom{
|
|
|
|
cart: cart,
|
|
|
|
}
|
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 cl = self.cart.chr_rom.len();
|
|
|
|
let pl = self.cart.prg_rom.len();
|
|
|
|
let addr = address % 0x4000;
|
|
|
|
match address {
|
|
|
|
0x0000..=0x1FFF => {
|
|
|
|
if cl > 0 {
|
|
|
|
self.cart.chr_rom[cl-1][address]
|
|
|
|
} else {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
0x8000..=0xBFFF => {
|
|
|
|
self.cart.prg_rom[0][addr]
|
|
|
|
},
|
|
|
|
0xC000..=0xFFFF => {
|
|
|
|
self.cart.prg_rom[pl-1][addr]
|
|
|
|
},
|
|
|
|
_ => panic!("bad address sent to NROM mapper: 0x{:X}", address),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn write(&mut self, address: usize, value: u8) {
|
|
|
|
let cl = self.cart.chr_rom.len();
|
|
|
|
let pl = self.cart.prg_rom.len();
|
|
|
|
let addr = address % 0x4000;
|
|
|
|
match address {
|
|
|
|
0x0000..=0x1FFF => {
|
|
|
|
if cl > 0 {
|
|
|
|
self.cart.chr_rom[cl-1][address] = value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
0x8000..=0xBFFF => {
|
|
|
|
self.cart.prg_rom[0][addr] = value;
|
|
|
|
},
|
|
|
|
0xC000..=0xFFFF => {
|
|
|
|
self.cart.prg_rom[pl-1][addr] = value;
|
|
|
|
},
|
|
|
|
_ => panic!("bad address sent to NROM mapper: 0x{:X}", address),
|
|
|
|
}
|
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
|
|
|
}
|
2020-01-15 02:51:59 +00:00
|
|
|
|
|
|
|
fn load_battery_backed_ram(&mut self) {}
|
|
|
|
fn save_battery_backed_ram(&self) {}
|
2019-11-12 00:04:07 +00:00
|
|
|
}
|