clang-format in src/unix/

This commit is contained in:
Jasmine Iwanek
2022-09-18 17:17:34 -04:00
parent d4c4ef6a5d
commit acbe718f1e
5 changed files with 744 additions and 848 deletions

View File

@@ -19,5 +19,4 @@ int toto();
CF_EXTERN_C_END
CF_IMPLICIT_BRIDGING_DISABLED
#endif /* macOSXGlue_h */

View File

@@ -66,8 +66,7 @@ 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] =
{
static const uint16_t sdl_to_xt[0x200] = {
[SDL_SCANCODE_ESCAPE] = 0x01,
[SDL_SCANCODE_1] = 0x02,
[SDL_SCANCODE_2] = 0x03,
@@ -175,24 +174,21 @@ static const uint16_t sdl_to_xt[0x200] =
[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;
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)
{
if (modhandle) {
for (imp = table; imp->name != NULL; imp++) {
if ((*(void **) imp->func = dlsym(modhandle, imp->name)) == NULL) {
dlclose(modhandle);
return NULL;
}
@@ -230,15 +226,16 @@ plat_chdir(char* str)
return chdir(str);
}
void dynld_close(void *handle)
void
dynld_close(void *handle)
{
dlclose(handle);
}
wchar_t* plat_get_string(int i)
{
switch (i)
wchar_t *
plat_get_string(int i)
{
switch (i) {
case IDS_2077:
return L"Click to capture mouse";
case IDS_2078:
@@ -353,7 +350,6 @@ path_get_filename(char *s)
return (s);
}
char *
path_get_extension(char *s)
{
@@ -371,7 +367,6 @@ path_get_extension(char *s)
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);
@@ -446,7 +440,8 @@ plat_get_micro_ticks(void)
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,19 +465,16 @@ plat_delay_ms(uint32_t count)
void
ui_sb_update_tip(int arg)
{
}
void
ui_sb_update_panes()
{
}
void
ui_sb_update_text()
{
}
void
@@ -509,17 +499,19 @@ path_get_dirname(char *dest, const char *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);
}
@@ -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,18 +612,23 @@ 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_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;
@@ -643,20 +636,20 @@ int ui_msgbox_header(int flags, void *header, void* message)
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;
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)
{
if (flags & MBX_ANSI) {
int button = 0;
msgdata.title = header;
msgdata.message = message;
SDL_ShowMessageBox(&msgdata, &button);
return button;
}
else
{
} 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));
@@ -671,7 +664,8 @@ 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();
snprintf(s, size, "%s%s", basepath, basepath[strlen(basepath) - 1] == '/' ? "86box" : "/86box");
@@ -691,21 +685,21 @@ 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);
typedef struct mouseinputdata
{
typedef struct mouseinputdata {
int deltax, deltay, deltaz;
int mousebuttons;
} mouseinputdata;
SDL_mutex *mousemutex;
static mouseinputdata mousedata;
void mouse_poll()
void
mouse_poll()
{
SDL_LockMutex(mousemutex);
mouse_x = mousedata.deltax;
@@ -716,19 +710,25 @@ void mouse_poll()
SDL_UnlockMutex(mousemutex);
}
int real_sdl_w, real_sdl_h;
void ui_sb_set_ready(int ready) {}
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;
if (!s)
return NULL;
end = s + strcspn(s, sep);
if (*end) *end++ = 0;
else end = 0;
if (*end)
*end++ = 0;
else
end = 0;
*str = end;
return s;
}
@@ -810,48 +810,40 @@ plat_init_rom_paths()
#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] == '"')
{
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;
@@ -863,52 +855,50 @@ void (*f_rl_callback_handler_remove)(void) = NULL;
#else
# 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;
}
void monitor_thread(void* param)
void
monitor_thread(void *param)
{
#ifndef USE_CLI
if (isatty(fileno(stdin)) && isatty(fileno(stdout)))
{
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)
{
if (line) {
int cmdargc = 0;
char *linecpy;
line[strcspn(line, "\r\n")] = '\0';
linecpy = strdup(line);
if (!linecpy)
{
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 <id> <filename> <wp> - Load floppy disk image into drive <id>.\n"
"cdload <id> <filename> - Load CD-ROM image into drive <id>.\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)
{
} 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];
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];
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];
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];
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];
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,7 +1063,8 @@ 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;
@@ -1131,28 +1080,24 @@ int main(int argc, char** argv)
gfxcard_2 = 0;
eventthread = SDL_ThreadID();
blitmtx = SDL_CreateMutex();
if (!blitmtx)
{
if (!blitmtx) {
fprintf(stderr, "Failed to create blit mutex: %s", SDL_GetError());
return -1;
}
libedithandle = dlopen(LIBEDIT_LIBRARY, RTLD_LOCAL | RTLD_LAZY);
if (libedithandle)
{
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);
}
@@ -1169,22 +1114,17 @@ 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)
{
if (mouse_capture || video_fullscreen) {
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
event.wheel.x *= -1;
event.wheel.y *= -1;
}
@@ -1196,8 +1136,7 @@ int main(int argc, char** argv)
}
case SDL_MOUSEMOTION:
{
if (mouse_capture || video_fullscreen)
{
if (mouse_capture || video_fullscreen) {
SDL_LockMutex(mousemutex);
mousedata.deltax += event.motion.xrel;
mousedata.deltay += event.motion.yrel;
@@ -1211,22 +1150,18 @@ int main(int argc, char** argv)
if ((event.button.button == SDL_BUTTON_LEFT)
&& !(mouse_capture || video_fullscreen)
&& event.button.state == SDL_RELEASED
&& mouse_inside)
{
&& mouse_inside) {
plat_mouse_capture(1);
break;
}
if (mouse_get_buttons() < 3 && event.button.button == SDL_BUTTON_MIDDLE && !video_fullscreen)
{
if (mouse_get_buttons() < 3 && event.button.button == SDL_BUTTON_MIDDLE && !video_fullscreen) {
plat_mouse_capture(0);
break;
}
if (mouse_capture || video_fullscreen)
{
if (mouse_capture || video_fullscreen) {
int buttonmask = 0;
switch(event.button.button)
{
switch (event.button.button) {
case SDL_BUTTON_LEFT:
buttonmask = 1;
break;
@@ -1238,11 +1173,10 @@ int main(int argc, char** argv)
break;
}
SDL_LockMutex(mousemutex);
if (event.button.state == SDL_PRESSED)
{
if (event.button.state == SDL_PRESSED) {
mousedata.mousebuttons |= buttonmask;
}
else mousedata.mousebuttons &= ~buttonmask;
} else
mousedata.mousebuttons &= ~buttonmask;
SDL_UnlockMutex(mousemutex);
}
break;
@@ -1258,8 +1192,7 @@ int main(int argc, char** argv)
case SDL_KEYUP:
{
uint16_t xtkey = 0;
switch(event.key.keysym.scancode)
{
switch (event.key.keysym.scancode) {
default:
xtkey = sdl_to_xt[event.key.keysym.scancode];
break;
@@ -1268,8 +1201,7 @@ int main(int argc, char** argv)
}
case SDL_WINDOWEVENT:
{
switch (event.window.event)
{
switch (event.window.event) {
case SDL_WINDOWEVENT_ENTER:
mouse_inside = 1;
break;
@@ -1280,32 +1212,26 @@ int main(int argc, char** argv)
}
}
}
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;
@@ -1344,15 +1272,26 @@ plat_language_code_r(uint32_t lcid, char* outbuf, int len)
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);
}

View File

@@ -39,8 +39,6 @@
#include <86box/plat.h>
#include <86box/ui.h>
void
cassette_mount(char *fn, uint8_t wp)
{
@@ -56,7 +54,6 @@ cassette_mount(char *fn, uint8_t wp)
config_save();
}
void
cassette_eject(void)
{
@@ -68,7 +65,6 @@ cassette_eject(void)
config_save();
}
void
cartridge_mount(uint8_t id, char *fn, uint8_t wp)
{
@@ -80,7 +76,6 @@ cartridge_mount(uint8_t id, char *fn, uint8_t wp)
config_save();
}
void
cartridge_eject(uint8_t id)
{
@@ -91,7 +86,6 @@ cartridge_eject(uint8_t id)
config_save();
}
void
floppy_mount(uint8_t id, char *fn, uint8_t wp)
{
@@ -104,7 +98,6 @@ floppy_mount(uint8_t id, char *fn, uint8_t wp)
config_save();
}
void
floppy_eject(uint8_t id)
{
@@ -115,7 +108,6 @@ floppy_eject(uint8_t id)
config_save();
}
void
plat_cdrom_ui_update(uint8_t id, uint8_t reload)
{
@@ -172,7 +164,6 @@ mo_eject(uint8_t id)
config_save();
}
void
mo_mount(uint8_t id, char *fn, uint8_t wp)
{
@@ -190,7 +181,6 @@ mo_mount(uint8_t id, char *fn, uint8_t wp)
config_save();
}
void
mo_reload(uint8_t id)
{
@@ -226,7 +216,6 @@ zip_eject(uint8_t id)
config_save();
}
void
zip_mount(uint8_t id, char *fn, uint8_t wp)
{
@@ -244,7 +233,6 @@ zip_mount(uint8_t id, char *fn, uint8_t wp)
config_save();
}
void
zip_reload(uint8_t id)
{

View File

@@ -22,8 +22,7 @@
#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;
@@ -127,7 +126,6 @@ sdl_stretch(int *w, int *h, int *x, int *y)
}
}
void
sdl_blit_shim(int x, int y, int w, int h, int monitor_index)
{
@@ -156,17 +154,13 @@ sdl_real_blit(SDL_Rect* r_src)
r_dst = *r_src;
r_dst.x = r_dst.y = 0;
if (sdl_fs)
{
if (sdl_fs) {
sdl_stretch(&r_dst.w, &r_dst.h, &r_dst.x, &r_dst.y);
}
else
{
} 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());
@@ -191,9 +185,9 @@ sdl_blit(int x, int y, int w, int h)
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,11 +205,9 @@ static void
sdl_destroy_window(void)
{
if (sdl_win != NULL) {
if (window_remember)
{
if (window_remember) {
SDL_GetWindowSize(sdl_win, &window_w, &window_h);
if (strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0)
{
if (strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0) {
SDL_GetWindowPosition(sdl_win, &window_x, &window_y);
}
}
@@ -224,7 +216,6 @@ sdl_destroy_window(void)
}
}
static void
sdl_destroy_texture(void)
{
@@ -285,8 +276,7 @@ sdl_select_best_hw_driver(void)
int i;
SDL_RendererInfo renderInfo;
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i)
{
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);
@@ -308,7 +298,6 @@ sdl_reinit_texture()
sdl_tex = SDL_CreateTexture(sdl_render, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING, 2048, 2048);
}
void
@@ -363,8 +352,7 @@ sdl_resize(int x, int y)
void
sdl_reload(void)
{
if (sdl_flags & RENDERER_HARDWARE)
{
if (sdl_flags & RENDERER_HARDWARE) {
SDL_LockMutex(sdl_mutex);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0");
@@ -399,23 +387,20 @@ sdl_init_common(int flags)
if (flags & RENDERER_HARDWARE) {
if (flags & RENDERER_OPENGL) {
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "OpenGL");
}
else
} 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_set_fs(video_fullscreen);
if (!(video_fullscreen & 1))
{
if (!(video_fullscreen & 1)) {
if (vid_resize & 2)
plat_resize(fixed_size_x, fixed_size_y);
else
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);
}
@@ -436,21 +421,18 @@ 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)
{
@@ -466,7 +448,8 @@ plat_mouse_capture(int 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;
@@ -478,17 +461,16 @@ void plat_resize(int w, int h)
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)
{
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)
{
if (res) {
SDL_SetWindowTitle(sdl_win, res);
SDL_free((void *) res);
}
@@ -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);
}

View File

@@ -7,28 +7,21 @@
#include <86box/plat.h>
#include <86box/thread.h>
typedef struct event_pthread_t
{
typedef struct event_pthread_t {
pthread_cond_t cond;
pthread_mutex_t mutex;
int state;
} event_pthread_t;
typedef struct thread_param
{
typedef struct thread_param {
void (*thread_rout)(void *);
void *param;
} thread_param;
typedef struct pt_mutex_t
{
typedef struct pt_mutex_t {
pthread_mutex_t mutex;
} pt_mutex_t;
void *
thread_run_wrapper(thread_param *arg)
{
@@ -38,7 +31,6 @@ thread_run_wrapper(thread_param* arg)
return NULL;
}
thread_t *
thread_create(void (*thread_rout)(void *param), void *param)
{
@@ -52,14 +44,12 @@ thread_create(void (*thread_rout)(void *param), void *param)
return thread;
}
int
thread_wait(thread_t *arg)
{
return pthread_join(*(pthread_t *) (arg), NULL);
}
event_t *
thread_create_event()
{
@@ -72,7 +62,6 @@ thread_create_event()
return (event_t *) event;
}
void
thread_set_event(event_t *handle)
{
@@ -84,7 +73,6 @@ thread_set_event(event_t *handle)
pthread_mutex_unlock(&event->mutex);
}
void
thread_reset_event(event_t *handle)
{
@@ -95,7 +83,6 @@ thread_reset_event(event_t *handle)
pthread_mutex_unlock(&event->mutex);
}
int
thread_wait_event(event_t *handle, int timeout)
{
@@ -121,7 +108,6 @@ thread_wait_event(event_t *handle, int timeout)
return 0;
}
void
thread_destroy_event(event_t *handle)
{
@@ -133,7 +119,6 @@ thread_destroy_event(event_t *handle)
free(event);
}
mutex_t *
thread_create_mutex(void)
{
@@ -144,7 +129,6 @@ thread_create_mutex(void)
return mutex;
}
int
thread_wait_mutex(mutex_t *_mutex)
{
@@ -152,11 +136,9 @@ thread_wait_mutex(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)
{
@@ -164,11 +146,9 @@ thread_test_mutex(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)
{
@@ -179,7 +159,6 @@ thread_release_mutex(mutex_t *_mutex)
return pthread_mutex_unlock(&mutex->mutex) != 0;
}
void
thread_close_mutex(mutex_t *_mutex)
{