Page Index Toggle Pages: 1 Send TopicPrint
Jaguar: Generating a random number (Read 535 times)
Morden
Reboot Member
*****
Offline


D-BUGer

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


Code
Select All
random_value:           dc.w 0

CODE IN VBI:


			rol.w	random_value    ; skew the random value counter


PROCEDURAL CODE:



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; 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)
			rts

 


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)
« Last Edit: 05.07.10 at 09:20:26 by ggn »  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint
 
  « Board Index ‹ Board  ^Top