Swapping Pattern Tables that Background draws from?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Swapping Pattern Tables that Background draws from?
by on (#224412)
I have a project written in C, using MMC3. I have some large backgrounds/story pieces that I am using more complicated tilesets for, so I'm using my four smaller CHR banks to get all the good detail in. Most of the time I draw my backgrounds from my two larger CHR banks and my sprites from the four smaller CHR banks, but I'm fairly certain there's a way to swap which pattern table to just reference the CHR data I have loaded into my four smaller banks.

How would you go about doing that, though? I haven't had to do this yet, and I'm a bit lost as to where to look.
Re: Swapping Pattern Tables that Background draws from?
by on (#224415)
Normally that's controlled by the register at $2000 (sometimes called PPUCTRL).

Edit: ...but tepples points out below that for MMC3 there is a bit for this in the mapper to use instead.
Re: Swapping Pattern Tables that Background draws from?
by on (#224417)
Using $2000 to swap pattern tables isn't recommended in MMC3 because it interferes with the IRQ. The preferred method is to use bit 7 of $8000 to swap the pattern tables in the MMC3.

$8000.D7 false
Background uses windows 0 and 1 (2K each); sprites use windows 2-5 (1K each)
Super Mario Bros. 2: Mario Madness, Super Mario Bros. 3, and The Curse of Possum Hollow use this method, with the player character in window 2 and other things in windows 3-5 as needed.

$8000.D7 true
Background uses windows 2-5 (1K each); sprites use windows 0 and 1 (2K each)
Kirby's Adventure uses this method, with Kirby in window 0 and predefined enemy sets in window 1. I'm told enemy sets appear several times in CHR ROM because different combinations have to be stored in different banks.
Re: Swapping Pattern Tables that Background draws from?
by on (#224420)
I wasn't aware of that fact. Since I will use again mm3, I guess I should read more about it.
Re: Swapping Pattern Tables that Background draws from?
by on (#224437)
The MMC3 has this setting because its scanline counter relies on background patterns being fetched from $0000 and sprite patterns from $1000, so at least it lets you decide which side gets better bankswitching granularity.
Re: Swapping Pattern Tables that Background draws from?
by on (#224438)
tepples wrote:
Using $2000 to swap pattern tables isn't recommended in MMC3 because it interferes with the IRQ. The preferred method is to use bit 7 of $8000 to swap the pattern tables in the MMC3.

My $2 : Final Fantasy III uses $2000 to swap pattern tables and IRQs during battle. The point is that, they use the "normal" setup for the top of the screen (BG using left pattern table, sprites using right pattern table), then triggers an IRQ at the desired scanline, then uses a non-standard setup (both BG and sprites from the right pattern table), that setup would screw up further IRQs, but since the game doesn't use the counter anymore until the next VBlank, that's a non-issue.

So you can swap pattern tables with $2000 and use MMC3 IRQs, but you need to be careful and know what you're doing.

Quote:
The MMC3 has this setting because its scanline counter relies on background patterns being fetched from $0000 and sprite patterns from $1000

I could be wrong, but I think it also works if bg patterns are from $1000 and sprites patterns from $0000. But it won't work if both are from the same side, and will screw up when 8x16 sprites are a mix from both sides.
Re: Swapping Pattern Tables that Background draws from?
by on (#224485)
Bregalad wrote:
and will screw up when 8x16 sprites are a mix from both sides.
And because the idle sprite fetch is tile $FF, some of the 8x16 sprites area always going to be from the $1000s side.
Re: Swapping Pattern Tables that Background draws from?
by on (#224490)
Bregalad wrote:
I could be wrong, but I think it also works if bg patterns are from $1000 and sprites patterns from $0000. But it won't work if both are from the same side, and will screw up when 8x16 sprites are a mix from both sides.

That's true, but the IRQ timing is different in this case.

lidnariq wrote:
And because the idle sprite fetch is tile $FF, some of the 8x16 sprites area always going to be from the $1000s side.

Oh yeah, there's that too.
Re: Swapping Pattern Tables that Background draws from?
by on (#224531)
lidnariq wrote:
And because the idle sprite fetch is tile $FF, some of the 8x16 sprites area always going to be from the $1000s side.

Ok so if I undersand if right, the configuration where sprites are from the left pattern table and BG from the right only works find with 8x8 sprites, so that's why it's so seldom used (if I remember right at least one game uses this ?).