hopefully finish the SAA1099 platform

This commit is contained in:
tildearrow 2022-01-14 23:26:22 -05:00
parent d2cef16adf
commit 0e2230d036
7 changed files with 81 additions and 86 deletions

View file

@ -62,6 +62,8 @@ enum DivDispatchCmds {
DIV_CMD_AY_ENVELOPE_HIGH, DIV_CMD_AY_ENVELOPE_HIGH,
DIV_CMD_AY_ENVELOPE_SLIDE, DIV_CMD_AY_ENVELOPE_SLIDE,
DIV_CMD_SAA_ENVELOPE,
DIV_ALWAYS_SET_VOLUME, DIV_ALWAYS_SET_VOLUME,
DIV_CMD_MAX DIV_CMD_MAX

View file

@ -11,7 +11,8 @@ enum DivInstrumentType {
DIV_INS_PCE=5, DIV_INS_PCE=5,
DIV_INS_AY=6, DIV_INS_AY=6,
DIV_INS_AY8930=7, DIV_INS_AY8930=7,
DIV_INS_TIA=8 DIV_INS_TIA=8,
DIV_INS_SAA1099=9
}; };
struct DivInstrumentFM { struct DivInstrumentFM {

View file

@ -9,11 +9,11 @@
#define PSG_FREQ_BASE 122240.0f #define PSG_FREQ_BASE 122240.0f
void DivPlatformSAA1099::acquire(short* bufL, short* bufR, size_t start, size_t len) { void DivPlatformSAA1099::acquire(short* bufL, short* bufR, size_t start, size_t len) {
if (ayBufLen<len) { if (saaBufLen<len) {
ayBufLen=len; saaBufLen=len;
for (int i=0; i<2; i++) { for (int i=0; i<2; i++) {
delete[] ayBuf[i]; delete[] saaBuf[i];
ayBuf[i]=new short[ayBufLen]; saaBuf[i]=new short[saaBufLen];
} }
} }
while (!writes.empty()) { while (!writes.empty()) {
@ -22,13 +22,17 @@ void DivPlatformSAA1099::acquire(short* bufL, short* bufR, size_t start, size_t
saa.data_w(w.val); saa.data_w(w.val);
writes.pop(); writes.pop();
} }
saa.sound_stream_update(ayBuf,len); saa.sound_stream_update(saaBuf,len);
for (size_t i=0; i<len; i++) { for (size_t i=0; i<len; i++) {
bufL[i+start]=ayBuf[0][i]; bufL[i+start]=saaBuf[0][i];
bufR[i+start]=ayBuf[1][i]; bufR[i+start]=saaBuf[1][i];
} }
} }
inline unsigned char applyPan(unsigned char vol, unsigned char pan) {
return (((vol*(pan>>4))/15)<<4)|((vol*(pan&15))/15);
}
void DivPlatformSAA1099::tick() { void DivPlatformSAA1099::tick() {
for (int i=0; i<6; i++) { for (int i=0; i<6; i++) {
chan[i].std.next(); chan[i].std.next();
@ -38,7 +42,7 @@ void DivPlatformSAA1099::tick() {
if (isMuted[i]) { if (isMuted[i]) {
rWrite(i,0); rWrite(i,0);
} else { } else {
rWrite(i,(chan[i].outVol&15)); rWrite(i,applyPan(chan[i].outVol&15,chan[i].pan));
} }
} }
if (chan[i].std.hadArp) { if (chan[i].std.hadArp) {
@ -57,11 +61,11 @@ void DivPlatformSAA1099::tick() {
} }
} }
if (chan[i].std.hadDuty) { if (chan[i].std.hadDuty) {
rWrite(0x06,31-chan[i].std.duty); saaNoise[i/3]=chan[i].std.duty&3;
rWrite(0x16,saaNoise[0]|(saaNoise[1]<<4));
} }
if (chan[i].std.hadWave) { if (chan[i].std.hadWave) {
chan[i].psgMode&=4; chan[i].psgMode=chan[i].std.wave&3;
chan[i].psgMode|=(chan[i].std.wave+1)&3;
} }
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) {
chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true); chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true);
@ -86,8 +90,6 @@ void DivPlatformSAA1099::tick() {
chan[i].freqH=7-chan[i].freqH; chan[i].freqH=7-chan[i].freqH;
if (chan[i].freq>4095) chan[i].freq=4095; if (chan[i].freq>4095) chan[i].freq=4095;
if (chan[i].keyOn) { if (chan[i].keyOn) {
//rWrite(16+i*5+1,((chan[i].duty&3)<<6)|(63-(ins->gb.soundLen&63)));
//rWrite(16+i*5+2,((chan[i].vol<<4))|(ins->gb.envLen&7)|((ins->gb.envDir&1)<<3));
} }
if (chan[i].keyOff) { if (chan[i].keyOff) {
rWrite(i,0); rWrite(i,0);
@ -115,26 +117,6 @@ void DivPlatformSAA1099::tick() {
((chan[4].psgMode&2)<<3)| ((chan[4].psgMode&2)<<3)|
((chan[5].psgMode&2)<<4) ((chan[5].psgMode&2)<<4)
); );
if (ayEnvSlide!=0) {
ayEnvSlideLow+=ayEnvSlide;
while (ayEnvSlideLow>7) {
ayEnvSlideLow-=8;
if (ayEnvPeriod<0xffff) {
ayEnvPeriod++;
rWrite(0x0b,ayEnvPeriod);
rWrite(0x0c,ayEnvPeriod>>8);
}
}
while (ayEnvSlideLow<-7) {
ayEnvSlideLow+=8;
if (ayEnvPeriod>0) {
ayEnvPeriod--;
rWrite(0x0b,ayEnvPeriod);
rWrite(0x0c,ayEnvPeriod>>8);
}
}
}
} }
int DivPlatformSAA1099::dispatch(DivCommand c) { int DivPlatformSAA1099::dispatch(DivCommand c) {
@ -150,7 +132,7 @@ int DivPlatformSAA1099::dispatch(DivCommand c) {
if (isMuted[c.chan]) { if (isMuted[c.chan]) {
rWrite(c.chan,0); rWrite(c.chan,0);
} else { } else {
rWrite(c.chan,(chan[c.chan].vol&15)); rWrite(c.chan,applyPan(chan[c.chan].vol&15,chan[c.chan].pan));
} }
break; break;
} }
@ -167,7 +149,7 @@ int DivPlatformSAA1099::dispatch(DivCommand c) {
if (isMuted[c.chan]) { if (isMuted[c.chan]) {
rWrite(c.chan,0); rWrite(c.chan,0);
} else { } else {
if (chan[c.chan].active) rWrite(c.chan,(chan[c.chan].vol&15)); if (chan[c.chan].active) rWrite(c.chan,applyPan(chan[c.chan].vol&15,chan[c.chan].pan));
} }
break; break;
break; break;
@ -191,13 +173,13 @@ int DivPlatformSAA1099::dispatch(DivCommand c) {
int destFreq=round(PSG_FREQ_BASE/pow(2.0f,((float)c.value2/12.0f))); int destFreq=round(PSG_FREQ_BASE/pow(2.0f,((float)c.value2/12.0f)));
bool return2=false; bool return2=false;
if (destFreq>chan[c.chan].baseFreq) { if (destFreq>chan[c.chan].baseFreq) {
chan[c.chan].baseFreq+=c.value; chan[c.chan].baseFreq+=c.value*(8-chan[c.chan].freqH);
if (chan[c.chan].baseFreq>=destFreq) { if (chan[c.chan].baseFreq>=destFreq) {
chan[c.chan].baseFreq=destFreq; chan[c.chan].baseFreq=destFreq;
return2=true; return2=true;
} }
} else { } else {
chan[c.chan].baseFreq-=c.value; chan[c.chan].baseFreq-=c.value*(8-chan[c.chan].freqH);
if (chan[c.chan].baseFreq<=destFreq) { if (chan[c.chan].baseFreq<=destFreq) {
chan[c.chan].baseFreq=destFreq; chan[c.chan].baseFreq=destFreq;
return2=true; return2=true;
@ -215,32 +197,16 @@ int DivPlatformSAA1099::dispatch(DivCommand c) {
chan[c.chan].freqChanged=true; chan[c.chan].freqChanged=true;
break; break;
} }
case DIV_CMD_STD_NOISE_MODE:
chan[c.chan].psgMode=(c.value&1)|((c.value&16)>>3);
break;
case DIV_CMD_STD_NOISE_FREQ: case DIV_CMD_STD_NOISE_FREQ:
rWrite(0x06,31-c.value); saaNoise[c.chan/3]=(c.value&1)|((c.value&16)>>3);
rWrite(0x16,saaNoise[0]|(saaNoise[1]<<4));
break; break;
case DIV_CMD_AY_ENVELOPE_SET: case DIV_CMD_SAA_ENVELOPE:
ayEnvMode=c.value>>4; saaEnv[c.value/3]=c.value;
rWrite(0x0d,ayEnvMode); rWrite(0x18+(c.value/3),c.value);
if (c.value&15) {
chan[c.chan].psgMode|=4;
} else {
chan[c.chan].psgMode&=~4;
}
break;
case DIV_CMD_AY_ENVELOPE_LOW:
ayEnvPeriod&=0xff00;
ayEnvPeriod|=c.value;
rWrite(0x0b,ayEnvPeriod);
rWrite(0x0c,ayEnvPeriod>>8);
break;
case DIV_CMD_AY_ENVELOPE_HIGH:
ayEnvPeriod&=0xff;
ayEnvPeriod|=c.value<<8;
rWrite(0x0b,ayEnvPeriod);
rWrite(0x0c,ayEnvPeriod>>8);
break;
case DIV_CMD_AY_ENVELOPE_SLIDE:
ayEnvSlide=c.value;
break; break;
case DIV_ALWAYS_SET_VOLUME: case DIV_ALWAYS_SET_VOLUME:
return 0; return 0;
@ -266,17 +232,18 @@ void DivPlatformSAA1099::muteChannel(int ch, bool mute) {
if (isMuted[ch]) { if (isMuted[ch]) {
rWrite(ch,0); rWrite(ch,0);
} else { } else {
rWrite(ch,(chan[ch].outVol&15)); if (chan[ch].active) rWrite(ch,applyPan(chan[ch].outVol&15,chan[ch].pan));
} }
} }
void DivPlatformSAA1099::forceIns() { void DivPlatformSAA1099::forceIns() {
for (int i=0; i<3; i++) { for (int i=0; i<6; i++) {
chan[i].insChanged=true; chan[i].insChanged=true;
chan[i].freqChanged=true;
} }
rWrite(0x0b,ayEnvPeriod); rWrite(0x18,saaEnv[0]);
rWrite(0x0c,ayEnvPeriod>>8); rWrite(0x19,saaEnv[1]);
rWrite(0x0d,ayEnvMode); rWrite(0x16,saaNoise[0]|(saaNoise[1]<<4));
} }
void DivPlatformSAA1099::reset() { void DivPlatformSAA1099::reset() {
@ -294,10 +261,10 @@ void DivPlatformSAA1099::reset() {
dacRate=0; dacRate=0;
dacSample=-1; dacSample=-1;
sampleBank=0; sampleBank=0;
ayEnvPeriod=0; saaEnv[0]=0;
ayEnvMode=0; saaEnv[1]=0;
ayEnvSlide=0; saaNoise[0]=0;
ayEnvSlideLow=0; saaNoise[1]=0;
delay=0; delay=0;
@ -310,6 +277,10 @@ bool DivPlatformSAA1099::isStereo() {
return true; return true;
} }
int DivPlatformSAA1099::getPortaFloor(int ch) {
return 12;
}
bool DivPlatformSAA1099::keyOffAffectsArp(int ch) { bool DivPlatformSAA1099::keyOffAffectsArp(int ch) {
return true; return true;
} }
@ -335,12 +306,12 @@ int DivPlatformSAA1099::init(DivEngine* p, int channels, int sugRate, bool pal)
isMuted[i]=false; isMuted[i]=false;
} }
setPAL(pal); setPAL(pal);
ayBufLen=65536; saaBufLen=65536;
for (int i=0; i<2; i++) ayBuf[i]=new short[ayBufLen]; for (int i=0; i<2; i++) saaBuf[i]=new short[saaBufLen];
reset(); reset();
return 3; return 3;
} }
void DivPlatformSAA1099::quit() { void DivPlatformSAA1099::quit() {
for (int i=0; i<2; i++) delete[] ayBuf[i]; for (int i=0; i<2; i++) delete[] saaBuf[i];
} }

View file

@ -43,12 +43,10 @@ class DivPlatformSAA1099: public DivDispatch {
short oldWrites[16]; short oldWrites[16];
short pendingWrites[16]; short pendingWrites[16];
unsigned char ayEnvMode; short* saaBuf[2];
unsigned short ayEnvPeriod; size_t saaBufLen;
short ayEnvSlideLow; unsigned char saaEnv[2];
short ayEnvSlide; unsigned char saaNoise[2];
short* ayBuf[2];
size_t ayBufLen;
public: public:
void acquire(short* bufL, short* bufR, size_t start, size_t len); void acquire(short* bufL, short* bufR, size_t start, size_t len);
@ -59,6 +57,7 @@ class DivPlatformSAA1099: public DivDispatch {
void muteChannel(int ch, bool mute); void muteChannel(int ch, bool mute);
void setPAL(bool pal); void setPAL(bool pal);
bool isStereo(); bool isStereo();
int getPortaFloor(int ch);
bool keyOffAffectsArp(int ch); bool keyOffAffectsArp(int ch);
void notifyInsDeletion(void* ins); void notifyInsDeletion(void* ins);
int init(DivEngine* parent, int channels, int sugRate, bool pal); int init(DivEngine* parent, int channels, int sugRate, bool pal);

View file

@ -74,6 +74,8 @@ const char* cmdName[DIV_CMD_MAX]={
"AY_ENVELOPE_HIGH", "AY_ENVELOPE_HIGH",
"AY_ENVELOPE_SLIDE", "AY_ENVELOPE_SLIDE",
"SAA_ENVELOPE",
"ALWAYS_SET_VOLUME" "ALWAYS_SET_VOLUME"
}; };
@ -356,6 +358,19 @@ bool DivEngine::perSystemPostEffect(int ch, unsigned char effect, unsigned char
break; break;
} }
break; break;
case DIV_SYSTEM_SAA1099:
switch (effect) {
case 0x10: // select channel mode
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
break;
case 0x11: // set noise freq
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_FREQ,ch,effectVal));
break;
case 0x12: // setup envelope
dispatchCmd(DivCommand(DIV_CMD_SAA_ENVELOPE,ch,effectVal));
break;
}
break;
default: default:
return false; return false;
} }

View file

@ -32,7 +32,7 @@ const int _ZERO=0;
const int _ONE=1; const int _ONE=1;
const int _THREE=3; const int _THREE=3;
const int _SEVEN=7; const int _SEVEN=7;
const int _EIGHT=8; const int _NINE=9;
const int _TEN=10; const int _TEN=10;
const int _FIFTEEN=15; const int _FIFTEEN=15;
const int _THIRTY_ONE=31; const int _THIRTY_ONE=31;
@ -567,6 +567,10 @@ void FurnaceGUI::drawInsList() {
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_INSTR_TIA]); ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_INSTR_TIA]);
name=fmt::sprintf(ICON_FA_BAR_CHART " %.2x: %s##_INS%d\n",i,ins->name,i); name=fmt::sprintf(ICON_FA_BAR_CHART " %.2x: %s##_INS%d\n",i,ins->name,i);
break; break;
case DIV_INS_SAA1099:
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_INSTR_SAA1099]);
name=fmt::sprintf(ICON_FA_BAR_CHART " %.2x: %s##_INS%d\n",i,ins->name,i);
break;
default: default:
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_INSTR_UNKNOWN]); ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_INSTR_UNKNOWN]);
name=fmt::sprintf(ICON_FA_QUESTION " %.2x: %s##_INS%d\n",i,ins->name,i); name=fmt::sprintf(ICON_FA_QUESTION " %.2x: %s##_INS%d\n",i,ins->name,i);
@ -591,8 +595,8 @@ int detuneTable[8]={
0, 1, 2, 3, 0, -3, -2, -1 0, 1, 2, 3, 0, -3, -2, -1
}; };
const char* insTypes[9]={ const char* insTypes[10]={
"Standard", "FM", "Game Boy", "C64", "Amiga", "PC Engine", "AY-3-8910/SSG", "AY8930", "TIA" "Standard", "FM", "Game Boy", "C64", "Amiga", "PC Engine", "AY-3-8910/SSG", "AY8930", "TIA", "SAA1099"
}; };
const char* ssgEnvTypes[8]={ const char* ssgEnvTypes[8]={
@ -607,8 +611,8 @@ void FurnaceGUI::drawInsEdit() {
} else { } else {
DivInstrument* ins=e->song.ins[curIns]; DivInstrument* ins=e->song.ins[curIns];
ImGui::InputText("Name",&ins->name); ImGui::InputText("Name",&ins->name);
if (ins->type<0 || ins->type>8) ins->type=DIV_INS_FM; if (ins->type<0 || ins->type>9) ins->type=DIV_INS_FM;
if (ImGui::SliderScalar("Type",ImGuiDataType_U8,&ins->type,&_ZERO,&_EIGHT,insTypes[ins->type])) { if (ImGui::SliderScalar("Type",ImGuiDataType_U8,&ins->type,&_ZERO,&_NINE,insTypes[ins->type])) {
ins->mode=(ins->type==DIV_INS_FM); ins->mode=(ins->type==DIV_INS_FM);
} }
@ -886,7 +890,7 @@ void FurnaceGUI::drawInsEdit() {
ImGui::Text("Relative Duty Macro"); ImGui::Text("Relative Duty Macro");
} }
} else { } else {
if (ins->type==DIV_INS_AY || ins->type==DIV_INS_AY8930) { if (ins->type==DIV_INS_AY || ins->type==DIV_INS_AY8930 || ins->type==DIV_INS_SAA1099) {
ImGui::Text("Noise Frequency Macro"); ImGui::Text("Noise Frequency Macro");
} else { } else {
ImGui::Text("Duty/Noise Mode Macro"); ImGui::Text("Duty/Noise Mode Macro");
@ -929,6 +933,7 @@ void FurnaceGUI::drawInsEdit() {
int waveMax=(ins->type==DIV_INS_AY || ins->type==DIV_INS_AY8930)?7:63; int waveMax=(ins->type==DIV_INS_AY || ins->type==DIV_INS_AY8930)?7:63;
if (ins->type==DIV_INS_TIA) waveMax=15; if (ins->type==DIV_INS_TIA) waveMax=15;
if (ins->type==DIV_INS_C64) waveMax=8; if (ins->type==DIV_INS_C64) waveMax=8;
if (ins->type==DIV_INS_SAA1099) waveMax=3;
if (waveMax>0) { if (waveMax>0) {
ImGui::Separator(); ImGui::Separator();
ImGui::Text("Waveform Macro"); ImGui::Text("Waveform Macro");
@ -3387,6 +3392,7 @@ FurnaceGUI::FurnaceGUI():
uiColors[GUI_COLOR_INSTR_AY]=ImVec4(1.0f,0.5f,1.0f,1.0f); uiColors[GUI_COLOR_INSTR_AY]=ImVec4(1.0f,0.5f,1.0f,1.0f);
uiColors[GUI_COLOR_INSTR_AY8930]=ImVec4(0.7f,0.5f,1.0f,1.0f); uiColors[GUI_COLOR_INSTR_AY8930]=ImVec4(0.7f,0.5f,1.0f,1.0f);
uiColors[GUI_COLOR_INSTR_TIA]=ImVec4(1.0f,0.6f,0.4f,1.0f); uiColors[GUI_COLOR_INSTR_TIA]=ImVec4(1.0f,0.6f,0.4f,1.0f);
uiColors[GUI_COLOR_INSTR_SAA1099]=ImVec4(0.3f,0.3f,1.0f,1.0f);
uiColors[GUI_COLOR_INSTR_UNKNOWN]=ImVec4(0.3f,0.3f,0.3f,1.0f); uiColors[GUI_COLOR_INSTR_UNKNOWN]=ImVec4(0.3f,0.3f,0.3f,1.0f);
uiColors[GUI_COLOR_CHANNEL_FM]=ImVec4(0.2f,0.8f,1.0f,1.0f); uiColors[GUI_COLOR_CHANNEL_FM]=ImVec4(0.2f,0.8f,1.0f,1.0f);
uiColors[GUI_COLOR_CHANNEL_PULSE]=ImVec4(0.4f,1.0f,0.2f,1.0f); uiColors[GUI_COLOR_CHANNEL_PULSE]=ImVec4(0.4f,1.0f,0.2f,1.0f);

View file

@ -22,6 +22,7 @@ enum FurnaceGUIColors {
GUI_COLOR_INSTR_AY, GUI_COLOR_INSTR_AY,
GUI_COLOR_INSTR_AY8930, GUI_COLOR_INSTR_AY8930,
GUI_COLOR_INSTR_TIA, GUI_COLOR_INSTR_TIA,
GUI_COLOR_INSTR_SAA1099,
GUI_COLOR_INSTR_UNKNOWN, GUI_COLOR_INSTR_UNKNOWN,
GUI_COLOR_CHANNEL_FM, GUI_COLOR_CHANNEL_FM,
GUI_COLOR_CHANNEL_PULSE, GUI_COLOR_CHANNEL_PULSE,