Exemple #1
0
int SndOpen()
{
unsigned int BufferSize;
unsigned int bufferStart;

	BufferSize = (nBurnSoundLen * nAudioChannels * AUDIO_BLOCKS)*2+512;
	EzxAudioBuffer= (unsigned short *)malloc(BufferSize);
	AudioBufferSize = nBurnSoundLen * nAudioChannels * 2;
	memset(EzxAudioBuffer,0,BufferSize);
	EzxAudioBuffer[1]=(EzxAudioBuffer[0]=(nBurnSoundLen * nAudioChannels * 2));
	EzxAudioBuffer[2]=(1000000000/nBurnSoundRate)&0xFFFF;
	EzxAudioBuffer[3]=(1000000000/nBurnSoundRate)>>16;
	bufferStart = (unsigned int)&EzxAudioBuffer[4];
	pOutput[0] = (short*)bufferStart;
	pOutput[1] = (short*)(bufferStart+1*EzxAudioBuffer[1]);
	pOutput[2] = (short*)(bufferStart+2*EzxAudioBuffer[1]);
	pOutput[3] = (short*)(bufferStart+3*EzxAudioBuffer[1]);
	pOutput[4] = (short*)(bufferStart+4*EzxAudioBuffer[1]);
	pOutput[5] = (short*)(bufferStart+5*EzxAudioBuffer[1]);
	pOutput[6] = (short*)(bufferStart+6*EzxAudioBuffer[1]);
	pOutput[7] = (short*)(bufferStart+7*EzxAudioBuffer[1]);
	if ( !GameMute )
	{
	int frag = 10 + config_options.option_samplerate;
    	frag |= 2 << 16;


		if (config_options.option_sound_enable==1)
		{
		    dspfd = ezx_open_dsp ( nBurnSoundRate, nAudioChannels, AUDIO_FORMAT, frag );
            if (dspfd >= 0)
            {
                pthread_create(&soundthread_p, NULL, &soundthread_f, NULL);
                return 0;
            }
		}
		if (config_options.option_sound_enable==2)
		{
            for(int i=0;i<NUM_BUFS;i++) buffer[i]=(unsigned char *) malloc(BUFFSIZE);
            SAMPLESIZE=512;  //lowest value accepted by audio driver
            dspfd=configure(nBurnSoundRate,nAudioChannels,AUDIO_S16);
		}
		// printf("SOUND: Init done (%d)\n", dspfd);
		if (((dspfd > 0)  && (config_options.option_sound_enable==2))  || ((dspfd>=0) && (config_options.option_sound_enable==1)))
		{
		    if (config_options.option_sound_enable==2) pBurnSoundOut  = (short*)pOutput[0];
		    if (config_options.option_sound_enable==2) audio_resume();


			return 0;
		}
		else
		{
			nBurnSoundRate	= 0;
			nBurnSoundLen	= 0;
		}
	}
	sampletime=EZX_GetTicks();
	return -1;
}
Exemple #2
0
void run_fba_emulator(const char *fn)
{
	char build_version[] = "Finalburn Alpha Plus for Pi  ("__DATE__")";

	// process rom path and name
	char romname[MAX_PATH];
	if (BurnCacheInit(fn, romname))
		goto finish;

	if(config_options.option_showfps)
		bShowFPS=true;

	BurnLibInit();
	
	// find rom by name
	for (nBurnDrvSelect=0; nBurnDrvSelect<nBurnDrvCount; nBurnDrvSelect++)
		if ( strcasecmp(romname, BurnDrvGetTextA(DRV_NAME)) == 0 )
			break;
	if (nBurnDrvSelect >= nBurnDrvCount) {
		// unsupport rom ...
		nBurnDrvSelect = ~0U;
		logoutput ("rom not supported!\n");
		printf ("rom not supported!\n");
		goto finish;
	}
	
	logoutput("Attempt to initialise '%s'\n", BurnDrvGetTextA(DRV_FULLNAME));
	
	memset (titlefb, 0, 320*240*2);
	DrawString (build_version, (uint16*)&titlefb, 10, 20, 320);
	DrawString ("Based on FinalBurnAlpha", (uint16*)&titlefb, 10, 35, 320);
	DrawString ("Now loading ... ", (uint16 *)&titlefb, 10, 105, 320);	
	show_rom_loading_text("Open Zip", 0, 0);
	memcpy (VideoBuffer, titlefb, 320*240*2); 
	pi_video_flip();
	 	
	InpInit();
	InpDIP();
	
	VideoInit();

	if (DrvInit(nBurnDrvSelect, false) != 0) {
		logoutput ("Driver initialisation failed! Likely causes are:\n- Corrupt/Missing ROM(s)\n- I/O Error\n- Memory error\n\n");
		printf ("Driver initialisation failed! Likely causes are:\n- Corrupt/Missing ROM(s)\n- I/O Error\n- Memory error\n\n");
		goto finish;
	}

	RunReset();

	frame_count = 0;
	GameLooping = true;

	EZX_StartTicks();

	logoutput ("Lets go!\n");
	logflush();

	if (config_options.option_sound_enable)
	{
		int timer = 0, tick=0, i=0, fps = 0;
		bool bRenderFrame;

		if (SndOpen() == 0)
		{		
			while (GameLooping)
			{
					if (bShowFPS)
					{
						timer = EZX_GetTicks();
						if(timer-tick>1000000)
						{
							fps = nFramesRendered;
							nFramesRendered = 0;
							tick = timer;
						}
					}
					//We need to render more audio:  
		
					bRenderFrame=true; // Render last frame
					RunOneFrame(bRenderFrame,fps);

					update_audio_stream(pBurnSoundOut);
					pi_process_events();
			}
		}
	}
	else
	{
		int now, done=0, timer = 0, ticks=0, tick=0, i=0, fps = 0;
		unsigned int frame_limit = nBurnFPS/100, frametime = 100000000/nBurnFPS;
		
		while (GameLooping)
		{
			timer = EZX_GetTicks()/frametime;;
			if(timer-tick>frame_limit && bShowFPS)
			{
				fps = nFramesRendered;
				nFramesRendered = 0;
				tick = timer;
			}
			now = timer;
			ticks=now-done;
			if(ticks<1) continue;
			if(ticks>10) ticks=10;
			for (i=0; i<ticks-1; i++)
			{
				RunOneFrame(false,fps);	
			} 
			if(ticks>=1)
			{
				RunOneFrame(true,fps);	
			}
			
			done = now;
		}
	}
	
	logoutput ("Finished emulating\n");
	
finish:
	logoutput("---- Shutdown Finalburn Alpha plus ----\n\n");
	DrvExit();
	BurnLibExit();

	if (config_options.option_sound_enable)
		SndExit();
	VideoExit();
	InpExit();
	BurnCacheExit();
}