[stella] Random seed

Subject: [stella] Random seed
From: Fabrizio Zavagli <fabrizio.zavagli@xxxxxxxxx>
Date: Thu, 14 Apr 2005 13:46:17 -0400
Hello everyone!

It's been quite a while since I've last posted a message to the list,
but I've finally resumed working on my project "Bounce!" (for those
who still remember it) and enjoying again coding for the 2600!

So, since I think it will be a bankswitched game, I thought I might
well be using some of the extra rom for a little cosmetics
enhancements. The idea would be of displaying a random screen/scene
once you start the game/power on the 2600 (so before any user
interaction takes place).
And here comes the trouble: how to initially generate a random seed
for the random number sub.

I've been brainstorming about it for a few days and checked the list
as well. Most (all?) of the samples I've found adopt the technique of
using values from the zero page ram/registers which should/could be
random at poweron.
Anyway I don't really happen to like this solution too much, as it may
fail on emulators/supercharger, plus I believe there's generally no
real guarantee about the randomness of the zero page memory.

So I've started to look for alternative methods. I've been thinking
that, before the first VBLANK sync is performed, the raster could
theoretically be at any position on the screen. So, I thought, if I
set a timer and then wait for VBLANK for the first time, a random time
should pass between the two events, and I should get a random value
from INTIM. Even a simple WSYNC could do the trick since the raster
could be at any position on the line... but it doesn't seem to be
working!

I've been experimenting with some code like:

	lda #76         ; Any value should be ok since the timer wraps at 0
	sta TIM1T     ; TIM1T should be ok..
	sta WSYNC  ; Raster may be at any position in the line, therefore
this part could take a variable amount of time to execute.. (given
it's tracing a line)
	lda INTIM
	sta random

and also (alternatively):

	lda #76         ; Any value should be ok since the timer wraps at 0
	sta TIM1T     ; TIM1T should be ok here as well since it should wrap at 0

	LDX  #0
	LDA  #2
	STA  WSYNC
	STA  VSYNC
	STA  WSYNC
	STA  WSYNC
	LDA #0
	STA  WSYNC
	STA  VSYNC

	lda INTIM
	sta random

... but I keep getting the same values from INTIM each time I run the binary! :(
I've tried on both z26 and with a CuttleCart, same results.

The only way I've been able to get a random number is by simply
reading from INTIM just after initializing the zero page with 0's, but
sadly this seems to work with z26 only and not on real hardware (with
CuttleCart1)!!

Of course I'm not sure if my theory of the random raster position is
correct, here the input of gurus is definitely welcome!

So here's my request for help: anyone has an idea on how to get a
random seed on powerup?

Thank you all in advance and regards!
Fabrizio.-
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://stella.biglist.com

Current Thread