renamed all ".inc" files to ".zas" (so egedit will properly highlight them)
[urasm.git] / libs / ritman_rnd.zas
bloba1224b7e20c2d516f4f74d00ad7752f311ea7e1e
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; generate random number
3 ;; IN:
4 ;;   rndSeed: 4 bytes of shit
5 ;; OUT:
6 ;;   HL: 32-bit random
7 ;;   DE: either dead or uncomment the line to get 64-bit number
8 ;;   BC: dead
9 ;; WARNING:
10 ;;  be careful to not have all zeroes in rndSeed!
11 random:
12   ld   hl,(rndSeed+2)
13   ld   d,l
14   add  hl,hl
15   add  hl,hl
16   ld   c,h
17   ld   hl,(rndSeed)
18   ld   b,h
19   rl   b
20   ld   e,h
21   rl   e
22   rl   d
23   add  hl,bc
24   ld   (rndSeed),hl
25   ld   hl,(rndSeed+2)
26   adc  hl,de
27   res  7,h
28   ld   (rndSeed+2),hl
29   jp   m,.done
30   ld   hl,rndSeed
31 .gotzero:
32   inc  (hl)
33   inc  hl
34   jr   z,.gotzero
35 .done:
36   ld   hl,(rndSeed)
37   ;ld   de,(seed+2)
38   ret
39 rndSeed: defm "Jon!"  ; not-so-bad initial value