-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0753603
commit 3e5baf3
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::mbc::mode::MBC; | ||
use crate::memory::Memory; | ||
|
||
pub struct MBC5 { | ||
rom: Vec<u8>, | ||
ram: Vec<u8>, | ||
ram_enabled: bool, | ||
rom_bank: usize, | ||
ram_bank: usize | ||
} | ||
|
||
impl Memory for MBC5 { | ||
fn read(&self, a: u16) -> u8 { | ||
match a { | ||
0x0000..=0x3FFF => self.rom[a as usize], | ||
0x4000..=0x7FFF => self.rom[a as usize + self.rom_bank * 0x4000 - 0x4000], | ||
0xA000..=0xBFFF => { | ||
if self.ram_enabled { | ||
self.ram[a as usize + self.ram_bank * 0x2000 - 0xA000] | ||
} else { | ||
0x00 | ||
} | ||
} | ||
_ => panic!("Read to unsupported MBC5 address ({:#06x})!", a), | ||
} | ||
} | ||
|
||
fn write(&mut self, a: u16, v: u8) { | ||
match a { | ||
0x0000..=0x1FFF => self.ram_enabled = v & 0x0F == 0x0A, | ||
0x2000..=0x2FFF => self.rom_bank = (self.rom_bank & 0x100) | (v as usize), | ||
0x3000..=0x3FFF => self.rom_bank = (self.rom_bank & 0x0ff) | (((v & 0x01) as usize) << 8), | ||
0x4000..=0x5FFF => self.ram_bank = (v & 0x0f) as usize, | ||
// Unknown writes | ||
0x6000..=0x7FFF => {}, | ||
0xA000..=0xBFFF => { | ||
if self.ram_enabled { | ||
self.ram[a as usize + self.ram_bank * 0x2000 - 0xA000] = v; | ||
} | ||
} | ||
_ => panic!("Write to unsupported MBC5 address ({:#06x})!", a), | ||
} | ||
} | ||
} | ||
|
||
impl MBC for MBC5 { } | ||
|
||
impl MBC5 { | ||
pub fn new(rom: Vec<u8>) -> Self { | ||
Self { | ||
rom, | ||
ram: vec![0x00; 131072], | ||
ram_enabled: false, | ||
rom_bank: 0x00, | ||
ram_bank: 0x00 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod mode; | ||
pub mod rom_only; | ||
pub mod mbc1; | ||
pub mod mbc3; | ||
pub mod mbc3; | ||
pub mod mbc5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters