vba next: memory domains

This commit is contained in:
goyuken 2014-08-16 05:45:31 +00:00
parent 0fd05b4800
commit 8c4696609d
7 changed files with 106 additions and 30 deletions

View File

@ -32,8 +32,9 @@ namespace BizHawk.Emulation.Common
/// <param name="size"></param>
/// <param name="endian"></param>
/// <param name="data">must remain valid as long as the MemoryDomain exists!</param>
/// <param name="writable">if false, writes will be ignored</param>
/// <returns></returns>
public unsafe static MemoryDomain FromIntPtr(string name, int size, Endian endian, IntPtr data)
public unsafe static MemoryDomain FromIntPtr(string name, int size, Endian endian, IntPtr data, bool writable = true)
{
if (data == IntPtr.Zero)
throw new ArgumentNullException("data");
@ -53,15 +54,16 @@ namespace BizHawk.Emulation.Common
},
delegate(int addr, byte val)
{
if (addr < 0 || addr >= size)
throw new ArgumentOutOfRangeException();
p[addr] = val;
if (writable)
{
if (addr < 0 || addr >= size)
throw new ArgumentOutOfRangeException();
p[addr] = val;
}
}
);
}
public MemoryDomain() { }
public override string ToString()
{
return Name;

View File

@ -122,6 +122,26 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
public static extern bool SaveRamSave(IntPtr g, byte[] data, int length);
[DllImport(dllname, CallingConvention = cc)]
public static extern bool SaveRamLoad(IntPtr g, byte[] data, int length);
[DllImport(dllname, CallingConvention = cc)]
public static extern void GetMemoryAreas(IntPtr g, [Out]MemoryAreas mem);
[DllImport(dllname, CallingConvention = cc)]
public static extern void SystemBusWrite(IntPtr g, int addr, byte val);
[DllImport(dllname, CallingConvention = cc)]
public static extern byte SystemBusRead(IntPtr g, int addr);
[StructLayout(LayoutKind.Sequential)]
public class MemoryAreas
{
public IntPtr bios;
public IntPtr iwram;
public IntPtr ewram;
public IntPtr palram;
public IntPtr vram;
public IntPtr oam;
public IntPtr rom;
public IntPtr mmio;
}
}
}

View File

@ -73,6 +73,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
savebuff = new byte[LibVBANext.BinStateSize(Core)];
savebuff2 = new byte[savebuff.Length + 13];
InitMemoryDomains();
}
catch
{
@ -253,11 +254,38 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
#region Debugging
public MemoryDomainList MemoryDomains
void InitMemoryDomains()
{
get { return MemoryDomainList.GetDummyList(); }
var mm = new List<MemoryDomain>();
var s = new LibVBANext.MemoryAreas();
var l = MemoryDomain.Endian.Little;
LibVBANext.GetMemoryAreas(Core, s);
mm.Add(MemoryDomain.FromIntPtr("IWRAM", 32 * 1024, l, s.iwram));
mm.Add(MemoryDomain.FromIntPtr("EWRAM", 256 * 1024, l, s.ewram));
mm.Add(MemoryDomain.FromIntPtr("BIOS", 16 * 1024, l, s.bios, false));
mm.Add(MemoryDomain.FromIntPtr("PALRAM", 1024, l, s.palram, false));
mm.Add(MemoryDomain.FromIntPtr("VRAM", 96 * 1024, l, s.vram));
mm.Add(MemoryDomain.FromIntPtr("OAM", 1024, l, s.oam));
mm.Add(MemoryDomain.FromIntPtr("ROM", 32 * 1024 * 1024, l, s.rom));
mm.Add(new MemoryDomain("BUS", 0x10000000, l,
delegate(int addr)
{
if (addr < 0 || addr >= 0x10000000)
throw new ArgumentOutOfRangeException();
return LibVBANext.SystemBusRead(Core, addr);
},
delegate(int addr, byte val)
{
if (addr < 0 || addr >= 0x10000000)
throw new ArgumentOutOfRangeException();
LibVBANext.SystemBusWrite(Core, addr, val);
}));
MemoryDomains = new MemoryDomainList(mm, 0);
}
public MemoryDomainList MemoryDomains { get; private set; }
public Dictionary<string, int> GetCpuFlagsAndRegisters()
{
throw new NotImplementedException();

View File

@ -319,28 +319,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
if (data != IntPtr.Zero && size > 0 && name != IntPtr.Zero)
{
byte* p = (byte*)data;
mm.Add(new MemoryDomain
(
Marshal.PtrToStringAnsi(name),
size,
MemoryDomain.Endian.Unknown,
delegate(int addr)
{
if (addr < 0 || addr >= size)
throw new ArgumentOutOfRangeException();
return p[addr];
},
delegate(int addr, byte val)
{
if (!writable)
return;
if (addr < 0 || addr >= size)
throw new ArgumentOutOfRangeException();
p[addr] = val;
}
));
mm.Add(MemoryDomain.FromIntPtr(Marshal.PtrToStringAnsi(name), size, MemoryDomain.Endian.Little, data, writable));
}
}
// add system bus

Binary file not shown.

View File

@ -13321,6 +13321,27 @@ template<bool isReader>bool SyncBatteryRam(NewState *ns)
return lagged;
}
void FillMemoryAreas(MemoryAreas &mem)
{
mem.bios = bios;
mem.iwram = internalRAM;
mem.ewram = workRAM;
mem.palram = graphics.paletteRAM;
mem.mmio = ioMem;
mem.rom = rom;
mem.vram = vram;
mem.oam = oam;
}
void BusWrite(u32 addr, u8 val)
{
CPUWriteByte(addr, val);
}
u8 BusRead(u32 addr)
{
return CPUReadByte(addr);
}
}; // class Gigazoid
// zeroing mem operators: these are very important
@ -13447,5 +13468,19 @@ EXPORT void TxtStateLoad(Gigazoid *g, FPtrs *ff)
g->SyncState<true>(&loader);
}
EXPORT void GetMemoryAreas(Gigazoid *g, MemoryAreas *mem)
{
g->FillMemoryAreas(*mem);
}
EXPORT void SystemBusWrite(Gigazoid *g, u32 addr, u8 val)
{
g->BusWrite(addr, val);
}
EXPORT u8 SystemBusRead(Gigazoid *g, u32 addr)
{
return g->BusRead(addr);
}
#include "optable.inc"

View File

@ -20,6 +20,18 @@ struct FrontEndSettings
};
struct MemoryAreas
{
void *bios;
void *iwram;
void *ewram;
void *palram;
void *vram;
void *oam;
void *rom;
void *mmio;
};
#define FLASH_128K_SZ 0x20000
#define EEPROM_IDLE 0