Example #1
0
int main(int argc, char* args[])
{
	std::cout<<"GBE+ 1.3 [SDL]\n";

	core_emu* gbe_plus = NULL;

	//Start SDL from the main thread now, report specific init errors later in the core
	SDL_Init(SDL_INIT_VIDEO);

	//Grab command-line arguments
	for(int x = 0; x++ < argc - 1;) 
	{ 
		std::string temp_arg = args[x]; 
		config::cli_args.push_back(temp_arg);
		parse_filenames();
	}

	//Parse .ini options
	parse_ini_file();

	//Load OSD font
	load_osd_font();

	//Parse cheat file
	if(config::use_cheats) { parse_cheats_file(false); }

	if(config::mute) { config::volume = 0; }

	//Parse command-line arguments
	//These will override .ini options!
	if(!parse_cli_args()) { return 0; }

	//Get emulated system type from file
	config::gb_type = get_system_type_from_file(config::rom_file);

	//GBA core
	if(config::gb_type == 3)
	{
		gbe_plus = new AGB_core();
	}
	
	//DMG-GBC core
	else if((config::gb_type >= 0) && (config::gb_type <= 2))
	{
		gbe_plus = new DMG_core();
	}

	//Super Game Boy (SGB1 and SGB2)
	else if((config::gb_type == 5) || (config::gb_type == 6))
	{
		gbe_plus = new SGB_core();
	}

	//NDS core
	else
	{
		gbe_plus = new NTR_core();
	}
	
	//Read BIOS file optionally
	if(config::use_bios) 
	{
		//If no bios file was passed from the command-line arguments, defer to .ini options
		if(config::bios_file == "")
		{
			switch(config::gb_type)
			{
				case 0x1 : config::bios_file = config::dmg_bios_path; break;
				case 0x2 : config::bios_file = config::gbc_bios_path; break;
				case 0x3 : config::bios_file = config::agb_bios_path; break;
			}
		}

		if(!gbe_plus->read_bios(config::bios_file)) { return 0; } 
	}

	//Read specified ROM file
	if(!gbe_plus->read_file(config::rom_file)) { return 0; }

	//Read firmware optionally (NDS)
	if((config::use_firmware) && (config::gb_type == 4))
	{
		if(!gbe_plus->read_firmware(config::nds_firmware_path)) { return 0; }
	}

	//Engage the core
	gbe_plus->start();
	gbe_plus->db_unit.debug_mode = config::use_debugger;

	if(gbe_plus->db_unit.debug_mode) { SDL_CloseAudio(); }

	//Disbale mouse cursor in SDL, it's annoying
	SDL_ShowCursor(SDL_DISABLE);

	//Actually run the core
	gbe_plus->run_core();

	return 0;
}  
Example #2
0
/****** Open game file ******/
void main_menu::open_file()
{
	SDL_PauseAudio(1);

	if(config::cli_args.empty())
	{
		QString filename = QFileDialog::getOpenFileName(this, tr("Open"), "", tr("GBx files (*.gb *.gbc *.gba)"));
		if(filename.isNull()) { SDL_PauseAudio(0); return; }

		config::rom_file = filename.toStdString();
		config::save_file = config::rom_file + ".sav";
	}

	else
	{
		parse_filenames();
		config::cli_args.clear();
	}

	SDL_PauseAudio(0);

	//Close the core
	if(main_menu::gbe_plus != NULL) 
	{
		main_menu::gbe_plus->shutdown();
		main_menu::gbe_plus->core_emu::~core_emu();
	}

	config::sdl_render = false;
	config::render_external_sw = render_screen_sw;
	config::render_external_hw = render_screen_hw;
	config::sample_rate = settings->sample_rate;

	if(qt_gui::screen != NULL) { delete qt_gui::screen; }
	qt_gui::screen = NULL;

	//Search the recent files list and add this path to it
	bool add_recent = true;

	for(int x = 0; x < config::recent_files.size(); x++)
	{
		if(config::recent_files[x] == config::rom_file) { add_recent = false; }
	}

	if(add_recent)
	{
		config::recent_files.push_back(config::rom_file);

		//Delete the earliest element
		if(config::recent_files.size() > 10) { config::recent_files.erase(config::recent_files.begin()); }


		//Update the recent list
		recent_list->clear();

		for(int x = (config::recent_files.size() - 1); x >= 0; x--)
		{
			QString path = QString::fromStdString(config::recent_files[x]);
			QFileInfo file(path);
			path = file.fileName();

			QAction* temp = new QAction(path, this);
			recent_list->addAction(temp);

			connect(temp, SIGNAL(triggered()), list_mapper, SLOT(map()));
			list_mapper->setMapping(temp, x);
		}

		connect(list_mapper, SIGNAL(mapped(int)), this, SLOT(load_recent(int)));
	}

	boot_game();
}