Skip to content

Commit

Permalink
Automatic detection of multi-disk / multi-tape content
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zoltanvb committed Dec 23, 2022
1 parent 657980c commit 3e9554d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
39 changes: 39 additions & 0 deletions core/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,45 @@ const std::string locale_identifiers[LOCALE_AMOUNT] = {
"(uk)", "[req zrom]", "[req brd-rom]", "(es)", "(fr)"
};

const std::multimap<std::string, std::string> 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:
Expand Down
50 changes: 47 additions & 3 deletions core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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|.";
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3e9554d

Please sign in to comment.