2022-02-15 03:12:20 +00:00
|
|
|
/**
|
|
|
|
* Furnace Tracker - multi-system chiptune tracker
|
|
|
|
* Copyright (C) 2021-2022 tildearrow and contributors
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2022-01-14 21:29:27 +00:00
|
|
|
#include "saa.h"
|
|
|
|
#include "../engine.h"
|
|
|
|
#include "sound/saa1099.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2022-01-17 18:29:35 +00:00
|
|
|
#define rWrite(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); if (dumpWrites) {addWrite(a,v);} }
|
2022-01-14 21:29:27 +00:00
|
|
|
|
2022-01-28 05:55:51 +00:00
|
|
|
#define CHIP_DIVIDER 2
|
2022-01-14 21:29:27 +00:00
|
|
|
|
2022-02-02 07:14:42 +00:00
|
|
|
const char* regCheatSheetSAA[]={
|
|
|
|
"Vol0", "00",
|
|
|
|
"Vol1", "01",
|
|
|
|
"Vol2", "02",
|
|
|
|
"Vol3", "03",
|
|
|
|
"Vol4", "04",
|
|
|
|
"Vol5", "05",
|
|
|
|
"Freq0", "08",
|
|
|
|
"Freq1", "09",
|
|
|
|
"Freq2", "0A",
|
|
|
|
"Freq3", "0B",
|
|
|
|
"Freq4", "0C",
|
|
|
|
"Freq5", "0D",
|
|
|
|
"Octave10", "10",
|
|
|
|
"Octave32", "11",
|
|
|
|
"Octave54", "12",
|
|
|
|
"ToneOn", "14",
|
|
|
|
"NoiseOn", "15",
|
|
|
|
"NoiseCtl", "16",
|
|
|
|
"EnvCtl0", "18",
|
|
|
|
"EnvCtl1", "19",
|
|
|
|
"Power", "1C",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2022-02-03 23:38:57 +00:00
|
|
|
const char** DivPlatformSAA1099::getRegisterSheet() {
|
|
|
|
return regCheatSheetSAA;
|
|
|
|
}
|
|
|
|
|
2022-02-13 22:49:24 +00:00
|
|
|
void DivPlatformSAA1099::acquire_mame(short* bufL, short* bufR, size_t start, size_t len) {
|
2022-01-15 04:26:22 +00:00
|
|
|
if (saaBufLen<len) {
|
|
|
|
saaBufLen=len;
|
2022-01-14 23:19:52 +00:00
|
|
|
for (int i=0; i<2; i++) {
|
2022-01-15 04:26:22 +00:00
|
|
|
delete[] saaBuf[i];
|
|
|
|
saaBuf[i]=new short[saaBufLen];
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!writes.empty()) {
|
|
|
|
QueuedWrite w=writes.front();
|
|
|
|
saa.control_w(w.addr);
|
|
|
|
saa.data_w(w.val);
|
|
|
|
writes.pop();
|
|
|
|
}
|
2022-01-15 04:26:22 +00:00
|
|
|
saa.sound_stream_update(saaBuf,len);
|
2022-01-14 21:29:27 +00:00
|
|
|
for (size_t i=0; i<len; i++) {
|
2022-01-15 04:26:22 +00:00
|
|
|
bufL[i+start]=saaBuf[0][i];
|
|
|
|
bufR[i+start]=saaBuf[1][i];
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-13 22:49:24 +00:00
|
|
|
void DivPlatformSAA1099::acquire_saaSound(short* bufL, short* bufR, size_t start, size_t len) {
|
|
|
|
if (saaBufLen<len*2) {
|
|
|
|
saaBufLen=len*2;
|
|
|
|
for (int i=0; i<2; i++) {
|
|
|
|
delete[] saaBuf[i];
|
|
|
|
saaBuf[i]=new short[saaBufLen];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!writes.empty()) {
|
|
|
|
QueuedWrite w=writes.front();
|
|
|
|
saa_saaSound->WriteAddressData(w.addr,w.val);
|
|
|
|
writes.pop();
|
|
|
|
}
|
|
|
|
saa_saaSound->GenerateMany((unsigned char*)saaBuf[0],len);
|
|
|
|
for (size_t i=0; i<len; i++) {
|
|
|
|
bufL[i+start]=saaBuf[0][i<<1];
|
|
|
|
bufR[i+start]=saaBuf[0][1+(i<<1)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformSAA1099::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
|
|
|
switch (core) {
|
|
|
|
case DIV_SAA_CORE_MAME:
|
|
|
|
acquire_mame(bufL,bufR,start,len);
|
|
|
|
break;
|
|
|
|
case DIV_SAA_CORE_SAASOUND:
|
|
|
|
acquire_saaSound(bufL,bufR,start,len);
|
|
|
|
break;
|
|
|
|
case DIV_SAA_CORE_E:
|
|
|
|
//acquire_e(bufL,bufR,start,len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-15 04:26:22 +00:00
|
|
|
inline unsigned char applyPan(unsigned char vol, unsigned char pan) {
|
2022-01-15 04:37:03 +00:00
|
|
|
return ((vol*(pan>>4))/15)|(((vol*(pan&15))/15)<<4);
|
2022-01-15 04:26:22 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 21:29:27 +00:00
|
|
|
void DivPlatformSAA1099::tick() {
|
2022-01-14 23:19:52 +00:00
|
|
|
for (int i=0; i<6; i++) {
|
2022-01-14 21:29:27 +00:00
|
|
|
chan[i].std.next();
|
|
|
|
if (chan[i].std.hadVol) {
|
2022-01-30 17:31:50 +00:00
|
|
|
chan[i].outVol=MIN(15,chan[i].std.vol)-(15-(chan[i].vol&15));
|
2022-01-14 21:29:27 +00:00
|
|
|
if (chan[i].outVol<0) chan[i].outVol=0;
|
|
|
|
if (isMuted[i]) {
|
2022-01-14 23:19:52 +00:00
|
|
|
rWrite(i,0);
|
2022-01-14 21:29:27 +00:00
|
|
|
} else {
|
2022-01-15 04:26:22 +00:00
|
|
|
rWrite(i,applyPan(chan[i].outVol&15,chan[i].pan));
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chan[i].std.hadArp) {
|
|
|
|
if (!chan[i].inPorta) {
|
|
|
|
if (chan[i].std.arpMode) {
|
2022-01-28 05:55:51 +00:00
|
|
|
chan[i].baseFreq=NOTE_PERIODIC(chan[i].std.arp);
|
2022-01-14 21:29:27 +00:00
|
|
|
} else {
|
2022-01-28 05:55:51 +00:00
|
|
|
chan[i].baseFreq=NOTE_PERIODIC(chan[i].note+chan[i].std.arp);
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
chan[i].freqChanged=true;
|
|
|
|
} else {
|
|
|
|
if (chan[i].std.arpMode && chan[i].std.finishedArp) {
|
2022-01-28 05:55:51 +00:00
|
|
|
chan[i].baseFreq=NOTE_PERIODIC(chan[i].note);
|
2022-01-14 21:29:27 +00:00
|
|
|
chan[i].freqChanged=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chan[i].std.hadDuty) {
|
2022-01-15 04:26:22 +00:00
|
|
|
saaNoise[i/3]=chan[i].std.duty&3;
|
|
|
|
rWrite(0x16,saaNoise[0]|(saaNoise[1]<<4));
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
if (chan[i].std.hadWave) {
|
2022-01-15 04:26:22 +00:00
|
|
|
chan[i].psgMode=chan[i].std.wave&3;
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
2022-02-01 08:44:02 +00:00
|
|
|
if (chan[i].std.hadEx1) {
|
|
|
|
saaEnv[i/3]=chan[i].std.ex1;
|
|
|
|
rWrite(0x18+(i/3),saaEnv[i/3]);
|
|
|
|
}
|
2022-01-14 21:29:27 +00:00
|
|
|
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) {
|
|
|
|
chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true);
|
2022-02-03 07:46:49 +00:00
|
|
|
if (chan[i].freq>65535) chan[i].freq=65535;
|
2022-01-14 23:19:52 +00:00
|
|
|
if (chan[i].freq>=32768) {
|
|
|
|
chan[i].freqH=7;
|
|
|
|
} else if (chan[i].freq>=16384) {
|
|
|
|
chan[i].freqH=6;
|
|
|
|
} else if (chan[i].freq>=8192) {
|
|
|
|
chan[i].freqH=5;
|
|
|
|
} else if (chan[i].freq>=4096) {
|
|
|
|
chan[i].freqH=4;
|
|
|
|
} else if (chan[i].freq>=2048) {
|
|
|
|
chan[i].freqH=3;
|
|
|
|
} else if (chan[i].freq>=1024) {
|
|
|
|
chan[i].freqH=2;
|
|
|
|
} else if (chan[i].freq>=512) {
|
|
|
|
chan[i].freqH=1;
|
|
|
|
} else {
|
|
|
|
chan[i].freqH=0;
|
|
|
|
}
|
|
|
|
chan[i].freqL=0xff-(chan[i].freq>>chan[i].freqH);
|
|
|
|
chan[i].freqH=7-chan[i].freqH;
|
2022-01-14 21:29:27 +00:00
|
|
|
if (chan[i].freq>4095) chan[i].freq=4095;
|
|
|
|
if (chan[i].keyOn) {
|
|
|
|
}
|
|
|
|
if (chan[i].keyOff) {
|
2022-01-14 23:19:52 +00:00
|
|
|
rWrite(i,0);
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
2022-01-14 23:19:52 +00:00
|
|
|
rWrite(0x08+i,chan[i].freqL);
|
2022-01-16 06:55:54 +00:00
|
|
|
rWrite(0x10+(i>>1),chan[i&6].freqH|(chan[1+(i&6)].freqH<<4));
|
2022-01-14 21:29:27 +00:00
|
|
|
if (chan[i].keyOn) chan[i].keyOn=false;
|
|
|
|
if (chan[i].keyOff) chan[i].keyOff=false;
|
|
|
|
chan[i].freqChanged=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 23:19:52 +00:00
|
|
|
rWrite(0x14,(chan[0].psgMode&1)|
|
|
|
|
((chan[1].psgMode&1)<<1)|
|
|
|
|
((chan[2].psgMode&1)<<2)|
|
|
|
|
((chan[3].psgMode&1)<<3)|
|
|
|
|
((chan[4].psgMode&1)<<4)|
|
|
|
|
((chan[5].psgMode&1)<<5)
|
|
|
|
);
|
|
|
|
|
|
|
|
rWrite(0x15,((chan[0].psgMode&2)>>1)|
|
|
|
|
(chan[1].psgMode&2)|
|
|
|
|
((chan[2].psgMode&2)<<1)|
|
|
|
|
((chan[3].psgMode&2)<<2)|
|
|
|
|
((chan[4].psgMode&2)<<3)|
|
|
|
|
((chan[5].psgMode&2)<<4)
|
|
|
|
);
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int DivPlatformSAA1099::dispatch(DivCommand c) {
|
|
|
|
switch (c.cmd) {
|
|
|
|
case DIV_CMD_NOTE_ON: {
|
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins);
|
2022-01-19 05:01:34 +00:00
|
|
|
if (c.value!=DIV_NOTE_NULL) {
|
2022-01-28 05:55:51 +00:00
|
|
|
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
|
2022-01-19 05:01:34 +00:00
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
chan[c.chan].note=c.value;
|
|
|
|
}
|
2022-01-14 21:29:27 +00:00
|
|
|
chan[c.chan].active=true;
|
|
|
|
chan[c.chan].keyOn=true;
|
|
|
|
chan[c.chan].std.init(ins);
|
|
|
|
if (isMuted[c.chan]) {
|
2022-01-14 23:19:52 +00:00
|
|
|
rWrite(c.chan,0);
|
2022-01-14 21:29:27 +00:00
|
|
|
} else {
|
2022-01-15 04:26:22 +00:00
|
|
|
rWrite(c.chan,applyPan(chan[c.chan].vol&15,chan[c.chan].pan));
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DIV_CMD_NOTE_OFF:
|
|
|
|
chan[c.chan].keyOff=true;
|
|
|
|
chan[c.chan].active=false;
|
|
|
|
chan[c.chan].std.init(NULL);
|
|
|
|
break;
|
2022-02-08 18:11:04 +00:00
|
|
|
case DIV_CMD_NOTE_OFF_ENV:
|
|
|
|
case DIV_CMD_ENV_RELEASE:
|
|
|
|
chan[c.chan].std.release();
|
|
|
|
break;
|
2022-01-14 21:29:27 +00:00
|
|
|
case DIV_CMD_VOLUME: {
|
|
|
|
chan[c.chan].vol=c.value;
|
|
|
|
if (!chan[c.chan].std.hasVol) {
|
|
|
|
chan[c.chan].outVol=c.value;
|
|
|
|
}
|
|
|
|
if (isMuted[c.chan]) {
|
2022-01-14 23:19:52 +00:00
|
|
|
rWrite(c.chan,0);
|
2022-01-14 21:29:27 +00:00
|
|
|
} else {
|
2022-01-15 04:26:22 +00:00
|
|
|
if (chan[c.chan].active) rWrite(c.chan,applyPan(chan[c.chan].vol&15,chan[c.chan].pan));
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DIV_CMD_GET_VOLUME: {
|
|
|
|
return chan[c.chan].vol;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DIV_CMD_INSTRUMENT:
|
2022-01-17 23:01:40 +00:00
|
|
|
if (chan[c.chan].ins!=c.value || c.value2==1) {
|
2022-01-14 21:29:27 +00:00
|
|
|
chan[c.chan].insChanged=true;
|
|
|
|
}
|
|
|
|
chan[c.chan].ins=c.value;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_PITCH: {
|
|
|
|
chan[c.chan].pitch=c.value;
|
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DIV_CMD_NOTE_PORTA: {
|
2022-01-28 05:55:51 +00:00
|
|
|
int destFreq=NOTE_PERIODIC(c.value2);
|
2022-01-14 21:29:27 +00:00
|
|
|
bool return2=false;
|
|
|
|
if (destFreq>chan[c.chan].baseFreq) {
|
2022-01-15 04:26:22 +00:00
|
|
|
chan[c.chan].baseFreq+=c.value*(8-chan[c.chan].freqH);
|
2022-01-14 21:29:27 +00:00
|
|
|
if (chan[c.chan].baseFreq>=destFreq) {
|
|
|
|
chan[c.chan].baseFreq=destFreq;
|
|
|
|
return2=true;
|
|
|
|
}
|
|
|
|
} else {
|
2022-01-15 04:26:22 +00:00
|
|
|
chan[c.chan].baseFreq-=c.value*(8-chan[c.chan].freqH);
|
2022-01-14 21:29:27 +00:00
|
|
|
if (chan[c.chan].baseFreq<=destFreq) {
|
|
|
|
chan[c.chan].baseFreq=destFreq;
|
|
|
|
return2=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
if (return2) {
|
|
|
|
chan[c.chan].inPorta=false;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-01-15 04:37:03 +00:00
|
|
|
case DIV_CMD_PANNING:
|
|
|
|
chan[c.chan].pan=c.value;
|
|
|
|
if (isMuted[c.chan]) {
|
|
|
|
rWrite(c.chan,0);
|
|
|
|
} else {
|
|
|
|
if (chan[c.chan].active) rWrite(c.chan,applyPan(chan[c.chan].vol&15,chan[c.chan].pan));
|
|
|
|
}
|
|
|
|
break;
|
2022-01-14 21:29:27 +00:00
|
|
|
case DIV_CMD_LEGATO: {
|
2022-01-28 05:55:51 +00:00
|
|
|
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
|
2022-01-14 21:29:27 +00:00
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
break;
|
|
|
|
}
|
2022-01-15 04:26:22 +00:00
|
|
|
case DIV_CMD_STD_NOISE_MODE:
|
|
|
|
chan[c.chan].psgMode=(c.value&1)|((c.value&16)>>3);
|
2022-01-14 21:29:27 +00:00
|
|
|
break;
|
2022-01-15 04:26:22 +00:00
|
|
|
case DIV_CMD_STD_NOISE_FREQ:
|
|
|
|
saaNoise[c.chan/3]=(c.value&1)|((c.value&16)>>3);
|
|
|
|
rWrite(0x16,saaNoise[0]|(saaNoise[1]<<4));
|
2022-01-14 21:29:27 +00:00
|
|
|
break;
|
2022-01-15 04:26:22 +00:00
|
|
|
case DIV_CMD_SAA_ENVELOPE:
|
2022-01-15 04:37:03 +00:00
|
|
|
saaEnv[c.chan/3]=c.value;
|
|
|
|
rWrite(0x18+(c.chan/3),c.value);
|
2022-01-14 21:29:27 +00:00
|
|
|
break;
|
|
|
|
case DIV_ALWAYS_SET_VOLUME:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_GET_VOLMAX:
|
|
|
|
return 15;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_PRE_PORTA:
|
2022-02-09 03:49:52 +00:00
|
|
|
if (chan[c.chan].active && c.value2) {
|
2022-02-09 03:46:58 +00:00
|
|
|
if (parent->song.resetMacroOnPorta) chan[c.chan].std.init(parent->getIns(chan[c.chan].ins));
|
|
|
|
}
|
2022-01-14 21:29:27 +00:00
|
|
|
chan[c.chan].inPorta=c.value;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_PRE_NOTE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//printf("WARNING: unimplemented command %d\n",c.cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformSAA1099::muteChannel(int ch, bool mute) {
|
|
|
|
isMuted[ch]=mute;
|
|
|
|
if (isMuted[ch]) {
|
2022-01-14 23:19:52 +00:00
|
|
|
rWrite(ch,0);
|
2022-01-14 21:29:27 +00:00
|
|
|
} else {
|
2022-01-15 04:26:22 +00:00
|
|
|
if (chan[ch].active) rWrite(ch,applyPan(chan[ch].outVol&15,chan[ch].pan));
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformSAA1099::forceIns() {
|
2022-01-15 04:26:22 +00:00
|
|
|
for (int i=0; i<6; i++) {
|
2022-01-14 21:29:27 +00:00
|
|
|
chan[i].insChanged=true;
|
2022-01-15 04:26:22 +00:00
|
|
|
chan[i].freqChanged=true;
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
2022-01-15 04:26:22 +00:00
|
|
|
rWrite(0x18,saaEnv[0]);
|
|
|
|
rWrite(0x19,saaEnv[1]);
|
|
|
|
rWrite(0x16,saaNoise[0]|(saaNoise[1]<<4));
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 05:29:16 +00:00
|
|
|
void* DivPlatformSAA1099::getChanState(int ch) {
|
|
|
|
return &chan[ch];
|
|
|
|
}
|
|
|
|
|
2022-01-14 21:29:27 +00:00
|
|
|
void DivPlatformSAA1099::reset() {
|
|
|
|
while (!writes.empty()) writes.pop();
|
2022-02-13 22:49:24 +00:00
|
|
|
switch (core) {
|
|
|
|
case DIV_SAA_CORE_MAME:
|
|
|
|
saa=saa1099_device();
|
|
|
|
break;
|
|
|
|
case DIV_SAA_CORE_SAASOUND:
|
|
|
|
saa_saaSound->Clear();
|
|
|
|
break;
|
|
|
|
case DIV_SAA_CORE_E:
|
|
|
|
break;
|
|
|
|
}
|
2022-01-14 23:19:52 +00:00
|
|
|
for (int i=0; i<6; i++) {
|
2022-01-14 21:29:27 +00:00
|
|
|
chan[i]=DivPlatformSAA1099::Channel();
|
|
|
|
chan[i].vol=0x0f;
|
|
|
|
}
|
2022-01-25 23:46:27 +00:00
|
|
|
if (dumpWrites) {
|
|
|
|
addWrite(0xffffffff,0);
|
|
|
|
}
|
2022-01-14 21:29:27 +00:00
|
|
|
|
|
|
|
lastBusy=60;
|
|
|
|
dacMode=0;
|
|
|
|
dacPeriod=0;
|
|
|
|
dacPos=0;
|
|
|
|
dacRate=0;
|
|
|
|
dacSample=-1;
|
|
|
|
sampleBank=0;
|
2022-01-15 04:26:22 +00:00
|
|
|
saaEnv[0]=0;
|
|
|
|
saaEnv[1]=0;
|
|
|
|
saaNoise[0]=0;
|
|
|
|
saaNoise[1]=0;
|
2022-01-14 21:29:27 +00:00
|
|
|
|
|
|
|
delay=0;
|
|
|
|
|
|
|
|
extMode=false;
|
2022-01-14 23:19:52 +00:00
|
|
|
|
|
|
|
rWrite(0x1c,1);
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DivPlatformSAA1099::isStereo() {
|
2022-01-14 23:19:52 +00:00
|
|
|
return true;
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
|
2022-01-15 04:26:22 +00:00
|
|
|
int DivPlatformSAA1099::getPortaFloor(int ch) {
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
|
2022-01-14 21:29:27 +00:00
|
|
|
bool DivPlatformSAA1099::keyOffAffectsArp(int ch) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformSAA1099::notifyInsDeletion(void* ins) {
|
2022-01-14 23:19:52 +00:00
|
|
|
for (int i=0; i<6; i++) {
|
2022-01-14 21:29:27 +00:00
|
|
|
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-28 17:59:53 +00:00
|
|
|
void DivPlatformSAA1099::setFlags(unsigned int flags) {
|
2022-01-29 05:20:27 +00:00
|
|
|
if (flags==2) {
|
|
|
|
chipClock=COLOR_PAL*8.0/5.0;
|
|
|
|
} else if (flags==1) {
|
|
|
|
chipClock=COLOR_NTSC*2.0;
|
|
|
|
} else {
|
|
|
|
chipClock=8000000;
|
|
|
|
}
|
2022-01-28 05:55:51 +00:00
|
|
|
rate=chipClock/32;
|
2022-02-13 22:49:24 +00:00
|
|
|
|
|
|
|
switch (core) {
|
|
|
|
case DIV_SAA_CORE_MAME:
|
|
|
|
break;
|
|
|
|
case DIV_SAA_CORE_SAASOUND:
|
|
|
|
saa_saaSound->SetClockRate(chipClock);
|
|
|
|
saa_saaSound->SetSampleRate(rate);
|
|
|
|
|
|
|
|
printf("rate: %ld bytes %d params %lx\n",saa_saaSound->GetCurrentSampleRate(),saa_saaSound->GetCurrentBytesPerSample(),saa_saaSound->GetCurrentSoundParameters());
|
|
|
|
break;
|
|
|
|
case DIV_SAA_CORE_E:
|
|
|
|
break;
|
|
|
|
}
|
2022-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-01 23:08:19 +00:00
|
|
|
void DivPlatformSAA1099::poke(unsigned int addr, unsigned short val) {
|
|
|
|
rWrite(addr,val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformSAA1099::poke(std::vector<DivRegWrite>& wlist) {
|
|
|
|
for (DivRegWrite& i: wlist) rWrite(i.addr,i.val);
|
|
|
|
}
|
|
|
|
|
2022-02-13 22:49:24 +00:00
|
|
|
void DivPlatformSAA1099::setCore(DivSAACores c) {
|
|
|
|
core=c;
|
|
|
|
}
|
|
|
|
|
2022-01-28 17:59:53 +00:00
|
|
|
int DivPlatformSAA1099::init(DivEngine* p, int channels, int sugRate, unsigned int flags) {
|
2022-01-14 21:29:27 +00:00
|
|
|
parent=p;
|
2022-01-17 04:21:27 +00:00
|
|
|
dumpWrites=false;
|
2022-01-14 21:29:27 +00:00
|
|
|
skipRegisterWrites=false;
|
2022-02-13 22:49:24 +00:00
|
|
|
saa_saaSound=NULL;
|
2022-01-14 23:19:52 +00:00
|
|
|
for (int i=0; i<6; i++) {
|
2022-01-14 21:29:27 +00:00
|
|
|
isMuted[i]=false;
|
|
|
|
}
|
2022-02-13 22:49:24 +00:00
|
|
|
if (core==DIV_SAA_CORE_SAASOUND) {
|
|
|
|
saa_saaSound=CreateCSAASound();
|
|
|
|
saa_saaSound->SetOversample(1);
|
|
|
|
saa_saaSound->SetSoundParameters(SAAP_NOFILTER|SAAP_16BIT|SAAP_STEREO);
|
|
|
|
}
|
2022-01-28 17:59:53 +00:00
|
|
|
setFlags(flags);
|
2022-01-15 04:26:22 +00:00
|
|
|
saaBufLen=65536;
|
|
|
|
for (int i=0; i<2; i++) saaBuf[i]=new short[saaBufLen];
|
2022-01-14 21:29:27 +00:00
|
|
|
reset();
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformSAA1099::quit() {
|
2022-02-13 22:49:24 +00:00
|
|
|
if (saa_saaSound!=NULL) {
|
|
|
|
DestroyCSAASound(saa_saaSound);
|
|
|
|
saa_saaSound=NULL;
|
|
|
|
}
|
2022-01-15 04:26:22 +00:00
|
|
|
for (int i=0; i<2; i++) delete[] saaBuf[i];
|
2022-01-17 18:29:35 +00:00
|
|
|
}
|