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

📄 x11.cpp

📁 著名SFC模拟器Snes9x的源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	XDefineCursor (GUI.display, GUI.window, GUI.point_cursor);#ifdef USE_DGA_EXTENSION	if (XF86.is_full_screen)	    XDefineCursor (GUI.display, GUI.window, GUI.point_cursor);#endif	GUI.superscope = FALSE;    }    if (x >= 0 && y >= 0 && x < width && y < height)    {	GUI.mouse_x = x;	GUI.mouse_y = y;	if (mask & Mod1Mask)	{	    IPPU.PrevMouseX [0] = IPPU.PrevMouseX [1] = GUI.mouse_x;	    IPPU.PrevMouseY [0] = IPPU.PrevMouseY [1] = GUI.mouse_y;	    if (!GUI.mod1_pressed)	    {		GUI.mod1_pressed = TRUE;		XDefineCursor (GUI.display, GUI.window, GUI.cross_hair_cursor);#ifdef USE_DGA_EXTENSION		if (XF86.is_full_screen)		    XDefineCursor (GUI.display, GUI.window, GUI.cross_hair_cursor);#endif	    }	}	else	if (GUI.mod1_pressed)	{	    GUI.mod1_pressed = FALSE;	    if (!GUI.superscope)	    {		XDefineCursor (GUI.display, GUI.window, GUI.point_cursor);#ifdef USE_DGA_EXTENSION		if (XF86.is_full_screen)		    XDefineCursor (GUI.display, GUI.window, GUI.point_cursor);#endif	    }	}	GUI.mouse_buttons = ((mask & 0x100) >> 8) | ((mask & 0x200) >> 7) |			((mask & 0x400) >> 9) | ((mask & 0x800) >> 8);    }#ifdef USE_GLIDE    }#endif}void S9xSetPalette (){#ifdef USE_GLIDE    if (Settings.GlideEnable)	return;#endif    int i;    if (GUI.grayscale)    {	uint16 Brightness = IPPU.MaxBrightness;	    	for (i = 0; i < 256; i++)	{	    GUI.colors[i].flags = DoRed | DoGreen | DoBlue;	    GUI.colors[i].red = GUI.colors[i].green = GUI.colors[i].blue = 		(uint16)(((((PPU.CGDATA[i] >> 0) & 0x1F) * Brightness * 50) +		        (((PPU.CGDATA[i] >> 5) & 0x1F) * Brightness * 69) +			(((PPU.CGDATA[i] >> 10) & 0x1F) * Brightness * 21)) * 1.40935);	}	XStoreColors (GUI.display, GUI.cmap, GUI.colors, 256);    }    else    if (GUI.pseudo)    {	if (Settings.SixteenBit)	{	    for (i = 0; i < 256; i++)	    {		GUI.colors[i].flags = DoRed | DoGreen | DoBlue;		GUI.colors[i].red = GUI.fixed_colours[i].red << 11;		GUI.colors[i].green = GUI.fixed_colours[i].green << 11;		GUI.colors[i].blue = GUI.fixed_colours[i].blue << 11;	    }	}	else	{	    uint16 Brightness = (IPPU.MaxBrightness) * 140;	    	    for (i = 0; i < 256; i++)	    {		GUI.colors[i].flags = DoRed | DoGreen | DoBlue;		GUI.colors[i].red = ((PPU.CGDATA[i] >> 0) & 0x1F) * Brightness;		GUI.colors[i].green = ((PPU.CGDATA[i] >> 5) & 0x1F) * Brightness;		GUI.colors[i].blue = ((PPU.CGDATA[i] >> 10) & 0x1F) * Brightness;	    }	}	XStoreColors (GUI.display, GUI.cmap, GUI.colors, 256);    }}const char *S9xSelectFilename (const char *def, const char *dir1,			    const char *ext1, const char *title){    static char path [PATH_MAX];    char buffer [PATH_MAX];        printf ("\n%s (default: %s): ", title, def);    fflush (stdout);    if (fgets (buffer, sizeof (buffer) - 1, stdin))    {	char *p = buffer;	while (isspace (*p))	    p++;	if (!*p)	{	    strcpy (buffer, def);	    p = buffer;	}	char *q = strrchr (p, '\n');	if (q)	    *q = 0;	char fname [PATH_MAX];	char drive [_MAX_DRIVE];	char dir [_MAX_DIR];	char ext [_MAX_EXT];	_splitpath (p, drive, dir, fname, ext);	_makepath (path, drive, *dir ? dir : dir1, fname, *ext ? ext : ext1);	return (path);    }    return (NULL);}void Scale8 (int width, int height){    register uint32 x_error;    register uint32 x_fraction;    uint32 y_error = 0;    uint32 y_fraction;    int yy = height - 1;        x_fraction = (width * 0x10000) / GUI.window_width;    y_fraction = (height * 0x10000) / GUI.window_height;        for (int y = GUI.window_height - 1; y >= 0; y--)    {	register uint8 *d = (uint8 *) GUI.image_date + y * GUI.bytes_per_line +			   GUI.window_width - 1;	register uint8 *s = GUI.output_screen + yy * GUI.output_pitch + width - 1;	y_error += y_fraction;	while (y_error >= 0x10000)	{	    yy--;	    y_error -= 0x10000;	}	x_error = 0;	for (register int x = GUI.window_width - 1; x >= 0; x--)	{	    *d-- = *s;	    x_error += x_fraction;	    while (x_error >= 0x10000)	    {		s--;		x_error -= 0x10000;	    }	}    }}void Scale16 (int width, int height){    register uint32 x_error;    register uint32 x_fraction;    uint32 y_error = 0;    uint32 y_fraction;    int yy = height - 1;        x_fraction = (width * 0x10000) / GUI.window_width;    y_fraction = (height * 0x10000) / GUI.window_height;        for (int y = GUI.window_height - 1; y >= 0; y--)    {	register uint16 *d = (uint16 *) (GUI.image_date + y * GUI.bytes_per_line) +					 GUI.window_width - 1;	register uint16 *s = (uint16 *) (GUI.output_screen + yy * GUI.output_pitch) + width - 1;	y_error += y_fraction;	while (y_error >= 0x10000)	{	    yy--;	    y_error -= 0x10000;	}	x_error = 0;	for (register int x = GUI.window_width - 1; x >= 0; x--)	{	    *d-- = *s;	    x_error += x_fraction;	    while (x_error >= 0x10000)	    {		s--;		x_error -= 0x10000;	    }	}    }}void Convert8To24 (int width, int height){    uint32 brightness = IPPU.MaxBrightness >> 1;    if (!GUI.image_needs_scaling)    {	// Convert	for (register int y = 0; y < height; y++)	{	    register uint32 *d = (uint32 *) (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++ = (((pixel & 0x1f) * brightness) << GUI.red_shift) |		       ((((pixel >> 5) & 0x1f) * brightness) << GUI.green_shift) |		       ((((pixel >> 10) & 0x1f) * brightness) << 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 uint32 *d = (uint32 *) (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++ = (((pixel & 0x1f) * brightness) << GUI.red_shift) |		       ((((pixel >> 5) & 0x1f) * brightness) << GUI.green_shift) |		       ((((pixel >> 10) & 0x1f) * brightness) << GUI.blue_shift);		       		x_error += x_fraction;		while (x_error >= 0x10000)		{		    s++;		    x_error -= 0x10000;		}	    }	}    }}void Convert16To24 (int width, int height){    if (!GUI.image_needs_scaling)    {	// Convert	for (register int y = 0; y < height; y++)	{	    register uint32 *d = (uint32 *) (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++)	    {		uint32 pixel = *s++;		*d++ = (((pixel >> 11) & 0x1f) << (GUI.red_shift + 3)) |		       (((pixel >> 6) & 0x1f) << (GUI.green_shift + 3)) |		       ((pixel & 0x1f) << (GUI.blue_shift + 3));	    }	}    }    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 uint32 *d = (uint32 *) (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++)	    {		uint32 pixel = *s;		*d++ = (((pixel >> 11) & 0x1f) << (GUI.red_shift + 3)) |		       (((pixel >> 6) & 0x1f) << (GUI.green_shift + 3)) |		       ((pixel & 0x1f) << (GUI.blue_shift + 3));		       		x_error += x_fraction;		while (x_error >= 0x10000)		{		    s++;		    x_error -= 0x10000;		}	    }	}    }}void Convert8To24Packed (int width, int height){    uint32 brightness = IPPU.MaxBrightness >> 1;    uint8 levels [32];    for (int l = 0; l < 32; l++)	levels [l] = l * brightness;	    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 uint8 *s = GUI.output_screen + y * GUI.output_pitch;#ifdef LSB_FIRST	    if (GUI.red_shift < GUI.blue_shift)#else	    	    if (GUI.red_shift > GUI.blue_shift)#endif	    {		// Order is RGB		for (register int x = 0; x < width; x++)		{		    uint16 pixel = PPU.CGDATA [*s++];		    *d++ = levels [(pixel & 0x1f)];		    *d++ = levels [((pixel >> 5) & 0x1f)];		    *d++ = levels [((pixel >> 10) & 0x1f)];		}	    }	    else	    {		// Order is BGR		for (register int x = 0; x < width; x++)		{		    uint16 pixel = PPU.CGDATA [*s++];		    *d++ = levels [((pixel >> 10) & 0x1f)];		    *d++ = levels [((pixel >> 5) & 0x1f)];		    *d++ = levels [(pixel & 0x1f)];		}	    }	}    }    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 uint8 *s = GUI.output_screen + yy * GUI.output_pitch;	    y_error += y_fraction;	    while (y_error >= 0x10000)	    {		yy++;		y_error -= 0x10000;	    }	    x_error = 0;#ifdef LSB_FIRST	    if (GUI.red_shift < GUI.blue_shift)#else	    if (GUI.red_shift > GUI.blue_shift)#endif	    {		// Order is RGB		for (register int x = 0; x < GUI.window_width; x++)		{		    uint16 pixel = PPU.CGDATA [*s];		    *d++ = levels [(pixel & 0x1f)];		    *d++ = levels [((pixel >> 5) & 0x1f)];		    *d++ = levels [((pixel >> 10) & 0x1f)];		       		    x_error += x_fraction;		    while (x_error >= 0x10000)		    {			s++;			x_error -= 0x10000;		    }		}	    }	    else	    {		// Order is BGR		for (register int x = 0; x < GUI.window_width; x++)		{		    uint16 pixel = PPU.CGDATA [*s];		    *d++ = levels [((pixel >> 10) & 0x1f)];		    *d++ = levels [((pixel >> 5) & 0x1f)];		    *d++ = levels [(pixel & 0x1f)];		       		    x_error += x_fraction;		    while (x_error >= 0x10000)		    {			s++;			x_error -= 0x10000;		    }		}	    }	}    }}void Convert16To24Packed (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);#ifdef LSB_FIRST	    if (GUI.red_shift < GUI.blue_shift)#else	    	    if (GUI.red_shift > GUI.blue_shift)#endif	    {		// Order is RGB		for (register int x = 0; x < width; x++)		{		    uint32 pixel = *s++;		    *d++ = (pixel >> (11 - 3)) & 0xf8;		    *d++ = (pixel >> (6 - 3)) & 0xf8;		    *d++ = (pixel & 0x1f) << 3;		}	    }	    else	    {		// Order is BGR		for (register int x = 0; x < width; x++)		{		    uint32 pixel = *s++;		    *d++ = (pixel & 0x1f) << 3;		    *d++ = (pixel >> (6 - 3)) & 0xf8;		    *d++ = (pixel >> (11 - 3)) & 0xf8;		}	    }	}    }    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;#ifdef LSB_FIRST	    if (GUI.red_shift < GUI.blue_shift)#else	    if (GUI.red_shift > GUI.blue_shift)#endif	    {		// Order is RGB		for (register int x = 0; x < GUI.window_width; x++)		{		    uint32 pixel = *s;		    *d++ = (pixel >> (11 - 3)) & 0xf8;		    *d++ = (pixel >> (6 - 3)) & 0xf8;		    *d++ = (pixel & 0x1f) << 3;		       		    x_error += x_fraction;		    while (x_error >= 0x10000)		    {			s++;			x_error -= 0x10000;		    }		}	    }	    else	    {

⌨️ 快捷键说明

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