-
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
2241ae2
commit 5b234ef
Showing
6 changed files
with
75 additions
and
14 deletions.
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
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,22 @@ | ||
/// Memory controller 0. No memory controller | ||
use crate::memory::GBAddress; | ||
use crate::memory::MemoryController; | ||
|
||
pub struct Mbc0 {} | ||
|
||
impl Mbc0 { | ||
pub fn new() -> Mbc0 { | ||
Mbc0 {} | ||
} | ||
} | ||
|
||
impl MemoryController for Mbc0 { | ||
fn write(&mut self, address: GBAddress, value: u8, cartridge: &mut Vec<u8>) { | ||
cartridge[address as usize] = value | ||
} | ||
|
||
fn read(&self, address: GBAddress, cartridge: &Vec<u8>) -> u8 { | ||
dbg!(cartridge); | ||
cartridge[address as usize] | ||
} | ||
} |
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,12 +1,29 @@ | ||
struct Mbc1 {} | ||
use crate::memory::GBAddress; | ||
use crate::memory::MemoryController; | ||
|
||
impl MemoryController for Mbc1 { | ||
fn write(&mut self, _address: GBAddress, value: u8) { | ||
pub struct Mbc1 {} | ||
|
||
impl Mbc1 { | ||
pub fn new() -> Mbc1 { | ||
Mbc1 {} | ||
} | ||
} | ||
|
||
fn read(&self, _address: GBAdress) -> u8 { | ||
impl MemoryController for Mbc1 { | ||
fn write(&mut self, address: GBAddress, value: u8, cartridge: &mut Vec<u8>) { | ||
if 0x0000 <= address && address <= 0x1fff { | ||
if value & 0xF == 0xA { | ||
// ram enable | ||
} else { | ||
// ram disable | ||
} | ||
} else if 0x2000 <= address && address <= 0x3fff { | ||
let rom_select = value & 0x1F; | ||
} else if 0x4000 <= address && address <= 0x5fff { | ||
} | ||
} | ||
|
||
fn read(&self, _address: GBAddress, cartridge: &Vec<u8>) -> u8 { | ||
0 | ||
} | ||
} | ||
|
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
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,6 @@ | ||
trait MemoryController { | ||
fn write(&mut self, address: GBAddress, value: u8); | ||
fn read(&self, address: GBAddress) -> u8; | ||
} | ||
use crate::memory::GBAddress; | ||
|
||
pub trait MemoryController { | ||
fn write(&mut self, address: GBAddress, value: u8, cartridge: &mut Vec<u8>); | ||
fn read(&self, address: GBAddress, cartridge: &Vec<u8>) -> u8; | ||
} |
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,3 +1,9 @@ | ||
mod mbc0; | ||
mod mbc1; | ||
mod memory; | ||
mod memory_controller; | ||
|
||
pub use memory::Bus; | ||
pub use mbc0::Mbc0; | ||
pub use mbc1::Mbc1; | ||
pub use memory::{Bus, GBAddress}; | ||
pub use memory_controller::MemoryController; |