diff --git a/src/snes/ppu/bus.rs b/src/snes/ppu/bus.rs index 99b2668..f0a7dca 100644 --- a/src/snes/ppu/bus.rs +++ b/src/snes/ppu/bus.rs @@ -255,7 +255,18 @@ where // CGADSUB - Color Math Control Register B (W) 0x2131 => Some(self.cgadsub = val), // COLDATA - Color Math Sub Screen Backdrop Color (W) - 0x2132 => Some(self.coldata = val), + 0x2132 => { + if val & (1 << 5) != 0 { + self.coldata = self.coldata.with_r(val & 0x1F); + } + if val & (1 << 6) != 0 { + self.coldata = self.coldata.with_g(val & 0x1F); + } + if val & (1 << 7) != 0 { + self.coldata = self.coldata.with_b(val & 0x1F); + } + Some(()) + } // RDCGRAM - Palette CGRAM Data Read 0x213B => None, diff --git a/src/snes/ppu/mod.rs b/src/snes/ppu/mod.rs index dfc6710..1b2e84a 100644 --- a/src/snes/ppu/mod.rs +++ b/src/snes/ppu/mod.rs @@ -16,6 +16,7 @@ use num_traits::{FromPrimitive, ToPrimitive}; use crate::frontend::Renderer; use crate::tickable::{Tickable, Ticks}; +use color::SnesColor; use tile::{Tile, TILE_HEIGHT, TILE_WIDTH}; pub const SCREEN_WIDTH: usize = 8 * 32; @@ -148,7 +149,7 @@ pub struct PPU { // Color math settings cgwsel: u8, cgadsub: u8, - coldata: u8, + coldata: SnesColor, } pub struct BgTile<'a> { @@ -236,7 +237,7 @@ where cgwsel: 0, cgadsub: 0, - coldata: 0, + coldata: SnesColor::BLACK, } }