diff --git a/src/engine/fileOps/dmf.cpp b/src/engine/fileOps/dmf.cpp index 06c0754ed..7a7f06918 100644 --- a/src/engine/fileOps/dmf.cpp +++ b/src/engine/fileOps/dmf.cpp @@ -1646,8 +1646,139 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) { short note, octave; w->writeC(curPat[i].effectCols); + bool convertSampleUsage=false; + int convIns=-1; + bool isConverting=false; + bool alwaysConvert=false; + + switch (sys) { + case DIV_SYSTEM_GENESIS: + if (i==5) convertSampleUsage=true; + break; + case DIV_SYSTEM_GENESIS_EXT: + if (i==8) convertSampleUsage=true; + break; + case DIV_SYSTEM_PCE: + convertSampleUsage=true; + break; + case DIV_SYSTEM_NES: + if (i==4) { + convertSampleUsage=true; + alwaysConvert=true; + } + break; + case DIV_SYSTEM_ARCADE: + if (i>=8) { + convertSampleUsage=true; + alwaysConvert=true; + } + break; + case DIV_SYSTEM_YM2610: + if (i>=7) { + convertSampleUsage=true; + alwaysConvert=true; + } + break; + case DIV_SYSTEM_YM2610_EXT: + if (i>=10) { + convertSampleUsage=true; + alwaysConvert=true; + } + break; + default: + break; + } + for (int j=0; jordersLen; j++) { - DivPattern* pat=curPat[i].getPattern(curOrders->ord[i][j],false); + // we make a copy in order to convertFurnace sample mode to Defle one + DivPattern* origPat=curPat[i].getPattern(curOrders->ord[i][j],false); + DivPattern* pat=new DivPattern; + origPat->copyOn(pat); + + if (convertSampleUsage) { + for (int k=0; kpatLen; k++) { + int insert17xx=-1; + int insertEBxx=-1; + + if (pat->newData[k][DIV_PAT_INS]!=-1) { + if (pat->newData[k][DIV_PAT_INS]>=0 && pat->newData[k][DIV_PAT_INS]newData[k][DIV_PAT_INS]; + } else { + convIns=-1; + } + + bool willBeConverting=false; + if (convIns>=0 && convInstype==DIV_INS_AMIGA || + convInsInst->type==DIV_INS_ADPCMA || + convInsInst->type==DIV_INS_SEGAPCM || + (convInsInst->type==DIV_INS_PCE && convInsInst->amiga.useSample)) { + willBeConverting=true; + } + } + + if (isConverting!=willBeConverting) { + if (!alwaysConvert) { + if (willBeConverting) { + insert17xx=1; + } else { + insert17xx=0; + } + } + isConverting=willBeConverting; + } + + if (isConverting || alwaysConvert) { + pat->newData[k][DIV_PAT_INS]=-1; + } + } + + if (pat->newData[k][DIV_PAT_NOTE]!=-1 && pat->newData[k][DIV_PAT_NOTE]!=DIV_NOTE_OFF && pat->newData[k][DIV_PAT_NOTE]!=DIV_NOTE_REL && pat->newData[k][DIV_PAT_NOTE]!=DIV_MACRO_REL) { + if (isConverting || alwaysConvert) { + if (convIns>=0 && convInsamiga.useNoteMap) { + int mapTarget=pat->newData[k][DIV_PAT_NOTE]-60; + if (mapTarget<0) mapTarget=0; + if (mapTarget>119) mapTarget=119; + insertEBxx=convInsInst->amiga.noteMap[mapTarget].map/12; + pat->newData[k][DIV_PAT_NOTE]=(12*(pat->newData[k][DIV_PAT_NOTE]/12))+(convInsInst->amiga.noteMap[mapTarget].map%12); + } else { + insertEBxx=convInsInst->amiga.initSample/12; + pat->newData[k][DIV_PAT_NOTE]=(12*(pat->newData[k][DIV_PAT_NOTE]/12))+(convInsInst->amiga.initSample%12); + } + } + } + } + + if (insert17xx!=-1) { + int freeSlot=0; + for (int l=0; lnewData[k][DIV_PAT_FX(l)]==-1) { + freeSlot=l; + break; + } + } + + pat->newData[k][DIV_PAT_FX(freeSlot)]=0x17; + pat->newData[k][DIV_PAT_FXVAL(freeSlot)]=insert17xx; + } + if (insertEBxx!=-1) { + int freeSlot=1; + for (int l=0; lnewData[k][DIV_PAT_FX(l)]==-1) { + freeSlot=l; + break; + } + } + + pat->newData[k][DIV_PAT_FX(freeSlot)]=0xeb; + pat->newData[k][DIV_PAT_FXVAL(freeSlot)]=insertEBxx; + } + } + } + for (int k=0; kpatLen; k++) { if (pat->newData[k][DIV_PAT_NOTE]==DIV_NOTE_REL || pat->newData[k][DIV_PAT_NOTE]==DIV_MACRO_REL) { w->writeS(100); @@ -1671,6 +1802,8 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) { #endif w->writeS(pat->newData[k][DIV_PAT_INS]); // instrument } + + delete pat; } } diff --git a/src/engine/legacySample.cpp b/src/engine/legacySample.cpp index faf91086a..dbaab38c5 100644 --- a/src/engine/legacySample.cpp +++ b/src/engine/legacySample.cpp @@ -366,5 +366,7 @@ bool DivEngine::convertLegacySampleMode() { } } + delete[] isUsedByIns; + return (legacyInsInit!=-1); }