Skip to content

Commit

Permalink
Start MMU
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Nov 29, 2023
1 parent 2fc0ea0 commit 2fd9cf1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use winit::{event_loop::EventLoop, window::WindowBuilder};

mod context;
mod cpu;
mod mmu;
mod mode;
mod registers;

Expand Down
25 changes: 25 additions & 0 deletions src/mmu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pub struct MMU {
wram: [u8; 0x8000],
hram: [u8; 0x7f],
interrupt: u8,
}

impl MMU {
pub fn read(&self, a: u16) -> u8 {
match a {
0xC000..=0xCFFF => self.wram[a as usize - 0xC000],
0xFF80..=0xFFFE => self.hram[a as usize - 0xFF80],
0xFFFF => self.interrupt,
_ => 0x00,
}
}

pub fn write(&mut self, a: u16, v: u8) {
match a {
0xC000..=0xCFFF => self.wram[a as usize - 0xC000] = v,
0xFF80..=0xFFFE => self.hram[a as usize - 0xFF80] = v,
0xFFFF => self.interrupt = v,
_ => {},
}
}
}

0 comments on commit 2fd9cf1

Please sign in to comment.