Example #1
0
	static vector<char> GetBytes(astring filePath)
	{
		vector<char> bytes;
		
#ifdef _WIN32
		ifstream fin(filePath.c_str(), ios::binary | ios::in);
#else
		ifstream fin(ToUtf8String(filePath.c_str()).c_str(), ios::binary | ios::in);
#endif

		ACE_ASSERT(!fin.fail(), "ファイルは開けませんでした");

		while (!fin.eof())
		{
			char byte;
			fin.read(&byte, 1);
			if (!fin.eof())
			{
				bytes.push_back(byte);
			}
		}

		fin.close();

		return bytes;
	}
Example #2
0
void ui_menu_image_info::image_info_astring(running_machine &machine, astring &string)
{
	string.printf("%s\n\n", machine.system().description);

#if 0
	if (mess_ram_size > 0)
	{
		char buf2[RAM_STRING_BUFLEN];
		string.catprintf("RAM: %s\n\n", ram_string(buf2, mess_ram_size));
	}
#endif

	image_interface_iterator iter(machine.root_device());
	for (device_image_interface *image = iter.first(); image != NULL; image = iter.next())
	{
		const char *name = image->filename();
		if (name != NULL)
		{
			const char *base_filename;
			const char *info;
			char *base_filename_noextension;

			base_filename = image->basename();
			base_filename_noextension = strip_extension(base_filename);

			// display device type and filename
			string.catprintf("%s: %s\n", image->device().name(), base_filename);

			// display long filename, if present and doesn't correspond to name
			info = image->longname();
			if (info && (!base_filename_noextension || core_stricmp(info, base_filename_noextension)))
				string.catprintf("%s\n", info);

			// display manufacturer, if available
			info = image->manufacturer();
			if (info != NULL)
			{
				string.catprintf("%s", info);
				info = stripspace(image->year());
				if (info && *info)
					string.catprintf(", %s", info);
				string.catprintf("\n");
			}

			// display supported information, if available
			switch(image->supported()) {
				case SOFTWARE_SUPPORTED_NO : string.catprintf("Not supported\n"); break;
				case SOFTWARE_SUPPORTED_PARTIAL : string.catprintf("Partially supported\n"); break;
				default : break;
			}

			if (base_filename_noextension != NULL)
				free(base_filename_noextension);
		}
		else
		{
			string.catprintf("%s: ---\n", image->device().name());
		}
	}
}
Example #3
0
bool path_iterator::next(astring &buffer, const char *name)
{
    // if none left, return FALSE to indicate we are done
    if (m_index != 0 && *m_current == 0)
        return false;

    // copy up to the next semicolon
    const char *semi = strchr(m_current, ';');
    if (semi == NULL)
        semi = m_current + strlen(m_current);
    buffer.cpy(m_current, semi - m_current);
    m_current = (*semi == 0) ? semi : semi + 1;

    // append the name if we have one
    if (name != NULL)
    {
        // compute the full pathname
        if (buffer.len() > 0)
            buffer.cat(PATH_SEPARATOR);
        buffer.cat(name);
    }

    // bump the index and return TRUE
    m_index++;
    return true;
}
Example #4
0
bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_priority, astring &error_string)
{
	// loop over lines in the file
	char buffer[4096];
	while (core_fgets(buffer, ARRAY_LENGTH(buffer), &inifile) != NULL)
	{
		// find the extent of the name
		char *optionname;
		for (optionname = buffer; *optionname != 0; optionname++)
			if (!isspace((UINT8)*optionname))
				break;

		// skip comments
		if (*optionname == 0 || *optionname == '#')
			continue;

		// scan forward to find the first space
		char *temp;
		for (temp = optionname; *temp != 0; temp++)
			if (isspace((UINT8)*temp))
				break;

		// if we hit the end early, print a warning and continue
		if (*temp == 0)
		{
			error_string.catprintf("Warning: invalid line in INI: %s", buffer);
			continue;
		}

		// NULL-terminate
		*temp++ = 0;
		char *optiondata = temp;

		// scan the data, stopping when we hit a comment
		bool inquotes = false;
		for (temp = optiondata; *temp != 0; temp++)
		{
			if (*temp == '"')
				inquotes = !inquotes;
			if (*temp == '#' && !inquotes)
				break;
		}
		*temp = 0;

		// find our entry
		entry *curentry = m_entrymap.find(optionname);
		if (curentry == NULL)
		{
			if (priority >= ignore_priority)
				error_string.catprintf("Warning: unknown option in INI: %s\n", optionname);
			continue;
		}

		// set the new data
		validate_and_set_data(*curentry, optiondata, priority, error_string);
	}
	return true;
}
Example #5
0
bool core_options::parse_command_line(int argc, char **argv, int priority, astring &error_string)
{
	// reset the errors and the command
	error_string.reset();
	m_command.reset();

	// iterate through arguments
	int unadorned_index = 0;
	bool retVal = true;
	for (int arg = 1; arg < argc; arg++)
	{
		// determine the entry name to search for
		const char *curarg = argv[arg];
		bool is_unadorned = (curarg[0] != '-');
		const char *optionname = is_unadorned ? core_options::unadorned(unadorned_index++) : &curarg[1];

		// find our entry; if not found, indicate invalid option
		entry *curentry = m_entrymap.find(optionname);
		if (curentry == NULL)
		{
			error_string.catprintf("Error: unknown option: %s\n", curarg);
			retVal = false;
			if (!is_unadorned) arg++;
			continue;
		}

		// process commands first
		if (curentry->type() == OPTION_COMMAND)
		{
			// can only have one command
			if (m_command)
			{
				error_string.catprintf("Error: multiple commands specified -%s and %s\n", m_command.cstr(), curarg);
				return false;
			}
			m_command = curentry->name();
			continue;
		}

		// get the data for this argument, special casing booleans
		const char *newdata;
		if (curentry->type() == OPTION_BOOLEAN)
			newdata = (strncmp(&curarg[1], "no", 2) == 0) ? "0" : "1";
		else if (is_unadorned)
			newdata = curarg;
		else if (arg + 1 < argc)
			newdata = argv[++arg];
		else
		{
			error_string.catprintf("Error: option %s expected a parameter\n", curarg);
			return false;
		}

		// set the new data
		validate_and_set_data(*curentry, newdata, priority, error_string);
	}
	return retVal;
}
Example #6
0
static astring nvram_filename(running_machine &machine, astring &result)
{
    if (rom_system_bios(machine) == 0 || rom_default_bios(machine) == rom_system_bios(machine)) {
        result.printf("%s",machine.basename());
    } else {
        result.printf("%s_%d",machine.basename(),rom_system_bios(machine) - 1);
    }
    return result;
}
Example #7
0
void device_image_interface::software_name_split(const char *swlist_swname, astring &swlist_name, astring &swname, astring &swpart)
{
	// reset all output parameters
	swlist_name.reset();
	swname.reset();
	swpart.reset();

	// if no colon, this is the swname by itself
	const char *split1 = strchr(swlist_swname, ':');
	if (split1 == NULL)
	{
		swname.cpy(swlist_swname);
		return;
	}

	// if one colon, it is the swname and swpart alone
	const char *split2 = strchr(split1 + 1, ':');
	if (split2 == NULL)
	{
		swname.cpy(swlist_swname, split1 - swlist_swname);
		swpart.cpy(split1 + 1);
		return;
	}

	// if two colons present, split into 3 parts
	swlist_name.cpy(swlist_swname, split1 - swlist_swname);
	swname.cpy(split1 + 1, split2 - (split1 + 1));
	swpart.cpy(split2 + 1);
}
Example #8
0
static astring get_file_path(astring &path)
{
	int pos = path.rchr( 0, '\\');
	if (pos!=-1) {
		path = path.substr(0,pos+1);
	} else {
		pos = path.rchr( 0, '/');
		path = path.substr(0,pos+1);
	}
	return path;
}
Example #9
0
static astring nvram_filename(device_t &device, astring &result)
{
    running_machine &machine = device.machine();
    astring name = astring(device.tag()).replacechr(':','_');
    if (rom_system_bios(machine) == 0 || rom_default_bios(machine) == rom_system_bios(machine)) {
        result.printf("%s\\%s",machine.basename(),name.cstr());
    } else {
        result.printf("%s_%d\\%s",machine.basename(),rom_system_bios(machine) - 1,name.cstr());
    }
    return result;
}
Example #10
0
		void read(PCWSTR path, astring &buf)
		{
			memory::auto_close<HANDLE> file(::CreateFileW(path, GENERIC_READ, 0, nullptr, OPEN_EXISTING,
			FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS,
			                                            nullptr));
			if (file != INVALID_HANDLE_VALUE) {
				DWORD size = (DWORD)get_size(file);
				buf.reserve(size);
				CheckApi(::ReadFile(file, (PWSTR )buf.c_str(), buf.size(), &size, nullptr));
			}
		}
