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_SLIDE,
DIV_CMD_SAA_ENVELOPE,
DIV_ALWAYS_SET_VOLUME,
DIV_CMD_MAX

View File

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

View File

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

View File

@ -32,7 +32,7 @@ const int _ZERO=0;
const int _ONE=1;
const int _THREE=3;
const int _SEVEN=7;
const int _EIGHT=8;
const int _NINE=9;
const int _TEN=10;
const int _FIFTEEN=15;
const int _THIRTY_ONE=31;
@ -567,6 +567,10 @@ void FurnaceGUI::drawInsList() {
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);
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:
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_INSTR_UNKNOWN]);
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
};
const char* insTypes[9]={
"Standard", "FM", "Game Boy", "C64", "Amiga", "PC Engine", "AY-3-8910/SSG", "AY8930", "TIA"
const char* insTypes[10]={
"Standard", "FM", "Game Boy", "C64", "Amiga", "PC Engine", "AY-3-8910/SSG", "AY8930", "TIA", "SAA1099"
};
const char* ssgEnvTypes[8]={
@ -607,8 +611,8 @@ void FurnaceGUI::drawInsEdit() {
} else {
DivInstrument* ins=e->song.ins[curIns];
ImGui::InputText("Name",&ins->name);
if (ins->type<0 || ins->type>8) ins->type=DIV_INS_FM;
if (ImGui::SliderScalar("Type",ImGuiDataType_U8,&ins->type,&_ZERO,&_EIGHT,insTypes[ins->type])) {
if (ins->type<0 || ins->type>9) ins->type=DIV_INS_FM;
if (ImGui::SliderScalar("Type",ImGuiDataType_U8,&ins->type,&_ZERO,&_NINE,insTypes[ins->type])) {
ins->mode=(ins->type==DIV_INS_FM);
}
@ -886,7 +890,7 @@ void FurnaceGUI::drawInsEdit() {
ImGui::Text("Relative Duty Macro");
}
} 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");
} else {
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;
if (ins->type==DIV_INS_TIA) waveMax=15;
if (ins->type==DIV_INS_C64) waveMax=8;
if (ins->type==DIV_INS_SAA1099) waveMax=3;
if (waveMax>0) {
ImGui::Separator();
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_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_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_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);

View File

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