.fixed broken PSG noise frequency

.improved accuracy Game Gear PSG stereo (cycle-accurate)
This commit is contained in:
EkeEke 2012-10-15 10:40:39 +02:00
parent c830a70872
commit 54687cde58
5 changed files with 39 additions and 29 deletions

View File

@ -547,7 +547,7 @@ void io_gg_write(unsigned int offset, unsigned int data)
case 6: /* PSG Stereo output control */
io_reg[6] = data;
SN76489_Config(config.psg_preamp, config.psgBoostNoise, data);
SN76489_Config(Z80.cycles, config.psg_preamp, config.psgBoostNoise, data);
return;
default: /* Read-only */

View File

@ -157,29 +157,6 @@ void SN76489_Reset()
SN76489.clocks = 0;
}
void SN76489_Config(int preAmp, int boostNoise, int stereo)
{
int i;
for (i=0; i<4; i++)
{
/* stereo channel pre-amplification */
SN76489.PreAmp[i][0] = preAmp * ((stereo >> (i*2)) & 1);
SN76489.PreAmp[i][1] = preAmp * ((stereo >> (i*2 + 1)) & 1);
/* noise channel boost */
if (i == 3)
{
SN76489.PreAmp[3][0] = SN76489.PreAmp[3][0] << boostNoise;
SN76489.PreAmp[3][1] = SN76489.PreAmp[3][1] << boostNoise;
}
/* update stereo channel amplitude */
SN76489.Channel[i][0]= (PSGVolumeValues[SN76489.Registers[i*2 + 1]] * SN76489.PreAmp[i][0]) / 100;
SN76489.Channel[i][1]= (PSGVolumeValues[SN76489.Registers[i*2 + 1]] * SN76489.PreAmp[i][1]) / 100;
}
}
void *SN76489_GetContextPtr(void)
{
return (uint8 *)&SN76489;
@ -331,6 +308,39 @@ static void SN76489_RunUntil(unsigned int clocks)
}
}
void SN76489_Config(unsigned int clocks, int preAmp, int boostNoise, int stereo)
{
int i;
/* cycle-accurate Game Gear stereo */
if (clocks > SN76489.clocks)
{
/* Run chip until current timestamp */
SN76489_RunUntil(clocks);
/* Update internal M-cycle counter */
SN76489.clocks += ((clocks - SN76489.clocks + PSG_MCYCLES_RATIO - 1) / PSG_MCYCLES_RATIO) * PSG_MCYCLES_RATIO;
}
for (i=0; i<4; i++)
{
/* stereo channel pre-amplification */
SN76489.PreAmp[i][0] = preAmp * ((stereo >> (i*2)) & 1);
SN76489.PreAmp[i][1] = preAmp * ((stereo >> (i*2 + 1)) & 1);
/* noise channel boost */
if (i == 3)
{
SN76489.PreAmp[3][0] = SN76489.PreAmp[3][0] << boostNoise;
SN76489.PreAmp[3][1] = SN76489.PreAmp[3][1] << boostNoise;
}
/* update stereo channel amplitude */
SN76489.Channel[i][0]= (PSGVolumeValues[SN76489.Registers[i*2 + 1]] * SN76489.PreAmp[i][0]) / 100;
SN76489.Channel[i][1]= (PSGVolumeValues[SN76489.Registers[i*2 + 1]] * SN76489.PreAmp[i][1]) / 100;
}
}
void SN76489_Update(unsigned int clocks)
{
int i;
@ -424,7 +434,7 @@ void SN76489_Write(unsigned int clocks, unsigned int data)
SN76489.NoiseShiftRegister = NoiseInitialState;
/* set noise signal generator frequency */
SN76489.NoiseFreq = (0x10 << (data&0x3)) * PSG_MCYCLES_RATIO;
SN76489.NoiseFreq = 0x10 << (data&0x3);
break;
}

View File

@ -14,7 +14,7 @@
/* Function prototypes */
extern void SN76489_Init(blip_t* left, blip_t* right, int type);
extern void SN76489_Reset(void);
extern void SN76489_Config(int preAmp, int boostNoise, int stereo);
extern void SN76489_Config(unsigned int clocks, int preAmp, int boostNoise, int stereo);
extern void SN76489_Write(unsigned int clocks, unsigned int data);
extern void SN76489_Update(unsigned int cycles);
extern void *SN76489_GetContextPtr(void);

View File

@ -102,7 +102,7 @@ void sound_init( void )
}
/* Initialize PSG chip */
SN76489_Config(config.psg_preamp, config.psgBoostNoise, 0xff);
SN76489_Config(0, config.psg_preamp, config.psgBoostNoise, 0xff);
}
void sound_reset(void)

View File

@ -117,12 +117,12 @@ int state_load(unsigned char *state)
if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
{
SN76489_Init(snd.blips[0][0], snd.blips[0][1], SN_INTEGRATED);
SN76489_Config(config.psg_preamp, config.psgBoostNoise, 0xff);
SN76489_Config(0, config.psg_preamp, config.psgBoostNoise, 0xff);
}
else
{
SN76489_Init(snd.blips[0][0], snd.blips[0][1], (system_hw < SYSTEM_MARKIII) ? SN_DISCRETE : SN_INTEGRATED);
SN76489_Config(config.psg_preamp, config.psgBoostNoise, io_reg[6]);
SN76489_Config(0, config.psg_preamp, config.psgBoostNoise, io_reg[6]);
}
/* 68000 */