📄 unix.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 <signal.h>#include <errno.h>#include <stdlib.h>#include <string.h>#ifdef HAVE_STRINGS_H#include <strings.h>#endif#include <unistd.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/time.h>/* FIXME: Linux alpha (aristocat) has a broken timercmp. Make testcase */#if defined(__linux)# ifndef timercmp# define timercmp(tvp, uvp, cmp)\ ((tvp)->tv_sec cmp (uvp)->tv_sec ||\ (tvp)->tv_sec == (uvp)->tv_sec &&\ (tvp)->tv_usec cmp (uvp)->tv_usec)# endif#endif#include <sys/types.h>#include <ctype.h>#include <dirent.h>#ifdef HAVE_SYS_IOCTL_H# include <sys/ioctl.h>#endif#ifdef USE_THREADS#include <pthread.h>#include <sched.h>pthread_t thread;pthread_mutex_t mutex;#endif#if !defined(NOSOUND) && defined(__linux)#include <sys/soundcard.h>#include <sys/mman.h>#endif#if !defined(NOSOUND) && defined(__sun)#ifdef __SVR4#include <sys/audioio.h>#else#include <sun/audioio.h>#endif#endif//Breaks sol9 and probably others.//#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"#include "spc7110.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#if defined(__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;char *SDD1_pack = NULL;//FIXME: I see no reason not to configureenable this for all Unixen#if defined(DEBUGGER) && (defined(__linux) || defined(__sun))static void sigbrkhandler(int){ CPU.Flags |= DEBUG_MODE_FLAG; signal(SIGINT, (SIG_PF) sigbrkhandler);}#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; for (t=0; t<15; t++) js_map_button [0][t] = 0; 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; for (t=0; t<15; t++) js_map_button [1][t] = 0; 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; for (t=0; t<15; t++) js_map_button [2][t] = 0; 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; for (t=0; t<15; t++) js_map_button [3][t] = 0; 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 if (strcasecmp (argv [i], "-sdd1-pack") == 0) { if (i + 1 < argc) SDD1_pack = 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;#ifndef NOSOUND Settings.APUEnabled = Settings.NextAPUEnabled = TRUE;#else Settings.APUEnabled = Settings.NextAPUEnabled = FALSE;#endif 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_JOYPAD; 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 = 40; Settings.StretchScreenshots = 1; 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 (); 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)) { fprintf (stderr, "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 if (snapshot_filename) { int Flags = CPU.Flags & (DEBUG_MODE_FLAG | TRACE_FLAG); if (!S9xLoadSnapshot (snapshot_filename)) exit (1); CPU.Flags |= Flags; } S9xGraphicsMode (); sprintf (String, "\"%s\" %s: %s", Memory.ROMName, TITLE, VERSION); S9xSetTitle (String); #ifdef JOYSTICK_SUPPORT uint32 JoypadSkip = 0;#endif InitTimer (); if (!Settings.APUEnabled) S9xSetSoundMute (FALSE); /* FIXME: Is someone using this dead code, or should it go? */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -