4cade/src/fx/macros.a
2021-12-17 18:29:35 -05:00

188 lines
4.3 KiB
Plaintext

!ifndef _FX_MACROS_ {
!source "src/macros.a"
; .hgrlo, .hgr1hi will each be filled with $C0 bytes
; based on routine by John Brooks
; posted on comp.sys.apple2 on 2018-07-11
; https://groups.google.com/d/msg/comp.sys.apple2/v2HOfHOmeNQ/zD76fJg_BAAJ
!macro BUILD_HGR_LOOKUP_TABLES .hgrlo, .hgr1hi {
; preserves Y
ldx #0
+BUILD_HGR_LOOKUP_TABLES_X_IS_ALREADY_0 .hgrlo, .hgr1hi
}
; use this macro instead if you know X is already 0 on entry, to save 2 bytes
!macro BUILD_HGR_LOOKUP_TABLES_X_IS_ALREADY_0 .hgrlo, .hgr1hi {
; preserves Y
- txa
and #$F8
bpl +
ora #5
+ asl
bpl +
ora #5
+ asl
asl
sta .hgrlo,x
txa
and #7
rol
asl .hgrlo,x
rol
ora #$20
sta .hgr1hi,x
inx
cpx #$C0
bne -
}
; .hgrlomirror, .hgr1himirror will each be filled with $C0 bytes
!macro BUILD_HGR_MIRROR_LOOKUP_TABLES .hgrlomirror, .hgr1himirror {
ldx #$C0
ldy #0
- tya
and #$F8
bpl +
ora #5
+ asl
bpl +
ora #5
+ asl
asl
sta .hgrlomirror-1,x
tya
and #7
rol
asl .hgrlomirror-1,x
rol
ora #$20
sta .hgr1himirror-1,x
iny
dex
bne -
}
!macro HGR_CALC {
; in: A = HGR row (0x00..0xBF)
; out: A/X clobbered
; Y preserved
; ($26) points to first byte of given HGR row on hi-res page 1
; ($3C) points to same byte on hi-res page 2
; based on 'Woz Recodes Hi-Res Address Calculations'
; Apple Assembly Line vol. 7 issue 3 (December 1986)
; http://www.txbobsc.com/aal/1986/aal8612.html#a9
asl
tax
and #$F0
bpl @calc1
ora #$05
@calc1 bcc @calc2
ora #$0A
@calc2 asl
asl
sta $26
txa
and #$0E
adc #$10
asl $26
rol
sta $27
eor #$60
sta $3d
lda $26
sta $3c
}
!macro HGR_ROW_CALC {
asl
asl
asl
+HGR_CALC
}
; /!\ C must be clear before using this macro
!macro HGR_INC_WITHIN_BLOCK {
lda $27
adc #$04
sta $27
eor #$60
sta $3d
}
!macro RESET_HGR_CALC {
lda $27
sec
sbc #$20
sta $27
eor #$60
sta $3d
}
!macro COPY_BIT .src1, .dest1, .copymasks {
lda (.src1),y
eor (.dest1),y ; merge source and destination bits
and .copymasks,x ; isolate the bits to replace, zero the rest
eor (.dest1),y ; unmerge source and destination bits, leaves 'to keep' destination bits intact
sta (.dest1),y ; write the result
}
!macro COPY_BIT_ZP .src1, .dest1, .zpcopymask {
lda (.src1),y
eor (.dest1),y ; merge source and destination bits
and <.zpcopymask ; isolate the bits to replace, zero the rest
eor (.dest1),y ; unmerge source and destination bits, leaves 'to keep' destination bits intact
sta (.dest1),y ; write the result
}
!macro SWITCH_TO_MASKS .copy {
lda #<.copy
sta CopyMaskAddr
lda #>.copy
sta CopyMaskAddr+1
}
; must set N flag based on Y immediately before using these macros
; e.g. LDY, INY, DEY, TYA
!macro IS_Y_OFFSCREEN {
bpl +
sec
bcs ++
+ cpy #40
++
}
!macro BRANCH_IF_Y_IS_OFFSCREEN .target {
cpy #40
bcs .target
}
!macro LONG_BRANCH_IF_Y_IS_OFFSCREEN .target {
cpy #40
bcc +
jmp .target
+
}
!macro COPY_TO_0 .start, .end {
; out: X=0
; Z=1
ldx #(.end-.start)
- lda .start-1, x
sta $FF, x
dex
bne -
}
!macro OVERCOPY_TO_0 .start, .end {
; over-copy region to $00
; clobbers $FF
; out: X=0
; Y=last byte before start (e.g. 0 if the last instruction is JMP $0000)
ldx #(.end-.start+1)
- ldy .start-2, x
sty $FE, x
dex
bne -
}
_FX_MACROS_=*
}