cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/23/18:02:20

From: nil AT hem1 DOT passagen DOT se (Nicklas Lindgren)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Using interrupts....
Date: Tue, 23 Jun 1998 21:44:59 GMT
Organization: Algonet/Tninet
Lines: 43
Message-ID: <35901e59.23251678@news.algonet.se>
References: <1998062318062200 DOT OAA20538 AT ladder03 DOT news DOT aol DOT com>
NNTP-Posting-Host: du206-242.ppp.algonet.se
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On 23 Jun 1998 18:06:22 GMT, xsyphinex AT aol DOT com (XSyphineX) wrote:

>ok ok... Im new at this but how do I control the speed of my computer so that
>sprites dont go 2000 times per second? I have Allegro, I know thats a big help?
>Any suggestions on how they work?

The easiest way would probably be to use the timers in Allegro.

You can read more about timers in the Allegro.txt file or in the guide
called Allegro Vivace (http://www.canvaslink.com/gfoot/vivace/)

If you are in a hurry you can use this to limit the speed of a loop.
It's pretty crude but you can start with it.

#include <allegro.h>
//====================================
volatile unsigned long ticks;
const int delay = 10; //millisecs

void timer_ticker(...) {
  ticks++;
}
END_OF_FUNCTION(timer_ticker);

void loop() {
  LOCK_VARIABLE(ticks);
  LOCK_FUNCTION(timer_ticker);
  ticks = 0;
  install_int(timer_ticker,delay);

  do {
    do {/* nothing */} while (ticks == 0);
    ticks--;
    // do your stuff here
  } while (/*something*/);
  remove_int(timer_ticker);
}
//====================================

You can try that out. Im too lazy to explain in detail :) I hope it
helps you.

	Nicklas Lindgren <nil AT hem1 DOT passagen DOT se>

- Raw text -


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