How do I use Vblank?
Moderator: Moderators
-
- Posts: 318
- Joined: Mon Jan 30, 2017 5:20 pm
- Location: Colorado USA
How do I use Vblank?
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.
Re: How do I use Vblank?
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:
- Make an NMI handler, which is a special kind of subroutine that ends with RTI instead of RTS.
- Set the vector at $FFFA to point to the NMI handler. Exactly how this is done depends on the assembler you're using.
- 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 main program waits for the variable to change and then proceeds to update video memory.
- 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.
-
- Posts: 318
- Joined: Mon Jan 30, 2017 5:20 pm
- Location: Colorado USA
Re: How do I use Vblank?
I don't know, none of the assemblers I've ran into ever seem to work.
Re: How do I use Vblank?
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:
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.
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: Select all
nesasm3 code.asm
These steps cannot be skipped. Otherwise, you'll never get anywhere, let alone close to using vblank.
Re: How do I use Vblank?
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.DementedPurple wrote:I don't know, none of the assemblers I've ran into ever seem to work.
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.
-
- Posts: 318
- Joined: Mon Jan 30, 2017 5:20 pm
- Location: Colorado USA
Re: How do I use Vblank?
Okay then, so how would I use the NMI?
Re: How do I use Vblank?
tepples explained one way to do it.
Re: How do I use Vblank?
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
Nerdy Nights covers most of it pretty good, although it's not perfect:
http://nintendoage.com/forum/messagevie ... eadid=7155
Re: How do I use Vblank?
Doesn't Nerdy Nights use the less-than-ideal "everything in the NMI" model?
Re: How do I use Vblank?
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.
Re: How do I use Vblank?
Nerdy nights isn't perfect but there isn't a lot of other choices.
-
- Posts: 318
- Joined: Mon Jan 30, 2017 5:20 pm
- Location: Colorado USA
Re: How do I use Vblank?
I can't find a tutorial anywhere that mentions the address of NMI
Re: How do I use Vblank?
It's like the reset address: you set it in the last six bytes of your game.
-
- Posts: 318
- Joined: Mon Jan 30, 2017 5:20 pm
- Location: Colorado USA
Re: How do I use Vblank?
How do I do that?
Re: How do I use Vblank?
What assembler are you using?