Newsgroups: comp.os.msdos.djgpp From: tob AT world DOT std DOT com Subject: Re: Timers in Allegro Message-ID: Sender: tob AT world DOT std DOT com (Tom Breton) Reply-To: tob AT world DOT std DOT com Organization: BREnterprises References: <19970414205856798 DOT AAA152 AT ns1 DOT megsinet DOT net> Date: Tue, 15 Apr 1997 21:16:22 GMT Lines: 39 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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"