AUDIO: Backport commit r3523 from DOSBox to the CMS emulator

CMS/Gameblaster: add sbtype=gb, fix base addresses other than 220h, fix lack of sound when starting from autoexec, add autodetection (Thanks robertmo and Cloudschatze)
This commit is contained in:
Cameron Cawley 2022-11-17 18:11:45 +00:00 committed by Filippos Karapetis
parent 60676c825a
commit 99485ac757
2 changed files with 24 additions and 24 deletions

View File

@ -82,37 +82,23 @@ static const int amplitude_lookup[16] = {
}; };
void CMSEmulator::portWrite(int port, int val) { void CMSEmulator::portWrite(int port, int val) {
switch (port) { switch (port-_basePort) {
case 0x220: case 0:
portWriteIntern(0, 0, val);
break;
case 1:
portWriteIntern(0, 1, val); portWriteIntern(0, 1, val);
break; break;
case 0x221: case 2:
_saa1099[0].selected_reg = val & 0x1f; portWriteIntern(1, 0, val);
if (_saa1099[0].selected_reg == 0x18 || _saa1099[0].selected_reg == 0x19) {
/* clock the envelope channels */
if (_saa1099[0].env_clock[0])
envelope(0, 0);
if (_saa1099[0].env_clock[1])
envelope(0, 1);
}
break; break;
case 0x222: case 3:
portWriteIntern(1, 1, val); portWriteIntern(1, 1, val);
break; break;
case 0x223:
_saa1099[1].selected_reg = val & 0x1f;
if (_saa1099[1].selected_reg == 0x18 || _saa1099[1].selected_reg == 0x19) {
/* clock the envelope channels */
if (_saa1099[1].env_clock[0])
envelope(1, 0);
if (_saa1099[1].env_clock[1])
envelope(1, 1);
}
break;
default: default:
warning("CMSEmulator got port: 0x%X", port); warning("CMSEmulator got port: 0x%X", port);
break; break;
@ -252,6 +238,18 @@ void CMSEmulator::update(int chip, int16 *buffer, int length) {
void CMSEmulator::portWriteIntern(int chip, int offset, int data) { void CMSEmulator::portWriteIntern(int chip, int offset, int data) {
SAA1099 *saa = &_saa1099[chip]; SAA1099 *saa = &_saa1099[chip];
if(offset == 1) {
// address port
saa->selected_reg = data & 0x1f;
if (saa->selected_reg == 0x18 || saa->selected_reg == 0x19) {
/* clock the envelope channels */
if (saa->env_clock[0])
envelope(chip,0);
if (saa->env_clock[1])
envelope(chip,1);
}
return;
}
int reg = saa->selected_reg; int reg = saa->selected_reg;
int ch; int ch;

View File

@ -66,11 +66,12 @@ struct SAA1099 {
class CMSEmulator { class CMSEmulator {
public: public:
CMSEmulator(uint32 sampleRate) { CMSEmulator(uint32 sampleRate, uint32 basePort = 0x220) {
// In PCs the chips run at 7.15909 MHz instead of 8 MHz. // In PCs the chips run at 7.15909 MHz instead of 8 MHz.
// Adjust sampling rate upwards to bring pitch down. // Adjust sampling rate upwards to bring pitch down.
_sampleRate = (sampleRate * 352) / 315; _sampleRate = (sampleRate * 352) / 315;
memset(_saa1099, 0, sizeof(SAA1099)*2); memset(_saa1099, 0, sizeof(SAA1099)*2);
_basePort = basePort;
} }
~CMSEmulator() { } ~CMSEmulator() { }
@ -81,6 +82,7 @@ public:
private: private:
uint32 _sampleRate; uint32 _sampleRate;
uint32 _basePort;
SAA1099 _saa1099[2]; SAA1099 _saa1099[2];