TIMER.H 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /***************************************************************************
  15. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  16. ***************************************************************************
  17. * *
  18. * Project Name : Timer Class Functions *
  19. * *
  20. * File Name : TIMER.H *
  21. * *
  22. * Programmer : Scott K. Bowen *
  23. * *
  24. * Start Date : July 6, 1994 *
  25. * *
  26. * Last Update : July 12, 1994 [SKB] *
  27. * *
  28. *-------------------------------------------------------------------------*
  29. * Functions: *
  30. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  31. #ifndef TIMER_H
  32. #define TIMER_H
  33. #ifndef WIN32
  34. #define WIN32 1
  35. #ifndef _WIN32 // Denzil 6/2/98 Watcom 11.0 complains without this check
  36. #define _WIN32
  37. #endif // _WIN32
  38. #endif
  39. #include <windows.h>
  40. #include <windowsx.h>
  41. /*=========================================================================*/
  42. /* The following prototypes are for the file: TIMERA.ASM */
  43. /*=========================================================================*/
  44. //////////////////////////////////////////////////////////////////////////////////////////////
  45. //////////////////////////////////////// Externs /////////////////////////////////////////////
  46. extern BOOL TimerSystemOn;
  47. extern HANDLE TimerThreadHandle; //Handle of timer thread
  48. extern int InTimerCallback; //true if we are currently in a callback
  49. /*=========================================================================*/
  50. typedef enum BaseTimerEnum {
  51. BT_SYSTEM, // System timer (60 / second).
  52. BT_USER // User controllable timer (? / second).
  53. } BaseTimerEnum;
  54. class TimerClass {
  55. public:
  56. // Constructor. Timers set before low level init has been done will not
  57. // be able to be 'Started' or 'on' until timer system is in place.
  58. TimerClass(BaseTimerEnum timer=BT_SYSTEM, BOOL start=FALSE);
  59. // No destructor.
  60. ~TimerClass(void){}
  61. //
  62. long Set(long value, BOOL start=TRUE); // Set initial timer value.
  63. long Stop(void); // Pause timer.
  64. long Start(void); // Resume timer.
  65. long Reset(BOOL start=TRUE); // Reset timer to zero.
  66. long Time(void); // Fetch current timer value.
  67. protected:
  68. long Started; // Time last started (0 == not paused).
  69. long Accumulated; // Total accumulated ticks.
  70. private:
  71. // long (*Get_Ticks)(void); // System timer fetch.
  72. BaseTimerEnum TickType;
  73. long Get_Ticks (void);
  74. };
  75. inline long TimerClass::Reset(BOOL start)
  76. {
  77. return(Set(0, start));
  78. }
  79. class CountDownTimerClass : private TimerClass {
  80. public:
  81. // Constructor. Timers set before low level init has been done will not
  82. // be able to be 'Started' or 'on' until timer system is in place.
  83. CountDownTimerClass(BaseTimerEnum timer, long set, int on=FALSE);
  84. CountDownTimerClass(BaseTimerEnum timer=BT_SYSTEM, int on=FALSE);
  85. // No destructor.
  86. ~CountDownTimerClass(void){}
  87. // Public functions
  88. long Set(long set, BOOL start=TRUE); // Set count down value.
  89. long Reset(BOOL start=TRUE); // Reset timer to zero.
  90. long Stop(void); // Pause timer.
  91. long Start(void); // Resume timer.
  92. long Time(void); // Fetch current count down value.
  93. protected:
  94. long DelayTime; // Ticks remaining before countdown timer expires.
  95. };
  96. inline long CountDownTimerClass::Stop(void)
  97. {
  98. TimerClass::Stop();
  99. return(Time());
  100. }
  101. inline long CountDownTimerClass::Start(void)
  102. {
  103. TimerClass::Start();
  104. return(Time());
  105. }
  106. inline long CountDownTimerClass::Reset(BOOL start)
  107. {
  108. return (TimerClass::Reset(start));
  109. }
  110. class WinTimerClass {
  111. public:
  112. WinTimerClass ( UINT freq=60 , BOOL partial=0 );
  113. ~WinTimerClass();
  114. void Update_Tick_Count ( void );
  115. unsigned Get_System_Tick_Count ( void );
  116. unsigned Get_User_Tick_Count ( void );
  117. private:
  118. unsigned TimerHandle; //Handle for windows timer event
  119. unsigned Frequency; //Frequency of our windows timer in ticks per second
  120. unsigned TrueRate; //True rate of clock. (only use word)
  121. unsigned SysTicks; //Tick count of timer.
  122. unsigned UserTicks; //Tick count of timer.
  123. unsigned UserRate; //Desired rate of timer.
  124. };
  125. extern WinTimerClass *WindowsTimer;
  126. //////////////////////////////////////////////////////////////////////////////////////////////
  127. //////////////////////////////////////// externs //////////////////////////////////////////
  128. #ifndef FUNCTION_H
  129. extern TimerClass TickCount;
  130. #endif
  131. extern CountDownTimerClass CountDown;
  132. //////////////////////////////////////////////////////////////////////////////////////////////
  133. //////////////////////////////////////// Prototypes //////////////////////////////////////////
  134. extern "C" {
  135. long __cdecl Get_System_Tick_Count(void);
  136. long __cdecl Get_User_Tick_Count(void);
  137. void far __cdecl Timer_Interrupt_Func(void);
  138. // long Get_Num_Interrupts(unsigned int realmode);
  139. void __cdecl Disable_Timer_Interrupt(void);
  140. void __cdecl Enable_Timer_Interrupt(void);
  141. }
  142. /*=========================================================================*/
  143. /* The following prototypes are for the file: TIMER.CPP */
  144. /*=========================================================================*/
  145. BOOL __cdecl Init_Timer_System(unsigned int freq, int partial = FALSE);
  146. BOOL __cdecl Remove_Timer_System(VOID);
  147. #endif // TIMER_H