2018-08-23 20:02:48 +00:00
|
|
|
;license:MIT
|
2019-06-24 02:32:18 +00:00
|
|
|
;(c) 2018-9 by 4am
|
2018-08-23 20:02:48 +00:00
|
|
|
;
|
2018-11-10 15:08:14 +00:00
|
|
|
; common assembler macros (6502 compatible)
|
2018-08-23 20:02:48 +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
|
2018-08-30 20:30:58 +00:00
|
|
|
; clobbers A,X,Y
|
2018-08-23 20:02:48 +00:00
|
|
|
!macro PARAMS_ON_STACK .bytes {
|
|
|
|
pla
|
|
|
|
sta PARAM
|
2018-08-30 20:30:58 +00:00
|
|
|
pla
|
|
|
|
tax
|
2018-08-23 20:02:48 +00:00
|
|
|
stx PARAM+1
|
|
|
|
lda #.bytes
|
|
|
|
clc
|
|
|
|
adc PARAM
|
2018-08-30 20:30:58 +00:00
|
|
|
tay
|
2018-08-23 20:02:48 +00:00
|
|
|
bcc +
|
|
|
|
inx
|
2018-08-30 20:30:58 +00:00
|
|
|
+ txa
|
|
|
|
pha
|
|
|
|
tya
|
2018-08-23 20:02:48 +00:00
|
|
|
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 {
|
2018-08-30 20:30:58 +00:00
|
|
|
ldy #.offset
|
2018-08-23 20:02:48 +00:00
|
|
|
lda (PARAM),y
|
|
|
|
pha
|
2018-08-30 20:30:58 +00:00
|
|
|
iny
|
2018-08-23 20:02:48 +00:00
|
|
|
lda (PARAM),y
|
2018-08-30 20:30:58 +00:00
|
|
|
tay
|
|
|
|
pla
|
2018-08-23 20:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
; 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
|
|
|
|
}
|
|
|
|
|
2019-10-19 15:49:05 +00:00
|
|
|
!macro LBPL .target {
|
2019-10-18 19:41:41 +00:00
|
|
|
bmi +
|
|
|
|
jmp .target
|
|
|
|
+
|
|
|
|
}
|
|
|
|
|
2019-10-19 15:49:05 +00:00
|
|
|
!macro LBNE .target {
|
2019-10-18 19:41:41 +00:00
|
|
|
beq +
|
|
|
|
jmp .target
|
|
|
|
+
|
|
|
|
}
|
|
|
|
|
2019-10-19 15:49:05 +00:00
|
|
|
!macro LBCS .target {
|
|
|
|
bcc +
|
|
|
|
jmp .target
|
|
|
|
+
|
|
|
|
}
|
|
|
|
|
2018-08-23 20:02:48 +00:00
|
|
|
; 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
|
|
|
|
}
|
2018-08-31 04:31:54 +00:00
|
|
|
|
|
|
|
; various language card configurations
|
2019-06-27 14:55:07 +00:00
|
|
|
!macro READ_RAM1_NO_WRITE {
|
|
|
|
bit $C088
|
|
|
|
}
|
|
|
|
|
2018-08-31 04:31:54 +00:00
|
|
|
!macro READ_RAM1_WRITE_RAM1 {
|
|
|
|
bit $C08B
|
|
|
|
bit $C08B
|
|
|
|
}
|
|
|
|
|
2019-10-05 01:34:49 +00:00
|
|
|
!macro READ_RAM2_NO_WRITE {
|
|
|
|
bit $C080
|
|
|
|
}
|
|
|
|
|
2019-06-20 01:10:56 +00:00
|
|
|
!macro READ_RAM2_WRITE_RAM2 {
|
|
|
|
bit $C083
|
|
|
|
bit $C083
|
|
|
|
}
|
|
|
|
|
2018-08-31 04:31:54 +00:00
|
|
|
!macro READ_ROM_WRITE_RAM1 {
|
|
|
|
bit $C089
|
|
|
|
bit $C089
|
|
|
|
}
|
|
|
|
|
2019-06-20 01:36:49 +00:00
|
|
|
!macro READ_ROM_WRITE_RAM2 {
|
|
|
|
bit $C081
|
|
|
|
bit $C081
|
|
|
|
}
|
|
|
|
|
2018-08-31 04:31:54 +00:00
|
|
|
!macro READ_ROM_NO_WRITE {
|
|
|
|
bit $C082
|
|
|
|
}
|
2018-10-29 23:23:43 +00:00
|
|
|
|
2019-06-18 18:56:05 +00:00
|
|
|
!macro LOW_ASCII_TO_LOWER {
|
|
|
|
cmp #$41
|
|
|
|
bcc +
|
|
|
|
cmp #$5B
|
|
|
|
bcs +
|
|
|
|
ora #$20
|
|
|
|
+
|
|
|
|
}
|
2019-06-27 15:37:23 +00:00
|
|
|
|
2019-08-27 17:55:54 +00:00
|
|
|
; requires setting zpCharMask in zero page to #$FF or #$DF before use
|
|
|
|
!macro FORCE_UPPERCASE_IF_REQUIRED {
|
|
|
|
cmp #$E1
|
|
|
|
bcc +
|
|
|
|
and zpCharMask
|
|
|
|
+
|
|
|
|
}
|
2019-10-05 01:34:49 +00:00
|
|
|
|
|
|
|
; 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
|
|
|
|
}
|