Example #1
0
struct loaded_samples *readsamples(const char **samplenames, const char *basename)
{
	struct loaded_samples *samples;
	int skipfirst = 0;
	int i;

	/* if the user doesn't want to use samples, bail */
	if (!options.use_samples)
		return NULL;
	if (samplenames == 0 || samplenames[0] == 0)
		return NULL;

	/* if a name begins with '*', we will also look under that as an alternate basename */
	if (samplenames[0][0] == '*')
		skipfirst = 1;

	/* count the samples */
	for (i = 0; samplenames[i+skipfirst] != 0; i++) ;
	if (i == 0)
		return NULL;

	/* allocate the array */
	samples = auto_malloc(sizeof(struct loaded_samples) + (i-1) * sizeof(struct loaded_sample));
	memset(samples, 0, sizeof(struct loaded_samples) + (i-1) * sizeof(struct loaded_sample));
	samples->total = i;

	/* load the samples */
	for (i = 0; i < samples->total; i++)
		if (samplenames[i+skipfirst][0])
		{
			mame_file_error filerr;
			mame_file *f;
			char *fname;

			fname = assemble_3_strings(basename, PATH_SEPARATOR, samplenames[i+skipfirst]);
			filerr = mame_fopen(SEARCHPATH_SAMPLE, fname, OPEN_FLAG_READ, &f);
			free(fname);

			if (filerr != FILERR_NONE && skipfirst)
			{
				fname = assemble_3_strings(samplenames[0] + 1, PATH_SEPARATOR, samplenames[i+skipfirst]);
				filerr = mame_fopen(SEARCHPATH_SAMPLE, fname, OPEN_FLAG_READ, &f);
				free(fname);
			}
			if (filerr == FILERR_NONE)
			{
				read_wav_sample(f, &samples->sample[i]);
				mame_fclose(f);
			}
		}

