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

📄 unix.cpp

📁 著名SFC模拟器Snes9x的源代码。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. * * (c) Copyright 1996 - 2001 Gary Henderson (gary@daniver.demon.co.uk) and *                           Jerremy Koot (jkoot@snes9x.com) * * Super FX C emulator code  * (c) Copyright 1997 - 1999 Ivar (Ivar@snes9x.com) and *                           Gary Henderson. * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_. * * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson. * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_. * C4 C code (c) Copyright 2001 Gary Henderson (gary@daniver.demon.co.uk). * * DOS port code contains the works of other authors. See headers in * individual files. * * Snes9x homepage: 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 <signal.h>#include <errno.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/time.h>#include <sys/types.h>#include <ctype.h>#if defined(__linux) || defined(__sun)#undef USE_THREADS#define USE_THREADS#include <unistd.h>#include <sys/types.h>#include <sys/ioctl.h>#include <sys/time.h>#endif#ifdef USE_THREADS#include <pthread.h>#include <sched.h>pthread_t thread;pthread_mutex_t mutex;#endif#ifdef __linux#include <sys/soundcard.h>#include <sys/mman.h>#endif#ifdef __sun#ifdef __SVR4#include <sys/audioio.h>#else#include <sun/audioio.h>#endif#endif#if defined(__sun) && defined(__GNUC__)typedef void (*SIG_PF)();#endif#include "snes9x.h"#include "memmap.h"#include "debug.h"#include "cpuexec.h"#include "ppu.h"#include "snapshot.h"#include "apu.h"#include "display.h"#include "gfx.h"#include "soundux.h"#include "spc700.h"#ifdef SPCTOOL#include "spctool/spc700.h"extern "C" void TraceSPC (unsigned char *PC, unsigned short YA, unsigned char X,			  SPCFlags PS, unsigned char *SP);#endif#ifdef _NETPLAY_SUPPORT#include "netplay.h"#endifuint32 joypads [5] = {0};int NumControllers = 5;#ifdef JOYSTICK_SUPPORT#ifdef __linux#include <linux/joystick.h>int js_fd [4] = {-1, -1, -1, -1};int js_map_button [4][16] = {    {	SNES_B_MASK, SNES_A_MASK, SNES_A_MASK,	SNES_Y_MASK, SNES_X_MASK, SNES_B_MASK,	SNES_TL_MASK, SNES_TR_MASK,	SNES_START_MASK, SNES_SELECT_MASK, 0, 0, 0, 0, 0, 0    },    {	SNES_B_MASK, SNES_A_MASK, SNES_A_MASK,	SNES_Y_MASK, SNES_X_MASK, SNES_B_MASK,	SNES_TL_MASK, SNES_TR_MASK,	SNES_START_MASK, SNES_SELECT_MASK, 0, 0, 0, 0, 0, 0    },    {	SNES_B_MASK, SNES_A_MASK, SNES_A_MASK,	SNES_Y_MASK, SNES_X_MASK, SNES_B_MASK,	SNES_TL_MASK, SNES_TR_MASK,	SNES_START_MASK, SNES_SELECT_MASK, 0, 0, 0, 0, 0, 0    },    {	SNES_B_MASK, SNES_A_MASK, SNES_A_MASK,	SNES_Y_MASK, SNES_X_MASK, SNES_B_MASK,	SNES_TL_MASK, SNES_TR_MASK,	SNES_START_MASK, SNES_SELECT_MASK, 0, 0, 0, 0, 0, 0    }};#if 0SNES_A_MASK, SNES_B_MASK, SNES_X_MASK, SNES_Y_MASK,		            SNES_TL_MASK, SNES_TR_MASK, SNES_START_MASK, SNES_SELECT_MASK,			    0, 0, 0, 0, 0, 0, 0, 0},			   {SNES_A_MASK, SNES_B_MASK, SNES_X_MASK, SNES_Y_MASK,			    SNES_TL_MASK, SNES_TR_MASK, SNES_START_MASK, SNES_SELECT_MASK,			    0, 0, 0, 0, 0, 0, 0, 0},			   {SNES_A_MASK, SNES_B_MASK, SNES_X_MASK, SNES_Y_MASK,			    SNES_TL_MASK, SNES_TR_MASK, SNES_START_MASK, SNES_SELECT_MASK,			    0, 0, 0, 0, 0, 0, 0, 0},			   {SNES_A_MASK, SNES_B_MASK, SNES_X_MASK, SNES_Y_MASK,			    SNES_TL_MASK, SNES_TR_MASK, SNES_START_MASK, SNES_SELECT_MASK,			    0, 0, 0, 0, 0, 0, 0, 0}};#endifchar *js_device [4] = {"/dev/js0", "/dev/js1", "/dev/js2", "/dev/js3"};#endifvoid InitJoysticks ();void ReadJoysticks ();#endifvoid InitTimer ();void *S9xProcessSound (void *);char *rom_filename = NULL;char *snapshot_filename = NULL;#if defined(__linux) || defined(__sun)static void sigbrkhandler(int){#ifdef DEBUGGER    CPU.Flags |= DEBUG_MODE_FLAG;    signal(SIGINT, (SIG_PF) sigbrkhandler);#endif}#endifvoid OutOfMemory (){    fprintf (stderr, "\Snes9X: Memory allocation failure - not enough RAM/virtual memory available.\n\        S9xExiting...\n");    Memory.Deinit ();    S9xDeinitAPU ();        exit (1);}void S9xParseArg (char **argv, int &i, int argc){#ifdef JOYSTICK_SUPPORT    if (strcmp (argv [i], "-j") == 0 ||	     strcasecmp (argv [i], "-nojoy") == 0)	Settings.JoystickEnabled = FALSE;    else if (strcasecmp (argv [i], "-joydev1") == 0)    {	if (i + 1 < argc)	    js_device[0] = argv[++i];	else	    S9xUsage ();    }    else if (strcasecmp (argv [i], "-joydev2") == 0)    {	if (i + 1 < argc)	    js_device[1] = argv[++i];	else	    S9xUsage ();    }    else if (strcasecmp (argv [i], "-joymap1") == 0)    {	if (i + 8 < argc)	{	    int t;	    if ((t = atoi (argv [++i])) < 15) js_map_button [0][t] = SNES_A_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [0][t] = SNES_B_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [0][t] = SNES_X_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [0][t] = SNES_Y_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [0][t] = SNES_TL_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [0][t] = SNES_TR_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [0][t] = SNES_START_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [0][t] = SNES_SELECT_MASK;	}	else	    S9xUsage ();    }    else if (strcasecmp (argv [i], "-joymap2") == 0)    {	if (i + 8 < argc)	{	    int t;	    if ((t = atoi (argv [++i])) < 15) js_map_button [1][t] = SNES_A_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [1][t] = SNES_B_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [1][t] = SNES_X_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [1][t] = SNES_Y_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [1][t] = SNES_TL_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [1][t] = SNES_TR_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [1][t] = SNES_START_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [1][t] = SNES_SELECT_MASK;	}	else	    S9xUsage ();    }    else if (strcasecmp (argv [i], "-joymap3") == 0)    {	if (i + 8 < argc)	{	    int t;	    if ((t = atoi (argv [++i])) < 15) js_map_button [2][t] = SNES_A_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [2][t] = SNES_B_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [2][t] = SNES_X_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [2][t] = SNES_Y_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [2][t] = SNES_TL_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [2][t] = SNES_TR_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [2][t] = SNES_START_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [2][t] = SNES_SELECT_MASK;	}	else	    S9xUsage ();    }    else if (strcasecmp (argv [i], "-joymap4") == 0)    {	if (i + 8 < argc)	{	    int t;	    if ((t = atoi (argv [++i])) < 15) js_map_button [3][t] = SNES_A_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [3][t] = SNES_B_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [3][t] = SNES_X_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [3][t] = SNES_Y_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [3][t] = SNES_TL_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [3][t] = SNES_TR_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [3][t] = SNES_START_MASK;	    if ((t = atoi (argv [++i])) < 15) js_map_button [3][t] = SNES_SELECT_MASK;	}	else	    S9xUsage ();    }    else #endif    if (strcasecmp (argv [i], "-b") == 0 ||	     strcasecmp (argv [i], "-bs") == 0 ||	     strcasecmp (argv [i], "-buffersize") == 0)    {	if (i + 1 < argc)	    Settings.SoundBufferSize = atoi (argv [++i]);	else	    S9xUsage ();    }    else if (strcmp (argv [i], "-l") == 0 ||	     strcasecmp (argv [i], "-loadsnapshot") == 0)    {	if (i + 1 < argc)	    snapshot_filename = argv [++i];	else	    S9xUsage ();    }    else	S9xParseDisplayArg (argv, i, argc);}#include "cheats.h"int main (int argc, char **argv){    if (argc < S9xMinCommandLineArgs ())	S9xUsage ();	    ZeroMemory (&Settings, sizeof (Settings));#ifdef JOYSTICK_SUPPORT    Settings.JoystickEnabled = TRUE;#else    Settings.JoystickEnabled = FALSE;#endif    Settings.SoundPlaybackRate = 4;    Settings.Stereo = TRUE;    Settings.SoundBufferSize = 0;    Settings.CyclesPercentage = 100;    Settings.DisableSoundEcho = FALSE;    Settings.APUEnabled = Settings.NextAPUEnabled = TRUE;    Settings.H_Max = SNES_CYCLES_PER_SCANLINE;    Settings.SkipFrames = AUTO_FRAMERATE;    Settings.ShutdownMaster = TRUE;    Settings.FrameTimePAL = 20000;    Settings.FrameTimeNTSC = 16667;    Settings.FrameTime = Settings.FrameTimeNTSC;    Settings.DisableSampleCaching = FALSE;    Settings.DisableMasterVolume = FALSE;    Settings.Mouse = TRUE;    Settings.SuperScope = TRUE;    Settings.MultiPlayer5 = TRUE;    Settings.ControllerOption = SNES_MULTIPLAYER5;    Settings.Transparency = FALSE;    Settings.SixteenBit = FALSE;    Settings.SupportHiRes = FALSE;    Settings.NetPlay = FALSE;    Settings.ServerName [0] = 0;    Settings.ThreadSound = FALSE;    Settings.AutoSaveDelay = 30;#ifdef _NETPLAY_SUPPORT    Settings.Port = NP_DEFAULT_PORT;#endif    Settings.ApplyCheats = TRUE;    Settings.TurboMode = FALSE;    Settings.TurboSkipFrames = 15;    rom_filename = S9xParseArgs (argv, argc);    Settings.Transparency = Settings.ForceTransparency;    if (Settings.ForceNoTransparency)	Settings.Transparency = FALSE;    if (Settings.Transparency)	Settings.SixteenBit = TRUE;    Settings.HBlankStart = (256 * Settings.H_Max) / SNES_HCOUNTER_MAX;    if (!Memory.Init () || !S9xInitAPU())	OutOfMemory ();    (void) S9xInitSound (Settings.SoundPlaybackRate, Settings.Stereo,			 Settings.SoundBufferSize);    if (!Settings.APUEnabled)	S9xSetSoundMute (TRUE);    uint32 saved_flags = CPU.Flags;#ifdef GFX_MULTI_FORMAT    S9xSetRenderPixelFormat (RGB565);#endif    if (rom_filename)    {	if (!Memory.LoadROM (rom_filename))	{	    char dir [_MAX_DIR + 1];	    char drive [_MAX_DRIVE + 1];	    char name [_MAX_FNAME + 1];	    char ext [_MAX_EXT + 1];	    char fname [_MAX_PATH + 1];	    _splitpath (rom_filename, drive, dir, name, ext);	    _makepath (fname, drive, dir, name, ext);	    strcpy (fname, S9xGetROMDirectory ());	    strcat (fname, SLASH_STR);	    strcat (fname, name);	    if (ext [0])	    {		strcat (fname, ".");		strcat (fname, ext);	    }	    _splitpath (fname, drive, dir, name, ext);	    _makepath (fname, drive, dir, name, ext);	    if (!Memory.LoadROM (fname))	    {		printf ("Error opening: %s\n", rom_filename);		exit (1);	    }	}	Memory.LoadSRAM (S9xGetFilename (".srm"));	S9xLoadCheatFile (S9xGetFilename (".cht"));    }    else    {	S9xReset ();	Settings.Paused |= 2;    }    CPU.Flags = saved_flags;#if !defined(__MSDOS) && defined(DEBUGGER)#if defined(__unix) && !defined(__NeXT__)    struct sigaction sa;#if defined(__linux)    sa.sa_handler = sigbrkhandler;#else    sa.sa_handler = (SIG_PF) sigbrkhandler;#endif#ifdef SA_RESTART    sa.sa_flags = SA_RESTART;#else    sa.sa_flags = 0;#endif    sigemptyset(&sa.sa_mask);    sigaction(SIGINT, &sa, NULL);#else    signal(SIGINT, (SIG_PF) sigbrkhandler);#endif#endif    S9xInitInputDevices ();    S9xInitDisplay (argc, argv);    if (!S9xGraphicsInit ())	OutOfMemory ();	    S9xTextMode ();#ifdef _NETPLAY_SUPPORT    if (strlen (Settings.ServerName) == 0)    {	char *server = getenv ("S9XSERVER");	if (server)	{	    strncpy (Settings.ServerName, server, 127);	    Settings.ServerName [127] = 0;	}    }    char *port = getenv ("S9XPORT");    if (Settings.Port >= 0 && port)	Settings.Port = atoi (port);    else    if (Settings.Port < 0)	Settings.Port = -Settings.Port;    if (Settings.NetPlay)    {	int player;	if (!S9xNetPlayConnectToServer (Settings.ServerName, Settings.Port,					Memory.ROMName, player))	{	    fprintf (stderr, "\Failed to connected to Snes9x netplay server \"%s\" on port %d.\n",		 Settings.ServerName, Settings.Port);	    S9xExit ();	}	fprintf (stderr, "\Connected to \"%s\" on port %d as player #%d playing \"%s\"\n",		 Settings.ServerName, Settings.Port, player, Memory.ROMName);    }    #endif

⌨️ 快捷键说明

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