Skip to content

Commit

Permalink
Merge pull request tildearrow#23 from LTVA1/ES5503
Browse files Browse the repository at this point in the history
ES5503 in the fork
  • Loading branch information
LTVA1 authored Dec 30, 2023
2 parents 51155aa + db0d8ab commit 487409e
Show file tree
Hide file tree
Showing 23 changed files with 1,933 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ src/engine/platform/sound/ted-sound.c

src/engine/platform/sound/c140_c219.c

src/engine/platform/sound/es5503.cpp

src/engine/platform/oplAInterface.cpp
src/engine/platform/ym2608Interface.cpp
src/engine/platform/ym2610Interface.cpp
Expand Down Expand Up @@ -700,6 +702,7 @@ src/engine/platform/pv1000.cpp
src/engine/platform/k053260.cpp
src/engine/platform/ted.cpp
src/engine/platform/c140.cpp
src/engine/platform/es5503.cpp
src/engine/platform/pcmdac.cpp
src/engine/platform/dummy.cpp

Expand Down
6 changes: 6 additions & 0 deletions src/engine/dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ enum DivDispatchCmds {
DIV_CMD_C64_AD, // (value)
DIV_CMD_C64_SR, // (value)

DIV_CMD_ES5503_NUM_ENABLED_OSC, // (value); set number of enabled oscillators (more oscs enabled = less sample rate)
DIV_CMD_ES5503_OSC_OUTPUT, // (value)
DIV_CMD_ES5503_WAVE_LENGTH,
DIV_CMD_ES5503_WAVE_POS,
DIV_CMD_ES5503_OSC_MODE,

DIV_ALWAYS_SET_VOLUME, // () -> alwaysSetVol

DIV_CMD_MAX
Expand Down
4 changes: 4 additions & 0 deletions src/engine/dispatchContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#include "platform/k053260.h"
#include "platform/ted.h"
#include "platform/c140.h"
#include "platform/es5503.h"
#include "platform/pcmdac.h"
#include "platform/dummy.h"
#include "../ta-log.h"
Expand Down Expand Up @@ -685,6 +686,9 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do
dispatch=new DivPlatformC140;
((DivPlatformC140*)dispatch)->set219(true);
break;
case DIV_SYSTEM_ES5503:
dispatch=new DivPlatformES5503;
break;
case DIV_SYSTEM_PCM_DAC:
dispatch=new DivPlatformPCMDAC;
break;
Expand Down
3 changes: 2 additions & 1 deletion src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ enum DivChanTypes {
DIV_CH_NOISE=2,
DIV_CH_WAVE=3,
DIV_CH_PCM=4,
DIV_CH_OP=5
DIV_CH_OP=5,
DIV_CH_ES5503_VIRT = 6,
};

extern const char* cmdName[];
Expand Down
40 changes: 40 additions & 0 deletions src/engine/instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ bool DivInstrumentES5506::operator==(const DivInstrumentES5506& other) {
);
}

bool DivInstrumentES5503::operator==(const DivInstrumentES5503& other) {
return (
_C(initial_osc_mode) &&
_C(softpan_virtual_channel) &&
_C(phase_reset_on_start)
);
}

