D-Bug & Automation Forum
D-Bug & Automation Forum >> Coding >> Jaguar: Generating a random number

Message started by Morden on 26.05.09 at 03:01:31

Title: Jaguar: Generating a random number
Post by Morden on 26.05.09 at 03:01:31
I'll kick off with what I'm using in Tapperesque.  If anyone has a better idea then tell us!

random_value:           dc.w 0


                 rol.w      random_value    ; skew the random value counter


;; Generate a random number in d0
;; (Range 0-127)
random:                  lea      random_value,a0      ; vbl ROL counter
                 move.l      $f00004,d0      ; read video H/V offsets
                 eor.w      d0,(a0)            ; screw
                 swap.w      d0            ;  around
                 add.w      d0,(a0)         ;   with
                 add.w      d7,(a0)         ;    value
                 move.w      (a0),d0         ; get number
                 and.w      #%01111111,d0   ; (0-127)

Now, calling that, and doing a CMP D0 with a value between 0-127 allows you to get a percentage chance of random.

The VBI code ensures the number is mangled every frame, and using D7 in the random loop means its got a pseudo random seed (assuming d7 is trashed/used as a temp register in the main loop)

D-Bug & Automation Forum » Powered by YaBB 2.6.0!
YaBB Forum Software © 2000-2024. All Rights Reserved.