delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/17/15:12:51

From: "DeHackEd" <not AT given DOT out>
References: <Pine DOT BSF DOT 3 DOT 96 DOT 980216035155 DOT 22742C-100000 AT ravine DOT binary DOT net>
Subject: Re: Help with Timer function
Date: Mon, 16 Feb 1998 16:21:04 -0500
Lines: 63
Message-ID: <eM13xCyO9GA.171@upnetnews02.moswest.msn.net>
Newsgroups: comp.os.msdos.djgpp
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Do you have Allegro? I recommend it. It already has timer, keyboard, screen,
sound and othter things (made for games, but completely free). Then in your
code, have something like this (excuse my mess of comments, but I don't know how
my newsgroup reader will allign messages and word wrap them):

#include <allegro.h>

volatile int minutes;
volatile int seconds;
volatile char time_is_up = 0;

void count_down_timer()
{
    if (!doit)
        return; // code is not needed right now
    if (seconds == 0) // take away a minute
    {
        seconds = 59;
        if (minutes == 0)
        {
            time_is_up = 1;
            remove_int(count_down_timer); // disables on list
        }
        minutes--;
    }
    else
        seconds--; // just take 1 away from seconds
}

END_OF_FUNCTION(count_down_timer) // IMPORTANT!

int main()
{
    allegro_init();
    install_timer();

    LOCK_VARIABLE(minutes);
    LOCK_VARIABLE(seconds);
    LOCK_VARIABLE(doit);
    LOCK_FUNCTION(count_down_timer);
// 1000 is the millisecond delay between executions

/* your code here. when you want to start the clock, set the times in minutes
and seconds and just put this in. */
    install_timer_ex(count_down_timer, 1000);

/* make sure you adjust time_is_up as necessary. The function automaticly takes
itself off the timer list when it reaches 0 */

    return 0;
}

/* You can get allegro at http://www.talula.demon.co.uk/allegro/ if you don't
already have it.
--
"DeHackEd"

EMail address not given out due to low-life spammers.


*/


- Raw text -


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