4cade/src/macros.a

122 lines
2.3 KiB
Plaintext

;license:MIT
;(c) 2018-9 by 4am
;
; common assembler macros (6502 compatible)
;
; 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,Y
!macro PARAMS_ON_STACK .bytes {
pla
sta PARAM
pla
tax
stx PARAM+1
lda #.bytes
clc
adc PARAM
tay
bcc +
inx
+ txa
pha
tya
pha
}
; 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
lda (PARAM),y
pha
iny
lda (PARAM),y
tay
pla
}
; load the address of .ptr into A (low) and Y (high)
!macro LDADDR .ptr {
lda #<.ptr
ldy #>.ptr
}
; load a 16-bit value into A (low) and Y (high)
!macro LDAY .ptr {
lda .ptr
ldy .ptr+1
}
; store a 16-bit value from A (low) and Y (high)
!macro STAY .ptr {
sta .ptr
sty .ptr+1
}
; use BIT to swallow the following 1-byte opcode
!macro HIDE_NEXT_BYTE {
!byte $24
}
; use BIT to swallow the following 2-byte opcode
!macro HIDE_NEXT_2_BYTES {
!byte $2C
}
; various language card configurations
!macro READ_RAM1_WRITE_RAM1 {
bit $C08B
bit $C08B
}
!macro READ_RAM2_WRITE_RAM2 {
bit $C083
bit $C083
}
!macro READ_ROM_WRITE_RAM1 {
bit $C089
bit $C089
}
!macro READ_ROM_WRITE_RAM2 {
bit $C081
bit $C081
}
!macro READ_ROM_NO_WRITE {
bit $C082
}
!macro LOAD_FILE .subdirectory, .filename {
+LDADDR .subdirectory
jsr SetPath
+LDAY .filename
jsr AddToPath
jsr LoadFile
}
!macro LOAD_PATH .subdirectory {
+LDADDR .subdirectory
jsr SetPath
}
!macro LOAD_FILE_IMM .filename {
+LDAY .filename
jsr AddToPath
jsr LoadFile
}
!macro LOW_ASCII_TO_LOWER {
cmp #$41
bcc +
cmp #$5B
bcs +
ora #$20
+
}