A question about bank switching usage

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.
mkwong98
Posts: 319
Joined: Mon May 30, 2011 9:01 pm

A question about bank switching usage

Post by mkwong98 »

Are there any actual games that switch the same section of PRG ROM memory to different banks?
tepples
Posts: 23011
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)

Re: A question about bank switching usage

Post by tepples »

I've worked on several such games.

1. Linear PRG ROM on MMC3

Haunted: Halloween '86, Full Quiet, Garbage Pail Kids, and Haunted: Halloween '87 have 512 KiB of PRG ROM and use an MMC3 clone. The first 60 to 75 percent of the ROM is allocated "linearly", such that a block of data can overflow from one 8 KiB block to the next. To read linear data that starts in bank y, the game switches bank y into MMC3 window 6 (at $8000) and bank y + 1 into MMC3 window 7 ($A000).

Say a particular item is stored in linear memory, starting at $9E44 in PRG ROM bank 21 and ends at $A263 in bank 22. To read it, the game switches banks 21 and 22 into windows 6 and 7. The next item after that will start at $8264 in bank 22, and the game switches banks 22 and 23 into windows 6 and 7. This means bank 22 has been used in both windows.

These games often place the following in linear memory: background maps, background tilesets, animated tiles, and (some) sprite sheets. It helps eliminate the possibility of external fragmentation, or space at the end of the bank that is left unused because it's too small to fit anything.

2. Action 53 ROM packing

In 2012, I made a multicart menu called Action 53. I can think of in which a particular bank can get switched into $8000-$BFFF at one point and $C000-$FFFF at another: insertion of compressed CHR data into unused portions of a game, and how NROM-128 games are handled. If (non-pirate) multicarts count as "actual games" as you define them, let me know and I'll explain these in more detail.
mkwong98
Posts: 319
Joined: Mon May 30, 2011 9:01 pm

Re: A question about bank switching usage

Post by mkwong98 »

Thanks! It sounds like those ROM sections are filled with data and not code. Is that correct? I'm asking because I'm porting code to C++ and I do not include data in the ported code. Handling many ROM addresses to 1 CPU address is easier than many to many.
tepples
Posts: 23011
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)

Re: A question about bank switching usage

Post by tepples »

Many MMC1 games have a stub duplicated in all 16 KiB banks that is executed from $C000-$FFFF on reset to help bring the mapper into a known state. Even if the vast majority of the bank is code and data where the code is executed from $8000-$BFEF, the last 16 bytes might be a stub intended to run at $FFF0-$FFF9 followed by a duplicate of the vectors.
mkwong98
Posts: 319
Joined: Mon May 30, 2011 9:01 pm

Re: A question about bank switching usage

Post by mkwong98 »

Thanks! My next game to port is a MMC1 game too.
Oziphantom
Posts: 2001
Joined: Tue Feb 07, 2017 2:03 am

Re: A question about bank switching usage

Post by Oziphantom »

The vast majority of NES games do this.
Fiskbit
Site Admin
Posts: 1405
Joined: Sat Nov 18, 2017 9:15 pm

Re: A question about bank switching usage

Post by Fiskbit »

The question as I understand it is not about using multiple banks in the same section of the address space, which is very common, but having the same bank used in different sections of the address space, which is not common.
Oziphantom
Posts: 2001
Joined: Tue Feb 07, 2017 2:03 am

Re: A question about bank switching usage

Post by Oziphantom »

ohh okay.