Jump to content
IGNORED

random brainstorming what if code


grafixbmp

Recommended Posts

Just had a little thought about something and wondered if anyone has done this before or if it would ever be useful at all. so with standard subroutines they are absolute but with jumps they are either absolute or variable (indirect) so with some extra code we should be able to have indirect subroutines. I sudo coded a brief example of what I mean and wondered if it had any merit. My syntax may have errors but  hopefully the idea gets across.

 

	Indirect_Subroutine = $80	

	I_S = $81

	;some code


	lda <#subroutine_B

	sta Indirect_Subroutine

	lda >#subroutine_B

	sta Indirect_Subroutine+1


	; some more code


	
	lda <#continue_from_routine

	pha

	lda >#continue_from_routine

	pha

	jmp (Indirect_Subroutine)

continue_from_routine


	;some more code



subroutine_A

	;do stuff

	rts

subroutine_B

	;do_stuff

	rts

subroutine_C

	;do_stuff

	rts

 

Link to comment
Share on other sites

Rather than indirect jump you can also push the address you want to jump to onto the stack then rts. This is one of the techniques used in bank switching. It is a simple idea that I found mind blowing coming from higher level languages because you just get so used to thinking about returning to your caller not returning to something you want to call.

 

I have some more recent code that does primitive multitasking. There are various routines that may not complete before the vblank routine ends so I have them all periodically jsr to a routine called “wait” that ensures we preserve the stack and jumps back to the rest of the code base so we can draw the screen, etc. Then I have a “continue” routine that does an rts back to the address we waited from. I am 1000% certain these are not novel techniques.

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