Beispiel #1
1
int main( int argc, char* args[] ) 
{ 
	screen = NULL;

	//Start SDL 
	SDL_Init( SDL_INIT_EVERYTHING ); 
	
	// Setup the screen
	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_SWSURFACE);
	
	Emulator emu;
	emu.loadFromFile("superkuken");

	while(true) {
		emu.run();


//			SDL_Flip(screen);

		SDL_Delay(0);
	}
	

	//Quit SDL 
	SDL_Quit(); 
	return 0; 
} 
Beispiel #2
0
int main() {
    Emulator* emu = new Emulator();
    //emu->loadFile("/home/sosella/Desarrollo/Emuladores/NES/Roms/nestest.nes");
    //emu->loadFile("/home/sosella/Desarrollo/Emuladores/NES/Roms/balloon.nes");
    //emu->loadFile("/home/sosella/Desarrollo/Emuladores/NES/Roms/demo.nes");
    //emu->loadFile("/home/sosella/Desarrollo/Emuladores/NES/Roms/kong.nes");
    emu->loadFile("/home/sosella/Desarrollo/Emuladores/NES/Roms/pacman.nes");
    //emu->loadFile("/home/sosella/Desarrollo/Emuladores/NES/Roms/kong3.nes");
    //emu->loadFile("/home/sosella/Desarrollo/Emuladores/NES/Roms/kong_classics.nes");
    emu->start();

    return 0;
}
/*
 * Determines whether the node is currently visible
 *
 * node     The node
 * return   Whether the node is visible
 */
BOOL wii_menu_handle_is_node_visible( TREENODE *node )
{
  switch( node->node_type )
  {
    case NODETYPE_LOAD_STATE:
      return wii_snapshot_current_exists();
    case NODETYPE_REWIND_BUTTON:
      return wii_rewind;
    case NODETYPE_GX_VI_SCALER_SPACER:
    case NODETYPE_GX_VI_SCALER:
      return !wii_filter;
    case NODETYPE_RESET:
    case NODETYPE_RESUME:
    case NODETYPE_EMULATOR_SETTINGS_SPACER:
      return wii_last_rom != NULL;
    case NODETYPE_CARTRIDGE_SAVE_STATES:
      return wii_last_rom != NULL && MDFNGameInfo->StateAction != NULL;
    case NODETYPE_CARTRIDGE_SETTINGS_CURRENT_SPACER:
      {
        Emulator* emu = emuRegistry.getCurrentEmulator();
        return
          emu != NULL && 
          ( ( emu->getMenuManager().getCartridgeSettingsMenu() != NULL &&
              wii_last_rom != NULL ) ||
            ( emu->getMenuManager().getEmulatorMenu() != NULL ) );
      }
    case NODETYPE_CARTRIDGE_SETTINGS_CURRENT:    
      {
        Emulator* emu = emuRegistry.getCurrentEmulator();
        return 
          emu != NULL && 
          emu->getMenuManager().getCartridgeSettingsMenu() != NULL &&
          wii_last_rom != NULL;
      }
    case NODETYPE_EMULATOR_SETTINGS:
      {
        Emulator* emu = emuRegistry.getCurrentEmulator();
        return 
          emu != NULL && 
          emu->getMenuManager().getEmulatorMenu() != NULL;
      }
    default:
      {
        Emulator* emu = emuRegistry.getCurrentEmulator();
        if( emu != NULL )
        { 
          return emu->getMenuManager().isNodeVisible( node );
        }   
      }
  }

  return TRUE;
}
Beispiel #4
0
int main( int argc, char *argv[] ){
	Emulator *emu;
	
	if ( argc > 1 ){
		std::cout << "Opening rom file " << argv[1] << std::endl;

		emu = new Emulator( argv[1] );
		emu->run( );
		delete emu;

	} else {
		std::cout << "Usage: chaps [rom file]" << std::endl;
	}

	return 0;
}
Beispiel #5
0
int main(int argc, char *args[])
{
	Emulator emulator;

	//string name = "cpu/cpu_instrs";
	//string name = "instr_timing";

	//emulator.memory.load_rom("tests/" + name + ".gb");
	//emulator.memory.load_rom("roms/Dr. Mario.gb");
	//emulator.memory.load_rom("roms/kirby.gb");
	//emulator.memory.load_rom("roms/tetris.gb");
	//emulator.memory.load_rom("roms/minesweeper.gb");
	//emulator.memory.load_rom("roms/Super Mario Land.gb");
	//emulator.memory.load_rom("roms/cASTELIAN.gb");
	//emulator.memory.load_rom("roms/Serpent.gb");
	emulator.memory.load_rom("roms/yupferris.gb");

	emulator.run();

	return 0;
}
Beispiel #6
0
void GameInfoWidget::setGame(QModelIndex gameIndex, QString apiName)
{
    m_slideshow->stop();
    m_dbGameApi = ApiSelector::getUsedApi(); //verifying if the user switched to another api

    m_currentIndex = gameIndex;
    QModelIndex id = m_currentIndex.sibling(m_currentIndex.row(), 1);

    QSqlRecord record = m_games.find(id.data().toInt(), apiName);

    if(!record.isEmpty())
    {
        if(!record.value("remote_game_id").isNull())
        {
            getRemoteGameInfos(record.value("remote_game_id").toInt());
        }

        QString title = record.value("name").toString();
        int playedTime = record.value("playedtime").toInt();
        QString formatedTime = this->formatTimeToString(playedTime);
        //int lastPlayedTime = record.value("lasttimeplayed").toInt();

        int emulatorUsed = record.value("emulator_used").toInt();

        if(emulatorUsed != -1) {
            Emulators emulators;
            Emulator emu = emulators.getEmulator(emulatorUsed);

            QString message = QString("<b>" + tr("Emulator") + "</b>: " + emu.emulatorName());
            m_emulatorUsedLabel->setText(message);
        } else {
            m_emulatorUsedLabel->setText("");
        }

       m_gameTitle->setText(title);
       m_playedTime->setText("<b>Game time</b>: " + formatedTime);
       m_playButton->show();
    }
}
DWORD __stdcall draw_roads4( CDC* pDC )
{
	Emulator* emu = GLOBAL_EMU;
	if (emu->num_of_roads() == 4) {
		int corner = 360 / emu->num_of_roads();
		int road_id = 0;
		int line_index = 0;
		int v_num_of_lines = emu->num_of_lines(0)+emu->num_of_lines(2);
		int h_num_of_lines = emu->num_of_lines(1)+emu->num_of_lines(3);
		int center_to_up_road = h_num_of_lines / 2 * LINE_WIDTH;
		int center_to_left_road = v_num_of_lines / 2 * LINE_WIDTH;
		int x1 = CENTER_X - center_to_left_road;
		int y1 = CENTER_Y - center_to_up_road;

		draw_road(0,x1,y1,v_num_of_lines*LINE_WIDTH,center_to_up_road,emu->num_of_lines(0),90,pDC);
		draw_road(1,CENTER_X+center_to_left_road,CENTER_Y-center_to_up_road,h_num_of_lines*LINE_WIDTH,center_to_left_road,emu->num_of_lines(1),180,pDC);
		draw_road(2,CENTER_X+center_to_left_road,CENTER_Y+center_to_up_road,v_num_of_lines*LINE_WIDTH,center_to_up_road,emu->num_of_lines(2),270,pDC);
		draw_road(3,CENTER_X-center_to_left_road,CENTER_Y+center_to_up_road,h_num_of_lines*LINE_WIDTH,center_to_left_road,emu->num_of_lines(3),0,pDC);

	}
	return 0;
}
BusComponent::BusComponent(Emulator& aEmulator) : Component(aEmulator), 
mBus(aEmulator.getBus())
{
    mSlot = 0;
    mSubSlot = 0;
}
/*
 * React to the "select" event for the specified node
 *
 * node     The node
 */
