Bankswitch when image > 256 tiles, possible issues?

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
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Bankswitch when image > 256 tiles, possible issues?

Post by Banshaku »

I didn't test it yet so the goal it to get information about an hypothetical continuous image that has more than 256 tiles. And I don't want to hear about "keep it less than 255", I just want to know the possible issues, if any ;)

Let say this image is used in a non interactive section, where there is no game play. It could be a cut scene, or anything that doesn't require any input from the user. This image, being complex, requires more 256 tiles. Let say this time the target picture doesn't have a black space where the bankswitch will occur (my 2 split I did before had such thing, which helped a lot). If this image is continuous and you have to change the bank mid-screen to see the rest of the image properly, is there is no sprite on the scanline where you switch, is there any possibility of artifact or any possible issue doing so?

Was is common during the nes era too? I just hope I won't really need to use that often but I may have one case when I won't be able to avoid it.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Bankswitch when image > 256 tiles, possible issues?

Post by Bregalad »

There is no possible issue.
Banshaku wrote: Was is common during the nes era too?
No, it was common to keep the tiles on screen less than 257. Mid-frame CHR bankswitching was used mainly for status bars. And it was more common to change the tileset with $2000.4 and use sprites tiles as BG.
User avatar
pubby
Posts: 583
Joined: Thu Mar 31, 2016 11:15 am

Re: Bankswitch when image > 256 tiles, possible issues?

Post by pubby »

It causes a glitch on GTROM I think, but not most other mappers.

Instead of changing the bank, you can also change PPUCTRL to point to the other pattern table. You get 512 tiles that way.
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Bankswitch when image > 256 tiles, possible issues?

Post by Banshaku »

@Bregalad / @pubby

Switching bg/sprite is the most common, interesting one. Will keep that in mind.

For mapper, it would be with an mmc3.

Let's say that even though you really wanted to use the bg/sprite switch but for some reason, you still needed some sprites for some highlights that cannot be done with bg. If we use the trick mentioned above, the only way I would see is keeps the lower part of the pt for tiles and keep upper one (1k) for sprite and duplicate into the other pt then. This one seems the simplest to do.

Still, what if you try to switch bank with mmc3, what could be the possible issue to do so for such image?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Bankswitch when image > 256 tiles, possible issues?

Post by tokumaru »

I remember pirate ports of Genesis and SNES games doing this for title screens and such, but can't think of any examples in official games at the moment.

