Change return type of `IEmulationApi.Disassemble` to tuple

This commit is contained in:
YoshiRulz 2022-07-14 03:27:22 +10:00
parent 056db314d4
commit eb4e8d6cd7
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 22 additions and 13 deletions

View File

@ -73,25 +73,23 @@ namespace BizHawk.Client.Common
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)

View File

@ -10,7 +10,10 @@ namespace BizHawk.Client.Common
{
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);

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using NLua;
@ -38,8 +39,15 @@ namespace BizHawk.Client.Common
[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 ] );")]