Visual corruption in Super Mario

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
jotac
Posts: 13
Joined: Wed Feb 17, 2021 1:08 pm

Visual corruption in Super Mario

Post by jotac »

Hello!

I am having this weird "corruption" in Super Mario (see below). Entire game plays out fine tho (sprites collisions and what not). Also worth mentioning games like Donkey Kong, Pacman, Balloon Fight and Bomberman play out fine.

https://imgur.com/GabbMk6
Image

Did some debugging, here is what I found:
- these random visuals appear in spaces where it should be background color (e.g. the sky); I noticed the pixel is 0 there but the color fetched is the green color, from $3F01 in this case; I read from

Code: Select all

0x3F00 + ((palette as u16) << 2) + pixel as u16
In this case to be $3F01 it means the palette is 0 but pixel is 1. To be 1, it means the background pixel in this case had to be 1, and it was. I determine the background pixel like this:

Code: Select all

let (bg_pixel, bg_palette) = if self.mask.render_background {
            let bit_offset = 0x8000 >> self.fine_x;
            let pixel_lo = ((self.bg_shifter_pattern_lo & bit_offset) != 0) as u8;
            let pixel_hi = ((self.bg_shifter_pattern_hi & bit_offset) != 0) as u8;
            let palette_lo = ((self.bg_shifter_attrib_lo & bit_offset) != 0) as u8;
            let palette_hi = ((self.bg_shifter_attrib_hi & bit_offset) != 0) as u8;
            ((pixel_hi << 1) | pixel_lo, (palette_hi << 1) | palette_lo)
        } else {
            (0x00, 0x00)
        };
I have no clue what could be causing this, does anyone have any thoughts? Or more tests to run. I have ran all of blargs tests and passed. If there are others out there that could help debug this, tell me! (PS: currently only implemented mapper 0)
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Visual corruption in Super Mario

Post by tepples »

My first guess is that you're accidentally writing palette writes ($3F00-$3F1F) also to the nametable ($2700-$271F).

The PPU has special-case behavior to block writes with address $3F00 through $3FFF from going to video memory. You didn't notice this in other games because these are non-scrolling games (DK; Pac-Man) or they scroll in the same direction as the mirroring (Balloon Fight).
jotac
Posts: 13
Joined: Wed Feb 17, 2021 1:08 pm

Re: Visual corruption in Super Mario

Post by jotac »

@tepples thank you so much! indeed that was it.
Post Reply