Since pattern tables are in a separate chip from the PPU and switching them doesn't directly interfere with any of the PPU's work (i.e. the rendering pipeline isn't disturbed in any way), this operation shouldn't suffer from a ton of "gotchas" like other raster effects do.

Looking at the good old PPU timing diagram, you can see that the PPU starts processing the background for the next scanline at cycle 321, and keeps fetching background data (including pattern bytes) all throughout the scanline. Then, when hblank starts, the PPU starts fetching sprite patterns, and does this until cycle 320, and the whole thing repeats. This means that the PPU is constantly reading pattern data, so you should switch background tiles when the PPU is fetching sprite tiles (between PPU cycles 257 and 320, or the first ~21 CPU cycles of hblank) and vice versa, in order to avoid inconsistent tile usage.
Banshaku wrote:Switching bg/sprite is the most common, interesting one. Will keep that in mind.
That will affect how MMC3 IRQs work though, so for that specific mapper, this might not be a good idea (if you plan on using IRQs after swapping the pattern tables via $2000).
Let's say that even though you really wanted to use the bg/sprite switch but for some reason, you still needed some sprites for some highlights that cannot be done with bg. If we use the trick mentioned above, the only way I would see is keeps the lower part of the pt for tiles and keep upper one (1k) for sprite and duplicate into the other pt then. This one seems the simplest to do.
$2000 switching will give you 512 tiles to distribute between sprites and background. If the frame starts with the background using tiles from $0000 and sprites from $1000, then at the spit you tell the background to use tiles from $1000, sprites will keep using tiles from $1000. This will totally screw up the MMC3's scanline counter though.
Still, what if you try to switch bank with mmc3, what could be the possible issue to do so for such image?
I don't see why not. If you're using 2KB windows for the background, you only need to switch 2 banks: do the first $8000 write in advance, then use A, X and Y to buffer the remaining $8001, $8000 and $8001 values so you can make those writes as fast as possible when hblank starts. If you're using 1KB windows for the background though it may be hard to fit all those writes into the tiny hblank window, so you may want to try and design the graphics in a way that tiles from the 1KB windows that are switched last aren't used near the beginning of the scanline.
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Bankswitch when image > 256 tiles, possible issues?

Post by koitsu »

You know, I had a nice concise write-up composed for this, but then I accidentally clicked on [X] for a tab in Chrome instead of switching a tab, so now I get to try and re-write the entire thing. (Yeah, I'm pissed off right now, and this is backed by a 16 hour work day)

I can't tell precise from the initial post, but are we simply talking about doing CHR page swapping during HBlank, to achieve more graphics than the "classic" pattern table contains? And if so, was it common?

If I understand the subject correctly: no, it wasn't common. There are a handful of games which do this, but the one that gets brought up all the time is Jurassic Park -- it does pretty much non-stop MMC3 page swapping of some sort all the time, best I can tell (Mesen's Event Viewer is incredible for this sort of thing), but I'm not sure how much it actual CHR + palette swapping. Jurassic Park's an MMC3 / NES-TSROM game.

There's this post/thread from almost 10 years ago talking about this general subject. And let's not forget about Bregalad's write-up.

You don't have very much time in HBlank, though, which is why doing it for status bars or split-screen stuff is easier -- those extra scanlines give you more time (cycles) to do what you need. You only have something like ~110 CPU cycles in HBlank, IIRC.

Off-topic: I used to try and keep a list of these type of games in my head, mainly as "test subjects" for emulator authors who wanted to really test their general mapper and PPU emulation out heavily, but I've since forgotten many of them. It might be worth putting a list somewhere on the Wiki, just as sorts of general FYI games, especially considering this page talks about the advantages of HBlank CHR-ROM swapping (see "Advantages" bullet list). This page might make a good place to put such things, maybe?
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Bankswitch when image > 256 tiles, possible issues?

Post by Banshaku »

@Tokumaru

It seems quite achievable if done properly in hblank while sprites are done. thank you for confirming!

@koitsu,
Sorry to hear that you lost you post, I know how infuriating it is ^^;;; Lost a long post for beta testing on another forum because I didn't know how the bbs soft worked yet.

This is not for realtime use (I need to check Jurasic park now, I'm curious!) but for showing some content during either an intro or cutscene so not much processing input, just showing an image. Yes, it means having more tile than the pt can show by switching mid-frame and restarting tiles from 0 (or any arbitrary one in upper bg bank) to show more content when necessary. I guess it is less intensive than the mid-screen scanline scroll split then.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Bankswitch when image > 256 tiles, possible issues?

Post by tokumaru »

koitsu wrote:You only have something like ~110 CPU cycles in HBlank, IIRC.
In NTSC, an ENTIRE SCANLINE is about 114 CPU cycles (341 PPU cycles / 3 = 113,66666...), hblank is just the small portion when a picture is not being rendered (341 - 256 = 85 PPU cycles, or about 28 CPU cycles), but even during hblank the PPU is still doing stuff - most of it is used to fetch sprite patterns, and the rest is used to kick off the background rendering for the next scanline, so you still have to tiptoe around those things when making use of hblank.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Bankswitch when image > 256 tiles, possible issues?

Post by Bregalad »

If the frame starts with the background using tiles from $0000 and sprites from $1000, then at the spit you tell the background to use tiles from $1000, sprites will keep using tiles from $1000. This will totally screw up the MMC3's scanline counter though.
This is absolutely not a problem if the part where BG and sprites uses the same side of the pattern table is after the split. What you describe is also exactly what Final Fantasy III does for its battle scenes.
There's this post/thread from almost 10 years ago talking about this general subject. And let's not forget about Bregalad's write-up.
@Banshaku : No problem but it looked like you opened many threads about things that were discussed over and over in the past 15 years, so some further searching in the forums before asking something wouldn't be completely pointless...
Also, instead of ressorting to obscure archives of old versions of the document from my no-longer-existing-former-personal-website, you can get the last version officially from RHDN.
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Bankswitch when image > 256 tiles, possible issues?

Post by Banshaku »

@Bregalad

It is true that I didn't search in detail about that specific case (phbb search is not that accurate though) but one of your post, forgot in which thread, that mentioned to do things in the limit of the hardware instead made me want to post on the subject since it seemed that maybe it was not common somehow.

It is possible that many questions refer to content that have been posted 10~15 years ago but I'm not aware of all of them and sometime it is not easy to find them if you don't know how to search them. I'm not aware of a easy list to search on that subject too and I'm been inactive for quite sometime. In that case I will be more than glad if you refer me in the right direction and I will gladly look at that post then.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Bankswitch when image > 256 tiles, possible issues?

Post by rainwarrior »

Heosphoros' Embered Recollections album ROM used MMC3 CHR splits. The ROM itself is just music over static images, and instead of having to manage background tiles they split each image into 4 parts, if I recall:
https://chipmusic.org/forums/topic/201/ ... andor-mp3/
(I'm pretty sure miau programmed this one.)

Was it common to do CHR splits for more background tiles? Sure. Especially common for status bars. Metal Slader Glory does it to swap in its font set. More generically for splitting a background was a lot less common though. (I can't even think of an example offhand, but I'm sure there's some title screens that do it. Edit: Gimmick! does on its title screen at the same time as a scroll split.)

Swapping within hblank was always possible, but I don't know of any commercial era games that did so. (Lot easier now with the hindsight of decades of reverse engineering and emulators.) Edit: I think there's a few that did use hblank, but it was uncommon.
Last edited by rainwarrior on Tue Sep 18, 2018 9:16 am, edited 1 time in total.
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Bankswitch when image > 256 tiles, possible issues?

Post by Kasumi »

Smash TV is another game that does it. Its title screen, but maybe elsewhere as well.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Bankswitch when image > 256 tiles, possible issues?

Post by rainwarrior »

pubby wrote:It causes a glitch on GTROM I think, but not most other mappers.
GTROM has a problem with CHR banking?

I remember Memblers mentioning some problems during prototyping, but is there a problem in the finished board?
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Bankswitch when image > 256 tiles, possible issues?

Post by Banshaku »

@ rainwarrior

Yes! That album does seems to use multiple banks to display a dithered like image so some people did it with not much artifact too. So I should ask Miau then? ;)

@Kasumi

Smash TV then? understood, will check that too.

So what I want to do is not futile and may have been done before, I'm happy to hear that. Time to work then.

Yes, I know, next time I should search more. Hopefully the next time I ask a question will be when I have more sleep in me :lol: if not, my memory blurs and I'm quite trigger happy to ask questions since I love talking about these things ;)

edit:

yep, Jurasick Park changes bank mid-scanline to show more details in the t-rex mouth. Smash TV does something but I'm not sure what. When you put the scanline in the middle, color is different so I'm not sure what it does. I guess I should sleep ^^;;
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Bankswitch when image > 256 tiles, possible issues?

Post by rainwarrior »

Since it's easy to check a few title screens by opening a nametable viewer and cycling through a few games. There's probably a lot of examples of this, but here's a few more:

Gauntlet II: 3 CHR splits for its title screen. (Much like that Heosphoros album above.)
RoboCop 2 and RoboCop 3: CHR split for background.
Gremlins 2: CHR split for text.
Gun Nac: Also CHR switches for text throughout its intro and title.

Also, there was the MMC2 made for Punch Out to do exactly this in an automated way by having the mapper switch CHR whenever a particular tile is fetched.
Post Reply