📄 x11.cpp
字号:
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_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){ XStoreName (GUI.display, GUI.window, string); XFlush (GUI.display);} bool8 S9xReadMousePosition (int which1, int &x, int &y, uint32 &buttons){ if (which1 == 0) { x = GUI.mouse_x; y = GUI.mouse_y; buttons = GUI.mouse_buttons; return (TRUE); } return (FALSE);}bool8 S9xReadSuperScopePosition (int &x, int &y, uint32 &buttons){ x = (int) ((GUI.mouse_x - GUI.box.x) * (256.0 / (double) GUI.box.width)); y = (int) ((GUI.mouse_y - GUI.box.y) * (224.0 / (double) GUI.box.height)); buttons = (GUI.mouse_buttons & 3) | (GUI.superscope_turbo << 2) | (GUI.superscope_pause << 3); return (TRUE);}void S9xProcessEvents (bool8 block){ while (block || XPending (GUI.display)) { XEvent event; XNextEvent (GUI.display, &event); block = FALSE;#if 0 if (event.xany.window != window) { app->x11ProcessEvent (&event); continue; }#endif uint8 byte1 = 0; uint8 byte2 = 0; uint8 byte3 = 0; uint8 byte4 = 0; switch (event.type) { case KeyPress: case KeyRelease: { int key; switch (key = XKeycodeToKeysym (GUI.display, event.xkey.keycode, 0)) { case XK_k: case XK_Right: byte2 = 1; break; case XK_h: case XK_Left: byte2 = 2; break; case XK_j: case XK_n: case XK_Down: byte2 = 4; break; case XK_u: case XK_Up: byte2 = 8; break; case XK_Return: byte2 = 16; break; // Start case XK_space: byte2 = 32; break; // Select case XK_period: case XK_t: case XK_d: byte1 = 128; break; // A case XK_y: case XK_c: byte2 = 128; break; // B case XK_m: case XK_e: case XK_s: byte1 = 64; break; // X case XK_comma: case XK_r: case XK_x: byte2 = 64; break; // Y case XK_v: case XK_q: case XK_a: byte1 = 32; break; // TL case XK_b: case XK_w: case XK_z: byte1 = 16; break; // TR case XK_KP_4: byte4 = 1; break; case XK_KP_6: byte4 = 2; break; case XK_KP_2: byte4 = 4; break; case XK_KP_8: byte4 = 8; break; case XK_KP_Enter: byte4 = 16; break; // Start case XK_KP_Add: byte4 = 32; break; // Select case XK_Prior: byte3 = 128; break; // A case XK_Next: byte4 = 128; break; // B case XK_Home: byte3 = 64; break; // X case XK_End: byte4 = 64; break; // Y case XK_Insert: byte3 = 32; break; // TL case XK_Delete: byte3 = 16; break; // TR case XK_Escape: if (event.type == KeyPress) {#ifdef USE_DGA_EXTENSION if (XF86.is_full_screen) { S9xSwitchToFullScreen (FALSE); break; }#endif S9xExit (); } break; case XK_0: if (event.type == KeyPress) { Settings.DisableHDMA = !Settings.DisableHDMA; S9xDisplayStateChange ("HDMA emulation", !Settings.DisableHDMA); } break; case XK_1: if (event.type == KeyPress) { PPU.BG_Forced ^= 1; S9xDisplayStateChange ("BG#0", !(PPU.BG_Forced & 1)); } break; case XK_2: if (event.type == KeyPress) { PPU.BG_Forced ^= 2; S9xDisplayStateChange ("BG#1", !(PPU.BG_Forced & 2)); } break; case XK_3: if (event.type == KeyPress) { PPU.BG_Forced ^= 4; S9xDisplayStateChange ("BG#2", !(PPU.BG_Forced & 4)); } break; case XK_4: if (event.type == KeyPress) { PPU.BG_Forced ^= 8; S9xDisplayStateChange ("BG#3", !(PPU.BG_Forced & 8)); } break; case XK_5: if (event.type == KeyPress) { PPU.BG_Forced ^= 16; S9xDisplayStateChange ("Sprites", !(PPU.BG_Forced & 16)); } break; case XK_6: if (event.type == KeyPress) { Settings.SwapJoypads = !Settings.SwapJoypads; S9xDisplayStateChange ("Joypad swapping", Settings.SwapJoypads); } break; case XK_7: if (event.type == KeyPress) { static char *controllers [] = { "Multiplayer 5 on #0", "Joypad on #0", "Mouse on #1", "Mouse on #0", "Superscope on #1" }; S9xNextController (); S9xSetInfoString (controllers [IPPU.Controller]); } break; case XK_8: if (event.type == KeyPress) { Settings.BGLayering = !Settings.BGLayering; S9xDisplayStateChange ("Background layering hack", Settings.BGLayering); } break; case XK_9: if (event.type == KeyPress) { if (event.xkey.state & ShiftMask) { Settings.Mode7Interpolate ^= TRUE; S9xDisplayStateChange ("Mode 7 Interpolation", Settings.Mode7Interpolate); } else { if (Settings.SixteenBit) { Settings.Transparency = !Settings.Transparency; S9xDisplayStateChange ("Transparency effects", Settings.Transparency); } } } break; case XK_minus: if (event.type == KeyPress) { if (event.xkey.state & ShiftMask) { // Decrease emulated frame time by 1ms if (Settings.FrameTime >= 1000) Settings.FrameTime -= 1000; sprintf (GUI.info_string, "Emulated frame time: %dms", Settings.FrameTime / 1000); S9xSetInfoString (GUI.info_string); } else { if (Settings.SkipFrames <= 1) Settings.SkipFrames = AUTO_FRAMERATE; else if (Settings.SkipFrames != AUTO_FRAMERATE) Settings.SkipFrames--; if (Settings.SkipFrames == AUTO_FRAMERATE) S9xSetInfoString ("Auto frame skip"); else { sprintf (GUI.info_string, "Frame skip: %d", Settings.SkipFrames - 1); S9xSetInfoString (GUI.info_string); } } } break; case XK_equal: case XK_plus: if (event.type == KeyPress) { if (event.xkey.state & ShiftMask) { // Increase emulated frame time by 1ms Settings.FrameTime += 1000; sprintf (GUI.info_string, "Emulated frame time: %dms", Settings.FrameTime / 1000); S9xSetInfoString (GUI.info_string); } else { if (Settings.SkipFrames == AUTO_FRAMERATE) Settings.SkipFrames = 1; else if (Settings.SkipFrames < 10) Settings.SkipFrames++; if (Settings.SkipFrames == AUTO_FRAMERATE) S9xSetInfoString ("Auto frame skip"); else { sprintf (GUI.info_string, "Frame skip: %d", Settings.SkipFrames - 1); S9xSetInfoString (GUI.info_string); } } } break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -