VBlank synchronization?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
ehguacho
Posts: 83
Joined: Tue Mar 09, 2010 11:12 pm
Location: Rosario, Argentina
Contact:

VBlank synchronization?

Post by ehguacho »

hi! i have a doubt in how to synchronize my emulator with VBlank.
i know there's an Allegro function called "vsync()" that automatically waits for VBlank, but as read it's very reliable. so how i know when vblank is happening? do i have to manually set $2002.7 to 1 when VBlank is happening?

thanks in advance for any reply
sorry about my english, i'm from argentina...

http://nestate.uuuq.com
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

The refresh rate of your computer (which is what the Allegro functions are based on, I assume) has nothing to do with the refresh rate of the emulated machine (the NES).

You know when the NES VBlank happens when the time of a frame has passed. Your emulator has to keep track of time in the form of PPU cycles. Since each frame has a known number of scanlines, and each scanline has a known number of cycles, you'll know when a frame is complete, and at that time you set the VBlank flag.
User avatar
ehguacho
Posts: 83
Joined: Tue Mar 09, 2010 11:12 pm
Location: Rosario, Argentina
Contact:

Post by ehguacho »

ok thanks Tokumaru!
sorry about my english, i'm from argentina...

http://nestate.uuuq.com
Post Reply