Jump to content
IGNORED

Has anyone used a jump table pattern in VCS coding?


tschak909

Recommended Posts

Would something like this be useful in VCS code, or would the overhead be too much?

				;-------------------------------------------------------------------------------------
				;$04 - address low to jump address
				;$05 - address high to jump address
				;$06 - jump address low
				;$07 - jump address high
			        JumpEngine:
				asl ;shift bit from contents of A
				tay
				pla ;pull saved return address from stack
				sta $04 ;save to indirect	
				pla
				sta $05
				iny
				lda ($04),y ;load pointer from indirect
				sta $06 ;note that if an RTS is performed in next routine
				iny ;it will return to the execution before the sub
				lda ($04),y ;that called this routine
				sta $07
				jmp ($06) ;jump to the address we loaded

It basically allows for the following pattern:

      LDA OperMode
      JSR JumpEngine
 
      .BYTE #<DoThis, #>DoThis
      .BYTE #<DoThat,#>DoThat
      .BYTE #<AndSoOn,#>AndSoOn

-Thom

Link to comment
Share on other sites

Try:

 

1) Keep your address tables separate for High and Low, so you don't waste cycles and bytes multiplying by 2.

2) Don't bother with loading indirect pointers just to load an indirect address. Instead just store all the address and index them.

 

 

Actually I just talked about indirect jumps here and here with some sample code.

Link to comment
Share on other sites

I'm assuming that the goal was to be able to set different sets of pointers for each JSR JumpEngine encountered...the code is reading the pointers from the return addy. But in that case, the routine is still inefficient. No need to pull the address off the stack just to do an indirect read...just use the stack ram address that the return address was saved to. i.e. if you are not nesting subs, LDA($FE),Y does the same thing. However...since the data tables are directly below the JSRs, you would not be able to RTS if you wanted. Why not just use separate low and high pointer tables in two complete tables - setting the initial subgroup value for Y before you JSR?

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...