source: golgotha/src/i4/time/win_time.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.1 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifdef _WINDOWS
10#include <windows.h>
11#include <windef.h>
12#include <winbase.h>
13#endif
14
15#include "arch.hh"
16#include "time/time.hh"
17
18#include <stdio.h>
19#include <stdlib.h>
20
21sw32 i4_win32_start_clock=GetTickCount();
22
23void i4_time_class::get()
24{
25  time.win32_time.clock=GetTickCount()-i4_win32_start_clock;
26  time.win32_time.overflow=0;
27}
28
29void i4_time_class::add_milli(sw32 milli_sec)
30{
31  time.win32_time.clock+=milli_sec;
32}
33
34
35
36i4_bool i4_time_class::operator <(const i4_time_class &other) const
37{
38  return (other.time.win32_time.clock<time.win32_time.clock);
39}
40
41
42
43i4_bool i4_time_class::operator >(const i4_time_class &other) const
44{
45  return (other.time.win32_time.clock<time.win32_time.clock);
46}
47
48
49sw32 i4_time_class::milli_diff(const i4_time_class &past_time) const
50{
51  return (sw32)time.win32_time.clock-(sw32)past_time.time.win32_time.clock;
52}
53
54i4_time_class::i4_time_class(sw32 milli_sec)
55{
56  time.win32_time.clock=milli_sec - i4_win32_start_clock;
57}
58
59
60w64 i4_get_system_clock()
61{
62  w32 lo, hi;
63  __asm
64    {
65      __emit 0x0F
66      __emit 0x31
67      mov lo, eax
68      mov hi, edx
69    };
70  return (((w64)hi)<<32) | lo;
71}
72
73int i4_win_clocks_per_sec = -1;
74
75int i4_get_clocks_per_second()
76{
77  if (i4_win_clocks_per_sec==-1)
78  {
79    w64 _start = i4_get_system_clock();
80 
81    i4_time_class now,start;
82    while (now.milli_diff(start) < 1000) now.get();
83 
84    w64 end = i4_get_system_clock();
85
86    i4_win_clocks_per_sec = end - _start;
87  }
88 
89  return i4_win_clocks_per_sec;
90}
91
92void i4_sleep(int seconds) { Sleep(seconds*1000); }
93void i4_milli_sleep(int milli_seconds) { Sleep(milli_seconds); }
Note: See TracBrowser for help on using the repository browser.