It is currently Tue Oct 24, 2017 12:50 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sun May 24, 2015 8:31 am 
Offline
User avatar

Joined: Mon Dec 22, 2008 10:45 pm
Posts: 311
Location: Argentina
Is it correct to wait for 262x341* PPU cycles have passed and then set 2002.7 to 1 and immediately start NMI?
Should one of them start earlier? how much?

*: I'm not accounting for the 340 cycle scanline odd frames yet, and this is NTSC only of course.


Top
 Profile  
 
PostPosted: Sun May 24, 2015 12:34 pm 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3944
I think they happen at the same time. But note that your typical read instruction does the read at the last cycle, so it's possible to begin a read instruction before NMI happens. The read instruction will read the vblank flag before the NMI happens, and that would cancel the NMI from ever happening.
Also, if the read happens on the exact cycle when NMI is set, it will read back 0 for that bit, and cancel NMI as well.

In PocketNES, I used a hack so that any pollable flag will be set 4 CPU cycles before the event happens, so the read instruction will see the flag change before the event happens.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
PostPosted: Mon May 25, 2015 10:09 am 
Offline
User avatar

Joined: Mon Dec 22, 2008 10:45 pm
Posts: 311
Location: Argentina
Oh, so this might happen very frequently, as the main game loop usually enters a loop { LDA $2002; BPL } to wait for the next frame, right?
PS: Do you have an emulator written in other than Assembler?


Top
 Profile  
 
PostPosted: Mon May 25, 2015 10:40 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10068
Location: Rio de Janeiro - Brazil
Petruza wrote:
Oh, so this might happen very frequently, as the main game loop usually enters a loop { LDA $2002; BPL } to wait for the next frame, right?

This is what early homebrew programs did, before we found out about this issue. In order to reliably detect VBlank, you have to use the NMI.


Top
 Profile  
 
PostPosted: Tue May 26, 2015 1:15 am 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
I don't know why, but im my emu i do the following "hack" to pass Blargg's test: at cc 1 of vblank i set the flag then at cc 3 check if vblank flag is set and if nmi_on_vblank is set and set a preliminay "ppu_nmi_pending" flag. Now if this ppu_nmi_pending flag is set i delay to cc 15 to set the "nmi_pending" flag on the cpu. This throw me an error in 1942 that leaves screen letters unredeable. And at the same way if i trigger the nmi the same time the flag is set Bomberman hangs in its init screen.

_________________
ANes


Top
 Profile  
 
PostPosted: Tue May 26, 2015 6:45 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 10:45 pm
Posts: 311
Location: Argentina
tokumaru wrote:
This is what early homebrew programs did, before we found out about this issue. In order to reliably detect VBlank, you have to use the NMI.

Oh ok, so they set some flag in RAM from the NMI subroutine and then check for that instead of 2002.7? because the main game loop has to know where to stop and loop again.


Top
 Profile  
 
PostPosted: Tue May 26, 2015 6:46 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
That's correct.


Top
 Profile  
 
PostPosted: Tue May 26, 2015 6:47 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19122
Location: NE Indiana, USA (NTSC)
Quote:
so they set some flag in RAM from the NMI subroutine and then check for that instead of 2002.7?

NMI#Race condition describes how this works.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 10 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