4cade/src/fx/macros.shr.a

232 lines
5.1 KiB
Plaintext

;license:MIT
;(c) 2021 by 4am
!macro BUILD_SHR_LOOKUP_TABLES .lo, .hi {
; in: none
; out: X=0
; Z=1
ldx #$C8
lda #$60
ldy #$9C
- sta .lo-1, x
!if .hi < $100 {
sty .hi-1, x
} else {
pha
tya
sta .hi-1, x
pla
}
sec
sbc #$A0
bcs +
dey
+ dex
bne -
}
!macro BUILD_SHR_REVERSE_LOOKUP_TABLES .lo, .hi {
; in: none
; out: X=0
; Z=1
ldx #$C8
lda #$00
ldy #$20
- sta .lo-1, x
!if .hi < $100 {
sty .hi-1, x
} else {
pha
tya
sta .hi-1, x
pla
}
clc
adc #$A0
bcc +
iny
+ dex
bne -
}
!macro COPY_SCB_AND_PALETTES {
; in: X=0 /!\
; out: X=0
; Z=1
; WRITEAUXMEM active
sta $C005
- lda $9D00, x
sta $9D00, x
lda $9E00, x
sta $9E00, x
lda $9F00, x
sta $9F00, x
inx
bne -
}
!macro BUILD_SHR_MIRROR_ROWS_AND_COLS .mirror_rows, .mirror_cols {
; out: X=0
; Z=1
ldx #$C7
ldy #$00
- tya
sta .mirror_cols-$28, x
sta .mirror_rows-1, x
iny
dex
bne -
}
!macro SHR_COPY_TO_STAGE_2 {
; in: X=0 /!\
; out: X=0
; Z=1
; WRITEMAINMEM active
+WRITE_MAIN
- lda $A000, x
sta $9D00, x
lda $A100, x
sta $9E00, x
inx
bne -
}
!macro SHR_RESTORE_FROM_STAGE_2 {
; out: X=0
; Z=1
ldx #$00
- lda $9D00, x ; copy main code back to $A000
sta $A000, x ; so it can be called again if necessary
lda $9E00, x
sta $A100, x
inx
bne -
}
!macro LOAD_SHR_COORDINATES_AT .coords, .filename, .scratch {
; out: WRITEMAINMEM active
; LC RAM2 active and read/write
ldx .filename ; LOAD_FILE_AT macro destroys pathname
- lda .filename, x ; so we need to make a copy
sta .scratch, x
dex
bpl -
+READ_RAM2_WRITE_RAM2
+LOAD_FILE_AT .scratch, .coords
}
!macro SHR_STAGE_1 .shrlo, .shrhi, .mirror_rows, .mirror_cols {
+BUILD_SHR_MIRROR_ROWS_AND_COLS .mirror_rows, .mirror_cols
;X=0
+BUILD_SHR_LOOKUP_TABLES .shrlo, .shrhi
;X=0
+COPY_SCB_AND_PALETTES
;X=0
;WRITEAUXMEM active
+SHR_COPY_TO_STAGE_2
}
!macro SHR_STAGE_2 .startzp, .endzp {
+COPY_TO_0 .startzp, .endzp
+WRITE_AUX
jsr $0
+WRITE_MAIN
+SHR_RESTORE_FROM_STAGE_2
+READ_RAM1_WRITE_RAM1
}
!macro SHR_STAGE_3 .coords, .shrlo, .shrhi, .mirror_rows, .mirror_cols {
input ldx .coords ; first value: SHR row (only 0..99 will be in input array)
bmi exit ; if > 127 then we're done
ldy #1
lda (<input+1), y
tay
; main 2x2 block in top-left quadrant
jsr copy_block_from_x
; corresponding 2x2 block in top-right quadrant
lda .mirror_cols, y
tay
jsr copy_block
; corresponding 2x2 block in bottom-right quadrant
lda .mirror_rows, x
tax
jsr copy_block_from_x
; corresponding 2x2 block in bottom-left quadrant
lda .mirror_cols, y
tay
jsr copy_block
inc <input+1
inc <input+1
bne input
inc <input+2
bit $C000
bpl input
copy_block_from_x
lda .shrlo, x
sta <src1+1
lda .shrhi, x
sta <src1+2
lda .shrlo+1, x
sta <src2+1
lda .shrhi+1, x
sta <src2+2
copy_block
src1 lda $FD00, y ; SMC high byte
sta (src1+1), y
src2 lda $FD00, y ; SMC high byte
sta (src2+1), y
exit rts
}
!macro SHR_REVERSE .coords {
.length=$1F40
ldy #<.coords
sty $f0
lda #>.coords
sta $f1
lda #<(.coords + .length - 2)
sta $f2
lda #>(.coords + .length - 2)
sta $f3
clc
!byte $24
- sec
-- lda ($f0), y
pha
lda ($f2), y
sta ($f0), y
pla
sta ($f2), y
iny
bcc -
ldy #0
!byte $24
- clc
inc $f0
bne +
inc $f1
+ lda $f1
eor #>(.coords + .length/2)
bne +
lda $f0
eor #<(.coords + .length/2)
beq ++
+ lda $f2
bne +
dec $f3
+ dec $f2
bcs -
bcc -- ; always
++
}