Dan Moos wrote:
Correct me if I'm wrong, but if I use the mentioned method of JSRing to a subroutine that has an indirect JMP in it, I can RTS just as if I'd never had to use the extra JMP, correct? My understanding of how those commands work (stack and all) says yes, but just checking.
Yes, because the JMP does not disturb the return address on the stack, or its position relative to the stack pointer. Are you using
self-modifying code in the subroutine with the indirect JMP? Another way would be something like
Code:
LDA #>(ReturnAddr-1) ; (High byte, but remember that the
PHA ; RTS increments it; hence the "-1".)
LDA #<(ReturnAddr-1) ; (Low byte.)
PHA
JMP (TableAddr,X)
ReturnAddr:
Which you'll probably want to put in a macro. If you don't want the return address label, you could replace the LDA#'s with $+8 and $+5 (or modify the numbers per what your assembler returns for the $ (or *), whether it's the address of the first byte of the instruction or that of the operand.
I added a little more to my post above. I'll add even more now. Yes, the '816 adds the JSR (abs,X) capability; but even if it didn't and you wanted to do the LDA#, PHA, LDA#, PHA above, the '816 can do those four lines in a single 3-byte, 6-clock instruction PER "Push Effective Relative address" which is always 16-bit regardless of the size you have the accumulator and index registers set to, and it does not affect the processor registers (except the stack pointer of course). It is useful in writing self-relocatable (address-agnostic) code.
Congratulations on getting a big routine working on first try! It's always a relief, isn't it? Exciting too.