Mail Archives: djgpp/1997/04/17/15:31:35
admcs AT megsinet DOT net (Paul Schmidt) writes:
> Is it possible to have a counting timer, like how many seconds (fix 1, i.e.
> 28.4 secs) and is there functions to start pause and stop a timer after you
> create it?
No, at least not with the existing API. You'd have to extend the source
for that.
What you want is not as straightforward as it looks, because Allegro's
timer interrupt essentially tells the system timer when it will need the
next timer interrupt, rather than receiving regular interrupts at an
accelerated rate. So a stopwatch has no way of getting itself serviced,
but you can still make it give a very exact time.
To make a stopwatch, IMO, you would have to do these things:
Make the ISR itself, my_timer_int, keep a running total of how
long it has gone on. static variable, 1 line of code, easy.
Zero the static variable in the timer init routine. Easy.
Make a function to get reasonably exact time. Grabbing the
static variable will give you a coarser time than you want, so
you have to call read_timer(); to get the offset of time. When
doing this, block my_timer_int with the semaphore momentarily so
that no tick occurs between getting the coarse time and getting
the offset of time.
Obviously, make your add-stopwatch routine remember when it
started.
Obviously, make your read-stopwatch routine tell the current
time.
Obviously, set up an appropriate memory structure and interface
for your stopwatch(es).
Tom "Just got finished hacking timer.c myself"
- Raw text -