Beispiel #1
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);
}
Beispiel #2
0
int memcard_insert(int index)
{
	mame_file *file;
	char name[16];

	/* if a card is already inserted, eject it first */
	if (memcard_inserted != -1)
		memcard_eject();
	assert(memcard_inserted == -1);

	/* create a name */
	memcard_name(index, name);

	/* open the file; if we can't, it's an error */
	file = mame_fopen(Machine->gamedrv->name, name, FILETYPE_MEMCARD, FALSE);
	if (file == NULL)
		return 1;

	/* initialize and then load the card */
	if (Machine->drv->memcard_handler)
		(*Machine->drv->memcard_handler)(file, MEMCARD_INSERT);

	/* close the file */
	mame_fclose(file);
	memcard_inserted = index;
	return 0;
}
Beispiel #3
0
static void hs_load (void)
{
	mame_file *f = mame_fopen (Machine->gamedrv->name, 0, FILETYPE_HIGHSCORE, 0);
	state.hiscores_have_been_loaded = 1;
	LOG(("hs_load\n"));
	if (f)
	{
		struct mem_range *mem_range = state.mem_range;
		LOG(("loading...\n"));
		while (mem_range)
		{
			UINT8 *data = osd_malloc (mem_range->num_bytes);
			if (data)
			{
				/*	this buffer will almost certainly be small
					enough to be dynamically allocated, but let's
					avoid memory trashing just in case
				*/
				mame_fread (f, data, mem_range->num_bytes);
				copy_to_memory (mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
				free (data);
			}
			mem_range = mem_range->next;
		}
		mame_fclose (f);
	}
}
Beispiel #4
0
static void update_fps(mame_time emutime)
{
	osd_ticks_t curr = osd_ticks();

	// update stats for the FPS average calculation
	if (fps_start_time == 0)
	{
		// start the timer going 1 second into the game
		if (emutime.seconds > 1)
			fps_start_time = osd_ticks();
	}
	else
	{
		fps_frames_displayed++;
		if (fps_frames_displayed == video_config.framestorun)
		{
			mame_file_error filerr;
			mame_file *fp;
			char name[20];

			// make a filename with an underscore prefix
			sprintf(name, "_%.8s.png", Machine->gamedrv->name);

			// write out the screenshot
			filerr = mame_fopen(SEARCHPATH_SCREENSHOT, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &fp);
			if (filerr == FILERR_NONE)
			{
				video_screen_save_snapshot(fp, 0);
				mame_fclose(fp);
			}
			mame_schedule_exit(Machine);
		}
		fps_end_time = curr;
	}
}
Beispiel #5
0
/* load battery backed nvram from a driver subdir. in the nvram dir. */
int image_battery_load(mess_image *img, void *buffer, int length)
{
	mame_file *f;
	int bytes_read = 0;
	int result = FALSE;
	char *nvram_filename;

	/* some sanity checking */
	if( buffer != NULL && length > 0 )
	{
		nvram_filename = battery_nvramfilename(img);
		if (nvram_filename)
		{
			f = mame_fopen(Machine->gamedrv->name, nvram_filename, FILETYPE_NVRAM, 0);
			if (f)
			{
				bytes_read = mame_fread(f, buffer, length);
				mame_fclose(f);
				result = TRUE;
			}
			free(nvram_filename);
		}

		/* fill remaining bytes (if necessary) */
		memset(((char *) buffer) + bytes_read, '\0', length - bytes_read);
	}
	return result;
}
Beispiel #6
0
void memcard_eject(void)
{
	mame_file *file;
	char name[16];

	/* if no card is preset, just ignore */
	if (memcard_inserted == -1)
		return;

	/* create a name */
	memcard_name(memcard_inserted, name);

	/* open the file; if we can't, it's an error */
	file = mame_fopen(Machine->gamedrv->name, name, FILETYPE_MEMCARD, TRUE);
	if (file == NULL)
	{
		mame_fclose(file);
		return;
	}

	/* initialize and then load the card */
	if (Machine->drv->memcard_handler)
		(*Machine->drv->memcard_handler)(file, MEMCARD_EJECT);

	/* close the file */
	mame_fclose(file);
	memcard_inserted = -1;
}
Beispiel #7
0
static void hs_save (void)
{
	mame_file *f = mame_fopen (Machine->gamedrv->name, 0, FILETYPE_HIGHSCORE, 1);
	LOG(("hs_save\n"));
	if (f)
	{
		struct mem_range *mem_range = state.mem_range;
		LOG(("saving...\n"));
		while (mem_range)
		{
			UINT8 *data = osd_malloc (mem_range->num_bytes);
			if (data)
			{
				/*	this buffer will almost certainly be small
					enough to be dynamically allocated, but let's
					avoid memory trashing just in case
				*/
				copy_from_memory (mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
				mame_fwrite(f, data, mem_range->num_bytes);
			}
			mem_range = mem_range->next;
		}
		mame_fclose(f);
	}
}
Beispiel #8
0
struct GameSamples *readsamples(const char **samplenames,const char *basename)
/* V.V - avoids samples duplication */
/* if first samplename is *dir, looks for samples into "basename" first, then "dir" */
{
	int i;
	struct GameSamples *samples;
	int skipfirst = 0;

	/* if the user doesn't want to use samples, bail */
	if (!options.use_samples) return 0;

	if (samplenames == 0 || samplenames[0] == 0) return 0;

	if (samplenames[0][0] == '*')
		skipfirst = 1;

	i = 0;
	while (samplenames[i+skipfirst] != 0) i++;

	if (!i) return 0;

	if ((samples = auto_malloc(sizeof(struct GameSamples) + (i-1)*sizeof(struct GameSample))) == 0)
		return 0;

	samples->total = i;
	for (i = 0;i < samples->total;i++)
		samples->sample[i] = 0;

	for (i = 0;i < samples->total;i++)
	{
		mame_file *f;

		if (samplenames[i+skipfirst][0])
		{
			if ((f = mame_fopen(basename,samplenames[i+skipfirst],FILETYPE_SAMPLE,0)) == 0)
				if (skipfirst)
					f = mame_fopen(samplenames[0]+1,samplenames[i+skipfirst],FILETYPE_SAMPLE,0);
			if (f != 0)
			{
				samples->sample[i] = read_wav_sample(f);
				mame_fclose(f);
			}
		}
	}

	return samples;
}
int debug_comment_load(void)
{
	mame_file *fp = mame_fopen(Machine->gamedrv->name, 0, FILETYPE_COMMENT, 0);
	if (!fp) return 0;
	debug_comment_load_xml(fp);
	mame_fclose(fp);

	return 1;
}
Beispiel #10
0
static chd_file *get_disc(const device_config *device)
{
	mame_file *image_file = NULL;
	chd_file *image_chd = NULL;
	mame_path *path;

	/* open a path to the ROMs and find the first CHD file */
	path = mame_openpath(mame_options(), OPTION_ROMPATH);
	if (path != NULL)
	{
		const osd_directory_entry *dir;

		/* iterate while we get new objects */
		while ((dir = mame_readpath(path)) != NULL)
		{
			int length = strlen(dir->name);

			/* look for files ending in .chd */
			if (length > 4 &&
				dir->name[length - 4] == '.' &&
				tolower(dir->name[length - 3]) == 'c' &&
				tolower(dir->name[length - 2]) == 'h' &&
				tolower(dir->name[length - 1]) == 'd')
			{
				file_error filerr;
				chd_error chderr;

				/* open the file itself via our search path */
				filerr = mame_fopen(SEARCHPATH_IMAGE, dir->name, OPEN_FLAG_READ, &image_file);
				if (filerr == FILERR_NONE)
				{
					/* try to open the CHD */
					chderr = chd_open_file(mame_core_file(image_file), CHD_OPEN_READ, NULL, &image_chd);
					if (chderr == CHDERR_NONE)
					{
						set_disk_handle(device->machine, "laserdisc", image_file, image_chd);
						filename = astring_dupc(dir->name);
						add_exit_callback(device->machine, free_string);
						break;
					}

					/* close the file on failure */
					mame_fclose(image_file);
					image_file = NULL;
				}
			}
		}
		mame_closepath(path);
	}

	/* if we failed, pop a message and exit */
	if (image_file == NULL)
		fatalerror("No valid image file found!\n");

	return get_disk_handle(device->machine, "laserdisc");
}
Beispiel #11
0
void nvram_load(void)
{
	if (Machine->drv->nvram_handler != NULL)
	{
		mame_file *nvram_file = mame_fopen(Machine->gamedrv->name, 0, FILETYPE_NVRAM, 0);
		(*Machine->drv->nvram_handler)(nvram_file, 0);
		if (nvram_file != NULL)
			mame_fclose(nvram_file);
	}
}
Beispiel #12
0
void mc146818_save(void)
{
	mame_file *file;

	file = mame_fopen(Machine->gamedrv->name, 0, FILETYPE_NVRAM, 1);
	if (file)
	{
		mame_fwrite(file, mc146818->data, sizeof(mc146818->data));
		mame_fclose(file);
	}
}
Beispiel #13
0
void mc146818_load(void)
{
	mame_file *file;

	file = mame_fopen(Machine->gamedrv->name, 0, FILETYPE_NVRAM, 0);
	if (file)
	{
		mc146818_load_stream(file);
		mame_fclose(file);
	}
}
Beispiel #14
0
mame_file *nvram_fopen(running_machine *machine, UINT32 openflags)
{
	file_error filerr;
	mame_file *file;
	astring *fname;

	fname = astring_assemble_2(astring_alloc(), machine->basename, ".nv");
	filerr = mame_fopen(SEARCHPATH_NVRAM, astring_c(fname), openflags, &file);
	astring_free(fname);

	return (filerr == FILERR_NONE) ? file : NULL;
}
Beispiel #15
0
/*
 * gamedrv  = NULL --> parse named configfile
 * gamedrv != NULL --> parse gamename.ini and all parent.ini's (recursively)
 * return 0 --> no problem
 * return 1 --> something went wrong
 */
int parse_config (const char* filename, const struct GameDriver *gamedrv)
{
	mame_file *f;
	char buffer[128];
	int retval = 0;

	if (!readconfig) return 0;

	if (gamedrv)
	{
		if (gamedrv->clone_of && strlen(gamedrv->clone_of->name))
		{
			retval = parse_config (NULL, gamedrv->clone_of);
			if (retval)
				return retval;
		}
		sprintf(buffer, "%s.ini", gamedrv->name);
	}
	else
	{
		sprintf(buffer, "%s", filename);
	}

	if (verbose)
		fprintf(stderr, "parsing %s...", buffer);

	f = mame_fopen (buffer, NULL, FILETYPE_INI, 0);
	if (f)
	{
		if(osd_rc_read(rc, f, buffer, 1, 1))
		{
			if (verbose)
				fprintf (stderr, "problem parsing %s\n", buffer);
			retval = 1;
		}
		else
		{
			if (verbose)
				fprintf (stderr, "OK.\n");
		}
	}
	else
	{
		if (verbose)
			fprintf (stderr, "N/A\n");
	}

	if (f)
		mame_fclose (f);

	return retval;
}
Beispiel #16
0
void record_movie_start(const char *name)
{
#if 0 /* AdvanceMAME has its record code */
	if (movie_file != NULL)
		mame_fclose(movie_file);

	if (name)
		movie_file = mame_fopen(Machine->gamedrv->name, name, FILETYPE_MOVIE, 1);
	else
		movie_file = mame_fopen_next(FILETYPE_MOVIE);

	movie_frame = 0;
#endif
}
Beispiel #17
0
int memcard_create(int index, int overwrite)
{
	file_error filerr;
	mame_file *file;
	astring *fname;
	char name[16];

	/* create a name */
	memcard_name(index, name);

	/* if we can't overwrite, fail if the file already exists */
	fname = astring_assemble_3(astring_alloc(), Machine->basename, PATH_SEPARATOR, name);
	if (!overwrite)
	{
		filerr = mame_fopen(SEARCHPATH_MEMCARD, astring_c(fname), OPEN_FLAG_READ, &file);
		if (filerr == FILERR_NONE)
		{
			mame_fclose(file);
			astring_free(fname);
			return 1;
		}
	}

	/* create a new file */
	filerr = mame_fopen(SEARCHPATH_MEMCARD, astring_c(fname), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
	astring_free(fname);
	if (filerr != FILERR_NONE)
		return 1;

	/* initialize and then save the card */
	if (Machine->drv->memcard_handler)
		(*Machine->drv->memcard_handler)(Machine, file, MEMCARD_CREATE);

	/* close the file */
	mame_fclose(file);
	return 0;
}
Beispiel #18
0
static int init_errorlog(struct rc_option *option, const char *arg, int priority)
{
    /* provide errorlog from here on */
    if (errorlog)
    {
        options.logfile = mame_fopen(NULL, "error.log", FILETYPE_DEBUGLOG, TRUE);
        if (!options.logfile)
        {
            perror("unable to open log file\n");
            exit(1);
        }
    }
    option->priority = priority;
    return 0;
}
Beispiel #19
0
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))
	{
		void* file = mame_fopen(drv->name, filename, FILETYPE_IMAGE, 0);

		if (file != NULL)
			return file;
	}

	return NULL;
}
Beispiel #20
0
static mame_file_error open_battery_file(mess_image *image, UINT32 openflags, mame_file **file)
{
	mame_file_error filerr;
	char *basename_noext;
	char *fname;

	basename_noext = strip_extension(image_basename(image));
	if (!basename_noext)
		return FILERR_OUT_OF_MEMORY;
	fname = assemble_4_strings(Machine->gamedrv->name, PATH_SEPARATOR, basename_noext, ".nv");
	filerr = mame_fopen(SEARCHPATH_NVRAM, fname, openflags, file);
	free(fname);
	free(basename_noext);
	return filerr;
}
Beispiel #21
0
void video_movie_begin_recording(const char *name)
{
	mame_file_error filerr;

	/* close any existing movie file */
	if (movie_file != NULL)
		mame_fclose(movie_file);

	/* create a new movie file and start recording */
	if (name != NULL)
		filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &movie_file);
	else
		filerr = mame_fopen_next(SEARCHPATH_MOVIE, "mng", &movie_file);

	movie_frame = 0;
}
Beispiel #22
0
static void dump_screenshot(int write_file)
{
	mame_file *fp;
	char buf[128];
	mame_bitmap *bitmap;
	int x, y, is_blank;
	pen_t color;
	extern mame_bitmap *scrbitmap[8];

	bitmap = artwork_get_ui_bitmap();

	if (write_file)
	{
		/* dump a screenshot */
		snprintf(buf, sizeof(buf) / sizeof(buf[0]),
			(screenshot_num >= 0) ? "_%s_%d.png" : "_%s.png",
			current_testcase.name, screenshot_num);
		fp = mame_fopen(Machine->gamedrv->name, buf, FILETYPE_SCREENSHOT, 1);
		if (fp)
		{
			save_screen_snapshot_as(fp, bitmap);
			mame_fclose(fp);
			report_message(MSG_INFO, "Saved screenshot as %s", buf);
		}

		if (screenshot_num >= 0)
			screenshot_num++;
	}

	/* check to see if bitmap is blank */
	bitmap = scrbitmap[0];
	is_blank = 1;
	color = bitmap->read(bitmap, 0, 0);
	for (y = 0; is_blank && (y < bitmap->height); y++)
	{
		for (x = 0; is_blank && (x < bitmap->width); x++)
		{
			if (bitmap->read(bitmap, x, y) != color)
				is_blank = 0;
		}
	}
	if (is_blank)
	{
		had_failure = TRUE;
		report_message(MSG_FAILURE, "Screenshot is blank");
	}
}
Beispiel #23
0
int ti99_ide_load_memcard(void)
{
	mame_file_error filerr;
	mame_file *file;

	filerr = mame_fopen(SEARCHPATH_MEMCARD, "ide.nv", OPEN_FLAG_READ, &file);
	if (filerr != FILERR_NONE)
		return /*1*/0;
	if (rtc65271_file_load(file))
	{
		mame_fclose(file);
		return 1;
	}

	mame_fclose(file);
	return 0;
}
Beispiel #24
0
int ti99_hsgpl_load_memcard(void)
{
	mame_file *file;


	file = mame_fopen(Machine->gamedrv->name, "hsgpl", FILETYPE_MEMCARD, OSD_FOPEN_READ);
	if (! file)
		return /*1*/0;
	if (ti99_hsgpl_file_load(file))
	{
		mame_fclose(file);
		return 1;
	}

	mame_fclose(file);
	return 0;
}
Beispiel #25
0
/****************************************************************************
 *      ParseOpen - Open up file for reading
 ****************************************************************************/
