⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snapshot.cpp

📁 著名SFC模拟器Snes9x的源代码。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    }    delete block;    return (result);}int UnfreezeBlock (STREAM stream, char *name, uint8 *block, int size){    char buffer [20];    int len = 0;    int rem = 0;        if (READ_STREAM (buffer, 11, stream) != 11 ||	strncmp (buffer, name, 3) != 0 || buffer [3] != ':' ||	(len = atoi (&buffer [4])) == 0)    {	return (WRONG_FORMAT);    }    if (len > size)    {	rem = len - size;	len = size;    }    if (READ_STREAM (block, len, stream) != len)	return (WRONG_FORMAT);    if (rem)    {	char *junk = new char [rem];	READ_STREAM (junk, rem, stream);	delete junk;    }	    return (SUCCESS);}bool8 S9xSPCDump (const char *filename){    static uint8 header [] = {	'S', 'N', 'E', 'S', '-', 'S', 'P', 'C', '7', '0', '0', ' ',	'S', 'o', 'u', 'n', 'd', ' ', 'F', 'i', 'l', 'e', ' ',	'D', 'a', 't', 'a', ' ', 'v', '0', '.', '3', '0', 26, 26, 26    };    static uint8 version = {	0x1e    };    FILE *fs;    S9xSetSoundMute (TRUE);    if (!(fs = fopen (filename, "wb")))	return (FALSE);    // The SPC file format:    // 0000: header:	'SNES-SPC700 Sound File Data v0.30',26,26,26    // 0036: version:	$1e    // 0037: SPC700 PC:    // 0039: SPC700 A:    // 0040: SPC700 X:    // 0041: SPC700 Y:    // 0042: SPC700 P:    // 0043: SPC700 S:    // 0044: Reserved: 0, 0, 0, 0    // 0048: Title of game: 32 bytes    // 0000: Song name: 32 bytes    // 0000: Name of dumper: 32 bytes    // 0000: Comments: 32 bytes    // 0000: Date of SPC dump: 4 bytes    // 0000: Fade out time in milliseconds: 4 bytes    // 0000: Fade out length in milliseconds: 2 bytes    // 0000: Default channel enables: 1 bytes    // 0000: Emulator used to dump .SPC files: 1 byte, 1 == ZSNES    // 0000: Reserved: 36 bytes    // 0256: SPC700 RAM: 64K    // ----: DSP Registers: 256 bytes    if (fwrite (header, sizeof (header), 1, fs) != 1 ||	fputc (version, fs) == EOF ||	fseek (fs, 37, SEEK_SET) == EOF ||	fputc (APURegisters.PC & 0xff, fs) == EOF ||	fputc (APURegisters.PC >> 8, fs) == EOF ||	fputc (APURegisters.YA.B.A, fs) == EOF ||	fputc (APURegisters.X, fs) == EOF ||	fputc (APURegisters.YA.B.Y, fs) == EOF ||	fputc (APURegisters.P, fs) == EOF ||	fputc (APURegisters.S, fs) == EOF ||	fseek (fs, 256, SEEK_SET) == EOF ||	fwrite (IAPU.RAM, 0x10000, 1, fs) != 1 ||	fwrite (APU.DSP, 1, 256, fs) != 1 ||	fwrite (APU.ExtraRAM, 64, 1, fs) != 1 ||	fclose (fs) < 0)    {	S9xSetSoundMute (FALSE);	return (FALSE);    }    S9xSetSoundMute (FALSE);    return (TRUE);}bool8 S9xUnfreezeZSNES (const char *filename){    FILE *fs;    uint8 t [4000];    if (!(fs = fopen (filename, "rb")))	return (FALSE);    if (fread (t, 64, 1, fs) == 1 &&	strncmp ((char *) t, "ZSNES Save State File V0.6", 26) == 0)    {	S9xReset ();	S9xSetSoundMute (TRUE);	// 28 Curr cycle	CPU.V_Counter = READ_WORD (&t [29]);	// 33 instrset	Settings.APUEnabled = t [36];	// 34 bcycpl cycles per scanline	// 35 cycphb cyclers per hblank	Registers.A.W   = READ_WORD (&t [41]);	Registers.DB    = t [43];	Registers.PB    = t [44];	Registers.S.W   = READ_WORD (&t [45]);	Registers.D.W   = READ_WORD (&t [47]);	Registers.X.W   = READ_WORD (&t [49]);	Registers.Y.W   = READ_WORD (&t [51]);	Registers.P.W   = READ_WORD (&t [53]);	Registers.PC    = READ_WORD (&t [55]);	fread (t, 1, 8, fs);	fread (t, 1, 3019, fs);	S9xSetCPU (t [2], 0x4200);	Memory.FillRAM [0x4210] = t [3];	PPU.IRQVBeamPos = READ_WORD (&t [4]);	PPU.IRQHBeamPos = READ_WORD (&t [2527]);	PPU.Brightness = t [6];	PPU.ForcedBlanking = t [8] >> 7;	int i;	for (i = 0; i < 544; i++)	    S9xSetPPU (t [0464 + i], 0x2104);	PPU.OBJNameBase = READ_WORD (&t [9]);	PPU.OBJNameSelect = READ_WORD (&t [13]) - PPU.OBJNameBase;	switch (t [18])	{	case 4:	    if (t [17] == 1)		PPU.OBJSizeSelect = 0;	    else		PPU.OBJSizeSelect = 6;	    break;	case 16:	    if (t [17] == 1)		PPU.OBJSizeSelect = 1;	    else		PPU.OBJSizeSelect = 3;	    break;	default:	case 64:	    if (t [17] == 1)		PPU.OBJSizeSelect = 2;	    else	    if (t [17] == 4)		PPU.OBJSizeSelect = 4;	    else		PPU.OBJSizeSelect = 5;	    break;	}	PPU.OAMAddr = READ_WORD (&t [25]);	PPU.SavedOAMAddr =  READ_WORD (&t [27]);	PPU.FirstSprite = t [29];	PPU.BGMode = t [30];	PPU.BG3Priority = t [31];	PPU.BG[0].BGSize = (t [32] >> 0) & 1;	PPU.BG[1].BGSize = (t [32] >> 1) & 1;	PPU.BG[2].BGSize = (t [32] >> 2) & 1;	PPU.BG[3].BGSize = (t [32] >> 3) & 1;	PPU.Mosaic = t [33] + 1;	PPU.BGMosaic [0] = (t [34] & 1) != 0;	PPU.BGMosaic [1] = (t [34] & 2) != 0;	PPU.BGMosaic [2] = (t [34] & 4) != 0;	PPU.BGMosaic [3] = (t [34] & 8) != 0;	PPU.BG [0].SCBase = READ_WORD (&t [35]) >> 1;	PPU.BG [1].SCBase = READ_WORD (&t [37]) >> 1;	PPU.BG [2].SCBase = READ_WORD (&t [39]) >> 1;	PPU.BG [3].SCBase = READ_WORD (&t [41]) >> 1;	PPU.BG [0].SCSize = t [67];	PPU.BG [1].SCSize = t [68];	PPU.BG [2].SCSize = t [69];	PPU.BG [3].SCSize = t [70];	PPU.BG[0].NameBase = READ_WORD (&t [71]) >> 1;	PPU.BG[1].NameBase = READ_WORD (&t [73]) >> 1;	PPU.BG[2].NameBase = READ_WORD (&t [75]) >> 1;	PPU.BG[3].NameBase = READ_WORD (&t [77]) >> 1;	PPU.BG[0].HOffset = READ_WORD (&t [79]);	PPU.BG[1].HOffset = READ_WORD (&t [81]);	PPU.BG[2].HOffset = READ_WORD (&t [83]);	PPU.BG[3].HOffset = READ_WORD (&t [85]);	PPU.BG[0].VOffset = READ_WORD (&t [89]);	PPU.BG[1].VOffset = READ_WORD (&t [91]);	PPU.BG[2].VOffset = READ_WORD (&t [93]);	PPU.BG[3].VOffset = READ_WORD (&t [95]);	PPU.VMA.Increment = READ_WORD (&t [97]) >> 1;	PPU.VMA.High = t [99];	IPPU.FirstVRAMRead = t [100];	S9xSetPPU (t [2512], 0x2115);	PPU.VMA.Address = READ_DWORD (&t [101]);	for (i = 0; i < 512; i++)	    S9xSetPPU (t [1488 + i], 0x2122);	PPU.CGADD = (uint8) READ_WORD (&t [105]);	Memory.FillRAM [0x212c] = t [108];	Memory.FillRAM [0x212d] = t [109];	PPU.ScreenHeight = READ_WORD (&t [111]);	Memory.FillRAM [0x2133] = t [2526];	Memory.FillRAM [0x4202] = t [113];	Memory.FillRAM [0x4204] = t [114];	Memory.FillRAM [0x4205] = t [115];	Memory.FillRAM [0x4214] = t [116];	Memory.FillRAM [0x4215] = t [117];	Memory.FillRAM [0x4216] = t [118];	Memory.FillRAM [0x4217] = t [119];	PPU.VBeamPosLatched = READ_WORD (&t [122]);	PPU.HBeamPosLatched = READ_WORD (&t [120]);	PPU.Window1Left = t [127];	PPU.Window1Right = t [128];	PPU.Window2Left = t [129];	PPU.Window2Right = t [130];	S9xSetPPU (t [131] | (t [132] << 4), 0x2123);	S9xSetPPU (t [133] | (t [134] << 4), 0x2124);	S9xSetPPU (t [135] | (t [136] << 4), 0x2125);	S9xSetPPU (t [137], 0x212a);	S9xSetPPU (t [138], 0x212b);	S9xSetPPU (t [139], 0x212e);	S9xSetPPU (t [140], 0x212f);	S9xSetPPU (t [141], 0x211a);	PPU.MatrixA = READ_WORD (&t [142]);	PPU.MatrixB = READ_WORD (&t [144]);	PPU.MatrixC = READ_WORD (&t [146]);	PPU.MatrixD = READ_WORD (&t [148]);	PPU.CentreX = READ_WORD (&t [150]);	PPU.CentreY = READ_WORD (&t [152]);	// JoyAPos t[154]	// JoyBPos t[155]	Memory.FillRAM [2134] = t [156]; // Matrix mult	Memory.FillRAM [2135] = t [157]; // Matrix mult	Memory.FillRAM [2136] = t [158]; // Matrix mult	PPU.WRAM = READ_DWORD (&t [161]);	for (i = 0; i < 128; i++)	    S9xSetCPU (t [165 + i], 0x4300 + i);	if (t [294])	    CPU.IRQActive |= PPU_V_BEAM_IRQ_SOURCE | PPU_H_BEAM_IRQ_SOURCE;	S9xSetCPU (t [296], 0x420c);	// hdmadata t[297] + 8 * 19	PPU.FixedColourRed = t [450];	PPU.FixedColourGreen = t [451];	PPU.FixedColourBlue = t [452];	S9xSetPPU (t [454], 0x2130);	S9xSetPPU (t [455], 0x2131);	// vraminctype ...	fread (Memory.RAM, 1, 128 * 1024, fs);	fread (Memory.VRAM, 1, 64 * 1024, fs);	if (Settings.APUEnabled)	{	    // SNES SPC700 RAM (64K)	    fread (IAPU.RAM, 1, 64 * 1024, fs);	    // Junk 16 bytes	    fread (t, 1, 16, fs);	    // SNES SPC700 state and internal ZSNES SPC700 emulation state	    fread (t, 1, 304, fs);	    APURegisters.PC   = READ_DWORD (&t [0]);	    APURegisters.YA.B.A = t [4];	    APURegisters.X    = t [8];	    APURegisters.YA.B.Y = t [12];	    APURegisters.P    = t [16];	    APURegisters.S    = t [24];	    	    APU.Cycles = READ_DWORD (&t [32]);	    APU.ShowROM = (IAPU.RAM [0xf1] & 0x80) != 0;	    APU.OutPorts [0] = t [36];	    APU.OutPorts [1] = t [37];	    APU.OutPorts [2] = t [38];	    APU.OutPorts [3] = t [39];	    APU.TimerEnabled [0] = (t [40] & 1) != 0;	    APU.TimerEnabled [1] = (t [40] & 2) != 0;	    APU.TimerEnabled [2] = (t [40] & 4) != 0;	    S9xSetAPUTimer (0xfa, t [41]);	    S9xSetAPUTimer (0xfb, t [42]);	    S9xSetAPUTimer (0xfc, t [43]);	    APU.Timer [0] = t [44];	    APU.Timer [1] = t [45];	    APU.Timer [2] = t [46];	    memmove (APU.ExtraRAM, &t [48], 64);	    // Internal ZSNES sound DSP state	    fread (t, 1, 1068, fs);	    // SNES sound DSP register values	    fread (t, 1, 256, fs);	    	    uint8 saved = IAPU.RAM [0xf2];	    for (i = 0; i < 128; i++)	    {		switch (i)		{		case APU_KON:		case APU_KOFF:		    break;		case APU_FLG:		    t [i] &= ~APU_SOFT_RESET;		default:		    IAPU.RAM [0xf2] = i;		    S9xSetAPUDSP (t [i]);		    break;		}	    }	    IAPU.RAM [0xf2] = APU_KON;	    S9xSetAPUDSP (t [APU_KON]);	    IAPU.RAM [0xf2] = saved;	    S9xSetSoundMute (FALSE);	    IAPU.PC = IAPU.RAM + APURegisters.PC;	    S9xAPUUnpackStatus ();	    if (APUCheckDirectPage ())		IAPU.DirectPage = IAPU.RAM + 0x100;	    else		IAPU.DirectPage = IAPU.RAM;	    Settings.APUEnabled = TRUE;	    IAPU.APUExecuting = TRUE;	}	else	{	    Settings.APUEnabled = FALSE;	    IAPU.APUExecuting = FALSE;	    S9xSetSoundMute (TRUE);	}	if (Settings.SuperFX)	{	    fread (::SRAM, 1, 64 * 1024, fs);	    fseek (fs, 64 * 1024, SEEK_CUR);	    fread (Memory.FillRAM + 0x7000, 1, 692, fs);	}	if (Settings.SA1)	{	    fread (t, 1, 2741, fs);	    S9xSetSA1 (t [4], 0x2200);  // Control	    S9xSetSA1 (t [12], 0x2203);	// ResetV low	    S9xSetSA1 (t [13], 0x2204); // ResetV hi	    S9xSetSA1 (t [14], 0x2205); // NMI low	    S9xSetSA1 (t [15], 0x2206); // NMI hi	    S9xSetSA1 (t [16], 0x2207); // IRQ low	    S9xSetSA1 (t [17], 0x2208); // IRQ hi	    S9xSetSA1 (((READ_DWORD (&t [28]) - (4096*1024-0x6000))) >> 13, 0x2224);	    S9xSetSA1 (t [36], 0x2201);	    S9xSetSA1 (t [41], 0x2209);	    SA1Registers.A.W = READ_DWORD (&t [592]);	    SA1Registers.X.W = READ_DWORD (&t [596]);	    SA1Registers.Y.W = READ_DWORD (&t [600]);	    SA1Registers.D.W = READ_DWORD (&t [604]);	    SA1Registers.DB  = t [608];	    SA1Registers.PB  = t [612];	    SA1Registers.S.W = READ_DWORD (&t [616]);	    SA1Registers.PC  = READ_DWORD (&t [636]);	    SA1Registers.P.W = t [620] | (t [624] << 8);	    memmove (&Memory.FillRAM [0x3000], t + 692, 2 * 1024);	    fread (::SRAM, 1, 64 * 1024, fs);	    fseek (fs, 64 * 1024, SEEK_CUR);	    S9xFixSA1AfterSnapshotLoad ();	}	fclose (fs);	Memory.FixROMSpeed ();	IPPU.ColorsChanged = TRUE;	IPPU.OBJChanged = TRUE;	CPU.InDMA = FALSE;	S9xFixColourBrightness ();	IPPU.RenderThisFrame = FALSE;	S9xFixSoundAfterSnapshotLoad ();	ICPU.ShiftedPB = Registers.PB << 16;	ICPU.ShiftedDB = Registers.DB << 16;	S9xSetPCBase (ICPU.ShiftedPB + Registers.PC);	S9xUnpackStatus ();	S9xFixCycles ();	S9xReschedule ();#ifdef ZSNES_FX	if (Settings.SuperFX)	    S9xSuperFXPostLoadState ();#endif	return (TRUE);    }    fclose (fs);    return (FALSE);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -