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

📄 xf86.cpp

📁 SFC游戏模拟器 snes9x 1.43 的原代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************  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.*******************************************************************************//*   XF86 code (xf86.cpp, this file) (c) Copyright 1998 Maciej Babinski,		use restricted to above terms.   Question/comments regarding this file only: maciej@imsa.edu */#ifdef __linux//#define USE_XF86VIDMODE#include <asm/ioctls.h>#include <sys/ioctl.h>#include <sys/time.h>#include <linux/ioctl.h>#include <fcntl.h>#include <sys/types.h>#include <string.h>#include <ctype.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <stdlib.h>#include <signal.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 <asm/io.h>#include <stdlib.h>#include <ctype.h>#include <string.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 <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/keysym.h>#include <X11/extensions/xf86dga.h>#ifdef USE_XF86VIDMODE/* GH: Added to allow to be compiled using C++ compiler */#if defined (__cplusplus) || defined (c_plusplus)#define private c_private#endif#   include <X11/extensions/xf86vmode.h>static XF86VidModeModeInfo	*orig_mode = NULL;static XF86VidModeModeInfo	*mod320x240 = NULL;bool cmpModeInfo (XF86VidModeModeInfo, XF86VidModeModeInfo);XF86VidModeModeInfo *ModeLine2ModeInfo (XF86VidModeModeLine, int);#endifvoid quit (int sig){	printf ("Received signal %d, quitting\n", sig);	S9xExit ();}struct vidinfo {	int bitdepth;	int screendepth;	int width;	int height;	int banksize;	int memsize;	char *vidMemBegin;	char *scrnBegin;};struct vidinfo	ourvideo;static Display		*ourdisp = NULL;/*   These three vars are "constants" for a particular display, who's value we   calculate in S9xInitDisplay, so that we don't have to do it on the fly in   S9xPutImage.	mEtoE = distance between end of once line of image and beginning of	        next one (units differ between bit-depths).*/static int		mWide, mHigh, mEtoE; static Colormap		cmap;static XColor		colors[256];static int		ourscreen;static bool		is_graphics=FALSE;static Window		inputwin;static Window		rootWindow;static int		is32or24 = 32;extern int		joypads[5];void S9xInitDisplay (int argc, char **argv){	Screen			*scrn;	XSetWindowAttributes	xattr;	signal (SIGINT, quit);	signal (SIGTERM, quit);	if ((ourdisp = XOpenDisplay(NULL)) == NULL) {		printf ("Can't connect to X server!\n");		S9xExit ();	}	ourscreen = DefaultScreen (ourdisp);	scrn = DefaultScreenOfDisplay (ourdisp);	ourvideo.bitdepth = DefaultDepth (ourdisp, ourscreen);	ourvideo.screendepth = ourvideo.bitdepth / 8;	rootWindow = RootWindowOfScreen (scrn);	xattr.override_redirect = True;	inputwin = XCreateWindow (ourdisp, RootWindowOfScreen(scrn),	                          10, 10, 100, 100, 0, 0, InputOutput,	                          DefaultVisualOfScreen(scrn),	                          CWOverrideRedirect, &xattr);	XMapWindow (ourdisp, inputwin);	ourvideo.height = HeightOfScreen (scrn);	switch (ourvideo.bitdepth) {		case  8:			Settings.SixteenBit = FALSE;			Settings.Transparency = FALSE;			cmap = XCreateColormap (ourdisp, rootWindow,			                        DefaultVisualOfScreen (scrn),						AllocAll);			XSetWindowColormap (ourdisp, inputwin, cmap);			for (int i=0; i<256; i++) {				colors[i].pixel = i;				colors[i].flags = DoRed | DoGreen | DoBlue;			}			break;		case 16:			Settings.SixteenBit = TRUE;			if (!Settings.ForceNoTransparency)				Settings.Transparency = TRUE;			break;		case 24:			if (is32or24 == 32) {				ourvideo.bitdepth = 32;				ourvideo.screendepth = 4;			}			Settings.SixteenBit = TRUE;			if (!Settings.ForceNoTransparency)				Settings.Transparency = TRUE;			break;		default:			printf ("Color depth %d not supported!\n");			S9xExit ();			break;	}	printf ("Found %d bit display\n", ourvideo.bitdepth);	XFree(scrn);	XF86DGAGetVideo (ourdisp, ourscreen, &(ourvideo.vidMemBegin),          	       &(ourvideo.width), &(ourvideo.banksize),          	       &(ourvideo.memsize));#ifdef USE_XF86VIDMODE   {	XF86VidModeModeInfo	**all_modes;	int			mode_count;	XF86VidModeModeLine	mod_tmp;	int			dotclock_tmp;	int			x;		XF86VidModeGetModeLine (ourdisp, ourscreen, &dotclock_tmp, &mod_tmp);	orig_mode = ModeLine2ModeInfo (mod_tmp, dotclock_tmp);	if (orig_mode->hdisplay == 320 && orig_mode->vdisplay == 240) {		mod320x240 = orig_mode;	} else {		XF86VidModeGetAllModeLines (ourdisp,ourscreen, &mode_count,		                            &all_modes);		for (x = 0; x < mode_count; x++)			if (all_modes[x]->hdisplay == 320 &&			    all_modes[x]->vdisplay == 240) {				mod320x240 = (XF86VidModeModeInfo *) malloc (				               sizeof(XF86VidModeModeInfo));				*mod320x240 = *(all_modes[x]);				break;			} else				XFree (all_modes[x]->c_private);		if (mod320x240 == NULL) {			printf ("No 320x240 mode available!\n");			S9xExit ();		}	}	XFree(all_modes);   }#endif	GFX.Pitch = IMAGE_WIDTH * (Settings.SixteenBit ? 2 : 1);	GFX.Screen = (uint8 *) malloc (IMAGE_HEIGHT * GFX.Pitch);	if (Settings.Transparency)		GFX.SubScreen = (uint8 *) malloc (IMAGE_HEIGHT * GFX.Pitch);	switch (ourvideo.bitdepth) {		case  8:			mWide = IMAGE_WIDTH / 4;			mHigh = IMAGE_HEIGHT;			mEtoE = (ourvideo.width - IMAGE_WIDTH) /4;			break;		case 16:			mWide = IMAGE_WIDTH / 2;			mHigh = IMAGE_HEIGHT;			mEtoE = (ourvideo.width - IMAGE_WIDTH) / 2;			break;		case 24:			mWide = IMAGE_WIDTH;			mHigh = IMAGE_HEIGHT;			mEtoE = (ourvideo.width - IMAGE_WIDTH) * 3;			break;		case 32:			mWide = IMAGE_WIDTH;			mHigh = IMAGE_HEIGHT;			mEtoE = (ourvideo.width - IMAGE_WIDTH) * 4;		default:			break;	}	ourvideo.scrnBegin = ourvideo.vidMemBegin + (320 - IMAGE_WIDTH) * ourvideo.screendepth / 2 + ourvideo.width * ourvideo.screendepth * 8;}void S9xGraphicsMode (){	if (is_graphics)		return;	XSelectInput (ourdisp, inputwin, KeyPressMask | KeyReleaseMask);	XSetInputFocus (ourdisp, inputwin, RevertToNone, CurrentTime);	XGrabKeyboard (ourdisp, inputwin, True, GrabModeAsync, GrabModeAsync,	               CurrentTime);	XGrabPointer (ourdisp, inputwin, True, 0, 	              GrabModeAsync, GrabModeAsync, inputwin, None, CurrentTime);		XFlush(ourdisp);	XAutoRepeatOff (ourdisp);#ifdef USE_XF86VIDMODE	if (orig_mode != mod320x240) {		XF86VidModeSwitchToMode (ourdisp,ourscreen, mod320x240);	}	XFlush (ourdisp);	XF86VidModeSetViewPort (ourdisp, ourscreen, 0, 0);	XFlush (ourdisp);#endif		XF86DGADirectVideo (ourdisp, ourscreen, XF86DGADirectGraphics);	memset ((void *) ourvideo.vidMemBegin, 0, ourvideo.width * 240 *	        ourvideo.screendepth);	is_graphics = TRUE;	XFlush (ourdisp);}void S9xTextMode () {	if (!is_graphics)		return;	if (ourdisp == NULL)		return;		XF86DGADirectVideo (ourdisp, ourscreen, 0);#ifdef USE_XF86VIDMODE	if (orig_mode != mod320x240) {		XF86VidModeSwitchToMode (ourdisp, ourscreen, orig_mode);	}#endif	XAutoRepeatOn (ourdisp);	XUngrabKeyboard (ourdisp, CurrentTime);	XUngrabPointer (ourdisp, CurrentTime);	XSelectInput (ourdisp, inputwin, 0);	XSync (ourdisp, True);	is_graphics = FALSE;} void S9xDeinitDisplay (){	S9xTextMode ();	if (ourdisp == NULL)		return;	XDestroyWindow (ourdisp, inputwin);	free (GFX.Screen);	free (GFX.SubScreen);#ifdef USE_XF86VIDMODE	free (orig_mode);	free (mod320x240);	if (orig_mode->privsize)		XFree (orig_mode->c_private);	if (mod320x240->privsize)		XFree (orig_mode->c_private);#endif	XFree (ourdisp);}void S9xSetPalette () {	int		Brightness;		if (ourvideo.bitdepth != 8)		return;	Brightness = IPPU.MaxBrightness *138;	for (int i = 0; i < 256; i++) {		colors[i].red = ((PPU.CGDATA[i] >> 0) & 0x1F) * Brightness;		colors[i].green = ((PPU.CGDATA[i] >> 5) & 0x1F) * Brightness;		colors[i].blue = ((PPU.CGDATA[i] >> 10) & 0x1F) * Brightness;	}	XStoreColors (ourdisp, cmap, colors, 256);	XF86DGAInstallColormap (ourdisp, ourscreen, cmap);}#define RED(r)		((uint8) (((r >> 11) & 31) * 256 / 32))#define GREEN(g)	((uint8) (((g >> 5) & 63) * 256 / 64))#define BLUE(b)		((uint8) (((b & 31)) * 256 / 32))void S9xPutImage (int width, int height){	register int x,y;		switch (ourvideo.bitdepth) {		case  8:		case 16:			{			long int	*p, *q;			p = (long int *) GFX.Screen;			q = (long int *) ourvideo.scrnBegin;			for (y=0;y<mHigh;y++) {				for (x=0;x<mWide;x++) {					*q = *p;					q++, p++;					}				q += mEtoE;				}			}			break;/*		case 24:			{			uint16		*p;

⌨️ 快捷键说明

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