取消对核心的低版本C#修改,使用dll standard2.0版本

This commit is contained in:
sin365 2024-12-20 20:18:41 +08:00
parent af82cff70a
commit 7c1a2af6f0
10 changed files with 33 additions and 57 deletions

View File

@ -2,7 +2,7 @@
{ {
public struct BLOCKHDR : IStateBufferObject public struct BLOCKHDR : IStateBufferObject
{ {
public bool Valid => !string.IsNullOrEmpty(ID); public readonly bool Valid => !string.IsNullOrEmpty(ID);
/// <summary> 总是8个字节 </summary> /// <summary> 总是8个字节 </summary>
public string ID; public string ID;
public ushort Reserved; public ushort Reserved;
@ -11,12 +11,12 @@
public uint GetSize() public readonly uint GetSize()
{ {
return (uint)(8 + sizeof(ushort) + sizeof(ushort) + sizeof(uint)); return (uint)(8 + sizeof(ushort) + sizeof(ushort) + sizeof(uint));
} }
public void SaveState(StateBuffer buffer) public readonly void SaveState(StateBuffer buffer)
{ {
if (Valid) if (Valid)
{ {

View File

@ -8,12 +8,12 @@
public uint pad4bit; public uint pad4bit;
public byte strobe; public byte strobe;
public uint GetSize() public readonly uint GetSize()
{ {
return sizeof(uint) * 4 + sizeof(byte); return sizeof(uint) * 4 + sizeof(byte);
} }
public void SaveState(StateBuffer buffer) public readonly void SaveState(StateBuffer buffer)
{ {
buffer.Write(pad1bit); buffer.Write(pad1bit);
buffer.Write(pad2bit); buffer.Write(pad2bit);

View File

@ -4,12 +4,12 @@
{ {
public uint data; public uint data;
public uint GetSize() public readonly uint GetSize()
{ {
return sizeof(uint); return sizeof(uint);
} }
public void SaveState(StateBuffer buffer) public readonly void SaveState(StateBuffer buffer)
{ {
buffer.Write(data); buffer.Write(data);
} }

View File

@ -14,12 +14,12 @@
public uint GetSize() public readonly uint GetSize()
{ {
return (uint)(ID.Length + sizeof(ushort) + sizeof(uint) + sizeof(ushort) + sizeof(ushort)); return (uint)(ID.Length + sizeof(ushort) + sizeof(uint) + sizeof(ushort) + sizeof(ushort));
} }
public void SaveState(StateBuffer buffer) public readonly void SaveState(StateBuffer buffer)
{ {
buffer.Write(ID); buffer.Write(ID);
buffer.Write(BlockVersion); buffer.Write(BlockVersion);

View File

@ -9,12 +9,12 @@
return new MMCSTAT() { mmcdata = new byte[256] }; return new MMCSTAT() { mmcdata = new byte[256] };
} }
public uint GetSize() public readonly uint GetSize()
{ {
return 256; return 256;
} }
public void SaveState(StateBuffer buffer) public readonly void SaveState(StateBuffer buffer)
{ {
buffer.Write(mmcdata); buffer.Write(mmcdata);
} }

View File

@ -22,12 +22,12 @@ namespace VirtualNes.Core
return res; return res;
} }
public uint GetSize() public readonly uint GetSize()
{ {
return (uint)(RAM.Length + BGPAL.Length + SPPAL.Length + SPRAM.Length); return (uint)(RAM.Length + BGPAL.Length + SPPAL.Length + SPRAM.Length);
} }
public void SaveState(StateBuffer buffer) public readonly void SaveState(StateBuffer buffer)
{ {
buffer.Write(RAM); buffer.Write(RAM);
buffer.Write(BGPAL); buffer.Write(BGPAL);

View File

@ -7,12 +7,12 @@
public uint GetSize() public readonly uint GetSize()
{ {
return cpureg.GetSize() + ppureg.GetSize(); return cpureg.GetSize() + ppureg.GetSize();
} }
public void SaveState(StateBuffer buffer) public readonly void SaveState(StateBuffer buffer)
{ {
cpureg.SaveState(buffer); cpureg.SaveState(buffer);
ppureg.SaveState(buffer); ppureg.SaveState(buffer);
@ -45,12 +45,12 @@
public long emul_cycles; public long emul_cycles;
public long base_cycles; public long base_cycles;
public uint GetSize() public readonly uint GetSize()
{ {
return 32; return 32;
} }
public void SaveState(StateBuffer buffer) public readonly void SaveState(StateBuffer buffer)
{ {
buffer.Write(PC); buffer.Write(PC);
buffer.Write(A); buffer.Write(A);
@ -102,12 +102,12 @@
public ushort loopy_v; public ushort loopy_v;
public ushort loopy_x; public ushort loopy_x;
public uint GetSize() public readonly uint GetSize()
{ {
return 12; return 12;
} }
public void SaveState(StateBuffer buffer) public readonly void SaveState(StateBuffer buffer)
{ {
buffer.Write(reg0); buffer.Write(reg0);
buffer.Write(reg1); buffer.Write(reg1);

View File

@ -9,12 +9,12 @@
return new SNDSTAT() { snddata = new byte[0x800] }; return new SNDSTAT() { snddata = new byte[0x800] };
} }
public uint GetSize() public readonly uint GetSize()
{ {
return (uint)snddata.Length; return (uint)snddata.Length;
} }
public void SaveState(StateBuffer buffer) public readonly void SaveState(StateBuffer buffer)
{ {
buffer.Write(snddata); buffer.Write(snddata);
} }

View File

@ -36,7 +36,7 @@ namespace VirtualNes.Core
public BLOCKHDR exctrBLOCK; public BLOCKHDR exctrBLOCK;
public EXCTRSTAT exctr; public EXCTRSTAT exctr;
public byte[] ToBytes() public readonly byte[] ToBytes()
{ {
StateBuffer buffer = new StateBuffer(); StateBuffer buffer = new StateBuffer();

View File

@ -22,18 +22,14 @@ namespace VirtualNes.Core
public bool HasButton(int player, EnumButtonType button) public bool HasButton(int player, EnumButtonType button)
{ {
uint raw; uint raw = player switch
switch (player)
{ {
case 0: raw = raw0; break; 0 => raw0,
case 1: raw = raw1; break; 1 => raw1,
case 2: raw = raw2; break; 2 => raw2,
case 3: raw = raw3; break; 3 => raw3,
default: _ => 0
raw = 0; };
break;
}
return (raw & (uint)button) == (uint)button; return (raw & (uint)button) == (uint)button;
} }
@ -55,27 +51,7 @@ namespace VirtualNes.Core
public override int GetHashCode() public override int GetHashCode()
{ {
//return HashCode.Combine(raw0, raw1, raw2, raw3, valid); return HashCode.Combine(raw0, raw1, raw2, raw3, valid);
return ComputeHashCode(raw0, raw1, raw2, raw3, valid);
}
public static int ComputeHashCode(uint raw0, uint raw1, uint raw2, uint raw3, bool valid)
{
unchecked // 允许溢出,使得哈希码计算更加合理
{
int hash = 17; // 选择一个非零的初始值
// 将每个 uint 类型的值转换为 int 并合并到哈希码中
hash = hash * 31 + (int)raw0;
hash = hash * 31 + (int)raw1;
hash = hash * 31 + (int)raw2;
hash = hash * 31 + (int)raw3;
// 将 bool 类型的值转换为 int 并合并到哈希码中
hash = hash * 31 + (valid ? 1 : 0);
return hash;
}
} }
public static bool operator ==(ControllerState left, ControllerState right) public static bool operator ==(ControllerState left, ControllerState right)