	return samples;
}
Example #2
0
static int open_rom_file(rom_load_data *romdata, const rom_entry *romp)
{
	mame_file_error filerr = FILERR_NOT_FOUND;
	const game_driver *drv;

	++romdata->romsloaded;

	/* update status display */
	display_loading_rom_message(ROM_GETNAME(romp), romdata);

	/* Attempt reading up the chain through the parents. It automatically also
       attempts any kind of load by checksum supported by the archives. */
	romdata->file = NULL;
	for (drv = Machine->gamedrv; !romdata->file && drv; drv = driver_get_clone(drv))
		if (drv->name && *drv->name)
		{
			UINT8 crcs[4];
			char *fname;

			fname = assemble_3_strings(drv->name, PATH_SEPARATOR, ROM_GETNAME(romp));
			if (hash_data_extract_binary_checksum(ROM_GETHASHDATA(romp), HASH_CRC, crcs))
			{
				UINT32 crc = (crcs[0] << 24) | (crcs[1] << 16) | (crcs[2] << 8) | crcs[3];
				filerr = mame_fopen_crc(SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ, &romdata->file);
			}
			else
				filerr = mame_fopen(SEARCHPATH_ROM, fname, OPEN_FLAG_READ, &romdata->file);
			free(fname);
		}

	/* return the result */
	return (filerr == FILERR_NONE);
}
Example #3
0
static image_error_t set_image_filename(mess_image *image, const char *filename, const char *zippath)
{
	image_error_t err = IMAGE_ERROR_SUCCESS;
	char *alloc_filename = NULL;
	char *new_name;
	char *new_dir;
	int pos;

	/* create the directory string */
	new_dir = image_strdup(image, filename);
	for (pos = strlen(new_dir); (pos > 0); pos--)
	{
		if (strchr(":\\/", new_dir[pos - 1]))
		{
			new_dir[pos] = '\0';
			break;
		}
	}

	/* do we have to concatenate the names? */
	if (zippath)
	{
		alloc_filename = assemble_3_strings(filename, PATH_SEPARATOR, zippath);
		filename = alloc_filename;
	}

	/* copy the string */
	new_name = image_strdup(image, filename);
	if (!new_name)
	{
		err = IMAGE_ERROR_OUTOFMEMORY;
		goto done;
	}

	/* set the new name and dir */
	if (image->name)
		image_freeptr(image, image->name);
	if (image->dir)
		image_freeptr(image, image->dir);
	image->name = new_name;
	image->dir = new_dir;

done:
	if (alloc_filename)
		free(alloc_filename);
	return err;
}
Example #4
0
static chd_interface_file *audit_chd_open(const char *filename, const char *mode)
{
	const game_driver *drv;

	/* attempt reading up the chain through the parents */
	for (drv = chd_gamedrv; drv != NULL; drv = driver_get_clone(drv))
	{
		mame_file_error filerr;
		mame_file *file;
		char *fname;

		fname = assemble_3_strings(drv->name, PATH_SEPARATOR, filename);
		filerr = mame_fopen(SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, &file);
		free(fname);

		if (filerr == FILERR_NONE)
			return (chd_interface_file *)file;
	}
	return NULL;
}
Example #5
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;
}
Example #6
0
static int audit_one_rom(const rom_entry *rom, const game_driver *gamedrv, UINT32 validation, audit_record *record)
{
	const game_driver *drv;
	const rom_entry *chunk;
	UINT32 crc = 0;
	UINT8 crcs[4];
	int has_crc;

	/* fill in the record basics */
	record->type = AUDIT_FILE_ROM;
	record->name = ROM_GETNAME(rom);
	record->exphash = ROM_GETHASHDATA(rom);

	/* compute the expected length by summing the chunks */
	for (chunk = rom_first_chunk(rom); chunk; chunk = rom_next_chunk(chunk))
		record->explength += ROM_GETLENGTH(chunk);

	/* see if we have a CRC and extract it if so */
	has_crc = hash_data_extract_binary_checksum(record->exphash, HASH_CRC, crcs);
	if (has_crc)
		crc = (crcs[0] << 24) | (crcs[1] << 16) | (crcs[2] << 8) | crcs[3];

	/* find the file and checksum it, getting the file length along the way */
	for (drv = gamedrv; drv != NULL; drv = driver_get_clone(drv))
	{
		mame_file_error filerr;
		mame_file *file;
		char *fname;

		/* open the file if we can */
		fname = assemble_3_strings(drv->name, PATH_SEPARATOR, ROM_GETNAME(rom));
	    if (has_crc)
			filerr = mame_fopen_crc(SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ, &file);
		else
			filerr = mame_fopen(SEARCHPATH_ROM, fname, OPEN_FLAG_READ, &file);
		free(fname);

		/* if we got it, extract the hash and length */
		if (filerr == FILERR_NONE)
		{
			hash_data_copy(record->hash, mame_fhash(file, validation));
			record->length = (UINT32)mame_fsize(file);
			mame_fclose(file);
			break;
		}
	}

	/* if we failed to find the file, set the appropriate status */
	if (drv == NULL)
	{
		const game_driver *parent;

		/* no good dump */
		if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP))
			set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_NODUMP);

		/* optional ROM */
		else if (ROM_ISOPTIONAL(rom))
			set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_OPTIONAL);

		/* not found and used by parent */
		else if (rom_used_by_parent(gamedrv, rom, &parent))
			set_status(record, AUDIT_STATUS_NOT_FOUND, (parent->flags & NOT_A_DRIVER) ? SUBSTATUS_NOT_FOUND_BIOS : SUBSTATUS_NOT_FOUND_PARENT);

		/* just plain old not found */
		else
			set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND);
	}

	/* if we did find the file, do additional verification */
	else
	{
		/* length mismatch */
		if (record->explength != record->length)
			set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_WRONG_LENGTH);

		/* found but needs a dump */
		else if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP))
			set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_FOUND_NODUMP);

		/* incorrect hash */
		else if (!hash_data_is_equal(record->exphash, record->hash, 0))
			set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_BAD_CHECKSUM);

		/* correct hash but needs a redump */
		else if (hash_data_has_info(record->exphash, HASH_INFO_BAD_DUMP))
			set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD_NEEDS_REDUMP);

		/* just plain old good */
		else
			set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD);
	}

	/* return TRUE if we found anything at all */
	return (drv != NULL);
}
Example #7
0
int audit_samples(int game, audit_record **audit)
{
	const game_driver *gamedrv = drivers[game];
	machine_config config;
	audit_record *record;
	int sndnum, sampnum;
	int records = 0;

	/* count the number of sample records attached to this driver */
	expand_machine_driver(gamedrv->drv, &config);
#if HAS_SAMPLES
	for (sndnum = 0; sndnum < ARRAY_LENGTH(config.sound); sndnum++)
		if (config.sound[sndnum].sound_type == SOUND_SAMPLES)
		{
			struct Samplesinterface *intf = (struct Samplesinterface *)config.sound[sndnum].config;

			if (intf->samplenames == NULL)
				continue;

			/* iterate over samples in this entry */
			for (sampnum = 0; intf->samplenames[sampnum] != NULL; sampnum++)
				if (intf->samplenames[sampnum][0] != '*')
					records++;
		}
#endif

	/* if no records, just quit now */
	if (records == 0)
		return records;

	/* allocate memory for the records */
	*audit = malloc_or_die(sizeof(**audit) * records);
	memset(*audit, 0, sizeof(**audit) * records);
	record = *audit;

	/* now iterate over sample entries */
	for (sndnum = 0; sndnum < ARRAY_LENGTH(config.sound); sndnum++)
		if (config.sound[sndnum].sound_type == SOUND_SAMPLES)
		{
			struct Samplesinterface *intf = (struct Samplesinterface *)config.sound[sndnum].config;
			const char *sharedname = NULL;

			/* iterate over samples in this entry */
			for (sampnum = 0; intf->samplenames[sampnum] != NULL; sampnum++)
				if (intf->samplenames[sampnum][0] == '*')
					sharedname = &intf->samplenames[sampnum][1];
				else
				{
					mame_file_error filerr;
					mame_file *file;
					char *fname;

					/* attempt to access the file from the game driver name */
					fname = assemble_3_strings(gamedrv->name, PATH_SEPARATOR, intf->samplenames[sampnum]);
					filerr = mame_fopen(SEARCHPATH_SAMPLE, fname, OPEN_FLAG_READ, &file);
					free(fname);

					/* attempt to access the file from the shared driver name */
					if (filerr != FILERR_NONE && sharedname != NULL)
					{
						fname = assemble_3_strings(sharedname, PATH_SEPARATOR, intf->samplenames[sampnum]);
						filerr = mame_fopen(SEARCHPATH_SAMPLE, fname, OPEN_FLAG_READ, &file);
						free(fname);
					}

					/* fill in the record */
					record->type = AUDIT_FILE_SAMPLE;
					record->name = intf->samplenames[sampnum];
					if (filerr == FILERR_NONE)
					{
						set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD);
						mame_fclose(file);
					}
					else
						set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND);
				}
		}

	return records;
}