From 967ef7c99586272de7345b38bafba8991d20579b Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Thu, 9 Dec 2021 15:47:49 -0500 Subject: [PATCH] NESHawk: move defining controller out of hardreset, fixes loading subneshawk --- .../Consoles/Nintendo/NES/NES.Core.cs | 69 ++++++++++--------- .../Consoles/Nintendo/NES/NES.cs | 2 + .../Nintendo/SubNESHawk/SubNESHawk.cs | 3 + 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs index a899f49183..d2d65b5fa2 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs @@ -88,6 +88,41 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public bool CanProvideAsync => false; + public void ResetControllerDefinition() + { + ControllerDefinition = null; + + ControllerDeck = ControllerSettings.Instantiate(ppu.LightGunCallback); + ControllerDefinition = ControllerDeck.ControllerDef; + + // controls other than the deck + ControllerDefinition.BoolButtons.Add("Power"); + ControllerDefinition.BoolButtons.Add("Reset"); + if (Board is FDS b) + { + ControllerDefinition.BoolButtons.Add("FDS Eject"); + for (int i = 0; i < b.NumSides; i++) + { + ControllerDefinition.BoolButtons.Add("FDS Insert " + i); + } + } + + if (_isVS) + { + ControllerDefinition.BoolButtons.Add("Insert Coin P1"); + ControllerDefinition.BoolButtons.Add("Insert Coin P2"); + ControllerDefinition.BoolButtons.Add("Service Switch"); + } + + // Add in the reset timing axis for subneshawk + if (using_reset_timing && ControllerDefinition.Axes.Count == 0) + { + ControllerDefinition.AddAxis("Reset Cycle", 0.RangeTo(500000), 0); + } + + ControllerDefinition.MakeImmutable(); + } + public void SetSyncMode(SyncSoundMode mode) { if (mode != SyncSoundMode.Sync) @@ -145,40 +180,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ram = new byte[0x800]; CIRAM = new byte[0x800]; - // set controller definition first time only - if (ControllerDefinition == null) - { - ControllerDeck = ControllerSettings.Instantiate(ppu.LightGunCallback); // this assignment was outside the conditional for some reason? --yoshi - ControllerDefinition = ControllerDeck.ControllerDef; - - // controls other than the deck - ControllerDefinition.BoolButtons.Add("Power"); - ControllerDefinition.BoolButtons.Add("Reset"); - if (Board is FDS b) - { - ControllerDefinition.BoolButtons.Add("FDS Eject"); - for (int i = 0; i < b.NumSides; i++) - { - ControllerDefinition.BoolButtons.Add("FDS Insert " + i); - } - } - - if (_isVS) - { - ControllerDefinition.BoolButtons.Add("Insert Coin P1"); - ControllerDefinition.BoolButtons.Add("Insert Coin P2"); - ControllerDefinition.BoolButtons.Add("Service Switch"); - } - } - - // Add in the reset timing axis for subneshawk - if (using_reset_timing && ControllerDefinition.Axes.Count == 0) - { - ControllerDefinition.AddAxis("Reset Cycle", 0.RangeTo(500000), 0); - } - - ControllerDefinition.MakeImmutable(); - // don't replace the magicSoundProvider on reset, as it's not needed // if (magicSoundProvider != null) magicSoundProvider.Dispose(); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs index f8152dfb21..a40c3f34a5 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs @@ -70,6 +70,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ser.Register(reader); } } + + ResetControllerDefinition(); } private static readonly bool USE_DATABASE = true; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs index 3f59a91cfa..d7a6d0dc93 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs @@ -19,6 +19,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SubNESHawk using_reset_timing = true }; + // Adds Reset timing control to controller definition + _nesCore.ResetControllerDefinition(); + HardReset(); current_cycle = 0; _nesCore.cpu.ext_ppu_cycle = current_cycle;