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

@@ -13,11 +13,10 @@
CF_IMPLICIT_BRIDGING_ENABLED CF_IMPLICIT_BRIDGING_ENABLED
CF_EXTERN_C_BEGIN CF_EXTERN_C_BEGIN
void getDefaultROMPath(char*); void getDefaultROMPath(char *);
int toto(); int toto();
CF_EXTERN_C_END CF_EXTERN_C_END
CF_IMPLICIT_BRIDGING_DISABLED CF_IMPLICIT_BRIDGING_DISABLED
#endif /* macOSXGlue_h */ #endif /* macOSXGlue_h */

File diff suppressed because it is too large Load Diff

View File

@@ -39,8 +39,6 @@
#include <86box/plat.h> #include <86box/plat.h>
#include <86box/ui.h> #include <86box/ui.h>
void void
cassette_mount(char *fn, uint8_t wp) cassette_mount(char *fn, uint8_t wp)
{ {
@@ -49,49 +47,45 @@ cassette_mount(char *fn, uint8_t wp)
cassette_ui_writeprot = wp; cassette_ui_writeprot = wp;
pc_cas_set_fname(cassette, fn); pc_cas_set_fname(cassette, fn);
if (fn != NULL) 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); 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); ui_sb_update_tip(SB_CASSETTE);
config_save(); config_save();
} }
void void
cassette_eject(void) cassette_eject(void)
{ {
pc_cas_set_fname(cassette, NULL); pc_cas_set_fname(cassette, NULL);
memset(cassette_fname, 0x00, sizeof(cassette_fname)); memset(cassette_fname, 0x00, sizeof(cassette_fname));
ui_sb_update_icon_state(SB_CASSETTE, 1); ui_sb_update_icon_state(SB_CASSETTE, 1);
//media_menu_update_cassette(); // media_menu_update_cassette();
ui_sb_update_tip(SB_CASSETTE); ui_sb_update_tip(SB_CASSETTE);
config_save(); config_save();
} }
void void
cartridge_mount(uint8_t id, char *fn, uint8_t wp) cartridge_mount(uint8_t id, char *fn, uint8_t wp)
{ {
cart_close(id); cart_close(id);
cart_load(id, fn); cart_load(id, fn);
ui_sb_update_icon_state(SB_CARTRIDGE | id, strlen(cart_fns[id]) ? 0 : 1); 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); ui_sb_update_tip(SB_CARTRIDGE | id);
config_save(); config_save();
} }
void void
cartridge_eject(uint8_t id) cartridge_eject(uint8_t id)
{ {
cart_close(id); cart_close(id);
ui_sb_update_icon_state(SB_CARTRIDGE | id, 1); 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); ui_sb_update_tip(SB_CARTRIDGE | id);
config_save(); config_save();
} }
void void
floppy_mount(uint8_t id, char *fn, uint8_t wp) 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; ui_writeprot[id] = wp;
fdd_load(id, fn); fdd_load(id, fn);
ui_sb_update_icon_state(SB_FLOPPY | id, strlen(floppyfns[id]) ? 0 : 1); 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); ui_sb_update_tip(SB_FLOPPY | id);
config_save(); config_save();
} }
void void
floppy_eject(uint8_t id) floppy_eject(uint8_t id)
{ {
fdd_close(id); fdd_close(id);
ui_sb_update_icon_state(SB_FLOPPY | id, 1); 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); ui_sb_update_tip(SB_FLOPPY | id);
config_save(); config_save();
} }
void void
plat_cdrom_ui_update(uint8_t id, uint8_t reload) plat_cdrom_ui_update(uint8_t id, uint8_t reload)
{ {
cdrom_t *drv = &cdrom[id]; cdrom_t *drv = &cdrom[id];
if (drv->host_drive == 0) { if (drv->host_drive == 0) {
ui_sb_update_icon_state(SB_CDROM|id, 1); ui_sb_update_icon_state(SB_CDROM | id, 1);
} else { } else {
ui_sb_update_icon_state(SB_CDROM|id, 0); ui_sb_update_icon_state(SB_CDROM | id, 0);
} }
//media_menu_update_cdrom(id); // media_menu_update_cdrom(id);
ui_sb_update_tip(SB_CDROM|id); ui_sb_update_tip(SB_CDROM | id);
} }
void void
@@ -137,20 +129,20 @@ cdrom_mount(uint8_t id, char *fn)
cdrom[id].prev_host_drive = cdrom[id].host_drive; cdrom[id].prev_host_drive = cdrom[id].host_drive;
strcpy(cdrom[id].prev_image_path, cdrom[id].image_path); strcpy(cdrom[id].prev_image_path, cdrom[id].image_path);
if (cdrom[id].ops && cdrom[id].ops->exit) if (cdrom[id].ops && cdrom[id].ops->exit)
cdrom[id].ops->exit(&(cdrom[id])); cdrom[id].ops->exit(&(cdrom[id]));
cdrom[id].ops = NULL; cdrom[id].ops = NULL;
memset(cdrom[id].image_path, 0, sizeof(cdrom[id].image_path)); memset(cdrom[id].image_path, 0, sizeof(cdrom[id].image_path));
cdrom_image_open(&(cdrom[id]), fn); cdrom_image_open(&(cdrom[id]), fn);
/* Signal media change to the emulated machine. */ /* Signal media change to the emulated machine. */
if (cdrom[id].insert) 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; cdrom[id].host_drive = (strlen(cdrom[id].image_path) == 0) ? 0 : 200;
if (cdrom[id].host_drive == 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 { } 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); ui_sb_update_tip(SB_CDROM | id);
config_save(); config_save();
} }
@@ -162,17 +154,16 @@ mo_eject(uint8_t id)
mo_disk_close(dev); mo_disk_close(dev);
if (mo_drives[id].bus_type) { if (mo_drives[id].bus_type) {
/* Signal disk change to the emulated machine. */ /* Signal disk change to the emulated machine. */
mo_insert(dev); mo_insert(dev);
} }
ui_sb_update_icon_state(SB_MO | id, 1); 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); ui_sb_update_tip(SB_MO | id);
config_save(); config_save();
} }
void void
mo_mount(uint8_t id, char *fn, uint8_t wp) 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); mo_insert(dev);
ui_sb_update_icon_state(SB_MO | id, strlen(mo_drives[id].image_path) ? 0 : 1); 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); ui_sb_update_tip(SB_MO | id);
config_save(); config_save();
} }
void void
mo_reload(uint8_t id) mo_reload(uint8_t id)
{ {
@@ -198,13 +188,13 @@ mo_reload(uint8_t id)
mo_disk_reload(dev); mo_disk_reload(dev);
if (strlen(mo_drives[id].image_path) == 0) { 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 { } else {
ui_sb_update_icon_state(SB_MO|id, 0); ui_sb_update_icon_state(SB_MO | id, 0);
} }
//media_menu_update_mo(id); // media_menu_update_mo(id);
ui_sb_update_tip(SB_MO|id); ui_sb_update_tip(SB_MO | id);
config_save(); config_save();
} }
@@ -216,17 +206,16 @@ zip_eject(uint8_t id)
zip_disk_close(dev); zip_disk_close(dev);
if (zip_drives[id].bus_type) { if (zip_drives[id].bus_type) {
/* Signal disk change to the emulated machine. */ /* Signal disk change to the emulated machine. */
zip_insert(dev); zip_insert(dev);
} }
ui_sb_update_icon_state(SB_ZIP | id, 1); 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); ui_sb_update_tip(SB_ZIP | id);
config_save(); config_save();
} }
void void
zip_mount(uint8_t id, char *fn, uint8_t wp) 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); zip_insert(dev);
ui_sb_update_icon_state(SB_ZIP | id, strlen(zip_drives[id].image_path) ? 0 : 1); 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); ui_sb_update_tip(SB_ZIP | id);
config_save(); config_save();
} }
void void
zip_reload(uint8_t id) zip_reload(uint8_t id)
{ {
@@ -252,13 +240,13 @@ zip_reload(uint8_t id)
zip_disk_reload(dev); zip_disk_reload(dev);
if (strlen(zip_drives[id].image_path) == 0) { 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 { } else {
ui_sb_update_icon_state(SB_ZIP|id, 0); ui_sb_update_icon_state(SB_ZIP | id, 0);
} }
//media_menu_update_zip(id); // media_menu_update_zip(id);
ui_sb_update_tip(SB_ZIP|id); ui_sb_update_tip(SB_ZIP | id);
config_save(); config_save();
} }

