Skip to content

Commit

Permalink
Implement mode 3, 4 direct color
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Apr 17, 2024
1 parent ce4a0cb commit 1e01f47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/snes/ppu/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ enum WindowMask {
}

impl PPUState {
#[inline(always)]
/// Maps direct color value to on-screen color
fn directcolor(dc: u8, palette: u8) -> SnesColor {
SnesColor::from_rgb5(
((dc & 7) << 2) | ((palette & 1) << 1),
(((dc >> 3) & 7) << 2) | (palette & 2),
(((dc >> 6) & 3) << 3) | (palette & 4),
)
}
#[inline(always)]
pub fn cgram_to_color(&self, addr: u8) -> SnesColor {
SnesColor::from(self.cgram[addr as usize])
Expand All @@ -89,7 +98,11 @@ impl PPUState {
BPP::Four => paletteidx * 16,
BPP::Eight => 0,
};
self.cgram_to_color(palette + idx)
if self.cgwsel & (1 << 0) != 0 && self.get_layer_bpp(bg) == BPP::Eight {
Self::directcolor(idx, palette)
} else {
self.cgram_to_color(palette + idx)
}
}

fn sprite_cindex_to_color(&self, tile: &SpriteTile, idx: u8) -> SnesColor {
Expand Down
2 changes: 1 addition & 1 deletion src/snes/ppu/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl OptEntry {
}
}

#[derive(Clone, Copy, Debug, ToPrimitive)]
#[derive(Clone, Copy, Debug, ToPrimitive, Eq, PartialEq)]
pub enum BPP {
// BPP == number of bitplanes
Two = 2, // 4 colors
Expand Down

0 comments on commit 1e01f47

Please sign in to comment.