From 3e9554dd5011ac30e81fcae3a624a9ef3394f2cf Mon Sep 17 00:00:00 2001 From: zoltanvb Date: Fri, 23 Dec 2022 22:08:01 +0100 Subject: [PATCH] Automatic detection of multi-disk / multi-tape content Use known patterns (e.g. TOSEC, CPC-Clean-DB) to detect and automatically add the rest of the disk/tape images when opening the first one in set. Disk/tape changing is still manual. --- core/core.hpp | 39 +++++++++++++++++++++++++++++++++++++++ core/main.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/core/core.hpp b/core/core.hpp index ef23c5d..c9106d9 100644 --- a/core/core.hpp +++ b/core/core.hpp @@ -224,6 +224,45 @@ const std::string locale_identifiers[LOCALE_AMOUNT] = { "(uk)", "[req zrom]", "[req brd-rom]", "(es)", "(fr)" }; +const std::multimap multidisk_replacements = { +{"Tape 1 of 2 Side A" , "Tape 2 of 2 Side B"}, +{"Tape 1 of 4 Side A" , "Tape 2 of 4 Side B"}, +{"Tape 1 of 4 Side A" , "Tape 3 of 4 Side A"}, +{"Tape 1 of 4 Side A" , "Tape 4 of 4 Side B"}, +{"Tape 1 of" , "Tape 2 of"}, +{"Tape 1 of" , "Tape 3 of"}, +{"Tape 1 of" , "Tape 4 of"}, +{"Tape 1 of" , "Tape 5 of"}, +{"Tape 1 of" , "Tape 6 of"}, +{"Tape 1 of" , "Tape 7 of"}, +{"Tape 1 of" , "Tape 8 of"}, +{"Tape 1 of" , "Tape 9 of"}, +{"Tape 1 of" , "Tape 10 of"}, +{"Disk 1 Side A" , "Disk 1 Side B"}, +{"Disk 1 Side A" , "Disk 2 Side A"}, +{"Disk 1 Side A" , "Disk 2 Side B"}, +{"Disk 1 Side A" , "Disk 3 Side A"}, +{"Disk 1 Side A" , "Disk 3 Side B"}, +{"Disk 1A" , "Disk 1B"}, +{"Disk 1A" , "Disk 2A"}, +{"Disk 1A" , "Disk 2B"}, +{"Disk 1A" , "Disk 3A"}, +{"Disk 1A" , "Disk 3B"}, +{"Disk 1 of" , "Disk 2 of"}, +{"Disk 1 of" , "Disk 3 of"}, +{"Disk 1 of" , "Disk 4 of"}, +{"Disk 1 of" , "Disk 5 of"}, +{"Disk 1 of" , "Disk 6 of"}, +{"Side 1A" , "Side 1B"}, +{"Side 1A" , "Side 2A"}, +{"Side 1A" , "Side 2B"}, +{"Side 1A" , "Side 3A"}, +{"Side 1A" , "Side 3B"}, +{"Side 1A" , "Side 4A"}, +{"Side 1A" , "Side 4B"}, +{"Side A" , "Side B"}, +}; + class LibretroCore { private: diff --git a/core/main.cpp b/core/main.cpp index 22856a9..3bcb7f9 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -41,7 +41,6 @@ EP Mouse support achievement support test mp3 support with sndfile 1.1 - cmake won't find lame / mpeg123 when compiling libsndfile led driver for tape / disk loading - see comments inside -name-based autodetect for multi-disk, multi-tape interface support (cpc 3 guerra) */ @@ -115,7 +114,7 @@ bool maxUsersSupported = true; unsigned diskIndex = 0; unsigned diskCount = 1; -#define MAX_DISK_COUNT 6 +#define MAX_DISK_COUNT 10 std::string diskPaths[MAX_DISK_COUNT]; std::string diskNames[MAX_DISK_COUNT]; bool diskEjected = false; @@ -418,6 +417,48 @@ static bool get_image_label_cb(unsigned index, char *label, size_t len) { return true; } +static bool add_new_image_auto(const char *path) { + + unsigned index = diskCount; + if (diskCount >= MAX_DISK_COUNT) return false; + diskCount++; + log_cb(RETRO_LOG_DEBUG, "Disk control: add new image (%d) as %s\n",diskCount,path); + + diskPaths[index] = path; + std::string contentPath; + Ep128Emu::splitPath(diskPaths[index],contentPath,diskNames[index]); + return true; +} + +static void scan_multidisk_files(const char *path) { + + std::string filename(path); + std::string filePrefix; + std::string filePostfix; + std::string additionalFile; + std::map< std::string, std::string >::const_iterator iter_multidisk; + + for (iter_multidisk = Ep128Emu::multidisk_replacements.begin(); iter_multidisk != Ep128Emu::multidisk_replacements.end(); ++iter_multidisk) + { + size_t idx = filename.rfind((*iter_multidisk).first); + if(idx != std::string::npos) { + filePrefix = filename.substr(0,idx); + filePostfix = filename.substr(idx+(*iter_multidisk).first.length()); + additionalFile = filePrefix + (*iter_multidisk).second.c_str() + filePostfix; + + if(Ep128Emu::does_file_exist(additionalFile.c_str())) + { + log_cb(RETRO_LOG_INFO, "Multidisk additional file found: %s => %s\n",filename.c_str(), additionalFile.c_str()); + if (!add_new_image_auto(additionalFile.c_str())) { + log_cb(RETRO_LOG_WARN, "Multidisk additional image add unsuccessful: %s\n",additionalFile.c_str()); + break; + } + } + } + } +} + + void retro_init(void) { @@ -579,7 +620,7 @@ void retro_get_system_info(struct retro_system_info *info) { memset(info, 0, sizeof(*info)); info->library_name = "ep128emu"; - info->library_version = "v1.2.4"; + info->library_version = "v1.2.5"; info->need_fullpath = true; info->valid_extensions = "img|dsk|tap|dtf|com|trn|128|bas|cas|cdt|tzx|wav|tvcwav|."; } @@ -1006,6 +1047,9 @@ bool retro_load_game(const struct retro_game_info *info) /* tape = openTapeFile(fileName.c_str(), 0, defaultTapeSampleRate, bitsPerSample);*/ } + if (diskContent || tapeContent) { + scan_multidisk_files(info->path); + } if (fileContent) { config->fileio.workingDirectory = contentPath;