Simple ROM to test power on or reset RAM state

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Simple ROM to test power on or reset RAM state

Post by rainwarrior »

I found this ROM I made a while back for testing the RAM startup/reset state on my NES. Sharing it in case anybody would find it useful.

It clobbers the low 3 bytes of ZP, and also the top couple of bytes of the stack page, but otherwise just shows RAM on the screen, and you can press up/down to browse the 8 pages. (B and A fill the page with ascending or descending values, was used to test reset state.)

Edit: I think jroatch's coredump ROM is better than this, though, seems to manage not to clobber any bytes at all. Might as well use that instead.
Attachments
ram_retain.zip
(4.53 KiB) Downloaded 1422 times
Last edited by rainwarrior on Thu Mar 07, 2019 6:55 pm, edited 2 times in total.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simple ROM to test power on or reset RAM state

Post by rainwarrior »

I posted on the Wiki about this, but just in case it's useful to anybody here:
I tested my NES and Famicom today with a simple ROM that just displays the contents of RAM. I get widely varying results at power-on. I tried leaving the system off for varying amounts of time between powerings, but I don't see much consistency at all. Here's some examples of what I've seen:
  • Mostly $FF.
  • Mostly some specific byte, e.g. $E7.
  • Repeating patterns like $00 $FF $00 FF, often in consistent lines of 16 or 32 bytes.
  • Often I get groups with a specific byte value, especially in columns (using rows of 16).
All of these patterns are heavily subject to noise. Sometimes a lot of noise, sometimes only a little. Really I don't see much consistent behaviour at all on my NES.

My Famicom usually powers up with mostly a repeating 16 byte pattern of 00FF00FF00FF00FFFF00FF00FF00FF00, often with one or many columns of bytes (using rows of 16) that look completely random in contrast to that pattern. Occasionally the Famicom powers up with different patterns than this too.

The recommendation for specific values at $0008/9/A/F seems bizarre to me. Why is this in the article at all? These bytes are not particularly consistent on either of my machines, and certainly don't match these magic values. A few quick power cycles sometimes seems to leave some bytes alone, but I don't see anything special about 8/9/A/F?

I'm not certain the idea that it should be "mostly FF" is particularly good either. On my Famicom, it looks like 50/50 for a randomly selected bit (though with a high probability of fitting the pattern listed for any specific bit). On my NES, I'd guess there's might be a slight bias toward 1 bits, but I really don't think that's a very useful piece of information given how random it is, and how often there are repetitive (and different) patterns in the bits.

I'm curious what other people might see on their machines.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Simple ROM to test power on or reset RAM state

Post by lidnariq »

Your archive includes your build scripts but not the source code...
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simple ROM to test power on or reset RAM state

Post by rainwarrior »

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

Re: Simple ROM to test power on or reset RAM state

Post by tokumaru »

rainwarrior wrote:
  • Mostly $FF.
  • Mostly some specific byte, e.g. $E7.
  • Repeating patterns like $00 $FF $00 FF, often in consistent lines of 16 or 32 bytes.
  • Often I get groups with a specific byte value, especially in columns (using rows of 16).
I never expected the power up state of RAM to vary so much.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simple ROM to test power on or reset RAM state

Post by rainwarrior »

Yeah, I'm completely baffled by it. I'm surprised how often I seem to get repeating 4 bit or 8 bit patterns, in many different arrangements. Every now and then it looks completely random, but most of the time it's got patterned groups-- but what really surprises me is how the patterns change! Maybe it has to do with the physical organization of the chip itself, like it seems like often every 16th bit has mostly the same value, or every 16th or 32nd byte has the same group, etc, but not always! Sometimes it's a pattern in mosty columns and then one column or a few columns are completely random looking.
User avatar
Myask
Posts: 965
Joined: Sat Jul 12, 2014 3:04 pm

Re: Simple ROM to test power on or reset RAM state

Post by Myask »

CLChambers00
Posts: 78
Joined: Wed Jul 19, 2017 10:23 am

Re: Simple ROM to test power on or reset RAM state

Post by CLChambers00 »

How do I put this or rom like it in an actual cart? Do you just scrap an NES cart, and load the rom on it? and what method do you recommend for putting such a rom on a chip, and where can I get a rom reader/writer and chips? Or does someone have one made or could be made for me for a price to be shipped to me. This is the rom I would like to use: viewtopic.php?f=22&t=11520#p157782

Would this show me the initial ram state of any Front Loader NES?
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simple ROM to test power on or reset RAM state

Post by rainwarrior »

You can use an old NES board and remove/replace parts from it if you know what you're doing and want to destroy an old game, but I personally would prefer using a new board.

Myself, I had an old ReproPak board from RetroUSB that I soldered chip sockets into. I burned two EPROMs of appropriate size with an old TOP853 EPROM programmer, and put them in the sockets.

