4cade/src/macros.a
2019-10-19 11:49:05 -04:00

156 lines
2.8 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
}
!macro LBPL .target {
bmi +
jmp .target
+
}
!macro LBNE .target {
beq +
jmp .target
+
}
!macro LBCS .target {
bcc +
jmp .target
+
}
; 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_NO_WRITE {
bit $C088
}
!macro READ_RAM1_WRITE_RAM1 {
bit $C08B
bit $C08B
}
!macro READ_RAM2_NO_WRITE {
bit $C080
}
!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 LOW_ASCII_TO_LOWER {
cmp #$41
bcc +
cmp #$5B
bcs +
ora #$20
+
}
; requires setting zpCharMask in zero page to #$FF or #$DF before use
!macro FORCE_UPPERCASE_IF_REQUIRED {
cmp #$E1
bcc +
and zpCharMask
+
}
; these are mostly for prelaunchers -- code in the main program should keep track of which bank is active to minimize code size
!macro ENABLE_ACCEL {
+READ_RAM2_NO_WRITE
jsr EnableAccelerator
+READ_ROM_NO_WRITE
}
!macro DISABLE_ACCEL {
+READ_RAM2_NO_WRITE
jsr DisableAccelerator
+READ_ROM_NO_WRITE
}
!macro GET_MACHINE_STATUS {
+READ_RAM2_NO_WRITE
lda MachineStatus
+READ_ROM_NO_WRITE
}