Example #1
0
int executeGame_cmd(char* path) {

	char tmp_dir[256];

	int paramCount;
	int result = 0;
	int gameRot=0;
	int driverIndex;
	bool CreateConf = ( strcmp(ARGUV[0],"-cc") == 0 || strcmp(ARGUV[0],"-createconfig") == 0 )?1:0;
	bool Only1Arg =   ( ARGUC==1 )?1:0;

	FirstTimeUpdate = 1;

	screenRot = 0;

	for (int i = 0; i<64; i++)xargv_cmd[i]=NULL;

	//split the path to directory and the name without the zip extension
	if (parsePath(Only1Arg?path:ARGUV[ARGUC-1], MgamePath, MgameName) == 0) {
		write_log("parse path failed! path=%s\n", path);
		strcpy(MgameName,path );
	}
	//Find the game info. Exit if game driver was not found.
	if (getGameInfo(Only1Arg?MgameName:ARGUV[0], &gameRot, &driverIndex) == 0) {

		// handle -cc/-createconfig case
		if(CreateConf){
			write_log("create an %s config\n", core);
		}
		else {
			write_log("game not found: %s\n", MgameName);
			return -2;
		}
	}

	//some hardcoded default Options
	paramCount=0;
	sprintf(XARGV[paramCount++],"%s\0",core);
	sprintf(XARGV[paramCount++],"%s\0","-joystick");
	sprintf(XARGV[paramCount++],"%s\0","-samplerate");
	sprintf(XARGV[paramCount++],"%s\0","48000");
	sprintf(XARGV[paramCount++],"%s\0","-sound");
	sprintf(XARGV[paramCount++],"%s\0","-cheat");
        sprintf(XARGV[paramCount++],"%s\0","-mouse");

	//Setup path Option according to retro (save/system) directory or current if NULL 
	for(int i=0;i<NB_OPTPATH;i++){

		sprintf(XARGV[paramCount++],"%s\0",(char*)(opt_name[i]));

		if(opt_type[i]==0){
			if(retro_save_directory!=NULL)sprintf(tmp_dir, "%s%c%s%c%s", retro_save_directory, slash, core, slash,dir_name[i]);	
			else sprintf(tmp_dir, "%s%c%s%c%s", ".", slash, core, slash,dir_name[i]);
		}
		else {
			if(retro_system_directory!=NULL)sprintf(tmp_dir, "%s%c%s%c%s", retro_system_directory, slash, core, slash,dir_name[i]);	
			else sprintf(tmp_dir, "%s%c%s%c%s", ".", slash, core, slash,dir_name[i]);
		}

		sprintf(XARGV[paramCount++],"%s\0",(char*)(tmp_dir));
	}

	if(Only1Arg){// Assume arcade rom with full path or -cc  

		if(CreateConf)
			sprintf(XARGV[paramCount++],"%s\0",(char*)"-createconfig");
		else {
			sprintf(XARGV[paramCount++],"%s\0",(char*)"-rp");	
			sprintf(XARGV[paramCount++],"%s\0",(char*)g_rom_dir);	
			sprintf(XARGV[paramCount++],"%s\0",MgameName);
		}
	}
	else { // Pass all cmdline args
		for(int i=0;i<ARGUC;i++)
			sprintf(XARGV[paramCount++],"%s\0", ARGUV[i]);
	}

	write_log("frontend parameters:%i\n", paramCount);

	for (int i = 0; i<paramCount; i++){
		xargv_cmd[i] = (char*)(XARGV[i]);
		write_log("  %s\n",XARGV[i]);
	}

	osd_init_midi();

	cli_options MRoptions;
	mini_osd_interface MRosd;
	cli_frontend frontend(MRoptions, MRosd);
	result = frontend.execute(paramCount, ( char **)xargv_cmd); 

	xargv_cmd[paramCount - 2] = NULL;

	return result;
}
Example #2
0
int main(int argc, char **argv)
{
	int res = 0;

#else

/* gee */
extern "C" DECLSPEC void SDLCALL SDL_SetModuleHandle(void *hInst);

// translated to utf8_main
int main(int argc, char *argv[])
{
	int res = 0;

#if !(SDLMAME_SDL2)
	/* Load SDL dynamic link library */
	if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) {
		fprintf(stderr, "WinMain() error: %s", SDL_GetError());
		return(FALSE);
	}
	SDL_SetModuleHandle(GetModuleHandle(NULL));
#endif
#endif
	// disable I/O buffering
	setvbuf(stdout, (char *) NULL, _IONBF, 0);
	setvbuf(stderr, (char *) NULL, _IONBF, 0);

	#ifdef SDLMAME_UNIX
	sdl_entered_debugger = 0;
	#if (!defined(SDLMAME_MACOSX)) && (!defined(SDLMAME_HAIKU)) && (!defined(SDLMAME_EMSCRIPTEN))
#if !(SDLMAME_SDL2)
	if (TTF_Init() == -1)
	{
		printf("SDL_ttf failed: %s\n", TTF_GetError());
	}
#endif
	FcInit();
	#endif
	#endif

	#ifdef SDLMAME_OS2
	MorphToPM();
	#endif

#if defined(SDLMAME_X11) && (SDL_MAJOR_VERSION == 1) && (SDL_MINOR_VERSION == 2)
	if (SDL_Linked_Version()->patch < 10)
	/* workaround for SDL choosing a 32-bit ARGB visual */
	{
		Display *display;
		if ((display = XOpenDisplay(NULL)) && (DefaultDepth(display, DefaultScreen(display)) >= 24))
		{
			XVisualInfo vi;
			char buf[130];
			if (XMatchVisualInfo(display, DefaultScreen(display), 24, TrueColor, &vi)) {
				snprintf(buf, sizeof(buf), "0x%lx", vi.visualid);
				osd_setenv(SDLENV_VISUALID, buf, 0);
			}
		}
		if (display)
			XCloseDisplay(display);
	}
#endif

	osd_init_midi();    // this is a blues riff in B, watch me for the changes and try to keep up...

	{
		sdl_osd_interface osd;
		sdl_options options;
		cli_frontend frontend(options, osd);
		res = frontend.execute(argc, argv);
	}

#ifdef MALLOC_DEBUG
	{
		void check_unfreed_mem(void);
		check_unfreed_mem();
	}
#endif

	// already called...
	//SDL_Quit();

	#ifdef SDLMAME_UNIX
	#if (!defined(SDLMAME_MACOSX)) && (!defined(SDLMAME_HAIKU)) && (!defined(SDLMAME_EMSCRIPTEN))
#if !(SDLMAME_SDL2)
	TTF_Quit();
#endif
	if (!sdl_entered_debugger)
	{
		FcFini();
	}
	#endif
	#endif

	osd_shutdown_midi();

	exit(res);

	return res;
}
Example #3
0
int executeGame(char* path) {
	// cli_frontend does the heavy lifting; if we have osd-specific options, we
	// create a derivative of cli_options and add our own
	
	int paramCount;
	int result = 0;
	int gameRot=0;

	int driverIndex;

	FirstTimeUpdate = 1;

	screenRot = 0;
	
	//split the path to directory and the name without the zip extension
	result = parsePath(path, MgamePath, MgameName);
	if (result == 0) {
		write_log("parse path failed! path=%s\n", path);
		strcpy(MgameName,path);
	//	return -1;
	}
	
	//split the path to directory and the name without the zip extension
	result = parseSystemName(path, MsystemName);
	if (result == 0) {
		write_log("parse path failed! path=%s\n", path);
		strcpy(MsystemName,path );
	//	return -1;
	}
	//get the parent path
	result = parseParentPath(path, MparentPath);
	if (result == 0) {
		write_log("parse path failed! path=%s\n", path);
		strcpy(MparentPath,path );
	//	return -1;
	}	
	
#ifdef WANT_MAME	
	//find if the driver exists for MgameName, if not, exit
	if (getGameInfo(MgameName, &gameRot, &driverIndex) == 0) {
		write_log("driver not found: %s\n", MgameName);
		return -2;
	}	
#else
    if(!commandline_enabled)
	{
	   //find if the driver exists for MgameName, if not, check if a driver exists for MsystemName, if not, exit
	   if (getGameInfo(MgameName, &gameRot, &driverIndex) == 0) {
		   write_log("driver not found: %s\n", MgameName);
		   if (getGameInfo(MsystemName, &gameRot, &driverIndex) == 0) {
		      write_log("driver not found: %s\n", MsystemName);
   		         return -2;
	       }
	   }
    }	   
#endif	

	//tate enabled	
	if (tate) {
		//horizontal game
		if (gameRot == ROT0) {
			screenRot = 1;
		} else
		if (gameRot &  ORIENTATION_FLIP_X) {
			write_log("*********** flip X \n");
			screenRot = 3;
		}

	} else
	{
		if (gameRot != ROT0) {
			screenRot = 1;
			if (gameRot &  ORIENTATION_FLIP_X) {
				write_log("*********** flip X \n");
				screenRot = 2;
			}
		}
	}
	
	write_log("creating frontend... game=%s\n", MgameName);
	printf("using softlists: %d\n", softlist_enabled);
	//find how many parameters we have
	for (paramCount = 0; xargv[paramCount] != NULL; paramCount++)
		printf("args: %s\n",xargv[paramCount]);
	
	xargv[paramCount++] = (char*)("-cfg_directory");
	
	char cfg_dir[256];
	sprintf(cfg_dir, "%s%c%s%c%s", retro_save_directory, slash, core, slash, "cfg");
	xargv[paramCount++] = (char*)(cfg_dir);
	
	xargv[paramCount++] = (char*)("-nvram_directory");
	
	char nv_dir[256];
	sprintf(nv_dir, "%s%c%s%c%s", retro_save_directory, slash, core, slash, "nvram");
	xargv[paramCount++] = (char*)(nv_dir);
	
	xargv[paramCount++] = (char*)("-memcard_directory");
	
	char mem_dir[256];
	sprintf(mem_dir, "%s%c%s%c%s", retro_save_directory, slash, core, slash, "memcard");
	xargv[paramCount++] = (char*)(mem_dir);
		
	xargv[paramCount++] = (char*)("-input_directory");
	
	char inp_dir[256];
	sprintf(inp_dir, "%s%c%s%c%s", retro_save_directory, slash, core, slash, "input");
	xargv[paramCount++] = (char*)(inp_dir);
	
	xargv[paramCount++] = (char*)("-state_directory");
	
	char state_dir[256];
	sprintf(state_dir, "%s%c%s%c%s", retro_save_directory, slash, core, slash, "states");
	xargv[paramCount++] = (char*)(state_dir);
		
	xargv[paramCount++] = (char*)("-snapshot_directory");
	
	char snap_dir[256];
	sprintf(snap_dir, "%s%c%s%c%s", retro_save_directory, slash, core, slash, "snaps");
	xargv[paramCount++] = (char*)(snap_dir);
		
	xargv[paramCount++] = (char*)("-diff_directory");

	char diff_dir[256];
	sprintf(diff_dir, "%s%c%s%c%s", retro_save_directory, slash, core, slash, "diff");
	xargv[paramCount++] = (char*)(diff_dir);
	
	xargv[paramCount++] = (char*)("-samplepath");
	
	char samples_dir[256];
	sprintf(samples_dir, "%s%c%s%c%s", retro_system_directory, slash, core, slash, "samples");
	xargv[paramCount++] = (char*)(samples_dir);
	
	xargv[paramCount++] = (char*)("-artpath");
	
	char art_dir[256];
	sprintf(art_dir, "%s%c%s%c%s", retro_system_directory, slash, core, slash, "artwork");
	xargv[paramCount++] = (char*)(art_dir);
		
	xargv[paramCount++] = (char*)("-cheatpath");
	
	char cheat_dir[256];
	sprintf(cheat_dir, "%s%c%s%c%s", retro_system_directory, slash, core, slash, "cheat");
	xargv[paramCount++] = (char*)(cheat_dir);
	
	xargv[paramCount++] = (char*)("-inipath");
	
	char ini_dir[256];
	sprintf(ini_dir, "%s%c%s%c%s", retro_system_directory, slash, core, slash, "ini");
	xargv[paramCount++] = (char*)(ini_dir);	
	xargv[paramCount++] = (char*)("-hashpath");
	
	char hash_dir[256];
	sprintf(hash_dir, "%s%c%s%c%s", retro_system_directory, slash, core, slash, "hash");
	xargv[paramCount++] = (char*)(hash_dir);				
	
	if (tate) {
		if (screenRot == 3) {
			xargv[paramCount++] =(char*) "-rol";
		} else {
			xargv[paramCount++] = (char*)(screenRot ? "-mouse" : "-ror");
		}
	} else {
		if (screenRot == 2) {
			xargv[paramCount++] = (char*)"-rol";
		} else {
			xargv[paramCount++] = (char*)(screenRot ? "-ror" : "-mouse");
		}
	}

	xargv[paramCount++] = (char*)("-rompath");
	
	char rom_dir[256];
		
#ifdef WANT_MAME
   sprintf(rom_dir, "%s", MgamePath);
   xargv[paramCount++] = (char*)(rom_dir);		   
   if(!boot_to_osd_enabled)
      xargv[paramCount++] = MgameName;
  
#else
   if(!commandline_enabled)
   {
	   if(!boot_to_osd_enabled)
	   {
		  sprintf(rom_dir, "%s", MgamePath);
		  xargv[paramCount++] = (char*)(rom_dir);		   
		  if(softlist_enabled)
		  {
			 if(!arcade)
			 {
				xargv[paramCount++] = MsystemName;   
				if(!boot_to_bios_enabled)
				{
				   if(!softlist_auto)
					  xargv[paramCount++] = (char*)mediaType;
				   xargv[paramCount++] = (char*)MgameName;
				}
			 }
			 else
			 {
				xargv[paramCount++] = (char*)MgameName;
			 }	     
		  }
		  else
		  {
			 if (strcmp(mediaType, "-rom") == 0) {
				xargv[paramCount++] = MgameName;
			 } else {
				xargv[paramCount++] = MsystemName;
				xargv[paramCount++] = (char*)mediaType;
				xargv[paramCount++] = (char*)gameName;
			 }   
	   
		  }
		}
		else
		{
		  sprintf(rom_dir, "%s;%s", MgamePath,MparentPath);
		  xargv[paramCount++] = (char*)(rom_dir);		   	
		}
	}
	else
	
	   xargv[paramCount++] = (char*)gameName;
	

   	
#endif 	 	 
	
	write_log("frontend parameters:%i\n", paramCount);

	for (int i = 0; xargv[i] != NULL; i++){
		write_log("  %s\n",xargv[i]);
	}
	
	osd_init_midi();

	cli_options MRoptions;
	mini_osd_interface MRosd;
	cli_frontend frontend(MRoptions, MRosd);
	result = frontend.execute(paramCount, ( char **)xargv); 

	xargv[paramCount - 2] = NULL;
	return result;
}