Skip to content

Commit eb4e8d6

Browse files
committed
Change return type of IEmulationApi.Disassemble to tuple
1 parent 056db31 commit eb4e8d6

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,23 @@ public EmulationApi(Action<string> logCallback, Config config, IGameInfo? game)
7373
public int FrameCount()
7474
=> Emulator!.Frame;
7575

76-
public object? Disassemble(uint pc, string? name = null)
76+
public (string Disasm, int Length) Disassemble(uint pc, string? name = null)
7777
{
7878
try
7979
{
8080
if (DisassemblableCore != null)
8181
{
82-
return new {
83-
disasm = DisassemblableCore.Disassemble(
84-
string.IsNullOrEmpty(name) ? MemoryDomains!.SystemBus : MemoryDomains![name!]!,
85-
pc,
86-
out var l
87-
),
88-
length = l
89-
};
82+
var disasm = DisassemblableCore.Disassemble(
83+
string.IsNullOrEmpty(name) ? MemoryDomains!.SystemBus : MemoryDomains![name!]!,
84+
pc,
85+
out var l
86+
);
87+
return (disasm, l);
9088
}
9189
}
9290
catch (NotImplementedException) {}
9391
LogCallback($"Error: {Emulator.Attributes().CoreName} does not yet implement {nameof(IDisassemblable.Disassemble)}()");
94-
return null;
92+
return (string.Empty, 0);
9593
}
9694

9795
public ulong? GetRegister(string name)

src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ public interface IEmulationApi : IExternalApi
1010
{
1111
void DisplayVsync(bool enabled);
1212
int FrameCount();
13-
object? Disassemble(uint pc, string? name = null);
13+
14+
/// <returns>disassembly and opcode width, or <c>(string.Empty, 0)</c> on failure</returns>
15+
(string Disasm, int Length) Disassemble(uint pc, string? name = null);
16+
1417
ulong? GetRegister(string name);
1518
IReadOnlyDictionary<string, ulong> GetRegisters();
1619
void SetRegister(string register, int value);

src/BizHawk.Client.Common/lua/CommonLibs/EmulationLuaLibrary.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel;
34

45
using NLua;
@@ -38,8 +39,15 @@ public int FrameCount()
3839
[LuaMethodExample("local obemudis = emu.disassemble( 0x8000 );")]
3940
[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")]
4041
[return: LuaASCIIStringParam]
41-
public object Disassemble(uint pc, [LuaASCIIStringParam] string name = "")
42-
=> APIs.Emulation.Disassemble(pc, name);
42+
public LuaTable Disassemble(uint pc, [LuaASCIIStringParam] string name = "")
43+
{
44+
var (disasm, length) = APIs.Emulation.Disassemble(pc, name);
45+
if (length is 0) return null;
46+
var table = _th.CreateTable();
47+
table["disasm"] = disasm;
48+
table["length"] = length;
49+
return table;
50+
}
4351

4452
// TODO: what about 64 bit registers?
4553
[LuaMethodExample("local inemuget = emu.getregister( emu.getregisters( )[ 0 ] );")]

0 commit comments

Comments
 (0)