Single screen mirroring: VRAM address of second screen?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Single screen mirroring: VRAM address of second screen?
by on (#119076)
Hello everyone! I'm new here but I have been browsing and learning quite a bit from this wonderful corner of the internet! I have been recently learning some 6502 assembly after a very cool friend of mine did an art show involving glitchy custom NES programs cartidges and a bunch of projectors (it was awesome!), in the hopes that I, too, may make something as cool.

On to my question!

So, I understand generally how nametables and scrolling works and have done some various tests with writing to the nametables on the fly using controller input and the like. But what baffles me is how single screen mirroring, like in Rare's AxROM games, works at all. There's plenty of literature around on how to write to the two (mirrored) nametables using V/H mirroring at addresses $2000, $2400, $2800, and $2C00, and I have done that and it all makes sense. I even grasp using the write to $8000-$FFFF with bit 4 set to 0 or 1 to select the VRAM page in single screen mirroring, but what is unclear to me is that that selecting actually does and how to write to the OTHER half of the VRAM.

I haven't played extensively with this as of yet since I have mostly just been reading up on it, but I am very curious and very confused. I'm assuming that the select write simply loads all four nametables with that portion of the VRAM, but what addresses am I writing to when I want to write on that "other" screen?

I hope this question is concise enough and I really hope I can get an answer I understand! So far, this forum has been a gold mine of greatness, and I have had many epiphanies here. Give me one more! Thanks again.

-Micheal

edit: for clarity
Re: Single screen mirroring: VRAM address of second screen?
by on (#119077)
Basically, nowhere, the address pins for it are tied to not be dynamic with the $2000 and $2800/$2400 areas, so there ram is basically unaccessable.
Re: Single screen mirroring: VRAM address of second screen?
by on (#119079)
I'm not sure I understand. If that is the case then how does a game like Battletoads draw the status bar in one half of the VRAM and the level background in the other and then use both to render out the screen? Are you saying that an AxROM only ever uses half the NES's VRAM? I don't think that's the case at all.

edit: Unless the switch is done part way through the rendering, but even then, seems wasteful.

edit: In fact, from the NesDev wiki on Single Screen Mirroring:

"Single-screen mirroring is only available with certain mappers, such as the AxROM, SxROM, and TLSROM boards, resulting in two 32x30 tilemaps.

Its main advantage is that it allows using a status bar at the top or bottom of the screen while also allowing the playfield to extend equally in any direction - this can be done by storing the status bar in one nametable, rendering the playfield in the other nametable, and switching mirroring (and scrolling parameters) at the appropriate screen location during rendering."

This is what I don't understand how to do, the accessing of that "second nametable".
Re: Single screen mirroring: VRAM address of second screen?
by on (#119081)
All nametables use the same address. If you draw one, switch the other, draw it, and switch back, yes it's possible. BUT, the PPU only sees 1KB of RAM at any point, so it will NOT know there's 2KB. It's a technical thing. I' suggest you learn more about normal mirroring and then more on address lines, as it all works together.
Re: Single screen mirroring: VRAM address of second screen?
by on (#119083)
mrmmaclean wrote:
I'm assuming that the select write simply loads all four nametables with that portion of the VRAM, but what addresses am I writing to when I want to write on that "other" screen?


I'm not sure if this is your conceptual confusion, but the nametables aren't "loaded". There is 2k of RAM, and 4k of address space. What mirroring does is directly wire each of the four 1k address blocks to one of the two 1k physical blocks of RAM. Writing and reading use the same addressing, and the data is never copied or duplicated, it is simply either looked up from the rewired address, or written to the rewired address. The screen selection affects both operations at the same time.

So, the screen select on a single screen mapper is the same mechanism for both writing to it and reading (i.e. rendering) from it. Switch to the screen you want to use before writing. Switch to the screen you want to use before rendering. If you want to use both, you need to switch screens in the middle of rendering with careful timing (e.g. use a sprite 0 hit).
Re: Single screen mirroring: VRAM address of second screen?
by on (#119084)
Ahh! Brilliant! I get it now.

Sorry, my wording really wasn't so clear after all. I do understand how that works, I was simply trying to be as generic as possible for my own sake and now that I re-read it, I was really backwards there... :oops:

But now I'm curious. Say I wanted draw something to the second screen but I want to render the first screen (not necessarily practical but it's just for example). Would I have to switch to the second screen during V/forced blank, draw, then switch back to the first before V-blank was finished or I switched rendering back on? Is this possible?

edit: I think that might just be exactly what you said...
Re: Single screen mirroring: VRAM address of second screen?
by on (#119085)
Yes, you can do that, and it's how you have to do it.
Re: Single screen mirroring: VRAM address of second screen?
by on (#119087)
Thank you kindly for your help! Yet another epiphany!

I can see a few advantages to doing that already.