Normally there is no need to check the timer yourself..
The normal timer usage is this:
Set the correct period to use.. (every 1, 64, 256 or 1024 clocks)
Set the start value by writing to TMxCNT_L, this is the value at which
the timer will start every time it overflows or gets started.. Standard
this is 0
Set the interrupt and enable it
Start the timer..
Now the timer will start at the start value, get increased every period
of clocks, and on overflow the interrupt will get called, in which you
do the handling..
http://www.suddenpresence.com/sgade/ has a nice implementation, you
might wanna look for sourcecode there
Now to your problem:
while(REG_TM3D < 263)
Depending on the period you chose, this situation will occur fast to
VERY fast. That's why you probably don't even notice it waiting..
With a period of 1 it takes 0.000015676021575927734375 seconds to make
the timer reach 263
With a period of 64 it takes 0.001003265380859375 seconds to make the
timer reach 263
With a period of 256 it takes 0.0040130615234375 seconds to make the
timer reach 263
With a period of 1024 it takes 0.01605224609375 seconds to make the
timer reach 263
So in the best case, it will only be a wait of 1/100ths of a second,
hardly noticable most of the times..
If you put in a WaitVblank(), after each check it waits an entire frame
before it checks again, obviously this will lead to incorrect results..
One other point you should check, is wheter that define use a volatile
pointer, else the compiler will optimise it away
But I think that's not the problem
Hope that helps,
Willem
> -----Original Message-----
> From: Roman Schaub [mailto:roman@...]
> Sent: Thursday, September 05, 2002 16:19 PM
> To: gbadev@yahoogroups.com
> Subject: [gbadev] timer-problems
>
>
> hello there..
>
> since i need a timer in my game, i tried to create a function
> which uses one of the internal timer registers (obviously).
> the problem i encountered was:
>
> if i create a while-loop and check the value of the counter,
> it never stops! (means: the cpu doesn't check the value of
> the counter, but if i insert something like
> "WaitforVBlank()" into the while-loop, the counter works
> correctly (but significantly slower...).
>
> while(REG_TM3D < 263){} //doesn't work
>
> while(REG_TM3D < 263){WaitVblank();} //works....
>
> i also tried to enable the interrupt-on-overflow...didn't
> work either...
>
> it just seems that counting occupies the cpu to 100% so he
> doesn't have the time anymore to check if the
> abort-conditions have already reached... i really don't have
> a clue how to fix that.
>
> cheers
>
> roman