Skip to content

Commit

Permalink
config: allow adding custom roms paths to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Cpasjuste committed Oct 2, 2023
1 parent b3ee63c commit ff452ec
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 134 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ set(OPTION_BUILTIN_LIBCONFIG OFF CACHE BOOL "Build libconfig from sources")
set(OPTION_BUILTIN_MINIZIP OFF CACHE BOOL "Build minizip from sources")
set(OPTION_MPV_PLAYER ON CACHE BOOL "Add support for video snaps (mpv)")
set(OPTION_UPDATE_CONFIG OFF CACHE BOOL "Force config file updating")
set(OPTION_FTP_SERVER OFF CACHE BOOL "Embedded ftp server")
####################
# BUILD OPTIONS
####################
Expand Down
3 changes: 0 additions & 3 deletions src/cores/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ int main(int argc, char **argv) {
auto uiState = new PEMUUiMenuState(pemu_ui);
pemu_ui->init(uiRomList, uiMenu, uiEmu, uiState);

// save/update config
cfg->save();

while (!pemu_ui->done) {
pemu_ui->flip();
}
Expand Down
40 changes: 31 additions & 9 deletions src/cores/pfbneo/sources/pfbneo_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ using namespace pemu;
PFBAConfig::PFBAConfig(c2d::Io *io, int version) : PEMUConfig(io, "PFBNEO", version) {
printf("PFBNConfig(%s, v%i)\n", getPath().c_str(), version);

/// add custom roms paths to config
for (const auto &gl: PFBAConfig::getCoreGameListInfo()) {
std::string path = io->getDataPath() + gl.rom_path + "/";
getGroup(CFG_ID_ROMS)->addOption({gl.cfg_name, path});
io->create(path);
}

/// MAIN OPTIONS
get(PEMUConfig::OptId::UI_SHOW_ZIP_NAMES)->setArrayIndex(0);

Expand Down Expand Up @@ -65,6 +58,35 @@ PFBAConfig::PFBAConfig(c2d::Io *io, int version) : PEMUConfig(io, "PFBNEO", vers
get(PEMUConfig::OptId::EMU_AUDIO_FREQ)->setFlags(PEMUConfig::Flags::HIDDEN);
#endif

// "c2dui_romlist" will also reload config, but we need new roms paths
load();
// "romlist.cpp" (RomList::build) will also reload config, but we need new roms paths
PEMUConfig::load();

// add custom rom path
PEMUConfig::addRomPath("ARCADE", io->getDataPath() + "arcade/", {HARDWARE_PREFIX_ARCADE, 0, "Arcade"});
PEMUConfig::addRomPath("CHANNELF", io->getDataPath() + "channelf/", {HARDWARE_PREFIX_CHANNELF, 0, "Channel F"});
PEMUConfig::addRomPath("COLECO", io->getDataPath() + "coleco/", {HARDWARE_PREFIX_COLECO, 0, "ColecoVision"});
PEMUConfig::addRomPath("FDS", io->getDataPath() + "fds/", {HARDWARE_PREFIX_FDS, 0, "NES FDS"});
PEMUConfig::addRomPath("GAMEGEAR", io->getDataPath() + "gamegear/",
{HARDWARE_PREFIX_SEGA_GAME_GEAR, 0, "Sega Game Gear"});
PEMUConfig::addRomPath("MEGADRIVE", io->getDataPath() + "megadrive/",
{HARDWARE_PREFIX_SEGA_MEGADRIVE, 0, "Sega Megadrive"});
PEMUConfig::addRomPath("MSX", io->getDataPath() + "msx/", {HARDWARE_PREFIX_MSX, 0, "MSX"});
PEMUConfig::addRomPath("NES", io->getDataPath() + "nes/", {HARDWARE_PREFIX_NES, 0, "NES"});
PEMUConfig::addRomPath("NGP", io->getDataPath() + "ngp/", {HARDWARE_PREFIX_NGP, 0, "Neo Geo Pocket"});
PEMUConfig::addRomPath("PCE", io->getDataPath() + "pce/", {HARDWARE_PCENGINE_PCENGINE, 0, "PC Engine"});
PEMUConfig::addRomPath("SG1000", io->getDataPath() + "sg1000/", {HARDWARE_PREFIX_SEGA_SG1000, 0, "Sega SG-1000"});
PEMUConfig::addRomPath("SGX", io->getDataPath() + "sgx/", {HARDWARE_PCENGINE_SGX, 0, "PC Engine SGX"});
PEMUConfig::addRomPath("MASTERSYSTEM", io->getDataPath() + "sms/",
{HARDWARE_PREFIX_SEGA_MASTER_SYSTEM, 0, "Sega Master System"});
PEMUConfig::addRomPath("SPECTRUM", io->getDataPath() + "spectrum/", {HARDWARE_PREFIX_SPECTRUM, 0, "ZX Spectrum"});
PEMUConfig::addRomPath("TG16", io->getDataPath() + "tg16/", {HARDWARE_PCENGINE_TG16, 0, "PC Engine TG16"});

// save newly added roms paths
PEMUConfig::save();

// create roms paths if needed
auto paths = getRomPaths();
for (const auto &path: paths) {
io->create(path.path);
}
}
20 changes: 0 additions & 20 deletions src/cores/pfbneo/sources/pfbneo_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,6 @@ class PFBAConfig : public pemu::PEMUConfig {
public:
PFBAConfig(c2d::Io *io, int version);

std::vector<GameListInfo> getCoreGameListInfo() override {
return {
{{HARDWARE_PREFIX_ARCADE, 0, "Arcade"}, "ARCADE", "arcade"},
{{HARDWARE_PREFIX_CHANNELF, 0, "Channel F"}, "CHANNELF", "channelf"},
{{HARDWARE_PREFIX_COLECO, 0, "ColecoVision"}, "COLECO", "coleco"},
{{HARDWARE_PREFIX_FDS, 0, "NES FDS"}, "FDS", "fds"},
{{HARDWARE_PREFIX_SEGA_GAME_GEAR, 0, "Sega Game Gear"}, "GAMEGEAR", "gamegear"},
{{HARDWARE_PREFIX_SEGA_MEGADRIVE, 0, "Sega Megadrive"}, "MEGADRIVE", "megadrive"},
{{HARDWARE_PREFIX_MSX, 0, "MSX"}, "MSX", "msx"},
{{HARDWARE_PREFIX_NES, 0, "NES"}, "NES", "nes"},
{{HARDWARE_PREFIX_NGP, 0, "Neo Geo Pocket"}, "NGP", "ngp"},
{{HARDWARE_PCENGINE_PCENGINE, 0, "PC Engine"}, "PCE", "pce"},
{{HARDWARE_PREFIX_SEGA_SG1000, 0, "Sega SG-1000"}, "SG1000", "sg1000"},
{{HARDWARE_PCENGINE_SGX, 0, "PC Engine SGX"}, "SGX", "sgx"},
{{HARDWARE_PREFIX_SEGA_MASTER_SYSTEM, 0, "Sega Master System"}, "MASTERSYSTEM", "sms"},
{{HARDWARE_PREFIX_SPECTRUM, 0, "ZX Spectrum"}, "SPECTRUM", "spectrum"},
{{HARDWARE_PCENGINE_TG16, 0, "PC Engine TG16"}, "TG16", "tg16"}
};
}

std::vector<int> getCoreHiddenOptionToEnable() override {
return {
PEMUConfig::OptId::UI_FILTER_CLONES,
Expand Down
6 changes: 4 additions & 2 deletions src/cores/pfbneo/sources/pfbneo_romlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ void PFBNRomList::build(const ss_api::GameList::GameAddedCb &cb) {
}
});

// remove custom "ARCADE" system added from "getCoreGameListInfo"
// remove custom "ARCADE" system added from "RomList::build"
gameList->systemList.remove(HARDWARE_PREFIX_ARCADE);

// sort systems
std::sort(gameList->systemList.systems.begin(), gameList->systemList.systems.end(), Api::sortSystemByName);
// update system filtering option
auto opt = ui->getConfig()->get(PEMUConfig::OptId::UI_FILTER_SYSTEM);
opt->setArray(gameList->systemList.getNames());

// update config
ui->getConfig()->load();
Expand Down
3 changes: 2 additions & 1 deletion src/cores/pfbneo/sources/pfbneo_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ PFBNEOUtility::GameInfo PFBNEOUtility::getGameInfo(const Game &game) {
gameInfo.sysId = (int) prefix;
switch (prefix) {
case HARDWARE_PREFIX_MISC_PRE90S:
gameInfo.sysId = 0x43214321;
gameInfo.sysName = "PRE-90S (MISC)";
break;
case HARDWARE_PREFIX_SEGA:
Expand All @@ -88,7 +89,7 @@ PFBNEOUtility::GameInfo PFBNEOUtility::getGameInfo(const Game &game) {
gameInfo.sysName = "CAVE";
break;
case HARDWARE_PREFIX_IGS_PGM:
gameInfo.sysName = "IGS PGM";
gameInfo.sysName = "PGM (IGS)";
break;
case HARDWARE_PREFIX_MISC_POST90S:
gameInfo.sysName = "POST-90S (MISC)";
Expand Down
19 changes: 12 additions & 7 deletions src/cores/pgba/sources/pgba_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ using namespace c2d;
using namespace pemu;

PGBAConfig::PGBAConfig(c2d::Io *io, int version) : PEMUConfig(io, "PGBA", version) {
// add custom roms paths to config
for (const auto &gl: PGBAConfig::getCoreGameListInfo()) {
getGroup(CFG_ID_ROMS)->addOption({gl.cfg_name, io->getDataPath() + gl.rom_path + "/"});
}

// no need for auto-scaling mode
getOption(PEMUConfig::OptId::EMU_SCALING_MODE)->setArray({"ASPECT", "INTEGER"}, 0);

// "c2dui_romlist" will also reload config, but we need new roms paths
load();
// "romlist.cpp" (RomList::build) will also reload config, but we need new roms paths
PEMUConfig::load();

// add custom rom path
PEMUConfig::addRomPath("GBA", io->getDataPath() + "roms/", {12, 0, "Game Boy Advance"});
PEMUConfig::save();

// create roms paths if needed
auto paths = getRomPaths();
for (const auto &path: paths) {
io->create(path.path);
}
}
6 changes: 0 additions & 6 deletions src/cores/pgba/sources/pgba_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ class PGBAConfig : public pemu::PEMUConfig {
public:
PGBAConfig(c2d::Io *io, int version);

std::vector<GameListInfo> getCoreGameListInfo() override {
return {
{{12, 0, "Game Boy Advance"}, "GBA", "roms"}
};
}

std::string getCoreVersion() override {
return std::string(projectName) + projectVersion;
}
Expand Down
23 changes: 16 additions & 7 deletions src/cores/pgen/sources/pgen_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ using namespace c2d;
using namespace pemu;

PGENConfig::PGENConfig(c2d::Io *io, int version) : PEMUConfig(io, "PGEN", version) {
// add custom roms paths to config
for (const auto &gl: getCoreGameListInfo()) {
getGroup(CFG_ID_ROMS)->addOption({gl.cfg_name, io->getDataPath() + gl.rom_path + "/"});
}

// no need for auto-scaling mode
getOption(PEMUConfig::OptId::EMU_SCALING_MODE)->setArray({"ASPECT", "INTEGER"}, 0);

// "c2dui_romlist" will also reload config, but we need new roms paths
load();
// "romlist.cpp" (RomList::build) will also reload config, but we need new roms paths
PEMUConfig::load();

// add custom rom path
PEMUConfig::addRomPath("MEGADRIVE", io->getDataPath() + "megadrive/", {1, 0, "Megadrive"});
PEMUConfig::addRomPath("MASTERSYSTEM", io->getDataPath() + "mastersystem/", {2, 0, "Master System"});
PEMUConfig::addRomPath("GAMEGEAR", io->getDataPath() + "gamegear/", {21, 0, "Game Gear"});
PEMUConfig::addRomPath("MEGACD", io->getDataPath() + "megacd/", {20, 0, "Mega-CD"});
PEMUConfig::addRomPath("SG1000", io->getDataPath() + "sg1000/", {109, 0, "SG-1000"});
PEMUConfig::save();

// create roms paths if needed
auto paths = getRomPaths();
for (const auto &path: paths) {
io->create(path.path);
}
}
14 changes: 0 additions & 14 deletions src/cores/pgen/sources/pgen_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ class PGENConfig : public pemu::PEMUConfig {
public:
PGENConfig(c2d::Io *io, int version);

~PGENConfig() override {
printf("PGENConfig::~PGENConfig()\n");
}

std::vector<GameListInfo> getCoreGameListInfo() override {
return {
{{1, 0, "Megadrive"}, "MEGADRIVE", "megadrive"},
{{2, 0, "Master System"}, "MASTERSYSTEM", "mastersystem"},
{{21, 0, "Game Gear"}, "GAMEGEAR", "gamegear"},
{{20, 0, "Mega-CD"}, "MEGACD", "megacd"},
{{109, 2, "SG-1000"}, "SG1000", "sg1000"}
};
}

std::vector<int> getCoreHiddenOptionToEnable() override {
return {PEMUConfig::OptId::UI_FILTER_SYSTEM};
}
Expand Down
19 changes: 12 additions & 7 deletions src/cores/pnes/sources/pnes_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ using namespace pemu;
PNESConfig::PNESConfig(c2d::Io *io, int version) : PEMUConfig(io, "PNES", version) {
printf("PNESConfig(%s, v%i)\n", getPath().c_str(), version);

// add custom roms paths to config
for (const auto &gl: PNESConfig::getCoreGameListInfo()) {
getGroup(CFG_ID_ROMS)->addOption({gl.cfg_name, io->getDataPath() + gl.rom_path + "/"});
}

// no need for auto-scaling mode on pnes
getOption(PEMUConfig::OptId::EMU_SCALING_MODE)->setArray({"ASPECT", "INTEGER"}, 0);

Expand All @@ -25,6 +20,16 @@ PNESConfig::PNESConfig(c2d::Io *io, int version) : PEMUConfig(io, "PNES", versio
getOption(PEMUConfig::OptId::JOY_B)->setInteger(KEY_JOY_A_DEFAULT);
#endif

// "c2dui_romlist" will also reload config, but we need new roms paths
load();
// "romlist.cpp" (RomList::build) will also reload config, but we need new roms paths
PEMUConfig::load();

// add custom rom path
PEMUConfig::addRomPath("NES", io->getDataPath() + "roms/", {3, 0, "NES"});
PEMUConfig::save();

// create roms paths if needed
auto paths = getRomPaths();
for (const auto &path: paths) {
io->create(path.path);
}
}
6 changes: 0 additions & 6 deletions src/cores/pnes/sources/pnes_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ class PNESConfig : public pemu::PEMUConfig {
public:
PNESConfig(c2d::Io *io, int version);

std::vector<GameListInfo> getCoreGameListInfo() override {
return {
{{3, 0, "NES"}, "NES", "roms"}
};
}

std::string getCoreVersion() override {
return "Nestopia 1.52.0";
}
Expand Down
19 changes: 12 additions & 7 deletions src/cores/psnes/sources/psnes_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ using namespace pemu;
PSNESConfig::PSNESConfig(c2d::Io *io, int version) : PEMUConfig(io, "PSNES", version) {
printf("PSNESConfig(%s, v%i)\n", getPath().c_str(), version);

// add custom roms paths to config
for (const auto &gl: PSNESConfig::getCoreGameListInfo()) {
getGroup(CFG_ID_ROMS)->addOption({gl.cfg_name, io->getDataPath() + gl.rom_path + "/"});
}

auto group = getGroup(PEMUConfig::GrpId::EMULATION);
if (!group) {
printf("PSNESConfig: error, group not found (MENU_ROM_OPTIONS)\n");
Expand Down Expand Up @@ -43,6 +38,16 @@ PSNESConfig::PSNESConfig(c2d::Io *io, int version) : PEMUConfig(io, "PSNES", ver
// no need for auto-scaling mode
getOption(PEMUConfig::OptId::EMU_SCALING_MODE)->setArray({"ASPECT", "INTEGER"}, 0);

// "c2dui_romlist" will also reload config, but we need new roms paths
load();
// "romlist.cpp" (RomList::build) will also reload config, but we need new roms paths
PEMUConfig::load();

// add custom rom path
PEMUConfig::addRomPath("SNES", io->getDataPath() + "roms/", {4, 0, "Super Nintendo"});
PEMUConfig::save();

// create roms paths if needed
auto paths = getRomPaths();
for (const auto &path: paths) {
io->create(path.path);
}
}
6 changes: 0 additions & 6 deletions src/cores/psnes/sources/psnes_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ class PSNESConfig : public pemu::PEMUConfig {
public:
PSNESConfig(c2d::Io *io, int version);

std::vector<GameListInfo> getCoreGameListInfo() override {
return {
{{4, 0, "Super Nintendo"}, "SNES", "roms"}
};
}

std::string getCoreVersion() override {
return "snes9x: " + std::string(VERSION);
}
Expand Down
68 changes: 54 additions & 14 deletions src/skeleton/pemu_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,62 @@ bool PEMUConfig::loadGame(const Game &game) {
return true;
}

bool PEMUConfig::save(bool isGame) {
if (isGame) {
if (!p_game_config) return false;
return p_game_config->save();
bool PEMUConfig::saveGame() {
if (!p_game_config) return false;
return p_game_config->save();
}

bool PEMUConfig::addRomPath(const std::string &name, const std::string &path, const ss_api::System &system) {
printf("PEMUConfig::addRomPath: %s (system: %s, path: %s)\n",
name.c_str(), system.name.c_str(), path.c_str());
auto roms = config_lookup(libConfigGetInstance(), std::string(getName() + ".ROMS").c_str());
if (config_setting_get_member(roms, name.c_str())) {
printf("PEMUConfig::addRomPath: %s found in config file, skipping\n", name.c_str());
return false;
}

auto setting = config_setting_add(roms, name.c_str(), CONFIG_TYPE_LIST);
if (setting) {
// add system name
auto opt = config_setting_add(setting, "SYSTEM_NAME", CONFIG_TYPE_STRING);
config_setting_set_string(opt, system.name.c_str());
// add system id
char sys[32];
snprintf(sys, 31, "0x%08x", system.id);
opt = config_setting_add(setting, "SYSTEM_ID", CONFIG_TYPE_STRING);
config_setting_set_string(opt, sys);
// add roms path
opt = config_setting_add(setting, "PATH", CONFIG_TYPE_STRING);
config_setting_set_string(opt, path.c_str());
return true;
}

return false;
}

std::vector<PEMUConfig::RomPath> PEMUConfig::getRomPaths() {
std::vector<PEMUConfig::RomPath> romPaths;
auto roms = config_lookup(libConfigGetInstance(), std::string(getName() + ".ROMS").c_str());
if (!roms) {
printf("PEMUConfig::getRomPaths: config_lookup failed\n");
return romPaths;
}

int count = config_setting_length(roms);
for (int i = 0; i < count; ++i) {
auto setting = config_setting_get_elem(roms, i);
auto sysName = config_setting_get_elem(setting, 0);
auto sysId = config_setting_get_elem(setting, 1);
auto path = config_setting_get_elem(setting, 2);
if (sysName && sysId && path) {
std::string p = config_setting_get_string(path);
if (!Utility::endsWith(p, "/")) p += "/";
auto id = Utility::parseHex(config_setting_get_string(sysId));
romPaths.push_back({p, {(int) id, 0, config_setting_get_string(sysName)}});
}
}

return Config::save();
return romPaths;
}

c2d::config::Option *PEMUConfig::getOption(int id, bool isGame) {
Expand All @@ -204,15 +253,6 @@ c2d::config::Option *PEMUConfig::get(int id, bool isGame) {
return getOption(id, isGame);
}

std::string PEMUConfig::getRomPath(const std::string &name) {
auto group = getGroup(CFG_ID_ROMS);
if (!group) return "";

auto option = name.empty() ? &group->getOptions()->at(0) : group->getOption(name);
if (!option) return "";
return option->getString();
}

std::vector<c2d::Input::ButtonMapping> PEMUConfig::getKeyboardMapping(int player, bool isGame) {
#ifndef NO_KEYBOARD
return {
Expand Down
Loading

0 comments on commit ff452ec

Please sign in to comment.