Skip to content

Commit

Permalink
Correct interpretation of the COLDATA register
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Nov 14, 2023
1 parent 9a1b374 commit a7083b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/snes/ppu/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
5 changes: 3 additions & 2 deletions src/snes/ppu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,7 +149,7 @@ pub struct PPU<TRenderer: Renderer> {
// Color math settings
cgwsel: u8,
cgadsub: u8,
coldata: u8,
coldata: SnesColor,
}

pub struct BgTile<'a> {
Expand Down Expand Up @@ -236,7 +237,7 @@ where

cgwsel: 0,
cgadsub: 0,
coldata: 0,
coldata: SnesColor::BLACK,
}
}

Expand Down

0 comments on commit a7083b8

Please sign in to comment.