From 697c10e3e64dfb5f6c0736e014262e0628ad87c7 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Wed, 20 Jul 2022 05:57:51 +1000 Subject: [PATCH] Enable MA0015 and fix noncompliance "Specify the parameter name in ArgumentException" needed to update package because this rule was broken until now --- Common.props | 2 +- Common.ruleset | 2 +- Dist/deps-base.nix | 2 +- .../CallingConventionAdapter.cs | 5 +--- .../movie/tasproj/ZwinderStateManager.cs | 2 +- .../rewind/ZwinderBuffer.cs | 5 ++-- .../tools/Watch/Watch.cs | 2 +- src/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs | 2 +- .../AVOut/FFmpegWriter.cs | 2 +- src/BizHawk.Client.EmuHawk/AVOut/GifWriter.cs | 2 +- src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs | 18 ++++++-------- src/BizHawk.Client.EmuHawk/AVOut/WavWriter.cs | 11 ++++----- .../CustomControls/MsgBox.cs | 6 +---- .../tools/ToolManager.cs | 2 +- src/BizHawk.Common/BinaryQuickSerializer.cs | 2 +- .../DescribableEnumConverter.cs | 4 ++-- .../Extensions/PathExtensions.cs | 6 ++--- .../SimpleSyncSoundProvider.cs | 5 +--- .../Sound/SpeexResampler.cs | 7 ++---- .../CPUs/68000/Memory.cs | 3 ++- .../CPUs/CP1610/CP1610.Execute.cs | 4 ++-- .../Calculators/Emu83/Emu83.IMemoryDomains.cs | 12 ++-------- .../Calculators/TI83/TI83.IMemoryDomains.cs | 12 ++-------- .../AmstradCPC/AmstradCPC.IMemoryDomains.cs | 10 ++------ .../Computers/AmstradCPC/AmstradCPC.Util.cs | 4 +--- .../AppleII/AppleII.IMemoryDomains.cs | 24 ++++--------------- .../ZXSpectrum.IMemoryDomains.cs | 11 ++------- .../SinclairSpectrum/ZXSpectrum.Util.cs | 4 +--- .../Coleco/ColecoVision.IMemoryDomains.cs | 12 ++-------- .../ChannelF/ChannelF.MemoryDomains.cs | 11 ++------- .../Consoles/Intellivision/Intellicart.cs | 20 ++++------------ .../Consoles/Intellivision/STIC.cs | 4 ++-- .../Gameboy/Gambatte.IMemoryDomains.cs | 12 ++-------- .../Nintendo/Gameboy/Gambatte.ISaveRam.cs | 8 +------ .../Consoles/Nintendo/NES/FDS/RamAdapter.cs | 6 ++--- .../QuickNES/QuickNES.IMemoryDomains.cs | 12 ++-------- .../SameBoy/SameBoy.IMemoryDomains.cs | 12 ++-------- .../Nintendo/SameBoy/SameBoy.ISaveRam.cs | 5 +--- .../PC Engine/PCEngine.IMemoryDomains.cs | 12 ++++------ .../Consoles/PC Engine/PceControllerDeck.cs | 2 +- .../Consoles/Sega/SMS/SMS.IMemoryDomains.cs | 12 ++-------- .../Sega/gpgx64/GPGX.IMemoryDomains.cs | 18 +++++--------- 42 files changed, 84 insertions(+), 233 deletions(-) diff --git a/Common.props b/Common.props index 5cbece6df9..09df18f3af 100644 --- a/Common.props +++ b/Common.props @@ -32,7 +32,7 @@ - + diff --git a/Common.ruleset b/Common.ruleset index 32f7bb17ae..60d36c96ad 100644 --- a/Common.ruleset +++ b/Common.ruleset @@ -156,7 +156,7 @@ - + diff --git a/Dist/deps-base.nix b/Dist/deps-base.nix index 659655dfe7..9081174cc3 100644 --- a/Dist/deps-base.nix +++ b/Dist/deps-base.nix @@ -172,7 +172,7 @@ let ]; since-2_8_1 = [ ({ name = "Menees.Analyzers"; version = "3.0.8"; sha256 = "1apv06cmnrakaylyh85hjyn380cnj0h53j3pakyp0f4jnpgw0bgf"; }) - ({ name = "Meziantou.Analyzer"; version = "1.0.704"; sha256 = "13jc2jylkiikyff5dmz762gmzalzsw7k8zcs6w6dk3xspwdd8n9j"; }) + ({ name = "Meziantou.Analyzer"; version = "1.0.707"; sha256 = "09drs16fr0xly4k8drznw7pa5f2byjc9km0pm0c3rrhl7jsz4ds5"; }) ({ name = "Microsoft.AspNetCore.App.Ref"; version = "6.0.6"; sha256 = "08pjgsq2vcsdy4vgff146izvxq5hpg02a8lvih0wcsgghv1m1qki"; }) ({ name = "Nullable"; version = "1.3.1"; sha256 = "0hwrr4q22c0i056dqy3v431rxjv7md910ihz0pjsi16qxsbpw7p7"; }) ({ name = "StyleCop.Analyzers"; version = "1.2.0-beta.435"; sha256 = "0dirz0av24ds2k7hgpss15y4wlhwlzz22qdjvkq0n3g3sxcckrsy"; }) diff --git a/src/BizHawk.BizInvoke/CallingConventionAdapter.cs b/src/BizHawk.BizInvoke/CallingConventionAdapter.cs index 10d5660897..8c4610950f 100644 --- a/src/BizHawk.BizInvoke/CallingConventionAdapter.cs +++ b/src/BizHawk.BizInvoke/CallingConventionAdapter.cs @@ -189,10 +189,7 @@ namespace BizHawk.BizInvoke { throw new InvalidOperationException("This calling convention adapter was created for departure only! Pass known delegate slots when constructing to enable arrival"); } - if (!(lifetime is Delegate d)) - { - throw new ArgumentException("For this calling convention adapter, lifetimes must be delegate so guest slot can be inferred"); - } + if (lifetime is not Delegate d) throw new ArgumentException(message: "For this calling convention adapter, lifetimes must be delegate so guest slot can be inferred", paramName: nameof(lifetime)); if (!_slots.TryGetValue(d, out var slot)) { throw new InvalidOperationException("All callback delegates must be registered at load"); diff --git a/src/BizHawk.Client.Common/movie/tasproj/ZwinderStateManager.cs b/src/BizHawk.Client.Common/movie/tasproj/ZwinderStateManager.cs index 7a0f5bbe4a..0fc7b9fafc 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/ZwinderStateManager.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/ZwinderStateManager.cs @@ -141,7 +141,7 @@ namespace BizHawk.Client.Common newReserved = new TempFileStateDictionary(); break; default: - throw new ArgumentException("Unsupported store type for reserved states."); + throw new InvalidOperationException("Unsupported store type for reserved states."); } if (_reserved != null) { diff --git a/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs b/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs index 85d273339a..f9c1c39cef 100644 --- a/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs +++ b/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs @@ -20,8 +20,7 @@ namespace BizHawk.Client.Common */ public ZwinderBuffer(IRewindSettings settings) { - if (settings == null) - throw new ArgumentException("ZwinderBuffer's settings cannot be null."); + if (settings is null) throw new ArgumentNullException(paramName: nameof(settings)); long targetSize = settings.BufferSize * 1024 * 1024; if (settings.TargetFrameLength < 1) throw new ArgumentException(message: nameof(IRewindSettings.TargetFrameLength) + " of provided settings is invalid", paramName: nameof(settings)); @@ -50,7 +49,7 @@ namespace BizHawk.Client.Common break; } default: - throw new ArgumentException("Unsupported store type for ZwinderBuffer."); + throw new ArgumentException(message: $"Unsupported {nameof(IRewindSettings.BackingStore)} type for ZwinderBuffer in provided settings.", paramName: nameof(settings)); } if (settings.UseFixedRewindInterval) { diff --git a/src/BizHawk.Client.Common/tools/Watch/Watch.cs b/src/BizHawk.Client.Common/tools/Watch/Watch.cs index 298f8eeed3..ee63772085 100644 --- a/src/BizHawk.Client.Common/tools/Watch/Watch.cs +++ b/src/BizHawk.Client.Common/tools/Watch/Watch.cs @@ -514,7 +514,7 @@ namespace BizHawk.Client.Common } else { - throw new ArgumentException($"WatchDisplayType {value} is invalid for this type of Watch"); + throw new ArgumentException(message: $"WatchDisplayType {value} is invalid for this type of Watch", paramName: nameof(value)); } } } diff --git a/src/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs b/src/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs index 54cd1b093a..94abc02a02 100644 --- a/src/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs +++ b/src/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs @@ -48,7 +48,7 @@ namespace BizHawk.Client.EmuHawk } else { - throw new ArgumentException($"{nameof(AviWriter)} only takes its own {nameof(CodecToken)}s!"); + throw new ArgumentException(message: $"{nameof(AviWriter)} only takes its own {nameof(CodecToken)}s!", paramName: nameof(token)); } } diff --git a/src/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs b/src/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs index 61d6fedf46..4567f7874f 100644 --- a/src/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs +++ b/src/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs @@ -231,7 +231,7 @@ namespace BizHawk.Client.EmuHawk } else { - throw new ArgumentException($"{nameof(FFmpegWriter)} can only take its own codec tokens!"); + throw new ArgumentException(message: $"{nameof(FFmpegWriter)} can only take its own codec tokens!", paramName: nameof(token)); } } diff --git a/src/BizHawk.Client.EmuHawk/AVOut/GifWriter.cs b/src/BizHawk.Client.EmuHawk/AVOut/GifWriter.cs index 9f549868ac..e9e97f70b0 100644 --- a/src/BizHawk.Client.EmuHawk/AVOut/GifWriter.cs +++ b/src/BizHawk.Client.EmuHawk/AVOut/GifWriter.cs @@ -98,7 +98,7 @@ namespace BizHawk.Client.EmuHawk } else { - throw new ArgumentException($"{nameof(GifWriter)} only takes its own tokens!"); + throw new ArgumentException(message: $"{nameof(GifWriter)} only takes its own tokens!", paramName: nameof(token)); } } diff --git a/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs b/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs index 5c60b81a8e..bd23341e73 100644 --- a/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs +++ b/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs @@ -169,7 +169,7 @@ namespace BizHawk.Client.EmuHawk { if (!f.CanWrite) { - throw new ArgumentException($"{nameof(Stream)} must be writable!"); + throw new ArgumentException(message: $"{nameof(Stream)} must be writable!", paramName: nameof(f)); } _f = f; @@ -323,11 +323,7 @@ namespace BizHawk.Client.EmuHawk /// private void WriteVar(int v) { - if (v < 0) - { - throw new ArgumentException("length cannot be less than 0!"); - } - + if (v < 0) throw new ArgumentException(message: "length cannot be less than 0!", paramName: nameof(v)); WriteVar((ulong)v); } @@ -542,7 +538,7 @@ namespace BizHawk.Client.EmuHawk } else { - throw new ArgumentException("codec token must be of right type"); + throw new ArgumentException(message: "codec token must be of right type", paramName: nameof(token)); } } @@ -590,10 +586,10 @@ namespace BizHawk.Client.EmuHawk { // the sampleRate limits are arbitrary, just to catch things which are probably silly-wrong // if a larger range of sampling rates is needed, it should be supported - if (!8000.RangeTo(96000).Contains(sampleRate) || !1.RangeTo(2).Contains(channels) || bits != 16) - { - throw new ArgumentException("Audio parameters out of range!"); - } + const string ERR_MSG_INVALID_ARG = "Audio parameters out of range!"; + if (sampleRate is < 8000 or > 96000) throw new ArgumentOutOfRangeException(paramName: nameof(sampleRate), sampleRate, message: ERR_MSG_INVALID_ARG); + if (channels is < 1 or > 2) throw new ArgumentOutOfRangeException(paramName: nameof(channels), channels, message: ERR_MSG_INVALID_ARG); + if (bits is not 16) throw new ArgumentException(message: ERR_MSG_INVALID_ARG, paramName: nameof(bits)); _audioSampleRate = sampleRate; _audioChannels = channels; diff --git a/src/BizHawk.Client.EmuHawk/AVOut/WavWriter.cs b/src/BizHawk.Client.EmuHawk/AVOut/WavWriter.cs index 53cedf6d6d..fd154e7d55 100644 --- a/src/BizHawk.Client.EmuHawk/AVOut/WavWriter.cs +++ b/src/BizHawk.Client.EmuHawk/AVOut/WavWriter.cs @@ -161,7 +161,7 @@ namespace BizHawk.Client.EmuHawk { if (_sampleRate < 1 || _numChannels < 1) { - throw new ArgumentException("Bad samplerate/numchannels"); + throw new InvalidOperationException("Bad samplerate/numchannels"); } } @@ -200,7 +200,7 @@ namespace BizHawk.Client.EmuHawk // advance to first if (!_fileChain.MoveNext()) { - throw new ArgumentException("Iterator was empty!"); + throw new ArgumentException(message: "Iterator was empty!", paramName: nameof(ss)); } OpenCurrent(ss.Current); @@ -234,15 +234,12 @@ namespace BizHawk.Client.EmuHawk return new WavWriterVToken(); } - /// is not 16 + /// is not 16 public void SetAudioParameters(int sampleRate, int channels, int bits) { _sampleRate = sampleRate; _channels = channels; - if (bits != 16) - { - throw new ArgumentException("Only support 16bit audio!"); - } + if (bits is not 16) throw new ArgumentException(message: "Only support 16bit audio!", paramName: nameof(bits)); } public void SetMetaData(string gameName, string authors, ulong lengthMs, ulong rerecords) diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/MsgBox.cs b/src/BizHawk.Client.EmuHawk/CustomControls/MsgBox.cs index 89f6bec8b3..0635757861 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/MsgBox.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/MsgBox.cs @@ -70,11 +70,7 @@ namespace BizHawk.Client.EmuHawk.CustomControls } int count = names.Length; - - if (!1.RangeTo(3).Contains(count)) - { - throw new ArgumentException("Invalid number of buttons. Must be between 1 and 3."); - } + if (count is < 1 or > 3) throw new ArgumentException(message: "Invalid number of buttons. Must be between 1 and 3.", paramName: nameof(names)); //---- Set Button 1 _minButtonRowWidth += SetButtonParams(btn1, names[0], def == 1 ? 1 : 2, results[0]); diff --git a/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs index 1d2136e49a..2bb1593268 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -75,7 +75,7 @@ namespace BizHawk.Client.EmuHawk { if (!typeof(IToolForm).IsAssignableFrom(toolType)) { - throw new ArgumentException($"Type {toolType.Name} does not implement {nameof(IToolForm)}."); + throw new ArgumentException(message: $"Type {toolType.Name} does not implement {nameof(IToolForm)}.", paramName: nameof(toolType)); } var mi = typeof(ToolManager).GetMethod(nameof(Load), new[] { typeof(bool), typeof(string) })!.MakeGenericMethod(toolType); return (IToolForm) mi.Invoke(this, new object[] { focus, "" }); diff --git a/src/BizHawk.Common/BinaryQuickSerializer.cs b/src/BizHawk.Common/BinaryQuickSerializer.cs index 77f410d61b..e808cb6bb7 100644 --- a/src/BizHawk.Common/BinaryQuickSerializer.cs +++ b/src/BizHawk.Common/BinaryQuickSerializer.cs @@ -17,7 +17,7 @@ namespace BizHawk.Common private static MethodInfo FromExpression(Expression e) => e is MethodCallExpression caller ? caller.Method - : throw new ArgumentException("Expression must be a method call"); + : throw new ArgumentException(message: "Expression must be a method call", paramName: nameof(e)); private static MethodInfo Method(Expression> f) { diff --git a/src/BizHawk.Common/DescribableEnumConverter.cs b/src/BizHawk.Common/DescribableEnumConverter.cs index 551be0ade3..63860350eb 100644 --- a/src/BizHawk.Common/DescribableEnumConverter.cs +++ b/src/BizHawk.Common/DescribableEnumConverter.cs @@ -22,7 +22,7 @@ namespace BizHawk.Common public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - var valueStr = value?.ToString() ?? throw new ArgumentException($"got null {nameof(value)}"); + var valueStr = value?.ToString() ?? throw new ArgumentNullException(paramName: nameof(value)); return Enum.Parse( enumType, enumType.GetFields(BindingFlags.Public | BindingFlags.Static) @@ -33,7 +33,7 @@ namespace BizHawk.Common public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType) { - var fieldName = Enum.GetName(enumType, value ?? throw new ArgumentException($"got null {nameof(value)}")); + var fieldName = Enum.GetName(enumType, value ?? throw new ArgumentNullException(paramName: nameof(value))); if (fieldName != null) { var fieldInfo = enumType.GetField(fieldName); diff --git a/src/BizHawk.Common/Extensions/PathExtensions.cs b/src/BizHawk.Common/Extensions/PathExtensions.cs index 26d6810b4c..7ec59db415 100644 --- a/src/BizHawk.Common/Extensions/PathExtensions.cs +++ b/src/BizHawk.Common/Extensions/PathExtensions.cs @@ -96,9 +96,9 @@ namespace BizHawk.Common.PathExtensions var path = new StringBuilder(260 /* = MAX_PATH */); return Win32Imports.PathRelativePathTo(path, fromPath, GetPathAttribute(fromPath), toPath, GetPathAttribute(toPath)) ? path.ToString() - : throw new ArgumentException("Paths must have a common prefix"); - } - + : throw new ArgumentException(message: "Paths must have a common prefix", paramName: nameof(toPath)); + } + /// absolute path (OS-dependent) equivalent to /// /// unless is given, uses CWDHacks.Get/Environment.CurrentDirectory, diff --git a/src/BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs b/src/BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs index 08f1f0966e..037b1ddce5 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs @@ -15,10 +15,7 @@ namespace BizHawk.Emulation.Common.Base_Implementations /// is not public void SetSyncMode(SyncSoundMode mode) { - if (mode != SyncSoundMode.Sync) - { - throw new ArgumentException("Only supports Sync mode"); - } + if (mode is not SyncSoundMode.Sync) throw new ArgumentException(message: "Only supports Sync mode", paramName: nameof(mode)); } public SyncSoundMode SyncMode => SyncSoundMode.Sync; diff --git a/src/BizHawk.Emulation.Common/Sound/SpeexResampler.cs b/src/BizHawk.Emulation.Common/Sound/SpeexResampler.cs index 151450d0cf..3d15421fb4 100644 --- a/src/BizHawk.Emulation.Common/Sound/SpeexResampler.cs +++ b/src/BizHawk.Emulation.Common/Sound/SpeexResampler.cs @@ -73,7 +73,7 @@ namespace BizHawk.Emulation.Common case LibSpeexDSP.RESAMPLER_ERR.BAD_STATE: throw new Exception($"{nameof(LibSpeexDSP)}: Bad state"); case LibSpeexDSP.RESAMPLER_ERR.INVALID_ARG: - throw new ArgumentException($"{nameof(LibSpeexDSP)}: Bad Argument"); + throw new Exception($"{nameof(LibSpeexDSP)}: Bad Argument"); case LibSpeexDSP.RESAMPLER_ERR.PTR_OVERLAP: throw new Exception($"{nameof(LibSpeexDSP)}: Buffers cannot overlap"); } @@ -90,10 +90,7 @@ namespace BizHawk.Emulation.Common /// unmanaged call failed public SpeexResampler(Quality quality, uint rationum, uint ratioden, uint sratein, uint srateout, Action drainer = null, ISoundProvider input = null) { - if (drainer != null && input != null) - { - throw new ArgumentException($"Can't autofetch without being an {nameof(ISoundProvider)}?"); - } + if (drainer is not null && input is not null) throw new ArgumentException(message: $"Can't autofetch without being an {nameof(ISoundProvider)}?", paramName: nameof(input)); var err = LibSpeexDSP.RESAMPLER_ERR.SUCCESS; _st = NativeDSP.speex_resampler_init_frac(2, rationum, ratioden, sratein, srateout, quality, ref err); diff --git a/src/BizHawk.Emulation.Cores/CPUs/68000/Memory.cs b/src/BizHawk.Emulation.Cores/CPUs/68000/Memory.cs index bf8b79677a..d456c4c5d4 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/68000/Memory.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/68000/Memory.cs @@ -366,8 +366,9 @@ namespace BizHawk.Emulation.Cores.Components.M68000 case 4: immed = ReadLong(pc); pc += 4; return $"#${immed:X}"; + default: + throw new ArgumentException(message: "Invalid size", paramName: nameof(size)); } - throw new ArgumentException("Invalid size"); } private string DisassembleAddress(int mode, int reg, ref int pc) diff --git a/src/BizHawk.Emulation.Cores/CPUs/CP1610/CP1610.Execute.cs b/src/BizHawk.Emulation.Cores/CPUs/CP1610/CP1610.Execute.cs index d739dc0592..1b663b7895 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/CP1610/CP1610.Execute.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/CP1610/CP1610.Execute.cs @@ -224,7 +224,7 @@ namespace BizHawk.Emulation.Cores.Components.CP1610 break; case 0x3: // Unknown opcode. - throw new ArgumentException(); + throw new InvalidOperationException(); } RegisterPC = addr; cycles = 12; @@ -1164,7 +1164,7 @@ namespace BizHawk.Emulation.Cores.Components.CP1610 // BEXT if (ext != 0) { - throw new ArgumentException(UNEXPECTED_BEXT); + throw new InvalidOperationException(UNEXPECTED_BEXT); } else { diff --git a/src/BizHawk.Emulation.Cores/Calculators/Emu83/Emu83.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Calculators/Emu83/Emu83.IMemoryDomains.cs index 83909a5e9f..3b8b8959fd 100644 --- a/src/BizHawk.Emulation.Cores/Calculators/Emu83/Emu83.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Calculators/Emu83/Emu83.IMemoryDomains.cs @@ -33,20 +33,12 @@ namespace BizHawk.Emulation.Cores.Calculators.Emu83 _memoryDomains.Add(new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little, addr => { - if (addr < 0 || addr >= 0x10000) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return LibEmu83.TI83_ReadMemory(Context, (ushort)addr); }, (addr, val) => { - if (addr < 0 || addr >= 0x10000) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); LibEmu83.TI83_WriteMemory(Context, (ushort)addr, val); }, 1)); diff --git a/src/BizHawk.Emulation.Cores/Calculators/TI83/TI83.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Calculators/TI83/TI83.IMemoryDomains.cs index d9412b485d..d5faf55949 100644 --- a/src/BizHawk.Emulation.Cores/Calculators/TI83/TI83.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Calculators/TI83/TI83.IMemoryDomains.cs @@ -19,20 +19,12 @@ namespace BizHawk.Emulation.Cores.Calculators.TI83 var systemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little, (addr) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return _cpu.ReadMemory((ushort)addr); }, (addr, value) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); _cpu.WriteMemory((ushort)addr, value); }, 1); diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IMemoryDomains.cs index e3d8a16beb..d4b4d60b99 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IMemoryDomains.cs @@ -22,18 +22,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little, (addr) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return _machine.ReadBus((ushort)addr); }, (addr, value) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); _machine.WriteBus((ushort)addr, value); }, 1) }; diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.Util.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.Util.cs index bc1ea0475c..61d92baf09 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.Util.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.Util.cs @@ -15,9 +15,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC /// public static int GetIntFromBitArray(BitArray bitArray) { - if (bitArray.Length > 32) - throw new ArgumentException("Argument length shall be at most 32 bits."); - + if (bitArray.Length > 32) throw new ArgumentException(message: "Argument length shall be at most 32 bits.", paramName: nameof(bitArray)); int[] array = new int[1]; bitArray.CopyTo(array, 0); return array[0]; diff --git a/src/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IMemoryDomains.cs index 4efccf5c36..7ae2a80591 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IMemoryDomains.cs @@ -14,20 +14,12 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII var mainRamDomain = new MemoryDomainDelegate("Main Ram", 0xC000, MemoryDomain.Endian.Little, addr => { - if (addr < 0 || addr >= 0xC000) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xBFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return (byte)_machine.Memory.Peek((int)addr); }, (addr, value) => { - if (addr < 0 || addr >= 0xC000) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xBFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); _machine.Memory.Write((int)addr, value); }, 1); @@ -36,20 +28,12 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII var systemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little, addr => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return (byte)_machine.Memory.Peek((int)addr); }, (addr, value) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); _machine.Memory.Write((int)addr, value); }, 1); diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IMemoryDomains.cs index 976d98581e..e23c31c8ca 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IMemoryDomains.cs @@ -22,19 +22,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little, (addr) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return _machine.ReadBus((ushort)addr); }, (addr, value) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); _machine.WriteBus((ushort)addr, value); }, 1) }; diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Util.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Util.cs index ced76bb1df..058aa948ae 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Util.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Util.cs @@ -15,9 +15,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public static int GetIntFromBitArray(BitArray bitArray) { - if (bitArray.Length > 32) - throw new ArgumentException("Argument length shall be at most 32 bits."); - + if (bitArray.Length > 32) throw new ArgumentException(message: "Argument length shall be at most 32 bits.", paramName: nameof(bitArray)); int[] array = new int[1]; bitArray.CopyTo(array, 0); return array[0]; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IMemoryDomains.cs index d781388cd9..3ded4d582b 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IMemoryDomains.cs @@ -19,20 +19,12 @@ namespace BizHawk.Emulation.Cores.ColecoVision new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little, addr => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return _cpu.ReadMemory((ushort)addr); }, (addr, value) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); _cpu.WriteMemory((ushort)addr, value); }, 1) }; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.MemoryDomains.cs b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.MemoryDomains.cs index 4ca26408b8..6881bbfe37 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.MemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.MemoryDomains.cs @@ -18,19 +18,12 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Big, (addr) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return ReadBus((ushort)addr); }, (addr, value) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); WriteBus((ushort)addr, value); }, 1) }; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellicart.cs b/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellicart.cs index a53bfa4fcf..e2e4d7c7d0 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellicart.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellicart.cs @@ -83,10 +83,7 @@ namespace BizHawk.Emulation.Cores.Intellivision crc = UpdateCRC16(crc, upper_end); ushort start = (ushort)(upper_start << 8); ushort end = (ushort)((upper_end << 8) | 0xFF); - if (end < start) - { - throw new ArgumentException("Ranges can't start higher than they end."); - } + if (end < start) throw new ArgumentException(message: "Ranges can't start higher than they end.", paramName: nameof(Rom)); for (int addr = start; addr <= end; addr++) { @@ -100,10 +97,7 @@ namespace BizHawk.Emulation.Cores.Intellivision } expected = (ushort)((Rom[offset++] << 8) | Rom[offset++]); - if (expected != crc) - { - throw new ArgumentException("Invalid CRC."); - } + if (expected != crc) throw new ArgumentException(message: "Invalid CRC.", paramName: nameof(Rom)); } // Parse for memory attributes. @@ -151,10 +145,7 @@ namespace BizHawk.Emulation.Cores.Intellivision int rangeStart = range * 2048; ushort start = (ushort)((((Rom[index] >> 4) & 0x07) << 8) + rangeStart); ushort end = (ushort)(((Rom[index] & 0x07) << 8) + 0xFF + rangeStart); - if (end < start) - { - throw new ArgumentException("Ranges can't start higher than they end."); - } + if (end < start) throw new ArgumentException(message: "Ranges can't start higher than they end.", paramName: nameof(Rom)); FineAddresses[range] = new ushort[2]; FineAddresses[range][0] = start; @@ -170,10 +161,7 @@ namespace BizHawk.Emulation.Cores.Intellivision expected = (ushort)((Rom[offset++] << 8) | (Rom[offset++] & 0xFF)); // Check if there is an invalid CRC for the memory attributes / fine addresses. - if (expected != crc) - { - throw new ArgumentException("Invalid CRC."); - } + if (expected != crc) throw new ArgumentException(message: "Invalid CRC.", paramName: nameof(Rom)); return offset; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Intellivision/STIC.cs b/src/BizHawk.Emulation.Cores/Consoles/Intellivision/STIC.cs index a4abb4cb67..a1c812f63b 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Intellivision/STIC.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Intellivision/STIC.cs @@ -307,9 +307,9 @@ namespace BizHawk.Emulation.Cores.Intellivision return 0x75CC80; case 15: return 0xB51A58; + default: + throw new ArgumentOutOfRangeException(paramName: nameof(color), color, message: "Specified color does not exist."); } - - throw new ArgumentException("Specified color does not exist."); } public void Background(int input_row) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IMemoryDomains.cs index 379d44f913..30684ca990 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IMemoryDomains.cs @@ -39,20 +39,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy _memoryDomains.Add(new MemoryDomainDelegate("System Bus", 65536, MemoryDomain.Endian.Little, addr => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return LibGambatte.gambatte_cpuread(GambatteState, (ushort)addr); }, (addr, val) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); LibGambatte.gambatte_cpuwrite(GambatteState, (ushort)addr, val); }, 1)); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISaveRam.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISaveRam.cs index cea0cb520b..89cdbe90fe 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISaveRam.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISaveRam.cs @@ -36,13 +36,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy public void StoreSaveRam(byte[] data) { int expected = LibGambatte.gambatte_getsavedatalength(GambatteState); - switch (data.Length - expected) - { - case 0: - break; - default: - throw new ArgumentException("Size of saveram data does not match expected!"); - } + if (data.Length != expected) throw new ArgumentException(message: "Size of saveram data does not match expected!", paramName: nameof(data)); LibGambatte.gambatte_loadsavedata(GambatteState, data); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/RamAdapter.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/RamAdapter.cs index cf4a2c79c5..a6eb72c53f 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/RamAdapter.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/RamAdapter.cs @@ -209,8 +209,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES /// disk is write protected public void Insert(byte[] side, int bitlength, bool writeprotect) { - if (side.Length * 8 < bitlength) - throw new ArgumentException("Disk too small for parameter!"); + if (side.Length * 8 < bitlength) throw new ArgumentException(message: "Disk too small for parameter!", paramName: nameof(side)); disk = side; disksize = bitlength; diskpos = 0; @@ -237,8 +236,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public void ApplyDiff(byte[] data) { int bitsize = data[0] * 0x10000 + data[1] * 0x100 + data[2]; - if (bitsize != disksize) - throw new ArgumentException("Disk size mismatch!"); + if (bitsize != disksize) throw new ArgumentException(message: "Disk size mismatch!", paramName: nameof(data)); int pos = 0; while (bitsize > 0) { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IMemoryDomains.cs index c6b055f5d5..8f1fa83be7 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IMemoryDomains.cs @@ -34,20 +34,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES MemoryDomain.Endian.Unknown, addr => { - if (addr < 0 || addr >= 0x10000) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return QN.qn_peek_prgbus(Context, (int)addr); }, (addr, val) => { - if (addr < 0 || addr >= 0x10000) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); QN.qn_poke_prgbus(Context, (int)addr, val); }, 1)); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IMemoryDomains.cs index 48026c2659..9216a39080 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IMemoryDomains.cs @@ -46,20 +46,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.Sameboy _memoryDomains.Add(new MemoryDomainDelegate("System Bus", 65536, MemoryDomain.Endian.Little, addr => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return LibSameboy.sameboy_cpuread(SameboyState, (ushort)addr); }, (addr, val) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); LibSameboy.sameboy_cpuwrite(SameboyState, (ushort)addr, val); }, 1)); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.ISaveRam.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.ISaveRam.cs index cef62cb31f..79458d617a 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.ISaveRam.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.ISaveRam.cs @@ -25,10 +25,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Sameboy public void StoreSaveRam(byte[] data) { int expected = LibSameboy.sameboy_sramlen(SameboyState); - if (data.Length - expected != 0) - { - throw new ArgumentException("Size of saveram data does not match expected!"); - } + if (data.Length != expected) throw new ArgumentException(message: "Size of saveram data does not match expected!", paramName: nameof(data)); if (expected > 0) { diff --git a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.IMemoryDomains.cs index 5d1861cf38..e3d704065d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.IMemoryDomains.cs @@ -20,14 +20,12 @@ namespace BizHawk.Emulation.Cores.PCEngine var systemBusDomain = new MemoryDomainDelegate("System Bus (21 bit)", 0x200000, MemoryDomain.Endian.Little, (addr) => { - if (addr < 0 || addr >= 0x200000) - throw new ArgumentOutOfRangeException(); + if (addr is < 0 or > 0x1FFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return Cpu.ReadMemory21((int)addr); }, (addr, value) => { - if (addr < 0 || addr >= 0x200000) - throw new ArgumentOutOfRangeException(); + if (addr is < 0 or > 0x1FFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); Cpu.WriteMemory21((int)addr, value); }, wordSize: 2); @@ -36,14 +34,12 @@ namespace BizHawk.Emulation.Cores.PCEngine var cpuBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little, (addr) => { - if (addr < 0 || addr >= 0x10000) - throw new ArgumentOutOfRangeException(); + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return Cpu.PeekMemory((ushort)addr); }, (addr, value) => { - if (addr < 0 || addr >= 0x10000) - throw new ArgumentOutOfRangeException(); + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); Cpu.PokeMemory((ushort)addr, value); }, wordSize: 2); diff --git a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs index 28c5e7c355..674f850bd5 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs @@ -60,7 +60,7 @@ namespace BizHawk.Emulation.Cores.PCEngine switch (portNum) { default: - throw new ArgumentException($"Invalid {nameof(portNum)}: {portNum}"); + throw new ArgumentOutOfRangeException(paramName: nameof(portNum), portNum, "port index out of range"); case 1: return _port1.Read(c, sel); case 2: diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IMemoryDomains.cs index 048e7fb28e..3801f193e6 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IMemoryDomains.cs @@ -19,20 +19,12 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little, (addr) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return Cpu.ReadMemory((ushort)addr); }, (addr, value) => { - if (addr < 0 || addr >= 65536) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); Cpu.WriteMemory((ushort)addr, value); }, 1) }; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IMemoryDomains.cs index 4d9afe7859..e9b112a41a 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IMemoryDomains.cs @@ -36,15 +36,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx mm.Add(new MemoryDomainDelegate(name, size, MemoryDomain.Endian.Unknown, addr => { - if (addr < 0 || addr >= 65536) - throw new ArgumentOutOfRangeException(); + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); using (_elf.EnterExit()) return p[addr ^ 1]; }, (addr, val) => { - if (addr < 0 || addr >= 65536) - throw new ArgumentOutOfRangeException(); + if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); Core.gpgx_poke_vram(((int)addr) ^ 1, val); }, wordSize: 2)); @@ -62,15 +60,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx addr => { var a = (uint)addr; - if (a >= 0x1000000) - throw new ArgumentOutOfRangeException(); + if (a > 0xFFFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), a, message: "address out of range"); return Core.gpgx_peek_m68k_bus(a); }, (addr, val) => { var a = (uint)addr; - if (a >= 0x1000000) - throw new ArgumentOutOfRangeException(); + if (a > 0xFFFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), a, message: "address out of range"); Core.gpgx_write_m68k_bus(a, val); }, 2); @@ -82,15 +78,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx addr => { var a = (uint)addr; - if (a >= 0x1000000) - throw new ArgumentOutOfRangeException(); + if (a > 0xFFFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), a, message: "address out of range"); return Core.gpgx_peek_s68k_bus(a); }, (addr, val) => { var a = (uint)addr; - if (a >= 0x1000000) - throw new ArgumentOutOfRangeException(); + if (a > 0xFFFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), a, message: "address out of range"); Core.gpgx_write_s68k_bus(a, val); }, 2);