From b8f214020f6e397eb0a668cfcba824dcbce289ea Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 8 Mar 2025 03:05:09 -0500 Subject: [PATCH] AY: get TFX and DAC working! sadly I don't think I can improve this any further for now... --- src/engine/platform/ay.cpp | 124 ++++++++++++++++++--------------- src/engine/platform/ay.h | 4 +- src/engine/platform/ay8930.cpp | 71 +++++++++++++------ src/engine/platform/ay8930.h | 2 +- 4 files changed, 123 insertions(+), 78 deletions(-) diff --git a/src/engine/platform/ay.cpp b/src/engine/platform/ay.cpp index 7c186a043..3b35e282c 100644 --- a/src/engine/platform/ay.cpp +++ b/src/engine/platform/ay.cpp @@ -113,15 +113,15 @@ const unsigned char dacLogTableAY[256]={ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 }; -void DivPlatformAY8910::runDAC(int runRate) { +void DivPlatformAY8910::runDAC(int runRate, int advance) { if (runRate==0) runRate=dacRate; for (int i=0; i<3; i++) { if (chan[i].active && (chan[i].curPSGMode.val&8) && chan[i].dac.sample!=-1) { - chan[i].dac.period+=chan[i].dac.rate; + chan[i].dac.period+=chan[i].dac.rate*advance; bool end=false; bool changed=false; int prevOut=chan[i].dac.out; - while (chan[i].dac.period>runRate && !end) { + while (chan[i].dac.period>=runRate && !end) { DivSample* s=parent->getSample(chan[i].dac.sample); if (s->samples<=0 || chan[i].dac.pos<0 || chan[i].dac.pos>=(int)s->samples) { chan[i].dac.sample=-1; @@ -155,14 +155,14 @@ void DivPlatformAY8910::runDAC(int runRate) { } } -void DivPlatformAY8910::runTFX(int runRate) { +void DivPlatformAY8910::runTFX(int runRate, int advance) { /* developer's note: if you are checking for intellivision make sure to add "&& selCore" because for some reason, the register remap doesn't work when the user uses AtomicSSG core */ - float counterRatio=1.0; + float counterRatio=advance; if (runRate!=0) counterRatio=(double)rate/(double)runRate; int timerPeriod, output; for (int i=0; i<3; i++) { @@ -255,59 +255,73 @@ void DivPlatformAY8910::acquire_mame(blip_buffer_t** bb, size_t len) { oscBuf[i]->begin(len); } - //logV("%d, %d, %d",ay->noise_enable(0),ay->noise_enable(1),ay->noise_enable(2)); - for (size_t i=0; itone_enable(j) && ay->m_tone[j].volume!=0) { - const int period=MAX(1,ay->m_tone[j].period)*(ay->m_step_mul<<1); - const int remain=(period-ay->m_tone[j].count)>>1; - if (remainnoise_enable(j) && ay->m_tone[j].volume!=0) { - careAboutNoise=true; - } - - // envelope check - if (ay->m_tone[j].volume&16) { - careAboutEnv=true; - } - } - // envelope - if (careAboutEnv) { - if (ay->m_envelope[0].holding==0) { - const int periodEnv=MAX(1,ay->m_envelope[0].period)*ay->m_env_step_mul; - const int remainEnv=periodEnv-ay->m_envelope[0].count; - if (remainEnvnoise_period())*ay->m_step_mul; - const int noiseRemain=noisePeriod-ay->m_count_noise; - if (noiseRemaintone_enable(j) && ay->m_tone[j].volume!=0) { + const int period=MAX(1,ay->m_tone[j].period)*(ay->m_step_mul<<1); + const int remain=(period-ay->m_tone[j].count)>>1; + if (remainnoise_enable(j) && ay->m_tone[j].volume!=0) { + careAboutNoise=true; + } + + // envelope check + if (ay->m_tone[j].volume&16) { + careAboutEnv=true; + } + + // DAC + if (chan[j].active && (chan[j].curPSGMode.val&8) && chan[j].dac.sample!=-1) { + if (chan[j].dac.rate<=0) continue; + const int remainTime=(rate-chan[j].dac.period+chan[j].dac.rate-1)/chan[j].dac.rate; + if (remainTimem_envelope[0].holding==0) { + const int periodEnv=MAX(1,ay->m_envelope[0].period)*ay->m_env_step_mul; + const int remainEnv=periodEnv-ay->m_envelope[0].count; + if (remainEnvnoise_period())*ay->m_step_mul; + const int noiseRemain=noisePeriod-ay->m_count_noise; + if (noiseRemainsound_stream_update(ayBuf,advance); @@ -360,8 +374,8 @@ void DivPlatformAY8910::acquire_atomic(short** buf, size_t len) { oscBuf[i]->begin(len); } for (size_t i=0; i& stream, int sRate, size_t len) { writes.clear(); for (size_t i=0; irate && !end) { + while (chan[i].dac.period>=rate && !end) { DivSample* s=parent->getSample(chan[i].dac.sample); if (s->samples<=0 || chan[i].dac.pos<0 || chan[i].dac.pos>=(int)s->samples) { chan[i].dac.sample=-1; @@ -172,28 +172,59 @@ void DivPlatformAY8930::acquireDirect(blip_buffer_t** bb, size_t len) { for (size_t i=0; im_tone[j].period)*(ay->m_step_mul<<1); - const int remain=(period-ay->m_tone[j].count)>>5; - if (remaintone_enable(j) && ay->m_tone[j].volume!=0) { + const int period=MAX(1,ay->m_tone[j].period)*(ay->m_step_mul<<1); + const int remain=(period-ay->m_tone[j].count)>>5; + if (remainm_envelope[j].holding==0) { - const int periodEnv=MAX(1,ay->m_envelope[j].period)*ay->m_env_step_mul; - const int remainEnv=periodEnv-ay->m_envelope[j].count; - if (remainEnvnoise_enable(j) && ay->m_tone[j].volume!=0) { + careAboutNoise=true; + } + + // envelope check + if (ay->m_tone[j].volume&32) { + if (ay->m_envelope[j].holding==0) { + const int periodEnv=MAX(1,ay->m_envelope[j].period)*ay->m_env_step_mul; + const int remainEnv=periodEnv-ay->m_envelope[j].count; + if (remainEnvnoise_period())*ay->m_step_mul; + const int noiseRemain=noisePeriod-ay->m_count_noise; + if (noiseRemainnoise_period())*ay->m_step_mul; - const int noiseRemain=noisePeriod-ay->m_count_noise; - if (noiseRemainsound_stream_update(ayBuf,advance); diff --git a/src/engine/platform/ay8930.h b/src/engine/platform/ay8930.h index 91dd9e15e..a6ecc546a 100644 --- a/src/engine/platform/ay8930.h +++ b/src/engine/platform/ay8930.h @@ -123,7 +123,7 @@ class DivPlatformAY8930: public DivDispatch { short oldWrites[32]; short pendingWrites[32]; - void runDAC(); + void runDAC(int advance); void checkWrites(); void updateOutSel(bool immediate=false); void immWrite(unsigned char a, unsigned char v);