Merge branch 'master' into feature/global-config

This commit is contained in:
David Hrdlička
2025-08-06 12:26:10 +02:00
committed by GitHub
715 changed files with 96594 additions and 40250 deletions

View File

@@ -64,8 +64,8 @@ int fixed_size_x = 640;
int fixed_size_y = 480;
extern int title_set;
extern wchar_t sdl_win_title[512];
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS];
plat_joystick_state_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
joystick_state_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS];
int joysticks_present;
SDL_mutex *blitmtx;
SDL_threadID eventthread;
@@ -208,22 +208,33 @@ dynld_module(const char *name, dllimp_t *table)
return modhandle;
}
#define TMPFILE_BUFSIZE 1024 // Assumed max buffer size
void
plat_tempfile(char *bufp, char *prefix, char *suffix)
{
struct tm *calendertime;
struct timeval t;
time_t curtime;
size_t used = 0;
if (prefix != NULL)
sprintf(bufp, "%s-", prefix);
else
strcpy(bufp, "");
used = snprintf(bufp, TMPFILE_BUFSIZE, "%s-", prefix);
else if (TMPFILE_BUFSIZE > 0)
bufp[0] = '\0';
gettimeofday(&t, NULL);
curtime = time(NULL);
calendertime = localtime(&curtime);
sprintf(&bufp[strlen(bufp)], "%d%02d%02d-%02d%02d%02d-%03ld%s", calendertime->tm_year, calendertime->tm_mon, calendertime->tm_mday, calendertime->tm_hour, calendertime->tm_min, calendertime->tm_sec, t.tv_usec / 1000, suffix);
if (used < TMPFILE_BUFSIZE) {
snprintf(bufp + used, TMPFILE_BUFSIZE - used,
"%d%02d%02d-%02d%02d%02d-%03" PRId32 "%s",
calendertime->tm_year, calendertime->tm_mon, calendertime->tm_mday,
calendertime->tm_hour, calendertime->tm_min, calendertime->tm_sec,
(int32_t)(t.tv_usec / 1000), suffix);
}
}
#undef TMPFILE_BUFSIZE
int
plat_getcwd(char *bufp, int max)
@@ -565,7 +576,7 @@ main_thread(UNUSED(void *param))
old_time = new_time;
if (drawits > 0 && !dopause) {
/* Yes, so do one frame now. */
drawits -= 10;
drawits -= force_10ms ? 10 : 1;
if (drawits > 50)
drawits = 0;
@@ -573,7 +584,7 @@ main_thread(UNUSED(void *param))
pc_run();
/* Every 200 frames we save the machine status. */
if (++frames >= 200 && nvr_dosave) {
if (++frames >= (force_10ms ? 200 : 2000) && nvr_dosave) {
nvr_save();
nvr_dosave = 0;
frames = 0;
@@ -783,65 +794,83 @@ plat_pause(int p)
}
}
#define TMP_PATH_BUFSIZE 1024
void
plat_init_rom_paths(void)
{
#ifndef __APPLE__
if (getenv("XDG_DATA_HOME")) {
char xdg_rom_path[1024] = { 0 };
strncpy(xdg_rom_path, getenv("XDG_DATA_HOME"), 1024);
path_slash(xdg_rom_path);
strncat(xdg_rom_path, "86Box/", 1023);
if (!plat_dir_check(xdg_rom_path))
const char *xdg_data_home = getenv("XDG_DATA_HOME");
if (xdg_data_home) {
char xdg_rom_path[TMP_PATH_BUFSIZE] = {0};
size_t used = snprintf(xdg_rom_path, sizeof(xdg_rom_path), "%s/", xdg_data_home);
if (used < sizeof(xdg_rom_path))
used += snprintf(xdg_rom_path + used, sizeof(xdg_rom_path) - used, "86Box/");
if (used < sizeof(xdg_rom_path) && !plat_dir_check(xdg_rom_path))
plat_dir_create(xdg_rom_path);
strcat(xdg_rom_path, "roms/");
if (!plat_dir_check(xdg_rom_path))
if (used < sizeof(xdg_rom_path))
used += snprintf(xdg_rom_path + used, sizeof(xdg_rom_path) - used, "roms/");
if (used < sizeof(xdg_rom_path) && !plat_dir_check(xdg_rom_path))
plat_dir_create(xdg_rom_path);
rom_add_path(xdg_rom_path);
if (used < sizeof(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);
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);
rom_add_path(home_rom_path);
}
if (getenv("XDG_DATA_DIRS")) {
char *xdg_rom_paths = strdup(getenv("XDG_DATA_DIRS"));
char *xdg_rom_paths_orig = xdg_rom_paths;
char *cur_xdg_rom_path = NULL;
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);
path_slash(real_xdg_rom_path);
strcat(real_xdg_rom_path, "86Box/roms/");
rom_add_path(real_xdg_rom_path);
}
const char *home = getenv("HOME");
if (!home) {
struct passwd *pw = getpwuid(getuid());
if (pw)
home = pw->pw_dir;
}
if (home) {
char home_rom_path[TMP_PATH_BUFSIZE] = {0};
size_t used = snprintf(home_rom_path, sizeof(home_rom_path),
"%s/.local/share/86Box/", home);
if (used < sizeof(home_rom_path) && !plat_dir_check(home_rom_path))
plat_dir_create(home_rom_path);
if (used < sizeof(home_rom_path))
used += snprintf(home_rom_path + used,
sizeof(home_rom_path) - used, "roms/");
if (used < sizeof(home_rom_path) && !plat_dir_check(home_rom_path))
plat_dir_create(home_rom_path);
if (used < sizeof(home_rom_path))
rom_add_path(home_rom_path);
}
}
const char *xdg_data_dirs = getenv("XDG_DATA_DIRS");
if (xdg_data_dirs) {
char *xdg_rom_paths = strdup(xdg_data_dirs);
if (xdg_rom_paths) {
// Trim trailing colons
size_t len = strlen(xdg_rom_paths);
while (len > 0 && xdg_rom_paths[len - 1] == ':')
xdg_rom_paths[--len] = '\0';
char *saveptr = NULL;
char *cur_xdg = strtok_r(xdg_rom_paths, ":", &saveptr);
while (cur_xdg) {
char real_xdg_rom_path[TMP_PATH_BUFSIZE] = {0};
size_t used = snprintf(real_xdg_rom_path,
sizeof(real_xdg_rom_path),
"%s/86Box/roms/", cur_xdg);
if (used < sizeof(real_xdg_rom_path))
rom_add_path(real_xdg_rom_path);
cur_xdg = strtok_r(NULL, ":", &saveptr);
}
free(xdg_rom_paths);
}
free(xdg_rom_paths_orig);
} else {
rom_add_path("/usr/local/share/86Box/roms/");
rom_add_path("/usr/share/86Box/roms/");
}
#else
char default_rom_path[1024] = { '\0' };
char default_rom_path[TMP_PATH_BUFSIZE] = {0};
getDefaultROMPath(default_rom_path);
rom_add_path(default_rom_path);
#endif
}
#undef TMP_PATH_BUFSIZE
void
plat_get_global_config_dir(char *outbuf, const size_t len)
@@ -919,6 +948,11 @@ void (*f_rl_callback_handler_remove)(void) = NULL;
# define LIBEDIT_LIBRARY "libedit.so"
#endif
void ui_sb_update_icon_wp(int tag, int state)
{
/* No-op */
}
uint32_t
timer_onesec(uint32_t interval, UNUSED(void *param))
{
@@ -972,12 +1006,12 @@ monitor_thread(UNUSED(void *param))
printf(
"fddload <id> <filename> <wp> - Load floppy disk image into drive <id>.\n"
"cdload <id> <filename> - Load CD-ROM image into drive <id>.\n"
"zipload <id> <filename> <wp> - Load ZIP image into ZIP drive <id>.\n"
"rdiskload <id> <filename> <wp> - Load removable disk image into removable disk drive <id>.\n"
"cartload <id> <filename> <wp> - Load cartridge image into cartridge drive <id>.\n"
"moload <id> <filename> <wp> - Load MO image into MO drive <id>.\n\n"
"fddeject <id> - eject disk from floppy drive <id>.\n"
"cdeject <id> - eject disc from CD-ROM drive <id>.\n"
"zipeject <id> - eject ZIP image from ZIP drive <id>.\n"
"rdiskeject <id> - eject removable disk image from removable disk drive <id>.\n"
"carteject <id> - eject cartridge from drive <id>.\n"
"moeject <id> - eject image from MO drive <id>.\n\n"
"hardreset - hard reset the emulated system.\n"
@@ -1082,8 +1116,8 @@ monitor_thread(UNUSED(void *param))
mo_eject(atoi(xargv[1]));
} else if (strncasecmp(xargv[0], "carteject", 8) == 0 && cmdargc >= 2) {
cartridge_eject(atoi(xargv[1]));
} else if (strncasecmp(xargv[0], "zipeject", 8) == 0 && cmdargc >= 2) {
zip_eject(atoi(xargv[1]));
} else if (strncasecmp(xargv[0], "rdiskeject", 8) == 0 && cmdargc >= 2) {
rdisk_eject(atoi(xargv[1]));
} else if (strncasecmp(xargv[0], "fddload", 7) == 0 && cmdargc >= 4) {
uint8_t id;
uint8_t wp;
@@ -1150,7 +1184,7 @@ monitor_thread(UNUSED(void *param))
printf("Inserting tape into cartridge holder %hhu: %s\n", id, fn);
cartridge_mount(id, fn, wp);
}
} else if (strncasecmp(xargv[0], "zipload", 7) == 0 && cmdargc >= 4) {
} else if (strncasecmp(xargv[0], "rdiskload", 7) == 0 && cmdargc >= 4) {
uint8_t id;
uint8_t wp;
bool err = false;
@@ -1169,8 +1203,8 @@ monitor_thread(UNUSED(void *param))
if (fn[strlen(fn) - 1] == '\''
|| fn[strlen(fn) - 1] == '"')
fn[strlen(fn) - 1] = '\0';
printf("Inserting disk into ZIP drive %c: %s\n", id + 'A', fn);
zip_mount(id, fn, wp);
printf("Inserting disk into removable disk drive %c: %s\n", id + 'A', fn);
rdisk_mount(id, fn, wp);
}
}
free(line);