2019-11-05 19:46:45 +00:00
|
|
|
;license:MIT
|
2020-09-05 23:11:29 +00:00
|
|
|
;(c) 2019-2020 by 4am
|
2019-11-05 19:46:45 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
copymasks = $0200 ; $100 bytes but sparse, index is 0..7 but in high 3 bits, so $00, $20, $40...
|
|
|
|
tmplo = $0300 ; $C0 bytes
|
|
|
|
extra_cols = $02F8 ; $08 bytes
|
|
|
|
tmphi = $BF40 ; $C0 bytes
|
|
|
|
hgrlo3a = $BC00 ; $80 bytes
|
|
|
|
hgrlo3b = $BC80 ; $80 bytes
|
|
|
|
hgrlo3c = $BD00 ; $80 bytes
|
|
|
|
hgrhi3a = $BD80 ; $80 bytes
|
|
|
|
hgrhi3b = $BE00 ; $80 bytes
|
|
|
|
hgrhi3c = $BE80 ; $80 bytes
|
2020-11-12 22:07:04 +00:00
|
|
|
Coordinates3Bit= $6B00 ; pixel data is $5001 bytes ($5000 on disk + 1 byte as EOF marker)
|
|
|
|
; and for optimization we only support loading external files page-aligned
|
|
|
|
; and $BC00+ is used by the 3bit macros for data tables
|
|
|
|
; so we load at $6B00 and waste $FF bytes at $BB01+ but it's okay
|
2019-11-05 19:46:45 +00:00
|
|
|
|
|
|
|
!source "src/fx/macros.a"
|
|
|
|
|
|
|
|
!macro BUILD_EXTRA_COLS {
|
|
|
|
; build lookup table to get $20+y for y in $00..$07
|
|
|
|
ldx #$07
|
|
|
|
ldy #$27
|
|
|
|
- tya
|
|
|
|
sta extra_cols-$20, y
|
|
|
|
dey
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
}
|
|
|
|
|
|
|
|
!macro BUILD_SPARSE_BITMASKS_3BIT {
|
|
|
|
; build sparse lookup tables for bitmasks
|
|
|
|
lda #%10000011
|
|
|
|
sta copymasks
|
|
|
|
|
|
|
|
lda #%10001100
|
|
|
|
sta copymasks+$20
|
|
|
|
|
|
|
|
lda #%10110000
|
|
|
|
sta copymasks+$40
|
|
|
|
|
|
|
|
lda #%11000000
|
|
|
|
sta copymasks+$60
|
|
|
|
|
|
|
|
lda #%10000001
|
|
|
|
sta copymasks+$80
|
|
|
|
|
|
|
|
lda #%10000110
|
|
|
|
sta copymasks+$A0
|
|
|
|
|
|
|
|
lda #%10011000
|
|
|
|
sta copymasks+$C0
|
|
|
|
|
|
|
|
lda #%11100000
|
|
|
|
sta copymasks+$E0
|
|
|
|
}
|
|
|
|
|
|
|
|
!macro BUILD_3BIT_HGR_LOOKUP_TABLES {
|
|
|
|
+BUILD_HGR_LOOKUP_TABLES tmplo, tmphi
|
|
|
|
ldx #$BF
|
|
|
|
ldy #$3F
|
|
|
|
- lda tmplo, x
|
|
|
|
sta hgrlo3c, y
|
|
|
|
sta hgrlo3c+$40, y
|
|
|
|
lda tmphi, x
|
|
|
|
sta hgrhi3c, y
|
|
|
|
sta hgrhi3c+$40, y
|
|
|
|
dex
|
|
|
|
lda tmplo, x
|
|
|
|
sta hgrlo3b, y
|
|
|
|
sta hgrlo3b+$40, y
|
|
|
|
lda tmphi, x
|
|
|
|
sta hgrhi3b, y
|
|
|
|
sta hgrhi3b+$40, y
|
|
|
|
dex
|
|
|
|
lda tmplo, x
|
|
|
|
sta hgrlo3a, y
|
|
|
|
sta hgrlo3a+$40, y
|
|
|
|
lda tmphi, x
|
|
|
|
sta hgrhi3a, y
|
|
|
|
sta hgrhi3a+$40, y
|
|
|
|
dex
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
}
|
|
|
|
|
|
|
|
!macro ROW_X_TO_3BIT_BASE_ADDRESSES {
|
|
|
|
; X = $00..$3F, mapping to row 0, 3, 6, 9, 12, ... 189
|
2020-09-05 23:11:29 +00:00
|
|
|
lda hgrlo3a, x
|
|
|
|
sta <dest1
|
|
|
|
sta <src1
|
|
|
|
lda hgrhi3a, x
|
|
|
|
sta <dest1+1
|
2019-11-05 19:46:45 +00:00
|
|
|
eor #$60
|
2020-09-05 23:11:29 +00:00
|
|
|
sta <src1+1
|
|
|
|
lda hgrlo3b, x
|
|
|
|
sta <dest2
|
|
|
|
sta <src2
|
|
|
|
lda hgrhi3b, x
|
|
|
|
sta <dest2+1
|
2019-11-05 19:46:45 +00:00
|
|
|
eor #$60
|
2020-09-05 23:11:29 +00:00
|
|
|
sta <src2+1
|
|
|
|
lda hgrlo3c, x
|
|
|
|
sta <dest3
|
|
|
|
sta <src3
|
|
|
|
lda hgrhi3c, x
|
|
|
|
sta <dest3+1
|
2019-11-05 19:46:45 +00:00
|
|
|
eor #$60
|
2020-09-05 23:11:29 +00:00
|
|
|
sta <src3+1
|
2019-11-05 19:46:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 22:07:04 +00:00
|
|
|
!macro FX_INITONCE_3BIT .CoordinatesFile, .Start {
|
|
|
|
InitOnce
|
|
|
|
bit .Start
|
|
|
|
lda #$4C
|
|
|
|
sta InitOnce
|
|
|
|
+READ_RAM2_WRITE_RAM2
|
|
|
|
+LOAD_FILE_AT .CoordinatesFile, Coordinates3Bit
|
|
|
|
+READ_RAM1_WRITE_RAM1
|
2020-11-16 20:21:28 +00:00
|
|
|
sec
|
|
|
|
ror Coordinates3Bit + $5000
|
2020-11-12 22:07:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
!macro FX_REVERSE_3BIT {
|
|
|
|
ldy #0 ; <Coordinates3Bit
|
|
|
|
sty $f0
|
|
|
|
lda #>Coordinates3Bit
|
|
|
|
sta $f1
|
|
|
|
lda #<(Coordinates3Bit + $5000 - 2)
|
|
|
|
sta $f2
|
|
|
|
lda #>(Coordinates3Bit + $5000 - 2)
|
|
|
|
sta $f3
|
|
|
|
|
2020-11-13 04:26:15 +00:00
|
|
|
ldx #$28 ; #$50/2
|
2020-11-12 22:07:04 +00:00
|
|
|
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
|
|
|
|
dex
|
|
|
|
beq ++
|
|
|
|
+ lda $f2
|
|
|
|
bne +
|
|
|
|
dec $f3
|
|
|
|
+ dec $f2
|
|
|
|
bcs -
|
|
|
|
bcc -- ; always branches
|
|
|
|
++
|
|
|
|
}
|
|
|
|
|
|
|
|
!macro FX_RIPPLE_3BIT {
|
|
|
|
ldx #$1B
|
|
|
|
- lda ripplezp, x
|
|
|
|
sta $e0, x
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
|
|
|
|
--- ldx #$0c
|
|
|
|
-- ldy $ee, x
|
|
|
|
lda $ef, x
|
|
|
|
jsr aslmod
|
|
|
|
sty $ee, x
|
|
|
|
sta $ef, x
|
|
|
|
sty $ec
|
|
|
|
clc
|
|
|
|
adc #>Coordinates3Bit
|
|
|
|
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 #$28
|
|
|
|
bcc +
|
|
|
|
iny
|
|
|
|
+ pha
|
|
|
|
tya
|
|
|
|
asl
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
rol
|
|
|
|
cmp #$50
|
|
|
|
bcc +
|
|
|
|
sbc #$50
|
|
|
|
+ rts
|
|
|
|
ripplezp
|
|
|
|
!byte $1F,$F3,$20,$F3,$20,$14,$20,$D3
|
|
|
|
!byte $1E,$F3,$1F,$54,$00,$00,$AA,$06
|
|
|
|
!byte $02,$00,$04,$00,$06,$00,$0C,$00
|
|
|
|
!byte $16,$00,$1A,$00
|
|
|
|
++
|
|
|
|
}
|
|
|
|
|
2019-11-05 19:46:45 +00:00
|
|
|
!macro FX_PRECOMPUTED_3BIT .coords {
|
|
|
|
+BUILD_3BIT_HGR_LOOKUP_TABLES
|
|
|
|
+BUILD_EXTRA_COLS
|
|
|
|
+BUILD_SPARSE_BITMASKS_3BIT
|
2020-09-06 14:44:04 +00:00
|
|
|
ldx #(end-start-1) ; copy InputLoop code to zero page
|
|
|
|
- lda start, x
|
|
|
|
sta $0, x
|
2020-09-05 23:11:29 +00:00
|
|
|
dex
|
2020-09-06 14:44:04 +00:00
|
|
|
bpl -
|
2020-11-13 20:14:20 +00:00
|
|
|
jmp InputLoop
|
2020-09-05 23:11:29 +00:00
|
|
|
start
|
|
|
|
!pseudopc 0 {
|
2019-11-05 19:46:45 +00:00
|
|
|
Exit3Bit rts
|
|
|
|
InputLoop
|
|
|
|
ldy #0
|
2020-09-05 23:11:29 +00:00
|
|
|
input=*+1
|
2020-09-06 14:44:04 +00:00
|
|
|
lda .coords, y
|
2019-11-05 19:46:45 +00:00
|
|
|
bmi Exit3Bit ; if high bit is 1 then we're done
|
|
|
|
cmp #$40
|
|
|
|
php
|
|
|
|
tax
|
|
|
|
+ROW_X_TO_3BIT_BASE_ADDRESSES
|
|
|
|
|
2020-09-05 23:11:29 +00:00
|
|
|
inc <input
|
|
|
|
lda (<input), y
|
2019-11-05 19:46:45 +00:00
|
|
|
and #%11100000
|
|
|
|
tax
|
2020-09-05 23:11:29 +00:00
|
|
|
eor (<input), y
|
2019-11-05 19:46:45 +00:00
|
|
|
plp
|
|
|
|
bcc +
|
|
|
|
tay
|
2020-09-05 23:11:29 +00:00
|
|
|
lda extra_cols, y
|
2019-11-05 19:46:45 +00:00
|
|
|
+ tay
|
|
|
|
|
|
|
|
; 2x3 block
|
2020-09-05 23:11:29 +00:00
|
|
|
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
|
|
|
|
src3=*+1
|
|
|
|
lda $FDFD, y
|
|
|
|
eor (<dest3), y
|
|
|
|
and copymasks, x
|
|
|
|
eor (<dest3), y
|
|
|
|
dest3=*+1
|
|
|
|
sta $FDFD, y
|
|
|
|
|
|
|
|
inc <input
|
|
|
|
bne InputLoop
|
|
|
|
bit $c000
|
|
|
|
bmi Exit3Bit
|
|
|
|
inc <input+1
|
|
|
|
bne InputLoop ; always branches
|
|
|
|
}
|
|
|
|
end
|
2019-11-05 19:46:45 +00:00
|
|
|
!if * and 1 {
|
|
|
|
!byte 0 ;align 2 but avoids the fake allocation bug if it was aligned already
|
|
|
|
}
|
|
|
|
}
|