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 > Using GBA timer or Counting by frame

#176950 - blessingta@hotmail.co.uk - Sun Nov 06, 2011 2:12 pm

hi

Whats the advantage and disadvantage of counting time either by frame or through looking at the gba clock?

Plus since I've head that gba has a clock, I've been left wondering about how its initialized or called. If you could give me some code on that it would be nice, I'm increasingly running out of time to complete this project

#176953 - Dwedit - Sun Nov 06, 2011 6:26 pm

There's 4 GBA timers, they are for high-speed events, such as the time it takes to output a single audio sample. Time frequencies usually measured in kilohertz. When they count up to 65536, they reset to zero. They are not suitable for time counting where you'd encounter units like seconds or minutes.

There's no real-time clock that keeps time persistently, unlike the NDS.

For time keeping, counting frames should be enough.
If you need precision finer than 1/60 seconds, you can also use the scanline counter. There are scanlines numbered between 0 and 227, and Vblank (when you increment your "frame number" variable) happens at #160. So add 67 then subtract 228 if it's >= 228, that gives you the number of scanlines since vblank.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#176956 - Miked0801 - Mon Nov 07, 2011 4:35 pm

VBlank counting is how we did external timers in all our games. Just take the vblank count divides by 59.7(ish) and it was accurate to a second or so per hour.

#176966 - blessingta@hotmail.co.uk - Wed Nov 09, 2011 8:41 pm

you mean counting by frames? I've already been suggested that and had implemented it. I had just began to wonder whether it was the best strategy for it

#176970 - Miked0801 - Thu Nov 10, 2011 4:49 pm

Nothing wrong with simplicity. It won't give millisecond resolution like internal timers, but its much easier to code and test.