41 lines
1.3 KiB
C
41 lines
1.3 KiB
C
function S32 os_main();
|
|
const SizeU page_size = 4096;
|
|
|
|
LRESULT CALLBACK
|
|
WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
|
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);;
|
|
}
|
|
|
|
int
|
|
WinMain(HINSTANCE hInstance, HINSTANCE a, LPSTR b, int nShowCmd){
|
|
wchar_t *CLASS_NAME = L"Cool window class";
|
|
wchar_t *WINDOW_NAME = L"Have a good day!";
|
|
|
|
WNDCLASSW wc = { };
|
|
wc.lpfnWndProc = WindowProc;
|
|
wc.hInstance = hInstance;
|
|
wc.lpszClassName = CLASS_NAME;
|
|
RegisterClassW(&wc);
|
|
|
|
HWND window_handle = CreateWindowExW(0, CLASS_NAME, WINDOW_NAME, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInstance, 0);
|
|
ShowWindow(window_handle, nShowCmd);
|
|
return os_main();
|
|
}
|
|
|
|
function OS_Memory
|
|
os_reserve(SizeU size){
|
|
OS_Memory result = {0};
|
|
SizeU adjusted_size = align_up(size, page_size);
|
|
result.data = VirtualAlloc(0, adjusted_size, MEM_RESERVE, PAGE_READWRITE);
|
|
assert_msg(result.data, "Failed to reserve virtual memory");
|
|
result.reserve = adjusted_size;
|
|
return result;
|
|
}
|
|
|
|
function void
|
|
os_commit(OS_Memory *m, SizeU size){
|
|
SizeU commit = align_up(size, page_size);
|
|
void *p = VirtualAlloc((U8 *)m->data + m->commit, commit, MEM_COMMIT, PAGE_READWRITE);
|
|
assert_msg(p, "Failed to commit more memory");
|
|
m->commit += commit;
|
|
} |