diff --git a/libcommon/src/libcommon.cpp b/libcommon/src/libcommon.cpp index 4f60a5a8..ca33816c 100644 --- a/libcommon/src/libcommon.cpp +++ b/libcommon/src/libcommon.cpp @@ -1,4 +1,5 @@ #include "types.h" #include "shared.h" +#include "shared.cpp" #include "tokenizer.h" #include "tokenizer.cpp" \ No newline at end of file diff --git a/libcommon/src/minwindows.h b/libcommon/src/minwindows.h new file mode 100644 index 00000000..4156a3e3 --- /dev/null +++ b/libcommon/src/minwindows.h @@ -0,0 +1,1190 @@ +#ifndef WINDOWS_H +#define WINDOWS_H + +// Compact windows.h + +// Retrieve our SDK & DDK versions for proper definition targeting +#include + +#define WINDOWS_API_IMPORT extern "C" __declspec(dllimport) + +#define CALLBACK __stdcall +#define WINAPI __stdcall +#define APIENTRY WINAPI + +#define MAX_PATH 260 + +typedef unsigned long DWORD, *PDWORD, *LPDWORD; +typedef int WINBOOL; +typedef WINBOOL BOOL, *LPBOOL; +typedef unsigned char BYTE, *PBYTE, *LPBYTE; + +typedef int INT, *PINT, *LPINT; +typedef unsigned int UINT, *PUINT; +typedef unsigned short WORD, *PWORD, *LPWORD; +typedef float FLOAT, *PFLOAT; +typedef int INT; +typedef unsigned int UINT; +typedef short SHORT; +typedef long LONG, *LPLONG; +typedef long long LONGLONG; +typedef unsigned short USHORT; +typedef unsigned long ULONG; +typedef unsigned long long ULONGLONG; + +typedef WORD ATOM; + +typedef char CHAR; +typedef const CHAR* LPCCH, * PCCH; +typedef char TCHAR; + +typedef void VOID, *PVOID, *LPVOID; +typedef const void* LPCVOID; + +typedef __int64 INT_PTR, *PINT_PTR; +typedef unsigned __int64 UINT_PTR, *PUINT_PTR; + +typedef __int64 LONG_PTR, *PLONG_PTR; +typedef unsigned __int64 ULONG_PTR, *PULONG_PTR; + +typedef ULONG_PTR SIZE_T, * PSIZE_T; +typedef LONG_PTR SSIZE_T, * PSSIZE_T; + +typedef signed char INT8, *PINT8; +typedef signed short INT16, *PINT16; +typedef signed int INT32, * PINT32; +typedef signed __int64 INT64, *PINT64; +typedef unsigned char UINT8, *PUINT8; +typedef unsigned short UINT16, *PUINT16; +typedef unsigned int UINT32, *PUINT32; +typedef unsigned __int64 UINT64, *PUINT64; + +typedef signed int LONG32, *PLONG32; +typedef unsigned int ULONG32, *PULONG32; +typedef unsigned int DWORD32, *PDWORD32; + +typedef const TCHAR* LPCTSTR; + +typedef DWORD* PDWORD, *LPDWORD; +typedef char* LPSTR; +typedef wchar_t* LPWSTR; +typedef const char* LPCSTR; // a.k.a Lets Puke C String +typedef const wchar_t* LPCWSTR; +typedef DWORD LCID; +typedef UINT_PTR WPARAM; +typedef LONG_PTR LPARAM; + +typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; + +typedef __int64 LONG64, *PLONG64; +typedef unsigned __int64 ULONG64, *PULONG64; +typedef unsigned __int64 DWORD64, *PDWORD64; + +typedef unsigned long ULONG, *PULONG; +typedef unsigned short USHORT, *PUSHORT; +typedef unsigned char UCHAR, *PUCHAR; + +typedef LONG LRESULT; +typedef LONG HRESULT; + +#ifdef STRICT +typedef void* HANDLE; +#if 0 && (_MSC_VER > 1000) +#define DECLARE_HANDLE(name) struct name##__; typedef struct name##__ *name +#else +#define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name +#endif +#else +typedef PVOID HANDLE; +#define DECLARE_HANDLE(name) typedef HANDLE name +#endif + +typedef HANDLE* PHANDLE; +typedef HANDLE HMODULE; +typedef HANDLE HINSTANCE; +typedef HANDLE HWND; + +typedef HANDLE HWND; +typedef HANDLE HMENU; +typedef HANDLE HACCEL; +typedef HANDLE HBRUSH; +typedef HANDLE HFONT; +typedef HANDLE HDC; +typedef HANDLE HGLRC; +typedef HANDLE HICON; +typedef HANDLE HRGN; +typedef HANDLE HMONITOR; +typedef HANDLE HCURSOR; + +typedef int (WINAPI* FARPROC)(); +typedef int (WINAPI* NEARPROC)(); +typedef int (WINAPI* PROC)(); +typedef LRESULT (CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM); + +#define IS_INTRESOURCE(_r) ((((ULONG_PTR)(_r)) >> 16) == 0) +#define MAKEINTRESOURCE(i) ((LPSTR)((ULONG_PTR)((WORD)(i)))) + +#define TRUE 1 +#define FALSE 0 + +#define INVALID_HANDLE_VALUE ((void *)(intptr_t)(-1)) + +#define HIGH_PRIORITY_CLASS 0x00000080 + +#define GENERIC_READ 0x80000000 +#define GENERIC_WRITE 0x40000000 +#define GENERIC_EXECUTE 0x20000000 +#define GENERIC_ALL 0x10000000 +#define FILE_SHARE_READ 0x00000001 +#define FILE_SHARE_WRITE 0x00000002 +#define FILE_SHARE_DELETE 0x00000004 +#define CREATE_NEW 1 +#define CREATE_ALWAYS 2 +#define OPEN_EXISTING 3 +#define OPEN_ALWAYS 4 +#define TRUNCATE_EXISTING 5 +#define FILE_SHARE_READ 0x00000001 +#define FILE_SHARE_WRITE 0x00000002 +#define FILE_SHARE_DELETE 0x00000004 +#define FILE_ATTRIBUTE_READONLY 0x00000001 +#define FILE_ATTRIBUTE_HIDDEN 0x00000002 +#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 +#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 +#define FILE_ATTRIBUTE_DEVICE 0x00000040 +#define FILE_ATTRIBUTE_NORMAL 0x00000080 +#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 +#define FILE_ATTRIBUTE_COMPRESSED 0x00000800 +#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 +#define FILE_ATTRIBUTE_VIRTUAL 0x00010000 +#define FILE_ATTRIBUTE_UNPINNED 0x00100000 +#define FILE_ATTRIBUTE_RECALL_ON_OPEN 0x00040000 +#define FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS 0x00400000 + +#define STD_INPUT_HANDLE (DWORD)(-10) +#define STD_OUTPUT_HANDLE (DWORD)(-11) +#define STD_ERROR_HANDLE (DWORD)(-12) + +#define MEM_COMMIT 0x00001000 +#define MEM_RESERVE 0x00002000 +#define MEM_LARGE_PAGES 0x20000000 + +#define PAGE_NOACCESS 0x0 +#define PAGE_READWRITE 0x04 +#define PAGE_EXECUTE_READWRITE 0x40 + +#define MEM_RELEASE 0x00008000 + +/* timer error return values */ +#define TIMERR_BASE 96 + +#define TIMERR_NOERROR (0) /* no error */ +#define TIMERR_NOCANDO (TIMERR_BASE+1) /* request not completed */ +#define TIMERR_STRUCT (TIMERR_BASE+33) /* time struct size */ + +// Window class styles +#define CS_HREDRAW 0x0002 +#define CS_OWNDC 0x0020 +#define CS_VREDRAW 0x0001 + +/* + * Window Messages + */ + +#define WM_NULL 0x0000 +#define WM_CREATE 0x0001 +#define WM_DESTROY 0x0002 +#define WM_MOVE 0x0003 +#define WM_SIZE 0x0005 + +#define WM_ACTIVATE 0x0006 + + /* + * WM_ACTIVATE state values + */ +#define WA_INACTIVE 0 +#define WA_ACTIVE 1 +#define WA_CLICKACTIVE 2 + +#define WM_SETFOCUS 0x0007 +#define WM_KILLFOCUS 0x0008 +#define WM_ENABLE 0x000A +#define WM_PAINT 0x000F +#define WM_CLOSE 0x0010 +#define WM_QUIT 0x0012 +#define WM_ACTIVATEAPP 0x001C +#define WM_SYSCOLORCHANGE 0x0015 +#define WM_SHOWWINDOW 0x0018 + +#define WM_WINDOWPOSCHANGING 0x0046 +#define WM_WINDOWPOSCHANGED 0x0047 + +#if(_WIN32_WINNT >= 0x0501) +#define WM_INPUT_DEVICE_CHANGE 0x00FE +#endif /* _WIN32_WINNT >= 0x0501 */ + +#if(_WIN32_WINNT >= 0x0501) +#define WM_INPUT 0x00FF +#endif /* _WIN32_WINNT >= 0x0501 */ + +#define WM_KEYDOWN 0x0100 +#define WM_KEYUP 0x0101 +#define WM_CHAR 0x0102 +#define WM_SYSKEYDOWN 0x0104 +#define WM_SYSKEYUP 0x0105 +#define WM_SYSCHAR 0x0106 +#define WM_SYSCOMMAND 0x0112 + +/* + * System Menu Command Values + */ +#define SC_SIZE 0xF000 +#define SC_MOVE 0xF010 +#define SC_MINIMIZE 0xF020 +#define SC_MAXIMIZE 0xF030 +#define SC_NEXTWINDOW 0xF040 +#define SC_PREVWINDOW 0xF050 +#define SC_CLOSE 0xF060 +#define SC_VSCROLL 0xF070 +#define SC_HSCROLL 0xF080 +#define SC_MOUSEMENU 0xF090 +#define SC_KEYMENU 0xF100 +#define SC_ARRANGE 0xF110 +#define SC_RESTORE 0xF120 +#define SC_TASKLIST 0xF130 +#define SC_SCREENSAVE 0xF140 +#define SC_HOTKEY 0xF150 +#if(WINVER >= 0x0400) +#define SC_DEFAULT 0xF160 +#define SC_MONITORPOWER 0xF170 +#define SC_CONTEXTHELP 0xF180 +#define SC_SEPARATOR 0xF00F +#endif /* WINVER >= 0x0400 */ + +/* + * Window Styles + */ +#define WS_OVERLAPPED 0x00000000L +#define WS_POPUP 0x80000000L +#define WS_CHILD 0x40000000L +#define WS_MINIMIZE 0x20000000L +#define WS_VISIBLE 0x10000000L +#define WS_DISABLED 0x08000000L +#define WS_CLIPSIBLINGS 0x04000000L +#define WS_CLIPCHILDREN 0x02000000L +#define WS_MAXIMIZE 0x01000000L +#define WS_CAPTION 0x00C00000L /* WS_BORDER | WS_DLGFRAME */ +#define WS_BORDER 0x00800000L +#define WS_DLGFRAME 0x00400000L +#define WS_VSCROLL 0x00200000L +#define WS_HSCROLL 0x00100000L +#define WS_SYSMENU 0x00080000L +#define WS_THICKFRAME 0x00040000L +#define WS_GROUP 0x00020000L +#define WS_TABSTOP 0x00010000L + +#define WS_MINIMIZEBOX 0x00020000L +#define WS_MAXIMIZEBOX 0x00010000L + + +#define WS_TILED WS_OVERLAPPED +#define WS_ICONIC WS_MINIMIZE +#define WS_SIZEBOX WS_THICKFRAME +#define WS_TILEDWINDOW WS_OVERLAPPEDWINDOW + +/* + * Common Window Styles + */ +#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | \ + WS_CAPTION | \ + WS_SYSMENU | \ + WS_THICKFRAME | \ + WS_MINIMIZEBOX | \ + WS_MAXIMIZEBOX) + +#define WS_POPUPWINDOW (WS_POPUP | \ + WS_BORDER | \ + WS_SYSMENU) + +#define WS_CHILDWINDOW (WS_CHILD) + +/* + * Extended Window Styles + */ +#define WS_EX_DLGMODALFRAME 0x00000001L +#define WS_EX_NOPARENTNOTIFY 0x00000004L +#define WS_EX_TOPMOST 0x00000008L +#define WS_EX_ACCEPTFILES 0x00000010L +#define WS_EX_TRANSPARENT 0x00000020L +#if(WINVER >= 0x0400) +#define WS_EX_MDICHILD 0x00000040L +#define WS_EX_TOOLWINDOW 0x00000080L +#define WS_EX_WINDOWEDGE 0x00000100L +#define WS_EX_CLIENTEDGE 0x00000200L +#define WS_EX_CONTEXTHELP 0x00000400L + +#endif /* WINVER >= 0x0400 */ +#if(WINVER >= 0x0400) + +#define WS_EX_RIGHT 0x00001000L +#define WS_EX_LEFT 0x00000000L +#define WS_EX_RTLREADING 0x00002000L +#define WS_EX_LTRREADING 0x00000000L +#define WS_EX_LEFTSCROLLBAR 0x00004000L +#define WS_EX_RIGHTSCROLLBAR 0x00000000L + +#define WS_EX_CONTROLPARENT 0x00010000L +#define WS_EX_STATICEDGE 0x00020000L +#define WS_EX_APPWINDOW 0x00040000L + + +#define WS_EX_OVERLAPPEDWINDOW (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE) +#define WS_EX_PALETTEWINDOW (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST) + +#endif /* WINVER >= 0x0400 */ + +#if(_WIN32_WINNT >= 0x0500) +#define WS_EX_LAYERED 0x00080000 + +#endif /* _WIN32_WINNT >= 0x0500 */ + + +#if(WINVER >= 0x0500) +#define WS_EX_NOINHERITLAYOUT 0x00100000L // Disable inheritence of mirroring by children +#endif /* WINVER >= 0x0500 */ + +#if(WINVER >= 0x0602) +#define WS_EX_NOREDIRECTIONBITMAP 0x00200000L +#endif /* WINVER >= 0x0602 */ + +#if(WINVER >= 0x0500) +#define WS_EX_LAYOUTRTL 0x00400000L // Right to left mirroring +#endif /* WINVER >= 0x0500 */ + +#if(_WIN32_WINNT >= 0x0501) +#define WS_EX_COMPOSITED 0x02000000L +#endif /* _WIN32_WINNT >= 0x0501 */ +#if(_WIN32_WINNT >= 0x0500) +#define WS_EX_NOACTIVATE 0x08000000L +#endif /* _WIN32_WINNT >= 0x0500 */ + + +/* + * Class styles + */ +#define CS_VREDRAW 0x0001 +#define CS_HREDRAW 0x0002 +#define CS_DBLCLKS 0x0008 +#define CS_OWNDC 0x0020 +#define CS_CLASSDC 0x0040 +#define CS_PARENTDC 0x0080 +#define CS_NOCLOSE 0x0200 +#define CS_SAVEBITS 0x0800 +#define CS_BYTEALIGNCLIENT 0x1000 +#define CS_BYTEALIGNWINDOW 0x2000 +#define CS_GLOBALCLASS 0x4000 + +#define CS_IME 0x00010000 +#if(_WIN32_WINNT >= 0x0501) +#define CS_DROPSHADOW 0x00020000 +#endif /* _WIN32_WINNT >= 0x0501 */ + +#define CW_USEDEFAULT ((int)0x80000000) + +#define SW_FORCEMINIMIZE 11 +#define SW_HIDE 0 +#define SW_MAXIMIZE 3 +#define SW_MINIMIZE 6 +#define SW_RESTORE 9 +#define SW_SHOW 5 +#define SW_SHOWDEFAULT 10 +#define SW_SHOWMAXIMIZED 3 +#define SW_SHOWMINIMIZED 2 +#define SW_SHOWMINNOACTIVE 7 +#define SW_SHOWNA 8 +#define SW_SHOWNOACTIVATE 4 +#define SW_SHOWNORMAL 1 + +/* + * PeekMessage() Options + */ +#define PM_NOREMOVE 0x0000 +#define PM_REMOVE 0x0001 +#define PM_NOYIELD 0x0002 + +/* + * WM_KEYUP/DOWN/CHAR HIWORD(lParam) flags + */ +#define KF_EXTENDED 0x0100 +#define KF_DLGMODE 0x0800 +#define KF_MENUMODE 0x1000 +#define KF_ALTDOWN 0x2000 +#define KF_REPEAT 0x4000 +#define KF_UP 0x8000 + +#ifndef NOVIRTUALKEYCODES + +/* + * Virtual Keys, Standard Set + */ +#define VK_LBUTTON 0x01 +#define VK_RBUTTON 0x02 +#define VK_CANCEL 0x03 +#define VK_MBUTTON 0x04 /* NOT contiguous with L & RBUTTON */ + +#if(_WIN32_WINNT >= 0x0500) +#define VK_XBUTTON1 0x05 /* NOT contiguous with L & RBUTTON */ +#define VK_XBUTTON2 0x06 /* NOT contiguous with L & RBUTTON */ +#endif /* _WIN32_WINNT >= 0x0500 */ + +/* + * 0x07 : reserved + */ + + +#define VK_BACK 0x08 +#define VK_TAB 0x09 + +/* + * 0x0A - 0x0B : reserved + */ + +#define VK_CLEAR 0x0C +#define VK_RETURN 0x0D + +/* + * 0x0E - 0x0F : unassigned + */ + +#define VK_SHIFT 0x10 +#define VK_CONTROL 0x11 +#define VK_MENU 0x12 +#define VK_PAUSE 0x13 +#define VK_CAPITAL 0x14 + +#define VK_KANA 0x15 +#define VK_HANGEUL 0x15 /* old name - should be here for compatibility */ +#define VK_HANGUL 0x15 + +/* + * 0x16 : unassigned + */ + +#define VK_JUNJA 0x17 +#define VK_FINAL 0x18 +#define VK_HANJA 0x19 +#define VK_KANJI 0x19 + +/* + * 0x1A : unassigned + */ + +#define VK_ESCAPE 0x1B + +#define VK_CONVERT 0x1C +#define VK_NONCONVERT 0x1D +#define VK_ACCEPT 0x1E +#define VK_MODECHANGE 0x1F + +#define VK_SPACE 0x20 +#define VK_PRIOR 0x21 +#define VK_NEXT 0x22 +#define VK_END 0x23 +#define VK_HOME 0x24 +#define VK_LEFT 0x25 +#define VK_UP 0x26 +#define VK_RIGHT 0x27 +#define VK_DOWN 0x28 +#define VK_SELECT 0x29 +#define VK_PRINT 0x2A +#define VK_EXECUTE 0x2B +#define VK_SNAPSHOT 0x2C +#define VK_INSERT 0x2D +#define VK_DELETE 0x2E +#define VK_HELP 0x2F + +/* + * VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39) + * 0x3A - 0x40 : unassigned + * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A) + */ + +#define VK_LWIN 0x5B +#define VK_RWIN 0x5C +#define VK_APPS 0x5D + +/* + * 0x5E : reserved + */ + +#define VK_SLEEP 0x5F + +#define VK_NUMPAD0 0x60 +#define VK_NUMPAD1 0x61 +#define VK_NUMPAD2 0x62 +#define VK_NUMPAD3 0x63 +#define VK_NUMPAD4 0x64 +#define VK_NUMPAD5 0x65 +#define VK_NUMPAD6 0x66 +#define VK_NUMPAD7 0x67 +#define VK_NUMPAD8 0x68 +#define VK_NUMPAD9 0x69 +#define VK_MULTIPLY 0x6A +#define VK_ADD 0x6B +#define VK_SEPARATOR 0x6C +#define VK_SUBTRACT 0x6D +#define VK_DECIMAL 0x6E +#define VK_DIVIDE 0x6F +#define VK_F1 0x70 +#define VK_F2 0x71 +#define VK_F3 0x72 +#define VK_F4 0x73 +#define VK_F5 0x74 +#define VK_F6 0x75 +#define VK_F7 0x76 +#define VK_F8 0x77 +#define VK_F9 0x78 +#define VK_F10 0x79 +#define VK_F11 0x7A +#define VK_F12 0x7B +#define VK_F13 0x7C +#define VK_F14 0x7D +#define VK_F15 0x7E +#define VK_F16 0x7F +#define VK_F17 0x80 +#define VK_F18 0x81 +#define VK_F19 0x82 +#define VK_F20 0x83 +#define VK_F21 0x84 +#define VK_F22 0x85 +#define VK_F23 0x86 +#define VK_F24 0x87 + +#if(_WIN32_WINNT >= 0x0604) + +/* + * 0x88 - 0x8F : UI navigation + */ + +#define VK_NAVIGATION_VIEW 0x88 // reserved +#define VK_NAVIGATION_MENU 0x89 // reserved +#define VK_NAVIGATION_UP 0x8A // reserved +#define VK_NAVIGATION_DOWN 0x8B // reserved +#define VK_NAVIGATION_LEFT 0x8C // reserved +#define VK_NAVIGATION_RIGHT 0x8D // reserved +#define VK_NAVIGATION_ACCEPT 0x8E // reserved +#define VK_NAVIGATION_CANCEL 0x8F // reserved + +#endif /* _WIN32_WINNT >= 0x0604 */ + +#define VK_NUMLOCK 0x90 +#define VK_SCROLL 0x91 + +/* + * NEC PC-9800 kbd definitions + */ +#define VK_OEM_NEC_EQUAL 0x92 // '=' key on numpad + +/* + * Fujitsu/OASYS kbd definitions + */ +#define VK_OEM_FJ_JISHO 0x92 // 'Dictionary' key +#define VK_OEM_FJ_MASSHOU 0x93 // 'Unregister word' key +#define VK_OEM_FJ_TOUROKU 0x94 // 'Register word' key +#define VK_OEM_FJ_LOYA 0x95 // 'Left OYAYUBI' key +#define VK_OEM_FJ_ROYA 0x96 // 'Right OYAYUBI' key + +/* + * 0x97 - 0x9F : unassigned + */ + +/* + * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys. + * Used only as parameters to GetAsyncKeyState() and GetKeyState(). + * No other API or message will distinguish left and right keys in this way. + */ +#define VK_LSHIFT 0xA0 +#define VK_RSHIFT 0xA1 +#define VK_LCONTROL 0xA2 +#define VK_RCONTROL 0xA3 +#define VK_LMENU 0xA4 +#define VK_RMENU 0xA5 + +#if(_WIN32_WINNT >= 0x0500) +#define VK_BROWSER_BACK 0xA6 +#define VK_BROWSER_FORWARD 0xA7 +#define VK_BROWSER_REFRESH 0xA8 +#define VK_BROWSER_STOP 0xA9 +#define VK_BROWSER_SEARCH 0xAA +#define VK_BROWSER_FAVORITES 0xAB +#define VK_BROWSER_HOME 0xAC + +#define VK_VOLUME_MUTE 0xAD +#define VK_VOLUME_DOWN 0xAE +#define VK_VOLUME_UP 0xAF +#define VK_MEDIA_NEXT_TRACK 0xB0 +#define VK_MEDIA_PREV_TRACK 0xB1 +#define VK_MEDIA_STOP 0xB2 +#define VK_MEDIA_PLAY_PAUSE 0xB3 +#define VK_LAUNCH_MAIL 0xB4 +#define VK_LAUNCH_MEDIA_SELECT 0xB5 +#define VK_LAUNCH_APP1 0xB6 +#define VK_LAUNCH_APP2 0xB7 + +#endif /* _WIN32_WINNT >= 0x0500 */ + +/* + * 0xB8 - 0xB9 : reserved + */ + +#define VK_OEM_1 0xBA // ';:' for US +#define VK_OEM_PLUS 0xBB // '+' any country +#define VK_OEM_COMMA 0xBC // ',' any country +#define VK_OEM_MINUS 0xBD // '-' any country +#define VK_OEM_PERIOD 0xBE // '.' any country +#define VK_OEM_2 0xBF // '/?' for US +#define VK_OEM_3 0xC0 // '`~' for US + +/* + * 0xC1 - 0xC2 : reserved + */ + +#if(_WIN32_WINNT >= 0x0604) + +/* + * 0xC3 - 0xDA : Gamepad input + */ + +#define VK_GAMEPAD_A 0xC3 // reserved +#define VK_GAMEPAD_B 0xC4 // reserved +#define VK_GAMEPAD_X 0xC5 // reserved +#define VK_GAMEPAD_Y 0xC6 // reserved +#define VK_GAMEPAD_RIGHT_SHOULDER 0xC7 // reserved +#define VK_GAMEPAD_LEFT_SHOULDER 0xC8 // reserved +#define VK_GAMEPAD_LEFT_TRIGGER 0xC9 // reserved +#define VK_GAMEPAD_RIGHT_TRIGGER 0xCA // reserved +#define VK_GAMEPAD_DPAD_UP 0xCB // reserved +#define VK_GAMEPAD_DPAD_DOWN 0xCC // reserved +#define VK_GAMEPAD_DPAD_LEFT 0xCD // reserved +#define VK_GAMEPAD_DPAD_RIGHT 0xCE // reserved +#define VK_GAMEPAD_MENU 0xCF // reserved +#define VK_GAMEPAD_VIEW 0xD0 // reserved +#define VK_GAMEPAD_LEFT_THUMBSTICK_BUTTON 0xD1 // reserved +#define VK_GAMEPAD_RIGHT_THUMBSTICK_BUTTON 0xD2 // reserved +#define VK_GAMEPAD_LEFT_THUMBSTICK_UP 0xD3 // reserved +#define VK_GAMEPAD_LEFT_THUMBSTICK_DOWN 0xD4 // reserved +#define VK_GAMEPAD_LEFT_THUMBSTICK_RIGHT 0xD5 // reserved +#define VK_GAMEPAD_LEFT_THUMBSTICK_LEFT 0xD6 // reserved +#define VK_GAMEPAD_RIGHT_THUMBSTICK_UP 0xD7 // reserved +#define VK_GAMEPAD_RIGHT_THUMBSTICK_DOWN 0xD8 // reserved +#define VK_GAMEPAD_RIGHT_THUMBSTICK_RIGHT 0xD9 // reserved +#define VK_GAMEPAD_RIGHT_THUMBSTICK_LEFT 0xDA // reserved + +#endif /* _WIN32_WINNT >= 0x0604 */ + + +#define VK_OEM_4 0xDB // '[{' for US +#define VK_OEM_5 0xDC // '\|' for US +#define VK_OEM_6 0xDD // ']}' for US +#define VK_OEM_7 0xDE // ''"' for US +#define VK_OEM_8 0xDF + +/* + * 0xE0 : reserved + */ + +/* + * Various extended or enhanced keyboards + */ +#define VK_OEM_AX 0xE1 // 'AX' key on Japanese AX kbd +#define VK_OEM_102 0xE2 // "<>" or "\|" on RT 102-key kbd. +#define VK_ICO_HELP 0xE3 // Help key on ICO +#define VK_ICO_00 0xE4 // 00 key on ICO + +#if(WINVER >= 0x0400) +#define VK_PROCESSKEY 0xE5 +#endif /* WINVER >= 0x0400 */ + +#define VK_ICO_CLEAR 0xE6 + + +#if(_WIN32_WINNT >= 0x0500) +#define VK_PACKET 0xE7 +#endif /* _WIN32_WINNT >= 0x0500 */ + +/* + * 0xE8 : unassigned + */ + +/* + * Nokia/Ericsson definitions + */ +#define VK_OEM_RESET 0xE9 +#define VK_OEM_JUMP 0xEA +#define VK_OEM_PA1 0xEB +#define VK_OEM_PA2 0xEC +#define VK_OEM_PA3 0xED +#define VK_OEM_WSCTRL 0xEE +#define VK_OEM_CUSEL 0xEF +#define VK_OEM_ATTN 0xF0 +#define VK_OEM_FINISH 0xF1 +#define VK_OEM_COPY 0xF2 +#define VK_OEM_AUTO 0xF3 +#define VK_OEM_ENLW 0xF4 +#define VK_OEM_BACKTAB 0xF5 + +#define VK_ATTN 0xF6 +#define VK_CRSEL 0xF7 +#define VK_EXSEL 0xF8 +#define VK_EREOF 0xF9 +#define VK_PLAY 0xFA +#define VK_ZOOM 0xFB +#define VK_NONAME 0xFC +#define VK_PA1 0xFD +#define VK_OEM_CLEAR 0xFE + +/* + * 0xFF : reserved + */ + +#endif /* !NOVIRTUALKEYCODES */ + +// MessageBox types +#define MB_ABORTRETRYIGNORE 0x00000002L +#define MB_CANCELTRYCONTINUE 0x00000006L +#define MB_OK 0x00000000L +#define MB_OKCANCEL 0x00000001L +#define MB_YESNO 0x00000004L +#define MB_YESNOCANCEL 0x00000003L + +// MessageBox result codes +#define IDABORT 3 +#define IDCANCEL 2 +#define IDCONTINUE 11 +#define IDIGNORE 5 +#define IDNO 7 +#define IDOK 1 +#define IDRETRY 4 +#define IDTRYAGAIN 10 +#define IDYES 6 + +/* pixel types */ +#define PFD_TYPE_RGBA 0 +#define PFD_TYPE_COLORINDEX 1 + +/* layer types */ +#define PFD_MAIN_PLANE 0 +#define PFD_OVERLAY_PLANE 1 +#define PFD_UNDERLAY_PLANE (-1) + +/* PIXELFORMATDESCRIPTOR flags */ +#define PFD_DOUBLEBUFFER 0x00000001 +#define PFD_STEREO 0x00000002 +#define PFD_DRAW_TO_WINDOW 0x00000004 +#define PFD_DRAW_TO_BITMAP 0x00000008 +#define PFD_SUPPORT_GDI 0x00000010 +#define PFD_SUPPORT_OPENGL 0x00000020 +#define PFD_GENERIC_FORMAT 0x00000040 +#define PFD_NEED_PALETTE 0x00000080 +#define PFD_NEED_SYSTEM_PALETTE 0x00000100 +#define PFD_SWAP_EXCHANGE 0x00000200 +#define PFD_SWAP_COPY 0x00000400 +#define PFD_SWAP_LAYER_BUFFERS 0x00000800 +#define PFD_GENERIC_ACCELERATED 0x00001000 +#define PFD_SUPPORT_DIRECTDRAW 0x00002000 +#define PFD_DIRECT3D_ACCELERATED 0x00004000 +#define PFD_SUPPORT_COMPOSITION 0x00008000 + +/* PIXELFORMATDESCRIPTOR flags for use in ChoosePixelFormat only */ +#define PFD_DEPTH_DONTCARE 0x20000000 +#define PFD_DOUBLEBUFFER_DONTCARE 0x40000000 +#define PFD_STEREO_DONTCARE 0x80000000 + +/* + * Standard Icon IDs + */ +#define IDC_ARROW MAKEINTRESOURCE(32512) +#ifdef RC_INVOKED +#define IDI_APPLICATION 32512 +#define IDI_HAND 32513 +#define IDI_QUESTION 32514 +#define IDI_EXCLAMATION 32515 +#define IDI_ASTERISK 32516 +#if(WINVER >= 0x0400) +#define IDI_WINLOGO 32517 +#endif /* WINVER >= 0x0400 */ +#if(WINVER >= 0x0600) +#define IDI_SHIELD 32518 +#endif /* WINVER >= 0x0600 */ +#else +#define IDI_APPLICATION MAKEINTRESOURCE(32512) +#define IDI_HAND MAKEINTRESOURCE(32513) +#define IDI_QUESTION MAKEINTRESOURCE(32514) +#define IDI_EXCLAMATION MAKEINTRESOURCE(32515) +#define IDI_ASTERISK MAKEINTRESOURCE(32516) +#if(WINVER >= 0x0400) +#define IDI_WINLOGO MAKEINTRESOURCE(32517) +#endif /* WINVER >= 0x0400 */ +#if(WINVER >= 0x0600) +#define IDI_SHIELD MAKEINTRESOURCE(32518) +#endif /* WINVER >= 0x0600 */ +#endif /* RC_INVOKED */ + +#if(WINVER >= 0x0400) +#define IDI_WARNING IDI_EXCLAMATION +#define IDI_ERROR IDI_HAND +#define IDI_INFORMATION IDI_ASTERISK +#endif /* WINVER >= 0x0400 */ + +#define COLOR_WINDOW 5 + +#define ERROR_INVALID_VERSION_ARB 0x2095 +#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 +#define WGL_CONTEXT_FLAGS_ARB 0x2094 +#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002 +#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 +#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 +#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 + + +#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 +#define WGL_DRAW_TO_WINDOW_ARB 0x2001 +#define WGL_DRAW_TO_BITMAP_ARB 0x2002 +#define WGL_ACCELERATION_ARB 0x2003 +#define WGL_NEED_PALETTE_ARB 0x2004 +#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 +#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 +#define WGL_SWAP_METHOD_ARB 0x2007 +#define WGL_NUMBER_OVERLAYS_ARB 0x2008 +#define WGL_NUMBER_UNDERLAYS_ARB 0x2009 +#define WGL_TRANSPARENT_ARB 0x200A +#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 +#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 +#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 +#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A +#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B +#define WGL_SHARE_DEPTH_ARB 0x200C +#define WGL_SHARE_STENCIL_ARB 0x200D +#define WGL_SHARE_ACCUM_ARB 0x200E +#define WGL_SUPPORT_GDI_ARB 0x200F +#define WGL_SUPPORT_OPENGL_ARB 0x2010 +#define WGL_DOUBLE_BUFFER_ARB 0x2011 +#define WGL_STEREO_ARB 0x2012 +#define WGL_PIXEL_TYPE_ARB 0x2013 +#define WGL_COLOR_BITS_ARB 0x2014 +#define WGL_RED_BITS_ARB 0x2015 +#define WGL_RED_SHIFT_ARB 0x2016 +#define WGL_GREEN_BITS_ARB 0x2017 +#define WGL_GREEN_SHIFT_ARB 0x2018 +#define WGL_BLUE_BITS_ARB 0x2019 +#define WGL_BLUE_SHIFT_ARB 0x201A +#define WGL_ALPHA_BITS_ARB 0x201B +#define WGL_ALPHA_SHIFT_ARB 0x201C +#define WGL_ACCUM_BITS_ARB 0x201D +#define WGL_ACCUM_RED_BITS_ARB 0x201E +#define WGL_ACCUM_GREEN_BITS_ARB 0x201F +#define WGL_ACCUM_BLUE_BITS_ARB 0x2020 +#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 +#define WGL_DEPTH_BITS_ARB 0x2022 +#define WGL_STENCIL_BITS_ARB 0x2023 +#define WGL_AUX_BUFFERS_ARB 0x2024 +#define WGL_NO_ACCELERATION_ARB 0x2025 +#define WGL_GENERIC_ACCELERATION_ARB 0x2026 +#define WGL_FULL_ACCELERATION_ARB 0x2027 + +#define WGL_SWAP_EXCHANGE_ARB 0x2028 +#define WGL_SWAP_COPY_ARB 0x2029 +#define WGL_SWAP_UNDEFINED_ARB 0x202A + +#define WGL_TYPE_RGBA_ARB 0x202B +#define WGL_TYPE_COLORINDEX_ARB 0x202C + +#define _O_TEXT 0x4000 /* file mode is text (translated) */ +#define _O_BINARY 0x8000 /* file mode is binary (untranslated) */ + +enum MMRESULT : unsigned int { + MMSYSERR_NOERROR = 0, + MMSYSERR_ERROR = 1, + MMSYSERR_BADDEVICEID = 2, + MMSYSERR_NOTENABLED = 3, + MMSYSERR_ALLOCATED = 4, + MMSYSERR_INVALHANDLE = 5, + MMSYSERR_NODRIVER = 6, + MMSYSERR_NOMEM = 7, + MMSYSERR_NOTSUPPORTED = 8, + MMSYSERR_BADERRNUM = 9, + MMSYSERR_INVALFLAG = 10, + MMSYSERR_INVALPARAM = 11, + MMSYSERR_HANDLEBUSY = 12, + MMSYSERR_INVALIDALIAS = 13, + MMSYSERR_BADDB = 14, + MMSYSERR_KEYNOTFOUND = 15, + MMSYSERR_READERROR = 16, + MMSYSERR_WRITEERROR = 17, + MMSYSERR_DELETEERROR = 18, + MMSYSERR_VALNOTFOUND = 19, + MMSYSERR_NODRIVERCB = 20, + WAVERR_BADFORMAT = 32, + WAVERR_STILLPLAYING = 33, + WAVERR_UNPREPARED = 34 +}; + +typedef union _LARGE_INTEGER { + struct { + DWORD LowPart; + LONG HighPart; + } DUMMYSTRUCTNAME; + struct { + DWORD LowPart; + LONG HighPart; + } u; + LONGLONG QuadPart; +} LARGE_INTEGER, *PLARGE_INTEGER; + +typedef struct _OVERLAPPED { + ULONG_PTR Internal; + ULONG_PTR InternalHigh; + union { + struct { + DWORD Offset; + DWORD OffsetHigh; + }; + void* Pointer; + }; + HANDLE hEvent; +} OVERLAPPED, *LPOVERLAPPED; + +typedef union _ULARGE_INTEGER { + struct { + DWORD LowPart; + DWORD HighPart; + } DUMMYSTRUCTNAME; + struct { + DWORD LowPart; + DWORD HighPart; + } u; + ULONGLONG QuadPart; +} ULARGE_INTEGER; + +typedef struct _FILETIME { + DWORD dwLowDateTime; + DWORD dwHighDateTime; +} FILETIME; + +typedef struct _WIN32_FILE_ATTRIBUTE_DATA { + DWORD dwFileAttributes; + FILETIME ftCreationTime; + FILETIME ftLastAccessTime; + FILETIME ftLastWriteTime; + DWORD nFileSizeHigh; + DWORD nFileSizeLow; +} WIN32_FILE_ATTRIBUTE_DATA; + +typedef struct _SECURITY_ATTRIBUTES { + DWORD nLength; + LPVOID lpSecurityDescriptor; + BOOL bInheritHandle; +} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; + +typedef enum _GET_FILEEX_INFO_LEVELS { + GetFileExInfoStandard, + GetFileExMaxInfoLevel +} GET_FILEEX_INFO_LEVELS; + +typedef struct tagWNDCLASSA { + UINT style; + WNDPROC lpfnWndProc; + int cbClsExtra; + int cbWndExtra; + HINSTANCE hInstance; + HICON hIcon; + HCURSOR hCursor; + HBRUSH hbrBackground; + LPCSTR lpszMenuName; + LPCSTR lpszClassName; +} WNDCLASSA, *PWNDCLASSA, *NPWNDCLASSA, *LPWNDCLASSA; + +typedef struct tagWNDCLASSEXA { + UINT cbSize; + UINT style; + WNDPROC lpfnWndProc; + int cbClsExtra; + int cbWndExtra; + HINSTANCE hInstance; + HICON hIcon; + HCURSOR hCursor; + HBRUSH hbrBackground; + LPCSTR lpszMenuName; + LPCSTR lpszClassName; + HICON hIconSm; +} WNDCLASSEXA, *PWNDCLASSEXA, *NPWNDCLASSEXA, *LPWNDCLASSEXA; + +typedef struct tagPOINT { + LONG x; + LONG y; +} POINT, * PPOINT, * NPPOINT, * LPPOINT; + +/* + * Message structure + */ +typedef struct tagMSG { + HWND hwnd; + UINT message; + WPARAM wParam; + LPARAM lParam; + DWORD time; + POINT pt; +} MSG, * PMSG, * NPMSG, * LPMSG; + +typedef struct _MEMORY_BASIC_INFORMATION { + PVOID BaseAddress; + PVOID AllocationBase; + DWORD AllocationProtect; + SIZE_T RegionSize; + DWORD State; + DWORD Protect; + DWORD Type; +} MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION; + +typedef struct _WIN32_FIND_DATA { + DWORD dwFileAttributes; + FILETIME ftCreationTime; + FILETIME ftLastAccessTime; + FILETIME ftLastWriteTime; + DWORD nFileSizeHigh; + DWORD nFileSizeLow; + DWORD dwOID; + TCHAR cFileName[MAX_PATH]; +} WIN32_FIND_DATA; + +typedef struct _WIN32_FIND_DATAA { + DWORD dwFileAttributes; + FILETIME ftCreationTime; + FILETIME ftLastAccessTime; + FILETIME ftLastWriteTime; + DWORD nFileSizeHigh; + DWORD nFileSizeLow; + DWORD dwReserved0; + DWORD dwReserved1; + CHAR cFileName[MAX_PATH]; + CHAR cAlternateFileName[14]; + DWORD dwFileType; + DWORD dwCreatorType; + WORD wFinderFlags; +} WIN32_FIND_DATAA, *PWIN32_FIND_DATAA, *LPWIN32_FIND_DATAA; + +typedef struct tagPIXELFORMATDESCRIPTOR { + WORD nSize; + WORD nVersion; + DWORD dwFlags; + BYTE iPixelType; + BYTE cColorBits; + BYTE cRedBits; + BYTE cRedShift; + BYTE cGreenBits; + BYTE cGreenShift; + BYTE cBlueBits; + BYTE cBlueShift; + BYTE cAlphaBits; + BYTE cAlphaShift; + BYTE cAccumBits; + BYTE cAccumRedBits; + BYTE cAccumGreenBits; + BYTE cAccumBlueBits; + BYTE cAccumAlphaBits; + BYTE cDepthBits; + BYTE cStencilBits; + BYTE cAuxBuffers; + BYTE iLayerType; + BYTE bReserved; + DWORD dwLayerMask; + DWORD dwVisibleMask; + DWORD dwDamageMask; +} PIXELFORMATDESCRIPTOR, *PPIXELFORMATDESCRIPTOR, *LPPIXELFORMATDESCRIPTOR; + +WINDOWS_API_IMPORT BOOL WINAPI WINAPI CloseHandle(HANDLE object); + +WINDOWS_API_IMPORT HANDLE WINAPI GetCurrentProcess(); +WINDOWS_API_IMPORT DWORD WINAPI GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize); +WINDOWS_API_IMPORT HMODULE WINAPI GetModuleHandleA(LPCSTR lpModuleName); + +WINDOWS_API_IMPORT BOOL WINAPI SetPriorityClass(HANDLE hProcess, DWORD dwPriorityClass); + +WINDOWS_API_IMPORT BOOL WINAPI PathIsRelativeA(LPCSTR pszPath); +WINDOWS_API_IMPORT HMODULE WINAPI LoadLibraryA(LPCSTR lpLibFileName); +WINDOWS_API_IMPORT HMODULE WINAPI LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags); +WINDOWS_API_IMPORT BOOL WINAPI FreeLibrary(HMODULE hLibModule); +WINDOWS_API_IMPORT FARPROC WINAPI GetProcAddress(HMODULE hModule, LPCSTR lpProcName); + +WINDOWS_API_IMPORT BOOL WINAPI AllocConsole(void); +WINDOWS_API_IMPORT void WINAPI ExitProcess(UINT uExitCode); + +WINDOWS_API_IMPORT HANDLE WINAPI CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); +WINDOWS_API_IMPORT BOOL WINAPI ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped); +WINDOWS_API_IMPORT BOOL WINAPI WriteFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped); + +WINDOWS_API_IMPORT BOOL WINAPI FlushFileBuffers(HANDLE hFile); +WINDOWS_API_IMPORT BOOL WINAPI GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize); + +WINDOWS_API_IMPORT BOOL WINAPI SetStdHandle( DWORD nStdHandle, HANDLE hHandle); + +WINDOWS_API_IMPORT void WINAPI OutputDebugStringA(LPCSTR lpOutputString); + +WINDOWS_API_IMPORT LPVOID WINAPI VirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect); +WINDOWS_API_IMPORT BOOL WINAPI VirtualFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType); + +#ifndef __INTRIN_H +WINDOWS_API_IMPORT LONG WINAPI _InterlockedCompareExchange(LONG volatile *Destination, LONG ExChange, LONG Comperand); +WINDOWS_API_IMPORT LONG64 WINAPI _InterlockedExchange64(LONG64 volatile *Target, LONG64 Value); +WINDOWS_API_IMPORT LONG64 WINAPI _InterlockedExchangeAdd64(LONG64 volatile *Addend, LONG64 Value); +#endif + +WINDOWS_API_IMPORT MMRESULT WINAPI timeBeginPeriod(UINT uPeriod); + +WINDOWS_API_IMPORT ATOM WINAPI RegisterClassA(const WNDCLASSA *lpWndClass); +WINDOWS_API_IMPORT ATOM WINAPI RegisterClassExA(const WNDCLASSEXA *Arg1); +WINDOWS_API_IMPORT LRESULT WINAPI DefWindowProcA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +WINDOWS_API_IMPORT HWND WINAPI CreateWindowExA(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam); +WINDOWS_API_IMPORT BOOL WINAPI ShowWindow( HWND hWnd, int nCmdShow); +WINDOWS_API_IMPORT BOOL WINAPI DestroyWindow(HWND hWnd); +WINDOWS_API_IMPORT BOOL WINAPI UnregisterClassA(LPCSTR lpClassName, HINSTANCE hInstance); + +WINDOWS_API_IMPORT BOOL WINAPI PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg); +WINDOWS_API_IMPORT BOOL WINAPI TranslateMessage(const MSG* lpMsg); +WINDOWS_API_IMPORT LRESULT WINAPI DispatchMessageA(const MSG* lpMsg); + +WINDOWS_API_IMPORT BOOL WINAPI VirtualProtect(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect); +WINDOWS_API_IMPORT SIZE_T WINAPI VirtualQuery(LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SIZE_T dwLength); +WINDOWS_API_IMPORT void WINAPI CopyMemory(PVOID Destination, const VOID *Source, SIZE_T Length); + +WINDOWS_API_IMPORT DWORD WINAPI GetLastError(); + +WINDOWS_API_IMPORT BOOL WINAPI QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency); +WINDOWS_API_IMPORT BOOL WINAPI QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount); + +WINDOWS_API_IMPORT HANDLE WINAPI FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); +WINDOWS_API_IMPORT BOOL WINAPI FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData); +WINDOWS_API_IMPORT BOOL WINAPI FindClose(HANDLE hFindFile); + +WINDOWS_API_IMPORT int WINAPI MessageBoxA(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType); +WINDOWS_API_IMPORT void WINAPI Sleep(DWORD dwMilliseconds); + +WINDOWS_API_IMPORT HDC WINAPI GetDC(HWND hWnd); +WINDOWS_API_IMPORT int WINAPI ReleaseDC(HWND hWnd, HDC hDC); +WINDOWS_API_IMPORT int WINAPI ChoosePixelFormat(HDC hdc, const PIXELFORMATDESCRIPTOR *ppfd); +WINDOWS_API_IMPORT int WINAPI DescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR ppfd); +WINDOWS_API_IMPORT BOOL WINAPI SetPixelFormat(HDC hdc, int format, const PIXELFORMATDESCRIPTOR *ppfd); + +WINDOWS_API_IMPORT HANDLE WINAPI GetStdHandle(DWORD nStdHandle); + +WINDOWS_API_IMPORT HICON WINAPI LoadIconA(HINSTANCE hInstance, LPCSTR lpIconName); +WINDOWS_API_IMPORT HCURSOR WINAPI LoadCursorA(HINSTANCE hInstance, LPCSTR lpCursorName); +WINDOWS_API_IMPORT HGLRC WINAPI wglCreateContext(HDC Arg1); +WINDOWS_API_IMPORT BOOL WINAPI wglMakeCurrent(HDC, HGLRC); +WINDOWS_API_IMPORT BOOL WINAPI wglDeleteContext(HGLRC Arg1); +WINDOWS_API_IMPORT PROC WINAPI wglGetProcAddress(LPCSTR Arg1); + +WINDOWS_API_IMPORT BOOL WINAPI WriteConsole(HANDLE hConsoleOutput, const VOID *lpBuffer, DWORD nNumberOfCharsToWrite, LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved); + +#endif \ No newline at end of file diff --git a/libcommon/src/shared.cpp b/libcommon/src/shared.cpp new file mode 100644 index 00000000..62c7244e --- /dev/null +++ b/libcommon/src/shared.cpp @@ -0,0 +1,358 @@ +struct format_dest { + umm Size; + char* At; +}; + +void OutChar(format_dest* Dest, char Value) { + if (Dest->Size){ + --Dest->Size; + *Dest->At++ = Value; + } +} + +void OutChars(format_dest* Dest, char* Value) { + // note(jax): Not particularily speedy@ + while (*Value) { + OutChar(Dest, *Value++); + } +} + +#define ReadVarArgUnsignedInteger(Length, ArgList) ((Length) == 8) ? _crt_va_arg(*ArgList, u64) : (u64)_crt_va_arg(*ArgList, u32) +#define ReadVarArgSignedInteger(Length, ArgList) ((Length) == 8) ? _crt_va_arg(*ArgList, s64) : (s64)_crt_va_arg(*ArgList, s32) +#define ReadVarArgFloat(Length, ArgList) _crt_va_arg(*ArgList, f64) + +static char DecChars[] = "0123456789"; +static char LowerHexChars[] = "0123456789abcdef"; +static char UpperHexChars[] = "0123456789ABCDEF"; + +void U64ToASCII(format_dest* Dest, u64 Value, u32 Base, char* Digits) { + Assert(Base != 0); + + char* Start = Dest->At; + do { + u64 DigitIndex = (Value % Base); + char Digit = Digits[DigitIndex]; + OutChar(Dest, Digit); + + Value /= Base; + } while (Value != 0); + char* End = Dest->At; + + while (Start < End) { + --End; + char Temp = *End; + *End = *Start; + *Start = Temp; + ++Start; + } +} + +void F64ToASCII(format_dest* Dest, f64 Value, u32 Precision) { + if (Value < 0) { + OutChar(Dest, '-'); + Value = -Value; + } + + u64 IntegerPart = (u64)Value; + Value -= (f64)IntegerPart; + U64ToASCII(Dest, IntegerPart, 10, DecChars); + + OutChar(Dest, '.'); + + // tood(jax): Note that this is NOT an accurate way to do this! + for (u32 PrecisionIndex = 0; PrecisionIndex < Precision; ++PrecisionIndex) { + Value *= 10.0f; + u32 Integer = (u32)Value; + Value -= (f32)Integer; + OutChar(Dest, DecChars[Integer]); + } +} + +// note(jax): This function serves as a replacement to `stdio.h` sprintf() +umm FormatArgList(umm DestSize, char* DestInit, char* Format, va_list ArgList) { + format_dest Dest = {DestSize, DestInit}; + if (Dest.Size) { + char* At = Format; + while (At[0]) { + if (*At == '%') { + ++At; + + b32 ForceSign = false; + b32 PadWithZeros = false; + b32 LeftJustify = false; + b32 PositiveSignIsBlank = false; + b32 AnnotateIfNotZero = false; + + // note(jax): Handle the flags + b32 Parsing = true; + + Parsing = true; + while (Parsing) { + switch (*At) { + case '+': { ForceSign = true; } break; + case '0': { PadWithZeros = true; } break; + case '-': { LeftJustify = true; } break; + case ' ': { PositiveSignIsBlank = true; } break; + case '#': { AnnotateIfNotZero = true; } break; + default: { Parsing = false; } break; + } + + if (Parsing) { + ++At; + } + } + + // note(jax): Handle the width + b32 WidthSpecified = false; + int32 Width = 0; + if (*At == '*') { + Width = _crt_va_arg(ArgList, int); + WidthSpecified = true; + ++At; + } else if ((*At >= '0') && (*At <= '9')) { + Width = StringToI32(At); + WidthSpecified = true; + //? ++At; + } + + // note(jax): Handle the precision + b32 PrecisionSpecified = false; + int32 Precision = 0; + if (*At == '.') { + ++At; + + if (*At == '*') { + Precision = _crt_va_arg(ArgList, int); + PrecisionSpecified = true; + ++At; + } else if ((*At >= '0') && (*At <= '9')) { + Precision = StringToI32(At); + PrecisionSpecified = true; + //++At; + } else { + Assert(!"Malformed precision specifier!"); + } + } + + // todo(jax): Right now our routine doesn't allow non-specified + // precisions, so we just set non-specified precisions to a specific value. + if (!PrecisionSpecified) { + Precision = 6; + } + + // note(jax): Handle the length + u32 IntegerLength = 4; + u32 FloatLength = 8; + // todo(jax): Actually set different values here. + if ((At[0] == 'h') && (At[1] == 'h')) { + At += 2; + } else if ((At[0] == 'l') && (At[1] == 'l')) { + At += 2; + } else if (*At == 'h') { + ++At; + } else if (*At == 'l') { + IntegerLength = 8; + ++At; + } else if (*At == 'j') { + ++At; + } else if (*At == 'z') { + ++At; + } else if (*At == 't') { + ++At; + } else if (*At == 'L') { + ++At; + } + + char TempBuffer[64]; + char* Temp = TempBuffer; + format_dest TempDest = {ArrayCount(TempBuffer), Temp}; + char* Prefix = ""; + b32 IsFloat = false; + + switch (*At) { + case 'd': + case 'i': { + s64 Value = ReadVarArgSignedInteger(IntegerLength, &ArgList); + b32 WasNegative = (Value < 0); + if (WasNegative) { + Value = -Value; + } + + U64ToASCII(&TempDest, (u64)Value, 10, DecChars); + // todo(jax): Make this a common routine once floating poiunt is available. + if (WasNegative) { + Prefix = "-"; + } else if (ForceSign) { + Assert(!PositiveSignIsBlank); // note(jax): Not a problem, but probably shouldn't be specified. + Prefix = "+"; + } else if (PositiveSignIsBlank) { + Prefix = " "; + } + } break; + + case 'u': { + u64 Value = ReadVarArgUnsignedInteger(IntegerLength, &ArgList); + U64ToASCII(&TempDest, Value, 10, DecChars); + } break; + + case 'o': { + u64 Value = ReadVarArgUnsignedInteger(IntegerLength, &ArgList); + U64ToASCII(&TempDest, Value, 8, DecChars); + if (AnnotateIfNotZero && (Value != 0)) { + Prefix = "0"; + } + } break; + + case 'x': { + u64 Value = ReadVarArgUnsignedInteger(IntegerLength, &ArgList); + U64ToASCII(&TempDest, Value, 16, LowerHexChars); + if (AnnotateIfNotZero && (Value != 0)) { + Prefix = "0x"; + } + } break; + + case 'X': { + u64 Value = ReadVarArgUnsignedInteger(IntegerLength, &ArgList); + U64ToASCII(&TempDest, Value, 16, UpperHexChars); + if (AnnotateIfNotZero && (Value != 0)) { + Prefix = "0X"; + } + } break; + + // todo(jax): Support other kinds of floating point prints + // Currently we only do basic decimal output. + case 'f': + case 'F': + case 'e': + case 'E': + case 'g': + case 'G': + case 'a': + case 'A': { + f64 Value = ReadVarArgFloat(FloatLength, &ArgList); + F64ToASCII(&TempDest, Value, Precision); + IsFloat = true; + + // @Speed @Cleanup todo(jax): If we still have more floats in temp, increase + // the size again. This is a very, very bad hack and is NOT shippable! (shame!) + if (Temp) { + Dest.Size += FloatLength; + } + } break; + + case 'c': { + // todo(jax): How much are we supposed to read here? + int Value = _crt_va_arg(ArgList, int); + OutChar(&TempDest, (char)Value); + } break; + + case 's': { + char* String = _crt_va_arg(ArgList, char*); + + // todo(jax): Obey precision, width, etc. + + Temp = String; + if (PrecisionSpecified) { + TempDest.Size = 0; + for (char* Scan = String; *Scan && (TempDest.Size < Precision); ++Scan) { + ++TempDest.Size; + } + } + else { + TempDest.Size = StringLength(String); + } + + TempDest.At = String + TempDest.Size; + } break; + + case 'p': { + void* Value = _crt_va_arg(ArgList, void*); + U64ToASCII(&TempDest, *(umm*)&Value, 16, LowerHexChars); + } break; + + case 'n': { + int* TabDest = _crt_va_arg(ArgList, int*); + *TabDest = (int)(Dest.At - DestInit); + } break; + + case '%': { + OutChar(&Dest, '%'); + } break; + + default: { + Assert(!"Unrecognized format specifier!"); + } break; + } + + if (TempDest.At - Temp) { + smm UsePrecision = Precision; + if (IsFloat || !PrecisionSpecified) { + UsePrecision = (TempDest.At - Temp); + } + + smm PrefixLength = StringLength(Prefix); + smm UseWidth = Width; + smm ComputedWidth = UsePrecision + PrefixLength; + if (UseWidth < ComputedWidth) { + UseWidth = ComputedWidth; + } + + if (PadWithZeros) { + Assert(!LeftJustify); // note(jax): Not a problem, but no way to do it? + LeftJustify = false; + } + + if (!LeftJustify) { + while (UseWidth > (UsePrecision + PrefixLength)) { + OutChar(&Dest, PadWithZeros ? '0' : ' '); + --UseWidth; + } + } + + for (char* Pre = Prefix; *Pre && UseWidth; ++Pre) { + OutChar(&Dest, *Pre); + --UseWidth; + } + + if (UsePrecision > UseWidth) { + UsePrecision = UseWidth; + } + + while (UsePrecision > (TempDest.At - Temp)) { + OutChar(&Dest, '0'); + --UsePrecision; + --UseWidth; + } + + while (UsePrecision && (TempDest.At != Temp)) { + OutChar(&Dest, *Temp++); + --UsePrecision; + --UseWidth; + } + + if (LeftJustify) { + while (UseWidth) { + OutChar(&Dest, ' '); + --UseWidth; + } + } + } + + if (*At) { + ++At; + } + } else { + OutChar(&Dest, *At++); + } + } + + if (Dest.Size) { + Dest.At[0] = 0; + } else { + Dest.At[-1] = 0; + } + } + + umm Result = Dest.At - DestInit; + return Result; +} \ No newline at end of file diff --git a/libcommon/src/shared.h b/libcommon/src/shared.h index 9103cdf1..bdda5d22 100644 --- a/libcommon/src/shared.h +++ b/libcommon/src/shared.h @@ -111,6 +111,14 @@ inline int StringLength(char* String) { return Count; } +inline string make_string(char* String) { + string Result = {}; + Result.Data = (u8*)String; + Result.Count = StringLength(String); + + return Result; +} + inline char* Substring(char* Source, char* String) { while (*Source) { char *Begin = Source; @@ -236,7 +244,7 @@ void U64ToASCII(format_dest* Dest, u64 Value, u32 Base, char* Digits); void F64ToASCII(format_dest* Dest, f64 Value, u32 Precision); // note(jax): This function serves as a replacement to `stdio.h` sprintf() -umm FormatArgList(umm DestSize, char* DestInit, char* Format, va_list ArgList); +API_EXPORT umm FormatArgList(umm DestSize, char* DestInit, char* Format, va_list ArgList); inline umm Format(umm DestSize, char* Dest, char* Format, ...) { va_list ArgList; _crt_va_start(ArgList, Format); diff --git a/libcommon/src/tokenizer.cpp b/libcommon/src/tokenizer.cpp index 0f4928ea..c8afacb2 100644 --- a/libcommon/src/tokenizer.cpp +++ b/libcommon/src/tokenizer.cpp @@ -87,15 +87,25 @@ token GetToken(tokenizer* Tokenizer) { AdvanceInput(Tokenizer, 1); } + // Speed: This block of code is pretty hacky... if (Token.Text.Count && (Token.Text.Data[0] == '"')) { ++Token.Text.Data; --Token.Text.Count; - } - if (Token.Text.Count && - (Token.Text.Data[Token.Text.Count - 1] == '"')) { - --Token.Text.Count; + int TextLength = 0; + char* Temp = (char*)malloc(Token.Text.Count); + sprintf(Temp, "%s", Token.Text.Data); + while (Temp) { + if (*Temp == '\"') { + break; + } + ++TextLength; + ++Temp; + } + + Token.String = (char*)malloc(TextLength); + sprintf(Token.String, "%.*s", (int)TextLength, Token.Text.Data); } } break; @@ -149,6 +159,10 @@ token GetToken(tokenizer* Tokenizer) { while (IsAlphabetical(Tokenizer->At[0]) || IsNumeric(Tokenizer->At[0]) || (Tokenizer->At[0] == '_')) { AdvanceInput(Tokenizer, 1); } + + __int64 IndentLength = (Tokenizer->Input.Data - Token.Text.Data); + Token.String = (char*)malloc(IndentLength); + sprintf(Token.String, "%.*s", (int)IndentLength, Token.Text.Data); } else if (IsNumeric(C)) { f32 Number = (f32)(C - '0'); @@ -184,4 +198,9 @@ token GetToken(tokenizer* Tokenizer) { return Token; } -token PeekToken(tokenizer* Tokenizer); \ No newline at end of file +token PeekToken(tokenizer* Tokenizer) { + tokenizer Temp = *Tokenizer; + token Result = GetToken(Tokenizer); + *Tokenizer = Temp; + return Result; +} \ No newline at end of file diff --git a/libcommon/src/tokenizer.h b/libcommon/src/tokenizer.h index e84b8330..7f9f1f94 100644 --- a/libcommon/src/tokenizer.h +++ b/libcommon/src/tokenizer.h @@ -55,7 +55,7 @@ struct tokenizer { b32 IsTokenValid(token Token); b32 TokenEquals(token Token, char* Match); API_EXPORT token GetToken(tokenizer* Tokenizer); -API_EXPORT token PeekToken(tokenizer* Tokenizer, int Lookahead); +API_EXPORT token PeekToken(tokenizer* Tokenizer); API_EXPORT tokenizer Tokenize(char* Data); API_EXPORT tokenizer Tokenize(char* Filename); API_EXPORT tokenizer Tokenize(string Data, char* Filename); diff --git a/libcommon/src/types.h b/libcommon/src/types.h index 6a73835d..078c5a16 100644 --- a/libcommon/src/types.h +++ b/libcommon/src/types.h @@ -83,6 +83,31 @@ inline b32 IsPow2(u32 Value) { return ((Value & ~(Value - 1)) == Value); } +//Regular text +#define BLACK "\33[0;30m" +#define RED "\33[0;31m" +#define GREEN "\33[0;32m" +#define YELLOW "\33[0;33m" +#define BLUE "\33[0;34m" +#define MAGENTA "\33[0;35m" +#define CYAN "\33[0;36m" +#define WHITE "\33[0;37m" +#define LIGHT_GRAY "\33[0;37m" +#define DARK_GRAY "\33[1;30m" + +//Regular bold text +#define BOLD_BLACK "\33[1;30m" +#define BOLD_RED "\33[1;31m" +#define BOLD_GREEN "\33[1;32m" +#define BOLD_YELLOW "\33[1;33m" +#define BOLD_BLUE "\33[1;34m" +#define BOLD_MAGENTA "\33[1;35m" +#define BOLD_CYAN "\33[1;36m" +#define BOLD_WHITE "\33[1;37m" + +//Reset +#define RESET "\33[0m" + // note(jax): Platform-independent way to perform an assertion. // Flat out writes to zero memory to crash the program. // todo(jax): Create some sort of assert function that creates a message box