feat(cartridge): handle MBC-less games like tetris
TODO: This will panic whenever a write is attempted on the MBC-less cartridge. This would be fine if games held the implicit rules given by the hardware, however this is not the case. We will have to modify the NoMBC implementation to ignore writes to the cartrige (while still documenting them just in case of bugs)
This commit is contained in:
parent
823e4b1e0a
commit
6db132ad48
|
@ -30,18 +30,20 @@ impl Cartridge {
|
||||||
let mbc_kind = Self::find_mbc(&memory);
|
let mbc_kind = Self::find_mbc(&memory);
|
||||||
let ram_byte_count = ram_size.to_byte_count();
|
let ram_byte_count = ram_size.to_byte_count();
|
||||||
|
|
||||||
let mbc = match mbc_kind {
|
match mbc_kind {
|
||||||
MbcKind::None => todo!("Handle no MBC Situation"),
|
MbcKind::None => Box::new(NoMbc {}),
|
||||||
MbcKind::MBC1 => Mbc1 {
|
MbcKind::Mbc1 => {
|
||||||
ram_size,
|
let mbc = Mbc1 {
|
||||||
ram: vec![0; ram_byte_count as usize],
|
ram_size,
|
||||||
bank_count,
|
ram: vec![0; ram_byte_count as usize],
|
||||||
..Default::default()
|
bank_count,
|
||||||
},
|
..Default::default()
|
||||||
MbcKind::MBC5 => todo!("Implement MBC5"),
|
};
|
||||||
};
|
|
||||||
|
|
||||||
Box::new(mbc)
|
Box::new(mbc)
|
||||||
|
}
|
||||||
|
MbcKind::Mbc5 => todo!("Implement MBC5"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_ram_size(memory: &[u8]) -> RamSize {
|
fn find_ram_size(memory: &[u8]) -> RamSize {
|
||||||
|
@ -60,8 +62,8 @@ impl Cartridge {
|
||||||
// TODO: Refactor this to match the other enums in this module
|
// TODO: Refactor this to match the other enums in this module
|
||||||
match id {
|
match id {
|
||||||
0x00 => MbcKind::None,
|
0x00 => MbcKind::None,
|
||||||
0x01 => MbcKind::MBC1,
|
0x01 => MbcKind::Mbc1,
|
||||||
0x19 => MbcKind::MBC5,
|
0x19 => MbcKind::Mbc5,
|
||||||
_ => unimplemented!("{} is the id of an unsupported memory bank controller", id),
|
_ => unimplemented!("{} is the id of an unsupported memory bank controller", id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,6 +213,18 @@ impl MemoryBankController for Mbc1 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
struct NoMbc {}
|
||||||
|
|
||||||
|
impl MemoryBankController for NoMbc {
|
||||||
|
fn handle_read(&self, addr: u16) -> MbcResult {
|
||||||
|
MbcResult::Address(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_write(&mut self, _addr: u16, _byte: u8) {
|
||||||
|
panic!("A MBC-less cartridge is read only")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
trait MemoryBankController: CloneMbc {
|
trait MemoryBankController: CloneMbc {
|
||||||
fn handle_read(&self, addr: u16) -> MbcResult;
|
fn handle_read(&self, addr: u16) -> MbcResult;
|
||||||
|
@ -238,8 +252,8 @@ enum MbcResult {
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum MbcKind {
|
enum MbcKind {
|
||||||
None,
|
None,
|
||||||
MBC1,
|
Mbc1,
|
||||||
MBC5,
|
Mbc5,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MbcKind {
|
impl Default for MbcKind {
|
||||||
|
|
Loading…
Reference in New Issue