From c81247306bcff7f4db1bc3b17ad68eea316b9596 Mon Sep 17 00:00:00 2001 From: Andre Zeps Date: Tue, 11 Nov 2025 15:51:35 +0100 Subject: [PATCH] CD-i: Adapt save file name according to PSX behavior (#1060) All of these scenarios will share one save file: - Root folder titles - Multi-Disc titles - CHD and CUE/BIN --- support/cdi/cdi.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/support/cdi/cdi.cpp b/support/cdi/cdi.cpp index fd1deba..e054b9e 100644 --- a/support/cdi/cdi.cpp +++ b/support/cdi/cdi.cpp @@ -840,11 +840,36 @@ void cdi_mount_cd(int s_index, const char *filename) { int loaded = 0; + /// Last used directory for save file management + /// Must be static to keep the value between mount calls + static char last_dir[1024] = {}; + if (strlen(filename)) { if (load_cd_image(filename, &toc) && toc.last) { - cdi_mount_save(filename); + const char *p = strrchr(filename, '/'); + int cur_len = p ? p - filename : 0; + int old_len = strlen(last_dir); + + int same_game = old_len && (cur_len == old_len) && !strncmp(last_dir, filename, old_len); + + // Handle multi disc titles and avoid re-mounting the save file + // to avoid resets on the core + if (!same_game) + { + strncpy(last_dir, filename, sizeof(last_dir)); + char *p = strrchr(last_dir, '/'); + if (p) + *p = 0; + else + *last_dir = 0; + + // FPGA side will be informed about the mount and perform a reset + // if configured to do so + cdi_mount_save(last_dir); + } + prepare_toc_buffer(&toc); user_io_set_index(0); mount_cd(toc.end * CD_SECTOR_LEN, s_index);