Example #1
0
static void image_unload_internal(mess_image *image, int is_final_unload)
{
	/* is there an actual image loaded? */
	if (!is_loaded(image))
		return;

	/* call the unload function */
	if (image->dev->unload)
		image->dev->unload(image);

	image_clear(image);
	image_clear_error(image);
	osd_image_load_status_changed(image, is_final_unload);
}
Example #2
0
static void image_unload_internal(mess_image *img, int is_final_unload)
{
	const struct IODevice *dev;
	int type = image_devtype(img);

	if ((img->status & IMAGE_STATUS_ISLOADED) == 0)
		return;

	dev = device_find(Machine->devices, type);
	assert(dev);

	if (dev->unload)
		dev->unload(img);

	if (img->fp)
	{
		mame_fclose(img->fp);
		img->fp = NULL;
	}
	pool_exit(&img->mempool);

	image_clear_error(img);
	img->status = 0;
	img->name = NULL;
	img->dir = NULL;
	img->hash = NULL;
	img->length = 0;
	img->longname = NULL;
	img->manufacturer = NULL;
	img->year = NULL;
	img->playable = NULL;
	img->extrainfo = NULL;
	img->basename_noext = NULL;

	osd_image_load_status_changed(img, is_final_unload);
}
Example #3
0
static int image_load_internal(mess_image *image, const char *path,
	int is_create, int create_format, option_resolution *create_args)
{
	image_error_t err;
	const char *software_path;
	char *software_path_list = NULL;
	const void *buffer;
	const game_driver *gamedrv;
	UINT32 open_plan[4];
	int i;

	/* sanity checks */
	assert_always(image, "image_load(): image is NULL");
	assert_always(path, "image_load(): path is NULL");

	/* we are now loading */
	image->is_loading = 1;

	/* first unload the image */
	image_unload(image);

	/* record the filename */
	image->err = set_image_filename(image, path, NULL);
	if (image->err)
		goto done;

	/* tell the OSD layer that this is changing */
	osd_image_load_status_changed(image, 0);

	/* do we need to reset the CPU? */
	if ((timer_get_time() > 0) && image->dev->reset_on_load)
		mame_schedule_soft_reset(Machine);

	/* determine open plan */
	determine_open_plan(image, is_create, open_plan);

	/* attempt to open the file in various ways */
	for (i = 0; !image->file && open_plan[i]; i++)
	{
		software_path = software_path_list;
		do
		{
			gamedrv = Machine->gamedrv;
			while(!is_loaded(image) && gamedrv)
			{
				/* open the file */
				image->err = load_image_by_path(image, software_path, gamedrv, open_plan[i], path);
				if (image->err && (image->err != IMAGE_ERROR_FILENOTFOUND))
					goto done;

				/* move on to the next driver */
				gamedrv = mess_next_compatible_driver(gamedrv);
			}

			/* move on to the next entry in the software path; if we can */
			if (software_path)
				software_path += strlen(software_path) + 1;
		}
		while(!is_loaded(image) && software_path && *software_path);
	}

	/* did we fail to find the file? */
	if (!is_loaded(image))
	{
		image->err = IMAGE_ERROR_FILENOTFOUND;
		goto done;
	}

	/* if applicable, call device verify */
	if (image->dev->imgverify && !image_has_been_created(image))
	{
		/* access the memory */
		buffer = image_ptr(image);
		if (!buffer)
		{
			image->err = IMAGE_ERROR_OUTOFMEMORY;
			goto done;
		}

		/* verify the file */
		err = image->dev->imgverify(buffer, (size_t) image->length);
		if (err)
		{
			image->err = IMAGE_ERROR_INVALIDIMAGE;
			goto done;
		}
	}

	/* call device load or create */
	if (image_has_been_created(image) && image->dev->create)
	{
		err = image->dev->create(image, create_format, create_args);
		if (err)
		{
			if (!image->err)
				image->err = IMAGE_ERROR_UNSPECIFIED;
			goto done;
		}
	}
	else if (image->dev->load)
	{
		/* using device load */
		err = image->dev->load(image);
		if (err)
		{
			if (!image->err)
				image->err = IMAGE_ERROR_UNSPECIFIED;
			goto done;
		}
	}

	/* success! */

done:
	if (software_path_list)
		free(software_path_list);
	if (image->err)
		image_clear(image);
	image->is_loading = 1;
	return image->err ? INIT_FAIL : INIT_PASS;
}
Example #4
0
static int image_load_internal(mess_image *img, const char *name, int is_create, int create_format, option_resolution *create_args)
{
	const struct IODevice *dev;
	const char *s;
	char *newname;
	int err = INIT_PASS;
	mame_file *file = NULL;
	UINT8 *buffer = NULL;
	UINT64 size;
	unsigned int readable, writeable, creatable;

	/* unload if we are loaded */
	if (img->status & IMAGE_STATUS_ISLOADED)
		image_unload(img);

	/* clear out the error */
	image_clear_error(img);
	
	/* if we are attempting to "load" NULL, then exit at this point */
	if (!name)
		return INIT_PASS;

	dev = image_device(img);
	assert(dev);

	img->status |= IMAGE_STATUS_ISLOADING;

	if (name && *name)
	{
		newname = image_strdup(img, name);
		if (!newname)
		{
			err = IMAGE_ERROR_OUTOFMEMORY;
			goto error;
		}
	}
	else
		newname = NULL;

	img->name = newname;
	img->dir = NULL;

	osd_image_load_status_changed(img, 0);

	/* do we need to reset the CPU? */
	if ((timer_get_time() > 0) && dev->reset_on_load)
		machine_reset();

	/* prepare to open the file */
	img->created = 0;
	img->writeable = 0;
	file = NULL;
	if (dev->getdispositions)
	{
		dev->getdispositions(dev, image_index_in_device(img), &readable, &writeable, &creatable);
	}
	else
	{
		readable = dev->readable;
		writeable = dev->writeable;
		creatable = dev->creatable;
	}

	/* is this a ZIP file? */
	s = strrchr(img->name, '.');
	if (s && !mame_stricmp(s, ".ZIP"))
	{
		/* ZIP files are writeable */
		writeable = 0;
		creatable = 0;
	}

	if (readable && !writeable)
	{
		file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_READ);
	}
	else if (!readable && writeable)
	{
		file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_WRITE);
		img->writeable = file ? 1 : 0;
	}
	else if (readable && writeable)
	{
		file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_RW);
		img->writeable = file ? 1 : 0;

		if (!file)
		{
			file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_READ);
			if (!file && creatable)
			{
				file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_RW_CREATE);
				img->writeable = file ? 1 : 0;
				img->created = file ? 1 : 0;
			}
		}
	}

	/* did this attempt succeed? */
	if (!file)
	{
		img->err = IMAGE_ERROR_FILENOTFOUND;
		goto error;
	}

	/* if applicable, call device verify */
	if (dev->imgverify && !image_has_been_created(img))
	{
		size = mame_fsize(file);
		buffer = malloc(size);
		if (!buffer)
		{
			img->err = IMAGE_ERROR_OUTOFMEMORY;
			goto error;
		}

		if (mame_fread(file, buffer, (UINT32) size) != size)
		{
			img->err = IMAGE_ERROR_INVALIDIMAGE;
			goto error;
		}

		err = dev->imgverify(buffer, size);
		if (err)
		{
			img->err = IMAGE_ERROR_INVALIDIMAGE;
			goto error;
		}

		mame_fseek(file, 0, SEEK_SET);

		free(buffer);
		buffer = NULL;
	}

	/* call device load or create */
	if (image_has_been_created(img) && dev->create)
	{
		err = dev->create(img, file, create_format, create_args);
		if (err)
		{
			if (!img->err)
				img->err = IMAGE_ERROR_UNSPECIFIED;
			goto error;
		}
	}
	else if (dev->load)
	{
		/* using device load */
		err = dev->load(img, file);
		if (err)
		{
			if (!img->err)
				img->err = IMAGE_ERROR_UNSPECIFIED;
			goto error;
		}
	}

	img->status &= ~IMAGE_STATUS_ISLOADING;
	img->status |= IMAGE_STATUS_ISLOADED;
	return INIT_PASS;

error:
	if (file)
		mame_fclose(file);
	if (buffer)
		free(buffer);
	if (img)
	{
		img->fp = NULL;
		img->name = NULL;
		img->status &= ~IMAGE_STATUS_ISLOADING|IMAGE_STATUS_ISLOADED;
	}

	osd_image_load_status_changed(img, 0);

	return INIT_FAIL;
}