win32stuff.cpp
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "dependencies.h"
#include "AnubisSupport.h"
#include "DebugLog.h"
#include <assert.h>
#include <string>
int kernelInit(void)
{
WSADATA wsadata;
/* Open console for output */
// AllocConsole();
assert(sizeof(long) == 4);
if (WSAStartup(MAKEWORD(2,2),&wsadata) != 0)
{
LOGERROR("Winsock.dll not found.");
my_exit(1);
}
return 1;
}
const char * getpass(const char * in)
{
return "";
}
void my_exit(int returnCode)
{
// WaitForKeyboard();
exit(returnCode);
}
void WaitForKeyboard(void)
{
INPUT_RECORD inpRecord;
DWORD readRecord = 0;
BOOL quit = FALSE;
while ( quit == FALSE)
{
ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &inpRecord, 1, &readRecord);
if(inpRecord.EventType == KEY_EVENT )
quit = TRUE;
}
}
void common_sleep(unsigned int mseconds )
{
Sleep(mseconds);
}
/* Time functions */
static int64 startclock = 0; // we want a start time
static double rate_inv = 0;
status_t
initftime(void) {
int64 rate;
// we need the accuracy
if(!QueryPerformanceFrequency((LARGE_INTEGER*)&rate)) {
return B_ERROR; // win errors
}
// usually the rate will be the CPU clock
if(!rate) {
return B_ERROR;
}
rate_inv = 1.0 / (double)rate; // in second / ticks
rate_inv = rate_inv * 1000000L; // in µsecond / ticks
if(!QueryPerformanceCounter((LARGE_INTEGER*)&startclock)) {
return B_ERROR; // win errors
}
return B_OK; // there is a clock
}
// you would have to start up with initftime() at the beginning
// of the game. And check for errors
bigtime_t
system_time (void) /* time since booting in microseconds */
{
// by dividing by its rate you get accurate µseconds
int64 endclock;
QueryPerformanceCounter((LARGE_INTEGER*)&endclock);
return (bigtime_t)(endclock*rate_inv);
}