I had a few indirect jumps followed by hard coded return locations in parts of my game engine. I decided to revise this and use the well known "rts trick." The wiki pointed out you must have a subroutine that does the trick in order for the jsr to push the correct return address on the stack. However I didn't like that I'd have to jump far away from the code just to jump far away again, so I developed this macro (ca65 syntax):
Where * is the current program counter address (as calculated during assembly of your code). I wondered if anyone else has used a similar approach for their own usage of the rts trick?
Code:
.macro indirectJsr address
lda #>(*+12)
pha
lda #<(*+9)
pha
lda address+1
pha
lda address
pha
rts
.endmacro
lda #>(*+12)
pha
lda #<(*+9)
pha
lda address+1
pha
lda address
pha
rts
.endmacro
Where * is the current program counter address (as calculated during assembly of your code). I wondered if anyone else has used a similar approach for their own usage of the rts trick?