Beispiel #1
0
static running_machine *create_machine(int game)
{
	running_machine *machine;
	int scrnum;

	/* allocate memory for the machine */
	machine = malloc(sizeof(*machine));
	if (machine == NULL)
		goto error;
	memset(machine, 0, sizeof(*machine));

	/* allocate memory for the internal mame_data */
	machine->mame_data = malloc(sizeof(*machine->mame_data));
	if (machine->mame_data == NULL)
		goto error;
	memset(machine->mame_data, 0, sizeof(*machine->mame_data));

	/* initialize the driver-related variables in the machine */
	machine->gamedrv = drivers[game];
	machine->drv = malloc(sizeof(*machine->drv));
	if (machine->drv == NULL)
		goto error;
	machine->basename = mame_strdup(machine->gamedrv->name);
	expand_machine_driver(machine->gamedrv->drv, (machine_config *)machine->drv);

	/* allocate the driver data */
	if (machine->drv->driver_data_size != 0)
	{
		machine->driver_data = malloc(machine->drv->driver_data_size);
		if (machine->driver_data == NULL)
			goto error;
		memset(machine->driver_data, 0, machine->drv->driver_data_size);
	}

	/* configure all screens to be the default */
	for (scrnum = 0; scrnum < MAX_SCREENS; scrnum++)
		machine->screen[scrnum] = machine->drv->screen[scrnum].defstate;

	/* convert some options into live state */
	machine->sample_rate = options.samplerate;
	machine->record_file = options.record;
	machine->playback_file = options.playback;
	machine->debug_mode = options.mame_debug;

	return machine;

error:
	if (machine->driver_data != NULL)
		free(machine->driver_data);
	if (machine->drv != NULL)
		free((machine_config *)machine->drv);
	if (machine->mame_data != NULL)
		free(machine->mame_data);
	if (machine != NULL)
		free(machine);
	return NULL;
}
Beispiel #2
0
static char *assemble_software_path(const game_driver *gamedrv, const char *filename)
{
	char *result;
	if (osd_is_absolute_path(filename))
		result = mame_strdup(filename);
	else
		result = assemble_5_strings("software", PATH_SEPARATOR, gamedrv->name, PATH_SEPARATOR, filename);
	return result;
}
Beispiel #3
0
void mame_schedule_load(const char *filename)
{
	/* free any existing request and allocate a copy of the requested name */
	if (saveload_pending_file != NULL)
		free(saveload_pending_file);
	saveload_pending_file = mame_strdup(filename);

	/* note the start time and set a timer for the next timeslice to actually schedule it */
	saveload_schedule_callback = handle_load;
	saveload_schedule_time = mame_timer_get_time();

	/* we can't be paused since we need to clear out anonymous timers */
	mame_pause(FALSE);
}
Beispiel #4
0
void mame_schedule_save(running_machine *machine, const char *filename)
{
	mame_private *mame = machine->mame_data;

	/* free any existing request and allocate a copy of the requested name */
	if (mame->saveload_pending_file != NULL)
		free(mame->saveload_pending_file);
	mame->saveload_pending_file = mame_strdup(filename);

	/* note the start time and set a timer for the next timeslice to actually schedule it */
	mame->saveload_schedule_callback = handle_save;
	mame->saveload_schedule_time = mame_timer_get_time();

	/* we can't be paused since we need to clear out anonymous timers */
	mame_pause(machine, FALSE);
}
Beispiel #5
0
static void edit_add_hist(edit *e, const char *text)
{
	if(e->ch)
		e->ch = 0;

	if(e->hold) {
		osd_free(e->hold);
		e->hold =0;
	}

	if(!e->h || (text[0] && strcmp(text, e->h->e))) {
		hentry *h = (hentry *) osd_malloc(sizeof(hentry));
		h->h = e->h;
		h->e = mame_strdup(text);
		e->h = h;
	}
}
Beispiel #6
0
static void edit_hist_back(edit *e)
{
	const char *text = gtk_entry_get_text(e->edit_w);
	if(e->ch) {
		if(!e->ch->h)
			return;
		e->ch = e->ch->h;
	} else {
		if(!e->h)
			return;
		if(!strcmp(text, e->h->e)) {
			if(!e->h->h)
				return;
			e->ch = e->h->h;
		} else {
			if(text[0])
				e->hold = mame_strdup(text);
			e->ch = e->h;
		}
	}
	gtk_entry_set_text(e->edit_w, e->ch->e);
	gtk_editable_select_region(GTK_EDITABLE(e->edit_w), 0, -1);
}
Beispiel #7
0
BOOL LoadDIB(LPCTSTR filename, HGLOBAL *phDIB, HPALETTE *pPal, int pic_type)
{
	mame_file_error filerr;
	mame_file *mfile = NULL;
	char *fname;
	BOOL success;
	const char *zip_name = NULL;
	char *pngfilename = NULL;
	char tmp[MAX_PATH];
	strcpy(tmp, filename);
	strcat(tmp,  ".png");
	pngfilename = mame_strdup(tmp);
	switch (pic_type)
	{
	case TAB_SCREENSHOT :
		options_set_string(SEARCHPATH_ARTWORK,GetImgDir());
		zip_name = "snap";
		break;
	case TAB_FLYER :
		options_set_string(SEARCHPATH_ARTWORK,GetFlyerDir());
		zip_name = "flyers";
		break;
	case TAB_CABINET :
		options_set_string(SEARCHPATH_ARTWORK,GetCabinetDir());
		zip_name = "cabinets";
		break;
	case TAB_MARQUEE :
		options_set_string(SEARCHPATH_ARTWORK,GetMarqueeDir());
		zip_name = "marquees";
		break;
	case TAB_TITLE :
		options_set_string(SEARCHPATH_ARTWORK,GetTitlesDir());
		zip_name = "titles";
		break;
	case TAB_CONTROL_PANEL :
		options_set_string(SEARCHPATH_ARTWORK,GetControlPanelDir());
		zip_name = "cpanel";
		break;
	case BACKGROUND :
		options_set_string(SEARCHPATH_ARTWORK,GetBgDir());
		zip_name = "bkground";
		break;
	default :
		// in case a non-image tab gets here, which can happen
		return FALSE;
	}
	
	// look for the raw file
	filerr = mame_fopen(SEARCHPATH_ARTWORK, pngfilename, OPEN_FLAG_READ, &mfile);
	if (filerr != FILERR_NONE)
	{
		// and look for the zip
		fname = assemble_3_strings(zip_name, PATH_SEPARATOR, pngfilename);
		filerr = mame_fopen(SEARCHPATH_ARTWORK, fname, OPEN_FLAG_READ, &mfile);
		free(fname);
	}
	if (filerr != FILERR_NONE)
		return FALSE;

	success = png_read_bitmap(mfile, phDIB, pPal);

	mame_fclose(mfile);

	return success;
}
Beispiel #8
0
void ram_device::device_validity_check(validity_checker &valid) const
{
	const char *ramsize_string = NULL;
	int is_valid = FALSE;
	UINT32 specified_ram = 0;
	const char *gamename_option = NULL;

	/* verify default ram value */
	if (default_size() == 0)
		mame_printf_error("Invalid default RAM option: %s\n", m_default_size);

	/* command line options are only parsed for the device named RAM_TAG */
	if (tag() != NULL && strcmp(tag(), ":" RAM_TAG) == 0)
	{
		/* verify command line ram option */
		ramsize_string = mconfig().options().ram_size();
		gamename_option = mconfig().options().system_name();

		if ((ramsize_string != NULL) && (ramsize_string[0] != '\0'))
		{
			specified_ram = parse_string(ramsize_string);

			if (specified_ram == 0)
				mame_printf_error("Cannot recognize the RAM option %s\n", ramsize_string);

			if (gamename_option != NULL && *gamename_option != 0 && strcmp(gamename_option, mconfig().gamedrv().name) == 0)
			{
				/* compare command line option to default value */
				if (default_size() == specified_ram)
					is_valid = TRUE;

				/* verify extra ram options */
				if (m_extra_options != NULL)
				{
					int j;
					int size = strlen(m_extra_options);
					char * const s = mame_strdup(m_extra_options);
					char * const e = s + size;
					char *p = s;
					for (j=0;j<size;j++) {
						if (p[j]==',') p[j]=0;
					}

					/* try to parse each option */
					while(p <= e)
					{
						UINT32 option_ram_size = parse_string(p);

						if (option_ram_size == 0)
							mame_printf_error("Invalid RAM option: %s\n", p);

						if (option_ram_size == specified_ram)
							is_valid = TRUE;

						p += strlen(p);
						if (p == e)
							break;
						p += 1;
					}

					osd_free(s);
				}

			} else {
				/* if not for this driver then return ok */
				is_valid = TRUE;
			}
		}
		else
		{
			/* not specifying the ramsize on the command line is valid as well */
			is_valid = TRUE;
		}
	}
	else
		is_valid = TRUE;

	if (!is_valid)
	{
		astring output;
		output.catprintf("Cannot recognize the RAM option %s", ramsize_string);
		output.catprintf(" (valid options are %s", m_default_size);

		if (m_extra_options != NULL)
			output.catprintf(",%s).\n", m_extra_options);
		else
			output.catprintf(").\n");

		mame_printf_error("%s", output.cstr());

		mame_printf_warning("Setting value to default %s\n",m_default_size);
		astring error;
		mconfig().options().set_value(OPTION_RAMSIZE, m_default_size, OPTION_PRIORITY_CMDLINE, error);
		assert(!error);
	}
}
static BOOL RamPopulateControl(datamap *map, HWND dialog, HWND control, windows_options *opts, const char *option_name)
{
	int i, current_index, driver_index;
	const game_driver *gamedrv;
	UINT32 ram, current_ram;
	const char *this_ram_string;
	TCHAR* t_ramstring;
	const device_t *device;

	// identify the driver
	driver_index = PropertiesCurrentGame(dialog);
	gamedrv = &driver_list::driver(driver_index);

	// clear out the combo box
	(void)ComboBox_ResetContent(control);

	// allocate the machine config
	machine_config cfg(*gamedrv,*opts);

	// identify how many options that we have
	device = cfg.devicelist().first(RAM);

	EnableWindow(control, (device != NULL));
	i = 0;
	// we can only do something meaningful if there is more than one option
	if (device != NULL)
	{
		ram_config *config = (ram_config *)downcast<const legacy_device_base *>(device)->inline_config();

		// identify the current amount of RAM
		this_ram_string = opts->value(OPTION_RAMSIZE);
		current_ram = (this_ram_string != NULL) ? ram_parse_string(this_ram_string) : 0;
		if (current_ram == 0)
			current_ram = ram_parse_string(config->default_size);

		// by default, assume index 0
		current_index = 0;

		{
			ram = ram_parse_string(config->default_size);
			t_ramstring = tstring_from_utf8(config->default_size);
			if( !t_ramstring )
				return FALSE;

			(void)ComboBox_InsertString(control, i, win_tstring_strdup(t_ramstring));
			(void)ComboBox_SetItemData(control, i, ram);

			osd_free(t_ramstring);
		}
		if (config->extra_options != NULL)
		{
			int j;
			int size = strlen(config->extra_options);
			char * const s = mame_strdup(config->extra_options);
			char * const e = s + size;
			char *p = s;
			for (j=0;j<size;j++) {
				if (p[j]==',') p[j]=0;
			}

			/* try to parse each option */
			while(p <= e)
			{
				i++;
				// identify this option
				ram = ram_parse_string(p);

				this_ram_string = p;

				t_ramstring = tstring_from_utf8(this_ram_string);
				if( !t_ramstring )
					return FALSE;

				// add this option to the combo box
				(void)ComboBox_InsertString(control, i, win_tstring_strdup(t_ramstring));
				(void)ComboBox_SetItemData(control, i, ram);

				osd_free(t_ramstring);

				// is this the current option?  record the index if so
				if (ram == current_ram)
					current_index = i;

				p+= strlen(p);
				if (p == e)
					break;

				p += 1;
			}

			osd_free(s);
		}

		// set the combo box
		(void)ComboBox_SetCurSel(control, current_index);
	}
	return TRUE;
}
Beispiel #10
0
void driver_switch::assign_drivers(emu_options &opts)
{
	static const struct
	{
		const char *name;
		const game_driver * const *driver;
	} drivers_table[] =
	{
#ifndef TINY_BUILD
		{ "mame",		mamedrivers },
		{ "plus",		mameplusdrivers },
		{ "homebrew",	mamehbdrivers },
		{ "decrypted",	mamedecrypteddrivers },
#ifdef MAMEMESS
		{ "console",	messdrivers },
#endif /* MAMEMESS */
#else
		{ "mame",		tinydrivers },
#endif /* !TINY_BUILD */
		{ NULL }
	};

	UINT32 enabled = 0;
	int i, n;
	bool mechanical = opts.bool_value(OPTION_DISABLE_MECHANICAL_DRIVER);

#ifndef TINY_BUILD
	const char *drv_option = opts.value(OPTION_DRIVER_CONFIG);
	if (drv_option)
	{
		char *temp = mame_strdup(drv_option);
		if (temp)
		{
			char *p = strtok(temp, ",");
 			while (p)
			{
				char *s = core_strtrim(p);	//get individual driver name
				if (s[0])
				{
					if (mame_stricmp(s, "all") == 0)
					{
						enabled = (UINT32)-1;
						break;
					}

					for (i = 0; drivers_table[i].name; i++)
						if (mame_stricmp(s, drivers_table[i].name) == 0)
						{
							enabled |= 1 << i;
							break;
						}

					if (!drivers_table[i].name)
						mame_printf_warning(_("Illegal value for %s = %s\n"), OPTION_DRIVER_CONFIG, s);
				}
				osd_free(s);
 				p = strtok(NULL, ",");
			}
 			osd_free(temp);
		}
	}
#endif /* !TINY_BUILD */

	if (enabled == 0)
		enabled = 1;	// default to mamedrivers

	n = 0;
	for (i = 0; drivers_table[i].name; i++)
		if (enabled & (1 << i))
		{
			for (int c = 0; drivers_table[i].driver[c]; c++)
				if (mame_stricmp(drivers_table[i].driver[c]->name, "___empty"))
					if (!mechanical || !(drivers_table[i].driver[c]->flags & GAME_MECHANICAL))
						driver_list::s_drivers_sorted[n++] = drivers_table[i].driver[c];
		}

	// ___empty driver add once
	driver_list::s_drivers_sorted[n++] = &GAME_NAME(___empty);
	driver_list::s_driver_count = n;

	qsort(driver_list::s_drivers_sorted, n, sizeof(*driver_list::s_drivers_sorted), driver_list::driver_sort_callback);
}
Beispiel #11
0
static image_error_t load_zip_path(mess_image *image, const char *path)
{
	image_error_t err = IMAGE_ERROR_FILENOTFOUND;
	zip_file *zip = NULL;
	zip_error ziperr;
	const zip_file_header *header;
	const char *zip_extension = ".zip";
	char *path_copy;
	const char *zip_entry;
	void *ptr;
	int pos;

	/* create our own copy of the path */
	path_copy = mame_strdup(path);
	if (!path_copy)
	{
		err = IMAGE_ERROR_OUTOFMEMORY;
		goto done;
	}

	/* loop through the path and try opening zip files */
	ziperr = ZIPERR_FILE_ERROR;
	zip_entry = NULL;
	pos = strlen(path_copy);
	while(pos > strlen(zip_extension))
	{
		/* is this a potential zip path? */
		if ((path_copy[pos] == '\0') || !strncmp(&path_copy[pos], PATH_SEPARATOR, strlen(PATH_SEPARATOR)))
		{
			/* parse out the zip path */
			if (path_copy[pos] == '\0')
			{
				/* no zip path */
				zip_entry = NULL;
			}
			else
			{
				/* we are at a zip path */
				path_copy[pos] = '\0';
				zip_entry = &path_copy[pos + strlen(PATH_SEPARATOR)];
			}

			/* try to open the zip file */
			ziperr = zip_file_open(path_copy, &zip);
			if (ziperr != ZIPERR_FILE_ERROR)
				break;

			/* restore the path if we changed */
			if (zip_entry)
				path_copy[pos] = PATH_SEPARATOR[0];
		}
		pos--;
	}

	/* did we succeed in opening up a zip file? */
	if (ziperr == ZIPERR_NONE)
	{
		/* iterate through the zip file */
		header = zip_file_first_file(zip);

		/* if we specified a zip partial path, find it */
		if (zip_entry)
		{
			while(header)
			{
				if (!mame_stricmp(header->filename, zip_entry))
					break;
				header = zip_file_next_file(zip);
			}
		}

		/* were we successful? */
		if (header)
		{
			/* if no zip path was specified, we have to change the name */
			if (!zip_entry)
			{
				/* use the first entry; tough part is we have to change the name */
				err = set_image_filename(image, image->name, header->filename);
				if (err)
					goto done;
			}

			/* allocate space for this zip file */
			ptr = image_malloc(image, header->uncompressed_length);
			if (!ptr)
			{
				err = IMAGE_ERROR_OUTOFMEMORY;
				goto done;
			}

			ziperr = zip_file_decompress(zip, ptr, header->uncompressed_length);
			if (ziperr == ZIPERR_NONE)
			{
				/* success! */
				err = IMAGE_ERROR_SUCCESS;
				image->ptr = ptr;
				image->length = header->uncompressed_length;
			}
		}
	}

done:
	if (path_copy)
		free(path_copy);
	if (zip)
		zip_file_close(zip);
	return err;
}
Beispiel #12
0
static LPWSTR GetPatchDescByLangcode(FILE *fp, int langcode)
{
	LPWSTR result;
	char *desc = NULL;
	char langtag[8];

	sprintf(langtag, "[%s]", ui_lang_info[langcode].name);

	fseek(fp, 0, SEEK_SET);

	while (!feof(fp))
	{
		char s[4096];

		if (fgets(s, ARRAY_LENGTH(s), fp) != NULL)
		{
			if (strncmp(langtag, s, strlen(langtag)) != 0)
				continue;

			while (fgets(s, ARRAY_LENGTH(s), fp) != NULL)
			{
				char *p;

				if (*s == '[')
				{
					if (desc)
					{
						result = _UTF8Unicode(desc);
						global_free(desc);
						return result;
					}
					else
						return NULL;
				}

				for (p = s; *p; p++)
					if (*p == '\r' || *p == '\n')
					{
						*p = '\0';
						break;
					}

//				if (*s == '\0')
//					continue;

				if (desc)
				{
					char *p;
					int len = strlen(desc);

					len += strlen(s) + 2;
					p = (char *)malloc(len + 1);
					sprintf(p, "%s\r\n%s", desc, s);
					FreeIfAllocated(&desc);
					desc = p;
				}
				else
				{
					desc = mame_strdup(s);
				}
			}
		}
	}

	if (desc)
	{
		result = _UTF8Unicode(desc);
		global_free(desc);
		return result;
	}
	else
		return NULL;
}