Beispiel #1
0
int SaveStateGz(gzFile f, long* gzsize) {
	int Size;
	unsigned char pMemGpuPic[SZ_GPUPIC];

	//if (f == NULL) return -1;

	gzwrite(f, (void *)PcsxrHeader, sizeof(PcsxrHeader));
	gzwrite(f, (void *)&SaveVersion, sizeof(u32));
	gzwrite(f, (void *)&Config.HLE, sizeof(boolean));

	if (gzsize)GPU_getScreenPic(pMemGpuPic); // Not necessary with ephemeral saves
	gzwrite(f, pMemGpuPic, SZ_GPUPIC);

	if (Config.HLE)
		psxBiosFreeze(1);

	gzwrite(f, psxM, 0x00200000);
	gzwrite(f, psxR, 0x00080000);
	gzwrite(f, psxH, 0x00010000);
	gzwrite(f, (void *)&psxRegs, sizeof(psxRegs));

	// gpu
	if (!gpufP)gpufP = (GPUFreeze_t *)malloc(sizeof(GPUFreeze_t));
	gpufP->ulFreezeVersion = 1;
	GPU_freeze(1, gpufP);
	gzwrite(f, gpufP, sizeof(GPUFreeze_t));

	// SPU Plugin cannot change during run, so we query size info just once per session
	if (!spufP) {
		spufP = (SPUFreeze_t *)malloc(offsetof(SPUFreeze_t, SPUPorts)); // only first 3 elements (up to Size)        
		SPU_freeze(2, spufP);
		Size = spufP->Size;
		SysPrintf("SPUFreezeSize %i/(%i)\n", Size, offsetof(SPUFreeze_t, SPUPorts));
		free(spufP);
		spufP = (SPUFreeze_t *) malloc(Size);
		spufP->Size = Size;

		if (spufP->Size <= 0) {
			gzclose(f);
			free(spufP);
			spufP = NULL;
			return 1; // error
		}
	}
	// spu
	gzwrite(f, &(spufP->Size), 4);
	SPU_freeze(1, spufP);
	gzwrite(f, spufP, spufP->Size);

	sioFreeze(f, 1);
	cdrFreeze(f, 1);
	psxHwFreeze(f, 1);
	psxRcntFreeze(f, 1);
	mdecFreeze(f, 1);

	if(gzsize)*gzsize = gztell(f);
	gzclose(f);

	return 0;
}
Beispiel #2
0
int SaveState(const char *file) {
	void *f;
	GPUFreeze_t *gpufP;
	SPUFreeze_t *spufP;
	int Size;
	unsigned char *pMem;

	f = SaveFuncs.open(file, "wb");
	if (f == NULL) return -1;

	new_dyna_before_save();

	SaveFuncs.write(f, (void *)PcsxHeader, 32);
	SaveFuncs.write(f, (void *)&SaveVersion, sizeof(u32));
	SaveFuncs.write(f, (void *)&Config.HLE, sizeof(boolean));

	pMem = (unsigned char *)malloc(128 * 96 * 3);
	if (pMem == NULL) return -1;
	GPU_getScreenPic(pMem);
	SaveFuncs.write(f, pMem, 128 * 96 * 3);
	free(pMem);

	if (Config.HLE)
		psxBiosFreeze(1);

	SaveFuncs.write(f, psxM, 0x00200000);
	SaveFuncs.write(f, psxR, 0x00080000);
	SaveFuncs.write(f, psxH, 0x00010000);
	SaveFuncs.write(f, (void *)&psxRegs, sizeof(psxRegs));

	// gpu
	gpufP = (GPUFreeze_t *)malloc(sizeof(GPUFreeze_t));
	gpufP->ulFreezeVersion = 1;
	GPU_freeze(1, gpufP);
	SaveFuncs.write(f, gpufP, sizeof(GPUFreeze_t));
	free(gpufP);

	// spu
	spufP = (SPUFreeze_t *) malloc(16);
	SPU_freeze(2, spufP, psxRegs.cycle);
	Size = spufP->Size; SaveFuncs.write(f, &Size, 4);
	free(spufP);
	spufP = (SPUFreeze_t *) malloc(Size);
	SPU_freeze(1, spufP, psxRegs.cycle);
	SaveFuncs.write(f, spufP, Size);
	free(spufP);

	sioFreeze(f, 1);
	cdrFreeze(f, 1);
	psxHwFreeze(f, 1);
	psxRcntFreeze(f, 1);
	mdecFreeze(f, 1);
	new_dyna_freeze(f, 1);

	SaveFuncs.close(f);

	new_dyna_after_save();

	return 0;
}
Beispiel #3
0
int LoadState(const char *file) {
	gzFile f;
	GPUFreeze_t *gpufP;
	SPUFreeze_t *spufP;
	int Size;
	char header[32];
	u32 version;
	boolean hle;

	f = gzopen(file, "rb");
	if (f == NULL) return -1;

	gzread(f, header, sizeof(header));
	gzread(f, &version, sizeof(u32));
	gzread(f, &hle, sizeof(boolean));

	if (strncmp("STv4 PCSXR", header, 10) != 0 || version != SaveVersion || hle != Config.HLE) {
		gzclose(f);
		return -1;
	}

	psxCpu->Reset();
	gzseek(f, 128 * 96 * 3, SEEK_CUR);

	gzread(f, psxM, 0x00200000);
	gzread(f, psxR, 0x00080000);
	gzread(f, psxH, 0x00010000);
	gzread(f, (void *)&psxRegs, sizeof(psxRegs));

	if (Config.HLE)
		psxBiosFreeze(0);

	// gpu
	gpufP = (GPUFreeze_t *)malloc(sizeof(GPUFreeze_t));
	gzread(f, gpufP, sizeof(GPUFreeze_t));
	GPU_freeze(0, gpufP);
	free(gpufP);

	// spu
	gzread(f, &Size, 4);
	spufP = (SPUFreeze_t *)malloc(Size);
	gzread(f, spufP, Size);
	SPU_freeze(0, spufP);
	free(spufP);

	sioFreeze(f, 0);
	cdrFreeze(f, 0);
	psxHwFreeze(f, 0);
	psxRcntFreeze(f, 0);
	mdecFreeze(f, 0);

	gzclose(f);

	return 0;
}
Beispiel #4
0
int LoadStateGz(gzFile f) {
	SPUFreeze_t *_spufP;
	int Size;
	char header[sizeof(PcsxrHeader)];
	u32 version;
	boolean hle;

	if (f == NULL) return -1;

	gzread(f, header, sizeof(header));
	gzread(f, &version, sizeof(u32));
	gzread(f, &hle, sizeof(boolean));

	// Compare header only "STv4 PCSXR" part no version
	if (strncmp(PcsxrHeader, header, PCSXR_HEADER_SZ) != 0 || version != SaveVersion || hle != Config.HLE) {
		gzclose(f);
		return -1;
	}

	psxCpu->Reset();
	gzseek(f, SZ_GPUPIC, SEEK_CUR);

	gzread(f, psxM, 0x00200000);
	gzread(f, psxR, 0x00080000);
	gzread(f, psxH, 0x00010000);
	gzread(f, (void *)&psxRegs, sizeof(psxRegs));

	if (Config.HLE)
		psxBiosFreeze(0);

	// gpu
	if (!gpufP)gpufP = (GPUFreeze_t *)malloc(sizeof(GPUFreeze_t));
	gzread(f, gpufP, sizeof(GPUFreeze_t));
	GPU_freeze(0, gpufP);

	// spu
	gzread(f, &Size, 4);
	_spufP = (SPUFreeze_t *)malloc(Size);
	gzread(f, _spufP, Size);
	SPU_freeze(0, _spufP);
	free(_spufP);

	sioFreeze(f, 0);
	cdrFreeze(f, 0);
	psxHwFreeze(f, 0);
	psxRcntFreeze(f, 0);
	mdecFreeze(f, 0);

	gzclose(f);

	return 0;
}
Beispiel #5
0
int LoadState(const char *file) {
	void *f;
	GPUFreeze_t *gpufP;
	SPUFreeze_t *spufP;
	int Size;
	char header[32];
	u32 version;
	boolean hle;

	f = SaveFuncs.open(file, "rb");
	if (f == NULL) return -1;

	SaveFuncs.read(f, header, sizeof(header));
	SaveFuncs.read(f, &version, sizeof(u32));
	SaveFuncs.read(f, &hle, sizeof(boolean));

	if (strncmp("STv4 PCSX", header, 9) != 0 || version != SaveVersion) {
		SaveFuncs.close(f);
		return -1;
	}
	Config.HLE = hle;

	if (Config.HLE)
		psxBiosInit();

	psxCpu->Reset();
	SaveFuncs.seek(f, 128 * 96 * 3, SEEK_CUR);

	SaveFuncs.read(f, psxM, 0x00200000);
	SaveFuncs.read(f, psxR, 0x00080000);
	SaveFuncs.read(f, psxH, 0x00010000);
	SaveFuncs.read(f, (void *)&psxRegs, sizeof(psxRegs));

	if (Config.HLE)
		psxBiosFreeze(0);

	// gpu
	gpufP = (GPUFreeze_t *)malloc(sizeof(GPUFreeze_t));
	SaveFuncs.read(f, gpufP, sizeof(GPUFreeze_t));
	GPU_freeze(0, gpufP);
	free(gpufP);
	if (HW_GPU_STATUS == 0)
		HW_GPU_STATUS = GPU_readStatus();

	// spu
	SaveFuncs.read(f, &Size, 4);
	spufP = (SPUFreeze_t *)malloc(Size);
	SaveFuncs.read(f, spufP, Size);
	SPU_freeze(0, spufP);
	free(spufP);

	sioFreeze(f, 0);
	cdrFreeze(f, 0);
	psxHwFreeze(f, 0);
	psxRcntFreeze(f, 0);
	mdecFreeze(f, 0);

	SaveFuncs.close(f);
	new_dyna_restore();

	return 0;
}
Beispiel #6
0
int LoadStateEmbed(char *file) {
	GPUFreeze_t *gpufP;
	int Size;
	char header[32];
	FILE* fp;
	FILE* fp2;
	uint8 * embSaveTmp;
	size_t blockSize = Movie.memoryCard1Offset-Movie.saveStateOffset;

	embSaveTmp = (uint8*)malloc(blockSize);
	fp = fopen(file,"rb");
	fp2 = fopen("embsave.tmp","wb");
	fseek(fp, Movie.saveStateOffset, SEEK_SET);
	fread(embSaveTmp, 1, blockSize, fp);
	fwrite(embSaveTmp, 1, blockSize, fp2);
	fclose(fp);
	fclose(fp2);

	EMUFILE_FILE ef("embsave.tmp", "rb");
	if (ef.fail()) return -1;
	EMUFILE *f = &ef;

	psxCpu->Reset();

	gzread(f, header, 32);

	if (strncmp("STv3 PSXjin", header, 9)) { return -1; }

	exceptionPatches.clear();
	int tag;
	gzread(f, &tag, 4);
	if (tag == 'ExPs') {
		gzread(f, &Size, 4);
		while (Size--) {
			u32 addr, val;
			gzread(f, &addr, 4);
			gzread(f, &val, 4);
			exceptionPatches.push_back(std::make_pair(addr, val));
		}
		gzseek(f, 128*96*3-4-4-exceptionPatches.size()*4*2, SEEK_CUR);
	}
	else
		gzseek(f, 128*96*3-4, SEEK_CUR);

	gzread(f, psxM, 0x00200000);
	gzread(f, psxP, 0x00010000);
	gzread(f, psxR, 0x00080000);
	gzread(f, psxH, 0x00010000);
	gzread(f, (void*)&psxRegs, sizeof(psxRegs));

	if (Config.HLE)	//adelikat: TODO: remove all references to Config.HLE, we will not be using that BIOS, ever
		psxBiosFreeze(0);

	// gpu
	gpufP = (GPUFreeze_t *) malloc (sizeof(GPUFreeze_t));
	gzread(f, gpufP, sizeof(GPUFreeze_t));
	gpufP->extraData = malloc(gpufP->extraDataSize);
	gzread(f, gpufP->extraData, gpufP->extraDataSize);
	GPUfreeze(0, gpufP);
	free(gpufP->extraData);
	free(gpufP);

	sioFreeze(f, 0);
	cdrFreeze(f, 0);
	psxHwFreeze(f, 0);
	CDRisoFreeze(f,0);
	psxRcntFreeze(f, 0);
	mdecFreeze(f, 0);
	//TODO - no movie state? are you sure?

	// spu
	gzread(f, &Size, 4);
	EMUFILE_MEMORY memfile;
	memfile.truncate(Size);
	gzread(f, memfile.buf(), Size);
	bool ok = SPUunfreeze_new(&memfile);
	if(!ok) return 1;

	remove("embsave.tmp");

	return 0;
}
Beispiel #7
0
int SaveStateEmbed(char *file) {
	GPUFreeze_t *gpufP;
	int Size;
	unsigned char *pMem;

	EMUFILE_FILE ef(file, "ab");
	if (ef.fail()) return -1;
	EMUFILE *f = &ef;

	gzwrite(f, (void*)PSXjinHeader, 32);

	pMem = (unsigned char *) malloc(128*96*3);
	if (pMem == NULL) return -1;
	//GPU_getScreenPic(pMem);
	memset(pMem,0,128*96*3);

	int tag = 'ExPs';
	gzwrite(f, &tag, 4);
	Size = exceptionPatches.size();
	gzwrite(f, &Size, 4);
	for (int i = 0; i < Size; i++) {
		gzwrite(f, &exceptionPatches[i].first, 4);
		gzwrite(f, &exceptionPatches[i].second, 4);
	}

	gzwrite(f, pMem, 128*96*3-4-4-Size*4*2);
	free(pMem);

	gzwrite(f, psxM, 0x00200000);
	gzwrite(f, psxP, 0x00010000);
	gzwrite(f, psxR, 0x00080000);
	gzwrite(f, psxH, 0x00010000);
	gzwrite(f, (void*)&psxRegs, sizeof(psxRegs));

	if (Config.HLE)
		psxBiosFreeze(1);

	// gpu
	gpufP = (GPUFreeze_t *) malloc(sizeof(GPUFreeze_t));
	gpufP->ulFreezeVersion = 1;
	GPUfreeze(1, gpufP);
	void* temp = gpufP->extraData;
	gpufP->extraData = 0;
	gzwrite(f, gpufP, sizeof(GPUFreeze_t));
	gzwrite(f, temp, gpufP->extraDataSize);
	GPUfreeze(3, gpufP);
	free(gpufP);

	sioFreeze(f, 1);
	cdrFreeze(f, 1);
	psxHwFreeze(f, 1);
	CDRisoFreeze(f,1);
	psxRcntFreeze(f, 1);
	mdecFreeze(f, 1);
	//TODO - no movie state? are you sure?

	// spu
	EMUFILE_MEMORY memfile;
	SPUfreeze_new(&memfile);
	Size = memfile.size();
	gzwrite(f, &Size, 4);
	gzwrite(f, memfile.buf(),Size);

	return 0;
}
Beispiel #8
0
int LoadStateEmufile(EMUFILE *f) {
	GPUFreeze_t *gpufP;
	int Size;
	char header[32];

	printf("loadstate---\n");

	psxCpu->Reset();

	gzread(f, header, 32);
	if (strncmp("STv3 PSXjin", header, 9)) { return -1; }

	exceptionPatches.clear();
	int tag;
	gzread(f, &tag, 4);
	if (tag == 'ExPs') {
		gzread(f, &Size, 4);
		while (Size--) {
			u32 addr, val;
			gzread(f, &addr, 4);
			gzread(f, &val, 4);
			exceptionPatches.push_back(std::make_pair(addr, val));
		}
		gzseek(f, 128*96*3-4-4-exceptionPatches.size()*4*2, SEEK_CUR);
	}
	else
		gzseek(f, 128*96*3-4, SEEK_CUR);

	gzread(f, psxM, 0x00200000);
	gzread(f, psxP, 0x00010000);
	gzread(f, psxR, 0x00080000);
	gzread(f, psxH, 0x00010000);
	gzread(f, (void*)&psxRegs, sizeof(psxRegs));

	if (Config.HLE)
		psxBiosFreeze(0);

	// gpu
	gpufP = (GPUFreeze_t *) malloc (sizeof(GPUFreeze_t));
	gzread(f, gpufP, sizeof(GPUFreeze_t));
	gpufP->extraData = malloc(gpufP->extraDataSize);
	gzread(f, gpufP->extraData, gpufP->extraDataSize);
	GPUfreeze(0, gpufP);
	free(gpufP->extraData);
	free(gpufP);

	sioFreeze(f, 0);
	cdrFreeze(f, 0);
	psxHwFreeze(f, 0);
	CDRisoFreeze(f,0);
	psxRcntFreeze(f, 0);
	mdecFreeze(f, 0);
	PadFreeze(f, 0);
	MovieFreeze(f, 0);

	// spu
	gzread(f, &Size, 4);
	EMUFILE_MEMORY memfile;
	memfile.truncate(Size);
	gzread(f, memfile.buf(), Size);
	bool ok = SPUunfreeze_new(&memfile);
	if(!ok) return 1;

	return 0;
}
Beispiel #9
0
int SaveStateEmufile(EMUFILE *f) {
	GPUFreeze_t *gpufP;
	int Size;
	unsigned char *pMem;

	gzwrite(f, (void*)PSXjinHeader, 32);

	pMem = (unsigned char *) malloc(128*96*3);
	if (pMem == NULL) return -1;
	memset(pMem,0,128*96*3);

	// Ugh. We need to store this information, but in a backwards-compatible fashion. Do this
	// by (ab)using the gap previously occupied by GPU_getScreenPic. The data is tagged so it
	// can be detected on savestate load
	int tag = 'ExPs';
	gzwrite(f, &tag, 4);
	Size = exceptionPatches.size();
	gzwrite(f, &Size, 4);
	for (int i = 0; i < Size; i++) {
		gzwrite(f, &exceptionPatches[i].first, 4);
		gzwrite(f, &exceptionPatches[i].second, 4);
	}

	gzwrite(f, pMem, 128*96*3-4-4-Size*4*2);
	free(pMem);

	gzwrite(f, psxM, 0x00200000);
	gzwrite(f, psxP, 0x00010000);
	gzwrite(f, psxR, 0x00080000);
	gzwrite(f, psxH, 0x00010000);
	gzwrite(f, (void*)&psxRegs, sizeof(psxRegs));

	if (Config.HLE)
		psxBiosFreeze(1);

	// gpu
	gpufP = (GPUFreeze_t *) malloc(sizeof(GPUFreeze_t));
	gpufP->ulFreezeVersion = 1;
	GPUfreeze(1, gpufP);
	void* temp = gpufP->extraData;
	gpufP->extraData = 0;
	gzwrite(f, gpufP, sizeof(GPUFreeze_t));
	gzwrite(f, temp, gpufP->extraDataSize);
	GPUfreeze(3, gpufP);
	free(gpufP);

	sioFreeze(f, 1);
	cdrFreeze(f, 1);
	psxHwFreeze(f, 1);
	CDRisoFreeze(f,1);
	psxRcntFreeze(f, 1);
	mdecFreeze(f, 1);
	PadFreeze(f, 1);
	MovieFreeze(f, 1);

	EMUFILE_MEMORY memfile;
	SPUfreeze_new(&memfile);
	Size = memfile.size();
	gzwrite(f, &Size, 4);
	gzwrite(f, memfile.buf(),Size);

	return 0;
}