From 2ae14b75de84c27736aec633d12c0d31f0d78e6b Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Sun, 25 Oct 2020 13:58:06 +0800 Subject: [PATCH] APU: Move duty cycle swapping during apu writes --- src/sound.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sound.c b/src/sound.c index 40973c2..a3f331b 100644 --- a/src/sound.c +++ b/src/sound.c @@ -195,6 +195,8 @@ static DECLFW(Write_PSG) { DoSQ1(); EnvUnits[0].Mode = (V & 0x30) >> 4; EnvUnits[0].Speed = (V & 0xF); + if (swapDuty) + V = (V & 0x3F) | ((V & 0x80) >> 1) | ((V & 0x40) << 1); break; case 0x1: DoSQ1(); @@ -214,6 +216,8 @@ static DECLFW(Write_PSG) { DoSQ2(); EnvUnits[1].Mode = (V & 0x30) >> 4; EnvUnits[1].Speed = (V & 0xF); + if (swapDuty) + V = (V & 0x3F) | ((V & 0x80) >> 1) | ((V & 0x40) << 1); break; case 0x5: DoSQ2(); @@ -561,8 +565,6 @@ static INLINE void RDoSQ(int x) { amp <<= 24; dutyCycle = (PSG[(x << 2)] & 0xC0) >> 6; - if (swapDuty) - dutyCycle = ((dutyCycle & 2) >> 1) | ((dutyCycle & 1) << 1); rthresh = RectDuties[dutyCycle]; currdc = RectDutyCount[x]; D = &WaveHi[ChannelBC[x]]; @@ -640,8 +642,6 @@ static void RDoSQLQ(void) { if (!inie[x]) amp[x] = 0; /* Correct? Buzzing in MM2, others otherwise... */ dutyCycle = (PSG[(x << 2)] & 0xC0) >> 6; - if (swapDuty) - dutyCycle = ((dutyCycle & 2) >> 1) | ((dutyCycle & 1) << 1); rthresh[x] = RectDuties[dutyCycle]; for (y = 0; y < 8; y++) {