home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s300 / 1.ddi / CHAP2 / TIME0.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-02  |  2.5 KB  |  105 lines

  1. /***********************************************************************
  2.  
  3. FILE
  4.     time0.c  -  simple timer routine using ftime() calls
  5.  
  6. ROUTINES
  7.     SetTimer  -  set timer for specified interval
  8.     TimeUp    -  is time up?
  9.  
  10. REMARKS
  11.     These functions uses the Microsoft C compiler library's ftime()
  12.     calls to tell time.  They will run under DOS and not interfere
  13.     with DOS's date/time keeping.
  14.     
  15.     Time resolution is same as system clock - approx. 55 milliseconds.
  16.  
  17. LAST UPDATE
  18.     12 January 1988
  19.         creation
  20.  
  21.     Copyright(C) 1988, D.M.Auslander and C.H. Tham
  22.  
  23. ***********************************************************************/
  24.  
  25. /***********************************************************************
  26.                             I M P O R T S
  27. ***********************************************************************/
  28.  
  29. #include <stdio.h>
  30. #include <sys\types.h>
  31. #include <sys\timeb.h>
  32.  
  33. #include "time0.h"
  34.  
  35.  
  36. /***********************************************************************
  37.             P R I V A T E    D A T A    V A R I A B L E S
  38. ***********************************************************************/
  39.  
  40. static struct timeb start;      /* record starting time */
  41. static long period;             /* countdown period in milliseconds */
  42.  
  43.  
  44. /***********************************************************************
  45.                     E N T R Y    R O U T I N E S
  46. /***********************************************************************
  47.  
  48. /*----------------------------------------------------------------------
  49. PROCEDURE
  50.     SETTIMER  -  set countdown timer
  51.  
  52. SYNOPSIS
  53.     void SetTimer(ms)
  54.     long ms;
  55.  
  56. PARAMETER
  57.     ms -  count down period in milliseconds
  58.  
  59. LAST UPDATE
  60.     18 January 1988
  61. ----------------------------------------------------------------------*/
  62.  
  63. void SetTimer(ms)
  64. long ms;
  65. {
  66.  
  67.     ftime(&start);      /* record starting time */
  68.  
  69.     period = ms;
  70.  
  71. }
  72.  
  73.  
  74.  
  75. /*---------------------------------------------------------------------
  76. FUNCTION
  77.     TIMEUP  -  has timer timed out?
  78.  
  79. SYNOPSIS
  80.     int TimeUp()
  81.  
  82. RETURNS
  83.     1 if timer runs out, 0 otherwise
  84.  
  85. LAST UPDATE
  86.     18 January 1988
  87. ----------------------------------------------------------------------*/
  88.  
  89. int TimeUp()
  90. {
  91.     struct timeb now;           /* current time */
  92.  
  93.  
  94.     ftime(&now);
  95.  
  96.     if (((now.time - start.time) * 1000)
  97.             + now.millitm - start.millitm < period)
  98.         return(0);
  99.     else
  100.         return(1);
  101.  
  102. }
  103.  
  104.  
  105.