Page 1 of 1

VBlank synchronization?

Posted: Sat May 15, 2010 12:57 pm
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

Posted: Sat May 15, 2010 1:21 pm
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.

Posted: Sat May 15, 2010 1:48 pm
by ehguacho
ok thanks Tokumaru!