AxibugEmuOnline/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/State.cs
2024-09-13 17:39:48 +08:00

106 lines
2.6 KiB
C#

using System.Collections.Generic;
namespace VirtualNes.Core
{
public struct State
{
public FILEHDR2 HEADER;
public BLOCKHDR regBLOCK;
public REGSTAT reg;
public BLOCKHDR ramBLOCK;
public RAMSTAT ram;
/// <summary> Maybe null cause by rom IsSaveRAM() </summary>
public byte[] WRAM;
public BLOCKHDR mmuBLOCK;
public MMUSTAT mmu;
public List<byte> CPU_MEM_BANK;
public byte[] VRAM;
public List<byte> CRAM;
public BLOCKHDR mmcBLOCK;
public MMCSTAT mmc;
public BLOCKHDR ctrBLOCK;
public CTRSTAT ctr;
public BLOCKHDR sndBLOCK;
public SNDSTAT snd;
public BLOCKHDR dskBLOCK;
public DISKDATA dsk;
public List<uint> dskdata;
public BLOCKHDR exctrBLOCK;
public EXCTRSTAT exctr;
public readonly byte[] ToBytes()
{
StateBuffer buffer = new StateBuffer();
HEADER.SaveState(buffer);
if (regBLOCK.Valid)
{
regBLOCK.SaveState(buffer);
reg.SaveState(buffer);
}
if (regBLOCK.Valid)
{
ramBLOCK.SaveState(buffer);
ram.SaveState(buffer);
}
if (WRAM != null) buffer.Write(WRAM);
if (mmuBLOCK.Valid)
{
mmuBLOCK.SaveState(buffer);
mmu.SaveState(buffer);
buffer.Write(CPU_MEM_BANK.ToArray());
buffer.Write(VRAM);
buffer.Write(CRAM.ToArray());
}
if (mmcBLOCK.Valid)
{
mmcBLOCK.SaveState(buffer);
mmc.SaveState(buffer);
}
if (ctrBLOCK.Valid)
{
ctrBLOCK.SaveState(buffer);
ctr.SaveState(buffer);
}
if (sndBLOCK.Valid)
{
sndBLOCK.SaveState(buffer);
snd.SaveState(buffer);
}
if (dskBLOCK.Valid)
{
dskBLOCK.SaveState(buffer);
dsk.SaveState(buffer);
foreach (var data in dskdata)
{
buffer.Write(data);
}
}
if (exctrBLOCK.Valid)
{
exctrBLOCK.SaveState(buffer);
exctr.SaveState(buffer);
}
return buffer.Data.ToArray();
}
}
}