void wii_menu_handle_select_node( TREENODE *node )
{
  char buff[WII_MAX_PATH];

  Emulator* emu = emuRegistry.getCurrentEmulator();
  if( emu != NULL )
  { 
    emu->getMenuManager().selectNode( node );
  }

  if( node->node_type == NODETYPE_ROM ||
      node->node_type == NODETYPE_RESUME ||
      node->node_type == NODETYPE_LOAD_STATE ||
      node->node_type == NODETYPE_RESET )
  {   
    // Essentially blanks the screen
    //wii_gx_push_callback( NULL, FALSE, NULL );

    switch( node->node_type )
    {
      case NODETYPE_LOAD_STATE:
        wii_start_snapshot();
        break;
      case NODETYPE_ROM:            
        snprintf( 
          buff, sizeof(buff), "%s%s", wii_get_roms_dir(), node->name ); 
        last_rom_index = wii_menu_get_current_index();
        loading_game = TRUE;
        wii_start_emulation( buff, "", false, false );
        loading_game = FALSE;
        break;
      case NODETYPE_RESUME:
        wii_resume_emulation();
        break;
      case NODETYPE_RESET:
        wii_reset_emulation();
        break;
      default:
        /* do nothing */
        break;
    }

    //wii_gx_pop_callback();
  }
  else
  {
    LOCK_RENDER_MUTEX();

    switch( node->node_type )
    {
      case NODETYPE_VOLUME:
        wii_volume += 10;
        if( wii_volume > 150 )
        {
          wii_volume = 0;
        }
        break;
      case NODETYPE_SAVE_STATE:
        wii_save_snapshot( NULL, TRUE );
        break;
      case NODETYPE_CARTRIDGE_SAVE_STATES_SLOT:
        wii_snapshot_next();
        break;
      case NODETYPE_SELECT_LANG:
        language_index++;
        if( language_index >= language_menu->child_count )
        {
          language_index = 0;
        }
        select_language();
        break;
      case NODETYPE_DOUBLE_STRIKE:
        wii_double_strike_mode ^= 1;
        break;
      case NODETYPE_FULL_WIDESCREEN:
        wii_full_widescreen++;
        if( wii_full_widescreen > WS_AUTO )
        {
          wii_full_widescreen = 0;
        }
        break;
      case NODETYPE_16_9_CORRECTION:
        wii_16_9_correction ^= 1;
        break;
      case NODETYPE_GX_VI_SCALER:
        wii_gx_vi_scaler ^= 1;
        break;
      case NODETYPE_AUTO_LOAD_SAVE:
        wii_auto_load_save_state ^= 1;
        break;
      case NODETYPE_TOP_MENU_EXIT:
        wii_top_menu_exit ^= 1;
        break;
      case NODETYPE_CHEATS:
        wii_cheats ^= 1;
        break;
      case NODETYPE_REWIND:
        wii_rewind ^= 1;
        if( wii_rewind )
        {
          wii_set_status_message( 
            "Note: Enabling rewind may affect performance." );
        }
        break;
      case NODETYPE_REWIND_BUTTON:
        wii_rewind_add_buttons ^= 1;
        break;
      case NODETYPE_WIIMOTE_MENU_ORIENT:
        wii_mote_menu_vertical ^= 1;
        break;
      case NODETYPE_DEBUG_MODE:
        wii_debug ^= 1;
        break;
      case NODETYPE_TRAP_FILTER:
        wii_trap_filter ^= 1;
        break;
      case NODETYPE_FILTER:
        wii_filter ^= 1;
        break;
      case NODETYPE_ROOT_DRIVE:
      case NODETYPE_UPDIR:
      case NODETYPE_DIR:
        if( node->node_type == NODETYPE_ROOT_DRIVE )
        {
          char path[WII_MAX_PATH];
          snprintf( path, sizeof(path), "%s/", node->name );
          wii_set_roms_dir( path );
          mount_pending = TRUE;
        }
        else if( node->node_type == NODETYPE_UPDIR )
        {
          const char* romsDir = wii_get_roms_dir();
          int len = strlen( romsDir );
          if( len > 1 && romsDir[len-1] == '/' )
          {
            char dirpart[WII_MAX_PATH] = "";
            char filepart[WII_MAX_PATH] = "";
            Util_splitpath( romsDir, dirpart, filepart );
            len = strlen(dirpart);
            if( len > 0 )
            {
              dirpart[len] = '/';
              dirpart[len+1] = '\0';
            }
            wii_set_roms_dir( dirpart );
          }
        }
        else
        {
          char newDir[WII_MAX_PATH];
          snprintf( newDir, sizeof(newDir), "%s%s/", 
            wii_get_roms_dir(), node->name );
          wii_set_roms_dir( newDir );
        }
        games_read = FALSE;
        last_rom_index = 1;
        break;
      case NODETYPE_ADVANCED:
      case NODETYPE_VIDEO_SETTINGS:
      case NODETYPE_CARTRIDGE_SAVE_STATES:
      case NODETYPE_LOAD_ROM:               
        wii_menu_push( node );
        if( node->node_type == NODETYPE_LOAD_ROM )
        {
          if( games_read )
          {
            wii_menu_move( node, last_rom_index );  
          }
        }
        else if( node->node_type == NODETYPE_CARTRIDGE_SAVE_STATES )
        {
          // Initialize the "current" value prior to displaying
          // the menu...
          BOOL foo;
          wii_snapshot_current( &foo );
        }          
        break;
      case NODETYPE_CARTRIDGE_SETTINGS_CURRENT:
        {
          Emulator* emu = emuRegistry.getCurrentEmulator();
          if( emu != NULL )
          {
            TREENODE* menu = 
              emu->getMenuManager().getCartridgeSettingsMenu();

            if( menu != NULL )
            {
              wii_menu_push( menu );
            }
          }
        }
        break;
      case NODETYPE_EMULATOR_SETTINGS:
        {
          Emulator* emu = emuRegistry.getCurrentEmulator();
          if( emu != NULL )
          {
            TREENODE* menu = emu->getMenuManager().getEmulatorMenu();
            if( menu != NULL )
            {
              wii_menu_push( menu );
            }
          }
        }
        break;
      default:
        /* do nothing */
        break;
    }

    UNLOCK_RENDER_MUTEX();
  }
}
Beispiel #10
0
/*
 * Updates the buffer with the name of the specified node
 *
 * node     The node
 * name     The name of the specified node
 * value    The value of the specified node
 */
