mirror of
https://github.com/a2-4am/4cade.git
synced 2024-06-27 03:29:30 +00:00
396 lines
9.6 KiB
Plaintext
396 lines
9.6 KiB
Plaintext
;license:MIT
|
|
;(c) 2019-2022 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
|
|
dithermasks = $8500 ; $58 bytes
|
|
evenrow_masks = dithermasks
|
|
oddrow_masks = dithermasks+2
|
|
no_masks = dithermasks+44
|
|
Coordinates1Bit= $8600 ; $3481 bytes ($3480 on disk + 1 byte EOF marker)
|
|
EndCoordinates1Bit=Coordinates1Bit+$3480
|
|
|
|
!source "src/fx/macros.a"
|
|
|
|
!macro BUILD_SPARSE_BITMASKS_1BIT {
|
|
; 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 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
|
|
; data file must contain this EOF marker
|
|
;lda #$80
|
|
;sta EndCoordinates1Bit
|
|
}
|
|
|
|
!macro FX_REVERSE_1BIT {
|
|
ldy #0 ; <Coordinates1Bit
|
|
sty $f0
|
|
lda #>Coordinates1Bit
|
|
sta $f1
|
|
lda #<(EndCoordinates1Bit - 2)
|
|
sta $f2
|
|
lda #>(EndCoordinates1Bit - 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 .target {
|
|
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 .target
|
|
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
|
|
aslmod4 jsr aslmod
|
|
aslmod3 jsr aslmod
|
|
aslmod2 jsr aslmod
|
|
aslmod 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_1BIT
|
|
+COPY_TO_0 start, end
|
|
jmp InputLoop
|
|
start
|
|
!pseudopc 0 {
|
|
Exit1Bit rts
|
|
InputLoop
|
|
ldy #0
|
|
input=*+1
|
|
ldx .coords ; first value: HGR row (only 0..95 will be in input array)
|
|
bmi Exit1Bit ; if > 127 then we're done
|
|
+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
|
|
}
|
|
|
|
!macro FX_PRECOMPUTED_1BIT_DITHER .coords, .endcoords {
|
|
+BUILD_DITHER_MASKS dithermasks
|
|
+BUILD_HGR_LOOKUP_TABLES hgrlo, hgr1hi
|
|
+BUILD_HGR_MIRROR_LOOKUP_TABLES hgrlomirror, hgr1himirror
|
|
+BUILD_MIRROR_COLS mirror_cols
|
|
+BUILD_SPARSE_BITMASKS_1BIT
|
|
|
|
; phase 1 - in reverse, with additional masking
|
|
+COPY_TO_0 start, end
|
|
|
|
; set up starting coordinate for reading coordinates in reverse order
|
|
+LDADDR .endcoords-2
|
|
sta <input
|
|
sty <input+1
|
|
|
|
; set up EOF marker to stop reading coordinates in reverse order
|
|
lda #$80
|
|
sta .coords-2
|
|
|
|
; set up logic to advance to next coordinates in reverse order
|
|
ldx #(next2_end-next2_start-1)
|
|
- lda next2_start, x
|
|
sta <next, x
|
|
dex
|
|
bpl -
|
|
|
|
jsr InputLoop
|
|
|
|
bit KBD
|
|
bmi start
|
|
|
|
; phase 2 - in order, without additional masking
|
|
+COPY_TO_0 start, end
|
|
|
|
; redirect additional masking pointers to an array that contains #$FFs (so no masking)
|
|
lda #<no_masks
|
|
sta <evenrow_ptr
|
|
sta <oddrow_ptr
|
|
|
|
jmp InputLoop
|
|
start
|
|
!pseudopc 0 {
|
|
Exit1Bit rts
|
|
evenrow_ptr
|
|
!word evenrow_masks
|
|
oddrow_ptr
|
|
!word oddrow_masks
|
|
InputLoop
|
|
ldy #0
|
|
input=*+1
|
|
ldx .coords ; first value: HGR row (only 0..95 will be in input array)
|
|
bmi Exit1Bit ; if > 127 then we're done
|
|
+ROW_X_TO_BASE_ADDRESSES
|
|
+ROW_X_TO_MIRROR_ADDRESSES
|
|
|
|
iny
|
|
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
|
|
and (<evenrow_ptr), y
|
|
eor (<dest1), y
|
|
dest1=*+1
|
|
sta $FDFD, y
|
|
src2=*+1
|
|
lda $FDFD, y
|
|
eor (<dest2), y
|
|
and copymasks, x
|
|
and (<oddrow_ptr), y
|
|
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_DITHER src1, dest1, mirror_copymasks, evenrow_ptr
|
|
+COPY_BIT_DITHER src2, dest2, mirror_copymasks, oddrow_ptr
|
|
|
|
; 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
|
|
and (<oddrow_ptr), y
|
|
eor (<mirror_dest1), y
|
|
mirror_dest1=*+1
|
|
sta $FDFD, y
|
|
mirror_src2=*+1
|
|
lda $FDFD, y
|
|
eor (<mirror_dest2), y
|
|
and mirror_copymasks, x
|
|
and (<evenrow_ptr), y
|
|
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_DITHER mirror_src1, mirror_dest1, copymasks, oddrow_ptr
|
|
+COPY_BIT_DITHER mirror_src2, mirror_dest2, copymasks, evenrow_ptr
|
|
|
|
next
|
|
inc <input
|
|
inc <input
|
|
bne +
|
|
bit KBD
|
|
bmi ++
|
|
inc <input+1
|
|
+ jmp InputLoop
|
|
++ rts
|
|
}
|
|
end
|
|
|
|
next2_start
|
|
!pseudopc next {
|
|
lda <input
|
|
php
|
|
dec <input
|
|
dec <input
|
|
plp
|
|
bne +
|
|
dec <input+1
|
|
bit KBD
|
|
bmi ++
|
|
+ jmp InputLoop
|
|
++ rts
|
|
}
|
|
next2_end
|
|
}
|