diff --git a/src/bus.rs b/src/bus.rs index 596cda8..9dff821 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -1,10 +1,12 @@ -use super::cartridge::Cartridge; +use crate::ppu; +use super::cartridge::Cartridge; +use super::ppu::PPU; #[derive(Debug, Clone)] pub struct Bus { boot: Option<[u8; 256]>, // Boot ROM is 256b long cartridge: Option, - vram: [u8; 8192], // 8KB of VRAM + ppu: PPU } impl Default for Bus { @@ -12,7 +14,7 @@ impl Default for Bus { Self { boot: Some(include_bytes!("../bin/DMG_ROM.bin").to_owned()), cartridge: None, - vram: [0; 8192], + ppu: Default::default(), } } } @@ -56,7 +58,7 @@ impl Bus { }, 0x8000..=0x9FFF => { // 8KB Video RAM - self.vram[(addr - 0x8000) as usize] + self.ppu.vram[(addr - 0x8000) as usize] } 0xA000..=0xBFFF => { // 8KB External RAM @@ -106,7 +108,7 @@ impl Bus { } 0x8000..=0x9FFF => { // 8KB Video RAM - self.vram[(addr - 0x8000) as usize] = byte; + self.ppu.vram[(addr - 0x8000) as usize] = byte; } 0xA000..=0xBFFF => { // 8KB External RAM @@ -168,8 +170,8 @@ impl Bus { }, 0x8000..=0x9FFF => { // 8KB Video RAM - (self.vram[((addr + 1) - 0x8000) as usize] as u16) << 8 - | self.vram[(addr - 0x8000) as usize] as u16 + (self.ppu.vram[((addr + 1) - 0x8000) as usize] as u16) << 8 + | self.ppu.vram[(addr - 0x8000) as usize] as u16 } 0xA000..=0xBFFF => { // 8KB External RAM diff --git a/src/ppu.rs b/src/ppu.rs index 5bd1076..8319aea 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -1,7 +1,19 @@ -struct PPU { +#[derive(Debug, Clone)] +pub struct PPU { lcdc: LCDControl, + pub vram: [u8; 8192], } +impl Default for PPU { + fn default() -> Self { + Self { + lcdc: Default::default(), + vram: [0; 8192], + } + } +} + +#[derive(Debug,Default, Clone, Copy)] struct LCDControl { lcd_enable: bool, // Bit 7 window_tile_map_select: bool,