slightly faster swapzp, and some comments

This commit is contained in:
4am 2020-09-04 19:11:30 -04:00
parent 3365ac8a37
commit 39b643de50

View File

@ -5,12 +5,13 @@
!to "build/FX/BIT.FIZZLE",plain !to "build/FX/BIT.FIZZLE",plain
*=$6000 *=$6000
copymasks = $6100 ; [256 bytes] copymasks = $6100 ; [256 bytes, page-aligned]
addrs = $6200 ; [256 bytes] addrs = $6200 ; [256 bytes, page-aligned]
jsr swapzp jsr swapzp ; copy LFSR code to zerp page
ldx #0
lda #1 inx
lda #1 ; create copymask lookup table
-- ldy #$20 -- ldy #$20
ora #$80 ora #$80
- sta copymasks, x - sta copymasks, x
@ -19,8 +20,9 @@ addrs = $6200 ; [256 bytes]
bne - bne -
asl asl
bne -- bne --
clc clc
-- ldy #$20 -- ldy #$20 ; create address lookup table
tya tya
- sta addrs, x - sta addrs, x
adc #1 adc #1
@ -29,14 +31,17 @@ addrs = $6200 ; [256 bytes]
bne - bne -
txa txa
bne -- bne --
jsr $0
jsr $0 ; call LFSR code on zero page
lda $4000 ; last lousy byte (because LFSR never hits 0)
sta $2000
; fall through to restore and exit
swapzp ldx #(end-start-1) swapzp ldx #(end-start-1)
- lda $0, x - ldy start, x
pha lda $0, x
lda start, x
sta $0, x
pla
sta start, x sta start, x
sty $0, x
dex dex
bpl - bpl -
rts rts
@ -45,31 +50,30 @@ start
!pseudopc 0 { !pseudopc 0 {
; in: X,Y=0 ; in: X,Y=0
loop txa loop txa
loop1 eor #$B4 loop1 eor #$B4 ; LFSR form 0xB400 for period 65535
tax tax ; X is LFSR high byte, Y is LFSR low byte
loop2 lda addrs, x loop2 lda addrs, x ; which means X is the index into the base address lookup table
sta <dst+2 sta <dst+2 ; and Y is the offset from the base address
eor #$60 eor #$60 ; which works out well with the available addressing modes
sta <src+2 sta <src+2
lda (<dst+1), y lda (<dst+1), y
src eor $FD00, y src eor $FD00, y ; merge source and destination bits
and copymasks, x and copymasks, x ; isolate the bits to replace, zero the rest
eor (<dst+1), y eor (<dst+1), y ; unmerge source and destination bits, leaves 'to keep' destination bits intact
dst sta $FD00, y dst sta $FD00, y ; write the result
txa txa
lsr lsr
tax tax
tya tya
ror ror
tay tay
bcc loop2 bcc loop2 ; C set by ror
bne loop bne loop ; Z set by tay
bit $C000 bit $C000
bmi exit bmi exit
txa txa
bne loop1 bne loop1
exit lda $4000 exit rts
sta $2000
rts
} }
end end