home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / xaes_new / timer.c < prev    next >
C/C++ Source or Header  |  1994-09-21  |  2KB  |  83 lines

  1. /********************************************************************
  2.  *                                                                0.10*
  3.  *    XAES: Timer module                                                *
  4.  *                                                                    *
  5.  *    Copyright (c) 1994, Bitgate Software                            *
  6.  *                                                                    *
  7.  *    Although I have the idea of how to create a cooperative task    *
  8.  *    switching multitasking timer event, I have not done it yet.        *
  9.  *    It's going to be a complicated design, and this will be a task    *
  10.  *    in itself.  For now, it uses timing based on the 200HZ timer.    *
  11.  *                                                                    *
  12.  ********************************************************************/
  13.  
  14. #include <time.h>
  15.  
  16. #include "xaes.h"
  17.  
  18. #ifdef __TURBOC__
  19. #pragma warn -pia
  20. #endif
  21.  
  22. #ifndef __TIMER__
  23. #define __TIMER__
  24. #endif
  25.  
  26. /*
  27.  *    Start timer (ticks based on 200HZ timer)
  28.  */
  29. GLOBAL void WStartTimer(WINDOW *win)
  30. {
  31.     if (win) {
  32.         win->timer.clock = clock() * 1000 / CLK_TCK + win->timer.ev_mtcount;
  33.         win->timer.status = TRUE;
  34.  
  35.         WCallTMDDispatcher(win, T_RUNNING);
  36.     }
  37. }
  38.  
  39. /*
  40.  *    Stop timer
  41.  */
  42. GLOBAL void WStopTimer(WINDOW *win)
  43. {
  44.     if (win) {
  45.         win->timer.status = FALSE;
  46.  
  47.         WCallTMDDispatcher(win, T_STOPPED);
  48.     }
  49. }
  50.  
  51. /*
  52.  *    Register new timer
  53.  *
  54.  *    status = status of timer
  55.  *    ev_tcount = counter time in milliseconds
  56.  *    TmrDispatcher = timer dispatcher
  57.  *    user = pointer to user defined structure
  58.  */
  59. GLOBAL void WCreateTimer(WINDOW *win, int status, long ev_tcount, void *user)
  60. {
  61.     if (win) {
  62.         win->timer.ev_mtcount = ev_tcount;
  63.         win->timer.user = user;
  64.  
  65.         if (status)
  66.             WStartTimer(win);
  67.         else
  68.             WStopTimer(win);
  69.     }
  70. }
  71.  
  72. GLOBAL BOOL WCheckTimersOpen(void)
  73. {
  74.     WINDOW *win = WindowChain;
  75.  
  76.     while(win->next) {
  77.         win = win->next;
  78.         if (win->timer.status != T_NOTEXIST)
  79.             return TRUE;
  80.     }
  81.  
  82.     return FALSE;
  83. }