Excitebike Screen Tearing?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
siliconandsolder
Posts: 9
Joined: Tue Apr 20, 2021 1:25 pm

Excitebike Screen Tearing?

Post by siliconandsolder »

Hi all! I've been tearing my hair out for the past few days over some horizontal scrolling problems. The scrolling problems are apparent in several games, most prominently Excitebike. Here's a video of what I mean: https://streamable.com/77jqjk

Any idea what the issue might be? I read in some other posts that scrolling bugs often have to do with reads to PPU register 2002 and writes to PPU registers 2005/2006. Here are my implementations:

2002:

Code: Select all

    fn ppuStatus(&mut self) -> u8 {
        let mut value = self.prevReg & 0x001F;
        value |= self.fSprOver << 5;
        value |= self.fSprZero << 6;

        if self.nmiOccured {
            value |= 1 << 7;
        }

        self.w = 0;
        self.nmiOccured = false;

        return value;
    }

2005/2006:

Code: Select all

    fn ppuScroll(&mut self, val: u8) -> () {
        if self.w == 0 {
            self.t = (self.t & 0xFFE0) | ((val as u16) >> 3);
            self.x = (val & 0x07);
            self.w = 1;
        }
        else {
            self.t = (self.t & 0x8FFF) | (((val & 0x07) as u16) << 12);
            self.t = (self.t & 0xFC1F) | (((val & 0xF8) as u16) << 2);
            self.w = 0;
        }
    }

    fn ppuAddress(&mut self, val: u8) -> () {
        if self.w == 0 {
            self.t = (self.t & 0x80FF) | ((val as u16 & 0x3F) << 8);
            self.w = 1;
        }
        else {
            self.t = (self.t & 0xFF00) | (val as u16);
            self.v = self.t;
            self.w = 0;
        }
    }
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Excitebike Screen Tearing?

Post by lidnariq »

Your implementation of sprite 0 hits is wrong. (Look at what the game does using Mesen's Event Viewer)
siliconandsolder
Posts: 9
Joined: Tue Apr 20, 2021 1:25 pm

Re: Excitebike Screen Tearing?

Post by siliconandsolder »

lidnariq wrote: Sat Jul 03, 2021 4:45 pm Your implementation of sprite 0 hits is wrong. (Look at what the game does using Mesen's Event Viewer)
Ok cool, thanks. Once I find the source of the bug, I'll post the solution here for anyone else who encounters it.
siliconandsolder
Posts: 9
Joined: Tue Apr 20, 2021 1:25 pm

Re: Excitebike Screen Tearing?

Post by siliconandsolder »

I found the bug. I had two booleans to keep track of when a sprite zero hit was possible, and when sprite zero was being rendered. I confused the two when fetching OAM data for the current scanline. Thanks lidnariq!
Post Reply