Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


GBA question

This topic is 6105 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i was thinking of puting something to my game code, like a timer that would tell me when 1/30th of a second has passed so that i can lock my animations to 30 fps cause thats the speed i made them at is that a good idea? how would i do it?

Share this post

Link to post
Share on other sites
The GBA has 4 built-in timers, and they can be set to four different frequencies: once every 1, 64, 256, or 1024 clock ticks (which correspond to about 0.056, 3.8, 15.2 and 61 microseconds). There are 8 registers for the timers. For each timer, there is a control register and a register that actually tells you how much time has elapsed. They are defined as:

#define REG_TM0D *(u16*)0x4000100
#define REG_TM0CNT *(u16*)0x4000102
#define REG_TM1D *(u16*)0x4000104
#define REG_TM1CNT *(u16*)0x4000106
#define REG_TM2D *(u16*)0x4000108
#define REG_TM2CNT *(u16*)0x400010A
#define REG_TM3D *(u16*)0x400010C
#define REG_TM3CNT *(u16*)0x400010E

To initialize the timers, use the following definitions:

#define TIME_FREQUENCY_64 0x1
#define TIME_FREQUENCY_256 0x2
#define TIME_FREQUENCY_1024 0x3
#define TIME_OVERFLOW 0x4 // This causes the timer to increment when the timer below it overflows
#define TIME_ENABLE 0x80
#define TIME_IRQ_ENABLE 040 // This causes it to generate an interrupt when it overflows

REG_TMxCNT = TIME_FREQUENCY_y | TIME_ENABLE; // This enables timer x with a frequency of y
REG_TMxD = 0; // Reset the timer

// Do the following each frame:
start_time = REG_TMxD;

if(REG_TMxD - start_time > some_number) // Has 1/30 of a second gone by?

This is basically the stuff from http://www.thepernproject.com .

Edited by - Aprosenf on February 2, 2002 10:18:36 AM

Edited by - Aprosenf on February 2, 2002 10:20:08 AM

Edited by - Aprosenf on February 2, 2002 10:21:28 AM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!