uae: swapper wip

This commit is contained in:
feos 2024-06-13 17:33:42 +03:00
parent 830f5ba205
commit 52fb840b0e
3 changed files with 146 additions and 33 deletions

View File

@ -8,7 +8,13 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
{
public abstract class LibPUAE : LibWaterboxCore
{
public const int KEY_COUNT = 0x68;
public const int PAL_WIDTH = 720;
public const int PAL_HEIGHT = 576;
public const int NTSC_WIDTH = 720;
public const int NTSC_HEIGHT = 480;
public const int FASTMEM_AUTO = -1;
public const int MAX_FLOPPIES = 4;
public const int KEY_COUNT = 0x68;
[BizImport(CC, Compatibility = true)]
public abstract bool Init(int argc, string[] argv);
@ -40,6 +46,23 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
Joystick_Button_3 = 1 << 6
}
public enum DiscAction
{
Eject,
Insert
}
[Flags]
public enum DiskControl : byte
{
FloppyDrive0 = 1 << 0,
FloppyDrive1 = 1 << 1,
FloppyDrive2 = 1 << 2,
FloppyDrive3 = 1 << 3,
CdDrive = 1 << 4,
Trigger = 1 << 5
}
// https://wiki.amigaos.net/wiki/Keymap_Library
public enum PUAEKeyboard : int
{

View File

@ -220,7 +220,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
AppendSetting("bogomem_size=" + (int)settings.SlowMemory);
}
if (settings.FastMemory != FASTMEM_AUTO)
if (settings.FastMemory != LibPUAE.FASTMEM_AUTO)
{
AppendSetting("fastmem_size=" + settings.FastMemory);
}
@ -310,8 +310,8 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
[DisplayName("Fast memory")]
[Description("Size in megabytes of fast-memory. -1 means Auto.")]
[Range(FASTMEM_AUTO, 512)]
[DefaultValue(FASTMEM_AUTO)]
[Range(LibPUAE.FASTMEM_AUTO, 512)]
[DefaultValue(LibPUAE.FASTMEM_AUTO)]
[TypeConverter(typeof(ConstrainedIntConverter))]
public int FastMemory { get; set; }

View File

@ -3,9 +3,11 @@ using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Waterbox;
using BizHawk.Emulation.DiscSystem;
using System;
using System.Collections.Generic;
using System.IO;
namespace BizHawk.Emulation.Cores.Computers.Amiga
{
@ -16,31 +18,34 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
portedUrl: "https://github.com/libretro/libretro-uae")]
public partial class PUAE : WaterboxCore
{
internal CoreComm _comm { get; }
private readonly List<IRomAsset> _roms;
private readonly List<IDiscAsset> _discs;
private LibPUAE _puae;
private List<string> _args;
private static string _chipsetCompatible = "";
public const int PAL_WIDTH = 720;
public const int PAL_HEIGHT = 576;
public const int NTSC_WIDTH = 720;
public const int NTSC_HEIGHT = 480;
public const int FASTMEM_AUTO = -1;
public const int MAX_FLOPPIES = 4;
private static int _currentDrive = 0;
private static int _currentSlot = 0;
private bool _nextSlotPressed = false;
private bool _nextDrivePressed = false;
[CoreConstructor(VSystemID.Raw.Amiga)]
public PUAE(CoreLoadParameters<object, PUAESyncSettings> lp)
: base(lp.Comm, new Configuration
{
DefaultWidth = PAL_WIDTH,
DefaultHeight = PAL_HEIGHT,
MaxWidth = PAL_WIDTH,
MaxHeight = PAL_HEIGHT,
DefaultWidth = LibPUAE.PAL_WIDTH,
DefaultHeight = LibPUAE.PAL_HEIGHT,
MaxWidth = LibPUAE.PAL_WIDTH,
MaxHeight = LibPUAE.PAL_HEIGHT,
MaxSamples = 2 * 1024,
SystemId = VSystemID.Raw.Amiga,
DefaultFpsNumerator = 50,
DefaultFpsDenominator = 1
})
{
_comm = lp.Comm;
_roms = lp.Roms;
_discs = lp.Discs;
_syncSettings = lp.SyncSettings ?? new();
var filesToRemove = new List<string>();
CreateArguments(_syncSettings);
@ -59,20 +64,16 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
});
for (var index = 0; index < Math.Min(Math.Min(
lp.Roms.Count,
MAX_FLOPPIES),
_syncSettings.FloppyDrives
); index++)
lp.Roms.Count, LibPUAE.MAX_FLOPPIES), _syncSettings.FloppyDrives); index++)
{
_exe.AddReadonlyFile(lp.Roms[index].FileData, "disk" + index);
filesToRemove.Add("disk" + index);
AppendSetting($"floppy{ index }=disk{ index }");
_exe.AddReadonlyFile(lp.Roms[index].FileData, FileNames.FD + index);
AppendSetting($"floppy{ index }={ FileNames.FD }{ index }");
AppendSetting($"floppy{ index }type={ (int)DriveType.DRV_35_DD }");
}
var (kickstartData, kickstartInfo) = CoreComm.CoreFileProvider.GetFirmwareWithGameInfoOrThrow(
new(VSystemID.Raw.Amiga, _chipsetCompatible),
"Firmware files are usually required and may stop your game from loading");
"Firmware files are required!");
_exe.AddReadonlyFile(kickstartData, kickstartInfo.Name);
filesToRemove.Add(kickstartInfo.Name);
_args.AddRange(new List<string>
@ -83,9 +84,9 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
if (!_puae.Init(_args.Count, _args.ToArray()))
throw new InvalidOperationException("Core rejected the rom!");
foreach (var s in filesToRemove)
foreach (var f in filesToRemove)
{
//_exe.RemoveReadonlyFile(s);
_exe.RemoveReadonlyFile(f);
}
PostInit();
@ -104,12 +105,12 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
controller.BoolButtons.AddRange(new List<string>
{
"Mouse Left Button", "Mouse Middle Button", "Mouse Right Button"
Inputs.MLB, Inputs.MMB, Inputs.MRB
});
controller
.AddAxis("Mouse X", (0).RangeTo(PAL_WIDTH), PAL_WIDTH / 2)
.AddAxis("Mouse Y", (0).RangeTo(PAL_HEIGHT), PAL_HEIGHT / 2);
.AddAxis(Inputs.X, (0).RangeTo(LibPUAE.PAL_WIDTH), LibPUAE.PAL_WIDTH / 2)
.AddAxis(Inputs.Y, (0).RangeTo(LibPUAE.PAL_HEIGHT), LibPUAE.PAL_HEIGHT / 2);
foreach (var b in controller.BoolButtons)
{
@ -119,6 +120,11 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
}
}
controller.BoolButtons.AddRange(new List<string>
{
Inputs.EJ, Inputs.INS, Inputs.ND, Inputs.NS
});
foreach (var b in Enum.GetValues(typeof(LibPUAE.PUAEKeyboard)))
{
var name = Enum.GetName(typeof(LibPUAE.PUAEKeyboard), b).Replace('_', ' ');
@ -144,21 +150,63 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
}
}
if (controller.IsPressed("Mouse Left Button"))
if (controller.IsPressed(Inputs.MLB))
{
fi.MouseButtons |= 1 << 0;
}
if (controller.IsPressed("Mouse Right Button"))
if (controller.IsPressed(Inputs.MRB))
{
fi.MouseButtons |= 1 << 1;
}
if (controller.IsPressed("Mouse Middle Button"))
if (controller.IsPressed(Inputs.MMB))
{
fi.MouseButtons |= 1 << 2;
}
fi.MouseX = controller.AxisValue("Mouse X");
fi.MouseY = controller.AxisValue("Mouse Y");
if (controller.IsPressed(Inputs.NS))
{
if (!_nextSlotPressed)
{
_currentSlot++;
_currentSlot %= _roms.Count + _discs.Count;
string selectedFile;
if (_currentSlot < _roms.Count)
{
selectedFile = _roms[_currentSlot].Game.Name;
}
else
{
selectedFile = _discs[_currentSlot - _roms.Count].DiscName;
}
_comm.Notify(selectedFile, null);
}
}
_nextSlotPressed = controller.IsPressed(Inputs.NS);
if (controller.IsPressed(Inputs.ND))
{
if (!_nextDrivePressed)
{
_currentDrive++;
_currentDrive %= _syncSettings.FloppyDrives + (_discs.Count > 0 ? 1 : 0);
string selectedDrive;
if (_currentDrive < _syncSettings.FloppyDrives)
{
selectedDrive = "FD" + _currentDrive;
}
else
{
selectedDrive = "CD";
}
_comm.Notify(selectedDrive, null);
}
}
_nextDrivePressed = controller.IsPressed(Inputs.ND);
fi.MouseX = controller.AxisValue(Inputs.X);
fi.MouseY = controller.AxisValue(Inputs.Y);
foreach (var b in Enum.GetValues(typeof(LibPUAE.PUAEKeyboard)))
{
@ -175,5 +223,47 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
return fi;
}
public void SaveStateBinary(BinaryWriter writer)
{
using (_exe.EnterExit())
{
_exe.SaveStateBinary(writer);
}
writer.Write(_nextSlotPressed);
writer.Write(_nextDrivePressed);
}
public void LoadStateBinary(BinaryReader reader)
{
using (_exe.EnterExit())
{
_exe.LoadStateBinary(reader);
}
_nextSlotPressed = reader.ReadBoolean();
_nextDrivePressed = reader.ReadBoolean();
}
private static class FileNames
{
public const string FD = "FloppyDisk";
public const string CD = "CompactDisk";
public const string HD = "HardDrive";
}
private static class Inputs
{
public const string MLB = "Mouse Left Button";
public const string MRB = "Mouse Right Button";
public const string MMB = "Mouse Middle Button";
public const string X = "Mouse X";
public const string Y = "Mouse Y";
public const string EJ = "Eject";
public const string INS = "Insert";
public const string ND = "Next Drive";
public const string NS = "Next Slot";
}
}
}