diff --git a/papers/newIns.md b/papers/newIns.md index 341956c32..d301d27c2 100644 --- a/papers/newIns.md +++ b/papers/newIns.md @@ -150,6 +150,7 @@ the following feature codes are recognized: - `X1`: X1-010 ins data - `NE`: NES DPCM sample map data - `EF`: ESFM ins data +- `PN`: PowerNoise ins data - `EN`: end of features - if you find this feature code, stop reading the instrument. - it will usually appear only when there sample/wave lists. @@ -657,3 +658,11 @@ size | description if some fields are missing, that's because they are defined in the SM feature. NES instruments with DPCM sample maps have both SM and NE features. + +# PowerNoise data (PN) + +``` +size | description +-----|------------------------------------ + 1 | octave +``` diff --git a/src/engine/instrument.cpp b/src/engine/instrument.cpp index 78e509046..990af8da3 100644 --- a/src/engine/instrument.cpp +++ b/src/engine/instrument.cpp @@ -253,6 +253,10 @@ bool DivInstrumentESFM::Operator::operator==(const DivInstrumentESFM::Operator& ); } +bool DivInstrumentPowerNoise::operator==(const DivInstrumentPowerNoise& other) { + return _C(octave); +} + #undef _C #define FEATURE_BEGIN(x) \ @@ -782,6 +786,14 @@ void DivInstrument::writeFeatureEF(SafeWriter* w) { FEATURE_END; } +void DivInstrument::writeFeaturePN(SafeWriter* w) { + FEATURE_BEGIN("PN"); + + w->writeC(powernoise.octave); + + FEATURE_END; +} + void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bool insName) { size_t blockStartSeek=0; size_t blockEndSeek=0; @@ -826,6 +838,7 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo bool featureX1=false; bool featureNE=false; bool featureEF=false; + bool featurePN=false; bool checkForWL=false; @@ -1044,8 +1057,10 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo featureEF=true; break; case DIV_INS_POWERNOISE: + featurePN=true; break; case DIV_INS_POWERNOISE_SLOPE: + featurePN=true; break; case DIV_INS_MAX: break; @@ -1097,6 +1112,9 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo if (esfm!=defaultIns.esfm) { featureEF=true; } + if (powernoise!=defaultIns.powernoise) { + featurePN=true; + } } // check ins name @@ -1242,6 +1260,9 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo if (featureEF) { writeFeatureEF(w); } + if (featurePN) { + writeFeaturePN(w); + } if (fui && (featureSL || featureWL)) { w->write("EN",2); @@ -2677,6 +2698,14 @@ void DivInstrument::readFeatureEF(SafeReader& reader, short version) { READ_FEAT_END; } +void DivInstrument::readFeaturePN(SafeReader& reader, short version) { + READ_FEAT_BEGIN; + + powernoise.octave=reader.readC(); + + READ_FEAT_END; +} + DivDataErrors DivInstrument::readInsDataNew(SafeReader& reader, short version, bool fui, DivSong* song) { unsigned char featCode[2]; bool volIsCutoff=false; @@ -2747,6 +2776,8 @@ DivDataErrors DivInstrument::readInsDataNew(SafeReader& reader, short version, b readFeatureNE(reader,version); } else if (memcmp(featCode,"EF",2)==0) { // ESFM readFeatureEF(reader,version); + } else if (memcmp(featCode,"PN",2)==0) { // PowerNoise + readFeaturePN(reader,version); } else { if (song==NULL && (memcmp(featCode,"SL",2)==0 || (memcmp(featCode,"WL",2)==0))) { // nothing diff --git a/src/engine/instrument.h b/src/engine/instrument.h index d5d62c142..80bd8f251 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -824,6 +824,17 @@ struct DivInstrumentESFM { } }; +struct DivInstrumentPowerNoise { + unsigned char octave; + + bool operator==(const DivInstrumentPowerNoise& other); + bool operator!=(const DivInstrumentPowerNoise& other) { + return !(*this==other); + } + DivInstrumentPowerNoise(): + octave(0) {} +}; + struct DivInstrument { String name; DivInstrumentType type; @@ -841,6 +852,7 @@ struct DivInstrument { DivInstrumentES5506 es5506; DivInstrumentSNES snes; DivInstrumentESFM esfm; + DivInstrumentPowerNoise powernoise; /** * these are internal functions. @@ -866,6 +878,7 @@ struct DivInstrument { void writeFeatureX1(SafeWriter* w); void writeFeatureNE(SafeWriter* w); void writeFeatureEF(SafeWriter* w); + void writeFeaturePN(SafeWriter* w); void readFeatureNA(SafeReader& reader, short version); void readFeatureFM(SafeReader& reader, short version); @@ -887,6 +900,7 @@ struct DivInstrument { void readFeatureX1(SafeReader& reader, short version); void readFeatureNE(SafeReader& reader, short version); void readFeatureEF(SafeReader& reader, short version); + void readFeaturePN(SafeReader& reader, short version); DivDataErrors readInsDataOld(SafeReader& reader, short version); DivDataErrors readInsDataNew(SafeReader& reader, short version, bool fui, DivSong* song);