some disassembler stuff

This commit is contained in:
goyuken 2014-12-13 21:49:15 +00:00
parent 15a64b954e
commit c6ed49c067
5 changed files with 97 additions and 4 deletions

View File

@ -45,6 +45,17 @@ namespace BizHawk.Emulation.Common
}
}
/// <summary>
/// the core can call this to register an additional service
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="provider"></param>
public void Register<T>(T provider)
where T : IEmulatorService
{
Services[typeof(T)] = provider;
}
public IEmulatorService GetService<T>()
where T : IEmulatorService
{

View File

@ -1,8 +1,10 @@
using System.Collections.Generic;
using System;
using System.Linq;
using System.Collections.Generic;
namespace BizHawk.Emulation.Common
{
public interface IDisassemblable : IEmulator, IEmulatorService
public interface IDisassemblable : IEmulatorService
{
/// <summary>
/// Gets or sets the Cpu that will be used to disassemble
@ -13,11 +15,45 @@ namespace BizHawk.Emulation.Common
/// <summary>
/// Gets a list of Cpus that can be used when setting the Cpu property
/// </summary>
IEnumerable<string> AvailableCpus { get; set; }
IEnumerable<string> AvailableCpus { get; }
/// <summary>
/// returns a disassembly starting at addr lasting for length, using the given domain
/// </summary>
string Disassemble(MemoryDomain m, uint addr, out int length);
}
/// <summary>
/// does santiy checking on Cpu parameters
/// </summary>
public abstract class VerifiedDisassembler : IDisassemblable
{
protected string _cpu;
public virtual string Cpu
{
get
{
return _cpu;
}
set
{
if (!AvailableCpus.Contains(value))
throw new ArgumentException();
_cpu = value;
}
}
public abstract IEnumerable<string> AvailableCpus
{
get;
}
public abstract string Disassemble(MemoryDomain m, uint addr, out int length);
public VerifiedDisassembler()
{
_cpu = AvailableCpus.First();
}
}
}

View File

@ -274,6 +274,7 @@
<Compile Include="Consoles\Nintendo\Gameboy\GambatteLink.cs" />
<Compile Include="Consoles\Nintendo\Gameboy\GBColors.cs" />
<Compile Include="Consoles\Nintendo\Gameboy\LibGambatte.cs" />
<Compile Include="Consoles\Nintendo\GBA\ArmV4Disassembler.cs" />
<Compile Include="Consoles\Nintendo\GBA\IGBAGPUViewable.cs" />
<Compile Include="Consoles\Nintendo\GBA\LibMeteor.cs" />
<Compile Include="Consoles\Nintendo\GBA\LibVBANext.cs" />

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.GBA
{
public class ArmV4Disassembler : VerifiedDisassembler
{
public override IEnumerable<string> AvailableCpus
{
get
{
return new[] { "ARM v4", "ARM v4 (Thumb)" };
}
}
public override string Disassemble(MemoryDomain m, uint addr, out int length)
{
if (_cpu == "ARM v4 (Thumb)")
{
addr &= unchecked((uint)~1);
int op = m.PeekByte((int)addr) | m.PeekByte((int)addr + 1) << 8;
string ret = Emulation.Cores.Components.ARM.Darm.DisassembleStuff(addr | 1, (uint)op);
length = 2;
return ret;
}
else
{
addr &= unchecked((uint)~3);
int op = m.PeekByte((int)addr)
| m.PeekByte((int)addr + 1) << 8
| m.PeekByte((int)addr + 2) << 16
| m.PeekByte((int)addr + 3) << 24;
string ret = Emulation.Cores.Components.ARM.Darm.DisassembleStuff(addr, (uint)op);
length = 4;
return ret;
}
}
}
}

View File

@ -23,7 +23,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
[CoreConstructor("GBA")]
public VBANext(byte[] file, CoreComm comm, GameInfo game, bool deterministic, object syncsettings)
{
ServiceProvider = new BasicServiceProvider(this);
var ser = new BasicServiceProvider(this);
ser.Register<IDisassemblable>(new ArmV4Disassembler());
ServiceProvider = ser;
CoreComm = comm;
byte[] biosfile = CoreComm.CoreFileProvider.GetFirmware("GBA", "Bios", true, "GBA bios file is mandatory.");