mirror of
https://github.com/a2-4am/4cade.git
synced 2024-10-04 11:59:16 +00:00
339 lines
7.9 KiB
Plaintext
339 lines
7.9 KiB
Plaintext
;license:MIT
|
|
;(c) 2019 by 4am
|
|
;
|
|
copymasks = $0200 ; $100 bytes but sparse, index is 0..6 but in high 3 bits, so $00, $20, $40, $60, $80, $A0, $C0
|
|
mirror_copymasks = $0201
|
|
hgrlo = $0300 ; $C0 bytes
|
|
hgrlomirror = $BD40 ; $C0 bytes
|
|
mirror_cols = $BE00 ; $28 bytes
|
|
hgr1hi = $BE40 ; $C0 bytes
|
|
hgr1himirror = $BF40 ; $C0 bytes
|
|
Coordinates1Bit= $8800 ; $3481 bytes ($3480 on disk + 1 byte EOF marker)
|
|
|
|
!source "src/fx/macros.a"
|
|
|
|
!macro BUILD_MIRROR_COLS .mirror_cols {
|
|
; build lookup table to get $27-y for y in $00..$27
|
|
ldx #$27
|
|
ldy #$00
|
|
- tya
|
|
sta .mirror_cols, x
|
|
iny
|
|
dex
|
|
bpl -
|
|
}
|
|
|
|
!macro BUILD_SPARSE_BITMASKS .copymasks, .mirror_copymasks {
|
|
; build sparse lookup tables for bitmasks
|
|
lda #%10000001
|
|
sta .copymasks
|
|
sta .mirror_copymasks+$C0
|
|
|
|
lda #%10000010
|
|
sta .copymasks+$20
|
|
sta .mirror_copymasks+$A0
|
|
|
|
lda #%10000100
|
|
sta .copymasks+$40
|
|
sta .mirror_copymasks+$80
|
|
|
|
lda #%10001000
|
|
sta .copymasks+$60
|
|
sta .mirror_copymasks+$60
|
|
|
|
lda #%10010000
|
|
sta .copymasks+$80
|
|
sta .mirror_copymasks+$40
|
|
|
|
lda #%10100000
|
|
sta .copymasks+$A0
|
|
sta .mirror_copymasks+$20
|
|
|
|
lda #%11000000
|
|
sta .copymasks+$C0
|
|
sta .mirror_copymasks
|
|
}
|
|
|
|
!macro ROW_X_TO_BASE_ADDRESSES {
|
|
lda hgrlo, x
|
|
sta <dest1
|
|
sta <src1
|
|
lda hgr1hi, x
|
|
sta <dest1+1
|
|
eor #$60
|
|
sta <src1+1
|
|
lda hgrlo+1, x
|
|
sta <dest2
|
|
sta <src2
|
|
lda hgr1hi+1, x
|
|
sta <dest2+1
|
|
eor #$60
|
|
sta <src2+1
|
|
}
|
|
|
|
!macro ROW_X_TO_MIRROR_ADDRESSES {
|
|
lda hgrlomirror, x
|
|
sta <mirror_dest1
|
|
sta <mirror_src1
|
|
lda hgr1himirror, x
|
|
sta <mirror_dest1+1
|
|
eor #$60
|
|
sta <mirror_src1+1
|
|
lda hgrlomirror+1, x
|
|
sta <mirror_dest2
|
|
sta <mirror_src2
|
|
lda hgr1himirror+1, x
|
|
sta <mirror_dest2+1
|
|
eor #$60
|
|
sta <mirror_src2+1
|
|
}
|
|
|
|
!macro HIGH_3_LOW_5 .input {
|
|
and #%11100000 ; second value: high 3 bits = index into tables to find bitmasks
|
|
tax
|
|
eor (<.input), y ; second value: low 5 bits = byte offset within the row (implicitly "and #%00011111")
|
|
tay
|
|
}
|
|
|
|
!macro INC_INPUT_AND_LOOP .loop {
|
|
inc <input
|
|
beq +
|
|
jmp .loop
|
|
+ bit $c000
|
|
bmi +
|
|
inc <input+1
|
|
jmp .loop
|
|
+ rts
|
|
}
|
|
|
|
!macro DEC_INPUT_AND_LOOP .loop {
|
|
lda input
|
|
beq +
|
|
dec input
|
|
dec input
|
|
jmp .loop
|
|
+ dec input
|
|
dec input
|
|
dec input+1
|
|
bit $c000
|
|
bmi +
|
|
jmp .loop
|
|
+ rts
|
|
}
|
|
|
|
!macro FX_INITONCE_1BIT .CoordinatesFile, .Start {
|
|
InitOnce
|
|
bit .Start
|
|
lda #$4C
|
|
sta InitOnce
|
|
+READ_RAM2_WRITE_RAM2
|
|
+LOAD_FILE_AT .CoordinatesFile, Coordinates1Bit
|
|
+READ_RAM1_WRITE_RAM1
|
|
lda #$80
|
|
sta Coordinates1Bit + $3480
|
|
}
|
|
|
|
!macro FX_REVERSE_1BIT {
|
|
ldy #0 ; <Coordinates1Bit
|
|
sty $f0
|
|
lda #>Coordinates1Bit
|
|
sta $f1
|
|
lda #<(Coordinates1Bit + $3480 - 2)
|
|
sta $f2
|
|
lda #>(Coordinates1Bit + $3480 - 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 #>(Coordinates1Bit + $1A40)
|
|
bne +
|
|
lda $f0
|
|
eor #<(Coordinates1Bit + $1A40)
|
|
beq ++
|
|
+ lda $f2
|
|
bne +
|
|
dec $f3
|
|
+ dec $f2
|
|
bcs -
|
|
bcc -- ; always
|
|
++
|
|
}
|
|
|
|
!macro FX_RIPPLE_1BIT {
|
|
lda #2 ; <(Coordinates1Bit + 2)
|
|
sta $f0
|
|
ldy #0
|
|
sty $f1
|
|
lda #$16 ; <(Coordinates1Bit + 22)
|
|
sta $f2
|
|
sty $f3
|
|
|
|
lda #$1f
|
|
sta $ee
|
|
lda #$0d
|
|
sta $ef
|
|
|
|
lda Coordinates1Bit + 2
|
|
sta $e0
|
|
lda Coordinates1Bit + 3
|
|
sta $e1
|
|
lda Coordinates1Bit + 22
|
|
sta $e2
|
|
lda Coordinates1Bit + 23
|
|
sta $e3
|
|
|
|
--- ldx #4
|
|
-- ldy $ee, x
|
|
lda $ef, x
|
|
jsr aslmod
|
|
sty $ee, x
|
|
sta $ef, x
|
|
sty $ec
|
|
clc
|
|
adc #>Coordinates1Bit
|
|
sta $ed
|
|
ldy #0
|
|
!byte $24
|
|
- sec
|
|
lda ($ec), y
|
|
pha
|
|
lda $de, x
|
|
sta ($ec), y
|
|
pla
|
|
sta $de, x
|
|
inx
|
|
iny
|
|
bcc -
|
|
dex
|
|
dex
|
|
dex
|
|
dex
|
|
bne --
|
|
dec $ee
|
|
bne ---
|
|
dec $ef
|
|
bpl ---
|
|
bmi +++ ; always branches
|
|
aslmod
|
|
jsr +
|
|
+ cmp #$1A
|
|
bcc +
|
|
bne ++
|
|
cpy #$40
|
|
bcc +
|
|
++ iny
|
|
+ pha
|
|
tya
|
|
asl
|
|
tay
|
|
pla
|
|
rol
|
|
cmp #$34
|
|
bcc +
|
|
bne ++
|
|
cpy #$80
|
|
bcc +
|
|
++ pha
|
|
tya
|
|
sbc #$80
|
|
tay
|
|
pla
|
|
sbc #$34
|
|
+ rts
|
|
+++
|
|
}
|
|
|
|
!macro FX_PRECOMPUTED_1BIT .coords {
|
|
+BUILD_HGR_LOOKUP_TABLES hgrlo, hgr1hi
|
|
+BUILD_HGR_MIRROR_LOOKUP_TABLES hgrlomirror, hgr1himirror
|
|
+BUILD_MIRROR_COLS mirror_cols
|
|
+BUILD_SPARSE_BITMASKS copymasks, mirror_copymasks
|
|
ldx #(end-start) ; copy InputLoop code to zero page
|
|
- lda start-1, x
|
|
sta $FF, x
|
|
dex
|
|
bne -
|
|
jmp InputLoop
|
|
start
|
|
!pseudopc 0 {
|
|
Exit1Bit rts
|
|
InputLoop
|
|
ldy #0
|
|
input=*+1
|
|
lda .coords, y ; first value: HGR row (only 0..95 will be in input array)
|
|
bmi Exit1Bit ; if > 127 then we're done
|
|
tax
|
|
+ROW_X_TO_BASE_ADDRESSES
|
|
+ROW_X_TO_MIRROR_ADDRESSES
|
|
|
|
inc input
|
|
lda (input), y
|
|
+HIGH_3_LOW_5 input
|
|
|
|
; main 1x2 block in top-left quadrant
|
|
src1=*+1
|
|
lda $FDFD, y
|
|
eor (<dest1), y
|
|
and copymasks, x
|
|
eor (<dest1), y
|
|
dest1=*+1
|
|
sta $FDFD, y
|
|
src2=*+1
|
|
lda $FDFD, y
|
|
eor (<dest2), y
|
|
and copymasks, x
|
|
eor (<dest2), y
|
|
dest2=*+1
|
|
sta $FDFD, y
|
|
|
|
; corresponding 1x2 block in top-right quadrant (same row, opposite column)
|
|
lda mirror_cols, y
|
|
tay
|
|
+COPY_BIT src1, dest1, mirror_copymasks
|
|
+COPY_BIT src2, dest2, mirror_copymasks
|
|
|
|
; corresponding 1x2 block in bottom-right quadrant (opposite row, opposite column)
|
|
mirror_src1=*+1
|
|
lda $FDFD, y
|
|
eor (<mirror_dest1), y
|
|
and mirror_copymasks, x
|
|
eor (<mirror_dest1), y
|
|
mirror_dest1=*+1
|
|
sta $FDFD, y
|
|
mirror_src2=*+1
|
|
lda $FDFD, y
|
|
eor (<mirror_dest2), y
|
|
and mirror_copymasks, x
|
|
eor (<mirror_dest2), y
|
|
mirror_dest2=*+1
|
|
sta $FDFD, y
|
|
|
|
; corresponding 1x2 block in bottom-left quadrant (opposite row, original column)
|
|
lda mirror_cols, y
|
|
tay
|
|
+COPY_BIT mirror_src1, mirror_dest1, copymasks
|
|
+COPY_BIT mirror_src2, mirror_dest2, copymasks
|
|
|
|
+INC_INPUT_AND_LOOP InputLoop
|
|
}
|
|
end
|
|
!if * and 1 {
|
|
!byte 0 ;align 2 but avoids the fake allocation bug if it was aligned already
|
|
}
|
|
}
|