CMultitaskCompositeMachine::CMultitaskCompositeMachine(
     CMachine* machine, CFeatures* train_features, 
     CLabels* train_labels, CTaskGroup* task_group) :
	CMachine(), m_machine(NULL), m_features(NULL), 
	m_current_task(0), m_task_group(NULL)
{
	set_machine(machine);
	set_features(train_features);
	set_labels(train_labels);
	set_task_group(task_group);
	register_parameters();
}
Exemple #2
0
int machine_manager::execute()
{
	bool started_empty = false;

	bool firstgame = true;
	bool firstrun = true;

	// loop across multiple hard resets
	bool exit_pending = false;
	int error = MAMERR_NONE;

	if (m_options.console()) {
		m_lua->start_console();
	}
	while (error == MAMERR_NONE && !exit_pending)
	{
		m_new_driver_pending = nullptr;

		// if no driver, use the internal empty driver
		const game_driver *system = m_options.system();
		if (system == nullptr)
		{
			system = &GAME_NAME(___empty);
			if (firstgame)
				started_empty = true;
		}

		firstgame = false;

		// parse any INI files as the first thing
		if (m_options.read_config())
		{
			m_options.revert(OPTION_PRIORITY_INI);
			std::string errors;
			m_options.parse_standard_inis(errors);
		}

		// otherwise, perform validity checks before anything else
		if (system != nullptr)
		{
			validity_checker valid(m_options);
			valid.set_verbose(false);
			valid.check_shared_source(*system);
		}

		// create the machine configuration
		machine_config config(*system, m_options);

		// create the machine structure and driver
		running_machine machine(config, *this);

		set_machine(&machine);

		// run the machine
		error = machine.run(firstrun);
		firstrun = false;

		// check the state of the machine
		if (m_new_driver_pending)
		{
			std::string old_system_name(m_options.system_name());
			bool new_system = (old_system_name.compare(m_new_driver_pending->name)!=0);
			// first: if we scheduled a new system, remove device options of the old system
			// notice that, if we relaunch the same system, there is no effect on the emulation
			if (new_system)
				m_options.remove_device_options();
			// second: set up new system name (and the related device options)
			m_options.set_system_name(m_new_driver_pending->name);
			// third: if we scheduled a new system, take also care of ramsize options
			if (new_system)
			{
				std::string error_string;
				m_options.set_value(OPTION_RAMSIZE, "", OPTION_PRIORITY_CMDLINE, error_string);
			}
			firstrun = true;
			if (m_options.software_name())
			{
				std::string sw_load(m_options.software_name());
				std::string sw_list, sw_name, sw_part, sw_instance, option_errors, error_string;
				int left = sw_load.find_first_of(':');
				int middle = sw_load.find_first_of(':', left + 1);
				int right = sw_load.find_last_of(':');

				sw_list = sw_load.substr(0, left - 1);
				sw_name = sw_load.substr(left + 1, middle - left - 1);
				sw_part = sw_load.substr(middle + 1, right - middle - 1);
				sw_instance = sw_load.substr(right + 1);
				sw_load.assign(sw_load.substr(0, right));

				char arg[] = "ume";
				char *argv = &arg[0];
				m_options.set_value(OPTION_SOFTWARENAME, sw_name.c_str(), OPTION_PRIORITY_CMDLINE, error_string);
				m_options.parse_slot_devices(1, &argv, option_errors, sw_instance.c_str(), sw_load.c_str());
			}
		}
		else
		{
			if (machine.exit_pending()) m_options.set_system_name("");
		}

		if (machine.exit_pending() && (!started_empty || (system == &GAME_NAME(___empty))))
			exit_pending = true;

		// machine will go away when we exit scope
		set_machine(nullptr);
	}
	// return an error
	return error;
}
Exemple #3
0
int machine_manager::execute()
{
	bool started_empty = false;

	bool firstgame = true;
	bool firstrun = true;

	// loop across multiple hard resets
	bool exit_pending = false;
	int error = MAMERR_NONE;

	m_lua.initialize();
	if (m_options.console()) {
		m_lua.start_console();
	}
	while (error == MAMERR_NONE && !exit_pending)
	{
		m_new_driver_pending = NULL;

		// if no driver, use the internal empty driver
		const game_driver *system = m_options.system();
		if (system == NULL)
		{
			system = &GAME_NAME(___empty);
			if (firstgame)
				started_empty = true;
		}

		firstgame = false;

		// parse any INI files as the first thing
		if (m_options.read_config())
		{
			m_options.revert(OPTION_PRIORITY_INI);
			astring errors;
			m_options.parse_standard_inis(errors);
		}

		// otherwise, perform validity checks before anything else
		if (system != NULL)
		{
			validity_checker valid(m_options);
			valid.check_shared_source(*system);
		}

		// create the machine configuration
		machine_config config(*system, m_options);

		//Set up client/server as appropriate
		if(m_options.client())
		  {
		    deleteGlobalClient();
		    createGlobalClient(m_options.username());
		  }
		else if(m_options.server())
		  {
		    deleteGlobalServer();
		    createGlobalServer(m_options.username(),
                           (unsigned short)m_options.port(),
                           m_options.baseDelay(),
                           m_options.rollback());
		    netServer->setSyncTransferTime(m_options.syncTransferSeconds());
		  }

		// create the machine structure and driver
		running_machine machine(config, *this);

		set_machine(&machine);

		// run the machine
		error = machine.run(firstrun);
		firstrun = false;

		deleteGlobalClient();
		deleteGlobalServer();

		// check the state of the machine
		if (m_new_driver_pending)
		{
			astring old_system_name(m_options.system_name());
			bool new_system = (old_system_name != m_new_driver_pending->name);
			// first: if we scheduled a new system, remove device options of the old system
			// notice that, if we relaunch the same system, there is no effect on the emulation
			if (new_system)
				m_options.remove_device_options();
			// second: set up new system name (and the related device options)
			m_options.set_system_name(m_new_driver_pending->name);
			// third: if we scheduled a new system, take also care of ramsize options
			if (new_system)
			{
				astring error_string;
				m_options.set_value(OPTION_RAMSIZE, "", OPTION_PRIORITY_CMDLINE, error_string);
			}
			firstrun = true;
		}
		else
		{
			if (machine.exit_pending()) m_options.set_system_name("");
		}

		if (machine.exit_pending() && (!started_empty || (system == &GAME_NAME(___empty))))
			exit_pending = true;

		// machine will go away when we exit scope
		set_machine(NULL);
	}
	// return an error
	return error;
}
Exemple #4
0
int mame_machine_manager::execute()
{
	bool started_empty = false;

	bool firstgame = true;
	bool firstrun = true;

	// loop across multiple hard resets
	bool exit_pending = false;
	int error = EMU_ERR_NONE;

	if (m_options.console()) {
		m_lua->start_console();
	}
	while (error == EMU_ERR_NONE && !exit_pending)
	{
		m_new_driver_pending = nullptr;

		// if no driver, use the internal empty driver
		const game_driver *system = m_options.system();
		if (system == nullptr)
		{
			system = &GAME_NAME(___empty);
			if (firstgame)
				started_empty = true;
		}

		firstgame = false;

		// parse any INI files as the first thing
		if (m_options.read_config())
		{
			m_options.revert(OPTION_PRIORITY_INI);
			std::string errors;
			mame_options::parse_standard_inis(m_options,errors);
		}

		// otherwise, perform validity checks before anything else
		if (system != nullptr)
		{
			validity_checker valid(m_options);
			valid.set_verbose(false);
			valid.check_shared_source(*system);
		}

		// create the machine configuration
		machine_config config(*system, m_options);

		// create the machine structure and driver
		running_machine machine(config, *this);

		set_machine(&machine);

		// run the machine
		error = machine.run(firstrun);
		firstrun = false;

		// check the state of the machine
		if (m_new_driver_pending)
		{
			// set up new system name and adjust device options accordingly
			mame_options::set_system_name(m_options,m_new_driver_pending->name);
			firstrun = true;
		}
		else
		{
			if (machine.exit_pending()) mame_options::set_system_name(m_options,"");
		}

		if (machine.exit_pending() && (!started_empty || (system == &GAME_NAME(___empty))))
			exit_pending = true;

		// machine will go away when we exit scope
		set_machine(nullptr);
	}
	// return an error
	return error;
}
Exemple #5
0
int main(int argc, char **argv) {
#define FIND_LONG_OPTION(ARRAY) \
	{															\
		for(i = 0; i < sizeof (ARRAY) / sizeof(struct option); i++) {							\
			struct option *o = (ARRAY) + i;										\
			if(o->arg < 2) {											\
				if(strcmp(arg, o->opt) == 0) {									\
					const char *a = o->arg ? *++v : argv[0];						\
					if(o->arg && !a) {									\
						fprintf(stderr, "%s: option '%s' need an argument\n", argv[0], *v);		\
						return 1;									\
					}											\
					if(o->act) o->act(a);									\
					goto first_loop;									\
				}												\
			} else {												\
				size_t len = strlen(o->opt);									\
				if(strncmp(arg, o->opt, len) == 0) {								\
					if(arg[len] && arg[len] != '=') continue;						\
					if(!arg[len] || !arg[len + 1]) {							\
						fprintf(stderr, "%s: option '%s' need an argument\n", argv[0], *v);		\
						return 1;									\
					}											\
					const char *a = arg + len + 1;								\
					if(o->act) o->act(a);									\
					goto first_loop;									\
				}												\
			}													\
		}														\
	}

#define UNRECOGNIZED_OPTION(O) \
	do {									\
		fprintf(stderr, "%s: error: unrecognized option '%s'\n",	\
			argv[0], (O));						\
		return 1;							\
	} while(0)


	int verbose = 0;
	int no_link = 0;
	int preprocess_only = -1;
	int no_warning = -1;
	int end_of_options = 0;
	const char *output_file = NULL;
	char **v = argv;
	init_argv();

	const char *vs_path = getenv("VS_PATH");
	if(!vs_path) vs_path = getenv("VSINSTALLDIR");
	if(!getenv("INCLUDE")) {
		if(vs_path) {
			size_t len = strlen(vs_path);
			if(vs_path[len - 1] == '/' || vs_path[len - 1] == '\\') len--; 
			char buffer[len + 12 + len + 24 + 1];
			memcpy(buffer, vs_path, len);
			memcpy(buffer + len, "/VC/include;", 12);
			memcpy(buffer + len + 12, vs_path, len);
			strcpy(buffer + len + 12 + len, "/VC/PlatformSDK/include;");
			setenv("INCLUDE", buffer, 0);
		} else {
			no_warning = find_argv(argv, "-w");
			if(!no_warning) fprintf(stderr, "%s: warning: no system include path set\n", argv[0]);
		}
	}
	if(!getenv("LIB")) {
		if(vs_path) {
			size_t len = strlen(vs_path);
			if(vs_path[len - 1] == '/' || vs_path[len - 1] == '\\') len--; 
			char buffer[len + 8 + len + 20 + 1];
			memcpy(buffer, vs_path, len);
			memcpy(buffer + len, "/VC/lib;", 8);
			memcpy(buffer + len + 12, vs_path, len);
			strcpy(buffer + len + 12 + len, "/VC/PlatformSDK/lib;");
			setenv("LIB", buffer, 0);
		} else {
			if(no_warning == -1) no_warning = find_argv(argv, "-w");
			if(!no_warning) fprintf(stderr, "%s: warning: no system library path set\n", argv[0]);
		}
	}

first_loop:
	while(*++v) {
		if(!end_of_options && **v == '-') {
			int i;
			if((*v)[1] == '-') {
				const char *arg = *v + 2;
				if(!*arg) {
					end_of_options = 1;
					continue;
				}
				FIND_LONG_OPTION(double_dash_long_options);
				if(strcmp(arg, "verbose") == 0) {
					verbose = 1;
				} else UNRECOGNIZED_OPTION(*v);
			} else {
				const char *arg = *v + 1;
				FIND_LONG_OPTION(singal_dash_long_options);
				switch(*arg) {
					case 0:
						goto not_an_option;
					case 'c':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-c");
						no_link = 1;
						break;
					case 'D':
						if(arg[1]) add_to_argv(*v);
						else {
							const char *d = *++v;
							if(!d) {
								fprintf(stderr, "%s: error: macro name missing after '-D'\n",
									argv[0]);
								return 1;
							}
							define(d);
						}
						break;
					case 'E':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-E");
						preprocess_only = 1;						
						break;
					case 'f':
						if(arg[1]) set_feature(arg + 1);
						else {
							const char *feature = *++v;
							if(!feature) {
								fprintf(stderr, "%s: error: option '-f' need an argument\n",
									argv[0]);
								return -1;
							}
							set_feature(feature);
						}
						break;
					case 'g':
						// -g[coff][<level>] (level: 0~3)
						if(arg[1]) {
							const char *level = arg + 1;
							if(strncmp(level, "coff", 4) == 0) level += 4;
							if(*level && *level != '-') {
								int i = 0;
								do {
									if(!isdigit(level[i])) {
										fprintf(stderr, "%s: error: unrecognized debug output level \"%s\"\n",
											argv[0], level);
										return 1;
									}
								} while(level[++i]);
								/*
								if(i > 1 || *level > '3') {
									fprintf(stderr, "%s: error: debug output level %s is too high\n",
										argv[0], level);
									return 1;
								}
								if(*level == '0') break;
								*/
								int l = atoi(level);
								if(!l) break;
								if(l > 3) {
									fprintf(stderr, "%s: error: debug output level %s is too high\n",
										argv[0], level);
									return 1;
								}
							}
						}
						add_to_argv("-Zi");
						break;
					case 'I':
						if(no_warning == -1) no_warning = find_argv(argv, "-w");
						//if(arg[1]) add_to_argv(*v);
						if(arg[1]) add_include_path(arg + 1, no_warning);
						else {
							const char *path = *++v;
							if(!path) {
								fprintf(stderr, "%s: error: option '-I' need an argument\n",
									argv[0]);
								return 1;
							}
							add_include_path(path, no_warning);
						}
						break;
					case 'L':
						if(no_warning == -1) no_warning = find_argv(argv, "-w");
						if(arg[1]) add_library_path(arg + 1, no_warning);
						else {
							const char *path = *++v;
							if(!path) {
								fprintf(stderr, "%s: error: option '-L' need an argument\n",
									argv[0]);
								return 1;
							}
							add_library_path(path, no_warning);
						}
						break;
					case 'l':
						if(arg[1]) add_library(arg + 1);
						else {
							const char *path = *++v;
							if(!path) {
								fprintf(stderr, "%s: error: option '-l' need an argument\n",
									argv[0]);
								return 1;
							}
							add_library(path);
						}
						break;
					case 'M':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-showIncludes");
						break;
					case 'm':
						if(arg[1]) set_machine(arg + 1);
						else {
							const char *machine = *++v;
							if(!machine) {
								fprintf(stderr, "%s: argument to `-m' is missing\n",
									argv[0]);
								return 1;
							}
							set_machine(machine);
						}
						break;
					case 'O':
						if(arg[1]) {
							const char *o = arg + 1;
							if(strcmp(o, "0") == 0) add_to_argv("-Od");
							else if(strcmp(o, "1") == 0) add_to_argv("-O2");
							else if(strcmp(o, "3") == 0) add_to_argv("-Ox");
							else if(strcmp(o, "s") == 0) add_to_argv("-O1");
							else if(strcmp(o, "fast") == 0) add_to_argv("-O2");
							else add_to_argv(*v);
						} else add_to_argv("-O2");
						break;
					case 'o':
						if(arg[1]) output_file = arg + 1;
						else {
							output_file = *++v;
							if(!output_file) {
								fprintf(stderr, "%s: error: option '-o' need an argument\n",
									argv[0]);
								return 1;
							}
						}
						break;
					case 'P':
						if(preprocess_only == -1) preprocess_only = find_argv(argv, "-E");
						if(preprocess_only) add_to_argv("-EP");
						break;
					case 's':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						break;
					case 'U':
						if(arg[1]) add_to_argv(*v);
						else {
							const char *u = *++v;
							if(!u) {
								fprintf(stderr, "%s: error: macro name missing after '-U'\n",
									argv[0]);
								return 1;
							}
							undefine(u);
						}
						break;
					case 'v':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						verbose = 1;
						break;
					case 'W':
						if(!arg[1]) {
							if(no_warning == -1) no_warning = find_argv(argv, "-w");
							if(!no_warning) {
								fprintf(stderr, "%s: warning: option '-W' is deprecated; use '-Wextra' instead\n",
									argv[0]);
							}
							add_to_argv("-Wall");
							break;
						}
						if(strncmp(arg, "Wa,", 3) == 0 || strncmp(arg, "Wp,", 3) == 0 || strncmp(arg, "Wl,", 3) == 0) {
							(*v)[3] = 0;		// XXX
							fprintf(stderr, "%s: warning: option '%s' is not supported\n", argv[0], *v);
							break;
						} 
						if(set_warning(arg + 1)) break;
						add_to_argv(*v);
						break;
					case 'w':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-w");
						no_warning = 1;
						break;
					case 'x':
						if(arg[1]) set_language(arg + 1);
						else {
							const char *lang = *++v;
							if(!lang) {
								fprintf(stderr, "%s: error: missing argument to ‘-x’",
									argv[0]);
								return 4;
							}
							set_language(lang);
						}
						break;
					default:
						fprintf(stderr, "%s: error: unrecognized option '%s'\n", argv[0], *v);
						return 1;
				}
			}
		} else {
not_an_option:
#if defined __INTERIX && !defined _NO_CONV_PATH
			if(**v == '/') {
				char buffer[PATH_MAX + 1];
				if(unixpath2win(*v, 0, buffer, sizeof buffer) == 0) {
					add_input_file(buffer);
				} else {
					if(no_warning == -1) no_warning = find_argv(argv, "-w");
					if(!no_warning) {
						fprintf(stderr, "%s: warning: cannot convert '%s' to Windows path name, %s\n",
							argv[0], *v, strerror(errno));
					}
					add_input_file(*v);
				}
			} else
#endif
			add_input_file(*v);
		}
	}
	setvbuf(stdout, NULL, _IOLBF, 0);
	if(preprocess_only == -1) preprocess_only = 0;
	if(no_warning == -1) no_warning = 0;
	if(last_language && last_language_unused && !no_warning) {
		fprintf(stderr, "%s: warning: '-x %s' after last input file has no effect\n", argv[0], last_language);
	}
	if(!first_input_file) {
		if(verbose) {
			if(!no_link) add_to_argv("-c");
			start_cl();
			return 0;
		}
		fprintf(stderr, "%s: no input files\n", argv[0]);
		return 1;
	}
	if(multiple_input_files && (preprocess_only || no_link)) {
		if(output_file) {
			fprintf(stderr, "%s: error: cannot specify -o with -c or -E with multiple files\n", argv[0]);
			return 4;
		} else if(no_link) {
			fprintf(stderr, "%s: error: '-c' with multiple files is currently not supported\n", argv[0]);
			return -1;
		}
	}
	if(!output_file && !preprocess_only) {
		if(no_link) {
			size_t len = strlen(first_input_file);
			int n = get_last_dot(first_input_file, len);
			if(n >= 0) len = n;
			char *p = malloc(len + 3);
			if(!p) {
				perror(argv[0]);
				return 1;
			}
			memcpy(p, first_input_file, len);
			strcpy(p + len, ".o");
			output_file = p;
		} else output_file = DEFAULT_OUTPUT_FILENAME;
	}
	if(!verbose) add_to_argv("-nologo");
	if(preprocess_only) {
		if(output_file) target.name = output_file;
		target.type = PREPROCESSED_SOURCE;
	} else set_output_file(output_file, no_link, no_warning);
	//if(no_static_link) add_to_argv("-MD");
	add_to_argv(no_static_link ? "-MD" : "-MT");
	add_libraries_to_argv();
	if(verbose) print_argv();
	return start_cl();
}