It is currently Mon Sep 16, 2019 1:37 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Sat Aug 24, 2019 11:19 am 
Offline

Joined: Sat Aug 24, 2019 9:42 am
Posts: 2
I have a few very basic questions about the Hello World program that comes with NESICIDE 2.

First, in .proc reset, there is a brief loop:
Code:
vwait1:
bit PPUSTATUS
bpl vwait1


Which is then followed by initializing a few values.
Then we get to

Code:
vwait2:
bit PPUSTATUS
bpl vwait2


Why is vwait1 even included in the code?
It appears to me that this program loops the 'vwait1' portion until the PPU is ready, then sets a few values, then does 'wait2', but by that time the PPU is already warmed up.
If I comment out vwait1, (all three lines mentioned above) the compiled program appears to run just as well.
The basic process is then: Power on console. Initialize a few values, then wait for PPU before proceeding.


Top
 Profile  
 
PostPosted: Sat Aug 24, 2019 1:02 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7582
Location: Canada
Nukatha wrote:
If I comment out vwait1, (all three lines mentioned above) the compiled program appears to run just as well.

Test it on hardware and you'll find out the difference. Emulators don't tend to cover this issue.

The PPU takes a little more than 1 full frame to initialize itself after reset. You need to wait at least that long before using it.

https://wiki.nesdev.com/w/index.php/PPU_power_up_state

Blargg's testing notes show a good example: http://forums.nesdev.com/viewtopic.php?f=2&t=3958

It's not just NESICIDE it's pretty much every NES program ever written. Though I've seen a few games get by with just "doing a bunch of stuff" before using the PPU rather than explicitly waiting like this. There's really very little reason to do it any other way besides the vblank waits, though. Two wait loops on $2002 is safe and effective and small code, easy to implement and not very prone to error. (Make sure to read $2002 once before the first wait loop though.)

A lot of people like to stick a standard memory clearing routine in between the two waits so that some work is being done during the wait, though really it doesn't matter much. Unless you're a robot one extra frame after reset isn't a significant thing.

There's some example "standard" initialization here: Wiki: Init code


Last edited by rainwarrior on Sat Aug 24, 2019 2:08 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sat Aug 24, 2019 2:08 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 8557
Location: Seattle
To very quickly summarize everything:
* The PPU is only ready after 262 (or 312 on PAL) scanlines have passed
* The bit in PPUSTATUS becomes true after only 240 scanlines have passed, so it's not sufficient to determine whether the PPU is ready
* The bit in PPUSTATUS may be incorrectly be set after a warm reboot.

The amount of time (and bytes of code) taken to wait for an extra vblank is so small and rare that it's not worth optimizing, and getting it wrong could cause glitchy results.


Top
 Profile  
 
PostPosted: Sat Aug 24, 2019 2:25 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11412
Location: Rio de Janeiro - Brazil
rainwarrior wrote:
Test it on hardware and you'll find out the difference.

Do note that "on hardware" in this context excludes Flash carts with a menu, such as the PowerPak or the Everdrive, because those only call your program after the system is fully initialized.


Top
 Profile  
 
PostPosted: Sat Aug 24, 2019 2:49 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7582
Location: Canada
tokumaru wrote:
rainwarrior wrote:
Test it on hardware and you'll find out the difference.

Do note that "on hardware" in this context excludes Flash carts with a menu, such as the PowerPak or the Everdrive, because those only call your program after the system is fully initialized.

Actually, the PPU warmup state is triggered by reset, so you can test the problem with these on an NES. (Famicom does not reset its PPU so you can't do it there.)

Power-on state is still inaccessible but reset is enough to test this.


Top
 Profile  
 
PostPosted: Sat Aug 24, 2019 3:43 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21591
Location: NE Indiana, USA (NTSC)
rainwarrior wrote:
Unless you're a robot one extra frame after reset isn't a significant thing.

And even if you are a robot, you probably wait for the first pulse on $4016 D0 before you start replaying inputs.

rainwarrior wrote:
Actually, the PPU warmup state is triggered by reset, so you can test the problem with these on an NES. (Famicom does not reset its PPU so you can't do it there.)

But only on a front-loading NES. Like the Famicom, the top-loading NES doesn't reset the PPU.

_________________
Pin Eight | Twitter | GitHub | Patreon


Top
 Profile  
 
PostPosted: Sat Aug 24, 2019 8:51 pm 
Offline

Joined: Sat Aug 24, 2019 9:42 am
Posts: 2
Many thanks to each of you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group