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 |
|
---|
21 | sw32 i4_win32_start_clock=GetTickCount();
|
---|
22 |
|
---|
23 | void i4_time_class::get()
|
---|
24 | {
|
---|
25 | time.win32_time.clock=GetTickCount()-i4_win32_start_clock;
|
---|
26 | time.win32_time.overflow=0;
|
---|
27 | }
|
---|
28 |
|
---|
29 | void i4_time_class::add_milli(sw32 milli_sec)
|
---|
30 | {
|
---|
31 | time.win32_time.clock+=milli_sec;
|
---|
32 | }
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | i4_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 |
|
---|
43 | i4_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 |
|
---|
49 | sw32 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 |
|
---|
54 | i4_time_class::i4_time_class(sw32 milli_sec)
|
---|
55 | {
|
---|
56 | time.win32_time.clock=milli_sec - i4_win32_start_clock;
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 | w64 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 |
|
---|
73 | int i4_win_clocks_per_sec = -1;
|
---|
74 |
|
---|
75 | int 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 |
|
---|
92 | void i4_sleep(int seconds) { Sleep(seconds*1000); }
|
---|
93 | void i4_milli_sleep(int milli_seconds) { Sleep(milli_seconds); }
|
---|