void wii_menu_handle_get_node_name( 
  TREENODE* node, char *buffer, char* value )
{
  const char* strmode = NULL;
  int index;

  snprintf( buffer, WII_MENU_BUFF_SIZE, "%s", node->name );

  switch( node->node_type )
  {
    case NODETYPE_ROOT_DRIVE:
      {
        int device;
        FindDevice( node->name, &device );
        switch( device )
        {
          case DEVICE_SD:
            snprintf( buffer, WII_MENU_BUFF_SIZE, "[%s]", 
              gettextmsg( "SD Card" ) );
            break;
          case DEVICE_USB:
            snprintf( buffer, WII_MENU_BUFF_SIZE, "[%s]",
              gettextmsg( "USB Device" ) );
            break;
          case DEVICE_SMB:
            snprintf( buffer, WII_MENU_BUFF_SIZE, "[%s]",
              gettextmsg( "Network Share" ) );
            break;
        }
      }
      break;
    case NODETYPE_DIR:
      snprintf( buffer, WII_MENU_BUFF_SIZE, "[%s]", node->name );
      break;
    case NODETYPE_CARTRIDGE_SAVE_STATES_SLOT:
      {
        BOOL isLatest;
        int current = wii_snapshot_current( &isLatest );
        current++;
        if( !isLatest )
        {
          snprintf( value, WII_MENU_BUFF_SIZE, "%d", current );
        }
        else
        {
          snprintf( value, WII_MENU_BUFF_SIZE, "%d (%s)", 
            current, gettextmsg( "Latest" ) );
        }
      }
      break;
    case NODETYPE_EMULATOR_SETTINGS:
      snprintf( 
        buffer, WII_MENU_BUFF_SIZE, "%s (%s)", 
          gettextmsg(node->name), 
          gettextmsg(emuRegistry.getCurrentEmulator()->getName()) );
      break;
    case NODETYPE_SELECT_LANG:
      snprintf( 
        value, WII_MENU_BUFF_SIZE, "%s", 
          language_menu->children[language_index]->name );
      break;
    case NODETYPE_FULL_WIDESCREEN:
      snprintf( value, WII_MENU_BUFF_SIZE, "%s", 
        ( wii_full_widescreen == WS_AUTO ? "(auto)" :
          ( wii_full_widescreen ? "Enabled" : "Disabled" ) ) );
      break;
    case NODETYPE_GX_VI_SCALER:
      snprintf( value, WII_MENU_BUFF_SIZE, "%s", 
        ( wii_gx_vi_scaler ? "GX + VI" : "GX" ) );
      break;
    case NODETYPE_VOLUME:
      snprintf( value, WII_MENU_BUFF_SIZE, "%d %s", 
        ( wii_volume / 10 ), 
        ( wii_volume == 100 ?  gettextmsg("(normal)") : "" ) );
      break;
    case NODETYPE_REWIND_BUTTON:
      snprintf( value, WII_MENU_BUFF_SIZE, "%s", 
        wii_rewind_add_buttons ? "Auto" : "Manual" );
      break;
    case NODETYPE_DEBUG_MODE:
    case NODETYPE_TOP_MENU_EXIT:
    case NODETYPE_FILTER:
    case NODETYPE_VSYNC:
    case NODETYPE_AUTO_LOAD_SAVE:
    case NODETYPE_DOUBLE_STRIKE:
    case NODETYPE_CHEATS:    
    case NODETYPE_TRAP_FILTER:
    case NODETYPE_16_9_CORRECTION:
    case NODETYPE_REWIND:
      {
        BOOL enabled = FALSE;
        switch( node->node_type )
        {
          case NODETYPE_REWIND:
            enabled = wii_rewind;
            break;
          case NODETYPE_16_9_CORRECTION:
            enabled = wii_16_9_correction;
            break;
          case NODETYPE_TRAP_FILTER:
            enabled = wii_trap_filter;
            break;
          case NODETYPE_DOUBLE_STRIKE:
            enabled = wii_double_strike_mode;
            break;
          case NODETYPE_CHEATS:
            enabled = wii_cheats;
            break;
          case NODETYPE_AUTO_LOAD_SAVE:
            enabled = wii_auto_load_save_state;
            break;
          case NODETYPE_VSYNC:
            enabled = ( wii_vsync == VSYNC_ENABLED );
            break;
          case NODETYPE_DEBUG_MODE:
            enabled = wii_debug;
            break;
          case NODETYPE_FILTER:
            enabled = wii_filter;
            break;
          case NODETYPE_TOP_MENU_EXIT:
            enabled = wii_top_menu_exit;
            break;
          default:
            /* do nothing */
            break;
        }
        snprintf( value, WII_MENU_BUFF_SIZE, "%s", 
          enabled ? "Enabled" : "Disabled" );
        break;
    }
    case NODETYPE_WIIMOTE_MENU_ORIENT:
      if( wii_mote_menu_vertical )
      {
        strmode="Upright";
      }
      else
      {
        strmode="Sideways";
      }
      snprintf( value, WII_MENU_BUFF_SIZE, "%s", strmode );
      break;
    default:
      {
        Emulator* emu = emuRegistry.getCurrentEmulator();
        if( emu != NULL )
        { 
          emu->getMenuManager().getNodeName( node, buffer, value );
        }
      }
      break;
  }
}
Beispiel #11
0
CPU::CPU(Emulator& aEmulator) : Component(aEmulator), 
mBus(aEmulator.getBus())
{

}
Beispiel #12
0
Bus::Bus(Emulator& aEmulator) :  
mEmulator(aEmulator),
mScheduler(aEmulator.getScheduler())
{
}
Beispiel #13
0
int main(int argc, char *argv[])
{
	static SDL_Event event;
	int i;
	void* userData = (void*) 0xDEADC0DE;
	char dirname[1024], savedirname[1024], *home;
	
	// read the config file
	read_config_file();

	if (argc == 1 && conf->misc_disable_gui) {
		// Show usage and free config 
		cli_show_usage();
		config_file_free();
		return 0;
	}

	cli_handle_command(argc, argv);
	
	playing = 0;
	intbuffer = NULL;

	// Initialize File input/output routines
	fileio_init();
	
	// Initialize SDL
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
		return 1;
	}
	
	// Initialize input and read input config
	input_init();
	input_read_config();
	
	// Set up the video parameters
	video_set_params();
	
	// Initialize GTK+
	gtk_init(&argc, &argv);
	
	if (conf->misc_disable_gui) {
		// do nothing at this point
	}
	// Don't show a GUI if it has been disabled in the config
	else {
		gtkui_init(argc, argv, rendersize.w, rendersize.h);
	}

	// Create the game window
	video_create();
	
	// setup video lock/unlock callbacks
	Video::Output::lockCallback.Set( VideoLock, userData );
	Video::Output::unlockCallback.Set( VideoUnlock, userData );

	// misc callbacks (for others, see NstApuUser.hpp)
	User::fileIoCallback.Set( DoFileIO, userData );
	User::logCallback.Set( DoLog, userData );

	// try to load the FDS BIOS
	fileio_set_fds_bios();

	// and the NST database
	fileio_load_db();

	// attempt to load and autostart a file specified on the commandline
	if (argc > 1)
	{
		NstLoadGame(argv[argc - 1]);

		if (loaded)
		{
			if (nsf_mode)
			{
				on_nsfplay_clicked(NULL, NULL);
			}
			else
			{
				on_playbutton_clicked(NULL, NULL);
			}
		}
	}

	nst_quit = 0;
	while (!nst_quit)
	{
		while (gtk_events_pending())
		{
			gtk_main_iteration();
		}
		
		if (playing)
		{
				gtk_main_iteration_do(FALSE);

			 	while (SDL_PollEvent(&event))
				{
					switch (event.type)
					{
						case SDL_QUIT:
							schedule_stop = 1;
							return 0; // FIX
							break;
						
						case SDL_KEYDOWN:
						case SDL_KEYUP:
							// ignore num lock, caps lock, and "mode" (whatever that is)
							//event.key.keysym.mod = (SDLMod)((int)event.key.keysym.mod & (~(KMOD_NUM | KMOD_CAPS | KMOD_MODE)));
							
							// (intentional fallthrough)
						case SDL_JOYHATMOTION:
						case SDL_JOYAXISMOTION:
						case SDL_JOYBUTTONDOWN:
						case SDL_JOYBUTTONUP:
							input_process(cNstPads, event);
							break;
					}	
				}
				//}

				if (NES_SUCCEEDED(Rewinder(emulator).Enable(true)))
				{
					Rewinder(emulator).EnableSound(true);
				}

			m1sdr_TimeCheck();
			if (updateok)
			{
				emulator.Execute(cNstVideo, cNstSound, cNstPads);
				//emulator.Execute(cNstVideo, NULL, cNstPads);
				updateok = 0;
			}
			

			if (state_save)
			{
				fileio_do_state_save();
				state_save = 0;
				cleanup_after_io();
			}

			if (state_load)
			{
				fileio_do_state_load();
				state_load = 0;
				cleanup_after_io();
			}

			if (movie_load)
			{
				fileio_do_movie_load();
				movie_load = 0;
				cleanup_after_io();
			}

			if (movie_save)
			{
				fileio_do_movie_save();
				movie_load = 0;
				cleanup_after_io();
			}

			if (movie_stop)
			{
				movie_stop = 0;
				fileio_do_movie_stop();
			}

			if (schedule_stop)
			{
				NstStopPlaying();
			}
		}
		else
		{
			gtk_main_iteration_do(TRUE);
		}
	}

	nst_unload();

	fileio_shutdown();
	
	input_deinit();
	
	write_config_file();
	input_write_config();

	return 0;
}
Beispiel #14
0
void Medusa::LoadModules(std::wstring const& rModulesPath)
{
  try
  {
    const boost::filesystem::path CurDir = rModulesPath;
    Module Module;

    Log::Write("core") << "Module directory: " << boost::filesystem::system_complete(CurDir) << LogEnd;

    boost::filesystem::directory_iterator End;
    for (boost::filesystem::directory_iterator It(CurDir);
      It != End; ++It)
    {
      std::wstring const& rFilename = It->path().wstring();

      if (rFilename.substr(rFilename.find_last_of(L".") + 1) != Module::GetExtension())
        continue;

      std::wstring FullPath = boost::filesystem::system_complete(*It).wstring();
      Log::Write("core") << "Module: \"" << rFilename << "\" ";

      void* pMod = Module.Load(FullPath);
      if (pMod == nullptr)
        continue;

      TGetLoader pGetLoader = Module.Load<TGetLoader>(pMod, "GetLoader");
      if (pGetLoader != nullptr)
      {
        Log::Write("core") << "is a loader ";

        Loader* pLoader = pGetLoader(m_Database);
        if (pLoader->IsSupported())
        {
          Loader::SharedPtr LoaderPtr(pLoader);
          m_Loaders.push_back(LoaderPtr);
          Log::Write("core") << "(loaded)" << LogEnd;
        }
        else
        {
          Log::Write("core") << "(unloaded)" << LogEnd;
          delete pLoader;
        }
        continue;
      }

      TGetArchitecture pGetArchitecture = Module.Load<TGetArchitecture>(pMod, "GetArchitecture");
      if (pGetArchitecture != nullptr)
      {
        Log::Write("core") << "is an Architecture" << LogEnd;

        Architecture* pArchitecture = pGetArchitecture();
        Architecture::SharedPtr ArchitecturePtr(pArchitecture);
        m_AvailableArchitectures.push_back(ArchitecturePtr);
        continue;
      }

      TGetOperatingSystem pGetOperatingSystem = Module.Load<TGetOperatingSystem>(pMod, "GetOperatingSystem");
      if (pGetOperatingSystem != nullptr)
      {
        Log::Write("core") << "is an operating system" << LogEnd;

        OperatingSystem* pOperatingSystem = pGetOperatingSystem(m_Database);
        OperatingSystem::SharedPtr spOperatingSystem(pOperatingSystem);
        m_CompatibleOperatingSystems.push_back(spOperatingSystem);
        continue;
      }

      TGetEmulator pGetEmulator = Module.Load<TGetEmulator>(pMod, "GetEmulator");
      if (pGetEmulator != nullptr)
      {
        Log::Write("core") << "is an Emulator" << LogEnd;

        Emulator* pEmulator = pGetEmulator(nullptr, nullptr, nullptr);
        m_Emulators[pEmulator->GetName()] = pGetEmulator;
        continue;
      }

      Log::Write("core") << "is unknown (ignored)" << LogEnd;
    }
  }
  catch (std::exception &e)
  {
    Log::Write("core") << e.what() << LogEnd;
  }
}
Beispiel #15
0
int main(int argc, char *argv[])
{
	static SDL_Event event;
	int i;
	void* userData = (void*) 0xDEADC0DE;
	char dirname[1024], savedirname[1024], *home;

	// read the key/controller mapping
	ctl_defs = parse_input_file();

	if (!ctl_defs)
	{
		std::cout << "~/.nestopia/nstcontrols not found, creating a new one.\n";
		
		// make sure the output directory exists
		home = getenv("HOME");
		sprintf(dirname, "%s/.nestopia/", home);
		sprintf(savedirname, "%ssave/", dirname);
		mkdir(dirname, 0700);
		mkdir(savedirname, 0700);
		create_input_file();
		
		ctl_defs = parse_input_file();
		if (!ctl_defs)
		{
			std::cout << "Reading ~/.nestopia/nstcontrols file: FAIL\n";
			return -1;
		}
	} 

	playing = 0;
	intbuffer = NULL;

	auxio_init();

	sSettings = new Settings;
	sCheatMgr = new CheatMgr;
	
	gtk_init(&argc, &argv);
	
	get_screen_res();

	UIHelp_Init(argc, argv, sSettings, sCheatMgr, cur_Rwidth, cur_Rheight);
	
	// setup video lock/unlock callbacks
	Video::Output::lockCallback.Set( VideoLock, userData );
	Video::Output::unlockCallback.Set( VideoUnlock, userData );

	// misc callbacks (for others, see NstApuUser.hpp)
	User::fileIoCallback.Set( DoFileIO, userData );
	User::logCallback.Set( DoLog, userData );

	// try to load the FDS BIOS
	auxio_set_fds_bios();

	// and the NST database
	auxio_load_db();

	// attempt to load and autostart a file specified on the commandline
	if (argc > 1)
	{
		NstLoadGame(argv[1]);

		if (loaded)
		{
			if (nsf_mode)
			{
				on_nsfplay_clicked(NULL, NULL);
			}
			else
			{
				on_playbutton_clicked(NULL, NULL);
			}
		}
	}

	nst_quit = 0;
	while (!nst_quit)
	{
		while (gtk_events_pending())
		{
			gtk_main_iteration();
		}
		
		if (playing)
		{
				gtk_main_iteration_do(FALSE);

			 	while (SDL_PollEvent(&event))
				{
					switch (event.type)
					{
						case SDL_QUIT:
							schedule_stop = 1;
							break;

						case SDL_KEYDOWN:
						case SDL_KEYUP:
							// ignore num lock, caps lock, and "mode" (whatever that is)
							event.key.keysym.mod = (SDLMod)((int)event.key.keysym.mod & (~(KMOD_NUM | KMOD_CAPS | KMOD_MODE)));
							
							// (intentional fallthrough)
						case SDL_JOYHATMOTION:
						case SDL_JOYAXISMOTION:
						case SDL_JOYBUTTONDOWN:
						case SDL_JOYBUTTONUP:
							nst_dispatch(cNstPads, event);
							break;
					}	
				}
				//}

				if (NES_SUCCEEDED(Rewinder(emulator).Enable(true)))
				{
					Rewinder(emulator).EnableSound(true);
				}

			m1sdr_TimeCheck();
			if (updateok)
			{
				emulator.Execute(cNstVideo, cNstSound, cNstPads);
				updateok = 0;
			}

			if (state_save)
			{
				kill_video_if_fs();
				auxio_do_state_save();
				state_save = 0;
				cleanup_after_io();
			}

			if (state_load)
			{
				kill_video_if_fs();
				auxio_do_state_load();
				state_load = 0;
				cleanup_after_io();
			}

			if (movie_load)
			{
				kill_video_if_fs();
				auxio_do_movie_load();
				movie_load = 0;
				cleanup_after_io();
			}

			if (movie_save)
			{
				kill_video_if_fs();
				auxio_do_movie_save();
				movie_load = 0;
				cleanup_after_io();
			}

			if (movie_stop)
			{
				movie_stop = 0;
				auxio_do_movie_stop();
			}

			if (schedule_stop)
			{
				NstStopPlaying();
			}
		}
		else
		{
			gtk_main_iteration_do(TRUE);
		}
	}

	nst_unload();

	auxio_shutdown();

	delete sSettings;
	delete sCheatMgr;

	write_output_file(ctl_defs);
	free(ctl_defs);

	return 0;
}
Beispiel #16
0
void nst_load(const char *filename) {
	// Load a Game ROM
	Machine machine(emulator);
	Sound sound(emulator);
	Nes::Result result;
	char *rom;
	int romsize;
	char patchname[512];
	
	// Pause play before pulling out a cartridge
	if (playing) { nst_pause(); }
	
	// Pull out any inserted cartridges
	nst_unload();
	
	// Handle the file as an archive if it is one
	#ifdef _GTK
	char reqname[256];
	bool isarchive = gtkui_archive_handle(filename, reqname, sizeof(reqname));

	if (isarchive) {
		nst_archive_handle(filename, &rom, &romsize, reqname);
	#else
	if (nst_archive_handle(filename, &rom, &romsize, NULL)) {
	#endif
		// Convert the malloc'd char* to an istream
		std::string rombuf(rom, romsize);
		std::istringstream file(rombuf);
		result = machine.Load(file, nst_default_system());
	}
	// Otherwise just load the file
	else {
		std::ifstream file(filename, std::ios::in|std::ios::binary);
		
		// Set the file paths
		nst_set_paths(filename);
		
		if (nst_find_patch(patchname)) { // Load with a patch if there is one
			std::ifstream pfile(patchname, std::ios::in|std::ios::binary);
			Machine::Patch patch(pfile, false);
			result = machine.Load(file, nst_default_system(), patch);
		}
		else { result = machine.Load(file, nst_default_system()); }
	}
	
	if (NES_FAILED(result)) {
		switch (result) {
			case Nes::RESULT_ERR_INVALID_FILE:
				fprintf(stderr, "Error: Invalid file\n");
				break;

			case Nes::RESULT_ERR_OUT_OF_MEMORY:
				fprintf(stderr, "Error: Out of Memory\n");
				break;

			case Nes::RESULT_ERR_CORRUPT_FILE:
				fprintf(stderr, "Error: Corrupt or Missing File\n");
				break;

			case Nes::RESULT_ERR_UNSUPPORTED_MAPPER:
				fprintf(stderr, "Error: Unsupported Mapper\n");
				break;

			case Nes::RESULT_ERR_MISSING_BIOS:
				fprintf(stderr, "Error: Missing Fds BIOS\n");
				break;

			default:
				fprintf(stderr, "Error: %d\n", result);
				break;
		}
		return;
	}
	
	// Deal with any DIP Switches
	nst_dipswitch();
	
	// Set the region
	nst_set_region();
	
	if (machine.Is(Machine::DISK)) {
		Fds fds(emulator);
		fds.InsertDisk(0, 0);
		nst_fds_info();
	}
	
	// Check if sound distortion should be enabled
	sound.SetGenie(conf.misc_genie_distortion);
	
	// note that something is loaded
	loaded = 1;
	
	// Set the title
	video_set_title(nstpaths.gamename);
	#ifdef _GTK
	if (!conf.misc_disable_gui) { gtkui_opengl_start(); gtkui_set_title(nstpaths.gamename); }
	#endif

	// power on
	machine.Power(true); // false = power off
	
	nst_play();
}

int main(int argc, char *argv[]) {
	// This is the main function
	
	static SDL_Event event;
	void *userData = (void*)0xDEADC0DE;

	// Set up directories
	nst_set_dirs();
	
	// Set default config options
	config_set_default();
	
	// Read the config file and override defaults
	config_file_read();
	
	// Exit if there is no CLI argument
	#ifdef _GTK
	if (argc == 1 && conf.misc_disable_gui) {
	#else
	if (argc == 1) {
	#endif
		cli_show_usage();
		return 0;
	}
	
	// Handle command line arguments
	cli_handle_command(argc, argv);
	
	// Initialize SDL
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
		return 1;
	}
	
	// Detect Joysticks
	input_joysticks_detect();
	
	// Set default input keys
	input_set_default();
	
	// Read the input config file and override defaults
	input_config_read();
	
	// Set up the video parameters
	video_set_params();
	
	// Create the window
	#ifdef _GTK
	conf.misc_disable_gui ? video_create() : gtkui_init(argc, argv);
	if (conf.video_fullscreen) { video_create(); }
	#else
	video_create();
	#endif
	
	// Set up the callbacks
	Video::Output::lockCallback.Set(VideoLock, userData);
	Video::Output::unlockCallback.Set(VideoUnlock, userData);
	
	Sound::Output::lockCallback.Set(SoundLock, userData);
	Sound::Output::unlockCallback.Set(SoundUnlock, userData);
	
	User::fileIoCallback.Set(nst_cb_file, userData);
	User::logCallback.Set(nst_cb_log, userData);
	User::eventCallback.Set(nst_cb_event, userData);
	
	// Initialize and load FDS BIOS and NstDatabase.xml
	nstdb = NULL;
	fdsbios = NULL;
	nst_load_db();
	nst_load_fds_bios();

	// Load a rom from the command line
	if (argc > 1) {
		nst_load(argv[argc - 1]);
		
		if (!loaded) {
			fprintf(stderr, "Fatal: Could not load ROM\n");
			exit(1);
		}
	}
	
	// Start the main loop
	nst_quit = 0;
	
	while (!nst_quit) {
		#ifdef _GTK
		while (gtk_events_pending()) {
			gtk_main_iteration_do(FALSE);
		}
		#endif
		if (playing) {
			while (SDL_PollEvent(&event)) {
				switch (event.type) {
					case SDL_QUIT:
						nst_quit = 1;
						break;
					
					case SDL_KEYDOWN:
					case SDL_KEYUP:
					case SDL_JOYHATMOTION:
					case SDL_JOYAXISMOTION:
					case SDL_JOYBUTTONDOWN:
					case SDL_JOYBUTTONUP:
					case SDL_MOUSEBUTTONDOWN:
					case SDL_MOUSEBUTTONUP:
						input_process(cNstPads, event);
						break;
					default: break;
				}	
			}
			
			if (NES_SUCCEEDED(Rewinder(emulator).Enable(true))) {
				Rewinder(emulator).EnableSound(true);
			}
			
			audio_play();
			
			if (updateok) {
				// Pulse the turbo buttons
				input_pulse_turbo(cNstPads);
				
				// Check if it's time to skip a frame
				frameskip = timing_frameskip();
				
				// Execute a frame
				if (!frameskip) {
					emulator.Execute(cNstVideo, cNstSound, cNstPads);
				}
				else { emulator.Execute(NULL, cNstSound, cNstPads); }
				
				// Prevent insane speeds when vsync is turned off...
				if (!altspeed) { updateok = false; }
				
				// ...but only use the limiter when enabled
				if (!conf.timing_limiter) { updateok = true; }
			}
		}
	}
	
	// Remove the cartridge and shut down the NES
	nst_unload();
	
	// Unload the FDS BIOS and NstDatabase.xml
	if (nstdb) { delete nstdb; nstdb = NULL; }
	if (fdsbios) { delete fdsbios; fdsbios = NULL; }
	
	// Deinitialize audio
	audio_deinit();
	
	// Deinitialize joysticks
	input_joysticks_close();
	
	// Write the input config file
	input_config_write();
	
	// Write the config file
	config_file_write();

	return 0;
}
Beispiel #17
0
void tmain(int ac, const char * av[])
{
    if ( ac < 2 ) { void usage(); usage(); return; }

    Context ctx;
    ctx.init_clo(ac, av);

    if (ctx.mmcalc) return;

    Pragma pgm("cryptoleq", CRYPTOLEQVERSION);

    pgm.load_file("cryptoleq.pgm");

    string data = "stdin";
    if (!ctx.input_file.empty())
        data = file2str(ctx.input_file);

    if (data.empty())
        throw "Cannot read file " + ctx.input_file;

    if ( ctx.do_translate )
    {
        {
            std::istringstream is(data);
            pgm.load_dot_input(is);
        }

        pgm.read(ctx.clo_pragma);

        Compiler comp;
        {
            const Pragma & g = pgm;

            Unumber r = make_unumber(ctx.clo_seed, 0);
            if ( r.iszero() ) r = g.R();

            comp.init_pqkru(g.N(), g.P(), g.Q(), g.K(), r, g.U());

            if (g.beta())
                comp.proc.setB2Beta(g.beta());

            if ( !g.snk.empty() )
                comp.sneak = Unumber(g.snk, Unumber::Decimal);

            for ( auto i : g.include_paths)
                Input_token_stream::include_paths.push_back(i);
        }

        Cell::setN(comp.proc.N);
        ctx.setcompiler(comp);

        if ( ctx.bshow )
        {
            ctx.show();
            comp.show();
            return;
        }

        if ( ctx.bcrypt )
        {
            ctx.crypt();
            return;
        }

        auto token_stream = ctx.tokenize(data);

        if ( ctx.preproc )
        {
            cout << ctx.write(token_stream, pgm);
            return;
        }

        auto itr = ctx.parse(token_stream, &comp);

        ctx.evaluate(itr);

        bool outputx = (pgm.cqtype == pgm.Cqtype::X);
        auto out_stream = ctx.compile(itr, outputx);

        data = ctx.write(out_stream, pgm);
    }

    if (!ctx.do_emulate)
    {
        ctx.save(data);
        ctx.stat.output_e();
        return;
    }

    // execute
    {
        Emulator emu;
        Pragma pgm("cryptoleq", CRYPTOLEQVERSION);

        {
            std::istringstream in(data);
            emu.current_input_stream = &in;
            emu.mkmem_stream(pgm, ctx.clo_pragma);
        }

        Cell::setN(pgm.N());
        ProcessorTS proc(pgm.N());

        emu.io_type = pgm.io;

        if ( !ctx.separator.empty() )
            emu.sep_ts = emu.sep_x = char(std::atoi(ctx.separator.c_str()));

        if (!pgm.entry.empty())
            emu.entry = str2ts(pgm.entry);

        Stat * stat = nullptr;

        if ( !ctx.stat.filename.empty() )
        {
            stat = &ctx.stat;
            stat->addrinit(); // in case no compilation
        }


        emu.run(proc, stat);

        if (stat)
            stat->output();
    }
}
Beispiel #18
-1
void* runEmulation(void* theEmu)
{
    DebugLogMessage("runEmulation");
    Emulator* theRealEmu = (Emulator*)theEmu;
    assert(theRealEmu);
    DebugLogMessage("runEmulation lock");
    theRealEmu->emuSync.lock();
    DebugLogMessage("runEmulation Emulate");
    theRealEmu->Emulate();
    DebugLogMessage("runEmulation unlock");
    theRealEmu->emuSync.unlock();
    return NULL;
}