Last active
August 10, 2019 20:39
-
-
Save nurpax/5aeaba58e359c6d040a9e0f87fa68ab9 to your computer and use it in GitHub Desktop.
zero page allocation context example for c64jasm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
create: ({}, initial) => { | |
const stack = [initial]; | |
return { | |
push: (elt) => { | |
stack.push(elt) | |
}, | |
pop: () => stack.pop(), | |
top: () => { | |
return stack[stack.length-1]; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!use "context" as zp | |
!let defaultZp = { | |
tmp0: $20, | |
sprite_idx: $22 | |
} | |
; Zeropage allocation context for macro expansion | |
!let zpctx = zp.create(defaultZp) | |
; Macro expansion will look at the 'current' zp allocation | |
; by getting the top of the zp allocation stack. | |
!macro test() { | |
!let zp = zpctx.top() | |
lda #13 | |
sta zp.tmp0 | |
ldx zp.sprite_idx | |
} | |
func: { | |
+test() | |
rts | |
} | |
;; IRQ routine -- overload default ZP slots | |
;; used by above macro. Overloading uses | |
;; a stack to save/restore whatever is currently | |
;; assigned as the ZP allocation. | |
irq_func: { | |
!! zpctx.push({ | |
tmp0: $40, ;; $40 instead of $20 here | |
sprite_idx: $42 ;; $42 instead of $22 here | |
}) | |
+test() | |
!!zpctx.pop() | |
rti | |
} | |
;; This should use defaults again | |
func2: { | |
+test() | |
rts | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment