Don't understand 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

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Don't understand mirroring.

Post by DementedPurple »

So I know what mirroring is, but I don't know how I set it. There isn't a bit in the PPU control registers to set the mirroring, and when I went the nesdev wiki page, it says that vertical mirroring is in address $2000 and $2800, while as vertical is in $2000 and $2400. They say that mirroring exists because the NES didn't have enough PPU memory to have 4 screens, well why is there addresses, $2000, $2400, $2800. and $2C00, seems like it has enough memory to me. It says it has something to do with mappers. Well, if it involves mappers, then how come Super Mario Bros. can have Vertical Mirroring even though it doesn't have a mapper? You might not know what I'm referring to, so let me explain. on the wiki, it says "To configure a cartridge board for horizontal mirroring, connect PPU A11 to CIRAM A10. On cartridge boards made by Nintendo, this is selected by shorting the "V" solder pad (for "vertical arrangement"). Note using inverse logic may make more sense, "Leaving the 'H' jumper open gives horizontal mirroring" on Nintendo boards."
Well if this is the case, then how come games like Metroid or Super Mario Bros. 2 switch mirroring modes on the fly?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Don't understand mirroring.

Post by tokumaru »

Just because an address exists, that doesn't mean the memory it points to is visible ONLY at that address. Another example of memory mirroring on the NES is the CPU RAM, which is only 2KB, but can be seen at 4 different address ranges: $0000-$07ff, $0800-$0fff, $1000-$17ff and $1fff.

The PPU can see 4 name table slots, but the internal RAM chip for name tables only has enough actual space for 2, which can be arranged in different ways depending on configurations made inside the cartridge. These configurations may be hardwired (i.e. permanently soldered) or dynamically controlled by mapper chips.

The cartridge connector was designed to give a lot of control over the name tables to the cartridge, meaning that there are enough signals there to control which name table is mapped where and even to provide extra memory for a total of 4 unique name tables, so that no mirroring is necessary.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Don't understand mirroring.

Post by tepples »

The mapper is switching H or V at runtime based on what values the CPU writes to its ports.

