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.

Coding > GBA timers and VSync (basic question)

#22676 - Wriggler - Sat Jun 26, 2004 7:33 pm

Hi there,

I'm learning basic GBA programming with a bloke at work, and we're going through the tutorials in our own time and occassionally meeting up and comparing notes.

However, yesterday he told me that the GBA has 4 internal timers. Is that right? Why would you need four? What's the difference between them?

He mentioned how it was quite tough to sync your code to a timer so it runs at a constant frame rate. To which I replied, why can't you just watch what the VSync is doing and base your game timings from that? To my understanding, the vsync is all done by hardware and it doesn't wait for your code to finish whatever it's doing before it starts drawing the next frame...

I'm sure there's a really good reason, but why does the GBA need these timers when it's got the VSync in memory which constantly updates itself (or does it)?

Cheers for the help, apologies if it's a newbish question but I am infact, a newb... :)

Ben

#22680 - poslundc - Sat Jun 26, 2004 8:11 pm

First of all, your friend is wrong: it's easy to synchronize your game to the GBA's refresh rate (approx 60 Hz) pretty much the way you're describing, by watching for the VBlank status to change.

The timers are useful more for specialized tasks like controlling the GBA's sound chip, timing a music player, or when you want specific tasks to interrupt your main code after a period of time has elapsed.

But yes, use a loop that runs once every VBlank to control the game's state and keep track of time in general.

Dan.

#22681 - dagamer34 - Sat Jun 26, 2004 8:22 pm

There's no difference between the 4 timers. It's just that you can use 4 at the same time. Some people use them for audio mixers, others for vblank effects, etc. Anything that requires a time interval can use a timer so you don't have to waste time counting how many vblanks have passed (though it still works).
_________________
Little kids and Playstation 2's don't mix. :(

#22684 - Wriggler - Sat Jun 26, 2004 10:17 pm

Excellent, so we were both right :) Thanks guys!

Now that I think about it, it does make sense to have more specific timers to calculate sound and other things. But for the time being I'll stick to using the VBlank... seems to work for everything I need so far.

Cheers,

Ben