I don't understand: vertical mapping

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

User avatar
Marscaleb
Posts: 240
Joined: Fri Sep 11, 2015 10:39 am
Contact:

I don't understand: vertical mapping

Post by Marscaleb »

I've been thinking about the limitations of the NES so as to properly emulate them, and there is something I simply don't understand. Vertical mapping. By which I mean, when the image map for the background is drawn to fill a vertical space. (If I have the term wrong please correct me.)
I want to avoid ever needing that so I don't have to worry about seeing the tiles on one side of the screen using the wrong palette. (Not just because it looks ugly but because I have no idea how to recreate that effect properly.) So I have been studying how various games work to understand how I can avoid the problem. And... I'm kind of at a loss as to why any game had this problem.

Most games can avoid this because the top and bottom edges are cut off on the NTSC NES, and so if the game has the map laid out horizontally, when/if the screen moves vertically those tiles that are the wrong palette are simply not seen. So to avoid seeing this problem, all I need to do is make sure my game is laying out the map horizontally.

Typically, a game that features vertical and horizontal scrolling and a status bar will have this problem. In that situation, the map has the status bar on the top or bottom of the map, and then draws a vertical chunk of the map, and since it has to write over the map to "scroll" to the left or right, an edge will get that palette-bleeding effect.

As I have been studying various games, it has become apparent to me that each scanline can draw the background from any desired co-ordinate in the map. So when it gets to the scanline where the status bar is, it just draws that portion of the map which contains the status bar. (And this is also how games fake parallax scrolling by having some scanlines more at a different rate across the map than others.)
But if this feature exists, why can't a game with a status bar still have vertical scrolling with a horizontal map? Couldn't the system (if it had to) split the screen to draw, say, the bottom portion of the map on the top portion of the screen, and the top portion of the map on the bottom portion of the screen? It wouldn't be too hard to compute the math for that, so I don't see why a game couldn't do that to avoid the palette-bleeding that would come from using a vertical map.
In fact, isn't this already happening in a couple games? Games that have vertical scrolling and a status bar. Some parts of Castlevania III and some maps in Super Mario Bros 3; they have vertical levels that clear are taller than the two screens worth of map the game can load. How do they handle this and not draw the status bar into the play area?

And then I see some games that use a vertical map, and I have no idea why. Mega Man 5 is a good example. Since the health bar is made of sprites, it could just have the map be horizontal, but it doesn't. And it just keeps a chunk of the level that can't even be seen in that spot. Why? It's not using that space; it's a terrible waste.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: I don't understand: vertical mapping

Post by rainwarrior »

