***************************************************************************/
-//
+//
// From mame.txt (http://www.mame.net/readme.html)
-//
+//
// VI. Reuse of Source Code
// --------------------------
// This chapter might not apply to specific portions of MAME (e.g. CPU
// However, given the amount of time and energy it took to collect this
// information, if you find new information we would appreciate if you made it
// freely available as well.
-//
+//
// JLH: Commented out MAME specific crap
-#include <string.h> // for memset()
#include "ay8910.h"
+#include <string.h> // for memset()
#define MAX_OUTPUT 0x7FFF
unsigned char Regs[16];
int lastEnable;
unsigned int UpdateStep;
- int PeriodA,PeriodB,PeriodC,PeriodN,PeriodE;
- int CountA,CountB,CountC,CountN,CountE;
- unsigned int VolA,VolB,VolC,VolE;
- unsigned char EnvelopeA,EnvelopeB,EnvelopeC;
- unsigned char OutputA,OutputB,OutputC,OutputN;
+ int PeriodA, PeriodB, PeriodC, PeriodN, PeriodE;
+ int CountA, CountB, CountC, CountN, CountE;
+ unsigned int VolA, VolB, VolC, VolE;
+ unsigned char EnvelopeA, EnvelopeB, EnvelopeC;
+ unsigned char OutputA, OutputB, OutputC, OutputN;
signed char CountEnv;
- unsigned char Hold,Alternate,Attack,Holding;
+ unsigned char Hold, Alternate, Attack, Holding;
int RNG;
unsigned int VolTable[32];
};
old = PSG->PeriodA;
PSG->PeriodA = (PSG->Regs[AY_AFINE] + 256 * PSG->Regs[AY_ACOARSE]) * PSG->UpdateStep;
- if (PSG->PeriodA == 0) PSG->PeriodA = PSG->UpdateStep;
+ if (PSG->PeriodA == 0)
+ PSG->PeriodA = PSG->UpdateStep;
PSG->CountA += PSG->PeriodA - old;
- if (PSG->CountA <= 0) PSG->CountA = 1;
+ if (PSG->CountA <= 0)
+ PSG->CountA = 1;
break;
case AY_BFINE:
case AY_BCOARSE:
old = PSG->PeriodB;
PSG->PeriodB = (PSG->Regs[AY_BFINE] + 256 * PSG->Regs[AY_BCOARSE]) * PSG->UpdateStep;
- if (PSG->PeriodB == 0) PSG->PeriodB = PSG->UpdateStep;
+ if (PSG->PeriodB == 0)
+ PSG->PeriodB = PSG->UpdateStep;
PSG->CountB += PSG->PeriodB - old;
- if (PSG->CountB <= 0) PSG->CountB = 1;
+ if (PSG->CountB <= 0)
+ PSG->CountB = 1;
break;
case AY_CFINE:
case AY_CCOARSE:
old = PSG->PeriodC;
PSG->PeriodC = (PSG->Regs[AY_CFINE] + 256 * PSG->Regs[AY_CCOARSE]) * PSG->UpdateStep;
- if (PSG->PeriodC == 0) PSG->PeriodC = PSG->UpdateStep;
+ if (PSG->PeriodC == 0)
+ PSG->PeriodC = PSG->UpdateStep;
PSG->CountC += PSG->PeriodC - old;
- if (PSG->CountC <= 0) PSG->CountC = 1;
+ if (PSG->CountC <= 0)
+ PSG->CountC = 1;
break;
case AY_NOISEPER:
PSG->Regs[AY_NOISEPER] &= 0x1F;
old = PSG->PeriodN;
PSG->PeriodN = PSG->Regs[AY_NOISEPER] * PSG->UpdateStep;
- if (PSG->PeriodN == 0) PSG->PeriodN = PSG->UpdateStep;
+ if (PSG->PeriodN == 0)
+ PSG->PeriodN = PSG->UpdateStep;
PSG->CountN += PSG->PeriodN - old;
- if (PSG->CountN <= 0) PSG->CountN = 1;
+ if (PSG->CountN <= 0)
+ PSG->CountN = 1;
break;
case AY_ENABLE:
if ((PSG->lastEnable == -1) ||
old = PSG->PeriodE;
PSG->PeriodE = ((PSG->Regs[AY_EFINE] + 256 * PSG->Regs[AY_ECOARSE])) * PSG->UpdateStep;
- if (PSG->PeriodE == 0) PSG->PeriodE = PSG->UpdateStep / 2;
+ if (PSG->PeriodE == 0)
+ PSG->PeriodE = PSG->UpdateStep / 2;
PSG->CountE += PSG->PeriodE - old;
- if (PSG->CountE <= 0) PSG->CountE = 1;
+ if (PSG->CountE <= 0)
+ PSG->CountE = 1;
break;
case AY_ESHAPE:
/* envelope shapes:
PSG->Holding = 0;
PSG->VolE = PSG->VolTable[PSG->CountEnv ^ PSG->Attack];
- if (PSG->EnvelopeA) PSG->VolA = PSG->VolE;
- if (PSG->EnvelopeB) PSG->VolB = PSG->VolE;
- if (PSG->EnvelopeC) PSG->VolC = PSG->VolE;
+ if (PSG->EnvelopeA)
+ PSG->VolA = PSG->VolE;
+
+ if (PSG->EnvelopeB)
+ PSG->VolB = PSG->VolE;
+
+ if (PSG->EnvelopeC)
+ PSG->VolC = PSG->VolE;
break;
case AY_PORTA:
if (PSG->Regs[AY_ENABLE] & 0x40)
// /length/ is the number of samples we require
// NB. This should be called at twice the 6522 IRQ rate or (eg) 60Hz if no IRQ.
-void AY8910Update(int chip, int16 ** buffer, int length) // [TC: Removed static]
+void AY8910Update(int chip, int16_t ** buffer, int length) // [TC: Removed static]
{
struct AY8910 * PSG = &AYPSG[chip];
- INT16 * buf1, * buf2, * buf3;
+ int16_t * buf1, * buf2, * buf3;
int outn;
buf1 = buffer[0];
* If the volume is 0, increase the counter, but don't touch the output. */
if (PSG->Regs[AY_ENABLE] & 0x01)
{
- if (PSG->CountA <= length * STEP) PSG->CountA += length * STEP;
+ if (PSG->CountA <= length * STEP)
+ PSG->CountA += length * STEP;
+
PSG->OutputA = 1;
}
else if (PSG->Regs[AY_AVOL] == 0)
/* note that I do count += length, NOT count = length + 1. You might think *
* it's the same since the volume is 0, but doing the latter could cause *
* interferencies when the program is rapidly modulating the volume. */
- if (PSG->CountA <= length * STEP) PSG->CountA += length * STEP;
+ if (PSG->CountA <= length * STEP)
+ PSG->CountA += length * STEP;
}
if (PSG->Regs[AY_ENABLE] & 0x02)
{
- if (PSG->CountB <= length * STEP) PSG->CountB += length * STEP;
+ if (PSG->CountB <= length * STEP)
+ PSG->CountB += length * STEP;
+
PSG->OutputB = 1;
}
else if (PSG->Regs[AY_BVOL] == 0)
{
- if (PSG->CountB <= length * STEP) PSG->CountB += length * STEP;
+ if (PSG->CountB <= length * STEP)
+ PSG->CountB += length * STEP;
}
if (PSG->Regs[AY_ENABLE] & 0x04)
{
- if (PSG->CountC <= length * STEP) PSG->CountC += length * STEP;
+ if (PSG->CountC <= length * STEP)
+ PSG->CountC += length * STEP;
+
PSG->OutputC = 1;
}
else if (PSG->Regs[AY_CVOL] == 0)
{
- if (PSG->CountC <= length * STEP) PSG->CountC += length * STEP;
+ if (PSG->CountC <= length * STEP)
+ PSG->CountC += length * STEP;
}
/* for the noise channel we must not touch OutputN - it's also not necessary *
* since we use outn. */
if ((PSG->Regs[AY_ENABLE] & 0x38) == 0x38) /* all off */
- if (PSG->CountN <= length * STEP) PSG->CountN += length * STEP;
+ if (PSG->CountN <= length * STEP)
+ PSG->CountN += length * STEP;
outn = (PSG->OutputN | PSG->Regs[AY_ENABLE]);
{
int nextevent;
- if (PSG->CountN < left) nextevent = PSG->CountN;
- else nextevent = left;
+ if (PSG->CountN < left)
+ nextevent = PSG->CountN;
+ else
+ nextevent = left;
if (outn & 0x08)
{
- if (PSG->OutputA) vola += PSG->CountA;
+ if (PSG->OutputA)
+ vola += PSG->CountA;
PSG->CountA -= nextevent;
/* PeriodA is the half period of the square wave. Here, in each *
{
PSG->OutputA ^= 1;
- if (PSG->OutputA) vola += PSG->PeriodA;
+ if (PSG->OutputA)
+ vola += PSG->PeriodA;
break;
}
vola += PSG->PeriodA;
}
- if (PSG->OutputA) vola -= PSG->CountA;
+ if (PSG->OutputA)
+ vola -= PSG->CountA;
}
else
{
if (outn & 0x10)
{
- if (PSG->OutputB) volb += PSG->CountB;
+ if (PSG->OutputB)
+ volb += PSG->CountB;
PSG->CountB -= nextevent;
{
PSG->OutputB ^= 1;
- if (PSG->OutputB) volb += PSG->PeriodB;
+ if (PSG->OutputB)
+ volb += PSG->PeriodB;
break;
}
volb += PSG->PeriodB;
}
- if (PSG->OutputB) volb -= PSG->CountB;
+ if (PSG->OutputB)
+ volb -= PSG->CountB;
}
else
{
if (outn & 0x20)
{
- if (PSG->OutputC) volc += PSG->CountC;
+ if (PSG->OutputC)
+ volc += PSG->CountC;
PSG->CountC -= nextevent;
{
PSG->OutputC ^= 1;
- if (PSG->OutputC) volc += PSG->PeriodC;
+ if (PSG->OutputC)
+ volc += PSG->PeriodC;
break;
}
volc += PSG->PeriodC;
}
- if (PSG->OutputC) volc -= PSG->CountC;
+ if (PSG->OutputC)
+ volc -= PSG->CountC;
}
else
{
PSG->VolE = PSG->VolTable[PSG->CountEnv ^ PSG->Attack];
/* reload volume */
- if (PSG->EnvelopeA) PSG->VolA = PSG->VolE;
- if (PSG->EnvelopeB) PSG->VolB = PSG->VolE;
- if (PSG->EnvelopeC) PSG->VolC = PSG->VolE;
+ if (PSG->EnvelopeA)
+ PSG->VolA = PSG->VolE;
+
+ if (PSG->EnvelopeB)
+ PSG->VolB = PSG->VolE;
+
+ if (PSG->EnvelopeC)
+ PSG->VolC = PSG->VolE;
}
}
AY8910_set_clock(chip, clock);
}
-uint8 * AY8910_GetRegsPtr(uint16 chipNum)
+uint8_t * AY8910_GetRegsPtr(uint16_t chipNum)
{
if (chipNum >= MAX_8910)
return NULL;