This is how I'm doing it in MMC3:
I use one of the switchable banks as a fixed bank. So, after this bank is set once in the beginning, it never gets changed anymore.
This way, I have 24 KB of space that are always available.
Furthermore, I programmed a function that can copy source code from a bank into the cartridge RAM.*
This way, I have up to 8 KB of space that are also always available, minus the RAM space that you actually need for conventional variables.
And so, we have 24-32 KB of always available code in contrast to the 16 KB of UNROM, so that we hopefully don't have to worry about bankswitching actual source code in the first place and can dedicate the bankswitching to data alone.
If it is still not enough, then I would look for all the functions that are independent from other code and data and put them into a bank. Then I'd use the one bank that is still switchable for these things.
In this case, the functions of course have to be independent not only from other functions, but also from data constants, unless these constants and functions are all located within in the same bank.
In my case, even though it wouldn't be necessary yet, I store the code and data of the title screen, game over screen, save data menu etc. into a separate bank.
These things never need anything from the rest of the game, only battery RAM values for savestates, but nothing from code or external ROM data.
So, I can waste eight more KB for text screens that are not counted towards my up to 32 KB of always available stuff. And the text screens are guaranteed to never interfere with the flow of my program since they are only called in one specific location that will never change ever again.
* About putting code from ROM to RAM:
If you use cc65, the config file allows you to declare a segment that is stored in one location, but that gets executed in another location. You just have to program the copy function, but from then on, you can use the functions out of the RAM, even though at compile time, they are stored at a different address in ROM.
bleubleu wrote:simply remember to switch before calling and it's all good
A little hint: Everything that is in a switchable banks gets a postfix in my code:
ProcessTitleScreen_bTxt
This shows me that the function is stored in the text screens bank, so I have to call
SwitchBank(BankTextScreens) before I call it. (Unless the function that calls
ProcessTitleScreen also has the postfix
_bTxt in which case I know that I'm in this bank.)
Furthermore, any function that switches a bank gets the postfix
_sB, so that I know: After I called this function, it's not guaranteed anymore that the current bank is still the same:
Code: Select all
SwitchBank(BankXyz);
DoSomething_bXyz();
// Stored in global bank:
SomethingDifferent();
// No bank switch necessary: We're still in XYZ.
DoSomethingElse_bXyz();
// Stored in global bank, but changes the variable bank to any value:
SomethingCompletelyDifferent_sB();
// Bankswitch necessary again because it was changed.
SwitchBank(BankXyz);
DoSomething_bXyz();