-romout command line export

consolidate DivEngine::isROMExportViable function from FurnaceGUI::updateROMExportAvail to avoid copy-paste
This commit is contained in:
bbbradsmith 2024-12-13 03:44:52 -05:00 committed by tildearrow
parent addb50e384
commit 55a189444f
5 changed files with 118 additions and 51 deletions

View file

@ -25,6 +25,51 @@ const DivROMExportDef* DivEngine::getROMExportDef(DivROMExportOptions opt) {
return romExportDefs[opt];
}
bool DivEngine::isROMExportViable(DivROMExportOptions opt)
{
const DivROMExportDef* newDef=getROMExportDef(opt);
if (newDef==NULL) {
return false;
}
unsigned char sysReqCount[DIV_SYSTEM_MAX];
memset(sysReqCount,0,DIV_SYSTEM_MAX);
for (int i=0; i<song.systemLen; i++) {
sysReqCount[song.system[i]]++;
}
unsigned char defReqCount[DIV_SYSTEM_MAX];
memset(defReqCount,0,DIV_SYSTEM_MAX);
for (DivSystem j: newDef->requisites) {
defReqCount[j]++;
}
switch (newDef->requisitePolicy) {
case DIV_REQPOL_EXACT:
for (int j=0; j<DIV_SYSTEM_MAX; j++) {
if (defReqCount[j]!=sysReqCount[j]) {
return false;
}
}
break;
case DIV_REQPOL_ANY:
for (int j=0; j<DIV_SYSTEM_MAX; j++) {
if (defReqCount[j]>sysReqCount[j]) {
return false;
}
}
break;
case DIV_REQPOL_LAX:
for (DivSystem j: newDef->requisites) {
if (defReqCount[j]<=sysReqCount[j]) {
return true;
}
}
return false;
}
return true;
}
void DivEngine::registerROMExports() {
logD("registering ROM exports...");