From 4f8beb55362c3953b80e3e225ba080c0837bd420 Mon Sep 17 00:00:00 2001 From: feos Date: Sat, 7 Jun 2025 15:36:59 +0300 Subject: [PATCH] cleanup --- .../Computers/Amiga/LibUAE.cs | 1 + .../Computers/Amiga/UAE.Controllers.cs | 4 +- .../Computers/Amiga/UAE.ISettable.cs | 44 ++++++++--------- .../Computers/Amiga/UAE.cs | 18 +++---- .../Computers/Doom/DSDA.Controller.cs | 12 ++--- .../Computers/Doom/DSDA.IEmulator.cs | 8 +-- .../Computers/Doom/DSDA.IMemoryDomains.cs | 10 ++-- .../Computers/Doom/DSDA.IVideoProvider.cs | 2 +- .../Computers/Doom/DSDA.cs | 49 +++++++++++++------ .../Consoles/Atari/Stella/Stella.ISettable.cs | 2 +- .../Consoles/Atari/Stella/Stella.cs | 2 +- 11 files changed, 86 insertions(+), 66 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Computers/Amiga/LibUAE.cs b/src/BizHawk.Emulation.Cores/Computers/Amiga/LibUAE.cs index dd0ba79b33..5b72f35c03 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Amiga/LibUAE.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Amiga/LibUAE.cs @@ -125,6 +125,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga [Flags] public enum AllButtons : short { + None = 0b0000000000000000, Up = 0b0000000000000001, Down = 0b0000000000000010, Left = 0b0000000000000100, diff --git a/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.Controllers.cs b/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.Controllers.cs index cb50008d0d..7e6b0d4d19 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.Controllers.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.Controllers.cs @@ -8,7 +8,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga { public partial class UAE { - private LibUAE.ControllerType[] _ports { get; set; } + private LibUAE.ControllerType[] Ports { get; set; } private static readonly (string Name, LibUAE.AllButtons Button)[] _joystickMap = CreateJoystickMap(); private static readonly (string Name, LibUAE.AllButtons Button)[] _cd32padMap = CreateCd32padMap(); private static readonly (string Name, LibUAE.UAEKeyboard Key)[] _keyboardMap = CreateKeyboardMap(); @@ -62,7 +62,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga for (int port = 1; port <= 2; port++) { - LibUAE.ControllerType type = port == 1 + var type = port == 1 ? settings.ControllerPort1 : settings.ControllerPort2; diff --git a/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.ISettable.cs b/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.ISettable.cs index 0b165bc288..131865b9dd 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.ISettable.cs @@ -145,56 +145,56 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga private void CreateArguments(UAESyncSettings settings) { - _args = new List - { + _args = + [ "uae", - }; + ]; switch(settings.MachineConfig) { case MachineConfig.A500_OCS_130_512K_512K: _chipsetCompatible = Enum.GetName(typeof(ChipsetCompatible), ChipsetCompatible.A500); - AppendSetting(new List - { + AppendSetting( + [ "cpu_model=" + (int)CpuModel._68000, "chipset=" + Chipset.OCS, "chipset_compatible=" + _chipsetCompatible, "chipmem_size=" + (int)ChipMemory.KB_512, "bogomem_size=" + (int)SlowMemory.KB_512, "fastmem_size=0", - }); + ]); EnableCycleExact(); break; case MachineConfig.A600_ECS_205_2M: _chipsetCompatible = Enum.GetName(typeof(ChipsetCompatible), ChipsetCompatible.A600); - AppendSetting(new List - { + AppendSetting( + [ "cpu_model=" + (int)CpuModel._68000, "chipset=" + Chipset.ECS, "chipset_compatible=" + _chipsetCompatible, "chipmem_size=" + (int)ChipMemory.MB_2, "bogomem_size=" + (int)SlowMemory.KB_0, "fastmem_size=0", - }); + ]); EnableCycleExact(); break; case MachineConfig.A1200_AGA_310_2M_8M: _chipsetCompatible = Enum.GetName(typeof(ChipsetCompatible), ChipsetCompatible.A1200); - AppendSetting(new List - { + AppendSetting( + [ "cpu_model=" + (int)CpuModel._68020, "chipset=" + Chipset.AGA, "chipset_compatible=" + _chipsetCompatible, "chipmem_size=" + (int)ChipMemory.MB_2, "bogomem_size=" + (int)SlowMemory.KB_0, "fastmem_size=0", - }); + ]); EnableCycleExact(); break; case MachineConfig.A4000_AGA_310_2M_8M: _chipsetCompatible = Enum.GetName(typeof(ChipsetCompatible), ChipsetCompatible.A4000); - AppendSetting(new List - { + AppendSetting( + [ "cpu_model=" + (int)CpuModel._68040, "fpu_model=68040", "mmu_model=68040", @@ -203,7 +203,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga "chipmem_size=" + (int)ChipMemory.MB_2, "bogomem_size=" + (int)SlowMemory.KB_0, "fastmem_size=8", - }); + ]); break; } @@ -258,7 +258,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga for (int port = 0; port <= 1; port++) { - LibUAE.ControllerType type = port == 0 + var type = port == 0 ? settings.ControllerPort1 : settings.ControllerPort2; AppendSetting(type is LibUAE.ControllerType.None @@ -269,13 +269,13 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga private void EnableCycleExact() { - AppendSetting(new List - { + AppendSetting( + [ "cpu_compatible=true", "cpu_cycle_exact=true", "cpu_memory_cycle_exact=true", "blitter_cycle_exact=true", - }); + ]); } private void AppendSetting(List settings) @@ -288,10 +288,10 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga private void AppendSetting(string setting) { - _args.AddRange(new List - { + _args.AddRange( + [ "-s", setting - }); + ]); } public object GetSettings() => null; diff --git a/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.cs b/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.cs index 9132fcf7d4..9ed6ef6229 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.cs @@ -17,7 +17,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga isReleased: true)] public partial class UAE : WaterboxCore { - private static readonly Configuration ConfigPAL = new Configuration + private static readonly Configuration ConfigPAL = new() { SystemId = VSystemID.Raw.Amiga, MaxSamples = 8 * 1024, @@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga DefaultFpsDenominator = LibUAE.VIDEO_DENOMINATOR_PAL }; - private static readonly Configuration ConfigNTSC = new Configuration + private static readonly Configuration ConfigNTSC = new() { SystemId = VSystemID.Raw.Amiga, MaxSamples = 8 * 1024, @@ -75,7 +75,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga DeterministicEmulation = lp.DeterministicEmulationRequested || _syncSettings.FloppySpeed is FloppySpeed._100; var filesToRemove = new List(); - _ports = [ + Ports = [ _syncSettings.ControllerPort1, _syncSettings.ControllerPort2 ]; @@ -97,7 +97,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga MmapHeapSizeKB = 20 * 1024, SkipCoreConsistencyCheck = lp.Comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxCoreConsistencyCheck), SkipMemoryConsistencyCheck = lp.Comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck), - }, new Delegate[] { _ledCallback }); + }, [ _ledCallback ]); for (var index = 0; index < lp.Roms.Count; index++) { @@ -146,13 +146,13 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga { Port1 = new LibUAE.ControllerState { - Type = _ports[0], - Buttons = 0 + Type = Ports[0], + Buttons = LibUAE.AllButtons.None }, Port2 = new LibUAE.ControllerState { - Type = _ports[1], - Buttons = 0 + Type = Ports[1], + Buttons = LibUAE.AllButtons.None }, Action = LibUAE.DriveAction.None }; @@ -161,7 +161,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga { ref var currentPort = ref (port is 1 ? ref fi.Port1 : ref fi.Port2); - switch (_ports[port - 1]) + switch (Ports[port - 1]) { case LibUAE.ControllerType.DJoy: { diff --git a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.Controller.cs b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.Controller.cs index 3443c8b4a7..4049cb3a04 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.Controller.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.Controller.cs @@ -8,15 +8,13 @@ namespace BizHawk.Emulation.Cores.Computers.Doom { public static ControllerDefinition CreateControllerDefinition(DoomSyncSettings settings) { - var controller = new ControllerDefinition($"Doom Controller"); + var controller = new ControllerDefinition("Doom Controller"); var longtics = settings.TurningResolution == TurningResolution.Longtics; - for (int i = 0; i < 4; i++) + for (int port = 1; port <= 4; port++) { - if ((PlayersPresent(settings) & (1 << i)) is not 0) + if (PlayerPresent(settings, port)) { - var port = i + 1; - controller .AddAxis($"P{port} Run Speed", (-50).RangeTo(50), 0) .AddAxis($"P{port} Strafing Speed", (-50).RangeTo(50), 0) @@ -31,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom } controller - .AddAxis($"P{port} Weapon Select", (0).RangeTo(7), 0) + .AddAxis($"P{port} Weapon Select", 0.RangeTo(7), 0) .AddAxis($"P{port} Mouse Running", (-128).RangeTo(127), 0) // current max raw mouse delta is 180 .AddAxis($"P{port} Mouse Turning", (longtics ? -180 : -128).RangeTo(longtics ? 180 : 127), 0); @@ -40,7 +38,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom { controller .AddAxis($"P{port} Fly / Look", (-7).RangeTo(7), 0) - .AddAxis($"P{port} Use Artifact", (0).RangeTo(10), 0); + .AddAxis($"P{port} Use Artifact", 0.RangeTo(10), 0); } controller.BoolButtons.AddRange([ diff --git a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IEmulator.cs b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IEmulator.cs index 73f0d357de..60999e00c8 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IEmulator.cs @@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom // cycle through [0 - 4] _settings.Gamma++; _settings.Gamma %= 5; - _comm.Notify("Gamma correction " + + Comm.Notify("Gamma correction " + (_settings.Gamma == 0 ? "OFF" : "level " + _settings.Gamma), 4); // internal messages last 4 seconds } @@ -59,9 +59,9 @@ namespace BizHawk.Emulation.Cores.Computers.Doom for (int i = 0; i < 4; i++) { - if ((PlayersPresent(_syncSettings) & (1 << i)) is not 0) + var port = i + 1; + if (PlayerPresent(_syncSettings, port)) { - int port = i + 1; players[i].Buttons = LibDSDA.Buttons.None; bool strafe = controller.IsPressed($"P{port} Strafe"); @@ -231,7 +231,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom } } - LibDSDA.PackedRenderInfo renderInfo = new LibDSDA.PackedRenderInfo() + var renderInfo = new LibDSDA.PackedRenderInfo() { SfxVolume = _settings.SfxVolume, MusicVolume = _settings.MusicVolume, diff --git a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IMemoryDomains.cs index 27c4357485..2e0a18686b 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IMemoryDomains.cs @@ -18,15 +18,15 @@ namespace BizHawk.Emulation.Cores.Computers.Doom MemoryDomain.Endian.Little, addr => { - if (addr > 0xFFFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); - return _core.dsda_read_memory_array(LibDSDA.MemoryArrayType.Things, (uint)addr); + if (addr > 0xFFFFFF) + throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); + return _core.dsda_read_memory_array(LibDSDA.MemoryArrayType.Things, (uint) addr); }, null, 1), + _elf.GetPagesDomain() }; - - domains.Add(_elf.GetPagesDomain()); - MemoryDomains = new MemoryDomainList(domains) { }; + MemoryDomains = new MemoryDomainList(domains); ((BasicServiceProvider)ServiceProvider).Register(MemoryDomains); } } diff --git a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IVideoProvider.cs b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IVideoProvider.cs index 0dc2c72f5a..a308743d9b 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IVideoProvider.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IVideoProvider.cs @@ -21,7 +21,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom { using (_elf.EnterExit()) { - _core.dsda_get_video(gamma, out LibDSDA.VideoInfo vi); + _core.dsda_get_video(gamma, out var vi); var videoBuffer = (byte*)vi.VideoBuffer.ToPointer(); var paletteBuffer = (int*)vi.PaletteBuffer.ToPointer(); diff --git a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.cs b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.cs index 93f9f0ea5d..cbb34ec5bd 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.cs @@ -28,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom ServiceProvider = new BasicServiceProvider(this); _finalSyncSettings = _syncSettings = lp.SyncSettings ?? new DoomSyncSettings(); _settings = lp.Settings ?? new DoomSettings(); - _comm = lp.Comm; + Comm = lp.Comm; _loadCallback = LoadCallback; // Gathering information for the rest of the wads @@ -46,7 +46,13 @@ namespace BizHawk.Emulation.Cores.Computers.Doom if (wadFile.RomData is [ (byte) 'I', (byte) 'W', (byte) 'A', (byte) 'D', .. ]) { // Check not more than one IWAD is provided - if (foundIWAD) throw new Exception($"More than one IWAD provided. Trying to load '{wadFile.RomPath}', but IWAD '{IWADName}' was already provided"); + if (foundIWAD) + { + throw new ArgumentException( + $"More than one IWAD provided. Trying to load '{wadFile.RomPath}', but IWAD '{IWADName}' was already provided", + paramName: nameof(lp)); + } + IWADName = wadFile.RomPath; _iwadFile = wadFile; foundIWAD = true; @@ -60,14 +66,18 @@ namespace BizHawk.Emulation.Cores.Computers.Doom if (!recognized) { - throw new Exception($"Unrecognized WAD provided: '{wadFile.RomPath}' has non-standard header."); + throw new ArgumentException( + $"Unrecognized WAD provided: '{wadFile.RomPath}' has non-standard header.", + paramName: nameof(lp)); } } // Check at least one IWAD was provided if (!foundIWAD) { - throw new Exception("No IWAD was provided"); + throw new ArgumentException( + "No IWAD was provided", + paramName: nameof(lp)); } // Getting dsda-doom.wad -- required by DSDA @@ -149,7 +159,9 @@ namespace BizHawk.Emulation.Cores.Computers.Doom _gameMode = _core.dsda_add_wad_file(_iwadFile.RomPath, _iwadFile.RomData.Length, _loadCallback); if (_gameMode is LibDSDA.GameMode.Fail) { - throw new Exception($"Could not load WAD file: '{_iwadFile.RomPath}'"); + throw new ArgumentException( + $"Could not load WAD file: '{_iwadFile.RomPath}'", + paramName: nameof(lp)); } // Adding PWAD file(s) @@ -158,18 +170,22 @@ namespace BizHawk.Emulation.Cores.Computers.Doom _gameMode = _core.dsda_add_wad_file(wadFile.RomPath, wadFile.RomData.Length, _loadCallback); if (_gameMode is LibDSDA.GameMode.Fail) { - throw new Exception($"Could not load WAD file: '{wadFile.RomPath}'"); + throw new ArgumentException( + $"Could not load WAD file: '{wadFile.RomPath}'", + paramName: nameof(lp)); } } _elf.AddReadonlyFile(_configFile, "dsda-doom.cfg"); - var initSettings = _syncSettings.GetNativeSettings(lp.Game); + var initSettings = _syncSettings.GetNativeSettings(); CreateArguments(initSettings); var initResult = _core.dsda_init(ref initSettings, _args.Count, _args.ToArray()); if (!initResult) { - throw new Exception($"{nameof(_core.dsda_init)}() failed"); + throw new ArgumentException( + $"{nameof(_core.dsda_init)}() failed", + paramName: nameof(lp)); } VsyncNumerator = 35; @@ -183,7 +199,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom if (_pwadFiles.Count > 0) { - SortedList hashes = new(); + SortedList hashes = [ ]; foreach (var file in _pwadFiles) { @@ -266,13 +282,18 @@ namespace BizHawk.Emulation.Cores.Computers.Doom private string GetFullName(IRomAsset rom) => Path.GetFileName(rom.RomPath.SubstringAfter('|')); - private static int PlayersPresent(DoomSyncSettings syncSettings) => Convert.ToInt32(syncSettings.Player1Present) - | Convert.ToInt32(syncSettings.Player2Present) << 1 - | Convert.ToInt32(syncSettings.Player3Present) << 2 - | Convert.ToInt32(syncSettings.Player4Present) << 3; + private static bool PlayerPresent(DoomSyncSettings syncSettings, int port) => + port switch + { + 1 => syncSettings.Player1Present, + 2 => syncSettings.Player2Present, + 3 => syncSettings.Player3Present, + 4 => syncSettings.Player4Present, + _ => false + }; // ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable - internal CoreComm _comm { get; } + internal CoreComm Comm { get; } private readonly WaterboxHost _elf; private readonly LibDSDA _core; private readonly LibDSDA.load_archive_cb _loadCallback; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.ISettable.cs index 645da9572d..ad23ea430e 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.ISettable.cs @@ -40,7 +40,7 @@ namespace BizHawk.Emulation.Cores.Atari.Stella [TypeConverter(typeof(DescribableEnumConverter))] public Atari2600ControllerTypes Port2 { get; set; } - public CInterface.InitSettings GetNativeSettings(GameInfo game) + public CInterface.InitSettings GetNativeSettings() { return new CInterface.InitSettings { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.cs index 7fcdda7a3c..437a77c6a0 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/Stella/Stella.cs @@ -52,7 +52,7 @@ namespace BizHawk.Emulation.Cores.Atari.Stella Core = BizInvoker.GetInvoker(_elf, _elf, callingConventionAdapter); _romfile = lp.Roms[0].RomData; - var initResult = Core.stella_init("rom.a26", _loadCallback, _syncSettings.GetNativeSettings(lp.Game)); + var initResult = Core.stella_init("rom.a26", _loadCallback, _syncSettings.GetNativeSettings()); if (!initResult) throw new Exception($"{nameof(Core.stella_init)}() failed");