From 319c559f4771602ae4c8bf3af11ee7c9e62ea103 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 23 Feb 2022 03:19:32 -0500 Subject: [PATCH] compound system flattening, part 2 .dmf saving implemented. only available for the following setups: - YM2612 + SMS = Genesis - YM2612 ext3 + SMS = Genesis ext3 - YM2151 + SegaPCM compat = Arcade - SMS + OPLL = SMS with FM expansion --- src/engine/fileOps.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/engine/fileOps.cpp b/src/engine/fileOps.cpp index 6eaeccecc..743d55866 100644 --- a/src/engine/fileOps.cpp +++ b/src/engine/fileOps.cpp @@ -1447,15 +1447,28 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) { lastError="invalid version to save in! this is a bug!"; return NULL; } + // check whether system is compound + bool isFlat=false; + if (song.systemLen==2) { + if (song.system[0]==DIV_SYSTEM_YM2612 && song.system[1]==DIV_SYSTEM_SMS) { + isFlat=true; + } + if (song.system[0]==DIV_SYSTEM_YM2612_EXT && song.system[1]==DIV_SYSTEM_SMS) { + isFlat=true; + } + if (song.system[0]==DIV_SYSTEM_YM2151 && song.system[1]==DIV_SYSTEM_SEGAPCM_COMPAT) { + isFlat=true; + } + if (song.system[0]==DIV_SYSTEM_SMS && song.system[1]==DIV_SYSTEM_OPLL) { + isFlat=true; + } + } // fail if more than one system - // TODO: fix this mess for the flattening in 0.6 - if (!(song.system[0]==DIV_SYSTEM_SMS && song.system[1]==DIV_SYSTEM_OPLL)) { - if (song.systemLen!=1) { + if (!isFlat && song.systemLen!=1) { logE("cannot save multiple systems in this format!\n"); lastError="multiple systems not possible on .dmf"; return NULL; } - } // fail if this is an YMU759 song if (song.system[0]==DIV_SYSTEM_YMU759) { logE("cannot save YMU759 song!\n"); @@ -1469,7 +1482,7 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) { return NULL; } // fail if the system is Furnace-exclusive - if (systemToFile(song.system[0])&0x80) { + if (!isFlat && systemToFile(song.system[0])&0x80) { logE("cannot save Furnace-exclusive system song!\n"); lastError="this system is not possible on .dmf"; return NULL; @@ -1485,7 +1498,16 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) { // version w->writeC(version); DivSystem sys=DIV_SYSTEM_NULL; - if (song.system[0]==DIV_SYSTEM_SMS && song.system[1]==DIV_SYSTEM_OPLL) { + if (song.system[0]==DIV_SYSTEM_YM2612 && song.system[1]==DIV_SYSTEM_SMS) { + w->writeC(systemToFile(DIV_SYSTEM_GENESIS)); + sys=DIV_SYSTEM_GENESIS; + } else if (song.system[0]==DIV_SYSTEM_YM2612_EXT && song.system[1]==DIV_SYSTEM_SMS) { + w->writeC(systemToFile(DIV_SYSTEM_GENESIS_EXT)); + sys=DIV_SYSTEM_GENESIS_EXT; + } else if (song.system[0]==DIV_SYSTEM_YM2151 && song.system[1]==DIV_SYSTEM_SEGAPCM_COMPAT) { + w->writeC(systemToFile(DIV_SYSTEM_ARCADE)); + sys=DIV_SYSTEM_ARCADE; + } else if (song.system[0]==DIV_SYSTEM_SMS && song.system[1]==DIV_SYSTEM_OPLL) { w->writeC(systemToFile(DIV_SYSTEM_SMS_OPLL)); sys=DIV_SYSTEM_SMS_OPLL; } else {