Skip to content

Commit

Permalink
Shift the entire screen up by one scanline
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Nov 29, 2023
1 parent b3ab5ee commit 6f2bde7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/snes/ppu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ use tile::{Tile, TILE_HEIGHT, TILE_WIDTH};
pub const SCREEN_WIDTH: usize = 8 * 32;
pub const SCREEN_HEIGHT: usize = 8 * 28;

// The entire screen should be shifted up by 1 scanline
const SCANLINE_OUTPUT_OFFSET: isize = -1;

type VramWord = u16;
const VRAM_WORDS: usize = 32 * 1024;
const VRAM_WORDSIZE: usize = 2;
Expand Down Expand Up @@ -467,8 +470,11 @@ where
}
} else {
self.vblank = false;
if self.last_scanline < SCREEN_HEIGHT {
self.render_scanline(self.last_scanline);
if (self.last_scanline as isize)
< ((SCREEN_HEIGHT as isize) - SCANLINE_OUTPUT_OFFSET)
&& (self.last_scanline as isize) + SCANLINE_OUTPUT_OFFSET >= 0
{
self.render_scanline(self.last_scanline, SCANLINE_OUTPUT_OFFSET);
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/snes/ppu/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ where
state
}

pub fn render_scanline(&mut self, scanline: usize) {
pub fn render_scanline(&mut self, scanline: usize, output_offset: isize) {
let windows = self.render_windows();
let mainscreen = self.render_scanline_screen(
scanline,
Expand All @@ -299,12 +299,13 @@ where
);

// Send line to screen buffer
let output_line = usize::try_from((scanline as isize) + output_offset).unwrap();
let brightness = (self.inidisp & 0x0F) as usize;
for x in 0..mainscreen.paletted.len() {
if brightness == 0 || self.inidisp & 0x80 != 0 {
// Force blank or no brightness
self.renderer
.set_pixel(x, scanline, SnesColor::BLACK.to_native());
.set_pixel(x, output_line, SnesColor::BLACK.to_native());
continue;
}

Expand All @@ -318,8 +319,11 @@ where
);

// Apply master brightness and output
self.renderer
.set_pixel(x, scanline, pixel.apply_brightness(brightness).to_native());
self.renderer.set_pixel(
x,
output_line,
pixel.apply_brightness(brightness).to_native(),
);
}
}

Expand Down

0 comments on commit 6f2bde7

Please sign in to comment.