gb-emu/lib/src/processor/memory/rom/mbcs.rs

64 lines
1.4 KiB
Rust
Raw Normal View History

2023-02-07 10:08:34 +11:00
use crate::processor::memory::Address;
2023-02-22 21:58:47 +11:00
mod mbc1;
2023-03-02 18:53:26 +11:00
mod mbc2;
2023-02-27 09:37:46 +11:00
mod mbc3;
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-03-02 18:53:26 +11:00
pub use mbc2::Mbc2;
2023-02-27 09:37:46 +11:00
pub use mbc3::Mbc3;
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-03-02 20:07:48 +11:00
pub(super) const KB: usize = 1024;
2023-02-23 11:00:29 +11:00
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-27 10:00:12 +11:00
fn is_rumbling(&self) -> bool {
false
}
fn can_rumble(&self) -> bool {
false
}
2023-03-02 11:29:54 +11:00
fn flush(&mut self) {}
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"),
}
}