Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shuffle:
- ;(seed) is a non-zero 16-bit value
- ;array is 52 bytes that will be populated with integers 0..51, shuffled.
- xor a
- loop:
- ld e,a
- ;This xorhift routine was written by John Metcalf
- ; http://www.retroprogramming.com/2017/07/xorshift-pseudorandom-numbers-in-z80.html
- ld hl,(seed)
- ld a,h
- rra
- ld a,l
- rra
- xor h
- ld h,a
- ld a,l
- rra
- ld a,h
- rra
- xor l
- ld l,a
- xor h
- ld h,a
- ld (seed),hl
- ; End of the xorshift routine
- ld a,r
- add a,h
- ld h,a
- ld a,e
- push af
- inc a
- ex de,hl
- ld hl,0
- ld b,8
- ld c,l
- add hl,hl
- rla
- jr nc,$+4
- add hl,de
- adc a,c
- djnz $-6
- ;(array+A) ==> (array+index)
- ;index ==> (array+A)
- ;add A to array
- ld e,a
- ld d,b
- pop af
- ld l,a
- ld h,b
- ld bc,array
- add hl,bc
- ex de,hl
- add hl,bc
- ldi
- dec hl
- ld (hl),a
- inc a
- cp 52
- jr nz,loop
- ret
Add Comment
Please, Sign In to add comment