From 7d06f6cbd1324e60ac7b94d6764960666bd32df7 Mon Sep 17 00:00:00 2001 From: feos Date: Fri, 10 Apr 2020 12:38:25 +0300 Subject: [PATCH] mame: add lag, even tho the core can't set it there's no concept of "controller poll" in mame, because this information isn't considered useful by them, and it also has to be done for every machine separately. theoretically it can be determined by watching controller register reads, but that requires running the entire debugger UI and setting watchpoints manually via debugger console, which is also super complicated. mame lua can set WPs, but only if debugger is there. even then, there's no way to assign lua callbacks to WPs. I'm planning to add simple mem hooks to mame lua some day, but it will be super hard due to incredibly complex abstraction, and there's no guarantee they will even merge it. --- BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs b/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs index 0a7a91a4ac..ec5ef9305b 100644 --- a/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs +++ b/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs @@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME portedVersion: "0.220", portedUrl: "https://github.com/mamedev/mame.git", singleInstance: false)] - public partial class MAME : IEmulator, IVideoProvider, ISoundProvider, ISettable, IStatable + public partial class MAME : IEmulator, IVideoProvider, ISoundProvider, ISettable, IStatable, IInputPollable { public MAME(string dir, string file, object syncSettings, out string gamename) { @@ -103,6 +103,11 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME public int BufferHeight { get; private set; } = 240; public int VsyncNumerator { get; private set; } = 60; public int VsyncDenominator { get; private set; } = 1; + public int LagCount { get; set; } = 0; + public bool IsLagFrame { get; set; } = false; + + [FeatureNotImplemented] + public IInputCallbackSystem InputCallbacks => throw new NotImplementedException(); #endregion @@ -160,12 +165,19 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME Frame++; + if (IsLagFrame) + { + LagCount++; + } + return true; } public void ResetCounters() { Frame = 0; + LagCount = 0; + IsLagFrame = false; } public void Dispose() @@ -201,6 +213,8 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME writer.Write(_mameSaveBuffer); writer.Write(Frame); + writer.Write(LagCount); + writer.Write(IsLagFrame); _memoryAccessComplete.Set(); _memAccess = false; @@ -227,6 +241,8 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME } Frame = reader.ReadInt32(); + LagCount = reader.ReadInt32(); + IsLagFrame = reader.ReadBoolean(); _memoryAccessComplete.Set(); _memAccess = false; @@ -707,7 +723,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME int length = LibMAME.mame_lua_get_int("return string.len(manager:machine():buffer_save())"); _mameSaveBuffer = new byte[length]; - _hawkSaveBuffer = new byte[length + 4 + 4]; + _hawkSaveBuffer = new byte[length + 4 + 4 + 4 + 1]; _mameStartupComplete.Set(); }