From d4b5bac4752edfac936a192272adda9ce5256462 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Mon, 6 May 2024 20:46:31 -0400 Subject: [PATCH] Clear VRAM after Boot ROM Fixes blank areas in some CGB Games --- src/components/mmu.rs | 5 ++++- src/components/ppu/ppu.rs | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/mmu.rs b/src/components/mmu.rs index 7050bb1..5fe9808 100644 --- a/src/components/mmu.rs +++ b/src/components/mmu.rs @@ -167,7 +167,10 @@ impl Memory for MMU { 0xFF04..=0xFF07 => self.timer.write(a, v), 0xFF10..=0xFF3F => self.apu.write(a, v), 0xFF0F => self.intf = Interrupts::from_bits_truncate(v), - 0xFF50 => self.boot_rom_enabled = false, + 0xFF50 => { + self.boot_rom_enabled = false; + self.ppu.clear_vram(); + }, // TODO: RP 0xFF56 => { }, 0xFF51..=0xFF6F => self.ppu.write(a, v), diff --git a/src/components/ppu/ppu.rs b/src/components/ppu/ppu.rs index a61db2a..b173cef 100644 --- a/src/components/ppu/ppu.rs +++ b/src/components/ppu/ppu.rs @@ -445,6 +445,10 @@ impl PPU { } } + pub fn clear_vram(&mut self) { + self.vram = [0; 0x4000]; + } + fn read_vram(&self, a: u16, bank: usize) -> u8 { self.vram[(bank * 0x2000) + a as usize - 0x8000] }