This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Game structure using multiple banks, code/data/etc..

Game structure using multiple banks, code/data/etc..
by on (#89893)
Hey all, I been lurking for a while and got to the point where I need to revise my banking strategy since my code, LUTs, and DPCM samples have overblown 16k. I'm curious what you guys find works well.

For me I'm MMC3 page switching $8000 and $A000 with static $C000 (needed for DPCM samples).

Most of the time I have 8k of level data for the current level set (metatiles, spawn points, etc) in $8000.

The only switch I currently do is duing the music update I bank in
my music data (all but DPCM samples) in $8000, and Famitone (thanks Shiru!) code and related lookup tables, and my sound effects in $A000.

I'm considering putting all my LUTs (sprite layouts, atan, log2, exp2, sin and cos tables) in a $A000 page to bank in when needed. Or maybe its better to bank in related code chunks as needed?

What do you guys do in your games?

by on (#89895)
Personally I've never really used bankswitched ROM and always managed to make things fit in 32k.
But if I were to use bankswitching I'd probably go for 32k banks, and putting everything related to levels in one bank, everything related to music in one bank, etc... see the picture ?
Of course some piece of code would have to be duplicated in every bank, but it's possible to make it quite short and just does the right bank-switching actions and go to the right bank.

If I were to work with the fixed 16k and banswitched 16k sheme (UNROM-style), then the static bank becomes extremely important as it is always present in the memory map. Therefore, you should avoid putting code in there as much as possible, and only put what is capital in this bank.
Try to put everything level-related, music-related, etc... in various 16k banks.
Then if it doesn't fit, for example if your level-related code + your levels takes more than 16k, you should put level-related code in the fixed bank and the level-related data in various switchable 16k banks.

If with this sheme you still can't get everything you wanted to in your 16k bank, then you probably don't have a choice but to duplicate code in the various switchable banks, for example you have two 16k banks with level data in them, and the level-related code is duplicated in both of those banks.


Again this is pure theory as personally I don't remember doing anything significant with more than 32k PRG, except for the purpose of trying it out.
I hope this helped you.

by on (#89904)
This really depends on the amount of bank slots you have. The nice thing about the MMC3 is that you can use 1 bank for code and the other for data. Levels, music, etc. would be loaded in the data slot, while the music engine, mini games, VBlank code (which might be big due to unrolled loops for fast VRAM updates) and complex AI routines could go in the data slot.

I would put the main program in the fixed banks, and as much of the game engine in it as well. If the game engine doesn't fit, it can be divided in parts that don't run at the same time and be mapped to the switchable code slot.

On mappers that switch the whole 32KB at once (AxROM, BxROM), I think it's better that each individual engine (main gameplay, bonus levels, etc.) are limited to their own bank. Data banks would not only contain the data, but also the routines that manipulate that data (for example, all banks containing level maps would have a copy of the routines that decode rows and columns of tiles for scrolling), in order to minimize the amount of bankswitching necessary to accomplish various tasks.

If you have a fixed 16KB slot and a switchable one (UxROM, MMC1), a mix of the above techniques could be used.

EDIT: Basically, I'm agreeing with Bregalad.

by on (#89946)
If you find it difficult to arrange everything, using WRAM (if you aren't already) can allow you to keep some stuff in memory while switching to other banks. (For example, Final Fantasy stores the entire decompressed level in WRAM.)

by on (#89947)
Karatorian wrote:
If you find it difficult to arrange everything, using WRAM (if you aren't already) can allow you to keep some stuff in memory while switching to other banks. (For example, Final Fantasy stores the entire decompressed level in WRAM.)


Great. :) That's what I was right to reply here. Well, actually, we have 32k at $8000-$FFFF and 8k at $6000-$7FFF. If you're smart, even $5000-$5FFF offers room for ROM data.