Refresh the repo

This commit is contained in:
Krzosa Karol
2026-03-20 08:35:18 +01:00
parent 771e9b59b3
commit 6e18bb6641
77 changed files with 27788 additions and 27766 deletions

65
modules/OSWin32.core Normal file
View File

@@ -0,0 +1,65 @@
#import "KERNEL32.core"
#import "Base.core"
PAGE_SIZE :: 4096
Memory :: struct
commit : SizeU
reserve: SizeU
data : *U8
ProcessHeap: HANDLE
Allocate :: (size: U64): *void
if ProcessHeap == 0
ProcessHeap = GetProcessHeap()
return HeapAlloc(ProcessHeap, 0, size)
Reserve :: (size: SizeU): Memory
result := Memory{reserve=AlignUp(size, PAGE_SIZE)}
result.data = VirtualAlloc(
flProtect = PAGE_READWRITE,
dwSize = result.reserve,
flAllocationType = MEM_RESERVE,
lpAddress = 0)->*U8
return result
Commit :: (m: *Memory, size: SizeU): bool
commit_size := AlignUp(size, PAGE_SIZE)
total_commit := m.commit + commit_size
clamped_commit := ClampTopSizeU(total_commit, m.reserve)
adjusted_commit := clamped_commit - m.commit
if adjusted_commit != 0
result := VirtualAlloc(
lpAddress = (m.data + m.commit)->*void,
dwSize = adjusted_commit,
flAllocationType = MEM_COMMIT,
flProtect = PAGE_READWRITE,
)
Assert(result != 0)
m.commit += adjusted_commit
return true
return false
Release :: (m: *Memory)
result := VirtualFree(m.data->*void, 0, MEM_RELEASE)
if result != 0
m.data = 0
m.commit = 0
m.reserve = 0
WriteConsole :: (string: String16)
handle := GetStdHandle(STD_OUTPUT_HANDLE)
WriteConsoleW(handle, string.str->*void, string.len->DWORD, 0, 0)
PerformanceFrequency: F64
PerformanceFrequency_S64: S64
Time :: (): F64
query: LARGE_INTEGER
if PerformanceFrequency_S64 == 0
err := QueryPerformanceFrequency(&PerformanceFrequency_S64)
Assert(err != 0)
PerformanceFrequency = PerformanceFrequency_S64->F64
err := QueryPerformanceCounter(&query)
Assert(err != 0)
result := query->F64 / PerformanceFrequency
return result