Example #11
0
	/**
	@brief	文字列分割
	@note
	http://shnya.jp/blog/?p=195 のコードを改造
	*/
	static std::vector<astring> split(const astring &str, const astring &delim)
	{
		std::vector<astring> res;
		size_t current = 0, found, delimlen = delim.size();
		while ((found = str.find(delim, current)) != astring::npos)
		{
			res.push_back(astring(str, current, found - current));
			current = found + delimlen;
		}
		res.push_back(astring(str, current, str.size() - current));
		return res;
	}
Example #12
0
void debug_view_breakpoints::pad_astring_to_length(astring& str, int len)
{
	int diff = len - str.len();
	if (diff > 0)
	{
		astring buffer;
		buffer.expand(diff);
		for (int i = 0; i < diff; i++)
			buffer.catprintf(" ");
		str.catprintf("%s", buffer.cstr());
	}
}
Example #13
0
void consolewin_info::build_generic_filter(device_image_interface *img, bool is_save, astring &filter)
{
	// common image types
	add_filter_entry(filter, "Common image types", img->file_extensions());

	// compressed
	if (!is_save)
		filter.cat("Compressed Images (*.zip)|*.zip|");

	// all files
	filter.cat("All files (*.*)|*.*|");
}
Example #14
0
	WaitResult_t QueueImpl::get(Message& message, int64_t timeout_msec)
	{
		LogTraceObj("['%s'] (0x%I64X%s)", name.c_str(), timeout_msec, timeout_msec == TIMEOUT_INFINITE ? " INFINITE" : "");
		auto waitResult = se.try_lock_ex(timeout_msec);
		if (waitResult == WaitResult_t::SUCCESS) {
			auto guard = simstd::auto_lock(cs);
			message = simstd::move(front());
			erase(cbegin());
		}
		LogAttenIf(waitResult != WaitResult_t::SUCCESS, "['%s'] -> '%S'", name.c_str(), totext::c_str(waitResult));
		LogDebugIf(waitResult == WaitResult_t::SUCCESS, "['%s'] -> '%S' Message(0x%IX(%Iu, %Iu, %Iu))", name.c_str(), totext::c_str(waitResult), message->get_code(), message->get_a(), message->get_b(), message->get_c());
		return waitResult;
	}
