From eb4e8d6cd777873bc26e553c4c2cbea70000ee6b Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 14 Jul 2022 03:27:22 +1000 Subject: [PATCH] Change return type of `IEmulationApi.Disassemble` to tuple --- .../Api/Classes/EmulationApi.cs | 18 ++++++++---------- .../Api/Interfaces/IEmulationApi.cs | 5 ++++- .../lua/CommonLibs/EmulationLuaLibrary.cs | 12 ++++++++++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs b/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs index 9cc0587be9e..062dd992ad9 100644 --- a/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs @@ -73,25 +73,23 @@ public EmulationApi(Action logCallback, Config config, IGameInfo? game) public int FrameCount() => Emulator!.Frame; - public object? Disassemble(uint pc, string? name = null) + public (string Disasm, int Length) Disassemble(uint pc, string? name = null) { try { if (DisassemblableCore != null) { - return new { - disasm = DisassemblableCore.Disassemble( - string.IsNullOrEmpty(name) ? MemoryDomains!.SystemBus : MemoryDomains![name!]!, - pc, - out var l - ), - length = l - }; + var disasm = DisassemblableCore.Disassemble( + string.IsNullOrEmpty(name) ? MemoryDomains!.SystemBus : MemoryDomains![name!]!, + pc, + out var l + ); + return (disasm, l); } } catch (NotImplementedException) {} LogCallback($"Error: {Emulator.Attributes().CoreName} does not yet implement {nameof(IDisassemblable.Disassemble)}()"); - return null; + return (string.Empty, 0); } public ulong? GetRegister(string name) diff --git a/src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs b/src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs index 177c73223aa..885706661ee 100644 --- a/src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs +++ b/src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs @@ -10,7 +10,10 @@ public interface IEmulationApi : IExternalApi { void DisplayVsync(bool enabled); int FrameCount(); - object? Disassemble(uint pc, string? name = null); + + /// disassembly and opcode width, or (string.Empty, 0) on failure + (string Disasm, int Length) Disassemble(uint pc, string? name = null); + ulong? GetRegister(string name); IReadOnlyDictionary GetRegisters(); void SetRegister(string register, int value); diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/EmulationLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/EmulationLuaLibrary.cs index 898970d1af0..dfa3b314cd5 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/EmulationLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/EmulationLuaLibrary.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using NLua; @@ -38,8 +39,15 @@ public int FrameCount() [LuaMethodExample("local obemudis = emu.disassemble( 0x8000 );")] [LuaMethod("disassemble", "Returns the disassembly object (disasm string and length int) for the given PC address. Uses System Bus domain if no domain name provided")] [return: LuaASCIIStringParam] - public object Disassemble(uint pc, [LuaASCIIStringParam] string name = "") - => APIs.Emulation.Disassemble(pc, name); + public LuaTable Disassemble(uint pc, [LuaASCIIStringParam] string name = "") + { + var (disasm, length) = APIs.Emulation.Disassemble(pc, name); + if (length is 0) return null; + var table = _th.CreateTable(); + table["disasm"] = disasm; + table["length"] = length; + return table; + } // TODO: what about 64 bit registers? [LuaMethodExample("local inemuget = emu.getregister( emu.getregisters( )[ 0 ] );")]