Jump to content
IGNORED

Random seed in title sequence


DZ-Jay

Recommended Posts

I have a random number generator which I seed initially with some value.  I then add additional bits of randomness during the idle loop, shifting it and mixing in controller state, etc.  By the time the player presses a button to start the game, the random seed has gone through many changes.

 

Because the time the player takes to start the game is indeterminate, it more or less guarantees that the seed used during the game is non-deterministic.  So that's great. 😊

 

However, I now need a random number before the player gets a chance to do anything.  For example, I have a table of elements for my title screen (animations, sprite records, scripts, etc.), and I want to pick one at random to show at a given time, and then loop around again.  The problem is that the time from booting up, to title screen, is purely deterministic.  It means the sequence of items chosen will always be the same 😞

 

I know that there is no possible way to be truly random, but I thought to ask in case anybody has any suggestions on what to do for this particular case.  I've been too deep in this project for several days now and my brain is sort of fried, so I can't really tell if what I want is possible or not.

 

Suggestions are welcomed!

 

     dZ.

Link to comment
Share on other sites

I guess the only way to get some entropy from a real Intellivision after a cold start would be to read the low memory and XOR everything together (or, for something more uniformly distributed, compute a CRC16 or some other kind of checksum or hash). I'm pretty sure the STIC registers are slightly random at start-up and I think the Scratch RAM may contain some garbage as well, but I don't recall for sure. Of course, you'd need to take control of the system as soon as possible (i.e. with code at $4800). Otherwise, the EXEC would already have cleaned up almost everything.

 

Another thing you may want to try is to write some pattern to the GRAM until you don't get the same value anymore (because of the end of VBLANK). The number of iterations and the last read value may be slightly random. But the system is pretty darn stable, so I won't expect much entropy from that.

Edited by Arnauld
added another point
Link to comment
Share on other sites

7 minutes ago, Arnauld said:

I guess the only way to get some entropy from a real Intellivision after a cold start would be to read the low memory and XOR everything together (or, for something more uniformly distributed, compute a CRC16 or some other kind of checksum or hash). I'm pretty sure the STIC registers are slightly random at start-up and I think the Scratch RAM may contain some garbage as well, but I don't recall for sure. Of course, you'd need to take control of the system as soon as possible (i.e. with code at $4800). Otherwise, the EXEC would already have cleaned up almost everything.

 

Hi, Arnauld,

 

Thanks for the response.  That's sort of what I was thinking.  Since I was using CART.MAC, which hooks in during the Title/Copyright display right after the EXEC initializes, I was hoping to find a way to get some entropy after that.

 

In my new framework I bypass the EXEC completely, hooking up at $4800 and going from there.  It means that I end up having to initialize all memory and devices myself.  On the other hand, it means I can get some potentially random bits from the initial state of the machine.  I'm pretty sure we've established in the past that the PSG or the STIC have some garbage in them after a cold boot.

 

Unfortunately, I'm currently working on a project stuck with my older framework and CART.MAC.  I guess I'll have to change the bootstrap sequence then if I want to get some initial entropy.  More work. :(

 

Thanks!

     -dZ.

 

Edited by DZ-Jay
  • Like 1
Link to comment
Share on other sites

6 minutes ago, DZ-Jay said:

 

Unfortunately, I'm currently working on a project stuck with my older framework and CART.MAC.  I guess I'll have to change the bootstrap sequence then if I want to get some initial entropy.  More work. :(

 

Well, I think you'd just have to jump at either $1041 (including the Scratch RAM clean-up) or $1048 (skipping the Scratch RAM clean-up) to resume the EXEC initialization after your code at $4800 has completed.

Link to comment
Share on other sites

7 minutes ago, Arnauld said:

Well, I think you'd just have to jump at either $1041 (including the Scratch RAM clean-up) or $1048 (skipping the Scratch RAM clean-up) to resume the EXEC initialization after your code at $4800 has completed.

 

Sure, but I ... won't be able to store the seed in RAM if I want to let the EXEC clean it up. ;)

 

I could probably use the stack, but then it'll get clobbered on the next ISR, and of course Cart.mac plays with it to reset it.  It's not a big deal really, but it probably will require digging into Cart.mac to modify some parts (it's been years since I last looked at it).

 

I also did notice that when I bypass the EXEC startup completely, and just jump to my program from $4800, a few things are messed up, mostly things having to do with the STIC, like the border, display mode, delay registers, etc.  (I guess I never noticed that I was depending too much on the EXEC).

 

Anyway, the good news is that I should be able to get some random bits if I hook up to the machine initialization early on.  Thanks again!

 

    -dZ.

Edited by DZ-Jay
Link to comment
Share on other sites

3 minutes ago, DZ-Jay said:

 

Sure, but I ... won't be able to store the seed in RAM if I want to let the EXEC clean it up. ;)

 

That's why you may want to jump at $1048 to skip the Scratch RAM clean-up. Alternately, I think you can use the range $307-$349. The EXEC writes a lot of stuff to the System RAM for the title screen but never clears it entirely. This range should be left unchanged.

Link to comment
Share on other sites

1 minute ago, Arnauld said:

That's why you may want to jump at $1048 to skip the Scratch RAM clean-up. Alternately, I think you can use the range $307-$349. The EXEC writes a lot of stuff to the System RAM for the title screen but never clears it entirely. This range should be left unchanged.

 

Oh, nice.  I'll take a look at that.  At some point I should look closer to the EXEC initialization to see how it works; I just never bothered in the past. :)

 

Thank you so much!

 

     -dZ.

Link to comment
Share on other sites

@Arnauld,

 

It seems that starting at $300 onwards, there's potentially garbage and the EXEC does not touch it.  So, it seems a great place to grab a chunk, XOR or it, and set it as the seed during startup.  The PRNG (and the additional entropy added in the idle loop) will take it from there. :)

 

On emulation, the game will have to be run with the "--rand-mem" flag, or else it'll all be zeroed out.

 

Thanks a lot, this is great.

 

     -dZ.

Edited by DZ-Jay
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...