Skip to content

Commit

Permalink
PPU: fix force blank/zero brightness only applied to half the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed May 18, 2024
1 parent 066d1cf commit a52bc49
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/snes/ppu/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use arrayvec::ArrayVec;
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;

use std::iter;

const LAYER_BACKDROP: u8 = 255;
const LAYER_SPRITES: u8 = 4;
pub struct RenderState {
Expand Down Expand Up @@ -501,6 +503,17 @@ impl PPUState {
scanline_bg: usize,
scanline_sprites: usize,
) -> ArrayVec<Color, SCREEN_WIDTH> {
let brightness = (self.inidisp & 0x0F) as usize;
let scale = self.get_screen_mode_scale_bg();
let mut out: ArrayVec<Color, SCREEN_WIDTH> = ArrayVec::new();

if brightness == 0 || self.inidisp & 0x80 != 0 {
// Force blank or no brightness
return ArrayVec::from_iter(
iter::repeat(SnesColor::BLACK.to_native()).take(SCREEN_WIDTH),
);
}

let windows = self.render_windows();
let mainscreen = self.render_scanline_screen(
scanline_bg,
Expand All @@ -526,17 +539,7 @@ impl PPUState {
);

// Send line to screen buffer
let scale = self.get_screen_mode_scale_bg();
let brightness = (self.inidisp & 0x0F) as usize;

let mut out: ArrayVec<Color, SCREEN_WIDTH> = ArrayVec::new();
for x in 0..(SCREEN_WIDTH / scale) {
if brightness == 0 || self.inidisp & 0x80 != 0 {
// Force blank or no brightness
out.push(SnesColor::BLACK.to_native());
continue;
}

let pixel = if self.in_highres_h() {
// Mode 5/6 do not support color math
mainscreen.paletted[x]
Expand Down

0 comments on commit a52bc49

Please sign in to comment.