コード例 #1
0
static void *ym2151_start(int sndindex, int clock, const void *config)
{
	static const struct YM2151interface dummy = { 0 };
	int rate = Machine->sample_rate;
	struct ym2151_info *info;

	info = auto_malloc(sizeof(*info));
	memset(info, 0, sizeof(*info));

	info->intf = config ? config : &dummy;

	if( rate == 0 ) rate = 1000;	/* kludge to prevent nasty crashes */

	rate = clock/64;

	/* stream setup */
	info->stream = stream_create(0,2,rate,info,ym2151_update);

	info->chip = YM2151Init(sndindex,clock,rate);

	state_save_register_func_postload_ptr(ym2151_postload, info);

	if (info->chip != 0)
	{
		YM2151SetIrqHandler(info->chip,info->intf->irqhandler);
		YM2151SetPortWriteHandler(info->chip,info->intf->portwritehandler);
		return info;
	}
	return NULL;
}
コード例 #2
0
ファイル: 2151intf.c プロジェクト: Bremma/pinmame
static int my_YM2151_sh_start(const struct MachineSound *msound,int mode)
{
	int i,j;
	int rate = Machine->sample_rate;
	char buf[YM2151_NUMBUF][40];
	const char *name[YM2151_NUMBUF];
	int mixed_vol,vol[YM2151_NUMBUF];

	if( rate == 0 ) rate = 1000;	/* kludge to prevent nasty crashes */

	intf = msound->sound_interface;

	if( mode ) FMMode = CHIP_YM2151_ALT;
	else       FMMode = CHIP_YM2151_DAC;

	switch(FMMode)
	{
#if (HAS_YM2151)
	case CHIP_YM2151_DAC:	/* Tatsuyuki's */
		/* stream system initialize */
		for (i = 0;i < intf->num;i++)
		{
			mixed_vol = intf->volume[i];
			/* stream setup */
			for (j = 0 ; j < YM2151_NUMBUF ; j++)
			{
				name[j]=buf[j];
				vol[j] = mixed_vol & 0xffff;
				mixed_vol>>=16;
				sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
			}
			stream[i] = stream_init_multi(YM2151_NUMBUF,
				name,vol,rate,i,OPMUpdateOne);
		}
		/* Set Timer handler */
		for (i = 0; i < intf->num; i++)
		{
			Timer[i][0] = timer_alloc(timer_callback_2151);
			Timer[i][1] = timer_alloc(timer_callback_2151);
		}
		if (OPMInit(intf->num,intf->baseclock,Machine->sample_rate,TimerHandler,IRQHandler) == 0)
		{
			/* set port handler */
			for (i = 0; i < intf->num; i++)
				OPMSetPortHander(i,intf->portwritehandler[i]);
			return 0;
		}
		/* error */
		return 1;
#endif
#if (HAS_YM2151_ALT)
	case CHIP_YM2151_ALT:	/* Jarek's */

		if (options.use_filter)
			rate = intf->baseclock/64;

		/* stream system initialize */
		for (i = 0;i < intf->num;i++)
		{
			/* stream setup */
			mixed_vol = intf->volume[i];
			for (j = 0 ; j < YM2151_NUMBUF ; j++)
			{
				name[j]=buf[j];
				vol[j] = mixed_vol & 0xffff;
				mixed_vol>>=16;
				sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
			}
			stream[i] = stream_init_multi(YM2151_NUMBUF,
				name,vol,rate,i,YM2151UpdateOne);
		}

		if (YM2151Init(intf->num,intf->baseclock,rate) == 0)
		{
			for (i = 0; i < intf->num; i++)
			{
				YM2151SetIrqHandler(i,intf->irqhandler[i]);
				YM2151SetPortWriteHandler(i,intf->portwritehandler[i]);
			}
			return 0;
		}
		return 1;
#endif
	}
	return 1;
}
コード例 #3
0
ファイル: 2151intf.cpp プロジェクト: cyberkni/276in1JAMMA
int YM2151_sh_start(struct YM2151interface *interface,int mode)
{
	int i,j;
	int rate = Machine->sample_rate;
	char buf[YM2151_NUMBUF][40];
	const char *name[YM2151_NUMBUF];
	int vol;

	if( rate == 0 ) rate = 1000;	/* kludge to prevent nasty crashes */

	intf = interface;

	if( mode ) FMMode = CHIP_YM2151_ALT;
	else       FMMode = CHIP_YM2151_DAC;

	switch(FMMode)
	{
	case CHIP_YM2151_DAC:	/* Tatsuyuki's */
		/* stream system initialize */
		for (i = 0;i < intf->num;i++)
		{
			/* stream setup */
			for (j = 0 ; j < YM2151_NUMBUF ; j++)
			{
				char *chname[2] = { "Lt", "Rt" };
				int ch;


				name[j] = buf[j];
				ch = j & 1;
				if (intf->volume[i] & YM2151_STEREO_REVERSE)
					ch ^= 1;
				sprintf(buf[j],"YM2151 #%d %s",i,chname[ch]);
			}
			stream[i] = stream_init_multi(YM2151_NUMBUF,
				name,(int)(((double)rate)/snd_opm_reduction),Machine->sample_bits,
				i,OPMUpdateOne);
			/* volume setup */
			vol = intf->volume[i] & 0xff;
			for( j=0 ; j < YM2151_NUMBUF ; j++ )
			{
				int ch;

				ch = j & 1;
				if (intf->volume[i] & YM2151_STEREO_REVERSE)
					ch ^= 1;

				stream_set_volume(stream[i]+j,vol);
				stream_set_pan(stream[i]+j,ch ? OSD_PAN_RIGHT : OSD_PAN_LEFT);
			}
		}
		/* Set Timer handler */
		for (i = 0; i < intf->num; i++)
			Timer[i][0] =Timer[i][1] = 0;
		if (OPMInit(intf->num,
//			intf->baseclock,
			((100.0-((snd_opm_reduction-1.0)*10.0))*((double)intf->baseclock))/100.0,
//			Machine->sample_rate,
			((100.0-((snd_opm_reduction-1.0)*10.0))*((double)Machine->sample_rate))/100.0,
			Machine->sample_bits,TimerHandler,0) == 0)
		{
			/* set port handler */
			for (i = 0; i < intf->num; i++)
				OPMSetPortHander(i,intf->portwritehandler[i]);
			return 0;
		}
		/* error */
		return 1;
	case CHIP_YM2151_ALT:	/* Jarek's */
		/* stream system initialize */
		for (i = 0;i < intf->num;i++)
		{
			/* stream setup */
			for (j = 0 ; j < YM2151_NUMBUF ; j++)
			{
				char *chname[2] = { "Lt", "Rt" };
				int ch;


				name[j] = buf[j];
				ch = j & 1;
				if (intf->volume[i] & YM2151_STEREO_REVERSE)
					ch ^= 1;
				sprintf(buf[j],"YM2151 #%d %s",i,chname[ch]);
			}
			stream[i] = stream_init_multi(YM2151_NUMBUF,
				name,rate,Machine->sample_bits,
				i,YM2151UpdateOne);
			/* volume setup */
			vol = intf->volume[i] & 0xff;
			for( j=0 ; j < YM2151_NUMBUF ; j++ )
			{
				int ch;

				ch = j & 1;
				if (intf->volume[i] & YM2151_STEREO_REVERSE)
					ch ^= 1;

				stream_set_volume(stream[i]+j,vol);
				stream_set_pan(stream[i]+j,ch ? OSD_PAN_RIGHT : OSD_PAN_LEFT);
			}
		}
		if (YM2151Init(intf->num,intf->baseclock,Machine->sample_rate,Machine->sample_bits) == 0)
		{
			for (i = 0; i < intf->num; i++)
			{
				YM2151SetIrqHandler(i,intf->irqhandler[i]);
				YM2151SetPortWriteHandler(i,intf->portwritehandler[i]);
			}
			return 0;
		}
		return 1;
	case CHIP_YM2151_OPL:
		break;
	}
	return 1;
}