static UINT8 ParseOpen(const char *pszFilename)
{
        /* Open file up in binary mode */

        fp = mame_fopen (NULL, pszFilename, FILETYPE_HISTORY, 0);

        /* If this is NULL, return FALSE. We can't open it */

        if (NULL == fp)
        {
                return(FALSE);
        }

        /* Otherwise, prepare! */

        dwFilePos = 0;
        return(TRUE);
}
Beispiel #26
0
static chd_interface_file *mess_chd_open(const char *filename, const char *mode)
{
	mess_image *img = decode_image_ref(filename);

	/* used when experimenting with CHDs */
	if (USE_CHD_OPEN && !img)
		return (chd_interface_file *) mame_fopen(NULL, filename, FILETYPE_IMAGE, 0);

	/* invalid "file name"? */
	assert(img);

	/* read-only fp? */
	if (!image_is_writable(img) && !(mode[0] == 'r' && !strchr(mode, '+')))
		return NULL;

	/* otherwise return file pointer */
	return (chd_interface_file *) image_fp(img);
}
Beispiel #27
0
static mame_file *mame_fopen_next(int filetype)
{
	char name[FILENAME_MAX];
	int seq;

	/* avoid overwriting existing files */
	/* first of all try with "gamename.xxx" */
	sprintf(name,"%.8s", Machine->gamedrv->name);
	if (mame_faccess(name, filetype))
	{
		seq = 0;
		do
		{
			/* otherwise use "nameNNNN.xxx" */
			sprintf(name,"%.4s%04d",Machine->gamedrv->name, seq++);
		} while (mame_faccess(name, filetype));
	}

    return (mame_fopen(Machine->gamedrv->name, name, filetype, 1));
}
Beispiel #28
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;
}
Beispiel #29
0
int ti99_hsgpl_save_memcard(void)
{
	mame_file *file;

	if (ti99_hsgpl_get_dirty_flag())
	{
		file = mame_fopen(Machine->gamedrv->name, "hsgpl", FILETYPE_MEMCARD, OSD_FOPEN_WRITE);
		if (! file)
			return 1;
		if (ti99_hsgpl_file_save(file))
		{
			mame_fclose(file);
			return 1;
		}

		mame_fclose(file);
	}

	return 0;
}
Beispiel #30
0
int ti99_ide_save_memcard(void)
{
	mame_file_error filerr;
	mame_file *file;

	/*if (ti99_ide_get_dirty_flag())*/
	{
		filerr = mame_fopen(SEARCHPATH_MEMCARD, "ide.nv", OPEN_FLAG_WRITE, &file);
		if (filerr != FILERR_NONE)
			return 1;
		if (rtc65271_file_save(file))
		{
			mame_fclose(file);
			return 1;
		}

		mame_fclose(file);
	}

	return 0;
}