Metroid (メトロイド), Super Mario Bros. 2, and Doki Doki Panic are for the Famicom Disk System. This mapper contains a 2-to-1 multiplexer controlled by bit 3 of $4025, which selects PA10 or PA11 to be routed to A10 of nametable memory. Metroid and Doki Doki Panic changes the value of this bit when Samus goes through a doorway or Papa enters or leaves a vertical level, be it through a door or a ladder. (SMB2 doesn't change it.)

Metroid (U) is for the MMC1. This mapper contains a 4-to-1 multiplexer controlled by bits 1-0 of $8000, which select a constant 0, a constant 1, PA10, or PA11 to be routed to A10 of nametable memory. It changes the value of this bit every time Samus goes through a doorway.

Super Mario Bros. 2: Mario Madness (also called Super Mario USA) is a port of Doki Doki Panic to the MMC3. This mapper contains a 2-to-1 multiplexer controlled by bit 0 of $A000, which selects PA10 or PA11 to be routed to A10 of nametable memory. It changes the value of this bit when Toad enters or leaves a vertical level, be it through a door or a ladder.

The MMC3's multiplexer follows this truth table:

Code: Select all

Select PA11 PA10 | Out
   0    0    0   |  0
   0    0    1   |  1
   0    1    0   |  0
   0    1    1   |  1
   1    0    0   |  0
   1    0    1   |  0
   1    1    0   |  1
   1    1    1   |  1
Written more compactly using "don't care" notation:

Code: Select all

Select PA11 PA10 | Out
   0    x    0   |  0
   0    x    1   |  1
   1    0    x   |  0
   1    1    x   |  1
The multiplexer in MMC1 and Action 53 follows this truth table:

Code: Select all

Select PA11 PA10 | Out
  00    x    x   |  0
  01    x    x   |  1
  10    x    0   |  0
  10    x    1   |  1
  11    0    x   |  0
  11    1    x   |  1
DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Re: Don't understand mirroring.

Post by DementedPurple »

Okay, but how would a simple game with no mapper set mirroring, like Super Mario Bros.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Don't understand mirroring.

Post by tepples »

If there's no mapper, the mirroring is set using solder pads that hardwire PA10 or PA11 to A10 in. You set the mirroring by bridging one pair of pads and not bridging the other pair.
User avatar
infiniteneslives
Posts: 2104
Joined: Mon Apr 04, 2011 11:49 am
Location: WhereverIparkIt, USA
Contact:

Re: Don't understand mirroring.

Post by infiniteneslives »

DementedPurple wrote:Okay, but how would a simple game with no mapper set mirroring, like Super Mario Bros.
Simply put, you can't from the perspective of your game's code.

You can select H/V mirroring in you ines header which tells the emulator what mirroring your cart has. That's something you decide at compile time.

You'll need a mapper if you want to change mirroring at run time.
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Don't understand mirroring.

Post by Bregalad »

DementedPurple wrote:So I know what mirroring is, but I don't know how I set it. There isn't a bit in the PPU control registers to set the mirroring, and when I went the nesdev wiki page, it says that vertical mirroring is in address $2000 and $2800, while as vertical is in $2000 and $2400.
The current wiki page on mirroring is awful, and my attempts to revise it (to be still mediocre but less awful) were repeatedly rejected, so I gave up on the matter.

What does matter is that the wiki is a terrible ressource when it comes to this - the diagrams however should be helpful in understanding it. Other than that your best bet is to play games with nametable viewers enabled and see what is going on.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Don't understand mirroring.

Post by tepples »

Bregalad wrote:The current wiki page on mirroring is awful, and my attempts to revise it (to be still mediocre but less awful) were repeatedly rejected, so I gave up on the matter.
I encourage you to propose a fork in your own user space. Or did you and did I miss it?
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Don't understand mirroring.

Post by Pokun »

Also I think the term "mirroring" have always been confusing in itself. Who cares what's mirrored when it's where the nametables are when scrolling that's the interesting part. Also using a term that is opposite from what Nintendo's boards and documents use (V-mirroring is H-scroll and H-mirroring is V-scroll) isn't very intuitive either.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Don't understand mirroring.

Post by tepples »

Except a lot of games use horizontal scrolling with horizontal mirroring, such as Super Mario Bros. 3. That's why I've tried to use the term "vertical arrangement" to represent the $2000/$2800 layout where the nametable is 32 cells wide and 60 cells tall.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Don't understand mirroring.

Post by rainwarrior »

tepples wrote:
Bregalad wrote:The current wiki page on mirroring is awful, and my attempts to revise it (to be still mediocre but less awful) were repeatedly rejected, so I gave up on the matter.
I encourage you to propose a fork in your own user space. Or did you and did I miss it?
He did, and you missed it (despite commenting in its discussion thread, somehow). Here's the discussion if you want to comment:
http://wiki.nesdev.com/w/index.php/Talk ... lling_page
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Don't understand mirroring.

Post by Pokun »

tepples wrote:Except a lot of games use horizontal scrolling with horizontal mirroring, such as Super Mario Bros. 3. That's why I've tried to use the term "vertical arrangement" to represent the $2000/$2800 layout where the nametable is 32 cells wide and 60 cells tall.
Well H-scroll obviously doesn't mean that the game must scroll horizontally, but that horizontal scrolling takes you into the second nametable instead of mirrored VRAM. I say call it scroll mapping or nametable arrangement, either is fine, but mirroring is just backwards. Although it might be a bit late to change a convention like that.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Don't understand mirroring.

Post by tepples »

That's why I tried to describe both the arrangement terminology and the mirroring terminology in the "awful" page on the wiki.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Don't understand mirroring.

Post by tokumaru »

Changing the convention at this point may indeed end up causing even more confusion.

I don't understand how anyone in their right mind, dumping ROMs and looking directly at the "H" and "V" markings on the boards, would come up with the "mirroring" notation instead. I mean, the guy who invented the iNES format must have reverse engineered a couple of boards at some point in order to figure out what kind of information the header would need, right?
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Don't understand mirroring.

Post by Bregalad »

tepples wrote: I encourage you to propose a fork in your own user space. Or did you and did I miss it?
I did exactly that but eventually I lost interest because the whole topic is a whole mess anyway. As already pointed out the "mirroring" terminology is already bad for vertical or horizontal mirroring, and becomes awful for describing anything else. My personal taste goes for the "arrangement" or "tilemap" terminology, but since the tile maps are not continious the arrangement terminology is the best. Saying a "64x30" tilemap seems to imply a row of continuous 64 characters, which is not the case when vertical mirroring is used.

In addition to that the term confuses mapper controlled and hardwired mirroring, which are two entirely different things hardware wise. That's why in my opinion when a MMC1 is configured to have, say, "vertical mirroring" it is not actual vertical mirroring but an emulation of vertical mirroring because the MMC1 controls the pin and it is not hard-wired. But other people refused to agree with me on this one, so it only brings more confusion to say mapper controlled mirroring can also be horizontal and vertical mirroring when it is in fact completely different than true hard-wired mirroring.

And I'm not even starting on iNES format which has complicated support for this. What a mess.
Post Reply