Skip to content

Commit

Permalink
Block VRAM/OAM R/W in certain modes
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Jan 4, 2024
1 parent 24100df commit 7d1dd3c
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,20 @@ impl PPU {
impl Memory for PPU {
fn read(&self, a: u16) -> u8 {
match a {
0x8000..=0x9FFF => self.ram[self.ram_bank * 0x2000 + a as usize - 0x8000],
0xFE00..=0xFE9F => self.oam[a as usize - 0xFE00],
0x8000..=0x9FFF => {
if self.ppu_mode != PPUMode::Draw {
self.ram[self.ram_bank * 0x2000 + a as usize - 0x8000]
} else {
0xFF
}
},
0xFE00..=0xFE9F => {
if self.ppu_mode != PPUMode::Draw && self.ppu_mode != PPUMode::OAMScan {
self.oam[a as usize - 0xFE00]
} else {
0xFF
}
},
0xFF40 => self.lcdc.bits(),
0xFF41 => {
let mut lcds = self.lcds;
Expand All @@ -454,8 +466,16 @@ impl Memory for PPU {

fn write(&mut self, a: u16, v: u8) {
match a {
0x8000..=0x9FFF => self.ram[self.ram_bank * 0x2000 + a as usize - 0x8000] = v,
0xFE00..=0xFE9F => self.oam[a as usize - 0xFE00] = v,
0x8000..=0x9FFF => {
if self.ppu_mode != PPUMode::Draw {
self.ram[self.ram_bank * 0x2000 + a as usize - 0x8000] = v
}
},
0xFE00..=0xFE9F => {
if self.ppu_mode != PPUMode::Draw && self.ppu_mode != PPUMode::OAMScan {
self.oam[a as usize - 0xFE00] = v
}
},
0xFF40 => {
self.lcdc = LCDC::from_bits(v).unwrap();
if !self.lcdc.contains(LCDC::LCD_ENABLE) {
Expand Down

0 comments on commit 7d1dd3c

Please sign in to comment.