From 3bda78d3e5392de82ea313b7a62b0b7bbc264c72 Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Mon, 17 Feb 2025 17:48:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E4=B8=80=E6=AD=A5=E6=8E=A5=E5=85=A5Es?= =?UTF-8?q?sgss.Unity=EF=BC=8C=E9=94=AE=E5=80=BC=E5=92=8C=E5=8D=B3?= =?UTF-8?q?=E6=97=B6=E5=AD=98=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plugins/Essgee.Unity/Configuration.cs | 3 - .../Plugins/Essgee.Unity/Emulation.meta | 2 +- .../Plugins/Essgee.Unity/Emulation/Audio.meta | 2 +- .../Essgee.Unity/Emulation/Audio/CGBAudio.cs | 4 +- .../Essgee.Unity/Emulation/Audio/DMGAudio.cs | 20 +- .../Essgee.Unity/Emulation/Audio/IAudio.cs | 2 +- .../Essgee.Unity/Emulation/Audio/SN76489.cs | 41 +- .../Emulation/Audio/SegaSMSPSG.cs | 15 + .../Plugins/Essgee.Unity/Emulation/CPU.meta | 2 +- .../Essgee.Unity/Emulation/CPU/ICPU.cs | 2 +- .../Emulation/CPU/SM83.Register.cs | 4 + .../Essgee.Unity/Emulation/CPU/SM83.cs | 45 ++ .../Emulation/CPU/Z80A.Register.cs | 4 + .../Essgee.Unity/Emulation/CPU/Z80A.cs | 75 ++ .../Essgee.Unity/Emulation/Cartridges.meta | 2 +- .../Emulation/Cartridges/Coleco.meta | 2 +- .../Cartridges/Coleco/ColecoCartridge.cs | 12 + .../Emulation/Cartridges/ICartridge.cs | 2 +- .../Emulation/Cartridges/Nintendo.meta | 2 +- .../Cartridges/Nintendo/GBCameraCartridge.cs | 14 + .../Cartridges/Nintendo/IGameBoyCartridge.cs | 2 +- .../Cartridges/Nintendo/MBC1Cartridge.cs | 12 + .../Cartridges/Nintendo/MBC2Cartridge.cs | 12 + .../Cartridges/Nintendo/MBC3Cartridge.cs | 15 + .../Cartridges/Nintendo/MBC5Cartridge.cs | 12 + .../Cartridges/Nintendo/NoMapperCartridge.cs | 12 + .../Cartridges/Nintendo/SpecializedLoader.cs | 2 +- .../Emulation/Cartridges/Sega.meta | 2 +- .../Cartridges/Sega/CodemastersCartridge.cs | 35 +- .../Sega/KoreanMSX8kMapperCartridge.cs | 26 +- .../Cartridges/Sega/KoreanMapperCartridge.cs | 22 + .../Sega/KoreanSpriteMapperCartridge.cs | 32 +- .../Sega/Multicart4PakAllActionCartridge.cs | 25 +- .../Cartridges/Sega/SegaMapperCartridge.cs | 26 +- .../Cartridges/Sega/SegaSGCartridge.cs | 25 +- .../Essgee.Unity/Emulation/Configuration.meta | 2 +- .../Emulation/Configuration/ColecoVision.cs | 2 - .../Emulation/Configuration/GameBoy.cs | 1 - .../Emulation/Configuration/GameBoyColor.cs | 1 - .../Emulation/Configuration/GameGear.cs | 2 - .../Emulation/Configuration/MasterSystem.cs | 2 - .../Emulation/Configuration/SC3000.cs | 5 +- .../Emulation/Configuration/SG1000.cs | 5 +- .../Essgee.Unity/Emulation/EmulatorHandler.cs | 244 +++--- .../Essgee.Unity/Emulation/ExtDevices.meta | 2 +- .../Emulation/ExtDevices/Nintendo.meta | 2 +- .../Essgee.Unity/Emulation/Machines.meta | 2 +- .../Emulation/Machines/ColecoVision.cs | 95 ++- .../Emulation/Machines/GameBoy.cs | 22 +- .../Emulation/Machines/GameBoyColor.cs | 20 +- .../Emulation/Machines/GameGear.cs | 146 ++-- .../Emulation/Machines/IMachine.cs | 9 +- .../Emulation/Machines/MasterSystem.cs | 136 +++- .../Essgee.Unity/Emulation/Machines/SC3000.cs | 87 +- .../Essgee.Unity/Emulation/Machines/SG1000.cs | 71 +- .../Essgee.Unity/Emulation/Peripherals.meta | 2 +- .../Emulation/Peripherals/IPeripheral.cs | 2 +- .../Emulation/Peripherals/Intel8255.cs | 35 + .../Emulation/SaveStateHandler.cs | 252 +++--- .../Plugins/Essgee.Unity/Emulation/Video.meta | 2 +- .../Essgee.Unity/Emulation/Video/IVideo.cs | 2 +- .../Emulation/Video/Nintendo.meta | 2 +- .../Emulation/Video/Nintendo/CGBVideo.cs | 15 + .../Emulation/Video/Nintendo/DMGVideo.cs | 16 + .../Essgee.Unity/Emulation/Video/SegaGGVDP.cs | 1 - .../Emulation/Video/SegaSMSVDP.cs | 34 + .../Essgee.Unity/Emulation/Video/TMS99xxA.cs | 116 ++- .../Plugins/Essgee.Unity/EventArguments.meta | 2 +- .../EventArguments/EnqueueSamplesEventArgs.cs | 2 +- .../Plugins/Essgee.Unity/Exceptions.meta | 2 +- .../Plugins/Essgee.Unity/Extensions.meta | 2 +- .../Assets/Plugins/Essgee.Unity/IAxiStatus.cs | 222 +++++ .../Plugins/Essgee.Unity/IAxiStatus.cs.meta | 2 + .../Assets/Plugins/Essgee.Unity/Metadata.meta | 2 +- .../Metadata/GameMetadataHandler.cs | 4 +- .../Plugins/Essgee.Unity/Utilities.meta | 2 +- .../Essgee.Unity/Utilities/XInput.meta | 2 +- .../Emulator/EssgeeEmulator/UEssgee.cs | 131 ++- .../UEssgeeInterface/KeyCodeCore.cs | 418 ---------- .../UEssgeeInterface/KeyCodeCore.cs.meta | 2 - .../UEssgeeInterface/UEGKeyboard.cs | 763 ++++++++++++++++-- .../EssgeeEmulator/UEssgeeInterface/UEGLog.cs | 8 +- .../UEssgeeInterface/UEGVideoPlayer.cs | 2 + .../AppMain/Emulator/MameEmulator/UMAME.cs | 1 - .../MameEmulator/UniInterface/UniKeyboard.cs | 3 - 85 files changed, 2449 insertions(+), 971 deletions(-) create mode 100644 AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/IAxiStatus.cs create mode 100644 AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/IAxiStatus.cs.meta delete mode 100644 AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/KeyCodeCore.cs delete mode 100644 AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/KeyCodeCore.cs.meta diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Configuration.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Configuration.cs index 959f804d..342ce17d 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Configuration.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Configuration.cs @@ -1,7 +1,4 @@ using Essgee.Emulation.Configuration; -using Essgee.Utilities; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; using System.Collections.Generic; using System.Drawing; diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation.meta index ca594039..309068c2 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 267425c59f2efba48a44a3b55a5eb01d +guid: 289897a5723c6484ca800ed09fb528f5 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio.meta index c3f058b2..73a47ea2 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ab3f0235ad62cb046ac1518f29d21e81 +guid: 957a410fe17ff6242ab46d90146f525d folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/CGBAudio.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/CGBAudio.cs index 4d9144d5..cfd2495b 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/CGBAudio.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/CGBAudio.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace Essgee.Emulation.Audio +namespace Essgee.Emulation.Audio { public partial class CGBAudio : DMGAudio, IAudio { diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.cs index 228d6922..1974e9fa 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.cs @@ -2,8 +2,6 @@ using Essgee.Exceptions; using Essgee.Utilities; using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; namespace Essgee.Emulation.Audio @@ -130,6 +128,24 @@ namespace Essgee.Emulation.Audio channel4ForceEnable = true; } + + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + sampleCycleCount = BitConverter.ToInt32(data.MemberData[nameof(sampleCycleCount)]); + frameCycleCount = BitConverter.ToInt32(data.MemberData[nameof(frameCycleCount)]); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.MemberData[nameof(sampleCycleCount)] = BitConverter.GetBytes(sampleCycleCount); + data.MemberData[nameof(frameCycleCount)] = BitConverter.GetBytes(frameCycleCount); + return data; + } + #endregion + public object GetRuntimeOption(string name) { switch (name) diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/IAudio.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/IAudio.cs index c3415d3d..7bb06c8c 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/IAudio.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/IAudio.cs @@ -3,7 +3,7 @@ using System; namespace Essgee.Emulation.Audio { - interface IAudio + interface IAudio : IAxiStatus { event EventHandler EnqueueSamples; void OnEnqueueSamples(EnqueueSamplesEventArgs e); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/SN76489.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/SN76489.cs index 35967514..16b4ea96 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/SN76489.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/SN76489.cs @@ -2,7 +2,6 @@ using Essgee.Exceptions; using Essgee.Utilities; using System; -using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using static Essgee.Emulation.Utilities; @@ -157,6 +156,46 @@ namespace Essgee.Emulation.Audio channel4ForceEnable = true; } + #region AxiState + + public virtual void LoadAxiStatus(AxiEssgssStatusData data) + { + volumeRegisters = data.MemberData[nameof(volumeRegisters)].ToUShortArray(); + toneRegisters = data.MemberData[nameof(toneRegisters)].ToUShortArray(); + + channelCounters = data.MemberData[nameof(channelCounters)].ToUShortArray(); + channelOutput = data.MemberData[nameof(channelOutput)].ToBoolArray(); + + latchedChannel = data.MemberData[nameof(latchedChannel)].First(); + latchedType = data.MemberData[nameof(latchedType)].First(); + + noiseLfsr = BitConverter.ToUInt16(data.MemberData[nameof(noiseLfsr)]); + + sampleCycleCount = BitConverter.ToInt32(data.MemberData[nameof(sampleCycleCount)]); + frameCycleCount = BitConverter.ToInt32(data.MemberData[nameof(frameCycleCount)]); + dividerCount = BitConverter.ToInt32(data.MemberData[nameof(dividerCount)]); + } + + public virtual AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.MemberData[nameof(volumeRegisters)] = volumeRegisters.ToByteArray(); + data.MemberData[nameof(toneRegisters)] = toneRegisters.ToByteArray(); + + data.MemberData[nameof(channelCounters)] = channelCounters.ToByteArray(); + data.MemberData[nameof(channelOutput)] = channelOutput.ToByteArray(); + + data.MemberData[nameof(latchedChannel)] = BitConverter.GetBytes(latchedChannel); + data.MemberData[nameof(latchedType)] = BitConverter.GetBytes(latchedType); + + data.MemberData[nameof(noiseLfsr)] = BitConverter.GetBytes(noiseLfsr); + + data.MemberData[nameof(sampleCycleCount)] = BitConverter.GetBytes(sampleCycleCount); + data.MemberData[nameof(frameCycleCount)] = BitConverter.GetBytes(frameCycleCount); + data.MemberData[nameof(dividerCount)] = BitConverter.GetBytes(dividerCount); + return data; + } + #endregion public object GetRuntimeOption(string name) { switch (name) diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/SegaSMSPSG.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/SegaSMSPSG.cs index 8480b473..f624ddda 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/SegaSMSPSG.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/SegaSMSPSG.cs @@ -15,5 +15,20 @@ noiseLfsr = 0x8000; } + + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + base.LoadAxiStatus(data); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = base.SaveAxiStatus(); + return data; + } + #endregion + } } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU.meta index 09cd98cc..3717bf17 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 11616634c9d44b541b8505293e437778 +guid: ac5ab16607ba9574992b980c27ee0bba folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/ICPU.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/ICPU.cs index 2193de41..0964cc33 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/ICPU.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/ICPU.cs @@ -1,6 +1,6 @@ namespace Essgee.Emulation.CPU { - interface ICPU + interface ICPU : IAxiStatus { void Startup(); void Shutdown(); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/SM83.Register.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/SM83.Register.cs index 873c2d33..8a613c81 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/SM83.Register.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/SM83.Register.cs @@ -20,6 +20,10 @@ namespace Essgee.Emulation.CPU [FieldOffset(0)] public ushort Word; + + + [FieldOffset(0)] + public ushort axi_AllData; } } } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/SM83.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/SM83.cs index 5fb6e4b7..ac131721 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/SM83.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/SM83.cs @@ -74,6 +74,51 @@ namespace Essgee.Emulation.CPU } } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + af.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(af)]); + bc.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(bc)]); + de.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(de)]); + hl.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(hl)]); + + sp = BitConverter.ToUInt16(data.MemberData[nameof(sp)]); + pc = BitConverter.ToUInt16(data.MemberData[nameof(pc)]); + + ime = BitConverter.ToBoolean(data.MemberData[nameof(ime)]); + imeDelay = BitConverter.ToBoolean(data.MemberData[nameof(imeDelay)]); + halt = BitConverter.ToBoolean(data.MemberData[nameof(halt)]); + doHaltBug = BitConverter.ToBoolean(data.MemberData[nameof(doHaltBug)]); + + op = data.MemberData[nameof(op)].First(); + + currentCycles = BitConverter.ToInt32(data.MemberData[nameof(currentCycles)]); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + + data.MemberData[nameof(af)] = BitConverter.GetBytes(af.axi_AllData); + data.MemberData[nameof(bc)] = BitConverter.GetBytes(bc.axi_AllData); + data.MemberData[nameof(de)] = BitConverter.GetBytes(de.axi_AllData); + data.MemberData[nameof(hl)] = BitConverter.GetBytes(hl.axi_AllData); + + data.MemberData[nameof(sp)] = BitConverter.GetBytes(sp); + data.MemberData[nameof(pc)] = BitConverter.GetBytes(pc); + + data.MemberData[nameof(ime)] = BitConverter.GetBytes(ime); + data.MemberData[nameof(imeDelay)] = BitConverter.GetBytes(imeDelay); + data.MemberData[nameof(halt)] = BitConverter.GetBytes(halt); + data.MemberData[nameof(doHaltBug)] = BitConverter.GetBytes(doHaltBug); + + data.MemberData[nameof(op)] = BitConverter.GetBytes(op); + + data.MemberData[nameof(currentCycles)] = BitConverter.GetBytes(currentCycles); + return data; + } + #endregion public virtual void Startup() { Reset(); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/Z80A.Register.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/Z80A.Register.cs index 26af5c11..73232df2 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/Z80A.Register.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/Z80A.Register.cs @@ -20,6 +20,10 @@ namespace Essgee.Emulation.CPU [FieldOffset(0)] public ushort Word; + + + [FieldOffset(0)] + public ushort axi_AllData; } } } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/Z80A.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/Z80A.cs index c6066d04..aad65619 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/Z80A.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/CPU/Z80A.cs @@ -1,6 +1,7 @@ using Essgee.Exceptions; using Essgee.Utilities; using System; +using System.Linq; using static Essgee.Emulation.Utilities; namespace Essgee.Emulation.CPU @@ -71,6 +72,80 @@ namespace Essgee.Emulation.CPU portWriteDelegate = portWrite; } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + af.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(af)]); + bc.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(bc)]); + de.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(de)]); + hl.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(hl)]); + + af_.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(af_)]); + bc_.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(bc_)]); + de_.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(de_)]); + hl_.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(hl_)]); + + ix.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(ix)]); + iy.axi_AllData = BitConverter.ToUInt16(data.MemberData[nameof(iy)]); + + i = data.MemberData[nameof(i)].First(); + r = data.MemberData[nameof(r)].First(); + + sp = BitConverter.ToUInt16(data.MemberData[nameof(sp)]); + pc = BitConverter.ToUInt16(data.MemberData[nameof(pc)]); + + iff1 = BitConverter.ToBoolean(data.MemberData[nameof(iff1)]); + iff2 = BitConverter.ToBoolean(data.MemberData[nameof(iff2)]); + eiDelay = BitConverter.ToBoolean(data.MemberData[nameof(eiDelay)]); + halt = BitConverter.ToBoolean(data.MemberData[nameof(halt)]); + + im = data.MemberData[nameof(im)].First(); + op = data.MemberData[nameof(op)].First(); + + intState = data.MemberData[nameof(intState)].ToEnum(); + nmiState = data.MemberData[nameof(nmiState)].ToEnum(); + + currentCycles = BitConverter.ToInt32(data.MemberData[nameof(currentCycles)]); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + + data.MemberData[nameof(af)] = BitConverter.GetBytes(af.axi_AllData); + data.MemberData[nameof(bc)] = BitConverter.GetBytes(bc.axi_AllData); + data.MemberData[nameof(de)] = BitConverter.GetBytes(de.axi_AllData); + data.MemberData[nameof(hl)] = BitConverter.GetBytes(hl.axi_AllData); + + data.MemberData[nameof(af_)] = BitConverter.GetBytes(af_.axi_AllData); + data.MemberData[nameof(bc_)] = BitConverter.GetBytes(bc_.axi_AllData); + data.MemberData[nameof(de_)] = BitConverter.GetBytes(de_.axi_AllData); + data.MemberData[nameof(hl_)] = BitConverter.GetBytes(hl_.axi_AllData); + + data.MemberData[nameof(i)] = BitConverter.GetBytes(i); + data.MemberData[nameof(r)] = BitConverter.GetBytes(r); + + data.MemberData[nameof(ix)] = BitConverter.GetBytes(ix.axi_AllData); + data.MemberData[nameof(iy)] = BitConverter.GetBytes(iy.axi_AllData); + + data.MemberData[nameof(sp)] = BitConverter.GetBytes(sp); + data.MemberData[nameof(pc)] = BitConverter.GetBytes(pc); + + data.MemberData[nameof(iff1)] = BitConverter.GetBytes(iff1); + data.MemberData[nameof(iff2)] = BitConverter.GetBytes(iff2); + data.MemberData[nameof(eiDelay)] = BitConverter.GetBytes(eiDelay); + data.MemberData[nameof(halt)] = BitConverter.GetBytes(halt); + + data.MemberData[nameof(im)] = BitConverter.GetBytes(im); + + data.MemberData[nameof(op)] = BitConverter.GetBytes(op); + data.MemberData[nameof(intState)] = intState.ToByteArray(); + data.MemberData[nameof(nmiState)] = nmiState.ToByteArray(); + data.MemberData[nameof(currentCycles)] = BitConverter.GetBytes(currentCycles); + return data; + } + #endregion public virtual void Startup() { Reset(); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges.meta index 603fa142..6b93e802 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fd37849c4f2dfbb4fa2e82cdc6fc36e3 +guid: fc75a07f5083eef408264c31457c5131 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Coleco.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Coleco.meta index f6a383c7..173df534 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Coleco.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Coleco.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3f9cb94bc81a41e45a844926b14f89eb +guid: 1185c3d60bd11204ead23f542a5c6427 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Coleco/ColecoCartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Coleco/ColecoCartridge.cs index 5278bcfb..630520fc 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Coleco/ColecoCartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Coleco/ColecoCartridge.cs @@ -8,6 +8,18 @@ namespace Essgee.Emulation.Cartridges.Coleco byte[] romData; + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + return data; + } + #endregion public ColecoCartridge(int romSize, int ramSize) { romData = new byte[romSize]; diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/ICartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/ICartridge.cs index ef381702..3926b7d6 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/ICartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/ICartridge.cs @@ -1,6 +1,6 @@ namespace Essgee.Emulation.Cartridges { - public interface ICartridge + internal interface ICartridge : IAxiStatus { void LoadRom(byte[] data); void LoadRam(byte[] data); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo.meta index 196bc877..3ecdcd2c 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3eb99a6b5fa5ea348b79aa6dfc080f12 +guid: eea6a30841878a34286f04f99571c050 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/GBCameraCartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/GBCameraCartridge.cs index 62fe3967..2a8e8c7c 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/GBCameraCartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/GBCameraCartridge.cs @@ -65,6 +65,20 @@ namespace Essgee.Emulation.Cartridges.Nintendo hasBattery = false; } + + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + return data; + } + #endregion + public void LoadRom(byte[] data) { Buffer.BlockCopy(data, 0, romData, 0, Math.Min(data.Length, romData.Length)); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/IGameBoyCartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/IGameBoyCartridge.cs index 9f039c0b..68b2a0c9 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/IGameBoyCartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/IGameBoyCartridge.cs @@ -1,6 +1,6 @@ namespace Essgee.Emulation.Cartridges.Nintendo { - public interface IGameBoyCartridge : ICartridge + internal interface IGameBoyCartridge : ICartridge { void SetCartridgeConfig(bool battery, bool rtc, bool rumble); } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC1Cartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC1Cartridge.cs index 93afc77d..fef802d8 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC1Cartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC1Cartridge.cs @@ -27,6 +27,18 @@ namespace Essgee.Emulation.Cartridges.Nintendo hasBattery = false; } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + return data; + } + #endregion public void LoadRom(byte[] data) { Buffer.BlockCopy(data, 0, romData, 0, Math.Min(data.Length, romData.Length)); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC2Cartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC2Cartridge.cs index c84e692b..77b4111c 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC2Cartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC2Cartridge.cs @@ -21,6 +21,18 @@ namespace Essgee.Emulation.Cartridges.Nintendo hasBattery = false; } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + return data; + } + #endregion public void LoadRom(byte[] data) { diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC3Cartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC3Cartridge.cs index 60d7886d..9e91d228 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC3Cartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC3Cartridge.cs @@ -32,6 +32,8 @@ namespace Essgee.Emulation.Cartridges.Nintendo IsLatched = false; } + + public void FromSaveData(byte[] ramData) { var rtcOffset = ramData.Length - 0x30; @@ -129,6 +131,18 @@ namespace Essgee.Emulation.Cartridges.Nintendo rtc = new RTC(); } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + return data; + } + #endregion public void LoadRom(byte[] data) { Buffer.BlockCopy(data, 0, romData, 0, Math.Min(data.Length, romData.Length)); @@ -257,5 +271,6 @@ namespace Essgee.Emulation.Cartridges.Nintendo ramData[(ramBank << 13) | (address & 0x1FFF)] = value; } } + } } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC5Cartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC5Cartridge.cs index 63889c94..62ff26c7 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC5Cartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/MBC5Cartridge.cs @@ -30,6 +30,18 @@ namespace Essgee.Emulation.Cartridges.Nintendo hasRumble = false; } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + return data; + } + #endregion public void LoadRom(byte[] data) { Buffer.BlockCopy(data, 0, romData, 0, Math.Min(data.Length, romData.Length)); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/NoMapperCartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/NoMapperCartridge.cs index 68d1a792..fc795ca8 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/NoMapperCartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/NoMapperCartridge.cs @@ -13,6 +13,18 @@ namespace Essgee.Emulation.Cartridges.Nintendo ramData = new byte[ramSize]; } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + return data; + } + #endregion public void LoadRom(byte[] data) { Buffer.BlockCopy(data, 0, romData, 0, Math.Min(data.Length, romData.Length)); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/SpecializedLoader.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/SpecializedLoader.cs index c6028f2e..c11ffe24 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/SpecializedLoader.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Nintendo/SpecializedLoader.cs @@ -5,7 +5,7 @@ namespace Essgee.Emulation.Cartridges.Nintendo { public static class SpecializedLoader { - public static IGameBoyCartridge CreateCartridgeInstance(byte[] romData, byte[] ramData, Type mapperType) + internal static IGameBoyCartridge CreateCartridgeInstance(byte[] romData, byte[] ramData, Type mapperType) { var romSize = -1; switch (romData[0x0148]) diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega.meta index d73ad575..45cd0cd3 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ce378fe5a7c0ff14e8ffd0ad6c86ac65 +guid: 9dbf1dc8385034e4082468ce1f21dca0 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/CodemastersCartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/CodemastersCartridge.cs index d61c7fd0..83ed6bee 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/CodemastersCartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/CodemastersCartridge.cs @@ -1,6 +1,7 @@ using Essgee.Exceptions; using Essgee.Utilities; using System; +using System.Linq; namespace Essgee.Emulation.Cartridges.Sega { @@ -11,14 +12,39 @@ namespace Essgee.Emulation.Cartridges.Sega [StateRequired] byte[] ramData; - [StateRequired] - readonly byte[] pagingRegisters; - [StateRequired] - readonly byte bankMask; + [StateRequired]//TODO 感觉不用保存 保留readonly + byte[] pagingRegisters; + //readonly byte[] pagingRegisters; + [StateRequired]//TODO 感觉不用保存 保留readonly + byte bankMask; + //readonly byte bankMask; [StateRequired] bool isRamEnabled; + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + ramData = data.MemberData[nameof(ramData)]; + pagingRegisters = data.MemberData[nameof(pagingRegisters)]; + bankMask = data.MemberData[nameof(bankMask)].First(); + isRamEnabled = BitConverter.ToBoolean(data.MemberData[nameof(isRamEnabled)]); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + + data.MemberData[nameof(ramData)] = ramData; + data.MemberData[nameof(pagingRegisters)] = pagingRegisters; + data.MemberData[nameof(bankMask)] = BitConverter.GetBytes(bankMask); + data.MemberData[nameof(isRamEnabled)] = BitConverter.GetBytes(isRamEnabled); + + return data; + } + #endregion + public CodemastersCartridge(int romSize, int ramSize) { pagingRegisters = new byte[3]; @@ -116,5 +142,6 @@ namespace Essgee.Emulation.Cartridges.Sega if (isRamEnabled && ((address & 0xF000) == 0xA000 || (address & 0xF000) == 0xB000)) ramData[address & 0x1FFF] = value; } + } } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanMSX8kMapperCartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanMSX8kMapperCartridge.cs index 44477a32..78f5c8dc 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanMSX8kMapperCartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanMSX8kMapperCartridge.cs @@ -1,6 +1,7 @@ using Essgee.Exceptions; using Essgee.Utilities; using System; +using System.Linq; namespace Essgee.Emulation.Cartridges.Sega { @@ -8,8 +9,10 @@ namespace Essgee.Emulation.Cartridges.Sega { byte[] romData; - [StateRequired] - readonly byte[] pagingRegisters; + + [StateRequired]//TODO 感觉不用保存 保留readonly + byte[] pagingRegisters; + //readonly byte[] pagingRegisters; [StateRequired] byte bankMask; @@ -21,6 +24,25 @@ namespace Essgee.Emulation.Cartridges.Sega romData = new byte[romSize]; } + + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + pagingRegisters = data.MemberData[nameof(pagingRegisters)]; + bankMask = data.MemberData[nameof(bankMask)].First(); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + + data.MemberData[nameof(pagingRegisters)] = pagingRegisters; + data.MemberData[nameof(bankMask)] = BitConverter.GetBytes(bankMask); + + return data; + } + #endregion public void LoadRom(byte[] data) { Buffer.BlockCopy(data, 0, romData, 0, Math.Min(data.Length, romData.Length)); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanMapperCartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanMapperCartridge.cs index 37a5d00f..2cefca19 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanMapperCartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanMapperCartridge.cs @@ -1,6 +1,7 @@ using Essgee.Exceptions; using Essgee.Utilities; using System; +using System.Linq; namespace Essgee.Emulation.Cartridges.Sega { @@ -11,6 +12,27 @@ namespace Essgee.Emulation.Cartridges.Sega [StateRequired] byte bankMask, pagingRegister; + + + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + bankMask = data.MemberData[nameof(bankMask)].First(); + pagingRegister = data.MemberData[nameof(pagingRegister)].First(); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + + data.MemberData[nameof(bankMask)] = BitConverter.GetBytes(bankMask); + data.MemberData[nameof(pagingRegister)] = BitConverter.GetBytes(pagingRegister); + + return data; + } + #endregion + public KoreanMapperCartridge(int romSize, int ramSize) { pagingRegister = 0x02; diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanSpriteMapperCartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanSpriteMapperCartridge.cs index 299e19b1..01d09bad 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanSpriteMapperCartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/KoreanSpriteMapperCartridge.cs @@ -1,6 +1,7 @@ using Essgee.Exceptions; using Essgee.Utilities; using System; +using System.Linq; using static Essgee.Emulation.Utilities; namespace Essgee.Emulation.Cartridges.Sega @@ -17,8 +18,10 @@ namespace Essgee.Emulation.Cartridges.Sega [StateRequired] byte[] ramData; - [StateRequired] - readonly byte[] pagingRegisters; + + [StateRequired]//TODO 感觉不用保存 保留readonly + byte[] pagingRegisters; + //readonly byte[] pagingRegisters; [StateRequired] byte romBankMask; @@ -52,6 +55,31 @@ namespace Essgee.Emulation.Cartridges.Sega isBitReverseBank1 = isBitReverseBank2 = false; } + + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + ramData = data.MemberData[nameof(ramData)]; + pagingRegisters = data.MemberData[nameof(pagingRegisters)]; + romBankMask = data.MemberData[nameof(romBankMask)].First(); + hasCartRam = BitConverter.ToBoolean(data.MemberData[nameof(hasCartRam)]); + isBitReverseBank1 = BitConverter.ToBoolean(data.MemberData[nameof(isBitReverseBank1)]); + isBitReverseBank2 = BitConverter.ToBoolean(data.MemberData[nameof(isBitReverseBank2)]); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.MemberData[nameof(ramData)] = ramData; + data.MemberData[nameof(pagingRegisters)] = pagingRegisters; + data.MemberData[nameof(romBankMask)] = BitConverter.GetBytes(romBankMask); + data.MemberData[nameof(hasCartRam)] = BitConverter.GetBytes(hasCartRam); + data.MemberData[nameof(isBitReverseBank1)] = BitConverter.GetBytes(isBitReverseBank1); + data.MemberData[nameof(isBitReverseBank2)] = BitConverter.GetBytes(isBitReverseBank2); + return data; + } + #endregion public void LoadRom(byte[] data) { Buffer.BlockCopy(data, 0, romData, 0, Math.Min(data.Length, romData.Length)); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/Multicart4PakAllActionCartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/Multicart4PakAllActionCartridge.cs index 33935e00..696f8e0c 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/Multicart4PakAllActionCartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/Multicart4PakAllActionCartridge.cs @@ -10,8 +10,9 @@ namespace Essgee.Emulation.Cartridges.Sega { byte[] romData; - [StateRequired] - readonly int romMask; + [StateRequired]//TODO 感觉不用保存 保留readonly + int romMask; + //readonly int romMask; [StateRequired] int romBank0, romBank1, romBank2; @@ -27,6 +28,26 @@ namespace Essgee.Emulation.Cartridges.Sega romBank0 = romBank1 = romBank2 = 0; } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + romMask = BitConverter.ToInt32(data.MemberData[nameof(romMask)]); + romBank0 = BitConverter.ToInt32(data.MemberData[nameof(romBank0)]); + romBank1 = BitConverter.ToInt32(data.MemberData[nameof(romBank1)]); + romBank2 = BitConverter.ToInt32(data.MemberData[nameof(romBank2)]); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.MemberData[nameof(romMask)] = BitConverter.GetBytes(romMask); + data.MemberData[nameof(romBank0)] = BitConverter.GetBytes(romBank0); + data.MemberData[nameof(romBank1)] = BitConverter.GetBytes(romBank1); + data.MemberData[nameof(romBank2)] = BitConverter.GetBytes(romBank2); + return data; + } + #endregion public void LoadRom(byte[] data) { Buffer.BlockCopy(data, 0, romData, 0, Math.Min(data.Length, romData.Length)); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/SegaMapperCartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/SegaMapperCartridge.cs index 0d987e57..0b80d337 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/SegaMapperCartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/SegaMapperCartridge.cs @@ -1,6 +1,7 @@ using Essgee.Exceptions; using Essgee.Utilities; using System; +using System.Linq; using static Essgee.Emulation.Utilities; namespace Essgee.Emulation.Cartridges.Sega @@ -13,7 +14,7 @@ namespace Essgee.Emulation.Cartridges.Sega byte[] ramData; [StateRequired] - readonly byte[] pagingRegisters; + byte[] pagingRegisters; [StateRequired] byte romBankMask; @@ -27,6 +28,7 @@ namespace Essgee.Emulation.Cartridges.Sega int romBank1 { get { return pagingRegisters[2]; } } int romBank2 { get { return pagingRegisters[3]; } } + public SegaMapperCartridge(int romSize, int ramSize) { pagingRegisters = new byte[0x04]; @@ -44,6 +46,27 @@ namespace Essgee.Emulation.Cartridges.Sega hasCartRam = false; } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + ramData = data.MemberData[nameof(ramData)]; + pagingRegisters = data.MemberData[nameof(pagingRegisters)]; + romBankMask = data.MemberData[nameof(romBankMask)].First(); + hasCartRam = BitConverter.ToBoolean(data.MemberData[nameof(hasCartRam)]); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.MemberData[nameof(ramData)] = ramData; + data.MemberData[nameof(pagingRegisters)] = pagingRegisters; + data.MemberData[nameof(romBankMask)] = BitConverter.GetBytes(romBankMask); + data.MemberData[nameof(hasCartRam)] = BitConverter.GetBytes(hasCartRam); + return data; + } + #endregion + public void LoadRom(byte[] data) { Buffer.BlockCopy(data, 0, romData, 0, Math.Min(data.Length, romData.Length)); @@ -143,5 +166,6 @@ namespace Essgee.Emulation.Cartridges.Sega /* Otherwise ignore writes to ROM, as some games seem to be doing that? (ex. Gunstar Heroes GG to 0000) */ } + } } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/SegaSGCartridge.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/SegaSGCartridge.cs index 8849c9fb..7ae290d0 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/SegaSGCartridge.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Cartridges/Sega/SegaSGCartridge.cs @@ -1,5 +1,6 @@ using Essgee.Utilities; using System; +using System.Linq; namespace Essgee.Emulation.Cartridges.Sega { @@ -10,8 +11,9 @@ namespace Essgee.Emulation.Cartridges.Sega [StateRequired] byte[] ramData; - [StateRequired] - readonly int romMask, ramMask; + [StateRequired]//TODO 感觉不用保存 保留readonly + int romMask, ramMask; + //readonly int romMask, ramMask; public SegaSGCartridge(int romSize, int ramSize) { @@ -25,6 +27,25 @@ namespace Essgee.Emulation.Cartridges.Sega ramMask = (ramSize - 1); } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + ramData = data.MemberData[nameof(romMask)]; + romMask = data.MemberData[nameof(romMask)].First(); + ramMask = data.MemberData[nameof(ramMask)].First(); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.MemberData[nameof(ramData)] = ramData; + data.MemberData[nameof(romMask)] = BitConverter.GetBytes(romMask); + data.MemberData[nameof(ramMask)] = BitConverter.GetBytes(ramMask); + return data; + } + #endregion + public void LoadRom(byte[] data) { Buffer.BlockCopy(data, 0, romData, 0, Math.Min(data.Length, romData.Length)); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration.meta index 20d4d891..211444d9 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f8270d4162b9c6a42afbed3387a40a37 +guid: 9359d9b379638da42a314af0f095fe0c folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/ColecoVision.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/ColecoVision.cs index 761ae479..adf3eb48 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/ColecoVision.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/ColecoVision.cs @@ -1,6 +1,4 @@ using Essgee.Utilities; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; namespace Essgee.Emulation.Configuration { diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameBoy.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameBoy.cs index a0a66913..7f548ffd 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameBoy.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameBoy.cs @@ -2,7 +2,6 @@ using Essgee.Emulation.ExtDevices.Nintendo; using Essgee.Utilities; using Newtonsoft.Json; -using Newtonsoft.Json.Converters; using System; namespace Essgee.Emulation.Configuration diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameBoyColor.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameBoyColor.cs index 83e929f8..6c9ec403 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameBoyColor.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameBoyColor.cs @@ -2,7 +2,6 @@ using Essgee.Emulation.ExtDevices.Nintendo; using Essgee.Utilities; using Newtonsoft.Json; -using Newtonsoft.Json.Converters; using System; namespace Essgee.Emulation.Configuration diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameGear.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameGear.cs index 9297077f..3218d102 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameGear.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/GameGear.cs @@ -1,6 +1,4 @@ using Essgee.Utilities; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; namespace Essgee.Emulation.Configuration { diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/MasterSystem.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/MasterSystem.cs index b6fc5697..6ba97dcc 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/MasterSystem.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/MasterSystem.cs @@ -1,6 +1,4 @@ using Essgee.Utilities; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; namespace Essgee.Emulation.Configuration { diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/SC3000.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/SC3000.cs index 6c82e4ad..36a31ac1 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/SC3000.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/SC3000.cs @@ -1,7 +1,4 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; - -namespace Essgee.Emulation.Configuration +namespace Essgee.Emulation.Configuration { //todo Unity [ElementPriority(1)] public class SC3000 : IConfiguration diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/SG1000.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/SG1000.cs index 3a8eca49..112d8111 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/SG1000.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Configuration/SG1000.cs @@ -1,7 +1,4 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; - -namespace Essgee.Emulation.Configuration +namespace Essgee.Emulation.Configuration { //todo Unity [ElementPriority(0)] public class SG1000 : IConfiguration diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/EmulatorHandler.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/EmulatorHandler.cs index 33f0d192..2f061bc8 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/EmulatorHandler.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/EmulatorHandler.cs @@ -5,7 +5,6 @@ using Essgee.Metadata; using Essgee.Utilities; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Threading; @@ -204,7 +203,7 @@ namespace Essgee.Emulation } } - public Dictionary GetDebugInformation() + public Dictionary GetDebugInformation() { return emulator.GetDebugInformation(); } @@ -255,115 +254,148 @@ namespace Essgee.Emulation } - private void ThreadMainLoop() + //private void ThreadMainLoop() + //{ + // // TODO: rework fps limiter/counter - AGAIN - because the counter is inaccurate at sampleTimespan=0.25 and the limiter CAN cause sound crackling at sampleTimespan>0.25 + // // try this maybe? https://stackoverflow.com/a/34839411 + + // var stopWatch = Stopwatch.StartNew(); + + // TimeSpan accumulatedTime = TimeSpan.Zero, lastStartTime = TimeSpan.Zero, lastEndTime = TimeSpan.Zero; + + // var frameCounter = 0; + // var sampleTimespan = TimeSpan.FromSeconds(0.5); + + // try + // { + // while (true) + // { + // if (!emulationThreadRunning) + // break; + + // if (stateLoadRequested && stateNumber != -1) + // { + // var statePath = GetSaveStateFilename(stateNumber); + // if (File.Exists(statePath)) + // { + // using (var stream = new FileStream(statePath, FileMode.Open)) + // { + // emulator.SetState(SaveStateHandler.Load(stream, emulator.GetType().Name)); + // } + // } + + // stateLoadRequested = false; + // stateNumber = -1; + // } + + // var refreshRate = emulator.RefreshRate; + // var targetElapsedTime = TimeSpan.FromTicks((long)Math.Round(TimeSpan.TicksPerSecond / refreshRate)); + + // var startTime = stopWatch.Elapsed; + + // while (pauseStateChangesRequested.Count > 0) + // { + // var newPauseState = pauseStateChangesRequested.Dequeue(); + // emulationThreadPaused = newPauseState; + + // PauseChanged?.Invoke(this, EventArgs.Empty); + // } + + // if (!emulationThreadPaused) + // { + // if (limitFps) + // { + // var elapsedTime = (startTime - lastStartTime); + // lastStartTime = startTime; + + // if (elapsedTime < targetElapsedTime) + // { + // accumulatedTime += elapsedTime; + + // while (accumulatedTime >= targetElapsedTime) + // { + // emulator.RunFrame(); + // frameCounter++; + + // accumulatedTime -= targetElapsedTime; + // } + // } + // } + // else + // { + // emulator.RunFrame(); + // frameCounter++; + // } + + // if ((stopWatch.Elapsed - lastEndTime) >= sampleTimespan) + // { + // FramesPerSecond = (int)((frameCounter * 1000.0) / sampleTimespan.TotalMilliseconds); + // frameCounter = 0; + // lastEndTime = stopWatch.Elapsed; + // } + // } + // else + // { + // lastEndTime = stopWatch.Elapsed; + // } + + // if (configChangeRequested) + // { + // emulator.SetConfiguration(newConfiguration); + // configChangeRequested = false; + // } + + // if (stateSaveRequested && stateNumber != -1) + // { + // var statePath = GetSaveStateFilename(stateNumber); + // using (var stream = new FileStream(statePath, FileMode.OpenOrCreate)) + // { + // SaveStateHandler.Save(stream, emulator.GetType().Name, emulator.GetState()); + // } + + // stateSaveRequested = false; + // stateNumber = -1; + // } + // } + // } + // catch (Exception ex) when (!AppEnvironment.DebugMode) + // { + // ex.Data.Add("Thread", Thread.CurrentThread.Name); + // exceptionHandler(ex); + // } + //} + + public void SaveSnapShotToFile(int stateNumber) { - // TODO: rework fps limiter/counter - AGAIN - because the counter is inaccurate at sampleTimespan=0.25 and the limiter CAN cause sound crackling at sampleTimespan>0.25 - // try this maybe? https://stackoverflow.com/a/34839411 - - var stopWatch = Stopwatch.StartNew(); - - TimeSpan accumulatedTime = TimeSpan.Zero, lastStartTime = TimeSpan.Zero, lastEndTime = TimeSpan.Zero; - - var frameCounter = 0; - var sampleTimespan = TimeSpan.FromSeconds(0.5); - - try + var statePath = GetSaveStateFilename(stateNumber); + using (var stream = new FileStream(statePath, FileMode.OpenOrCreate)) { - while (true) + //SaveStateHandler.Save(stream, emulator.GetType().Name, emulator.GetState()); + SaveStateHandler.Save(stream, emulator.GetType().Name, emulator.SaveAxiStatus()); + } + } + + public void LoadSnapShotFromFile(int stateNumber) + { + var statePath = GetSaveStateFilename(stateNumber); + if (File.Exists(statePath)) + { + using (var stream = new FileStream(statePath, FileMode.Open)) { - if (!emulationThreadRunning) - break; - - if (stateLoadRequested && stateNumber != -1) - { - var statePath = GetSaveStateFilename(stateNumber); - if (File.Exists(statePath)) - { - using (var stream = new FileStream(statePath, FileMode.Open)) - { - emulator.SetState(SaveStateHandler.Load(stream, emulator.GetType().Name)); - } - } - - stateLoadRequested = false; - stateNumber = -1; - } - - var refreshRate = emulator.RefreshRate; - var targetElapsedTime = TimeSpan.FromTicks((long)Math.Round(TimeSpan.TicksPerSecond / refreshRate)); - - var startTime = stopWatch.Elapsed; - - while (pauseStateChangesRequested.Count > 0) - { - var newPauseState = pauseStateChangesRequested.Dequeue(); - emulationThreadPaused = newPauseState; - - PauseChanged?.Invoke(this, EventArgs.Empty); - } - - if (!emulationThreadPaused) - { - if (limitFps) - { - var elapsedTime = (startTime - lastStartTime); - lastStartTime = startTime; - - if (elapsedTime < targetElapsedTime) - { - accumulatedTime += elapsedTime; - - while (accumulatedTime >= targetElapsedTime) - { - emulator.RunFrame(); - frameCounter++; - - accumulatedTime -= targetElapsedTime; - } - } - } - else - { - emulator.RunFrame(); - frameCounter++; - } - - if ((stopWatch.Elapsed - lastEndTime) >= sampleTimespan) - { - FramesPerSecond = (int)((frameCounter * 1000.0) / sampleTimespan.TotalMilliseconds); - frameCounter = 0; - lastEndTime = stopWatch.Elapsed; - } - } - else - { - lastEndTime = stopWatch.Elapsed; - } - - if (configChangeRequested) - { - emulator.SetConfiguration(newConfiguration); - configChangeRequested = false; - } - - if (stateSaveRequested && stateNumber != -1) - { - var statePath = GetSaveStateFilename(stateNumber); - using (var stream = new FileStream(statePath, FileMode.OpenOrCreate)) - { - SaveStateHandler.Save(stream, emulator.GetType().Name, emulator.GetState()); - } - - stateSaveRequested = false; - stateNumber = -1; - } + //emulator.SetState(SaveStateHandler.Load(stream, emulator.GetType().Name)); + emulator.LoadAxiStatus(SaveStateHandler.LoadAxiStatus(stream, emulator.GetType().Name)); } } - catch (Exception ex) when (!AppEnvironment.DebugMode) - { - ex.Data.Add("Thread", Thread.CurrentThread.Name); - exceptionHandler(ex); - } + } + + public byte[] GetStateData() + { + return emulator.SaveAxiStatus().ToByteArray(); + } + + public void SetStateData(byte[] data) + { + emulator.LoadAxiStatus(data.ToAxiEssgssStatusData()); } } } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/ExtDevices.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/ExtDevices.meta index 8528b60f..58e1490b 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/ExtDevices.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/ExtDevices.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 380af0157665736438ef805bfda57a98 +guid: 32a6b746a89ac5242be599fa472bab1b folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/ExtDevices/Nintendo.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/ExtDevices/Nintendo.meta index a12b50b0..a256439c 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/ExtDevices/Nintendo.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/ExtDevices/Nintendo.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b00fddc211d9d854580cc2b110c5e524 +guid: a09bb4257e29ab646b70aba3720660e1 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines.meta index 5ba35678..70899f19 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5c3c1bb41ecdcb043ac9083b76f8dee4 +guid: e77364449233a0e4b8f13621ff8ee825 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/ColecoVision.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/ColecoVision.cs index 7df654ed..fab8dd15 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/ColecoVision.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/ColecoVision.cs @@ -219,44 +219,79 @@ namespace Essgee.Emulation.Machines } //public void SetState(Dictionary state) - public void SetState(Dictionary state) + //public void SetState(Dictionary state) + //{ + // SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); + // wram = (byte[])state[nameof(wram)]; + // SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); + // SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); + // SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); + + // portControls1 = (ushort)state[nameof(portControls1)]; + // portControls2 = (ushort)state[nameof(portControls2)]; + // controlsReadMode = (byte)state[nameof(controlsReadMode)]; + // isNmi = (bool)state[nameof(isNmi)]; + // isNmiPending = (bool)state[nameof(isNmiPending)]; + + // ReconfigureSystem(); + //} + + //public Dictionary GetState() + //{ + // return new Dictionary + // { + // [nameof(cartridge)] = SaveStateHandler.PerformGetState(cartridge), + // [nameof(wram)] = wram, + // [nameof(cpu)] = SaveStateHandler.PerformGetState(cpu), + // [nameof(vdp)] = SaveStateHandler.PerformGetState(vdp), + // [nameof(psg)] = SaveStateHandler.PerformGetState(psg), + + // [nameof(portControls1)] = portControls1, + // [nameof(portControls2)] = portControls2, + // [nameof(controlsReadMode)] = controlsReadMode, + // [nameof(isNmi)] = isNmi, + // [nameof(isNmiPending)] = isNmiPending + // }; + //} + + #region + public void LoadAxiStatus(AxiEssgssStatusData data) { - SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); - wram = (byte[])state[nameof(wram)]; - SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); - SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); - SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); + cartridge.LoadAxiStatus(data.ClassData[nameof(cartridge)]); + wram = data.MemberData[nameof(wram)]; + cpu.LoadAxiStatus(data.ClassData[nameof(cpu)]); + vdp.LoadAxiStatus(data.ClassData[nameof(vdp)]); + psg.LoadAxiStatus(data.ClassData[nameof(psg)]); - portControls1 = (ushort)state[nameof(portControls1)]; - portControls2 = (ushort)state[nameof(portControls2)]; - controlsReadMode = (byte)state[nameof(controlsReadMode)]; - isNmi = (bool)state[nameof(isNmi)]; - isNmiPending = (bool)state[nameof(isNmiPending)]; - - ReconfigureSystem(); + portControls1 = BitConverter.ToUInt16(data.MemberData[nameof(portControls1)]); + portControls2 = BitConverter.ToUInt16(data.MemberData[nameof(portControls2)]); + controlsReadMode = data.MemberData[nameof(controlsReadMode)].First(); + isNmi = BitConverter.ToBoolean(data.MemberData[nameof(isNmi)]); + isNmiPending = BitConverter.ToBoolean(data.MemberData[nameof(isNmiPending)]); } - public Dictionary GetState() + public AxiEssgssStatusData SaveAxiStatus() { - return new Dictionary - { - [nameof(cartridge)] = SaveStateHandler.PerformGetState(cartridge), - [nameof(wram)] = wram, - [nameof(cpu)] = SaveStateHandler.PerformGetState(cpu), - [nameof(vdp)] = SaveStateHandler.PerformGetState(vdp), - [nameof(psg)] = SaveStateHandler.PerformGetState(psg), + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.ClassData[nameof(cartridge)] = cartridge.SaveAxiStatus(); + data.MemberData[nameof(wram)] = wram; + data.ClassData[nameof(cpu)] = cpu.SaveAxiStatus(); + data.ClassData[nameof(vdp)] = vdp.SaveAxiStatus(); + data.ClassData[nameof(psg)] = psg.SaveAxiStatus(); + + data.MemberData[nameof(portControls1)] = BitConverter.GetBytes(portControls1); + data.MemberData[nameof(portControls2)] = BitConverter.GetBytes(portControls2); + data.MemberData[nameof(controlsReadMode)] = BitConverter.GetBytes(controlsReadMode); + data.MemberData[nameof(isNmi)] = BitConverter.GetBytes(isNmi); + data.MemberData[nameof(isNmiPending)] = BitConverter.GetBytes(isNmiPending); + + return data; - [nameof(portControls1)] = portControls1, - [nameof(portControls2)] = portControls2, - [nameof(controlsReadMode)] = controlsReadMode, - [nameof(isNmi)] = isNmi, - [nameof(isNmiPending)] = isNmiPending - }; } - - public Dictionary GetDebugInformation() + #endregion + public Dictionary GetDebugInformation() { - var dict = new Dictionary + var dict = new Dictionary { { "CyclesInFrame", currentMasterClockCyclesInFrame }, }; diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameBoy.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameBoy.cs index 723811a8..1ad5db52 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameBoy.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameBoy.cs @@ -131,6 +131,20 @@ namespace Essgee.Emulation.Machines public GameBoy() { } + + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + return data; + } + #endregion + public void Initialize() { bootstrap = null; @@ -306,19 +320,19 @@ namespace Essgee.Emulation.Machines audio?.Shutdown(); } - public void SetState(Dictionary state) + public void SetState(Dictionary state) { throw new NotImplementedException(); } - public Dictionary GetState() + public Dictionary GetState() { throw new NotImplementedException(); } - public Dictionary GetDebugInformation() + public Dictionary GetDebugInformation() { - var dict = new Dictionary + var dict = new Dictionary { { "CyclesInFrame", currentMasterClockCyclesInFrame }, }; diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameBoyColor.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameBoyColor.cs index 56c4f1cf..1d1488cc 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameBoyColor.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameBoyColor.cs @@ -162,6 +162,18 @@ namespace Essgee.Emulation.Machines public GameBoyColor() { } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + return data; + } + #endregion public void Initialize() { bootstrap = null; @@ -363,19 +375,19 @@ namespace Essgee.Emulation.Machines audio?.Shutdown(); } - public void SetState(Dictionary state) + public void SetState(Dictionary state) { throw new NotImplementedException(); } - public Dictionary GetState() + public Dictionary GetState() { throw new NotImplementedException(); } - public Dictionary GetDebugInformation() + public Dictionary GetDebugInformation() { - var dict = new Dictionary + var dict = new Dictionary { { "CyclesInFrame", currentMasterClockCyclesInFrame }, }; diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameGear.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameGear.cs index e396fca7..d218db46 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameGear.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/GameGear.cs @@ -241,64 +241,119 @@ namespace Essgee.Emulation.Machines } //public void SetState(Dictionary state) - public void SetState(Dictionary state) + //public void SetState(Dictionary state) + //{ + // configuration.Region = (Region)state[nameof(configuration.Region)]; + + // SaveStateHandler.PerformSetState(bootstrap, (Dictionary)state[nameof(bootstrap)]); + // SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); + // wram = (byte[])state[nameof(wram)]; + // SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); + // SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); + // SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); + + // portMemoryControl = (byte)state[nameof(portMemoryControl)]; + // portIoControl = (byte)state[nameof(portIoControl)]; + // hCounterLatched = (byte)state[nameof(hCounterLatched)]; + // portIoAB = (byte)state[nameof(portIoAB)]; + // portIoBMisc = (byte)state[nameof(portIoBMisc)]; + + // portIoC = (byte)state[nameof(portIoC)]; + // portParallelData = (byte)state[nameof(portParallelData)]; + // portDataDirNMI = (byte)state[nameof(portDataDirNMI)]; + // portTxBuffer = (byte)state[nameof(portTxBuffer)]; + // portRxBuffer = (byte)state[nameof(portRxBuffer)]; + // portSerialControl = (byte)state[nameof(portSerialControl)]; + + // ReconfigureSystem(); + //} + + //public Dictionary GetState() + //{ + // return new Dictionary + // { + // [nameof(configuration.Region)] = configuration.Region, + + // [nameof(bootstrap)] = SaveStateHandler.PerformGetState(bootstrap), + // [nameof(cartridge)] = SaveStateHandler.PerformGetState(cartridge), + // [nameof(wram)] = wram, + // [nameof(cpu)] = SaveStateHandler.PerformGetState(cpu), + // [nameof(vdp)] = SaveStateHandler.PerformGetState(vdp), + // [nameof(psg)] = SaveStateHandler.PerformGetState(psg), + + // [nameof(portMemoryControl)] = portMemoryControl, + // [nameof(portIoControl)] = portIoControl, + // [nameof(hCounterLatched)] = hCounterLatched, + // [nameof(portIoAB)] = portIoAB, + // [nameof(portIoBMisc)] = portIoBMisc, + + // [nameof(portIoC)] = portIoC, + // [nameof(portParallelData)] = portParallelData, + // [nameof(portDataDirNMI)] = portDataDirNMI, + // [nameof(portTxBuffer)] = portTxBuffer, + // [nameof(portRxBuffer)] = portRxBuffer, + // [nameof(portSerialControl)] = portSerialControl + // }; + //} + + + public void LoadAxiStatus(AxiEssgssStatusData data) { - configuration.Region = (Region)state[nameof(configuration.Region)]; + configuration.Region = data.MemberData[nameof(configuration.Region)].ToEnum(); - SaveStateHandler.PerformSetState(bootstrap, (Dictionary)state[nameof(bootstrap)]); - SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); - wram = (byte[])state[nameof(wram)]; - SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); - SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); - SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); + bootstrap.LoadAxiStatus(data.ClassData[nameof(bootstrap)]); + cartridge.LoadAxiStatus(data.ClassData[nameof(cartridge)]); + wram = data.MemberData[nameof(wram)]; + cpu.LoadAxiStatus(data.ClassData[nameof(cpu)]); + vdp.LoadAxiStatus(data.ClassData[nameof(vdp)]); + psg.LoadAxiStatus(data.ClassData[nameof(psg)]); - portMemoryControl = (byte)state[nameof(portMemoryControl)]; - portIoControl = (byte)state[nameof(portIoControl)]; - hCounterLatched = (byte)state[nameof(hCounterLatched)]; - portIoAB = (byte)state[nameof(portIoAB)]; - portIoBMisc = (byte)state[nameof(portIoBMisc)]; + portMemoryControl = data.MemberData[nameof(portMemoryControl)].First(); + portIoControl = data.MemberData[nameof(portIoControl)].First(); + hCounterLatched = data.MemberData[nameof(hCounterLatched)].First(); + portIoAB = data.MemberData[nameof(portIoAB)].First(); + portIoBMisc = data.MemberData[nameof(portIoBMisc)].First(); - portIoC = (byte)state[nameof(portIoC)]; - portParallelData = (byte)state[nameof(portParallelData)]; - portDataDirNMI = (byte)state[nameof(portDataDirNMI)]; - portTxBuffer = (byte)state[nameof(portTxBuffer)]; - portRxBuffer = (byte)state[nameof(portRxBuffer)]; - portSerialControl = (byte)state[nameof(portSerialControl)]; - - ReconfigureSystem(); + portIoC = data.MemberData[nameof(portIoC)].First(); + portParallelData = data.MemberData[nameof(portParallelData)].First(); + portDataDirNMI = data.MemberData[nameof(portDataDirNMI)].First(); + portTxBuffer = data.MemberData[nameof(portTxBuffer)].First(); + portRxBuffer = data.MemberData[nameof(portRxBuffer)].First(); + portSerialControl = data.MemberData[nameof(portSerialControl)].First(); } - public Dictionary GetState() + public AxiEssgssStatusData SaveAxiStatus() { - return new Dictionary - { - [nameof(configuration.Region)] = configuration.Region, + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.MemberData[nameof(configuration.Region)] = configuration.Region.ToByteArray(); - [nameof(bootstrap)] = SaveStateHandler.PerformGetState(bootstrap), - [nameof(cartridge)] = SaveStateHandler.PerformGetState(cartridge), - [nameof(wram)] = wram, - [nameof(cpu)] = SaveStateHandler.PerformGetState(cpu), - [nameof(vdp)] = SaveStateHandler.PerformGetState(vdp), - [nameof(psg)] = SaveStateHandler.PerformGetState(psg), + data.ClassData[nameof(bootstrap)] = bootstrap.SaveAxiStatus(); + data.ClassData[nameof(cartridge)] = cartridge.SaveAxiStatus(); + data.MemberData[nameof(wram)] = wram; + data.ClassData[nameof(cpu)] = cpu.SaveAxiStatus(); + data.ClassData[nameof(vdp)] = vdp.SaveAxiStatus(); + data.ClassData[nameof(psg)] = psg.SaveAxiStatus(); - [nameof(portMemoryControl)] = portMemoryControl, - [nameof(portIoControl)] = portIoControl, - [nameof(hCounterLatched)] = hCounterLatched, - [nameof(portIoAB)] = portIoAB, - [nameof(portIoBMisc)] = portIoBMisc, + data.MemberData[nameof(portMemoryControl)] = BitConverter.GetBytes(portMemoryControl); + data.MemberData[nameof(portIoControl)] = BitConverter.GetBytes(portIoControl); + data.MemberData[nameof(hCounterLatched)] = BitConverter.GetBytes(hCounterLatched); + data.MemberData[nameof(portIoAB)] = BitConverter.GetBytes(portIoAB); + data.MemberData[nameof(portIoBMisc)] = BitConverter.GetBytes(portIoBMisc); + + data.MemberData[nameof(portIoC)] = BitConverter.GetBytes(portIoC); + data.MemberData[nameof(portParallelData)] = BitConverter.GetBytes(portParallelData); + data.MemberData[nameof(portDataDirNMI)] = BitConverter.GetBytes(portDataDirNMI); + data.MemberData[nameof(portTxBuffer)] = BitConverter.GetBytes(portTxBuffer); + data.MemberData[nameof(portRxBuffer)] = BitConverter.GetBytes(portRxBuffer); + data.MemberData[nameof(portSerialControl)] = BitConverter.GetBytes(portSerialControl); + + return data; - [nameof(portIoC)] = portIoC, - [nameof(portParallelData)] = portParallelData, - [nameof(portDataDirNMI)] = portDataDirNMI, - [nameof(portTxBuffer)] = portTxBuffer, - [nameof(portRxBuffer)] = portRxBuffer, - [nameof(portSerialControl)] = portSerialControl - }; } - public Dictionary GetDebugInformation() + public Dictionary GetDebugInformation() { - var dict = new Dictionary + var dict = new Dictionary { { "CyclesInFrame", currentMasterClockCyclesInFrame }, }; @@ -509,5 +564,6 @@ namespace Essgee.Emulation.Machines break; } } + } } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/IMachine.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/IMachine.cs index 3740adbc..287915ce 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/IMachine.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/IMachine.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; namespace Essgee.Emulation.Machines { - public interface IMachine + public interface IMachine : IAxiStatus { event EventHandler SendLogMessage; event EventHandler EmulationReset; @@ -26,7 +26,7 @@ namespace Essgee.Emulation.Machines double PixelAspectRatio { get; } (string Name, string Description)[] RuntimeOptions { get; } - Dictionary GetDebugInformation(); + Dictionary GetDebugInformation(); void SetConfiguration(IConfiguration config); @@ -38,8 +38,9 @@ namespace Essgee.Emulation.Machines void Reset(); void Shutdown(); - void SetState(Dictionary state); - Dictionary GetState(); + //void SetState(Dictionary state); + //Dictionary GetState(); + void Load(byte[] romData, byte[] ramData, Type mapperType); byte[] GetCartridgeRam(); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/MasterSystem.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/MasterSystem.cs index 45699c2c..6b4725f7 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/MasterSystem.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/MasterSystem.cs @@ -268,54 +268,124 @@ namespace Essgee.Emulation.Machines } //public void SetState(Dictionary state) - public void SetState(Dictionary state) + //public void SetState(Dictionary state) + //{ + // configuration.TVStandard = (TVStandard)state[nameof(configuration.TVStandard)]; + // configuration.Region = (Region)state[nameof(configuration.Region)]; + + // SaveStateHandler.PerformSetState(bootstrap, (Dictionary)state[nameof(bootstrap)]); + // SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); + // wram = (byte[])state[nameof(wram)]; + // SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); + // SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); + // SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); + + // inputDevices = (InputDevice[])state[nameof(inputDevices)]; + // lightgunLatched = (bool)state[nameof(lightgunLatched)]; + + // portMemoryControl = (byte)state[nameof(portMemoryControl)]; + // portIoControl = (byte)state[nameof(portIoControl)]; + // hCounterLatched = (byte)state[nameof(hCounterLatched)]; + + // ReconfigureSystem(); + //} + + public void LoadAxiStatus(AxiEssgssStatusData data) { - configuration.TVStandard = (TVStandard)state[nameof(configuration.TVStandard)]; - configuration.Region = (Region)state[nameof(configuration.Region)]; + configuration.TVStandard = data.MemberData[nameof(configuration.TVStandard)].ToEnum(); + configuration.Region = data.MemberData[nameof(configuration.Region)].ToEnum(); - SaveStateHandler.PerformSetState(bootstrap, (Dictionary)state[nameof(bootstrap)]); - SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); - wram = (byte[])state[nameof(wram)]; - SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); - SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); - SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); + if (data.ClassData.ContainsKey(nameof(bootstrap))) + bootstrap.LoadAxiStatus(data.ClassData[nameof(bootstrap)]); + cartridge.LoadAxiStatus(data.ClassData[nameof(cartridge)]); + wram = data.MemberData[nameof(wram)]; + cpu.LoadAxiStatus(data.ClassData[nameof(cpu)]); + vdp.LoadAxiStatus(data.ClassData[nameof(vdp)]); + psg.LoadAxiStatus(data.ClassData[nameof(psg)]); - inputDevices = (InputDevice[])state[nameof(inputDevices)]; - lightgunLatched = (bool)state[nameof(lightgunLatched)]; + inputDevices = data.MemberData[nameof(inputDevices)].ToEnumArray(); + lightgunLatched = BitConverter.ToBoolean(data.MemberData[nameof(lightgunLatched)]); - portMemoryControl = (byte)state[nameof(portMemoryControl)]; - portIoControl = (byte)state[nameof(portIoControl)]; - hCounterLatched = (byte)state[nameof(hCounterLatched)]; + portMemoryControl = data.MemberData[nameof(portMemoryControl)].First(); + portIoControl = data.MemberData[nameof(portIoControl)].First(); + hCounterLatched = data.MemberData[nameof(hCounterLatched)].First(); ReconfigureSystem(); } - public Dictionary GetState() + //public Dictionary GetState() + //{ + // return new Dictionary + // { + // [nameof(configuration.TVStandard)] = configuration.TVStandard, + // [nameof(configuration.Region)] = configuration.Region, + + // [nameof(bootstrap)] = SaveStateHandler.PerformGetState(bootstrap), + // [nameof(cartridge)] = SaveStateHandler.PerformGetState(cartridge), + // [nameof(wram)] = wram, + // [nameof(cpu)] = SaveStateHandler.PerformGetState(cpu), + // [nameof(vdp)] = SaveStateHandler.PerformGetState(vdp), + // [nameof(psg)] = SaveStateHandler.PerformGetState(psg), + + // [nameof(inputDevices)] = inputDevices, + // [nameof(lightgunLatched)] = lightgunLatched, + + // [nameof(portMemoryControl)] = portMemoryControl, + // [nameof(portIoControl)] = portIoControl, + // [nameof(hCounterLatched)] = hCounterLatched + // }; + //} + + public AxiEssgssStatusData SaveAxiStatus() { - return new Dictionary - { - [nameof(configuration.TVStandard)] = configuration.TVStandard, - [nameof(configuration.Region)] = configuration.Region, + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.MemberData[nameof(configuration.TVStandard)] = configuration.TVStandard.ToByteArray(); + data.MemberData[nameof(configuration.Region)] = configuration.Region.ToByteArray(); - [nameof(bootstrap)] = SaveStateHandler.PerformGetState(bootstrap), - [nameof(cartridge)] = SaveStateHandler.PerformGetState(cartridge), - [nameof(wram)] = wram, - [nameof(cpu)] = SaveStateHandler.PerformGetState(cpu), - [nameof(vdp)] = SaveStateHandler.PerformGetState(vdp), - [nameof(psg)] = SaveStateHandler.PerformGetState(psg), + if (bootstrap != null) + data.ClassData[nameof(bootstrap)] = bootstrap.SaveAxiStatus(); - [nameof(inputDevices)] = inputDevices, - [nameof(lightgunLatched)] = lightgunLatched, + data.ClassData[nameof(cartridge)] = cartridge.SaveAxiStatus(); + data.MemberData[nameof(wram)] = wram; + data.ClassData[nameof(cpu)] = cpu.SaveAxiStatus(); + data.ClassData[nameof(vdp)] = vdp.SaveAxiStatus(); + data.ClassData[nameof(psg)] = psg.SaveAxiStatus(); - [nameof(portMemoryControl)] = portMemoryControl, - [nameof(portIoControl)] = portIoControl, - [nameof(hCounterLatched)] = hCounterLatched - }; + data.MemberData[nameof(inputDevices)] = inputDevices.ToByteArray(); + data.MemberData[nameof(lightgunLatched)] = BitConverter.GetBytes(lightgunLatched); + + data.MemberData[nameof(portMemoryControl)] = BitConverter.GetBytes((int)portMemoryControl); + data.MemberData[nameof(portIoControl)] = BitConverter.GetBytes((int)portIoControl); + data.MemberData[nameof(hCounterLatched)] = BitConverter.GetBytes(hCounterLatched); + + + return data; + + + //return new Dictionary + //{ + // [nameof(configuration.TVStandard)] = configuration.TVStandard, + // [nameof(configuration.Region)] = configuration.Region, + + // [nameof(bootstrap)] = SaveStateHandler.PerformGetState(bootstrap), + // [nameof(cartridge)] = SaveStateHandler.PerformGetState(cartridge), + // [nameof(wram)] = wram, + // [nameof(cpu)] = SaveStateHandler.PerformGetState(cpu), + // [nameof(vdp)] = SaveStateHandler.PerformGetState(vdp), + // [nameof(psg)] = SaveStateHandler.PerformGetState(psg), + + // [nameof(inputDevices)] = inputDevices, + // [nameof(lightgunLatched)] = lightgunLatched, + + // [nameof(portMemoryControl)] = portMemoryControl, + // [nameof(portIoControl)] = portIoControl, + // [nameof(hCounterLatched)] = hCounterLatched + //}; } - public Dictionary GetDebugInformation() + public Dictionary GetDebugInformation() { - var dict = new Dictionary + var dict = new Dictionary { { "CyclesInFrame", currentMasterClockCyclesInFrame }, }; diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/SC3000.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/SC3000.cs index b9c6f70a..ceaf0801 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/SC3000.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/SC3000.cs @@ -245,40 +245,75 @@ namespace Essgee.Emulation.Machines psg?.Shutdown(); } - //public void SetState(Dictionary state) - public void SetState(Dictionary state) - { - configuration.TVStandard = (TVStandard)state[nameof(configuration.TVStandard)]; + ////public void SetState(Dictionary state) + //public void SetState(Dictionary state) + //{ + // configuration.TVStandard = (TVStandard)state[nameof(configuration.TVStandard)]; + + // SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); + // wram = (byte[])state[nameof(wram)]; + // SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); + // SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); + // SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); + // SaveStateHandler.PerformSetState(ppi, (Dictionary)state[nameof(ppi)]); + // keyboard = (bool[,])(state[nameof(keyboard)]); + // ReconfigureSystem(); + //} + + //public Dictionary GetState() + //{ + // return new Dictionary + // { + // [nameof(configuration.TVStandard)] = configuration.TVStandard, + + // [nameof(cartridge)] = SaveStateHandler.PerformGetState(cartridge), + // [nameof(wram)] = wram, + // [nameof(cpu)] = SaveStateHandler.PerformGetState(cpu), + // [nameof(vdp)] = SaveStateHandler.PerformGetState(vdp), + // [nameof(psg)] = SaveStateHandler.PerformGetState(psg), + // [nameof(ppi)] = SaveStateHandler.PerformGetState(ppi), + // [nameof(keyboard)] = keyboard + // }; + //} + + #region + public void LoadAxiStatus(AxiEssgssStatusData data) + { + configuration.TVStandard = data.MemberData[nameof(configuration.TVStandard)].ToEnum(); + + cartridge.LoadAxiStatus(data.ClassData[nameof(cartridge)]); + wram = data.MemberData[nameof(wram)]; + cpu.LoadAxiStatus(data.ClassData[nameof(cpu)]); + vdp.LoadAxiStatus(data.ClassData[nameof(vdp)]); + psg.LoadAxiStatus(data.ClassData[nameof(psg)]); + ppi.LoadAxiStatus(data.ClassData[nameof(ppi)]); + //TODO keyboard 怕是不用保存哦 + //keyboard.LoadAxiStatus(data.ClassData[nameof(ppi)]); - SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); - wram = (byte[])state[nameof(wram)]; - SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); - SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); - SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); - SaveStateHandler.PerformSetState(ppi, (Dictionary)state[nameof(ppi)]); - keyboard = (bool[,])(state[nameof(keyboard)]); - ReconfigureSystem(); } - public Dictionary GetState() + public AxiEssgssStatusData SaveAxiStatus() { - return new Dictionary - { - [nameof(configuration.TVStandard)] = configuration.TVStandard, + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.MemberData[nameof(configuration.TVStandard)] = configuration.TVStandard.ToByteArray(); + + data.ClassData[nameof(cartridge)] = cartridge.SaveAxiStatus(); + data.MemberData[nameof(wram)] = wram; + data.ClassData[nameof(cpu)] = cpu.SaveAxiStatus(); + data.ClassData[nameof(vdp)] = vdp.SaveAxiStatus(); + data.ClassData[nameof(psg)] = psg.SaveAxiStatus(); + data.ClassData[nameof(ppi)] = ppi.SaveAxiStatus(); + //TODO keyboard 怕是不用保存哦 + //keyboard + + return data; - [nameof(cartridge)] = SaveStateHandler.PerformGetState(cartridge), - [nameof(wram)] = wram, - [nameof(cpu)] = SaveStateHandler.PerformGetState(cpu), - [nameof(vdp)] = SaveStateHandler.PerformGetState(vdp), - [nameof(psg)] = SaveStateHandler.PerformGetState(psg), - [nameof(ppi)] = SaveStateHandler.PerformGetState(ppi), - [nameof(keyboard)] = keyboard - }; } + #endregion - public Dictionary GetDebugInformation() + public Dictionary GetDebugInformation() { - var dict = new Dictionary + var dict = new Dictionary { { "CyclesInFrame", currentMasterClockCyclesInFrame }, }; diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/SG1000.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/SG1000.cs index bb581106..e8f94579 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/SG1000.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Machines/SG1000.cs @@ -221,37 +221,66 @@ namespace Essgee.Emulation.Machines psg?.Shutdown(); } - //public void SetState(Dictionary state) - public void SetState(Dictionary state) + ////public void SetState(Dictionary state) + //public void SetState(Dictionary state) + //{ + // configuration.TVStandard = (TVStandard)state[nameof(configuration.TVStandard)]; + + // SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); + // wram = (byte[])state[nameof(wram)]; + // SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); + // SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); + // SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); + + // ReconfigureSystem(); + //} + + //public Dictionary GetState() + //{ + // return new Dictionary + // { + // [nameof(configuration.TVStandard)] = configuration.TVStandard, + + // [nameof(cartridge)] = SaveStateHandler.PerformGetState(cartridge), + // [nameof(wram)] = wram, + // [nameof(cpu)] = SaveStateHandler.PerformGetState(cpu), + // [nameof(vdp)] = SaveStateHandler.PerformGetState(vdp), + // [nameof(psg)] = SaveStateHandler.PerformGetState(psg) + // }; + //} + + #region + public void LoadAxiStatus(AxiEssgssStatusData data) { - configuration.TVStandard = (TVStandard)state[nameof(configuration.TVStandard)]; + configuration.TVStandard = data.MemberData[nameof(configuration.TVStandard)].ToEnum(); - SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); - wram = (byte[])state[nameof(wram)]; - SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); - SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); - SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); + cartridge.LoadAxiStatus(data.ClassData[nameof(cartridge)]); + wram = data.MemberData[nameof(wram)]; + cpu.LoadAxiStatus(data.ClassData[nameof(cpu)]); + vdp.LoadAxiStatus(data.ClassData[nameof(vdp)]); + psg.LoadAxiStatus(data.ClassData[nameof(psg)]); - ReconfigureSystem(); } - public Dictionary GetState() + public AxiEssgssStatusData SaveAxiStatus() { - return new Dictionary - { - [nameof(configuration.TVStandard)] = configuration.TVStandard, + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.MemberData[nameof(configuration.TVStandard)] = configuration.TVStandard.ToByteArray(); + + data.ClassData[nameof(cartridge)] = cartridge.SaveAxiStatus(); + data.MemberData[nameof(wram)] = wram; + data.ClassData[nameof(cpu)] = cpu.SaveAxiStatus(); + data.ClassData[nameof(vdp)] = vdp.SaveAxiStatus(); + data.ClassData[nameof(psg)] = psg.SaveAxiStatus(); + + return data; - [nameof(cartridge)] = SaveStateHandler.PerformGetState(cartridge), - [nameof(wram)] = wram, - [nameof(cpu)] = SaveStateHandler.PerformGetState(cpu), - [nameof(vdp)] = SaveStateHandler.PerformGetState(vdp), - [nameof(psg)] = SaveStateHandler.PerformGetState(psg) - }; } + #endregion - public Dictionary GetDebugInformation() + public Dictionary GetDebugInformation() { - var dict = new Dictionary + var dict = new Dictionary { { "CyclesInFrame", currentMasterClockCyclesInFrame }, }; diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals.meta index 2ef6bf42..5d5f4a86 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 565e2e3b2a9ae8a4d843b313678a1165 +guid: 53ebe1049b81852448c0a7671f0d499f folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals/IPeripheral.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals/IPeripheral.cs index b4431e24..a653d71d 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals/IPeripheral.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals/IPeripheral.cs @@ -1,6 +1,6 @@ namespace Essgee.Emulation.Peripherals { - interface IPeripheral + interface IPeripheral : IAxiStatus { void Startup(); void Shutdown(); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals/Intel8255.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals/Intel8255.cs index b3d30ebe..1cfaa4de 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals/Intel8255.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Peripherals/Intel8255.cs @@ -1,5 +1,7 @@ using Essgee.Exceptions; using Essgee.Utilities; +using System; +using System.Linq; namespace Essgee.Emulation.Peripherals { @@ -32,6 +34,39 @@ namespace Essgee.Emulation.Peripherals public Intel8255() { } + + #region AxiState + + public virtual void LoadAxiStatus(AxiEssgssStatusData data) + { + PortAInput = data.MemberData[nameof(PortAInput)].First(); + PortBInput = data.MemberData[nameof(PortBInput)].First(); + PortCInput = data.MemberData[nameof(PortCInput)].First(); + PortAOutput = data.MemberData[nameof(PortAOutput)].First(); + PortBOutput = data.MemberData[nameof(PortBOutput)].First(); + PortCOutput = data.MemberData[nameof(PortCOutput)].First(); + configByte = data.MemberData[nameof(configByte)].First(); + setResetControlByte = data.MemberData[nameof(setResetControlByte)].First(); + } + + public virtual AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + PortAInput = data.MemberData[nameof(PortAInput)].First(); + PortBInput = data.MemberData[nameof(PortBInput)].First(); + PortCInput = data.MemberData[nameof(PortCInput)].First(); + data.MemberData[nameof(PortAInput)] = BitConverter.GetBytes(PortAInput); + data.MemberData[nameof(PortBInput)] = BitConverter.GetBytes(PortBInput); + data.MemberData[nameof(PortCInput)] = BitConverter.GetBytes(PortCInput); + data.MemberData[nameof(PortAOutput)] = BitConverter.GetBytes(PortAOutput); + data.MemberData[nameof(PortBOutput)] = BitConverter.GetBytes(PortBOutput); + data.MemberData[nameof(PortCOutput)] = BitConverter.GetBytes(PortCOutput); + data.MemberData[nameof(configByte)] = BitConverter.GetBytes(configByte); + data.MemberData[nameof(setResetControlByte)] = BitConverter.GetBytes(setResetControlByte); + return data; + } + #endregion + public void Startup() { // diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/SaveStateHandler.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/SaveStateHandler.cs index e45ea458..2fc94d0d 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/SaveStateHandler.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/SaveStateHandler.cs @@ -1,149 +1,159 @@ -using Essgee.Exceptions; -using Essgee.Utilities; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.Serialization.Formatters.Binary; -using System.Text; +using System.IO; namespace Essgee.Emulation { public static class SaveStateHandler { - public static string ExpectedVersion = $"ESGST{new Version(EmuStandInfo.ProductVersion).Major:D3}"; + //public static string ExpectedVersion = $"ESGST{new Version(EmuStandInfo.ProductVersion).Major:D3}"; - public static Dictionary Load(Stream stream, string machineName) + //public static Dictionary Load(Stream stream, string machineName) + //{ + // stream.Position = 0; + + // using (var reader = new BinaryReader(stream)) + // { + // /* Read and check version string */ + // var version = Encoding.ASCII.GetString(reader.ReadBytes(ExpectedVersion.Length)); + // if (version != ExpectedVersion) throw new EmulationException("Unsupported savestate version"); + + // /* Read and check filesize */ + // var filesize = reader.ReadUInt32(); + // if (filesize != reader.BaseStream.Length) throw new EmulationException("Savestate filesize mismatch"); + + // /* Read CRC32 */ + // var crc32 = reader.ReadUInt32(); + + // /* Read and check machine ID */ + // var machineId = Encoding.ASCII.GetString(reader.ReadBytes(16)); + // if (machineId != GenerateMachineIdString(machineName)) throw new EmulationException("Savestate machine mismatch"); + + // /* Check CRC32 */ + // using (var stateStream = new MemoryStream()) + // { + // reader.BaseStream.CopyTo(stateStream); + // stateStream.Position = 0; + // var expectedCrc32 = Crc32.Calculate(stateStream); + // if (crc32 != expectedCrc32) throw new EmulationException("Savestate checksum error"); + + // /* Read state data */ + // var binaryFormatter = new BinaryFormatter(); + // return (binaryFormatter.Deserialize(stateStream) as Dictionary); + // } + // } + //} + + public static AxiEssgssStatusData LoadAxiStatus(Stream stream, string machineName) { - stream.Position = 0; - using (var reader = new BinaryReader(stream)) { - /* Read and check version string */ - var version = Encoding.ASCII.GetString(reader.ReadBytes(ExpectedVersion.Length)); - if (version != ExpectedVersion) throw new EmulationException("Unsupported savestate version"); - - /* Read and check filesize */ - var filesize = reader.ReadUInt32(); - if (filesize != reader.BaseStream.Length) throw new EmulationException("Savestate filesize mismatch"); - - /* Read CRC32 */ - var crc32 = reader.ReadUInt32(); - - /* Read and check machine ID */ - var machineId = Encoding.ASCII.GetString(reader.ReadBytes(16)); - if (machineId != GenerateMachineIdString(machineName)) throw new EmulationException("Savestate machine mismatch"); - /* Check CRC32 */ using (var stateStream = new MemoryStream()) { reader.BaseStream.CopyTo(stateStream); - stateStream.Position = 0; - var expectedCrc32 = Crc32.Calculate(stateStream); - if (crc32 != expectedCrc32) throw new EmulationException("Savestate checksum error"); - - /* Read state data */ - var binaryFormatter = new BinaryFormatter(); - return (binaryFormatter.Deserialize(stateStream) as Dictionary); + return stateStream.ToArray().ToAxiEssgssStatusData(); } } } - public static void Save(Stream stream, string machineName, Dictionary state) + //public static void Save(Stream stream, string machineName, Dictionary state) + //{ + // using (var writer = new BinaryWriter(new MemoryStream())) + // { + // /* Write version string */ + // writer.Write(Encoding.ASCII.GetBytes(ExpectedVersion)); + + // /* Write filesize placeholder */ + // var filesizePosition = writer.BaseStream.Position; + // writer.Write(uint.MaxValue); + + // /* Write CRC32 placeholder */ + // var crc32Position = writer.BaseStream.Position; + // writer.Write(uint.MaxValue); + + // /* Write machine ID */ + // writer.Write(Encoding.ASCII.GetBytes(GenerateMachineIdString(machineName))); + + // /* Current position is end of header, store for later */ + // var headerSize = writer.BaseStream.Position; + + // /* Write state data */ + // var binaryFormatter = new BinaryFormatter(); + // binaryFormatter.Serialize(writer.BaseStream, state); + + // /* Write filesize */ + // var lastOffset = writer.BaseStream.Position; + // writer.BaseStream.Position = filesizePosition; + // writer.Write((uint)writer.BaseStream.Length); + // writer.BaseStream.Position = lastOffset; + + // /* Calculate CRC32 for state data, then write CRC32 */ + // lastOffset = writer.BaseStream.Position; + + // writer.BaseStream.Position = 0; + // var crc32 = Crc32.Calculate(writer.BaseStream, (int)headerSize, (int)(writer.BaseStream.Length - headerSize)); + + // writer.BaseStream.Position = crc32Position; + // writer.Write(crc32); + // writer.BaseStream.Position = lastOffset; + + // /* Copy to file */ + // writer.BaseStream.Position = 0; + // writer.BaseStream.CopyTo(stream); + // } + //} + + public static void Save(Stream stream, string machineName, AxiEssgssStatusData state) { - using (var writer = new BinaryWriter(new MemoryStream())) - { - /* Write version string */ - writer.Write(Encoding.ASCII.GetBytes(ExpectedVersion)); - - /* Write filesize placeholder */ - var filesizePosition = writer.BaseStream.Position; - writer.Write(uint.MaxValue); - - /* Write CRC32 placeholder */ - var crc32Position = writer.BaseStream.Position; - writer.Write(uint.MaxValue); - - /* Write machine ID */ - writer.Write(Encoding.ASCII.GetBytes(GenerateMachineIdString(machineName))); - - /* Current position is end of header, store for later */ - var headerSize = writer.BaseStream.Position; - - /* Write state data */ - var binaryFormatter = new BinaryFormatter(); - binaryFormatter.Serialize(writer.BaseStream, state); - - /* Write filesize */ - var lastOffset = writer.BaseStream.Position; - writer.BaseStream.Position = filesizePosition; - writer.Write((uint)writer.BaseStream.Length); - writer.BaseStream.Position = lastOffset; - - /* Calculate CRC32 for state data, then write CRC32 */ - lastOffset = writer.BaseStream.Position; - - writer.BaseStream.Position = 0; - var crc32 = Crc32.Calculate(writer.BaseStream, (int)headerSize, (int)(writer.BaseStream.Length - headerSize)); - - writer.BaseStream.Position = crc32Position; - writer.Write(crc32); - writer.BaseStream.Position = lastOffset; - - /* Copy to file */ - writer.BaseStream.Position = 0; - writer.BaseStream.CopyTo(stream); - } + byte[] data = state.ToByteArray(); + stream.Write(data, 0, data.Length); } + //private static string GenerateMachineIdString(string machineId) + //{ + // return machineId.Substring(0, Math.Min(machineId.Length, 16)).PadRight(16); + //} - private static string GenerateMachineIdString(string machineId) - { - return machineId.Substring(0, Math.Min(machineId.Length, 16)).PadRight(16); - } + ////public static void PerformSetState(object obj, Dictionary state) - //public static void PerformSetState(object obj, Dictionary state) + //public static void PerformSetState(object obj, Dictionary state) + //{ + // if (obj != null) + // { + // /* Restore property values from state */ + // foreach (var prop in obj.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Where(x => x.GetCustomAttributes(typeof(StateRequiredAttribute), false).Length != 0)) + // { + // prop.SetValue(obj, state[prop.Name]); + // } - public static void PerformSetState(object obj, Dictionary state) - { - if (obj != null) - { - /* Restore property values from state */ - foreach (var prop in obj.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Where(x => x.GetCustomAttributes(typeof(StateRequiredAttribute), false).Length != 0)) - { - prop.SetValue(obj, state[prop.Name]); - } + // /* Restore field values from state */ + // foreach (var field in obj.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Where(x => x.GetCustomAttributes(typeof(StateRequiredAttribute), false).Length != 0)) + // { + // field.SetValue(obj, state[field.Name]); + // } + // } + //} - /* Restore field values from state */ - foreach (var field in obj.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Where(x => x.GetCustomAttributes(typeof(StateRequiredAttribute), false).Length != 0)) - { - field.SetValue(obj, state[field.Name]); - } - } - } + ////public static Dictionary PerformGetState(object obj) + //public static Dictionary PerformGetState(object obj) + //{ + // //var state = new Dictionary(); + // var state = new Dictionary(); - //public static Dictionary PerformGetState(object obj) - public static Dictionary PerformGetState(object obj) - { - //var state = new Dictionary(); - var state = new Dictionary(); + // if (obj != null) + // { + // /* Copy property values to state */ + // foreach (var prop in obj.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Where(x => x.GetCustomAttributes(typeof(StateRequiredAttribute), false).Length != 0)) + // { + // state.Add(prop.Name, prop.GetValue(obj)); + // } - if (obj != null) - { - /* Copy property values to state */ - foreach (var prop in obj.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Where(x => x.GetCustomAttributes(typeof(StateRequiredAttribute), false).Length != 0)) - { - state.Add(prop.Name, prop.GetValue(obj)); - } + // /* Copy field values to state */ + // foreach (var field in obj.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Where(x => x.GetCustomAttributes(typeof(StateRequiredAttribute), false).Length != 0)) + // { + // state.Add(field.Name, field.GetValue(obj)); + // } + // } - /* Copy field values to state */ - foreach (var field in obj.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Where(x => x.GetCustomAttributes(typeof(StateRequiredAttribute), false).Length != 0)) - { - state.Add(field.Name, field.GetValue(obj)); - } - } - - return state; - } + // return state; + //} } } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video.meta index 47b777fb..eed81891 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a26b509fa7ea461489c1010e81e82d7f +guid: 38fa5b2e38bbb7b4695789da71a3506b folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/IVideo.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/IVideo.cs index 47305aa9..fcbadd4f 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/IVideo.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/IVideo.cs @@ -3,7 +3,7 @@ using System; namespace Essgee.Emulation.Video { - interface IVideo + interface IVideo : IAxiStatus { (int X, int Y, int Width, int Height) Viewport { get; } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo.meta index 0aa68f6b..192c4e4b 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3eda1878d76837140be1b0e89f93f37a +guid: 1ddba906f8855dd40bb9666a7106c3b9 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo/CGBVideo.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo/CGBVideo.cs index 4c9fc788..51fda27c 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo/CGBVideo.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo/CGBVideo.cs @@ -64,6 +64,20 @@ namespace Essgee.Emulation.Video.Nintendo objPaletteData = new byte[64]; } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + base.LoadAxiStatus(data); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = base.SaveAxiStatus(); + return data; + } + #endregion + public override void Reset() { base.Reset(); @@ -94,6 +108,7 @@ namespace Essgee.Emulation.Video.Nintendo hdmaBytesLeft = 0; } + // protected override void StepHBlank() diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo/DMGVideo.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo/DMGVideo.cs index a8f738c7..f75d4e47 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo/DMGVideo.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/Nintendo/DMGVideo.cs @@ -145,6 +145,22 @@ namespace Essgee.Emulation.Video.Nintendo layerSpritesForceEnable = true; } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + vram = data.Array2DMemberData[nameof(vram)].Get2DArrayBytesData(); + oam = data.MemberData[nameof(oam)]; + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.Array2DMemberData[nameof(vram)] = new AxiEssgssStatusData_2DArray(vram); + data.MemberData[nameof(oam)] = oam; + return data; + } + #endregion public object GetRuntimeOption(string name) { switch (name) diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/SegaGGVDP.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/SegaGGVDP.cs index bea49851..3986fabb 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/SegaGGVDP.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/SegaGGVDP.cs @@ -1,7 +1,6 @@ using Essgee.EventArguments; using Essgee.Utilities; using System; -using System.Runtime.InteropServices; using static Essgee.Emulation.Utilities; namespace Essgee.Emulation.Video diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/SegaSMSVDP.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/SegaSMSVDP.cs index 59af3b61..f856c146 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/SegaSMSVDP.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/SegaSMSVDP.cs @@ -2,6 +2,7 @@ using Essgee.Utilities; using System; using System.Diagnostics; +using System.Linq; using System.Runtime.InteropServices; using static Essgee.Emulation.Utilities; @@ -358,6 +359,39 @@ namespace Essgee.Emulation.Video for (int i = 0; i < spriteBuffer.Length; i++) spriteBuffer[i] = new (int Number, int Y, int X, int Pattern, int Attribute)[NumSpritesPerLineMode4]; } + #region AxiState + + public void LoadAxiStatus(AxiEssgssStatusData data) + { + base.LoadAxiStatus(data); + cram_set = data.MemberData[nameof(cram)]; + vCounter = BitConverter.ToInt32(data.MemberData[nameof(vCounter)]); + hCounter = BitConverter.ToInt32(data.MemberData[nameof(hCounter)]); + lineInterruptCounter = BitConverter.ToInt32(data.MemberData[nameof(lineInterruptCounter)]); + isLineInterruptPending = BitConverter.ToBoolean(data.MemberData[nameof(isLineInterruptPending)]); + horizontalScrollLatched = data.MemberData[nameof(horizontalScrollLatched)].First(); + verticalScrollLatched = data.MemberData[nameof(verticalScrollLatched)].First(); + } + + public AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = base.SaveAxiStatus(); + + data.MemberData[nameof(cram)] = cram_src; + data.MemberData[nameof(vCounter)] = BitConverter.GetBytes(vCounter); + data.MemberData[nameof(hCounter)] = BitConverter.GetBytes(hCounter); + + data.MemberData[nameof(lineInterruptCounter)] = BitConverter.GetBytes(lineInterruptCounter); + + data.MemberData[nameof(isLineInterruptPending)] = BitConverter.GetBytes(isLineInterruptPending); + + data.MemberData[nameof(horizontalScrollLatched)] = BitConverter.GetBytes(horizontalScrollLatched); + data.MemberData[nameof(verticalScrollLatched)] = BitConverter.GetBytes(verticalScrollLatched); + + return data; + } + #endregion + public override void Reset() { base.Reset(); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/TMS99xxA.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/TMS99xxA.cs index 372c4217..46edd5fc 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/TMS99xxA.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Video/TMS99xxA.cs @@ -2,6 +2,7 @@ using Essgee.Utilities; using System; using System.Diagnostics; +using System.Linq; using System.Runtime.InteropServices; using static Essgee.Emulation.Utilities; @@ -90,6 +91,82 @@ namespace Essgee.Emulation.Video [StateRequired] protected (int Number, int Y, int X, int Pattern, int Attribute)[][] spriteBuffer; + // 序列化方法 + public byte[] spriteBuffer_Serialize() + { + // 首先,我们需要计算序列化后的总字节数 + int totalBytes = 0; + foreach (var row in spriteBuffer) + { + if (row != null) + { + totalBytes += row.Length * 5 * sizeof(int); // 每个元组有5个int,每个int占4个字节 + } + } + + // 分配一个足够大的字节数组 + byte[] data = new byte[totalBytes]; + int offset = 0; + + // 填充字节数组 + foreach (var row in spriteBuffer) + { + if (row != null) + { + foreach (var tuple in row) + { + Buffer.BlockCopy(BitConverter.GetBytes(tuple.Number), 0, data, offset, sizeof(int)); + offset += sizeof(int); + Buffer.BlockCopy(BitConverter.GetBytes(tuple.Y), 0, data, offset, sizeof(int)); + offset += sizeof(int); + Buffer.BlockCopy(BitConverter.GetBytes(tuple.X), 0, data, offset, sizeof(int)); + offset += sizeof(int); + Buffer.BlockCopy(BitConverter.GetBytes(tuple.Pattern), 0, data, offset, sizeof(int)); + offset += sizeof(int); + Buffer.BlockCopy(BitConverter.GetBytes(tuple.Attribute), 0, data, offset, sizeof(int)); + offset += sizeof(int); + } + } + } + + return data; + } + + // 反序列化方法 + public void spriteBuffer_SetData(byte[] data) + { + // 假设我们已经知道spriteBuffer的维度(这通常需要在序列化时保存并在反序列化时读取) + // 为了简化,这里假设维度是已知的,并且与原始spriteBuffer相同 + int rowCount = spriteBuffer.Length; + int[] columnCounts = new int[rowCount]; + for (int i = 0; i < rowCount; i++) + { + if (spriteBuffer[i] != null) + { + columnCounts[i] = spriteBuffer[i].Length; + } + } + + int offset = 0; + spriteBuffer = new (int, int, int, int, int)[rowCount][]; + + for (int i = 0; i < rowCount; i++) + { + spriteBuffer[i] = new (int, int, int, int, int)[columnCounts[i]]; + for (int j = 0; j < columnCounts[i]; j++) + { + spriteBuffer[i][j] = ( + BitConverter.ToInt32(data, offset), + BitConverter.ToInt32(data, offset + sizeof(int)), + BitConverter.ToInt32(data, offset + 2 * sizeof(int)), + BitConverter.ToInt32(data, offset + 3 * sizeof(int)), + BitConverter.ToInt32(data, offset + 4 * sizeof(int)) + ); + offset += 5 * sizeof(int); + } + } + } + //protected ushort vramMask16k => 0x3FFF; //protected ushort vramMask4k => 0x0FFF; protected const ushort vramMask16k = 0x3FFF; @@ -103,7 +180,7 @@ namespace Essgee.Emulation.Video protected byte readBuffer; protected byte codeRegister => (byte)((controlWord >> 14) & 0x03); - + protected ushort addressRegister { get { return (ushort)(controlWord & 0x3FFF); } @@ -246,6 +323,43 @@ namespace Essgee.Emulation.Video layerBordersForceEnable = true; } + + #region AxiState + + public virtual void LoadAxiStatus(AxiEssgssStatusData data) + { + registers_set = data.MemberData[nameof(registers)]; + vram_set = data.MemberData[nameof(vram)]; + spriteBuffer_SetData(data.MemberData[nameof(spriteBuffer)]); + isSecondControlWrite = BitConverter.ToBoolean(data.MemberData[nameof(isSecondControlWrite)]); + controlWord = BitConverter.ToUInt16(data.MemberData[nameof(controlWord)]); + readBuffer = data.MemberData[nameof(readBuffer)].First(); + statusFlags = data.MemberData[nameof(statusFlags)].ToEnum(); + InterruptLine = data.MemberData[nameof(InterruptLine)].ToEnum(); + currentScanline = BitConverter.ToInt32(data.MemberData[nameof(currentScanline)]); + screenUsage = data.MemberData[nameof(screenUsage)]; + cycleCount = BitConverter.ToInt32(data.MemberData[nameof(cycleCount)]); + } + + public virtual AxiEssgssStatusData SaveAxiStatus() + { + AxiEssgssStatusData data = new AxiEssgssStatusData(); + data.MemberData[nameof(registers)] = registers_src; + data.MemberData[nameof(vram)] = vram_src; + data.MemberData[nameof(spriteBuffer)] = spriteBuffer_Serialize(); + data.MemberData[nameof(isSecondControlWrite)] = BitConverter.GetBytes(isSecondControlWrite); + data.MemberData[nameof(controlWord)] = BitConverter.GetBytes(controlWord); + data.MemberData[nameof(readBuffer)] = BitConverter.GetBytes(readBuffer); + data.MemberData[nameof(statusFlags)] = statusFlags.ToByteArray(); + data.MemberData[nameof(InterruptLine)] = InterruptLine.ToByteArray(); + data.MemberData[nameof(currentScanline)] = BitConverter.GetBytes(currentScanline); + data.MemberData[nameof(screenUsage)] = screenUsage; + data.MemberData[nameof(cycleCount)] = BitConverter.GetBytes(cycleCount); + return data; + } + + #endregion + public object GetRuntimeOption(string name) { switch (name) diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/EventArguments.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/EventArguments.meta index 773ed789..b85ebf73 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/EventArguments.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/EventArguments.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9ebca929cde32f948ae9c370636aa6d2 +guid: 281db18b9e0f1054e8b4abae8427ba41 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/EventArguments/EnqueueSamplesEventArgs.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/EventArguments/EnqueueSamplesEventArgs.cs index 5f4e1932..181c6631 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/EventArguments/EnqueueSamplesEventArgs.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/EventArguments/EnqueueSamplesEventArgs.cs @@ -20,7 +20,7 @@ namespace Essgee.EventArguments //} //public static EnqueueSamplesEventArgs Create(int numChannels, short[][] channelSamples, bool[] isMuted, short[] mixedSamples) - public static EnqueueSamplesEventArgs Create(int numChannels, short*[] channelSamples, bool[] isMuted, short* mixedSamples,int mixedSamplesLength) + public static EnqueueSamplesEventArgs Create(int numChannels, short*[] channelSamples, bool[] isMuted, short* mixedSamples, int mixedSamplesLength) { var eventArgs = ObjectPoolAuto.Acquire(); eventArgs.NumChannels = numChannels; diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Exceptions.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Exceptions.meta index 444088aa..afa813c1 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Exceptions.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Exceptions.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d1c46752ccd1bc9458481cc6745a9d00 +guid: f1e895bd77f41874fad666b2f480f482 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Extensions.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Extensions.meta index cb376e74..01847d1a 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Extensions.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Extensions.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2558194e2eb5320458689c46b71d51d5 +guid: 1be95ab09a576dd4db60392be7d5f9f0 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/IAxiStatus.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/IAxiStatus.cs new file mode 100644 index 00000000..64c9382c --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/IAxiStatus.cs @@ -0,0 +1,222 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.Serialization.Formatters.Binary; + +[Serializable] +public class AxiEssgssStatusData +{ + public Dictionary MemberData = new Dictionary(); + public Dictionary Array2DMemberData = new Dictionary(); + public Dictionary ClassData = new Dictionary(); +} + +[Serializable] +public class AxiEssgssStatusData_2DArray +{ + public int rows; + public int cols; + public byte[] array1D; + public AxiEssgssStatusData_2DArray(byte[,] data2D) + { + rows = data2D.GetLength(0); + cols = data2D.GetLength(1); + array1D = data2D.FlattenByteArray2D(); + } + + public byte[,] Get2DArrayBytesData() + { + return array1D.CreateByteArray2D(rows, cols); + } +} +public static class AxiEssgssStatusDataExtention +{ + public static byte[] ToByteArray(this AxiEssgssStatusData data) + { + using (MemoryStream ms = new MemoryStream()) + { + BinaryFormatter formatter = new BinaryFormatter(); + formatter.Serialize(ms, data); + return ms.ToArray(); + } + } + + public static AxiEssgssStatusData ToAxiEssgssStatusData(this byte[] byteArray) + { + using (MemoryStream ms = new MemoryStream(byteArray)) + { + BinaryFormatter formatter = new BinaryFormatter(); + return (AxiEssgssStatusData)formatter.Deserialize(ms); + } + } +} +public interface IAxiStatus +{ + public void LoadAxiStatus(AxiEssgssStatusData data); + public AxiEssgssStatusData SaveAxiStatus(); +} + +internal static class AxiStatus +{ + // öתΪbyte[] + public static byte[] ToByteArray(this TEnum[] enumArray) where TEnum : struct, Enum + { + if (!typeof(TEnum).IsEnum) throw new ArgumentException("TEnum must be an enumerated type"); + + // ȡöٵĻͣͨInt32 + Type enumUnderlyingType = Enum.GetUnderlyingType(typeof(TEnum)); + if (enumUnderlyingType != typeof(byte)) // ǷΪbyteǣҪжĴ + { + // ͲbyteҪδǼintתΪbyte飬 + // Ҫע⣬ܻᵼݶʧöֵbyteķΧ + // һȫķʹøͣint[]Ϊмʾ + // Ϊ˼ʾǽöֵ԰ȫתΪbyte + // 棺ܲ + + // ǼintöٻͣǿֱתÿöֵΪint + // ȻǷ԰ȫתΪbyteܣォ׳쳣 + return enumArray.Select(e => + { + int intValue = Convert.ToInt32(e); + if (intValue < byte.MinValue || intValue > byte.MaxValue) + throw new OverflowException($"Enum value {e} ({intValue}) is out of range for byte."); + return (byte)intValue; + }).ToArray(); + } + else + { + // Ѿbyteֱת + return Array.ConvertAll(enumArray, e => Convert.ToByte(e)); + } + } + + // byte[]תΪö + public static TEnum[] ToEnumArray(this byte[] byteArray) where TEnum : struct, Enum + { + if (!typeof(TEnum).IsEnum) throw new ArgumentException("TEnum must be an enumerated type"); + + // ֱתÿbyteΪöֵ + return Array.ConvertAll(byteArray, b => (TEnum)Enum.ToObject(typeof(TEnum), b)); + } + + // öתΪbyte[]ͨת̫Ϊֻһֽڣǻʵ + public static byte[] ToByteArray(this TEnum enumValue) where TEnum : struct, Enum + { + if (!typeof(TEnum).IsEnum) throw new ArgumentException("TEnum must be an enumerated type"); + + // ȡöٵĻ + Type enumUnderlyingType = Enum.GetUnderlyingType(typeof(TEnum)); + + // ǷΪbyteǣתǼ԰ȫתΪbyteͨöٵĻint + if (enumUnderlyingType == typeof(byte)) + { + // Ѿbyteֱӷذֽڵ + return new[] { Convert.ToByte(enumValue) }; + } + else if (enumUnderlyingType == typeof(int)) // öٻ + { + // öֵתΪintȻǷ԰ȫתΪbyte + int intValue = Convert.ToInt32(enumValue); + if (intValue < byte.MinValue || intValue > byte.MaxValue) + throw new OverflowException($"Enum value {enumValue} ({intValue}) is out of range for byte."); + + // ذתֽڵ + return new[] { (byte)intValue }; + } + else + { + // Ͳbyteint׳쳣Ӹͼʹ߼ + throw new NotSupportedException($"The underlying type of the enum {typeof(TEnum).Name} is not supported."); + } + } + + // byte[]תΪö٣byte[]ֻһֽڣ + public static TEnum ToEnum(this byte[] byteArray) where TEnum : struct, Enum + { + if (byteArray == null || byteArray.Length != 1) + throw new ArgumentException("The byte array must contain exactly one byte."); + + // ֱӴֽתΪöֵ + return (TEnum)Enum.ToObject(typeof(TEnum), byteArray[0]); + } + + // ushort[] ת byte[] + public static byte[] ToByteArray(this ushort[] ushortArray) + { + byte[] byteArray = new byte[ushortArray.Length * 2]; + Buffer.BlockCopy(ushortArray, 0, byteArray, 0, byteArray.Length); + return byteArray; + } + + // byte[] ת ushort[] + public static ushort[] ToUShortArray(this byte[] byteArray) + { + if (byteArray.Length % 2 != 0) + throw new ArgumentException("byte鳤ȱż"); + + ushort[] ushortArray = new ushort[byteArray.Length / 2]; + Buffer.BlockCopy(byteArray, 0, ushortArray, 0, byteArray.Length); + return ushortArray; + } + + + + public static byte[] ToByteArray(this bool[] boolArr) + { + byte[] byteArray = new byte[boolArr.Length]; + for (int i = 0; i < byteArray.Length; i++) + { + byteArray[i] = (byte)(boolArr[i] ? 1 : 0); + } + return byteArray; + } + + public static bool[] ToBoolArray(this byte[] byteArray) + { + bool[] boolArr = new bool[byteArray.Length]; + for (int i = 0; i < byteArray.Length; i++) + { + boolArr[i] = byteArray[i] == 0 ? false : true; + } + return boolArr; + } + + public static byte[] FlattenByteArray2D(this byte[,] array2D) + { + int rows = array2D.GetLength(0); + int cols = array2D.GetLength(1); + byte[] array1D = new byte[rows * cols]; + + int index = 0; + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < cols; j++) + { + array1D[index++] = array2D[i, j]; + } + } + + return array1D; + } + public static byte[,] CreateByteArray2D(this byte[] array1D, int rows, int cols) + { + if (array1D.Length != rows * cols) + { + throw new ArgumentException("The length of the 1D array does not match the specified dimensions for the 2D array."); + } + + byte[,] array2D = new byte[rows, cols]; + + int index = 0; + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < cols; j++) + { + array2D[i, j] = array1D[index++]; + } + } + + return array2D; + } +} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/IAxiStatus.cs.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/IAxiStatus.cs.meta new file mode 100644 index 00000000..7febd990 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/IAxiStatus.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 40ed20a1384827f45b7f187a4ccb4740 \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Metadata.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Metadata.meta index 19817c95..3dedfe35 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Metadata.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Metadata.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ae0b7e73691b4fd448b102af0875a373 +guid: 5b91d039db189d445a206d1852ae838a folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Metadata/GameMetadataHandler.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Metadata/GameMetadataHandler.cs index 7fce5473..3eba71b5 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Metadata/GameMetadataHandler.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Metadata/GameMetadataHandler.cs @@ -18,7 +18,7 @@ namespace Essgee.Metadata public interface IGameMetaReources { public bool GetCartMetadataDatabase(out string loadedData); - public bool GetDatBytes(string DatName,out byte[] loadedData); + public bool GetDatBytes(string DatName, out byte[] loadedData); } public class GameMetadataHandler @@ -37,7 +37,7 @@ namespace Essgee.Metadata { gameMetaReources = metaresources; - if(!gameMetaReources.GetCartMetadataDatabase(out string loadedData)) + if (!gameMetaReources.GetCartMetadataDatabase(out string loadedData)) throw new HandlerException("CartMetadataDatabase file not found"); cartMetadataDatabase = JsonConvert.DeserializeObject>(loadedData); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Utilities.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Utilities.meta index 3d6ea178..57481524 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Utilities.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Utilities.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fd20bf051feed2649a0b54c1c23246b0 +guid: efbb7663b0390d544a2f62d060d8441d folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Utilities/XInput.meta b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Utilities/XInput.meta index 9c55cf14..0e742947 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Utilities/XInput.meta +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Utilities/XInput.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e7cd06ff5a47d6b49b280e1f99c667e4 +guid: 37b3e1d7093e0f545807ab54c1209c8b folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs index 36ebbbfd..b84a9cb7 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs @@ -1,3 +1,5 @@ +using AxibugEmuOnline.Client; +using AxibugProtobuf; using Essgee; using Essgee.Emulation; using Essgee.Emulation.Configuration; @@ -13,13 +15,25 @@ using System.IO; using System.Linq; using System.Text; using UnityEngine; +using UnityEngine.UI; -public class Essgeeinit : MonoBehaviour +public class Essgeeinit : MonoBehaviour, IEmuCore { - static Essgeeinit instance; + public static Essgeeinit instance; public static System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); public static bool bInGame => instance?.emulatorHandler?.IsRunning == true ? true : false; + + public RomPlatformType Platform => mPlatform; + + public uint Frame => throw new NotImplementedException(); + + public Texture OutputPixel => graphicsHandler.rawBufferWarper; + + public RawImage DrawCanvas => graphicsHandler.DrawCanvas; + + public static bool bLogicUpdatePause { get; private set; } #region + UEGVideoPlayer graphicsHandler; UEGSoundPlayer soundHandler; GameMetadataHandler gameMetadataHandler; @@ -29,22 +43,19 @@ public class Essgeeinit : MonoBehaviour UEGLog uegLog; bool lastUserPauseState; - (int x, int y, int width, int height) currentViewport; double currentPixelAspectRatio; - byte[] lastFramebufferData; - (int width, int height) lastFramebufferSize; private UEGKeyboard mUniKeyboard; + private RomPlatformType mPlatform = RomPlatformType.MasterSystem; #endregion void Awake() { instance = this; - uegResources = new UEGResources(); uegLog = new UEGLog(); InitAll(uegResources, Application.persistentDataPath); - LoadAndRunCartridge("G:/psjapa.sms"); + //LoadAndRunCartridge("G:/psjapa.sms"); //LoadAndRunCartridge("G:/Ninja_Gaiden_(UE)_type_A_[!].sms"); //LoadAndRunCartridge("G:/SML2.gb"); } @@ -55,16 +66,96 @@ public class Essgeeinit : MonoBehaviour Dispose(false); } - private void Update() - { - if (!emulatorHandler.IsRunning) - return; - mUniKeyboard.UpdateInputKey(); - emulatorHandler.Update_Frame(); + #region EmuCoreʵ + + public object GetState() + { + return emulatorHandler.GetStateData(); } - void InitAll(IGameMetaReources metaresources,string CustonDataDir) + public byte[] GetStateBytes() + { + return emulatorHandler.GetStateData(); + } + + public void LoadState(object state) + { + Application.targetFrameRate = 60; + emulatorHandler.SetStateData((byte[])state); + } + + public void LoadStateFromBytes(byte[] data) + { + emulatorHandler.SetStateData(data); + } + + public void Pause() + { + bLogicUpdatePause = false; + } + public void Resume() + { + bLogicUpdatePause = true; + } + + public MsgBool StartGame(RomFile romFile) + { + mPlatform = romFile.Platform; + bLogicUpdatePause = true; + + //浱ǰڽеϷ浵 + if (!emulatorHandler.IsRunning) + { + emulatorHandler.SaveCartridge(); + } + + if (LoadAndRunCartridge(romFile.FileName)) + return true; + else + return "Romʧ"; + } + + public void Dispose() + { + if (!emulatorHandler.IsRunning) + { + emulatorHandler.SaveCartridge(); + } + ShutdownEmulation(); + } + + public void DoReset() + { + emulatorHandler.SaveCartridge(); + emulatorHandler.Reset(); + } + + public IControllerSetuper GetControllerSetuper() + { + return mUniKeyboard.ControllerMapper; + } + + public bool PushEmulatorFrame() + { + if (!emulatorHandler.IsRunning) return false; + if (!bLogicUpdatePause) return false; + + //ɼ֡Input + bool bhadNext = mUniKeyboard.SampleInput(); + //δյInput,֡ƽ + if (!bhadNext) return false; + + emulatorHandler.Update_Frame(); + return true; + } + + public void AfterPushFrame() + { + } + #endregion + + void InitAll(IGameMetaReources metaresources, string CustonDataDir) { //ʼ InitAppEnvironment(CustonDataDir); @@ -344,11 +435,11 @@ public class Essgeeinit : MonoBehaviour } - private void LoadAndRunCartridge(string fileName) + private bool LoadAndRunCartridge(string fileName) { - Application.targetFrameRate = 60; try { + var (machineType, romData) = CartridgeLoader.Load(fileName, "ROM image"); //TODO IsRecording?? Ҫʵ @@ -389,10 +480,13 @@ public class Essgeeinit : MonoBehaviour //SetWindowTitleAndStatus(); EssgeeLogger.EnqueueMessage($"Loaded '{lastGameMetadata?.KnownName ?? "unrecognized game"}'."); + + return true; } catch (Exception ex) when (!AppEnvironment.DebugMode) { ExceptionHandler(ex); + return false; } } private void InitializeEmulation(Type machineType) @@ -549,8 +643,6 @@ public class Essgeeinit : MonoBehaviour emulatorHandler = null; GC.Collect(); - //graphicsHandler?.FlushTextures(); - EssgeeLogger.WriteLine("Emulation stopped."); } #endregion @@ -618,7 +710,7 @@ public class Essgeeinit : MonoBehaviour //TODO Inputʵ //e.Keyboard = mUniKeyboard.mKeyCodeCore.GetPressedKeys(); - e.Keyboard.AddRange(mUniKeyboard.mKeyCodeCore.GetPressedKeys()); + e.Keyboard.AddRange(mUniKeyboard.GetPressedKeys()); e.MouseButtons = default; e.MousePosition = default; @@ -721,6 +813,7 @@ public class Essgeeinit : MonoBehaviour //soundHandler.SubmitSamples(e.MixedSamples, e.ChannelSamples, e.MixedSamples.Length); soundHandler.SubmitSamples(e.MixedSamples, e.ChannelSamples, e.MixedSamplesLength); } + #endregion } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/KeyCodeCore.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/KeyCodeCore.cs deleted file mode 100644 index 3ea94e80..00000000 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/KeyCodeCore.cs +++ /dev/null @@ -1,418 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using UnityEngine; - -public class KeyCodeCore -{ - //public Dictionary dictKeyCfgs = new Dictionary(); - public Dictionary dictKey2Motion = new Dictionary(); - public Dictionary dictMotion2RealKey = new Dictionary() - { -{ EssgeeUnityKey.P1_UP,KeyCode.W}, -{ EssgeeUnityKey.P1_DOWN,KeyCode.S}, -{ EssgeeUnityKey.P1_LEFT,KeyCode.A}, -{ EssgeeUnityKey.P1_RIGHT,KeyCode.D}, -{ EssgeeUnityKey.P1_BTN_1,KeyCode.J}, -{ EssgeeUnityKey.P1_BTN_2,KeyCode.K}, -{ EssgeeUnityKey.P1_BTN_3,KeyCode.U}, -{ EssgeeUnityKey.P1_BTN_4,KeyCode.I}, -{ EssgeeUnityKey.P1_POTION_1,KeyCode.Return}, -{ EssgeeUnityKey.P1_POTION_2,KeyCode.RightShift}, -{ EssgeeUnityKey.P2_UP,KeyCode.UpArrow}, -{ EssgeeUnityKey.P2_DOWN,KeyCode.DownArrow}, -{ EssgeeUnityKey.P2_LEFT,KeyCode.LeftArrow}, -{ EssgeeUnityKey.P2_RIGHT,KeyCode.RightArrow}, -{ EssgeeUnityKey.P2_BTN_1,KeyCode.Keypad1}, -{ EssgeeUnityKey.P2_BTN_2,KeyCode.Keypad2}, -{ EssgeeUnityKey.P2_BTN_3,KeyCode.Keypad4}, -{ EssgeeUnityKey.P2_BTN_4,KeyCode.Keypad5}, -{ EssgeeUnityKey.P2_POTION_1,KeyCode.Keypad0}, -{ EssgeeUnityKey.P2_POTION_2,KeyCode.KeypadPeriod}, -{ EssgeeUnityKey.P3_UP,KeyCode.F12}, -{ EssgeeUnityKey.P3_DOWN,KeyCode.F12}, -{ EssgeeUnityKey.P3_LEFT,KeyCode.F12}, -{ EssgeeUnityKey.P3_RIGHT,KeyCode.F12}, -{ EssgeeUnityKey.P3_BTN_1,KeyCode.F12}, -{ EssgeeUnityKey.P3_BTN_2,KeyCode.F12}, -{ EssgeeUnityKey.P3_BTN_3,KeyCode.F12}, -{ EssgeeUnityKey.P3_BTN_4,KeyCode.F12}, -{ EssgeeUnityKey.P3_POTION_1,KeyCode.F12}, -{ EssgeeUnityKey.P3_POTION_2,KeyCode.F12}, -{ EssgeeUnityKey.P4_UP,KeyCode.F12}, -{ EssgeeUnityKey.P4_DOWN,KeyCode.F12}, -{ EssgeeUnityKey.P4_LEFT,KeyCode.F12}, -{ EssgeeUnityKey.P4_RIGHT,KeyCode.F12}, -{ EssgeeUnityKey.P4_BTN_1,KeyCode.F12}, -{ EssgeeUnityKey.P4_BTN_2,KeyCode.F12}, -{ EssgeeUnityKey.P4_BTN_3,KeyCode.F12}, -{ EssgeeUnityKey.P4_BTN_4,KeyCode.F12}, -{ EssgeeUnityKey.P4_POTION_1,KeyCode.F12}, -{ EssgeeUnityKey.P4_POTION_2,KeyCode.F12}, - }; - public ulong[] CheckList; - public EssgeeMotionKey[] mCurrKey = new EssgeeMotionKey[0]; - List temp = new List(); - ulong tempInputAllData = 0; - UEGKeyboard mUniKeyboard; - ulong last_CurryInpuAllData_test = 0; - public static class EssgeeUnityKey - { - public const ulong NONE = 0; - public const ulong P1_UP = 1; - public const ulong P1_DOWN = 1 << 1; - public const ulong P1_LEFT = 1 << 2; - public const ulong P1_RIGHT = 1 << 3; - public const ulong P1_BTN_1 = 1 << 4; - public const ulong P1_BTN_2 = 1 << 5; - public const ulong P1_BTN_3 = 1 << 6; - public const ulong P1_BTN_4 = 1 << 7; - public const ulong P1_POTION_1 = 1 << 8; - public const ulong P1_POTION_2 = 1 << 9; - public const ulong P2_UP = 65536; - public const ulong P2_DOWN = 65536 << 1; - public const ulong P2_LEFT = 65536 << 2; - public const ulong P2_RIGHT = 65536 << 3; - public const ulong P2_BTN_1 = 65536 << 4; - public const ulong P2_BTN_2 = 65536 << 5; - public const ulong P2_BTN_3 = 65536 << 6; - public const ulong P2_BTN_4 = 65536 << 7; - public const ulong P2_POTION_1 = 65536 << 8; - public const ulong P2_POTION_2 = 65536 << 9; - public const ulong P3_UP = 4294967296; - public const ulong P3_DOWN = 4294967296 << 1; - public const ulong P3_LEFT = 4294967296 << 2; - public const ulong P3_RIGHT = 4294967296 << 3; - public const ulong P3_BTN_1 = 4294967296 << 4; - public const ulong P3_BTN_2 = 4294967296 << 5; - public const ulong P3_BTN_3 = 4294967296 << 6; - public const ulong P3_BTN_4 = 654294967296536 << 7; - public const ulong P3_POTION_1 = 4294967296 << 8; - public const ulong P3_POTION_2 = 4294967296 << 9; - public const ulong P4_UP = 281474976710656; - public const ulong P4_DOWN = 281474976710656 << 1; - public const ulong P4_LEFT = 281474976710656 << 2; - public const ulong P4_RIGHT = 281474976710656 << 3; - public const ulong P4_BTN_1 = 281474976710656 << 4; - public const ulong P4_BTN_2 = 281474976710656 << 5; - public const ulong P4_BTN_3 = 281474976710656 << 6; - public const ulong P4_BTN_4 = 281474976710656 << 7; - public const ulong P4_POTION_1 = 281474976710656 << 8; - public const ulong P4_POTION_2 = 281474976710656 << 9; - } - - public EssgeeMotionKey[] GetPressedKeys() - { - return mCurrKey; - } - - public void SetRePlay(bool IsReplay) - { - //bReplayMode = IsReplay; - } - public void Init(Essgee.Emulation.Machines.IMachine Machine, UEGKeyboard uniKeyboard, bool IsReplay) - { - mUniKeyboard = uniKeyboard; - //dictKeyCfgs.Clear(); - dictKey2Motion.Clear(); - if (Machine is Essgee.Emulation.Machines.MasterSystem) - { - var machine = (Essgee.Emulation.Machines.MasterSystem)Machine; - //dictKeyCfgs.Add(KeyCode.W, machine.configuration.Joypad1Up); - //dictKeyCfgs.Add(KeyCode.S, machine.configuration.Joypad1Down); - //dictKeyCfgs.Add(KeyCode.A, machine.configuration.Joypad1Left); - //dictKeyCfgs.Add(KeyCode.D, machine.configuration.Joypad1Right); - //dictKeyCfgs.Add(KeyCode.J, machine.configuration.Joypad1Button1); - //dictKeyCfgs.Add(KeyCode.K, machine.configuration.Joypad1Button2); - - //dictKeyCfgs.Add(KeyCode.UpArrow, machine.configuration.Joypad2Up); - //dictKeyCfgs.Add(KeyCode.DownArrow, machine.configuration.Joypad2Down); - //dictKeyCfgs.Add(KeyCode.LeftArrow, machine.configuration.Joypad2Left); - //dictKeyCfgs.Add(KeyCode.RightAlt, machine.configuration.Joypad2Right); - //dictKeyCfgs.Add(KeyCode.Alpha1, machine.configuration.Joypad2Button1); - //dictKeyCfgs.Add(KeyCode.Alpha2, machine.configuration.Joypad2Button2); - - - dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.Joypad1Up); - dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.Joypad1Down); - dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.Joypad1Left); - dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.Joypad1Right); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.Joypad1Button1); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.Joypad1Button2); - - dictKey2Motion.Add(EssgeeUnityKey.P2_UP, machine.configuration.Joypad2Up); - dictKey2Motion.Add(EssgeeUnityKey.P2_DOWN, machine.configuration.Joypad2Down); - dictKey2Motion.Add(EssgeeUnityKey.P2_LEFT, machine.configuration.Joypad2Left); - dictKey2Motion.Add(EssgeeUnityKey.P2_RIGHT, machine.configuration.Joypad2Right); - dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_1, machine.configuration.Joypad2Button1); - dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_2, machine.configuration.Joypad2Button2); - } - else if (Machine is Essgee.Emulation.Machines.GameBoy) - { - var machine = (Essgee.Emulation.Machines.GameBoy)Machine; - - //dictKeyCfgs.Add(KeyCode.W, machine.configuration.ControlsUp); - //dictKeyCfgs.Add(KeyCode.S, machine.configuration.ControlsDown); - //dictKeyCfgs.Add(KeyCode.A, machine.configuration.ControlsLeft); - //dictKeyCfgs.Add(KeyCode.D, machine.configuration.ControlsRight); - //dictKeyCfgs.Add(KeyCode.J, machine.configuration.ControlsB); - //dictKeyCfgs.Add(KeyCode.K, machine.configuration.ControlsA); - //dictKeyCfgs.Add(KeyCode.Return, machine.configuration.ControlsStart); - //dictKeyCfgs.Add(KeyCode.RightShift, machine.configuration.ControlsSelect); - - dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.ControlsUp); - dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.ControlsDown); - dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.ControlsLeft); - dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.ControlsRight); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.ControlsB); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.ControlsA); - dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_1, machine.configuration.ControlsStart); - dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_2, machine.configuration.ControlsSelect); - } - else if (Machine is Essgee.Emulation.Machines.GameBoyColor) - { - var machine = (Essgee.Emulation.Machines.GameBoyColor)Machine; - - //dictKeyCfgs.Add(KeyCode.W, machine.configuration.ControlsUp); - //dictKeyCfgs.Add(KeyCode.S, machine.configuration.ControlsDown); - //dictKeyCfgs.Add(KeyCode.A, machine.configuration.ControlsLeft); - //dictKeyCfgs.Add(KeyCode.D, machine.configuration.ControlsRight); - //dictKeyCfgs.Add(KeyCode.J, machine.configuration.ControlsB); - //dictKeyCfgs.Add(KeyCode.K, machine.configuration.ControlsA); - - //dictKeyCfgs.Add(KeyCode.Return, machine.configuration.ControlsStart); - //dictKeyCfgs.Add(KeyCode.RightShift, machine.configuration.ControlsSelect); - //dictKeyCfgs.Add(KeyCode.Space, machine.configuration.ControlsSendIR); - - dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.ControlsUp); - dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.ControlsDown); - dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.ControlsLeft); - dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.ControlsRight); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.ControlsA); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.ControlsB); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_3, machine.configuration.ControlsSendIR); - dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_1, machine.configuration.ControlsStart); - dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_2, machine.configuration.ControlsSelect); - - } - else if (Machine is Essgee.Emulation.Machines.GameGear) - { - var machine = (Essgee.Emulation.Machines.GameGear)Machine; - //dictKeyCfgs.Add(KeyCode.W, machine.configuration.ControlsUp); - //dictKeyCfgs.Add(KeyCode.S, machine.configuration.ControlsDown); - //dictKeyCfgs.Add(KeyCode.A, machine.configuration.ControlsLeft); - //dictKeyCfgs.Add(KeyCode.D, machine.configuration.ControlsRight); - //dictKeyCfgs.Add(KeyCode.J, machine.configuration.ControlsButton2); - //dictKeyCfgs.Add(KeyCode.K, machine.configuration.ControlsButton1); - //dictKeyCfgs.Add(KeyCode.Return, machine.configuration.ControlsStart); - - - dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.ControlsUp); - dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.ControlsDown); - dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.ControlsLeft); - dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.ControlsRight); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.ControlsButton2); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.ControlsButton1); - dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_1, machine.configuration.ControlsStart); - } - else if (Machine is Essgee.Emulation.Machines.SC3000) - { - var machine = (Essgee.Emulation.Machines.SC3000)Machine; - - /* - * InputReset = MotionKey.F12; - InputChangeMode = MotionKey.F1; - InputPlayTape = MotionKey.F2; - - Joypad1Up = MotionKey.Up; - Joypad1Down = MotionKey.Down; - Joypad1Left = MotionKey.Left; - Joypad1Right = MotionKey.Right; - Joypad1Button1 = MotionKey.A; - Joypad1Button2 = MotionKey.S; - - Joypad2Up = MotionKey.NumPad8; - Joypad2Down = MotionKey.NumPad2; - Joypad2Left = MotionKey.NumPad4; - Joypad2Right = MotionKey.NumPad6; - Joypad2Button1 = MotionKey.NumPad1; - Joypad2Button2 = MotionKey.NumPad3; - */ - - //dictKeyCfgs.Add(KeyCode.F12, machine.configuration.InputReset); - - //dictKeyCfgs.Add(KeyCode.F1, machine.configuration.InputChangeMode); - //dictKeyCfgs.Add(KeyCode.F2, machine.configuration.InputPlayTape); - - //dictKeyCfgs.Add(KeyCode.W, machine.configuration.Joypad1Up); - //dictKeyCfgs.Add(KeyCode.S, machine.configuration.Joypad1Down); - //dictKeyCfgs.Add(KeyCode.A, machine.configuration.Joypad1Left); - //dictKeyCfgs.Add(KeyCode.D, machine.configuration.Joypad1Right); - //dictKeyCfgs.Add(KeyCode.J, machine.configuration.Joypad1Button2); - //dictKeyCfgs.Add(KeyCode.K, machine.configuration.Joypad1Button1); - - //dictKeyCfgs.Add(KeyCode.UpArrow, machine.configuration.Joypad2Up); - //dictKeyCfgs.Add(KeyCode.DownArrow, machine.configuration.Joypad2Down); - //dictKeyCfgs.Add(KeyCode.LeftArrow, machine.configuration.Joypad2Left); - //dictKeyCfgs.Add(KeyCode.RightAlt, machine.configuration.Joypad2Right); - //dictKeyCfgs.Add(KeyCode.Alpha1, machine.configuration.Joypad2Button1); - //dictKeyCfgs.Add(KeyCode.Alpha2, machine.configuration.Joypad2Button2); - - - dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_1, machine.configuration.InputChangeMode); - dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_2, machine.configuration.InputPlayTape); - - dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.Joypad1Up); - dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.Joypad1Down); - dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.Joypad1Left); - dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.Joypad1Right); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.Joypad1Button2); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.Joypad1Button1); - - dictKey2Motion.Add(EssgeeUnityKey.P2_UP, machine.configuration.Joypad1Up); - dictKey2Motion.Add(EssgeeUnityKey.P2_DOWN, machine.configuration.Joypad1Down); - dictKey2Motion.Add(EssgeeUnityKey.P2_LEFT, machine.configuration.Joypad1Left); - dictKey2Motion.Add(EssgeeUnityKey.P2_RIGHT, machine.configuration.Joypad1Right); - dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_1, machine.configuration.Joypad1Button2); - dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_2, machine.configuration.Joypad1Button1); - - } - else if (Machine is Essgee.Emulation.Machines.SG1000) - { - var machine = (Essgee.Emulation.Machines.SG1000)Machine; - - /* - TVStandard = TVStandard.NTSC; - - InputPause = MotionKey.Space; - - Joypad1Up = MotionKey.Up; - Joypad1Down = MotionKey.Down; - Joypad1Left = MotionKey.Left; - Joypad1Right = MotionKey.Right; - Joypad1Button1 = MotionKey.A; - Joypad1Button2 = MotionKey.S; - - Joypad2Up = MotionKey.NumPad8; - Joypad2Down = MotionKey.NumPad2; - Joypad2Left = MotionKey.NumPad4; - Joypad2Right = MotionKey.NumPad6; - Joypad2Button1 = MotionKey.NumPad1; - Joypad2Button2 = MotionKey.NumPad3; - */ - - //dictKeyCfgs.Add(KeyCode.W, machine.configuration.Joypad1Up); - //dictKeyCfgs.Add(KeyCode.S, machine.configuration.Joypad1Down); - //dictKeyCfgs.Add(KeyCode.A, machine.configuration.Joypad1Left); - //dictKeyCfgs.Add(KeyCode.D, machine.configuration.Joypad1Right); - //dictKeyCfgs.Add(KeyCode.J, machine.configuration.Joypad1Button2); - //dictKeyCfgs.Add(KeyCode.K, machine.configuration.Joypad1Button1); - - //dictKeyCfgs.Add(KeyCode.UpArrow, machine.configuration.Joypad2Up); - //dictKeyCfgs.Add(KeyCode.DownArrow, machine.configuration.Joypad2Down); - //dictKeyCfgs.Add(KeyCode.LeftArrow, machine.configuration.Joypad2Left); - //dictKeyCfgs.Add(KeyCode.RightAlt, machine.configuration.Joypad2Right); - //dictKeyCfgs.Add(KeyCode.Alpha1, machine.configuration.Joypad2Button2); - //dictKeyCfgs.Add(KeyCode.Alpha2, machine.configuration.Joypad2Button1); - - - - dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.Joypad1Up); - dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.Joypad1Down); - dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.Joypad1Left); - dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.Joypad1Right); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.Joypad1Button2); - dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.Joypad1Button1); - - dictKey2Motion.Add(EssgeeUnityKey.P2_UP, machine.configuration.Joypad1Up); - dictKey2Motion.Add(EssgeeUnityKey.P2_DOWN, machine.configuration.Joypad1Down); - dictKey2Motion.Add(EssgeeUnityKey.P2_LEFT, machine.configuration.Joypad1Left); - dictKey2Motion.Add(EssgeeUnityKey.P2_RIGHT, machine.configuration.Joypad1Right); - dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_1, machine.configuration.Joypad1Button2); - dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_2, machine.configuration.Joypad1Button1); - } - CheckList = dictKey2Motion.Keys.ToArray(); - - //mUniKeyboard.btnP1.Key = new long[] { (long)MotionKey.P1_GAMESTART }; - //mUniKeyboard.btnCoin1.Key = new long[] { (long)MotionKey.P1_INSERT_COIN }; - //mUniKeyboard.btnA.Key = new long[] { (long)MotionKey.P1_BTN_1 }; - //mUniKeyboard.btnB.Key = new long[] { (long)MotionKey.P1_BTN_2 }; - //mUniKeyboard.btnC.Key = new long[] { (long)MotionKey.P1_BTN_3 }; - //mUniKeyboard.btnD.Key = new long[] { (long)MotionKey.P1_BTN_4 }; - ////mUniKeyboard.btnE.Key = new long[] { (long)MotionKey.P1_BTN_5 }; - ////mUniKeyboard.btnF.Key = new long[] { (long)MotionKey.P1_BTN_6 }; - //mUniKeyboard.btnAB.Key = new long[] { (long)MotionKey.P1_BTN_1, (long)MotionKey.P1_BTN_2 }; - //mUniKeyboard.btnCD.Key = new long[] { (long)MotionKey.P1_BTN_3, (long)MotionKey.P1_BTN_4 }; - //mUniKeyboard.btnABC.Key = new long[] { (long)MotionKey.P1_BTN_1, (long)MotionKey.P1_BTN_2, (long)MotionKey.P1_BTN_3 }; - } - - public void UpdateLogic() - { - tempInputAllData = 0; - temp.Clear(); - for (int i = 0; i < CheckList.Length; i++) - { - ulong key = CheckList[i]; - if (Input.GetKey(dictMotion2RealKey[key])) - { - EssgeeMotionKey mk = dictKey2Motion[key]; - temp.Add(mk); - tempInputAllData |= (ulong)mk; - } - } - mCurrKey = temp.ToArray(); - - - //if (bReplayMode) return; - //tempInputAllData = 0; - //temp.Clear(); - //for (int i = 0; i < CheckList.Length; i++) - //{ - // if (Input.GetKey(CheckList[i])) - // { - // EssgeeMotionKey mk = dictKeyCfgs[CheckList[i]]; - // temp.Add(mk); - // tempInputAllData |= (ulong)mk; - // } - //} - //mCurrKey = temp.ToArray(); - - //for (int i = 0; i < mUniKeyboard.mUIBtns.Count; i++) - //{ - // if (mUniKeyboard.mUIBtns[i].bHotKey) - // { - // for (int j = 0; j < mUniKeyboard.mUIBtns[i].Key.Length; j++) - // { - // MotionKey mk = (MotionKey)mUniKeyboard.mUIBtns[i].Key[j]; - // temp.Add(mk); - // tempInputAllData |= (ulong)mk; - // } - // } - //} - - //Vector2Int inputV2 = mUniKeyboard.mJoystick.RawInputV2; - ////Debug.Log($"{inputV2.x},{inputV2.y}"); - //if (inputV2.x > 0) - //{ - // temp.Add(MotionKey.P1_RIGHT); - // tempInputAllData |= (ulong)MotionKey.P1_RIGHT; - //} - //else if (inputV2.x < 0) - //{ - // temp.Add(MotionKey.P1_LEFT); - // tempInputAllData |= (ulong)MotionKey.P1_LEFT; - //} - //if (inputV2.y > 0) - //{ - // temp.Add(MotionKey.P1_UP); - // tempInputAllData |= (ulong)MotionKey.P1_UP; - //} - //else if (inputV2.y < 0) - //{ - // temp.Add(MotionKey.P1_DOWN); - // tempInputAllData |= (ulong)MotionKey.P1_DOWN; - //} - //CurryInpuAllData = tempInputAllData; - //mCurrKey = temp.ToArray(); - - } -} \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/KeyCodeCore.cs.meta b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/KeyCodeCore.cs.meta deleted file mode 100644 index 28d1460f..00000000 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/KeyCodeCore.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: 3054336185b15f84d9543bdafb49907f \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs index 59348577..5e633215 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs @@ -1,77 +1,718 @@ +using AxibugEmuOnline.Client; +using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.Event; +using AxiReplay; +using System; +using System.Collections.Generic; +using System.Linq; using UnityEngine; public class UEGKeyboard : MonoBehaviour { - public KeyCodeCore mKeyCodeCore = new KeyCodeCore(); - #region - //public UILongClickButton btnP1; - //public UILongClickButton btnCoin1; - //public UILongClickButton btnA; - //public UILongClickButton btnB; - //public UILongClickButton btnC; - //public UILongClickButton btnD; - ////public UILongClickButton btnE; - ////public UILongClickButton btnF; - //public UILongClickButton btnAB; - //public UILongClickButton btnCD; - //public UILongClickButton btnABC; - //public Transform tfKeyPad; - //public FloatingJoystick mJoystick; - #endregion - - //public List mUIBtns = new List(); - + public EssgeeControllerMapper ControllerMapper { get; private set; } + public Dictionary dictKey2Motion = new Dictionary(); + public Dictionary dictMotion2RealKey = new Dictionary() + { +{ EssgeeUnityKey.P1_UP,KeyCode.W}, +{ EssgeeUnityKey.P1_DOWN,KeyCode.S}, +{ EssgeeUnityKey.P1_LEFT,KeyCode.A}, +{ EssgeeUnityKey.P1_RIGHT,KeyCode.D}, +{ EssgeeUnityKey.P1_BTN_1,KeyCode.J}, +{ EssgeeUnityKey.P1_BTN_2,KeyCode.K}, +{ EssgeeUnityKey.P1_BTN_3,KeyCode.U}, +{ EssgeeUnityKey.P1_BTN_4,KeyCode.I}, +{ EssgeeUnityKey.P1_POTION_1,KeyCode.Return}, +{ EssgeeUnityKey.P1_POTION_2,KeyCode.RightShift}, +{ EssgeeUnityKey.P2_UP,KeyCode.UpArrow}, +{ EssgeeUnityKey.P2_DOWN,KeyCode.DownArrow}, +{ EssgeeUnityKey.P2_LEFT,KeyCode.LeftArrow}, +{ EssgeeUnityKey.P2_RIGHT,KeyCode.RightArrow}, +{ EssgeeUnityKey.P2_BTN_1,KeyCode.Keypad1}, +{ EssgeeUnityKey.P2_BTN_2,KeyCode.Keypad2}, +{ EssgeeUnityKey.P2_BTN_3,KeyCode.Keypad4}, +{ EssgeeUnityKey.P2_BTN_4,KeyCode.Keypad5}, +{ EssgeeUnityKey.P2_POTION_1,KeyCode.Keypad0}, +{ EssgeeUnityKey.P2_POTION_2,KeyCode.KeypadPeriod}, +{ EssgeeUnityKey.P3_UP,KeyCode.F12}, +{ EssgeeUnityKey.P3_DOWN,KeyCode.F12}, +{ EssgeeUnityKey.P3_LEFT,KeyCode.F12}, +{ EssgeeUnityKey.P3_RIGHT,KeyCode.F12}, +{ EssgeeUnityKey.P3_BTN_1,KeyCode.F12}, +{ EssgeeUnityKey.P3_BTN_2,KeyCode.F12}, +{ EssgeeUnityKey.P3_BTN_3,KeyCode.F12}, +{ EssgeeUnityKey.P3_BTN_4,KeyCode.F12}, +{ EssgeeUnityKey.P3_POTION_1,KeyCode.F12}, +{ EssgeeUnityKey.P3_POTION_2,KeyCode.F12}, +{ EssgeeUnityKey.P4_UP,KeyCode.F12}, +{ EssgeeUnityKey.P4_DOWN,KeyCode.F12}, +{ EssgeeUnityKey.P4_LEFT,KeyCode.F12}, +{ EssgeeUnityKey.P4_RIGHT,KeyCode.F12}, +{ EssgeeUnityKey.P4_BTN_1,KeyCode.F12}, +{ EssgeeUnityKey.P4_BTN_2,KeyCode.F12}, +{ EssgeeUnityKey.P4_BTN_3,KeyCode.F12}, +{ EssgeeUnityKey.P4_BTN_4,KeyCode.F12}, +{ EssgeeUnityKey.P4_POTION_1,KeyCode.F12}, +{ EssgeeUnityKey.P4_POTION_2,KeyCode.F12}, + }; + public ulong[] CheckList; + public EssgeeMotionKey[] mCurrKey = new EssgeeMotionKey[0]; + List temp = new List(); + public ulong CurrRemoteInpuAllData = 0; + public ulong CurrLocalInpuAllData { get; private set; } void Awake() { - //mJoystick = GameObject.Find("tfJoystick").GetComponent(); - //tfKeyPad = GameObject.Find("tfKeyPad").transform; - //btnP1 = GameObject.Find("btnP1").GetComponent(); - //btnCoin1 = GameObject.Find("btnCoin1").GetComponent(); - //btnA = GameObject.Find("btnA").GetComponent(); - //btnB = GameObject.Find("btnB").GetComponent(); - //btnC = GameObject.Find("btnC").GetComponent(); - //btnD = GameObject.Find("btnD").GetComponent(); - ////btnE = GameObject.Find("btnE")?.GetComponent(); - ////btnF = GameObject.Find("btnF")?.GetComponent(); - //btnAB = GameObject.Find("btnAB").GetComponent(); - //btnCD = GameObject.Find("btnCD").GetComponent(); - //btnABC = GameObject.Find("btnABC").GetComponent(); - - //mUIBtns.Add(btnP1); - //mUIBtns.Add(btnCoin1); - //mUIBtns.Add(btnA); - //mUIBtns.Add(btnB); - //mUIBtns.Add(btnC); - //mUIBtns.Add(btnD); - //mUIBtns.Add(btnAB); - //mUIBtns.Add(btnCD); - //mUIBtns.Add(btnABC); - - //if (btnE != null) - //{ - // mUIBtns.Add(btnE); - // btnE.gameObject.SetActive(false); - //} - //else - //{ - // mUIBtns.Add(btnF); - // btnF.gameObject.SetActive(false); - //} - - -#if UNITY_STANDALONE_WIN || UNITY_EDITOR - //tfKeyPad.gameObject.SetActive(false); -#endif } public void Init(Essgee.Emulation.Machines.IMachine Machine) { - mKeyCodeCore.Init(Machine, this, false); + ControllerMapper = new EssgeeControllerMapper(); + Init(Machine, false); } - public void UpdateInputKey() + public EssgeeMotionKey[] GetPressedKeys() { - mKeyCodeCore.UpdateLogic(); + return mCurrKey; + } + + public void SetRePlay(bool IsReplay) + { + //bReplayMode = IsReplay; + } + + void Init(Essgee.Emulation.Machines.IMachine Machine, bool IsReplay) + { + dictKey2Motion.Clear(); + if (Machine is Essgee.Emulation.Machines.MasterSystem) + { + var machine = (Essgee.Emulation.Machines.MasterSystem)Machine; + //dictKeyCfgs.Add(KeyCode.W, machine.configuration.Joypad1Up); + //dictKeyCfgs.Add(KeyCode.S, machine.configuration.Joypad1Down); + //dictKeyCfgs.Add(KeyCode.A, machine.configuration.Joypad1Left); + //dictKeyCfgs.Add(KeyCode.D, machine.configuration.Joypad1Right); + //dictKeyCfgs.Add(KeyCode.J, machine.configuration.Joypad1Button1); + //dictKeyCfgs.Add(KeyCode.K, machine.configuration.Joypad1Button2); + + //dictKeyCfgs.Add(KeyCode.UpArrow, machine.configuration.Joypad2Up); + //dictKeyCfgs.Add(KeyCode.DownArrow, machine.configuration.Joypad2Down); + //dictKeyCfgs.Add(KeyCode.LeftArrow, machine.configuration.Joypad2Left); + //dictKeyCfgs.Add(KeyCode.RightAlt, machine.configuration.Joypad2Right); + //dictKeyCfgs.Add(KeyCode.Alpha1, machine.configuration.Joypad2Button1); + //dictKeyCfgs.Add(KeyCode.Alpha2, machine.configuration.Joypad2Button2); + + + dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.Joypad1Up); + dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.Joypad1Down); + dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.Joypad1Left); + dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.Joypad1Right); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.Joypad1Button1); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.Joypad1Button2); + + dictKey2Motion.Add(EssgeeUnityKey.P2_UP, machine.configuration.Joypad2Up); + dictKey2Motion.Add(EssgeeUnityKey.P2_DOWN, machine.configuration.Joypad2Down); + dictKey2Motion.Add(EssgeeUnityKey.P2_LEFT, machine.configuration.Joypad2Left); + dictKey2Motion.Add(EssgeeUnityKey.P2_RIGHT, machine.configuration.Joypad2Right); + dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_1, machine.configuration.Joypad2Button1); + dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_2, machine.configuration.Joypad2Button2); + } + else if (Machine is Essgee.Emulation.Machines.GameBoy) + { + var machine = (Essgee.Emulation.Machines.GameBoy)Machine; + + //dictKeyCfgs.Add(KeyCode.W, machine.configuration.ControlsUp); + //dictKeyCfgs.Add(KeyCode.S, machine.configuration.ControlsDown); + //dictKeyCfgs.Add(KeyCode.A, machine.configuration.ControlsLeft); + //dictKeyCfgs.Add(KeyCode.D, machine.configuration.ControlsRight); + //dictKeyCfgs.Add(KeyCode.J, machine.configuration.ControlsB); + //dictKeyCfgs.Add(KeyCode.K, machine.configuration.ControlsA); + //dictKeyCfgs.Add(KeyCode.Return, machine.configuration.ControlsStart); + //dictKeyCfgs.Add(KeyCode.RightShift, machine.configuration.ControlsSelect); + + dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.ControlsUp); + dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.ControlsDown); + dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.ControlsLeft); + dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.ControlsRight); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.ControlsB); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.ControlsA); + dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_1, machine.configuration.ControlsStart); + dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_2, machine.configuration.ControlsSelect); + } + else if (Machine is Essgee.Emulation.Machines.GameBoyColor) + { + var machine = (Essgee.Emulation.Machines.GameBoyColor)Machine; + + //dictKeyCfgs.Add(KeyCode.W, machine.configuration.ControlsUp); + //dictKeyCfgs.Add(KeyCode.S, machine.configuration.ControlsDown); + //dictKeyCfgs.Add(KeyCode.A, machine.configuration.ControlsLeft); + //dictKeyCfgs.Add(KeyCode.D, machine.configuration.ControlsRight); + //dictKeyCfgs.Add(KeyCode.J, machine.configuration.ControlsB); + //dictKeyCfgs.Add(KeyCode.K, machine.configuration.ControlsA); + + //dictKeyCfgs.Add(KeyCode.Return, machine.configuration.ControlsStart); + //dictKeyCfgs.Add(KeyCode.RightShift, machine.configuration.ControlsSelect); + //dictKeyCfgs.Add(KeyCode.Space, machine.configuration.ControlsSendIR); + + dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.ControlsUp); + dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.ControlsDown); + dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.ControlsLeft); + dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.ControlsRight); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.ControlsA); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.ControlsB); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_3, machine.configuration.ControlsSendIR); + dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_1, machine.configuration.ControlsStart); + dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_2, machine.configuration.ControlsSelect); + + } + else if (Machine is Essgee.Emulation.Machines.GameGear) + { + var machine = (Essgee.Emulation.Machines.GameGear)Machine; + //dictKeyCfgs.Add(KeyCode.W, machine.configuration.ControlsUp); + //dictKeyCfgs.Add(KeyCode.S, machine.configuration.ControlsDown); + //dictKeyCfgs.Add(KeyCode.A, machine.configuration.ControlsLeft); + //dictKeyCfgs.Add(KeyCode.D, machine.configuration.ControlsRight); + //dictKeyCfgs.Add(KeyCode.J, machine.configuration.ControlsButton2); + //dictKeyCfgs.Add(KeyCode.K, machine.configuration.ControlsButton1); + //dictKeyCfgs.Add(KeyCode.Return, machine.configuration.ControlsStart); + + + dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.ControlsUp); + dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.ControlsDown); + dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.ControlsLeft); + dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.ControlsRight); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.ControlsButton2); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.ControlsButton1); + dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_1, machine.configuration.ControlsStart); + } + else if (Machine is Essgee.Emulation.Machines.SC3000) + { + var machine = (Essgee.Emulation.Machines.SC3000)Machine; + + /* + * InputReset = MotionKey.F12; + InputChangeMode = MotionKey.F1; + InputPlayTape = MotionKey.F2; + + Joypad1Up = MotionKey.Up; + Joypad1Down = MotionKey.Down; + Joypad1Left = MotionKey.Left; + Joypad1Right = MotionKey.Right; + Joypad1Button1 = MotionKey.A; + Joypad1Button2 = MotionKey.S; + + Joypad2Up = MotionKey.NumPad8; + Joypad2Down = MotionKey.NumPad2; + Joypad2Left = MotionKey.NumPad4; + Joypad2Right = MotionKey.NumPad6; + Joypad2Button1 = MotionKey.NumPad1; + Joypad2Button2 = MotionKey.NumPad3; + */ + + //dictKeyCfgs.Add(KeyCode.F12, machine.configuration.InputReset); + + //dictKeyCfgs.Add(KeyCode.F1, machine.configuration.InputChangeMode); + //dictKeyCfgs.Add(KeyCode.F2, machine.configuration.InputPlayTape); + + //dictKeyCfgs.Add(KeyCode.W, machine.configuration.Joypad1Up); + //dictKeyCfgs.Add(KeyCode.S, machine.configuration.Joypad1Down); + //dictKeyCfgs.Add(KeyCode.A, machine.configuration.Joypad1Left); + //dictKeyCfgs.Add(KeyCode.D, machine.configuration.Joypad1Right); + //dictKeyCfgs.Add(KeyCode.J, machine.configuration.Joypad1Button2); + //dictKeyCfgs.Add(KeyCode.K, machine.configuration.Joypad1Button1); + + //dictKeyCfgs.Add(KeyCode.UpArrow, machine.configuration.Joypad2Up); + //dictKeyCfgs.Add(KeyCode.DownArrow, machine.configuration.Joypad2Down); + //dictKeyCfgs.Add(KeyCode.LeftArrow, machine.configuration.Joypad2Left); + //dictKeyCfgs.Add(KeyCode.RightAlt, machine.configuration.Joypad2Right); + //dictKeyCfgs.Add(KeyCode.Alpha1, machine.configuration.Joypad2Button1); + //dictKeyCfgs.Add(KeyCode.Alpha2, machine.configuration.Joypad2Button2); + + + dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_1, machine.configuration.InputChangeMode); + dictKey2Motion.Add(EssgeeUnityKey.P1_POTION_2, machine.configuration.InputPlayTape); + + dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.Joypad1Up); + dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.Joypad1Down); + dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.Joypad1Left); + dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.Joypad1Right); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.Joypad1Button2); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.Joypad1Button1); + + dictKey2Motion.Add(EssgeeUnityKey.P2_UP, machine.configuration.Joypad1Up); + dictKey2Motion.Add(EssgeeUnityKey.P2_DOWN, machine.configuration.Joypad1Down); + dictKey2Motion.Add(EssgeeUnityKey.P2_LEFT, machine.configuration.Joypad1Left); + dictKey2Motion.Add(EssgeeUnityKey.P2_RIGHT, machine.configuration.Joypad1Right); + dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_1, machine.configuration.Joypad1Button2); + dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_2, machine.configuration.Joypad1Button1); + + } + else if (Machine is Essgee.Emulation.Machines.SG1000) + { + var machine = (Essgee.Emulation.Machines.SG1000)Machine; + + /* + TVStandard = TVStandard.NTSC; + + InputPause = MotionKey.Space; + + Joypad1Up = MotionKey.Up; + Joypad1Down = MotionKey.Down; + Joypad1Left = MotionKey.Left; + Joypad1Right = MotionKey.Right; + Joypad1Button1 = MotionKey.A; + Joypad1Button2 = MotionKey.S; + + Joypad2Up = MotionKey.NumPad8; + Joypad2Down = MotionKey.NumPad2; + Joypad2Left = MotionKey.NumPad4; + Joypad2Right = MotionKey.NumPad6; + Joypad2Button1 = MotionKey.NumPad1; + Joypad2Button2 = MotionKey.NumPad3; + */ + + //dictKeyCfgs.Add(KeyCode.W, machine.configuration.Joypad1Up); + //dictKeyCfgs.Add(KeyCode.S, machine.configuration.Joypad1Down); + //dictKeyCfgs.Add(KeyCode.A, machine.configuration.Joypad1Left); + //dictKeyCfgs.Add(KeyCode.D, machine.configuration.Joypad1Right); + //dictKeyCfgs.Add(KeyCode.J, machine.configuration.Joypad1Button2); + //dictKeyCfgs.Add(KeyCode.K, machine.configuration.Joypad1Button1); + + //dictKeyCfgs.Add(KeyCode.UpArrow, machine.configuration.Joypad2Up); + //dictKeyCfgs.Add(KeyCode.DownArrow, machine.configuration.Joypad2Down); + //dictKeyCfgs.Add(KeyCode.LeftArrow, machine.configuration.Joypad2Left); + //dictKeyCfgs.Add(KeyCode.RightAlt, machine.configuration.Joypad2Right); + //dictKeyCfgs.Add(KeyCode.Alpha1, machine.configuration.Joypad2Button2); + //dictKeyCfgs.Add(KeyCode.Alpha2, machine.configuration.Joypad2Button1); + + + + dictKey2Motion.Add(EssgeeUnityKey.P1_UP, machine.configuration.Joypad1Up); + dictKey2Motion.Add(EssgeeUnityKey.P1_DOWN, machine.configuration.Joypad1Down); + dictKey2Motion.Add(EssgeeUnityKey.P1_LEFT, machine.configuration.Joypad1Left); + dictKey2Motion.Add(EssgeeUnityKey.P1_RIGHT, machine.configuration.Joypad1Right); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_1, machine.configuration.Joypad1Button2); + dictKey2Motion.Add(EssgeeUnityKey.P1_BTN_2, machine.configuration.Joypad1Button1); + + dictKey2Motion.Add(EssgeeUnityKey.P2_UP, machine.configuration.Joypad1Up); + dictKey2Motion.Add(EssgeeUnityKey.P2_DOWN, machine.configuration.Joypad1Down); + dictKey2Motion.Add(EssgeeUnityKey.P2_LEFT, machine.configuration.Joypad1Left); + dictKey2Motion.Add(EssgeeUnityKey.P2_RIGHT, machine.configuration.Joypad1Right); + dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_1, machine.configuration.Joypad1Button2); + dictKey2Motion.Add(EssgeeUnityKey.P2_BTN_2, machine.configuration.Joypad1Button1); + } + CheckList = dictKey2Motion.Keys.ToArray(); + + //mUniKeyboard.btnP1.Key = new long[] { (long)MotionKey.P1_GAMESTART }; + //mUniKeyboard.btnCoin1.Key = new long[] { (long)MotionKey.P1_INSERT_COIN }; + //mUniKeyboard.btnA.Key = new long[] { (long)MotionKey.P1_BTN_1 }; + //mUniKeyboard.btnB.Key = new long[] { (long)MotionKey.P1_BTN_2 }; + //mUniKeyboard.btnC.Key = new long[] { (long)MotionKey.P1_BTN_3 }; + //mUniKeyboard.btnD.Key = new long[] { (long)MotionKey.P1_BTN_4 }; + ////mUniKeyboard.btnE.Key = new long[] { (long)MotionKey.P1_BTN_5 }; + ////mUniKeyboard.btnF.Key = new long[] { (long)MotionKey.P1_BTN_6 }; + //mUniKeyboard.btnAB.Key = new long[] { (long)MotionKey.P1_BTN_1, (long)MotionKey.P1_BTN_2 }; + //mUniKeyboard.btnCD.Key = new long[] { (long)MotionKey.P1_BTN_3, (long)MotionKey.P1_BTN_4 }; + //mUniKeyboard.btnABC.Key = new long[] { (long)MotionKey.P1_BTN_1, (long)MotionKey.P1_BTN_2, (long)MotionKey.P1_BTN_3 }; + } + + public bool SampleInput() + { + //Netģʽ + if (InGameUI.Instance.IsNetPlay) + { + bool bHadNetData = false; + int targetFrame; ReplayStep replayData; int frameDiff; bool inputDiff; + if (App.roomMgr.netReplay.TryGetNextFrame((int)Essgeeinit.instance.Frame, out replayData, out frameDiff, out inputDiff)) + { + if (inputDiff) + { + App.log.Debug($"{DateTime.Now.ToString("hh:mm:ss.fff")} TryGetNextFrame remoteFrame->{App.roomMgr.netReplay.mRemoteFrameIdx} diff->{frameDiff} " + + $"frame=>{replayData.FrameStartID} InPut=>{replayData.InPut}"); + } + CurrRemoteInpuAllData = replayData.InPut; + SetCurrKeyArr(CurrRemoteInpuAllData); + bHadNetData = true; + } + else// + { + CurrRemoteInpuAllData = 0; + } + + //ͱز + App.roomMgr.SendRoomSingelPlayerInput(Essgeeinit.instance.Frame, + DoLocalPressedKeys()); + + return bHadNetData; + } + //ģʽ + else + { + ulong inputData = DoLocalPressedKeys(); + SetCurrKeyArr(inputData); + return true; + } + } + + void SetCurrKeyArr(ulong inputData) + { + temp.Clear(); + for (int i = 0; i < CheckList.Length; i++) + { + ulong key = CheckList[i]; + if ((inputData & key) > 0) + { + EssgeeMotionKey mk = dictKey2Motion[key]; + temp.Add(mk); + } + } + mCurrKey = temp.ToArray(); + } + + ulong DoLocalPressedKeys() + { + //tempInputAllData = 0; + //for (int i = 0; i < CheckList.Length; i++) + //{ + // ulong key = CheckList[i]; + // if (Input.GetKey(dictMotion2RealKey[key])) + // { + // EssgeeMotionKey mk = dictKey2Motion[key]; + // tempInputAllData |= (ulong)mk; + // } + //} + //return tempInputAllData; + + ulong tempLocalInputAllData = 0; + tempLocalInputAllData |= ControllerMapper.Controller0.GetSingleAllInput(); + tempLocalInputAllData |= ControllerMapper.Controller1.GetSingleAllInput(); + tempLocalInputAllData |= ControllerMapper.Controller2.GetSingleAllInput(); + tempLocalInputAllData |= ControllerMapper.Controller3.GetSingleAllInput(); + +#if UNITY_EDITOR + if (CurrLocalInpuAllData != tempLocalInputAllData) + { + string ShowKeyNames = string.Empty; + } +#endif + + CurrLocalInpuAllData = tempLocalInputAllData; + + CheckPlayerSlotChanged(); + + return CurrLocalInpuAllData; + } + + + void CheckPlayerSlotChanged() + { + if (!ControllerMapper.Controller0.ConnectSlot.HasValue && ControllerMapper.Controller0.AnyButtonDown()) + Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 0); + + if (!ControllerMapper.Controller1.ConnectSlot.HasValue && ControllerMapper.Controller1.AnyButtonDown()) + Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 1); + + if (!ControllerMapper.Controller2.ConnectSlot.HasValue && ControllerMapper.Controller2.AnyButtonDown()) + Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 2); + + if (!ControllerMapper.Controller3.ConnectSlot.HasValue && ControllerMapper.Controller3.AnyButtonDown()) + Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 3); + } +} + +public static class EssgeeUnityKey +{ + public const ulong NONE = 0; + public const ulong P1_UP = 1; + public const ulong P1_DOWN = 1 << 1; + public const ulong P1_LEFT = 1 << 2; + public const ulong P1_RIGHT = 1 << 3; + public const ulong P1_BTN_1 = 1 << 4; + public const ulong P1_BTN_2 = 1 << 5; + public const ulong P1_BTN_3 = 1 << 6; + public const ulong P1_BTN_4 = 1 << 7; + public const ulong P1_POTION_1 = 1 << 8; + public const ulong P1_POTION_2 = 1 << 9; + public const ulong P2_UP = 65536; + public const ulong P2_DOWN = 65536 << 1; + public const ulong P2_LEFT = 65536 << 2; + public const ulong P2_RIGHT = 65536 << 3; + public const ulong P2_BTN_1 = 65536 << 4; + public const ulong P2_BTN_2 = 65536 << 5; + public const ulong P2_BTN_3 = 65536 << 6; + public const ulong P2_BTN_4 = 65536 << 7; + public const ulong P2_POTION_1 = 65536 << 8; + public const ulong P2_POTION_2 = 65536 << 9; + public const ulong P3_UP = 4294967296; + public const ulong P3_DOWN = 4294967296 << 1; + public const ulong P3_LEFT = 4294967296 << 2; + public const ulong P3_RIGHT = 4294967296 << 3; + public const ulong P3_BTN_1 = 4294967296 << 4; + public const ulong P3_BTN_2 = 4294967296 << 5; + public const ulong P3_BTN_3 = 4294967296 << 6; + public const ulong P3_BTN_4 = 654294967296536 << 7; + public const ulong P3_POTION_1 = 4294967296 << 8; + public const ulong P3_POTION_2 = 4294967296 << 9; + public const ulong P4_UP = 281474976710656; + public const ulong P4_DOWN = 281474976710656 << 1; + public const ulong P4_LEFT = 281474976710656 << 2; + public const ulong P4_RIGHT = 281474976710656 << 3; + public const ulong P4_BTN_1 = 281474976710656 << 4; + public const ulong P4_BTN_2 = 281474976710656 << 5; + public const ulong P4_BTN_3 = 281474976710656 << 6; + public const ulong P4_BTN_4 = 281474976710656 << 7; + public const ulong P4_POTION_1 = 281474976710656 << 8; + public const ulong P4_POTION_2 = 281474976710656 << 9; + public const ulong FinalKey = 281474976710656 << 10; +} + + +public class EssgeeControllerMapper : IControllerSetuper +{ + public EssgssSingleController Controller0 = new EssgssSingleController(0); + public EssgssSingleController Controller1 = new EssgssSingleController(1); + public EssgssSingleController Controller2 = new EssgssSingleController(2); + public EssgssSingleController Controller3 = new EssgssSingleController(3); + + ulong mCurrAllInput; + + public void SetConnect(uint? con0ToSlot = null, + uint? con1ToSlot = null, + uint? con2ToSlot = null, + uint? con3ToSlot = null) + { + Controller0.ConnectSlot = con0ToSlot; + Controller1.ConnectSlot = con1ToSlot; + Controller2.ConnectSlot = con2ToSlot; + Controller3.ConnectSlot = con3ToSlot; + } + public int? GetSlotConnectingControllerIndex(int slotIndex) + { + if (Controller0.ConnectSlot.HasValue && Controller0.ConnectSlot.Value == slotIndex) return 0; + else if (Controller1.ConnectSlot.HasValue && Controller1.ConnectSlot.Value == slotIndex) return 1; + else if (Controller2.ConnectSlot.HasValue && Controller2.ConnectSlot.Value == slotIndex) return 2; + else if (Controller3.ConnectSlot.HasValue && Controller3.ConnectSlot.Value == slotIndex) return 3; + else return null; + } + public IController GetSlotConnectingController(int slotIndex) + { + if (Controller0.ConnectSlot.HasValue && Controller0.ConnectSlot.Value == slotIndex) return Controller0; + else if (Controller1.ConnectSlot.HasValue && Controller1.ConnectSlot.Value == slotIndex) return Controller1; + else if (Controller2.ConnectSlot.HasValue && Controller2.ConnectSlot.Value == slotIndex) return Controller2; + else if (Controller3.ConnectSlot.HasValue && Controller3.ConnectSlot.Value == slotIndex) return Controller3; + else return null; + } + static HashSet s_temp = new HashSet(); + public uint? GetFreeSlotIndex() + { + s_temp.Clear(); + s_temp.Add(0); + s_temp.Add(1); + s_temp.Add(2); + s_temp.Add(3); + + if (Controller0.ConnectSlot.HasValue) s_temp.Remove(Controller0.ConnectSlot.Value); + if (Controller1.ConnectSlot.HasValue) s_temp.Remove(Controller1.ConnectSlot.Value); + if (Controller2.ConnectSlot.HasValue) s_temp.Remove(Controller2.ConnectSlot.Value); + if (Controller3.ConnectSlot.HasValue) s_temp.Remove(Controller3.ConnectSlot.Value); + + if (s_temp.Count > 0) return s_temp.First(); + else return null; + } + public void LetControllerConnect(int conIndex, uint slotIndex) + { + EssgssSingleController targetController; + switch (conIndex) + { + case 0: targetController = Controller0; break; + case 1: targetController = Controller1; break; + case 2: targetController = Controller2; break; + case 3: targetController = Controller3; break; + default: + throw new System.Exception($"Not Allowed conIndex Range: {conIndex}"); + break; + } + if (targetController.ConnectSlot.HasValue) return; + + targetController.ConnectSlot = slotIndex; + Eventer.Instance.PostEvent(EEvent.OnControllerConnectChanged); + } + +} +public class EssgssSingleController : IController +{ + public KeyCode UP, DOWN, LEFT, RIGHT, BTN_1, BTN_2, BTN_3, BTN_4, OPTION_1, OPTION_2; + + public ulong tg_UP, tg_DOWN, tg_LEFT, tg_RIGHT, tg_BTN_1, tg_BTN_2, tg_BTN_3, tg_BTN_4, tg_OPTION_1, tg_OPTION_2; + public ulong CurrLocalSingleAllInput { get; private set; } + + int mControllerIndex; + uint? mConnectSlot; + + /// + /// ָʾֱӵֱ + /// ֵ˸ֱʵϷпƵPlayer + /// [0,3] :Ϊմδ + /// + public uint? ConnectSlot + { + get { return mConnectSlot; } + set { mConnectSlot = value; this.ResetTargetMotionKey(); } + } + + /// + /// + /// ˱ŲǶӦϷеplayer1,player2,player3,player4,Ϊ4ֱʵ + /// [0,3] + /// + public int ControllerIndex + { + get { return mControllerIndex; } + set { mControllerIndex = value; this.LoadControlKeyForConfig(); } + } + + public EssgssSingleController(int controllerIndex) + { + ControllerIndex = controllerIndex; + } + + public bool AnyButtonDown() + { + if (Input.GetKeyDown(UP)) return true; + if (Input.GetKeyDown(DOWN)) return true; + if (Input.GetKeyDown(LEFT)) return true; + if (Input.GetKeyDown(RIGHT)) return true; + if (Input.GetKeyDown(BTN_1)) return true; + if (Input.GetKeyDown(BTN_2)) return true; + if (Input.GetKeyDown(BTN_3)) return true; + if (Input.GetKeyDown(BTN_4)) return true; + if (Input.GetKeyDown(OPTION_1)) return true; + if (Input.GetKeyDown(OPTION_2)) return true; + return false; + } + public ulong GetSingleAllInput() + { + if (!ConnectSlot.HasValue) + return 0; + CurrLocalSingleAllInput = 0; + if (Input.GetKey(UP)) CurrLocalSingleAllInput |= (ulong)tg_UP; + if (Input.GetKey(DOWN)) CurrLocalSingleAllInput |= (ulong)tg_DOWN; + if (Input.GetKey(LEFT)) CurrLocalSingleAllInput |= (ulong)tg_LEFT; + if (Input.GetKey(RIGHT)) CurrLocalSingleAllInput |= (ulong)tg_RIGHT; + if (Input.GetKey(BTN_1)) CurrLocalSingleAllInput |= (ulong)tg_BTN_1; + if (Input.GetKey(BTN_2)) CurrLocalSingleAllInput |= (ulong)tg_BTN_2; + if (Input.GetKey(BTN_3)) CurrLocalSingleAllInput |= (ulong)tg_BTN_3; + if (Input.GetKey(BTN_4)) CurrLocalSingleAllInput |= (ulong)tg_BTN_4; + if (Input.GetKey(OPTION_1)) CurrLocalSingleAllInput |= (ulong)tg_OPTION_1; + if (Input.GetKey(OPTION_2)) CurrLocalSingleAllInput |= (ulong)tg_OPTION_1; + return CurrLocalSingleAllInput; + } +} + + +public static class EssgssSingleControllerSetter +{ + public static void LoadControlKeyForConfig(this EssgssSingleController singlecontrol) + { + //TODO ȴ֧ãͳһ + switch (singlecontrol.ControllerIndex) + { + case 0: + singlecontrol.UP = KeyCode.W; + singlecontrol.DOWN = KeyCode.S; + singlecontrol.LEFT = KeyCode.A; + singlecontrol.RIGHT = KeyCode.D; + singlecontrol.BTN_1 = KeyCode.J; + singlecontrol.BTN_2 = KeyCode.K; + singlecontrol.BTN_3 = KeyCode.L; + singlecontrol.BTN_4 = KeyCode.U; + singlecontrol.OPTION_1 = KeyCode.Return; + singlecontrol.OPTION_2 = KeyCode.LeftShift; + break; + case 1: + singlecontrol.UP = KeyCode.UpArrow; + singlecontrol.DOWN = KeyCode.DownArrow; + singlecontrol.LEFT = KeyCode.LeftArrow; + singlecontrol.RIGHT = KeyCode.RightArrow; + singlecontrol.BTN_1 = KeyCode.Keypad1; + singlecontrol.BTN_2 = KeyCode.Keypad2; + singlecontrol.BTN_3 = KeyCode.Keypad3; + singlecontrol.BTN_4 = KeyCode.Keypad4; + singlecontrol.OPTION_1 = KeyCode.Keypad0; + singlecontrol.OPTION_2 = KeyCode.KeypadPeriod; + break; + case 2: + break; + case 3: + break; + } + } + public static void ResetTargetMotionKey(this EssgssSingleController singlecontrol) + { + if (!singlecontrol.ConnectSlot.HasValue) + { + singlecontrol.tg_UP + = singlecontrol.tg_DOWN + = singlecontrol.tg_LEFT + = singlecontrol.tg_RIGHT + = singlecontrol.tg_BTN_1 + = singlecontrol.tg_BTN_2 + = singlecontrol.tg_BTN_3 + = singlecontrol.tg_BTN_4 + = singlecontrol.tg_OPTION_1 + = singlecontrol.tg_OPTION_2 + = EssgeeUnityKey.FinalKey; + return; + } + switch (singlecontrol.ConnectSlot.Value) + { + case 0: + singlecontrol.tg_UP = EssgeeUnityKey.P1_UP; + singlecontrol.tg_DOWN = EssgeeUnityKey.P1_DOWN; + singlecontrol.tg_LEFT = EssgeeUnityKey.P1_LEFT; + singlecontrol.tg_RIGHT = EssgeeUnityKey.P1_RIGHT; + singlecontrol.tg_BTN_1 = EssgeeUnityKey.P1_BTN_1; + singlecontrol.tg_BTN_2 = EssgeeUnityKey.P1_BTN_2; + singlecontrol.tg_BTN_3 = EssgeeUnityKey.P1_BTN_3; + singlecontrol.tg_BTN_4 = EssgeeUnityKey.P1_BTN_4; + singlecontrol.tg_OPTION_1 = EssgeeUnityKey.P1_POTION_1; + singlecontrol.tg_OPTION_2 = EssgeeUnityKey.P1_POTION_2; + break; + case 1: + singlecontrol.tg_UP = EssgeeUnityKey.P2_UP; + singlecontrol.tg_DOWN = EssgeeUnityKey.P2_DOWN; + singlecontrol.tg_LEFT = EssgeeUnityKey.P2_LEFT; + singlecontrol.tg_RIGHT = EssgeeUnityKey.P2_RIGHT; + singlecontrol.tg_BTN_1 = EssgeeUnityKey.P2_BTN_1; + singlecontrol.tg_BTN_2 = EssgeeUnityKey.P2_BTN_2; + singlecontrol.tg_BTN_3 = EssgeeUnityKey.P2_BTN_3; + singlecontrol.tg_BTN_4 = EssgeeUnityKey.P2_BTN_4; + singlecontrol.tg_OPTION_1 = EssgeeUnityKey.P2_POTION_1; + singlecontrol.tg_OPTION_2 = EssgeeUnityKey.P2_POTION_2; + break; + //޸ĺ ֧P3 P4 + case 2: + singlecontrol.tg_UP = EssgeeUnityKey.P3_UP; + singlecontrol.tg_DOWN = EssgeeUnityKey.P3_DOWN; + singlecontrol.tg_LEFT = EssgeeUnityKey.P3_LEFT; + singlecontrol.tg_RIGHT = EssgeeUnityKey.P3_RIGHT; + singlecontrol.tg_BTN_1 = EssgeeUnityKey.P3_BTN_1; + singlecontrol.tg_BTN_2 = EssgeeUnityKey.P3_BTN_2; + singlecontrol.tg_BTN_3 = EssgeeUnityKey.P3_BTN_3; + singlecontrol.tg_BTN_4 = EssgeeUnityKey.P3_BTN_4; + singlecontrol.tg_OPTION_1 = EssgeeUnityKey.P3_POTION_1; + singlecontrol.tg_OPTION_2 = EssgeeUnityKey.P3_POTION_2; + break; + case 3: + singlecontrol.tg_UP = EssgeeUnityKey.P4_UP; + singlecontrol.tg_DOWN = EssgeeUnityKey.P4_DOWN; + singlecontrol.tg_LEFT = EssgeeUnityKey.P4_LEFT; + singlecontrol.tg_RIGHT = EssgeeUnityKey.P4_RIGHT; + singlecontrol.tg_BTN_1 = EssgeeUnityKey.P4_BTN_1; + singlecontrol.tg_BTN_2 = EssgeeUnityKey.P4_BTN_2; + singlecontrol.tg_BTN_3 = EssgeeUnityKey.P4_BTN_3; + singlecontrol.tg_BTN_4 = EssgeeUnityKey.P4_BTN_4; + singlecontrol.tg_OPTION_1 = EssgeeUnityKey.P4_POTION_1; + singlecontrol.tg_OPTION_2 = EssgeeUnityKey.P4_POTION_2; + break; + } } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGLog.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGLog.cs index e7da1618..7e8ad12a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGLog.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGLog.cs @@ -1,17 +1,19 @@ +using AxibugEmuOnline.Client.ClientCore; + public class UEGLog : IEssgeeLogger { public void Debug(string message) { + App.log.Debug(message); UnityEngine.Debug.Log(message); } - public void Warning(string message) { - UnityEngine.Debug.LogWarning(message); + App.log.Warning(message); } public void Err(string message) { - UnityEngine.Debug.LogError(message); + App.log.Error(message); } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGVideoPlayer.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGVideoPlayer.cs index b9399459..448c0f42 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGVideoPlayer.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGVideoPlayer.cs @@ -18,6 +18,8 @@ public class UEGVideoPlayer : MonoBehaviour private RectTransform m_drawCanvasrect; //byte[] mFrameData; IntPtr mFrameDataPtr; + public Texture2D rawBufferWarper => m_rawBufferWarper; + public RawImage DrawCanvas => m_drawCanvas; private TimeSpan lastElapsed; public double videoFPS { get; private set; } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs index 04c8764b..722ed759 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs @@ -1,6 +1,5 @@ using AxibugEmuOnline.Client; using AxibugEmuOnline.Client.ClientCore; -using AxibugEmuOnline.Client.Network; using AxibugProtobuf; using AxiReplay; using MAME.Core; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UniInterface/UniKeyboard.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UniInterface/UniKeyboard.cs index d1e80dfa..74c8a8ea 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UniInterface/UniKeyboard.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UniInterface/UniKeyboard.cs @@ -7,9 +7,6 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEngine; -using static AxibugEmuOnline.Client.NesControllerMapper; -using static UnityEditor.VersionControl.Asset; -using VirtualNes.Core; public class UniKeyboard : MonoBehaviour, IKeyboard {