From 3cec306ecf6ee9c4b2e64f78843d0d9a232de61e Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 4 Apr 2022 18:11:39 +0200 Subject: [PATCH 01/37] Device config fix, phase 1. --- src/device.c | 23 +++++++++++++++++++++++ src/include/86box/device.h | 1 + src/video/vid_table.c | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/device.c b/src/device.c index 136c11446..75ea59ff4 100644 --- a/src/device.c +++ b/src/device.c @@ -339,6 +339,29 @@ device_available(const device_t *d) } +int +device_has_config(const device_t *d) +{ + int c = 0; + + if (d == NULL) + return 0; + + if (d->config == NULL) + return 0; + + config = d->config; + + while (config->type != -1) { + if (config->type != CONFIG_MAC) + c++; + config++; + } + + return (c > 0) ? 1 : 0; +} + + int device_poll(const device_t *d, int x, int y, int z, int b) { diff --git a/src/include/86box/device.h b/src/include/86box/device.h index 28e9485ef..afd7c3731 100644 --- a/src/include/86box/device.h +++ b/src/include/86box/device.h @@ -147,6 +147,7 @@ extern void device_register_pci_slot(const device_t *d, int device, int type, i extern void device_speed_changed(void); extern void device_force_redraw(void); extern void device_get_name(const device_t *d, int bus, char *name); +extern int device_has_config(const device_t *d); extern int device_is_valid(const device_t *, int m); diff --git a/src/video/vid_table.c b/src/video/vid_table.c index ccd9c4071..02d5ad81c 100644 --- a/src/video/vid_table.c +++ b/src/video/vid_table.c @@ -364,7 +364,7 @@ video_card_has_config(int card) { if (video_cards[card].device == NULL) return(0); - return(video_cards[card].device->config ? 1 : 0); + return(device_has_config(video_cards[card].device) ? 1 : 0); } From 8714f7969376273505dec33fca92dd8395c335ca Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 4 Apr 2022 18:15:41 +0200 Subject: [PATCH 02/37] Phase 2 (Bug fix and Sound). --- src/device.c | 3 ++- src/sound/sound.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/device.c b/src/device.c index 75ea59ff4..501ae6b64 100644 --- a/src/device.c +++ b/src/device.c @@ -343,6 +343,7 @@ int device_has_config(const device_t *d) { int c = 0; + device_config_t *config; if (d == NULL) return 0; @@ -350,7 +351,7 @@ device_has_config(const device_t *d) if (d->config == NULL) return 0; - config = d->config; + config = (device_config_t *) d->config; while (config->type != -1) { if (config->type != CONFIG_MAC) diff --git a/src/sound/sound.c b/src/sound/sound.c index 5a3e978f6..5110b9c59 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -186,7 +186,7 @@ sound_card_has_config(int card) { if (!sound_cards[card].device) return 0; - return sound_cards[card].device->config ? 1 : 0; + return device_has_config(sound_cards[card].device) ? 1 : 0; } char * From 1a99a7cc6aa972d93aef0c798e8a009045504e23 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 4 Apr 2022 18:16:53 +0200 Subject: [PATCH 03/37] Phase 3 (Network and SCSI). --- src/network/network.c | 2 +- src/scsi/scsi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network/network.c b/src/network/network.c index a02000372..cb81ea154 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -630,7 +630,7 @@ network_card_has_config(int card) { if (! net_cards[card].device) return(0); - return(net_cards[card].device->config ? 1 : 0); + return(device_has_config(net_cards[card].device) ? 1 : 0); } diff --git a/src/scsi/scsi.c b/src/scsi/scsi.c index 7edfa1844..cf6f0207e 100644 --- a/src/scsi/scsi.c +++ b/src/scsi/scsi.c @@ -153,7 +153,7 @@ scsi_card_has_config(int card) { if (! scsi_cards[card].device) return(0); - return(scsi_cards[card].device->config ? 1 : 0); + return(device_had_config(scsi_cards[card].device) ? 1 : 0); } From b455d8f64d681312fbb39610274879e75552bfc6 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 4 Apr 2022 18:19:14 +0200 Subject: [PATCH 04/37] SCSI Bugfix, HDC, and FDC. --- src/disk/hdc.c | 2 +- src/floppy/fdc.c | 2 +- src/scsi/scsi.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/disk/hdc.c b/src/disk/hdc.c index 90d46a815..7ba9a0f1e 100644 --- a/src/disk/hdc.c +++ b/src/disk/hdc.c @@ -202,7 +202,7 @@ hdc_has_config(int hdc) if (dev == NULL) return(0); - if (dev->config == NULL) return(0); + if (!device_has_config(dev)) return(0); return(1); } diff --git a/src/floppy/fdc.c b/src/floppy/fdc.c index 171a77fa7..a28328587 100644 --- a/src/floppy/fdc.c +++ b/src/floppy/fdc.c @@ -154,7 +154,7 @@ fdc_card_has_config(int card) { if (! fdc_cards[card].device) return(0); - return(fdc_cards[card].device->config ? 1 : 0); + return(device_has_config(fdc_cards[card].device) ? 1 : 0); } diff --git a/src/scsi/scsi.c b/src/scsi/scsi.c index cf6f0207e..675abff26 100644 --- a/src/scsi/scsi.c +++ b/src/scsi/scsi.c @@ -153,7 +153,7 @@ scsi_card_has_config(int card) { if (! scsi_cards[card].device) return(0); - return(device_had_config(scsi_cards[card].device) ? 1 : 0); + return(device_has_config(scsi_cards[card].device) ? 1 : 0); } From 4b09a6329aa8b5cb9392c5bab7a97e152b7d9fef Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 5 Apr 2022 02:16:23 +0600 Subject: [PATCH 05/37] Multiple ROM paths implementation --- src/86box.c | 129 +++++++++++++++++++++++++++++++++++----- src/include/86box/rom.h | 7 +++ src/mem/rom.c | 12 +++- 3 files changed, 132 insertions(+), 16 deletions(-) diff --git a/src/86box.c b/src/86box.c index db0182d84..a645d88d6 100644 --- a/src/86box.c +++ b/src/86box.c @@ -32,6 +32,7 @@ #ifndef _WIN32 #include +#include #endif #ifdef __APPLE__ #include @@ -125,6 +126,7 @@ uint64_t unique_id = 0; uint64_t source_hwnd = 0; #endif char rom_path[1024] = { '\0'}; /* (O) full path to ROMs */ +rom_path_t rom_paths = { "", NULL }; /* (O) full paths to ROMs */ char log_path[1024] = { '\0'}; /* (O) full path of logfile */ char vm_name[1024] = { '\0'}; /* (O) display name of the VM */ @@ -383,6 +385,48 @@ pc_log(const char *fmt, ...) #define pc_log(fmt, ...) #endif +static void +add_rom_path(const char* path) +{ + static char cwd[1024]; + memset(cwd, 0x00, sizeof(cwd)); + rom_path_t* cur_rom_path = &rom_paths; + while (cur_rom_path->next != NULL) { + cur_rom_path = cur_rom_path->next; + } + if (!plat_path_abs((char*)path)) { + /* + * This looks like a relative path. + * + * Add it to the current working directory + * to convert it (back) to an absolute path. + */ + plat_getcwd(cwd, 1024); + plat_path_slash(cwd); + snprintf(cur_rom_path->rom_path, 1024, "%s%s%c", cwd, path, 0); + } + else { + /* + * The user-provided path seems like an + * absolute path, so just use that. + */ + strncpy(cur_rom_path->rom_path, path, 1024); + } + plat_path_slash(cur_rom_path->rom_path); + cur_rom_path->next = calloc(1, sizeof(rom_path_t)); +} + +// Copied over from Unix code, which in turn is lifted from musl. Needed for parsing XDG_DATA_DIRS. +static 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; +} /* * Perform initial startup of the PC. @@ -496,6 +540,7 @@ usage: if ((c+1) == argc) goto usage; strcpy(path2, argv[++c]); + add_rom_path(path2); } else if (!strcasecmp(argv[c], "--config") || !strcasecmp(argv[c], "-C")) { if ((c+1) == argc) goto usage; @@ -591,26 +636,77 @@ usage: plat_dir_create(usr_path); } - if (path2[0] == '\0') { + if (vmrp) { + char vmrppath[1024] = { 0 }; + strcpy(vmrppath, usr_path); + plat_path_slash(vmrppath); + strcat(vmrppath, "roms"); + plat_path_slash(vmrppath); + add_rom_path(vmrppath); + if (path2[0] == '\0') { + strcpy(path2, vmrppath); + } + } + + { + char default_rom_path[1024] = { 0 }; #if defined(__APPLE__) - getDefaultROMPath(path2); + getDefaultROMPath(default_rom_path); #elif !defined(_WIN32) appimage = getenv("APPIMAGE"); if (appimage && (appimage[0] != '\0')) { - plat_get_dirname(path2, appimage); - plat_path_slash(path2); - strcat(path2, "roms"); - plat_path_slash(path2); + plat_get_dirname(default_rom_path, appimage); + plat_path_slash(default_rom_path); + strcat(default_rom_path, "roms"); + plat_path_slash(default_rom_path); } #endif + if (default_rom_path[0] == '\0') { + plat_getcwd(default_rom_path, 1024); + plat_path_slash(default_rom_path); + snprintf(default_rom_path, 1024, "%s%s%c", default_rom_path, "roms", 0); + plat_path_slash(default_rom_path); + } + add_rom_path(default_rom_path); + if (path2[0] == '\0') { + strcpy(path2, default_rom_path); + } } - if (vmrp && (path2[0] == '\0')) { - strcpy(path2, usr_path); - plat_path_slash(path2); - strcat(path2, "roms"); - plat_path_slash(path2); - } +#if !defined __APPLE__ && !defined _WIN32 + if (getenv("XDG_DATA_HOME")) { + char xdg_rom_path[1024] = { 0 }; + strncpy(xdg_rom_path, getenv("XDG_DATA_HOME"), 1024); + plat_path_slash(xdg_rom_path); + strcat(xdg_rom_path, "86Box/roms/"); + add_rom_path(xdg_rom_path); + } else { + char home_rom_path[1024] = { 0 }; + snprintf(home_rom_path, 1024, "%s/.local/share/86Box/roms/", getenv("HOME") ? getenv("HOME") : getpwuid(getuid())->pw_dir); + add_rom_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; + if (xdg_rom_paths) { + while (xdg_rom_paths[strlen(xdg_rom_paths) - 1] == ':') { + xdg_rom_paths[strlen(xdg_rom_paths) - 1] = '\0'; + } + while ((cur_xdg_rom_path = local_strsep(&xdg_rom_paths, ";")) != NULL) { + char real_xdg_rom_path[1024] = { '\0' }; + strcat(real_xdg_rom_path, cur_xdg_rom_path); + plat_path_slash(real_xdg_rom_path); + strcat(real_xdg_rom_path, "86Box/roms/"); + add_rom_path(real_xdg_rom_path); + } + } + free(xdg_rom_paths_orig); + } else { + add_rom_path("/usr/local/share/86Box/roms/"); + add_rom_path("/usr/share/86Box/roms/"); + } +#endif /* * If the user provided a path for ROMs, use that @@ -708,8 +804,13 @@ usage: pclog("# VM: %s\n#\n", vm_name); pclog("# Emulator path: %s\n", exe_path); pclog("# Userfiles path: %s\n", usr_path); - if (rom_path[0] != '\0') - pclog("# ROM path: %s\n", rom_path); + if (rom_paths.next) { + rom_path_t* cur_rom_path = &rom_paths; + while (cur_rom_path->next) { + pclog("# ROM path: %s\n", cur_rom_path->rom_path); + cur_rom_path = cur_rom_path->next; + } + } else #ifndef _WIN32 pclog("# ROM path: %sroms/\n", exe_path); diff --git a/src/include/86box/rom.h b/src/include/86box/rom.h index dfea9f0b5..63500d912 100644 --- a/src/include/86box/rom.h +++ b/src/include/86box/rom.h @@ -41,6 +41,13 @@ typedef struct { } rom_t; +typedef struct rom_path_t { + char rom_path[1024]; + struct rom_path_t* next; +} rom_path_t; + +extern rom_path_t rom_paths; + extern uint8_t rom_read(uint32_t addr, void *p); extern uint16_t rom_readw(uint32_t addr, void *p); extern uint32_t rom_readl(uint32_t addr, void *p); diff --git a/src/mem/rom.c b/src/mem/rom.c index 30e873a4e..907c090ee 100644 --- a/src/mem/rom.c +++ b/src/mem/rom.c @@ -69,11 +69,19 @@ rom_fopen(char *fn, char *mode) fn2 = (char *) malloc(strlen(fn) + 1); memcpy(fn2, fn, strlen(fn) + 1); - if (rom_path[0] != '\0') { + if (rom_paths.next) { + rom_path_t* cur_rom_path = &rom_paths; memset(fn2, 0x00, strlen(fn) + 1); memcpy(fn2, &(fn[5]), strlen(fn) - 4); - plat_append_filename(temp, rom_path, fn2); + while (cur_rom_path->next) { + memset(temp, 0, sizeof(temp)); + plat_append_filename(temp, cur_rom_path->rom_path, fn2); + if (rom_present(temp)) { + break; + } + cur_rom_path = cur_rom_path->next; + } } else { /* Make sure to make it a backslash, just in case there's malformed code calling us that assumes Windows. */ From d0191d492884beb427fce733702d8b8eecb8f168 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 5 Apr 2022 15:25:48 +0600 Subject: [PATCH 06/37] Create ROM directories in home folder on Unix if they doesn't exist --- src/86box.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/86box.c b/src/86box.c index a645d88d6..73eb582a4 100644 --- a/src/86box.c +++ b/src/86box.c @@ -678,11 +678,25 @@ usage: char xdg_rom_path[1024] = { 0 }; strncpy(xdg_rom_path, getenv("XDG_DATA_HOME"), 1024); plat_path_slash(xdg_rom_path); - strcat(xdg_rom_path, "86Box/roms/"); + strncat(xdg_rom_path, "86Box/", 1024); + + if (!plat_dir_check(xdg_rom_path)) + plat_dir_create(xdg_rom_path); + strcat(xdg_rom_path, "roms/"); + + if (!plat_dir_check(xdg_rom_path)) + plat_dir_create(xdg_rom_path); add_rom_path(xdg_rom_path); } else { char home_rom_path[1024] = { 0 }; - snprintf(home_rom_path, 1024, "%s/.local/share/86Box/roms/", getenv("HOME") ? getenv("HOME") : getpwuid(getuid())->pw_dir); + snprintf(home_rom_path, 1024, "%s/.local/share/86Box/", getenv("HOME") ? getenv("HOME") : getpwuid(getuid())->pw_dir); + + if (!plat_dir_check(home_rom_path)) + plat_dir_create(home_rom_path); + strcat(home_rom_path, "roms/"); + + if (!plat_dir_check(home_rom_path)) + plat_dir_create(home_rom_path); add_rom_path(home_rom_path); } if (getenv("XDG_DATA_DIRS")) { From 2c63f5b4977d8a972fd074cc4aa75c6930b8bd2e Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 6 Apr 2022 00:18:17 +0600 Subject: [PATCH 07/37] rom_getfile now works properly --- src/mem/rom.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/src/mem/rom.c b/src/mem/rom.c index 907c090ee..3dcbfe568 100644 --- a/src/mem/rom.c +++ b/src/mem/rom.c @@ -105,17 +105,54 @@ rom_fopen(char *fn, char *mode) int rom_getfile(char *fn, char *s, int size) { - FILE *f; + char temp[1024] = {'\0'}; + char *fn2; + int retval = 0; - plat_append_filename(s, exe_path, fn); + if ((strstr(fn, "roms/") == fn) || (strstr(fn, "roms\\") == fn)) { + /* Relative path */ + fn2 = (char *) malloc(strlen(fn) + 1); + memcpy(fn2, fn, strlen(fn) + 1); - f = plat_fopen(s, "rb"); - if (f != NULL) { - (void)fclose(f); - return(1); + if (rom_paths.next) { + rom_path_t* cur_rom_path = &rom_paths; + memset(fn2, 0x00, strlen(fn) + 1); + memcpy(fn2, &(fn[5]), strlen(fn) - 4); + + while (cur_rom_path->next) { + memset(temp, 0, sizeof(temp)); + plat_append_filename(temp, cur_rom_path->rom_path, fn2); + if (rom_present(temp)) { + strncpy(s, temp, size); + retval = 1; + break; + } + cur_rom_path = cur_rom_path->next; + } + } else { + /* Make sure to make it a backslash, just in case there's malformed + code calling us that assumes Windows. */ + if (fn2[4] == '\\') + fn2[4] = '/'; + + plat_append_filename(temp, exe_path, fn2); + if (rom_present(temp)) { + strncpy(s, temp, size); + retval = 1; + } } - return(0); + free(fn2); + fn2 = NULL; + } else { + /* Absolute path */ + if (rom_present(fn)) { + strncpy(s, fn, size); + retval = 1; + } + } + + return(retval); } From 1a3a7bec0e2af25ad03b95ff9b27d948b0996cee Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 6 Apr 2022 16:16:25 +0600 Subject: [PATCH 08/37] Move platform-specific ROM path adding code into plat modules --- src/86box.c | 51 ++-------------------------------- src/include/86box/plat.h | 1 + src/include/86box/rom.h | 2 ++ src/qt/qt_platform.cpp | 59 ++++++++++++++++++++++++++++++++++++++++ src/unix/unix.c | 55 +++++++++++++++++++++++++++++++++++++ src/win/win.c | 26 ++++++++++++++++++ 6 files changed, 145 insertions(+), 49 deletions(-) diff --git a/src/86box.c b/src/86box.c index 73eb582a4..4eae7ab02 100644 --- a/src/86box.c +++ b/src/86box.c @@ -385,7 +385,7 @@ pc_log(const char *fmt, ...) #define pc_log(fmt, ...) #endif -static void +void add_rom_path(const char* path) { static char cwd[1024]; @@ -673,54 +673,7 @@ usage: } } -#if !defined __APPLE__ && !defined _WIN32 - if (getenv("XDG_DATA_HOME")) { - char xdg_rom_path[1024] = { 0 }; - strncpy(xdg_rom_path, getenv("XDG_DATA_HOME"), 1024); - plat_path_slash(xdg_rom_path); - strncat(xdg_rom_path, "86Box/", 1024); - - if (!plat_dir_check(xdg_rom_path)) - plat_dir_create(xdg_rom_path); - strcat(xdg_rom_path, "roms/"); - - if (!plat_dir_check(xdg_rom_path)) - plat_dir_create(xdg_rom_path); - add_rom_path(xdg_rom_path); - } else { - char home_rom_path[1024] = { 0 }; - snprintf(home_rom_path, 1024, "%s/.local/share/86Box/", getenv("HOME") ? getenv("HOME") : getpwuid(getuid())->pw_dir); - - if (!plat_dir_check(home_rom_path)) - plat_dir_create(home_rom_path); - strcat(home_rom_path, "roms/"); - - if (!plat_dir_check(home_rom_path)) - plat_dir_create(home_rom_path); - add_rom_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; - if (xdg_rom_paths) { - while (xdg_rom_paths[strlen(xdg_rom_paths) - 1] == ':') { - xdg_rom_paths[strlen(xdg_rom_paths) - 1] = '\0'; - } - while ((cur_xdg_rom_path = local_strsep(&xdg_rom_paths, ";")) != NULL) { - char real_xdg_rom_path[1024] = { '\0' }; - strcat(real_xdg_rom_path, cur_xdg_rom_path); - plat_path_slash(real_xdg_rom_path); - strcat(real_xdg_rom_path, "86Box/roms/"); - add_rom_path(real_xdg_rom_path); - } - } - free(xdg_rom_paths_orig); - } else { - add_rom_path("/usr/local/share/86Box/roms/"); - add_rom_path("/usr/share/86Box/roms/"); - } -#endif + plat_init_rom_paths(); /* * If the user provided a path for ROMs, use that diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 71ad89927..ad7006165 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -104,6 +104,7 @@ extern int plat_getcwd(char *bufp, int max); extern int plat_chdir(char *path); extern void plat_tempfile(char *bufp, char *prefix, char *suffix); extern void plat_get_exe_name(char *s, int size); +extern void plat_init_rom_paths(); extern char *plat_get_basename(const char *path); extern void plat_get_dirname(char *dest, const char *path); extern char *plat_get_filename(char *s); diff --git a/src/include/86box/rom.h b/src/include/86box/rom.h index 63500d912..04fe94422 100644 --- a/src/include/86box/rom.h +++ b/src/include/86box/rom.h @@ -48,6 +48,8 @@ typedef struct rom_path_t { extern rom_path_t rom_paths; +extern void add_rom_path(const char* path); + extern uint8_t rom_read(uint32_t addr, void *p); extern uint16_t rom_readw(uint32_t addr, void *p); extern uint32_t rom_readl(uint32_t addr, void *p); diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 508103169..c48a84020 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -88,6 +88,8 @@ extern "C" { #include <86box/timer.h> #include <86box/nvr.h> #include <86box/plat_dynld.h> +#include <86box/mem.h> +#include <86box/rom.h> #include <86box/config.h> #include <86box/ui.h> #include <86box/discord.h> @@ -583,3 +585,60 @@ plat_chdir(char *path) { return QDir::setCurrent(QString(path)) ? 0 : -1; } + +void +plat_init_rom_paths() +{ +#if !defined __APPLE__ && !defined _WIN32 + if (getenv("XDG_DATA_HOME")) { + char xdg_rom_path[1024] = { 0 }; + strncpy(xdg_rom_path, getenv("XDG_DATA_HOME"), 1024); + plat_path_slash(xdg_rom_path); + strncat(xdg_rom_path, "86Box/", 1024); + + if (!plat_dir_check(xdg_rom_path)) + plat_dir_create(xdg_rom_path); + strcat(xdg_rom_path, "roms/"); + + if (!plat_dir_check(xdg_rom_path)) + plat_dir_create(xdg_rom_path); + add_rom_path(xdg_rom_path); + } else { + char home_rom_path[1024] = { 0 }; + snprintf(home_rom_path, 1024, "%s/.local/share/86Box/", getenv("HOME") ? getenv("HOME") : QDir::homePath().toUtf8().constData()); + + if (!plat_dir_check(home_rom_path)) + plat_dir_create(home_rom_path); + strcat(home_rom_path, "roms/"); + + if (!plat_dir_check(home_rom_path)) + plat_dir_create(home_rom_path); + add_rom_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; + if (xdg_rom_paths) { + while (xdg_rom_paths[strlen(xdg_rom_paths) - 1] == ':') { + xdg_rom_paths[strlen(xdg_rom_paths) - 1] = '\0'; + } + QStringList path_list = QString(xdg_rom_paths).split(":", Qt::SkipEmptyParts); + for (auto& cur_path : path_list) { + if (cur_path.right(1) != '/') + cur_path.push_back('/'); + add_rom_path((cur_path + "86Box/roms").toUtf8().constData()); + } + } + free(xdg_rom_paths_orig); + } else { + add_rom_path("/usr/local/share/86Box/roms/"); + add_rom_path("/usr/share/86Box/roms/"); + } +#elif _WIN32 + auto appDataDir = QDir(qEnvironmentVariable("LOCALAPPDATA")); + appDataDir.mkdir("86Box"); + appDataDir.mkdir("86Box/roms"); + add_rom_path((appDataDir.path().replace("\\","/") + "/86Box/roms").toUtf8().constData()); +#endif +} diff --git a/src/unix/unix.c b/src/unix/unix.c index 1f60ad565..1c8917626 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -21,6 +21,8 @@ #include #include <86box/86box.h> +#include <86box/mem.h> +#include <86box/rom.h> #include <86box/keyboard.h> #include <86box/mouse.h> #include <86box/config.h> @@ -744,6 +746,59 @@ plat_pause(int p) } } +void +plat_init_rom_paths() +{ +#ifndef __APPLE__ + if (getenv("XDG_DATA_HOME")) { + char xdg_rom_path[1024] = { 0 }; + strncpy(xdg_rom_path, getenv("XDG_DATA_HOME"), 1024); + plat_path_slash(xdg_rom_path); + strncat(xdg_rom_path, "86Box/", 1024); + + if (!plat_dir_check(xdg_rom_path)) + plat_dir_create(xdg_rom_path); + strcat(xdg_rom_path, "roms/"); + + if (!plat_dir_check(xdg_rom_path)) + plat_dir_create(xdg_rom_path); + add_rom_path(xdg_rom_path); + } else { + char home_rom_path[1024] = { 0 }; + snprintf(home_rom_path, 1024, "%s/.local/share/86Box/", getenv("HOME") ? getenv("HOME") : getpwuid(getuid())->pw_dir); + + if (!plat_dir_check(home_rom_path)) + plat_dir_create(home_rom_path); + strcat(home_rom_path, "roms/"); + + if (!plat_dir_check(home_rom_path)) + plat_dir_create(home_rom_path); + add_rom_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; + if (xdg_rom_paths) { + while (xdg_rom_paths[strlen(xdg_rom_paths) - 1] == ':') { + xdg_rom_paths[strlen(xdg_rom_paths) - 1] = '\0'; + } + while ((cur_xdg_rom_path = local_strsep(&xdg_rom_paths, ";")) != NULL) { + char real_xdg_rom_path[1024] = { '\0' }; + strcat(real_xdg_rom_path, cur_xdg_rom_path); + plat_path_slash(real_xdg_rom_path); + strcat(real_xdg_rom_path, "86Box/roms/"); + add_rom_path(real_xdg_rom_path); + } + } + free(xdg_rom_paths_orig); + } else { + add_rom_path("/usr/local/share/86Box/roms/"); + add_rom_path("/usr/share/86Box/roms/"); + } +#endif +} + bool process_media_commands_3(uint8_t* id, char* fn, uint8_t* wp, int cmdargc) { bool err = false; diff --git a/src/win/win.c b/src/win/win.c index f4b906d7d..06db20bad 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -45,6 +45,8 @@ #include <86box/timer.h> #include <86box/nvr.h> #include <86box/video.h> +#include <86box/mem.h> +#include <86box/rom.h> #define GLOBAL #include <86box/plat.h> #include <86box/ui.h> @@ -910,6 +912,30 @@ plat_mmap(size_t size, uint8_t executable) } +void +plat_init_rom_paths() +{ + wchar_t appdata_dir[1024] = { L'\0' }; + + if (_wgetenv("LOCALAPPDATA") && _wgetenv("LOCALAPPDATA")[0] != L'\0') { + char appdata_dir_a[1024] = { '\0' }; + size_t len = 0; + wcsncpy(appdata_dir, _wgetenv("LOCALAPPDATA"), 1024); + len = wcslen(appdata_dir); + if (appdata_dir[len - 1] != L'\\') { + appdata_dir[len] = L'\\'; + appdata_dir[len + 1] = L'\0'; + } + wcscat(appdata_dir, "86box"); + CreateDirectoryW(appdata_dir, NULL); + wcscat(appdata_dir, "\\roms"); + CreateDirectoryW(appdata_dir, NULL); + wcscat(appdata_dir, "\\"); + c16stombs(appdata_dir_a, appdata_dir, 1024); + add_rom_path(appdata_dir_a); + } +} + void plat_munmap(void *ptr, size_t size) { From f8c53dec3ab9f524e007817a6012a743313a41da Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 6 Apr 2022 19:56:30 +0600 Subject: [PATCH 09/37] qt: Fix compilation on Linux --- src/qt/qt_platform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index c48a84020..2033421b8 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -623,7 +623,7 @@ plat_init_rom_paths() while (xdg_rom_paths[strlen(xdg_rom_paths) - 1] == ':') { xdg_rom_paths[strlen(xdg_rom_paths) - 1] = '\0'; } - QStringList path_list = QString(xdg_rom_paths).split(":", Qt::SkipEmptyParts); + QStringList path_list = QString(xdg_rom_paths).split(":"); for (auto& cur_path : path_list) { if (cur_path.right(1) != '/') cur_path.push_back('/'); From e860c480b841a5410d34fb5874da096b786e955f Mon Sep 17 00:00:00 2001 From: richardg867 Date: Wed, 6 Apr 2022 15:27:10 -0300 Subject: [PATCH 10/37] Jenkins: Add MacPorts dependencies file --- .ci/dependencies_macports.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .ci/dependencies_macports.txt diff --git a/.ci/dependencies_macports.txt b/.ci/dependencies_macports.txt new file mode 100644 index 000000000..4171a0a69 --- /dev/null +++ b/.ci/dependencies_macports.txt @@ -0,0 +1,10 @@ +cmake@3.22.3_0 +pkgconfig@0.29.2_0 +ninja@1.10.2_4 +freetype@2.11.1_0 +libsdl2@2.0.20_0 +libpng@1.6.37_0 +openal-soft@1.21.1_0 +rtmidi@5.0.0_0 +qt5@5.15.3_0 +wget From e1906c03b3fa015f7b2f6443c1f599905d577a30 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Wed, 6 Apr 2022 15:28:23 -0300 Subject: [PATCH 11/37] Jenkins: Add macOS to the build script --- .ci/build.sh | 86 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index 0a1eb9ef3..9d476f6b7 100644 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -28,9 +28,13 @@ # - Packaging the Discord DLL requires wget (MSYS should come with it) # - For Linux builds: # - Only Debian and derivatives are supported -# - dpkg and apt-get are called through sudo to manage dependencies +# - dpkg and apt-get are called through sudo to manage dependencies; make sure those +# are configured as NOPASSWD in /etc/sudoers if you're doing unattended builds # - For macOS builds: -# - TBD +# - A standard MacPorts installation is required, with the following macports.conf settings: +# +# - port is called through sudo to manage dependencies; make sure it is configured +# as NOPASSWD in /etc/sudoers if you're doing unattended builds # # Define common functions. @@ -178,13 +182,16 @@ fi echo [-] Building [$package_name] for [$arch] with flags [$cmake_flags] # Determine CMake toolchain file for this architecture. +toolchain_prefix=flags-gcc +is_mac && toolchain_prefix=llvm-macos case $arch in - 32 | x86) toolchain="flags-gcc-i686";; - 64 | x86_64) toolchain="flags-gcc-x86_64";; - ARM32 | arm32) toolchain="flags-gcc-armv7";; - ARM64 | arm64) toolchain="flags-gcc-aarch64";; - *) toolchain="flags-gcc-$arch";; + 32 | x86) toolchain="$toolchain_prefix-i686";; + 64 | x86_64) toolchain="$toolchain_prefix-x86_64";; + ARM32 | arm32) toolchain="$toolchain_prefix-armv7";; + ARM64 | arm64) toolchain="$toolchain_prefix-aarch64";; + *) toolchain="$toolchain_prefix-$arch";; esac +[ ! -e "cmake/$toolchain.cmake" ] && toolchain=flags-gcc # Perform platform-specific setup. strip_binary=strip @@ -313,11 +320,19 @@ then fi # Point CMake to the toolchain file. - cmake_flags_extra="$cmake_flags_extra -D \"CMAKE_TOOLCHAIN_FILE=cmake/$toolchain.cmake\"" + [ -e "cmake/$toolchain.cmake" ] && cmake_flags_extra="$cmake_flags_extra -D \"CMAKE_TOOLCHAIN_FILE=cmake/$toolchain.cmake\"" elif is_mac then # macOS lacks nproc, but sysctl can do the same job. alias nproc='sysctl -n hw.logicalcpu' + + # Install dependencies. + echo [-] Installing dependencies through MacPorts + sudo port selfupdate + sudo port install $(cat .ci/dependencies_macports.txt) + + # Point CMake to the toolchain file. + [ -e "cmake/$toolchain.cmake" ] && cmake_flags_extra="$cmake_flags_extra -D \"CMAKE_TOOLCHAIN_FILE=cmake/$toolchain.cmake\"" else # Determine Debian architecture. case $arch in @@ -350,18 +365,18 @@ else [ $length -gt $longest_libpkg ] && longest_libpkg=$length done - # Determine GNU toolchain architecture. + # Determine toolchain architecture triplet. case $arch in - x86) arch_gnu="i686-linux-gnu";; - arm32) arch_gnu="arm-linux-gnueabihf";; - arm64) arch_gnu="aarch64-linux-gnu";; - *) arch_gnu="$arch-linux-gnu";; + x86) arch_triplet="i686-linux-gnu";; + arm32) arch_triplet="arm-linux-gnueabihf";; + arm64) arch_triplet="aarch64-linux-gnu";; + *) arch_triplet="$arch-linux-gnu";; esac # Determine library directory name for this architecture. case $arch in x86) libdir="i386-linux-gnu";; - *) libdir="$arch_gnu";; + *) libdir="$arch_triplet";; esac # Create CMake toolchain file. @@ -369,15 +384,15 @@ else set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR $arch) -set(CMAKE_AR $arch_gnu-ar) -set(CMAKE_ASM_COMPILER $arch_gnu-gcc) -set(CMAKE_C_COMPILER $arch_gnu-gcc) -set(CMAKE_CXX_COMPILER $arch_gnu-g++) -set(CMAKE_LINKER $arch_gnu-ld) -set(CMAKE_OBJCOPY $arch_gnu-objcopy) -set(CMAKE_RANLIB $arch_gnu-ranlib) -set(CMAKE_SIZE $arch_gnu-size) -set(CMAKE_STRIP $arch_gnu-strip) +set(CMAKE_AR $arch_triplet-ar) +set(CMAKE_ASM_COMPILER $arch_triplet-gcc) +set(CMAKE_C_COMPILER $arch_triplet-gcc) +set(CMAKE_CXX_COMPILER $arch_triplet-g++) +set(CMAKE_LINKER $arch_triplet-ld) +set(CMAKE_OBJCOPY $arch_triplet-objcopy) +set(CMAKE_RANLIB $arch_triplet-ranlib) +set(CMAKE_SIZE $arch_triplet-size) +set(CMAKE_STRIP $arch_triplet-strip) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) @@ -389,7 +404,7 @@ set(ENV{PKG_CONFIG_LIBDIR} "/usr/lib/$libdir/pkgconfig:/usr/share/$libdir/pkgcon include("$(pwd)/cmake/$toolchain.cmake") EOF cmake_flags_extra="$cmake_flags_extra -D CMAKE_TOOLCHAIN_FILE=toolchain.cmake" - strip_binary="$arch_gnu-strip" + strip_binary="$arch_triplet-strip" # Install or update dependencies. echo [-] Installing dependencies through apt @@ -524,8 +539,21 @@ then fi elif is_mac then - # TBD - : + # Archive app bundle with libraries. + cmake_flags_install= + [ $strip -ne 0 ] && cmake_flags_install="$cmake_flags_install --strip" + cmake --install build --prefix "$(pwd)/archive_tmp" $cmake_flags_install + status=$? + + if [ $status -eq 0 ] + then + # Archive Discord Game SDK library. + unzip discord_game_sdk.zip "lib/$arch_discord/discord_game_sdk.dylib" -d "archive_tmp/"*".app/Contents/Frameworks" + [ ! -e "archive_tmp/"*".app/Contents/Frameworks/discord_game_sdk.dylib" ] && echo [!] No Discord Game SDK for architecture [$arch_discord] + + # Sign app bundle. + codesign --force --deep -s - "archive_tmp/"*".app" + fi else cwd_root=$(pwd) @@ -643,8 +671,10 @@ then status=$? elif is_mac then - # TBD - : + # Create zip. (TODO: dmg) + cd archive_tmp + zip -r "$cwd/$package_name.zip" . + status=$? else # Determine AppImage runtime architecture. case $arch in From ce7a1ad1c1d8e6dbc5f3c1ed81d6ef95132bff24 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Wed, 6 Apr 2022 15:38:27 -0300 Subject: [PATCH 12/37] Jenkins: Use OpenAL on macOS --- .ci/build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.ci/build.sh b/.ci/build.sh index 9d476f6b7..4e164bcdf 100644 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -333,6 +333,9 @@ then # Point CMake to the toolchain file. [ -e "cmake/$toolchain.cmake" ] && cmake_flags_extra="$cmake_flags_extra -D \"CMAKE_TOOLCHAIN_FILE=cmake/$toolchain.cmake\"" + + # Use OpenAL. + cmake_flags_extra="$cmake_flags_extra -D OPENAL=ON" else # Determine Debian architecture. case $arch in From 7f27f44b3a6a24f711466319c8e80a2faa7b217f Mon Sep 17 00:00:00 2001 From: richardg867 Date: Wed, 6 Apr 2022 15:39:32 -0300 Subject: [PATCH 13/37] Jenkins: Add macOS Intel to Jenkinsfile --- .ci/Jenkinsfile | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 3d4fa7e13..e9fd8b986 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -16,20 +16,22 @@ */ /* ['main builds', 'branch builds'] */ -def repository = ['https://github.com/86Box/86Box.git', 'https://github.com/richardg867/86Box.git'] +def repository = ['https://github.com/86Box/86Box.git', scm.userRemoteConfigs[0].url] def commitBrowser = ['https://github.com/86Box/86Box/commit/%s', null] -def branch = ['master', 'cleanup30'] +def branch = ['master', scm.branches[0].name] def buildType = ['beta', 'alpha'] def buildBranch = env.JOB_BASE_NAME.contains('-') ? 1 : 0 def osArchs = [ 'Windows': ['32', '64'], - 'Linux': ['x86', 'x86_64', 'arm32', 'arm64'] + 'Linux': ['x86', 'x86_64', 'arm32', 'arm64'], + 'macOS': ['x86_64'] ] def osFlags = [ 'Windows': '-D QT=ON', - 'Linux': '-D QT=ON' + 'Linux': '-D QT=ON', + 'macOS': '-D QT=ON' ] def archNames = [ @@ -41,6 +43,11 @@ def archNames = [ 'arm64': 'ARM (64-bit)' ] +def archNamesMac = [ + 'x86_64': 'Intel', + 'arm64': 'Apple Silicon' +] + def dynarecNames = [ 'ODR': 'Old Recompiler (recommended)', 'NDR': 'New Recompiler (beta)', @@ -53,9 +60,7 @@ def dynarecArchs = [ '64': ['ODR', 'NDR'], 'x86_64': ['ODR', 'NDR'], 'arm32': ['NDR'], - 'ARM32': ['NDR'], - 'arm64': ['NDR'], - 'ARM64': ['NDR'] + 'arm64': ['NDR'] ] def dynarecFlags = [ @@ -238,7 +243,7 @@ pipeline { osArchs.each { os, thisOsArchs -> def combinations = [:] thisOsArchs.each { arch -> - def thisArchDynarecs = dynarecArchs[arch] + def thisArchDynarecs = dynarecArchs[arch.toLowerCase()] if (!thisArchDynarecs) thisArchDynarecs = ['NoDR'] thisArchDynarecs.each { dynarec -> @@ -257,7 +262,10 @@ pipeline { /* Run build process. */ def packageName = "${env.JOB_BASE_NAME}${dynarecSlugs[dynarec]}${presetSlugs[preset]}-$os-$arch$buildSuffix" def ret = -1 - dir("${dynarecNames[dynarec]}/$os - ${archNames[arch]}") { + def archName = archNames[arch] + if (os == 'macOS') + archName = archNamesMac[arch] + dir("${dynarecNames[dynarec]}/$os - $archName") { ret = runBuild("-b \"$packageName\" \"$arch\" ${presetFlags[preset]} ${dynarecFlags[dynarec]} ${osFlags[os]} $buildFlags") } From 0fd3042e0cf18ed58657062ce2c1925e6bafdcec Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 7 Apr 2022 00:57:16 +0600 Subject: [PATCH 14/37] qt: Add support for loading ROMs from ~/Documents/86Box/roms on macOS --- src/qt/qt_platform.cpp | 5 ++++- src/unix/unix.c | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index c48a84020..5f4d23baa 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -589,7 +589,10 @@ plat_chdir(char *path) void plat_init_rom_paths() { -#if !defined __APPLE__ && !defined _WIN32 +#if defined __APPLE__ + QDir::root().mkpath(QStringLiteral("%1/Documents/86Box/roms/").arg(QDir::homePath())); + add_rom_path(QStringLiteral("%1/Documents/86Box/roms/").arg(QDir::homePath()).toUtf8().constData()); +#elif !defined _WIN32 if (getenv("XDG_DATA_HOME")) { char xdg_rom_path[1024] = { 0 }; strncpy(xdg_rom_path, getenv("XDG_DATA_HOME"), 1024); diff --git a/src/unix/unix.c b/src/unix/unix.c index 1c8917626..5f6429b89 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -796,6 +796,13 @@ plat_init_rom_paths() add_rom_path("/usr/local/share/86Box/roms/"); add_rom_path("/usr/share/86Box/roms/"); } +#else + char home_rom_path[1024] = { '\0' }; + snprintf(home_rom_path, 1024, "%s/Documents/86Box/", getenv("HOME") ? getenv("HOME") : getpwuid(getuid())->pw_dir); + plat_dir_create(home_rom_path); + strcat(home_rom_path, "roms/"); + plat_dir_create(home_rom_path); + add_rom_path(home_rom_path); #endif } From 027179ab959859f42bc9da82407fe387ea1f6b5e Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 7 Apr 2022 01:14:36 +0600 Subject: [PATCH 15/37] qt/languages/pt-PT.po: Fix "No ROMs Found" message --- src/qt/languages/pt-PT.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/languages/pt-PT.po b/src/qt/languages/pt-PT.po index 301b52566..8497b935d 100644 --- a/src/qt/languages/pt-PT.po +++ b/src/qt/languages/pt-PT.po @@ -614,7 +614,7 @@ msgid "ZIP images" msgstr "Imagens ZIP" msgid "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory." -msgstr "O 86Box não conseguiu encontrar nenhuma imagem ROM utilizável.\n\nPor favor, vá a href=\"https://github.com/86Box/roms/releases/latest\">descarregue um pacote ROM e instale-o na pasta \"roms\"." +msgstr "O 86Box não conseguiu encontrar nenhuma imagem ROM utilizável.\n\nPor favor, vá descarregue um pacote ROM e instale-o na pasta \"roms\"." msgid "(empty)" msgstr "(empty)" From 84b1a8a7d3964c7edd0a519bf801e98be5b105ba Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 7 Apr 2022 01:23:23 +0600 Subject: [PATCH 16/37] qt: Fix mistyped LCID value of en-US --- src/qt/qt_platform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 508103169..ff7b99c93 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -375,7 +375,7 @@ extern "C++" { {0x0405, {"cs-CZ", "Czech (Czech Republic)"} }, {0x0407, {"de-DE", "German (Germany)"} }, - {0x0408, {"en-US", "English (United States)"} }, + {0x0409, {"en-US", "English (United States)"} }, {0x0809, {"en-GB", "English (United Kingdom)"} }, {0x0C0A, {"es-ES", "Spanish (Spain)"} }, {0x040B, {"fi-FI", "Finnish (Finland)"} }, From c700f93b4b90ccd1b174716405ef51a90754e961 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 7 Apr 2022 01:27:16 +0600 Subject: [PATCH 17/37] qt: Fix warnings --- src/qt/qt_platform.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 2df4acd3f..e6e3256d3 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -377,7 +377,7 @@ extern "C++" { {0x0405, {"cs-CZ", "Czech (Czech Republic)"} }, {0x0407, {"de-DE", "German (Germany)"} }, - {0x0408, {"en-US", "English (United States)"} }, + {0x0409, {"en-US", "English (United States)"} }, {0x0809, {"en-GB", "English (United Kingdom)"} }, {0x0C0A, {"es-ES", "Spanish (Spain)"} }, {0x040B, {"fi-FI", "Finnish (Finland)"} }, @@ -594,7 +594,7 @@ plat_init_rom_paths() add_rom_path(QStringLiteral("%1/Documents/86Box/roms/").arg(QDir::homePath()).toUtf8().constData()); #elif !defined _WIN32 if (getenv("XDG_DATA_HOME")) { - char xdg_rom_path[1024] = { 0 }; + char xdg_rom_path[1024 + 1] = { 0 }; strncpy(xdg_rom_path, getenv("XDG_DATA_HOME"), 1024); plat_path_slash(xdg_rom_path); strncat(xdg_rom_path, "86Box/", 1024); From 61c9f9beac9d606c2b293dae124284eee7712eb6 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 7 Apr 2022 02:17:14 +0600 Subject: [PATCH 18/37] cmake: Enable 64-bit file support on 32-bit Linux --- src/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 06cebf82b..36df54404 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,10 @@ add_executable(86Box 86box.c config.c log.c random.c timer.c io.c acpi.c apm.c dma.c ddma.c discord.c nmi.c pic.c pit.c port_6x.c port_92.c ppi.c pci.c mca.c usb.c fifo8.c device.c nvr.c nvr_at.c nvr_ps2.c) +if(CMAKE_SYSTEM_NAME MATCHES "Linux") + add_compile_definitions(_FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE=1 _LARGEFILE64_SOURCE=1) +endif() + if(CPPTHREADS) target_sources(86Box PRIVATE thread.cpp) endif() From 44ef14b143abaf0588724e1f7ba7a8b00d8fa50d Mon Sep 17 00:00:00 2001 From: richardg867 Date: Wed, 6 Apr 2022 18:21:25 -0300 Subject: [PATCH 19/37] Jenkins: Fix Discord Game SDK extraction on macOS --- .ci/build.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index 4e164bcdf..437f06b95 100644 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -32,7 +32,11 @@ # are configured as NOPASSWD in /etc/sudoers if you're doing unattended builds # - For macOS builds: # - A standard MacPorts installation is required, with the following macports.conf settings: -# +# buildfromsource always +# build_arch x86_64 (or arm64) +# universal_archs (blank) +# ui_interactive no +# macosx_deployment_target 10.13 # - port is called through sudo to manage dependencies; make sure it is configured # as NOPASSWD in /etc/sudoers if you're doing unattended builds # @@ -551,7 +555,7 @@ then if [ $status -eq 0 ] then # Archive Discord Game SDK library. - unzip discord_game_sdk.zip "lib/$arch_discord/discord_game_sdk.dylib" -d "archive_tmp/"*".app/Contents/Frameworks" + unzip -j discord_game_sdk.zip "lib/$arch_discord/discord_game_sdk.dylib" -d "archive_tmp/"*".app/Contents/Frameworks" [ ! -e "archive_tmp/"*".app/Contents/Frameworks/discord_game_sdk.dylib" ] && echo [!] No Discord Game SDK for architecture [$arch_discord] # Sign app bundle. From 6ac35ffe4310faaef4de03dce8cc43f143dafd85 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Thu, 7 Apr 2022 15:48:07 -0300 Subject: [PATCH 20/37] Jenkins: Search for MacPorts prefix when building --- .ci/build.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index 437f06b95..590119cc4 100644 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -330,15 +330,20 @@ then # macOS lacks nproc, but sysctl can do the same job. alias nproc='sysctl -n hw.logicalcpu' + # Locate the MacPorts prefix. + macports="/opt/local" + [ -e "/opt/$arch/bin/port" ] && macports="/opt/$arch" + [ "$arch" = "x86_64" -a -e "/opt/intel/bin/port" ] && macports="/opt/intel" + # Install dependencies. echo [-] Installing dependencies through MacPorts - sudo port selfupdate - sudo port install $(cat .ci/dependencies_macports.txt) + sudo $macports/bin/port selfupdate + sudo $macports/bin/port install $(cat .ci/dependencies_macports.txt) # Point CMake to the toolchain file. [ -e "cmake/$toolchain.cmake" ] && cmake_flags_extra="$cmake_flags_extra -D \"CMAKE_TOOLCHAIN_FILE=cmake/$toolchain.cmake\"" - # Use OpenAL. + # Use OpenAL as MacPorts doesn't package FAudio. cmake_flags_extra="$cmake_flags_extra -D OPENAL=ON" else # Determine Debian architecture. From e5ab6a85648736cc310b177c8aa47f737324272c Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 8 Apr 2022 01:51:32 +0600 Subject: [PATCH 21/37] qt: Avoid reading absolute mouse input from cross-platform Qt code on Windows This ensures only RAWINPUT sends mouse input to the emulated machine on Windows. --- src/qt/qt_rendererstack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index c77e76474..88b2395d5 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -174,7 +174,7 @@ RendererStack::mouseMoveEvent(QMouseEvent *event) event->ignore(); return; } -#ifdef __APPLE__ +#if defined __APPLE__ || defined _WIN32 event->accept(); return; #else From a780d9a241093ff15b004c48623c93cb34c33ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 8 Apr 2022 00:58:38 +0200 Subject: [PATCH 22/37] Rewrite plat_init_rom_paths in Qt frontend --- src/86box.c | 5 +-- src/mac/CMakeLists.txt | 9 +++-- src/qt/qt_platform.cpp | 64 +++++++--------------------------- src/unix/CMakeLists.txt | 4 +++ src/{mac => unix}/macOSXGlue.h | 0 src/{mac => unix}/macOSXGlue.m | 0 src/unix/unix.c | 13 +++---- 7 files changed, 28 insertions(+), 67 deletions(-) rename src/{mac => unix}/macOSXGlue.h (100%) rename src/{mac => unix}/macOSXGlue.m (100%) diff --git a/src/86box.c b/src/86box.c index 4eae7ab02..5ba477fb4 100644 --- a/src/86box.c +++ b/src/86box.c @@ -37,7 +37,6 @@ #ifdef __APPLE__ #include #include -#include "mac/macOSXGlue.h" #ifdef __aarch64__ #include #endif @@ -650,9 +649,7 @@ usage: { char default_rom_path[1024] = { 0 }; -#if defined(__APPLE__) - getDefaultROMPath(default_rom_path); -#elif !defined(_WIN32) +#if !defined(_WIN32) && !defined(__APPLE__) appimage = getenv("APPIMAGE"); if (appimage && (appimage[0] != '\0')) { plat_get_dirname(default_rom_path, appimage); diff --git a/src/mac/CMakeLists.txt b/src/mac/CMakeLists.txt index ae3837f0e..2b71dd266 100644 --- a/src/mac/CMakeLists.txt +++ b/src/mac/CMakeLists.txt @@ -19,17 +19,16 @@ # Pick the bundle icon depending on the release channel if(RELEASE_BUILD) - set(APP_ICON_MACOSX icons/release/86Box.icns) + target_sources(86Box PRIVATE icons/release/86Box.icns) elseif(BETA_BUILD) - set(APP_ICON_MACOSX icons/beta/86Box.icns) + target_sources(86Box PRIVATE icons/beta/86Box.icns) elseif(ALPHA_BUILD) - set(APP_ICON_MACOSX icons/dev/86Box.icns) + target_sources(86Box PRIVATE icons/dev/86Box.icns) else() - set(APP_ICON_MACOSX icons/branch/86Box.icns) + target_sources(86Box PRIVATE icons/branch/86Box.icns) endif() target_link_libraries(86Box "-framework AppKit") -target_sources(86Box PRIVATE macOSXGlue.m ${APP_ICON_MACOSX}) # Make sure the icon is copied to the bundle set_source_files_properties(${APP_ICON_MACOSX} diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index e6e3256d3..1d709e3ac 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -589,59 +590,18 @@ plat_chdir(char *path) void plat_init_rom_paths() { -#if defined __APPLE__ - QDir::root().mkpath(QStringLiteral("%1/Documents/86Box/roms/").arg(QDir::homePath())); - add_rom_path(QStringLiteral("%1/Documents/86Box/roms/").arg(QDir::homePath()).toUtf8().constData()); -#elif !defined _WIN32 - if (getenv("XDG_DATA_HOME")) { - char xdg_rom_path[1024 + 1] = { 0 }; - strncpy(xdg_rom_path, getenv("XDG_DATA_HOME"), 1024); - plat_path_slash(xdg_rom_path); - strncat(xdg_rom_path, "86Box/", 1024); + auto paths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); - if (!plat_dir_check(xdg_rom_path)) - plat_dir_create(xdg_rom_path); - strcat(xdg_rom_path, "roms/"); +#ifdef _WIN32 + // HACK: The standard locations returned for GenericDataLocation include + // the EXE path and a `data` directory within it as the last two entries. - if (!plat_dir_check(xdg_rom_path)) - plat_dir_create(xdg_rom_path); - add_rom_path(xdg_rom_path); - } else { - char home_rom_path[1024] = { 0 }; - snprintf(home_rom_path, 1024, "%s/.local/share/86Box/", getenv("HOME") ? getenv("HOME") : QDir::homePath().toUtf8().constData()); - - if (!plat_dir_check(home_rom_path)) - plat_dir_create(home_rom_path); - strcat(home_rom_path, "roms/"); - - if (!plat_dir_check(home_rom_path)) - plat_dir_create(home_rom_path); - add_rom_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; - if (xdg_rom_paths) { - while (xdg_rom_paths[strlen(xdg_rom_paths) - 1] == ':') { - xdg_rom_paths[strlen(xdg_rom_paths) - 1] = '\0'; - } - QStringList path_list = QString(xdg_rom_paths).split(":"); - for (auto& cur_path : path_list) { - if (cur_path.right(1) != '/') - cur_path.push_back('/'); - add_rom_path((cur_path + "86Box/roms").toUtf8().constData()); - } - } - free(xdg_rom_paths_orig); - } else { - add_rom_path("/usr/local/share/86Box/roms/"); - add_rom_path("/usr/share/86Box/roms/"); - } -#elif _WIN32 - auto appDataDir = QDir(qEnvironmentVariable("LOCALAPPDATA")); - appDataDir.mkdir("86Box"); - appDataDir.mkdir("86Box/roms"); - add_rom_path((appDataDir.path().replace("\\","/") + "/86Box/roms").toUtf8().constData()); + // Remove the entries as we don't need them. + paths.removeLast(); + paths.removeLast(); #endif + + for (auto& path : paths) { + add_rom_path(QDir(path).filePath("86Box/roms").toUtf8().constData()); + } } diff --git a/src/unix/CMakeLists.txt b/src/unix/CMakeLists.txt index 1712288d2..6d1c01a34 100644 --- a/src/unix/CMakeLists.txt +++ b/src/unix/CMakeLists.txt @@ -28,3 +28,7 @@ target_link_libraries(86Box Threads::Threads) add_library(ui OBJECT unix_sdl.c unix_cdrom.c) target_compile_definitions(ui PUBLIC _FILE_OFFSET_BITS=64) target_link_libraries(ui ${CMAKE_DL_LIBS}) + +if(APPLE) + target_sources(plat PRIVATE macOSXGlue.m) +endif() diff --git a/src/mac/macOSXGlue.h b/src/unix/macOSXGlue.h similarity index 100% rename from src/mac/macOSXGlue.h rename to src/unix/macOSXGlue.h diff --git a/src/mac/macOSXGlue.m b/src/unix/macOSXGlue.m similarity index 100% rename from src/mac/macOSXGlue.m rename to src/unix/macOSXGlue.m diff --git a/src/unix/unix.c b/src/unix/unix.c index 5f6429b89..8854be1a8 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -36,6 +36,10 @@ #include <86box/ui.h> #include <86box/gdbstub.h> +#ifdef __APPLE__ +#include "macOSXGlue.h" +#endif + static int first_use = 1; static uint64_t StartingTime; static uint64_t Frequency; @@ -797,12 +801,9 @@ plat_init_rom_paths() add_rom_path("/usr/share/86Box/roms/"); } #else - char home_rom_path[1024] = { '\0' }; - snprintf(home_rom_path, 1024, "%s/Documents/86Box/", getenv("HOME") ? getenv("HOME") : getpwuid(getuid())->pw_dir); - plat_dir_create(home_rom_path); - strcat(home_rom_path, "roms/"); - plat_dir_create(home_rom_path); - add_rom_path(home_rom_path); + char default_rom_path[1024] = { '\0 '}; + getDefaultROMPath(default_rom_path); + add_rom_path(default_rom_path); #endif } From 3449a173ae60d231ba5247a89d93613e1defa73e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 8 Apr 2022 00:46:30 +0200 Subject: [PATCH 23/37] Move ROM search path code to `rom.c`, rewrite `rom_fopen` --- src/86box.c | 58 +++---------------- src/include/86box/rom.h | 4 +- src/mem/rom.c | 122 +++++++++++++++++----------------------- src/qt/qt_platform.cpp | 2 +- src/unix/unix.c | 12 ++-- src/win/win.c | 2 +- 6 files changed, 71 insertions(+), 129 deletions(-) diff --git a/src/86box.c b/src/86box.c index 5ba477fb4..696f65a5d 100644 --- a/src/86box.c +++ b/src/86box.c @@ -384,48 +384,6 @@ pc_log(const char *fmt, ...) #define pc_log(fmt, ...) #endif -void -add_rom_path(const char* path) -{ - static char cwd[1024]; - memset(cwd, 0x00, sizeof(cwd)); - rom_path_t* cur_rom_path = &rom_paths; - while (cur_rom_path->next != NULL) { - cur_rom_path = cur_rom_path->next; - } - if (!plat_path_abs((char*)path)) { - /* - * This looks like a relative path. - * - * Add it to the current working directory - * to convert it (back) to an absolute path. - */ - plat_getcwd(cwd, 1024); - plat_path_slash(cwd); - snprintf(cur_rom_path->rom_path, 1024, "%s%s%c", cwd, path, 0); - } - else { - /* - * The user-provided path seems like an - * absolute path, so just use that. - */ - strncpy(cur_rom_path->rom_path, path, 1024); - } - plat_path_slash(cur_rom_path->rom_path); - cur_rom_path->next = calloc(1, sizeof(rom_path_t)); -} - -// Copied over from Unix code, which in turn is lifted from musl. Needed for parsing XDG_DATA_DIRS. -static 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; -} /* * Perform initial startup of the PC. @@ -539,7 +497,7 @@ usage: if ((c+1) == argc) goto usage; strcpy(path2, argv[++c]); - add_rom_path(path2); + rom_add_path(path2); } else if (!strcasecmp(argv[c], "--config") || !strcasecmp(argv[c], "-C")) { if ((c+1) == argc) goto usage; @@ -641,7 +599,7 @@ usage: plat_path_slash(vmrppath); strcat(vmrppath, "roms"); plat_path_slash(vmrppath); - add_rom_path(vmrppath); + rom_add_path(vmrppath); if (path2[0] == '\0') { strcpy(path2, vmrppath); } @@ -650,13 +608,13 @@ usage: { char default_rom_path[1024] = { 0 }; #if !defined(_WIN32) && !defined(__APPLE__) - appimage = getenv("APPIMAGE"); - if (appimage && (appimage[0] != '\0')) { + appimage = getenv("APPIMAGE"); + if (appimage && (appimage[0] != '\0')) { plat_get_dirname(default_rom_path, appimage); plat_path_slash(default_rom_path); strcat(default_rom_path, "roms"); plat_path_slash(default_rom_path); - } + } #endif if (default_rom_path[0] == '\0') { plat_getcwd(default_rom_path, 1024); @@ -664,11 +622,11 @@ usage: snprintf(default_rom_path, 1024, "%s%s%c", default_rom_path, "roms", 0); plat_path_slash(default_rom_path); } - add_rom_path(default_rom_path); + rom_add_path(default_rom_path); if (path2[0] == '\0') { strcpy(path2, default_rom_path); } - } + } plat_init_rom_paths(); @@ -771,7 +729,7 @@ usage: if (rom_paths.next) { rom_path_t* cur_rom_path = &rom_paths; while (cur_rom_path->next) { - pclog("# ROM path: %s\n", cur_rom_path->rom_path); + pclog("# ROM path: %s\n", cur_rom_path->path); cur_rom_path = cur_rom_path->next; } } diff --git a/src/include/86box/rom.h b/src/include/86box/rom.h index 04fe94422..30c7c0561 100644 --- a/src/include/86box/rom.h +++ b/src/include/86box/rom.h @@ -42,13 +42,13 @@ typedef struct { typedef struct rom_path_t { - char rom_path[1024]; + char path[1024]; struct rom_path_t* next; } rom_path_t; extern rom_path_t rom_paths; -extern void add_rom_path(const char* path); +extern void rom_add_path(const char* path); extern uint8_t rom_read(uint32_t addr, void *p); extern uint16_t rom_readw(uint32_t addr, void *p); diff --git a/src/mem/rom.c b/src/mem/rom.c index 3dcbfe568..fda529181 100644 --- a/src/mem/rom.c +++ b/src/mem/rom.c @@ -57,47 +57,55 @@ rom_log(const char *fmt, ...) #define rom_log(fmt, ...) #endif +void +rom_add_path(const char* path) +{ + char cwd[1024] = { 0 }; + + // Iterate to the end of the list. + rom_path_t* rom_path = &rom_paths; + while (rom_path->next != NULL) { + rom_path = rom_path->next; + } + + // Allocate the new entry. + rom_path = rom_path->next = calloc(1, sizeof(rom_path_t)); + + // Save the path, turning it into absolute if needed. + if (!plat_path_abs((char*) path)) { + plat_getcwd(cwd, 1024); + plat_path_slash(cwd); + snprintf(rom_path->path, 1024, "%s%s%c", cwd, path, 0); + } else { + strncpy(rom_path->path, path, 1024); + } + + // Ensure the path ends with a separator. + plat_path_slash(rom_path->path); +} + FILE * rom_fopen(char *fn, char *mode) { char temp[1024]; - char *fn2; + rom_path_t *rom_path = &rom_paths; + FILE *fp; - if ((strstr(fn, "roms/") == fn) || (strstr(fn, "roms\\") == fn)) { - /* Relative path */ - fn2 = (char *) malloc(strlen(fn) + 1); - memcpy(fn2, fn, strlen(fn) + 1); + if (strstr(fn, "roms/") == fn) { + /* Relative path */ + do { + plat_append_filename(temp, rom_path->path, fn + 5); - if (rom_paths.next) { - rom_path_t* cur_rom_path = &rom_paths; - memset(fn2, 0x00, strlen(fn) + 1); - memcpy(fn2, &(fn[5]), strlen(fn) - 4); - - while (cur_rom_path->next) { - memset(temp, 0, sizeof(temp)); - plat_append_filename(temp, cur_rom_path->rom_path, fn2); - if (rom_present(temp)) { - break; + if (fp = plat_fopen(temp, mode)) { + return fp; } - cur_rom_path = cur_rom_path->next; - } - } else { - /* Make sure to make it a backslash, just in case there's malformed - code calling us that assumes Windows. */ - if (fn2[4] == '\\') - fn2[4] = '/'; + } while(rom_path = rom_path->next); - plat_append_filename(temp, exe_path, fn2); - } - - free(fn2); - fn2 = NULL; - - return(plat_fopen(temp, mode)); + return fp; } else { - /* Absolute path */ - return(plat_fopen(fn, mode)); + /* Absolute path */ + return plat_fopen(fn, mode); } } @@ -105,54 +113,30 @@ rom_fopen(char *fn, char *mode) int rom_getfile(char *fn, char *s, int size) { - char temp[1024] = {'\0'}; - char *fn2; - int retval = 0; + char temp[1024]; + rom_path_t *rom_path = &rom_paths; - if ((strstr(fn, "roms/") == fn) || (strstr(fn, "roms\\") == fn)) { - /* Relative path */ - fn2 = (char *) malloc(strlen(fn) + 1); - memcpy(fn2, fn, strlen(fn) + 1); + if (strstr(fn, "roms/") == fn) { + /* Relative path */ + do { + plat_append_filename(temp, rom_path->path, fn + 5); - if (rom_paths.next) { - rom_path_t* cur_rom_path = &rom_paths; - memset(fn2, 0x00, strlen(fn) + 1); - memcpy(fn2, &(fn[5]), strlen(fn) - 4); - - while (cur_rom_path->next) { - memset(temp, 0, sizeof(temp)); - plat_append_filename(temp, cur_rom_path->rom_path, fn2); if (rom_present(temp)) { strncpy(s, temp, size); - retval = 1; - break; + return 1; } - cur_rom_path = cur_rom_path->next; - } - } else { - /* Make sure to make it a backslash, just in case there's malformed - code calling us that assumes Windows. */ - if (fn2[4] == '\\') - fn2[4] = '/'; + } while(rom_path = rom_path->next); - plat_append_filename(temp, exe_path, fn2); - if (rom_present(temp)) { - strncpy(s, temp, size); - retval = 1; - } - } - - free(fn2); - fn2 = NULL; + return 0; } else { /* Absolute path */ if (rom_present(fn)) { strncpy(s, fn, size); - retval = 1; + return 1; } + + return 0; } - - return(retval); } @@ -163,8 +147,8 @@ rom_present(char *fn) f = rom_fopen(fn, "rb"); if (f != NULL) { - (void)fclose(f); - return(1); + (void)fclose(f); + return(1); } return(0); diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 1d709e3ac..af3d2b9e8 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -602,6 +602,6 @@ plat_init_rom_paths() #endif for (auto& path : paths) { - add_rom_path(QDir(path).filePath("86Box/roms").toUtf8().constData()); + rom_add_path(QDir(path).filePath("86Box/roms").toUtf8().constData()); } } diff --git a/src/unix/unix.c b/src/unix/unix.c index 8854be1a8..36187d44a 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -766,7 +766,7 @@ plat_init_rom_paths() if (!plat_dir_check(xdg_rom_path)) plat_dir_create(xdg_rom_path); - add_rom_path(xdg_rom_path); + rom_add_path(xdg_rom_path); } else { char home_rom_path[1024] = { 0 }; snprintf(home_rom_path, 1024, "%s/.local/share/86Box/", getenv("HOME") ? getenv("HOME") : getpwuid(getuid())->pw_dir); @@ -777,7 +777,7 @@ plat_init_rom_paths() if (!plat_dir_check(home_rom_path)) plat_dir_create(home_rom_path); - add_rom_path(home_rom_path); + rom_add_path(home_rom_path); } if (getenv("XDG_DATA_DIRS")) { char* xdg_rom_paths = strdup(getenv("XDG_DATA_DIRS")); @@ -792,18 +792,18 @@ plat_init_rom_paths() strcat(real_xdg_rom_path, cur_xdg_rom_path); plat_path_slash(real_xdg_rom_path); strcat(real_xdg_rom_path, "86Box/roms/"); - add_rom_path(real_xdg_rom_path); + rom_add_path(real_xdg_rom_path); } } free(xdg_rom_paths_orig); } else { - add_rom_path("/usr/local/share/86Box/roms/"); - add_rom_path("/usr/share/86Box/roms/"); + rom_add_path("/usr/local/share/86Box/roms/"); + rom_add_path("/usr/share/86Box/roms/"); } #else char default_rom_path[1024] = { '\0 '}; getDefaultROMPath(default_rom_path); - add_rom_path(default_rom_path); + rom_path_add(default_rom_path); #endif } diff --git a/src/win/win.c b/src/win/win.c index 06db20bad..b655b58cf 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -932,7 +932,7 @@ plat_init_rom_paths() CreateDirectoryW(appdata_dir, NULL); wcscat(appdata_dir, "\\"); c16stombs(appdata_dir_a, appdata_dir, 1024); - add_rom_path(appdata_dir_a); + rom_add_path(appdata_dir_a); } } From db2b868909d63e79579ce10d51b6780563cebfcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 8 Apr 2022 01:33:49 +0200 Subject: [PATCH 24/37] Refactor the ROM set command line options --- src/86box.c | 76 +++++++++++++++++++-------------------------------- src/mem/rom.c | 16 +++++++---- 2 files changed, 38 insertions(+), 54 deletions(-) diff --git a/src/86box.c b/src/86box.c index 696f65a5d..3a9b199c0 100644 --- a/src/86box.c +++ b/src/86box.c @@ -395,12 +395,12 @@ pc_log(const char *fmt, ...) int pc_init(int argc, char *argv[]) { - char path[2048], path2[2048]; + char *ppath = NULL, *rpath = NULL; char *cfg = NULL, *p; #if !defined(__APPLE__) && !defined(_WIN32) char *appimage; #endif - char temp[128]; + char temp[2048]; struct tm *info; time_t now; int c, vmrp = 0; @@ -424,9 +424,6 @@ pc_init(int argc, char *argv[]) plat_getcwd(usr_path, sizeof(usr_path) - 1); plat_getcwd(rom_path, sizeof(rom_path) - 1); - memset(path, 0x00, sizeof(path)); - memset(path2, 0x00, sizeof(path)); - for (c=1; cnext != NULL) { - rom_path = rom_path->next; - } - // Allocate the new entry. - rom_path = rom_path->next = calloc(1, sizeof(rom_path_t)); + if (rom_paths.path[0] != '\0') + { + // Iterate to the end of the list. + while (rom_path->next != NULL) { + rom_path = rom_path->next; + } + + // Allocate the new entry. + rom_path = rom_path->next = calloc(1, sizeof(rom_path_t)); + } // Save the path, turning it into absolute if needed. if (!plat_path_abs((char*) path)) { From 37b478d25ea3c3fb36b3bfe17ed2a3c47c4a352d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 8 Apr 2022 01:49:04 +0200 Subject: [PATCH 25/37] Fix up `exe_path` when running as AppImage --- src/86box.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/86box.c b/src/86box.c index 3a9b199c0..63f4f3c52 100644 --- a/src/86box.c +++ b/src/86box.c @@ -413,6 +413,14 @@ pc_init(int argc, char *argv[]) p = plat_get_filename(exe_path); *p = '\0'; +#if !defined(_WIN32) && !defined(__APPLE__) + /* Grab the actual path if we are an AppImage. */ + appimage = getenv("APPIMAGE"); + if (appimage && (appimage[0] != '\0')) { + plat_get_dirname(exe_path, appimage); + } +#endif + /* * Get the current working directory. * @@ -591,21 +599,10 @@ usage: // Add the VM-local ROM path. plat_append_filename(temp, usr_path, "roms"); - plat_path_slash(temp); rom_add_path(temp); // Add the standard ROM path in the same directory as the executable. -#if !defined(_WIN32) && !defined(__APPLE__) - appimage = getenv("APPIMAGE"); - if (appimage && (appimage[0] != '\0')) { - plat_append_filename(temp, appimage, "roms"); - } else { -#endif - plat_append_filename(temp, exe_path, "roms"); -#if !defined(_WIN32) && !defined(__APPLE__) - } -#endif - + plat_append_filename(temp, exe_path, "roms"); rom_add_path(temp); plat_init_rom_paths(); From 8e65036b71f3d233d2d4ff79de6824b46c2f928f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 8 Apr 2022 02:18:28 +0200 Subject: [PATCH 26/37] Fix ROM path logging at startup --- src/86box.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/86box.c b/src/86box.c index 63f4f3c52..58a57dff3 100644 --- a/src/86box.c +++ b/src/86box.c @@ -407,6 +407,7 @@ pc_init(int argc, char *argv[]) int ng = 0, lvmp = 0; uint32_t *uid, *shwnd; uint32_t lang_init = 0; + rom_path_t *rom_path = &rom_path; /* Grab the executable's full path. */ plat_get_exe_name(exe_path, sizeof(exe_path)-1); @@ -703,19 +704,10 @@ usage: pclog("# VM: %s\n#\n", vm_name); pclog("# Emulator path: %s\n", exe_path); pclog("# Userfiles path: %s\n", usr_path); - if (rom_paths.next) { - rom_path_t* cur_rom_path = &rom_paths; - while (cur_rom_path->next) { - pclog("# ROM path: %s\n", cur_rom_path->path); - cur_rom_path = cur_rom_path->next; - } - } - else -#ifndef _WIN32 - pclog("# ROM path: %sroms/\n", exe_path); -#else - pclog("# ROM path: %sroms\\\n", exe_path); -#endif + do { + pclog("# ROM path: %s\n", rom_path->path); + } while (rom_path = rom_path->next); + pclog("# Configuration file: %s\n#\n\n", cfg_path); /* * We are about to read the configuration file, which MAY From 2bd9884a32124c1d830f33bad0c600fb699bb15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 8 Apr 2022 02:22:13 +0200 Subject: [PATCH 27/37] Fix ROM path logging, take two --- src/86box.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/86box.c b/src/86box.c index 58a57dff3..b1c969509 100644 --- a/src/86box.c +++ b/src/86box.c @@ -407,7 +407,6 @@ pc_init(int argc, char *argv[]) int ng = 0, lvmp = 0; uint32_t *uid, *shwnd; uint32_t lang_init = 0; - rom_path_t *rom_path = &rom_path; /* Grab the executable's full path. */ plat_get_exe_name(exe_path, sizeof(exe_path)-1); @@ -704,9 +703,9 @@ usage: pclog("# VM: %s\n#\n", vm_name); pclog("# Emulator path: %s\n", exe_path); pclog("# Userfiles path: %s\n", usr_path); - do { + for(rom_path_t *rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) { pclog("# ROM path: %s\n", rom_path->path); - } while (rom_path = rom_path->next); + } pclog("# Configuration file: %s\n#\n\n", cfg_path); /* From ac77a2161146fd26a2aecdc4b483b4883f58ddb0 Mon Sep 17 00:00:00 2001 From: Emily Date: Sat, 19 Mar 2022 00:44:42 +0000 Subject: [PATCH 28/37] cmake: Fix Qt 6 plugin installation on macOS Run find_package to import the CMake rules for the various plugins, as install_qt5_plugin didn't work for me on Qt 6 otherwise, and install the macOS style and icon plugins as well so that the widget style and icons work correctly on Qt 6. ${_qt_plugin_dir} doesn't seem to get set by anything and install_qt5_plugin hardcodes the PlugIns path, so hardcode that in qt.conf as well. Additionally, adjust the Qt library folder to take into account the major version being used. --- src/qt/CMakeLists.txt | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index a62032537..91891087b 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -22,6 +22,14 @@ endif() find_package(Threads REQUIRED) find_package(Qt${QT_MAJOR} COMPONENTS Core Widgets Network OpenGL REQUIRED) find_package(Qt${QT_MAJOR}LinguistTools REQUIRED) +# TODO: Is this the correct way to do this, and is it required on any +# other platforms or with Qt 5? +if(APPLE AND USE_QT6) + find_package(Qt6Gui/Qt6QCocoaIntegrationPlugin REQUIRED) + find_package(Qt6Widgets/Qt6QMacStylePlugin REQUIRED) + find_package(Qt6Gui/Qt6QICOPlugin REQUIRED) + find_package(Qt6Gui/Qt6QICNSPlugin REQUIRED) +endif() add_library(plat STATIC qt.c @@ -232,17 +240,13 @@ if (APPLE AND CMAKE_MACOSX_BUNDLE) set(INSTALL_CMAKE_DIR "${prefix}/Resources") # using the install_qt5_plugin to add Qt plugins into the macOS app bundle - if (USE_QT6) - install_qt5_plugin("Qt6::QCocoaIntegrationPlugin" QT_PLUGINS ${prefix}) - else() - install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS ${prefix}) - install_qt5_plugin("Qt5::QMacStylePlugin" QT_PLUGINS ${prefix}) - install_qt5_plugin("Qt5::QICOPlugin" QT_PLUGINS ${prefix}) - install_qt5_plugin("Qt5::QICNSPlugin" QT_PLUGINS ${prefix}) - endif() + install_qt5_plugin("Qt${QT_MAJOR}::QCocoaIntegrationPlugin" QT_PLUGINS ${prefix}) + install_qt5_plugin("Qt${QT_MAJOR}::QMacStylePlugin" QT_PLUGINS ${prefix}) + install_qt5_plugin("Qt${QT_MAJOR}::QICOPlugin" QT_PLUGINS ${prefix}) + install_qt5_plugin("Qt${QT_MAJOR}::QICNSPlugin" QT_PLUGINS ${prefix}) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" - "[Paths]\nPlugins = ${_qt_plugin_dir}\n") + "[Paths]\nPlugins = PlugIns\n") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" DESTINATION "${INSTALL_CMAKE_DIR}") @@ -253,8 +257,8 @@ if (APPLE AND CMAKE_MACOSX_BUNDLE) endforeach() endif() - # Append Qt's lib folder which is two levels above Qt5Widgets_DIR - list(APPEND DIRS "${Qt5Widgets_DIR}/../..") + # Append Qt's lib folder which is two levels above Qt*Widgets_DIR + list(APPEND DIRS "${Qt${QT_MAJOR}Widgets_DIR}/../..") include(InstallRequiredSystemLibraries) From 9c6001dabb7b75bf18d5b678a2dbb3a6c0a38da9 Mon Sep 17 00:00:00 2001 From: Emily Date: Sat, 19 Mar 2022 23:06:17 +0000 Subject: [PATCH 29/37] qt: Fix Qt 6 modifier key handling on macOS Per QTBUG-69608 (https://bugreports.qt.io/browse/QTBUG-69608), QKeyEvent::nativeVirtualKey() returns 0 on Qt 6 (and possibly some versions of Qt 5) for keyboard modifier events. Despite being closed, the bug doesn't appear to have been fixed, or perhaps was fixed and then regressed again. Detect this case and handle the events manually by keeping track of the active modifier keys and using QKeyEvent::nativeModifiers() and the platform-specific modifier values. Caps Lock requires some special handling and doesn't get discrete press/release events, at least with the Qt input system; see the code for details. It's possible some other toggle modifiers like Scroll Lock will need special handling along these lines too. Fix #2211. --- src/qt/qt_mainwindow.cpp | 80 +++++++++++++++++++++++++++++++++++++--- src/qt/qt_mainwindow.hpp | 5 +++ 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index fe249874b..ca3cf1a2e 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -82,6 +82,14 @@ extern "C" { #undef KeyRelease #endif +#ifdef Q_OS_MACOS +// The namespace is required to avoid clashing typedefs; we only use this +// header for its #defines anyway. +namespace IOKit { + #include +} +#endif + #ifdef __HAIKU__ #include #include @@ -1215,7 +1223,7 @@ uint16_t x11_keycode_to_keysym(uint32_t keycode) uint16_t finalkeycode = 0; #if defined(Q_OS_WINDOWS) finalkeycode = (keycode & 0xFFFF); -#elif defined(__APPLE__) +#elif defined(Q_OS_MACOS) finalkeycode = darwin_to_xt[keycode]; #elif defined(__HAIKU__) finalkeycode = be_to_xt[keycode]; @@ -1252,6 +1260,68 @@ uint16_t x11_keycode_to_keysym(uint32_t keycode) return finalkeycode; } +#ifdef Q_OS_MACOS +// These modifiers are listed as "device-dependent" in IOLLEvent.h, but +// that's followed up with "(really?)". It's the only way to distinguish +// left and right modifiers with Qt 6 on macOS, so let's just roll with it. +static std::unordered_map mac_modifiers_to_xt = { + {NX_DEVICELCTLKEYMASK, 0x1D}, + {NX_DEVICELSHIFTKEYMASK, 0x2A}, + {NX_DEVICERSHIFTKEYMASK, 0x36}, + {NX_DEVICELCMDKEYMASK, 0x15B}, + {NX_DEVICERCMDKEYMASK, 0x15C}, + {NX_DEVICELALTKEYMASK, 0x38}, + {NX_DEVICERALTKEYMASK, 0x138}, + {NX_DEVICE_ALPHASHIFT_STATELESS_MASK, 0x3A}, + {NX_DEVICERCTLKEYMASK, 0x11D}, +}; + +void MainWindow::processMacKeyboardInput(bool down, const QKeyEvent* event) { + // Per QTBUG-69608 (https://bugreports.qt.io/browse/QTBUG-69608), + // QKeyEvents QKeyEvents for presses/releases of modifiers on macOS give + // nativeVirtualKey() == 0 (at least in Qt 6). Handle this by manually + // processing the nativeModifiers(). We need to check whether the key() is + // a known modifier because because kVK_ANSI_A is also 0, so the + // nativeVirtualKey() == 0 condition is ambiguous... + if (event->nativeVirtualKey() == 0 + && (event->key() == Qt::Key_Shift + || event->key() == Qt::Key_Control + || event->key() == Qt::Key_Meta + || event->key() == Qt::Key_Alt + || event->key() == Qt::Key_AltGr + || event->key() == Qt::Key_CapsLock)) { + // We only process one modifier at a time since events from Qt seem to + // always be non-coalesced (NX_NONCOALESCEDMASK is always set). + uint32_t changed_modifiers = last_modifiers ^ event->nativeModifiers(); + for (auto const& pair : mac_modifiers_to_xt) { + if (changed_modifiers & pair.first) { + last_modifiers ^= pair.first; + keyboard_input(down, pair.second); + return; + } + } + + // Caps Lock seems to be delivered as a single key press event when + // enabled and a single key release event when disabled, so we can't + // detect Caps Lock being held down; just send an infinitesimally-long + // press and release as a compromise. + // + // The event also doesn't get delivered if you turn Caps Lock off after + // turning it on when the window isn't focused. Doing better than this + // probably requires bypassing Qt input processing. + // + // It's possible that other lock keys get delivered in this way, but + // standard Apple keyboards don't have them, so this is untested. + if (event->key() == Qt::Key_CapsLock) { + keyboard_input(1, 0x3A); + keyboard_input(0, 0x3A); + } + } else { + keyboard_input(down, x11_keycode_to_keysym(event->nativeVirtualKey())); + } +} +#endif + void MainWindow::on_actionFullscreen_triggered() { if (video_fullscreen > 0) { showNormal(); @@ -1370,8 +1440,8 @@ void MainWindow::keyPressEvent(QKeyEvent* event) { if (send_keyboard_input && !(kbd_req_capture && !mouse_capture && !video_fullscreen)) { -#ifdef __APPLE__ - keyboard_input(1, x11_keycode_to_keysym(event->nativeVirtualKey())); +#ifdef Q_OS_MACOS + processMacKeyboardInput(true, event); #else keyboard_input(1, x11_keycode_to_keysym(event->nativeScanCode())); #endif @@ -1397,8 +1467,8 @@ void MainWindow::keyReleaseEvent(QKeyEvent* event) if (!send_keyboard_input) return; -#ifdef __APPLE__ - keyboard_input(0, x11_keycode_to_keysym(event->nativeVirtualKey())); +#ifdef Q_OS_MACOS + processMacKeyboardInput(false, event); #else keyboard_input(0, x11_keycode_to_keysym(event->nativeScanCode())); #endif diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 5b155079c..84d08f8ed 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -118,6 +118,11 @@ private: std::unique_ptr status; std::shared_ptr mm; +#ifdef Q_OS_MACOS + uint32_t last_modifiers = 0; + void processMacKeyboardInput(bool down, const QKeyEvent* event); +#endif + /* If main window should send keyboard input */ bool send_keyboard_input = true; bool shownonce = false; From e711b6c44a9cc3bb5ced42dec773bc8ba1961c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 8 Apr 2022 10:20:01 +0200 Subject: [PATCH 30/37] Fix ROM location on macOS --- src/qt/qt_platform.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index af3d2b9e8..607f4fd76 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -520,11 +520,6 @@ size_t c16stombs(char dst[], const uint16_t src[], int len) #define LIB_NAME_FREETYPE "libfreetype" #define MOUSE_CAPTURE_KEYSEQ "CTRL-END" #endif -#ifdef Q_OS_MACOS -#define ROMDIR "~/Library/Application Support/net.86box.86box/roms" -#else -#define ROMDIR "roms" -#endif QMap ProgSettings::translatedstrings; @@ -602,6 +597,10 @@ plat_init_rom_paths() #endif for (auto& path : paths) { +#ifdef __APPLE__ + rom_add_path(QDir(path).filePath("net.86Box.86Box/roms").toUtf8().constData()); +#else rom_add_path(QDir(path).filePath("86Box/roms").toUtf8().constData()); +#endif } } From 3113d2555b9d3cb7344906b1cb702c5079c6a19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 8 Apr 2022 10:23:28 +0200 Subject: [PATCH 31/37] Fix Mac bundle icon --- src/mac/CMakeLists.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mac/CMakeLists.txt b/src/mac/CMakeLists.txt index 2b71dd266..aa0fdd8b5 100644 --- a/src/mac/CMakeLists.txt +++ b/src/mac/CMakeLists.txt @@ -19,16 +19,17 @@ # Pick the bundle icon depending on the release channel if(RELEASE_BUILD) - target_sources(86Box PRIVATE icons/release/86Box.icns) + set(APP_ICON_MACOSX icons/release/86Box.icns) elseif(BETA_BUILD) - target_sources(86Box PRIVATE icons/beta/86Box.icns) + set(APP_ICON_MACOSX icons/beta/86Box.icns) elseif(ALPHA_BUILD) - target_sources(86Box PRIVATE icons/dev/86Box.icns) + set(APP_ICON_MACOSX icons/dev/86Box.icns) else() - target_sources(86Box PRIVATE icons/branch/86Box.icns) + set(APP_ICON_MACOSX icons/branch/86Box.icns) endif() target_link_libraries(86Box "-framework AppKit") +target_sources(86Box PRIVATE ${APP_ICON_MACOSX}) # Make sure the icon is copied to the bundle set_source_files_properties(${APP_ICON_MACOSX} @@ -47,7 +48,6 @@ configure_file(Info.plist.in Info.plist @ONLY) set_target_properties(86Box PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist) -set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "-o linker-signed") -set(XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "YES") -set(XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "-") -#set(XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS ${CMAKE_CURRENT_SOURCE_DIR}/mac/codesign/dev/app.entitlements) +#set(XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "YES") +#set(XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "-") +#set(XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS ${CMAKE_CURRENT_SOURCE_DIR}/mac/codesign/dev/app.entitlements) \ No newline at end of file From 25b8f42dc66c7e9d01f8d7d88af60ae734208202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 8 Apr 2022 10:34:59 +0200 Subject: [PATCH 32/37] qt: FIx broken build due to missing define --- src/qt/qt_platform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 607f4fd76..1af65a670 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -545,7 +545,7 @@ void ProgSettings::reloadStrings() translatedstrings[IDS_2128] = QCoreApplication::translate("", "Hardware not available").toStdWString(); translatedstrings[IDS_2142] = QCoreApplication::translate("", "Monitor in sleep mode").toStdWString(); translatedstrings[IDS_2120] = QCoreApplication::translate("", "No ROMs found").toStdWString(); - translatedstrings[IDS_2056] = QCoreApplication::translate("", "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory.").replace("roms", ROMDIR).toStdWString(); + translatedstrings[IDS_2056] = QCoreApplication::translate("", "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into directory.").toStdWString(); auto flsynthstr = QCoreApplication::translate("", " is required for FluidSynth MIDI output."); if (flsynthstr.contains("libfluidsynth")) From 760d02243271bf4302379fe3e47cbd08ed0e0b95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 8 Apr 2022 10:35:26 +0200 Subject: [PATCH 33/37] rom: Little fixes to get rid of warnings --- src/mem/rom.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mem/rom.c b/src/mem/rom.c index 99d6bb582..2e9697801 100644 --- a/src/mem/rom.c +++ b/src/mem/rom.c @@ -77,11 +77,11 @@ rom_add_path(const char* path) // Save the path, turning it into absolute if needed. if (!plat_path_abs((char*) path)) { - plat_getcwd(cwd, 1024); + plat_getcwd(cwd, sizeof(cwd)); plat_path_slash(cwd); - snprintf(rom_path->path, 1024, "%s%s%c", cwd, path, 0); + snprintf(rom_path->path, sizeof(rom_path->path), "%s%s", cwd, path); } else { - strncpy(rom_path->path, path, 1024); + snprintf(rom_path->path, sizeof(rom_path->path), "%s", path); } // Ensure the path ends with a separator. @@ -98,13 +98,13 @@ rom_fopen(char *fn, char *mode) if (strstr(fn, "roms/") == fn) { /* Relative path */ - do { + for(rom_path_t *rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) { plat_append_filename(temp, rom_path->path, fn + 5); - if (fp = plat_fopen(temp, mode)) { + if ((fp = plat_fopen(temp, mode)) != NULL) { return fp; } - } while(rom_path = rom_path->next); + } return fp; } else { @@ -122,14 +122,14 @@ rom_getfile(char *fn, char *s, int size) if (strstr(fn, "roms/") == fn) { /* Relative path */ - do { + for(rom_path_t *rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) { plat_append_filename(temp, rom_path->path, fn + 5); if (rom_present(temp)) { strncpy(s, temp, size); return 1; } - } while(rom_path = rom_path->next); + } return 0; } else { From 048cfbea00483df0252b6f5a4e28daed7bb516ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 8 Apr 2022 10:45:46 +0200 Subject: [PATCH 34/37] Fix accidental removal --- src/qt/qt_platform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 1af65a670..366e05970 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -545,7 +545,7 @@ void ProgSettings::reloadStrings() translatedstrings[IDS_2128] = QCoreApplication::translate("", "Hardware not available").toStdWString(); translatedstrings[IDS_2142] = QCoreApplication::translate("", "Monitor in sleep mode").toStdWString(); translatedstrings[IDS_2120] = QCoreApplication::translate("", "No ROMs found").toStdWString(); - translatedstrings[IDS_2056] = QCoreApplication::translate("", "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into directory.").toStdWString(); + translatedstrings[IDS_2056] = QCoreApplication::translate("", "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory.").toStdWString(); auto flsynthstr = QCoreApplication::translate("", " is required for FluidSynth MIDI output."); if (flsynthstr.contains("libfluidsynth")) From ff86f97fefb8b1c88c2c3afd3de5f513218498ff Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 8 Apr 2022 15:00:35 +0600 Subject: [PATCH 35/37] unix: Fix missing include --- src/unix/unix.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/unix.c b/src/unix/unix.c index 36187d44a..e4be19e05 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include <86box/86box.h> From f8e53a957a71c6c8e1870eb75b725882e17233d1 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sat, 9 Apr 2022 00:12:27 +0600 Subject: [PATCH 36/37] win: Fix AppData directory creation --- src/win/win.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/win/win.c b/src/win/win.c index b655b58cf..922525cf9 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -926,11 +926,11 @@ plat_init_rom_paths() appdata_dir[len] = L'\\'; appdata_dir[len + 1] = L'\0'; } - wcscat(appdata_dir, "86box"); + wcscat(appdata_dir, L"86box"); CreateDirectoryW(appdata_dir, NULL); - wcscat(appdata_dir, "\\roms"); + wcscat(appdata_dir, L"\\roms"); CreateDirectoryW(appdata_dir, NULL); - wcscat(appdata_dir, "\\"); + wcscat(appdata_dir, L"\\"); c16stombs(appdata_dir_a, appdata_dir, 1024); rom_add_path(appdata_dir_a); } From fe94e79fa0453fbb3af9d3261ab6487ffe0e5fdf Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 11 Apr 2022 00:55:24 +0600 Subject: [PATCH 37/37] qt: Fix crashes on failed loads of media images --- src/qt/qt_mediamenu.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/qt/qt_mediamenu.cpp b/src/qt/qt_mediamenu.cpp index 8ffccffdd..64f547272 100644 --- a/src/qt/qt_mediamenu.cpp +++ b/src/qt/qt_mediamenu.cpp @@ -338,6 +338,9 @@ void MediaMenu::floppyExportTo86f(int i) { void MediaMenu::floppyUpdateMenu(int i) { QString name = floppyfns[i]; + if (!floppyMenus.contains(i)) + return; + auto* menu = floppyMenus[i]; auto childs = menu->children(); @@ -412,6 +415,8 @@ void MediaMenu::cdromReload(int i) { void MediaMenu::cdromUpdateMenu(int i) { QString name = cdrom[i].image_path; + if (!cdromMenus.contains(i)) + return; auto* menu = cdromMenus[i]; auto childs = menu->children(); @@ -515,6 +520,8 @@ void MediaMenu::zipReload(int i) { void MediaMenu::zipUpdateMenu(int i) { QString name = zip_drives[i].image_path; QString prev_name = zip_drives[i].prev_image_path; + if (!zipMenus.contains(i)) + return; auto* menu = zipMenus[i]; auto childs = menu->children(); @@ -612,6 +619,8 @@ void MediaMenu::moReload(int i) { void MediaMenu::moUpdateMenu(int i) { QString name = mo_drives[i].image_path; QString prev_name = mo_drives[i].prev_image_path; + if (!moMenus.contains(i)) + return; auto* menu = moMenus[i]; auto childs = menu->children();