From 9ec72fd5438e87718f5ec8000e5ae556f2878d93 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 1 Aug 2021 14:39:37 +1000 Subject: [PATCH] Enable nullability in some more services and CodeDataLog --- .../cheats/GameSharkDecoder.cs | 2 +- .../lua/LuaHelperLibs/MainMemoryLuaLibrary.cs | 2 +- .../movie/interfaces/IMovie.cs | 2 +- .../movie/tasproj/TasMovie.cs | 2 +- .../tools/BasicBot/BasicBot.cs | 2 +- .../tools/Cheats/CheatEdit.cs | 4 +- .../Base Implementations/CodeDataLog.cs | 8 ++-- .../Interfaces/Services/ICodeDataLogger.cs | 8 ++-- .../Interfaces/Services/IDebuggable.cs | 4 +- .../Interfaces/Services/IMemoryDomains.cs | 6 +-- .../Interfaces/Services/ISaveRam.cs | 6 +-- .../Interfaces/Services/ISoundProvider.cs | 4 +- .../CPUs/HuC6280/HuC6280_CDL.cs | 2 +- .../Serial/Drive1541.IDebuggable.cs | 2 +- .../ZXSpectrum.ICodeDataLog.cs | 38 +++++++++++-------- .../Consoles/Atari/2600/Mappers/mAR.cs | 2 +- .../GCE/Vectrex/VectrexHawk.ICodeDataLog.cs | 4 +- .../Magnavox/Odyssey2/O2Hawk.ICodeDataLog.cs | 12 +++--- .../Nintendo/GBHawk/GBHawk.ICodeDataLog.cs | 12 +++--- .../GBHawkLink/GBHawkLink.ICodeDataLog.cs | 12 +++--- .../GBHawkLink3x/GBHawkLink3x.ICodeDataLog.cs | 12 +++--- .../GBHawkLink4x/GBHawkLink4x.ICodeDataLog.cs | 12 +++--- .../Nintendo/Gameboy/Gambatte.ICodeDataLog.cs | 12 +++--- .../Nintendo/Gameboy/GambatteLink.ISaveRam.cs | 8 ++-- .../Nintendo/NES/NES.ICodeDataLogger.cs | 22 ++++------- .../Consoles/Nintendo/QuickNES/QuickNES.cs | 2 +- .../SNES/LibsnesCore.ICodeDataLogger.cs | 28 +++++++------- .../GGHawkLink/GGHawkLink.ICodeDataLog.cs | 18 ++++----- .../Consoles/Sega/SMS/SMS.ICodeDataLogger.cs | 18 ++++----- .../Sega/gpgx64/GPGX.ICodeDataLogger.cs | 10 ++--- 30 files changed, 122 insertions(+), 154 deletions(-) diff --git a/src/BizHawk.Client.Common/cheats/GameSharkDecoder.cs b/src/BizHawk.Client.Common/cheats/GameSharkDecoder.cs index 2ba60bc803..f19728cf41 100644 --- a/src/BizHawk.Client.Common/cheats/GameSharkDecoder.cs +++ b/src/BizHawk.Client.Common/cheats/GameSharkDecoder.cs @@ -35,7 +35,7 @@ namespace BizHawk.Client.Common.cheats var domain = CheatDomainName(); return CheatDomainName() == null ? _domains.SystemBus - : _domains[domain]; + : _domains[domain]!; } private string CheatDomainName() => _systemId switch diff --git a/src/BizHawk.Client.Common/lua/LuaHelperLibs/MainMemoryLuaLibrary.cs b/src/BizHawk.Client.Common/lua/LuaHelperLibs/MainMemoryLuaLibrary.cs index 80ce63370e..e8837c46ae 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelperLibs/MainMemoryLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelperLibs/MainMemoryLuaLibrary.cs @@ -20,7 +20,7 @@ namespace BizHawk.Client.Common private string _mainMemName; - private MemoryDomain Domain => _mainMemDomain ??= ((MemoryApi) APIs.Memory).DomainList[MainMemName]; + private MemoryDomain Domain => _mainMemDomain ??= ((MemoryApi) APIs.Memory).DomainList[MainMemName]!; private string MainMemName => _mainMemName ??= APIs.Memory.MainMemoryName; diff --git a/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs b/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs index 02f74e8903..5dafd19cf0 100644 --- a/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs +++ b/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs @@ -300,7 +300,7 @@ namespace BizHawk.Client.Common { if (movie.StartsFromSaveRam && emulator.HasSaveRam()) { - emulator.AsSaveRam().StoreSaveRam(movie.SaveRam); + emulator.AsSaveRam().StoreSaveRam(movie.SaveRam!); } } diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 28edff3337..a0ef561238 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -53,7 +53,7 @@ namespace BizHawk.Client.Common var ms = new MemoryStream(); if (StartsFromSaveRam && emulator.HasSaveRam()) { - emulator.AsSaveRam().StoreSaveRam(SaveRam); + emulator.AsSaveRam().StoreSaveRam(SaveRam!); } emulator.AsStatable().SaveStateBinary(new BinaryWriter(ms)); TasStateManager.Engage(ms.ToArray()); diff --git a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs index 7e0c768782..167596f9a0 100644 --- a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs +++ b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs @@ -800,7 +800,7 @@ namespace BizHawk.Client.EmuHawk private void SetMemoryDomain(string name) { _currentDomain = MemoryDomains[name]; - _bigEndian = MemoryDomains[name].EndianType == MemoryDomain.Endian.Big; + _bigEndian = _currentDomain!.EndianType == MemoryDomain.Endian.Big; MaximizeAddressBox.SetHexProperties(_currentDomain.Size); TieBreaker1Box.SetHexProperties(_currentDomain.Size); diff --git a/src/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs b/src/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs index ad658b16a9..f64ab4f1db 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs @@ -233,7 +233,7 @@ namespace BizHawk.Client.EmuHawk { if (!_loading) { - var domain = MemoryDomains[DomainDropDown.SelectedItem.ToString()]; + var domain = MemoryDomains[DomainDropDown.SelectedItem.ToString()]!; AddressBox.SetHexProperties(domain.Size); } } @@ -294,7 +294,7 @@ namespace BizHawk.Client.EmuHawk public Cheat GetCheat() { - var domain = MemoryDomains[DomainDropDown.SelectedItem.ToString()]; + var domain = MemoryDomains[DomainDropDown.SelectedItem.ToString()]!; var address = AddressBox.ToRawInt().Value; if (address < domain.Size) { diff --git a/src/BizHawk.Emulation.Common/Base Implementations/CodeDataLog.cs b/src/BizHawk.Emulation.Common/Base Implementations/CodeDataLog.cs index a8bd928c53..3f257d8270 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/CodeDataLog.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/CodeDataLog.cs @@ -1,6 +1,4 @@ -#nullable disable - -using System; +using System; using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; @@ -70,7 +68,7 @@ namespace BizHawk.Emulation.Common /// public bool Active { get; set; } - public string SubType { get; set; } + public string? SubType { get; set; } public int SubVer { get; set; } /// @@ -156,7 +154,7 @@ namespace BizHawk.Emulation.Common var ret = new Dictionary(); var w = new BinaryWriter(s); w.Write("BIZHAWK-CDL-2"); - w.Write(SubType.PadRight(15)); + w.Write(SubType!.PadRight(15)); w.Write(Count); w.Flush(); long addr = s.Position; diff --git a/src/BizHawk.Emulation.Common/Interfaces/Services/ICodeDataLogger.cs b/src/BizHawk.Emulation.Common/Interfaces/Services/ICodeDataLogger.cs index f933942780..fb8853e645 100644 --- a/src/BizHawk.Emulation.Common/Interfaces/Services/ICodeDataLogger.cs +++ b/src/BizHawk.Emulation.Common/Interfaces/Services/ICodeDataLogger.cs @@ -1,6 +1,4 @@ -#nullable disable - -using System; +using System; using System.IO; using System.Collections.Generic; @@ -15,7 +13,7 @@ namespace BizHawk.Emulation.Common /// /// Sets the CodeDataLog as current (and logging) on the core /// - void SetCDL(ICodeDataLog cdl); + void SetCDL(ICodeDataLog? cdl); /// /// Fills a new CodeDataLog with memory domain information suitable for the core @@ -61,7 +59,7 @@ namespace BizHawk.Emulation.Common /// bool Active { get; set; } - string SubType { get; set; } + string? SubType { get; set; } int SubVer { get; set; } diff --git a/src/BizHawk.Emulation.Common/Interfaces/Services/IDebuggable.cs b/src/BizHawk.Emulation.Common/Interfaces/Services/IDebuggable.cs index 579bdb56a9..54d52b19bb 100644 --- a/src/BizHawk.Emulation.Common/Interfaces/Services/IDebuggable.cs +++ b/src/BizHawk.Emulation.Common/Interfaces/Services/IDebuggable.cs @@ -1,6 +1,4 @@ -#nullable disable - -using System; +using System; using System.Collections.Generic; namespace BizHawk.Emulation.Common diff --git a/src/BizHawk.Emulation.Common/Interfaces/Services/IMemoryDomains.cs b/src/BizHawk.Emulation.Common/Interfaces/Services/IMemoryDomains.cs index 9012f98ce9..85b4629363 100644 --- a/src/BizHawk.Emulation.Common/Interfaces/Services/IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Common/Interfaces/Services/IMemoryDomains.cs @@ -1,6 +1,4 @@ -#nullable disable - -using System.Collections.Generic; +using System.Collections.Generic; namespace BizHawk.Emulation.Common { @@ -17,7 +15,7 @@ namespace BizHawk.Emulation.Common /// public interface IMemoryDomains : IEnumerable, IEmulatorService { - MemoryDomain this[string name] { get; } + MemoryDomain? this[string name] { get; } MemoryDomain MainMemory { get; } diff --git a/src/BizHawk.Emulation.Common/Interfaces/Services/ISaveRam.cs b/src/BizHawk.Emulation.Common/Interfaces/Services/ISaveRam.cs index e0422a5ac8..7fe10020de 100644 --- a/src/BizHawk.Emulation.Common/Interfaces/Services/ISaveRam.cs +++ b/src/BizHawk.Emulation.Common/Interfaces/Services/ISaveRam.cs @@ -1,6 +1,4 @@ -#nullable disable - -namespace BizHawk.Emulation.Common +namespace BizHawk.Emulation.Common { /// /// This service provides the system by which a client can request SaveRAM data to be stored by the client @@ -16,7 +14,7 @@ namespace BizHawk.Emulation.Common /// Unfortunately, the core may think differently of a nonexisting (null) saveram vs a 0 size saveram. /// Frontend users of the ISaveRam should treat null as nonexisting (and thus not even write the file, so that the "does not exist" condition can be roundtripped and not confused with an empty file) /// - byte[] CloneSaveRam(); + byte[]? CloneSaveRam(); /// /// store new SaveRAM to the emu core. the data should be the same size as the return from ReadSaveRam() diff --git a/src/BizHawk.Emulation.Common/Interfaces/Services/ISoundProvider.cs b/src/BizHawk.Emulation.Common/Interfaces/Services/ISoundProvider.cs index 98e07e96db..b83161de34 100644 --- a/src/BizHawk.Emulation.Common/Interfaces/Services/ISoundProvider.cs +++ b/src/BizHawk.Emulation.Common/Interfaces/Services/ISoundProvider.cs @@ -1,6 +1,4 @@ -#nullable disable - -using System; +using System; namespace BizHawk.Emulation.Common { diff --git a/src/BizHawk.Emulation.Cores/CPUs/HuC6280/HuC6280_CDL.cs b/src/BizHawk.Emulation.Cores/CPUs/HuC6280/HuC6280_CDL.cs index 7e1e0bdea6..52cf918872 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/HuC6280/HuC6280_CDL.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/HuC6280/HuC6280_CDL.cs @@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Components.H6280 w.WriteLine(".\"{0}\" size=0x{1:x8}", kvp.Key, kvp.Value.Length); byte[] cd = kvp.Value; - var md = mem[kvp.Key]; + var md = mem[kvp.Key]!; for (int i = 0; i < kvp.Value.Length; i++) { diff --git a/src/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/Drive1541.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/Drive1541.IDebuggable.cs index e869a3ecfb..534b86217e 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/Drive1541.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/Drive1541.IDebuggable.cs @@ -147,6 +147,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial private const byte Rts = 0x60; private const byte JsrSize = 3; - public IMemoryCallbackSystem MemoryCallbacks { get; private set; } + public IMemoryCallbackSystem MemoryCallbacks => throw new NotImplementedException(); } } diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.ICodeDataLog.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.ICodeDataLog.cs index e2246a0ecc..4bd9ef13b9 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.ICodeDataLog.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.ICodeDataLog.cs @@ -26,30 +26,36 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public void NewCDL(ICodeDataLog cdl) { - cdl["System Bus"] = new byte[memoryDomains["System Bus"].Size]; + void AddIfExists(string name) + { + var found = memoryDomains[name]; + if (found is not null) cdl[name] = new byte[found.Size]; + } - if (memoryDomains.Has("ROM - 128K Editor & Menu")) { cdl["ROM - 128K Editor & Menu"] = new byte[memoryDomains["ROM - 128K Editor & Menu"].Size]; } - if (memoryDomains.Has("ROM - 128K Syntax Checker")) { cdl["ROM - 128K Syntax Checker"] = new byte[memoryDomains["ROM - 128K Syntax Checker"].Size]; } - if (memoryDomains.Has("ROM - +3DOS")) { cdl["ROM - +3DOS"] = new byte[memoryDomains["ROM - +3DOS"].Size]; } - if (memoryDomains.Has("ROM - 48K BASIC")) { cdl["ROM - 48K BASIC"] = new byte[memoryDomains["ROM - 48K BASIC"].Size]; } + cdl["System Bus"] = new byte[memoryDomains["System Bus"]!.Size]; + + AddIfExists("ROM - 128K Editor & Menu"); + AddIfExists("ROM - 128K Syntax Checker"); + AddIfExists("ROM - +3DOS"); + AddIfExists("ROM - 48K BASIC"); // different RAM bank ordering for < 128k models if (_machineType == MachineType.ZXSpectrum16 || _machineType == MachineType.ZXSpectrum48) { - if (memoryDomains.Has("RAM - BANK 0 (Screen)")) { cdl["RAM - BANK 0 (Screen)"] = new byte[memoryDomains["RAM - BANK 0 (Screen)"].Size]; } - if (memoryDomains.Has("RAM - BANK 1")) { cdl["RAM - BANK 1"] = new byte[memoryDomains["RAM - BANK 1"].Size]; } - if (memoryDomains.Has("RAM - BANK 2")) { cdl["RAM - BANK 2"] = new byte[memoryDomains["RAM - BANK 2"].Size]; } + AddIfExists("RAM - BANK 0 (Screen)"); + AddIfExists("RAM - BANK 1"); + AddIfExists("RAM - BANK 2"); } else { - if (memoryDomains.Has("RAM - BANK 5 (Screen)")) { cdl["RAM - BANK 5 (Screen)"] = new byte[memoryDomains["RAM - BANK 5 (Screen)"].Size]; } - if (memoryDomains.Has("RAM - BANK 2")) { cdl["RAM - BANK 2"] = new byte[memoryDomains["RAM - BANK 2"].Size]; } - if (memoryDomains.Has("RAM - BANK 0")) { cdl["RAM - BANK 0"] = new byte[memoryDomains["RAM - BANK 0"].Size]; } - if (memoryDomains.Has("RAM - BANK 1")) { cdl["RAM - BANK 1"] = new byte[memoryDomains["RAM - BANK 1"].Size]; } - if (memoryDomains.Has("RAM - BANK 3")) { cdl["RAM - BANK 3"] = new byte[memoryDomains["RAM - BANK 3"].Size]; } - if (memoryDomains.Has("RAM - BANK 4")) { cdl["RAM - BANK 4"] = new byte[memoryDomains["RAM - BANK 4"].Size]; } - if (memoryDomains.Has("RAM - BANK 6")) { cdl["RAM - BANK 6"] = new byte[memoryDomains["RAM - BANK 6"].Size]; } - if (memoryDomains.Has("RAM - BANK 7 (Shadow Screen)")) { cdl["RAM - BANK 7 (Shadow Screen)"] = new byte[memoryDomains["RAM - BANK 7 (Shadow Screen)"].Size]; } + AddIfExists("RAM - BANK 5 (Screen)"); + AddIfExists("RAM - BANK 2"); + AddIfExists("RAM - BANK 0"); + AddIfExists("RAM - BANK 1"); + AddIfExists("RAM - BANK 3"); + AddIfExists("RAM - BANK 4"); + AddIfExists("RAM - BANK 6"); + AddIfExists("RAM - BANK 7 (Shadow Screen)"); } cdl.SubType = "ZXSpectrum"; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mAR.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mAR.cs index cf3c9facd8..4a1da154c5 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mAR.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mAR.cs @@ -236,7 +236,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 if (addr == 0x1850 && _imageOffsets[1] == 3 << 11) { - LoadIntoRam(Core.MemoryDomains["System Bus"].PeekByte(0x80)); // Get load that's being accessed (BIOS places load number at 0x80) // TODO: a better way to do this + LoadIntoRam(Core.MemoryDomains["System Bus"]!.PeekByte(0x80)); // Get load that's being accessed (BIOS places load number at 0x80) // TODO: a better way to do this return _superChargerImage[(addr & 0x7FF) + _imageOffsets[1]]; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ICodeDataLog.cs b/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ICodeDataLog.cs index 8f4e1f47c0..c901dac911 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ICodeDataLog.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ICodeDataLog.cs @@ -14,8 +14,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex public void NewCDL(ICodeDataLog cdl) { - cdl["RAM"] = new byte[MemoryDomains["Main RAM"].Size]; - cdl["ROM"] = new byte[MemoryDomains["ROM"].Size]; + cdl["RAM"] = new byte[MemoryDomains["Main RAM"]!.Size]; + cdl["ROM"] = new byte[MemoryDomains["ROM"]!.Size]; cdl.SubType = "VEC"; cdl.SubVer = 0; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.ICodeDataLog.cs b/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.ICodeDataLog.cs index 6cda2e86dc..61943e039d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.ICodeDataLog.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.ICodeDataLog.cs @@ -18,15 +18,13 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk public void NewCDL(ICodeDataLog cdl) { - cdl["ROM"] = new byte[MemoryDomains["ROM"].Size]; - cdl["HRAM"] = new byte[MemoryDomains["Zero Page RAM"].Size]; + cdl["ROM"] = new byte[MemoryDomains["ROM"]!.Size]; + cdl["HRAM"] = new byte[MemoryDomains["Zero Page RAM"]!.Size]; - cdl["WRAM"] = new byte[MemoryDomains["Main RAM"].Size]; + cdl["WRAM"] = new byte[MemoryDomains["Main RAM"]!.Size]; - if (MemoryDomains.Has("Cart RAM")) - { - cdl["CartRAM"] = new byte[MemoryDomains["Cart RAM"].Size]; - } + var found = MemoryDomains["Cart RAM"]; + if (found is not null) cdl["CartRAM"] = new byte[found.Size]; cdl.SubType = "O2"; cdl.SubVer = 0; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ICodeDataLog.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ICodeDataLog.cs index bb6eefa4c4..e2c8c4d36e 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ICodeDataLog.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ICodeDataLog.cs @@ -18,15 +18,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public void NewCDL(ICodeDataLog cdl) { - cdl["ROM"] = new byte[MemoryDomains["ROM"].Size]; - cdl["HRAM"] = new byte[MemoryDomains["HRAM"].Size]; + cdl["ROM"] = new byte[MemoryDomains["ROM"]!.Size]; + cdl["HRAM"] = new byte[MemoryDomains["HRAM"]!.Size]; - cdl["WRAM"] = new byte[MemoryDomains["WRAM"].Size]; + cdl["WRAM"] = new byte[MemoryDomains["WRAM"]!.Size]; - if (MemoryDomains.Has("Cart RAM")) - { - cdl["CartRAM"] = new byte[MemoryDomains["Cart RAM"].Size]; - } + var found = MemoryDomains["Cart RAM"]; + if (found is not null) cdl["CartRAM"] = new byte[found.Size]; cdl.SubType = "GB"; cdl.SubVer = 0; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.ICodeDataLog.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.ICodeDataLog.cs index 72de61e527..ae2cbe72ef 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.ICodeDataLog.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.ICodeDataLog.cs @@ -19,15 +19,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink public void NewCDL(ICodeDataLog cdl) { - cdl["ROM"] = new byte[MemoryDomains["ROM L"].Size]; - cdl["HRAM"] = new byte[MemoryDomains["Zero Page RAM L"].Size]; + cdl["ROM"] = new byte[MemoryDomains["ROM L"]!.Size]; + cdl["HRAM"] = new byte[MemoryDomains["Zero Page RAM L"]!.Size]; - cdl["WRAM"] = new byte[MemoryDomains["Main RAM L"].Size]; + cdl["WRAM"] = new byte[MemoryDomains["Main RAM L"]!.Size]; - if (MemoryDomains.Has("Cart RAM L")) - { - cdl["CartRAM"] = new byte[MemoryDomains["Cart RAM L"].Size]; - } + var found = MemoryDomains["Cart RAM L"]; + if (found is not null) cdl["CartRAM"] = new byte[found.Size]; cdl.SubType = "GB"; cdl.SubVer = 0; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ICodeDataLog.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ICodeDataLog.cs index 0aed58c5cf..19b1e4fcda 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ICodeDataLog.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ICodeDataLog.cs @@ -19,15 +19,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x public void NewCDL(ICodeDataLog cdl) { - cdl["ROM"] = new byte[MemoryDomains["ROM L"].Size]; - cdl["HRAM"] = new byte[MemoryDomains["Zero Page RAM L"].Size]; + cdl["ROM"] = new byte[MemoryDomains["ROM L"]!.Size]; + cdl["HRAM"] = new byte[MemoryDomains["Zero Page RAM L"]!.Size]; - cdl["WRAM"] = new byte[MemoryDomains["Main RAM L"].Size]; + cdl["WRAM"] = new byte[MemoryDomains["Main RAM L"]!.Size]; - if (MemoryDomains.Has("Cart RAM L")) - { - cdl["CartRAM"] = new byte[MemoryDomains["Cart RAM L"].Size]; - } + var found = MemoryDomains["Cart RAM L"]; + if (found is not null) cdl["CartRAM"] = new byte[found.Size]; cdl.SubType = "GB"; cdl.SubVer = 0; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.ICodeDataLog.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.ICodeDataLog.cs index 4b00ec8133..bb25702720 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.ICodeDataLog.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.ICodeDataLog.cs @@ -19,15 +19,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x public void NewCDL(ICodeDataLog cdl) { - cdl["ROM"] = new byte[MemoryDomains["ROM A"].Size]; - cdl["HRAM"] = new byte[MemoryDomains["Zero Page RAM A"].Size]; + cdl["ROM"] = new byte[MemoryDomains["ROM A"]!.Size]; + cdl["HRAM"] = new byte[MemoryDomains["Zero Page RAM A"]!.Size]; - cdl["WRAM"] = new byte[MemoryDomains["Main RAM A"].Size]; + cdl["WRAM"] = new byte[MemoryDomains["Main RAM A"]!.Size]; - if (MemoryDomains.Has("Cart RAM A")) - { - cdl["CartRAM"] = new byte[MemoryDomains["Cart RAM A"].Size]; - } + var found = MemoryDomains["Cart RAM A"]; + if (found is not null) cdl["CartRAM"] = new byte[found.Size]; cdl.SubType = "GB"; cdl.SubVer = 0; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ICodeDataLog.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ICodeDataLog.cs index ca0da3ba53..40600228ca 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ICodeDataLog.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ICodeDataLog.cs @@ -15,15 +15,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy public void NewCDL(ICodeDataLog cdl) { - cdl["ROM"] = new byte[MemoryDomains["ROM"].Size]; + cdl["ROM"] = new byte[MemoryDomains["ROM"]!.Size]; - // cdl["HRAM"] = new byte[_memoryDomains["HRAM"].Size]; //this is probably useless, but it's here if someone needs it - cdl["WRAM"] = new byte[MemoryDomains["WRAM"].Size]; + // cdl["HRAM"] = new byte[_memoryDomains["HRAM"]!.Size]; //this is probably useless, but it's here if someone needs it + cdl["WRAM"] = new byte[MemoryDomains["WRAM"]!.Size]; - if (MemoryDomains.Has("CartRAM")) - { - cdl["CartRAM"] = new byte[MemoryDomains["CartRAM"].Size]; - } + var found = MemoryDomains["CartRAM"]; + if (found is not null) cdl["CartRAM"] = new byte[found.Size]; cdl.SubType = "GB"; cdl.SubVer = 0; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.ISaveRam.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.ISaveRam.cs index ec648bba8c..7a6908930e 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.ISaveRam.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.ISaveRam.cs @@ -9,8 +9,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy public byte[] CloneSaveRam() { - byte[] lb = L.CloneSaveRam(); - byte[] rb = R.CloneSaveRam(); + var lb = L.CloneSaveRam()!; + var rb = R.CloneSaveRam()!; byte[] ret = new byte[lb.Length + rb.Length]; Buffer.BlockCopy(lb, 0, ret, 0, lb.Length); Buffer.BlockCopy(rb, 0, ret, lb.Length, rb.Length); @@ -19,8 +19,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy public void StoreSaveRam(byte[] data) { - byte[] lb = new byte[L.CloneSaveRam().Length]; - byte[] rb = new byte[R.CloneSaveRam().Length]; + var lb = new byte[L.CloneSaveRam()!.Length]; + var rb = new byte[R.CloneSaveRam()!.Length]; Buffer.BlockCopy(data, 0, lb, 0, lb.Length); Buffer.BlockCopy(data, lb.Length, rb, 0, rb.Length); L.StoreSaveRam(lb); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ICodeDataLogger.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ICodeDataLogger.cs index 7506154303..b4593ac009 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ICodeDataLogger.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ICodeDataLogger.cs @@ -13,23 +13,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public void NewCDL(ICodeDataLog cdl) { - cdl["RAM"] = new byte[_memoryDomains["RAM"].Size]; - - if (_memoryDomains.Has("Save RAM")) + void AddIfExists(string name) { - cdl["Save RAM"] = new byte[_memoryDomains["Save RAM"].Size]; + var found = _memoryDomains[name]; + if (found is not null) cdl[name] = new byte[found.Size]; } - - if (_memoryDomains.Has("Battery RAM")) - { - cdl["Battery RAM"] = new byte[_memoryDomains["Battery RAM"].Size]; - } - - if (_memoryDomains.Has("Battery RAM")) - { - cdl["Battery RAM"] = new byte[_memoryDomains["Battery RAM"].Size]; - } - + cdl["RAM"] = new byte[_memoryDomains["RAM"]!.Size]; + AddIfExists("Save RAM"); + AddIfExists("Battery RAM"); + AddIfExists("Battery RAM"); // ??? cdl.SubType = "NES"; cdl.SubVer = 0; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs index 510ebf15c1..4fadb9dd50 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs @@ -236,7 +236,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES { // inefficient, sloppy, etc etc var chrrom = _memoryDomains["CHR VROM"]; - var prgrom = _memoryDomains["PRG ROM"]; + var prgrom = _memoryDomains["PRG ROM"]!; var ms = new MemoryStream(); for (int i = 0; i < prgrom.Size; i++) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs index 11a6b0cf08..9aeb9dd6a5 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs @@ -17,23 +17,25 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES public void NewCDL(ICodeDataLog cdl) { - cdl["CARTROM"] = new byte[_memoryDomains["CARTROM"].Size]; - cdl["CARTROM-DB"] = new byte[_memoryDomains["CARTROM"].Size]; - cdl["CARTROM-D"] = new byte[_memoryDomains["CARTROM"].Size*2]; - cdl["WRAM"] = new byte[_memoryDomains["WRAM"].Size]; - cdl["APURAM"] = new byte[_memoryDomains["APURAM"].Size]; + void AddIfExists(string name, string addAs = null) + { + var found = _memoryDomains[name]; + if (found is not null) cdl[addAs ?? name] = new byte[found.Size]; + } - if (_memoryDomains.Has("CARTRAM")) - cdl["CARTRAM"] = new byte[_memoryDomains["CARTRAM"].Size]; + cdl["CARTROM"] = new byte[_memoryDomains["CARTROM"]!.Size]; + cdl["CARTROM-DB"] = new byte[_memoryDomains["CARTROM"]!.Size]; + cdl["CARTROM-D"] = new byte[_memoryDomains["CARTROM"]!.Size*2]; + cdl["WRAM"] = new byte[_memoryDomains["WRAM"]!.Size]; + cdl["APURAM"] = new byte[_memoryDomains["APURAM"]!.Size]; + AddIfExists("CARTRAM"); if (IsSGB) { - cdl["SGB_CARTROM"] = new byte[_memoryDomains["SGB CARTROM"].Size]; - cdl["SGB_HRAM"] = new byte[_memoryDomains["SGB HRAM"].Size]; - cdl["SGB_WRAM"] = new byte[_memoryDomains["SGB WRAM"].Size]; - - if (_memoryDomains.Has("SGB CARTRAM")) - cdl["SGB_CARTRAM"] = new byte[_memoryDomains["SGB CARTRAM"].Size]; + cdl["SGB_CARTROM"] = new byte[_memoryDomains["SGB CARTROM"]!.Size]; + cdl["SGB_HRAM"] = new byte[_memoryDomains["SGB HRAM"]!.Size]; + cdl["SGB_WRAM"] = new byte[_memoryDomains["SGB WRAM"]!.Size]; + AddIfExists("SGB CARTRAM", addAs: "SGB_CARTRAM"); } cdl.SubType = "SNES"; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.ICodeDataLog.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.ICodeDataLog.cs index d33fa8d7aa..c2fcf01c4d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.ICodeDataLog.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.ICodeDataLog.cs @@ -27,19 +27,15 @@ namespace BizHawk.Emulation.Cores.Sega.GGHawkLink public void NewCDL(ICodeDataLog cdl) { - cdl["ROM"] = new byte[_memoryDomains["ROM"].Size]; - cdl["Main RAM"] = new byte[_memoryDomains["Main RAM"].Size]; - - if (_memoryDomains.Has("Save RAM")) + void AddIfExists(string name) { - cdl["Save RAM"] = new byte[_memoryDomains["Save RAM"].Size]; + var found = _memoryDomains[name]; + if (found is not null) cdl[name] = new byte[found.Size]; } - - if (_memoryDomains.Has("Cart (Volatile) RAM")) - { - cdl["Cart (Volatile) RAM"] = new byte[_memoryDomains["Cart (Volatile) RAM"].Size]; - } - + cdl["ROM"] = new byte[_memoryDomains["ROM"]!.Size]; + cdl["Main RAM"] = new byte[_memoryDomains["Main RAM"]!.Size]; + AddIfExists("Save RAM"); + AddIfExists("Cart (Volatile) RAM"); cdl.SubType = "SMS"; cdl.SubVer = 0; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.ICodeDataLogger.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.ICodeDataLogger.cs index 6592bf41b4..be6ae7c750 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.ICodeDataLogger.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.ICodeDataLogger.cs @@ -25,19 +25,15 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem public void NewCDL(ICodeDataLog cdl) { - cdl["ROM"] = new byte[MemoryDomains["ROM"].Size]; - cdl["Main RAM"] = new byte[MemoryDomains["Main RAM"].Size]; - - if (MemoryDomains.Has("Save RAM")) + void AddIfExists(string name) { - cdl["Save RAM"] = new byte[MemoryDomains["Save RAM"].Size]; + var found = MemoryDomains[name]; + if (found is not null) cdl[name] = new byte[found.Size]; } - - if (MemoryDomains.Has("Cart (Volatile) RAM")) - { - cdl["Cart (Volatile) RAM"] = new byte[MemoryDomains["Cart (Volatile) RAM"].Size]; - } - + cdl["ROM"] = new byte[MemoryDomains["ROM"]!.Size]; + cdl["Main RAM"] = new byte[MemoryDomains["Main RAM"]!.Size]; + AddIfExists("Save RAM"); + AddIfExists("Cart (Volatile) RAM"); cdl.SubType = "SMS"; cdl.SubVer = 0; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ICodeDataLogger.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ICodeDataLogger.cs index f3a29eab94..d2f992cb9f 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ICodeDataLogger.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ICodeDataLogger.cs @@ -16,12 +16,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx public void NewCDL(ICodeDataLog cdl) { - cdl["MD CART"] = new byte[_memoryDomains["MD CART"].Size]; - cdl["68K RAM"] = new byte[_memoryDomains["68K RAM"].Size]; - cdl["Z80 RAM"] = new byte[_memoryDomains["Z80 RAM"].Size]; + cdl["MD CART"] = new byte[_memoryDomains["MD CART"]!.Size]; + cdl["68K RAM"] = new byte[_memoryDomains["68K RAM"]!.Size]; + cdl["Z80 RAM"] = new byte[_memoryDomains["Z80 RAM"]!.Size]; - if (_memoryDomains.Has("SRAM")) - cdl["SRAM"] = new byte[_memoryDomains["SRAM"].Size]; + var found = _memoryDomains["SRAM"]; + if (found is not null) cdl["SRAM"] = new byte[found.Size]; cdl.SubType = "GEN"; cdl.SubVer = 0;