Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
69
Task/Knuth-shuffle/6502-Assembly/knuth-shuffle.6502
Normal file
69
Task/Knuth-shuffle/6502-Assembly/knuth-shuffle.6502
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
define sysRandom $fe
|
||||
define tempMask $ff
|
||||
define range $00
|
||||
define tempX $01
|
||||
define tempY $02
|
||||
define tempRandIndex $03
|
||||
define temp $04
|
||||
CreateIdentityTable:
|
||||
txa
|
||||
sta $0200,x
|
||||
sta $1000,x
|
||||
inx
|
||||
bne CreateIdentityTable
|
||||
;creates a sorted array from 0-255 starting at addr $1000
|
||||
;also creates another one at $0200 for our test input
|
||||
|
||||
lda #1
|
||||
sta range
|
||||
|
||||
ConstrainRNG:
|
||||
ldx #255
|
||||
;max range of RNG
|
||||
lda range
|
||||
bne outerloop
|
||||
jmp end
|
||||
|
||||
outerloop:
|
||||
cpx range
|
||||
bcc continue ;if X >= range, we need to lower X
|
||||
pha
|
||||
txa
|
||||
sta tempX
|
||||
|
||||
lsr
|
||||
cmp range
|
||||
bcc continue2
|
||||
|
||||
tax
|
||||
pla
|
||||
jmp outerloop
|
||||
|
||||
continue2:
|
||||
pla
|
||||
ldx tempX
|
||||
|
||||
continue:
|
||||
ldy range
|
||||
|
||||
KnuthShuffle:
|
||||
lda sysRandom
|
||||
and $1000,x ;and with range constrictor
|
||||
tay
|
||||
|
||||
lda $0200,y
|
||||
sty tempRandIndex
|
||||
sta temp
|
||||
ldy range
|
||||
lda $0200,y
|
||||
pha
|
||||
lda temp
|
||||
sta $0200,y
|
||||
pla
|
||||
ldy tempRandIndex
|
||||
sta $0200,y
|
||||
dec range
|
||||
jmp ConstrainRNG
|
||||
|
||||
end:
|
||||
brk
|
||||
Loading…
Add table
Add a link
Reference in a new issue