pitch-dark/src/macros.a

64 lines
1.3 KiB
Plaintext
Raw Normal View History

2018-04-15 16:29:24 +00:00
;license:MIT
;(c) 2018 by 4am
;
; common assembler macros
;
2018-04-15 16:36:11 +00:00
; for functions that take parameters on the stack
; set (PARAM) to point to the parameters and
; move the stack pointer to the first byte after the parameters
; clobbers A,X
2018-03-24 19:28:55 +00:00
!macro PARAMS_ON_STACK .bytes {
pla
sta PARAM
plx
stx PARAM+1
lda #.bytes
clc
adc PARAM
bcc +
inx
+ phx
pha
}
2018-03-29 02:49:51 +00:00
2018-04-15 16:36:11 +00:00
; for functions that take parameters on the stack
; load a 16-bit value from the parameters on the stack into A (low) and Y (high)
; (assumes PARAMS_ON_STACK was used first)
!macro LDPARAM .offset {
ldy #.offset+1
lda (PARAM),y
pha
dey
lda (PARAM),y
ply
}
; load the address of .ptr into A (low) and Y (high)
2018-03-29 02:49:51 +00:00
!macro LDADDR .ptr {
lda #<.ptr
ldy #>.ptr
}
2018-04-15 16:36:11 +00:00
; load a 16-bit value into A (low) and Y (high)
2018-03-29 02:49:51 +00:00
!macro LDAY .ptr {
lda .ptr
ldy .ptr+1
}
2018-04-15 16:36:11 +00:00
; store a 16-bit value from A (low) and Y (high)
2018-03-29 02:49:51 +00:00
!macro STAY .ptr {
sta .ptr
sty .ptr+1
}
2018-04-18 02:28:22 +00:00
2018-07-06 22:29:15 +00:00
; use BIT to swallow the following 1-byte opcode
!macro HIDE_NEXT_BYTE {
!byte $24
}
2018-04-18 02:28:22 +00:00
; use BIT to swallow the following 2-byte opcode
!macro HIDE_NEXT_2_BYTES {
!byte $2C
}