It is currently Tue Jul 25, 2017 7:50 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 65 posts ]  Go to page 1, 2, 3, 4, 5  Next
Author Message
 Post subject: How do I use Vblank?
PostPosted: Tue Feb 21, 2017 11:26 am 
Offline

Joined: Mon Jan 30, 2017 5:20 pm
Posts: 272
Location: Colorado USA
For the game I'm designing I need to use the Vblank bit, but I don't exactly understand how I'm supposed to access it. Is it a memory address? I don't know.


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Tue Feb 21, 2017 11:55 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 18673
Location: NE Indiana, USA (NTSC)
Vertical blanking (vblank) is the period between frames, during which your program can write to video memory through the PPU. It lasts about 2,270 cycles, after which point the rendering logic takes control of video memory again for the next frame. To be notified that vblank has occurred, you need to do three things:

  1. Make an NMI handler, which is a special kind of subroutine that ends with RTI instead of RTS.
  2. Set the vector at $FFFA to point to the NMI handler. Exactly how this is done depends on the assembler you're using.
  3. Set bit 7 of PPUCTRL ($2000) to 1. If bit 7 of PPUCTRL is 1, the CPU will call the NMI handler at the start of every vblank.

The NMI handler usually sets a variable in memory notifying the main program that vblank has occurred. There are two schools of thought on how to organize a game loop:

  1. The main program waits for the variable to change and then proceeds to update video memory.
  2. The main program sets a variable that the updates have been prepared in video memory, the NMI handler does the video memory updates and clears the ready variable, and then the main program waits for the variable to change before beginning the next frame of game logic. This method resembles multithreading, and it's more stable if you're using a raster split such as a status bar.

Which assembler are you using? Is it NESASM, asm6, ca65, or something else?


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Tue Feb 21, 2017 5:30 pm 
Offline

Joined: Mon Jan 30, 2017 5:20 pm
Posts: 272
Location: Colorado USA
I don't know, none of the assemblers I've ran into ever seem to work.


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Tue Feb 21, 2017 6:23 pm 
Offline
User avatar

Joined: Wed Oct 16, 2013 7:55 am
Posts: 120
What was the problem when you tried to use these assemblers?

In a previous thread, it seemed like you were trying to double-click on the assembler executables. If that's what's happening, you need to learn all about the command-line and how to use command-line applications. Read this - http://www.makeuseof.com/tag/a-beginner ... mand-line/ Once you're done with that, you need to "cd" to the directory that has the assembler and run a command such as:

Code:
nesasm3 code.asm


Where "code.asm" is a source file that contains your assembly code.

These steps cannot be skipped. Otherwise, you'll never get anywhere, let alone close to using vblank.


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Tue Feb 21, 2017 6:31 pm 
Online
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 9798
Location: Rio de Janeiro - Brazil
DementedPurple wrote:
I don't know, none of the assemblers I've ran into ever seem to work.

Well, they do work, because many people are making games with them... But they're not magical, you have to know what you're doing. :wink:

Anyway, don't ever use the vblank bit ($2002.7) to control the frame rate of your games. The PPU has a bug that causes a false negative to be returned in that bit if the register happens to be read at the exact time vblank starts, causing the program to constantly miss vblanks. The reliable way to detect the start of the vertical blank is with NMIs. The NMI is an interrupt that reliably fires every time vblank starts, letting you know it's safe to perform video updates for the next frame.


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Wed Feb 22, 2017 12:41 pm 
Offline

Joined: Mon Jan 30, 2017 5:20 pm
Posts: 272
Location: Colorado USA
Okay then, so how would I use the NMI?


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Wed Feb 22, 2017 1:10 pm 
Online
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 9798
Location: Rio de Janeiro - Brazil
tepples explained one way to do it.


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Wed Feb 22, 2017 4:06 pm 
Offline

Joined: Tue May 28, 2013 5:49 am
Posts: 631
Location: Sweden
Make sure you understand the basics.

Nerdy Nights covers most of it pretty good, although it's not perfect:
http://nintendoage.com/forum/messagevie ... eadid=7155


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Wed Feb 22, 2017 4:54 pm 
Online
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 9798
Location: Rio de Janeiro - Brazil
Doesn't Nerdy Nights use the less-than-ideal "everything in the NMI" model?


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Thu Feb 23, 2017 12:56 am 
Offline

Joined: Tue May 28, 2013 5:49 am
Posts: 631
Location: Sweden
Yep, so it's not perfect (and it also has a few other flaws). But I mean it teaches other things, like working the assembler, I think.


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Thu Feb 23, 2017 5:20 am 
Offline
User avatar

Joined: Wed Sep 21, 2016 8:55 am
Posts: 53
Location: Calgary.Alberta,Canada
Nerdy nights isn't perfect but there isn't a lot of other choices.


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Sun Mar 12, 2017 1:10 pm 
Offline

Joined: Mon Jan 30, 2017 5:20 pm
Posts: 272
Location: Colorado USA
I can't find a tutorial anywhere that mentions the address of NMI


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Sun Mar 12, 2017 1:19 pm 
Online

Joined: Sun Apr 13, 2008 11:12 am
Posts: 5924
Location: Seattle
It's like the reset address: you set it in the last six bytes of your game.


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Sun Mar 12, 2017 1:20 pm 
Offline

Joined: Mon Jan 30, 2017 5:20 pm
Posts: 272
Location: Colorado USA
How do I do that?


Top
 Profile  
 
 Post subject: Re: How do I use Vblank?
PostPosted: Sun Mar 12, 2017 1:27 pm 
Online

Joined: Sun Apr 13, 2008 11:12 am
Posts: 5924
Location: Seattle
What assembler are you using?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 65 posts ]  Go to page 1, 2, 3, 4, 5  Next

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:  
cron
Powered by phpBB® Forum Software © phpBB Group