Skip to content

Commit

Permalink
Change return type of IEmulationApi.Disassemble to tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Jul 13, 2022
1 parent 056db31 commit eb4e8d6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
18 changes: 8 additions & 10 deletions src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,23 @@ public EmulationApi(Action<string> 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)
Expand Down
5 changes: 4 additions & 1 deletion src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public interface IEmulationApi : IExternalApi
{
void DisplayVsync(bool enabled);
int FrameCount();
object? Disassemble(uint pc, string? name = null);

/// <returns>disassembly and opcode width, or <c>(string.Empty, 0)</c> on failure</returns>
(string Disasm, int Length) Disassemble(uint pc, string? name = null);

ulong? GetRegister(string name);
IReadOnlyDictionary<string, ulong> GetRegisters();
void SetRegister(string register, int value);
Expand Down
12 changes: 10 additions & 2 deletions src/BizHawk.Client.Common/lua/CommonLibs/EmulationLuaLibrary.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;

using NLua;
Expand Down Expand Up @@ -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 ] );")]
Expand Down

0 comments on commit eb4e8d6

Please sign in to comment.