J0nas - You want to use a trampoline function in bank 0.
For one of my homebrew games I used one that takes 2 parameters, the bank # and address of the fn you want to call. It:
- reads the current bank
- pushes that onto the stack
- changes to the requested bank
- calls the requested fn
- when it returns it pop the original bank and switches back to that, then returns
I've also seen similar fns that take a position into a jump table. So you call the Bank9Trampoline with 12, and then it switches to bank 9, and looks in the jump table at the start of bank 9 for the address of fn 12 and calls that.
If you need to make some space, hopefully there are some graphics you can move from bank 0 to somewhere else, otherwise you are stuck moving code around
Yep. That's the cleanest way to do it without having to messing with code moving :-) That's exactly how I rewrote the entire Mega Man World 5 DX code, as I was running out of space.
It is really useful to have some free space in bank 0 though. Also, look for the game's original memory and video management subroutines as they are usually on bank 0 and you can reuse them.
Neat trick! I didn't realize. That should only require a minimum amount of free space in bank 0. Where do you learn this kind of stuff?
The only downside would be that the routine in the added ROM bank doesn't have access to the data in the ROM bank that was originally switched in. But that's probably not much of an issue, as you could put a copy of that data in the added ROM bank.
The problem with that approach is that you have to set up all the values in the startup routine and can't change them later on. You can do it that way, but it won't look good. If you want to colorize a game properly, you have to change values at runtime.
It really depends on the game. Simple games like Dr. Mario or Alleyway could work without changing palettes, but player will thank for palette changing between levels.
Then there is also de fade in/fade out issue, which could lead to momentary glitched screen if you do not implement it.
But it's not just about setting palettes, it also requires to edit the sprite OAM and the VRAM map tile attributes so you can set which OBJ or BG palettes the sprites and background tiles will use. And, unfortunately, there isn't an universal method, as every game was coded in a different way, so the process of intercepting and injecting code is totally different in every game.