2023-02-07 10:08:34 +11:00
|
|
|
use crate::processor::memory::Address;
|
|
|
|
|
2023-02-22 21:58:47 +11:00
|
|
|
mod mbc1;
|
2023-02-23 11:00:29 +11:00
|
|
|
mod mbc5;
|
2023-02-22 21:58:47 +11:00
|
|
|
mod none;
|
|
|
|
pub use mbc1::Mbc1;
|
2023-02-23 11:00:29 +11:00
|
|
|
pub use mbc5::Mbc5;
|
2023-02-22 21:58:47 +11:00
|
|
|
pub use none::None;
|
|
|
|
|
2023-02-23 11:00:29 +11:00
|
|
|
const KB: usize = 1024;
|
|
|
|
const ROM_BANK_SIZE: usize = 16 * KB;
|
|
|
|
const RAM_BANK_SIZE: usize = 8 * KB;
|
|
|
|
|
2023-02-12 09:46:47 +11:00
|
|
|
pub(super) trait Mbc {
|
2023-02-23 11:00:29 +11:00
|
|
|
// addresses 0x0000 - 0x7FFF
|
2023-02-07 10:08:34 +11:00
|
|
|
fn get(&self, address: Address) -> u8;
|
2023-02-23 11:00:29 +11:00
|
|
|
// addresses 0xA000 - 0xBFFF
|
2023-02-11 21:43:36 +11:00
|
|
|
fn get_ram(&self, address: Address) -> u8;
|
2023-02-07 10:08:34 +11:00
|
|
|
fn set(&mut self, address: Address, data: u8);
|
2023-02-11 21:43:36 +11:00
|
|
|
fn set_ram(&mut self, address: Address, data: u8);
|
2023-02-12 17:21:24 +11:00
|
|
|
fn mbc_type(&self) -> String;
|
2023-02-07 10:08:34 +11:00
|
|
|
}
|
2023-02-23 11:00:29 +11:00
|
|
|
|
|
|
|
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<usize> {
|
|
|
|
match ram_size {
|
|
|
|
0x00 => None,
|
|
|
|
0x01 => Some(2),
|
|
|
|
0x02 => Some(8),
|
|
|
|
0x03 => Some(32),
|
|
|
|
0x04 => Some(128),
|
|
|
|
0x05 => Some(64),
|
|
|
|
_ => panic!("unacceptable ram size"),
|
|
|
|
}
|
|
|
|
}
|