Why do some NES games have a bunch of JMP instructions at the beginning of a bank?
Moderator: Moderators
Why do some NES games have a bunch of JMP instructions at the beginning of a bank?
I've seen some NES games have a list of JMP instructions at the beginning of a PRG bank. These games seem to jump to these instructions from the fixed bank(s) that then jump to a subroutine in the bank. I would get this if these banks were not fixed in code (swapped bank would depend on a variable), but they seem to be loading a very specific bank. So, why don't they jump directly to the code that needs to be executed instead of going through an additional JMP instruction? Is there a reason this method is used?
Avatar is pixel art of Noah Prime from Astral Chain
-
- Posts: 1565
- Joined: Tue Feb 07, 2017 2:03 am
Re: Why do some NES games have a bunch of JMP instructions at the beginning of a bank?
that is linking.
Because when I load up Bank00.asm and assemble it, it doesn't know anything about Bank01.asm or Bank02.asm or Bank03.asm. Those wont fit into RAM. I could pay a lot more money and get a linker that handles it, but then also that would take minutes longer, and if I'm on a floppy disk and not a HDD(which cost thousands for 5MB), yeah we are looking at 10s of minutes if not 30-45 in the large case. Then Bank 02 is made by John, and Bank 03 is by Bill, so every time John or Bill change their code I don't want to have to go to their desk get a floppy copy of it, and then bring it back to my desk. Then I have to burn 3 ROMs per test not 1 ROM, so that saves a good 30 mins. And a few bucks, those EEPROMS were out..
Because when I load up Bank00.asm and assemble it, it doesn't know anything about Bank01.asm or Bank02.asm or Bank03.asm. Those wont fit into RAM. I could pay a lot more money and get a linker that handles it, but then also that would take minutes longer, and if I'm on a floppy disk and not a HDD(which cost thousands for 5MB), yeah we are looking at 10s of minutes if not 30-45 in the large case. Then Bank 02 is made by John, and Bank 03 is by Bill, so every time John or Bill change their code I don't want to have to go to their desk get a floppy copy of it, and then bring it back to my desk. Then I have to burn 3 ROMs per test not 1 ROM, so that saves a good 30 mins. And a few bucks, those EEPROMS were out..
Re: Why do some NES games have a bunch of JMP instructions at the beginning of a bank?
This is called a jump table, and there's several reasons a developer might decide to put one at the beginning of each bank.
As Oziphantom says, the developer might be dealing with limitations on how the source code gets assembled, like if the assembler doesn't support relocatable origins (which would mean each bank needs to be assembled separately, so one bank doesn't have the benefit of knowing what labels exist in other banks), or if it's too expensive (time/resources) to re-assemble the entire ROM image at once, like if the dev equipment uses multiple ROMs, one for each bank.
It might also be part of how the developer decided to handle situations where code in one bank needs to call a subroutine in another bank. They might've found it easier to say "call function 3 in bank 2", especially if you need to jsr/rts since you'd need to go through a helper routine which can restore the previous bank after the callee returns.
As Oziphantom says, the developer might be dealing with limitations on how the source code gets assembled, like if the assembler doesn't support relocatable origins (which would mean each bank needs to be assembled separately, so one bank doesn't have the benefit of knowing what labels exist in other banks), or if it's too expensive (time/resources) to re-assemble the entire ROM image at once, like if the dev equipment uses multiple ROMs, one for each bank.
It might also be part of how the developer decided to handle situations where code in one bank needs to call a subroutine in another bank. They might've found it easier to say "call function 3 in bank 2", especially if you need to jsr/rts since you'd need to go through a helper routine which can restore the previous bank after the callee returns.