SAA1099: implement SAASound core option

This commit is contained in:
tildearrow 2022-02-13 17:49:24 -05:00
parent 2f766553e8
commit 9ea510c351
5 changed files with 96 additions and 5 deletions

View file

@ -173,9 +173,13 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do
case DIV_SYSTEM_TIA:
dispatch=new DivPlatformTIA;
break;
case DIV_SYSTEM_SAA1099:
case DIV_SYSTEM_SAA1099: {
int saaCore=eng->getConfInt("saaCore",0);
if (saaCore<0 || saaCore>2) saaCore=0;
dispatch=new DivPlatformSAA1099;
((DivPlatformSAA1099*)dispatch)->setCore((DivSAACores)saaCore);
break;
}
default:
logW("this system is not supported yet! using dummy platform.\n");
dispatch=new DivPlatformDummy;

View file

@ -37,7 +37,7 @@ const char** DivPlatformSAA1099::getRegisterSheet() {
return regCheatSheetSAA;
}
void DivPlatformSAA1099::acquire(short* bufL, short* bufR, size_t start, size_t len) {
void DivPlatformSAA1099::acquire_mame(short* bufL, short* bufR, size_t start, size_t len) {
if (saaBufLen<len) {
saaBufLen=len;
for (int i=0; i<2; i++) {
@ -58,6 +58,40 @@ void DivPlatformSAA1099::acquire(short* bufL, short* bufR, size_t start, size_t
}
}
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;
}
}
inline unsigned char applyPan(unsigned char vol, unsigned char pan) {
return ((vol*(pan>>4))/15)|(((vol*(pan&15))/15)<<4);
}
@ -301,7 +335,16 @@ void* DivPlatformSAA1099::getChanState(int ch) {
void DivPlatformSAA1099::reset() {
while (!writes.empty()) writes.pop();
saa=saa1099_device();
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;
}
for (int i=0; i<6; i++) {
chan[i]=DivPlatformSAA1099::Channel();
chan[i].vol=0x0f;
@ -356,6 +399,19 @@ void DivPlatformSAA1099::setFlags(unsigned int flags) {
chipClock=8000000;
}
rate=chipClock/32;
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;
}
}
void DivPlatformSAA1099::poke(unsigned int addr, unsigned short val) {
@ -366,13 +422,23 @@ void DivPlatformSAA1099::poke(std::vector<DivRegWrite>& wlist) {
for (DivRegWrite& i: wlist) rWrite(i.addr,i.val);
}
void DivPlatformSAA1099::setCore(DivSAACores c) {
core=c;
}
int DivPlatformSAA1099::init(DivEngine* p, int channels, int sugRate, unsigned int flags) {
parent=p;
dumpWrites=false;
skipRegisterWrites=false;
saa_saaSound=NULL;
for (int i=0; i<6; i++) {
isMuted[i]=false;
}
if (core==DIV_SAA_CORE_SAASOUND) {
saa_saaSound=CreateCSAASound();
saa_saaSound->SetOversample(1);
saa_saaSound->SetSoundParameters(SAAP_NOFILTER|SAAP_16BIT|SAAP_STEREO);
}
setFlags(flags);
saaBufLen=65536;
for (int i=0; i<2; i++) saaBuf[i]=new short[saaBufLen];
@ -381,5 +447,9 @@ int DivPlatformSAA1099::init(DivEngine* p, int channels, int sugRate, unsigned i
}
void DivPlatformSAA1099::quit() {
if (saa_saaSound!=NULL) {
DestroyCSAASound(saa_saaSound);
saa_saaSound=NULL;
}
for (int i=0; i<2; i++) delete[] saaBuf[i];
}

View file

@ -4,6 +4,7 @@
#include "../macroInt.h"
#include <queue>
#include "sound/saa1099.h"
#include "../../../../extern/SAASound/src/SAASound.h"
enum DivSAACores {
DIV_SAA_CORE_MAME=0,
@ -33,7 +34,9 @@ class DivPlatformSAA1099: public DivDispatch {
QueuedWrite(unsigned short a, unsigned char v): addr(a), val(v), addrOrVal(false) {}
};
std::queue<QueuedWrite> writes;
DivSAACores core;
saa1099_device saa;
CSAASound* saa_saaSound;
unsigned char lastBusy;
bool dacMode;
@ -67,6 +70,7 @@ class DivPlatformSAA1099: public DivDispatch {
void forceIns();
void tick();
void muteChannel(int ch, bool mute);
void setCore(DivSAACores core);
void setFlags(unsigned int flags);
bool isStereo();
int getPortaFloor(int ch);