Heaven/TQA Posted October 28, 2007 Share Posted October 28, 2007 (edited) Guys, i want to jump to a subroutine with a table. and as there is no JSR (pointer) and i do not want to use JMP (pointer) what about this: check_newpos: ldx sprite_nr lda check_tabl,x pha lda check_tabh,x pha rts;jumps to desired subroutine check_continue: ... check_tabl: dta <check_pos1vs234-1,<check_pos2vs134-1,<check_pos3vs124-1,<check_pos4vs123-1 check_tabh: dta >check_pos1vs234-1,>check_pos2vs134-1,>check_pos3vs124-1,>check_pos4vs123-1 now just as i am not sure...is this correct? esp. the subroutines with "-1" on stack? and what happens if the subroutine returns with RTS...does it continue to the check_continue? or to the main code where the jsr check_newpos is performed? Edited October 28, 2007 by Heaven/TQA Quote Link to comment Share on other sites More sharing options...
DEBRO Posted October 28, 2007 Share Posted October 28, 2007 Guys, i want to jump to a subroutine with a table. and as there is no JSR (pointer) and i do not want to use JMP (pointer) what about this:This is legal. IIRC HSW does this in Yar's Revenge and/or E.T. Now if the subroutine has a RTS then the CPU will act as normal...meaning it will return to the location on the stack. How do you get to this routine to begin with? Do you JSR into it? If so then the RTS in the next subroutine should return back to the original caller. If not then the RTS would probably crash the program or give undesired results. Why don't you want to use JMP (pointer)? I hope I understood the question and this is what you're looking for. Quote Link to comment Share on other sites More sharing options...
kenfused Posted October 28, 2007 Share Posted October 28, 2007 Guys, i want to jump to a subroutine with a table. and as there is no JSR (pointer) and i do not want to use JMP (pointer) what about this: When you JSR to this routine you are pushing the return address on the stack. Your routine effectively does a jump, so when it hits a rts it will go back to the instruction after where you first did the JSR. This is legal. IIRC HSW does this in Yar's Revenge and/or E.T. Now if the subroutine has a RTS then the CPU will act as normal...meaning it will return to the location on the stack. How do you get to this routine to begin with? Do you JSR into it? If so then the RTS in the next subroutine should return back to the original caller. If not then the RTS would probably crash the program or give undesired results. Why don't you want to use JMP (pointer)? I hope I understood the question and this is what you're looking for. I assume he isn't using JMP (pointer) because he is using a table based on "x" on which routine to call. JMP also has the disadvantage in the bug if the location containing the address cannot cross a page boundary although that isn't too had to work around. Quote Link to comment Share on other sites More sharing options...
supercat Posted October 28, 2007 Share Posted October 28, 2007 How do you get to this routine to begin with? Do you JSR into it? If so then the RTS in the next subroutine should return back to the original caller. If not then the RTS would probably crash the program or give undesired results. If the code you're PHA/RTS'ing to will do an RTS itself, then something should have JSR'ed the PHA/RTS code. If the code doesn't do an RTS, but just jumps back into the mainline, then one should just JMP the PHA/RTS code or else include it in-line. Why don't you want to use JMP (pointer)? The PHA/RTS approach requires two free bytes on the stack; the JMP (ind) requires two free bytes somewhere else. In some cases, one or the other may be easier to come by. The PHA/RTS approach is also a tiny bit smaller. JMP also has the disadvantage in the bug if the location containing the address cannot cross a page boundary although that isn't too had to work around. Since none of the RAM on the 2600 crosses a page boundary, I don't see that as a problem. Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted October 28, 2007 Author Share Posted October 28, 2007 yeah. i want to use a table to jump to a desired subroutine...as i am on A8 stack/memory is not a major issue here... thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.