Trying to understand nametable mirroring

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
Petruza
Posts: 311
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Trying to understand nametable mirroring

Post by Petruza »

Hi, so far I've understood this:
Vertical mirroring means both bottom nametables are a copy ( mirror ) of the top nametables, where you write to, and you can scroll between them horizontally.

Horizontal mirroring is the opposite.

And third, you can have 2way scrolling which has no mirroring, and you can write to the 4 nametables.

Is this right?
Why is mirroring so important?
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Trying to understand nametable mirroring

Post by tepples »

Petruza wrote:Vertical mirroring means [something]

Horizontal mirroring is the opposite.

And third, you can have 2way scrolling which has no mirroring, and you can write to the 4 nametables.

Is this right?
Yes, except what you call "2way scrolling" is called "four-screen".
Why is mirroring so important?
The NES had only enough VRAM for two nametables. Four-screen wasn't used often because it needed a couple more chips on the cartridge board, and those chips made Game Paks more costly to replicate.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Trying to understand nametable mirroring

Post by tokumaru »

Petruza wrote:Why is mirroring so important?
As far as the PPU is concerned, there are always 4 name tables, arranged in a 2x2 grid. However, there are only 2KB of actual memory for them, enough for only 2 name tables, so the PPU sees the same 2KB twice.

Depending on how the address lines are wired, the 2 unique name tables can be arranged vertically or horizontally. Earlier carts have that setting hardwired, and programmers selected the type of mirroring that was more suited to the kind of game they were making. Newer boards have mappers capable of changing that selection on the fly.

From a programming point of view, mirroring is important because it has a great impact on how the name tables must be updated during scrolling animations. Mirroring is only important in programs that scroll: horizontal scrollers benefit from a wide drawing area, so vertical mirroring is used, while vertical scrollers benefit from a tall drawing area and horizontal mirroring.

When both types of scrolling are used in the same program, one of them will cause visible glitches, unless tricks are done to hide them. Another option to hide such glitches is including an extra 2KB of RAM in the cart for 2 more name tables, which allows for 4 name tables and eliminates mirroring altogether. Very few games had that, and most games that scroll in both directions have visible glitches at the edges of the screen.
User avatar
Petruza
Posts: 311
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Post by Petruza »

Thanks, it's like I suspected, my doubt was about why was mirroring mentioned instead of scrolling, that made me think mirroring was in itself important.
Everywhere "vertical mirroring" is metioned, what really matters, from the point of view of the programmer, is "horizontal scrolling", I realize that there's mirroring because there aren't 4 physical unique addresable memory areas available, the fact that the two bottom nametables are mirrors of the other two, is irrelevant, they could be unaccessable, or be always $FF or whatever.
But because everyone mentioned the mirroring instead of the scrolling, I thought mirroring was in some way used for something.[/quote]
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

The iNES spec calls it "vertical mirroring", and I guess emulators just follow that. But most of Nintendo's discrete boards (NROM, C*ROM, U*ROM, B*ROM) have "H" and "V" solder pads for horizontal arrangement and vertical arrangement of the nametables, which is opposite the convention that the iNES spec uses.

As for calling horizontal arrangement "horizontal scrolling", the scrolling direction is independent of the nametable. Super Mario Bros. 3 uses vertical arrangement (horizontal mirroring) in the vast majority of levels, but you don't see any vertical scrolling at all in 1-2, or in 1-1 until Mario gets the tail.
User avatar
Petruza
Posts: 311
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Post by Petruza »

But it does horizontal scrolling ( obviously ) then how come it scrolls horizontally if the nametable on the right is a mirror of the nametable on the left?
I have to check it now on FCEXUD because I don't get it.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Petruza wrote:But it does horizontal scrolling ( obviously )...
...as well as vertical! Since the game has two types of scrolling, and only one type of mirroring can be used at a time, one type of scrolling is gonna take the hit. Some programmers prefer to introduce vertical glitches, others horizontal. In SMB3, notice how the left 8 pixels of the screen are masked (to hide glitches) and the left actually shows color glitches as the screen scrolls. Like you said, the screen on the right is a mirror of the one on the left, so as soon as tiles scroll out from the left, they are introduced on the right. The glitches exist because the attributes must be changed in front of the player's eyes. The 8 pixel mask can hide tile glitches though, as tiles are 8 pixels wide.

In fact, as tepples said, the mirroring doesn't dictate the type of scrolling used. Mirroring is just something the programmer has to take into consideration when designing the scrolling engine, but any type of mirroring can be used for any type of scrolling, even if there are a few glitches visible as a result.

With vertical mirroring, a horizontal (only horizontal!) scroller can be programmed without any visible glitches. But if for any reason the programmer wants to use the second name table for something else, say, a status screen or something else he doesn't want to be overwritten by the scrolling, he might very well use horizontal mirroring and use only 1 name table for the actual game, which will introduce glitches at the left and right of the screen (unless tricks are done to hide them).

So, "horizontal scrolling" is not interchangeable with "vertical mirroring", even though this is true in many cases. I do think that it would make much more sense if we used Nintendo's terminology though, since many people get confused because the H and V on the boards do not match our mirroring terminology. We'd have to stop using the word "mirroring" and start calling it "arrangement", like tepples did.
User avatar
Petruza
Posts: 311
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Post by Petruza »

Thanks! now I get it.
Post Reply