Exemple #1
0
bool SnesEmu::init(const QString &diskPath, QString *error) {
	S9xSetSoundMute(FALSE);
	setDefaultSettings();
	S9xSetPlaybackRate();
	m_frame = QImage(512, 239, QImage::Format_RGB16);
	setVideoSrcRect(QRectF(0.0f, 0.0f, 256.0f, 224.f));
	setFrameRate(60);

	GFX.Pitch = 512 * 2;
	GFX.RealPitch = 512 * 2;
	GFX.PPL = GFX.Pitch >> 1;
	GFX.PPLx2 = GFX.Pitch;
	GFX.Screen = (u8 *)m_frame.bits();
	GFX.SubScreen = (u8 *) malloc(GFX.RealPitch * 239);
	GFX.ZBuffer = (u8 *) malloc(GFX.PPL * 239);
	GFX.SubZBuffer = (u8 *) malloc(GFX.PPL * 239);
	GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1;

	if (!GFX.Screen || !GFX.SubScreen || !GFX.ZBuffer || !Memory.Init() || !S9xInitAPU() || !GFX.SubZBuffer ) {
		*error = tr("SNES emulation init failed!");
		return false;
	}
	S9xInitSound();
	if (!S9xGraphicsInit()) {
		*error = tr("SNES emulation init failed!");
		return false;
	}
	S9xReset();
	setDefaultSettings();
	*error = setDisk(diskPath);
	return error->isEmpty();
}
Exemple #2
0
void snes_init()
{
   memset(&Settings, 0, sizeof(Settings));
   Settings.MouseMaster = TRUE;
   Settings.SuperScopeMaster = TRUE;
   Settings.JustifierMaster = TRUE;
   Settings.MultiPlayer5Master = TRUE;
   Settings.FrameTimePAL = 20000;
   Settings.FrameTimeNTSC = 16667;
   Settings.SixteenBitSound = TRUE;
   Settings.Stereo = TRUE;
   Settings.SoundPlaybackRate = 32000;
   Settings.SoundInputRate = 32000;
   Settings.SupportHiRes = TRUE;
   Settings.Transparency = TRUE;
   Settings.AutoDisplayMessages = TRUE;
   Settings.InitialInfoStringTimeout = 120;
   Settings.HDMATimingHack = 100;
   Settings.BlockInvalidVRAMAccessMaster = TRUE;
   Settings.StopEmulation = TRUE;
   Settings.WrongMovieStateProtection = TRUE;
   Settings.DumpStreamsMaxFrames = -1;
   Settings.StretchScreenshots = 1;
   Settings.SnapshotScreenshots = TRUE;
   Settings.SkipFrames = AUTO_FRAMERATE;
   Settings.TurboSkipFrames = 15;
   Settings.CartAName[0] = 0;
   Settings.CartBName[0] = 0;
   Settings.AutoSaveDelay = 1;

   CPU.Flags = 0;

   if (!Memory.Init() || !S9xInitAPU())
   {
      Memory.Deinit();
      S9xDeinitAPU();
      fprintf(stderr, "[libsnes]: Failed to init Memory or APU.\n");
      exit(1);
   }

   S9xInitSound(64, 0);
   S9xSetSoundMute(FALSE);
   S9xSetSamplesAvailableCallback(S9xAudioCallback, NULL);

   S9xSetRenderPixelFormat(RGB555);
   GFX.Pitch = 2048;
   GFX.Screen = (uint16*) calloc(1, GFX.Pitch * 512 * sizeof(uint16));
   S9xGraphicsInit();

   S9xInitInputDevices();
   for (int i = 0; i < 2; i++)
   {
      S9xSetController(i, CTL_JOYPAD, i, 0, 0, 0);
      snes_devices[i] = SNES_DEVICE_JOYPAD;
   }

   S9xUnmapAllControls();
   map_buttons();
}
Exemple #3
0
static void snes_init (void)
{
    memset(&Settings, 0, sizeof(Settings));
    Settings.SpeedhackGameID = SPEEDHACK_NONE;
    Settings.Transparency = TRUE;
    Settings.FrameTimePAL = 20000;
    Settings.FrameTimeNTSC = 16667;
    Settings.SoundPlaybackRate = 32000;
    Settings.SoundInputRate = 32000;
    Settings.HDMATimingHack = 100;
    Settings.BlockInvalidVRAMAccessMaster = TRUE;
    Settings.CartAName[0] = 0;
    Settings.CartBName[0] = 0;
    Settings.Crosshair = 1;

    CPU.Flags = 0;

    if (!Init() || !S9xInitAPU())
    {
        Deinit();
        S9xDeinitAPU();
        if (log_cb)
            log_cb(RETRO_LOG_ERROR, "Failed to init Memory or APU.\n");
        exit(1);
    }

    //very slow devices will still pop

    //this needs to be applied to all snes9x cores

    //increasing the buffer size does not cause extra lag(tested with 1000ms buffer)
    //bool8 S9xInitSound (int buffer_ms, int lag_ms)

    S9xInitSound(1000, 0);//just give it a 1 second buffer

    S9xSetSamplesAvailableCallback(S9xAudioCallback);

    GFX.Pitch = use_overscan ? 1024 : 2048; // FIXME: What is this supposed to do? Overscan has nothing to do with anything like this. If this is the Wii performance hack, it should be done differently.

#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)
    /* request 128-bit alignment here if possible */
    posix_memalign((void**)&GFX.Screen, 16, GFX.Pitch * 512 * sizeof(uint16));
#else
    GFX.Screen = (uint16*) calloc(1, GFX.Pitch * 512 * sizeof(uint16));
#endif

    S9xGraphicsInit();

    retro_set_controller_port_device(0, RETRO_DEVICE_JOYPAD);
    retro_set_controller_port_device(1, RETRO_DEVICE_JOYPAD);

    S9xUnmapAllControls();
    map_buttons();

    /* Initialize SuperFX CPU to normal speed by default */
    Settings.SuperFXSpeedPerLine = 0.417 * 10.5e6;
}
Exemple #4
0
EXPORT void snes_init()
{
	int i;
	if(environ_cb)
	{
		unsigned pitch;
		if (!environ_cb(SNES_ENVIRONMENT_GET_OVERSCAN, &use_overscan))
			use_overscan = FALSE;

		if (use_overscan)
		{
			struct snes_geometry geom = {256, 239, 512, 512};
			environ_cb(SNES_ENVIRONMENT_SET_GEOMETRY, &geom);
			pitch = 1024;
			environ_cb(SNES_ENVIRONMENT_SET_PITCH, &pitch);
		}
	}
	memset(&Settings, 0, sizeof(Settings));
	Settings.FrameTimePAL = 20000;
	Settings.FrameTimeNTSC = 16667;
	Settings.SoundPlaybackRate = 32000;
	Settings.SoundInputRate = 32000;
	Settings.HDMATimingHack = 100;
	Settings.BlockInvalidVRAMAccessMaster = TRUE;
	Settings.CartAName[0] = 0;
	Settings.CartBName[0] = 0;
	Settings.Crosshair = 1;

	CPU.Flags = 0;

	if (!Init() || !S9xInitAPU())
	{
		Deinit();
		S9xDeinitAPU();
		fprintf(stderr, "[libsnes]: Failed to init Memory or APU.\n");
		exit(1);
	}

	S9xInitSound(16, 0);
	S9xSetSamplesAvailableCallback(S9xAudioCallback);

	GFX.Pitch = use_overscan ? 1024 : 2048;
	GFX.Screen = (uint16*) calloc(1, GFX.Pitch * 512 * sizeof(uint16));
	S9xGraphicsInit();

	for ( i = 0; i < 2; i++)
	{
		S9xSetController(i, CTL_JOYPAD, i, 0, 0, 0);
		snes_devices[i] = SNES_DEVICE_JOYPAD;
	}

	S9xUnmapAllControls();
	map_buttons();
}
Exemple #5
0
void snes_init()
{
   memset(&Settings, 0, sizeof(Settings));
   Settings.MouseMaster = TRUE;
   Settings.SuperScopeMaster = TRUE;
   Settings.JustifierMaster = TRUE;
   Settings.MultiPlayer5Master = TRUE;
   Settings.FrameTimePAL = 20000;
   Settings.FrameTimeNTSC = 16667;
   Settings.SoundPlaybackRate = 32000;
   Settings.SoundInputRate = 32000;
   Settings.AutoDisplayMessages = TRUE;
   Settings.InitialInfoStringTimeout = 120;
   Settings.HDMATimingHack = 100;
   Settings.BlockInvalidVRAMAccessMaster = TRUE;
   Settings.CartAName[0] = 0;
   Settings.CartBName[0] = 0;
   Settings.AutoSaveDelay = 1;

   CPU.Flags = 0;

   if (!Memory.Init() || !S9xInitAPU())
   {
      Memory.Deinit();
      S9xDeinitAPU();
      fprintf(stderr, "[libsnes]: Failed to init Memory or APU.\n");
      exit(1);
   }

   S9xInitSound(16, 0);
   S9xSetSamplesAvailableCallback(S9xAudioCallback);

   S9xSetRenderPixelFormat(RGB555);
   GFX.Pitch = 2048;
   GFX.Screen = (uint16*) calloc(1, GFX.Pitch * 512 * sizeof(uint16));
   S9xGraphicsInit();

   S9xInitInputDevices();
   for (int i = 0; i < 2; i++)
   {
      S9xSetController(i, CTL_JOYPAD, i, 0, 0, 0);
      snes_devices[i] = SNES_DEVICE_JOYPAD;
   }

   S9xUnmapAllControls();
   map_buttons();
}
Exemple #6
0
static void InitSnes9X()
{
	WinSetDefaultValues ();

	// Sound options
	Settings.SoundSync = TRUE;
	Settings.Mute =	FALSE;
	Settings.SoundPlaybackRate = 32000;
	Settings.SixteenBitSound = TRUE;
	Settings.Stereo	= TRUE;
	Settings.ReverseStereo = FALSE;

    Memory.Init();

    S9xInitAPU();
	S9xInitSound(10, 0);
}
Exemple #7
0
static void S9xInit() 
{
	if (!Memory.Init () || !S9xInitAPU())
         DIE("Memory or APU failed");

	if (!S9xInitSound ())
		DIE("Sound failed");
	S9xSetSoundMute (TRUE);
	
	// TODO: PAL/NTSC something better than this
	Settings.PAL = Settings.ForcePAL;
	
	Settings.FrameTime = Settings.PAL?Settings.FrameTimePAL:Settings.FrameTimeNTSC;
	Memory.ROMFramesPerSecond = Settings.PAL?50:60;
	
	IPPU.RenderThisFrame = TRUE;
}
Exemple #8
0
/* Load SPC file [CLEANUP]
   ---------------------------------------------------------------- */
