CPU ram Initial value is 0x00?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
zxbdragon
Posts: 498
Joined: Mon Dec 12, 2011 8:15 pm

CPU ram Initial value is 0x00?

Post by zxbdragon »

fceux is 0x00 (NTSC)
nestopia is 0xFF (NTSC),or 0x00(DENDY)

Which is the right one?
User avatar
Bregalad
Posts: 8055
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: CPU ram Initial value is 0x00?

Post by Bregalad »

The memory is filled randomly with values which varies from system to system, usually it's $ff but with some bits randomly clear. This is not just CPU RAM, but also VRAM, as both are materialized 6116 chips on the NES' motherboard.

I have no idea of the initial state of the Dendy or other famiclones though.
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: CPU ram Initial value is 0x00?

Post by Zepper »

It doesn't matter. All memory must be initialized by software.
zxbdragon
Posts: 498
Joined: Mon Dec 12, 2011 8:15 pm

Re: CPU ram Initial value is 0x00?

Post by zxbdragon »

Zepper wrote:It doesn't matter. All memory must be initialized by software.
No, initialization is different, a game may be different
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: CPU ram Initial value is 0x00?

Post by Zepper »

zxbdragon wrote:
Zepper wrote:It doesn't matter. All memory must be initialized by software.
No, initialization is different, a game may be different
Argh, read what Bregalad wrote.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: CPU ram Initial value is 0x00?

Post by tokumaru »

AFAIK the initial contents of RAM can change depending on how the chip is manufactured, the temperature, and a whole lot of other unpredictable analog variables. There are no "official" values an emulator can use, which is why different emulators use different values.

Games aren't supposed to rely on uninitialized memory, unless they're using it as a source of randomness (the randomness is quite poor though, since many addresses tend to be either $00 or $ff, with few flipped bits, and the same memory location tends to assume the same value every time). If they do rely on it, and can possibly misbehave with any values, then that's a bug.
User avatar
Dwedit
Posts: 4922
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: CPU ram Initial value is 0x00?

Post by Dwedit »

Bootleg versions of games ripped from multicarts often rely on uninitialized memory, since the menu program would initialize them. Hence World 0-1 in bad versions of Super Mario Bros.
Final Fantasy 1 uses uninitialized memory for the RNG.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
zxbdragon
Posts: 498
Joined: Mon Dec 12, 2011 8:15 pm

Re: CPU ram Initial value is 0x00?

Post by zxbdragon »

Dwedit wrote:Bootleg versions of games ripped from multicarts often rely on uninitialized memory, since the menu program would initialize them. Hence World 0-1 in bad versions of Super Mario Bros.
Final Fantasy 1 uses uninitialized memory for the RNG.
0-1 Will not happen in fceux
User avatar
Dwedit
Posts: 4922
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: CPU ram Initial value is 0x00?

Post by Dwedit »

FCEUX uses a 0000 FFFF 0000 FFFF pattern that happens to put the world byte as 0, so it starts on 1-1. Real hardware would probably have FF there, so it would start at 0-1.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: CPU ram Initial value is 0x00?

Post by rainwarrior »

There's some valid reasons not to entirely initialize memory.

The most common is to retain some state after reset, like how Mario Bros. will remember which world you got to for the "continue" cheat code even after you reset. It checks for a very specific "key" value somewhere in RAM on startup, and if it's there it presumes that you've already been playing and it should leave it how it is. (The key value should be at least few bytes, with a healthy mix of 0 and 1 bits, something unlikely to happen by accident.) This is how the SMB / Tennis "swap trick" works: https://www.youtube.com/watch?v=eEEnEoKSgQs

Games that have a battery backed save will have to deal with uninitialized SRAM at first boot, and after any battery failure. Obviously it shouldn't be initialized if the player already has something saved there. Similar techniques apply in this case.

Of course, there's a bunch of games that just straight up forget to initialize memory, and rely on "lucky" startup values to run correctly.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: CPU ram Initial value is 0x00?

Post by tepples »

The initial values in CPU RAM ($0000-$1FFF) and VRAM are unspecified. The same is true of PRG RAM (usually at $6000-$7FFF) and CHR RAM on the cartridge unless they're battery-backed.

(I use "unspecified" with the meaning that the C and C++ standards use.)
AWJ
Posts: 433
Joined: Mon Nov 10, 2008 3:09 pm

Re: CPU ram Initial value is 0x00?

Post by AWJ »

zxbdragon wrote:
Zepper wrote:It doesn't matter. All memory must be initialized by software.
No, initialization is different, a game may be different
If a game runs differently depending on the initial contents of RAM, it'll run differently on different NES consoles.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: CPU ram Initial value is 0x00?

Post by rainwarrior »

AWJ wrote:If a game runs differently depending on the initial contents of RAM, it'll run differently on different NES consoles.
In theory it may run differently on the same console at different times too.

In practice, RAM usually initializes mostly to 1s, with a few 0 bits here and there. Most of the time, uninitialized RAM bugs are only dependent on the state of a few bytes, and most of the time they will be $FF.
Post Reply