Skip to content

Commit

Permalink
Implemented the greyscale PPU mask (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
zer0x64 authored Jul 19, 2021
1 parent d387927 commit 6801c4c
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions nestadia/src/ppu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,18 @@ impl Ppu {

// Palette table:
0x3F00..=0x3FFF => {
if read_addr & 0b11 == 0 {
let color = if read_addr & 0b11 == 0 {
// Mirror to the universal background color
self.palette_table[usize::from(read_addr & 0x0f)]
} else {
self.palette_table[usize::from(read_addr & 0x1f)]
};

// Apply greyscale to reads
if self.mask_reg.contains(registers::MaskReg::GREYSCALE) {
color & 0x30
} else {
color
}
}

Expand Down Expand Up @@ -495,6 +502,12 @@ impl Ppu {
}

fn set_pixel(&mut self, x: u16, y: u16, color: u8) {
let color = if self.mask_reg.contains(registers::MaskReg::GREYSCALE) {
color & 0x30
} else {
color
};

let idx = y as usize * FRAME_WIDTH + x as usize;
if idx < self.frame.len() {
self.frame[idx] = color;
Expand Down Expand Up @@ -796,13 +809,18 @@ impl Ppu {
self.secondary_oam[((sprite_idx << 2) | sprite_cycle) as usize];
}
3 => {
let y = (self.scanline as u16).wrapping_sub(self.oam_temp_y_buffer as u16);

let x = self.secondary_oam[((sprite_idx << 2) | sprite_cycle) as usize];

self.sprites_x_counter[sprite_idx as usize] = if x == 0 {
SpriteXCounter::Rendering(0)
} else {
SpriteXCounter::NotRendered(x)
};
self.sprites_x_counter[sprite_idx as usize] =
if y >= (self.ctrl_reg.sprite_size() as u16) {
SpriteXCounter::WontRender
} else if x == 0 {
SpriteXCounter::Rendering(0)
} else {
SpriteXCounter::NotRendered(x)
};
}
5 => {
let y = (self.scanline as u16).wrapping_sub(self.oam_temp_y_buffer as u16);
Expand Down

0 comments on commit 6801c4c

Please sign in to comment.