delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/26/01:18:18

From: michael DOT mauch AT gmx DOT de (Michael Mauch)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro and timer routines
Date: Thu, 23 Oct 1997 19:22:17 +0200
Organization: Gerhard-Mercator-Universitaet -GH- Duisburg
Lines: 42
Message-ID: <34516509.19929574@news.uni-duisburg.de>
References: <62mosa$nb5$1 AT postern DOT mbnet DOT mb DOT ca>
NNTP-Posting-Host: ppp102.uni-duisburg.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Thu, 23 Oct 1997 06:10:27 GMT, bigphil AT merlin DOT magic DOT mb DOT ca (Mark
Phillips) wrote:

> What allegro routine do I use to make the computer pause for less than
> one millisecond?   rest() is the only function i know and its lowest
> denomination is one millisecond. please help me out.

The libc function uclock() has a resolution of approx. 980 nanoseconds,
you can use it for a usleep()-like function (see below). IIRC you may
not use allegro timers together with uclock(), because the allegro
timers change the timer chip mode just like uclock() does. If your
program is going to be run under Windows/Win95, search the DJGPP mail
archives for (one of the oldest occurrences of) "puclock()", because
uclock() can't work there.

usleep() does not provide 1 ms delay, because it is based on clock()
which in turn has a resolution of 55 ms. You can use a homebrew version
of usleep(), e.g.:

#include <dpmi.h>
#include "puclock.h"

unsigned int
pusleep(unsigned int _useconds)
{
  uclock_t stop_time = puclock() + _useconds * (uclock_t)UCLOCKS_PER_SEC
/ 1e6;

  while (puclock() < stop_time)
  {
    __dpmi_yield();
  }
  return 0;
}

If you don't need it to run in Windows/Win95, you can change puclock()
into uclock() and #include <time.h> instead of "puclock.h". (Hmm, also
the __dpmi_yield() doesn't make much sense if you don't use any kind of
multi-tasker, so you can just leave it off, IMHO.)

Regards...
		Michael

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019