Can different pattern table sections be referenced in a nametable tile?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
supersonic4336
Posts: 2
Joined: Fri May 22, 2020 1:09 pm

Can different pattern table sections be referenced in a nametable tile?

Post by supersonic4336 » Fri May 22, 2020 1:25 pm

Hi Everyone, just joined today and started on the NES Emulation journey.

I've managed to get through the CPU and part of the PPU from the awesome info on the wiki, still in the PPU stage when a thought occurred to me.

Since the nametable is just a series of indexes into the pattern table is it possible for it to have 8 bit slivers of different tiles in each scanline for the same cycle?

For instance start of scanline 1 the nametable value fetched is pointing to tile 3 in the pattern table and scanline 2 it's pointing to tile 4?

Sorry if this has been answered but my searches turned up nothing and its a hard thing to put to words to search. Or I'm wildly misunderstanding how VRAM can be populated.

lidnariq
Posts: 9290
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Can different pattern table sections be referenced in a nametable tile?

Post by lidnariq » Fri May 22, 2020 1:37 pm

In isolation, no, all 8 scanlines of the tile will always hold the same value.

However, the CPU can change the scroll value, or which nametable is to be used, at any time.

As an extreme example, I made a demo ROM that has separate nametables for each scanline

User avatar
rainwarrior
Posts: 7801
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Can different pattern table sections be referenced in a nametable tile?

Post by rainwarrior » Fri May 22, 2020 1:52 pm

A suitably complex mapper can substitute every byte of nametable and/or attribute fetched. MMC5 has a mode that makes attributes per-tile rather than per 2x2 group.

However, other than that, there is not much existing mapper hardware that tries to do something like this. Rasteri's DOOM on NES cart comes to mind.

Otherwise with scanline IRQs and 4 screens of nametable, you could do what lidnariq suggested to reasonably get arbitrary 8x2 tiles and 16x2 attributes (at a large but manageable CPU expense). With N163 or VRC6 or some other mapper that can bank nametables, and large CHR-RAM, you could get 8x1 or 16x1.

4-screens + MMC3 (scanline IRQ) did exist in games during the commercial era. Large CHR-RAM however was extremely rare, and emulator support for variations like that is spotty (but many popular emulators will do it).

User avatar
tokumaru
Posts: 11644
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Can different pattern table sections be referenced in a nametable tile?

Post by tokumaru » Fri May 22, 2020 2:19 pm

The PPU does fetch an entire row of tile indices from the name tables every scanline, so you can theoretically swap the name table memory every scanline and have the PPU render a different set of tiles across the 8 scanlines that would normally use the same set of tiles.

However, the first problem is that no commonly available hardware provides enough memory for this. If you really wanted 240 unique rows of tiles, you'd need the equivalent to 8 name tables (since each one has 30 rows), possibly more if you're planning on scrolling without glitches on the edges of the screen. The NES only comes with space for 2 name tables built in, and some cartridges from back in the day were released with extra memory for a total of 4. To use more than that you'd need a custom mapper with the ability to switch name tables, at which point you run into the problem of emulator support, because only a few relatively obscure mappers really have that.

The other problem is timing. Switching to other name tables is a task that the CPU has to perform, stealing processing power that would otherwise be used for the game logic. Not only that, but the switches need to be done in synchronization with the rendering process (i.e. between one scanline and the next) in order to not cause visual glitches (flicker and/or jitter). This basically eliminates the possibility of this being used during gameplay.

One solution would be to design an entirely new mapper with all the necessary RAM and the hardware to automatically switch that memory as the picture is rendered. Much like the scanline counter in a mapper like the MMC3, this new mapper could detect the end of each scanline automatically loop through multiple sets of name tables.

supersonic4336
Posts: 2
Joined: Fri May 22, 2020 1:09 pm

Re: Can different pattern table sections be referenced in a nametable tile?

Post by supersonic4336 » Fri May 22, 2020 4:38 pm

On looking back at the nametable wiki page I'm realizing I was so focused on the algorithm the PPU uses I'd convinced myself that each scanline was the next vertical index into the nametable, and could be prepopulated to do that kind of shenanigan. ie) the nametable "height" was was 240, rather than just 30 bytes representing those 240 pixels. Even looking at my own code it's not that way. :P

However hearing you guys go through the thought experiment that if you had a ram/mapper with enough space or enough time in an hblank to swap it you could pull it off. Thanks guys!

Post Reply