Skip to content

Commit

Permalink
Implement force blank and master brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Nov 9, 2023
1 parent 20b5ea0 commit a780e4b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/snes/ppu/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ where
match bank {
// System area
0x00..=0x3F | 0x80..=0xBF => match addr {
// INIDISP - Display Control 1 (W)
0x2100 => Some(self.inidisp = val),
// OBSEL - Object Size and Object Base
0x2101 => {
println!("OBSEL = {}", val);
Some(self.obsel = val)
}
0x2101 => Some(self.obsel = val),
// OAMADDL - OAM Address and Priority Rotation (W)
0x2102 => {
let v = self.oamadd.get() & 0xFF00;
Expand Down
4 changes: 4 additions & 0 deletions src/snes/ppu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub struct PPU<TRenderer: Renderer> {
oamadd: Cell<u16>,
oam: [u8; OAM_SIZE],
oam_writebuf: u8,

inidisp: u8,
}

#[derive(Debug)]
Expand Down Expand Up @@ -196,6 +198,8 @@ where
oamadd: Cell::new(0),
oam: [0; OAM_SIZE],
oam_writebuf: 0,

inidisp: 0,
}
}

Expand Down
21 changes: 20 additions & 1 deletion src/snes/ppu/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@ where
{
fn cgram_to_color(&self, addr: u8) -> Color {
let entry = self.cgram[addr as usize];
(

if self.inidisp & 0x80 != 0 {
// Force blank
return (0, 0, 0);
}

let (r, g, b) = (
(((entry >> 0) & 0x1F) as u8) << 3, // Red, 5-bit
(((entry >> 5) & 0x1F) as u8) << 3, // Green, 5-bit
(((entry >> 10) & 0x1F) as u8) << 3, // Blue, 5-bit
);

// Apply master brightness
let brightness = f32::from(self.inidisp & 0x0F) / 15.0_f32;

(
(f32::from(r) * brightness).to_u8().unwrap(),
(f32::from(g) * brightness).to_u8().unwrap(),
(f32::from(b) * brightness).to_u8().unwrap(),
)
}

Expand Down Expand Up @@ -72,6 +87,10 @@ where
line_paletted: &mut [Color],
priority: u8,
) {
if (self.tm | self.ts) & (1 << 4) == 0 {
return;
}

for idx in 0..OAM_ENTRIES {
let e = self.get_oam_entry(idx);

Expand Down

0 comments on commit a780e4b

Please sign in to comment.