Paperboy and Power Up Timing

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Alyosha_TAS
Posts: 173
Joined: Wed Jun 15, 2016 11:49 am

Paperboy and Power Up Timing

Post by Alyosha_TAS »

Paperboy is an interesting and useful game to test powerup timing with because it uses the initial 'wait for vbl flag' loop to seed the house RNG. As long as you start the game before the demo starts, you get a consistent house layout. About 90% of the time (testing on front loading NES with G model ppu), I get houses that looks like this:

Image

This corresponds with the expected power up time it takes as referenced with the wiki (assuming vbl flag starts off.) It also matches what I see in youtube videos of the game.

The other 10% of the time (mostly after resets but can persist for a shot time through power cycles) I get this arrangement:

Image

My assumption was that this was the result of the VBL flag being on at reset, but upon trying to recreate this in emulator, I am unable to. In fact, with VBL flag on at reset, the game starts writing to registers before they should be available.

Code: Select all

809A:  A9 90     LDA #$90        A:00  X:00  Y:01  SP:FF  P:26  nvTbdIZc  Cy:28049
809C:  8D 00 20  STA $2000       A:90  X:00  Y:01  SP:FF  P:A4  NvTbdIzc  Cy:28051
(then it waits for NMI.)

It seems like this should result in a hang, but I've never seen a hang on console.

I've tried to reproduce the unusual housing arrangement in emulator by varying powerup timing over a fairly wide window but cannot reproduce it. I've tried using Mesen's randomize cpu/ppu alignment setting as well but it always gives the usual arrangement.

So right now I'm pretty stumped, it should hang with VBL on as far as I can tell but it never does, and console gives a house arrangement that I cannot reproduce.

Seems like a pretty big coincidence to me, like somehow the console is filtering out the times when VBL started on and somehow resulting in the unusual arrangement by some process instead.

I should note that I also tried powering up Donkey Kong numerous times in accordance with this thread: viewtopic.php?f=3&t=19792 and never saw any zeroes.

If I just let all ppu writes proceed as normal, I get a different arrangement altogether, so that's not it either.

If anyone can offer any insight into any of this please do, this is very perplexing.
Alyosha_TAS
Posts: 173
Joined: Wed Jun 15, 2016 11:49 am

Re: Paperboy and Power Up Timing

Post by Alyosha_TAS »

One possibility I thought of is that maybe the VBL flag is random at power on, but only for a short time before it gets pulled down. I noticed that in blargg's original testing he started sampling the $2002 flag almost right away, but in Paperboy it doesn't happen until almost 800 cpu cycles after power on. That might explain why the early flag is never seen, but still not the unusual house arrangement, I still can't reproduce that.

Just a guess though, really needs some hardware tests.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Paperboy and Power Up Timing

Post by lidnariq »

Alyosha_TAS wrote: Thu Jun 24, 2021 3:00 pm One possibility I thought of is that maybe the VBL flag is random at power on, but only for a short time before it gets pulled down. I noticed that in blargg's original testing he started sampling the $2002 flag almost right away, but in Paperboy it doesn't happen until almost 800 cpu cycles after power on. That might explain why the early flag is never seen, but still not the unusual house arrangement, I still can't reproduce that.
Not really. It shouldn't change the state that's read after ... at most a couple microseconds after power is applied (not just released from reset), up until the time that 262 (or 312) scanlines have passed.
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: Paperboy and Power Up Timing

Post by Fiskbit »

I looked into this issue a bit last year, but didn't come to any conclusion. I really need to get a writable cartridge that lets me run code from power-on to narrow down exactly what is going on in weird cases like this.

My understanding is that the game is running its random number generator in the initial wait for PPU init:

Code: Select all

805A    JSR $8151                
805D    LDA $2002                
8060    BPL $805A                
One suggestion I have is to try various numbers of iterations of the random number routine to figure out which one is giving the alternate house order. Each loop takes 85 cycles, so it's a lot of possibilities (about 350 if the loop runs for any possible fraction of a frame), but maybe there's a fast way to check which one real hardware is settling on, such as automating it to try all possibilities, take a screenshot on the house screen for each one, and compare that screenshot to one that matches the alternate house order (or finding the RAM representation of house order and comparing against one matching the alternate one). How long the loop has to run to get this result might clue us in on what's happening. In Mesen, I tried making the loop take one iteration more and one iteration less, and neither matched the alternate order.

Note that the thread you linked had some weird results in it. BMF54123 was able to get carts that don't wait for PPU init to work sometimes, but not other times. This doesn't make sense to me if the CPU and PPU are released from reset at the same time. If anything, I'd expect the Famicom to be the one that has variance in the PPU's head start because of the way the CPU comes out of reset, while the frontloader would be reasonably consistent.
Alyosha_TAS
Posts: 173
Joined: Wed Jun 15, 2016 11:49 am

Re: Paperboy and Power Up Timing

Post by Alyosha_TAS »

I tried varying power up timing over a 2 frame window and did not see the exact house arrangement console gives. So yeah I'm also thinking it must be some non-standard power up state. But that is the only other arrangement I see on console, so it's also consistent, however it comes about. Also I tried again and it seems I never see this unusual arrangement from cold power on , always first after a reset, but then it can persist through power cycles of short duration.

The simple explanation is that my console always powers up with VBL reset and that the reset button occasionally brings it into some consistent but unknown state.

I think that means that Time Lord should never work on my console from a cold power up? I guess I need to get that game and find out.
Post Reply