30 lines
1.3 KiB
Plaintext
30 lines
1.3 KiB
Plaintext
1 ; Fast RND
|
|
2 ;
|
|
3 ; An 8-bit pseudo-random number generator,
|
|
4 ; using a similar method to the Spectrum ROM,
|
|
5 ; - without the overhead of the Spectrum ROM.
|
|
6 ;
|
|
7 ; R = random number seed
|
|
8 ; an integer in the range [1, 256]
|
|
9 ;
|
|
10 ; R -> (33*R) mod 257
|
|
11 ;
|
|
12 ; S = R - 1
|
|
13 ; an 8-bit unsigned integer
|
|
14
|
|
0000 15 _random::
|
|
0000 3Ar00r00 [13] 16 ld a, (_seed)
|
|
0003 47 [ 4] 17 ld b, a
|
|
18
|
|
0004 0F [ 4] 19 rrca ; multiply by 32
|
|
0005 0F [ 4] 20 rrca
|
|
0006 0F [ 4] 21 rrca
|
|
0007 EE 1F [ 7] 22 xor #0x1f
|
|
23
|
|
0009 80 [ 4] 24 add a, b
|
|
000A DE FF [ 7] 25 sbc a, #255 ; carry
|
|
26
|
|
000C 32r00r00 [13] 27 ld (_seed), a
|
|
000F 6F [ 4] 28 ld l, a
|
|
0010 C9 [10] 29 ret
|