This commit is contained in:
twinaphex 2016-08-14 15:09:15 +02:00
parent 34c8b54bbe
commit 176c19f582
2 changed files with 95 additions and 89 deletions

View File

@ -974,119 +974,127 @@ MDFNGI EmulatedPCE_Fast =
2, // Number of output sound channels
};
#ifdef NEED_CD
static void ReadM3U(std::vector<std::string> &file_list, std::string path, unsigned depth = 0)
static bool ReadM3U(std::vector<std::string> &file_list, std::string path, unsigned depth = 0)
{
std::vector<std::string> ret;
FileWrapper m3u_file(path.c_str(), FileWrapper::MODE_READ, _("M3U CD Set"));
std::string dir_path;
char linebuf[2048];
std::vector<std::string> ret;
FileWrapper m3u_file(path.c_str(), FileWrapper::MODE_READ, _("M3U CD Set"));
std::string dir_path;
char linebuf[2048];
bool result = true;
MDFN_GetFilePathComponents(path, &dir_path);
MDFN_GetFilePathComponents(path, &dir_path);
while(m3u_file.get_line(linebuf, sizeof(linebuf)))
{
std::string efp;
while(m3u_file.get_line(linebuf, sizeof(linebuf)))
{
std::string efp;
if(linebuf[0] == '#') continue;
MDFN_rtrim(linebuf);
if(linebuf[0] == 0) continue;
if(linebuf[0] == '#') continue;
MDFN_rtrim(linebuf);
if(linebuf[0] == 0) continue;
efp = MDFN_EvalFIP(dir_path, std::string(linebuf));
efp = MDFN_EvalFIP(dir_path, std::string(linebuf));
if(efp.size() >= 4 && efp.substr(efp.size() - 4) == ".m3u")
{
if(efp == path)
throw(MDFN_Error(0, _("M3U at \"%s\" references self."), efp.c_str()));
if(efp.size() >= 4 && efp.substr(efp.size() - 4) == ".m3u")
{
if(efp == path)
{
log_cb(RETRO_LOG_ERROR, "M3U at \"%s\" references self.\n", efp.c_str());
result = false;
goto Breakout;
}
if(depth == 99)
throw(MDFN_Error(0, _("M3U load recursion too deep!")));
if(depth == 99)
{
log_cb(RETRO_LOG_ERROR, "M3U load recursion too deep!\n");
result = false;
goto Breakout;
}
ReadM3U(file_list, efp, depth++);
}
else
file_list.push_back(efp);
}
ReadM3U(file_list, efp, depth++);
}
else
file_list.push_back(efp);
}
Breakout:
return result;
}
#ifdef NEED_CD
static std::vector<CDIF *> CDInterfaces; // FIXME: Cleanup on error out.
#endif
// TODO: LoadCommon()
MDFNGI *MDFNI_LoadCD(const char *force_module, const char *devicename)
{
MDFN_printf(_("Loading %s...\n\n"), devicename ? devicename : _("PHYSICAL CD"));
bool ret = false;
log_cb(RETRO_LOG_INFO, "Loading %s...\n\n", devicename);
try
{
if(devicename && strlen(devicename) > 4 && !strcasecmp(devicename + strlen(devicename) - 4, ".m3u"))
{
std::vector<std::string> file_list;
ReadM3U(file_list, devicename);
for(unsigned i = 0; i < file_list.size(); i++)
if(devicename && strlen(devicename) > 4 && !strcasecmp(devicename + strlen(devicename) - 4, ".m3u"))
{
CDInterfaces.push_back(CDIF_Open(file_list[i].c_str(), false, old_cdimagecache));
std::vector<std::string> file_list;
if (ReadM3U(file_list, devicename))
ret = true;
for(unsigned i = 0; i < file_list.size(); i++)
{
CDInterfaces.push_back(CDIF_Open(file_list[i].c_str(), false, old_cdimagecache));
}
}
else
{
CDInterfaces.push_back(CDIF_Open(devicename, false, old_cdimagecache));
ret = true;
}
}
else
{
CDInterfaces.push_back(CDIF_Open(devicename, false, old_cdimagecache));
}
}
catch(std::exception &e)
{
MDFND_PrintError(e.what());
MDFN_PrintError(_("Error opening CD."));
return(0);
}
//
// Print out a track list for all discs.
//
MDFN_indent(1);
for(unsigned i = 0; i < CDInterfaces.size(); i++)
{
TOC toc;
if (!ret)
{
log_cb(RETRO_LOG_ERROR, "Error opening CD.\n");
return(0);
}
CDInterfaces[i]->ReadTOC(&toc);
//
// Print out a track list for all discs.
//
MDFN_indent(1);
for(unsigned i = 0; i < CDInterfaces.size(); i++)
{
TOC toc;
MDFN_printf(_("CD %d Layout:\n"), i + 1);
MDFN_indent(1);
CDInterfaces[i]->ReadTOC(&toc);
for(int32 track = toc.first_track; track <= toc.last_track; track++)
{
MDFN_printf(_("Track %2d, LBA: %6d %s\n"), track, toc.tracks[track].lba, (toc.tracks[track].control & 0x4) ? "DATA" : "AUDIO");
}
MDFN_printf(_("CD %d Layout:\n"), i + 1);
MDFN_indent(1);
MDFN_printf("Leadout: %6d\n", toc.tracks[100].lba);
MDFN_indent(-1);
MDFN_printf("\n");
}
MDFN_indent(-1);
for(int32 track = toc.first_track; track <= toc.last_track; track++)
{
MDFN_printf(_("Track %2d, LBA: %6d %s\n"), track, toc.tracks[track].lba, (toc.tracks[track].control & 0x4) ? "DATA" : "AUDIO");
}
MDFN_printf(_("Using module: supergrafx\n\n"));
MDFN_printf("Leadout: %6d\n", toc.tracks[100].lba);
MDFN_indent(-1);
MDFN_printf("\n");
}
MDFN_indent(-1);
if(!(LoadCD(&CDInterfaces)))
{
for(unsigned i = 0; i < CDInterfaces.size(); i++)
delete CDInterfaces[i];
CDInterfaces.clear();
MDFN_printf(_("Using module: supergrafx\n\n"));
MDFNGameInfo = NULL;
return(0);
}
if(!(LoadCD(&CDInterfaces)))
{
for(unsigned i = 0; i < CDInterfaces.size(); i++)
delete CDInterfaces[i];
CDInterfaces.clear();
//MDFNI_SetLayerEnableMask(~0ULL);
MDFNGameInfo = NULL;
return(0);
}
MDFN_LoadGameCheats(NULL);
MDFNMP_InstallReadPatches();
//MDFNI_SetLayerEnableMask(~0ULL);
return(MDFNGameInfo);
MDFN_LoadGameCheats(NULL);
MDFNMP_InstallReadPatches();
return(MDFNGameInfo);
}
#endif
MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
{
@ -1094,10 +1102,8 @@ MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
std::vector<FileExtensionSpecStruct> valid_iae;
MDFNGameInfo = &EmulatedPCE_Fast;
#ifdef NEED_CD
if(strlen(name) > 4 && (!strcasecmp(name + strlen(name) - 4, ".cue") || !strcasecmp(name + strlen(name) - 4, ".ccd") || !strcasecmp(name + strlen(name) - 4, ".toc") || !strcasecmp(name + strlen(name) - 4, ".m3u")))
return(MDFNI_LoadCD(force_module, name));
#endif
MDFN_printf(_("Loading %s...\n"),name);
@ -1306,9 +1312,7 @@ void retro_init(void)
else
log_cb = NULL;
#ifdef NEED_CD
CDUtility_Init();
#endif
const char *dir = NULL;
@ -1599,11 +1603,9 @@ void retro_unload_game(void)
MDFNGameInfo = NULL;
#ifdef NEED_CD
for(unsigned i = 0; i < CDInterfaces.size(); i++)
delete CDInterfaces[i];
CDInterfaces.clear();
#endif
}
static void update_input(void)

View File

@ -5,6 +5,8 @@
#include "video.h"
#include "../libretro.h"
typedef struct
{
const char *extension; // Example ".nes"
@ -337,4 +339,6 @@ typedef struct
extern int StateAction(void *data, int load, int data_only);
extern uint8 MemRead(uint32 addr);
extern retro_log_printf_t log_cb;
#endif