AxibugEmuOnline/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/State.cs

106 lines
2.6 KiB
C#
Raw Normal View History

2024-08-29 17:20:01 +08:00
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;
2024-09-13 17:39:48 +08:00
public List<uint> dskdata;
2024-08-29 17:20:01 +08:00
public BLOCKHDR exctrBLOCK;
public EXCTRSTAT exctr;
2024-08-29 17:30:56 +08:00
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);
2024-09-13 17:39:48 +08:00
foreach (var data in dskdata)
{
buffer.Write(data);
}
}
if (exctrBLOCK.Valid)
{
exctrBLOCK.SaveState(buffer);
exctr.SaveState(buffer);
}
2024-08-29 17:30:56 +08:00
return buffer.Data.ToArray();
}
2024-08-29 17:20:01 +08:00
}
}