bool DivInstrumentSNES::operator==(const DivInstrumentSNES& other) {
return (
_C(useEnv) &&
Expand Down Expand Up @@ -712,6 +720,14 @@ void DivInstrument::writeFeatureNE(SafeWriter* w) {
FEATURE_END;
}

void DivInstrument::writeFeatureE3(SafeWriter* w) {
FEATURE_BEGIN("E3");

w->writeC((es5503.initial_osc_mode << 6)|((uint8_t)es5503.softpan_virtual_channel << 5)|((uint8_t)es5503.phase_reset_on_start << 4));

FEATURE_END;
}

void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bool insName) {
size_t blockStartSeek=0;
size_t blockEndSeek=0;
Expand Down Expand Up @@ -755,6 +771,7 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo
bool featureES=false;
bool featureX1=false;
bool featureNE=false;
bool featureE3=false;

bool checkForWL=false;

Expand Down Expand Up @@ -968,6 +985,9 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo
featureSM=true;
featureSL=true;
break;
case DIV_INS_ES5503:
featureE3=true;
break;

case DIV_INS_MAX:
break;
Expand Down Expand Up @@ -1016,6 +1036,9 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo
if (x1_010!=defaultIns.x1_010) {
featureX1=true;
}
if (es5503!=defaultIns.es5503) {
featureE3=true;
}
}

// check ins name
Expand Down Expand Up @@ -1164,6 +1187,9 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo
if (featureNE) {
writeFeatureNE(w);
}
if (featureE3) {
writeFeatureE3(w);
}

if (fui && (featureSL || featureWL)) {
w->write("EN",2);
Expand Down Expand Up @@ -1818,6 +1844,18 @@ void DivInstrument::readFeatureNE(SafeReader& reader, short version) {
READ_FEAT_END;
}

void DivInstrument::readFeatureE3(SafeReader& reader, short version) {
READ_FEAT_BEGIN;

uint8_t temp = reader.readC();

es5503.initial_osc_mode = temp >> 6;
es5503.softpan_virtual_channel = (temp >> 5) & 1;
es5503.phase_reset_on_start = (temp >> 4) & 1;

READ_FEAT_END;
}

DivDataErrors DivInstrument::readInsDataNew(SafeReader& reader, short version, bool fui, DivSong* song) {
unsigned char featCode[2];
bool volIsCutoff=false;
Expand Down Expand Up @@ -1891,6 +1929,8 @@ DivDataErrors DivInstrument::readInsDataNew(SafeReader& reader, short version, b
readFeatureX1(reader,version);
} else if (memcmp(featCode,"NE",2)==0) { // NES (DPCM)
readFeatureNE(reader,version);
} else if (memcmp(featCode,"E3",2)==0) { // ES5503
readFeatureE3(reader,version);
} else {
if (song==NULL && (memcmp(featCode,"SL",2)==0 || (memcmp(featCode,"WL",2)==0))) {
// nothing
Expand Down
25 changes: 25 additions & 0 deletions src/engine/instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ enum DivInstrumentType: unsigned short {
DIV_INS_TED=52,
DIV_INS_C140=53,
DIV_INS_C219=54,
DIV_INS_ES5503=55,
DIV_INS_MAX,
DIV_INS_NULL
};
Expand Down Expand Up @@ -820,6 +821,27 @@ struct DivInstrumentES5506 {
envelope(Envelope()) {}
};

struct DivInstrumentES5503 {
unsigned char initial_osc_mode;
bool softpan_virtual_channel;
bool phase_reset_on_start;

enum WaveTableLengths: unsigned char {
DIV_ES5503_WAVE_LENGTH_MAX=8,
};

bool operator==(const DivInstrumentES5503& other);
bool operator!=(const DivInstrumentES5503& other) {
return !(*this==other);
}

DivInstrumentES5503():
initial_osc_mode(0), softpan_virtual_channel(false),
phase_reset_on_start(true) {

}
};

struct DivInstrumentSNES {
enum GainMode: unsigned char {
GAIN_MODE_DIRECT=0,
Expand Down Expand Up @@ -871,6 +893,7 @@ struct DivInstrument {
DivInstrumentSoundUnit su;
DivInstrumentES5506 es5506;
DivInstrumentSNES snes;
DivInstrumentES5503 es5503;

/**
* these are internal functions.
Expand All @@ -895,6 +918,7 @@ struct DivInstrument {
void writeFeatureES(SafeWriter* w);
void writeFeatureX1(SafeWriter* w);
void writeFeatureNE(SafeWriter* w);
void writeFeatureE3(SafeWriter* w);

void readFeatureNA(SafeReader& reader, short version);
void readFeatureFM(SafeReader& reader, short version);
Expand All @@ -915,6 +939,7 @@ struct DivInstrument {
void readFeatureES(SafeReader& reader, short version);
void readFeatureX1(SafeReader& reader, short version);
void readFeatureNE(SafeReader& reader, short version);
void readFeatureE3(SafeReader& reader, short version);

DivDataErrors readInsDataOld(SafeReader& reader, short version);
DivDataErrors readInsDataNew(SafeReader& reader, short version, bool fui, DivSong* song);
Expand Down
Loading

0 comments on commit 487409e

Please sign in to comment.