commit 18297ead751a1fe1747efa82eec05bbe8abeb83f
parent d27c56cf73ea9cd7dbc2ae9110b748a253ead4b8
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Mon, 5 Aug 2024 15:58:49 +0200
add rom verification to prevent that we accidentially load a rom that is not a NL2x rom
Diffstat:
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/source/nord/n2x/n2xLib/n2xrom.cpp b/source/nord/n2x/n2xLib/n2xrom.cpp
@@ -1,7 +1,17 @@
#include "n2xrom.h"
+#include <algorithm>
+
#include "synthLib/os.h"
namespace n2x
{
+ Rom::Rom() : RomData()
+ {
+ constexpr uint8_t key[] = {'n', 'r', '2', 0, 'n', 'L', '2', 0};
+
+ const auto it = std::search(data().begin(), data().end(), std::begin(key), std::end(key));
+ if(it == data().end())
+ invalidate();
+ }
}
diff --git a/source/nord/n2x/n2xLib/n2xrom.h b/source/nord/n2x/n2xLib/n2xrom.h
@@ -5,5 +5,9 @@
namespace n2x
{
- class Rom : public RomData<g_romSize> {};
+ class Rom : public RomData<g_romSize>
+ {
+ public:
+ Rom();
+ };
}
diff --git a/source/nord/n2x/n2xLib/n2xromdata.h b/source/nord/n2x/n2xLib/n2xromdata.h
@@ -20,6 +20,10 @@ namespace n2x
const auto& getFilename() const { return m_filename; }
+ void invalidate()
+ {
+ m_filename.clear();
+ }
private:
std::array<uint8_t, Size> m_data;
std::string m_filename;