From 2fd9cf1faa18404468d96a2f1dffb85e28176c56 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Tue, 28 Nov 2023 19:09:23 -0500 Subject: [PATCH] Start MMU --- src/main.rs | 1 + src/mmu.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/mmu.rs diff --git a/src/main.rs b/src/main.rs index 7cbcffa..a9628ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ use winit::{event_loop::EventLoop, window::WindowBuilder}; mod context; mod cpu; +mod mmu; mod mode; mod registers; diff --git a/src/mmu.rs b/src/mmu.rs new file mode 100644 index 0000000..10d302e --- /dev/null +++ b/src/mmu.rs @@ -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, + _ => {}, + } + } +} \ No newline at end of file