Beispiel #1
0
void emu_options::set_system_name(const char *name)
{
	// remember the original system name
	std::string old_system_name(system_name());

	// if the system name changed, fix up the device options
	if (old_system_name.compare(name)!=0)
	{
		// first set the new name
		astring error;
		set_value(OPTION_SYSTEMNAME, name, OPTION_PRIORITY_CMDLINE, error);
		assert(error.empty());

		// remove any existing device options and then add them afresh
		remove_device_options();
		if (add_slot_options(true))
			while (add_slot_options(false)) { }

		// then add the options
		add_device_options(true);
		int num = 0;
		do {
			num = options_count();
			update_slot_options();
		} while(num != options_count());
	}
}
Beispiel #2
0
bool emu_options::parse_slot_devices(int argc, char *argv[], std::string &error_string, const char *name, const char *value, const software_part *swpart)
{
	// an initial parse to capture the initial set of values
	bool result;

	core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);

	// keep adding slot options until we stop seeing new stuff
	while (add_slot_options(swpart))
		core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);

	// add device options and reparse
	add_device_options();
	if (name != nullptr && exists(name))
		set_value(name, value, OPTION_PRIORITY_SUBCMD, error_string);
	core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);

	int num;
	do {
		num = options_count();
		update_slot_options(swpart);
		result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);
	} while (num != options_count());

	update_cached_options();

	return result;
}
Beispiel #3
0
bool emu_options::parse_slot_devices(int argc, char *argv[], astring &error_string, const char *name, const char *value)
{
	// an initial parse to capture the initial set of values
	bool result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);

	// keep adding slot options until we stop seeing new stuff
	bool isfirstpass = true;
	while (add_slot_options(isfirstpass))
	{
		result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);
		isfirstpass = false;
	}

	// add device options and reparse
	add_device_options(true);
	if (name != NULL && exists(name))
		set_value(name, value, OPTION_PRIORITY_CMDLINE, error_string);
	result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);

	int num = 0;
	do {
		num = options_count();
		update_slot_options();
		result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);
	} while (num != options_count());

	return result;
}
Beispiel #4
0
void emu_options::set_system_name(const char *name)
{
	// remember the original system name
	astring old_system_name(system_name());

	// if the system name changed, fix up the device options
	if (old_system_name != name)
	{
		// first set the new name
		astring error;
		set_value(OPTION_SYSTEMNAME, name, OPTION_PRIORITY_CMDLINE, error);
		assert(!error);
		// remove any existing device options
		remove_device_options();

		bool isfirst = true;
		while (add_slot_options(isfirst)) {
			isfirst = false;
		}
		// then add the options
		add_device_options(true);
		int num = 0;
		do {
			num = options_count();
			update_slot_options();
			while (add_slot_options(false));
			add_device_options(false);
		} while(num != options_count());
	}
}
Beispiel #5
0
bool emu_options::parse_slot_devices(int argc, char *argv[], astring &error_string, const char *name, const char *value)
{
	bool isfirst = true;
	bool result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);
	while (add_slot_options(isfirst)) {
		result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);
		isfirst = false;
	}
	add_device_options(true);
	if (name && exists(name)) {
		set_value(name, value, OPTION_PRIORITY_CMDLINE, error_string);
	}
	result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);

	int num = 0;
	do {
		num = options_count();
		update_slot_options();
		while (add_slot_options(false));
		add_device_options(false);
		result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);
	} while(num != options_count());

	return result;
}
Beispiel #6
0
bool emu_options::add_slot_options(const software_part *swpart)
{
	// look up the system configured by name; if no match, do nothing
	const game_driver *cursystem = system();
	if (cursystem == nullptr)
		return false;

	// create the configuration
	machine_config config(*cursystem, *this);

	// iterate through all slot devices
	int starting_count = options_count();
	slot_interface_iterator iter(config.root_device());
	for (const device_slot_interface *slot = iter.first(); slot != nullptr; slot = iter.next())
	{
		// skip fixed slots
		if (slot->fixed())
			continue;

		// first device? add the header as to be pretty
		if (m_slot_options++ == 0)
			add_entry(nullptr, "SLOT DEVICES", OPTION_HEADER | OPTION_FLAG_DEVICE);

		// retrieve info about the device instance
		const char *name = slot->device().tag() + 1;
		if (!exists(name))
		{
			// add the option
			UINT32 flags = OPTION_STRING | OPTION_FLAG_DEVICE;
			const char *defvalue = slot->default_option();
			if (defvalue != nullptr)
			{
				const device_slot_option *option = slot->option(defvalue);
				if (option != nullptr && !option->selectable())
					flags |= OPTION_FLAG_INTERNAL;
			}
			add_entry(name, nullptr, flags, defvalue, true);
		}

		// allow software lists to supply their own defaults
		if (swpart != nullptr)
		{
			std::string featurename = std::string(name).append("_default");
			const char *value = swpart->feature(featurename.c_str());
			if (value != nullptr && (*value == '\0' || slot->option(value) != nullptr))
				set_default_value(name, value);
		}
	}
	return (options_count() != starting_count);
}
Beispiel #7
0
bool emu_options::add_slot_options(bool isfirstpass)
{
	// look up the system configured by name; if no match, do nothing
	const game_driver *cursystem = system();
	if (cursystem == NULL)
		return false;
	machine_config config(*cursystem, *this);

	// iterate through all slot devices
	bool first = true;

	// create the configuration
	int starting_count = options_count();
	slot_interface_iterator iter(config.root_device());
	for (const device_slot_interface *slot = iter.first(); slot != NULL; slot = iter.next())
	{
		// skip fixed slots
		if (slot->fixed())
			continue;

		// first device? add the header as to be pretty
		if (isfirstpass && first)
			add_entry(NULL, "SLOT DEVICES", OPTION_HEADER | OPTION_FLAG_DEVICE);
		first = false;

		// retrieve info about the device instance
		const char *name = slot->device().tag() + 1;
		if (!exists(name))
		{
			// add the option
			UINT32 flags = OPTION_STRING | OPTION_FLAG_DEVICE;
			const char *defvalue = slot->default_option();
			if (defvalue != NULL)
			{
				const device_slot_option *option = slot->option(defvalue);
				if (option != NULL && !option->selectable())
					flags |= OPTION_FLAG_INTERNAL;
			}
			add_entry(name, NULL, flags, defvalue, true);
		}
	}
	return (options_count() != starting_count);
}
Beispiel #8
0
// Parse pools array in json config
bool parse_pool_array(json_t *obj)
{
	size_t idx;
	json_t *p, *val;

	if (!json_is_array(obj))
		return false;

	// array of objects [ {}, {} ]
	json_array_foreach(obj, idx, p)
	{
		if (!json_is_object(p))
			continue;

		for (int i = 0; i < ARRAY_SIZE(cfg_array_keys); i++)
		{
			int opt = -1;
			char *s = NULL;
			if (cfg_array_keys[i].cat != CFG_POOL)
				continue;

			val = json_object_get(p, cfg_array_keys[i].name);
			if (!val)
				continue;

			for (int k = 0; k < options_count(); k++)
			{
				const char *alias = cfg_array_keys[i].longname;
				if (alias && !strcasecmp(options[k].name, alias)) {
					opt = k;
					break;
				}
				if (!alias && !strcasecmp(options[k].name, cfg_array_keys[i].name)) {
					opt = k;
					break;
				}
			}
			if (opt == -1)
				continue;

			if (json_is_string(val)) {
				s = strdup(json_string_value(val));
				if (!s)
					continue;

				// applog(LOG_DEBUG, "pool key %s '%s'", options[opt].name, s);
				parse_arg(options[opt].val, s);
				free(s);
			} else {
				// numeric or bool
				char buf[32] = { 0 };
				double d = 0.;
				if (json_is_true(val)) d = 1.;
				else if (json_is_integer(val))
					d = 1.0 * json_integer_value(val);
				else if (json_is_real(val))
					d = json_real_value(val);
				snprintf(buf, sizeof(buf)-1, "%f", d);
				// applog(LOG_DEBUG, "pool key %s '%f'", options[opt].name, d);
				parse_arg(options[opt].val, buf);
			}
		}
	}
	return true;
}
Beispiel #9
0
void emu_options::set_system_name(const char *name)
{
	// remember the original system name
	std::string old_system_name(system_name());
	bool new_system = old_system_name.compare(name)!=0;

	// if the system name changed, fix up the device options
	if (new_system)
	{
		// first set the new name
		std::string error;
		set_value(OPTION_SYSTEMNAME, name, OPTION_PRIORITY_CMDLINE, error);
		assert(error.empty());

		// remove any existing device options
		remove_device_options();
	}
	else
	{
		// revert device options set for the old software
		revert(OPTION_PRIORITY_SUBCMD, OPTION_PRIORITY_SUBCMD);
	}

	// get the new system
	const game_driver *cursystem = system();
	if (cursystem == nullptr)
		return;

	if (*software_name() != 0)
	{
		std::string sw_load(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));

		// look up the software part
		machine_config config(*cursystem, *this);
		software_list_device *swlist = software_list_device::find_by_name(config, sw_list.c_str());
		software_info *swinfo = swlist != nullptr ? swlist->find(sw_name.c_str()) : nullptr;
		software_part *swpart = swinfo != nullptr ? swinfo->find_part(sw_part.c_str()) : nullptr;

		// then add the options
		if (new_system)
		{
			while (add_slot_options(swpart)) { }
			add_device_options();
		}

		set_value(OPTION_SOFTWARENAME, sw_name.c_str(), OPTION_PRIORITY_CMDLINE, error_string);
		if (exists(sw_instance.c_str()))
			set_value(sw_instance.c_str(), sw_load.c_str(), OPTION_PRIORITY_SUBCMD, error_string);

		int num;
		do {
			num = options_count();
			update_slot_options(swpart);
		} while(num != options_count());
	}
	else if (new_system)
	{
		// add the options afresh
		while (add_slot_options()) { }
		add_device_options();
		int num;
		do {
			num = options_count();
			update_slot_options();
		} while(num != options_count());
	}
}