$2001 8-pixel mask

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
$2001 8-pixel mask
by on (#108820)
Is there an engineering reason behind Nintendo's decision to only include the sprite/background mask on the leftmost 8 pixels of the screen? If its purpose was to hide color artifacts, why not place it on the right since most side-scrollers head in that direction -- or make it an option for all four borders? Or was it originally included for a different reason, like a safe area to hide unused tiles?

I know we likely don't know Nintendo's design intentions, but I'm curious about any informed speculation (and couldn't find a previous topic addressing it).
Re: $2001 8-pixel mask
by on (#108823)
Without it, how would you have a sprite slide off the left side of the screen?
Re: $2001 8-pixel mask
by on (#108826)
Yeah, hiding sprites disappearing sudden of all is pretty much the only reason for it (though doesn't explain why you can set it separately for the tilemap and sprites). As for tilemap glitches, I believe it reduces the color clash area from 8 pixels minimum to 4 pixels minimum (if you're using horizontal mirroring), while it's enough to completely hide tile replacements.
Re: $2001 8-pixel mask
by on (#108862)
Just my guess. The original purpose of the mask was only for for the sprites sliding to the left edge of the screen. The Famicom/NES was originally designed for relatively simple games and the complexity of the later releases (achieved by using more complex mappers and programming tricks) weren't expected. Since there are enough RAM onboard for two nametables, fixing the mirroring alone is already enough for glitchless scrolling, provided the game only scrolls in the vertical or in the horizontal direction. Those glitches are mainly caused by having 4/8 way scrolling which was not envisioned when the system was designed. If the mask was supposed to be used to hide attribute clash, they should hide more columns of pixels (like, say, hiding 8 pixels from either sides of the screen).

That say, the SMS also has the same option to hide the first 8 columns of pixels, but since it only has one nametable this is also essential for hiding artifacts while scrolling.
Re: $2001 8-pixel mask
by on (#108869)
Gilbert wrote:
That say, the SMS also has the same option to hide the first 8 columns of pixels, but since it only has one nametable this is also essential for hiding artifacts while scrolling.

In that case it's even worse because what should be the partial column at the left isn't rendered at all, so the column hiding is literally needed if you plan to scroll horizontally. Curiously in that case sprites disappearing at the left isn't an issue because there's a bit that shifts the sprite to the left by 8 pixels.
Re: $2001 8-pixel mask
by on (#108913)
The "shift sprite left" bit on the SMS only works in the old TMS9918 video modes. Sprite attributes in the Master System mode are lacking the 4th sprite attribute byte that the old modes had, which stored the extra bit, as well as the sprite color.

The bit actually shifts the sprite by 32 pixels, which is the largest size a sprite can be in those modes, when you use scaled, 16 pixel sprites.
Re: $2001 8-pixel mask
by on (#108926)
I feel silly for asking, but what are some examples of the sprite sliding off the left edge? And why only the left?
Re: $2001 8-pixel mask
by on (#108929)
Sprites can't be placed at negative X coordinates on the NES. Play any game with horizontal wraparound, such as Balloon Fight or Mario Bros. and notice the pop-on when the player slowly crosses the side of the screen.
Re: $2001 8-pixel mask
by on (#108930)
If sprites were one pixel wide, there would be no problem: you could set them to all 256 possible X positions. But if sprites are two or more pixels wide, there are more than 256 X positions they can occupy. Take a two pixel wide sprite: it is visible on X positions of -1 through 255, 257 total positions. This won't fit in a byte. One approach is to add an extra bit to the X position. Another is to make the screen narrower by the width of a sprite-1 or more. The NES takes the latter approach, reducing it by 8 probably because it's simpler than reducing by 7. When enabled, 8-pixel-wide sprites have 255 positions in which some portion of them is visible on screen (the 256th, X=0, results in them being hidden).
Re: $2001 8-pixel mask
by on (#108935)
Yes, I always noticed that reducing by 7 pixels would be enough, as a sprite with X = 0 would have one pixel which is visible, as a sprite with X=255.
Re: $2001 8-pixel mask
by on (#109020)
Thanks for the answer to an elementary question. I realized the answer myself today when I was fooling around with Super Mario Bros. I had a 'oh, duh' moment.