ridiculously fast SHR fizzle

This commit is contained in:
4am 2020-09-04 17:27:04 -04:00
parent 5fca4ad4f2
commit 3365ac8a37

View File

@ -1,94 +1,73 @@
;license:MIT ;license:MIT
;(c) 2019-2020 by qkumba/4am ;(c) 2019-2020 by qkumba/4am/John Brooks
!cpu 6502 !cpu 6502
!to "build/FX/SHR.FIZZLE",plain !to "build/FX/SHR.FIZZLE",plain
*=$a000 *=$A000
rnd1=$fe addrs=$A100 ; [128 bytes, can be anywhere in main memory but don't cross page boundary]
rnd2=$ff
;init RNG jsr swapzp ; copy LFSR code to zero page
ldy #1 ldx #$7F ; create address lookup table
sty rnd1 lda #$9F
dey sec
sty rnd2 - sta addrs, x
sbc #1
;copy SCB and palette
lda #$9d
sta $3d
sty $3c
ldx #$23 ; copy SCB+palette+this code to auxmem
sta $c005
@copystuff
lda ($3c),y
sta ($3c),y
iny
bne @copystuff
inc $3d
dex dex
bne @copystuff bpl -
inx
;force write offset 0 otherwise it will be missed sta $C005 ; pre-copy SHR SCB and palette
ldy #0
- lda $9D00, y
sta $9D00, y
lda $9E00, y
sta $9E00, y
lda $9F00, y
sta $9F00, y
iny
bne -
lda $2000 jsr $0 ; call LFSR code on zero page
lda $2000 ; last lousy byte (because LFSR never hits 0)
sta $2000 sta $2000
sta $c004
;iterate sta $C004 ; restore and exit
swapzp ldx #(end-start-1)
- lda $0, x
pha
lda start, x
sta $0, x
pla
sta start, x
dex
bpl -
rts
@loop start
ldx rnd1 !pseudopc 0 {
@loop2 ; in: X,Y=0
stx $26 loop txa
stx $3c loop1 eor #$60 ; LFSR form 0x6000 with period 32767
ldx rnd2 tax
lsr rnd2 loop2 lda addrs, x
ror rnd1 sta <dst+2
bcc + lda (<dst+1), y
dst sta $FD00, y
;feedback polynomial forms #$4001 for period of 32767
lda rnd1
eor #1
sta rnd1
lda rnd2
eor #$40
sta rnd2
;don't rewrite SCB or palette
;it will make the fizzle take longer than obviously needed
+ cpx #$7d
bcs +
txa txa
lsr
;select address tax
tya
adc #$20 ror
sta $27 tay
sta $3d bcc loop2
bne loop
;copy pixel from other page to this page bit $C000
bmi exit
lda ($3c),y txa
sta $c005 bne loop1
sta ($26),y exit rts
sta $c004 }
end
+
;exit conditions
ldx rnd2
bne @loop
ldx $c000
bmi @exit
ldx rnd1
cpx #1
bne @loop2
@exit rts