Beispiel #1
0
int emu_SaveLoadSRAM(int load)
{
	int ret = 0;
	static char saveFname[512];

	romfname_ext(saveFname, NULL, (PicoMCD & 1) ? ".brm" : ".srm");
	if (load && !try_ropen_file(saveFname)) return 0;

	FILE *sramFile;
	int sram_size;
	unsigned char *sram_data;
	int truncate = 1;
	if (PicoMCD & 1) {
		if (PicoOpt & PicoOpt_enable_cd_ramcart) { // MCD RAM cart?
			sram_size = 0x12000;
			sram_data = SRam.data;
			if (sram_data)
				memcpy32((int *)sram_data, (int *)Pico_mcd->bram, 0x2000/4);
		} else {
			sram_size = 0x2000;
			sram_data = Pico_mcd->bram;
			truncate  = 0; // the .brm may contain RAM cart data after normal brm
		}
	} else {
		sram_size = SRam.end - SRam.start + 1;
		if(Pico.m.sram_reg & 4) sram_size=0x2000;
		sram_data = SRam.data;
	}
	if (!sram_data) return 0; // SRam forcefully disabled for this game

	if (load) {
		sramFile = fopen(saveFname, "rb");
		if(!sramFile) return -1;
		fread(sram_data, 1, sram_size, sramFile);
		fclose(sramFile);
		if ((PicoMCD & 1) && (PicoOpt & PicoOpt_enable_cd_ramcart))
			memcpy32((int *)Pico_mcd->bram, (int *)sram_data, 0x2000/4);
	} else {
		// sram save needs some special processing
		// see if we have anything to save
		for (; sram_size > 0; sram_size--)
			if (sram_data[sram_size - 1]) break;

		if (sram_size) {
			sramFile = fopen(saveFname, truncate ? "wb" : "r+b");
			if (!sramFile) sramFile = fopen(saveFname, "wb"); // retry
			if (!sramFile) return -1;
			ret = fwrite(sram_data, 1, sram_size, sramFile);
			ret = (ret != sram_size) ? -1 : 0;
			fclose(sramFile);
		}
	}

	return ret;	
}
Beispiel #2
0
char *emu_GetSaveFName(int load, int is_sram, int slot)
{
	static char saveFname[512];
	char ext[16];

	if (is_sram)
	{
		romfname_ext(saveFname, (PicoMCD&1) ? brmPath : srmPath, (PicoMCD&1) ? ".brm" : ".srm");
		if (load) {
			if (try_ropen_file(saveFname)) return saveFname;
			// try in current dir..
			romfname_ext(saveFname, NULL, (PicoMCD&1) ? ".brm" : ".srm");
			if (try_ropen_file(saveFname)) return saveFname;
			return NULL; // give up
		}
	}
	else
	{
		ext[0] = 0;
		if(slot > 0 && slot < 10) sprintf(ext, ".%i", slot);
		strcat(ext, (currentConfig.EmuOpt & 8) ? ".mds.gz" : ".mds");

		romfname_ext(saveFname, mdsPath, ext);
		if (load) {
			if (try_ropen_file(saveFname)) return saveFname;
			romfname_ext(saveFname, NULL, ext);
			if (try_ropen_file(saveFname)) return saveFname;
			if (currentConfig.EmuOpt & 8) {
				ext[0] = 0;
				if(slot > 0 && slot < 10) sprintf(ext, ".%i", slot);
				strcat(ext, ".mds");

				romfname_ext(saveFname, mdsPath, ext);
				if (try_ropen_file(saveFname)) return saveFname;
				romfname_ext(saveFname, NULL, ext);
				if (try_ropen_file(saveFname)) return saveFname;
			}
			return NULL;
		}
	}

	return saveFname;
}