Jump to content
IGNORED

Subroutine call via "RTS"


Heaven/TQA

Recommended Posts

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 by Heaven/TQA
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...