puae: fix framerate and resolutions, cleanup

todo: av dumper dies in ntsc mode on frame 11...
This commit is contained in:
feos 2024-11-20 22:10:49 +03:00
parent 2a0870234e
commit 118e2876a4
6 changed files with 78 additions and 73 deletions

Binary file not shown.

View File

@ -451,7 +451,7 @@ namespace BizHawk.Emulation.Common
case ".ADF":
case ".ADZ":
case ".DMS":
case ".DMS":
case ".FDI":
// case ".HDF":
// case ".LHA":

View File

@ -9,9 +9,21 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
public abstract class LibPUAE : LibWaterboxCore
{
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 NTSC_WIDTH = PAL_WIDTH;
// the core renders 576 which is what libretro displays
// but default window height is 568 in original PUAE and WinUAE
// this lets us hide a black line and a weird artifact that our A600 config has there
public const int PAL_HEIGHT = 568;
// 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 PUAE_VIDEO_HZ_PAL as 49.9204101562500000f
public const int PUAE_VIDEO_NUMERATOR_PAL = 102237;
public const int PUAE_VIDEO_DENOMINATOR_PAL = 2048;
// libretro defines PUAE_VIDEO_HZ_NTSC as 59.8260993957519531f
public const int PUAE_VIDEO_NUMERATOR_NTSC = 299130497;
public const int PUAE_VIDEO_DENOMINATOR_NTSC = 5000000;
public const int FASTMEM_AUTO = -1;
public const int MAX_FLOPPIES = 4;
public const int FILENAME_MAXLENGTH = 64;

View File

@ -15,35 +15,48 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
isReleased: false)]
public partial class PUAE : WaterboxCore
{
private readonly List<IRomAsset> _roms;
//private readonly List<IDiscAsset> _discs;
private List<string> _args;
private string _chipsetCompatible = "";
private static readonly Configuration ConfigPAL = new Configuration
{
SystemId = VSystemID.Raw.Amiga,
MaxSamples = 2 * 1024,
DefaultWidth = LibPUAE.PAL_WIDTH,
DefaultHeight = LibPUAE.PAL_HEIGHT,
MaxWidth = LibPUAE.PAL_WIDTH,
MaxHeight = LibPUAE.PAL_HEIGHT,
DefaultFpsNumerator = LibPUAE.PUAE_VIDEO_NUMERATOR_PAL,
DefaultFpsDenominator = LibPUAE.PUAE_VIDEO_DENOMINATOR_PAL
};
private static readonly Configuration ConfigNTSC = new Configuration
{
SystemId = VSystemID.Raw.Amiga,
MaxSamples = 2 * 1024,
DefaultWidth = LibPUAE.NTSC_WIDTH,
DefaultHeight = LibPUAE.NTSC_HEIGHT,
MaxWidth = LibPUAE.NTSC_WIDTH,
MaxHeight = LibPUAE.NTSC_HEIGHT,
DefaultFpsNumerator = LibPUAE.PUAE_VIDEO_NUMERATOR_NTSC,
DefaultFpsDenominator = LibPUAE.PUAE_VIDEO_DENOMINATOR_NTSC
};
private string _chipsetCompatible = "";
private readonly List<IRomAsset> _roms;
private List<string> _args;
private int _currentDrive;
private int _currentSlot;
private bool _ejectPressed;
private bool _insertPressed;
private bool _nextSlotPressed;
private bool _nextDrivePressed;
private int _correctedWidth;
public override int VirtualWidth => _correctedWidth;
[CoreConstructor(VSystemID.Raw.Amiga)]
public PUAE(CoreLoadParameters<object, PUAESyncSettings> lp)
: base(lp.Comm, new Configuration
{
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
})
: base(lp.Comm, lp.SyncSettings.Region is VideoStandard.PAL ? ConfigPAL : ConfigNTSC)
{
_roms = lp.Roms;
//_discs = lp.Discs;
_syncSettings = lp.SyncSettings ?? new();
_syncSettings.FloppyDrives = Math.Min(LibPUAE.MAX_FLOPPIES, _syncSettings.FloppyDrives);
DeterministicEmulation = lp.DeterministicEmulationRequested || _syncSettings.FloppySpeed is FloppySpeed._100;
@ -54,6 +67,7 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
_syncSettings.ControllerPort2
];
UpdateAspectRatio(_syncSettings);
CreateArguments(_syncSettings);
ControllerDefinition = CreateControllerDefinition(_syncSettings);
@ -71,53 +85,15 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
for (var index = 0; index < lp.Roms.Count; index++)
{
if (lp.Roms[index].Extension.ToLowerInvariant() == ".hdf") // doesn't work yet
_exe.AddReadonlyFile(lp.Roms[index].FileData, FileNames.FD + index);
if (index < _syncSettings.FloppyDrives)
{
var access = "ro";
var device_name = "DH0";
var volume_name = FileNames.HD + index;
var blocks_per_track = 32;
var surfaces = 1;
var reserved = 2;
var block_size = 512;
var boot_priority = 0;
var filesys_path = "";
var controller_unit = "uae0";
if (Encoding.ASCII.GetString(lp.Roms[index].FileData, 0, 3) == "RDS")
{
blocks_per_track = 0;
surfaces = 0;
reserved = 0;
}
_exe.AddReadonlyFile(lp.Roms[index].FileData, volume_name);
AppendSetting($"hardfile2=" +
$"{access}," +
$"{device_name}:" +
$"\"{volume_name}\"," +
$"{blocks_per_track}," +
$"{surfaces}," +
$"{reserved}," +
$"{block_size}," +
$"{boot_priority}," +
$"{filesys_path}," +
$"{controller_unit}");
}
else
{
_exe.AddReadonlyFile(lp.Roms[index].FileData, FileNames.FD + index);
if (index < _syncSettings.FloppyDrives)
{
AppendSetting($"floppy{index}={FileNames.FD}{index}");
AppendSetting($"floppy{index}type={(int)DriveType.DRV_35_DD}");
AppendSetting("floppy_write_protect=true");
}
AppendSetting($"floppy{index}={FileNames.FD}{index}");
AppendSetting($"floppy{index}type={(int)DriveType.DRV_35_DD}");
AppendSetting("floppy_write_protect=true");
}
}
//AppendSetting("filesystem2=ro,DH0:data:Floppy/,0");
var (kickstartData, kickstartInfo) = CoreComm.CoreFileProvider.GetFirmwareWithGameInfoOrThrow(
new(VSystemID.Raw.Amiga, _chipsetCompatible),
"Firmware files are required!");
@ -128,9 +104,8 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
"-r", kickstartInfo.Name
]);
var s = string.Join(" ", _args);
Console.WriteLine();
Console.WriteLine(s);
Console.WriteLine(string.Join(" ", _args));
Console.WriteLine();
if (!paue.Init(_args.Count, _args.ToArray()))
@ -282,7 +257,17 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
protected override void FrameAdvancePost()
{
VsyncNumerator = BufferHeight == LibPUAE.NTSC_HEIGHT ? 60 : 50;
if (BufferHeight == LibPUAE.NTSC_HEIGHT)
{
VsyncNumerator = LibPUAE.PUAE_VIDEO_NUMERATOR_NTSC;
VsyncDenominator = LibPUAE.PUAE_VIDEO_DENOMINATOR_NTSC;
}
else
{
VsyncNumerator = LibPUAE.PUAE_VIDEO_NUMERATOR_PAL;
VsyncDenominator = LibPUAE.PUAE_VIDEO_DENOMINATOR_PAL;
}
UpdateAspectRatio(_syncSettings);
}
protected override void SaveStateBinaryInternal(BinaryWriter writer)
@ -305,6 +290,13 @@ namespace BizHawk.Emulation.Cores.Computers.Amiga
_currentSlot = reader.ReadInt32();
}
private void UpdateAspectRatio(PUAESyncSettings settings)
{
_correctedWidth = settings.Region is VideoStandard.PAL
? LibPUAE.PAL_WIDTH
: LibPUAE.PAL_WIDTH * 6 / 7;
}
private static class FileNames
{
public const string FD = "FloppyDisk";

View File

@ -7,10 +7,9 @@ ECL_EXPORT bool Init(int argc, char **argv)
pix_bytes = 4;
defaultw = PUAE_VIDEO_WIDTH;
defaulth = PUAE_VIDEO_HEIGHT_PAL;
retrow = PUAE_VIDEO_WIDTH;
retrow_crop = retrow;
retroh_crop = retroh;
defaulth = PUAE_WINDOW_HEIGHT_PAL;
retrow_crop = retrow = PUAE_VIDEO_WIDTH;
retroh_crop = retroh = PUAE_WINDOW_HEIGHT_PAL;
retro_set_audio_sample_batch(biz_audio_cb);
init_output_audio_buffer(2048);
@ -40,7 +39,7 @@ ECL_EXPORT void FrameAdvance(MyFrameInfo* f)
{
bool is_ntsc = minfirstline == VBLANK_ENDLINE_NTSC;
f->base.Width = PUAE_VIDEO_WIDTH;
f->base.Height = is_ntsc ? PUAE_VIDEO_HEIGHT_NTSC : PUAE_VIDEO_HEIGHT_PAL;
f->base.Height = is_ntsc ? PUAE_WINDOW_HEIGHT_NTSC : PUAE_WINDOW_HEIGHT_PAL;
thisframe_y_adjust = minfirstline;
visible_left_border = retro_max_diwlastword - retrow;
@ -103,7 +102,7 @@ ECL_EXPORT void FrameAdvance(MyFrameInfo* f)
m68k_go(1, 1);
upload_output_audio_buffer();
f->base.Samples = sound_sample_count;
memcpy(f->base.VideoBuffer, retro_bmp, sizeof(retro_bmp) / sizeof(retro_bmp[0]));
memcpy(f->base.VideoBuffer, retro_bmp, f->base.Width * f->base.Height * pix_bytes);
sound_buffer = NULL;
for (int port = 0; port <= 1; port++)

View File

@ -22,6 +22,8 @@
// libretro
#include "libretro/libretro-core.h"
static const int PUAE_WINDOW_HEIGHT_NTSC = 482;
static const int PUAE_WINDOW_HEIGHT_PAL = 568;
static const int FILENAME_MAXLENGTH = 4;
static const int KEY_COUNT = 0x68;