Quietust wrote:
SEI is unneeded because all interrupts (including Reset) set the I flag, and CLD isn't needed specifically because the NES doesn't do decimal mode.
blargg wrote:
At the very least, the decimal flag is pushed on the stack whenever flags are saved, which a bug might pick up and cause random behavior based on.
So you're saying that since omitting the CLD instruction could cause buggy code to behave in a buggy way, you shouldn't remove it?
When you oversimplify it, of course the answer seems obvious. In reality, it's a choice between coding your reset so that in rare circumstances on perhaps rare revisions of the NES, your program state will be slightly different than normal and could trigger an obscure but, or coding your reset so that the NES state is as consistent as possible in all cases so that it any bugs that will manifest will do so on your own hardware more often, or will remain latent. And then during development you can root out things like this by intentionally altering whatever NES state your program's not supposed to be depending on, and see what bugs you bring out reliably.
There's also the question of what's a bug and what's by design. If you can place the NES into a consistent state in your reset routine, you have the option of considering code that depends on this buggy or correct. Why would you not consider depending on this state a bug? For the same reason you allow any piece of code to depend on other things being set up beforehand.
Regardless of what one considers a bug, it's just asking for Murphy's Law to strike if you don't fully initialize everything in the NES at reset for your release build. You're leaving state around that's available for a bug to pick up and behave in a bad way when some particular value happens to be there, one that happens to come up on someone
else's NES. Develop with memory randomization or something, then release with a consistent initialization pattern, so you fix what you can find, then make latent whatever is remaining, or at least make it dependent on what's done after reset, and not what the static RAM and other registers happen to power up with.