From 07ed76a63b620661966b51af30eb702d016dfb63 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Mon, 13 Mar 2023 14:17:05 -0500 Subject: [PATCH] add ROM export framework, part 1 --- CMakeLists.txt | 2 ++ src/engine/engine.cpp | 4 +++ src/engine/engine.h | 8 +++++- src/engine/export.cpp | 37 +++++++++++++++++++++++++++ src/engine/export.h | 24 ++++++++++++----- src/engine/export/abstract.cpp | 4 +-- src/engine/export/amigaValidation.cpp | 27 +++++++++++++++++++ src/engine/export/amigaValidation.h | 26 +++++++++++++++++++ 8 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 src/engine/export.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fa8f92c1..9dd1418c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -473,6 +473,7 @@ src/engine/config.cpp src/engine/configEngine.cpp src/engine/dispatchContainer.cpp src/engine/engine.cpp +src/engine/export.cpp src/engine/fileOps.cpp src/engine/fileOpsIns.cpp src/engine/filter.cpp @@ -553,6 +554,7 @@ src/engine/platform/pcmdac.cpp src/engine/platform/dummy.cpp src/engine/export/abstract.cpp +src/engine/export/amigaValidation.cpp ) if (USE_SNDFILE) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 14d90aa6..d03b83b5 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -2580,6 +2580,10 @@ int DivEngine::divToFileRate(int drate) { return 4; } +void DivEngine::testFunction() { + logI("it works!"); +} + int DivEngine::getEffectiveSampleRate(int rate) { if (rate<1) return 0; switch (song.system[0]) { diff --git a/src/engine/engine.h b/src/engine/engine.h index 7cbc1bd0..e5deb7ac 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -456,6 +456,8 @@ class DivEngine { void reset(); void playSub(bool preserveDrift, int goalRow=0); + void testFunction(); + bool loadDMF(unsigned char* file, size_t len); bool loadFur(unsigned char* file, size_t len); bool loadMod(unsigned char* file, size_t len); @@ -496,6 +498,10 @@ class DivEngine { // check whether an asset directory is complete void checkAssetDir(std::vector& dir, size_t entries); + // add every export method here + friend class DivROMExport; + friend class DivExportAmigaValidation; + public: DivSong song; DivOrders* curOrders; @@ -532,7 +538,7 @@ class DivEngine { SafeWriter* saveFur(bool notPrimary=false); // build a ROM file (TODO). // specify system to build ROM for. - std::vector buildROM(int sys); + std::vector buildROM(DivROMExportOptions sys); // dump to VGM. // set trailingTicks to: // - 0 to add one tick of trailing diff --git a/src/engine/export.cpp b/src/engine/export.cpp new file mode 100644 index 00000000..141736d9 --- /dev/null +++ b/src/engine/export.cpp @@ -0,0 +1,37 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "engine.h" + +#include "export/amigaValidation.h" + +std::vector DivEngine::buildROM(DivROMExportOptions sys) { + DivROMExport* exporter=NULL; + switch (sys) { + case DIV_ROM_AMIGA_VALIDATION: + exporter=new DivExportAmigaValidation; + break; + default: + exporter=new DivROMExport; + break; + } + std::vector ret=exporter->go(this); + delete exporter; + return ret; +} diff --git a/src/engine/export.h b/src/engine/export.h index 82ba790d..07354fdb 100644 --- a/src/engine/export.h +++ b/src/engine/export.h @@ -21,6 +21,7 @@ #define _EXPORT_H #include "song.h" +#include #include class DivEngine; @@ -45,6 +46,12 @@ struct DivROMExportOutput { }; class DivROMExport { + public: + virtual std::vector go(DivEngine* e); + virtual ~DivROMExport() {} +}; + +struct DivROMExportDef { const char* name; const char* author; const char* description; @@ -52,12 +59,17 @@ class DivROMExport { int requisitesLen; bool multiOutput; - public: - virtual std::vector go(DivEngine* e); - DivROMExport(const char* n, const char* auth, const char* desc): - name(n), - author(auth), - description(desc) {} + DivROMExportDef(const char* n, const char* a, const char* d, std::initializer_list req, bool multiOut): + name(n), + author(a), + description(d), + multiOutput(multiOut) { + requisitesLen=0; + memset(requisites,0,32*sizeof(DivSystem)); + for (DivSystem i: req) { + requisites[requisitesLen++]=i; + } + } }; #endif diff --git a/src/engine/export/abstract.cpp b/src/engine/export/abstract.cpp index e60e5b0f..ce07519c 100644 --- a/src/engine/export/abstract.cpp +++ b/src/engine/export/abstract.cpp @@ -20,7 +20,7 @@ #include "../export.h" #include "../../ta-log.h" -std::vector go(DivEngine* e) { +std::vector DivROMExport::go(DivEngine* e) { logW("what's this? the null ROM export?"); return std::vector(); -} \ No newline at end of file +} diff --git a/src/engine/export/amigaValidation.cpp b/src/engine/export/amigaValidation.cpp index e69de29b..7552350e 100644 --- a/src/engine/export/amigaValidation.cpp +++ b/src/engine/export/amigaValidation.cpp @@ -0,0 +1,27 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "amigaValidation.h" +#include "../engine.h" + +std::vector DivExportAmigaValidation::go(DivEngine* e) { + e->testFunction(); + + return std::vector(); +} diff --git a/src/engine/export/amigaValidation.h b/src/engine/export/amigaValidation.h index e69de29b..94d5eabb 100644 --- a/src/engine/export/amigaValidation.h +++ b/src/engine/export/amigaValidation.h @@ -0,0 +1,26 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "../export.h" + +class DivExportAmigaValidation: public DivROMExport { + public: + std::vector go(DivEngine* e); + ~DivExportAmigaValidation() {} +};