gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Game Design > I need more infomation about vsync's and vblanks, etc.

#21102 - mr_schmoe - Sun May 23, 2004 10:11 pm

Ok, I not sure I understand things correctly. If any of you could of some help, and you all have been very much so in the past, that would be fantastic.

What I understand is that the GBA updates the screen 60 times a second. So, does that mean each frame takes 1/60 of seconds to draw? And each scan line takes 1/160 of 1/60 of a second to draw? And if that's true, then after the 160th line is draw, do we only have 1/160 of 1/60 of seconds to update the OAM and do all the other drawing we need to. Because that doesn't seem like much time. If that's not the case, how long do we have? And is the time between the 160th line and the 1st line, is that called the vblank? And what if we take too much time to draw everything? Do we get the same effects as if one didn't wait for a vsync because the GBA is already halfway down the screen before we are finished drawing. And what about vblank interrupts? How do they work and how much time do we have in one of those? So many questions, I'm sorry. I'll probably post some more as the first ones get answered though. Thanks for all your help.

#21105 - poslundc - Sun May 23, 2004 10:47 pm

I refer you to the Cowbite Virtual Hardware Spec.

The GBA's rendering cycle is comprised of two phases: VDraw and VBlank.

VDraw lasts for 160 scanlines (ie. the height of the GBA's screen). This is when the screen is actually being drawn, and when you generally do not want to tamper with anything that affects the video. You can use this time to prepare for the next frame by performing calculations, updating the game world's state, etc.

VBlank lasts for 68 "invisible" scanlines during which the image is sustained on the GBA's screen. Now is when you can safely tamper with video RAM, OAM, etc. without creating screen artifacts.

FYI: The GBA's CPU is 16.78 MHz. Each "scanline" lasts 1,232 cycles. 68 scanlines comes out to 83,776 cycles which is more than enough time for most of the updates you would have to make to the screen.

Scanlines are also broken down into an HDraw and HBlank period. HDraw lasts 1004 cycles and HBlank lasts 228 cycles. HBlank is just barely long enough for you to change some minor elements of the GBA's display on an individual scanline basis, so it's possible to create scanline or "raster" effects such as sinusoidal motion or Mode 7 perspective.

Dan.