The ReproPak isn't available anymore but there are lots of people selling similar NES boards. There's a variety of inexpensive EPROM programmers as well. Old UV EPROM chips are pretty easy to get from eBay. Flash EPROM is easier to get new and can be erased more easily.

If you don't know how to solder, you can get a board with flash EPROM chips already on it, and an inexpensive programmer from INL:
http://www.infiniteneslives.com/nessupplies.php
http://www.infiniteneslives.com/kazzo.php
CLChambers00
Posts: 78
Joined: Wed Jul 19, 2017 10:23 am

Re: Simple ROM to test power on or reset RAM state

Post by CLChambers00 »

Thanks for the reply. Which specific item would I need on http://www.infiniteneslives.com/nessupplies.php

The item shown at http://www.infiniteneslives.com/kazzo.php is not available. And the TOP853 USB Universal Programmer is not being sold on Ebay at the moment, do you have another recommendation?

So basically I would buy one of these boards from INL, remove the chip and use a EPROM programmer on it, and then put the chip back in, no soldering needed. Very easy to do?
CLChambers00
Posts: 78
Joined: Wed Jul 19, 2017 10:23 am

Re: Simple ROM to test power on or reset RAM state

Post by CLChambers00 »

Also I just read what you wrote about seeing lots of variance on your RAM state at power on. I know with some games, Metroid in particular, which has at least one memory address value taken from the initial state that influences RNG, that some people can get a certain pattern from power on each time, which leads me to believe that this particular address seems to go back to a starting value instead of retaining its last value, though I don't understand how that can be.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simple ROM to test power on or reset RAM state

Post by rainwarrior »

CLChambers00 wrote:Which specific item would I need on http://www.infiniteneslives.com/nessupplies.php
This specific test is NROM.
CLChambers00 wrote:The item shown at http://www.infiniteneslives.com/kazzo.php is not available. And the TOP853 USB Universal Programmer is not being sold on Ebay at the moment, do you have another recommendation?
For programming INL's flash boards, you need the kazzo specifically, so I guess wait for new ones to become available.

For programming EPROM generically, there are a lot of different EPROM programmers. Willem makes some popular ones. I can't recommend a specific one. The TOP853 I have is not a "good" one, but there's not really a difference in the end result between one programmer and another as long as they function correctly. I think some people have managed to build an inexpensive one using an arduino as a base.
CLChambers00 wrote:So basically I would buy one of these boards from INL, remove the chip and use a EPROM programmer on it, and then put the chip back in, no soldering needed. Very easy to do?
With INL the boards are designed to be flashed via the carrtridge connector. There is no need to remove the chip.

With non-Flash boards, generally what you want to do is install (solder) a chip socket where the chips go so you can put the EPROM in and out without having to do any soldering between tests.

Here's one alternative board: https://www.game-tech.us/product/reprox/
Though the ReproPak is not being sold anymore, its manual may give you some idea of how these kinds of boards are used: http://www.retrousb.com/product_info.php?products_id=42
There's others too, just search for NES reproduction boards: https://www.muramasaentertainment.com/i ... -nrom.html
Or you can cannibalize an existing NES game: http://callanbrown.com/index.php/basic-nes-reproduction

They're all basically the same design and work the same way, so learning about one will gain useful information about the other.
CLChambers00 wrote:Also I just read what you wrote about seeing lots of variance on your RAM state at power on. I know with some games, Metroid in particular, which has at least one memory address value taken from the initial state that influences RNG, that some people can get a certain pattern from power on each time, which leads me to believe that this particular address seems to go back to a starting value instead of retaining its last value, though I don't understand how that can be.
I'll make a sort of simplified description, probably a little inaccurate but should give the idea:

Bits in RAM are a device that take an existing charge and continually amplify it to maintain it at 0 or 1. When you're powering it on, the signal is very weak, and the circuit is deciding whether a signal that's in a very questionable range should be driven toward 0 or 1.

This is a device with many thousands of those bits. They're made to be reliable within a certain tolerance, but it doesn't matter if the bit splits between 0 and 1 at 0.5, or if it split at 0.4 or 0.6, etc... that doesn't really matter whenever the input signal coming in is strong. To split at exactly 0.5 you'd need the two sides of the amplifier to be perfectly balanced, but in practice you only need them balanced well enough for tolerantly reliable behaviour, so it doesn't have to be that accurate. This difference only really has an effect at power-on, where some particular bits might have a tendency to power on in a 0 or 1 more often.

