Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 716 | lvd | 1 | #pragma once |
| 2 | |||
| 3 | class TCriticalSection |
||
| 4 | { |
||
| 5 | CRITICAL_SECTION CritSect; |
||
| 6 | public: |
||
| 7 | TCriticalSection() { InitializeCriticalSection(&CritSect); } |
||
| 8 | ~TCriticalSection() { DeleteCriticalSection(&CritSect); } |
||
| 9 | void Lock() { EnterCriticalSection(&CritSect); } |
||
| 10 | void Unlock() { LeaveCriticalSection(&CritSect); } |
||
| 11 | }; |
||
| 12 | |||
| 13 | class TEvent |
||
| 14 | { |
||
| 15 | HANDLE Event; |
||
| 16 | public: |
||
| 784 | DimkaM | 17 | TEvent(BOOL InitState) { Event = CreateEvent(nullptr, TRUE, InitState, nullptr); } |
| 716 | lvd | 18 | ~TEvent() { CloseHandle(Event); } |
| 19 | void Set() { SetEvent(Event); } |
||
| 20 | void Reset() { ResetEvent(Event); } |
||
| 21 | bool Wait(DWORD TimeOut = INFINITE) { return WaitForSingleObject(Event, TimeOut) == WAIT_OBJECT_0; } |
||
| 22 | }; |
||
| 23 | |||
| 24 | |||
| 25 | #define VK_ALT VK_MENU |
||
| 26 | |||
| 27 | #define WORD4(a,b,c,d) (((unsigned)(a)) | (((unsigned)(b)) << 8) | (((unsigned)(c)) << 16) | (((unsigned)(d)) << 24)) |
||
| 28 | #define WORD2(a,b) ((a) | ((b)<<8)) |
||
| 29 | #define align_by(a,b) (((ULONG_PTR)(a) + ((b)-1)) & ~((b)-1)) |
||
| 30 | #define hexdigit(a) ((a) < 'A' ? (a)-'0' : toupper(a)-'A'+10) |
||
| 31 | |||
| 32 | extern const char nop; |
||
| 33 | extern const char * const nil; |
||
| 34 | |||
| 35 | void eat(); |
||
| 36 | void trim(char *dst); |
||
| 784 | DimkaM | 37 | void errmsg(const char *err, const char *str = nullptr); |
| 716 | lvd | 38 | void err_printf(const char *format, ...); |
| 39 | void err_win32(DWORD errcode = 0xFFFFFFFF); |
||
| 40 | void color(int ink = CONSCLR_DEFAULT); |
||
| 41 | int ishex(char c); |
||
| 42 | unsigned char hex(char p); |
||
| 43 | unsigned char hex(const char *p); |
||
| 44 | |||
| 784 | DimkaM | 45 | void __declspec(noreturn) errexit(const char *err, const char *str = nullptr); |
| 716 | lvd | 46 | unsigned process_msgs(); |
| 47 | bool dispatch(action *table); |
||
| 48 | bool dispatch_more(action *table); |
||
| 49 | |||
| 50 | void fillCpuString(char *dst); |
||
| 51 | unsigned cpuid(unsigned _eax, int ext); |
||
| 52 | unsigned __int64 GetCPUFrequency(); |
||
| 53 | |||
| 54 | static forceinline u64 rdtsc() |
||
| 55 | { |
||
| 56 | return __rdtsc(); |
||
| 57 | } |
||
| 58 | |||
| 59 | bool wcmatch(char *string, char *wc); |
||
| 784 | DimkaM | 60 | void dump1(BYTE *p, unsigned sz); |