Skip to content

Commit

Permalink
[GEN] avoid a flickering frame if a game enables interlacing with a n…
Browse files Browse the repository at this point in the history
…on-blank frame
  • Loading branch information
jsgroth committed Dec 14, 2024
1 parent 9c406dd commit 09dc90e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion backend/genesis-core/src/vdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,11 +915,16 @@ impl Vdp {
self.state.frame_count += 1;
self.state.v_border_forgotten = false;

self.state.interlaced_frame = match self.registers.interlacing_mode {
let next_frame_interlaced = match self.registers.interlacing_mode {
InterlacingMode::Progressive => false,
InterlacingMode::Interlaced => !self.config.deinterlace,
InterlacingMode::InterlacedDouble => true,
};
if next_frame_interlaced && !self.state.interlaced_frame && !self.config.deinterlace
{
self.prepare_frame_buffer_for_interlaced();
}
self.state.interlaced_frame = next_frame_interlaced;

// Top border length needs to be saved at start-of-frame in case there is a mid-frame swap between V28
// mode and V30 mode. Titan Overdrive 2 depends on this for the arcade scene
Expand Down Expand Up @@ -1055,6 +1060,20 @@ impl Vdp {
}
}

fn prepare_frame_buffer_for_interlaced(&mut self) {
// Duplicate every line to avoid a flickering frame if a game enables interlacing without
// first blanking the screen
let screen_width = self.screen_width();
let screen_height = self.screen_height();
for scanline in (0..screen_height).rev() {
for pixel in 0..screen_width {
let color = self.frame_buffer[(scanline * screen_width + pixel) as usize];
self.frame_buffer[((2 * scanline) * screen_width + pixel) as usize] = color;
self.frame_buffer[((2 * scanline + 1) * screen_width + pixel) as usize] = color;
}
}
}

fn in_vblank(&self) -> bool {
self.state.scanline >= self.registers.vertical_display_size.active_scanlines()
&& self.state.scanline < self.timing_mode.scanlines_per_frame() - 1
Expand Down

0 comments on commit 09dc90e

Please sign in to comment.