View File

@@ -18,34 +18,33 @@
#include <86box/version.h> #include <86box/version.h>
#include <86box/unix_sdl.h> #include <86box/unix_sdl.h>
#define RENDERER_FULL_SCREEN 1 #define RENDERER_FULL_SCREEN 1
#define RENDERER_HARDWARE 2 #define RENDERER_HARDWARE 2
#define RENDERER_OPENGL 4 #define RENDERER_OPENGL 4
typedef struct sdl_blit_params typedef struct sdl_blit_params {
{
int x, y, w, h; int x, y, w, h;
} sdl_blit_params; } sdl_blit_params;
extern sdl_blit_params params; extern sdl_blit_params params;
extern int blitreq; extern int blitreq;
SDL_Window *sdl_win = NULL; SDL_Window *sdl_win = NULL;
SDL_Renderer *sdl_render = NULL; SDL_Renderer *sdl_render = NULL;
static SDL_Texture *sdl_tex = NULL; static SDL_Texture *sdl_tex = NULL;
int sdl_w = SCREEN_RES_X, sdl_h = SCREEN_RES_Y; int sdl_w = SCREEN_RES_X, sdl_h = SCREEN_RES_Y;
static int sdl_fs, sdl_flags = -1; static int sdl_fs, sdl_flags = -1;
static int cur_w, cur_h; static int cur_w, cur_h;
static int cur_wx = 0, cur_wy = 0, cur_ww =0, cur_wh = 0; static int cur_wx = 0, cur_wy = 0, cur_ww = 0, cur_wh = 0;
static volatile int sdl_enabled = 1; static volatile int sdl_enabled = 1;
static SDL_mutex* sdl_mutex = NULL; static SDL_mutex *sdl_mutex = NULL;
int mouse_capture; int mouse_capture;
int title_set = 0; int title_set = 0;
int resize_pending = 0; int resize_pending = 0;
int resize_w = 0; int resize_w = 0;
int resize_h = 0; int resize_h = 0;
double mouse_sensitivity = 1.0; /* Unused. */ double mouse_sensitivity = 1.0; /* Unused. */
double mouse_x_error = 0.0, mouse_y_error = 0.0; /* Unused. */ double mouse_x_error = 0.0, mouse_y_error = 0.0; /* Unused. */
static uint8_t interpixels[17842176]; static uint8_t interpixels[17842176];
extern void RenderImGui(); extern void RenderImGui();
static void static void
@@ -54,11 +53,11 @@ sdl_integer_scale(double *d, double *g)
double ratio; double ratio;
if (*d > *g) { if (*d > *g) {
ratio = floor(*d / *g); ratio = floor(*d / *g);
*d = *g * ratio; *d = *g * ratio;
} else { } else {
ratio = ceil(*d / *g); ratio = ceil(*d / *g);
*d = *g / ratio; *d = *g / ratio;
} }
} }
@@ -68,66 +67,65 @@ static void
sdl_stretch(int *w, int *h, int *x, int *y) sdl_stretch(int *w, int *h, int *x, int *y)
{ {
double hw, gw, hh, gh, dx, dy, dw, dh, gsr, hsr; 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); SDL_GL_GetDrawableSize(sdl_win, &real_sdl_w, &real_sdl_h);
hw = (double) real_sdl_w; hw = (double) real_sdl_w;
hh = (double) real_sdl_h; hh = (double) real_sdl_h;
gw = (double) *w; gw = (double) *w;
gh = (double) *h; gh = (double) *h;
hsr = hw / hh; hsr = hw / hh;
switch (video_fullscreen_scale) { switch (video_fullscreen_scale) {
case FULLSCR_SCALE_FULL: case FULLSCR_SCALE_FULL:
default: default:
*w = real_sdl_w; *w = real_sdl_w;
*h = real_sdl_h; *h = real_sdl_h;
*x = 0; *x = 0;
*y = 0; *y = 0;
break; break;
case FULLSCR_SCALE_43: case FULLSCR_SCALE_43:
case FULLSCR_SCALE_KEEPRATIO: case FULLSCR_SCALE_KEEPRATIO:
if (video_fullscreen_scale == FULLSCR_SCALE_43) if (video_fullscreen_scale == FULLSCR_SCALE_43)
gsr = 4.0 / 3.0; gsr = 4.0 / 3.0;
else else
gsr = gw / gh; gsr = gw / gh;
if (gsr <= hsr) { if (gsr <= hsr) {
dw = hh * gsr; dw = hh * gsr;
dh = hh; dh = hh;
} else { } else {
dw = hw; dw = hw;
dh = hw / gsr; dh = hw / gsr;
} }
dx = (hw - dw) / 2.0; dx = (hw - dw) / 2.0;
dy = (hh - dh) / 2.0; dy = (hh - dh) / 2.0;
*w = (int) dw; *w = (int) dw;
*h = (int) dh; *h = (int) dh;
*x = (int) dx; *x = (int) dx;
*y = (int) dy; *y = (int) dy;
break; break;
case FULLSCR_SCALE_INT: case FULLSCR_SCALE_INT:
gsr = gw / gh; gsr = gw / gh;
if (gsr <= hsr) { if (gsr <= hsr) {
dw = hh * gsr; dw = hh * gsr;
dh = hh; dh = hh;
} else { } else {
dw = hw; dw = hw;
dh = hw / gsr; dh = hw / gsr;
} }
sdl_integer_scale(&dw, &gw); sdl_integer_scale(&dw, &gw);
sdl_integer_scale(&dh, &gh); sdl_integer_scale(&dh, &gh);
dx = (hw - dw) / 2.0; dx = (hw - dw) / 2.0;
dy = (hh - dh) / 2.0; dy = (hh - dh) / 2.0;
*w = (int) dw; *w = (int) dw;
*h = (int) dh; *h = (int) dh;
*x = (int) dx; *x = (int) dx;
*y = (int) dy; *y = (int) dy;
break; break;
} }
} }
void void
sdl_blit_shim(int x, int y, int w, int h, int monitor_index) 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.w = w;
params.h = h; 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)) 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) if (screenshots)
video_screenshot(interpixels, 0, 0, 2048); video_screenshot(interpixels, 0, 0, 2048);
blitreq = 1; blitreq = 1;
video_blit_complete_monitor(monitor_index); 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 ui_window_title_real();
void void
sdl_real_blit(SDL_Rect* r_src) sdl_real_blit(SDL_Rect *r_src)
{ {
SDL_Rect r_dst; SDL_Rect r_dst;
int ret, winx, winy; int ret, winx, winy;
SDL_GL_GetDrawableSize(sdl_win, &winx, &winy); SDL_GL_GetDrawableSize(sdl_win, &winx, &winy);
SDL_RenderClear(sdl_render); SDL_RenderClear(sdl_render);
r_dst = *r_src; r_dst = *r_src;
r_dst.x = r_dst.y = 0; 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);
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); ret = SDL_RenderCopy(sdl_render, sdl_tex, r_src, &r_dst);
if (ret) 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); SDL_RenderPresent(sdl_render);
} }
@@ -180,20 +174,20 @@ sdl_blit(int x, int y, int w, int h)
SDL_Rect r_src; 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)) { 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.x = x;
r_src.y = y; r_src.y = y;
r_src.w = w; r_src.w = w;
r_src.h = h; r_src.h = h;
sdl_real_blit(&r_src); sdl_real_blit(&r_src);
blitreq = 0; blitreq = 0;
return; return;
} }
SDL_LockMutex(sdl_mutex); SDL_LockMutex(sdl_mutex);
if (resize_pending) if (resize_pending) {
{ if (!video_fullscreen)
if (!video_fullscreen) sdl_resize(resize_w, resize_h); sdl_resize(resize_w, resize_h);
resize_pending = 0; resize_pending = 0;
} }
r_src.x = x; r_src.x = x;
@@ -211,27 +205,24 @@ static void
sdl_destroy_window(void) sdl_destroy_window(void)
{ {
if (sdl_win != NULL) { if (sdl_win != NULL) {
if (window_remember) if (window_remember) {
{ SDL_GetWindowSize(sdl_win, &window_w, &window_h);
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);
{ }
SDL_GetWindowPosition(sdl_win, &window_x, &window_y);
} }
} SDL_DestroyWindow(sdl_win);
SDL_DestroyWindow(sdl_win); sdl_win = NULL;
sdl_win = NULL;
} }
} }
static void static void
sdl_destroy_texture(void) sdl_destroy_texture(void)
{ {
/* SDL_DestroyRenderer also automatically destroys all associated textures. */ /* SDL_DestroyRenderer also automatically destroys all associated textures. */
if (sdl_render != NULL) { if (sdl_render != NULL) {
SDL_DestroyRenderer(sdl_render); SDL_DestroyRenderer(sdl_render);
sdl_render = NULL; sdl_render = NULL;
} }
} }
@@ -239,17 +230,17 @@ void
sdl_close(void) sdl_close(void)
{ {
if (sdl_mutex != NULL) if (sdl_mutex != NULL)
SDL_LockMutex(sdl_mutex); SDL_LockMutex(sdl_mutex);
/* Unregister our renderer! */ /* Unregister our renderer! */
video_setblit(NULL); video_setblit(NULL);
if (sdl_enabled) if (sdl_enabled)
sdl_enabled = 0; sdl_enabled = 0;
if (sdl_mutex != NULL) { if (sdl_mutex != NULL) {
SDL_DestroyMutex(sdl_mutex); SDL_DestroyMutex(sdl_mutex);
sdl_mutex = NULL; sdl_mutex = NULL;
} }
sdl_destroy_texture(); sdl_destroy_texture();
@@ -266,14 +257,14 @@ void
sdl_enable(int enable) sdl_enable(int enable)
{ {
if (sdl_flags == -1) if (sdl_flags == -1)
return; return;
SDL_LockMutex(sdl_mutex); SDL_LockMutex(sdl_mutex);
sdl_enabled = !!enable; sdl_enabled = !!enable;
if (enable == 1) { if (enable == 1) {
SDL_SetWindowSize(sdl_win, cur_ww, cur_wh); SDL_SetWindowSize(sdl_win, cur_ww, cur_wh);
sdl_reinit_texture(); sdl_reinit_texture();
} }
SDL_UnlockMutex(sdl_mutex); SDL_UnlockMutex(sdl_mutex);
@@ -282,16 +273,15 @@ sdl_enable(int enable)
static void static void
sdl_select_best_hw_driver(void) sdl_select_best_hw_driver(void)
{ {
int i; int i;
SDL_RendererInfo renderInfo; SDL_RendererInfo renderInfo;
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
{ SDL_GetRenderDriverInfo(i, &renderInfo);
SDL_GetRenderDriverInfo(i, &renderInfo); if (renderInfo.flags & SDL_RENDERER_ACCELERATED) {
if (renderInfo.flags & SDL_RENDERER_ACCELERATED) { SDL_SetHint(SDL_HINT_RENDER_DRIVER, renderInfo.name);
SDL_SetHint(SDL_HINT_RENDER_DRIVER, renderInfo.name); return;
return; }
}
} }
} }
@@ -301,14 +291,13 @@ sdl_reinit_texture()
sdl_destroy_texture(); sdl_destroy_texture();
if (sdl_flags & RENDERER_HARDWARE) { if (sdl_flags & RENDERER_HARDWARE) {
sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_ACCELERATED); sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_ACCELERATED);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0"); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0");
} else } 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_tex = SDL_CreateTexture(sdl_render, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING, 2048, 2048); SDL_TEXTUREACCESS_STREAMING, 2048, 2048);
} }
void void
@@ -316,14 +305,14 @@ sdl_set_fs(int fs)
{ {
SDL_LockMutex(sdl_mutex); SDL_LockMutex(sdl_mutex);
SDL_SetWindowFullscreen(sdl_win, fs ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); 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; sdl_fs = fs;
if (fs) if (fs)
sdl_flags |= RENDERER_FULL_SCREEN; sdl_flags |= RENDERER_FULL_SCREEN;
else else
sdl_flags &= ~RENDERER_FULL_SCREEN; sdl_flags &= ~RENDERER_FULL_SCREEN;
sdl_reinit_texture(); sdl_reinit_texture();
SDL_UnlockMutex(sdl_mutex); SDL_UnlockMutex(sdl_mutex);
@@ -335,10 +324,10 @@ sdl_resize(int x, int y)
int ww = 0, wh = 0, wx = 0, wy = 0; int ww = 0, wh = 0, wx = 0, wy = 0;
if (video_fullscreen & 2) if (video_fullscreen & 2)
return; return;
if ((x == cur_w) && (y == cur_h)) if ((x == cur_w) && (y == cur_h))
return; return;
SDL_LockMutex(sdl_mutex); SDL_LockMutex(sdl_mutex);
@@ -363,19 +352,18 @@ sdl_resize(int x, int y)
void void
sdl_reload(void) sdl_reload(void)
{ {
if (sdl_flags & RENDERER_HARDWARE) if (sdl_flags & RENDERER_HARDWARE) {
{ SDL_LockMutex(sdl_mutex);
SDL_LockMutex(sdl_mutex);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0"); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0");
sdl_reinit_texture(); sdl_reinit_texture();
SDL_UnlockMutex(sdl_mutex); SDL_UnlockMutex(sdl_mutex);
} }
} }
int int
plat_vidapi(char* api) plat_vidapi(char *api)
{ {
return 0; return 0;
} }
@@ -383,7 +371,7 @@ plat_vidapi(char* api)
static int static int
sdl_init_common(int flags) sdl_init_common(int flags)
{ {
wchar_t temp[128]; wchar_t temp[128];
SDL_version ver; SDL_version ver;
/* Get and log the version of the DLL we are using. */ /* Get and log the version of the DLL we are using. */
@@ -392,30 +380,27 @@ sdl_init_common(int flags)
/* Initialize the SDL system. */ /* Initialize the SDL system. */
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL: initialization failed (%s)\n", SDL_GetError()); fprintf(stderr, "SDL: initialization failed (%s)\n", SDL_GetError());
return(0); return (0);
} }
if (flags & RENDERER_HARDWARE) { if (flags & RENDERER_HARDWARE) {
if (flags & RENDERER_OPENGL) { if (flags & RENDERER_OPENGL) {
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "OpenGL"); SDL_SetHint(SDL_HINT_RENDER_DRIVER, "OpenGL");
} } else
else sdl_select_best_hw_driver();
sdl_select_best_hw_driver();
} }
sdl_mutex = SDL_CreateMutex(); 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); sdl_set_fs(video_fullscreen);
if (!(video_fullscreen & 1)) if (!(video_fullscreen & 1)) {
{
if (vid_resize & 2) if (vid_resize & 2)
plat_resize(fixed_size_x, fixed_size_y); plat_resize(fixed_size_x, fixed_size_y);
else 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); SDL_SetWindowSize(sdl_win, window_w, window_h);
} }
@@ -427,7 +412,7 @@ sdl_init_common(int flags)
sdl_enabled = 1; sdl_enabled = 1;
return(1); return (1);
} }
int int
@@ -436,61 +421,58 @@ sdl_inits()
return sdl_init_common(0); return sdl_init_common(0);
} }
int int
sdl_inith() sdl_inith()
{ {
return sdl_init_common(RENDERER_HARDWARE); return sdl_init_common(RENDERER_HARDWARE);
} }
int int
sdl_initho() sdl_initho()
{ {
return sdl_init_common(RENDERER_HARDWARE | RENDERER_OPENGL); return sdl_init_common(RENDERER_HARDWARE | RENDERER_OPENGL);
} }
int int
sdl_pause(void) sdl_pause(void)
{ {
return(0); return (0);
} }
void void
plat_mouse_capture(int on) plat_mouse_capture(int on)
{ {
SDL_LockMutex(sdl_mutex); SDL_LockMutex(sdl_mutex);
SDL_SetRelativeMouseMode((SDL_bool)on); SDL_SetRelativeMouseMode((SDL_bool) on);
mouse_capture = on; mouse_capture = on;
SDL_UnlockMutex(sdl_mutex); SDL_UnlockMutex(sdl_mutex);
} }
void plat_resize(int w, int h) void
plat_resize(int w, int h)
{ {
SDL_LockMutex(sdl_mutex); SDL_LockMutex(sdl_mutex);
resize_w = w; resize_w = w;
resize_h = h; resize_h = h;
resize_pending = 1; resize_pending = 1;
SDL_UnlockMutex(sdl_mutex); SDL_UnlockMutex(sdl_mutex);
} }
wchar_t sdl_win_title[512] = { L'8', L'6', L'B', L'o', L'x', 0 }; wchar_t sdl_win_title[512] = { L'8', L'6', L'B', L'o', L'x', 0 };
SDL_mutex* titlemtx = NULL; SDL_mutex *titlemtx = NULL;
void ui_window_title_real() void
ui_window_title_real()
{ {
char* res; char *res;
if (sizeof(wchar_t) == 1) if (sizeof(wchar_t) == 1) {
{ SDL_SetWindowTitle(sdl_win, (char *) sdl_win_title);
SDL_SetWindowTitle(sdl_win, (char*)sdl_win_title);
return; 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)); 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_SetWindowTitle(sdl_win, res);
SDL_free((void*)res); SDL_free((void *) res);
} }
title_set = 0; title_set = 0;
} }
@@ -498,9 +480,11 @@ extern SDL_threadID eventthread;
/* Only activate threading path on macOS, otherwise it will softlock Xorg. /* Only activate threading path on macOS, otherwise it will softlock Xorg.
Wayland doesn't seem to have this issue. */ 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__ #ifdef __APPLE__
if (eventthread == SDL_ThreadID()) if (eventthread == SDL_ThreadID())
#endif #endif
@@ -518,10 +502,17 @@ wchar_t* ui_window_title(wchar_t* str)
return str; return str;
} }
void ui_init_monitor(int monitor_index) {} void
void ui_deinit_monitor(int monitor_index) {} 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); atomic_store((&doresize_monitors[monitor_index]), 1);
} }

