slightly faster swapzp, and some comments

This commit is contained in:
4am 2020-09-04 19:25:05 -04:00
parent 39b643de50
commit 3dfc71a25a
3 changed files with 43 additions and 40 deletions

View File

@ -8,7 +8,7 @@
copymasks = $6100 ; [256 bytes, page-aligned] copymasks = $6100 ; [256 bytes, page-aligned]
addrs = $6200 ; [256 bytes, page-aligned] addrs = $6200 ; [256 bytes, page-aligned]
jsr swapzp ; copy LFSR code to zerp page jsr swapzp ; copy LFSR code to zero page
inx inx
lda #1 ; create copymask lookup table lda #1 ; create copymask lookup table
@ -62,14 +62,15 @@ src eor $FD00, y ; merge source and destination bits
and copymasks, x ; isolate the bits to replace, zero the rest and copymasks, x ; isolate the bits to replace, zero the rest
eor (<dst+1), y ; unmerge source and destination bits, leaves 'to keep' destination bits intact eor (<dst+1), y ; unmerge source and destination bits, leaves 'to keep' destination bits intact
dst sta $FD00, y ; write the result dst sta $FD00, y ; write the result
txa txa
lsr lsr
tax tax
tya tya
ror ror
tay tay
bcc loop2 ; C set by ror bcc loop2 ; C modified by ror
bne loop ; Z set by tay bne loop ; Z modified by tay
bit $C000 bit $C000
bmi exit bmi exit
txa txa

View File

@ -5,12 +5,13 @@
!to "build/FX/BIT2.FIZZLE",plain !to "build/FX/BIT2.FIZZLE",plain
*=$6000 *=$6000
addrs = $6100 ; [256 bytes] addrs = $6100 ; [256 bytes, page-aligned]
copymasks = $6200 ; [128 bytes] copymasks = $6200 ; [128 bytes, should not cross page boundary]
jsr swapzp ; copy LFSR code to zero page
jsr swapzp
ldx #0 ldx #0
lda #%00000011 lda #%00000011 ; create copymask lookup table
-- ldy #$20 -- ldy #$20
ora #%10000000 ora #%10000000
- sta copymasks, x - sta copymasks, x
@ -22,7 +23,7 @@ copymasks = $6200 ; [128 bytes]
bne -- bne --
clc clc
ldx #0 ldx #0
-- ldy #$20 -- ldy #$20 ; create address lookup table
tya tya
- sta addrs, x - sta addrs, x
adc #1 adc #1
@ -31,14 +32,17 @@ copymasks = $6200 ; [128 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
@ -47,31 +51,31 @@ start
!pseudopc 0 { !pseudopc 0 {
; in: X,Y=0 ; in: X,Y=0
loop txa loop txa
loop1 eor #$60 loop1 eor #$60 ; LFSR form 0x6000 with period 32767
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 modified by ror
bne loop bne loop ; Z modified 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

View File

@ -5,11 +5,11 @@
!to "build/FX/SHR.FIZZLE",plain !to "build/FX/SHR.FIZZLE",plain
*=$A000 *=$A000
addrs=$A100 ; [128 bytes, can be anywhere in main memory but don't cross page boundary] addrs=$A100 ; [128 bytes, can be anywhere in main memory but don't cross page boundary]
jsr swapzp ; copy LFSR code to zero page jsr swapzp ; copy LFSR code to zero page
ldx #$7F ; create address lookup table ldx #$7F ; create address lookup table
lda #$9F lda #$9F
sec sec
- sta addrs, x - sta addrs, x
@ -18,7 +18,7 @@ addrs=$A100 ; [128 bytes, can be anywhere in main memory but don't
bpl - bpl -
inx inx
sta $C005 ; pre-copy SHR SCB and palette sta $C005 ; pre-copy SHR SCB and palette
ldy #0 ldy #0
- lda $9D00, y - lda $9D00, y
sta $9D00, y sta $9D00, y
@ -29,19 +29,17 @@ addrs=$A100 ; [128 bytes, can be anywhere in main memory but don't
iny iny
bne - bne -
jsr $0 ; call LFSR code on zero page jsr $0 ; call LFSR code on zero page
lda $2000 ; last lousy byte (because LFSR never hits 0) lda $2000 ; last lousy byte (because LFSR never hits 0)
sta $2000 sta $2000
sta $C004 ; restore and exit sta $C004 ; 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