Convert windows.odin to the new naming convention

This commit is contained in:
Ginger Bill
2017-05-28 16:08:29 +01:00
parent d3f63e5903
commit 826e05c96e
7 changed files with 179 additions and 179 deletions
+13 -13
View File
@@ -6,9 +6,9 @@ _ := compile_assert(ODIN_ARCH == "amd64"); // TODO(bill): x86 version
yield_thread :: proc() { win32.mm_pause(); } yield_thread :: proc() { win32.mm_pause(); }
mfence :: proc() { win32.ReadWriteBarrier(); } mfence :: proc() { win32.read_write_barrier(); }
sfence :: proc() { win32.WriteBarrier(); } sfence :: proc() { win32.write_barrier(); }
lfence :: proc() { win32.ReadBarrier(); } lfence :: proc() { win32.read_barrier(); }
load :: proc(a: ^i32) -> i32 { load :: proc(a: ^i32) -> i32 {
@@ -18,20 +18,20 @@ store :: proc(a: ^i32, value: i32) {
a^ = value; a^ = value;
} }
compare_exchange :: proc(a: ^i32, expected, desired: i32) -> i32 { compare_exchange :: proc(a: ^i32, expected, desired: i32) -> i32 {
return win32.InterlockedCompareExchange(a, desired, expected); return win32.interlocked_compare_exchange(a, desired, expected);
} }
exchanged :: proc(a: ^i32, desired: i32) -> i32 { exchanged :: proc(a: ^i32, desired: i32) -> i32 {
return win32.InterlockedExchange(a, desired); return win32.interlocked_exchange(a, desired);
} }
fetch_add :: proc(a: ^i32, operand: i32) -> i32 { fetch_add :: proc(a: ^i32, operand: i32) -> i32 {
return win32.InterlockedExchangeAdd(a, operand); return win32.interlocked_exchange_add(a, operand);
} }
fetch_and :: proc(a: ^i32, operand: i32) -> i32 { fetch_and :: proc(a: ^i32, operand: i32) -> i32 {
return win32.InterlockedAnd(a, operand); return win32.interlocked_and(a, operand);
} }
fetch_or :: proc(a: ^i32, operand: i32) -> i32 { fetch_or :: proc(a: ^i32, operand: i32) -> i32 {
return win32.InterlockedOr(a, operand); return win32.interlocked_or(a, operand);
} }
spin_lock :: proc(a: ^i32, time_out: int) -> bool { // NOTE(bill) time_out = -1 as default spin_lock :: proc(a: ^i32, time_out: int) -> bool { // NOTE(bill) time_out = -1 as default
old_value := compare_exchange(a, 1, 0); old_value := compare_exchange(a, 1, 0);
@@ -63,19 +63,19 @@ store :: proc(a: ^i64, value: i64) {
a^ = value; a^ = value;
} }
compare_exchange :: proc(a: ^i64, expected, desired: i64) -> i64 { compare_exchange :: proc(a: ^i64, expected, desired: i64) -> i64 {
return win32.InterlockedCompareExchange64(a, desired, expected); return win32.interlocked_compare_exchange64(a, desired, expected);
} }
exchanged :: proc(a: ^i64, desired: i64) -> i64 { exchanged :: proc(a: ^i64, desired: i64) -> i64 {
return win32.InterlockedExchange64(a, desired); return win32.interlocked_exchange64(a, desired);
} }
fetch_add :: proc(a: ^i64, operand: i64) -> i64 { fetch_add :: proc(a: ^i64, operand: i64) -> i64 {
return win32.InterlockedExchangeAdd64(a, operand); return win32.interlocked_exchange_add64(a, operand);
} }
fetch_and :: proc(a: ^i64, operand: i64) -> i64 { fetch_and :: proc(a: ^i64, operand: i64) -> i64 {
return win32.InterlockedAnd64(a, operand); return win32.interlocked_and64(a, operand);
} }
fetch_or :: proc(a: ^i64, operand: i64) -> i64 { fetch_or :: proc(a: ^i64, operand: i64) -> i64 {
return win32.InterlockedOr64(a, operand); return win32.interlocked_or64(a, operand);
} }
spin_lock :: proc(a: ^i64, time_out: int) -> bool { // NOTE(bill) time_out = -1 as default spin_lock :: proc(a: ^i64, time_out: int) -> bool { // NOTE(bill) time_out = -1 as default
old_value := compare_exchange(a, 1, 0); old_value := compare_exchange(a, 1, 0);
+1 -1
View File
@@ -1072,7 +1072,7 @@ sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ..any) -> string {
end := len(fmt); end := len(fmt);
arg_index := 0; arg_index := 0;
was_prev_index := false; was_prev_index := false;
for i := 0; i < end; { for i := 0; i < end; /**/ {
fi = FmtInfo{buf = b, good_arg_index = true}; fi = FmtInfo{buf = b, good_arg_index = true};
prev_i := i; prev_i := i;
+5 -5
View File
@@ -33,17 +33,17 @@ TexImage2D :: proc(target, level, internal_format,
_string_data :: proc(s: string) -> ^u8 #inline { return &s[0]; } _string_data :: proc(s: string) -> ^u8 #inline { return &s[0]; }
_libgl := win32.LoadLibraryA(_string_data("opengl32.dll\x00")); _libgl := win32.load_library_a(_string_data("opengl32.dll\x00"));
GetProcAddress :: proc(name: string) -> proc() #cc_c { get_proc_address :: proc(name: string) -> proc() #cc_c {
if name[len(name)-1] == 0 { if name[len(name)-1] == 0 {
name = name[0..<len(name)-1]; name = name[0..<len(name)-1];
} }
// NOTE(bill): null terminated // NOTE(bill): null terminated
assert((&name[0] + len(name))^ == 0); assert((&name[0] + len(name))^ == 0);
res := wgl.GetProcAddress(&name[0]); res := wgl.get_proc_address(&name[0]);
if res == nil { if res == nil {
res = win32.GetProcAddress(_libgl, &name[0]); res = win32.get_proc_address(_libgl, &name[0]);
} }
return res; return res;
} }
@@ -111,7 +111,7 @@ GetUniformLocation: proc(program: u32, name: ^byte) -> i32 #cc_c;
init :: proc() { init :: proc() {
set_proc_address :: proc(p: rawptr, name: string) #inline { set_proc_address :: proc(p: rawptr, name: string) #inline {
x := ^(proc() #cc_c)(p); x := ^(proc() #cc_c)(p);
x^ = GetProcAddress(name); x^ = get_proc_address(name);
} }
set_proc_address(&GenBuffers, "glGenBuffers\x00"); set_proc_address(&GenBuffers, "glGenBuffers\x00");
+22 -22
View File
@@ -96,16 +96,16 @@ open :: proc(path: string, mode: int, perm: u32) -> (Handle, Errno) {
buf: [300]byte; buf: [300]byte;
copy(buf[..], []byte(path)); copy(buf[..], []byte(path));
handle := Handle(win32.CreateFileA(&buf[0], access, share_mode, sa, create_mode, win32.FILE_ATTRIBUTE_NORMAL, nil)); handle := Handle(win32.create_file_a(&buf[0], access, share_mode, sa, create_mode, win32.FILE_ATTRIBUTE_NORMAL, nil));
if handle != INVALID_HANDLE { if handle != INVALID_HANDLE {
return handle, ERROR_NONE; return handle, ERROR_NONE;
} }
err := win32.GetLastError(); err := win32.get_last_error();
return INVALID_HANDLE, Errno(err); return INVALID_HANDLE, Errno(err);
} }
close :: proc(fd: Handle) { close :: proc(fd: Handle) {
win32.CloseHandle(win32.Handle(fd)); win32.close_handle(win32.Handle(fd));
} }
@@ -126,9 +126,9 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
} else { } else {
to_read = MAX; to_read = MAX;
} }
e := win32.WriteFile(win32.Handle(fd), &data[total_write], to_read, &single_write_length, nil); e := win32.write_file(win32.Handle(fd), &data[total_write], to_read, &single_write_length, nil);
if single_write_length <= 0 || e == win32.FALSE { if single_write_length <= 0 || e == win32.FALSE {
err := win32.GetLastError(); err := win32.get_last_error();
return int(total_write), Errno(e); return int(total_write), Errno(e);
} }
total_write += i64(single_write_length); total_write += i64(single_write_length);
@@ -155,9 +155,9 @@ read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
to_read = MAX; to_read = MAX;
} }
e := win32.ReadFile(win32.Handle(fd), &data[total_read], to_read, &single_read_length, nil); e := win32.read_file(win32.Handle(fd), &data[total_read], to_read, &single_read_length, nil);
if single_read_length <= 0 || e == win32.FALSE { if single_read_length <= 0 || e == win32.FALSE {
err := win32.GetLastError(); err := win32.get_last_error();
return int(total_read), Errno(e); return int(total_read), Errno(e);
} }
total_read += i64(single_read_length); total_read += i64(single_read_length);
@@ -174,13 +174,13 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
} }
hi := i32(offset>>32); hi := i32(offset>>32);
lo := i32(offset); lo := i32(offset);
ft := win32.GetFileType(win32.Handle(fd)); ft := win32.get_file_type(win32.Handle(fd));
if ft == win32.FILE_TYPE_PIPE { if ft == win32.FILE_TYPE_PIPE {
return 0, ERROR_FILE_IS_PIPE; return 0, ERROR_FILE_IS_PIPE;
} }
dw_ptr := win32.SetFilePointer(win32.Handle(fd), lo, &hi, w); dw_ptr := win32.set_file_pointer(win32.Handle(fd), lo, &hi, w);
if dw_ptr == win32.INVALID_SET_FILE_POINTER { if dw_ptr == win32.INVALID_SET_FILE_POINTER {
err := win32.GetLastError(); err := win32.get_last_error();
return 0, Errno(err); return 0, Errno(err);
} }
return i64(hi)<<32 + i64(dw_ptr), ERROR_NONE; return i64(hi)<<32 + i64(dw_ptr), ERROR_NONE;
@@ -189,8 +189,8 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
file_size :: proc(fd: Handle) -> (i64, Errno) { file_size :: proc(fd: Handle) -> (i64, Errno) {
length: i64; length: i64;
err: Errno; err: Errno;
if win32.GetFileSizeEx(win32.Handle(fd), &length) == 0 { if win32.get_file_size_ex(win32.Handle(fd), &length) == 0 {
err = Errno(win32.GetLastError()); err = Errno(win32.get_last_error());
} }
return length, err; return length, err;
} }
@@ -204,8 +204,8 @@ stderr := get_std_handle(win32.STD_ERROR_HANDLE);
get_std_handle :: proc(h: int) -> Handle { get_std_handle :: proc(h: int) -> Handle {
fd := win32.GetStdHandle(i32(h)); fd := win32.get_std_handle(i32(h));
win32.SetHandleInformation(fd, win32.HANDLE_FLAG_INHERIT, 0); win32.set_handle_information(fd, win32.HANDLE_FLAG_INHERIT, 0);
return Handle(fd); return Handle(fd);
} }
@@ -216,7 +216,7 @@ get_std_handle :: proc(h: int) -> Handle {
last_write_time :: proc(fd: Handle) -> FileTime { last_write_time :: proc(fd: Handle) -> FileTime {
file_info: win32.ByHandleFileInformation; file_info: win32.ByHandleFileInformation;
win32.GetFileInformationByHandle(win32.Handle(fd), &file_info); win32.get_file_information_by_handle(win32.Handle(fd), &file_info);
lo := FileTime(file_info.last_write_time.lo); lo := FileTime(file_info.last_write_time.lo);
hi := FileTime(file_info.last_write_time.hi); hi := FileTime(file_info.last_write_time.hi);
return lo | hi << 32; return lo | hi << 32;
@@ -231,7 +231,7 @@ last_write_time_by_name :: proc(name: string) -> FileTime {
copy(buf[..], []byte(name)); copy(buf[..], []byte(name));
if win32.GetFileAttributesExA(&buf[0], win32.GetFileExInfoStandard, &data) != 0 { if win32.get_file_attributes_ex_a(&buf[0], win32.GetFileExInfoStandard, &data) != 0 {
last_write_time = data.last_write_time; last_write_time = data.last_write_time;
} }
@@ -243,7 +243,7 @@ last_write_time_by_name :: proc(name: string) -> FileTime {
heap_alloc :: proc(size: int) -> rawptr { heap_alloc :: proc(size: int) -> rawptr {
return win32.HeapAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, size); return win32.heap_alloc(win32.get_process_heap(), win32.HEAP_ZERO_MEMORY, size);
} }
heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr { heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
if new_size == 0 { if new_size == 0 {
@@ -253,24 +253,24 @@ heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
if ptr == nil { if ptr == nil {
return heap_alloc(new_size); return heap_alloc(new_size);
} }
return win32.HeapReAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, ptr, new_size); return win32.heap_realloc(win32.get_process_heap(), win32.HEAP_ZERO_MEMORY, ptr, new_size);
} }
heap_free :: proc(ptr: rawptr) { heap_free :: proc(ptr: rawptr) {
if ptr == nil { if ptr == nil {
return; return;
} }
win32.HeapFree(win32.GetProcessHeap(), 0, ptr); win32.heap_free(win32.get_process_heap(), 0, ptr);
} }
exit :: proc(code: int) { exit :: proc(code: int) {
win32.ExitProcess(u32(code)); win32.exit_process(u32(code));
} }
current_thread_id :: proc() -> int { current_thread_id :: proc() -> int {
return int(win32.GetCurrentThreadId()); return int(win32.get_current_thread_id());
} }
@@ -329,7 +329,7 @@ _alloc_command_line_arguments :: proc() -> []string {
} }
arg_count: i32; arg_count: i32;
arg_list_ptr := win32.CommandLineToArgvW(win32.GetCommandLineW(), &arg_count); arg_list_ptr := win32.command_line_to_argv_w(win32.get_command_line_w(), &arg_count);
arg_list := make([]string, arg_count); arg_list := make([]string, arg_count);
for _, i in arg_list { for _, i in arg_list {
arg_list[i] = alloc_ucs2_to_utf8((arg_list_ptr+i)^); arg_list[i] = alloc_ucs2_to_utf8((arg_list_ptr+i)^);
+5 -5
View File
@@ -13,25 +13,25 @@ Mutex :: struct {
} }
current_thread_id :: proc() -> i32 { current_thread_id :: proc() -> i32 {
return i32(win32.GetCurrentThreadId()); return i32(win32.get_current_thread_id());
} }
semaphore_init :: proc(s: ^Semaphore) { semaphore_init :: proc(s: ^Semaphore) {
s._handle = win32.CreateSemaphoreA(nil, 0, 1<<31-1, nil); s._handle = win32.create_semaphore_a(nil, 0, 1<<31-1, nil);
} }
semaphore_destroy :: proc(s: ^Semaphore) { semaphore_destroy :: proc(s: ^Semaphore) {
win32.CloseHandle(s._handle); win32.close_handle(s._handle);
} }
semaphore_post :: proc(s: ^Semaphore, count: int) { semaphore_post :: proc(s: ^Semaphore, count: int) {
win32.ReleaseSemaphore(s._handle, i32(count), nil); win32.release_semaphore(s._handle, i32(count), nil);
} }
semaphore_release :: proc(s: ^Semaphore) #inline { semaphore_post(s, 1); } semaphore_release :: proc(s: ^Semaphore) #inline { semaphore_post(s, 1); }
semaphore_wait :: proc(s: ^Semaphore) { semaphore_wait :: proc(s: ^Semaphore) {
win32.WaitForSingleObject(s._handle, win32.INFINITE); win32.wait_for_single_object(s._handle, win32.INFINITE);
} }
+22 -22
View File
@@ -10,7 +10,7 @@ CONTEXT_CORE_PROFILE_BIT_ARB :: 0x00000001;
CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002; CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002;
Hglrc :: Handle; Hglrc :: Handle;
Color_Ref :: u32; ColorRef :: u32;
LayerPlaneDescriptor :: struct { LayerPlaneDescriptor :: struct {
size: u16, size: u16,
@@ -36,7 +36,7 @@ LayerPlaneDescriptor :: struct {
aux_buffers: byte, aux_buffers: byte,
layer_type: byte, layer_type: byte,
reserved: byte, reserved: byte,
transparent: Color_Ref, transparent: ColorRef,
} }
PointFloat :: struct { PointFloat :: struct {
@@ -57,26 +57,26 @@ SwapIntervalEXTType :: #type proc(interval : i32) -> bool #cc_c;
GetExtensionsStringARBType :: #type proc(Hdc) -> ^byte #cc_c; GetExtensionsStringARBType :: #type proc(Hdc) -> ^byte #cc_c;
CreateContextAttribsARB: CreateContextAttribsARBType; create_context_attribs_arb: CreateContextAttribsARBType;
ChoosePixelFormatARB: ChoosePixelFormatARBType; choose_pixel_format_arb: ChoosePixelFormatARBType;
SwapIntervalEXT: SwapIntervalEXTType; swap_interval_ext: SwapIntervalEXTType;
GetExtensionsStringARB: GetExtensionsStringARBType; get_extensions_string_arb: GetExtensionsStringARBType;
CreateContext :: proc(hdc: Hdc) -> Hglrc #foreign opengl32 "wglCreateContext"; create_context :: proc(hdc: Hdc) -> Hglrc #foreign opengl32 "wglCreateContext";
MakeCurrent :: proc(hdc: Hdc, hglrc: Hglrc) -> Bool #foreign opengl32 "wglMakeCurrent"; make_current :: proc(hdc: Hdc, hglrc: Hglrc) -> Bool #foreign opengl32 "wglMakeCurrent";
GetProcAddress :: proc(c_str: ^u8) -> Proc #foreign opengl32 "wglGetProcAddress"; get_proc_address :: proc(c_str: ^u8) -> Proc #foreign opengl32 "wglGetProcAddress";
DeleteContext :: proc(hglrc: Hglrc) -> Bool #foreign opengl32 "wglDeleteContext"; delete_context :: proc(hglrc: Hglrc) -> Bool #foreign opengl32 "wglDeleteContext";
CopyContext :: proc(src, dst: Hglrc, mask: u32) -> Bool #foreign opengl32 "wglCopyContext"; copy_context :: proc(src, dst: Hglrc, mask: u32) -> Bool #foreign opengl32 "wglCopyContext";
CreateLayerContext :: proc(hdc: Hdc, layer_plane: i32) -> Hglrc #foreign opengl32 "wglCreateLayerContext"; create_layer_context :: proc(hdc: Hdc, layer_plane: i32) -> Hglrc #foreign opengl32 "wglCreateLayerContext";
DescribeLayerPlane :: proc(hdc: Hdc, pixel_format, layer_plane: i32, bytes: u32, pd: ^LayerPlaneDescriptor) -> Bool #foreign opengl32 "wglDescribeLayerPlane"; describe_layer_plane :: proc(hdc: Hdc, pixel_format, layer_plane: i32, bytes: u32, pd: ^LayerPlaneDescriptor) -> Bool #foreign opengl32 "wglDescribeLayerPlane";
GetCurrentContext :: proc() -> Hglrc #foreign opengl32 "wglGetCurrentContext"; get_current_context :: proc() -> Hglrc #foreign opengl32 "wglGetCurrentContext";
GetCurrentDC :: proc() -> Hdc #foreign opengl32 "wglGetCurrentDC"; get_current_dc :: proc() -> Hdc #foreign opengl32 "wglGetCurrentDC";
GetLayerPaletteEntries :: proc(hdc: Hdc, layer_plane, start, entries: i32, cr: ^Color_Ref) -> i32 #foreign opengl32 "wglGetLayerPaletteEntries"; get_layer_palette_entries :: proc(hdc: Hdc, layer_plane, start, entries: i32, cr: ^ColorRef) -> i32 #foreign opengl32 "wglGetLayerPaletteEntries";
RealizeLayerPalette :: proc(hdc: Hdc, layer_plane: i32, realize: Bool) -> Bool #foreign opengl32 "wglRealizeLayerPalette"; realize_layer_palette :: proc(hdc: Hdc, layer_plane: i32, realize: Bool) -> Bool #foreign opengl32 "wglRealizeLayerPalette";
SetLayerPaletteEntries :: proc(hdc: Hdc, layer_plane, start, entries: i32, cr: ^Color_Ref) -> i32 #foreign opengl32 "wglSetLayerPaletteEntries"; set_layer_palette_entries :: proc(hdc: Hdc, layer_plane, start, entries: i32, cr: ^ColorRef) -> i32 #foreign opengl32 "wglSetLayerPaletteEntries";
ShareLists :: proc(hglrc1, hglrc2: Hglrc) -> Bool #foreign opengl32 "wglShareLists"; share_lists :: proc(hglrc1, hglrc2: Hglrc) -> Bool #foreign opengl32 "wglShareLists";
SwapLayerBuffers :: proc(hdc: Hdc, planes: u32) -> Bool #foreign opengl32 "wglSwapLayerBuffers"; swap_layer_buffers :: proc(hdc: Hdc, planes: u32) -> Bool #foreign opengl32 "wglSwapLayerBuffers";
UseFontBitmaps :: proc(hdc: Hdc, first, count, list_base: u32) -> Bool #foreign opengl32 "wglUseFontBitmaps"; use_font_bitmaps :: proc(hdc: Hdc, first, count, list_base: u32) -> Bool #foreign opengl32 "wglUseFontBitmaps";
UseFontOutlines :: proc(hdc: Hdc, first, count, list_base: u32, deviation, extrusion: f32, format: i32, gmf: ^Glyph_MetricsFloat) -> Bool #foreign opengl32 "wglUseFontOutlines"; use_font_outlines :: proc(hdc: Hdc, first, count, list_base: u32, deviation, extrusion: f32, format: i32, gmf: ^Glyph_MetricsFloat) -> Bool #foreign opengl32 "wglUseFontOutlines";
+111 -111
View File
@@ -71,7 +71,7 @@ Point :: struct #ordered {
WndClassExA :: struct #ordered { WndClassExA :: struct #ordered {
size, style: u32, size, style: u32,
wndproc: WndProc, wndproc: WndProc,
cls_extra, wnd_extra: i32, cls_extra, wnd_extra: i32,
instance: Hinstance, instance: Hinstance,
icon: Hicon, icon: Hicon,
@@ -148,90 +148,90 @@ GET_FILEEX_INFO_LEVELS :: i32;
GetFileExInfoStandard: GET_FILEEX_INFO_LEVELS : 0; GetFileExInfoStandard: GET_FILEEX_INFO_LEVELS : 0;
GetFileExMaxInfoLevel: GET_FILEEX_INFO_LEVELS : 1; GetFileExMaxInfoLevel: GET_FILEEX_INFO_LEVELS : 1;
GetLastError :: proc() -> i32 #foreign kernel32; get_last_error :: proc() -> i32 #foreign kernel32 "GetLastError";
ExitProcess :: proc(exit_code: u32) #foreign kernel32; exit_process :: proc(exit_code: u32) #foreign kernel32 "ExitProcess";
GetDesktopWindow :: proc() -> Hwnd #foreign user32; get_desktop_window :: proc() -> Hwnd #foreign user32 "GetDesktopWindow";
ShowCursor :: proc(show : Bool) #foreign user32; show_cursor :: proc(show : Bool) #foreign user32 "ShowCursor";
GetCursorPos :: proc(p: ^Point) -> i32 #foreign user32; get_cursor_pos :: proc(p: ^Point) -> i32 #foreign user32 "GetCursorPos";
ScreenToClient :: proc(h: Hwnd, p: ^Point) -> i32 #foreign user32; screen_to_client :: proc(h: Hwnd, p: ^Point) -> i32 #foreign user32 "ScreenToClient";
GetModuleHandleA :: proc(module_name: ^u8) -> Hinstance #foreign kernel32; get_module_handle_a :: proc(module_name: ^u8) -> Hinstance #foreign kernel32 "GetModuleHandleA";
GetStockObject :: proc(fn_object: i32) -> Hgdiobj #foreign gdi32; get_stock_object :: proc(fn_object: i32) -> Hgdiobj #foreign gdi32 "GetStockObject";
PostQuitMessage :: proc(exit_code: i32) #foreign user32; post_quit_message :: proc(exit_code: i32) #foreign user32 "PostQuitMessage";
SetWindowTextA :: proc(hwnd: Hwnd, c_string: ^u8) -> Bool #foreign user32; set_window_text_a :: proc(hwnd: Hwnd, c_string: ^u8) -> Bool #foreign user32 "SetWindowTextA";
QueryPerformanceFrequency :: proc(result: ^i64) -> i32 #foreign kernel32; query_performance_frequency :: proc(result: ^i64) -> i32 #foreign kernel32 "QueryPerformanceFrequency";
QueryPerformanceCounter :: proc(result: ^i64) -> i32 #foreign kernel32; query_performance_counter :: proc(result: ^i64) -> i32 #foreign kernel32 "QueryPerformanceCounter";
Sleep :: proc(ms: i32) -> i32 #foreign kernel32; sleep :: proc(ms: i32) -> i32 #foreign kernel32 "Sleep";
OutputDebugStringA :: proc(c_str: ^u8) #foreign kernel32; output_debug_string_a :: proc(c_str: ^u8) #foreign kernel32 "OutputDebugStringA";
RegisterClassExA :: proc(wc: ^WndClassExA) -> i16 #foreign user32; register_class_ex_a :: proc(wc: ^WndClassExA) -> i16 #foreign user32 "RegisterClassExA";
CreateWindowExA :: proc(ex_style: u32, create_window_ex_a :: proc(ex_style: u32,
class_name, title: ^u8, class_name, title: ^u8,
style: u32, style: u32,
x, y, w, h: i32, x, y, w, h: i32,
parent: Hwnd, menu: Hmenu, instance: Hinstance, parent: Hwnd, menu: Hmenu, instance: Hinstance,
param: rawptr) -> Hwnd #foreign user32; param: rawptr) -> Hwnd #foreign user32 "CreateWindowExA";
ShowWindow :: proc(hwnd: Hwnd, cmd_show: i32) -> Bool #foreign user32; show_window :: proc(hwnd: Hwnd, cmd_show: i32) -> Bool #foreign user32 "ShowWindow";
TranslateMessage :: proc(msg: ^Msg) -> Bool #foreign user32; translate_message :: proc(msg: ^Msg) -> Bool #foreign user32 "TranslateMessage";
DispatchMessageA :: proc(msg: ^Msg) -> Lresult #foreign user32; dispatch_message_a :: proc(msg: ^Msg) -> Lresult #foreign user32 "DispatchMessageA";
UpdateWindow :: proc(hwnd: Hwnd) -> Bool #foreign user32; update_window :: proc(hwnd: Hwnd) -> Bool #foreign user32 "UpdateWindow";
PeekMessageA :: proc(msg: ^Msg, hwnd: Hwnd, peek_message_a :: proc(msg: ^Msg, hwnd: Hwnd,
msg_filter_min, msg_filter_max, remove_msg: u32) -> Bool #foreign user32; msg_filter_min, msg_filter_max, remove_msg: u32) -> Bool #foreign user32 "PeekMessageA";
DefWindowProcA :: proc(hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Lresult #foreign user32; def_window_proc_a :: proc(hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Lresult #foreign user32 "DefWindowProcA";
AdjustWindowRect :: proc(rect: ^Rect, style: u32, menu: Bool) -> Bool #foreign user32; adjust_window_rect :: proc(rect: ^Rect, style: u32, menu: Bool) -> Bool #foreign user32 "AdjustWindowRect";
GetActiveWindow :: proc() -> Hwnd #foreign user32; get_active_window :: proc() -> Hwnd #foreign user32 "GetActiveWindow";
DestroyWindow :: proc(wnd: Hwnd) -> Bool #foreign user32; destroy_window :: proc(wnd: Hwnd) -> Bool #foreign user32 "DestroyWindow";
DescribePixelFormat :: proc(dc: Hdc, pixel_format: i32, bytes : u32, pfd: ^PixelFormatDescriptor) -> i32 #foreign user32; describe_pixel_format :: proc(dc: Hdc, pixel_format: i32, bytes : u32, pfd: ^PixelFormatDescriptor) -> i32 #foreign user32 "DescribePixelFormat";
GetQueryPerformanceFrequency :: proc() -> i64 { get_query_performance_frequency :: proc() -> i64 {
r: i64; r: i64;
QueryPerformanceFrequency(&r); query_performance_frequency(&r);
return r; return r;
} }
GetCommandLineA :: proc() -> ^u8 #foreign kernel32; get_command_line_a :: proc() -> ^u8 #foreign kernel32 "GetCommandLineA";
GetCommandLineW :: proc() -> ^u16 #foreign kernel32; get_command_line_w :: proc() -> ^u16 #foreign kernel32 "GetCommandLineW";
GetSystemMetrics :: proc(index: i32) -> i32 #foreign kernel32; get_system_metrics :: proc(index: i32) -> i32 #foreign kernel32 "GetSystemMetrics";
GetCurrentThreadId :: proc() -> u32 #foreign kernel32; get_current_thread_id :: proc() -> u32 #foreign kernel32 "GetCurrentThreadId";
CommandLineToArgvW :: proc(cmd_list: ^u16, num_args: ^i32) -> ^^u16 #foreign shell32; command_line_to_argv_w :: proc(cmd_list: ^u16, num_args: ^i32) -> ^^u16 #foreign shell32 "CommandLineToArgvW";
timeGetTime :: proc() -> u32 #foreign winmm; time_get_time :: proc() -> u32 #foreign winmm "timeGetTime";
GetSystemTimeAsFileTime :: proc(system_time_as_file_time: ^Filetime) #foreign kernel32; get_system_time_as_file_time :: proc(system_time_as_file_time: ^Filetime) #foreign kernel32 "GetSystemTimeAsFileTime";
FileTimeToLocalFileTime :: proc(file_time: ^Filetime, local_file_time: ^Filetime) -> Bool #foreign kernel32; file_time_to_local_file_time :: proc(file_time: ^Filetime, local_file_time: ^Filetime) -> Bool #foreign kernel32 "FileTimeToLocalFileTime";
FileTimeToSystemTime :: proc(file_time: ^Filetime, system_time: ^Systemtime) -> Bool #foreign kernel32; file_time_to_system_time :: proc(file_time: ^Filetime, system_time: ^Systemtime) -> Bool #foreign kernel32 "FileTimeToSystemTime";
SystemTimeToFileTime :: proc(system_time: ^Systemtime, file_time: ^Filetime) -> Bool #foreign kernel32; system_time_to_file_time :: proc(system_time: ^Systemtime, file_time: ^Filetime) -> Bool #foreign kernel32 "SystemTimeToFileTime";
// File Stuff // File Stuff
CloseHandle :: proc(h: Handle) -> i32 #foreign kernel32; close_handle :: proc(h: Handle) -> i32 #foreign kernel32 "CloseHandle";
GetStdHandle :: proc(h: i32) -> Handle #foreign kernel32; get_std_handle :: proc(h: i32) -> Handle #foreign kernel32 "GetStdHandle";
CreateFileA :: proc(filename: ^u8, desired_access, share_mode: u32, create_file_a :: proc(filename: ^u8, desired_access, share_mode: u32,
security: rawptr, security: rawptr,
creation, flags_and_attribs: u32, template_file: Handle) -> Handle #foreign kernel32; creation, flags_and_attribs: u32, template_file: Handle) -> Handle #foreign kernel32 "CreateFileA";
ReadFile :: proc(h: Handle, buf: rawptr, to_read: u32, bytes_read: ^i32, overlapped: rawptr) -> Bool #foreign kernel32; read_file :: proc(h: Handle, buf: rawptr, to_read: u32, bytes_read: ^i32, overlapped: rawptr) -> Bool #foreign kernel32 "ReadFile";
WriteFile :: proc(h: Handle, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> Bool #foreign kernel32; write_file :: proc(h: Handle, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> Bool #foreign kernel32 "WriteFile";
GetFileSizeEx :: proc(file_handle: Handle, file_size: ^i64) -> Bool #foreign kernel32; get_file_size_ex :: proc(file_handle: Handle, file_size: ^i64) -> Bool #foreign kernel32 "GetFileSizeEx";
GetFileAttributesA :: proc(filename : ^byte) -> u32 #foreign kernel32; get_file_attributes_a :: proc(filename: ^byte) -> u32 #foreign kernel32 "GetFileAttributesA";
GetFileAttributesExA :: proc(filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool #foreign kernel32; get_file_attributes_ex_a :: proc(filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool #foreign kernel32 "GetFileAttributesExA";
GetFileInformationByHandle :: proc(file_handle: Handle, file_info: ^ByHandleFileInformation) -> Bool #foreign kernel32; get_file_information_by_handle :: proc(file_handle: Handle, file_info: ^ByHandleFileInformation) -> Bool #foreign kernel32 "GetFileInformationByHandle";
GetFileType :: proc(file_handle: Handle) -> u32 #foreign kernel32; get_file_type :: proc(file_handle: Handle) -> u32 #foreign kernel32 "GetFileType";
SetFilePointer :: proc(file_handle: Handle, distance_to_move: i32, distance_to_move_high: ^i32, move_method: u32) -> u32 #foreign kernel32; set_file_pointer :: proc(file_handle: Handle, distance_to_move: i32, distance_to_move_high: ^i32, move_method: u32) -> u32 #foreign kernel32 "SetFilePointer";
SetHandleInformation :: proc(obj: Handle, mask, flags: u32) -> Bool #foreign kernel32; set_handle_information :: proc(obj: Handle, mask, flags: u32) -> Bool #foreign kernel32 "SetHandleInformation";
FindFirstFileA :: proc(file_name : ^byte, data : ^FindData) -> Handle #foreign kernel32; find_first_file_a :: proc(file_name : ^byte, data : ^FindData) -> Handle #foreign kernel32 "FindFirstFileA";
FindNextFileA :: proc(file : Handle, data : ^FindData) -> Bool #foreign kernel32; find_next_file_a :: proc(file : Handle, data : ^FindData) -> Bool #foreign kernel32 "FindNextFileA";
FindClose :: proc(file : Handle) -> Bool #foreign kernel32; find_close :: proc(file : Handle) -> Bool #foreign kernel32 "FindClose";
MAX_PATH :: 0x00000104; MAX_PATH :: 0x00000104;
@@ -289,10 +289,10 @@ INVALID_SET_FILE_POINTER :: ~u32(0);
HeapAlloc :: proc (h: Handle, flags: u32, bytes: int) -> rawptr #foreign kernel32; heap_alloc :: proc (h: Handle, flags: u32, bytes: int) -> rawptr #foreign kernel32 "HeapAlloc";
HeapReAlloc :: proc (h: Handle, flags: u32, memory: rawptr, bytes: int) -> rawptr #foreign kernel32; heap_realloc :: proc (h: Handle, flags: u32, memory: rawptr, bytes: int) -> rawptr #foreign kernel32 "HeapReAlloc";
HeapFree :: proc (h: Handle, flags: u32, memory: rawptr) -> Bool #foreign kernel32; heap_free :: proc (h: Handle, flags: u32, memory: rawptr) -> Bool #foreign kernel32 "HeapFree";
GetProcessHeap :: proc () -> Handle #foreign kernel32; get_process_heap :: proc () -> Handle #foreign kernel32 "GetProcessHeap";
HEAP_ZERO_MEMORY :: 0x00000008; HEAP_ZERO_MEMORY :: 0x00000008;
@@ -307,27 +307,27 @@ Security_Attributes :: struct #ordered {
INFINITE :: 0xffffffff; INFINITE :: 0xffffffff;
CreateSemaphoreA :: proc(attributes: ^Security_Attributes, initial_count, maximum_count: i32, name: ^byte) -> Handle #foreign kernel32; create_semaphore_a :: proc(attributes: ^Security_Attributes, initial_count, maximum_count: i32, name: ^byte) -> Handle #foreign kernel32 "CreateSemaphoreA";
ReleaseSemaphore :: proc(semaphore: Handle, release_count: i32, previous_count: ^i32) -> Bool #foreign kernel32; release_semaphore :: proc(semaphore: Handle, release_count: i32, previous_count: ^i32) -> Bool #foreign kernel32 "ReleaseSemaphore";
WaitForSingleObject :: proc(handle: Handle, milliseconds: u32) -> u32 #foreign kernel32; wait_for_single_object :: proc(handle: Handle, milliseconds: u32) -> u32 #foreign kernel32 "WaitForSingleObject";
InterlockedCompareExchange :: proc(dst: ^i32, exchange, comparand: i32) -> i32 #foreign kernel32; interlocked_compare_exchange :: proc(dst: ^i32, exchange, comparand: i32) -> i32 #foreign kernel32 "InterlockedCompareExchange";
InterlockedExchange :: proc(dst: ^i32, desired: i32) -> i32 #foreign kernel32; interlocked_exchange :: proc(dst: ^i32, desired: i32) -> i32 #foreign kernel32 "InterlockedExchange";
InterlockedExchangeAdd :: proc(dst: ^i32, desired: i32) -> i32 #foreign kernel32; interlocked_exchange_add :: proc(dst: ^i32, desired: i32) -> i32 #foreign kernel32 "InterlockedExchangeAdd";
InterlockedAnd :: proc(dst: ^i32, desired: i32) -> i32 #foreign kernel32; interlocked_and :: proc(dst: ^i32, desired: i32) -> i32 #foreign kernel32 "InterlockedAnd";
InterlockedOr :: proc(dst: ^i32, desired: i32) -> i32 #foreign kernel32; interlocked_or :: proc(dst: ^i32, desired: i32) -> i32 #foreign kernel32 "InterlockedOr";
InterlockedCompareExchange64 :: proc(dst: ^i64, exchange, comparand: i64) -> i64 #foreign kernel32; interlocked_compare_exchange64 :: proc(dst: ^i64, exchange, comparand: i64) -> i64 #foreign kernel32 "InterlockedCompareExchange64";
InterlockedExchange64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign kernel32; interlocked_exchange64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign kernel32 "InterlockedExchange64";
InterlockedExchangeAdd64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign kernel32; interlocked_exchange_add64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign kernel32 "InterlockedExchangeAdd64";
InterlockedAnd64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign kernel32; interlocked_and64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign kernel32 "InterlockedAnd64";
InterlockedOr64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign kernel32; interlocked_or64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign kernel32 "InterlockedOr64";
mm_pause :: proc() #foreign kernel32 "_mm_pause"; mm_pause :: proc() #foreign kernel32 "_mm_pause";
ReadWriteBarrier :: proc() #foreign kernel32; read_write_barrier :: proc() #foreign kernel32 "ReadWriteBarrier";
WriteBarrier :: proc() #foreign kernel32; write_barrier :: proc() #foreign kernel32 "WriteBarrier";
ReadBarrier :: proc() #foreign kernel32; read_barrier :: proc() #foreign kernel32 "ReadBarrier";
@@ -335,7 +335,7 @@ ReadBarrier :: proc() #foreign kernel32;
Hmonitor :: Handle; Hmonitor :: Handle;
GWL_STYLE :: -16; GWL_STYLE :: -16;
Hwnd_TOP :: Hwnd(uint(0)); Hwnd_TOP :: Hwnd(uint(0));
@@ -366,19 +366,19 @@ WindowPlacement :: struct #ordered {
normal_pos: Rect, normal_pos: Rect,
} }
GetMonitorInfoA :: proc(monitor: Hmonitor, mi: ^MonitorInfo) -> Bool #foreign user32; get_monitor_info_a :: proc(monitor: Hmonitor, mi: ^MonitorInfo) -> Bool #foreign user32 "GetMonitorInfoA";
MonitorFromWindow :: proc(wnd: Hwnd, flags : u32) -> Hmonitor #foreign user32; monitor_from_window :: proc(wnd: Hwnd, flags : u32) -> Hmonitor #foreign user32 "MonitorFromWindow";
SetWindowPos :: proc(wnd: Hwnd, wndInsertAfter: Hwnd, x, y, width, height: i32, flags: u32) #foreign user32 "SetWindowPos"; set_window_pos :: proc(wnd: Hwnd, wndInsertAfter: Hwnd, x, y, width, height: i32, flags: u32) #foreign user32 "SetWindowPos";
GetWindowPlacement :: proc(wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #foreign user32; get_window_placement :: proc(wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #foreign user32 "GetWindowPlacement";
SetWindowPlacement :: proc(wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #foreign user32; set_window_placement :: proc(wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #foreign user32 "SetWindowPlacement";
GetWindowRect :: proc(wnd: Hwnd, rect: ^Rect) -> Bool #foreign user32; get_window_rect :: proc(wnd: Hwnd, rect: ^Rect) -> Bool #foreign user32 "GetWindowRect";
GetWindowLongPtrA :: proc(wnd: Hwnd, index: i32) -> i64 #foreign user32; get_window_long_ptr_a :: proc(wnd: Hwnd, index: i32) -> i64 #foreign user32 "GetWindowLongPtrA";
SetWindowLongPtrA :: proc(wnd: Hwnd, index: i32, new: i64) -> i64 #foreign user32; set_window_long_ptr_a :: proc(wnd: Hwnd, index: i32, new: i64) -> i64 #foreign user32 "SetWindowLongPtrA";
GetWindowText :: proc(wnd: Hwnd, str: ^byte, maxCount: i32) -> i32 #foreign user32; get_window_text :: proc(wnd: Hwnd, str: ^byte, maxCount: i32) -> i32 #foreign user32 "GetWindowText";
HIWORD :: proc(wParam: Wparam) -> u16 { return u16((u32(wParam) >> 16) & 0xffff); } HIWORD :: proc(wParam: Wparam) -> u16 { return u16((u32(wParam) >> 16) & 0xffff); }
HIWORD :: proc(lParam: Lparam) -> u16 { return u16((u32(lParam) >> 16) & 0xffff); } HIWORD :: proc(lParam: Lparam) -> u16 { return u16((u32(lParam) >> 16) & 0xffff); }
@@ -418,20 +418,20 @@ DIB_RGB_COLORS :: 0x00;
SRCCOPY: u32 : 0x00cc0020; SRCCOPY: u32 : 0x00cc0020;
StretchDIBits :: proc (hdc: Hdc, stretch_dibits :: proc (hdc: Hdc,
x_dst, y_dst, width_dst, height_dst: i32, x_dst, y_dst, width_dst, height_dst: i32,
x_src, y_src, width_src, header_src: i32, x_src, y_src, width_src, header_src: i32,
bits: rawptr, bits_info: ^BitmapInfo, bits: rawptr, bits_info: ^BitmapInfo,
usage: u32, usage: u32,
rop: u32) -> i32 #foreign gdi32; rop: u32) -> i32 #foreign gdi32 "StretchDIBits";
LoadLibraryA :: proc (c_str: ^u8) -> Hmodule #foreign kernel32; load_library_a :: proc (c_str: ^u8) -> Hmodule #foreign kernel32 "LoadLibraryA";
FreeLibrary :: proc (h: Hmodule) #foreign kernel32; free_library :: proc (h: Hmodule) #foreign kernel32 "FreeLibrary";
GetProcAddress :: proc (h: Hmodule, c_str: ^u8) -> Proc #foreign kernel32; get_proc_address :: proc (h: Hmodule, c_str: ^u8) -> Proc #foreign kernel32 "GetProcAddress";
GetClientRect :: proc(hwnd: Hwnd, rect: ^Rect) -> Bool #foreign user32; get_client_rect :: proc(hwnd: Hwnd, rect: ^Rect) -> Bool #foreign user32 "GetClientRect";
// Windows OpenGL // Windows OpenGL
PFD_TYPE_RGBA :: 0; PFD_TYPE_RGBA :: 0;
@@ -488,20 +488,20 @@ PixelFormatDescriptor :: struct #ordered {
damage_mask: u32, damage_mask: u32,
} }
GetDC :: proc(h: Hwnd) -> Hdc #foreign user32; get_d_c :: proc(h: Hwnd) -> Hdc #foreign user32 "GetDC";
SetPixelFormat :: proc(hdc: Hdc, pixel_format: i32, pfd: ^PixelFormatDescriptor) -> Bool #foreign gdi32; set_pixel_format :: proc(hdc: Hdc, pixel_format: i32, pfd: ^PixelFormatDescriptor) -> Bool #foreign gdi32 "SetPixelFormat";
ChoosePixelFormat :: proc(hdc: Hdc, pfd: ^PixelFormatDescriptor) -> i32 #foreign gdi32; choose_pixel_format :: proc(hdc: Hdc, pfd: ^PixelFormatDescriptor) -> i32 #foreign gdi32 "ChoosePixelFormat";
SwapBuffers :: proc(hdc: Hdc) -> Bool #foreign gdi32; swap_buffers :: proc(hdc: Hdc) -> Bool #foreign gdi32 "SwapBuffers";
ReleaseDC :: proc(wnd: Hwnd, hdc: Hdc) -> i32 #foreign user32; release_d_c :: proc(wnd: Hwnd, hdc: Hdc) -> i32 #foreign user32 "ReleaseDC";
Proc :: #type proc() #cc_c; Proc :: #type proc() #cc_c;
GetKeyState :: proc(v_key: i32) -> i16 #foreign user32; get_key_state :: proc(v_key: i32) -> i16 #foreign user32 "GetKeyState";
GetAsyncKeyState :: proc(v_key: i32) -> i16 #foreign user32; get_async_key_state :: proc(v_key: i32) -> i16 #foreign user32 "GetAsyncKeyState";
is_key_down :: proc(key: KeyCode) -> bool #inline { return GetAsyncKeyState(i32(key)) < 0; } is_key_down :: proc(key: KeyCode) -> bool #inline { return get_async_key_state(i32(key)) < 0; }
KeyCode :: enum i32 { KeyCode :: enum i32 {
Lbutton = 0x01, Lbutton = 0x01,