diff --git a/src/emu.h b/src/emu.h index 07e3c05..b19f2f5 100644 --- a/src/emu.h +++ b/src/emu.h @@ -8,7 +8,7 @@ * * Main include file for the application. * - * Version: @(#)emu.h 1.0.3 2018/02/28 + * Version: @(#)emu.h 1.0.4 2018/03/02 * * Author: Fred N. van Kempen, * @@ -155,7 +155,7 @@ extern int serial_do_log; extern int nic_do_log; #endif -extern wchar_t exe_path[1024]; /* path (dir) of executable */ +extern wchar_t emu_path[1024]; /* emu installation path */ extern wchar_t usr_path[1024]; /* path (dir) of user data */ extern wchar_t cfg_path[1024]; /* full path of config file */ extern FILE *stdlog; /* file to log output to */ diff --git a/src/pc.c b/src/pc.c index 52e58e7..a35c592 100644 --- a/src/pc.c +++ b/src/pc.c @@ -8,7 +8,7 @@ * * Main emulator module where most things are controlled. * - * Version: @(#)pc.c 1.0.3 2018/03/01 + * Version: @(#)pc.c 1.0.4 2018/03/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -175,7 +175,7 @@ int clockrate; int gfx_present[GFX_MAX]; /* should not be here */ -wchar_t exe_path[1024]; /* path (dir) of executable */ +wchar_t emu_path[1024]; /* emu installation path */ wchar_t usr_path[1024]; /* path (dir) of user data */ wchar_t cfg_path[1024]; /* full path of config file */ FILE *stdlog = NULL; /* file to log output to */ @@ -307,9 +307,33 @@ pc_init(int argc, wchar_t *argv[]) int c; /* Grab the executable's full path. */ - plat_get_exe_name(exe_path, sizeof(exe_path)-1); - p = plat_get_filename(exe_path); - *p = L'\0'; + plat_get_exe_name(emu_path, sizeof(emu_path)-1); + if ((p = plat_get_basename(emu_path)) != NULL) + *p = L'\0'; + + /* + * See if we are perhaps in a "bin/" subfolder of + * the installation path, in which case the real + * root of the installation is one level up. We + * can test this by looking for the 'roms' folder. + */ + wcscpy(path, emu_path); + p = plat_get_basename(path); + plat_path_slash(path); + wcscat(path, ROMS_PATH); + if (! plat_dir_check(path)) { + /* No 'roms' folder found, so go up one level. */ + if (p != NULL) + *p = L'\0'; + plat_path_slash(path); + wcscat(path, ROMS_PATH); + if (plat_dir_check(path)) { + if (p != NULL) + *p = L'\0'; + plat_path_slash(path); + wcscpy(emu_path, path); + } + } /* * Get the current working directory. @@ -481,7 +505,7 @@ usage: strftime(temp, sizeof(temp), "%Y/%m/%d %H:%M:%S", info); pclog("#\n# %ls v%ls logfile, created %s\n#\n", EMU_NAME_W, EMU_VERSION_W, temp); - pclog("# Emulator path: %ls\n", exe_path); + pclog("# Emulator path: %ls\n", emu_path); pclog("# Userfiles path: %ls\n", usr_path); pclog("# Configuration file: %ls\n#\n\n", cfg_path); diff --git a/src/plat.h b/src/plat.h index 859ac71..6da068d 100644 --- a/src/plat.h +++ b/src/plat.h @@ -8,7 +8,7 @@ * * Define the various platform support functions. * - * Version: @(#)plat.h 1.0.2 2018/02/21 + * Version: @(#)plat.h 1.0.3 2018/03/02 * * Author: Fred N. van Kempen, * @@ -101,16 +101,17 @@ GLOBAL char emu_version[128]; /* version ID string */ /* System-related functions. */ -extern wchar_t *fix_exe_path(wchar_t *str); +extern wchar_t *fix_emu_path(wchar_t *str); extern FILE *plat_fopen(wchar_t *path, wchar_t *mode); extern void plat_remove(wchar_t *path); extern int plat_getcwd(wchar_t *bufp, int max); extern int plat_chdir(wchar_t *path); -extern void plat_get_exe_name(wchar_t *s, int size); -extern wchar_t *plat_get_filename(wchar_t *s); -extern wchar_t *plat_get_extension(wchar_t *s); +extern void plat_get_exe_name(wchar_t *path, int size); +extern wchar_t *plat_get_basename(wchar_t *path); +extern wchar_t *plat_get_filename(wchar_t *path); +extern wchar_t *plat_get_extension(wchar_t *path); extern void plat_append_filename(wchar_t *dest, wchar_t *s1, wchar_t *s2); -extern void plat_put_backslash(wchar_t *s); +extern void plat_put_backslash(wchar_t *path); extern void plat_path_slash(wchar_t *path); extern int plat_path_abs(wchar_t *path); extern int plat_dir_check(wchar_t *path); diff --git a/src/rom.c b/src/rom.c index d9f24ad..9dc9e8b 100644 --- a/src/rom.c +++ b/src/rom.c @@ -13,7 +13,7 @@ * - c386sx16 BIOS fails checksum * - the loadfont() calls should be done elsewhere * - * Version: @(#)rom.c 1.0.4 2018/02/26 + * Version: @(#)rom.c 1.0.5 2018/03/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -63,7 +63,7 @@ rom_fopen(wchar_t *fn) { wchar_t temp[1024]; - wcscpy(temp, exe_path); + wcscpy(temp, emu_path); plat_put_backslash(temp); wcscat(temp, fn); @@ -76,7 +76,7 @@ rom_getfile(wchar_t *fn, wchar_t *s, int size) { FILE *f; - wcscpy(s, exe_path); + wcscpy(s, emu_path); plat_put_backslash(s); wcscat(s, fn); diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index caeff93..da84389 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -47,89 +47,89 @@ # Various compile-time options. ifndef STUFF -STUFF := + STUFF := endif # Add feature selections here. ifndef EXTRAS -EXTRAS := + EXTRAS := endif # Defaults for several build options (possibly defined in a chained file.) ifndef AUTODEP -AUTODEP := n + AUTODEP := n endif ifndef CRASHDUMP -CRASHDUMP := n + CRASHDUMP := n endif ifndef CROSS -CROSS := n + CROSS := n endif ifndef DEBUG -DEBUG := n + DEBUG := n endif ifndef OPTIM -OPTIM := n + OPTIM := n endif ifndef RELEASE -RELEASE := n + RELEASE := n endif ifndef X64 -X64 := n -endif -ifndef WX -WX := n -endif -ifndef USB -USB := n -endif -ifndef VNC -VNC := n -endif -ifndef RDP -RDP := n -endif -ifndef DEV_BUILD -DEV_BUILD := n -endif -ifndef DEV_BRANCH -DEV_BRANCH := n -endif -ifndef GREENB -GREENB := n -endif -ifndef LASERXT -LASERXT := n -endif -ifndef I686 -I686 := n -ifndef AMD_K -AMD_K := n -endif -endif -ifndef OPENAL -OPENAL := y -endif -ifndef PORTABLE3 -PORTABLE3 := n -endif -ifndef FLUIDSYNTH -FLUIDSYNTH := y -endif -ifndef MUNT -MUNT := y -endif -ifndef PAS16 -PAS16 := n -endif -ifndef STEALTH32 -STEALTH32 := n -endif -ifndef XL24 -XL24 := n + X64 := n endif ifndef DYNAREC -DYNAREC := y + DYNAREC := y +endif +ifndef WX + WX := n +endif +ifndef USB + USB := n +endif +ifndef VNC + VNC := n +endif +ifndef RDP + RDP := n +endif +ifndef DEV_BUILD + DEV_BUILD := n +endif +ifndef DEV_BRANCH + DEV_BRANCH := n +endif +ifndef GREENB + GREENB := n +endif +ifndef LASERXT + LASERXT := n +endif +ifndef I686 + I686 := n +endif +ifndef AMD_K + AMD_K := n +endif +ifndef PORTABLE3 + PORTABLE3 := n +endif +ifndef OPENAL + OPENAL := y +endif +ifndef FLUIDSYNTH + FLUIDSYNTH := y +endif +ifndef MUNT + MUNT := y +endif +ifndef PAS16 + PAS16 := n +endif +ifndef STEALTH32 + STEALTH32 := n +endif +ifndef XL24 + XL24 := n endif @@ -143,17 +143,16 @@ ifndef PROG endif ifeq ($(DEV_BUILD), y) -DEBUG := y -CRASHDUMP := y -DEV_BRANCH := y -I686 := y -AMD_K := y -GREENB := y -PORTABLE3 := y -LASERXT := y -PAS16 := y -STEALTH32 := y -XL24 := y + CRASHDUMP := y + DEV_BRANCH := y + I686 := y + AMD_K := y + GREENB := y + PORTABLE3 := y + LASERXT := y + PAS16 := y + STEALTH32 := y + XL24 := y endif # WxWidgets basic info. Extract using the config program. diff --git a/src/win/win.c b/src/win/win.c index 36fc75f..1454933 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -8,7 +8,7 @@ * * Platform main support module for Windows. * - * Version: @(#)win.c 1.0.2 2018/03/02 + * Version: @(#)win.c 1.0.3 2018/03/02 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -485,9 +485,9 @@ do_stop(void) void -plat_get_exe_name(wchar_t *s, int size) +plat_get_exe_name(wchar_t *bufp, int size) { - GetModuleFileName(hinstance, s, size); + GetModuleFileName(hinstance, bufp, size); } @@ -543,36 +543,52 @@ plat_path_abs(wchar_t *path) } +/* Return the last element of a pathname. */ wchar_t * -plat_get_filename(wchar_t *s) +plat_get_basename(wchar_t *path) { - int c = wcslen(s) - 1; + int c = wcslen(path); while (c > 0) { - if (s[c] == L'/' || s[c] == L'\\') - return(&s[c+1]); + if (path[c] == L'/' || path[c] == L'\\') + return(&path[c]); c--; } - return(s); + return(path); } wchar_t * -plat_get_extension(wchar_t *s) +plat_get_filename(wchar_t *path) { - int c = wcslen(s) - 1; + int c = wcslen(path) - 1; + + while (c > 0) { + if (path[c] == L'/' || path[c] == L'\\') + return(&path[c+1]); + c--; + } + + return(path); +} + + +wchar_t * +plat_get_extension(wchar_t *path) +{ + int c = wcslen(path) - 1; if (c <= 0) - return(s); + return(path); - while (c && s[c] != L'.') + while (c && path[c] != L'.') c--; if (!c) - return(&s[wcslen(s)]); + return(&path[wcslen(path)]); - return(&s[c+1]); + return(&path[c+1]); } @@ -585,12 +601,12 @@ plat_append_filename(wchar_t *dest, wchar_t *s1, wchar_t *s2) void -plat_put_backslash(wchar_t *s) +plat_put_backslash(wchar_t *path) { - int c = wcslen(s) - 1; + int c = wcslen(path) - 1; - if (s[c] != L'/' && s[c] != L'\\') - s[c] = L'/'; + if (path[c] != L'/' && path[c] != L'\\') + path[c] = L'/'; }