diff --git a/src/unix/macOSXGlue.h b/src/unix/macOSXGlue.h index cd3a880bd..f49402805 100644 --- a/src/unix/macOSXGlue.h +++ b/src/unix/macOSXGlue.h @@ -13,11 +13,10 @@ CF_IMPLICIT_BRIDGING_ENABLED CF_EXTERN_C_BEGIN -void getDefaultROMPath(char*); -int toto(); +void getDefaultROMPath(char *); +int toto(); CF_EXTERN_C_END CF_IMPLICIT_BRIDGING_DISABLED - #endif /* macOSXGlue_h */ diff --git a/src/unix/unix.c b/src/unix/unix.c index 598eb9acc..8d6aaf3d1 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -1,6 +1,6 @@ #ifdef __linux__ -#define _FILE_OFFSET_BITS 64 -#define _LARGEFILE64_SOURCE 1 +# define _FILE_OFFSET_BITS 64 +# define _LARGEFILE64_SOURCE 1 #endif #include #include @@ -41,158 +41,154 @@ #include <86box/gdbstub.h> #ifdef __APPLE__ -#include "macOSXGlue.h" +# include "macOSXGlue.h" #endif -static int first_use = 1; -static uint64_t StartingTime; +static int first_use = 1; +static uint64_t StartingTime; static uint64_t Frequency; -int rctrl_is_lalt; -int update_icons; -int kbd_req_capture; -int hide_status_bar; -int hide_tool_bar; -int fixed_size_x = 640; -int fixed_size_y = 480; -extern int title_set; -extern wchar_t sdl_win_title[512]; -plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; -joystick_t joystick_state[MAX_JOYSTICKS]; -int joysticks_present; -SDL_mutex *blitmtx; -SDL_threadID eventthread; -static int exit_event = 0; -static int fullscreen_pending = 0; -uint32_t lang_id = 0x0409, lang_sys = 0x0409; // Multilangual UI variables, for now all set to LCID of en-US -char icon_set[256] = ""; /* name of the iconset to be used */ +int rctrl_is_lalt; +int update_icons; +int kbd_req_capture; +int hide_status_bar; +int hide_tool_bar; +int fixed_size_x = 640; +int fixed_size_y = 480; +extern int title_set; +extern wchar_t sdl_win_title[512]; +plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; +joystick_t joystick_state[MAX_JOYSTICKS]; +int joysticks_present; +SDL_mutex *blitmtx; +SDL_threadID eventthread; +static int exit_event = 0; +static int fullscreen_pending = 0; +uint32_t lang_id = 0x0409, lang_sys = 0x0409; // Multilangual UI variables, for now all set to LCID of en-US +char icon_set[256] = ""; /* name of the iconset to be used */ -static const uint16_t sdl_to_xt[0x200] = -{ - [SDL_SCANCODE_ESCAPE] = 0x01, - [SDL_SCANCODE_1] = 0x02, - [SDL_SCANCODE_2] = 0x03, - [SDL_SCANCODE_3] = 0x04, - [SDL_SCANCODE_4] = 0x05, - [SDL_SCANCODE_5] = 0x06, - [SDL_SCANCODE_6] = 0x07, - [SDL_SCANCODE_7] = 0x08, - [SDL_SCANCODE_8] = 0x09, - [SDL_SCANCODE_9] = 0x0A, - [SDL_SCANCODE_0] = 0x0B, - [SDL_SCANCODE_MINUS] = 0x0C, - [SDL_SCANCODE_EQUALS] = 0x0D, - [SDL_SCANCODE_BACKSPACE] = 0x0E, - [SDL_SCANCODE_TAB] = 0x0F, - [SDL_SCANCODE_Q] = 0x10, - [SDL_SCANCODE_W] = 0x11, - [SDL_SCANCODE_E] = 0x12, - [SDL_SCANCODE_R] = 0x13, - [SDL_SCANCODE_T] = 0x14, - [SDL_SCANCODE_Y] = 0x15, - [SDL_SCANCODE_U] = 0x16, - [SDL_SCANCODE_I] = 0x17, - [SDL_SCANCODE_O] = 0x18, - [SDL_SCANCODE_P] = 0x19, - [SDL_SCANCODE_LEFTBRACKET] = 0x1A, +static const uint16_t sdl_to_xt[0x200] = { + [SDL_SCANCODE_ESCAPE] = 0x01, + [SDL_SCANCODE_1] = 0x02, + [SDL_SCANCODE_2] = 0x03, + [SDL_SCANCODE_3] = 0x04, + [SDL_SCANCODE_4] = 0x05, + [SDL_SCANCODE_5] = 0x06, + [SDL_SCANCODE_6] = 0x07, + [SDL_SCANCODE_7] = 0x08, + [SDL_SCANCODE_8] = 0x09, + [SDL_SCANCODE_9] = 0x0A, + [SDL_SCANCODE_0] = 0x0B, + [SDL_SCANCODE_MINUS] = 0x0C, + [SDL_SCANCODE_EQUALS] = 0x0D, + [SDL_SCANCODE_BACKSPACE] = 0x0E, + [SDL_SCANCODE_TAB] = 0x0F, + [SDL_SCANCODE_Q] = 0x10, + [SDL_SCANCODE_W] = 0x11, + [SDL_SCANCODE_E] = 0x12, + [SDL_SCANCODE_R] = 0x13, + [SDL_SCANCODE_T] = 0x14, + [SDL_SCANCODE_Y] = 0x15, + [SDL_SCANCODE_U] = 0x16, + [SDL_SCANCODE_I] = 0x17, + [SDL_SCANCODE_O] = 0x18, + [SDL_SCANCODE_P] = 0x19, + [SDL_SCANCODE_LEFTBRACKET] = 0x1A, [SDL_SCANCODE_RIGHTBRACKET] = 0x1B, - [SDL_SCANCODE_RETURN] = 0x1C, - [SDL_SCANCODE_LCTRL] = 0x1D, - [SDL_SCANCODE_A] = 0x1E, - [SDL_SCANCODE_S] = 0x1F, - [SDL_SCANCODE_D] = 0x20, - [SDL_SCANCODE_F] = 0x21, - [SDL_SCANCODE_G] = 0x22, - [SDL_SCANCODE_H] = 0x23, - [SDL_SCANCODE_J] = 0x24, - [SDL_SCANCODE_K] = 0x25, - [SDL_SCANCODE_L] = 0x26, - [SDL_SCANCODE_SEMICOLON] = 0x27, - [SDL_SCANCODE_APOSTROPHE] = 0x28, - [SDL_SCANCODE_GRAVE] = 0x29, - [SDL_SCANCODE_LSHIFT] = 0x2A, - [SDL_SCANCODE_BACKSLASH] = 0x2B, - [SDL_SCANCODE_Z] = 0x2C, - [SDL_SCANCODE_X] = 0x2D, - [SDL_SCANCODE_C] = 0x2E, - [SDL_SCANCODE_V] = 0x2F, - [SDL_SCANCODE_B] = 0x30, - [SDL_SCANCODE_N] = 0x31, - [SDL_SCANCODE_M] = 0x32, - [SDL_SCANCODE_COMMA] = 0x33, - [SDL_SCANCODE_PERIOD] = 0x34, - [SDL_SCANCODE_SLASH] = 0x35, - [SDL_SCANCODE_RSHIFT] = 0x36, - [SDL_SCANCODE_KP_MULTIPLY] = 0x37, - [SDL_SCANCODE_LALT] = 0x38, - [SDL_SCANCODE_SPACE] = 0x39, - [SDL_SCANCODE_CAPSLOCK] = 0x3A, - [SDL_SCANCODE_F1] = 0x3B, - [SDL_SCANCODE_F2] = 0x3C, - [SDL_SCANCODE_F3] = 0x3D, - [SDL_SCANCODE_F4] = 0x3E, - [SDL_SCANCODE_F5] = 0x3F, - [SDL_SCANCODE_F6] = 0x40, - [SDL_SCANCODE_F7] = 0x41, - [SDL_SCANCODE_F8] = 0x42, - [SDL_SCANCODE_F9] = 0x43, - [SDL_SCANCODE_F10] = 0x44, + [SDL_SCANCODE_RETURN] = 0x1C, + [SDL_SCANCODE_LCTRL] = 0x1D, + [SDL_SCANCODE_A] = 0x1E, + [SDL_SCANCODE_S] = 0x1F, + [SDL_SCANCODE_D] = 0x20, + [SDL_SCANCODE_F] = 0x21, + [SDL_SCANCODE_G] = 0x22, + [SDL_SCANCODE_H] = 0x23, + [SDL_SCANCODE_J] = 0x24, + [SDL_SCANCODE_K] = 0x25, + [SDL_SCANCODE_L] = 0x26, + [SDL_SCANCODE_SEMICOLON] = 0x27, + [SDL_SCANCODE_APOSTROPHE] = 0x28, + [SDL_SCANCODE_GRAVE] = 0x29, + [SDL_SCANCODE_LSHIFT] = 0x2A, + [SDL_SCANCODE_BACKSLASH] = 0x2B, + [SDL_SCANCODE_Z] = 0x2C, + [SDL_SCANCODE_X] = 0x2D, + [SDL_SCANCODE_C] = 0x2E, + [SDL_SCANCODE_V] = 0x2F, + [SDL_SCANCODE_B] = 0x30, + [SDL_SCANCODE_N] = 0x31, + [SDL_SCANCODE_M] = 0x32, + [SDL_SCANCODE_COMMA] = 0x33, + [SDL_SCANCODE_PERIOD] = 0x34, + [SDL_SCANCODE_SLASH] = 0x35, + [SDL_SCANCODE_RSHIFT] = 0x36, + [SDL_SCANCODE_KP_MULTIPLY] = 0x37, + [SDL_SCANCODE_LALT] = 0x38, + [SDL_SCANCODE_SPACE] = 0x39, + [SDL_SCANCODE_CAPSLOCK] = 0x3A, + [SDL_SCANCODE_F1] = 0x3B, + [SDL_SCANCODE_F2] = 0x3C, + [SDL_SCANCODE_F3] = 0x3D, + [SDL_SCANCODE_F4] = 0x3E, + [SDL_SCANCODE_F5] = 0x3F, + [SDL_SCANCODE_F6] = 0x40, + [SDL_SCANCODE_F7] = 0x41, + [SDL_SCANCODE_F8] = 0x42, + [SDL_SCANCODE_F9] = 0x43, + [SDL_SCANCODE_F10] = 0x44, [SDL_SCANCODE_NUMLOCKCLEAR] = 0x45, - [SDL_SCANCODE_SCROLLLOCK] = 0x46, - [SDL_SCANCODE_HOME] = 0x147, - [SDL_SCANCODE_UP] = 0x148, - [SDL_SCANCODE_PAGEUP] = 0x149, - [SDL_SCANCODE_KP_MINUS] = 0x4A, - [SDL_SCANCODE_LEFT] = 0x14B, - [SDL_SCANCODE_KP_5] = 0x4C, - [SDL_SCANCODE_RIGHT] = 0x14D, - [SDL_SCANCODE_KP_PLUS] = 0x4E, - [SDL_SCANCODE_END] = 0x14F, - [SDL_SCANCODE_DOWN] = 0x150, - [SDL_SCANCODE_PAGEDOWN] = 0x151, - [SDL_SCANCODE_INSERT] = 0x152, - [SDL_SCANCODE_DELETE] = 0x153, - [SDL_SCANCODE_F11] = 0x57, - [SDL_SCANCODE_F12] = 0x58, + [SDL_SCANCODE_SCROLLLOCK] = 0x46, + [SDL_SCANCODE_HOME] = 0x147, + [SDL_SCANCODE_UP] = 0x148, + [SDL_SCANCODE_PAGEUP] = 0x149, + [SDL_SCANCODE_KP_MINUS] = 0x4A, + [SDL_SCANCODE_LEFT] = 0x14B, + [SDL_SCANCODE_KP_5] = 0x4C, + [SDL_SCANCODE_RIGHT] = 0x14D, + [SDL_SCANCODE_KP_PLUS] = 0x4E, + [SDL_SCANCODE_END] = 0x14F, + [SDL_SCANCODE_DOWN] = 0x150, + [SDL_SCANCODE_PAGEDOWN] = 0x151, + [SDL_SCANCODE_INSERT] = 0x152, + [SDL_SCANCODE_DELETE] = 0x153, + [SDL_SCANCODE_F11] = 0x57, + [SDL_SCANCODE_F12] = 0x58, - [SDL_SCANCODE_KP_ENTER] = 0x11c, - [SDL_SCANCODE_RCTRL] = 0x11d, + [SDL_SCANCODE_KP_ENTER] = 0x11c, + [SDL_SCANCODE_RCTRL] = 0x11d, [SDL_SCANCODE_KP_DIVIDE] = 0x135, - [SDL_SCANCODE_RALT] = 0x138, - [SDL_SCANCODE_KP_9] = 0x49, - [SDL_SCANCODE_KP_8] = 0x48, - [SDL_SCANCODE_KP_7] = 0x47, - [SDL_SCANCODE_KP_6] = 0x4D, - [SDL_SCANCODE_KP_4] = 0x4B, - [SDL_SCANCODE_KP_3] = 0x51, - [SDL_SCANCODE_KP_2] = 0x50, - [SDL_SCANCODE_KP_1] = 0x4F, - [SDL_SCANCODE_KP_0] = 0x52, + [SDL_SCANCODE_RALT] = 0x138, + [SDL_SCANCODE_KP_9] = 0x49, + [SDL_SCANCODE_KP_8] = 0x48, + [SDL_SCANCODE_KP_7] = 0x47, + [SDL_SCANCODE_KP_6] = 0x4D, + [SDL_SCANCODE_KP_4] = 0x4B, + [SDL_SCANCODE_KP_3] = 0x51, + [SDL_SCANCODE_KP_2] = 0x50, + [SDL_SCANCODE_KP_1] = 0x4F, + [SDL_SCANCODE_KP_0] = 0x52, [SDL_SCANCODE_KP_PERIOD] = 0x53, - [SDL_SCANCODE_LGUI] = 0x15B, - [SDL_SCANCODE_RGUI] = 0x15C, + [SDL_SCANCODE_LGUI] = 0x15B, + [SDL_SCANCODE_RGUI] = 0x15C, [SDL_SCANCODE_APPLICATION] = 0x15D, [SDL_SCANCODE_PRINTSCREEN] = 0x137 }; -typedef struct sdl_blit_params -{ +typedef struct sdl_blit_params { int x, y, w, h; } sdl_blit_params; -sdl_blit_params params = { 0, 0, 0, 0 }; -int blitreq = 0; +sdl_blit_params params = { 0, 0, 0, 0 }; +int blitreq = 0; -void* dynld_module(const char *name, dllimp_t *table) +void * +dynld_module(const char *name, dllimp_t *table) { - dllimp_t* imp; - void* modhandle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL); - if (modhandle) - { - for (imp = table; imp->name != NULL; imp++) - { - if ((*(void**)imp->func = dlsym(modhandle, imp->name)) == NULL) - { + dllimp_t *imp; + void *modhandle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL); + if (modhandle) { + for (imp = table; imp->name != NULL; imp++) { + if ((*(void **) imp->func = dlsym(modhandle, imp->name)) == NULL) { dlclose(modhandle); return NULL; } @@ -204,16 +200,16 @@ void* dynld_module(const char *name, dllimp_t *table) void plat_tempfile(char *bufp, char *prefix, char *suffix) { - struct tm* calendertime; + struct tm *calendertime; struct timeval t; - time_t curtime; + time_t curtime; if (prefix != NULL) - sprintf(bufp, "%s-", prefix); - else - strcpy(bufp, ""); + sprintf(bufp, "%s-", prefix); + else + strcpy(bufp, ""); gettimeofday(&t, NULL); - curtime = time(NULL); + curtime = time(NULL); calendertime = localtime(&curtime); sprintf(&bufp[strlen(bufp)], "%d%02d%02d-%02d%02d%02d-%03ld%s", calendertime->tm_year, calendertime->tm_mon, calendertime->tm_mday, calendertime->tm_hour, calendertime->tm_min, calendertime->tm_sec, t.tv_usec / 1000, suffix); } @@ -225,20 +221,21 @@ plat_getcwd(char *bufp, int max) } int -plat_chdir(char* str) +plat_chdir(char *str) { return chdir(str); } -void dynld_close(void *handle) +void +dynld_close(void *handle) { - dlclose(handle); + dlclose(handle); } -wchar_t* plat_get_string(int i) +wchar_t * +plat_get_string(int i) { - switch (i) - { + switch (i) { case IDS_2077: return L"Click to capture mouse"; case IDS_2078: @@ -302,7 +299,7 @@ path_abs(char *path) } void -path_normalize(char* path) +path_normalize(char *path) { /* No-op. */ } @@ -310,8 +307,8 @@ path_normalize(char* path) void path_slash(char *path) { - if ((path[strlen(path)-1] != '/')) { - strcat(path, "/"); + if ((path[strlen(path) - 1] != '/')) { + strcat(path, "/"); } path_normalize(path); } @@ -322,22 +319,22 @@ plat_put_backslash(char *s) int c = strlen(s) - 1; if (s[c] != '/') - s[c] = '/'; + s[c] = '/'; } /* Return the last element of a pathname. */ char * plat_get_basename(const char *path) { - int c = (int)strlen(path); + int c = (int) strlen(path); while (c > 0) { - if (path[c] == '/') - return((char *)&path[c + 1]); - c--; + if (path[c] == '/') + return ((char *) &path[c + 1]); + c--; } - return((char *)path); + return ((char *) path); } char * path_get_filename(char *s) @@ -345,33 +342,31 @@ path_get_filename(char *s) int c = strlen(s) - 1; while (c > 0) { - if (s[c] == '/' || s[c] == '\\') - return(&s[c+1]); - c--; + if (s[c] == '/' || s[c] == '\\') + return (&s[c + 1]); + c--; } - return(s); + return (s); } - char * path_get_extension(char *s) { int c = strlen(s) - 1; if (c <= 0) - return(s); + return (s); while (c && s[c] != '.') - c--; + c--; if (!c) - return(&s[strlen(s)]); + return (&s[strlen(s)]); - return(&s[c+1]); + return (&s[c + 1]); } - void path_append_filename(char *dest, const char *s1, const char *s2) { @@ -384,8 +379,7 @@ int plat_dir_check(char *path) { struct stat dummy; - if (stat(path, &dummy) < 0) - { + if (stat(path, &dummy) < 0) { return 0; } return S_ISDIR(dummy.st_mode); @@ -403,7 +397,7 @@ plat_mmap(size_t size, uint8_t executable) #if defined __APPLE__ && defined MAP_JIT void *ret = mmap(0, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE | (executable ? MAP_JIT : 0), -1, 0); #else - void *ret = mmap(0, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE, -1, 0); + void *ret = mmap(0, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE, -1, 0); #endif return (ret < 0) ? NULL : ret; } @@ -425,11 +419,11 @@ plat_get_ticks_common(void) { uint64_t EndingTime, ElapsedMicroseconds; if (first_use) { - Frequency = SDL_GetPerformanceFrequency(); - StartingTime = SDL_GetPerformanceCounter(); - first_use = 0; + Frequency = SDL_GetPerformanceFrequency(); + StartingTime = SDL_GetPerformanceCounter(); + first_use = 0; } - EndingTime = SDL_GetPerformanceCounter(); + EndingTime = SDL_GetPerformanceCounter(); ElapsedMicroseconds = ((EndingTime - StartingTime) * 1000000) / Frequency; return ElapsedMicroseconds; } @@ -437,16 +431,17 @@ plat_get_ticks_common(void) uint32_t plat_get_ticks(void) { - return (uint32_t)(plat_get_ticks_common() / 1000); + return (uint32_t) (plat_get_ticks_common() / 1000); } uint32_t plat_get_micro_ticks(void) { - return (uint32_t)plat_get_ticks_common(); + return (uint32_t) plat_get_ticks_common(); } -void plat_remove(char* path) +void +plat_remove(char *path) { remove(path); } @@ -454,13 +449,11 @@ void plat_remove(char* path) void ui_sb_update_icon_state(int tag, int state) { - } void ui_sb_update_icon(int tag, int active) { - } void @@ -472,54 +465,53 @@ plat_delay_ms(uint32_t count) void ui_sb_update_tip(int arg) { - } void ui_sb_update_panes() { - } void ui_sb_update_text() { - } void path_get_dirname(char *dest, const char *path) { - int c = (int)strlen(path); + int c = (int) strlen(path); char *ptr; - ptr = (char *)path; + ptr = (char *) path; while (c > 0) { - if (path[c] == '/' || path[c] == '\\') { - ptr = (char *)&path[c]; - break; - } - c--; + if (path[c] == '/' || path[c] == '\\') { + ptr = (char *) &path[c]; + break; + } + c--; } /* Copy to destination. */ while (path < ptr) - *dest++ = *path++; + *dest++ = *path++; *dest = '\0'; } volatile int cpu_thread_run = 1; -void ui_sb_set_text_w(wchar_t *wstr) +void +ui_sb_set_text_w(wchar_t *wstr) { - } -int stricmp(const char* s1, const char* s2) +int +stricmp(const char *s1, const char *s2) { return strcasecmp(s1, s2); } -int strnicmp(const char *s1, const char *s2, size_t n) +int +strnicmp(const char *s1, const char *s2, size_t n) { return strncasecmp(s1, s2, n); } @@ -528,55 +520,55 @@ void main_thread(void *param) { uint32_t old_time, new_time; - int drawits, frames; + int drawits, frames; SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); framecountx = 0; - //title_update = 1; + // title_update = 1; old_time = SDL_GetTicks(); drawits = frames = 0; while (!is_quit && cpu_thread_run) { - /* See if it is time to run a frame of code. */ - new_time = SDL_GetTicks(); + /* See if it is time to run a frame of code. */ + new_time = SDL_GetTicks(); #ifdef USE_GDBSTUB - if (gdbstub_next_asap && (drawits <= 0)) - drawits = 10; - else + if (gdbstub_next_asap && (drawits <= 0)) + drawits = 10; + else #endif - drawits += (new_time - old_time); - old_time = new_time; - if (drawits > 0 && !dopause) { - /* Yes, so do one frame now. */ - drawits -= 10; - if (drawits > 50) - drawits = 0; + drawits += (new_time - old_time); + old_time = new_time; + if (drawits > 0 && !dopause) { + /* Yes, so do one frame now. */ + drawits -= 10; + if (drawits > 50) + drawits = 0; - /* Run a block of code. */ - pc_run(); + /* Run a block of code. */ + pc_run(); - /* Every 200 frames we save the machine status. */ - if (++frames >= 200 && nvr_dosave) { - nvr_save(); - nvr_dosave = 0; - frames = 0; - } - } else /* Just so we dont overload the host OS. */ - SDL_Delay(1); + /* Every 200 frames we save the machine status. */ + if (++frames >= 200 && nvr_dosave) { + nvr_save(); + nvr_dosave = 0; + frames = 0; + } + } else /* Just so we dont overload the host OS. */ + SDL_Delay(1); - /* If needed, handle a screen resize. */ - if (atomic_load(&doresize_monitors[0]) && !video_fullscreen && !is_quit) { - if (vid_resize & 2) - plat_resize(fixed_size_x, fixed_size_y); - else - plat_resize(scrnsz_x, scrnsz_y); - atomic_store(&doresize_monitors[0], 1); - } + /* If needed, handle a screen resize. */ + if (atomic_load(&doresize_monitors[0]) && !video_fullscreen && !is_quit) { + if (vid_resize & 2) + plat_resize(fixed_size_x, fixed_size_y); + else + plat_resize(scrnsz_x, scrnsz_y); + atomic_store(&doresize_monitors[0], 1); + } } is_quit = 1; } -thread_t* thMain = NULL; +thread_t *thMain = NULL; void do_start(void) @@ -595,21 +587,17 @@ do_start(void) void do_stop(void) { - if (SDL_ThreadID() != eventthread) - { + if (SDL_ThreadID() != eventthread) { exit_event = 1; return; } - if (blitreq) - { + if (blitreq) { blitreq = 0; video_blit_complete(); } - while(SDL_TryLockMutex(blitmtx) == SDL_MUTEX_TIMEDOUT) - { - if (blitreq) - { + while (SDL_TryLockMutex(blitmtx) == SDL_MUTEX_TIMEDOUT) { + if (blitreq) { blitreq = 0; video_blit_complete(); } @@ -624,44 +612,49 @@ do_stop(void) thMain = NULL; } -int ui_msgbox(int flags, void *message) +int +ui_msgbox(int flags, void *message) { return ui_msgbox_header(flags, NULL, message); } -int ui_msgbox_header(int flags, void *header, void* message) +int +ui_msgbox_header(int flags, void *header, void *message) { - SDL_MessageBoxData msgdata; + SDL_MessageBoxData msgdata; SDL_MessageBoxButtonData msgbtn; - if (!header) header = (flags & MBX_ANSI) ? "86Box" : L"86Box"; - if (header <= (void*)7168) header = plat_get_string(header); - if (message <= (void*)7168) message = plat_get_string(message); + if (!header) + header = (flags & MBX_ANSI) ? "86Box" : L"86Box"; + if (header <= (void *) 7168) + header = plat_get_string(header); + if (message <= (void *) 7168) + message = plat_get_string(message); msgbtn.buttonid = 1; - msgbtn.text = "OK"; - msgbtn.flags = 0; + msgbtn.text = "OK"; + msgbtn.flags = 0; memset(&msgdata, 0, sizeof(SDL_MessageBoxData)); msgdata.numbuttons = 1; - msgdata.buttons = &msgbtn; - int msgflags = 0; - if (msgflags & MBX_FATAL) msgflags |= SDL_MESSAGEBOX_ERROR; - else if (msgflags & MBX_ERROR || msgflags & MBX_WARNING) msgflags |= SDL_MESSAGEBOX_WARNING; - else msgflags |= SDL_MESSAGEBOX_INFORMATION; + msgdata.buttons = &msgbtn; + int msgflags = 0; + if (msgflags & MBX_FATAL) + msgflags |= SDL_MESSAGEBOX_ERROR; + else if (msgflags & MBX_ERROR || msgflags & MBX_WARNING) + msgflags |= SDL_MESSAGEBOX_WARNING; + else + msgflags |= SDL_MESSAGEBOX_INFORMATION; msgdata.flags = msgflags; - if (flags & MBX_ANSI) - { - int button = 0; - msgdata.title = header; + if (flags & MBX_ANSI) { + int button = 0; + msgdata.title = header; msgdata.message = message; SDL_ShowMessageBox(&msgdata, &button); return button; - } - else - { - int button = 0; - char *res = SDL_iconv_string("UTF-8", sizeof(wchar_t) == 2 ? "UTF-16LE" : "UTF-32LE", (char *)message, wcslen(message) * sizeof(wchar_t) + sizeof(wchar_t)); - char *res2 = SDL_iconv_string("UTF-8", sizeof(wchar_t) == 2 ? "UTF-16LE" : "UTF-32LE", (char *)header, wcslen(header) * sizeof(wchar_t) + sizeof(wchar_t)); + } else { + int button = 0; + char *res = SDL_iconv_string("UTF-8", sizeof(wchar_t) == 2 ? "UTF-16LE" : "UTF-32LE", (char *) message, wcslen(message) * sizeof(wchar_t) + sizeof(wchar_t)); + char *res2 = SDL_iconv_string("UTF-8", sizeof(wchar_t) == 2 ? "UTF-16LE" : "UTF-32LE", (char *) header, wcslen(header) * sizeof(wchar_t) + sizeof(wchar_t)); msgdata.message = res; - msgdata.title = res2; + msgdata.title = res2; SDL_ShowMessageBox(&msgdata, &button); free(res); free(res2); @@ -671,9 +664,10 @@ int ui_msgbox_header(int flags, void *header, void* message) return 0; } -void plat_get_exe_name(char *s, int size) +void +plat_get_exe_name(char *s, int size) { - char* basepath = SDL_GetBasePath(); + char *basepath = SDL_GetBasePath(); snprintf(s, size, "%s%s", basepath, basepath[strlen(basepath) - 1] == '/' ? "86box" : "/86box"); } @@ -691,65 +685,71 @@ plat_power_off(void) cpu_thread_run = 0; } -void ui_sb_bugui(char *str) +void +ui_sb_bugui(char *str) { - } -extern void sdl_blit(int x, int y, int w, int h); +extern void sdl_blit(int x, int y, int w, int h); -typedef struct mouseinputdata -{ +typedef struct mouseinputdata { int deltax, deltay, deltaz; int mousebuttons; } mouseinputdata; -SDL_mutex* mousemutex; +SDL_mutex *mousemutex; static mouseinputdata mousedata; -void mouse_poll() +void +mouse_poll() { SDL_LockMutex(mousemutex); - mouse_x = mousedata.deltax; - mouse_y = mousedata.deltay; - mouse_z = mousedata.deltaz; + mouse_x = mousedata.deltax; + mouse_y = mousedata.deltay; + mouse_z = mousedata.deltaz; mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0; - mouse_buttons = mousedata.mousebuttons; + mouse_buttons = mousedata.mousebuttons; SDL_UnlockMutex(mousemutex); } - int real_sdl_w, real_sdl_h; -void ui_sb_set_ready(int ready) {} -char* xargv[512]; +void +ui_sb_set_ready(int ready) +{ +} +char *xargv[512]; // From musl. -char *local_strsep(char **str, const char *sep) +char * +local_strsep(char **str, const char *sep) { - char *s = *str, *end; - if (!s) return NULL; - end = s + strcspn(s, sep); - if (*end) *end++ = 0; - else end = 0; - *str = end; - return s; + char *s = *str, *end; + if (!s) + return NULL; + end = s + strcspn(s, sep); + if (*end) + *end++ = 0; + else + end = 0; + *str = end; + return s; } void plat_pause(int p) { static wchar_t oldtitle[512]; - wchar_t title[512]; + wchar_t title[512]; if ((p == 0) && (time_sync & TIME_SYNC_ENABLED)) - nvr_time_sync(); + nvr_time_sync(); dopause = p; if (p) { - wcsncpy(oldtitle, ui_window_title(NULL), sizeof_w(oldtitle) - 1); - wcscpy(title, oldtitle); - wcscat(title, L" - PAUSED"); - ui_window_title(title); + wcsncpy(oldtitle, ui_window_title(NULL), sizeof_w(oldtitle) - 1); + wcscpy(title, oldtitle); + wcscat(title, L" - PAUSED"); + ui_window_title(title); } else { - ui_window_title(oldtitle); + ui_window_title(oldtitle); } } @@ -783,9 +783,9 @@ plat_init_rom_paths() rom_add_path(home_rom_path); } if (getenv("XDG_DATA_DIRS")) { - char* xdg_rom_paths = strdup(getenv("XDG_DATA_DIRS")); - char* xdg_rom_paths_orig = xdg_rom_paths; - char* cur_xdg_rom_path = NULL; + char *xdg_rom_paths = strdup(getenv("XDG_DATA_DIRS")); + char *xdg_rom_paths_orig = xdg_rom_paths; + char *cur_xdg_rom_path = NULL; if (xdg_rom_paths) { while (xdg_rom_paths[strlen(xdg_rom_paths) - 1] == ':') { xdg_rom_paths[strlen(xdg_rom_paths) - 1] = '\0'; @@ -804,111 +804,101 @@ plat_init_rom_paths() rom_add_path("/usr/share/86Box/roms/"); } #else - char default_rom_path[1024] = { '\0 '}; + char default_rom_path[1024] = { '\0 ' }; getDefaultROMPath(default_rom_path); rom_add_path(default_rom_path); #endif } -bool process_media_commands_3(uint8_t* id, char* fn, uint8_t* wp, int cmdargc) +bool +process_media_commands_3(uint8_t *id, char *fn, uint8_t *wp, int cmdargc) { bool err = false; - *id = atoi(xargv[1]); - if (xargv[2][0] == '\'' || xargv[2][0] == '"') - { + *id = atoi(xargv[1]); + if (xargv[2][0] == '\'' || xargv[2][0] == '"') { int curarg = 2; - for (curarg = 2; curarg < cmdargc; curarg++) - { - if (strlen(fn) + strlen(xargv[curarg]) >= PATH_MAX) - { + for (curarg = 2; curarg < cmdargc; curarg++) { + if (strlen(fn) + strlen(xargv[curarg]) >= PATH_MAX) { err = true; fprintf(stderr, "Path name too long.\n"); } strcat(fn, xargv[curarg] + (xargv[curarg][0] == '\'' || xargv[curarg][0] == '"')); if (fn[strlen(fn) - 1] == '\'' - || fn[strlen(fn) - 1] == '"') - { - if (curarg + 1 < cmdargc) - { + || fn[strlen(fn) - 1] == '"') { + if (curarg + 1 < cmdargc) { *wp = atoi(xargv[curarg + 1]); } break; } strcat(fn, " "); } - } - else - { - if (strlen(xargv[2]) < PATH_MAX) - { + } else { + if (strlen(xargv[2]) < PATH_MAX) { strcpy(fn, xargv[2]); *wp = atoi(xargv[3]); - } - else - { + } else { fprintf(stderr, "Path name too long.\n"); err = true; } } if (fn[strlen(fn) - 1] == '\'' - || fn[strlen(fn) - 1] == '"') fn[strlen(fn) - 1] = '\0'; + || fn[strlen(fn) - 1] == '"') + fn[strlen(fn) - 1] = '\0'; return err; } -char* (*f_readline)(const char*) = NULL; -int (*f_add_history)(const char *) = NULL; +char *(*f_readline)(const char *) = NULL; +int (*f_add_history)(const char *) = NULL; void (*f_rl_callback_handler_remove)(void) = NULL; #ifdef __APPLE__ -#define LIBEDIT_LIBRARY "libedit.dylib" +# define LIBEDIT_LIBRARY "libedit.dylib" #else -#define LIBEDIT_LIBRARY "libedit.so" +# define LIBEDIT_LIBRARY "libedit.so" #endif -uint32_t timer_onesec(uint32_t interval, void* param) +uint32_t +timer_onesec(uint32_t interval, void *param) { - pc_onesec(); - return interval; + pc_onesec(); + return interval; } -void monitor_thread(void* param) +void +monitor_thread(void *param) { #ifndef USE_CLI - if (isatty(fileno(stdin)) && isatty(fileno(stdout))) - { - char* line = NULL; + if (isatty(fileno(stdin)) && isatty(fileno(stdout))) { + char *line = NULL; size_t n; printf("86Box monitor console.\n"); - while (!exit_event) - { - if (feof(stdin)) break; + while (!exit_event) { + if (feof(stdin)) + break; if (f_readline) line = f_readline("(86Box) "); - else - { + else { printf("(86Box) "); getline(&line, &n, stdin); } - if (line) - { - int cmdargc = 0; - char* linecpy; + if (line) { + int cmdargc = 0; + char *linecpy; line[strcspn(line, "\r\n")] = '\0'; - linecpy = strdup(line); - if (!linecpy) - { + linecpy = strdup(line); + if (!linecpy) { free(line); line = NULL; continue; } - if (f_add_history) f_add_history(line); + if (f_add_history) + f_add_history(line); memset(xargv, 0, sizeof(xargv)); - while(1) - { + while (1) { xargv[cmdargc++] = local_strsep(&linecpy, " "); - if (xargv[cmdargc - 1] == NULL || cmdargc >= 512) break; + if (xargv[cmdargc - 1] == NULL || cmdargc >= 512) + break; } cmdargc--; - if (strncasecmp(xargv[0], "help", 4) == 0) - { + if (strncasecmp(xargv[0], "help", 4) == 0) { printf( "fddload - Load floppy disk image into drive .\n" "cdload - Load CD-ROM image into drive .\n" @@ -924,33 +914,22 @@ void monitor_thread(void* param) "pause - pause the the emulated system.\n" "fullscreen - toggle fullscreen.\n" "exit - exit 86Box.\n"); - } - else if (strncasecmp(xargv[0], "exit", 4) == 0) - { + } else if (strncasecmp(xargv[0], "exit", 4) == 0) { exit_event = 1; - } - else if (strncasecmp(xargv[0], "fullscreen", 10) == 0) - { - video_fullscreen = video_fullscreen ? 0 : 1; + } else if (strncasecmp(xargv[0], "fullscreen", 10) == 0) { + video_fullscreen = video_fullscreen ? 0 : 1; fullscreen_pending = 1; - } - else if (strncasecmp(xargv[0], "pause", 5) == 0) - { + } else if (strncasecmp(xargv[0], "pause", 5) == 0) { plat_pause(dopause ^ 1); printf("%s", dopause ? "Paused.\n" : "Unpaused.\n"); - } - else if (strncasecmp(xargv[0], "hardreset", 9) == 0) - { + } else if (strncasecmp(xargv[0], "hardreset", 9) == 0) { pc_reset_hard(); - } - else if (strncasecmp(xargv[0], "cdload", 6) == 0 && cmdargc >= 3) - { + } else if (strncasecmp(xargv[0], "cdload", 6) == 0 && cmdargc >= 3) { uint8_t id; - bool err = false; - char fn[PATH_MAX]; + bool err = false; + char fn[PATH_MAX]; - if (!xargv[2] || !xargv[1]) - { + if (!xargv[2] || !xargv[1]) { free(line); free(linecpy); line = NULL; @@ -958,149 +937,118 @@ void monitor_thread(void* param) } id = atoi(xargv[1]); memset(fn, 0, sizeof(fn)); - if (xargv[2][0] == '\'' || xargv[2][0] == '"') - { + if (xargv[2][0] == '\'' || xargv[2][0] == '"') { int curarg = 2; - for (curarg = 2; curarg < cmdargc; curarg++) - { - if (strlen(fn) + strlen(xargv[curarg]) >= PATH_MAX) - { + for (curarg = 2; curarg < cmdargc; curarg++) { + if (strlen(fn) + strlen(xargv[curarg]) >= PATH_MAX) { err = true; fprintf(stderr, "Path name too long.\n"); } strcat(fn, xargv[curarg] + (xargv[curarg][0] == '\'' || xargv[curarg][0] == '"')); if (fn[strlen(fn) - 1] == '\'' - || fn[strlen(fn) - 1] == '"') - { + || fn[strlen(fn) - 1] == '"') { break; } strcat(fn, " "); } - } - else - { - if (strlen(xargv[2]) < PATH_MAX) - { + } else { + if (strlen(xargv[2]) < PATH_MAX) { strcpy(fn, xargv[2]); - } - else - { + } else { fprintf(stderr, "Path name too long.\n"); } } - if (!err) - { + if (!err) { if (fn[strlen(fn) - 1] == '\'' - || fn[strlen(fn) - 1] == '"') fn[strlen(fn) - 1] = '\0'; + || fn[strlen(fn) - 1] == '"') + fn[strlen(fn) - 1] = '\0'; printf("Inserting disc into CD-ROM drive %hhu: %s\n", id, fn); cdrom_mount(id, fn); } - } - else if (strncasecmp(xargv[0], "fddeject", 8) == 0 && cmdargc >= 2) - { + } else if (strncasecmp(xargv[0], "fddeject", 8) == 0 && cmdargc >= 2) { floppy_eject(atoi(xargv[1])); - } - else if (strncasecmp(xargv[0], "cdeject", 8) == 0 && cmdargc >= 2) - { + } else if (strncasecmp(xargv[0], "cdeject", 8) == 0 && cmdargc >= 2) { cdrom_mount(atoi(xargv[1]), ""); - } - else if (strncasecmp(xargv[0], "moeject", 8) == 0 && cmdargc >= 2) - { + } else if (strncasecmp(xargv[0], "moeject", 8) == 0 && cmdargc >= 2) { mo_eject(atoi(xargv[1])); - } - else if (strncasecmp(xargv[0], "carteject", 8) == 0 && cmdargc >= 2) - { + } else if (strncasecmp(xargv[0], "carteject", 8) == 0 && cmdargc >= 2) { cartridge_eject(atoi(xargv[1])); - } - else if (strncasecmp(xargv[0], "zipeject", 8) == 0 && cmdargc >= 2) - { + } else if (strncasecmp(xargv[0], "zipeject", 8) == 0 && cmdargc >= 2) { zip_eject(atoi(xargv[1])); - } - else if (strncasecmp(xargv[0], "fddload", 7) == 0 && cmdargc >= 4) - { + } else if (strncasecmp(xargv[0], "fddload", 7) == 0 && cmdargc >= 4) { uint8_t id, wp; - bool err = false; - char fn[PATH_MAX]; + bool err = false; + char fn[PATH_MAX]; memset(fn, 0, sizeof(fn)); - if (!xargv[2] || !xargv[1]) - { + if (!xargv[2] || !xargv[1]) { free(line); free(linecpy); line = NULL; continue; } err = process_media_commands_3(&id, fn, &wp, cmdargc); - if (!err) - { + if (!err) { if (fn[strlen(fn) - 1] == '\'' - || fn[strlen(fn) - 1] == '"') fn[strlen(fn) - 1] = '\0'; + || fn[strlen(fn) - 1] == '"') + fn[strlen(fn) - 1] = '\0'; printf("Inserting disk into floppy drive %c: %s\n", id + 'A', fn); floppy_mount(id, fn, wp); } - } - else if (strncasecmp(xargv[0], "moload", 7) == 0 && cmdargc >= 4) - { + } else if (strncasecmp(xargv[0], "moload", 7) == 0 && cmdargc >= 4) { uint8_t id, wp; - bool err = false; - char fn[PATH_MAX]; + bool err = false; + char fn[PATH_MAX]; memset(fn, 0, sizeof(fn)); - if (!xargv[2] || !xargv[1]) - { + if (!xargv[2] || !xargv[1]) { free(line); free(linecpy); line = NULL; continue; } err = process_media_commands_3(&id, fn, &wp, cmdargc); - if (!err) - { + if (!err) { if (fn[strlen(fn) - 1] == '\'' - || fn[strlen(fn) - 1] == '"') fn[strlen(fn) - 1] = '\0'; + || fn[strlen(fn) - 1] == '"') + fn[strlen(fn) - 1] = '\0'; printf("Inserting into mo drive %hhu: %s\n", id, fn); mo_mount(id, fn, wp); } - } - else if (strncasecmp(xargv[0], "cartload", 7) == 0 && cmdargc >= 4) - { + } else if (strncasecmp(xargv[0], "cartload", 7) == 0 && cmdargc >= 4) { uint8_t id, wp; - bool err = false; - char fn[PATH_MAX]; + bool err = false; + char fn[PATH_MAX]; memset(fn, 0, sizeof(fn)); - if (!xargv[2] || !xargv[1]) - { + if (!xargv[2] || !xargv[1]) { free(line); free(linecpy); line = NULL; continue; } err = process_media_commands_3(&id, fn, &wp, cmdargc); - if (!err) - { + if (!err) { if (fn[strlen(fn) - 1] == '\'' - || fn[strlen(fn) - 1] == '"') fn[strlen(fn) - 1] = '\0'; + || fn[strlen(fn) - 1] == '"') + fn[strlen(fn) - 1] = '\0'; printf("Inserting tape into cartridge holder %hhu: %s\n", id, fn); cartridge_mount(id, fn, wp); } - } - else if (strncasecmp(xargv[0], "zipload", 7) == 0 && cmdargc >= 4) - { + } else if (strncasecmp(xargv[0], "zipload", 7) == 0 && cmdargc >= 4) { uint8_t id, wp; - bool err = false; - char fn[PATH_MAX]; + bool err = false; + char fn[PATH_MAX]; memset(fn, 0, sizeof(fn)); - if (!xargv[2] || !xargv[1]) - { + if (!xargv[2] || !xargv[1]) { free(line); free(linecpy); line = NULL; continue; } err = process_media_commands_3(&id, fn, &wp, cmdargc); - if (!err) - { + if (!err) { if (fn[strlen(fn) - 1] == '\'' - || fn[strlen(fn) - 1] == '"') fn[strlen(fn) - 1] = '\0'; + || fn[strlen(fn) - 1] == '"') + fn[strlen(fn) - 1] = '\0'; printf("Inserting disk into ZIP drive %c: %s\n", id + 'A', fn); zip_mount(id, fn, wp); } @@ -1115,52 +1063,49 @@ void monitor_thread(void* param) } extern int gfxcard_2; -int main(int argc, char** argv) +int +main(int argc, char **argv) { SDL_Event event; - void* libedithandle; + void *libedithandle; SDL_Init(0); pc_init(argc, argv); - if (! pc_init_modules()) { + if (!pc_init_modules()) { ui_msgbox_header(MBX_FATAL, L"No ROMs found.", L"86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory."); SDL_Quit(); return 6; } - gfxcard_2 = 0; + gfxcard_2 = 0; eventthread = SDL_ThreadID(); - blitmtx = SDL_CreateMutex(); - if (!blitmtx) - { + blitmtx = SDL_CreateMutex(); + if (!blitmtx) { fprintf(stderr, "Failed to create blit mutex: %s", SDL_GetError()); return -1; } libedithandle = dlopen(LIBEDIT_LIBRARY, RTLD_LOCAL | RTLD_LAZY); - if (libedithandle) - { - f_readline = dlsym(libedithandle, "readline"); + if (libedithandle) { + f_readline = dlsym(libedithandle, "readline"); f_add_history = dlsym(libedithandle, "add_history"); - if (!f_readline) - { + if (!f_readline) { fprintf(stderr, "readline in libedit not found, line editing will be limited.\n"); } f_rl_callback_handler_remove = dlsym(libedithandle, "rl_callback_handler_remove"); - } - else fprintf(stderr, "libedit not found, line editing will be limited.\n"); + } else + fprintf(stderr, "libedit not found, line editing will be limited.\n"); mousemutex = SDL_CreateMutex(); sdl_initho(); - if (start_in_fullscreen) - { + if (start_in_fullscreen) { video_fullscreen = 1; - sdl_set_fs(1); + sdl_set_fs(1); } /* Fire up the machine. */ pc_reset_hard_init(); /* Set the PAUSE mode depending on the renderer. */ - //plat_pause(0); + // plat_pause(0); /* Initialize the rendering window, or fullscreen. */ @@ -1169,84 +1114,73 @@ int main(int argc, char** argv) thread_create(monitor_thread, NULL); #endif SDL_AddTimer(1000, timer_onesec, NULL); - while (!is_quit) - { + while (!is_quit) { static int mouse_inside = 0; - while (SDL_PollEvent(&event)) - { - switch(event.type) - { + while (SDL_PollEvent(&event)) { + switch (event.type) { case SDL_QUIT: exit_event = 1; break; case SDL_MOUSEWHEEL: - { - if (mouse_capture || video_fullscreen) { - if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) - { - event.wheel.x *= -1; - event.wheel.y *= -1; + if (mouse_capture || video_fullscreen) { + if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) { + event.wheel.x *= -1; + event.wheel.y *= -1; + } + SDL_LockMutex(mousemutex); + mousedata.deltaz = event.wheel.y; + SDL_UnlockMutex(mousemutex); } - SDL_LockMutex(mousemutex); - mousedata.deltaz = event.wheel.y; - SDL_UnlockMutex(mousemutex); + break; } - break; - } case SDL_MOUSEMOTION: - { - if (mouse_capture || video_fullscreen) { - SDL_LockMutex(mousemutex); - mousedata.deltax += event.motion.xrel; - mousedata.deltay += event.motion.yrel; - SDL_UnlockMutex(mousemutex); + if (mouse_capture || video_fullscreen) { + SDL_LockMutex(mousemutex); + mousedata.deltax += event.motion.xrel; + mousedata.deltay += event.motion.yrel; + SDL_UnlockMutex(mousemutex); + } + break; } - break; - } case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: - { - if ((event.button.button == SDL_BUTTON_LEFT) - && !(mouse_capture || video_fullscreen) - && event.button.state == SDL_RELEASED - && mouse_inside) { - plat_mouse_capture(1); - break; - } - if (mouse_get_buttons() < 3 && event.button.button == SDL_BUTTON_MIDDLE && !video_fullscreen) - { - plat_mouse_capture(0); - break; - } - if (mouse_capture || video_fullscreen) - { - int buttonmask = 0; + if ((event.button.button == SDL_BUTTON_LEFT) + && !(mouse_capture || video_fullscreen) + && event.button.state == SDL_RELEASED + && mouse_inside) { + plat_mouse_capture(1); + break; + } + if (mouse_get_buttons() < 3 && event.button.button == SDL_BUTTON_MIDDLE && !video_fullscreen) { + plat_mouse_capture(0); + break; + } + if (mouse_capture || video_fullscreen) { + int buttonmask = 0; - switch(event.button.button) - { - case SDL_BUTTON_LEFT: - buttonmask = 1; - break; - case SDL_BUTTON_RIGHT: - buttonmask = 2; - break; - case SDL_BUTTON_MIDDLE: - buttonmask = 4; - break; + switch (event.button.button) { + case SDL_BUTTON_LEFT: + buttonmask = 1; + break; + case SDL_BUTTON_RIGHT: + buttonmask = 2; + break; + case SDL_BUTTON_MIDDLE: + buttonmask = 4; + break; + } + SDL_LockMutex(mousemutex); + if (event.button.state == SDL_PRESSED) { + mousedata.mousebuttons |= buttonmask; + } else + mousedata.mousebuttons &= ~buttonmask; + SDL_UnlockMutex(mousemutex); } - SDL_LockMutex(mousemutex); - if (event.button.state == SDL_PRESSED) - { - mousedata.mousebuttons |= buttonmask; - } - else mousedata.mousebuttons &= ~buttonmask; - SDL_UnlockMutex(mousemutex); + break; } - break; - } case SDL_RENDER_DEVICE_RESET: case SDL_RENDER_TARGETS_RESET: { @@ -1256,56 +1190,48 @@ int main(int argc, char** argv) } case SDL_KEYDOWN: case SDL_KEYUP: - { - uint16_t xtkey = 0; - switch(event.key.keysym.scancode) { - default: - xtkey = sdl_to_xt[event.key.keysym.scancode]; - break; + uint16_t xtkey = 0; + switch (event.key.keysym.scancode) { + default: + xtkey = sdl_to_xt[event.key.keysym.scancode]; + break; + } + keyboard_input(event.key.state == SDL_PRESSED, xtkey); } - keyboard_input(event.key.state == SDL_PRESSED, xtkey); - } case SDL_WINDOWEVENT: - { - switch (event.window.event) { - case SDL_WINDOWEVENT_ENTER: - mouse_inside = 1; - break; - case SDL_WINDOWEVENT_LEAVE: - mouse_inside = 0; - break; + switch (event.window.event) { + case SDL_WINDOWEVENT_ENTER: + mouse_inside = 1; + break; + case SDL_WINDOWEVENT_LEAVE: + mouse_inside = 0; + break; + } } - } } - } - if (mouse_capture && keyboard_ismsexit()) - { + } + if (mouse_capture && keyboard_ismsexit()) { plat_mouse_capture(0); } - if (blitreq) - { + if (blitreq) { extern void sdl_blit(int x, int y, int w, int h); sdl_blit(params.x, params.y, params.w, params.h); } - if (title_set) - { + if (title_set) { extern void ui_window_title_real(); ui_window_title_real(); } - if (video_fullscreen && keyboard_isfsexit()) - { + if (video_fullscreen && keyboard_isfsexit()) { sdl_set_fs(0); video_fullscreen = 0; } - if (fullscreen_pending) - { + if (fullscreen_pending) { sdl_set_fs(video_fullscreen); fullscreen_pending = 0; } - if (exit_event) - { + if (exit_event) { do_stop(); break; } @@ -1314,10 +1240,12 @@ int main(int argc, char** argv) SDL_DestroyMutex(blitmtx); SDL_DestroyMutex(mousemutex); SDL_Quit(); - if (f_rl_callback_handler_remove) f_rl_callback_handler_remove(); + if (f_rl_callback_handler_remove) + f_rl_callback_handler_remove(); return 0; } -char* plat_vidapi_name(int i) +char * +plat_vidapi_name(int i) { return "default"; } @@ -1328,9 +1256,9 @@ set_language(uint32_t id) lang_id = id; } - /* Sets up the program language before initialization. */ -uint32_t plat_language_code(char* langcode) +uint32_t +plat_language_code(char *langcode) { /* or maybe not */ return 0; @@ -1338,27 +1266,38 @@ uint32_t plat_language_code(char* langcode) /* Converts back the language code to LCID */ void -plat_language_code_r(uint32_t lcid, char* outbuf, int len) +plat_language_code_r(uint32_t lcid, char *outbuf, int len) { /* or maybe not */ return; } -void joystick_init(void) {} -void joystick_close(void) {} -void joystick_process(void) {} -void startblit() +void +joystick_init(void) +{ +} +void +joystick_close(void) +{ +} +void +joystick_process(void) +{ +} +void +startblit() { SDL_LockMutex(blitmtx); } -void endblit() +void +endblit() { SDL_UnlockMutex(blitmtx); } /* API */ void -ui_sb_mt32lcd(char* str) +ui_sb_mt32lcd(char *str) { } diff --git a/src/unix/unix_cdrom.c b/src/unix/unix_cdrom.c index 9eb3d962a..0419c6018 100644 --- a/src/unix/unix_cdrom.c +++ b/src/unix/unix_cdrom.c @@ -39,8 +39,6 @@ #include <86box/plat.h> #include <86box/ui.h> - - void cassette_mount(char *fn, uint8_t wp) { @@ -49,49 +47,45 @@ cassette_mount(char *fn, uint8_t wp) cassette_ui_writeprot = wp; pc_cas_set_fname(cassette, fn); if (fn != NULL) - memcpy(cassette_fname, fn, MIN(511, strlen(fn))); + memcpy(cassette_fname, fn, MIN(511, strlen(fn))); ui_sb_update_icon_state(SB_CASSETTE, (fn == NULL) ? 1 : 0); - //media_menu_update_cassette(); + // media_menu_update_cassette(); ui_sb_update_tip(SB_CASSETTE); config_save(); } - void cassette_eject(void) { pc_cas_set_fname(cassette, NULL); memset(cassette_fname, 0x00, sizeof(cassette_fname)); ui_sb_update_icon_state(SB_CASSETTE, 1); - //media_menu_update_cassette(); + // media_menu_update_cassette(); ui_sb_update_tip(SB_CASSETTE); config_save(); } - void cartridge_mount(uint8_t id, char *fn, uint8_t wp) { cart_close(id); cart_load(id, fn); ui_sb_update_icon_state(SB_CARTRIDGE | id, strlen(cart_fns[id]) ? 0 : 1); - //media_menu_update_cartridge(id); + // media_menu_update_cartridge(id); ui_sb_update_tip(SB_CARTRIDGE | id); config_save(); } - void cartridge_eject(uint8_t id) { cart_close(id); ui_sb_update_icon_state(SB_CARTRIDGE | id, 1); - //media_menu_update_cartridge(id); + // media_menu_update_cartridge(id); ui_sb_update_tip(SB_CARTRIDGE | id); config_save(); } - void floppy_mount(uint8_t id, char *fn, uint8_t wp) { @@ -99,36 +93,34 @@ floppy_mount(uint8_t id, char *fn, uint8_t wp) ui_writeprot[id] = wp; fdd_load(id, fn); ui_sb_update_icon_state(SB_FLOPPY | id, strlen(floppyfns[id]) ? 0 : 1); - //media_menu_update_floppy(id); + // media_menu_update_floppy(id); ui_sb_update_tip(SB_FLOPPY | id); config_save(); } - void floppy_eject(uint8_t id) { fdd_close(id); ui_sb_update_icon_state(SB_FLOPPY | id, 1); - //media_menu_update_floppy(id); + // media_menu_update_floppy(id); ui_sb_update_tip(SB_FLOPPY | id); config_save(); } - void plat_cdrom_ui_update(uint8_t id, uint8_t reload) { cdrom_t *drv = &cdrom[id]; if (drv->host_drive == 0) { - ui_sb_update_icon_state(SB_CDROM|id, 1); + ui_sb_update_icon_state(SB_CDROM | id, 1); } else { - ui_sb_update_icon_state(SB_CDROM|id, 0); + ui_sb_update_icon_state(SB_CDROM | id, 0); } - //media_menu_update_cdrom(id); - ui_sb_update_tip(SB_CDROM|id); + // media_menu_update_cdrom(id); + ui_sb_update_tip(SB_CDROM | id); } void @@ -137,20 +129,20 @@ cdrom_mount(uint8_t id, char *fn) cdrom[id].prev_host_drive = cdrom[id].host_drive; strcpy(cdrom[id].prev_image_path, cdrom[id].image_path); if (cdrom[id].ops && cdrom[id].ops->exit) - cdrom[id].ops->exit(&(cdrom[id])); + cdrom[id].ops->exit(&(cdrom[id])); cdrom[id].ops = NULL; memset(cdrom[id].image_path, 0, sizeof(cdrom[id].image_path)); cdrom_image_open(&(cdrom[id]), fn); /* Signal media change to the emulated machine. */ if (cdrom[id].insert) - cdrom[id].insert(cdrom[id].priv); + cdrom[id].insert(cdrom[id].priv); cdrom[id].host_drive = (strlen(cdrom[id].image_path) == 0) ? 0 : 200; if (cdrom[id].host_drive == 200) { - ui_sb_update_icon_state(SB_CDROM | id, 0); + ui_sb_update_icon_state(SB_CDROM | id, 0); } else { - ui_sb_update_icon_state(SB_CDROM | id, 1); + ui_sb_update_icon_state(SB_CDROM | id, 1); } - //media_menu_update_cdrom(id); + // media_menu_update_cdrom(id); ui_sb_update_tip(SB_CDROM | id); config_save(); } @@ -162,17 +154,16 @@ mo_eject(uint8_t id) mo_disk_close(dev); if (mo_drives[id].bus_type) { - /* Signal disk change to the emulated machine. */ - mo_insert(dev); + /* Signal disk change to the emulated machine. */ + mo_insert(dev); } ui_sb_update_icon_state(SB_MO | id, 1); - //media_menu_update_mo(id); + // media_menu_update_mo(id); ui_sb_update_tip(SB_MO | id); config_save(); } - void mo_mount(uint8_t id, char *fn, uint8_t wp) { @@ -184,13 +175,12 @@ mo_mount(uint8_t id, char *fn, uint8_t wp) mo_insert(dev); ui_sb_update_icon_state(SB_MO | id, strlen(mo_drives[id].image_path) ? 0 : 1); - //media_menu_update_mo(id); + // media_menu_update_mo(id); ui_sb_update_tip(SB_MO | id); config_save(); } - void mo_reload(uint8_t id) { @@ -198,13 +188,13 @@ mo_reload(uint8_t id) mo_disk_reload(dev); if (strlen(mo_drives[id].image_path) == 0) { - ui_sb_update_icon_state(SB_MO|id, 1); + ui_sb_update_icon_state(SB_MO | id, 1); } else { - ui_sb_update_icon_state(SB_MO|id, 0); + ui_sb_update_icon_state(SB_MO | id, 0); } - //media_menu_update_mo(id); - ui_sb_update_tip(SB_MO|id); + // media_menu_update_mo(id); + ui_sb_update_tip(SB_MO | id); config_save(); } @@ -216,17 +206,16 @@ zip_eject(uint8_t id) zip_disk_close(dev); if (zip_drives[id].bus_type) { - /* Signal disk change to the emulated machine. */ - zip_insert(dev); + /* Signal disk change to the emulated machine. */ + zip_insert(dev); } ui_sb_update_icon_state(SB_ZIP | id, 1); - //media_menu_update_zip(id); + // media_menu_update_zip(id); ui_sb_update_tip(SB_ZIP | id); config_save(); } - void zip_mount(uint8_t id, char *fn, uint8_t wp) { @@ -238,13 +227,12 @@ zip_mount(uint8_t id, char *fn, uint8_t wp) zip_insert(dev); ui_sb_update_icon_state(SB_ZIP | id, strlen(zip_drives[id].image_path) ? 0 : 1); - //media_menu_update_zip(id); + // media_menu_update_zip(id); ui_sb_update_tip(SB_ZIP | id); config_save(); } - void zip_reload(uint8_t id) { @@ -252,13 +240,13 @@ zip_reload(uint8_t id) zip_disk_reload(dev); if (strlen(zip_drives[id].image_path) == 0) { - ui_sb_update_icon_state(SB_ZIP|id, 1); + ui_sb_update_icon_state(SB_ZIP | id, 1); } else { - ui_sb_update_icon_state(SB_ZIP|id, 0); + ui_sb_update_icon_state(SB_ZIP | id, 0); } - //media_menu_update_zip(id); - ui_sb_update_tip(SB_ZIP|id); + // media_menu_update_zip(id); + ui_sb_update_tip(SB_ZIP | id); config_save(); } diff --git a/src/unix/unix_sdl.c b/src/unix/unix_sdl.c index b023299d2..bd2f3937b 100644 --- a/src/unix/unix_sdl.c +++ b/src/unix/unix_sdl.c @@ -18,34 +18,33 @@ #include <86box/version.h> #include <86box/unix_sdl.h> -#define RENDERER_FULL_SCREEN 1 -#define RENDERER_HARDWARE 2 -#define RENDERER_OPENGL 4 +#define RENDERER_FULL_SCREEN 1 +#define RENDERER_HARDWARE 2 +#define RENDERER_OPENGL 4 -typedef struct sdl_blit_params -{ +typedef struct sdl_blit_params { int x, y, w, h; } sdl_blit_params; extern sdl_blit_params params; -extern int blitreq; +extern int blitreq; -SDL_Window *sdl_win = NULL; -SDL_Renderer *sdl_render = NULL; -static SDL_Texture *sdl_tex = NULL; -int sdl_w = SCREEN_RES_X, sdl_h = SCREEN_RES_Y; -static int sdl_fs, sdl_flags = -1; -static int cur_w, cur_h; -static int cur_wx = 0, cur_wy = 0, cur_ww =0, cur_wh = 0; -static volatile int sdl_enabled = 1; -static SDL_mutex* sdl_mutex = NULL; -int mouse_capture; -int title_set = 0; -int resize_pending = 0; -int resize_w = 0; -int resize_h = 0; -double mouse_sensitivity = 1.0; /* Unused. */ -double mouse_x_error = 0.0, mouse_y_error = 0.0; /* Unused. */ -static uint8_t interpixels[17842176]; +SDL_Window *sdl_win = NULL; +SDL_Renderer *sdl_render = NULL; +static SDL_Texture *sdl_tex = NULL; +int sdl_w = SCREEN_RES_X, sdl_h = SCREEN_RES_Y; +static int sdl_fs, sdl_flags = -1; +static int cur_w, cur_h; +static int cur_wx = 0, cur_wy = 0, cur_ww = 0, cur_wh = 0; +static volatile int sdl_enabled = 1; +static SDL_mutex *sdl_mutex = NULL; +int mouse_capture; +int title_set = 0; +int resize_pending = 0; +int resize_w = 0; +int resize_h = 0; +double mouse_sensitivity = 1.0; /* Unused. */ +double mouse_x_error = 0.0, mouse_y_error = 0.0; /* Unused. */ +static uint8_t interpixels[17842176]; extern void RenderImGui(); static void @@ -54,11 +53,11 @@ sdl_integer_scale(double *d, double *g) double ratio; if (*d > *g) { - ratio = floor(*d / *g); - *d = *g * ratio; + ratio = floor(*d / *g); + *d = *g * ratio; } else { - ratio = ceil(*d / *g); - *d = *g / ratio; + ratio = ceil(*d / *g); + *d = *g / ratio; } } @@ -68,66 +67,65 @@ static void sdl_stretch(int *w, int *h, int *x, int *y) { double hw, gw, hh, gh, dx, dy, dw, dh, gsr, hsr; - int real_sdl_w, real_sdl_h; + int real_sdl_w, real_sdl_h; SDL_GL_GetDrawableSize(sdl_win, &real_sdl_w, &real_sdl_h); - hw = (double) real_sdl_w; - hh = (double) real_sdl_h; - gw = (double) *w; - gh = (double) *h; + hw = (double) real_sdl_w; + hh = (double) real_sdl_h; + gw = (double) *w; + gh = (double) *h; hsr = hw / hh; switch (video_fullscreen_scale) { - case FULLSCR_SCALE_FULL: - default: - *w = real_sdl_w; - *h = real_sdl_h; - *x = 0; - *y = 0; - break; - case FULLSCR_SCALE_43: - case FULLSCR_SCALE_KEEPRATIO: - if (video_fullscreen_scale == FULLSCR_SCALE_43) - gsr = 4.0 / 3.0; - else - gsr = gw / gh; - if (gsr <= hsr) { - dw = hh * gsr; - dh = hh; - } else { - dw = hw; - dh = hw / gsr; - } - dx = (hw - dw) / 2.0; - dy = (hh - dh) / 2.0; - *w = (int) dw; - *h = (int) dh; - *x = (int) dx; - *y = (int) dy; - break; - case FULLSCR_SCALE_INT: - gsr = gw / gh; - if (gsr <= hsr) { - dw = hh * gsr; - dh = hh; - } else { - dw = hw; - dh = hw / gsr; - } - sdl_integer_scale(&dw, &gw); - sdl_integer_scale(&dh, &gh); - dx = (hw - dw) / 2.0; - dy = (hh - dh) / 2.0; - *w = (int) dw; - *h = (int) dh; - *x = (int) dx; - *y = (int) dy; - break; + case FULLSCR_SCALE_FULL: + default: + *w = real_sdl_w; + *h = real_sdl_h; + *x = 0; + *y = 0; + break; + case FULLSCR_SCALE_43: + case FULLSCR_SCALE_KEEPRATIO: + if (video_fullscreen_scale == FULLSCR_SCALE_43) + gsr = 4.0 / 3.0; + else + gsr = gw / gh; + if (gsr <= hsr) { + dw = hh * gsr; + dh = hh; + } else { + dw = hw; + dh = hw / gsr; + } + dx = (hw - dw) / 2.0; + dy = (hh - dh) / 2.0; + *w = (int) dw; + *h = (int) dh; + *x = (int) dx; + *y = (int) dy; + break; + case FULLSCR_SCALE_INT: + gsr = gw / gh; + if (gsr <= hsr) { + dw = hh * gsr; + dh = hh; + } else { + dw = hw; + dh = hw / gsr; + } + sdl_integer_scale(&dw, &gw); + sdl_integer_scale(&dh, &gh); + dx = (hw - dw) / 2.0; + dy = (hh - dh) / 2.0; + *w = (int) dw; + *h = (int) dh; + *x = (int) dx; + *y = (int) dy; + break; } } - void sdl_blit_shim(int x, int y, int w, int h, int monitor_index) { @@ -136,9 +134,9 @@ sdl_blit_shim(int x, int y, int w, int h, int monitor_index) params.w = w; params.h = h; if (!(!sdl_enabled || (x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || (sdl_render == NULL) || (sdl_tex == NULL)) || (monitor_index >= 1)) - video_copy(interpixels, &(buffer32->line[y][x]), h * 2048 * sizeof(uint32_t)); + video_copy(interpixels, &(buffer32->line[y][x]), h * 2048 * sizeof(uint32_t)); if (screenshots) - video_screenshot(interpixels, 0, 0, 2048); + video_screenshot(interpixels, 0, 0, 2048); blitreq = 1; video_blit_complete_monitor(monitor_index); } @@ -146,30 +144,26 @@ sdl_blit_shim(int x, int y, int w, int h, int monitor_index) void ui_window_title_real(); void -sdl_real_blit(SDL_Rect* r_src) +sdl_real_blit(SDL_Rect *r_src) { SDL_Rect r_dst; - int ret, winx, winy; + int ret, winx, winy; SDL_GL_GetDrawableSize(sdl_win, &winx, &winy); SDL_RenderClear(sdl_render); - r_dst = *r_src; + r_dst = *r_src; r_dst.x = r_dst.y = 0; - if (sdl_fs) - { - sdl_stretch(&r_dst.w, &r_dst.h, &r_dst.x, &r_dst.y); + if (sdl_fs) { + sdl_stretch(&r_dst.w, &r_dst.h, &r_dst.x, &r_dst.y); + } else { + r_dst.w *= ((float) winx / (float) r_dst.w); + r_dst.h *= ((float) winy / (float) r_dst.h); } - else - { - r_dst.w *= ((float)winx / (float) r_dst.w); - r_dst.h *= ((float)winy / (float) r_dst.h); - } - ret = SDL_RenderCopy(sdl_render, sdl_tex, r_src, &r_dst); if (ret) - fprintf(stderr, "SDL: unable to copy texture to renderer (%s)\n", SDL_GetError()); + fprintf(stderr, "SDL: unable to copy texture to renderer (%s)\n", SDL_GetError()); SDL_RenderPresent(sdl_render); } @@ -180,20 +174,20 @@ sdl_blit(int x, int y, int w, int h) SDL_Rect r_src; if (!sdl_enabled || (x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || (sdl_render == NULL) || (sdl_tex == NULL)) { - r_src.x = x; - r_src.y = y; - r_src.w = w; - r_src.h = h; - sdl_real_blit(&r_src); - blitreq = 0; - return; + r_src.x = x; + r_src.y = y; + r_src.w = w; + r_src.h = h; + sdl_real_blit(&r_src); + blitreq = 0; + return; } SDL_LockMutex(sdl_mutex); - if (resize_pending) - { - if (!video_fullscreen) sdl_resize(resize_w, resize_h); + if (resize_pending) { + if (!video_fullscreen) + sdl_resize(resize_w, resize_h); resize_pending = 0; } r_src.x = x; @@ -211,27 +205,24 @@ static void sdl_destroy_window(void) { if (sdl_win != NULL) { - if (window_remember) - { - SDL_GetWindowSize(sdl_win, &window_w, &window_h); - if (strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0) - { - SDL_GetWindowPosition(sdl_win, &window_x, &window_y); + if (window_remember) { + SDL_GetWindowSize(sdl_win, &window_w, &window_h); + if (strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0) { + SDL_GetWindowPosition(sdl_win, &window_x, &window_y); + } } - } - SDL_DestroyWindow(sdl_win); - sdl_win = NULL; + SDL_DestroyWindow(sdl_win); + sdl_win = NULL; } } - static void sdl_destroy_texture(void) { /* SDL_DestroyRenderer also automatically destroys all associated textures. */ if (sdl_render != NULL) { - SDL_DestroyRenderer(sdl_render); - sdl_render = NULL; + SDL_DestroyRenderer(sdl_render); + sdl_render = NULL; } } @@ -239,17 +230,17 @@ void sdl_close(void) { if (sdl_mutex != NULL) - SDL_LockMutex(sdl_mutex); + SDL_LockMutex(sdl_mutex); /* Unregister our renderer! */ video_setblit(NULL); if (sdl_enabled) - sdl_enabled = 0; + sdl_enabled = 0; if (sdl_mutex != NULL) { - SDL_DestroyMutex(sdl_mutex); - sdl_mutex = NULL; + SDL_DestroyMutex(sdl_mutex); + sdl_mutex = NULL; } sdl_destroy_texture(); @@ -266,14 +257,14 @@ void sdl_enable(int enable) { if (sdl_flags == -1) - return; + return; SDL_LockMutex(sdl_mutex); sdl_enabled = !!enable; if (enable == 1) { - SDL_SetWindowSize(sdl_win, cur_ww, cur_wh); - sdl_reinit_texture(); + SDL_SetWindowSize(sdl_win, cur_ww, cur_wh); + sdl_reinit_texture(); } SDL_UnlockMutex(sdl_mutex); @@ -282,16 +273,15 @@ sdl_enable(int enable) static void sdl_select_best_hw_driver(void) { - int i; + int i; SDL_RendererInfo renderInfo; - for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) - { - SDL_GetRenderDriverInfo(i, &renderInfo); - if (renderInfo.flags & SDL_RENDERER_ACCELERATED) { - SDL_SetHint(SDL_HINT_RENDER_DRIVER, renderInfo.name); - return; - } + for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) { + SDL_GetRenderDriverInfo(i, &renderInfo); + if (renderInfo.flags & SDL_RENDERER_ACCELERATED) { + SDL_SetHint(SDL_HINT_RENDER_DRIVER, renderInfo.name); + return; + } } } @@ -301,14 +291,13 @@ sdl_reinit_texture() sdl_destroy_texture(); if (sdl_flags & RENDERER_HARDWARE) { - sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_ACCELERATED); - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0"); + sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_ACCELERATED); + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0"); } else - sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_SOFTWARE); + sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_SOFTWARE); sdl_tex = SDL_CreateTexture(sdl_render, SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_STREAMING, 2048, 2048); - + SDL_TEXTUREACCESS_STREAMING, 2048, 2048); } void @@ -316,14 +305,14 @@ sdl_set_fs(int fs) { SDL_LockMutex(sdl_mutex); SDL_SetWindowFullscreen(sdl_win, fs ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); - SDL_SetRelativeMouseMode((SDL_bool)mouse_capture); + SDL_SetRelativeMouseMode((SDL_bool) mouse_capture); sdl_fs = fs; if (fs) - sdl_flags |= RENDERER_FULL_SCREEN; + sdl_flags |= RENDERER_FULL_SCREEN; else - sdl_flags &= ~RENDERER_FULL_SCREEN; + sdl_flags &= ~RENDERER_FULL_SCREEN; sdl_reinit_texture(); SDL_UnlockMutex(sdl_mutex); @@ -335,10 +324,10 @@ sdl_resize(int x, int y) int ww = 0, wh = 0, wx = 0, wy = 0; if (video_fullscreen & 2) - return; + return; if ((x == cur_w) && (y == cur_h)) - return; + return; SDL_LockMutex(sdl_mutex); @@ -363,19 +352,18 @@ sdl_resize(int x, int y) void sdl_reload(void) { - if (sdl_flags & RENDERER_HARDWARE) - { - SDL_LockMutex(sdl_mutex); + if (sdl_flags & RENDERER_HARDWARE) { + SDL_LockMutex(sdl_mutex); - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0"); - sdl_reinit_texture(); + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0"); + sdl_reinit_texture(); - SDL_UnlockMutex(sdl_mutex); - } + SDL_UnlockMutex(sdl_mutex); + } } int -plat_vidapi(char* api) +plat_vidapi(char *api) { return 0; } @@ -383,7 +371,7 @@ plat_vidapi(char* api) static int sdl_init_common(int flags) { - wchar_t temp[128]; + wchar_t temp[128]; SDL_version ver; /* Get and log the version of the DLL we are using. */ @@ -392,30 +380,27 @@ sdl_init_common(int flags) /* Initialize the SDL system. */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "SDL: initialization failed (%s)\n", SDL_GetError()); - return(0); + fprintf(stderr, "SDL: initialization failed (%s)\n", SDL_GetError()); + return (0); } if (flags & RENDERER_HARDWARE) { - if (flags & RENDERER_OPENGL) { - SDL_SetHint(SDL_HINT_RENDER_DRIVER, "OpenGL"); - } - else - sdl_select_best_hw_driver(); + if (flags & RENDERER_OPENGL) { + SDL_SetHint(SDL_HINT_RENDER_DRIVER, "OpenGL"); + } else + sdl_select_best_hw_driver(); } sdl_mutex = SDL_CreateMutex(); - sdl_win = SDL_CreateWindow("86Box", strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0 && window_remember ? window_x : SDL_WINDOWPOS_CENTERED, strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0 && window_remember ? window_y : SDL_WINDOWPOS_CENTERED, scrnsz_x, scrnsz_y, SDL_WINDOW_OPENGL | (vid_resize & 1 ? SDL_WINDOW_RESIZABLE : 0)); + sdl_win = SDL_CreateWindow("86Box", strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0 && window_remember ? window_x : SDL_WINDOWPOS_CENTERED, strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0 && window_remember ? window_y : SDL_WINDOWPOS_CENTERED, scrnsz_x, scrnsz_y, SDL_WINDOW_OPENGL | (vid_resize & 1 ? SDL_WINDOW_RESIZABLE : 0)); sdl_set_fs(video_fullscreen); - if (!(video_fullscreen & 1)) - { + if (!(video_fullscreen & 1)) { if (vid_resize & 2) - plat_resize(fixed_size_x, fixed_size_y); + plat_resize(fixed_size_x, fixed_size_y); else - plat_resize(scrnsz_x, scrnsz_y); + plat_resize(scrnsz_x, scrnsz_y); } - if ((vid_resize < 2) && window_remember) - { + if ((vid_resize < 2) && window_remember) { SDL_SetWindowSize(sdl_win, window_w, window_h); } @@ -427,7 +412,7 @@ sdl_init_common(int flags) sdl_enabled = 1; - return(1); + return (1); } int @@ -436,61 +421,58 @@ sdl_inits() return sdl_init_common(0); } - int sdl_inith() { return sdl_init_common(RENDERER_HARDWARE); } - int sdl_initho() { return sdl_init_common(RENDERER_HARDWARE | RENDERER_OPENGL); } - int sdl_pause(void) { - return(0); + return (0); } void plat_mouse_capture(int on) { SDL_LockMutex(sdl_mutex); - SDL_SetRelativeMouseMode((SDL_bool)on); + SDL_SetRelativeMouseMode((SDL_bool) on); mouse_capture = on; SDL_UnlockMutex(sdl_mutex); } -void plat_resize(int w, int h) +void +plat_resize(int w, int h) { SDL_LockMutex(sdl_mutex); - resize_w = w; - resize_h = h; + resize_w = w; + resize_h = h; resize_pending = 1; SDL_UnlockMutex(sdl_mutex); } -wchar_t sdl_win_title[512] = { L'8', L'6', L'B', L'o', L'x', 0 }; -SDL_mutex* titlemtx = NULL; +wchar_t sdl_win_title[512] = { L'8', L'6', L'B', L'o', L'x', 0 }; +SDL_mutex *titlemtx = NULL; -void ui_window_title_real() +void +ui_window_title_real() { - char* res; - if (sizeof(wchar_t) == 1) - { - SDL_SetWindowTitle(sdl_win, (char*)sdl_win_title); + char *res; + if (sizeof(wchar_t) == 1) { + SDL_SetWindowTitle(sdl_win, (char *) sdl_win_title); return; } - res = SDL_iconv_string("UTF-8", sizeof(wchar_t) == 2 ? "UTF-16LE" : "UTF-32LE", (char*)sdl_win_title, wcslen(sdl_win_title) * sizeof(wchar_t) + sizeof(wchar_t)); - if (res) - { + res = SDL_iconv_string("UTF-8", sizeof(wchar_t) == 2 ? "UTF-16LE" : "UTF-32LE", (char *) sdl_win_title, wcslen(sdl_win_title) * sizeof(wchar_t) + sizeof(wchar_t)); + if (res) { SDL_SetWindowTitle(sdl_win, res); - SDL_free((void*)res); + SDL_free((void *) res); } title_set = 0; } @@ -498,9 +480,11 @@ extern SDL_threadID eventthread; /* Only activate threading path on macOS, otherwise it will softlock Xorg. Wayland doesn't seem to have this issue. */ -wchar_t* ui_window_title(wchar_t* str) +wchar_t * +ui_window_title(wchar_t *str) { - if (!str) return sdl_win_title; + if (!str) + return sdl_win_title; #ifdef __APPLE__ if (eventthread == SDL_ThreadID()) #endif @@ -518,10 +502,17 @@ wchar_t* ui_window_title(wchar_t* str) return str; } -void ui_init_monitor(int monitor_index) {} -void ui_deinit_monitor(int monitor_index) {} +void +ui_init_monitor(int monitor_index) +{ +} +void +ui_deinit_monitor(int monitor_index) +{ +} -void plat_resize_request(int w, int h, int monitor_index) +void +plat_resize_request(int w, int h, int monitor_index) { atomic_store((&doresize_monitors[monitor_index]), 1); } diff --git a/src/unix/unix_thread.c b/src/unix/unix_thread.c index 5221d90eb..268545719 100644 --- a/src/unix/unix_thread.c +++ b/src/unix/unix_thread.c @@ -7,30 +7,23 @@ #include <86box/plat.h> #include <86box/thread.h> - -typedef struct event_pthread_t -{ - pthread_cond_t cond; - pthread_mutex_t mutex; - int state; +typedef struct event_pthread_t { + pthread_cond_t cond; + pthread_mutex_t mutex; + int state; } event_pthread_t; - -typedef struct thread_param -{ - void (*thread_rout)(void*); - void * param; +typedef struct thread_param { + void (*thread_rout)(void *); + void *param; } thread_param; - -typedef struct pt_mutex_t -{ - pthread_mutex_t mutex; +typedef struct pt_mutex_t { + pthread_mutex_t mutex; } pt_mutex_t; - void * -thread_run_wrapper(thread_param* arg) +thread_run_wrapper(thread_param *arg) { thread_param localparam = *arg; free(arg); @@ -38,28 +31,25 @@ thread_run_wrapper(thread_param* arg) return NULL; } - thread_t * thread_create(void (*thread_rout)(void *param), void *param) { - pthread_t *thread = malloc(sizeof(pthread_t)); + pthread_t *thread = malloc(sizeof(pthread_t)); thread_param *thrparam = malloc(sizeof(thread_param)); - thrparam->thread_rout = thread_rout; - thrparam->param = param; + thrparam->thread_rout = thread_rout; + thrparam->param = param; - pthread_create(thread, NULL, (void* (*)(void*))thread_run_wrapper, thrparam); + pthread_create(thread, NULL, (void *(*) (void *) ) thread_run_wrapper, thrparam); return thread; } - int thread_wait(thread_t *arg) { - return pthread_join(*(pthread_t*)(arg), NULL); + return pthread_join(*(pthread_t *) (arg), NULL); } - event_t * thread_create_event() { @@ -69,14 +59,13 @@ thread_create_event() pthread_mutex_init(&event->mutex, NULL); event->state = 0; - return (event_t *)event; + return (event_t *) event; } - void thread_set_event(event_t *handle) { - event_pthread_t *event = (event_pthread_t *)handle; + event_pthread_t *event = (event_pthread_t *) handle; pthread_mutex_lock(&event->mutex); event->state = 1; @@ -84,48 +73,45 @@ thread_set_event(event_t *handle) pthread_mutex_unlock(&event->mutex); } - void thread_reset_event(event_t *handle) { - event_pthread_t *event = (event_pthread_t *)handle; + event_pthread_t *event = (event_pthread_t *) handle; pthread_mutex_lock(&event->mutex); event->state = 0; pthread_mutex_unlock(&event->mutex); } - int thread_wait_event(event_t *handle, int timeout) { - event_pthread_t *event = (event_pthread_t *)handle; - struct timespec abstime; + event_pthread_t *event = (event_pthread_t *) handle; + struct timespec abstime; clock_gettime(CLOCK_REALTIME, &abstime); abstime.tv_nsec += (timeout % 1000) * 1000000; abstime.tv_sec += (timeout / 1000); if (abstime.tv_nsec > 1000000000) { - abstime.tv_nsec -= 1000000000; - abstime.tv_sec++; + abstime.tv_nsec -= 1000000000; + abstime.tv_sec++; } pthread_mutex_lock(&event->mutex); if (timeout == -1) { - while (!event->state) - pthread_cond_wait(&event->cond, &event->mutex); + while (!event->state) + pthread_cond_wait(&event->cond, &event->mutex); } else if (!event->state) - pthread_cond_timedwait(&event->cond, &event->mutex, &abstime); + pthread_cond_timedwait(&event->cond, &event->mutex, &abstime); pthread_mutex_unlock(&event->mutex); return 0; } - void thread_destroy_event(event_t *handle) { - event_pthread_t *event = (event_pthread_t *)handle; + event_pthread_t *event = (event_pthread_t *) handle; pthread_cond_destroy(&event->cond); pthread_mutex_destroy(&event->mutex); @@ -133,7 +119,6 @@ thread_destroy_event(event_t *handle) free(event); } - mutex_t * thread_create_mutex(void) { @@ -144,46 +129,40 @@ thread_create_mutex(void) return mutex; } - int thread_wait_mutex(mutex_t *_mutex) { if (_mutex == NULL) - return(0); - pt_mutex_t *mutex = (pt_mutex_t *)_mutex; + return (0); + pt_mutex_t *mutex = (pt_mutex_t *) _mutex; - return - pthread_mutex_lock(&mutex->mutex) != 0; + return pthread_mutex_lock(&mutex->mutex) != 0; } - int thread_test_mutex(mutex_t *_mutex) { if (_mutex == NULL) - return(0); - pt_mutex_t *mutex = (pt_mutex_t *)_mutex; + return (0); + pt_mutex_t *mutex = (pt_mutex_t *) _mutex; - return - pthread_mutex_trylock(&mutex->mutex) != 0; + return pthread_mutex_trylock(&mutex->mutex) != 0; } - int thread_release_mutex(mutex_t *_mutex) { if (_mutex == NULL) - return(0); - pt_mutex_t *mutex = (pt_mutex_t *)_mutex; + return (0); + pt_mutex_t *mutex = (pt_mutex_t *) _mutex; return pthread_mutex_unlock(&mutex->mutex) != 0; } - void thread_close_mutex(mutex_t *_mutex) { - pt_mutex_t *mutex = (pt_mutex_t *)_mutex; + pt_mutex_t *mutex = (pt_mutex_t *) _mutex; pthread_mutex_destroy(&mutex->mutex);