From 211883889b683d94622e10f042fc69b4f71a5d80 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 14 Mar 2020 15:08:24 -0500 Subject: [PATCH] simplify CoreCom copying by implementing a Clone method, simplifies all the cores that have cores in them, this copies a lot more things than the original code had but it seems that's either fine or fixing broken stuff --- BizHawk.Emulation.Common/CoreComms.cs | 2 ++ .../Consoles/Nintendo/GBHawkLink/GBHawkLink.cs | 7 ++----- .../Nintendo/GBHawkLink3x/GBHawkLink3x.cs | 11 +++-------- .../Nintendo/GBHawkLink4x/GBHawkLink4x.cs | 15 ++++----------- .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 6 ++---- .../Consoles/Nintendo/SubGBHawk/SubGBHawk.cs | 3 +-- .../Consoles/Nintendo/SubNESHawk/SubNESHawk.cs | 4 +--- .../Consoles/Sega/GGHawkLink/GGHawkLink.cs | 9 +++------ BizHawk.sln.DotSettings | 1 + 9 files changed, 19 insertions(+), 39 deletions(-) diff --git a/BizHawk.Emulation.Common/CoreComms.cs b/BizHawk.Emulation.Common/CoreComms.cs index 9259c6b479..874a73f4d3 100644 --- a/BizHawk.Emulation.Common/CoreComms.cs +++ b/BizHawk.Emulation.Common/CoreComms.cs @@ -17,6 +17,8 @@ namespace BizHawk.Emulation.Common Notify = notifyMessage; } + public CoreComm Clone() => (CoreComm)MemberwiseClone(); + public ICoreFileProvider CoreFileProvider { get; set; } // a core should set these if you wish to provide rom status information yourself. otherwise it will be calculated by the frontend in a way you may not like, using RomGame-related concepts. diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.cs index 694cd2b944..eded6639f2 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.cs @@ -57,11 +57,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink temp_sync_L.RTCOffset = linkSyncSettings.RTCOffset_L; temp_sync_R.RTCOffset = linkSyncSettings.RTCOffset_R; - L = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game_L, rom_L, temp_set_L, temp_sync_L); - - R = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game_R, rom_R, temp_set_R, temp_sync_R); + L = new GBHawk.GBHawk(comm.Clone(), game_L, rom_L, temp_set_L, temp_sync_L); + R = new GBHawk.GBHawk(comm.Clone(), game_R, rom_R, temp_set_R, temp_sync_R); ser.Register(this); ser.Register(this); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.cs index a2f5e9fe5c..fdeb18dc1d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.cs @@ -63,14 +63,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x tempSyncC.RTCOffset = Link3xSyncSettings.RTCOffset_C; tempSyncR.RTCOffset = Link3xSyncSettings.RTCOffset_R; - L = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game_L, rom_L, tempSetL, tempSyncL); - - C = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game_C, rom_C, tempSetC, tempSyncC); - - R = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game_R, rom_R, tempSetR, tempSyncR); + L = new GBHawk.GBHawk(comm.Clone(), game_L, rom_L, tempSetL, tempSyncL); + C = new GBHawk.GBHawk(comm.Clone(), game_C, rom_C, tempSetC, tempSyncC); + R = new GBHawk.GBHawk(comm.Clone(), game_R, rom_R, tempSetR, tempSyncR); ser.Register(this); ser.Register(this); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.cs index ee1bd7d1cc..85440d9ddd 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.cs @@ -90,17 +90,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x tempSyncC.RTCOffset = Link4xSyncSettings.RTCOffset_C; tempSyncD.RTCOffset = Link4xSyncSettings.RTCOffset_D; - A = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game_A, rom_A, tempSetA, tempSyncA); - - B = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game_B, rom_B, tempSetB, tempSyncB); - - C = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game_C, rom_C, tempSetC, tempSyncC); - - D = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game_D, rom_D, tempSetD, tempSyncD); + A = new GBHawk.GBHawk(comm.Clone(), game_A, rom_A, tempSetA, tempSyncA); + B = new GBHawk.GBHawk(comm.Clone(), game_B, rom_B, tempSetB, tempSyncB); + C = new GBHawk.GBHawk(comm.Clone(), game_C, rom_C, tempSetC, tempSyncC); + D = new GBHawk.GBHawk(comm.Clone(), game_D, rom_D, tempSetD, tempSyncD); ser.Register(this); ser.Register(this); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 0fd0248d08..d0a1f1015c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -18,10 +18,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy GambatteLinkSyncSettings linkSyncSettings = (GambatteLinkSyncSettings)syncSettings ?? new GambatteLinkSyncSettings(); CoreComm = comm; - L = new Gameboy(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - leftinfo, leftrom, linkSettings.L, linkSyncSettings.L, deterministic); - R = new Gameboy(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - rightinfo, rightrom, linkSettings.R, linkSyncSettings.R, deterministic); + L = new Gameboy(comm.Clone(), leftinfo, leftrom, linkSettings.L, linkSyncSettings.L, deterministic); + R = new Gameboy(comm.Clone(), rightinfo, rightrom, linkSettings.R, linkSyncSettings.R, deterministic); // connect link cable LibGambatte.gambatte_linkstatus(L.GambatteState, 259); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs index 478204326e..6cd0902480 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs @@ -19,8 +19,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SubGBHawk var subGBSettings = (GBHawk.GBHawk.GBSettings)settings ?? new GBHawk.GBHawk.GBSettings(); var subGBSyncSettings = (GBHawk.GBHawk.GBSyncSettings)syncSettings ?? new GBHawk.GBHawk.GBSyncSettings(); - _GBCore = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game, rom, subGBSettings, subGBSyncSettings); + _GBCore = new GBHawk.GBHawk(comm.Clone(), game, rom, subGBSettings, subGBSyncSettings); HardReset(); current_cycle = 0; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs index fdb6deaecb..787196fc77 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs @@ -15,12 +15,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.SubNESHawk [CoreConstructor("NES")] public SubNESHawk(CoreComm comm, GameInfo game, byte[] rom, /*string gameDbFn,*/ object settings, object syncSettings) { - var subNesSettings = (NES.NES.NESSettings)settings ?? new NES.NES.NESSettings(); var subNesSyncSettings = (NES.NES.NESSyncSettings)syncSettings ?? new NES.NES.NESSyncSettings(); - _nesCore = new NES.NES(new CoreComm(comm.ShowMessage, comm.Notify) {CoreFileProvider = comm.CoreFileProvider}, - game, rom, subNesSettings, subNesSyncSettings) + _nesCore = new NES.NES(comm.Clone(), game, rom, subNesSettings, subNesSyncSettings) { using_reset_timing = true }; diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.cs b/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.cs index b39b515689..1ba4be9669 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.cs @@ -40,17 +40,14 @@ namespace BizHawk.Emulation.Cores.Sega.GGHawkLink var temp_sync_L = new SMS.SmsSyncSettings(); var temp_sync_R = new SMS.SmsSyncSettings(); - L = new SMS(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game_L, rom_L, temp_set_L, temp_sync_L); - - R = new SMS(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, - game_R, rom_R, temp_set_R, temp_sync_R); + L = new SMS(comm.Clone(), game_L, rom_L, temp_set_L, temp_sync_L); + R = new SMS(comm.Clone(), game_R, rom_R, temp_set_R, temp_sync_R); ser.Register(this); ser.Register(this); _tracer = new TraceBuffer { Header = L.Cpu.TraceHeader }; - ser.Register(_tracer); + ser.Register(_tracer); ServiceProvider = ser; diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index 2720dc2e80..c34c239c51 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -248,6 +248,7 @@ True True + True True True