home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
-
- FILE
- time0.c - simple timer routine using ftime() calls
-
- ROUTINES
- SetTimer - set timer for specified interval
- TimeUp - is time up?
-
- REMARKS
- These functions uses the Microsoft C compiler library's ftime()
- calls to tell time. They will run under DOS and not interfere
- with DOS's date/time keeping.
-
- Time resolution is same as system clock - approx. 55 milliseconds.
-
- LAST UPDATE
- 12 January 1988
- creation
-
- Copyright(C) 1988, D.M.Auslander and C.H. Tham
-
- ***********************************************************************/
-
- /***********************************************************************
- I M P O R T S
- ***********************************************************************/
-
- #include <stdio.h>
- #include <sys\types.h>
- #include <sys\timeb.h>
-
- #include "time0.h"
-
-
- /***********************************************************************
- P R I V A T E D A T A V A R I A B L E S
- ***********************************************************************/
-
- static struct timeb start; /* record starting time */
- static long period; /* countdown period in milliseconds */
-
-
- /***********************************************************************
- E N T R Y R O U T I N E S
- /***********************************************************************
-
- /*----------------------------------------------------------------------
- PROCEDURE
- SETTIMER - set countdown timer
-
- SYNOPSIS
- void SetTimer(ms)
- long ms;
-
- PARAMETER
- ms - count down period in milliseconds
-
- LAST UPDATE
- 18 January 1988
- ----------------------------------------------------------------------*/
-
- void SetTimer(ms)
- long ms;
- {
-
- ftime(&start); /* record starting time */
-
- period = ms;
-
- }
-
-
-
- /*---------------------------------------------------------------------
- FUNCTION
- TIMEUP - has timer timed out?
-
- SYNOPSIS
- int TimeUp()
-
- RETURNS
- 1 if timer runs out, 0 otherwise
-
- LAST UPDATE
- 18 January 1988
- ----------------------------------------------------------------------*/
-
- int TimeUp()
- {
- struct timeb now; /* current time */
-
-
- ftime(&now);
-
- if (((now.time - start.time) * 1000)
- + now.millitm - start.millitm < period)
- return(0);
- else
- return(1);
-
- }
-
-
-