From c0af4d4009e276fb844ad83c30c73a942e6ad536 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Wed, 25 Dec 2024 20:48:26 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81,=E8=A7=A3?= =?UTF-8?q?=E8=80=A6=E4=B8=8A=E5=B1=82=E9=80=BB=E8=BE=91=E5=BC=BA=E4=BE=9D?= =?UTF-8?q?=E8=B5=96virtualnes=E6=A0=B8=E5=BF=83=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/AppMain/IEmuCore.cs | 6 +- .../Assets/Script/AppMain/Manager/AppEmu.cs | 4 +- .../AppMain/Manager/ControllerInterface.cs | 39 +++++++ .../Manager/ControllerInterface.cs.meta | 2 + .../AppMain/NesEmulator/CoreSupporter.cs | 18 ++-- .../NesEmulator/NesControllerMapper.cs | 13 ++- .../Script/AppMain/NesEmulator/NesEmulator.cs | 27 +++-- .../AppMain/NesEmulator/PaletteDefine.cs | 2 +- .../Script/AppMain/UI/InGameUI/InGameUI.cs | 4 +- .../UI/XMBTopGroupUI/ControllerInfo.cs | 33 +++--- .../UI/XMBTopGroupUI/ControllerInfoPanel.cs | 6 +- .../Assets/VirtualNes.Core/APU.cs | 18 ++-- .../VirtualNes.Core/ApuEX/APU_INTERNAL.cs | 34 +++--- .../Assets/VirtualNes.Core/CPU.cs | 2 +- .../VirtualNes.Core/Mapper/Mapper072.cs | 2 +- .../VirtualNes.Core/Mapper/Mapper086.cs | 2 +- .../VirtualNes.Core/Mapper/Mapper092.cs | 2 +- .../Assets/VirtualNes.Core/NES.cs | 30 +++--- .../Assets/VirtualNes.Core/PAD.cs | 2 +- .../Assets/VirtualNes.Core/ROM.cs | 8 +- .../VirtualNes.Core/Supporter/Supporter.cs | 100 +----------------- 21 files changed, 165 insertions(+), 189 deletions(-) create mode 100644 AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/ControllerInterface.cs create mode 100644 AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/ControllerInterface.cs.meta diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs index 4a97765..8dc89d0 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; namespace AxibugEmuOnline.Client { @@ -14,7 +14,9 @@ namespace AxibugEmuOnline.Client void Resume(); void SetupScheme(); void StartGame(RomFile romFile); - void DoReset(); + void DoReset(); + IControllerSetuper GetControllerSetuper(); + EnumPlatform Platform { get; } uint Frame { get; } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs index 02c9302..d2be7b5 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs @@ -13,7 +13,7 @@ namespace AxibugEmuOnline.Client.Manager /// private IEmuCore m_emuCore; - private VirtualNes.Core.IControllerSetuper m_controllerSetuper; + private IControllerSetuper m_controllerSetuper; /// /// unity的c#实现有bug,以接口类型保存的monobehaviour引用,!=和==运算符没有调用到monobehaviour重写过的运算符 @@ -63,7 +63,7 @@ namespace AxibugEmuOnline.Client.Manager m_emuCore.SetupScheme(); - m_controllerSetuper = Supporter.GetControllerSetuper(); + m_controllerSetuper = m_emuCore.GetControllerSetuper(); //自动分配0号手柄到0号手柄位 m_controllerSetuper.SetConnect(con0ToSlot: 0); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/ControllerInterface.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/ControllerInterface.cs new file mode 100644 index 0000000..e5958eb --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/ControllerInterface.cs @@ -0,0 +1,39 @@ +/// +/// 负责管理本地控制器与具体游戏之间的槽位分配 +/// +public interface IControllerSetuper +{ + /// + /// 设置本地手柄与游戏手柄槽位的映射,这个方法是一个全量更新手柄插入设置的方法 + /// + void SetConnect( + uint? con0ToSlot = null, + uint? con1ToSlot = null, + uint? con2ToSlot = null, + uint? con3ToSlot = null); + + /// + /// 指定手柄插槽位,获取当前槽位连接的本地手柄序号 + /// + /// + /// + int? GetSlotConnectingControllerIndex(int slotIndex); + IController GetSlotConnectingController(int slotIndex); + + /// + /// 获得一个空的槽位 + /// + /// + uint? GetFreeSlotIndex(); + + /// + /// 增量式的修改一个手柄和一个槽位的连接关系 + /// + /// + /// + void LetControllerConnect(int conIndex, uint slotIndex); +} +public interface IController +{ + bool AnyButtonDown(); +} \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/ControllerInterface.cs.meta b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/ControllerInterface.cs.meta new file mode 100644 index 0000000..511a806 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/ControllerInterface.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f567cb126b157854e9f9b2c71f8cda8e \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs index e5db677..ad32677 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs @@ -1,4 +1,4 @@ -using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.ClientCore; using AxiReplay; using System; using System.IO; @@ -10,6 +10,12 @@ namespace AxibugEmuOnline.Client { public class CoreSupporter : ISupporterImpl { + private NesControllerMapper m_controllerMapper; + public CoreSupporter(NesControllerMapper conMapper) + { + m_controllerMapper = conMapper; + } + public Stream OpenRom(string fname) { try @@ -57,7 +63,6 @@ namespace AxibugEmuOnline.Client } public EmulatorConfig Config { get; private set; } = new EmulatorConfig(); - public NesControllerMapper ControllerMapper { get; private set; } = new NesControllerMapper(); public void PrepareDirectory(string directPath) { Directory.CreateDirectory($"{App.PersistentDataPath}/{directPath}"); @@ -116,7 +121,7 @@ namespace AxibugEmuOnline.Client } else m_sampledState = default(ControllerState); - var localState = ControllerMapper.CreateState(); + var localState = m_controllerMapper.CreateState(); var rawData = ToNet(localState); if (LastTestInput != rawData) { @@ -127,15 +132,10 @@ namespace AxibugEmuOnline.Client } else { - m_sampledState = ControllerMapper.CreateState(); + m_sampledState = m_controllerMapper.CreateState(); } } - public IControllerSetuper GetControllerSetuper() - { - return ControllerMapper; - } - public ControllerState FromNet(AxiReplay.ReplayStep step) { var temp = new ServerInputSnapShot(); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs index 6886e47..23b6e8f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs @@ -46,7 +46,7 @@ namespace AxibugEmuOnline.Client Controller3.ConnectSlot = con3ToSlot; } - public int? GetSlotConnectingController(int slotIndex) + 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; @@ -55,6 +55,15 @@ namespace AxibugEmuOnline.Client 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(4); public uint? GetFreeSlotIndex() { @@ -94,7 +103,7 @@ namespace AxibugEmuOnline.Client /// /// Nes控制器 /// - public class Controller + public class Controller : IController { /// /// 控制器编号 diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs index 402e380..1b2c9f0 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs @@ -21,7 +21,13 @@ namespace AxibugEmuOnline.Client public NES NesCore { get; private set; } /// 是否暂停 - public bool IsPause { get; private set; } + public bool IsPause { get; private set; } + public NesControllerMapper ControllerMapper { get; private set; } + + private void Awake() + { + ControllerMapper = new NesControllerMapper(); + } private void Start() { @@ -48,12 +54,11 @@ namespace AxibugEmuOnline.Client VideoProvider.SetDrawData(screenBuffer); } - VideoProvider.ApplyFilterEffect(); } public EnumPlatform Platform => EnumPlatform.NES; - + private CoreSupporter m_coreSupporter; /// /// 指定ROM开始游戏 /// @@ -61,7 +66,8 @@ namespace AxibugEmuOnline.Client { StopGame(); - Supporter.Setup(new CoreSupporter()); + m_coreSupporter = new CoreSupporter(ControllerMapper); + Supporter.Setup(m_coreSupporter); Debuger.Setup(new CoreDebuger()); App.nesRomLib.AddRomFile(rom); @@ -159,8 +165,8 @@ namespace AxibugEmuOnline.Client //推进帧 private bool PushEmulatorFrame() { - Supporter.SampleInput(NesCore.FrameCount); - var controlState = Supporter.GetControllerState(); + m_coreSupporter.SampleInput(NesCore.FrameCount); + var controlState = m_coreSupporter.GetControllerState(); //如果未收到Input数据,核心帧不推进 if (!controlState.valid) return false; @@ -205,8 +211,13 @@ namespace AxibugEmuOnline.Client EditorUtility.SetDirty(db); AssetDatabase.SaveAssets(); - } - + } + + public IControllerSetuper GetControllerSetuper() + { + return ControllerMapper; + } + #endif } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/PaletteDefine.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/PaletteDefine.cs index 1cfef39..bd1c78a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/PaletteDefine.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/PaletteDefine.cs @@ -27,7 +27,7 @@ namespace AxibugEmuOnline.Client } // スキャンラインカラー - private static int m_nScanlineColor => Supporter.Config.graphics.nScanlineColor; + private static int m_nScanlineColor => 75; //patternViewer调试器用的,参照EmulatorConfig.graphics.nScanlineColor的值 public static float[][] PalConvTbl = new float[8][] { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs index 17eeb8c..42dd0ad 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs @@ -117,10 +117,10 @@ namespace AxibugEmuOnline.Client m_delayCreateRoom = false; //延迟创建房间成功后,同步本地手柄连接状态 Dictionary temp = new Dictionary(); - var setuper = Supporter.GetControllerSetuper(); + var setuper = App.emu.Core.GetControllerSetuper(); for (int i = 0; i < 4; i++) { - var joyIndex = setuper.GetSlotConnectingController(i); + var joyIndex = setuper.GetSlotConnectingControllerIndex(i); if (joyIndex != null) temp[(uint)i] = (uint)joyIndex.Value; } App.roomMgr.SendChangePlaySlotIdxWithJoyIdx(temp); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs index 3feabb0..f8b1c77 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs @@ -1,6 +1,7 @@ using AxibugEmuOnline.Client; using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.Event; +using DG.Tweening; using System; using UnityEngine; using UnityEngine.UI; @@ -18,9 +19,7 @@ public class ControllerInfo : MonoBehaviour Image m_indexIcon; [SerializeField] Text m_playerName; - - int m_localJoyIndex; - bool m_isLocal; + private bool m_islocal; public int SlotIndex { @@ -60,6 +59,18 @@ public class ControllerInfo : MonoBehaviour Eventer.Instance.UnregisterEvent(EEvent.OnControllerConnectChanged, OnControlConnectChanged); } + private void Update() + { + if (m_islocal) + { + var controller = App.emu.Core.GetControllerSetuper().GetSlotConnectingController(m_slotIndex); + if (controller == null) return; + if (!controller.AnyButtonDown()) return; + + m_indexIcon.rectTransform.DOShakePosition(0.1f); + } + } + private void OnMineRoomCreated() => UpdateConnectInfo(); private void OnJoinRoom() => UpdateConnectInfo(); private void OnLeaveRoom() => UpdateConnectInfo(); @@ -79,14 +90,15 @@ public class ControllerInfo : MonoBehaviour } else { - var connecter = Supporter.GetControllerSetuper(); - if (connecter == null) + if (App.emu.Core.IsNull()) { SetDisconnect(); return; - } - var localControlIndex = connecter.GetSlotConnectingController(SlotIndex); + } + var connecter = App.emu.Core.GetControllerSetuper(); + + var localControlIndex = connecter.GetSlotConnectingControllerIndex(SlotIndex); if (localControlIndex == null) SetDisconnect(); else @@ -101,8 +113,7 @@ public class ControllerInfo : MonoBehaviour private void UpdateStateView(bool isLocal, string playerName, int slotIndex) { - m_localJoyIndex = slotIndex; - m_isLocal = isLocal; + m_islocal = isLocal; m_connectInfoNode.SetActiveEx(true); m_playerName.text = playerName; @@ -110,11 +121,9 @@ public class ControllerInfo : MonoBehaviour private void SetDisconnect() { - m_localJoyIndex = -1; - m_isLocal = false; - m_connectInfoNode.SetActiveEx(false); m_playerName.text = null; + m_islocal = false; } private void UpdateIndexIcon() diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs index 871541c..137a6de 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs @@ -1,4 +1,5 @@ -using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client; +using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.Event; using AxibugEmuOnline.Client.Manager; using System; @@ -31,7 +32,8 @@ public class ControllerInfoPanel : MonoBehaviour } else //不在房间中,直接设置 { - var setuper = Supporter.GetControllerSetuper(); + if (App.emu.Core.IsNull()) return; + var setuper = App.emu.Core.GetControllerSetuper(); if (setuper == null) return; var freeSlotIndex = setuper.GetFreeSlotIndex(); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/APU.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/APU.cs index eae930a..03ab741 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/APU.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/APU.cs @@ -73,7 +73,7 @@ namespace VirtualNes.Core public void Process(ISoundDataBuffer lpBuffer, uint dwSize) { - int nBits = Supporter.Config.sound.nBits; + int nBits = Supporter.S.Config.sound.nBits; uint dwLength = (uint)(dwSize / (nBits / 8)); int output; QUEUEDATA q = new QUEUEDATA(); @@ -82,11 +82,11 @@ namespace VirtualNes.Core var pSoundBuf = m_SoundBuffer; int nCcount = 0; - int nFilterType = Supporter.Config.sound.nFilterType; + int nFilterType = Supporter.S.Config.sound.nFilterType; - if (!Supporter.Config.sound.bEnable) + if (!Supporter.S.Config.sound.bEnable) { - byte empty = (byte)(Supporter.Config.sound.nRate == 8 ? 128 : 0); + byte empty = (byte)(Supporter.S.Config.sound.nRate == 8 ? 128 : 0); for (int i = 0; i < dwSize; i++) lpBuffer.WriteByte(empty); return; @@ -108,7 +108,7 @@ namespace VirtualNes.Core MemoryUtility.ZEROMEMORY(vol, vol.Length); var bMute = m_bMute; - var nVolume = Supporter.Config.sound.nVolume; + var nVolume = Supporter.S.Config.sound.nVolume; int nMasterVolume = bMute[0] ? nVolume[0] : 0; @@ -151,7 +151,7 @@ namespace VirtualNes.Core vol[23] = (int)(bMute[8] ? (FME7_VOL * nVolume[11] * nMasterVolume) / (100 * 100) : 0); // double cycle_rate = ((double)FRAME_CYCLES*60.0/12.0)/(double)Config.sound.nRate; - double cycle_rate = (nes.nescfg.FrameCycles * 60.0 / 12.0) / Supporter.Config.sound.nRate; + double cycle_rate = (nes.nescfg.FrameCycles * 60.0 / 12.0) / Supporter.S.Config.sound.nRate; // CPUサイクル数がループしてしまった時の対策処理 if (elapsed_time > nes.cpu.GetTotalCycles()) @@ -253,7 +253,7 @@ namespace VirtualNes.Core // DC成分のカット(HPF TEST) { // static double cutoff = (2.0*3.141592653579*40.0/44100.0); - double cutoff = cutofftemp / Supporter.Config.sound.nRate; + double cutoff = cutofftemp / Supporter.S.Config.sound.nRate; double @in, @out; @in = output; @@ -436,7 +436,7 @@ namespace VirtualNes.Core public void SoundSetup() { float fClock = nes.nescfg.CpuClock; - int nRate = Supporter.Config.sound.nRate; + int nRate = Supporter.S.Config.sound.nRate; @internal.Setup(fClock, nRate); vrc6.Setup(fClock, nRate); @@ -460,7 +460,7 @@ namespace VirtualNes.Core elapsed_time = 0; float fClock = nes.nescfg.CpuClock; - int nRate = Supporter.Config.sound.nRate; + int nRate = Supporter.S.Config.sound.nRate; @internal.Reset(fClock, nRate); vrc6.Reset(fClock, nRate); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ApuEX/APU_INTERNAL.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ApuEX/APU_INTERNAL.cs index 0fffa03..4f0a023 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ApuEX/APU_INTERNAL.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ApuEX/APU_INTERNAL.cs @@ -1,4 +1,4 @@ - + using System; namespace VirtualNes.Core @@ -184,15 +184,15 @@ namespace VirtualNes.Core Setup(fClock, nRate); - // $4011ϳڻʤ + // $4011は初期化しない ushort addr; for (addr = 0x4000; addr <= 0x4010; addr++) { Write(addr, 0x00); SyncWrite(addr, 0x00); } - // Write( 0x4001, 0x08 ); // Resetrinc`ɤˤʤ? - // Write( 0x4005, 0x08 ); // Resetrinc`ɤˤʤ? + // Write( 0x4001, 0x08 ); // Reset時はincモードになる? + // Write( 0x4005, 0x08 ); // Reset時はincモードになる? Write(0x4012, 0x00); Write(0x4013, 0x00); Write(0x4015, 0x00); @@ -200,7 +200,7 @@ namespace VirtualNes.Core SyncWrite(0x4013, 0x00); SyncWrite(0x4015, 0x00); - // $4017ϕzߤdzڻʤ(ڥ`ɤ0ǤΤڴեȤ) + // $4017は書き込みで初期化しない(初期モードが0であるのを期待したソフトがある為) FrameIRQ = 0xC0; FrameCycle = 0; FrameIRQoccur = 0; @@ -301,7 +301,7 @@ namespace VirtualNes.Core case 0x4017: break; - // VirtuaNESХݩ` + // VirtuaNES固有ポート case 0x4018: UpdateRectangle(ch0, data); UpdateRectangle(ch1, data); @@ -635,7 +635,7 @@ namespace VirtualNes.Core } } - // ץΥå(TEST) + // インチキ臭いプチノイズカット(TEST) ch4.dpcm_output_real = ((ch4.reg[1] & 0x01) + ch4.dpcm_value * 2) - 0x40; if (Math.Abs(ch4.dpcm_output_real - ch4.dpcm_output_fake) <= 8) { @@ -712,7 +712,7 @@ namespace VirtualNes.Core private int RenderTriangle() { int vol; - if (Supporter.Config.sound.bDisableVolumeEffect) + if (Supporter.S.Config.sound.bDisableVolumeEffect) { vol = 256; } @@ -731,7 +731,7 @@ namespace VirtualNes.Core return ch2.nowvolume * vol / 256; } - if (!(Supporter.Config.sound.bChangeTone && ChannelTone[2, 0] != 0)) + if (!(Supporter.S.Config.sound.bChangeTone && ChannelTone[2, 0] != 0)) { ch2.phaseacc -= cycle_rate; if (ch2.phaseacc >= 0) @@ -756,7 +756,7 @@ namespace VirtualNes.Core return ch2.nowvolume * vol / 256; } - // ƽ + // 加重平均 int num_times, total; num_times = total = 0; while (ch2.phaseacc < 0) @@ -799,7 +799,7 @@ namespace VirtualNes.Core return ch2.nowvolume * vol / 256; } - // ƽ + // 加重平均 int num_times, total; num_times = total = 0; while (ch2.phaseacc < 0) @@ -832,9 +832,9 @@ namespace VirtualNes.Core } int volume = ch.nowvolume; - if (!(Supporter.Config.sound.bChangeTone && (ChannelTone[(ch.complement == 0) ? 0 : 1, ch.reg[0] >> 6]) != 0)) + if (!(Supporter.S.Config.sound.bChangeTone && (ChannelTone[(ch.complement == 0) ? 0 : 1, ch.reg[0] >> 6]) != 0)) { - // agI + // 補間処理 double total; double sample_weight = ch.phaseacc; if (sample_weight > cycle_rate) @@ -864,7 +864,7 @@ namespace VirtualNes.Core int x = ChannelTone[(ch.complement == 0) ? 0 : 1, ch.reg[0] >> 6] - 1; int pTone = 0; - // Ÿo + // 更新無し ch.phaseacc -= cycle_rate * 2; if (ch.phaseacc >= 0) { @@ -872,7 +872,7 @@ namespace VirtualNes.Core return temp * volume / ((1 << RECTANGLE_VOL_SHIFT) / 2); } - // 1ƥåפ + // 1ステップだけ更新 int freq = INT2FIX(ch.freq + 1); if (freq > cycle_rate * 2) { @@ -882,7 +882,7 @@ namespace VirtualNes.Core return temp * volume / ((1 << RECTANGLE_VOL_SHIFT) / 2); } - // ƽ + // 加重平均 int num_times, total; num_times = total = 0; while (ch.phaseacc < 0) @@ -1015,7 +1015,7 @@ namespace VirtualNes.Core SyncWrite4017(data); break; - // VirtuaNESŗL|[g + // VirtuaNES屌桳億乕僩 case 0x4018: SyncUpdateRectangle(ch0, data); SyncUpdateRectangle(ch1, data); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/CPU.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/CPU.cs index a17c7b9..db10544 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/CPU.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/CPU.cs @@ -1110,7 +1110,7 @@ namespace VirtualNes.Core case 0xD2: /* JAM */ case 0xF2: /* JAM */ default: - if (!Supporter.Config.emulator.bIllegalOp) + if (!Supporter.S.Config.emulator.bIllegalOp) { throw new Exception("IllegalOp"); } diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper072.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper072.cs index 9fc7dc3..4ee74d2 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper072.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper072.cs @@ -40,7 +40,7 @@ namespace VirtualNes.Core Debuger.Log($"SOUND CODE:{addr & 0x1F:X2}"); // OSDにするべきか… - if (Supporter.Config.sound.bExtraSoundEnable) + if (Supporter.S.Config.sound.bExtraSoundEnable) { //TODO : 似乎VirtuaNES有直接播放某个音频文件的功能 //DirectSound.EsfAllStop(); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper086.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper086.cs index 694e267..038da74 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper086.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper086.cs @@ -43,7 +43,7 @@ namespace VirtualNes.Core } // OSDにするべきか… - if (Supporter.Config.sound.bExtraSoundEnable) + if (Supporter.S.Config.sound.bExtraSoundEnable) { //TODO : 似乎VirtuaNES有直接播放某个音频文件的功能 //DirectSound.EsfAllStop(); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper092.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper092.cs index 89d244b..2dcb122 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper092.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Mapper/Mapper092.cs @@ -57,7 +57,7 @@ namespace VirtualNes.Core 9,10, 8,11,13,12,14,15 }; // OSDにするべきか… - if (Supporter.Config.sound.bExtraSoundEnable) + if (Supporter.S.Config.sound.bExtraSoundEnable) { //TODO : 似乎VirtuaNES有直接播放某个音频文件的功能 Debuger.Log($"CODE {data:X2}"); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs index 93276bb..e334a58 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs @@ -326,7 +326,7 @@ namespace VirtualNes.Core if (pad.GetExController() != (int)EXCONTROLLER.EXCONTROLLER_TURBOFILE) return; - var fp = Supporter.OpenFile(Supporter.Config.path.szSavePath, "TurboFile.vtf"); + var fp = Supporter.S.OpenFile(Supporter.S.Config.path.szSavePath, "TurboFile.vtf"); try { if (fp == null) @@ -367,10 +367,10 @@ namespace VirtualNes.Core if (!rom.IsSAVERAM()) return; - var saveFileDir = Supporter.Config.path.szSavePath; + var saveFileDir = Supporter.S.Config.path.szSavePath; var saveFileName = $"{rom.GetRomName()}.sav"; - var fp = Supporter.OpenFile(saveFileDir, saveFileName); + var fp = Supporter.S.OpenFile(saveFileDir, saveFileName); try { @@ -502,13 +502,13 @@ namespace VirtualNes.Core EmulationCPU(nescfg.ScanlineCycles); if (bDraw) { - ppu.Scanline(scanline, Supporter.Config.graphics.bAllSprite, Supporter.Config.graphics.bLeftClip); + ppu.Scanline(scanline, Supporter.S.Config.graphics.bAllSprite, Supporter.S.Config.graphics.bLeftClip); } else { if (pad.IsZapperMode() && scanline == ZapperY) { - ppu.Scanline(scanline, Supporter.Config.graphics.bAllSprite, Supporter.Config.graphics.bLeftClip); + ppu.Scanline(scanline, Supporter.S.Config.graphics.bAllSprite, Supporter.S.Config.graphics.bLeftClip); } else { @@ -518,7 +518,7 @@ namespace VirtualNes.Core } else { - ppu.Scanline(scanline, Supporter.Config.graphics.bAllSprite, Supporter.Config.graphics.bLeftClip); + ppu.Scanline(scanline, Supporter.S.Config.graphics.bAllSprite, Supporter.S.Config.graphics.bLeftClip); } } } @@ -535,13 +535,13 @@ namespace VirtualNes.Core EmulationCPU(nescfg.HDrawCycles); if (bDraw) { - ppu.Scanline(scanline, Supporter.Config.graphics.bAllSprite, Supporter.Config.graphics.bLeftClip); + ppu.Scanline(scanline, Supporter.S.Config.graphics.bAllSprite, Supporter.S.Config.graphics.bLeftClip); } else { if (pad.IsZapperMode() && scanline == ZapperY) { - ppu.Scanline(scanline, Supporter.Config.graphics.bAllSprite, Supporter.Config.graphics.bLeftClip); + ppu.Scanline(scanline, Supporter.S.Config.graphics.bAllSprite, Supporter.S.Config.graphics.bLeftClip); } else { @@ -551,7 +551,7 @@ namespace VirtualNes.Core } else { - ppu.Scanline(scanline, Supporter.Config.graphics.bAllSprite, Supporter.Config.graphics.bLeftClip); + ppu.Scanline(scanline, Supporter.S.Config.graphics.bAllSprite, Supporter.S.Config.graphics.bLeftClip); } } } @@ -658,7 +658,7 @@ namespace VirtualNes.Core // 僗僋儕乕儞昤夋(Scanline 1乣239) if (bDraw) { - ppu.Scanline(scanline, Supporter.Config.graphics.bAllSprite, Supporter.Config.graphics.bLeftClip); + ppu.Scanline(scanline, Supporter.S.Config.graphics.bAllSprite, Supporter.S.Config.graphics.bLeftClip); ppu.ScanlineNext(); EmulationCPU(FETCH_CYCLES * 10); mapper.HSync(scanline); @@ -670,7 +670,7 @@ namespace VirtualNes.Core { if (pad.IsZapperMode() && scanline == ZapperY) { - ppu.Scanline(scanline, Supporter.Config.graphics.bAllSprite, Supporter.Config.graphics.bLeftClip); + ppu.Scanline(scanline, Supporter.S.Config.graphics.bAllSprite, Supporter.S.Config.graphics.bLeftClip); ppu.ScanlineNext(); EmulationCPU(FETCH_CYCLES * 10); mapper.HSync(scanline); @@ -694,7 +694,7 @@ namespace VirtualNes.Core } else { - ppu.Scanline(scanline, Supporter.Config.graphics.bAllSprite, Supporter.Config.graphics.bLeftClip); + ppu.Scanline(scanline, Supporter.S.Config.graphics.bAllSprite, Supporter.S.Config.graphics.bLeftClip); ppu.ScanlineNext(); EmulationCPU(FETCH_CYCLES * 10); mapper.HSync(scanline); @@ -1095,7 +1095,7 @@ namespace VirtualNes.Core Debuger.Log($"Saving SAVERAM...[{romName}]"); - Supporter.SaveSRAMToFile(MMU.WRAM, romName); + Supporter.S.SaveSRAMToFile(MMU.WRAM, romName); } } @@ -1143,7 +1143,7 @@ namespace VirtualNes.Core } } - Supporter.SaveDISKToFile(contents.ToArray(), rom.GetRomName()); + Supporter.S.SaveDISKToFile(contents.ToArray(), rom.GetRomName()); } catch (Exception ex) { @@ -1168,7 +1168,7 @@ namespace VirtualNes.Core { Debuger.Log("Saving TURBOFILE..."); - Supporter.SaveFile(MMU.ERAM, Supporter.Config.path.szSavePath, "TurboFile.vtf"); + Supporter.S.SaveFile(MMU.ERAM, Supporter.S.Config.path.szSavePath, "TurboFile.vtf"); } } diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/PAD.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/PAD.cs index 2b2e5b4..f0cc6b3 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/PAD.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/PAD.cs @@ -181,7 +181,7 @@ namespace VirtualNes.Core } else { - if (Supporter.Config.emulator.bFourPlayer) + if (Supporter.S.Config.emulator.bFourPlayer) { // NES type pad1bit = padbitsync[0] | ((uint)padbitsync[2] << 8) | 0x00080000; diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs index 718c08f..53a1005 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs @@ -50,7 +50,7 @@ namespace VirtualNes.Core try { - fp = Supporter.OpenRom(fname); + fp = Supporter.S.OpenRom(fname); if (fp == null) { throw new System.Exception($"Open Rom Failed:[{fname}]"); @@ -167,7 +167,7 @@ namespace VirtualNes.Core lpPRG[3] = 0x1A; lpPRG[4] = (byte)diskno; - fp = Supporter.OpenFile_DISKSYS(); + fp = Supporter.S.OpenFile_DISKSYS(); if (fp == null) { throw new Exception($"Not found DISKSYS.ROM for [{fname}]"); @@ -217,7 +217,7 @@ namespace VirtualNes.Core throw new Exception($"Unsupport format:[{fname}]"); } - Supporter.GetFilePathInfo(fname, out fullpath, out path); + Supporter.S.GetRomPathInfo(fname, out fullpath, out path); name = Path.GetFileNameWithoutExtension(fullpath); if (!bNSF) { @@ -244,7 +244,7 @@ namespace VirtualNes.Core FileNameCheck(fname); - if (Supporter.TryGetMapperNo(this, out int mapperNo)) + if (Supporter.S.TryGetMapperNo(this, out int mapperNo)) { Debuger.Log($"ROMDB Set Mapper #{mapper:000} to #{mapperNo:000}"); mapper = mapperNo; diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs index 913e2f5..3287ab8 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs @@ -5,73 +5,12 @@ namespace VirtualNes.Core public static class Supporter { private static ISupporterImpl s_support; + internal static ISupporterImpl S => s_support; public static void Setup(ISupporterImpl supporter) { s_support = supporter; } - - public static Stream OpenRom(string fname) - { - return s_support.OpenRom(fname); - } - - public static void GetFilePathInfo(string fname, out string fullPath, out string directPath) - { - s_support.GetRomPathInfo(fname, out fullPath, out directPath); - } - - public static Stream OpenFile_DISKSYS() - { - return s_support.OpenFile_DISKSYS(); - } - - public static void SaveSRAMToFile(byte[] sramContent, string romName) - { - s_support.SaveSRAMToFile(sramContent, romName); - } - - public static void SaveDISKToFile(byte[] diskFileContent, string romName) - { - s_support.SaveDISKToFile(diskFileContent, romName); - } - - public static void PrepareDirectory(string directPath) - { - s_support.PrepareDirectory(directPath); - } - - public static void SaveFile(byte[] fileData, string directPath, string fileName) - { - s_support.SaveFile(fileData, directPath, fileName); - } - - public static Stream OpenFile(string directPath, string fileName) - { - return s_support.OpenFile(directPath, fileName); - } - - public static bool TryGetMapperNo(ROM rom, out int mapperNo) - { - return s_support.TryGetMapperNo(rom, out mapperNo); - } - - public static ControllerState GetControllerState() - { - return s_support.GetControllerState(); - } - - public static void SampleInput(uint frameCount) - { - s_support.SampleInput(frameCount); - } - - public static IControllerSetuper GetControllerSetuper() - { - return s_support?.GetControllerSetuper(); - } - - public static EmulatorConfig Config => s_support.Config; } public interface ISupporterImpl @@ -82,48 +21,11 @@ namespace VirtualNes.Core void SaveSRAMToFile(byte[] sramContent, string romName); void SaveDISKToFile(byte[] diskFileContent, string romName); EmulatorConfig Config { get; } - void PrepareDirectory(string directPath); void SaveFile(byte[] fileData, string directPath, string fileName); Stream OpenFile(string directPath, string fileName); bool TryGetMapperNo(ROM rom, out int mapperNo); ControllerState GetControllerState(); void SampleInput(uint frameCount); - IControllerSetuper GetControllerSetuper(); - } - - /// - /// 负责管理本地控制器与具体游戏之间的槽位分配 - /// - public interface IControllerSetuper - { - /// - /// 设置本地手柄与游戏手柄槽位的映射,这个方法是一个全量更新手柄插入设置的方法 - /// - void SetConnect( - uint? con0ToSlot = null, - uint? con1ToSlot = null, - uint? con2ToSlot = null, - uint? con3ToSlot = null); - - /// - /// 指定手柄插槽位,获取当前槽位连接的本地手柄序号 - /// - /// - /// - int? GetSlotConnectingController(int slotIndex); - - /// - /// 获得一个空的槽位 - /// - /// - uint? GetFreeSlotIndex(); - - /// - /// 增量式的修改一个手柄和一个槽位的连接关系 - /// - /// - /// - void LetControllerConnect(int conIndex, uint slotIndex); } } \ No newline at end of file