;; This "subroutine" acts as a handler to be able to use variable ;; addresses as a subroutine. You can't JSR to a (variable) in 6502 ;; assembly, but you can JSR to a static label, which in turn jumps ;; to the (variable) address. If the routine at that address ends ;; in a RTS, it's handled as the RTS that belongs to the static ;; subroutine. This simulates a variable subroutine, also called a ;; "trampoline" in the NESmaker base scripts. doTemp16: JMP (temp16) ;; Usage: LDA low_byte_of_subroutine_address STA temp16 LDA high_byte_of_subroutine_address STA temp16+1 JSR doTemp16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; The following adaptation can be used if you need to call a subroutine in a ;; switchable bank, from another switchable bank. For example, to call ;; "doBank1Subroutine" from bank 2: ;; in the static bank: doTemp16: JMP (temp16) doTemp16inBankY: LDA currentBank STA prevBank JSR doBankswitchY JSR doTemp16 LDY prevBank JSR doBankswitchY RTS ;; in Bank 1: doBank1Subroutine: ;; (subroutine stuff here) RTS ;; in Bank 2: LDA #doBank1Subroutine STA temp16+1 LDY #1 JSR doTemp16inBankY