View File

@@ -7,30 +7,23 @@
#include <86box/plat.h> #include <86box/plat.h>
#include <86box/thread.h> #include <86box/thread.h>
typedef struct event_pthread_t {
typedef struct event_pthread_t pthread_cond_t cond;
{ pthread_mutex_t mutex;
pthread_cond_t cond; int state;
pthread_mutex_t mutex;
int state;
} event_pthread_t; } event_pthread_t;
typedef struct thread_param {
typedef struct thread_param void (*thread_rout)(void *);
{ void *param;
void (*thread_rout)(void*);
void * param;
} thread_param; } thread_param;
typedef struct pt_mutex_t {
typedef struct pt_mutex_t pthread_mutex_t mutex;
{
pthread_mutex_t mutex;
} pt_mutex_t; } pt_mutex_t;
void * void *
thread_run_wrapper(thread_param* arg) thread_run_wrapper(thread_param *arg)
{ {
thread_param localparam = *arg; thread_param localparam = *arg;
free(arg); free(arg);
@@ -38,28 +31,25 @@ thread_run_wrapper(thread_param* arg)
return NULL; return NULL;
} }
thread_t * thread_t *
thread_create(void (*thread_rout)(void *param), void *param) 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)); thread_param *thrparam = malloc(sizeof(thread_param));
thrparam->thread_rout = thread_rout; thrparam->thread_rout = thread_rout;
thrparam->param = param; 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; return thread;
} }
int int
thread_wait(thread_t *arg) thread_wait(thread_t *arg)
{ {
return pthread_join(*(pthread_t*)(arg), NULL); return pthread_join(*(pthread_t *) (arg), NULL);
} }
event_t * event_t *
thread_create_event() thread_create_event()
{ {
@@ -69,14 +59,13 @@ thread_create_event()
pthread_mutex_init(&event->mutex, NULL); pthread_mutex_init(&event->mutex, NULL);
event->state = 0; event->state = 0;
return (event_t *)event; return (event_t *) event;
} }
void void
thread_set_event(event_t *handle) 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); pthread_mutex_lock(&event->mutex);
event->state = 1; event->state = 1;
@@ -84,48 +73,45 @@ thread_set_event(event_t *handle)
pthread_mutex_unlock(&event->mutex); pthread_mutex_unlock(&event->mutex);
} }
void void
thread_reset_event(event_t *handle) 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); pthread_mutex_lock(&event->mutex);
event->state = 0; event->state = 0;
pthread_mutex_unlock(&event->mutex); pthread_mutex_unlock(&event->mutex);
} }
int int
thread_wait_event(event_t *handle, int timeout) thread_wait_event(event_t *handle, int timeout)
{ {
event_pthread_t *event = (event_pthread_t *)handle; event_pthread_t *event = (event_pthread_t *) handle;
struct timespec abstime; struct timespec abstime;
clock_gettime(CLOCK_REALTIME, &abstime); clock_gettime(CLOCK_REALTIME, &abstime);
abstime.tv_nsec += (timeout % 1000) * 1000000; abstime.tv_nsec += (timeout % 1000) * 1000000;
abstime.tv_sec += (timeout / 1000); abstime.tv_sec += (timeout / 1000);
if (abstime.tv_nsec > 1000000000) { if (abstime.tv_nsec > 1000000000) {
abstime.tv_nsec -= 1000000000; abstime.tv_nsec -= 1000000000;
abstime.tv_sec++; abstime.tv_sec++;
} }
pthread_mutex_lock(&event->mutex); pthread_mutex_lock(&event->mutex);
if (timeout == -1) { if (timeout == -1) {
while (!event->state) while (!event->state)
pthread_cond_wait(&event->cond, &event->mutex); pthread_cond_wait(&event->cond, &event->mutex);
} else if (!event->state) } 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); pthread_mutex_unlock(&event->mutex);
return 0; return 0;
} }
void void
thread_destroy_event(event_t *handle) 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_cond_destroy(&event->cond);
pthread_mutex_destroy(&event->mutex); pthread_mutex_destroy(&event->mutex);
@@ -133,7 +119,6 @@ thread_destroy_event(event_t *handle)
free(event); free(event);
} }
mutex_t * mutex_t *
thread_create_mutex(void) thread_create_mutex(void)
{ {
@@ -144,46 +129,40 @@ thread_create_mutex(void)
return mutex; return mutex;
} }
int int
thread_wait_mutex(mutex_t *_mutex) thread_wait_mutex(mutex_t *_mutex)
{ {
if (_mutex == NULL) if (_mutex == NULL)
return(0); return (0);
pt_mutex_t *mutex = (pt_mutex_t *)_mutex; pt_mutex_t *mutex = (pt_mutex_t *) _mutex;
return return pthread_mutex_lock(&mutex->mutex) != 0;
pthread_mutex_lock(&mutex->mutex) != 0;
} }
int int
thread_test_mutex(mutex_t *_mutex) thread_test_mutex(mutex_t *_mutex)
{ {
if (_mutex == NULL) if (_mutex == NULL)
return(0); return (0);
pt_mutex_t *mutex = (pt_mutex_t *)_mutex; pt_mutex_t *mutex = (pt_mutex_t *) _mutex;
return return pthread_mutex_trylock(&mutex->mutex) != 0;
pthread_mutex_trylock(&mutex->mutex) != 0;
} }
int int
thread_release_mutex(mutex_t *_mutex) thread_release_mutex(mutex_t *_mutex)
{ {
if (_mutex == NULL) if (_mutex == NULL)
return(0); return (0);
pt_mutex_t *mutex = (pt_mutex_t *)_mutex; pt_mutex_t *mutex = (pt_mutex_t *) _mutex;
return pthread_mutex_unlock(&mutex->mutex) != 0; return pthread_mutex_unlock(&mutex->mutex) != 0;
} }
void void
thread_close_mutex(mutex_t *_mutex) 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); pthread_mutex_destroy(&mutex->mutex);