2014-08-29 19:19:19 +00:00
|
|
|
;
|
|
|
|
; macros.s
|
|
|
|
; Generally useful macros for 6502 code
|
|
|
|
;
|
|
|
|
; Created by Quinn Dunki on 8/15/14.
|
|
|
|
; Copyright (c) 2014 One Girl, One Laptop Productions. All rights reserved.
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
; Macros
|
|
|
|
|
|
|
|
.macro SETSWITCH name ; Sets the named softswitch (assumes write method)
|
|
|
|
sta name
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro SAVE_AXY ; Saves all registers
|
|
|
|
pha
|
2014-10-02 21:59:13 +00:00
|
|
|
phx
|
|
|
|
phy
|
2014-08-29 19:19:19 +00:00
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro RESTORE_AXY ; Restores all registers
|
2014-10-02 21:59:13 +00:00
|
|
|
ply
|
|
|
|
plx
|
2014-08-29 19:19:19 +00:00
|
|
|
pla
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro SAVE_AY ; Saves accumulator and Y index
|
|
|
|
pha
|
2014-10-02 21:59:13 +00:00
|
|
|
phy
|
2014-08-29 19:19:19 +00:00
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro RESTORE_AY ; Restores accumulator and Y index
|
2014-10-02 21:59:13 +00:00
|
|
|
ply
|
2014-08-29 19:19:19 +00:00
|
|
|
pla
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro SAVE_AX ; Saves accumulator and X index
|
|
|
|
pha
|
2014-10-02 21:59:13 +00:00
|
|
|
phx
|
2014-08-29 19:19:19 +00:00
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro RESTORE_AX ; Restores accumulator and X index
|
2014-10-02 21:59:13 +00:00
|
|
|
plx
|
2014-08-29 19:19:19 +00:00
|
|
|
pla
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
2014-09-29 20:45:46 +00:00
|
|
|
.macro SAVE_XY ; Saves X and Y index
|
|
|
|
phx
|
|
|
|
phy
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro RESTORE_XY ; Restores X and Y index
|
|
|
|
ply
|
|
|
|
plx
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
2014-08-29 19:19:19 +00:00
|
|
|
.macro SAVE_ZPP ; Saves Zero Page locations we use for parameters
|
|
|
|
lda PARAM0
|
|
|
|
pha
|
|
|
|
lda PARAM1
|
|
|
|
pha
|
|
|
|
lda PARAM2
|
|
|
|
pha
|
|
|
|
lda PARAM3
|
|
|
|
pha
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro RESTORE_ZPP ; Restores Zero Page locations we use for parameters
|
|
|
|
pla
|
|
|
|
sta PARAM3
|
|
|
|
pla
|
|
|
|
sta PARAM2
|
|
|
|
pla
|
|
|
|
sta PARAM1
|
|
|
|
pla
|
|
|
|
sta PARAM0
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro SAVE_ZPS ; Saves Zero Page locations we use for scratch
|
|
|
|
lda SCRATCH0
|
|
|
|
pha
|
|
|
|
lda SCRATCH1
|
|
|
|
pha
|
2018-02-28 20:43:14 +00:00
|
|
|
lda SCRATCH2
|
|
|
|
pha
|
2014-08-29 19:19:19 +00:00
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro RESTORE_ZPS ; Restores Zero Page locations we use for scratch
|
2018-02-28 20:43:14 +00:00
|
|
|
pla
|
|
|
|
sta SCRATCH2
|
2014-08-29 19:19:19 +00:00
|
|
|
pla
|
|
|
|
sta SCRATCH1
|
|
|
|
pla
|
|
|
|
sta SCRATCH0
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
2014-09-21 20:08:41 +00:00
|
|
|
.macro PARAM16 addr
|
|
|
|
lda #<addr
|
|
|
|
sta PARAM0
|
|
|
|
lda #>addr
|
|
|
|
sta PARAM1
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro CALL16 func,addr
|
|
|
|
PARAM16 addr
|
|
|
|
jsr func
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
2014-08-29 19:19:19 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
; Rendering macros
|
|
|
|
;
|
|
|
|
|
2014-09-29 20:45:46 +00:00
|
|
|
|
|
|
|
.macro LDY_AVIEW
|
|
|
|
asl ; Find our new view record
|
2014-09-01 18:18:36 +00:00
|
|
|
asl
|
|
|
|
asl
|
|
|
|
asl ; Records are 16 bytes wide
|
2014-08-29 19:19:19 +00:00
|
|
|
tay
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
2014-09-29 20:45:46 +00:00
|
|
|
.macro LDY_ACTIVEVIEW
|
|
|
|
lda WG_ACTIVEVIEW ; Find our new view record
|
|
|
|
LDY_AVIEW
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
2014-08-29 19:19:19 +00:00
|
|
|
.macro LDX_ACTIVEVIEW
|
|
|
|
lda WG_ACTIVEVIEW ; Find our new view record
|
|
|
|
asl
|
|
|
|
asl
|
2014-09-01 18:18:36 +00:00
|
|
|
asl
|
2014-09-06 03:32:16 +00:00
|
|
|
asl ; Records are 16 bytes wide
|
|
|
|
tax
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro LDY_FOCUSVIEW
|
|
|
|
lda WG_FOCUSVIEW ; Find our new view record
|
2014-09-29 20:45:46 +00:00
|
|
|
LDY_AVIEW
|
2014-08-29 19:19:19 +00:00
|
|
|
.endmacro
|
|
|
|
|
|
|
|
|
|
|
|
.macro VBL_SYNC ; Synchronize with vertical blanking
|
|
|
|
lda #$80
|
2014-09-25 00:03:37 +00:00
|
|
|
;macroWaitVBLToFinish:
|
|
|
|
; bit RDVBLBAR
|
|
|
|
; bmi macroWaitVBLToFinish
|
|
|
|
@macroWaitVBLToStart:
|
|
|
|
; bit RDVBLBAR
|
|
|
|
; bpl @macroWaitVBLToStart
|
2014-08-29 19:19:19 +00:00
|
|
|
.endmacro
|