int vfsMemPutc(int caractere, VIRTUAL_FILE *f)		{
	unsigned char car = caractere;
	if (VirtualFileWrite(&car, sizeof(car), 1, f) < 1)
		return -1;
	else
		return caractere;
}
Ejemplo n.º 2
0
Archivo: SMS.c Proyecto: wally4000/code
int gb_save_sram(VIRTUAL_FILE *fd, byte *buf,int size)
{
	const int sram_tbl[]={1,1,1,4,16,8};
	int sram_size = 0x2000 * sram_tbl[size];

#ifdef CHEAT_SUPPORT
	cheat_decreate_cheat_map();
#endif
	VirtualFileWrite(buf, sram_size, 1, fd);
#ifdef CHEAT_SUPPORT
	cheat_create_cheat_map();
#endif

//	sram_crc = crc;
	return 1;
}
void vfsMemPuts(const char *s, VIRTUAL_FILE *f)		{
	VirtualFileWrite(s, strlen(s), 1, f);
}
Ejemplo n.º 4
0
Archivo: SMS.c Proyecto: wally4000/code
//force: 1 to always write, 0 to only if changed
int machine_manage_sram(int mode, int force)			{
    char name[MAX_PATH];
    VIRTUAL_FILE *fd;
	int ramsize = 0;

	if(menuConfig.file.filename[0] == '\0')
		return;

	pspGetStateName(name, STATE_SRAM);

    switch(mode)
    {
        case SRAM_SAVE:
			if (gblMachineType == EM_SMS)			{
				//Find out if something was written to the SRAM (which is zero initialized)
/*				int i, modified = 0;
				for (i=0;i<0x8000;i++)		{
					if (((u8*)cart.sram)[i] != 0)
						modified = 1;
				}
				if (!modified)
					break;*/

				//Determine if something has changed (using the CRC)
				uLong crc = crc32(0L, Z_NULL, 0);
				crc = crc32(crc, cart.sram, 0x8000);
				if (sram_crc == crc)
					break;

				sram_crc = crc;
			}
			else if (gblMachineType == EM_GBC)		{
				if (!(rom_get_loaded() && rom_has_battery()))
					break;

				//Determine if something has changed (using the CRC)
				const int sram_tbl[]={1,1,1,4,16,8};
				int sram_size = 0x2000 * sram_tbl[rom_get_info()->ram_size];

				if (rom_get_info()->cart_type>=0x0f && rom_get_info()->cart_type<=0x13)			{
					int tmp = renderer_get_timer_state();
					memcpy(get_sram() + sram_size, &tmp, sizeof(int));
					sram_size += sizeof(int);
				}

				uLong crc = crc32(0L, Z_NULL, 0);
				crc = crc32(crc, get_sram(), sram_size);

				if (sram_crc == crc)
					break;

				sram_crc = crc;
			}

			if (BatteryWarning("Your battery is low!\nDo you want to save the SRAM contents?\n(This might corrupt your Memory Stick if your PSP stops during this operation.)"))			{
				fd = VirtualFileOpen(name, 0, VF_GZFILE, VF_O_WRITE);
				if (fd)
				{
					if (gblMachineType == EM_SMS)
						VirtualFileWrite(cart.sram, 0x8000, 1, fd);
					else if (gblMachineType == EM_GBC)
						gb_save_sram(fd, get_sram(), rom_get_info()->ram_size);
					VirtualFileClose(fd);
				}
			}
            break;

        case SRAM_LOAD:
            fd = VirtualFileOpen(name, 0, VF_GZFILE, VF_O_READ);
			if (gblMachineType == EM_SMS)			{
				if(fd)			{
					sms.save = 1;
					VirtualFileRead(cart.sram, 0x8000, 1, fd);
					ramsize = 0x8000;
				}
				else
					/* No SRAM file, so initialize memory */
					memset(cart.sram, 0x00, 0x8000);

				sram_crc = crc32(0L, Z_NULL, 0);
				sram_crc = crc32(sram_crc, cart.sram, 0x8000);
			}
			else if (gblMachineType == EM_GBC)		{
				if (fd)
					ramsize = gb_load_sram(fd, sram_space, sizeof(sram_space));

				sram_crc = crc32(0L, Z_NULL, 0);
				sram_crc = crc32(sram_crc, sram_space, ramsize);
			}
			if (fd)
				VirtualFileClose(fd);
            break;
    }
	return ramsize;
}