From: notaz Date: Sat, 30 Sep 2017 15:14:20 +0000 (+0300) Subject: sn76496: simplify writes X-Git-Tag: v1.92~20 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5103774f6de1cd757dcff2fbfe9a2ac845143dd7;p=picodrive.git sn76496: simplify writes --- diff --git a/pico/sound/sn76496.c b/pico/sound/sn76496.c index 8474c703..b2127594 100644 --- a/pico/sound/sn76496.c +++ b/pico/sound/sn76496.c @@ -73,96 +73,54 @@ int *sn76496_regs; void SN76496Write(int data) { struct SN76496 *R = &ono_sn; - int n; - + int n, r, c; /* update the output buffer before changing the registers */ //stream_update(R->Channel,0); + r = R->LastRegister; if (data & 0x80) - { - int r = (data & 0x70) >> 4; - int c = r/2; + r = R->LastRegister = (data & 0x70) >> 4; + c = r / 2; - R->LastRegister = r; - R->Register[r] = (R->Register[r] & 0x3f0) | (data & 0x0f); - switch (r) - { - case 0: /* tone 0 : frequency */ - case 2: /* tone 1 : frequency */ - case 4: /* tone 2 : frequency */ - R->Period[c] = R->UpdateStep * R->Register[r]; - if (R->Period[c] == 0) R->Period[c] = R->UpdateStep; - if (r == 4) - { - /* update noise shift frequency */ - if ((R->Register[6] & 0x03) == 0x03) - R->Period[3] = 2 * R->Period[2]; - } - break; - case 1: /* tone 0 : volume */ - case 3: /* tone 1 : volume */ - case 5: /* tone 2 : volume */ - case 7: /* noise : volume */ - R->Volume[c] = R->VolTable[data & 0x0f]; - break; - case 6: /* noise : frequency, mode */ - { - int n = R->Register[6]; - R->NoiseFB = (n & 4) ? FB_WNOISE : FB_PNOISE; - n &= 3; - /* N/512,N/1024,N/2048,Tone #3 output */ - R->Period[3] = ((n&3) == 3) ? 2 * R->Period[2] : (R->UpdateStep << (5+(n&3))); - - /* reset noise shifter */ - R->RNG = NG_PRESET; - R->Output[3] = R->RNG & 1; - } - break; - } - } + if (!(data & 0x80) && (r == 0 || r == 2 || r == 4)) + // data byte (tone only) + R->Register[r] = (R->Register[r] & 0x0f) | ((data & 0x3f) << 4); else - { - int r = R->LastRegister; - int c = r/2; + R->Register[r] = (R->Register[r] & 0x3f0) | (data & 0x0f); - switch (r) - { - case 0: /* tone 0 : frequency */ - case 2: /* tone 1 : frequency */ - case 4: /* tone 2 : frequency */ - R->Register[r] = (R->Register[r] & 0x0f) | ((data & 0x3f) << 4); - R->Period[c] = R->UpdateStep * R->Register[r]; - if (R->Period[c] == 0) R->Period[c] = R->UpdateStep; - if (r == 4) - { - /* update noise shift frequency */ - if ((R->Register[6] & 0x03) == 0x03) - R->Period[3] = 2 * R->Period[2]; - } - break; - case 1: /* tone 0 : volume */ - case 3: /* tone 1 : volume */ - case 5: /* tone 2 : volume */ - case 7: /* noise : volume */ - R->Volume[c] = R->VolTable[data & 0x0f]; - R->Register[r] = (R->Register[r] & 0x3f0) | (data & 0x0f); - break; - case 6: /* noise : frequency, mode */ - { - R->Register[r] = (R->Register[r] & 0x3f0) | (data & 0x0f); - n = R->Register[6]; - R->NoiseFB = (n & 4) ? FB_WNOISE : FB_PNOISE; - n &= 3; - /* N/512,N/1024,N/2048,Tone #3 output */ - R->Period[3] = ((n&3) == 3) ? 2 * R->Period[2] : (R->UpdateStep << (5+(n&3))); - - /* reset noise shifter */ - R->RNG = NG_PRESET; - R->Output[3] = R->RNG & 1; - } - break; - } + data = R->Register[r]; + switch (r) + { + case 0: /* tone 0 : frequency */ + case 2: /* tone 1 : frequency */ + case 4: /* tone 2 : frequency */ + R->Period[c] = R->UpdateStep * data; + if (R->Period[c] == 0) R->Period[c] = R->UpdateStep; + if (r == 4) + { + /* update noise shift frequency */ + if ((R->Register[6] & 0x03) == 0x03) + R->Period[3] = 2 * R->Period[2]; + } + break; + case 1: /* tone 0 : volume */ + case 3: /* tone 1 : volume */ + case 5: /* tone 2 : volume */ + case 7: /* noise : volume */ + R->Volume[c] = R->VolTable[data & 0x0f]; + break; + case 6: /* noise : frequency, mode */ + n = data; + R->NoiseFB = (n & 4) ? FB_WNOISE : FB_PNOISE; + n &= 3; + /* N/512,N/1024,N/2048,Tone #3 output */ + R->Period[3] = (n == 3) ? 2 * R->Period[2] : (R->UpdateStep << (5 + n)); + + /* reset noise shifter */ + R->RNG = NG_PRESET; + R->Output[3] = R->RNG & 1; + break; } }