Esempio n. 1
0
void main_set_framerate() {
	// Set the framerate based on region
	Machine machine(emulator);
	Cartridge::Database database(emulator);

	framerate = 60;
	if (conf->misc_video_region == 2) {
		machine.SetMode(Machine::PAL);
		framerate = 50;
	}
	else if (conf->misc_video_region == 1) {
		machine.SetMode(Machine::NTSC);
	}
	else {
		if (database.IsLoaded()) {
			if (dbentry.GetSystem() == Cartridge::Profile::System::NES_PAL) {
				machine.SetMode(Machine::PAL);
				framerate = 50;
			}
			else {
				machine.SetMode(Machine::NTSC);
			}
		}
		else {
			machine.SetMode(machine.GetDesiredMode());
		}
	}
}
Esempio n. 2
0
void SetupVideo()
{
	// renderstate structure
	Video::RenderState renderState;
	Machine machine( emulator );
	Cartridge::Database database( emulator );
	Video::RenderState::Filter filter;
	int scalefactor = sSettings->GetScaleAmt() + 1;
	int i;

	// init SDL
	if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))
	{
		std::cout << "Unable to init SDL\n";
		return;
	}

	// figure out the region
	framerate = 60;
	if (sSettings->GetVideoMode() == 2)		// force PAL
	{
		machine.SetMode(Machine::PAL);
		framerate = 50;
	}
	else if (sSettings->GetVideoMode() == 1) 	// force NTSC
	{
		machine.SetMode(Machine::NTSC);
	}
	else	// auto
	{
		if (database.IsLoaded())
		{
			if (dbentry.GetSystem() == Cartridge::Profile::System::NES_PAL)
			{
				machine.SetMode(Machine::PAL);
				framerate = 50;
			}
			else
			{
				machine.SetMode(Machine::NTSC);
			}
		}
		else
		{
			machine.SetMode(machine.GetDesiredMode());
		}
	}

	// we don't create a window in NSF mode
	if (nsf_mode) 
	{
		return;
	}

	if (SDL_NumJoysticks() > 0)
	{
		for (i = 0; i < SDL_NumJoysticks(); i++)
		{
			// we only? support 10 joysticks
			if (i < 10)
			{
				joy[i] = SDL_JoystickOpen(i);
			}
		}

		SDL_JoystickEventState(SDL_ENABLE);	// turn on regular updates
	}
	
	get_screen_res();

	// compute the major video parameters from the scaler type and scale factor
	switch (sSettings->GetScale())
	{
		case 0:	// None (no scaling unless OpenGL)
			filter = Video::RenderState::FILTER_NONE;
			break;

		case 1: // NTSC
			filter = Video::RenderState::FILTER_NTSC;
			break;

		case 2: // scale x
			switch (scalefactor)
			{
				case 2:
					filter = Video::RenderState::FILTER_SCALE2X;
					break;

				case 3:
					filter = Video::RenderState::FILTER_SCALE3X;
					break;

				default:
					filter = Video::RenderState::FILTER_NONE;
					break;
			}
			break;

		case 3: // scale HQx
			switch (scalefactor)
			{
				case 2:
					filter = Video::RenderState::FILTER_HQ2X;
					break;

				case 3:
					filter = Video::RenderState::FILTER_HQ3X;
					break;

				case 4:
					filter = Video::RenderState::FILTER_HQ4X;
					break;

				default:
					filter = Video::RenderState::FILTER_NONE;
					break;
			}
			break;
		
		case 4: // 2xSaI
			filter = Video::RenderState::FILTER_2XSAI;
			break;
	}

	int eFlags = SDL_HWSURFACE;
        using_opengl = (sSettings->GetRenderType() > 0);
	linear_filter = (sSettings->GetRenderType() == 2);
	if (using_opengl)
	{
		SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
		eFlags = SDL_OPENGL;
	}

	if (sSettings->GetFullscreen())
	{
		GdkScreen *gdkscreen = gdk_screen_get_default();
		
		int fullscreen = sSettings->GetFullscreen();
		int fsnativeres = sSettings->GetFsNativeRes();

		if (fullscreen && fsnativeres && using_opengl) {	// Force native resolution in fullscreen mode
			cur_Rwidth = gdk_screen_get_width(gdkscreen);
			cur_Rheight = gdk_screen_get_height(gdkscreen);
		}
		screen = SDL_SetVideoMode(cur_Rwidth, cur_Rheight, 16, SDL_ANYFORMAT | SDL_DOUBLEBUF | SDL_FULLSCREEN | eFlags);
	}
	else
	{
		screen = SDL_SetVideoMode(cur_Rwidth, cur_Rheight, 16, SDL_ANYFORMAT | SDL_DOUBLEBUF | eFlags);
	}

	if (!screen)
	{
		std::cout << "SDL couldn't set video mode\n";
		exit(-1);
	}

	renderState.filter = filter;
	renderState.width = cur_width;
	renderState.height = cur_height;

	// example configuration
	if (using_opengl)
	{
		opengl_init_structures();

		renderState.bits.count = 32;
		renderState.bits.mask.r = 0x00ff0000;
		renderState.bits.mask.g = 0x0000ff00;
		renderState.bits.mask.b = 0x000000ff;
	}
	else
	{
		renderState.bits.count = screen->format->BitsPerPixel;
		renderState.bits.mask.r = screen->format->Rmask;
		renderState.bits.mask.g = screen->format->Gmask;
		renderState.bits.mask.b = screen->format->Bmask;
	}

	// allocate the intermediate render buffer
	intbuffer = malloc(renderState.bits.count * renderState.width * renderState.height);

	// acquire the video interface
	Video video( emulator );

	// set the sprite limit
	video.EnableUnlimSprites(sSettings->GetSprlimit() ? false : true);

	// set up the NTSC type
	switch (sSettings->GetNtscMode())
	{
		case 0:	// composite
			video.SetSharpness(Video::DEFAULT_SHARPNESS_COMP);
			video.SetColorResolution(Video::DEFAULT_COLOR_RESOLUTION_COMP);
			video.SetColorBleed(Video::DEFAULT_COLOR_BLEED_COMP);
			video.SetColorArtifacts(Video::DEFAULT_COLOR_ARTIFACTS_COMP);
			video.SetColorFringing(Video::DEFAULT_COLOR_FRINGING_COMP);
			break;

		case 1:	// S-Video
			video.SetSharpness(Video::DEFAULT_SHARPNESS_SVIDEO);
			video.SetColorResolution(Video::DEFAULT_COLOR_RESOLUTION_SVIDEO);
			video.SetColorBleed(Video::DEFAULT_COLOR_BLEED_SVIDEO);
			video.SetColorArtifacts(Video::DEFAULT_COLOR_ARTIFACTS_SVIDEO);
			video.SetColorFringing(Video::DEFAULT_COLOR_FRINGING_SVIDEO);
			break;

		case 2:	// RGB
			video.SetSharpness(Video::DEFAULT_SHARPNESS_RGB);
			video.SetColorResolution(Video::DEFAULT_COLOR_RESOLUTION_RGB);
			video.SetColorBleed(Video::DEFAULT_COLOR_BLEED_RGB);
			video.SetColorArtifacts(Video::DEFAULT_COLOR_ARTIFACTS_RGB);
			video.SetColorFringing(Video::DEFAULT_COLOR_FRINGING_RGB);
			break;
	}
			     
	// set the render state
	if (NES_FAILED(video.SetRenderState( renderState )))
	{
		std::cout << "Nestopia core rejected render state\n";
		::exit(0);
	}

	if (sSettings->GetFullscreen())
	{
		SDL_ShowCursor(0);
	}
}