From 1527a3a38cb29f31dc6e99a41ed3a0c8be9c6278 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Tue, 10 Jul 2018 09:58:57 +0300 Subject: [PATCH] RTC and Flash ROM file path late resolve support. --- akiko.cpp | 6 ++++-- arcadia.cpp | 20 ++++++++++++++------ cdtv.cpp | 14 +++++++++----- cdtvcr.cpp | 8 +++++--- cfgfile.cpp | 11 +++++++---- cia.cpp | 8 ++++++-- include/options.h | 1 + od-win32/win32gui.cpp | 7 +------ x86.cpp | 6 ++++-- 9 files changed, 51 insertions(+), 30 deletions(-) diff --git a/akiko.cpp b/akiko.cpp index d4dbb717..d916c76d 100644 --- a/akiko.cpp +++ b/akiko.cpp @@ -86,9 +86,11 @@ static void nvram_read (void) if (is_board_enabled(&currprefs, ROMTYPE_CUBO, 0)) { cubo_nvram = cd32_nvram + currprefs.cs_cd32nvram_size; } - cd32_flashfile = zfile_fopen (currprefs.flashfile, _T("rb+"), ZFD_NORMAL); + TCHAR path[MAX_DPATH]; + cfgfile_resolve_path_out(currprefs.flashfile, path, MAX_DPATH, PATH_ROM); + cd32_flashfile = zfile_fopen (path, _T("rb+"), ZFD_NORMAL); if (!cd32_flashfile) - cd32_flashfile = zfile_fopen (currprefs.flashfile, _T("wb"), 0); + cd32_flashfile = zfile_fopen (path, _T("wb"), 0); if (cd32_flashfile) { int size = zfile_fread(cd32_nvram, 1, currprefs.cs_cd32nvram_size, cd32_flashfile); if (size == currprefs.cs_cd32nvram_size && maxlen > currprefs.cs_cd32nvram_size) diff --git a/arcadia.cpp b/arcadia.cpp index b2551ee3..82cff02a 100644 --- a/arcadia.cpp +++ b/arcadia.cpp @@ -449,9 +449,11 @@ int is_arcadia_rom (const TCHAR *path) static void nvram_write (void) { - struct zfile *f = zfile_fopen (currprefs.flashfile, _T("rb+"), ZFD_NORMAL); + TCHAR path[MAX_DPATH]; + cfgfile_resolve_path_out(currprefs.flashfile, path, MAX_DPATH, PATH_ROM); + struct zfile *f = zfile_fopen (path, _T("rb+"), ZFD_NORMAL); if (!f) { - f = zfile_fopen (currprefs.flashfile, _T("wb"), 0); + f = zfile_fopen (path, _T("wb"), 0); if (!f) return; } @@ -463,7 +465,9 @@ static void nvram_read (void) { struct zfile *f; - f = zfile_fopen (currprefs.flashfile, _T("rb"), ZFD_NORMAL); + TCHAR path[MAX_DPATH]; + cfgfile_resolve_path_out(currprefs.flashfile, path, MAX_DPATH, PATH_ROM); + f = zfile_fopen (path, _T("rb"), ZFD_NORMAL); memset (arbmemory + nvram_offset, 0, NVRAM_SIZE); if (!f) return; @@ -595,9 +599,11 @@ static int algmemory_initialized; static void alg_nvram_write (void) { - struct zfile *f = zfile_fopen (currprefs.flashfile, _T("rb+"), ZFD_NORMAL); + TCHAR path[MAX_DPATH]; + cfgfile_resolve_path_out(currprefs.flashfile, path, MAX_DPATH, PATH_ROM); + struct zfile *f = zfile_fopen (path, _T("rb+"), ZFD_NORMAL); if (!f) { - f = zfile_fopen (currprefs.flashfile, _T("wb"), 0); + f = zfile_fopen (path, _T("wb"), 0); if (!f) return; } @@ -609,7 +615,9 @@ static void alg_nvram_read (void) { struct zfile *f; - f = zfile_fopen (currprefs.flashfile, _T("rb"), ZFD_NORMAL); + TCHAR path[MAX_DPATH]; + cfgfile_resolve_path_out(currprefs.flashfile, path, MAX_DPATH, PATH_ROM); + f = zfile_fopen (path, _T("rb"), ZFD_NORMAL); memset (algmemory, 0, ALG_NVRAM_SIZE); if (!f) return; diff --git a/cdtv.cpp b/cdtv.cpp index 71f2e1ef..a4f03894 100644 --- a/cdtv.cpp +++ b/cdtv.cpp @@ -1534,6 +1534,7 @@ addrbank dmac_bank = { #define CDTV_NVRAM_MASK 16383 #define CDTV_NVRAM_SIZE 32768 static uae_u8 cdtv_battram[CDTV_NVRAM_SIZE]; +static TCHAR flashfilepath[MAX_DPATH]; static void cdtv_loadcardmem (uae_u8 *p, int size) { @@ -1542,7 +1543,8 @@ static void cdtv_loadcardmem (uae_u8 *p, int size) if (!size) return; memset (p, 0, size); - f = zfile_fopen (currprefs.flashfile, _T("rb"), ZFD_NORMAL); + cfgfile_resolve_path_out(currprefs.flashfile, flashfilepath, MAX_DPATH, PATH_ROM); + f = zfile_fopen (flashfilepath, _T("rb"), ZFD_NORMAL); if (!f) return; zfile_fseek (f, CDTV_NVRAM_SIZE, SEEK_SET); @@ -1556,7 +1558,8 @@ static void cdtv_savecardmem (uae_u8 *p, int size) if (!size) return; - f = zfile_fopen (currprefs.flashfile, _T("rb+"), ZFD_NORMAL); + cfgfile_resolve_path_out(currprefs.flashfile, flashfilepath, MAX_DPATH, PATH_ROM); + f = zfile_fopen (flashfilepath, _T("rb+"), ZFD_NORMAL); if (!f) return; zfile_fseek (f, CDTV_NVRAM_SIZE, SEEK_SET); @@ -1570,9 +1573,10 @@ static void cdtv_battram_reset (void) int v; memset (cdtv_battram, 0, CDTV_NVRAM_SIZE); - f = zfile_fopen (currprefs.flashfile, _T("rb+"), ZFD_NORMAL); + cfgfile_resolve_path_out(currprefs.flashfile, flashfilepath, MAX_DPATH, PATH_ROM); + f = zfile_fopen (flashfilepath, _T("rb+"), ZFD_NORMAL); if (!f) { - f = zfile_fopen (currprefs.flashfile, _T("wb"), 0); + f = zfile_fopen (flashfilepath, _T("wb"), 0); if (f) { zfile_fwrite (cdtv_battram, CDTV_NVRAM_SIZE, 1, f); zfile_fclose (f); @@ -1596,7 +1600,7 @@ void cdtv_battram_write (int addr, int v) if (cdtv_battram[offset] == v) return; cdtv_battram[offset] = v; - f = zfile_fopen (currprefs.flashfile, _T("rb+"), ZFD_NORMAL); + f = zfile_fopen (flashfilepath, _T("rb+"), ZFD_NORMAL); if (!f) return; zfile_fseek (f, offset, SEEK_SET); diff --git a/cdtvcr.cpp b/cdtvcr.cpp index 17fddad0..5d91be72 100644 --- a/cdtvcr.cpp +++ b/cdtvcr.cpp @@ -102,6 +102,7 @@ static int cd_led; static volatile int subcodebufferoffset, subcodebufferoffsetw; static uae_u8 subcodebufferinuse[MAX_SUBCODEBUFFER]; static uae_u8 subcodebuffer[MAX_SUBCODEBUFFER * SUB_CHANNEL_SIZE]; +static TCHAR flashfilepath[MAX_DPATH]; static void cdtvcr_battram_reset (void) { @@ -109,9 +110,10 @@ static void cdtvcr_battram_reset (void) int v; memset (cdtvcr_ram, 0, CDTVCR_RAM_SIZE); - f = zfile_fopen (currprefs.flashfile, _T("rb+"), ZFD_NORMAL); + cfgfile_resolve_path_out(currprefs.flashfile, flashfilepath, MAX_DPATH, PATH_ROM); + f = zfile_fopen (flashfilepath, _T("rb+"), ZFD_NORMAL); if (!f) { - f = zfile_fopen (currprefs.flashfile, _T("wb"), 0); + f = zfile_fopen (flashfilepath, _T("wb"), 0); if (f) { zfile_fwrite (cdtvcr_ram, CDTVCR_RAM_SIZE, 1, f); zfile_fclose (f); @@ -135,7 +137,7 @@ static void cdtvcr_battram_write (int addr, int v) if (cdtvcr_ram[offset] == v) return; cdtvcr_ram[offset] = v; - f = zfile_fopen (currprefs.flashfile, _T("rb+"), ZFD_NORMAL); + f = zfile_fopen (flashfilepath, _T("rb+"), ZFD_NORMAL); if (!f) return; zfile_fseek (f, offset, SEEK_SET); diff --git a/cfgfile.cpp b/cfgfile.cpp index f939ca28..27d996e2 100644 --- a/cfgfile.cpp +++ b/cfgfile.cpp @@ -992,6 +992,9 @@ void cfgfile_resolve_path_out(const TCHAR *path, TCHAR *out, int size, int type) case PATH_CD: s = cfgfile_subst_path_load(UNEXPANDED, &p->path_cd, path, false); break; + case PATH_ROM: + s = cfgfile_subst_path_load(UNEXPANDED, &p->path_rom, path, false); + break; case PATH_FLOPPY: _tcscpy(out, path); cfgfile_adjust_path(out, MAX_DPATH, &p->path_floppy); @@ -1679,9 +1682,9 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type) cfgfile_write_board_rom(p, f, &p->path_rom, &p->expansionboard[i]); } - cfgfile_write_path (f, &p->path_rom, _T("flash_file"), p->flashfile); + cfgfile_write_str(f, _T("flash_file"), p->flashfile); cfgfile_write_path (f, &p->path_rom, _T("cart_file"), p->cartfile); - cfgfile_write_path (f, &p->path_rom, _T("rtc_file"), p->rtcfile); + cfgfile_write_str(f, _T("rtc_file"), p->rtcfile); if (p->cartident[0]) cfgfile_write_str (f, _T("cart"), p->cartident); cfgfile_dwrite_path (f, &p->path_rom, _T("picassoiv_rom_file"), p->picassoivromfile); @@ -5280,9 +5283,9 @@ static int cfgfile_parse_hardware (struct uae_prefs *p, const TCHAR *option, TCH || cfgfile_path (option, value, _T("kickstart_ext_rom_file2"), p->romextfile2, sizeof p->romextfile2 / sizeof (TCHAR), &p->path_rom) || cfgfile_rom(option, value, _T("kickstart_rom_file_id"), p->romfile, sizeof p->romfile / sizeof(TCHAR)) || cfgfile_rom (option, value, _T("kickstart_ext_rom_file_id"), p->romextfile, sizeof p->romextfile / sizeof (TCHAR)) - || cfgfile_path (option, value, _T("flash_file"), p->flashfile, sizeof p->flashfile / sizeof (TCHAR), &p->path_rom) + || cfgfile_string(option, value, _T("flash_file"), p->flashfile, sizeof p->flashfile / sizeof (TCHAR)) || cfgfile_path (option, value, _T("cart_file"), p->cartfile, sizeof p->cartfile / sizeof (TCHAR), &p->path_rom) - || cfgfile_path (option, value, _T("rtc_file"), p->rtcfile, sizeof p->rtcfile / sizeof (TCHAR), &p->path_rom) + || cfgfile_string(option, value, _T("rtc_file"), p->rtcfile, sizeof p->rtcfile / sizeof (TCHAR)) || cfgfile_path(option, value, _T("picassoiv_rom_file"), p->picassoivromfile, sizeof p->picassoivromfile / sizeof(TCHAR), &p->path_rom) || cfgfile_string(option, value, _T("genlock_image"), p->genlock_image_file, sizeof p->genlock_image_file / sizeof(TCHAR)) || cfgfile_string(option, value, _T("genlock_video"), p->genlock_video_file, sizeof p->genlock_video_file / sizeof(TCHAR)) diff --git a/cia.cpp b/cia.cpp index bf5db603..fff9d29f 100644 --- a/cia.cpp +++ b/cia.cpp @@ -2173,7 +2173,9 @@ static void write_battclock (void) { if (!currprefs.rtcfile[0] || currprefs.cs_rtc == 0) return; - struct zfile *f = zfile_fopen (currprefs.rtcfile, _T("wb")); + TCHAR path[MAX_DPATH]; + cfgfile_resolve_path_out(currprefs.rtcfile, path, MAX_DPATH, PATH_ROM); + struct zfile *f = zfile_fopen (path, _T("wb")); if (f) { struct tm *ct; time_t t = time (0); @@ -2228,7 +2230,9 @@ void rtc_hardreset (void) rtc_ricoh.delayed_write = 0; } if (currprefs.rtcfile[0]) { - struct zfile *f = zfile_fopen (currprefs.rtcfile, _T("rb")); + TCHAR path[MAX_DPATH]; + cfgfile_resolve_path_out(currprefs.rtcfile, path, MAX_DPATH, PATH_ROM); + struct zfile *f = zfile_fopen (path, _T("rb")); if (f) { uae_u8 empty[13]; zfile_fread (empty, 13, 1, f); diff --git a/include/options.h b/include/options.h index ce6fdcad..3a9b336f 100644 --- a/include/options.h +++ b/include/options.h @@ -40,6 +40,7 @@ struct multipath { #define PATH_GENLOCK_IMAGE 6 #define PATH_GENLOCK_VIDEO 7 #define PATH_GEO 8 +#define PATH_ROM 9 struct strlist { struct strlist *next; diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index 63c54885..62b54fd0 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -2150,6 +2150,7 @@ void target_multipath_modified(struct uae_prefs *p) memcpy(&currprefs.path_hardfile, &p->path_hardfile, sizeof(struct multipath)); memcpy(&currprefs.path_floppy, &p->path_floppy, sizeof(struct multipath)); memcpy(&currprefs.path_cd, &p->path_cd, sizeof(struct multipath)); + memcpy(&currprefs.path_rom, &p->path_rom, sizeof(struct multipath)); } int target_cfgfile_load (struct uae_prefs *p, const TCHAR *filename, int type, int isdefault) @@ -2200,10 +2201,6 @@ int target_cfgfile_load (struct uae_prefs *p, const TCHAR *filename, int type, i ct2 = 0; regqueryint (NULL, _T("ConfigFile_NoAuto"), &ct2); v = cfgfile_load (p, fname, &type2, ct2, isdefault ? 0 : 1); - if (p == &workprefs) { - memcpy(&currprefs.path_hardfile, &p->path_hardfile, sizeof(struct multipath)); - memcpy(&currprefs.path_floppy, &p->path_floppy, sizeof(struct multipath)); - } if (!v) return v; if (type > 0) @@ -3093,11 +3090,9 @@ int DiskSelection_2 (HWND hDlg, WPARAM wParam, int flag, struct uae_prefs *prefs break; case IDC_FLASHFILE: _tcscpy (workprefs.flashfile, full_path); - fullpath (workprefs.flashfile, MAX_DPATH); break; case IDC_RTCFILE: _tcscpy (workprefs.rtcfile, full_path); - fullpath (workprefs.rtcfile, MAX_DPATH); break; case IDC_CARTFILE: _tcscpy (workprefs.cartfile, full_path); diff --git a/x86.cpp b/x86.cpp index 626bb8fd..7a76447e 100644 --- a/x86.cpp +++ b/x86.cpp @@ -3386,10 +3386,12 @@ bool x86_bridge_init(struct autoconfig_info *aci, uae_u32 romtype, int type) TIMER_Init(dosbox_sec); FPU_Init(dosbox_sec); if (xb->type >= TYPE_2286) { + TCHAR path[MAX_DPATH]; + cfgfile_resolve_path_out(currprefs.flashfile, path, MAX_DPATH, PATH_ROM); xb->cmossize = xb->type == TYPE_2386 ? 192 : 64; - xb->cmosfile = zfile_fopen(currprefs.flashfile, _T("rb+"), ZFD_NORMAL); + xb->cmosfile = zfile_fopen(path, _T("rb+"), ZFD_NORMAL); if (!xb->cmosfile) { - xb->cmosfile = zfile_fopen(currprefs.flashfile, _T("wb")); + xb->cmosfile = zfile_fopen(path, _T("wb")); } memset(xb->cmosregs, 0, sizeof xb->cmosregs); if (xb->cmosfile) { -- 2.47.3