use crate::processor::memory::Address; mod mbc1; mod mbc2; mod mbc3; mod mbc5; mod none; pub use mbc1::Mbc1; pub use mbc2::Mbc2; pub use mbc3::Mbc3; pub use mbc5::Mbc5; pub use none::None; pub(super) const KB: usize = 1024; const ROM_BANK_SIZE: usize = 16 * KB; const RAM_BANK_SIZE: usize = 8 * KB; pub(super) trait Mbc: Send + Sync { // addresses 0x0000 - 0x7FFF fn get(&self, address: Address) -> u8; // addresses 0xA000 - 0xBFFF fn get_ram(&self, address: Address) -> u8; fn set(&mut self, address: Address, data: u8); fn set_ram(&mut self, address: Address, data: u8); fn mbc_type(&self) -> String; fn is_rumbling(&self) -> bool { false } fn can_rumble(&self) -> bool { false } fn flush(&mut self) {} } fn rom_banks(rom_size: u8) -> usize { match rom_size { 0x00 => 2, 0x01 => 4, 0x02 => 8, 0x03 => 16, 0x04 => 32, 0x05 => 64, 0x06 => 128, 0x07 => 256, 0x08 => 512, 0x52 => 72, 0x53 => 80, 0x54 => 96, _ => panic!("unacceptable rom size"), } } fn ram_size_kb(ram_size: u8) -> Option { match ram_size { 0x00 => None, 0x01 => Some(2), 0x02 => Some(8), 0x03 => Some(32), 0x04 => Some(128), 0x05 => Some(64), _ => panic!("unacceptable ram size"), } }