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

📄 x11.cpp

📁 著名SFC模拟器Snes9x的源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		// Order is BGR		for (register int x = 0; x < GUI.window_width; x++)		{		    uint32 pixel = *s;		    *d++ = (pixel & 0x1f) << 3;		    *d++ = (pixel >> (6 - 3)) & 0xf8;		    *d++ = (pixel >> (11 - 3)) & 0xf8;		       		    x_error += x_fraction;		    while (x_error >= 0x10000)		    {			s++;			x_error -= 0x10000;		    }		}	    }	}    }}void Convert16To8 (int width, int height){    if (!GUI.image_needs_scaling)    {	// Convert	for (register int y = 0; y < height; y++)	{	    register uint8 *d = (uint8 *) GUI.image_date + y * GUI.bytes_per_line;	    register uint16 *s = (uint16 *) (GUI.output_screen + y * GUI.output_pitch);	    for (register int x = 0; x < width; x++)		*d++ = GUI.palette [*s++];	}    }    else    {	// Scale and convert	register uint32 x_error;	register uint32 x_fraction;	uint32 y_error = 0;	uint32 y_fraction;	int yy = 0;		x_fraction = (width * 0x10000) / GUI.window_width;	y_fraction = (height * 0x10000) / GUI.window_height;		for (int y = 0; y < GUI.window_height; y++)	{	    register uint8 *d = (uint8 *) GUI.image_date + y * GUI.bytes_per_line;	    register uint16 *s = (uint16 *) (GUI.output_screen + yy * GUI.output_pitch);	    y_error += y_fraction;	    while (y_error >= 0x10000)	    {		yy++;		y_error -= 0x10000;	    }	    x_error = 0;	    for (register int x = 0; x < GUI.window_width; x++)	    {		*d++ = GUI.palette [*s];		       		x_error += x_fraction;		while (x_error >= 0x10000)		{		    s++;		    x_error -= 0x10000;		}	    }	}    }}void Convert8To16 (int width, int height){    uint32 levels [32];    for (int l = 0; l < 32; l++)	levels [l] = (l * IPPU.MaxBrightness) >> 4;	    if (!GUI.image_needs_scaling)    {	// Convert	for (register int y = 0; y < height; y++)	{	    register uint16 *d = (uint16 *) (GUI.image_date + y * GUI.bytes_per_line);	    register uint8 *s = GUI.output_screen + y * GUI.output_pitch;	    for (register int x = 0; x < width; x++)	    {		uint32 pixel = PPU.CGDATA [*s++];		*d++ = (levels [pixel & 0x1f] << GUI.red_shift) |		       (levels [(pixel >> 5) & 0x1f] << GUI.green_shift) |		       (levels [(pixel >> 10) & 0x1f] << GUI.blue_shift);	    }	}    }    else    {	// Scale and convert	register uint32 x_error;	register uint32 x_fraction;	uint32 y_error = 0;	uint32 y_fraction;	int yy = 0;		x_fraction = (width * 0x10000) / GUI.window_width;	y_fraction = (height * 0x10000) / GUI.window_height;		for (int y = 0; y < GUI.window_height; y++)	{	    register uint16 *d = (uint16 *) (GUI.image_date +					   y * GUI.bytes_per_line);	    register uint8 *s = GUI.output_screen + yy * GUI.output_pitch;	    y_error += y_fraction;	    while (y_error >= 0x10000)	    {		yy++;		y_error -= 0x10000;	    }	    x_error = 0;	    for (register int x = 0; x < GUI.window_width; x++)	    {		uint32 pixel = PPU.CGDATA [*s];		*d++ = (levels [pixel & 0x1f] << GUI.red_shift) |		       (levels [(pixel >> 5) & 0x1f] << GUI.green_shift) |		       (levels [(pixel >> 10) & 0x1f] << GUI.blue_shift);		       		x_error += x_fraction;		while (x_error >= 0x10000)		{		    s++;		    x_error -= 0x10000;		}	    }	}    }}void S9xTextMode (){#ifdef USE_DGA_EXTENSION    if (XF86.full_screen_available && XF86.is_full_screen)    {	XF86DGADirectVideo (GUI.display, GUI.screen_num, 0);#ifdef USE_VIDMODE_EXTENSION	if (XF86.switch_video_mode)	    XF86VidModeSwitchToMode (GUI.display, GUI.screen_num, &XF86.orig);#endif	XUngrabKeyboard (GUI.display, CurrentTime);	XUngrabPointer (GUI.display, CurrentTime);	XUnmapWindow (GUI.display, XF86.fs_window);	XWarpPointer (GUI.display, None, GUI.window, 0, 0, 0, 0, 0, 0);	XSync (GUI.display, False);    }#endif    XAutoRepeatOn (GUI.display);}void S9xGraphicsMode (){#ifdef USE_DGA_EXTENSION    if (XF86.full_screen_available && XF86.is_full_screen)    {	XMapRaised (GUI.display, XF86.fs_window);	XClearWindow (GUI.display, XF86.fs_window);	XGrabKeyboard (GUI.display, GUI.window, False, GrabModeAsync, GrabModeAsync,		       CurrentTime);	XGrabPointer (GUI.display, GUI.window, False, ALL_DEVICE_EVENTS,		      GrabModeAsync, GrabModeAsync, GUI.window, GUI.point_cursor,		      CurrentTime);	XWarpPointer (GUI.display, None, RootWindowOfScreen (GUI.screen),		      0, 0, 0, 0, 0, 0);	XSync (GUI.display, False);#ifdef USE_VIDMODE_EXTENSION	if (XF86.switch_video_mode)	{	    XF86VidModeSwitchToMode (GUI.display, GUI.screen_num, XF86.best);	    XF86DGAGetVideo (GUI.display, GUI.screen_num, &XF86.vram,			     &XF86.line_width, &XF86.bank_size,			     &XF86.size);	    XF86VidModeSetViewPort (GUI.display, GUI.screen_num, 0, 0);	    XSync (GUI.display, False);	}#endif	XF86DGADirectVideo (GUI.display, GUI.screen_num, XF86DGADirectGraphics);	XF86VidModeSetViewPort (GUI.display, GUI.screen_num, 0, 0);	XSync (GUI.display, False);	//memset (XF86.vram, 0, XF86.size * 1024);    }#endif    XAutoRepeatOff (GUI.display);}void S9xParseDisplayArg (char **argv, int &ind, int){    if (strncasecmp (argv [ind], "-y", 2) == 0)    {	Settings.SixteenBit = TRUE;        Settings.SupportHiRes = TRUE;        Settings.ForceTransparency = TRUE;	switch (argv[ind][2])	{	case 0:	    GUI.interpolate = TRUE;	break;	case '1':   GUI.interpolate = TRUE;	break;	case '2':   GUI.interpolate = 2;	break;	case '3':   GUI.interpolate = 3;	break;	case '4':   GUI.interpolate = 4;	break;	case '5':   GUI.interpolate = 5;	break;	}    }    else    if (strncasecmp (argv [ind], "-GUI.interpolate", 12) == 0)    {	Settings.SixteenBit = TRUE;        Settings.SupportHiRes = TRUE;        Settings.ForceTransparency = TRUE;	switch (argv[ind][12])	{	case 0:	    GUI.interpolate = TRUE;	break;	case '1':   GUI.interpolate = TRUE;	break;	case '2':   GUI.interpolate = 2;	break;	case '3':   GUI.interpolate = 3;	break;	case '4':   GUI.interpolate = 4;	break;	case '5':   GUI.interpolate = 5;	break;	}    }    else    if (strcasecmp (argv [ind], "-scale") == 0 ||	strcasecmp (argv [ind], "-sc") == 0)    {#ifdef USE_DGA_EXTENSION	XF86.scale = TRUE;#endif	GUI.scale = TRUE;    }#ifdef USE_DGA_EXTENSION#ifdef USE_VIDMODE_EXTENSION    else    if (strcasecmp (argv [ind], "-nms") == 0 ||	strcasecmp (argv [ind], "-nomodeswitch") == 0)	XF86.no_mode_switch = TRUE;#endif    else    if (strcasecmp (argv [ind], "-fs") == 0 ||	strcasecmp (argv [ind], "-fullscreen") == 0)	XF86.start_full_screen = TRUE;#endif    else	S9xUsage ();}void S9xExtraUsage (){}int S9xMinCommandLineArgs (){    return (2);}void S9xMessage (int /*type*/, int /*number*/, const char *message){#define MAX_MESSAGE_LEN (36 * 3)    static char buffer [MAX_MESSAGE_LEN + 1];    fprintf (stdout, "%s\n", message);    strncpy (buffer, message, MAX_MESSAGE_LEN);    buffer [MAX_MESSAGE_LEN] = 0;    S9xSetInfoString (buffer);}void TVMode (int width, int height){    switch (width != 256 && GUI.interpolate != 5 ? 1 : GUI.interpolate)    {    case 2:	Super2xSaI (GFX.Screen, GFX.Pitch, GUI.delta_screen, GUI.output_screen,		    GUI.output_pitch, width, height);	break;    case 3:	SuperEagle (GFX.Screen, GFX.Pitch, GUI.delta_screen, GUI.output_screen,		    GUI.output_pitch, width, height);	break;    case 4:	_2xSaI (GFX.Screen, GFX.Pitch, GUI.delta_screen, GUI.output_screen,		GUI.output_pitch, width, height);	break;    case 5:#ifdef USE_DGA_EXTENSION	if (XF86.is_full_screen && !XF86.scale)	{	    Scale_2xSaI (GFX.Screen, GFX.Pitch, GUI.delta_screen, GUI.output_screen,			 GUI.output_pitch, IMAGE_WIDTH, IMAGE_HEIGHT, width, height);	}	else#endif	Scale_2xSaI (GFX.Screen, GFX.Pitch, GUI.delta_screen, GUI.output_screen,		     GUI.output_pitch, GUI.window_width, GUI.window_height, width, height);	break;    case 1:    {	uint8 *nextLine, *srcPtr, *deltaPtr, *finish;	uint8 *dstPtr;	uint32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16));	uint32 lowPixelMask = RGB_LOW_BITS_MASK;	srcPtr = GFX.Screen;	deltaPtr = GUI.delta_screen;	dstPtr = GUI.output_screen;	nextLine = GUI.output_screen + GUI.output_pitch;	if (width == 256)	{	    do	    {		uint32 *bP = (uint32 *) srcPtr;		uint32 *xP = (uint32 *) deltaPtr;		uint32 *dP = (uint32 *) dstPtr;		uint32 *nL = (uint32 *) nextLine;		uint32 currentPixel;		uint32 nextPixel;		uint32 currentDelta;		uint32 nextDelta;		finish = (uint8 *) bP + ((width + 2) << 1);		nextPixel = *bP++;		nextDelta = *xP++;		do		{		    currentPixel = nextPixel;		    currentDelta = nextDelta;		    nextPixel = *bP++;		    nextDelta = *xP++;		    if ((nextPixel != nextDelta) || (currentPixel != currentDelta))		    {			uint32 colorA, colorB, product, darkened;			*(xP - 2) = currentPixel;#ifdef LSB_FIRST			colorA = currentPixel & 0xffff;#else			colorA = (currentPixel & 0xffff0000) >> 16;#endif#ifdef LSB_FIRST			colorB = (currentPixel & 0xffff0000) >> 16;			*(dP) = product = colorA |					  ((((colorA & colorMask) >> 1) +					    ((colorB & colorMask) >> 1) +					    (colorA & colorB & lowPixelMask)) << 16);#else			colorB = currentPixel & 0xffff;			*(dP) = product = (colorA << 16) | 					  (((colorA & colorMask) >> 1) +					   ((colorB & colorMask) >> 1) +					   (colorA & colorB & lowPixelMask));#endif			darkened = (product = ((product & colorMask) >> 1));			darkened += (product = ((product & colorMask) >> 1));			darkened += (product & colorMask) >> 1;			*(nL) = darkened;#ifdef LSB_FIRST			colorA = nextPixel & 0xffff;			*(dP + 1) = product = colorB |					      ((((colorA & colorMask) >> 1) +						((colorB & colorMask) >> 1) +						(colorA & colorB & lowPixelMask)) << 16);#else			colorA = (nextPixel & 0xffff0000) >> 16;			*(dP + 1) = product = (colorB << 16) | 					       (((colorA & colorMask) >> 1) +						((colorB & colorMask) >> 1) + 						(colorA & colorB & lowPixelMask));#endif			darkened = (product = ((product & colorMask) >> 1));			darkened += (product = ((product & colorMask) >> 1));			darkened += (product & colorMask) >> 1;			*(nL + 1) = darkened;		    }		    dP += 2;		    nL += 2;		}		while ((uint8 *) bP < finish);		deltaPtr += GFX.Pitch;		srcPtr += GFX.Pitch;		dstPtr += GUI.output_pitch * 2;		nextLine += GUI.output_pitch * 2;	    }	    while (--height);	}	else	{	    do	    {		uint32 *bP = (uint32 *) srcPtr;		uint32 *xP = (uint32 *) deltaPtr;		uint32 *dP = (uint32 *) dstPtr;		uint32 currentPixel;		finish = (uint8 *) bP + ((width + 2) << 1);		do		{		    currentPixel = *bP++;		    if (currentPixel != *xP++)		    {			uint32 product, darkened;			*(xP - 1) = currentPixel;			*dP = currentPixel;			darkened = (product = ((currentPixel & colorMask) >> 1));			darkened += (product = ((product & colorMask) >> 1));			darkened += (product & colorMask) >> 1;			*(uint32 *) ((uint8 *) dP + GUI.output_pitch) = darkened;		    }		    dP++;		}		while ((uint8 *) bP < finish);		deltaPtr += GFX.Pitch;		srcPtr += GFX.Pitch;		dstPtr += GUI.output_pitch * 2;	    }	    while (--height);	}    }    }}#ifdef __linuxextern "C" {#include <sys/ioctl.h>//#include <selectbits.h>// Select seems to be broken in 2.x.x kernels - if a signal interrupts a// select system call with a zero timeout, the select call is restarted but// with an infinite timeout! The call will block until data arrives on the// selected fd(s).int select (int n, fd_set *readfds, fd_set *writefds, fd_set * /* exceptfds */,	    struct timeval * /* timeval */){    int ret = 0;    if (readfds)    {	for (int i = 0; i < n; i++)	{	    if (__FD_ISSET (i, readfds))	    {		int arg = 0;		if (ioctl (i, FIONREAD, &arg) == 0 && arg)		    ret = 1;		break;	    }	}    }    else	__FD_ZERO (readfds);    if (writefds)    {	for (int i = 0; i < n; i++)	{	    if (__FD_ISSET (i, writefds))	    {		ret = 1;		break;	    }	}    }    return (ret);}}#endif#ifdef USE_DGA_EXTENSIONvoid CreateFullScreenWindow (){    int major, minor;    XF86.full_screen_available = False;    if (XF86DGAQueryVersion (GUI.display, &major, &minor))    {	int fd;	// Need to test for access to /dev/mem here because XF86DGAGetVideo	// just calls exit if it can't access this device.	if ((fd = open ("/dev/mem", O_RDWR) < 0))	{	    perror ("Can't open \"/dev/mem\", full screen mode not available");	    return;	}	else	    close (fd);	XF86DGAGetVideo (GUI.display, GUI.screen_num, &XF86.vram,			 &XF86.line_width, &XF86.bank_size,			 &XF86.size);	XF86.full_screen_available = True;	XSetWindowAttributes attributes;	attributes.override_redirect = True;	attributes.background_pixel = BlackPixelOfScreen (GUI.screen);	XF86.fs_window = XCreateWindow (GUI.display, RootWindowOfScreen (GUI.screen),				   0, 0, WidthOfScreen (GUI.screen), 				   HeightOfScreen (GUI.screen),				   0, GUI.depth,				   InputOutput, GUI.visual, 				   CWOverrideRedirect | CWBackPixel,				   &attributes);	XF86.window_width = WidthOfScreen (GUI.screen);	XF86.window_height = HeightOfScreen (GUI.screen);#ifdef USE_VIDMODE_E

⌨️ 快捷键说明

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