I'd like to be able to jump to certain subroutines (e.g. different enemy updates) in my game using indirect addressing in order to avoid wasteful if-else checks. So far, I've been using the JSR instruction to jump to subroutines; however, that instruction appears to support absolute addressing only.
I'm thinking it's possible to use the JMP instruction (which supports indirect addressing), but that would require pushing the address - 1 of the following instruction onto the stack in order to "play nice" with the RTS instruction that terminates the subroutine, wouldn't it?
I'm afraid of getting really nasty "off by one" errors if I push the wrong address onto the stack. What is the proper way to set up a correct jump?
Or is there a better method altogether?
I'm thinking it's possible to use the JMP instruction (which supports indirect addressing), but that would require pushing the address - 1 of the following instruction onto the stack in order to "play nice" with the RTS instruction that terminates the subroutine, wouldn't it?
I'm afraid of getting really nasty "off by one" errors if I push the wrong address onto the stack. What is the proper way to set up a correct jump?
Or is there a better method altogether?