Fix for sidfx in tight loop

Change might have been disregarded due to missing volatile
This commit is contained in:
drmortalwombat 2024-09-02 15:26:05 +02:00
parent 0163fb729a
commit 0b2c36ab1a

View File

@ -12,10 +12,11 @@ enum SIDFXState
static struct SIDFXChannel static struct SIDFXChannel
{ {
const SIDFX * com; const SIDFX * volatile com;
byte delay, cnt, priority; byte delay, priority;
volatile SIDFXState state; volatile byte cnt;
unsigned freq, pwm; volatile SIDFXState state;
unsigned freq, pwm;
} channels[3]; } channels[3];
@ -78,81 +79,92 @@ inline void sidfx_loop_ch(byte ch)
channels[ch].state = SIDFX_READY; channels[ch].state = SIDFX_READY;
break; break;
case SIDFX_READY: case SIDFX_READY:
if (channels[ch].com)
{ {
channels[ch].freq = channels[ch].com->freq; const SIDFX * com = channels[ch].com;
channels[ch].pwm = channels[ch].com->pwm; if (com)
{
channels[ch].freq = com->freq;
channels[ch].pwm = com->pwm;
sid.voices[ch].freq = channels[ch].com->freq; sid.voices[ch].freq = com->freq;
sid.voices[ch].pwm = channels[ch].com->pwm; sid.voices[ch].pwm = com->pwm;
sid.voices[ch].attdec = channels[ch].com->attdec; sid.voices[ch].attdec = com->attdec;
sid.voices[ch].susrel = channels[ch].com->susrel; sid.voices[ch].susrel = com->susrel;
sid.voices[ch].ctrl = channels[ch].com->ctrl; sid.voices[ch].ctrl = com->ctrl;
channels[ch].delay = channels[ch].com->time1; channels[ch].delay = com->time1;
channels[ch].state = SIDFX_PLAY; channels[ch].state = SIDFX_PLAY;
}
else
channels[ch].state = SIDFX_IDLE;
} }
else
channels[ch].state = SIDFX_IDLE;
break; break;
case SIDFX_PLAY: case SIDFX_PLAY:
if (channels[ch].com->dfreq)
{ {
channels[ch].freq += channels[ch].com->dfreq; const SIDFX * com = channels[ch].com;
sid.voices[ch].freq = channels[ch].freq; if (com->dfreq)
} {
if (channels[ch].com->dpwm) channels[ch].freq += com->dfreq;
{ sid.voices[ch].freq = channels[ch].freq;
channels[ch].pwm += channels[ch].com->dpwm; }
sid.voices[ch].pwm = channels[ch].pwm; if (com->dpwm)
} {
channels[ch].pwm += com->dpwm;
sid.voices[ch].pwm = channels[ch].pwm;
}
if (channels[ch].delay) if (channels[ch].delay)
channels[ch].delay--; channels[ch].delay--;
else if (channels[ch].com->time0) else if (com->time0)
{ {
sid.voices[ch].ctrl = channels[ch].com->ctrl & ~SID_CTRL_GATE; sid.voices[ch].ctrl = com->ctrl & ~SID_CTRL_GATE;
channels[ch].delay = channels[ch].com->time0; channels[ch].delay = com->time0;
channels[ch].state = SIDFX_WAIT; channels[ch].state = SIDFX_WAIT;
} }
else if (channels[ch].cnt) else if (channels[ch].cnt)
{ {
channels[ch].cnt--; com++;
channels[ch].com++; channels[ch].cnt--;
channels[ch].priority = channels[ch].com->priority; channels[ch].com = com;
channels[ch].state = SIDFX_READY; channels[ch].priority = com->priority;
} channels[ch].state = SIDFX_READY;
else }
{ else
channels[ch].com = nullptr; {
channels[ch].state = SIDFX_RESET_0; channels[ch].com = nullptr;
channels[ch].state = SIDFX_RESET_0;
}
} }
break; break;
case SIDFX_WAIT: case SIDFX_WAIT:
if (channels[ch].com->dfreq)
{ {
channels[ch].freq += channels[ch].com->dfreq; const SIDFX * com = channels[ch].com;
sid.voices[ch].freq = channels[ch].freq; if (com->dfreq)
} {
if (channels[ch].com->dpwm) channels[ch].freq += com->dfreq;
{ sid.voices[ch].freq = channels[ch].freq;
channels[ch].pwm += channels[ch].com->dpwm; }
sid.voices[ch].pwm = channels[ch].pwm; if (com->dpwm)
} {
channels[ch].pwm += com->dpwm;
sid.voices[ch].pwm = channels[ch].pwm;
}
if (channels[ch].delay) if (channels[ch].delay)
channels[ch].delay--; channels[ch].delay--;
else if (channels[ch].cnt) else if (channels[ch].cnt)
{ {
channels[ch].cnt--; com++;
channels[ch].com++; channels[ch].cnt--;
channels[ch].priority = channels[ch].com->priority; channels[ch].com = com;
channels[ch].state = SIDFX_RESET_0; channels[ch].priority = com->priority;
} channels[ch].state = SIDFX_RESET_0;
else }
{ else
channels[ch].com = nullptr; {
channels[ch].state = SIDFX_RESET_0; channels[ch].com = nullptr;
channels[ch].state = SIDFX_RESET_0;
}
} }
break; break;
} }