⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x11.cpp

📁 SFC游戏模拟器 snes9x 1.43 的原代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	int k = 6 - 1;	cr = (r * k) / MAX_RED;	q  = (r * k) % MAX_RED;	if (q > d && cr < k) 	    cr++;	diffr = abs (cr * k - r);	for (g = 0; g <= (int) MAX_GREEN; g++)	{	    int cg, b;	  	    k  = 6 - 1;	    cg = (g * k) / MAX_GREEN;	    q  = (g * k) % MAX_GREEN;	    if(q > d && cg < k)		cg++;	    diffg = abs (cg * k - g);	    for (b = 0; b <= (int) MAX_BLUE; b++) 	    {		int cb;		int rgb = BUILD_PIXEL2(r, g, b);		k  = 6 - 1;		cb = (b * k) / MAX_BLUE;		q  = (b * k) % MAX_BLUE;		if (q > d && cb < k)		    cb++;		diffb = abs (cb * k - b);		GUI.palette[rgb] = (cr * 6 + cg) * 6 + cb;		color_diff[rgb] = diffr + diffg + diffb;		if (color_diff[rgb] > maxdiff)		    maxdiff = color_diff[rgb];	    }	}    }    while (maxdiff > 0 && l < 256)    {	int newmaxdiff = 0;	lost = 0; won++;	for (r = MAX_RED; r >= 0; r--)	{	    int g;      	    for (g = MAX_GREEN; g >= 0; g--)	    {		int b;	  		for (b = MAX_BLUE; b >= 0; b--) 		{		    int rgb = BUILD_PIXEL2(r, g, b);		    if (color_diff[rgb] == maxdiff)		    {			if (l >= 256)			    lost++;			else			{			    GUI.fixed_colours [l].red = r;			    GUI.fixed_colours [l].green = g;			    GUI.fixed_colours [l].blue = b;			    GUI.palette [rgb] = l;			    l++;			}			color_diff[rgb] = 0;		    }		    else			if (color_diff[rgb] > newmaxdiff)			    newmaxdiff = color_diff[rgb];		    		}	    }	}	maxdiff = newmaxdiff;    }    delete[] color_diff;    XSetWindowAttributes attrib;    attrib.background_pixel = BlackPixelOfScreen (GUI.screen);    GUI.window = XCreateWindow (GUI.display, RootWindowOfScreen (GUI.screen),				(WidthOfScreen(GUI.screen) - GUI.window_width) / 2,				(HeightOfScreen(GUI.screen) - GUI.window_height) / 2,				GUI.window_width, GUI.window_height, 0, 				GUI.depth, InputOutput, GUI.visual, 				CWBackPixel, &attrib);#ifdef USE_DGA_EXTENSION    CreateFullScreenWindow ();#endif    static XColor bg;    static XColor fg;    static char data [8] = { 0x01 };    Pixmap bitmap = XCreateBitmapFromData (GUI.display, GUI.window, data, 8, 8);    GUI.point_cursor = XCreatePixmapCursor (GUI.display, bitmap, bitmap, &fg, &bg, 0, 0);    XDefineCursor (GUI.display, GUI.window, GUI.point_cursor);#ifdef USE_DGA_EXTENSION    if (XF86.full_screen_available)	XDefineCursor (GUI.display, XF86.fs_window, GUI.point_cursor);#endif    GUI.cross_hair_cursor = XCreateFontCursor (GUI.display, XC_crosshair);    GUI.gc = DefaultGCOfScreen (GUI.screen);    {        XSizeHints Hints;	XWMHints WMHints;	memset ((void *) &Hints, 0, sizeof (XSizeHints));	memset ((void *) &WMHints, 0, sizeof (XWMHints));	Hints.flags = PSize | PMinSize;	Hints.min_width = Hints.base_width = SNES_WIDTH;	Hints.min_height = Hints.base_height = SNES_HEIGHT_EXTENDED;	WMHints.input = True;	WMHints.flags = InputHint;	XSetWMHints (GUI.display, GUI.window, &WMHints);	XSetWMNormalHints (GUI.display, GUI.window, &Hints);    }    XSelectInput (GUI.display, GUI.window, FocusChangeMask | ExposureMask |		  KeyPressMask | KeyReleaseMask | StructureNotifyMask |		  ButtonPressMask | ButtonReleaseMask);#ifdef USE_DGA_EXTENSION    if (XF86.full_screen_available)	XSelectInput (GUI.display, XF86.fs_window, FocusChangeMask | ExposureMask |		      KeyPressMask | KeyReleaseMask | StructureNotifyMask |		      ButtonPressMask | ButtonReleaseMask);#endif    if (GUI.pseudo)    {	GUI.cmap = XCreateColormap (GUI.display, GUI.window, GUI.visual, True);	XSetWindowColormap (GUI.display, GUI.window, GUI.cmap);	for (i = 0; i < 256; i++)	{	    GUI.colors[i].red = GUI.colors[i].green = GUI.colors[i].blue = 0;	    GUI.colors[i].pixel = i;	    GUI.colors[i].flags = DoRed | DoGreen | DoBlue;	}	XStoreColors (GUI.display, GUI.cmap, GUI.colors, 256);    }    XMapRaised (GUI.display, GUI.window);    XClearWindow (GUI.display, GUI.window);    SetupImage ();    switch (GUI.depth)    {    case 8:	GUI.bytes_per_pixel = 1;	break;    case 15:    case 16:	GUI.bytes_per_pixel = 2;	break;    case 24:	if (GUI.image->bits_per_pixel == 24)	    GUI.bytes_per_pixel = 3;	else	    GUI.bytes_per_pixel = 4;	break;    case 32:	GUI.bytes_per_pixel = 4;	break;    }#if 0    app = new QApplication (GUI.display);    gui = new Snes9xGUI ();    app->setMainWidget (gui);    gui->show ();#endif#ifdef USE_OPENGL    if (Settings.OpenGLEnable)	S9xOpenGLInit2 ();#endif#ifdef USE_GLIDE    putenv("FX_GLIDE_NO_SPLASH=");    S9xSwitchToGlideMode (TRUE);#endif}void SetupImage (){    int tf = 0;    int image_width = GUI.window_width;    int image_height = GUI.window_height;    if (image_width < IMAGE_WIDTH)	image_width = IMAGE_WIDTH;    if (image_height < IMAGE_HEIGHT)	image_height = IMAGE_HEIGHT;    if (GUI.interpolate)    {	if (image_width < 512)	    image_width = 512;	if (image_height < 239 * 2)	    image_height = 239 * 2;	GUI.image_needs_scaling = (GUI.window_width != 512 || 				   GUI.window_height != 239 * 2) &&				   GUI.interpolate != 5;    }    else    {	GUI.image_needs_scaling = GUI.window_width != IMAGE_WIDTH ||				  GUI.window_height != IMAGE_HEIGHT ||				  GUI.scale#ifdef USE_DGA_EXTENSION				  || (XF86.is_full_screen && XF86.scale)#endif				  ;    }    uint32 i;    for (i = 0; i < sizeof (GUI.to_free) / sizeof (GUI.to_free [0]); i++)	if (GUI.to_free [i])	{	    free (GUI.to_free [i]);	    GUI.to_free [i] = NULL;	}    if (GUI.image)    {#ifdef MITSHM	if (GUI.use_shared_memory)	{	    XShmDetach (GUI.display, &GUI.sm_info);	    GUI.image->data = NULL;	    XDestroyImage (GUI.image);	    if (GUI.sm_info.shmaddr)		shmdt (GUI.sm_info.shmaddr);	    if (GUI.sm_info.shmid >= 0)		shmctl (GUI.sm_info.shmid, IPC_RMID, 0);	    GUI.image = NULL;        }	else#endif	{	    XDestroyImage (GUI.image);	    GUI.image = NULL;	}    }#ifdef MITSHM    GUI.use_shared_memory = 1;    int major, minor;    Bool shared;    if (!XShmQueryVersion (GUI.display, &major, &minor, &shared) || !shared)	GUI.image = NULL;    else	GUI.image = XShmCreateImage (GUI.display, GUI.visual, GUI.depth, ZPixmap, NULL, &GUI.sm_info,				     image_width, image_height);    if (!GUI.image)    {	fprintf (stderr, "XShmCreateImage failed, switching to XPutImage\n");	GUI.use_shared_memory = 0;    }    else    {	GUI.sm_info.shmid = shmget (IPC_PRIVATE, 				    GUI.image->bytes_per_line * GUI.image->height,				    IPC_CREAT | 0777);	if (GUI.sm_info.shmid < 0)	{	    fprintf (stderr, "shmget failed, switching to XPutImage\n");	    XDestroyImage (GUI.image);	    GUI.use_shared_memory = 0;	}	else	{	    GUI.image->data = GUI.sm_info.shmaddr = (char *) shmat (GUI.sm_info.shmid, 0, 0);	    if (!GUI.image->data)	    {		fprintf (stderr, "shmat failed, switching to XPutImage\n");		XDestroyImage (GUI.image);		shmctl (GUI.sm_info.shmid, IPC_RMID, 0);		GUI.use_shared_memory = 0;	    }	    else	    {		GUI.sm_info.readOnly = False;		XErrorHandler error_handler = XSetErrorHandler (ErrorHandler);		XShmAttach (GUI.display, &GUI.sm_info);		XSync (GUI.display, False);		(void) XSetErrorHandler (error_handler);		// X Error handler might clear GUI.use_shared_memory if XShmAttach failed		if (!GUI.use_shared_memory)		{		    fprintf (stderr, "XShmAttach failed, switching to XPutImage\n");		    XDestroyImage (GUI.image);		    shmdt (GUI.sm_info.shmaddr);		    shmctl (GUI.sm_info.shmid, IPC_RMID, 0);		}	    }	}    }    if (!GUI.use_shared_memory)    {#endif	GUI.image = XCreateImage (GUI.display, GUI.visual, GUI.depth, ZPixmap, 0,				  (char *) NULL, image_width, image_height,				  BitmapUnit (GUI.display), 0);	GUI.image->data = (char *) malloc (image_height *					   GUI.image->bytes_per_line);#ifdef LSB_FIRST	GUI.image->byte_order = LSBFirst;#else	GUI.image->byte_order = MSBFirst;#endif#ifdef MITSHM    }#endif    int h = IMAGE_HEIGHT;    if (!Settings.SixteenBit)    {	if (GUI.image_needs_scaling || GUI.depth != 8)	{	    GFX.Screen = (uint8 *) (GUI.to_free [tf++] = malloc (IMAGE_WIDTH * h));	    GFX.Pitch = IMAGE_WIDTH;	}	else	{	    GFX.Screen = (uint8 *) GUI.image->data;	    GFX.Pitch = GUI.image->bytes_per_line;	}	GFX.SubScreen = NULL;	GFX.ZBuffer = (uint8 *) (GUI.to_free [tf++] = malloc (GFX.Pitch * h));	GFX.SubZBuffer = NULL;    }    else    if (GUI.depth == 8)    {	if (GUI.interpolate)	{	    GFX.Pitch = (IMAGE_WIDTH + 4) * 2;	    h += 2;	}	else	    GFX.Pitch = IMAGE_WIDTH * 2;	GFX.Screen = (uint8 *) (GUI.to_free [tf++] = malloc (GFX.Pitch * h));	GFX.SubScreen = (uint8 *) (GUI.to_free [tf++] = malloc (GFX.Pitch * h));	GFX.ZBuffer = (uint8 *) (GUI.to_free [tf++] = malloc ((GFX.Pitch >> 1) * h));	GFX.SubZBuffer = (uint8 *) (GUI.to_free [tf++] = malloc ((GFX.Pitch >> 1) * h));	if (GUI.interpolate)	{	    GUI.interpolated_screen = (uint8 *) (GUI.to_free [tf++] = malloc (512 * 478 * 2));	    GUI.delta_screen = (uint8 *) (GUI.to_free [tf++] = malloc (GFX.Pitch * h));	}    }    else    {	if ((GUI.depth != 15 && GUI.depth != 16) || GUI.interpolate)	{	    if (GUI.interpolate)	    {		GFX.Pitch = (IMAGE_WIDTH + 4) * 2;		h += 2;	    }	    else		GFX.Pitch = IMAGE_WIDTH * 2;	    GFX.Screen = (uint8 *) (GUI.to_free [tf++] = malloc (GFX.Pitch * h));	    if (GUI.interpolate)	    {		if (GUI.image_needs_scaling || (GUI.depth != 15 && GUI.depth != 16)#ifdef USE_DGA_EXTENSION		    || XF86.scale#endif)		GUI.interpolated_screen = (uint8 *) (GUI.to_free [tf++] = malloc (512 * 478 * 2));		GUI.delta_screen = (uint8 *) (GUI.to_free [tf++] = malloc (GFX.Pitch * h));	    }	}	else	{	    GFX.Screen = (uint8 *) GUI.image->data;	    GFX.Pitch = GUI.image->bytes_per_line;	}	GFX.SubScreen = (uint8 *) (GUI.to_free [tf++] = malloc (GFX.Pitch * h));	GFX.ZBuffer = (uint8 *) (GUI.to_free [tf++] = malloc ((GFX.Pitch >> 1) * h));	GFX.SubZBuffer = (uint8 *) (GUI.to_free [tf++] = malloc ((GFX.Pitch >> 1) * h));    }    GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1;    ZeroMemory (GFX.Screen, GFX.Pitch * h);    if ((uint8 *) GUI.image->data != GFX.Screen)	ZeroMemory (GUI.image->data, GUI.image->bytes_per_line * GUI.image->height);    if (GUI.delta_screen)	memset (GUI.delta_screen, 0xff, GFX.Pitch * h);    if (GUI.interpolated_screen)	ZeroMemory (GUI.interpolated_screen, 512 * 478 * 2);    if (Settings.SixteenBit && GUI.interpolate)    {	// Offset the rendering of the SNES image by at least one pixel because	// Kreed's interpolation routines read one pixel beyond the bounds of	// the source image buffer.	GFX.Screen += GFX.Pitch + sizeof (uint16) * 2;    }    GUI.image_date = (uint8 *) GUI.image->data;    GUI.bytes_per_line = GUI.image->bytes_per_line;}int ErrorHandler (Display *, XErrorEvent *){#ifdef MITSHM    GUI.use_shared_memory = 0;#endif    return (0);}void S9xSetTitle (const char *string)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -