Skip to content

Commit

Permalink
fix #4142
Browse files Browse the repository at this point in the history
store slot index for each drive instead of filename, and add it to savestates
  • Loading branch information
vadosnaprimer committed Dec 22, 2024
1 parent a836884 commit 0e300fc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/BizHawk.Emulation.Cores/Computers/Amiga/LibUAE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
54 changes: 35 additions & 19 deletions src/BizHawk.Emulation.Cores/Computers/Amiga/UAE.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

using BizHawk.Emulation.Common;
Expand All @@ -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
Expand All @@ -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<IRomAsset> _roms;
private const int _messageDuration = 4;
private const int _driveNullOrEmpty = -1;
private int[] _driveSlots;
private List<string> _args;
private List<string> _drives;
private int _currentDrive;
private int _currentSlot;
private bool _ejectPressed;
Expand All @@ -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;
Expand All @@ -75,7 +78,7 @@ public UAE(CoreLoadParameters<object, UAESyncSettings> lp)
_syncSettings.ControllerPort1,
_syncSettings.ControllerPort2
];
_drives = new(_syncSettings.FloppyDrives);
_driveSlots = Enumerable.Repeat(_driveNullOrEmpty, LibUAE.MAX_FLOPPIES).ToArray();
DriveLightEnabled = _syncSettings.FloppyDrives > 0;

UpdateVideoStandard(true);
Expand All @@ -101,7 +104,7 @@ public UAE(CoreLoadParameters<object, UAESyncSettings> 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");
Expand Down Expand Up @@ -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))
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 0e300fc

Please sign in to comment.