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,8 +12,9 @@ enum SIDFXState
static struct SIDFXChannel static struct SIDFXChannel
{ {
const SIDFX * com; const SIDFX * volatile com;
byte delay, cnt, priority; byte delay, priority;
volatile byte cnt;
volatile SIDFXState state; volatile SIDFXState state;
unsigned freq, pwm; unsigned freq, pwm;
@ -78,48 +79,54 @@ 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 else
channels[ch].state = SIDFX_IDLE; 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;
if (com->dfreq)
{
channels[ch].freq += com->dfreq;
sid.voices[ch].freq = channels[ch].freq; sid.voices[ch].freq = channels[ch].freq;
} }
if (channels[ch].com->dpwm) if (com->dpwm)
{ {
channels[ch].pwm += channels[ch].com->dpwm; channels[ch].pwm += com->dpwm;
sid.voices[ch].pwm = channels[ch].pwm; 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)
{ {
com++;
channels[ch].cnt--; channels[ch].cnt--;
channels[ch].com++; channels[ch].com = com;
channels[ch].priority = channels[ch].com->priority; channels[ch].priority = com->priority;
channels[ch].state = SIDFX_READY; channels[ch].state = SIDFX_READY;
} }
else else
@ -127,16 +134,19 @@ inline void sidfx_loop_ch(byte ch)
channels[ch].com = nullptr; channels[ch].com = nullptr;
channels[ch].state = SIDFX_RESET_0; 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;
if (com->dfreq)
{
channels[ch].freq += com->dfreq;
sid.voices[ch].freq = channels[ch].freq; sid.voices[ch].freq = channels[ch].freq;
} }
if (channels[ch].com->dpwm) if (com->dpwm)
{ {
channels[ch].pwm += channels[ch].com->dpwm; channels[ch].pwm += com->dpwm;
sid.voices[ch].pwm = channels[ch].pwm; sid.voices[ch].pwm = channels[ch].pwm;
} }
@ -144,9 +154,10 @@ inline void sidfx_loop_ch(byte ch)
channels[ch].delay--; channels[ch].delay--;
else if (channels[ch].cnt) else if (channels[ch].cnt)
{ {
com++;
channels[ch].cnt--; channels[ch].cnt--;
channels[ch].com++; channels[ch].com = com;
channels[ch].priority = channels[ch].com->priority; channels[ch].priority = com->priority;
channels[ch].state = SIDFX_RESET_0; channels[ch].state = SIDFX_RESET_0;
} }
else else
@ -154,6 +165,7 @@ inline void sidfx_loop_ch(byte ch)
channels[ch].com = nullptr; channels[ch].com = nullptr;
channels[ch].state = SIDFX_RESET_0; channels[ch].state = SIDFX_RESET_0;
} }
}
break; break;
} }
} }