📄 x11.cpp
字号:
/******************************************************************************* Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2001 - 2004 John Weidman (jweidman@slip.net) (c) Copyright 2002 - 2004 Brad Jorsch (anomie@users.sourceforge.net), funkyass (funkyass@spam.shaw.ca), Joel Yliluoma (http://iki.fi/bisqwit/) Kris Bleakley (codeviolation@hotmail.com), Matthew Kendora, Nach (n-a-c-h@users.sourceforge.net), Peter Bortas (peter@bortas.org) and zones (kasumitokoduck@yahoo.com) C4 x86 assembler and some C emulation code (c) Copyright 2000 - 2003 zsKnight (zsknight@zsnes.com), _Demo_ (_demo_@zsnes.com), and Nach C4 C++ code (c) Copyright 2003 Brad Jorsch DSP-1 emulator code (c) Copyright 1998 - 2004 Ivar (ivar@snes9x.com), _Demo_, Gary Henderson, John Weidman, neviksti (neviksti@hotmail.com), Kris Bleakley, Andreas Naive DSP-2 emulator code (c) Copyright 2003 Kris Bleakley, John Weidman, neviksti, Matthew Kendora, and Lord Nightmare (lord_nightmare@users.sourceforge.net OBC1 emulator code (c) Copyright 2001 - 2004 zsKnight, pagefault (pagefault@zsnes.com) and Kris Bleakley Ported from x86 assembler to C by sanmaiwashi SPC7110 and RTC C++ emulator code (c) Copyright 2002 Matthew Kendora with research by zsKnight, John Weidman, and Dark Force S-DD1 C emulator code (c) Copyright 2003 Brad Jorsch with research by Andreas Naive and John Weidman S-RTC C emulator code (c) Copyright 2001 John Weidman ST010 C++ emulator code (c) Copyright 2003 Feather, Kris Bleakley, John Weidman and Matthew Kendora Super FX x86 assembler emulator code (c) Copyright 1998 - 2003 zsKnight, _Demo_, and pagefault Super FX C emulator code (c) Copyright 1997 - 1999 Ivar, Gary Henderson and John Weidman SH assembler code partly based on x86 assembler code (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) Specific ports contains the works of other authors. See headers in individual files. Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and distribute Snes9x in both binary and source form, for non-commercial purposes, is hereby granted without fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied warranty. In no event shall the authors be held liable for any damages arising from the use of this software. Snes9x is freeware for PERSONAL USE only. Commercial users should seek permission of the copyright holders first. Commercial use includes charging money for Snes9x or software derived from Snes9x. The copyright holders request that bug fixes and improvements to the code should be forwarded to them so everyone can benefit from the modifications in future versions. Super NES and Super Nintendo Entertainment System are trademarks of Nintendo Co., Limited and its subsidiary companies.*******************************************************************************/#include <stdlib.h>#include <ctype.h>#include <string.h>#ifdef HAVE_STRINGS_H#include <strings.h>#endif#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include "snes9x.h"#include "memmap.h"#include "debug.h"#include "ppu.h"#include "snapshot.h"#include "gfx.h"#include "display.h"#include "apu.h"#include "soundux.h"#include "x11.h"#include "spc7110.h"#if 0#define QT_CLEAN_NAMESPACE#include <qapplication.h>#include "snes9x_gui.h"#endif#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/keysym.h>#include <X11/cursorfont.h>#ifdef USE_GLIDEbool8 S9xGlideEnable (bool8);void S9xGlidePutImage (int, int);void S9xSwitchToGlideMode (bool8);#endif#ifdef USE_AIDO#include "aido.h"#endif#ifdef __linux// 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).//// The workaround is to stop the X library calling select in the first// place! Replace XPending - which polls for data from the X server using // select - with an ioctl call to poll for data and then only call the blocking// XNextEvent if data is waiting.#define SELECT_BROKEN_FOR_SIGNALS#endif#ifdef USE_DGA_EXTENSION#include <X11/extensions/xf86dga.h>void CreateFullScreenWindow ();void S9xSwitchToFullScreen (bool8 enable);#ifdef USE_VIDMODE_EXTENSION#if defined (__cplusplus) || defined (c_plusplus)#include <X11/extensions/xf86vmode.h>#endif#define ALL_DEVICE_EVENTS 0#endiftypedef struct { bool8 full_screen_available; bool8 is_full_screen; bool8 scale; char *vram; int line_width; int bank_size; int size; int window_width; int window_height; int saved_window_width; int saved_window_height; bool8 saved_image_needs_scaling; Window fs_window;#ifdef USE_VIDMODE_EXTENSION bool8 switch_video_mode; XF86VidModeModeInfo **all_modes; int num_modes; XF86VidModeModeInfo orig; XF86VidModeModeInfo *best; bool8 no_mode_switch; bool8 start_full_screen;#endif} XF86Data;static XF86Data XF86;#endifGUIData GUI;extern uint32 joypads [5];#if 0QApplication *app;Snes9xGUI *gui;#endifvoid Scale8 (int width, int height);void Scale16 (int width, int height);void Convert8To16 (int width, int height);void Convert16To8 (int width, int height);void Convert8To24 (int width, int height);void Convert8To24Packed (int width, int height);void Convert16To24 (int width, int height);void Convert16To24Packed (int width, int height);void SetupImage ();int ErrorHandler (Display *, XErrorEvent *);void TVMode (int width, int height);void S9xDisplayStateChange (const char *str, bool8 on);void Init_2xSaI (uint32);void Super2xSaI (uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch, int width, int height);void SuperEagle (uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch, int width, int height);void _2xSaI (uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch, int width, int height);void Scale_2xSaI (uint8 *srcPtr, uint32 srcPitch, uint8 * /* deltaPtr */, uint8 *dstPtr, uint32 dstPitch, uint32 dstWidth, uint32 dstHeight, int width, int height);START_EXTERN_Cuint8 snes9x_clear_change_log = 0;END_EXTERN_Cvoid S9xDeinitDisplay (){#ifdef USE_GLIDE S9xGlideEnable (FALSE);#elif USE_AIDO if (Settings.AIDOShmId) return;#endif S9xTextMode (); 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; } } XSync (GUI.display, False); XCloseDisplay (GUI.display);}void S9xInitDisplay (int, char **){#ifdef USE_AIDO if (Settings.AIDOShmId) { S9xAIDOInit (); return; }#endif if (!(GUI.display = XOpenDisplay (NULL))) { fprintf (stderr, "Failed to connect to X server.\n"); exit (1); } GUI.screen = DefaultScreenOfDisplay (GUI.display); GUI.screen_num = XScreenNumberOfScreen (GUI.screen); GUI.visual = DefaultVisualOfScreen (GUI.screen); GUI.window_width = IMAGE_WIDTH; GUI.window_height = IMAGE_HEIGHT;#ifdef USE_OPENGL // XXX: Settings.OpenGLEnable = TRUE; if (Settings.OpenGLEnable) S9xOpenGLInit ();#endif XVisualInfo plate; XVisualInfo *matches; int count; plate.visualid = XVisualIDFromVisual (GUI.visual); matches = XGetVisualInfo (GUI.display, VisualIDMask, &plate, &count); if (!count) { fprintf (stderr, "Your X Window System server is unwell!\n"); exit (1); } GUI.depth = matches[0].depth; if ((GUI.depth != 8 && GUI.depth != 15 && GUI.depth != 16 && GUI.depth != 24) || (matches[0].c_class != PseudoColor && matches[0].c_class != TrueColor && matches[0].c_class != GrayScale)) { fprintf (stderr, "\Snes9x needs an X Window System server set to 8, 15, 16, 24 or 32-bit colour GUI.depth\n\supporting PseudoColor, TrueColor or GrayScale.\n"); exit (1); } if (GUI.depth >= 15 && !Settings.ForceNoTransparency) { Settings.Transparency = TRUE; Settings.SixteenBit = TRUE; } GUI.pseudo = matches[0].c_class == PseudoColor || matches[0].c_class == GrayScale; GUI.grayscale = matches[0].c_class == GrayScale; if (GUI.depth != 8 || !GUI.pseudo) { GUI.red_shift = ffs (matches[0].red_mask) - 1; GUI.green_shift = ffs (matches[0].green_mask) - 1; GUI.blue_shift = ffs (matches[0].blue_mask) - 1; GUI.red_size = matches[0].red_mask >> GUI.red_shift; GUI.green_size = matches[0].green_mask >> GUI.green_shift; GUI.blue_size = matches[0].blue_mask >> GUI.blue_shift; if (GUI.depth == 16 && GUI.green_size == 63) GUI.green_shift++;#ifdef GFX_MULTI_FORMAT switch (GUI.depth) { default: case 24: case 8: S9xSetRenderPixelFormat (RGB565); Init_2xSaI (565); break; case 16: if (GUI.red_size != GUI.green_size || GUI.blue_size != GUI.green_size) { // 565 format if (GUI.green_shift > GUI.blue_shift && GUI.green_shift > GUI.red_shift) S9xSetRenderPixelFormat (GBR565); else if (GUI.red_shift > GUI.blue_shift) S9xSetRenderPixelFormat (RGB565); else S9xSetRenderPixelFormat (BGR565); Init_2xSaI (565); break; } /* FALL ... */ case 15: if (GUI.green_shift > GUI.blue_shift && GUI.green_shift > GUI.red_shift) S9xSetRenderPixelFormat (GBR555); else if (GUI.red_shift > GUI.blue_shift) S9xSetRenderPixelFormat (RGB555); else S9xSetRenderPixelFormat (BGR555); Init_2xSaI (555); break; }#endif } XFree ((char *) matches);#if defined(USE_OPENGL) || defined(USE_AIDO) if (Settings.OpenGLEnable || Settings.AIDOShmId) { S9xSetRenderPixelFormat (RGB555); Settings.SixteenBit = TRUE; Settings.Transparency = TRUE; }#endif int l = 0; int i; for (i = 0; i < 6; i++) { int r = (i * 31) / (6 - 1); for (int j = 0; j < 6; j++) { int g = (j * 31) / (6 - 1); for (int k = 0; k < 6; k++) { int b = (k * 31) / (6 - 1); GUI.fixed_colours [l].red = r; GUI.fixed_colours [l].green = g; GUI.fixed_colours [l++].blue = b; } } } int *color_diff = new int [0x10000]; int diffr, diffg, diffb, maxdiff = 0, won = 0, lost; int r, d = 8; for (r = 0; r <= (int) MAX_RED; r++) { int cr, g, q;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -