コード例 #1
0
ファイル: hiscore.c プロジェクト: LibXenonProject/mame-lx
static void hiscore_save (running_machine &machine)
{
    file_error filerr;
	if (is_highscore_enabled(machine))
	{
		astring fname(machine.basename(), ".hi");
 		emu_file f = emu_file(machine.options().value(OPTION_HISCORE_DIRECTORY), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
		filerr = f.open(fname);
		LOG(("hiscore_save\n"));
		if (filerr == FILERR_NONE)
		{
			memory_range *mem_range = state.mem_range;
			LOG(("saving...\n"));
			while (mem_range)
			{
				UINT8 *data = global_alloc_array(UINT8, 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 (machine, mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
					f.write(data, mem_range->num_bytes);
					global_free (data);
				}
				mem_range = mem_range->next;
			}
			f.close();
		}
	}
}
コード例 #2
0
ファイル: hiscore.cpp プロジェクト: h0tw1r3/mameuifx
static void hiscore_save (running_machine &machine)
{
	file_error filerr;
  	emu_file f(machine.options().hiscore_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
  	filerr = f.open(machine.basename(), ".hi");

	if (filerr == FILERR_NONE)
	{
		memory_range *mem_range = state.mem_range;

		while (mem_range)
		{
			std::unique_ptr<UINT8[]> data = std::make_unique<UINT8[]>(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 (machine, mem_range->cpu, mem_range->addr, data.get(), mem_range->num_bytes);
				f.write(data.get(), mem_range->num_bytes);
				data = nullptr;
			}
			
			mem_range = mem_range->next;
		}
		
		f.close();
	}
}
コード例 #3
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);
	}
}
コード例 #4
0
ファイル: hiscore.c プロジェクト: felipeota/cps2emu-rpi
static void hs_save (void)
{
	unsigned char *hs_cmp = malloc(state.hiscore_file_size);
	unsigned char *data = malloc (state.hiscore_file_size);

	if(!hs_cmp || !data) {
		msg_printf("High score save failed.\n");
	} else {
		struct mem_range *mem_range = state.mem_range;
		unsigned char *cmp = hs_cmp;
		char path[MAX_PATH];
		FILE *f = NULL;
		int ret = 0;

                sprintf(path, "%shi/%s.hi", launchDir, game_name);

		if ((f = fopen(path, "rb")) != NULL) {
			ret = fread(hs_cmp, 1, state.hiscore_file_size, f);
			fclose(f);
		}

		while (mem_range)
		{
			/*	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);
			if((ret != state.hiscore_file_size) || memcmp(data, cmp, mem_range->num_bytes)) {
				memcpy(cmp, data, mem_range->num_bytes);
				if(ret) ret = 0;
			}

			cmp += mem_range->num_bytes;
			mem_range = mem_range->next;
		}

		if(!ret) {
			if ((f = fopen(path, "wb")) == NULL) {
				msg_printf("High score save failed.\n");
			} else {
				fwrite(hs_cmp, 1, state.hiscore_file_size, f);
				fclose(f);
				msg_printf("High score saved.\n");
			}
		}
	}

	if(hs_cmp) free(hs_cmp);
	if(data) free(data);
}