SID2, part 1

thanks LTVA
This commit is contained in:
tildearrow 2024-04-21 03:54:34 -05:00
parent ca5cf58d00
commit 1850968def
38 changed files with 7237 additions and 0 deletions

View file

@ -258,6 +258,14 @@ bool DivInstrumentPowerNoise::operator==(const DivInstrumentPowerNoise& other) {
return _C(octave);
}
bool DivInstrumentSID2::operator==(const DivInstrumentSID2& other) {
return (
_C(volume) &&
_C(mixMode) &&
_C(noiseMode)
);
}
#undef _C
#define CONSIDER(x,t) \
@ -830,6 +838,42 @@ void DivInstrument::writeFeaturePN(SafeWriter* w) {
FEATURE_END;
}
void DivInstrument::writeFeatureS2(SafeWriter* w) {
FEATURE_BEGIN("S2");
// this is for compatibility.
w->writeC(
(c64.dutyIsAbs?0x80:0)|
(c64.initFilter?0x40:0)|
(c64.toFilter?0x10:0)|
(c64.noiseOn?8:0)|
(c64.pulseOn?4:0)|
(c64.sawOn?2:0)|
(c64.triOn?1:0)
);
w->writeC(
(c64.oscSync?0x80:0)|
(c64.ringMod?0x40:0)|
(c64.noTest?0x20:0)|
(c64.filterIsAbs?0x10:0)|
(c64.ch3off?8:0)|
(c64.bp?4:0)|
(c64.hp?2:0)|
(c64.lp?1:0)
);
w->writeC(((c64.a&15)<<4)|(c64.d&15));
w->writeC(((c64.s&15)<<4)|(c64.r&15));
w->writeS(c64.duty);
w->writeS(c64.cut&4095);
w->writeC(c64.res);
w->writeC(sid2.volume|(sid2.mixMode<<4)|(sid2.noiseMode<<6));
FEATURE_END;
}
void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bool insName) {
size_t blockStartSeek=0;
size_t blockEndSeek=0;
@ -875,6 +919,7 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo
bool featureNE=false;
bool featureEF=false;
bool featurePN=false;
bool featureS2=false;
bool checkForWL=false;
@ -1114,6 +1159,10 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo
break;
case DIV_INS_BIFURCATOR:
break;
case DIV_INS_SID2:
feature64=true;
featureS2=true;
break;
case DIV_INS_MAX:
break;
case DIV_INS_NULL:
@ -1167,6 +1216,9 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo
if (powernoise!=defaultIns.powernoise) {
featurePN=true;
}
if (sid2!=defaultIns.sid2) {
featureS2=true;
}
}
// check ins name
@ -1315,6 +1367,9 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo
if (featurePN) {
writeFeaturePN(w);
}
if (featureS2) {
writeFeatureS2(w);
}
if (fui && (featureSL || featureWL)) {
w->write("EN",2);
@ -2127,6 +2182,28 @@ void DivInstrument::readFeaturePN(SafeReader& reader, short version) {
READ_FEAT_END;
}
void DivInstrument::readFeatureS2(SafeReader& reader, short version) {
READ_FEAT_BEGIN;
// these are reserved.
reader.readC();
reader.readC();
reader.readC();
reader.readC();
reader.readS();
reader.readS();
reader.readC();
unsigned char next=reader.readC();
sid2.volume=next&0xf;
sid2.mixMode=(next>>4)&3;
sid2.noiseMode=next>>6;
READ_FEAT_END;
}
DivDataErrors DivInstrument::readInsDataNew(SafeReader& reader, short version, bool fui, DivSong* song) {
unsigned char featCode[2];
bool volIsCutoff=false;
@ -2199,6 +2276,8 @@ DivDataErrors DivInstrument::readInsDataNew(SafeReader& reader, short version, b
readFeatureEF(reader,version);
} else if (memcmp(featCode,"PN",2)==0) { // PowerNoise
readFeaturePN(reader,version);
} else if (memcmp(featCode,"S2",2)==0) { // SID2
readFeatureS2(reader,version);
} else {
if (song==NULL && (memcmp(featCode,"SL",2)==0 || (memcmp(featCode,"WL",2)==0))) {
// nothing