home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / TIMER.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  6KB  |  167 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                 This module was written by Bob Hartman                   */
  14. /*               with some hacking done by Vince Perriello                  */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*                       BinkleyTerm timer routines                         */
  18. /*                                                                          */
  19. /*                                                                          */
  20. /*    For complete  details  of the licensing restrictions, please refer    */
  21. /*    to the License  agreement,  which  is published in its entirety in    */
  22. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  23. /*                                                                          */
  24. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  25. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  26. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  27. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  28. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  29. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  30. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  31. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  32. /*                                                                          */
  33. /*                                                                          */
  34. /* You can contact Bit Bucket Software Co. at any one of the following      */
  35. /* addresses:                                                               */
  36. /*                                                                          */
  37. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  38. /* P.O. Box 460398                AlterNet 7:491/0                          */
  39. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  40. /*                                Internet f491.n343.z1.fidonet.org         */
  41. /*                                                                          */
  42. /* Please feel free to contact us at any time to share your comments about  */
  43. /* our software and/or licensing policies.                                  */
  44. /*                                                                          */
  45. /*--------------------------------------------------------------------------*/
  46.  
  47. /*
  48.   
  49.   This file contains routines to implement a simple multiple
  50.   alarm system.  The routines allow setting any number of alarms,
  51.   and then checking if any one of them has expired.  It also allows
  52.   adding time to an alarm.
  53. */
  54.  
  55.  
  56. /*
  57.  * $Log$
  58.  */
  59.  
  60. /* Include this file before any other includes or defines! */
  61.  
  62. #include "includes.h"
  63.  
  64. /*
  65.   long timerset (t)
  66.   unsigned int t;
  67.   
  68.   This routine returns a timer variable based on the MS-DOS
  69.   time.  The variable returned is a long which corresponds to
  70.   the MS-DOS time at which the timer will expire.  The variable
  71.   need never be used once set, but to find if the timer has in
  72.   fact expired, it will be necessary to call the timeup function.
  73.   The expire time 't' is in hundredths of a second.
  74.   
  75.   Note: This routine as coded had a granularity of one week. I
  76.   have put the code that implements that inside the flag 
  77.   "HIGH_OVERHEAD". If you want it, go ahead and use it. For
  78.   BT's purposes, (minute) granularity should suffice.
  79.   
  80. */
  81. long timerset (unsigned int t)
  82. {
  83.    long l;
  84.  
  85. #ifdef HIGH_OVERHEAD
  86.    int l2;
  87.  
  88. #endif
  89.    int hours, mins, secs, ths;
  90.  
  91. #ifdef HIGH_OVERHEAD
  92.    extern int week_day ();
  93.  
  94. #endif
  95.  
  96.    /* Get the DOS time and day of week */
  97.    dostime (&hours, &mins, &secs, &ths);
  98.  
  99. #ifdef HIGH_OVERHEAD
  100.    l2 = week_day ();
  101. #endif
  102.  
  103.    /* Figure out the hundredths of a second so far this week */
  104.    l =
  105.  
  106. #ifdef HIGH_OVERHEAD
  107.       l2 * PER_DAY +
  108.       (hours % 24) * PER_HOUR +
  109. #endif
  110.       (mins % 60) * PER_MINUTE +
  111.       (secs % 60) * PER_SECOND +
  112.       ths;
  113.  
  114.    /* Add in the timer value */
  115.    l += t;
  116.  
  117.    /* Return the alarm off time */
  118.    return (l);
  119. }
  120.  
  121. /*
  122.   int timeup (t)
  123.   long t;
  124.   
  125.   This routine returns a 1 if the passed timer variable corresponds
  126.   to a timer which has expired, or 0 otherwise.
  127. */
  128. int timeup (long t)
  129. {
  130.    long l;
  131.  
  132.    EventSub();
  133.  
  134.    /* Get current time in hundredths */
  135.    l = timerset (0);
  136.  
  137.    /* If current is less then set by more than max int, then adjust */
  138.    if (l < (t - 65536L))
  139.       {
  140. #ifdef HIGH_OVERHEAD
  141.       l += PER_WEEK;
  142. #else
  143.       l += PER_HOUR;
  144. #endif
  145.       }
  146.  
  147.    /* Return whether the current is greater than the timer variable */
  148.    return ((l - t) >= 0L);
  149. }
  150.  
  151.  
  152. /*
  153.   long addtime (t1, t2)
  154.   long t1;
  155.   unsigned int t2;
  156.   
  157.   This routine adds t2 hundredths of a second to the timer variable
  158.   in t1.  It returns a new timer variable.
  159.  
  160.         Not needed in BinkleyTerm, commented out.
  161.  
  162. long addtime (long t1, unsigned int t2)
  163. {
  164.    return (t1 + t2);
  165. }
  166. */
  167.