Example #15
0
static void output_footer_and_close_file(core_file *file, astring &templatefile, astring &path)
{
	astring modified(templatefile);
	modified.replace(0, "<!--PATH-->", path.cstr());
	core_fwrite(file, modified.cstr(), modified.len());
	core_fclose(file);
}
Example #16
0
void cbm_crt_get_card(astring &result, core_file *file)
{
	// read the header
	cbm_crt_header header;
	core_fread(file, &header, CRT_HEADER_LENGTH);

	if (memcmp(header.signature, CRT_SIGNATURE, 16) == 0)
	{
		UINT16 hardware = pick_integer_be(header.hardware, 0, 2);

		result.cpy(CRT_C64_SLOT_NAMES[hardware]);
		return;
	}

	result.reset();
}
Example #17
0
chd_error chd_file::read_metadata(chd_metadata_tag searchtag, UINT32 searchindex, astring &output)
{
	// wrap this for clean reporting
	try
	{
		// if we didn't find it, just return
		metadata_entry metaentry;
		if (!metadata_find(searchtag, searchindex, metaentry))
			throw CHDERR_METADATA_NOT_FOUND;

		// read the metadata
		// TODO: how to properly allocate a dynamic char buffer?
		char* metabuf = new char[metaentry.length+1];
		memset(metabuf, 0x00, metaentry.length+1);
		file_read(metaentry.offset + METADATA_HEADER_SIZE, metabuf, metaentry.length);
		output.cpy(metabuf);
		delete[] metabuf;
		return CHDERR_NONE;
	}

	// just return errors
	catch (chd_error &err)
	{
		return err;
	}
}
Example #18
0
static void output_footer_and_close_file(core_file *file, astring &templatefile, astring &title)
{
	astring modified(templatefile);
	modified.replace(0, "<!--TITLE-->", title.c_str());
	core_fwrite(file, modified.c_str(), modified.len());
	core_fclose(file);
}
Example #19
0
void xegs_cart_slot_device::get_default_card_software(astring &result)
{
	if (open_image_file(mconfig().options()))
	{
		const char *slot_string = "xegs";
		dynamic_buffer head(0x10);
		UINT32 len = core_fsize(m_file);
		int type = A800_8K;
		
		// check whether there is an header, to identify the cart type
		if ((len % 0x1000) == 0x10)
		{
			core_fread(m_file, head, 0x10);		
			type = identify_cart_type(head);
		}
		if (type != A800_XEGS)
		{
			osd_printf_info("This game is not designed for XEGS. ");
			if (type >= A5200_4K)
				osd_printf_info("You might want to run it in A5200.\n");
			else
				osd_printf_info("You might want to run it in A800 or A800XL.\n");
		}
		
		slot_string = a800_get_slot(type);
		
		clear();
		
		result.cpy(slot_string);
	}
	else
		software_get_default_slot(result, "xegs");
}
Example #20
0
void a5200_cart_slot_device::get_default_card_software(astring &result)
{
	if (open_image_file(mconfig().options()))
	{
		const char *slot_string = "a5200";
		dynamic_buffer head(0x10);
		UINT32 len = core_fsize(m_file);
		int type = A5200_8K;
		
		// check whether there is an header, to identify the cart type
		if ((len % 0x1000) == 0x10)
		{
			core_fread(m_file, head, 0x10);		
			type = identify_cart_type(head);

			astring info;
			if (hashfile_extrainfo(*this, info) && info == "A13MIRRORING")
				type = A5200_16K_2CHIPS;
		}
		if (type < A5200_4K)
			osd_printf_info("This game is not designed for A5200. You might want to run it in A800 or A800XL.\n");
		
		slot_string = a800_get_slot(type);
		
		clear();
		
		result.cpy(slot_string);
	}
	else
		software_get_default_slot(result, "a5200");
}
Example #21
0
void a800_cart_slot_device::get_default_card_software(astring &result)
{
	if (open_image_file(mconfig().options()))
	{
		const char *slot_string = "a800_8k";
		dynamic_buffer head(0x10);
		UINT32 len = core_fsize(m_file);
		int type = A800_8K;

		// check whether there is an header, to identify the cart type
		if ((len % 0x1000) == 0x10)
		{
			core_fread(m_file, head, 0x10);		
			type = identify_cart_type(head);
		}
		else	// otherwise try to guess based on size
		{
			if (len == 0x4000)
				type = A800_16K;
			if (len == 0x2000)
				type = A800_8K;
		}

		if (type >= A5200_4K)
			osd_printf_info("This game is not designed for A800. You might want to run it in A5200.\n");

		slot_string = a800_get_slot(type);
		
		clear();
		
		result.cpy(slot_string);
	}
	else
		software_get_default_slot(result, "a800_8k");
}
Example #22
0
void sega8_cart_slot_device::get_default_card_software(astring &result)
{
	if (open_image_file(mconfig().options()))
	{
		const char *slot_string = "rom";
		UINT32 len = core_fsize(m_file), offset = 0;
		dynamic_buffer rom(len);
		int type;

		core_fread(m_file, rom, len);

		if ((len % 0x4000) == 512)
			offset = 512;

		type = get_cart_type(rom + offset, len - offset);
		slot_string = sega8_get_slot(type);

		//printf("type: %s\n", slot_string);
		clear();

		result.cpy(slot_string);
		return;
	}

	software_get_default_slot(result, "rom");
}
Example #23
0
void apf_cart_slot_device::get_default_card_software(astring &result)
{
	if (open_image_file(mconfig().options()))
	{
		const char *slot_string = "std";
		UINT32 size = core_fsize(m_file);
		int type = APF_STD;

		// attempt to identify Space Destroyer, which needs 1K of additional RAM
		if (size == 0x1800)
			type = APF_SPACEDST;
		if (size > 0x2000)
			type = APF_BASIC;

		slot_string = apf_get_slot(type);

		//printf("type: %s\n", slot_string);
		clear();

		result.cpy(slot_string);
		return;
	}

	software_get_default_slot(result, "std");
}
Example #24
0
void device_image_interface::software_get_default_slot(astring &result, const char *default_card_slot)
{
	const char *path = device().mconfig().options().value(instance_name());
	result.reset();
	if (strlen(path) > 0)
	{
		result.cpy(default_card_slot);
		software_part *swpart = find_software_item(path, true);
		if (swpart != NULL)
		{
			const char *slot = swpart->feature("slot");
			if (slot != NULL)
				result.cpy(slot);
		}
	}
}
Example #25
0
VSCDiskDevice::VSCDiskDevice(astring strTitle, int usage, QWidget *parent)
    : QWidget(parent)
{
	ui.setupUi(this);
	ui.name->setText(strTitle.c_str());
	ui.progressBar->setValue(usage);

}
Example #26
0
void ui_menu_tape_control::get_time_string(astring &dest, cassette_image_device *cassette, int *curpos, int *endpos)
{
	double t0, t1;

	t0 = cassette->get_position();
	t1 = cassette->get_length();

	if (t1)
		dest.printf("%04d/%04d", (int) t0, (int) t1);
	else
		dest.printf("%04d/%04d", 0, (int) t1);

	if (curpos != NULL)
		*curpos = t0;
	if (endpos != NULL)
		*endpos = t1;
}
Example #27
0
void ldplayer_state::machine_reset()
{
	// set up a timer to start playing immediately
	timer_set(attotime::zero, TIMER_ID_AUTOPLAY);

	// indicate the name of the file we opened
	popmessage("Opened %s\n", m_filename.cstr());
}
Example #28
0
void emu_options::parse_standard_inis(astring &error_string)
{
	// start with an empty string
	error_string.reset();

	// parse the INI file defined by the platform (e.g., "mame.ini")
	// we do this twice so that the first file can change the INI path
	parse_one_ini(emulator_info::get_configname(), OPTION_PRIORITY_MAME_INI);
	parse_one_ini(emulator_info::get_configname(), OPTION_PRIORITY_MAME_INI, &error_string);

	// debug mode: parse "debug.ini" as well
	if (debug())
		parse_one_ini("debug", OPTION_PRIORITY_DEBUG_INI, &error_string);

	// if we have a valid system driver, parse system-specific INI files
	const game_driver *cursystem = system();
	if (cursystem == NULL)
		return;

	// parse "vertical.ini" or "horizont.ini"
	if (cursystem->flags & ORIENTATION_SWAP_XY)
		parse_one_ini("vertical", OPTION_PRIORITY_ORIENTATION_INI, &error_string);
	else
		parse_one_ini("horizont", OPTION_PRIORITY_ORIENTATION_INI, &error_string);

	// parse "vector.ini" for vector games
	{
		machine_config config(*cursystem, *this);
		screen_device_iterator iter(config.root_device());
		for (const screen_device *device = iter.first(); device != NULL; device = iter.next())
			if (device->screen_type() == SCREEN_TYPE_VECTOR)
			{
				parse_one_ini("vector", OPTION_PRIORITY_VECTOR_INI, &error_string);
				break;
			}
	}

	// next parse "source/<sourcefile>.ini"; if that doesn't exist, try <sourcefile>.ini
	astring sourcename;
	core_filename_extract_base(sourcename, cursystem->source_file, true).ins(0, "source" PATH_SEPARATOR);
	if (!parse_one_ini(sourcename, OPTION_PRIORITY_SOURCE_INI, &error_string))
	{
		core_filename_extract_base(sourcename, cursystem->source_file, true);
		parse_one_ini(sourcename, OPTION_PRIORITY_SOURCE_INI, &error_string);
	}

	// then parse the grandparent, parent, and system-specific INIs
	int parent = driver_list::clone(*cursystem);
	int gparent = (parent != -1) ? driver_list::clone(parent) : -1;
	if (gparent != -1)
		parse_one_ini(driver_list::driver(gparent).name, OPTION_PRIORITY_GPARENT_INI, &error_string);
	if (parent != -1)
		parse_one_ini(driver_list::driver(parent).name, OPTION_PRIORITY_PARENT_INI, &error_string);
	parse_one_ini(cursystem->name, OPTION_PRIORITY_DRIVER_INI, &error_string);

	// Re-evaluate slot options after loading ini files
	update_slot_options();
}
Example #29
0
void lr35902_cpu_device::state_string_export(const device_state_entry &entry, astring &string)
{
	switch (entry.index())
	{
		case LR35902_SPEED:
			string.printf("%02X", 0x7E | ( ( m_gb_speed - 1 ) << 7 ) | m_gb_speed_change_pending );
			break;

		case STATE_GENFLAGS:
			string.printf("%c%c%c%c",
				m_F & FLAG_Z   ? 'Z' : '.',
				m_F & FLAG_N   ? 'N' : '.',
				m_F & FLAG_H   ? 'H' : '.',
				m_F & FLAG_C   ? 'C' : '.'
			);
			break;
	}
}
Example #30
0
	void QueueImpl::put(Message&& message)
	{
		LogTraceObj("['%s'] Message(0x%IX(%Iu, %Iu, %Iu))", name.c_str(), message->get_code(), message->get_a(), message->get_b(), message->get_c());
		{
			auto guard = simstd::auto_lock(cs);
			emplace_back(simstd::move(message));
		}
		se.unlock();
	}