2151intf.c
2203intf.c
2608intf.c
2c2
< //#define YM2608_USE_SAMPLES
---
> /*#define YM2608_USE_SAMPLES */
62c62
< //	if(errorlog) fprintf(errorlog,"2608 TimerOver %d\n",c);
---
> /*	if(errorlog) fprintf(errorlog,"2608 TimerOver %d\n",c); */
74c74
< //			if(errorlog) fprintf(errorlog,"2608 TimerReset %d\n",c);
---
> /*			if(errorlog) fprintf(errorlog,"2608 TimerReset %d\n",c); */
241c241
< //if(errorlog) fprintf(errorlog,"PC %04x: 2608 S0A=%02X\n",cpu_get_pc(),YM2608Read(0,0));
---
> /*if(errorlog) fprintf(errorlog,"PC %04x: 2608 S0A=%02X\n",cpu_get_pc(),YM2608Read(0,0)); */
247c247
< //if(errorlog) fprintf(errorlog,"PC %04x: 2608 S0B=%02X\n",cpu_get_pc(),YM2608Read(0,2));
---
> /*if(errorlog) fprintf(errorlog,"PC %04x: 2608 S0B=%02X\n",cpu_get_pc(),YM2608Read(0,2)); */
2610intf.c
44c44
< //	if(errorlog) fprintf(errorlog,"2610 TimerOver %d\n",c);
---
> /*	if(errorlog) fprintf(errorlog,"2610 TimerOver %d\n",c); */
56c56
< //			if(errorlog) fprintf(errorlog,"2610 TimerReset %d\n",c);
---
> /*			if(errorlog) fprintf(errorlog,"2610 TimerReset %d\n",c); */
220c220
< //if(errorlog) fprintf(errorlog,"PC %04x: 2610 S0A=%02X\n",cpu_get_pc(),YM2610Read(0,0));
---
> /*if(errorlog) fprintf(errorlog,"PC %04x: 2610 S0A=%02X\n",cpu_get_pc(),YM2610Read(0,0)); */
226c226
< //if(errorlog) fprintf(errorlog,"PC %04x: 2610 S0B=%02X\n",cpu_get_pc(),YM2610Read(0,2));
---
> /*if(errorlog) fprintf(errorlog,"PC %04x: 2610 S0B=%02X\n",cpu_get_pc(),YM2610Read(0,2)); */
261c261
< //if(errorlog) fprintf(errorlog,"PC %04x: 2610 Reg A %02X",cpu_get_pc(),data);
---
> /*if(errorlog) fprintf(errorlog,"PC %04x: 2610 Reg A %02X",cpu_get_pc(),data); */
267c267
< //if(errorlog) fprintf(errorlog,"PC %04x: 2610 Reg B %02X",cpu_get_pc(),data);
---
> /*if(errorlog) fprintf(errorlog,"PC %04x: 2610 Reg B %02X",cpu_get_pc(),data); */
289c289
< //if(errorlog) fprintf(errorlog," =%02X\n",data);
---
> /*if(errorlog) fprintf(errorlog," =%02X\n",data); */
295c295
< //if(errorlog) fprintf(errorlog," =%02X\n",data);
---
> /*if(errorlog) fprintf(errorlog," =%02X\n",data); */
2612intf.c
46c46
< //	if(errorlog) fprintf(errorlog,"2612 TimerOver %d\n",c);
---
> /*	if(errorlog) fprintf(errorlog,"2612 TimerOver %d\n",c); */
59c59
< //			if(errorlog) fprintf(errorlog,"2612 TimerReset %d\n",c);
---
> /*			if(errorlog) fprintf(errorlog,"2612 TimerReset %d\n",c); */
77c77
< //			if(errorlog) fprintf(errorlog,"2612 TimerSet %d %f slack %f\n",c,timeSec,slack);
---
> /*			if(errorlog) fprintf(errorlog,"2612 TimerSet %d %f slack %f\n",c,timeSec,slack); */
3812intf.c
38c38
< 	int aOPLFreqArray[16];		// Up to 9 channels..
---
> 	int aOPLFreqArray[16];		/* Up to 9 channels.. */
319c319
< 		//stream[i] = stream_init(name,vol,rate,FM_OUTPUT_BIT,i,UpdateHandler);
---
> 		/*stream[i] = stream_init(name,vol,rate,FM_OUTPUT_BIT,i,UpdateHandler); */
414c414
< 	// The ym3812 supports several ym chips, update the interface if you want to use this feature!!!
---
> 	/* The ym3812 supports several ym chips, update the interface if you want to use this feature!!! */
483c483
< 	stream_update( stream[chip], 0 );	// Update the buffer before writing new regs
---
> 	stream_update( stream[chip], 0 );	/* Update the buffer before writing new regs */
5220intf.c
adpcm.c
772,774c772,774
< //		base = &Machine->memory_region[okim6295_interface->region[num]][okim6295_base[num] + okim6295_command[num] * 8];
< //		start = (base[0] << 16) + (base[1] << 8) + base[2];
< //		stop = (base[3] << 16) + (base[4] << 8) + base[5];
---
> /*		base = &Machine->memory_region[okim6295_interface->region[num]][okim6295_base[num] + okim6295_command[num] * 8]; */
> /*		start = (base[0] << 16) + (base[1] << 8) + base[2]; */
> /*		stop = (base[3] << 16) + (base[4] << 8) + base[5]; */
777c777
< //		buffer_end = cpu_scalebyfcount (buffer_len);
---
> /*		buffer_end = cpu_scalebyfcount (buffer_len); */
astrocde.c
ay8910.c
ay8910u.c
cem3394.c
cvsd.c
dac.c
fm.c
1635c1635
< //#define ADPCMA_DECODE_RANGE 1024
---
> /*#define ADPCMA_DECODE_RANGE 1024 */
1850c1850
< //#define CUT_RE_SAMPLING
---
> /*#define CUT_RE_SAMPLING */
1866c1866
< 	//*(ch->pan) += ch->adpcml;
---
> 	/**(ch->pan) += ch->adpcml; */
1895c1895
< 		if(F2610->pcmbuf[1]==NULL){			// Check ROM Mapped
---
> 		if(F2610->pcmbuf[1]==NULL){			/* Check ROM Mapped */
1903c1903
< 		  if(adpcm[c].end >= F2610->pcm_size[1]){		// Check End in Range
---
> 		  if(adpcm[c].end >= F2610->pcm_size[1]){		/* Check End in Range */
1909c1909
< 		  if(adpcm[c].start >= F2610->pcm_size[1]){	// Check Start in Range
---
> 		  if(adpcm[c].start >= F2610->pcm_size[1]){	/* Check Start in Range */
1988c1988
< 	    if(F2610->pcmbuf[0] == NULL){			// Check ROM Mapped
---
> 	    if(F2610->pcmbuf[0] == NULL){			/* Check ROM Mapped */
1995c1995
< 	      if( adpcm->end >= F2610->pcm_size[0] ){		// Check End in Range
---
> 	      if( adpcm->end >= F2610->pcm_size[0] ){		/* Check End in Range */
2001c2001
< 	      if( adpcm->start >= F2610->pcm_size[0] ){		// Check Start in Range
---
> 	      if( adpcm->start >= F2610->pcm_size[0] ){		/* Check Start in Range */
2320c2320
< 	//OPN->type &= (~TYPE_6CH);
---
> 	/*OPN->type &= (~TYPE_6CH); */
2359c2359
< 	//F2608->port1state = 0;
---
> 	/*F2608->port1state = 0; */
2439,2440c2439,2440
< 				//F2608->ADLimit = (F2608->ADLimit & 0xff00) | v;
< 				//break;
---
> 				/*F2608->ADLimit = (F2608->ADLimit & 0xff00) | v; */
> 				/*break; */
2442,2443c2442,2443
< 				//F2608->ADLimit = (F2608->ADLimit & 0x00ff) | (v<<8);
< 				//break;
---
> 				/*F2608->ADLimit = (F2608->ADLimit & 0x00ff) | (v<<8); */
> 				/*break; */
2445c2445
< 				//break;
---
> 				/*break; */
2447,2448c2447,2448
< 				//F2608->ADData = v;
< 				//FM_STATUS_RESET(F2608->OPN.ST,0x08);
---
> 				/*F2608->ADData = v; */
> 				/*FM_STATUS_RESET(F2608->OPN.ST,0x08); */
2539c2539
< //static YM2610 *FM2610=NULL;	/* array of YM2610's */
---
> /*static YM2610 *FM2610=NULL;	   array of YM2610's    */
2556c2556
< 		//cch[0] = &F2610->CH[0];
---
> 		/*cch[0] = &F2610->CH[0]; */
2559c2559
< 		//cch[3] = &F2610->CH[3];
---
> 		/*cch[3] = &F2610->CH[3]; */
2580c2580
< 	//CALC_FCOUNT( cch[0] );
---
> 	/*CALC_FCOUNT( cch[0] ); */
2592c2592
< 	//CALC_FCOUNT( cch[3] );
---
> 	/*CALC_FCOUNT( cch[3] ); */
2605c2605
< 		//FM_CALC_CH( cch[0] );
---
> 		/*FM_CALC_CH( cch[0] ); */
2608c2608
< 		//FM_CALC_CH( cch[3] );
---
> 		/*FM_CALC_CH( cch[3] ); */
2859c2859
< 	//F2610->port1state = 0;
---
> 	/*F2610->port1state = 0; */
2955,2956c2955,2956
< 	  //PrintDebug( "YM2610Status2 %02x\n", ret );
< 	  //PrintIngame(120,"YM2610Status2 %02x", ret );
---
> 	  /*PrintDebug( "YM2610Status2 %02x\n", ret ); */
> 	  /*PrintIngame(120,"YM2610Status2 %02x", ret ); */
fmext.c
fmopl.c
291c291
< 			//SLOT->evc = (ENV_CURVE[SLOT->evc>>ENV_BITS]<<ENV_BITS) + EG_DST;
---
> 			/*SLOT->evc = (ENV_CURVE[SLOT->evc>>ENV_BITS]<<ENV_BITS) + EG_DST; */
523,526c523,526
< 	// SD  (17) = mul14[fnum7] + white noise
< 	// TAM (15) = mul15[fnum8]
< 	// TOP (18) = fnum6(mul18[fnum8]+whitenoise)
< 	// HH  (14) = fnum7(mul18[fnum8]+whitenoise) + white noise
---
> 	/* SD  (17) = mul14[fnum7] + white noise */
> 	/* TAM (15) = mul15[fnum8] */
> 	/* TOP (18) = fnum6(mul18[fnum8]+whitenoise) */
> 	/* HH  (14) = fnum7(mul18[fnum8]+whitenoise) + white noise */
k007232.c
420c420
< static int  K007232_ReadReg( int r, int chip )
---
> static int K007232_ReadReg( int r, int chip )
k053260.c
161c161
< 						if ( pos[i] & 0x8000 )
---
> 							if ( pos[i] & 0x8000 )
163c163
< 						else
---
> 							else
272c272
< 						if ( pos[i] & 0x8000 )
---
> 								if ( pos[i] & 0x8000 )
274c274
< 						else
---
> 								else
mixer.c
177c177
< { if (len)	puts("mixer_play_sample() - nonzero len");
---
> {
182c182
< { if (len)	puts("mixer_play_sample_16() - nonzero len");
---
> {
187c187
< { if (len)	puts("mixer_play_streamed_sample() - nonzero len");
---
> {
193c193
< { if (len)	puts("mixer_play_streamed_sample_16() - nonzero len");
---
> {
msm5205.c
namco.c
1,505c1,505
< /***************************************************************************
< 
< 	NAMCO sound driver.
< 
< 	This driver handles the three known types of NAMCO wavetable sounds:
< 
< 		- 3-voice mono (Pac-Man, Pengo, Dig Dug, etc)
< 		- 8-voice mono (Mappy, Dig Dug 2, etc)
< 		- 8-voice stereo (System 1)
< 
< ***************************************************************************/
< 
< #include "driver.h"
< 
< /* note: we work with signed samples here, unlike other drivers */
< #define AUDIO_CONV(A) (A)
< 
< /* 8 voices max */
< #define MAX_VOICES 8
< 
< 
< /* this structure defines the parameters for a channel */
< typedef struct
< {
< 	int frequency;
< 	int counter;
< 	int volume[2];
< 	const unsigned char *wave;
< } sound_channel;
< 
< 
< /* globals available to everyone */
< unsigned char *namco_soundregs;
< unsigned char *namco_wavedata;
< 
< /* data about the sound system */
< static sound_channel channel_list[MAX_VOICES];
< static sound_channel *last_channel;
< 
< /* global sound parameters */
< static const unsigned char *sound_prom;
< static int samples_per_byte;
< static int sample_bits;
< static int num_voices;
< static int sound_enable;
< static int stream;
< 
< /* mixer tables and internal buffers */
< static signed char *mixer_table;
< static signed char *mixer_lookup;
< static short *mixer_buffer;
< static short *mixer_buffer_2;
< 
< 
< 
< /* build a table to divide by the number of voices */
< static int make_mixer_table(int voices, int bits)
< {
< 	int count = voices * 128;
< 	int i;
< 	int gain = 16;
< 
< 
< 	/* allocate memory */
< 	mixer_table = malloc(256 * voices * bits / 8);
< 	if (!mixer_table)
< 		return 1;
< 
< 	/* find the middle of the table */
< 	mixer_lookup = mixer_table + (128 * voices * bits / 8);
< 
< 	/* fill in the table - 8 bit case */
< 	if (bits == 8)
< 	{
< 		for (i = 0; i < count; i++)
< 		{
< 			int val = i * gain / (voices * 16);
< 			if (val > 127) val = 127;
< 			mixer_lookup[ i] = AUDIO_CONV(val);
< 			mixer_lookup[-i] = AUDIO_CONV(-val);
< 		}
< 	}
< 
< 	/* fill in the table - 16 bit case */
< 	else
< 	{
< 		for (i = 0; i < count; i++)
< 		{
< 			int val = i * gain * 16 / voices;
< 			if (val > 32767) val = 32767;
< 			((short *)mixer_lookup)[ i] = val;
< 			((short *)mixer_lookup)[-i] = -val;
< 		}
< 	}
< 
< 	return 0;
< }
< 
< 
< /* generate sound to the mix buffer in mono */
< static void namco_update_mono(int ch, void *buffer, int length)
< {
< 	sound_channel *voice;
< 	short *mix;
< 	int i;
< 
< 	/* if no sound, we're done */
< 	if (sound_enable == 0)
< 	{
< 		if (sample_bits == 16)
< 			memset(buffer, 0, length * 2);
< 		else
< 			memset(buffer, AUDIO_CONV(0x00), length);
< 		return;
< 	}
< 
< 	/* zap the contents of the mixer buffer */
< 	memset(mixer_buffer, 0, length * sizeof(short));
< 
< 	/* loop over each voice and add its contribution */
< 	for (voice = channel_list; voice < last_channel; voice++)
< 	{
< 		int f = voice->frequency;
< 		int v = voice->volume[0];
< 
< 		/* only update if we have non-zero volume and frequency */
< 		if (v && f)
< 		{
< 			const unsigned char *w = voice->wave;
< 			int c = voice->counter;
< 
< 			mix = mixer_buffer;
< 
< 			/* add our contribution */
< 			for (i = 0; i < length; i++)
< 			{
< 				int offs;
< 
< 				c += f;
< 				offs = (c >> 15) & 0x1f;
< 				if (samples_per_byte == 1)	/* use only low 4 bits */
< 					*mix++ += ((w[offs] & 0x0f) - 8) * v;
< 				else	/* use full byte, first the high 4 bits, then the low 4 bits */
< 				{
< 					if (offs & 1)
< 						*mix++ += ((w[offs>>1] & 0x0f) - 8) * v;
< 					else
< 						*mix++ += (((w[offs>>1]>>4) & 0x0f) - 8) * v;
< 				}
< 			}
< 
< 			/* update the counter for this voice */
< 			voice->counter = c;
< 		}
< 	}
< 
< 	/* mix it down */
< 	mix = mixer_buffer;
< 	if (sample_bits == 16)
< 	{
< 		short *dest = buffer;
< 		for (i = 0; i < length; i++)
< 			*dest++ = ((short *)mixer_lookup)[*mix++];
< 	}
< 	else
< 	{
< 		unsigned char *dest = buffer;
< 		for (i = 0; i < length; i++)
< 			*dest++ = mixer_lookup[*mix++];
< 	}
< }
< 
< 
< /* generate sound to the mix buffer in stereo */
< static void namco_update_stereo(int ch, void **buffer, int length)
< {
< 	sound_channel *voice;
< 	short *lmix, *rmix;
< 	int i;
< 
< 	/* if no sound, we're done */
< 	if (sound_enable == 0)
< 	{
< 		if (sample_bits == 16)
< 		{
< 			memset(buffer[0], 0, length * 2);
< 			memset(buffer[1], 0, length * 2);
< 		}
< 		else
< 		{
< 			memset(buffer[0], AUDIO_CONV(0x00), length);
< 			memset(buffer[1], AUDIO_CONV(0x00), length);
< 		}
< 		return;
< 	}
< 
< 	/* zap the contents of the mixer buffer */
< 	memset(mixer_buffer, 0, length * sizeof(short));
< 	memset(mixer_buffer_2, 0, length * sizeof(short));
< 
< 	/* loop over each voice and add its contribution */
< 	for (voice = channel_list; voice < last_channel; voice++)
< 	{
< 		int f = voice->frequency;
< 		int lv = voice->volume[0];
< 		int rv = voice->volume[1];
< 
< 		/* only update if we have non-zero volume and frequency */
< 		if ((lv || rv) && f)
< 		{
< 			const unsigned char *w = voice->wave;
< 			int c = voice->counter;
< 
< 			lmix = mixer_buffer;
< 			rmix = mixer_buffer_2;
< 
< 			/* add our contribution */
< 			for (i = 0; i < length; i++)
< 			{
< 				int offs;
< 
< 				c += f;
< 				offs = (c >> 15) & 0x1f;
< 				if (samples_per_byte == 1)	/* use only low 4 bits */
< 				{
< 					*lmix++ += ((w[offs] & 0x0f) - 8) * lv;
< 					*rmix++ += ((w[offs] & 0x0f) - 8) * rv;
< 				}
< 				else	/* use full byte, first the high 4 bits, then the low 4 bits */
< 				{
< 					if (offs & 1)
< 					{
< 						*lmix++ += ((w[offs>>1] & 0x0f) - 8) * lv;
< 						*rmix++ += ((w[offs>>1] & 0x0f) - 8) * rv;
< 					}
< 					else
< 					{
< 						*lmix++ += (((w[offs>>1]>>4) & 0x0f) - 8) * lv;
< 						*rmix++ += (((w[offs>>1]>>4) & 0x0f) - 8) * rv;
< 					}
< 				}
< 			}
< 
< 			/* update the counter for this voice */
< 			voice->counter = c;
< 		}
< 	}
< 
< 	/* mix it down */
< 	lmix = mixer_buffer;
< 	rmix = mixer_buffer_2;
< 	if (sample_bits == 16)
< 	{
< 		short *dest1 = buffer[0];
< 		short *dest2 = buffer[1];
< 		for (i = 0; i < length; i++)
< 		{
< 			*dest1++ = ((short *)mixer_lookup)[*lmix++];
< 			*dest2++ = ((short *)mixer_lookup)[*rmix++];
< 		}
< 	}
< 	else
< 	{
< 		unsigned char *dest1 = buffer[0];
< 		unsigned char *dest2 = buffer[1];
< 		for (i = 0; i < length; i++)
< 		{
< 			*dest1++ = mixer_lookup[*lmix++];
< 			*dest2++ = mixer_lookup[*rmix++];
< 		}
< 	}
< }
< 
< 
< int namco_sh_start(const struct MachineSound *msound)
< {
< 	const char *mono_name = "NAMCO sound";
< 	const char *stereo_names[] =
< 	{
< 		"NAMCO sound left",
< 		"NAMCO sound right"
< 	};
< 	sound_channel *voice;
< 	const struct namco_interface *intf = msound->sound_interface;
< 
< 
< 	/* get stream channels */
< 	sample_bits = Machine->sample_bits;
< 	if (intf->stereo)
< 	{
< 		int vol[2];
< 
< 		vol[0] = MIXER(intf->volume,MIXER_PAN_LEFT);
< 		vol[1] = MIXER(intf->volume,MIXER_PAN_RIGHT);
< 		stream = stream_init_multi(2, stereo_names, vol, intf->samplerate, sample_bits, 0, namco_update_stereo);
< 	}
< 	else
< 	{
< 		stream = stream_init(mono_name, intf->volume, intf->samplerate, sample_bits, 0, namco_update_mono);
< 	}
< 
< 	/* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */
< 	if ((mixer_buffer = malloc(2 * sizeof(short) * intf->samplerate)) == 0)
< 		return 1;
< 	mixer_buffer_2 = mixer_buffer + intf->samplerate;
< 
< 	/* build the mixer table */
< 	if (make_mixer_table(intf->voices, Machine->sample_bits))
< 	{
< 		free (mixer_buffer);
< 		return 1;
< 	}
< 
< 	/* extract globals from the interface */
< 	num_voices = intf->voices;
< 	last_channel = channel_list + num_voices;
< 
< 	if (intf->region == -1)
< 	{
< 		sound_prom = namco_wavedata;
< 		samples_per_byte = 2;	/* first 4 high bits, then low 4 bits */
< 	}
< 	else
< 	{
< 		sound_prom = Machine->memory_region[intf->region];
< 		samples_per_byte = 1;	/* use only low 4 bits */
< 	}
< 
< 	/* start with sound enabled, many games don't have a sound enable register */
< 	sound_enable = 1;
< 
< 	/* reset all the voices */
< 	for (voice = channel_list; voice < last_channel; voice++)
< 	{
< 		voice->frequency = 0;
< 		voice->volume[0] = voice->volume[1] = 0;
< 		voice->wave = &sound_prom[0];
< 		voice->counter = 0;
< 	}
< 
< 	return 0;
< }
< 
< 
< void namco_sh_stop(void)
< {
< 	free (mixer_table);
< 	free (mixer_buffer);
< }
< 
< 
< /********************************************************************************/
< 
< 
< void pengo_sound_enable_w(int offset,int data)
< {
< 	sound_enable = data;
< }
< 
< void pengo_sound_w(int offset,int data)
< {
< 	sound_channel *voice;
< 	int base;
< 
< 	/* update the streams */
< 	stream_update(stream, 0);
< 
< 	/* set the register */
< 	namco_soundregs[offset] = data & 0x0f;
< 
< 	/* recompute all the voice parameters */
< 	for (base = 0, voice = channel_list; voice < last_channel; voice++, base += 5)
< 	{
< 		voice->frequency = namco_soundregs[0x14 + base];	/* always 0 */
< 		voice->frequency = voice->frequency * 16 + namco_soundregs[0x13 + base];
< 		voice->frequency = voice->frequency * 16 + namco_soundregs[0x12 + base];
< 		voice->frequency = voice->frequency * 16 + namco_soundregs[0x11 + base];
< 		if (base == 0)	/* the first voice has extra frequency bits */
< 			voice->frequency = voice->frequency * 16 + namco_soundregs[0x10 + base];
< 		else
< 			voice->frequency = voice->frequency * 16;
< 
< 		voice->volume[0] = namco_soundregs[0x15 + base] & 0x0f;
< 		voice->wave = &sound_prom[32 * (namco_soundregs[0x05 + base] & 7)];
< 	}
< }
< 
< 
< /********************************************************************************/
< 
< void mappy_sound_enable_w(int offset,int data)
< {
< 	sound_enable = offset;
< }
< 
< void mappy_sound_w(int offset,int data)
< {
< 	sound_channel *voice;
< 	int base;
< 
< 	/* update the streams */
< 	stream_update(stream, 0);
< 
< 	/* set the register */
< 	namco_soundregs[offset] = data;
< 
< if (errorlog && (offset & 7) <= 2)
< {
< 	char baf[80];
< 	sprintf(baf,"PC %02x: Namco reg %02x = %02x\n",cpu_get_pc(),offset,data);
< 	fprintf(errorlog,baf);
< 	usrintf_showmessage(baf);
< }
< 
< 	/* recompute all the voice parameters */
< 	for (base = 0, voice = channel_list; voice < last_channel; voice++, base += 8)
< 	{
< 		voice->frequency = namco_soundregs[0x06 + base] & 15;	/* high bits are from here */
< 		voice->frequency = voice->frequency * 256 + namco_soundregs[0x05 + base];
< 		voice->frequency = voice->frequency * 256 + namco_soundregs[0x04 + base];
< 
< 		voice->volume[0] = namco_soundregs[0x03 + base] & 0x0f;
< 		voice->wave = &sound_prom[32 * ((namco_soundregs[0x06 + base] >> 4) & 7)];
< 	}
< }
< 
< 
< 
< /********************************************************************************/
< 
< void namcos1_sound_w(int offset, int data)
< {
< 	sound_channel *voice;
< 	int base;
< 
< 	/* verify the offset */
< 	if (offset > 63)
< 	{
< 		if (errorlog) fprintf(errorlog, "NAMCOS1 sound: Attempting to write past the 64 registers segment\n");
< 		return;
< 	}
< 
< 	/* update the streams */
< 	stream_update(stream,0);
< 
< 	/* set the register */
< 	namco_soundregs[offset] = data;
< 
< 	/* recompute all the voice parameters */
< 	for (base = 0, voice = channel_list; voice < last_channel; voice++, base += 8)
< 	{
< 		voice->frequency = namco_soundregs[0x01 + base] & 15;	/* high bits are from here */
< 		voice->frequency = voice->frequency * 256 + namco_soundregs[0x02 + base];
< 		voice->frequency = voice->frequency * 256 + namco_soundregs[0x03 + base];
< 
< 		voice->volume[0] = namco_soundregs[0x00 + base] & 0x0f;
< 		voice->volume[1] = namco_soundregs[0x04 + base] & 0x0f;
< 		voice->wave = &sound_prom[32/samples_per_byte * ((namco_soundregs[0x01 + base] >> 4) & 15)];
< 	}
< }
< 
< int namcos1_sound_r(int offset)
< {
< 	return namco_soundregs[offset];
< }
< 
< void namcos1_wavedata_w(int offset, int data)
< {
< 	/* update the streams */
< 	stream_update(stream,0);
< 
< 	namco_wavedata[offset] = data;
< }
< 
< int namcos1_wavedata_r(int offset)
< {
< 	return namco_wavedata[offset];
< }
< 
< 
< 
< 
< 
< 
< 
< 
< void snkwave_w(int offset,int data)
< {
< 	static int freq0 = 0xff;
< 	sound_channel *voice = channel_list;
< 	if( offset==0 ) freq0 = data;
< 	if( offset==1 )
< 	{
< 		stream_update(stream, 0);
< 		if( data==0xff || freq0==0 )
< 		{
< 			voice->volume[0] = 0x0;
< 		}
< 		else
< 		{
< 			voice->volume[0] = 0x8;
< 			voice->frequency = (data<<16)/freq0;
< 		}
< 	}
< }
---
> /***************************************************************************
> 
> 	NAMCO sound driver.
> 
> 	This driver handles the three known types of NAMCO wavetable sounds:
> 
> 		- 3-voice mono (Pac-Man, Pengo, Dig Dug, etc)
> 		- 8-voice mono (Mappy, Dig Dug 2, etc)
> 		- 8-voice stereo (System 1)
> 
> ***************************************************************************/
> 
> #include "driver.h"
> 
> /* note: we work with signed samples here, unlike other drivers */
> #define AUDIO_CONV(A) (A)
> 
> /* 8 voices max */
> #define MAX_VOICES 8
> 
> 
> /* this structure defines the parameters for a channel */
> typedef struct
> {
> 	int frequency;
> 	int counter;
> 	int volume[2];
> 	const unsigned char *wave;
> } sound_channel;
> 
> 
> /* globals available to everyone */
> unsigned char *namco_soundregs;
> unsigned char *namco_wavedata;
> 
> /* data about the sound system */
> static sound_channel channel_list[MAX_VOICES];
> static sound_channel *last_channel;
> 
> /* global sound parameters */
> static const unsigned char *sound_prom;
> static int samples_per_byte;
> static int sample_bits;
> static int num_voices;
> static int sound_enable;
> static int stream;
> 
> /* mixer tables and internal buffers */
> static signed char *mixer_table;
> static signed char *mixer_lookup;
> static short *mixer_buffer;
> static short *mixer_buffer_2;
> 
> 
> 
> /* build a table to divide by the number of voices */
> static int make_mixer_table(int voices, int bits)
> {
> 	int count = voices * 128;
> 	int i;
> 	int gain = 16;
> 
> 
> 	/* allocate memory */
> 	mixer_table = malloc(256 * voices * bits / 8);
> 	if (!mixer_table)
> 		return 1;
> 
> 	/* find the middle of the table */
> 	mixer_lookup = mixer_table + (128 * voices * bits / 8);
> 
> 	/* fill in the table - 8 bit case */
> 	if (bits == 8)
> 	{
> 		for (i = 0; i < count; i++)
> 		{
> 			int val = i * gain / (voices * 16);
> 			if (val > 127) val = 127;
> 			mixer_lookup[ i] = AUDIO_CONV(val);
> 			mixer_lookup[-i] = AUDIO_CONV(-val);
> 		}
> 	}
> 
> 	/* fill in the table - 16 bit case */
> 	else
> 	{
> 		for (i = 0; i < count; i++)
> 		{
> 			int val = i * gain * 16 / voices;
> 			if (val > 32767) val = 32767;
> 			((short *)mixer_lookup)[ i] = val;
> 			((short *)mixer_lookup)[-i] = -val;
> 		}
> 	}
> 
> 	return 0;
> }
> 
> 
> /* generate sound to the mix buffer in mono */
> static void namco_update_mono(int ch, void *buffer, int length)
> {
> 	sound_channel *voice;
> 	short *mix;
> 	int i;
> 
> 	/* if no sound, we're done */
> 	if (sound_enable == 0)
> 	{
> 		if (sample_bits == 16)
> 			memset(buffer, 0, length * 2);
> 		else
> 			memset(buffer, AUDIO_CONV(0x00), length);
> 		return;
> 	}
> 
> 	/* zap the contents of the mixer buffer */
> 	memset(mixer_buffer, 0, length * sizeof(short));
> 
> 	/* loop over each voice and add its contribution */
> 	for (voice = channel_list; voice < last_channel; voice++)
> 	{
> 		int f = voice->frequency;
> 		int v = voice->volume[0];
> 
> 		/* only update if we have non-zero volume and frequency */
> 		if (v && f)
> 		{
> 			const unsigned char *w = voice->wave;
> 			int c = voice->counter;
> 
> 			mix = mixer_buffer;
> 
> 			/* add our contribution */
> 			for (i = 0; i < length; i++)
> 			{
> 				int offs;
> 
> 				c += f;
> 				offs = (c >> 15) & 0x1f;
> 				if (samples_per_byte == 1)	/* use only low 4 bits */
> 					*mix++ += ((w[offs] & 0x0f) - 8) * v;
> 				else	/* use full byte, first the high 4 bits, then the low 4 bits */
> 				{
> 					if (offs & 1)
> 						*mix++ += ((w[offs>>1] & 0x0f) - 8) * v;
> 					else
> 						*mix++ += (((w[offs>>1]>>4) & 0x0f) - 8) * v;
> 				}
> 			}
> 
> 			/* update the counter for this voice */
> 			voice->counter = c;
> 		}
> 	}
> 
> 	/* mix it down */
> 	mix = mixer_buffer;
> 	if (sample_bits == 16)
> 	{
> 		short *dest = buffer;
> 		for (i = 0; i < length; i++)
> 			*dest++ = ((short *)mixer_lookup)[*mix++];
> 	}
> 	else
> 	{
> 		unsigned char *dest = buffer;
> 		for (i = 0; i < length; i++)
> 			*dest++ = mixer_lookup[*mix++];
> 	}
> }
> 
> 
> /* generate sound to the mix buffer in stereo */
> static void namco_update_stereo(int ch, void **buffer, int length)
> {
> 	sound_channel *voice;
> 	short *lmix, *rmix;
> 	int i;
> 
> 	/* if no sound, we're done */
> 	if (sound_enable == 0)
> 	{
> 		if (sample_bits == 16)
> 		{
> 			memset(buffer[0], 0, length * 2);
> 			memset(buffer[1], 0, length * 2);
> 		}
> 		else
> 		{
> 			memset(buffer[0], AUDIO_CONV(0x00), length);
> 			memset(buffer[1], AUDIO_CONV(0x00), length);
> 		}
> 		return;
> 	}
> 
> 	/* zap the contents of the mixer buffer */
> 	memset(mixer_buffer, 0, length * sizeof(short));
> 	memset(mixer_buffer_2, 0, length * sizeof(short));
> 
> 	/* loop over each voice and add its contribution */
> 	for (voice = channel_list; voice < last_channel; voice++)
> 	{
> 		int f = voice->frequency;
> 		int lv = voice->volume[0];
> 		int rv = voice->volume[1];
> 
> 		/* only update if we have non-zero volume and frequency */
> 		if ((lv || rv) && f)
> 		{
> 			const unsigned char *w = voice->wave;
> 			int c = voice->counter;
> 
> 			lmix = mixer_buffer;
> 			rmix = mixer_buffer_2;
> 
> 			/* add our contribution */
> 			for (i = 0; i < length; i++)
> 			{
> 				int offs;
> 
> 				c += f;
> 				offs = (c >> 15) & 0x1f;
> 				if (samples_per_byte == 1)	/* use only low 4 bits */
> 				{
> 					*lmix++ += ((w[offs] & 0x0f) - 8) * lv;
> 					*rmix++ += ((w[offs] & 0x0f) - 8) * rv;
> 				}
> 				else	/* use full byte, first the high 4 bits, then the low 4 bits */
> 				{
> 					if (offs & 1)
> 					{
> 						*lmix++ += ((w[offs>>1] & 0x0f) - 8) * lv;
> 						*rmix++ += ((w[offs>>1] & 0x0f) - 8) * rv;
> 					}
> 					else
> 					{
> 						*lmix++ += (((w[offs>>1]>>4) & 0x0f) - 8) * lv;
> 						*rmix++ += (((w[offs>>1]>>4) & 0x0f) - 8) * rv;
> 					}
> 				}
> 			}
> 
> 			/* update the counter for this voice */
> 			voice->counter = c;
> 		}
> 	}
> 
> 	/* mix it down */
> 	lmix = mixer_buffer;
> 	rmix = mixer_buffer_2;
> 	if (sample_bits == 16)
> 	{
> 		short *dest1 = buffer[0];
> 		short *dest2 = buffer[1];
> 		for (i = 0; i < length; i++)
> 		{
> 			*dest1++ = ((short *)mixer_lookup)[*lmix++];
> 			*dest2++ = ((short *)mixer_lookup)[*rmix++];
> 		}
> 	}
> 	else
> 	{
> 		unsigned char *dest1 = buffer[0];
> 		unsigned char *dest2 = buffer[1];
> 		for (i = 0; i < length; i++)
> 		{
> 			*dest1++ = mixer_lookup[*lmix++];
> 			*dest2++ = mixer_lookup[*rmix++];
> 		}
> 	}
> }
> 
> 
> int namco_sh_start(const struct MachineSound *msound)
> {
> 	const char *mono_name = "NAMCO sound";
> 	const char *stereo_names[] =
> 	{
> 		"NAMCO sound left",
> 		"NAMCO sound right"
> 	};
> 	sound_channel *voice;
> 	const struct namco_interface *intf = msound->sound_interface;
> 
> 
> 	/* get stream channels */
> 	sample_bits = Machine->sample_bits;
> 	if (intf->stereo)
> 	{
> 		int vol[2];
> 
> 		vol[0] = MIXER(intf->volume,MIXER_PAN_LEFT);
> 		vol[1] = MIXER(intf->volume,MIXER_PAN_RIGHT);
> 		stream = stream_init_multi(2, stereo_names, vol, intf->samplerate, sample_bits, 0, namco_update_stereo);
> 	}
> 	else
> 	{
> 		stream = stream_init(mono_name, intf->volume, intf->samplerate, sample_bits, 0, namco_update_mono);
> 	}
> 
> 	/* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */
> 	if ((mixer_buffer = malloc(2 * sizeof(short) * intf->samplerate)) == 0)
> 		return 1;
> 	mixer_buffer_2 = mixer_buffer + intf->samplerate;
> 
> 	/* build the mixer table */
> 	if (make_mixer_table(intf->voices, Machine->sample_bits))
> 	{
> 		free (mixer_buffer);
> 		return 1;
> 	}
> 
> 	/* extract globals from the interface */
> 	num_voices = intf->voices;
> 	last_channel = channel_list + num_voices;
> 
> 	if (intf->region == -1)
> 	{
> 		sound_prom = namco_wavedata;
> 		samples_per_byte = 2;	/* first 4 high bits, then low 4 bits */
> 	}
> 	else
> 	{
> 		sound_prom = Machine->memory_region[intf->region];
> 		samples_per_byte = 1;	/* use only low 4 bits */
> 	}
> 
> 	/* start with sound enabled, many games don't have a sound enable register */
> 	sound_enable = 1;
> 
> 	/* reset all the voices */
> 	for (voice = channel_list; voice < last_channel; voice++)
> 	{
> 		voice->frequency = 0;
> 		voice->volume[0] = voice->volume[1] = 0;
> 		voice->wave = &sound_prom[0];
> 		voice->counter = 0;
> 	}
> 
> 	return 0;
> }
> 
> 
> void namco_sh_stop(void)
> {
> 	free (mixer_table);
> 	free (mixer_buffer);
> }
> 
> 
> /********************************************************************************/
> 
> 
> void pengo_sound_enable_w(int offset,int data)
> {
> 	sound_enable = data;
> }
> 
> void pengo_sound_w(int offset,int data)
> {
> 	sound_channel *voice;
> 	int base;
> 
> 	/* update the streams */
> 	stream_update(stream, 0);
> 
> 	/* set the register */
> 	namco_soundregs[offset] = data & 0x0f;
> 
> 	/* recompute all the voice parameters */
> 	for (base = 0, voice = channel_list; voice < last_channel; voice++, base += 5)
> 	{
> 		voice->frequency = namco_soundregs[0x14 + base];	/* always 0 */
> 		voice->frequency = voice->frequency * 16 + namco_soundregs[0x13 + base];
> 		voice->frequency = voice->frequency * 16 + namco_soundregs[0x12 + base];
> 		voice->frequency = voice->frequency * 16 + namco_soundregs[0x11 + base];
> 		if (base == 0)	/* the first voice has extra frequency bits */
> 			voice->frequency = voice->frequency * 16 + namco_soundregs[0x10 + base];
> 		else
> 			voice->frequency = voice->frequency * 16;
> 
> 		voice->volume[0] = namco_soundregs[0x15 + base] & 0x0f;
> 		voice->wave = &sound_prom[32 * (namco_soundregs[0x05 + base] & 7)];
> 	}
> }
> 
> 
> /********************************************************************************/
> 
> void mappy_sound_enable_w(int offset,int data)
> {
> 	sound_enable = offset;
> }
> 
> void mappy_sound_w(int offset,int data)
> {
> 	sound_channel *voice;
> 	int base;
> 
> 	/* update the streams */
> 	stream_update(stream, 0);
> 
> 	/* set the register */
> 	namco_soundregs[offset] = data;
> 
> if (errorlog && (offset & 7) <= 2)
> {
> 	char baf[80];
> 	sprintf(baf,"PC %02x: Namco reg %02x = %02x\n",cpu_get_pc(),offset,data);
> 	fprintf(errorlog,baf);
> 	usrintf_showmessage(baf);
> }
> 
> 	/* recompute all the voice parameters */
> 	for (base = 0, voice = channel_list; voice < last_channel; voice++, base += 8)
> 	{
> 		voice->frequency = namco_soundregs[0x06 + base] & 15;	/* high bits are from here */
> 		voice->frequency = voice->frequency * 256 + namco_soundregs[0x05 + base];
> 		voice->frequency = voice->frequency * 256 + namco_soundregs[0x04 + base];
> 
> 		voice->volume[0] = namco_soundregs[0x03 + base] & 0x0f;
> 		voice->wave = &sound_prom[32 * ((namco_soundregs[0x06 + base] >> 4) & 7)];
> 	}
> }
> 
> 
> 
> /********************************************************************************/
> 
> void namcos1_sound_w(int offset, int data)
> {
> 	sound_channel *voice;
> 	int base;
> 
> 	/* verify the offset */
> 	if (offset > 63)
> 	{
> 		if (errorlog) fprintf(errorlog, "NAMCOS1 sound: Attempting to write past the 64 registers segment\n");
> 		return;
> 	}
> 
> 	/* update the streams */
> 	stream_update(stream,0);
> 
> 	/* set the register */
> 	namco_soundregs[offset] = data;
> 
> 	/* recompute all the voice parameters */
> 	for (base = 0, voice = channel_list; voice < last_channel; voice++, base += 8)
> 	{
> 		voice->frequency = namco_soundregs[0x01 + base] & 15;	/* high bits are from here */
> 		voice->frequency = voice->frequency * 256 + namco_soundregs[0x02 + base];
> 		voice->frequency = voice->frequency * 256 + namco_soundregs[0x03 + base];
> 
> 		voice->volume[0] = namco_soundregs[0x00 + base] & 0x0f;
> 		voice->volume[1] = namco_soundregs[0x04 + base] & 0x0f;
> 		voice->wave = &sound_prom[32/samples_per_byte * ((namco_soundregs[0x01 + base] >> 4) & 15)];
> 	}
> }
> 
> int namcos1_sound_r(int offset)
> {
> 	return namco_soundregs[offset];
> }
> 
> void namcos1_wavedata_w(int offset, int data)
> {
> 	/* update the streams */
> 	stream_update(stream,0);
> 
> 	namco_wavedata[offset] = data;
> }
> 
> int namcos1_wavedata_r(int offset)
> {
> 	return namco_wavedata[offset];
> }
> 
> 
> 
> 
> 
> 
> 
> 
> void snkwave_w(int offset,int data)
> {
> 	static int freq0 = 0xff;
> 	sound_channel *voice = channel_list;
> 	if( offset==0 ) freq0 = data;
> 	if( offset==1 )
> 	{
> 		stream_update(stream, 0);
> 		if( data==0xff || freq0==0 )
> 		{
> 			voice->volume[0] = 0x0;
> 		}
> 		else
> 		{
> 			voice->volume[0] = 0x8;
> 			voice->frequency = (data<<16)/freq0;
> 		}
> 	}
> }
nes.c
nesintf.c
pokey.c
rf5c68.c
1,266c1,266
< /*********************************************************/
< /*    ricoh RF5C68(or clone) PCM controller              */
< /*********************************************************/
< 
< #include "driver.h"
< #include <math.h>
< 
< #define PCM_NORMALIZE
< 
< enum
< {
< 	RF_L_PAN = 0, RF_R_PAN = 1, RF_LR_PAN = 2
< };
< 
< static RF5C68PCM    rpcm;
< static int  reg_port;
< static int emulation_rate;
< 
< static int buffer_len;
< static int stream;
< 
< //static unsigned char pcmbuf[0x10000];
< static unsigned char *pcmbuf=NULL;
< 
< static struct RF5C68interface *intf;
< 
< static unsigned char wreg[0x10]; /* write data */
< 
< #define   BASE_SHIFT    (11+4)
< 
< #define    RF_ON     (1<<0)
< #define    RF_START  (1<<1)
< 
< /************************************************/
< /*    RF5C68 start                              */
< /************************************************/
< int RF5C68_sh_start( const struct MachineSound *msound )
< {
< 	int i;
< 	int rate = Machine->sample_rate;
< 	struct RF5C68interface *inintf = msound->sound_interface;
< 
< 	if (Machine->sample_rate == 0) return 0;
< 
< 	if(pcmbuf==NULL) pcmbuf=(unsigned char *)malloc(0x10000);
< 	if(pcmbuf==NULL) return 1;
< 
< 	intf = inintf;
< 	buffer_len = rate / Machine->drv->frames_per_second;
< 	emulation_rate = buffer_len * Machine->drv->frames_per_second;
< 
< 	rpcm.clock = intf->clock;
< 	for( i = 0; i < RF5C68_PCM_MAX; i++ )
< 	{
< 		rpcm.env[i] = 0;
< 		rpcm.pan[i] = 0;
< 		rpcm.start[i] = 0;
< 		rpcm.step[i] = 0;
< 		rpcm.flag[i] = 0;
< 	}
< 	for( i = 0; i < 0x10; i++ )  wreg[i] = 0;
< 	reg_port = 0;
< 
< 	{
< 		char buf[LR_PAN][40];
< 		const char *name[LR_PAN];
< 		int  vol[2];
< 		name[0] = buf[0];
< 		name[1] = buf[1];
< 		sprintf( buf[0], "%s Left", sound_name(msound) );
< 		sprintf( buf[1], "%s Right", sound_name(msound) );
< 		vol[0] = (MIXER_PAN_LEFT<<8)  | (intf->volume&0xff);
< 		vol[1] = (MIXER_PAN_RIGHT<<8) | (intf->volume&0xff);
< 
< 		stream = stream_init_multi( RF_LR_PAN, name, vol, rate, 16, 0, RF5C68Update );
< 		if(stream == -1) return 1;
< 	}
< 	return 0;
< }
< 
< /************************************************/
< /*    RF5C68 stop                               */
< /************************************************/
< void RF5C68_sh_stop( void )
< {
< 	if(pcmbuf!=NULL) free(pcmbuf);
< 	pcmbuf=NULL;
< }
< 
< /************************************************/
< /*    RF5C68 update                             */
< /************************************************/
< 
< INLINE int ILimit(int v, int max, int min) { return v > max ? max : (v < min ? min : v); }
< 
< void RF5C68Update( int num, void **buffer, int length )
< {
< 	int i, j, tmp;
< 	unsigned int addr, old_addr;
< 	signed int ld, rd;
< 	RF5C68_SAMPLE  *datap[2];
< 
< 	datap[RF_L_PAN] = (RF5C68_SAMPLE *)buffer[0];
< 	datap[RF_R_PAN] = (RF5C68_SAMPLE *)buffer[1];
< 
< 	memset( datap[RF_L_PAN], 0x00, length * sizeof(RF5C68_SAMPLE) );
< 	memset( datap[RF_R_PAN], 0x00, length * sizeof(RF5C68_SAMPLE) );
< 
< 	for( i = 0; i < RF5C68_PCM_MAX; i++ )
< 	{
< 		if( (rpcm.flag[i]&(RF_START|RF_ON)) == (RF_START|RF_ON) )
< 		{
< 			/**** PCM setup ****/
< 			addr = (rpcm.addr[i]>>BASE_SHIFT)&0xffff;
< 			ld = (rpcm.pan[i]&0x0f);
< 			rd = ((rpcm.pan[i]>>4)&0x0f);
< 			/*       cen = (ld + rd) / 4; */
< 			/*       ld = (rpcm.env[i]&0xff) * (ld + cen); */
< 			/*       rd = (rpcm.env[i]&0xff) * (rd + cen); */
< 			ld = (rpcm.env[i]&0xff) * ld;
< 			rd = (rpcm.env[i]&0xff) * rd;
< 
< 			for( j = 0; j < length; j++ )
< 			{
< 				old_addr = addr;
< 				addr = (rpcm.addr[i]>>BASE_SHIFT)&0xffff;
< 				for(; old_addr <= addr; old_addr++ )
< 				{
< 					/**** PCM end check ****/
< 					if( (((unsigned int)pcmbuf[old_addr])&0x00ff) == (unsigned int)0x00ff )
< 					{
< 						rpcm.addr[i] = rpcm.loop[i] + ((addr - old_addr)<<BASE_SHIFT);
< 						addr = (rpcm.addr[i]>>BASE_SHIFT)&0xffff;
< 						/**** PCM loop check ****/
< 						if( (((unsigned int)pcmbuf[addr])&0x00ff) == (unsigned int)0x00ff )	// this causes looping problems
< 						{
< 							rpcm.flag[i] = 0;
< 							break;
< 						}
< 						else
< 						{
< 							old_addr = addr;
< 						}
< 					}
< #ifdef PCM_NORMALIZE
< 					tmp = rpcm.pcmd[i];
< 					rpcm.pcmd[i] = (pcmbuf[old_addr]&0x7f) * (-1 + (2 * ((pcmbuf[old_addr]>>7)&0x01)));
< 					rpcm.pcma[i] = (tmp - rpcm.pcmd[i]) / 2;
< 					rpcm.pcmd[i] += rpcm.pcma[i];
< #endif
< 				}
< 				rpcm.addr[i] += rpcm.step[i];
< 				if( !rpcm.flag[i] )  break; /* skip PCM */
< #ifndef PCM_NORMALIZE
< 				if( pcmbuf[addr]&0x80 )
< 				{
< 					rpcm.pcmx[0][i] = ((signed int)(pcmbuf[addr]&0x7f))*ld;
< 					rpcm.pcmx[1][i] = ((signed int)(pcmbuf[addr]&0x7f))*rd;
< 				}
< 				else
< 				{
< 					rpcm.pcmx[0][i] = ((signed int)(-(pcmbuf[addr]&0x7f)))*ld;
< 					rpcm.pcmx[1][i] = ((signed int)(-(pcmbuf[addr]&0x7f)))*rd;
< 				}
< #else
< 				rpcm.pcmx[0][i] = rpcm.pcmd[i] * ld;
< 				rpcm.pcmx[1][i] = rpcm.pcmd[i] * rd;
< #endif
< 				*(datap[RF_L_PAN] + j) = ILimit( ((int)*(datap[RF_L_PAN] + j) + ((rpcm.pcmx[0][i])>>4)), 32767, -32768 );
< 				*(datap[RF_R_PAN] + j) = ILimit( ((int)*(datap[RF_R_PAN] + j) + ((rpcm.pcmx[1][i])>>4)), 32767, -32768 );
< 			}
< 		}
< 	}
< }
< 
< /************************************************/
< /*    RF5C68 write register                     */
< /************************************************/
< void RF5C68WriteReg( int r, int v )
< {
< 	int  i;
< 	int  data;
< 
< 	wreg[r] = v;			/* stock write data */
< 	/**** set PCM registers ****/
< 	if( (wreg[0x07]&0x40) )  reg_port = wreg[0x07]&0x07;	/* select port # */
< 
< 	switch( r )
< 	{
< 		case 0x00:
< 			rpcm.env[reg_port] = v;		/* set env. */
< 			break;
< 		case 0x01:
< 			rpcm.pan[reg_port] = v;		/* set pan */
< 			break;
< 		case 0x02:
< 		case 0x03:
< 			/**** address step ****/
< 			data = (((((int)wreg[0x03])<<8)&0xff00) | (((int)wreg[0x02])&0x00ff));
< 			rpcm.step[reg_port] = (int)(
< 			(
< 			( 28456.0 / (float)emulation_rate ) *
< 			( data / (float)(0x0800) ) *
< 			(rpcm.clock / 8000000.0) *
< 			(1<<BASE_SHIFT)
< 			)
< 			);
< 			break;
< 		case 0x04:
< 		case 0x05:
< 			/**** loop address ****/
< 			rpcm.loop[reg_port] = (((((unsigned int)wreg[0x05])<<8)&0xff00)|(((unsigned int)wreg[0x04])&0x00ff))<<(BASE_SHIFT);
< 			break;
< 		case 0x06:
< 			/**** start address ****/
< 			rpcm.start[reg_port] = (((unsigned int)wreg[0x06])&0x00ff)<<(BASE_SHIFT + 8);
< 			rpcm.addr[reg_port] = rpcm.start[reg_port];
< 			break;
< 		case 0x07:
< 			if( (v&0xc0) == 0xc0 )
< 			{
< 				i = v&0x07;		/* register port */
< 				rpcm.pcmx[0][i] = 0;
< 				rpcm.pcmx[1][i] = 0;
< 				rpcm.flag[i] |= RF_START;
< 			}
< 			break;
< 
< 		case 0x08:
< 			/**** pcm on/off ****/
< 			for( i = 0; i < RF5C68_PCM_MAX; i++ )
< 			{
< 				if( !(v&(1<<i)) )
< 				{
< 					rpcm.flag[i] |= RF_ON;	/* PCM on */
< 				}
< 				else
< 				{
< 					rpcm.flag[i] &= ~(RF_ON); /* PCM off */
< 				}
< 			}
< 			break;
< 	}
< }
< 
< /************************************************/
< /*    RF5C68 read memory                        */
< /************************************************/
< int RF5C68ReadMem( int r )
< {
< 	unsigned int  bank;
< 	bank = ((unsigned int)(wreg[0x07]&0x0f))<<(8+4);
< 	return pcmbuf[bank + r];
< }
< /************************************************/
< /*    RF5C68 write memory                       */
< /************************************************/
< void RF5C68WriteMem( int r, int v )
< {
< 	unsigned int  bank;
< 	bank = ((unsigned int)(wreg[0x07]&0x0f))<<(8+4);
< 	pcmbuf[bank + r] = v;
< }
< 
< 
< /**************** end of file ****************/
---
> /*********************************************************/
> /*    ricoh RF5C68(or clone) PCM controller              */
> /*********************************************************/
> 
> #include "driver.h"
> #include <math.h>
> 
> #define PCM_NORMALIZE
> 
> enum
> {
> 	RF_L_PAN = 0, RF_R_PAN = 1, RF_LR_PAN = 2
> };
> 
> static RF5C68PCM    rpcm;
> static int  reg_port;
> static int emulation_rate;
> 
> static int buffer_len;
> static int stream;
> 
> /*static unsigned char pcmbuf[0x10000]; */
> static unsigned char *pcmbuf=NULL;
> 
> static struct RF5C68interface *intf;
> 
> static unsigned char wreg[0x10]; /* write data */
> 
> #define   BASE_SHIFT    (11+4)
> 
> #define    RF_ON     (1<<0)
> #define    RF_START  (1<<1)
> 
> /************************************************/
> /*    RF5C68 start                              */
> /************************************************/
> int RF5C68_sh_start( const struct MachineSound *msound )
> {
> 	int i;
> 	int rate = Machine->sample_rate;
> 	struct RF5C68interface *inintf = msound->sound_interface;
> 
> 	if (Machine->sample_rate == 0) return 0;
> 
> 	if(pcmbuf==NULL) pcmbuf=(unsigned char *)malloc(0x10000);
> 	if(pcmbuf==NULL) return 1;
> 
> 	intf = inintf;
> 	buffer_len = rate / Machine->drv->frames_per_second;
> 	emulation_rate = buffer_len * Machine->drv->frames_per_second;
> 
> 	rpcm.clock = intf->clock;
> 	for( i = 0; i < RF5C68_PCM_MAX; i++ )
> 	{
> 		rpcm.env[i] = 0;
> 		rpcm.pan[i] = 0;
> 		rpcm.start[i] = 0;
> 		rpcm.step[i] = 0;
> 		rpcm.flag[i] = 0;
> 	}
> 	for( i = 0; i < 0x10; i++ )  wreg[i] = 0;
> 	reg_port = 0;
> 
> 	{
> 		char buf[LR_PAN][40];
> 		const char *name[LR_PAN];
> 		int  vol[2];
> 		name[0] = buf[0];
> 		name[1] = buf[1];
> 		sprintf( buf[0], "%s Left", sound_name(msound) );
> 		sprintf( buf[1], "%s Right", sound_name(msound) );
> 		vol[0] = (MIXER_PAN_LEFT<<8)  | (intf->volume&0xff);
> 		vol[1] = (MIXER_PAN_RIGHT<<8) | (intf->volume&0xff);
> 
> 		stream = stream_init_multi( RF_LR_PAN, name, vol, rate, 16, 0, RF5C68Update );
> 		if(stream == -1) return 1;
> 	}
> 	return 0;
> }
> 
> /************************************************/
> /*    RF5C68 stop                               */
> /************************************************/
> void RF5C68_sh_stop( void )
> {
> 	if(pcmbuf!=NULL) free(pcmbuf);
> 	pcmbuf=NULL;
> }
> 
> /************************************************/
> /*    RF5C68 update                             */
> /************************************************/
> 
> INLINE int ILimit(int v, int max, int min) { return v > max ? max : (v < min ? min : v); }
> 
> void RF5C68Update( int num, void **buffer, int length )
> {
> 	int i, j, tmp;
> 	unsigned int addr, old_addr;
> 	signed int ld, rd;
> 	RF5C68_SAMPLE  *datap[2];
> 
> 	datap[RF_L_PAN] = (RF5C68_SAMPLE *)buffer[0];
> 	datap[RF_R_PAN] = (RF5C68_SAMPLE *)buffer[1];
> 
> 	memset( datap[RF_L_PAN], 0x00, length * sizeof(RF5C68_SAMPLE) );
> 	memset( datap[RF_R_PAN], 0x00, length * sizeof(RF5C68_SAMPLE) );
> 
> 	for( i = 0; i < RF5C68_PCM_MAX; i++ )
> 	{
> 		if( (rpcm.flag[i]&(RF_START|RF_ON)) == (RF_START|RF_ON) )
> 		{
> 			/**** PCM setup ****/
> 			addr = (rpcm.addr[i]>>BASE_SHIFT)&0xffff;
> 			ld = (rpcm.pan[i]&0x0f);
> 			rd = ((rpcm.pan[i]>>4)&0x0f);
> 			/*       cen = (ld + rd) / 4; */
> 			/*       ld = (rpcm.env[i]&0xff) * (ld + cen); */
> 			/*       rd = (rpcm.env[i]&0xff) * (rd + cen); */
> 			ld = (rpcm.env[i]&0xff) * ld;
> 			rd = (rpcm.env[i]&0xff) * rd;
> 
> 			for( j = 0; j < length; j++ )
> 			{
> 				old_addr = addr;
> 				addr = (rpcm.addr[i]>>BASE_SHIFT)&0xffff;
> 				for(; old_addr <= addr; old_addr++ )
> 				{
> 					/**** PCM end check ****/
> 					if( (((unsigned int)pcmbuf[old_addr])&0x00ff) == (unsigned int)0x00ff )
> 					{
> 						rpcm.addr[i] = rpcm.loop[i] + ((addr - old_addr)<<BASE_SHIFT);
> 						addr = (rpcm.addr[i]>>BASE_SHIFT)&0xffff;
> 						/**** PCM loop check ****/
> 						if( (((unsigned int)pcmbuf[addr])&0x00ff) == (unsigned int)0x00ff )	/* this causes looping problems */
> 						{
> 							rpcm.flag[i] = 0;
> 							break;
> 						}
> 						else
> 						{
> 							old_addr = addr;
> 						}
> 					}
> #ifdef PCM_NORMALIZE
> 					tmp = rpcm.pcmd[i];
> 					rpcm.pcmd[i] = (pcmbuf[old_addr]&0x7f) * (-1 + (2 * ((pcmbuf[old_addr]>>7)&0x01)));
> 					rpcm.pcma[i] = (tmp - rpcm.pcmd[i]) / 2;
> 					rpcm.pcmd[i] += rpcm.pcma[i];
> #endif
> 				}
> 				rpcm.addr[i] += rpcm.step[i];
> 				if( !rpcm.flag[i] )  break; /* skip PCM */
> #ifndef PCM_NORMALIZE
> 				if( pcmbuf[addr]&0x80 )
> 				{
> 					rpcm.pcmx[0][i] = ((signed int)(pcmbuf[addr]&0x7f))*ld;
> 					rpcm.pcmx[1][i] = ((signed int)(pcmbuf[addr]&0x7f))*rd;
> 				}
> 				else
> 				{
> 					rpcm.pcmx[0][i] = ((signed int)(-(pcmbuf[addr]&0x7f)))*ld;
> 					rpcm.pcmx[1][i] = ((signed int)(-(pcmbuf[addr]&0x7f)))*rd;
> 				}
> #else
> 				rpcm.pcmx[0][i] = rpcm.pcmd[i] * ld;
> 				rpcm.pcmx[1][i] = rpcm.pcmd[i] * rd;
> #endif
> 				*(datap[RF_L_PAN] + j) = ILimit( ((int)*(datap[RF_L_PAN] + j) + ((rpcm.pcmx[0][i])>>4)), 32767, -32768 );
> 				*(datap[RF_R_PAN] + j) = ILimit( ((int)*(datap[RF_R_PAN] + j) + ((rpcm.pcmx[1][i])>>4)), 32767, -32768 );
> 			}
> 		}
> 	}
> }
> 
> /************************************************/
> /*    RF5C68 write register                     */
> /************************************************/
> void RF5C68WriteReg( int r, int v )
> {
> 	int  i;
> 	int  data;
> 
> 	wreg[r] = v;			/* stock write data */
> 	/**** set PCM registers ****/
> 	if( (wreg[0x07]&0x40) )  reg_port = wreg[0x07]&0x07;	/* select port # */
> 
> 	switch( r )
> 	{
> 		case 0x00:
> 			rpcm.env[reg_port] = v;		/* set env. */
> 			break;
> 		case 0x01:
> 			rpcm.pan[reg_port] = v;		/* set pan */
> 			break;
> 		case 0x02:
> 		case 0x03:
> 			/**** address step ****/
> 			data = (((((int)wreg[0x03])<<8)&0xff00) | (((int)wreg[0x02])&0x00ff));
> 			rpcm.step[reg_port] = (int)(
> 			(
> 			( 28456.0 / (float)emulation_rate ) *
> 			( data / (float)(0x0800) ) *
> 			(rpcm.clock / 8000000.0) *
> 			(1<<BASE_SHIFT)
> 			)
> 			);
> 			break;
> 		case 0x04:
> 		case 0x05:
> 			/**** loop address ****/
> 			rpcm.loop[reg_port] = (((((unsigned int)wreg[0x05])<<8)&0xff00)|(((unsigned int)wreg[0x04])&0x00ff))<<(BASE_SHIFT);
> 			break;
> 		case 0x06:
> 			/**** start address ****/
> 			rpcm.start[reg_port] = (((unsigned int)wreg[0x06])&0x00ff)<<(BASE_SHIFT + 8);
> 			rpcm.addr[reg_port] = rpcm.start[reg_port];
> 			break;
> 		case 0x07:
> 			if( (v&0xc0) == 0xc0 )
> 			{
> 				i = v&0x07;		/* register port */
> 				rpcm.pcmx[0][i] = 0;
> 				rpcm.pcmx[1][i] = 0;
> 				rpcm.flag[i] |= RF_START;
> 			}
> 			break;
> 
> 		case 0x08:
> 			/**** pcm on/off ****/
> 			for( i = 0; i < RF5C68_PCM_MAX; i++ )
> 			{
> 				if( !(v&(1<<i)) )
> 				{
> 					rpcm.flag[i] |= RF_ON;	/* PCM on */
> 				}
> 				else
> 				{
> 					rpcm.flag[i] &= ~(RF_ON); /* PCM off */
> 				}
> 			}
> 			break;
> 	}
> }
> 
> /************************************************/
> /*    RF5C68 read memory                        */
> /************************************************/
> int RF5C68ReadMem( int r )
> {
> 	unsigned int  bank;
> 	bank = ((unsigned int)(wreg[0x07]&0x0f))<<(8+4);
> 	return pcmbuf[bank + r];
> }
> /************************************************/
> /*    RF5C68 write memory                       */
> /************************************************/
> void RF5C68WriteMem( int r, int v )
> {
> 	unsigned int  bank;
> 	bank = ((unsigned int)(wreg[0x07]&0x0f))<<(8+4);
> 	pcmbuf[bank + r] = v;
> }
> 
> 
> /**************** end of file ****************/
samples.c
segapcm.c
99c99
< 	//printf( "segaPCM in\n" );
---
> 	/*printf( "segaPCM in\n" ); */
126c126
< 	//printf( "segaPCM work init end\n" );
---
> 	/*printf( "segaPCM work init end\n" ); */
140c140
< 	//printf( "segaPCM end\n" );
---
> 	/*printf( "segaPCM end\n" ); */
197c197
< 	{
---
> 	{
199c199
< 		if( spcm.flag[i] == 2)
---
> 		if( spcm.flag[i] == 2)
201c201
< 		{
---
> 		{
203c203
< 			spcm.flag[i]=0;
---
> 			spcm.flag[i]=0;
205c205
< 			spcm.add_addr[i] = (( (((int)spcm.addr_h[i]<<8)&0xff00) |
---
> 			spcm.add_addr[i] = (( (((int)spcm.addr_h[i]<<8)&0xff00) |
207c207
< 				  (spcm.addr_l[i]&0x00ff) ) << PCM_ADDR_SHIFT) &0x0ffff000;
---
> 				  (spcm.addr_l[i]&0x00ff) ) << PCM_ADDR_SHIFT) &0x0ffff000;
217c217
< 			end_addr = ((((unsigned int)spcm.end_h[i]<<8)&0xff00) + 0x00ff);
---
> 			end_addr = ((((unsigned int)spcm.end_h[i]<<8)&0xff00) + 0x00ff);
224c224
< 				/**** make address ****/
---
> 				/**** make address ****/
280c280
< 	spcm.writeram[r&0x07ff] = (char)v;		/* write value data */
---
> 	spcm.writeram[r&0x07ff] = (char)v;		/* write value data */
295,297c295,297
< //			spcm.vol[channel][L_PAN] = (lv + cen)<<1;
< //			spcm.vol[channel][R_PAN] = (rv + cen)<<1;
< 			spcm.vol[channel][L_PAN] = (lv + cen)*9/5;	// too much clipping
---
> /*			spcm.vol[channel][L_PAN] = (lv + cen)<<1; */
> /*			spcm.vol[channel][R_PAN] = (rv + cen)<<1; */
> 			spcm.vol[channel][L_PAN] = (lv + cen)*9/5;	/* too much clipping */
325,326c325,326
< //				spcm.flag[channel] = 0;
< 				spcm.flag[channel] = 2;
---
> /*				spcm.flag[channel] = 0; */
> 				spcm.flag[channel] = 2;
328,329c328,329
< //				spcm.add_addr[channel] = (( (((int)spcm.addr_h[channel]<<8)&0xff00) |
< //					  (spcm.addr_l[channel]&0x00ff) ) << PCM_ADDR_SHIFT) &0x0ffff000;
---
> /*				spcm.add_addr[channel] = (( (((int)spcm.addr_h[channel]<<8)&0xff00) | */
> /*					  (spcm.addr_l[channel]&0x00ff) ) << PCM_ADDR_SHIFT) &0x0ffff000; */
sn76496.c
29,31c29,31
< //#define FB_WNOISE 0x14000	/* bit15.d(16bits) = bit0(out) ^ bit1 */
< //#define FB_WNOISE 0x28000	/* bit16.d(17bits) = bit0(out) ^ bit2 (same to AY-3-8910) */
< //#define FB_WNOISE 0x50000	/* bit17.d(18bits) = bit0(out) ^ bit2 */
---
> /*#define FB_WNOISE 0x14000	   bit15.d(16bits) = bit0(out) ^ bit1    */
> /*#define FB_WNOISE 0x28000	   bit16.d(17bits) = bit0(out) ^ bit2 (same to AY-3-8910)    */
> /*#define FB_WNOISE 0x50000	   bit17.d(18bits) = bit0(out) ^ bit2    */
35c35
< //#define FB_PNOISE 0x10000	/* 16bit rorate */
---
> /*#define FB_PNOISE 0x10000	   16bit rorate    */
165c165
< void SN76496_set_clock(int chip,int clock)
---
> static void SN76496_set_clock(int chip,int clock)
256c256
< 		if (SN76496_init(msound,chip,intf->baseclock,intf->volume[chip] & 0xff,Machine->sample_rate,Machine->sample_bits) != 0)
---
> 		if (SN76496_init(msound,chip,intf->baseclock[chip],intf->volume[chip] & 0xff,Machine->sample_rate,Machine->sample_bits) != 0)
sn76496u.c
streams.c
tiaintf.c
26c26
< //	int i, res;
---
> /*	int i, res; */
tiasound.c
tms5220.c
tms5220r.c
upd7759.c
97,98d96
< #define STATIC_SAMPLE_RATE 0	/* EHC - 13/08/99 */
< 
258c256
< #if STATIC_SAMPLE_RATE
---
> 
262a261
> 		case 0x5f: sample->freq = 5000; break;
266,271d264
< #else
< 	if ( ( data[j] & 0xf0 ) == 0x50 )
< 		sample->freq = 9000 - ( ( data[j] & 0x0f ) * 333 );
< 	else
< 		return 0;
< #endif
475c468
< 		//LOG(1,(errorlog,"upd7759_message_w $%02x\n", data));
---
> 		/*LOG(1,(errorlog,"upd7759_message_w $%02x\n", data)); */
515c508
< 				//LOG(1,(errorlog, "upd7759_message_w unhandled $%02x\n", data));
---
> 				/*LOG(1,(errorlog, "upd7759_message_w unhandled $%02x\n", data)); */
530c523
< 			//LOG(1,(errorlog, "upd7759_message_w set base $%08x\n", offset));
---
> 			/*LOG(1,(errorlog, "upd7759_message_w set base $%08x\n", offset)); */
vlm5030.c
192c192
< //8, 8, 8, 4, 4, 2, 2, 1
---
> /*8, 8, 8, 4, 4, 2, 2, 1 */
votrax.c
ym2151.c
12c12
< //#define FM_EMU
---
> /*#define FM_EMU */
1012,1013c1012,1013
< 	//osc->KCindex = kc_index_oscil;
< 	//osc->DT1val = PSG->DT1freq[ osc->DT1 + kc ];  /*DT1 value*/
---
> 	/*osc->KCindex = kc_index_oscil; */
> 	/*osc->DT1val = PSG->DT1freq[ osc->DT1 + kc ];    DT1 value   */
1028,1029c1028,1029
< 	//osc->KCindex = kc_index_oscil;
< 	//osc->DT1val = PSG->DT1freq[ kc ][ osc->DT1];  /*DT1 value*/
---
> 	/*osc->KCindex = kc_index_oscil; */
> 	/*osc->DT1val = PSG->DT1freq[ kc ][ osc->DT1];    DT1 value   */
1044,1045c1044,1045
< 	//osc->KCindex = kc_index_oscil;
< 	//osc->DT1val = PSG->DT1freq[ kc ][ osc->DT1];  /*DT1 value*/
---
> 	/*osc->KCindex = kc_index_oscil; */
> 	/*osc->DT1val = PSG->DT1freq[ kc ][ osc->DT1];    DT1 value   */
1060,1061c1060,1061
< 	//osc->KCindex = kc_index_oscil;
< 	//osc->DT1val = PSG->DT1freq[ kc ][ osc->DT1];  /*DT1 value*/
---
> 	/*osc->KCindex = kc_index_oscil; */
> 	/*osc->DT1val = PSG->DT1freq[ kc ][ osc->DT1];    DT1 value   */
1148c1148
< 	//op->LFOpm = pom - op->freq ;
---
> 	/*op->LFOpm = pom - op->freq ; */
1188c1188
< // signed int PM; pm_calc(OP0,chan); pm_calc(OP1,chan); pm_calc(OP2,chan); pm_calc(OP3,chan);
---
> /* signed int PM; pm_calc(OP0,chan); pm_calc(OP1,chan); pm_calc(OP2,chan); pm_calc(OP3,chan); */
1192c1192
< //#define op_calc(OP,env,pm)  sin_tab[ ( (OP->phase>>FREQ_SH) + pm ) & SIN_MASK] [  env + (pm>>7) /*+ (AM & OP->AMSmask)*/ ]
---
> /*#define op_calc(OP,env,pm)  sin_tab[ ( (OP->phase>>FREQ_SH) + pm ) & SIN_MASK] [  env + (pm>>7)   + (AM & OP->AMSmask)   ] */
1201c1201
< //unsigned int AM;
---
> /*unsigned int AM; */
1305c1305
< //lfo_calc();
---
> /*lfo_calc(); */
ym2413.c
ym3812.c
205c205
< //#define SHARKVER
---
> /*#define SHARKVER */
207c207
< //#define GENERALVER
---
> /*#define GENERALVER */
217c217
< // Include MAME stuff. If not Mame, then default to LSB_FIRST (PC)
---
> /* Include MAME stuff. If not Mame, then default to LSB_FIRST (PC) */
231c231
< // The number of entries in the sinus table! Do not change! Tweaked code depends on these values!
---
> /* The number of entries in the sinus table! Do not change! Tweaked code depends on these values! */
237c237
< // These numbers define attack and decay/sustain rates
---
> /* These numbers define attack and decay/sustain rates */
253c253
< // Mame converter
---
> /* Mame converter */
342c342
< 	// Set appropriate sample type (16bit or 8bit)
---
> 	/* Set appropriate sample type (16bit or 8bit) */
346c346
< 	// Insert stuff from host
---
> 	/* Insert stuff from host */
356c356
< 	// Generate some volume levels.. (ln)
---
> 	/* Generate some volume levels.. (ln) */
366c366
< 	// Generate a sinus table
---
> 	/* Generate a sinus table */
375c375
< 	// Calculate attack and decay time (release is same as decay)
---
> 	/* Calculate attack and decay time (release is same as decay) */
384c384
< 	// Initialize all slots
---
> 	/* Initialize all slots */
387,389c387,389
< 		pOPL->vEnvTime[l] = 0.0f;			// No time
< 		pOPL->nEnvState[l] = ADSR_Silent;	// Envelop is not playing
< 		pOPL->nTotalLevel[l] = 0;			// Envelop volume is 0
---
> 		pOPL->vEnvTime[l] = 0.0f;			/* No time */
> 		pOPL->nEnvState[l] = ADSR_Silent;	/* Envelop is not playing */
> 		pOPL->nTotalLevel[l] = 0;			/* Envelop volume is 0 */
401c401
< 		pOPL->nCurrPos[l] = 0;//rand() * SINTABLE_SIZE / RAND_MAX;
---
> 		pOPL->nCurrPos[l] = 0;/*rand() * SINTABLE_SIZE / RAND_MAX; */
404c404
< 	// Initialize all channels
---
> 	/* Initialize all channels */
414c414
< 	// Load Rhythm sounds
---
> 	/* Load Rhythm sounds */
436c436
< 	// MAME version
---
> 	/* MAME version */
444,445c444,445
< 			pOPL->nDrumRate[l] = psSamples->sample[l]->smpfreq; 			// Get frequency
< 			pOPL->nDrumSize[l] = psSamples->sample[l]->length;				// Get size
---
> 			pOPL->nDrumRate[l] = psSamples->sample[l]->smpfreq; 			/* Get frequency */
> 			pOPL->nDrumSize[l] = psSamples->sample[l]->length;				/* Get size */
447c447
< 			memset( pOPL->pDrum[l], 0, pOPL->nDrumSize[l]+1024 );			// Clear buffer
---
> 			memset( pOPL->pDrum[l], 0, pOPL->nDrumSize[l]+1024 );			/* Clear buffer */
449c449
< 			pDrum8 = psSamples->sample[l]->data;							// Get ptr to sample
---
> 			pDrum8 = psSamples->sample[l]->data;							/* Get ptr to sample */
451c451
< 			pDrum16 = (signed short*) pDrum8;								// Get 16 bit ptr to sample
---
> 			pDrum16 = (signed short*) pDrum8;								/* Get 16 bit ptr to sample */
472,479c472,479
< 			fseek( pFile, 0, SEEK_END );									// Go to end
< 			pOPL->nDrumSize[l] = ftell( pFile );							// Get file size
< 			fseek( pFile, 0, SEEK_SET );									// Rewind
< 			pOPL->pDrum[l] = (char*) malloc( pOPL->nDrumSize[l]+1024 );		// Alloc buffer
< 			memset( pOPL->pDrum[l], 0, pOPL->nDrumSize[l]+1024 );			// Clear buffer
< 			fread( pOPL->pDrum[l], pOPL->nDrumSize[l], 1, pFile );			// Read buffer
< 			fclose( pFile );												// Close file
< 			//Make sample signed.. Originally unsigned.
---
> 			fseek( pFile, 0, SEEK_END );									/* Go to end */
> 			pOPL->nDrumSize[l] = ftell( pFile );							/* Get file size */
> 			fseek( pFile, 0, SEEK_SET );									/* Rewind */
> 			pOPL->pDrum[l] = (char*) malloc( pOPL->nDrumSize[l]+1024 );		/* Alloc buffer */
> 			memset( pOPL->pDrum[l], 0, pOPL->nDrumSize[l]+1024 );			/* Clear buffer */
> 			fread( pOPL->pDrum[l], pOPL->nDrumSize[l], 1, pFile );			/* Read buffer */
> 			fclose( pFile );												/* Close file */
> 			/*Make sample signed.. Originally unsigned. */
540c540
< 			if( pOPL->vTimer1IntCnt > 0.250f ) pOPL->vTimer1IntCnt = 0.0f;	// Avoid incremental overflow of counter
---
> 			if( pOPL->vTimer1IntCnt > 0.250f ) pOPL->vTimer1IntCnt = 0.0f;	/* Avoid incremental overflow of counter */
562c562
< 			if( pOPL->vTimer2IntCnt > 0.250f ) pOPL->vTimer2IntCnt = 0.0f;	// Avoid incremental overflow of counter
---
> 			if( pOPL->vTimer2IntCnt > 0.250f ) pOPL->vTimer2IntCnt = 0.0f;	/* Avoid incremental overflow of counter */
590c590
< 				return cFALSE;	// Masking timer 1
---
> 				return cFALSE;	/* Masking timer 1 */
600c600
< 				return cFALSE;	// Masking timer 2
---
> 				return cFALSE;	/* Masking timer 2 */
603c603
< 	return cFALSE;	// Bad timer
---
> 	return cFALSE;	/* Bad timer */
694c694
< 		case 0x01:		// TEST - bit 5 means ym3812 mode on, not means ym3526 full compatibility
---
> 		case 0x01:		/* TEST - bit 5 means ym3812 mode on, not means ym3526 full compatibility */
697c697
< 		case 0x02:		// DATA OF TIMER 1
---
> 		case 0x02:		/* DATA OF TIMER 1 */
702c702
< 			if( pOPL->nTimerCtrl&ym3812_TCST1 ) // Change timer interval
---
> 			if( pOPL->nTimerCtrl&ym3812_TCST1 ) /* Change timer interval */
708c708
< 		case 0x03:		// DATA OF TIMER 2
---
> 		case 0x03:		/* DATA OF TIMER 2 */
713c713
< 			if( pOPL->nTimerCtrl&ym3812_TCST2 ) // Change timer interval
---
> 			if( pOPL->nTimerCtrl&ym3812_TCST2 ) /* Change timer interval */
719c719
< 		case 0x04:		// IRQ-RESET/CONTROL OF TIMER 1 AND 2
---
> 		case 0x04:		/* IRQ-RESET/CONTROL OF TIMER 1 AND 2 */
731c731
< 			{			// Start new timer if START TIMER1 was set this write.
---
> 			{			/* Start new timer if START TIMER1 was set this write. */
733c733
< 				pOPL->vTimer1IntCnt = 0.0f;	// Set timer to 0
---
> 				pOPL->vTimer1IntCnt = 0.0f;	/* Set timer to 0 */
736c736
< 			{			// Remove existing timer if START TIMER1 was cleared this write.
---
> 			{			/* Remove existing timer if START TIMER1 was cleared this write. */
740c740
< 			{			// Start new timer if START TIMER2 was set this write.
---
> 			{			/* Start new timer if START TIMER2 was set this write. */
742c742
< 				pOPL->vTimer2IntCnt = 0.0f;	// Set timer to 0
---
> 				pOPL->vTimer2IntCnt = 0.0f;	/* Set timer to 0 */
745c745
< 			{			// Remove existing timer if START TIMER2 was cleared this write.
---
> 			{			/* Remove existing timer if START TIMER2 was cleared this write. */
749c749
< 		case 0x08:		// CSM SPEECH SYNTHESIS MODE/NOTE SELECT
---
> 		case 0x08:		/* CSM SPEECH SYNTHESIS MODE/NOTE SELECT */
752c752
< 		case 0xbd:		// DEPTH(AM/VIB)/RHYTHM(BD, SD, TOM, TC, HH)
---
> 		case 0xbd:		/* DEPTH(AM/VIB)/RHYTHM(BD, SD, TOM, TC, HH) */
754c754
< 			pOPL->nDepthRhythm=nData;		// 0xbd - control of depth and rhythm
---
> 			pOPL->nDepthRhythm=nData;		/* 0xbd - control of depth and rhythm */
756,760c756,760
< 			if( nData&0x10 ) pOPL->nDrumOffs[0] = 0;	// Bass Drum
< 			if( nData&0x08 ) pOPL->nDrumOffs[1] = 0;	// Snare Drum
< 			if( nData&0x04 ) pOPL->nDrumOffs[2] = 0;	// Tom tom
< 			if( nData&0x02 ) pOPL->nDrumOffs[3] = 0;	// Top cymbal
< 			if( nData&0x01 ) pOPL->nDrumOffs[4] = 0;	// Hihat
---
> 			if( nData&0x10 ) pOPL->nDrumOffs[0] = 0;	/* Bass Drum */
> 			if( nData&0x08 ) pOPL->nDrumOffs[1] = 0;	/* Snare Drum */
> 			if( nData&0x04 ) pOPL->nDrumOffs[2] = 0;	/* Tom tom */
> 			if( nData&0x02 ) pOPL->nDrumOffs[3] = 0;	/* Top cymbal */
> 			if( nData&0x01 ) pOPL->nDrumOffs[4] = 0;	/* Hihat */
768c768
< 			case 0xa0:		// F-NUMBER (LOW 8 BITS) a0-a8
---
> 			case 0xa0:		/* F-NUMBER (LOW 8 BITS) a0-a8 */
771c771
< 			case 0xb0:		// KEY-ON/BLOCK/F-NUMER(LOW 2 BITS) b0-b8
---
> 			case 0xb0:		/* KEY-ON/BLOCK/F-NUMER(LOW 2 BITS) b0-b8 */
783c783
< 			case 0xc0:		// FEEDBACK/CONNECTION
---
> 			case 0xc0:		/* FEEDBACK/CONNECTION */
786c786
< 				if( !nData )	// Calculate Feedback RATIO!
---
> 				if( !nData )	/* Calculate Feedback RATIO! */
803c803
< 			case 0x20:		// AM-MOD/VIBRATO/EG-TYP/KEY-SCALE-RATE/MULTIPLE
---
> 			case 0x20:		/* AM-MOD/VIBRATO/EG-TYP/KEY-SCALE-RATE/MULTIPLE */
810c810
< 			case 0x40:		// KEY-SCALE LEVEL/TOTAL LEVEL
---
> 			case 0x40:		/* KEY-SCALE LEVEL/TOTAL LEVEL */
814c814
< 			case 0x60:		// ATTACK RATE/DECAY RATE
---
> 			case 0x60:		/* ATTACK RATE/DECAY RATE */
818c818
< 			case 0x80:		// SUSTAIN LEVEL/RELEASE RATE
---
> 			case 0x80:		/* SUSTAIN LEVEL/RELEASE RATE */
822c822
< 			case 0xE0:		// WAVE SELECT
---
> 			case 0xE0:		/* WAVE SELECT */
828c828
< 	return; // Writing to unused register - probably a bug
---
> 	return; /* Writing to unused register - probably a bug */
857,861c857,861
< 	int16_16	nCurrVol[18];					// Volume for each slot
< 	int16_16	nNowVol[18];					// What we actually multiply with..
< 	int			nCurrAdd[18];					// Frequency per channel
< 	int 		fPlaying[9];					// Is channel X playing??
< 	int 		nVibMul,nAMAdd; 				// Vibrato and Amplitude modulation numbers
---
> 	int16_16	nCurrVol[18];					/* Volume for each slot */
> 	int16_16	nNowVol[18];					/* What we actually multiply with.. */
> 	int			nCurrAdd[18];					/* Frequency per channel */
> 	int 		fPlaying[9];					/* Is channel X playing?? */
> 	int 		nVibMul,nAMAdd; 				/* Vibrato and Amplitude modulation numbers */
865c865
< 	float		vMulLevel,vTime;				// Temporary max volume level in envelope generator
---
> 	float		vMulLevel,vTime;				/* Temporary max volume level in envelope generator */
873c873
< // 16bit or 8bit samples?
---
> /* 16bit or 8bit samples? */
881c881
< 	nElapseTime = (nLength<<16) / pOPL->nReplayFrq;	// Time is in 16:16 format in seconds.
---
> 	nElapseTime = (nLength<<16) / pOPL->nReplayFrq;	/* Time is in 16:16 format in seconds. */
883c883
< // Update Timers
---
> /* Update Timers */
889c889
< // Do the subdivision stuff
---
> /* Do the subdivision stuff */
898c898
< // Check how many of the Rhythm sounds are playing..
---
> /* Check how many of the Rhythm sounds are playing.. */
920c920
< // Get values from and then update Vibrato and AMDepth sinus offsets.
---
> /* Get values from and then update Vibrato and AMDepth sinus offsets. */
922,923c922,923
< 		pOPL->nVibratoOffs += (int)(SINTABLE_SIZE * 6.4 * pOPL->nYM3812Clk / ym3812_StdClock / pOPL->nSubDivide * nElapseTime)>>16;	// Vibrato @ 6.4 Hz (3.6 MHz OPL)
< 		pOPL->nAMDepthOffs += (int)(SINTABLE_SIZE * 3.7 * pOPL->nYM3812Clk / ym3812_StdClock / pOPL->nSubDivide * nElapseTime)>>16;	// AMDepth @ 3.7 Hz (3.6 MHz OPL)
---
> 		pOPL->nVibratoOffs += (int)(SINTABLE_SIZE * 6.4 * pOPL->nYM3812Clk / ym3812_StdClock / pOPL->nSubDivide * nElapseTime)>>16;	/* Vibrato @ 6.4 Hz (3.6 MHz OPL) */
> 		pOPL->nAMDepthOffs += (int)(SINTABLE_SIZE * 3.7 * pOPL->nYM3812Clk / ym3812_StdClock / pOPL->nSubDivide * nElapseTime)>>16;	/* AMDepth @ 3.7 Hz (3.6 MHz OPL) */
925c925
< 		// Make vibrato only affect the frequency down. Depth is 7 or 14 cent.
---
> 		/* Make vibrato only affect the frequency down. Depth is 7 or 14 cent. */
929c929
< 		{	// 4.8 dB max Amplitude Modulation (48 out of 945 .1 dB)
---
> 		{	/* 4.8 dB max Amplitude Modulation (48 out of 945 .1 dB) */
933c933
< 		{	// 1.0 dB max Amplitude Modulation (10 out of 945 .1 dB)
---
> 		{	/* 1.0 dB max Amplitude Modulation (10 out of 945 .1 dB) */
939c939
< // Calculate frequency for each slot
---
> /* Calculate frequency for each slot */
943c943
< // Sometimes there's a pie, sometimes you're safe
---
> /* Sometimes there's a pie, sometimes you're safe */
948c948
< // Update currently playing envelopes (one per slot)
---
> /* Update currently playing envelopes (one per slot) */
965c965
< 				// Emulate KSL
---
> 				/* Emulate KSL */
979c979
< 				// Emulate amplitude modulation
---
> 				/* Emulate amplitude modulation */
991c991
< 						{	// The attack is actually linear, so this is not a typo.
---
> 						{	/* The attack is actually linear, so this is not a typo. */
993c993
< 							break;	// Do not fall through to Decay
---
> 							break;	/* Do not fall through to Decay */
999c999
< 						}	// Fall through to Decay..
---
> 						}	/* Fall through to Decay.. */
1008c1008
< 								break;	// Do not fall through to Sustain/Release
---
> 								break;	/* Do not fall through to Sustain/Release */
1016c1016
< 						// Fall through to Sustain/Release..
---
> 						/* Fall through to Sustain/Release.. */
1019c1019
< 						{	// Wait forever (until KeyOff)
---
> 						{	/* Wait forever (until KeyOff) */
1021c1021
< 							break; // No fall through to release
---
> 							break; /* No fall through to release */
1024c1024
< 						{	// No hold state in Sustain (Ignore KeyOff)
---
> 						{	/* No hold state in Sustain (Ignore KeyOff) */
1029c1029
< 						vTime = ym3812_aDecayTime[pOPL->nRelease[l]];	// Release timing = decay timing
---
> 						vTime = ym3812_aDecayTime[pOPL->nRelease[l]];	/* Release timing = decay timing */
1036c1036
< 						{	// Envelop has played and died
---
> 						{	/* Envelop has played and died */
1043c1043
< 				// Update envelop time for _NEXT_ frame
---
> 				/* Update envelop time for _NEXT_ frame */
1054c1054
< 		// Generate sample buffer
---
> 		/* Generate sample buffer */
1057c1057
< 			// Calculate one sample from all active FM channels
---
> 			/* Calculate one sample from all active FM channels */
1060c1060
< 			for( l=8; l>=0; --l )												// Do all channels
---
> 			for( l=8; l>=0; --l )												/* Do all channels */
1062c1062
< 				if( fPlaying[l] )												// Is this channel playing at all?
---
> 				if( fPlaying[l] )												/* Is this channel playing at all? */
1064,1065c1064,1065
< 					nSlot = l*2;												// Set Slot A
< 					nSlot2 = nSlot+1;											// Set Slot B
---
> 					nSlot = l*2;												/* Set Slot A */
> 					nSlot2 = nSlot+1;											/* Set Slot B */
1067c1067
< 					if( pOPL->nFeedback[l]==0 ) 								// Fix feedback
---
> 					if( pOPL->nFeedback[l]==0 ) 								/* Fix feedback */
1069c1069
< 						nOffs = (pOPL->nCurrPos[nSlot]/256)&(SINTABLE_SIZE-1);	// No feedback offset
---
> 						nOffs = (pOPL->nCurrPos[nSlot]/256)&(SINTABLE_SIZE-1);	/* No feedback offset */
1073c1073
< 						nOffs = ((pOPL->nCurrPos[nSlot]-(pOPL->nSinValue[nSlot]>>pOPL->nFeedback[l]))/256)&(SINTABLE_SIZE-1);// Add feedback offset
---
> 						nOffs = ((pOPL->nCurrPos[nSlot]-(pOPL->nSinValue[nSlot]>>pOPL->nFeedback[l]))/256)&(SINTABLE_SIZE-1);/* Add feedback offset */
1075c1075
< 					nSinValue = nNowVol[nSlot].parts[INTPART]*ym3812_aSinTable[pOPL->nWave[nSlot]][nOffs];			// Set old sample value
---
> 					nSinValue = nNowVol[nSlot].parts[INTPART]*ym3812_aSinTable[pOPL->nWave[nSlot]][nOffs];			/* Set old sample value */
1080c1080
< 					nOffs2 = (pOPL->nCurrPos[nSlot2] / 256)&(SINTABLE_SIZE-1);	// Calculate sintable offset this frame Slot B
---
> 					nOffs2 = (pOPL->nCurrPos[nSlot2] / 256)&(SINTABLE_SIZE-1);	/* Calculate sintable offset this frame Slot B */
1082c1082
< 					if( pOPL->fConnection[l] )									// Connect or Parallell?
---
> 					if( pOPL->fConnection[l] )									/* Connect or Parallell? */
1094,1095c1094,1095
< 					pOPL->nCurrPos[nSlot] += nCurrAdd[nSlot];					// Increase sintable offset Slot A
< 					pOPL->nCurrPos[nSlot2] += nCurrAdd[nSlot2]; 				// Increase sintable offset Slot B
---
> 					pOPL->nCurrPos[nSlot] += nCurrAdd[nSlot];					/* Increase sintable offset Slot A */
> 					pOPL->nCurrPos[nSlot2] += nCurrAdd[nSlot2]; 				/* Increase sintable offset Slot B */
1108c1108
< 			// Put sample value into sample buffer
---
> 			/* Put sample value into sample buffer */
