Skip to content

Commit 2d70afa

Browse files
committed
Fix RAND routine
Was not returning all the random bytes correctly
1 parent bd761ad commit 2d70afa

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

src/arch/zx48k/library-asm/random.asm

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ TAKE_FRAMES:
2929
FRAMES EQU 23672
3030
ENDP
3131

32-
RANDOM_SEED_HIGH EQU RAND+6 ; RANDOM seed, 16 higher bits
33-
RANDOM_SEED_LOW EQU 23670 ; RANDOM seed, 16 lower bits
32+
RANDOM_SEED_HIGH EQU RAND+6 ; RANDOM seed, 16 higher bits
33+
RANDOM_SEED_LOW EQU 23670 ; RANDOM seed, 16 lower bits
3434

3535

3636
RAND:
@@ -54,18 +54,17 @@ RAND_LOOP:
5454
rra ; t = t ^ (t >> 1) ^ w
5555
xor d
5656
xor e
57-
ld h,l ; y = z
58-
ld l,a ; w = t
59-
ld (RANDOM_SEED_HIGH),hl
57+
ld d,l ; y = z
58+
ld e,a ; w = t
59+
ld (RANDOM_SEED_HIGH),de
6060
push af
6161
djnz RAND_LOOP
62-
pop af
63-
pop af
64-
ld d, a
62+
pop de
6563
pop af
6664
ld e, a
65+
pop hl
6766
pop af
68-
ld h, a
67+
ld l, a
6968
ret
7069
ENDP
7170

@@ -89,7 +88,7 @@ RND:
8988
; We already have a random 32 bit mantissa in ED CB
9089
; From 0001h to FFFFh
9190

92-
ld l, 81h ; Exponent
91+
ld l, 81h ; Exponent
9392
; At this point we have [0 .. 1) FP number;
9493

9594
; Now we must shift mantissa left until highest bit goes into carry

0 commit comments

Comments
 (0)