Mail Archives: djgpp/1999/05/02/11:34:38
SIowTalker wrote:
>
> make a function like this
>
> #include <go32.h>
> unsigned long QueryTimer(void)
> {
> unsigned long clock = _farpeekl(_dos_ds, 0x0046C);
> return(clock);
> }
>
> then so each game loop takes at least 100 milliseconds, you save the time
> setting in the beggining of the game loop. Then at the end you get the time
> again and test if the difference between the two times is less than 100, if it
> is...it waits. Here's an example:
>
> start_time = TimerQuery()
> // do game processing
> while((start_time-TimerQuery())<100) { }
>
> Hope that helps...
> -Chad
If you do that you will be off by a factor of about 55,
because the counter at _farpeekl(_dos_ds, 0x0046C) only
advances about 18.2 times per second.
Also, that counter gets reset at midnight, so if you
are unlucky enough to start that loop shortly before
midnight, it will stay there forever.
This will work much better:
#include <dos.h>
#include <go32.h>
#include <sys/farptr.h>
#include <stdio.h>
void show_time()
{
struct dostime_t dt;
_dos_gettime( &dt);
printf( "%02d:%02d:%02d.%02d",
dt.hour, dt.minute, dt.second, dt.hsecond);
}
int main()
{
unsigned long counter = 0;
printf( "Starting at "); show_time(); printf( "\n");
unsigned long clock = _farpeekl(_dos_ds, 0x0046C);
for(int i=2; i>0; ) { // Work for 2 dos clock ticks, about 0.1 sec.
//
counter++; // Let's see how much work we can get done in 0.1 sec.
//
if ( clock != _farpeekl(_dos_ds, 0x0046C)) {
clock = _farpeekl(_dos_ds, 0x0046C);
i--;
}
}
printf( " Ending at "); show_time(); printf( "\n");
printf( "counter is %lu\n", counter);
return 0;
}
Dennis Yelle
--
Want to get paid for using the internet?
If so, go to: http://alladvantage.com/go.asp?refid=BAL536
- Raw text -