diff --git a/4ed_linux_keyboard.cpp b/4ed_linux_keyboard.cpp index 5d7dbecf..e4a2e9ee 100644 --- a/4ed_linux_keyboard.cpp +++ b/4ed_linux_keyboard.cpp @@ -13,22 +13,6 @@ internal void keycode_init(Display* dpy){ -#if 0 - // NOTE(inso): these are for XInput, currently not used. - - keycode_lookup_table[KEY_BACKSPACE] = codes->back; - keycode_lookup_table[KEY_DELETE] = codes->del; - keycode_lookup_table[KEY_UP] = codes->up; - keycode_lookup_table[KEY_DOWN] = codes->down; - keycode_lookup_table[KEY_LEFT] = codes->left; - keycode_lookup_table[KEY_RIGHT] = codes->right; - keycode_lookup_table[KEY_INSERT] = codes->insert; - keycode_lookup_table[KEY_HOME] = codes->home; - keycode_lookup_table[KEY_END] = codes->end; - keycode_lookup_table[KEY_PAGEUP] = codes->page_up; - keycode_lookup_table[KEY_PAGEDOWN] = codes->page_down; - keycode_lookup_table[KEY_ESC] = codes->esc; -#endif // NOTE(inso): This looks a bit dumb, but it's the best way I can think of to do it, since: // KeySyms are the type representing "virtual" keys, like XK_BackSpace, but they are 32-bit ints. @@ -55,7 +39,19 @@ keycode_init(Display* dpy){ { XK_End, key_end }, { XK_Page_Up, key_page_up }, { XK_Page_Down, key_page_down }, - { XK_Escape, key_esc } + { XK_Escape, key_esc }, + { XK_F1, key_f1 }, + { XK_F2, key_f2 }, + { XK_F3, key_f3 }, + { XK_F4, key_f4 }, + { XK_F5, key_f5 }, + { XK_F6, key_f6 }, + { XK_F7, key_f7 }, + { XK_F8, key_f8 }, + { XK_F9, key_f9 }, + { XK_F10, key_f10 }, + { XK_F11, key_f11 }, + { XK_F12, key_f12 }, }; const int table_size = sizeof(sym_table) / sizeof(struct SymMapping); diff --git a/linux_4ed.cpp b/linux_4ed.cpp index 6f4f85ec..ba9fc684 100644 --- a/linux_4ed.cpp +++ b/linux_4ed.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -177,7 +178,6 @@ globalvar Exchange exchange_vars; internal void* LinuxGetMemory_(i32 size, i32 line_number, char *file_name){ - // TODO(allen): Implement without stdlib.h void *result = 0; Assert(size != 0); @@ -197,7 +197,15 @@ LinuxGetMemory_(i32 size, i32 line_number, char *file_name){ result = bubble + 1; #else - result = malloc(size); + size_t real_size = size + sizeof(size_t); + result = mmap(0, real_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if(result == MAP_FAILED){ + perror("mmap"); + result = NULL; + } else { + memcpy(result, &real_size, sizeof(size_t)); + result = (char*)result + sizeof(size_t); + } #endif return(result); @@ -205,8 +213,6 @@ LinuxGetMemory_(i32 size, i32 line_number, char *file_name){ internal void LinuxFreeMemory(void *block){ - // TODO(allen): Implement without stdlib.h - if (block){ #if FRED_INTERNAL Sys_Bubble *bubble; @@ -220,7 +226,9 @@ LinuxFreeMemory(void *block){ free(bubble); #else - free(block); + block = (char*)block - sizeof(size_t); + size_t len = *(size_t*)block; + munmap(block, len); #endif } } @@ -1145,23 +1153,29 @@ Sys_To_Binary_Path(system_to_binary_path){ } internal b32 -LinuxLoadAppCode(){ +LinuxLoadAppCode(String* base_dir){ b32 result = 0; App_Get_Functions *get_funcs = 0; - linuxvars.app_code = dlopen("./4ed_app.so", RTLD_LAZY); + if(!system_to_binary_path(base_dir, "4ed_app.so")){ + return 0; + } + + printf("DLOPEN: %s\n", base_dir->str); + + linuxvars.app_code = dlopen(base_dir->str, RTLD_LAZY); if (linuxvars.app_code){ get_funcs = (App_Get_Functions*) dlsym(linuxvars.app_code, "app_get_functions"); } else { fprintf(stderr, "dlopen failed: %s\n", dlerror()); } - + if (get_funcs){ result = 1; linuxvars.app = get_funcs(); } - + return(result); } @@ -1802,11 +1816,14 @@ main(int argc, char **argv) linuxvars.first = 1; - if (!LinuxLoadAppCode()){ + char base_dir_mem[PATH_MAX]; + String base_dir = make_fixed_width_string(base_dir_mem); + + if (!LinuxLoadAppCode(&base_dir)){ // TODO(allen): Failed to load app code, serious problem. return 99; } - + System_Functions system_; System_Functions *system = &system_; linuxvars.system = system; @@ -1885,11 +1902,15 @@ main(int argc, char **argv) keycode_init(linuxvars.XDisplay); #ifdef FRED_SUPER - char *custom_file_default = "./4coder_custom.so"; + char custom_file_default[] = "4coder_custom.so"; char *custom_file; - if (linuxvars.settings.custom_dll) custom_file = linuxvars.settings.custom_dll; - else custom_file = custom_file_default; - + if (linuxvars.settings.custom_dll){ + custom_file = linuxvars.settings.custom_dll; + } else { + system_to_binary_path(&base_dir, custom_file_default); + custom_file = base_dir.str; + } + linuxvars.custom = dlopen(custom_file, RTLD_LAZY); if (!linuxvars.custom && custom_file != custom_file_default){ if (!linuxvars.settings.custom_dll_is_strict){ @@ -1961,7 +1982,7 @@ main(int argc, char **argv) linuxvars.target.max = Mbytes(1); linuxvars.target.push_buffer = (byte*)system_get_memory(linuxvars.target.max); - File_Slot file_slots[32]; + File_Slot file_slots[32] = {}; sysshared_init_file_exchange(&exchange_vars, file_slots, ArrayCount(file_slots), 0); Font_Load_Parameters params[8];