int SPC_load (const char *fname)
{
    FILE *fp;
    // unused // char temp[64];

    S9xInitAPU();

    fp = fopen (fname, "rb");
    if (!fp)
        return FALSE;
 
	if (!SPC_loadFP(fp)) { 
    	fclose(fp);
		return FALSE;
	}
	
    fclose(fp);
    return TRUE;
}
Exemple #9
0
/* Load SPC file [CLEANUP]
   ---------------------------------------------------------------- */
int SPC_load (const char *fname, SPC_ID666 * id)
{
    FILE *fp;
    char temp[64];

    if (id) {
        memset(id, 0, sizeof(*id));
    }

    fp = fopen (fname, "rb");
    if (!fp)
        return FALSE;

    read_id666(fp, id);

    IAPU.OneCycle = ONE_APU_CYCLE; /* VP : moved this before call to S9xResetAPU !! */

    S9xInitAPU();
    S9xResetAPU();

    fseek(fp, 0x25, SEEK_SET);
    fread(&BackupAPURegisters.PC, 1, 2, fp);
    fread(&BackupAPURegisters.YA.B.A, 1, 1, fp);
    fread(&BackupAPURegisters.X, 1, 1, fp);
    fread(&BackupAPURegisters.YA.B.Y, 1, 1, fp);
    fread(&BackupAPURegisters.P, 1, 1, fp);
    fread(&BackupAPURegisters.S, 1, 1, fp);

    fseek(fp, 0x100, SEEK_SET);
    fread(BackupAPURAM, 1, 0x10000, fp);
    fread(BackupDSPRAM, 1, 128, fp);
    fread(temp, 1, 64, fp);
    fread(BackupAPUExtraRAM, 1, 64, fp);

    fclose(fp);

    RestoreSPC();

    return TRUE;
}
Exemple #10
0
int SPC_loadFP(FILE *fp)
{
    char temp[64];
	unsigned char a, b;

    S9xInitAPU();

    if (!fp)
        return FALSE;
  
    S9xResetAPU();

    fseek(fp, 0x25, SEEK_SET);
   
	fread(&a, 1, 1, fp);
	fread(&b, 1, 1, fp);
	BackupAPURegisters.PC = (b << 8) | a;
//	fread(&BackupAPURegisters.PC, 1, 2, fp);
	
    fread(&BackupAPURegisters.YA.B.A, 1, 1, fp);
    fread(&BackupAPURegisters.X, 1, 1, fp);
    fread(&BackupAPURegisters.YA.B.Y, 1, 1, fp);
    fread(&BackupAPURegisters.P, 1, 1, fp);
    fread(&BackupAPURegisters.S, 1, 1, fp);

    fseek(fp, 0x100, SEEK_SET);
    fread(BackupAPURAM, 1, 0x10000, fp);
    fread(BackupDSPRAM, 1, 128, fp);
    fread(temp, 1, 64, fp);
    fread(BackupAPUExtraRAM, 1, 64, fp);

    RestoreSPC();
    IAPU.OneCycle = ONE_APU_CYCLE;

    return TRUE;
}
Exemple #11
0
int
main (int argc, char *argv[])
{
    struct sigaction sig_callback;

    g_thread_init (NULL);
    gdk_threads_init ();

    gtk_init (&argc, &argv);

    bindtextdomain (GETTEXT_PACKAGE, SNES9XLOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);

    ZeroMemory (&Settings, sizeof (Settings));

    /* Allow original config file for backend settings */
    S9xLoadConfigFiles (argv, argc);

    /* Perform our config here */
    gui_config = new Snes9xConfig ();

    S9xInitInputDevices ();

    gui_config->load_config_file ();

    char *rom_filename = S9xParseArgs (argv, argc);

    S9xReportControllers ();

    if (!Memory.Init () || !S9xInitAPU ())
        exit (3);

    g_set_application_name ("Snes9x");

    top_level = new Snes9xWindow (gui_config);

    /* If we're going to fullscreen, do it before showing window to avoid flicker. */
    if ((gui_config->full_screen_on_open && rom_filename) || (gui_config->fullscreen))
        gtk_window_fullscreen (top_level->get_window ());

    top_level->show ();

    S9xInitDisplay (argc, argv);

    Memory.PostRomInitFunc = S9xPostRomInit;

    S9xPortSoundInit ();

    gui_config->reconfigure ();
    top_level->update_accels ();

    Settings.Paused = TRUE;
    syncing = 0;
    idle_func_id = g_idle_add_full (IDLE_FUNC_PRIORITY,
                                    S9xIdleFunc,
                                    NULL,
                                    NULL);

    g_timeout_add (10000, S9xScreenSaverCheckFunc, NULL);

    S9xNoROMLoaded ();

    if (rom_filename)
    {
        if (S9xOpenROM (rom_filename) && gui_config->full_screen_on_open)
            gtk_window_unfullscreen (top_level->get_window());
    }

    memset (&sig_callback, 0, sizeof (struct sigaction));
    sig_callback.sa_handler = S9xTerm;

    sigaction (15 /* SIGTERM */, &sig_callback, NULL);
    sigaction (3  /* SIGQUIT */, &sig_callback, NULL);
    sigaction (2  /* SIGINT  */, &sig_callback, NULL);

    if (gui_config->fullscreen)
    {
        gui_config->fullscreen = 0;
        needs_fullscreening = 1;
    }

#ifdef USE_JOYSTICK
    gui_config->flush_joysticks ();
#endif

    gtk_window_present (top_level->get_window ());

    gdk_threads_lock ();

    gtk_main ();

    return 0;
}
Exemple #12
0
extern "C" int SIStartWithROM(char* rom_filename)
{
  // notify that we're running
  SI_EmulationIsRunning = 1;
  
  // frameskip settings reset
  SI_NextFrameTime = (timeval){0, 0};
  SI_FrameTimeDebt = 0;
  SI_SleptLastFrame = 0;
  
  // ensure dirs exist
  mode_t dir_mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
	mkdir(SI_SRAMPath, dir_mode);
  
  // unix init
	ZeroMemory(&Settings, sizeof(Settings));
	Settings.MouseMaster = TRUE;
	Settings.SuperScopeMaster = TRUE;
	Settings.JustifierMaster = TRUE;
	Settings.MultiPlayer5Master = TRUE;
	Settings.FrameTimePAL = 20000;
	Settings.FrameTimeNTSC = 16667;
	Settings.SixteenBitSound = TRUE;
	Settings.Stereo = TRUE;
  //Settings.Stereo = FALSE;
	Settings.SoundPlaybackRate = 32000;
  //Settings.SoundPlaybackRate = 22050;
	//Settings.SoundInputRate = 32000;
  Settings.SoundInputRate = 32000;
  Settings.SoundSync = FALSE;
	Settings.SupportHiRes = TRUE;
	Settings.Transparency = TRUE;
	Settings.AutoDisplayMessages = TRUE;
	Settings.InitialInfoStringTimeout = 120;
	Settings.HDMATimingHack = 100;
	Settings.BlockInvalidVRAMAccessMaster = TRUE;
	Settings.StopEmulation = TRUE;
	Settings.WrongMovieStateProtection = TRUE;
	Settings.DumpStreamsMaxFrames = -1;
	Settings.StretchScreenshots = 1;
	Settings.SnapshotScreenshots = TRUE;
  if(SI_AutoFrameskip)
    Settings.SkipFrames = AUTO_FRAMERATE;
  else
    Settings.SkipFrames = SI_Frameskip;
  //Settings.SkipFrames = 1;
	Settings.TurboSkipFrames = 15;
	Settings.CartAName[0] = 0;
	Settings.CartBName[0] = 0;
#ifdef NETPLAY_SUPPORT
	Settings.ServerName[0] = 0;
#endif
  
	CPU.Flags = 0;
  
	/*S9xLoadConfigFiles(argv, argc);
	rom_filename = S9xParseArgs(argv, argc);
  
	make_snes9x_dirs();*/
  
	if (!Memory.Init() || !S9xInitAPU())
	{
		fprintf(stderr, "Snes9x: Memory allocation failure - not enough RAM/virtual memory available.\nExiting...\n");
		Memory.Deinit();
		S9xDeinitAPU();
		exit(1);
	}
  
  int samplecount = Settings.SoundPlaybackRate/(Settings.PAL ? 50 : 60);
  int soundBufferSize = samplecount<<(1+(Settings.Stereo?1:0));
  S9xInitSound(soundBufferSize, 0);
	S9xSetSoundMute(TRUE);
  
  S9xReset();
  
  S9xUnmapAllControls();
  S9xSetController(0, CTL_JOYPAD, 0, 0, 0, 0);
  //S9xSetController(1, CTL_JOYPAD, 1, 0, 0, 0);
  
  s9xcommand_t	cmd;
  
	ASSIGN_BUTTONf(SIOS_X,         "Joypad1 X");
	ASSIGN_BUTTONf(SIOS_A,         "Joypad1 A");
	ASSIGN_BUTTONf(SIOS_B,         "Joypad1 B");
	ASSIGN_BUTTONf(SIOS_Y,         "Joypad1 Y");
	ASSIGN_BUTTONf(SIOS_L,         "Joypad1 L");
	ASSIGN_BUTTONf(SIOS_R,         "Joypad1 R");
	ASSIGN_BUTTONf(SIOS_SELECT,    "Joypad1 Select");
	ASSIGN_BUTTONf(SIOS_START,     "Joypad1 Start");
	ASSIGN_BUTTONf(SIOS_UP,        "Joypad1 Up");
	ASSIGN_BUTTONf(SIOS_DOWN,      "Joypad1 Down");
	ASSIGN_BUTTONf(SIOS_LEFT,      "Joypad1 Left");
	ASSIGN_BUTTONf(SIOS_RIGHT,     "Joypad1 Right");
  
	S9xReportControllers();
  
#ifdef GFX_MULTI_FORMAT
	S9xSetRenderPixelFormat(RGB565);
#endif
  
	uint32	saved_flags = CPU.Flags;
	bool8	loaded = FALSE;
  
	if (Settings.Multi)
	{
		loaded = Memory.LoadMultiCart(Settings.CartAName, Settings.CartBName);
    
		if (!loaded)
		{
			char	s1[PATH_MAX + 1], s2[PATH_MAX + 1];
			char	drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
      
			s1[0] = s2[0] = 0;
      
			if (Settings.CartAName[0])
			{
				_splitpath(Settings.CartAName, drive, dir, fname, ext);
				snprintf(s1, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(ROM_DIR), SLASH_STR, fname);
				if (ext[0] && (strlen(s1) <= PATH_MAX - 1 - strlen(ext)))
				{
					strcat(s1, ".");
					strcat(s1, ext);
				}
			}
      
			if (Settings.CartBName[0])
			{
				_splitpath(Settings.CartBName, drive, dir, fname, ext);
				snprintf(s2, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(ROM_DIR), SLASH_STR, fname);
				if (ext[0] && (strlen(s2) <= PATH_MAX - 1 - strlen(ext)))
				{
					strcat(s2, ".");
					strcat(s2, ext);
				}
			}
      
			loaded = Memory.LoadMultiCart(s1, s2);
		}
	}
	else
    if (rom_filename)
    {
      char rom_path[1024] = {0};
      sprintf(rom_path,"%s%s%s",SI_DocumentsPath,DIR_SEPERATOR,rom_filename);
      
      loaded = Memory.LoadROM(rom_path);
      
      /*if (!loaded && rom_filename[0])
      {
        char	s[PATH_MAX + 1];
        char	drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
        
        _splitpath(rom_filename, drive, dir, fname, ext);
        snprintf(s, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(ROM_DIR), SLASH_STR, fname);
        if (ext[0] && (strlen(s) <= PATH_MAX - 1 - strlen(ext)))
        {
          strcat(s, ".");
          strcat(s, ext);
        }
        
        loaded = Memory.LoadROM(s);
      }*/
    }
  
	if (!loaded)
	{
		fprintf(stderr, "Error opening the ROM file.\n");
		exit(1);
	}
  
	//NSRTControllerSetup();
	//Memory.LoadSRAM(S9xGetFilename(".srm", SRAM_DIR));
  SILoadSRAM();
	//S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
  
	CPU.Flags = saved_flags;
	Settings.StopEmulation = FALSE;
  
#ifdef DEBUGGER
	struct sigaction sa;
	sa.sa_handler = sigbrkhandler;
#ifdef SA_RESTART
	sa.sa_flags = SA_RESTART;
#else
	sa.sa_flags = 0;
#endif
	sigemptyset(&sa.sa_mask);
	sigaction(SIGINT, &sa, NULL);
#endif
  
  GFX.Pitch = SNES_WIDTH*2;
  /*vrambuffer = (uint8*) malloc (GFX.Pitch * SNES_HEIGHT_EXTENDED*2);
	memset (vrambuffer, 0, GFX.Pitch * SNES_HEIGHT_EXTENDED*2);
  GFX.Screen = (uint16*)vrambuffer;*/
  S9xGraphicsInit();
  
#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)
	{
		NetPlay.MaxFrameSkip = 10;
    
		if (!S9xNPConnectToServer(Settings.ServerName, Settings.Port, Memory.ROMName))
		{
			fprintf(stderr, "Failed to connect to server %s on port %d.\n", Settings.ServerName, Settings.Port);
			S9xExit();
		}
    
		fprintf(stderr, "Connected to server %s on port %d as player #%d playing %s.\n", Settings.ServerName, Settings.Port, NetPlay.Player, Memory.ROMName);
	}
#endif
  
  // HACK: disabling SMV
	/*if (play_smv_filename)
	{
		uint32	flags = CPU.Flags & (DEBUG_MODE_FLAG | TRACE_FLAG);
		if (S9xMovieOpen(play_smv_filename, TRUE) != SUCCESS)
			exit(1);
		CPU.Flags |= flags;
	}
	else
    if (record_smv_filename)
    {
      uint32	flags = CPU.Flags & (DEBUG_MODE_FLAG | TRACE_FLAG);
      if (S9xMovieCreate(record_smv_filename, 0xFF, MOVIE_OPT_FROM_RESET, NULL, 0) != SUCCESS)
        exit(1);
      CPU.Flags |= flags;
    }
    else
      if (snapshot_filename)
      {
        uint32	flags = CPU.Flags & (DEBUG_MODE_FLAG | TRACE_FLAG);
        if (!S9xUnfreezeGame(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
  
  SILoadRunningStateForGameNamed(rom_filename);
  SI_EmulationPaused = 0;
  
  //if(SI_SoundOn)
  SIDemuteSound(soundBufferSize);
	S9xSetSoundMute(FALSE);
  
#ifdef NETPLAY_SUPPORT
	bool8	NP_Activated = Settings.NetPlay;
#endif
  
	while (1)
	{
#ifdef NETPLAY_SUPPORT
		if (NP_Activated)
		{
			if (NetPlay.PendingWait4Sync && !S9xNPWaitForHeartBeatDelay(100))
			{
				S9xProcessEvents(FALSE);
				continue;
			}
      
			for (int J = 0; J < 8; J++)
				old_joypads[J] = MovieGetJoypad(J);
      
			for (int J = 0; J < 8; J++)
				MovieSetJoypad(J, joypads[J]);
      
			if (NetPlay.Connected)
			{
				if (NetPlay.PendingWait4Sync)
				{
					NetPlay.PendingWait4Sync = FALSE;
					NetPlay.FrameCount++;
					S9xNPStepJoypadHistory();
				}
			}
			else
			{
				fprintf(stderr, "Lost connection to server.\n");
				S9xExit();
			}
		}
#endif
    
#ifdef DEBUGGER
		if (!Settings.Paused || (CPU.Flags & (DEBUG_MODE_FLAG | SINGLE_STEP_FLAG)))
#else
    if (!Settings.Paused && !SI_EmulationPaused)
#endif
    {
      S9xMainLoop();
    }
    
#ifdef NETPLAY_SUPPORT
		if (NP_Activated)
		{
			for (int J = 0; J < 8; J++)
				MovieSetJoypad(J, old_joypads[J]);
		}
#endif
    
#ifdef DEBUGGER
		if(Settings.Paused || (CPU.Flags & DEBUG_MODE_FLAG))
#else
    if(Settings.Paused || SI_EmulationPaused)
#endif
        S9xSetSoundMute(TRUE);
    
#ifdef DEBUGGER
		if (CPU.Flags & DEBUG_MODE_FLAG)
			S9xDoDebug();
		else
#endif
      if(Settings.Paused || SI_EmulationPaused || !SI_EmulationRun)
      {
        SISaveSRAM();
        SISaveRunningStateForGameNamed(rom_filename);
        SI_EmulationDidPause = 1;
        
        do {
          //S9xProcessEvents(FALSE);
          if(!SI_EmulationRun)
            break;
          usleep(100000);
        } while (SI_EmulationPaused);
        
        if(!SI_EmulationRun)
        {
          SISaveSRAM();
          SISaveRunningStateForGameNamed(rom_filename);
          
          SIMuteSound();
          
          S9xGraphicsDeinit();
          Memory.Deinit();
          S9xDeinitAPU();
          break;
        }
      }
    
#ifdef JOYSTICK_SUPPORT
		if (unixSettings.JoystickEnabled && (JoypadSkip++ & 1) == 0)
			ReadJoysticks();
#endif
    
		//S9xProcessEvents(FALSE);
    
#ifdef DEBUGGER
		if(!Settings.Paused && !(CPU.Flags & DEBUG_MODE_FLAG))
#else
    if(!Settings.Paused && !SI_EmulationPaused)
#endif
      S9xSetSoundMute(FALSE);
	}
  SI_EmulationIsRunning = 0;
  
	return (0);
}
Exemple #13
0
int SnesInit()
{
	ZeroMemory (&Settings, sizeof (Settings));

	Settings.JoystickEnabled = FALSE;
	Settings.SoundPlaybackRate = 44100;
	Settings.Stereo = TRUE;
	Settings.SoundBufferSize = 0;
	Settings.CyclesPercentage = 100;
	Settings.DisableSoundEcho = FALSE;
	Settings.APUEnabled = TRUE;
	Settings.H_Max = SNES_CYCLES_PER_SCANLINE;
	Settings.SkipFrames = AUTO_FRAMERATE;
	Settings.Shutdown = Settings.ShutdownMaster = TRUE;
	Settings.FrameTimePAL = 20000;
	Settings.FrameTimeNTSC = 16667;
	Settings.FrameTime = Settings.FrameTimeNTSC;
	Settings.DisableSampleCaching = FALSE;
	Settings.DisableMasterVolume = TRUE;
	Settings.Mouse = FALSE;
	Settings.SuperScope = FALSE;
	Settings.MultiPlayer5 = FALSE;
	//	Settings.ControllerOption = SNES_MULTIPLAYER5;
	Settings.ControllerOption = 0;

	Settings.InterpolatedSound = TRUE;
	Settings.StarfoxHack = TRUE;
	
	Settings.ForceTransparency = FALSE;
	Settings.Transparency = TRUE;
	Settings.SixteenBit = TRUE;
	
	Settings.SupportHiRes = FALSE;
	Settings.NetPlay = FALSE;
	Settings.ServerName [0] = 0;
	Settings.AutoSaveDelay = 30;
	Settings.ApplyCheats = TRUE;
	Settings.TurboMode = FALSE;
	Settings.TurboSkipFrames = 15;
	Settings.ThreadSound = FALSE;
	Settings.SoundSync = FALSE;
	//Settings.NoPatch = true;		

	Settings.SuperFX = TRUE;
	Settings.DSP1Master = TRUE;
	Settings.SA1 = TRUE;
	Settings.C4 = TRUE;
	Settings.SDD1 = TRUE;

	GFX.Pitch = 320 * 2;
	GFX.RealPitch = 320 * 2;
	GFX.Screen = (uint8 *) sal_VideoGetBuffer();
	
	GFX.SubScreen = (uint8 *)malloc(GFX.RealPitch * 480 * 2); 
	GFX.ZBuffer =  (uint8 *)malloc(GFX.RealPitch * 480 * 2); 
	GFX.SubZBuffer = (uint8 *)malloc(GFX.RealPitch * 480 * 2);
	GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1;
	GFX.PPL = GFX.Pitch >> 1;
	GFX.PPLx2 = GFX.Pitch;
	GFX.ZPitch = GFX.Pitch >> 1;
	
	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())
	{
		S9xMessage (0,0,"Failed to init memory");
		return SAL_ERROR;
	}

	//S9xInitSound ();
	
	//S9xSetRenderPixelFormat (RGB565);
	S9xSetSoundMute (TRUE);

	if (!S9xGraphicsInit ())
	{
         	S9xMessage (0,0,"Failed to init graphics");
		return SAL_ERROR;
	}

	return SAL_OK;
}