mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
Significantly faster rand() implementation
This commit is contained in:
parent
fb260ef17f
commit
3994fee595
@ -35,27 +35,17 @@ rand: .dword 1
|
|||||||
.code
|
.code
|
||||||
|
|
||||||
_rand: clc
|
_rand: clc
|
||||||
lda rand+0 ; SEED *= $01010101
|
lda rand+0 ; SEED += $B3
|
||||||
adc rand+1
|
adc #$B3
|
||||||
|
sta rand+0
|
||||||
|
adc rand+1 ; SEED *= $01010101
|
||||||
sta rand+1
|
sta rand+1
|
||||||
adc rand+2
|
adc rand+2
|
||||||
sta rand+2
|
sta rand+2
|
||||||
adc rand+3
|
|
||||||
sta rand+3
|
|
||||||
clc
|
|
||||||
lda rand+0 ; SEED += $31415927
|
|
||||||
adc #$27
|
|
||||||
sta rand+0
|
|
||||||
lda rand+1
|
|
||||||
adc #$59
|
|
||||||
sta rand+1
|
|
||||||
lda rand+2
|
|
||||||
adc #$41
|
|
||||||
sta rand+2
|
|
||||||
and #$7f ; Suppress sign bit (make it positive)
|
and #$7f ; Suppress sign bit (make it positive)
|
||||||
tax
|
tax
|
||||||
lda rand+3
|
lda rand+2
|
||||||
adc #$31
|
adc rand+3
|
||||||
sta rand+3
|
sta rand+3
|
||||||
rts ; return bit (16-22,24-31) in (X,A)
|
rts ; return bit (16-22,24-31) in (X,A)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user