+grafixbmp Posted July 19, 2023 Share Posted July 19, 2023 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 Quote Link to comment Share on other sites More sharing options...
explorer Posted July 19, 2023 Share Posted July 19, 2023 The rts 6502 need #(continue_from_routine-1) pushed in the stack. Quote Link to comment Share on other sites More sharing options...
+Dave C Posted July 19, 2023 Share Posted July 19, 2023 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. 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.