Randomness before the first button press

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

tepples
Posts: 21977
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Randomness before the first button press

Post by tepples » Sun Feb 10, 2013 9:15 pm

In [url=http://forums.nesdev.com/viewtopic.php?p=43620#p43620]this post[/url], tokumaru wrote:Other aspects of the NES that might be random (such as register and memory contents) are probably not random enough for seeding a pseudo-random number generator.
Something glitchy this way comes.

¿Pretendo? ¿Innuendo? No entiendo.

Wintendo? Nesticle? Nintendon't.

Kevtris clued me in on how to get randomness before the player presses anything, without using a battery circuit. I'll have something to show you later this week.

User avatar
Bregalad
Posts: 7880
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Updating a 'random' nametable / pattern tile

Post by Bregalad » Mon Feb 11, 2013 2:02 am

No offence, but are you getting senile or something ?

I was on the point to report this as spam, when I suddenly saw : oh, this post was made by tepples ?

If you bump a 4 year old thread, at least write something sensible in it.

User avatar
tokumaru
Posts: 11700
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Updating a 'random' nametable / pattern tile

Post by tokumaru » Mon Feb 11, 2013 6:53 am

Bregalad wrote:If you bump a 4 year old thread, at least write something sensible in it.
The nonsensical links are expected from tepples, but I'd expect more than a "teaser" to justify the necrobump.

tepples
Posts: 21977
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Re:

Post by tepples » Mon Feb 11, 2013 7:50 am

tepples wrote:Kevtris clued me in on how to get randomness before the player presses anything, without using a battery circuit.
What was unclear about this post?

Let me explain further: Last night I was in #nesdev with kevtris, and I asked about potential sources of randomness to choose one of six opening cut scenes before the player has a chance to press Start. He told me about a way to read values resulting from analog effects in the PPU.

User avatar
tokumaru
Posts: 11700
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Re:

Post by tokumaru » Mon Feb 11, 2013 10:10 am

tepples wrote:What was unclear about this post?
Nothing was unclear, it's just that it had no actual content, it's a teaser for content you intend to post in the future.

Not that it bothers me or anything, I just found it weird.

User avatar
Bregalad
Posts: 7880
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Updating a 'random' nametable / pattern tile

Post by Bregalad » Mon Feb 11, 2013 10:15 am

Let me explain further: Last night I was in #nesdev with kevtris, and I asked about potential sources of randomness to choose one of six opening cut scenes before the player has a chance to press Start. He told me about a way to read values resulting from analog effects in the PPU.
Oh, and we were supposed to guess this by looking at your jargon post ?

I guess the time between reset and the first VBlank could be random... on real hardware but most (if not all) emus will not simulate this.

tepples
Posts: 21977
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Updating a 'random' nametable / pattern tile

Post by tepples » Mon Feb 11, 2013 10:36 am

Think back to that topic about Young Indiana Jones. Reading from $2007 during rendering causes the PPU to skip a line and possibly a byte. Young Indy and the title screen of Zelda II use this to skip some scanlines, and I had made a demo called Boing 2007 that uses this same effect to stretch a background.

As for the value itself, Kev tells me a whole bunch of things get enabled at once inside the PPU, which causes not-very-predictable "analog" effects. So I used a CRC16 routine to take a hash of 256 reads from $2007 in order to establish a random seed. I'll post a demo with source later, and I'll need people's help to test it on an NES without the PowerPak menu getting in the way.

Oh, and by now, I'm starting to agree that the necro-bump might not have been the best choice here.

User avatar
Bregalad
Posts: 7880
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Randomness before the first button press

Post by Bregalad » Mon Feb 11, 2013 11:02 am

I completely forgot about this, but I guess this was because you can't really do things that writes to $2005/6 can't do with this effect, so I quickly forgot about it.

User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Re: Randomness before the first button press

Post by blargg » Mon Feb 11, 2013 11:44 am

* Initial RAM contents
* Initial timing of things (how many cycles until first event)
* Indeterminate hardware behavior (double write to $2007)

If you have battery RAM, keep RNG's state in it or even just a reset counter, then no need for HW randomness

User avatar
infiniteneslives
Posts: 2100
Joined: Mon Apr 04, 2011 11:49 am
Location: WhereverIparkIt, USA
Contact:

Re: Randomness before the first button press

Post by infiniteneslives » Mon Feb 11, 2013 12:15 pm

blargg wrote:If you have battery RAM, keep RNG's state in it or even just a reset counter, then no need for HW randomness
Or flash that's writable via the NES. Flash is the only reasonable memory choice if something is going to be produced in sizable quantity. Admittedly though, a solution that would allow writing to it would need to be devised.

Tepples wrote:I'll post a demo with source later, and I'll need people's help to test it on an NES without the PowerPak menu getting in the way.
I can help you out.
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers

Denine
Posts: 398
Joined: Wed Feb 17, 2010 5:42 pm

Re: Randomness before the first button press

Post by Denine » Mon Feb 11, 2013 2:16 pm

blargg wrote:* Initial RAM contents
When I start reading this topic, I had same idea. But it is not emulated, is it?

tepples
Posts: 21977
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Randomness before the first button press

Post by tepples » Mon Feb 11, 2013 2:22 pm

http://pics.pineight.com/nes/pretendo-0.01.zip

Does it have the same 4-digit number every time?

User avatar
Bregalad
Posts: 7880
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Randomness before the first button press

Post by Bregalad » Mon Feb 11, 2013 3:31 pm

The initial RAM content will vary from NES to NES, but will be likely the same at power up on the same console.

Denine
Posts: 398
Joined: Wed Feb 17, 2010 5:42 pm

Re: Randomness before the first button press

Post by Denine » Mon Feb 11, 2013 3:34 pm

Denine:Tepples
0:1

So, RAM viewer in FCEUX just shows 00's and FF's?

At any rate, this may be very useful information, thanks!

EDIT:
Bregalad wrote:The initial RAM content will vary from NES to NES, but will be likely the same at power up on the same console.
yeahh... So player need to reset the game to have different initial value.

User avatar
Bregalad
Posts: 7880
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Randomness before the first button press

Post by Bregalad » Mon Feb 11, 2013 3:44 pm

Yes but then I think a soft reset is assimilable to a "button press".

Post Reply