I have a preference for calling this "horizontal mirroring" rather than calling it a "vertical arrangement" (or you've said "mapping" here), mostly because it's used for so many different things, and as you've pointed out some games do vertical scrolling situations by other means. Mirroring describes instead what the hardware is doing, rather than what you might be using it for. (This is just my semantic preference though, you can call it what you like.)

The NES was really only designed to facilitate simple horizontal or vertical scrolling, but not both directions at once. Horizontal mirroring is great for games that scroll vertically, or that have a limited vertical space (i.e. under 2 screens high) plus a status bar. Super Mario 3 makes fantastic use of it (check out its nametables in a debugger), in a way that is very simple to implement.

Aside from the simple situations, I think the reasons for choosing a mirroring mode in most games had a lot more to do with ease of implementation, and their individual schemes for storing level maps. Even though all of the Mega Man games look like they should work with simple horizontal/vertical mirroring, it seems like they tried many different approaches across the various games. Most developers didn't seem concerned with eliminating the glitches at the edges very much, especially since TVs used to commonly have wide bezels covering the edge of the screen.
Last edited by rainwarrior on Thu Dec 31, 2015 11:50 pm, edited 2 times in total.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: I don't understand: vertical mapping

Post by Dwedit »

Most games did not use large maps with full horizontal and vertical scrolling, and a status bar at the same time, but a few did. It was easier to program if you had single-screen mirroring available, such as MMC1 or AxROM (Rare games), which lets you switch to the other nametable at a screen split. But with careful use of MMC3 interrupts, you could simulate single screen mirroring when the nametables are arranged vertically (horizontal mirroring) by using a screen split at the bottom of the map to make it wrap back to the top. Crystalis does this.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: I don't understand: vertical mapping

Post by tokumaru »

Marscaleb wrote:Most games can avoid this because the top and bottom edges are cut off on the NTSC NES
In general, yes, but It's not like every TV cleanly cuts 8 scanlines at the top and 8 at the bottom, it varies a lot from TV to TV. The glitchy scanlines are present in the video signal after all, and many TVs will show at least a portion of them. And there's always PAL to consider.
So to avoid seeing this problem, all I need to do is make sure my game is laying out the map horizontally.
In all honesty, you'd be better off using a 4-screen layout and not bothering about scrolling glitches. Adding extra name table memory to a cartridge is pretty trivial, so there aren't any actual reasons for you to avoid that, specially considering that you're only simulating the constraints of the NES and not actually dealing with them.

Even when using 4 screens, there's still the status bar problem, but you can either skip over it with IRQs and mid-screen scroll changes, or redraw the status bar somewhere else whenever the map data is about to overwrite it.
As I have been studying various games, it has become apparent to me that each scanline can draw the background from any desired co-ordinate in the map.
Yes, but the CPU has to actively modify the scroll whenever you want to show a portion of the map other than the line that naturally follows the current one. And the CPU needs to be synced with the PPU to do this at the correct time, something that can be achieved with timed code or mapper IRQs.
But if this feature exists, why can't a game with a status bar still have vertical scrolling with a horizontal map?
It can, the logistics are just more complicated. IIRC, "The Jungle Book" uses this setup. It moves the status bar up and down within the name table as necessary, and blanks some scanlines to effectively reduce the vertical resolution and gain some room for scroll updates. It could have used IRQs to skip over the status bar like Crystalis does, instead of duplicating the status bar.
Some parts of Castlevania III and some maps in Super Mario Bros 3; they have vertical levels that clear are taller than the two screens worth of map the game can load.
I don't know much about Castlevania III, but IIRC, no level in SMB3 is taller than 2 screens minus the status bar. The game was intentionally designed that way to make the scrolling easier to code.
Mega Man 5 is a good example.
Yeah, the Mega Man games are all over the place when it comes to scrolling. Each game does it in a different way, and I suspect it has to do with special effects that are used sporadically, such as spikes on the ceiling moving up and down, or large background bosses.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: I don't understand: vertical mapping

Post by Dwedit »

tokumaru wrote:but IIRC, no level in SMB3 is taller than 2 screens minus the status bar.
SMB3 has a few vertical-only levels:
* Bonus room in second world 4 mini fortress
* World 5-2
* World 7-1
* World 7-6
Probably a few more too. Those levels use Vertical Mirroring, and have the status bar on the right nametable, leaving the entire left playfield as a single screen.
Last edited by Dwedit on Fri Jan 01, 2016 11:37 am, edited 1 time in total.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: I don't understand: vertical mapping

Post by thefox »

There's also this diagonally scrolling level: https://youtu.be/H1Ui3ZDX9MI?t=4195 (http://www.vgmaps.com/Atlas/NES/SuperMa ... rld5-9.png)

Probably these were handled as special cases in their game engine.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: I don't understand: vertical mapping

Post by Dwedit »

Checked out the diagonal level, appears to just be a regular H/V scrolling level, but every time the scroll reaches the top, and the screen is solid blue or white, it quickly wipes the nametables with the upcoming blocks (which match the screen so it doesn't look weird), then resets the scroll position to the bottom for new tiles to scroll in, until the scroll reaches the top again.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: I don't understand: vertical mapping

Post by tepples »

Kirby's Adventure and Little Nemo: The Dream Master use the same trick of duplicating the top nametable into the bottom one. It slows scrolling but can simplify the code, and with commercial time pressure to ship, that was often a good thing.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: I don't understand: vertical mapping

Post by psycopathicteen »

How does it wipe the entire name tables in one frame? Does it just selectively change tiles that aren't blank?
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: I don't understand: vertical mapping

Post by Dwedit »

SMB3 doesn't wipe the nametables in one frame, it just updates the nametable as if you were scrolling horizontally very quickly. It takes 32 frames for the entire double-height nametable.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: I don't understand: vertical mapping

Post by rainwarrior »

The diagonal level has a series of full-white or full-sky screens used at each camera transition. (I don't think the linked image map is accurate.)

When it reaches the transition point, the top screen is already full white, and then it just holds the camera at the top while it spends several frames covering the bottom screen with white (one row at a time). Then it jumps the camera back to the lower screen and resumes scrolling in the level background from there.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: I don't understand: vertical mapping

Post by psycopathicteen »

That's very clever. Does it continue scrolling horizontal even when it's not moving vertical?
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: I don't understand: vertical mapping

Post by rainwarrior »

psycopathicteen wrote:That's very clever. Does it continue scrolling horizontal even when it's not moving vertical?
Not sure what you're asking. I'll describe it again.

At transition start, it has reached a full white top-screen.

The transition takes 64 frames, every second frame it writes another column of solid white. The actual scroll position remains against the edge of the written column (moving 4 pixels to the right every frame), but it's kind of irrelevant; anywhere on the top edge would look identical right now.

At the end of 64 frames, both the top and bottom screen are full-white, and the camera jumps down to the bottom screen. This is in the same horizontal position it started (has gone once around).

At this point it resumes sliding the window diagonally up and right like it was before, writing in new columns as they are reached.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: I don't understand: vertical mapping

Post by Dwedit »

Try using the Tanuki statue ability during the solid blue/white screens...
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: I don't understand: vertical mapping

Post by rainwarrior »

Why?

(I tried it. I don't see anything special happening.)
Post Reply