The weak starting signal is subject to all sorts of noise, existing static charges in the chip, temperature and ambient or interfering electromagnetic radiation in the environment, etc. When the signal is weak enough all sorts of things can be affecting it. When you power off and on an SRAM very quickly, it tends to retain most of the bits it last had in it. When you power it off for longer, the charges tend to drain out and balance into a potentially more consistent starting state. The longer it's powered off, the closer you'll get to the chip's natural starting equilibrium and have the best chance of powering on with a consistent value. (Still only a chance though.)

Not all RAM is created equally, some have stronger tendencies than others. The contents at power-on aren't something the chip has to do anything consistent with, by design it doesn't matter, so there's a ton of variation here. Some might tend tend to have mostly 0, or mostly 1 bits, for example, if the bias is consistent.


Anyhow, this test ROM was designed to to take a look at this kind of thing. The results I found were that mine are indeed pretty random. I didn't even see much tendency when they were powered off for longer times.

As for looking at specific games, you should know that this program initialized a few bytes of RAM in order to operate, but you could easily rebuild it to move those bytes elsewhere if by bad luck they overlap the bytes the games you're interested in use for their uninitialized behaviour that you're trying to target. (This is one reason why it's useful to have a socketed board, or use a flashable one that you can rewrite the chips for. You may need to try different tests. You could also use it to try other mapper-compatible games and experiments as well.)

I don't know about uninitialized behaviour in Metroid, but I do know that it gathers some randomness from how many frames it spends on the title screen, so even if it was a consistent startup value it might need frame perfect input to be consistent after that anyway.
User avatar
infiniteneslives
Posts: 2104
Joined: Mon Apr 04, 2011 11:49 am
Location: WhereverIparkIt, USA
Contact:

Re: Simple ROM to test power on or reset RAM state

Post by infiniteneslives »

Doing everything I can to get new manufacturing of new programmers ramped up and released by end of this month (March 2018). I failed to get board files out before CNY which caused me to fall short of this goal last month.. If you sign up for the newletter on my homepage you'll get email notification when new products release including the new inlretro/kazzo programmer.
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers
CLChambers00
Posts: 78
Joined: Wed Jul 19, 2017 10:23 am

Re: Simple ROM to test power on or reset RAM state

Post by CLChambers00 »

Thanks for the response. It was very informative and good enough to read again in the future to deepen my understanding of it.

Also, I will sign up for the newsletter.

Additionally, for whatever reason the japan release of Metroid was better programmed because the US release seems to have broken its RNG. In the Japan version the RNG is calculated each frame yielding different results per frame. But in the US version, I am told, that the RNG is broken in that the first comparison of these two ram addresses sets the RNG, and no matter all subsequent comparisons the same outcomes is the result. This is how people have been able to get the same Ridley fireball pattern every time based on this phenomenon with certain consoles.

What has really interested the Metroid speedrunning community is that one of these memory addresses is initialized while the other is not, which gives some people a default good pattern or bad pattern. The present world record holder has a top loader that always gives bad pattern on power on, with slight change of good due to power on variance, which I still don't completely understand from our discussion of Who Framed Roger Rabbit.

I bought up a lot of $20 - $40 NES consoles from Ebay to see if I can find a good NES that will help him in this matter. I plan to clean and replace 72 pin connector and resell them.

We have also been discussing the influence of PowerPak and Everdrive on this one RNG related uninitialized memory address. Some have reported that they can get a good pattern from power on with their PowerPak and so the discussion has gravitated to the legitimacy of using a flash cart for Metroid since it is "modifying" this address, instead of reliance upon what value is attained through original hardware alone.

I must ask, if you happen to know, just before the ROM is loaded, does the PowerPak or Everdrive preset the RAM state to all 00 or FF or something similar in prep to load the ROM, or does it simply load the ROM over what was change only by the operating system from power on?

Also, speaking of Everdrive, I wonder if there is a way to determine precisely how it compiles its save state file. If someone could find this, and figure out how to convert it to a save file for use with say Bizhawk, we could hypothetically do a save state with the Everdrive of Who Framed Roger Rabbit at the earliest possible moment, and then load this up in Bizhawk with a Lua Script to map out the results we could get from original hardware and confirm that there are actually 4 distinct RNG paths for that game, based on what I read from our other discussion that even if I pressed start on the same frame I would still only have a 25% chance of getting the right RNG.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simple ROM to test power on or reset RAM state

Post by rainwarrior »

PowerPak and Everdrive both need to initialize at least some of RAM (if not all of it) to run their menu programs, etc. You could check the source code for their menus to be sure, or run this test ROM to investigate.

I don't think either of them explicitly leaves it cleared as 00s or FFs before running the game, it just boots the game with whatever was leftover. Probably you would have filenames and stuff scattered across it.

So, no, the RAM values at boot from a flash cart are going to be completely different than what you'd get at power-on directly. Probably you'd get the same result every time if you used the same CF/SD card contents and booted from the menu in the same way, not dependent on the underlying NES.
Post Reply