From 0e300fc094fa890cc96e9b94a5cfaae2400c2c46 Mon Sep 17 00:00:00 2001 From: feos Date: Sun, 22 Dec 2024 16:25:21 +0300 Subject: [PATCH] fix #4142 store slot index for each drive instead of filename, and add it to savestates --- .../Computers/Amiga/LibUAE.cs | 12 ++--- .../Computers/Amiga/UAE.cs | 54 ++++++++++++------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Computers/Amiga/LibUAE.cs b/src/BizHawk.Emulation.Cores/Computers/Amiga/LibUAE.cs index 173411be3c..aec33fe2d9 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Amiga/LibUAE.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Amiga/LibUAE.cs @@ -17,12 +17,12 @@ public abstract class LibUAE : LibWaterboxCore // WinUAE displays 484 lines for NTSC // but libretro port only renders 482 and then only displays 480 public const int NTSC_HEIGHT = 482; - // libretro defines UAE_VIDEO_HZ_PAL as 49.9204101562500000f - public const int UAE_VIDEO_NUMERATOR_PAL = 102237; - public const int UAE_VIDEO_DENOMINATOR_PAL = 2048; - // libretro defines UAE_VIDEO_HZ_NTSC as 59.8260993957519531f - public const int UAE_VIDEO_NUMERATOR_NTSC = 299130497; - public const int UAE_VIDEO_DENOMINATOR_NTSC = 5000000; + // libretro defines PUAE_VIDEO_HZ_PAL as 49.9204101562500000f + public const int VIDEO_NUMERATOR_PAL = 102237; + public const int VIDEO_DENOMINATOR_PAL = 2048; + // libretro defines PUAE_VIDEO_HZ_NTSC as 59.8260993957519531f + public const int VIDEO_NUMERATOR_NTSC = 299130497; + public const int VIDEO_DENOMINATOR_NTSC = 5000000; public const int FASTMEM_AUTO = -1; public const int MAX_FLOPPIES = 4; diff --git a/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.cs b/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.cs index 5b2ed86f45..c424b5e5d2 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using BizHawk.Emulation.Common; @@ -23,8 +24,8 @@ public partial class UAE : WaterboxCore DefaultHeight = LibUAE.PAL_HEIGHT, MaxWidth = LibUAE.PAL_WIDTH, MaxHeight = LibUAE.PAL_HEIGHT, - DefaultFpsNumerator = LibUAE.UAE_VIDEO_NUMERATOR_PAL, - DefaultFpsDenominator = LibUAE.UAE_VIDEO_DENOMINATOR_PAL + DefaultFpsNumerator = LibUAE.VIDEO_NUMERATOR_PAL, + DefaultFpsDenominator = LibUAE.VIDEO_DENOMINATOR_PAL }; private static readonly Configuration ConfigNTSC = new Configuration @@ -36,15 +37,16 @@ public partial class UAE : WaterboxCore // games never switch region, and video dumping won't be happy, but amiga can still do it MaxWidth = LibUAE.PAL_WIDTH, MaxHeight = LibUAE.PAL_HEIGHT, - DefaultFpsNumerator = LibUAE.UAE_VIDEO_NUMERATOR_NTSC, - DefaultFpsDenominator = LibUAE.UAE_VIDEO_DENOMINATOR_NTSC + DefaultFpsNumerator = LibUAE.VIDEO_NUMERATOR_NTSC, + DefaultFpsDenominator = LibUAE.VIDEO_DENOMINATOR_NTSC }; private readonly LibWaterboxCore.EmptyCallback _ledCallback; private readonly List _roms; private const int _messageDuration = 4; + private const int _driveNullOrEmpty = -1; + private int[] _driveSlots; private List _args; - private List _drives; private int _currentDrive; private int _currentSlot; private bool _ejectPressed; @@ -53,9 +55,10 @@ public partial class UAE : WaterboxCore private bool _nextDrivePressed; private int _correctedWidth; private string _chipsetCompatible = ""; - public override int VirtualWidth => _correctedWidth; private string GetFullName(IRomAsset rom) => rom.Game.Name + rom.Extension; + public override int VirtualWidth => _correctedWidth; + private void LEDCallback() { DriveLightOn = true; @@ -75,7 +78,7 @@ public UAE(CoreLoadParameters lp) _syncSettings.ControllerPort1, _syncSettings.ControllerPort2 ]; - _drives = new(_syncSettings.FloppyDrives); + _driveSlots = Enumerable.Repeat(_driveNullOrEmpty, LibUAE.MAX_FLOPPIES).ToArray(); DriveLightEnabled = _syncSettings.FloppyDrives > 0; UpdateVideoStandard(true); @@ -101,7 +104,7 @@ public UAE(CoreLoadParameters lp) _exe.AddReadonlyFile(rom.FileData, FileNames.FD + index); if (index < _syncSettings.FloppyDrives) { - _drives.Add(GetFullName(rom)); + _driveSlots[index] = index; AppendSetting($"floppy{index}={FileNames.FD}{index}"); AppendSetting($"floppy{index}type={(int) DriveType.DRV_35_DD}"); AppendSetting("floppy_write_protect=true"); @@ -210,8 +213,8 @@ protected override LibWaterboxCore.FrameInfo FrameAdvancePrep(IController contro if (!_ejectPressed) { fi.Action = LibUAE.DriveAction.EjectDisk; - CoreComm.Notify($"Ejected drive FD{_currentDrive}: {_drives[_currentDrive]}", _messageDuration); - _drives[_currentDrive] = "empty"; + CoreComm.Notify($"Ejected drive FD{_currentDrive}: {GetFullName(_roms[_driveSlots[_currentDrive]])}", _messageDuration); + _driveSlots[_currentDrive] = _driveNullOrEmpty; } } else if (controller.IsPressed(Inputs.InsertDisk)) @@ -230,8 +233,8 @@ protected override LibWaterboxCore.FrameInfo FrameAdvancePrep(IController contro } } } - _drives[_currentDrive] = GetFullName(_roms[_currentSlot]); - CoreComm.Notify($"Insterted drive FD{_currentDrive}: {_drives[_currentDrive]}", _messageDuration); + _driveSlots[_currentDrive] = _currentSlot; + CoreComm.Notify($"Insterted drive FD{_currentDrive}: {GetFullName(_roms[_driveSlots[_currentDrive]])}", _messageDuration); } } @@ -252,11 +255,16 @@ protected override LibWaterboxCore.FrameInfo FrameAdvancePrep(IController contro { _currentDrive++; _currentDrive %= _syncSettings.FloppyDrives; - if (_drives.Count <= _currentDrive) + string name = ""; + if (_driveSlots[_currentDrive] == _driveNullOrEmpty) + { + name = "empty"; + } + else { - _drives.Add("empty"); + name = GetFullName(_roms[_driveSlots[_currentDrive]]); } - CoreComm.Notify($"Selected drive FD{_currentDrive}: {_drives[_currentDrive]}", _messageDuration); + CoreComm.Notify($"Selected drive FD{_currentDrive}: {name}", _messageDuration); } } @@ -293,6 +301,10 @@ protected override void SaveStateBinaryInternal(BinaryWriter writer) writer.Write(_nextDrivePressed); writer.Write(_currentDrive); writer.Write(_currentSlot); + writer.Write(_driveSlots[0]); + writer.Write(_driveSlots[1]); + writer.Write(_driveSlots[2]); + writer.Write(_driveSlots[3]); } protected override void LoadStateBinaryInternal(BinaryReader reader) @@ -303,6 +315,10 @@ protected override void LoadStateBinaryInternal(BinaryReader reader) _nextDrivePressed = reader.ReadBoolean(); _currentDrive = reader.ReadInt32(); _currentSlot = reader.ReadInt32(); + _driveSlots[0] = reader.ReadInt32(); + _driveSlots[1] = reader.ReadInt32(); + _driveSlots[2] = reader.ReadInt32(); + _driveSlots[3] = reader.ReadInt32(); } private void UpdateVideoStandard(bool initial) @@ -314,14 +330,14 @@ private void UpdateVideoStandard(bool initial) if (ntsc) { _correctedWidth = LibUAE.PAL_WIDTH * 6 / 7; - VsyncNumerator = LibUAE.UAE_VIDEO_NUMERATOR_NTSC; - VsyncDenominator = LibUAE.UAE_VIDEO_DENOMINATOR_NTSC; + VsyncNumerator = LibUAE.VIDEO_NUMERATOR_NTSC; + VsyncDenominator = LibUAE.VIDEO_DENOMINATOR_NTSC; } else { _correctedWidth = LibUAE.PAL_WIDTH; - VsyncNumerator = LibUAE.UAE_VIDEO_NUMERATOR_PAL; - VsyncDenominator = LibUAE.UAE_VIDEO_DENOMINATOR_PAL; + VsyncNumerator = LibUAE.VIDEO_NUMERATOR_PAL; + VsyncDenominator = LibUAE.VIDEO_DENOMINATOR_PAL; } }