Skip to content

Instantly share code, notes, and snippets.

View JohnConnolly0's full-sized avatar

John Connolly JohnConnolly0

View GitHub Profile
@JohnConnolly0
JohnConnolly0 / ZX Spectrum Random Numbers
Created February 19, 2015 15:21
Z80 Psuedo-random number generator
LD A,R ; Load the A register with the refresh register
LD L,A ; Copy register A into register L
AND %00111111 ; This masking prevents the address we are forming from accessing RAM
LD H,A ; Copy register A into register H
LD A,(HL) ; Load the pseudo-random value into A
; HOW THIS WORKS
; The refresh register in the Z80 is highly unpredictable since it is incremented every cycle.
; Because it may be at any value when this routine is called, it is very good for random numbers.