push/pop:
Code: Select all
.macro push a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15
.ifnblank a0
.if .xmatch({a0},p) .or .xmatch({a0},P)
php
.else
.if .match({a0},x)
txa
.elseif .match({a0},y)
tya
.elseif .match(.left(1,{a0}),=)
lda #>(.right(.tcount({a0})-1,{a0}))
pha
lda #<(.right(.tcount({a0})-1,{a0}))
.elseif !(.match({a0},a))
lda a0
.endif
pha
.endif
push a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15
.endif
.endmacro
.macro pop a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15
.ifnblank a0
pop a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15
.if .xmatch({a0},p) .or .xmatch({a0},P)
plp
.else
pla
.if .match({a0},x)
tax
.elseif .match({a0},y)
tay
.elseif !(.match({a0},a))
sta a0
.endif
.endif
.endif
.endmacro
Code: Select all
push A,X,Y,somevar
pop A,X,Y,somevar
Also, push accepts regular immediate (8-bit) arguments but also 'absolute' arguments with =: one can push absolute addresses, and those addresses are pushed in the same order that jsr and brk does. So the following is a slow and convoluted way to jump at somelabel:
Code: Select all
; using rts
push =somelabel-1
rts
; using rti
push =somelabel, P
rti
Code: Select all
.macro mov dest, src
lda src
sta dest
.endmacro
.macro movw dest, src
.local sepd, seps
sepd .set 0
seps .set 0
.if .match({.right(2,{dest})},{,x}) .or .match({.right(2,{dest})},{,y})
sepd .set 2
.endif
.if .match({.right(2,{src})},{,x}) .or .match({.right(2,{src})},{,y})
seps .set 2
.endif
.if .match(.left(1, {src}),#)
mov {.left(.tcount({dest})-sepd,dest)+0 .right(sepd,dest)}, #<(.right(.tcount({src})-1,{src}))
mov {.left(.tcount({dest})-sepd,dest)+1 .right(sepd,dest)}, #>(.right(.tcount({src})-1,{src}))
.else
mov {.left(.tcount({dest})-sepd,dest)+0 .right(sepd,dest)}, {.left(.tcount({src})-seps,src)+0 .right(seps,src)}
mov {.left(.tcount({dest})-sepd,dest)+1 .right(sepd,dest)}, {.left(.tcount({src})-seps,src)+1 .right(seps,src)}
.endif
.endmacro
Code: Select all
movw {$4000,X}, {APU_virtualregs,X}