gba: some memory domains
This commit is contained in:
parent
83f74f1290
commit
ee9e67d023
|
@ -111,5 +111,26 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA
|
|||
[DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void libmeteor_setkeycallback(InputCallback callback);
|
||||
|
||||
/// <summary>
|
||||
/// parameter to libmeteor_getmemoryarea
|
||||
/// </summary>
|
||||
public enum MemoryArea : int
|
||||
{
|
||||
bios = 0,
|
||||
ewram = 1,
|
||||
iwram = 2,
|
||||
palram = 3,
|
||||
vram = 4,
|
||||
oam = 5,
|
||||
rom = 6
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// return a pointer to a memory area
|
||||
/// </summary>
|
||||
/// <param name="which"></param>
|
||||
/// <returns>IntPtr.Zero if which is unrecognized</returns>
|
||||
[DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr libmeteor_getmemoryarea(MemoryArea which);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA
|
|||
LibMeteor.libmeteor_reset();
|
||||
LibMeteor.libmeteor_loadbios(bios, (uint)bios.Length);
|
||||
LibMeteor.libmeteor_loadrom(rom, (uint)rom.Length);
|
||||
|
||||
SetUpMemoryDomains();
|
||||
}
|
||||
|
||||
public void FrameAdvance(bool render, bool rendersound = true)
|
||||
|
@ -110,16 +112,63 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA
|
|||
|
||||
public CoreOutputComm CoreOutputComm { get { return _CoreOutputComm; } }
|
||||
|
||||
public IList<MemoryDomain> MemoryDomains
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
#region memorydomains
|
||||
|
||||
List<MemoryDomain> _MemoryDomains = new List<MemoryDomain>();
|
||||
public IList<MemoryDomain> MemoryDomains { get { return _MemoryDomains; } }
|
||||
public MemoryDomain MainMemory
|
||||
{
|
||||
get { return null; }
|
||||
// some core tools assume MainMemory == MemoryDomains[0], so do that anyway
|
||||
get { return MemoryDomains[0]; }
|
||||
}
|
||||
|
||||
void AddMemoryDomain(LibMeteor.MemoryArea which, int size, string name)
|
||||
{
|
||||
IntPtr data = LibMeteor.libmeteor_getmemoryarea(which);
|
||||
if (data == IntPtr.Zero)
|
||||
throw new Exception("libmeteor_getmemoryarea() returned NULL??");
|
||||
|
||||
MemoryDomain md = new MemoryDomain(name, size, Endian.Little,
|
||||
delegate(int addr)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
byte* d = (byte*)data;
|
||||
if (addr < 0 || addr >= size)
|
||||
throw new IndexOutOfRangeException();
|
||||
return d[addr];
|
||||
}
|
||||
},
|
||||
delegate(int addr, byte val)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
byte* d = (byte*)data;
|
||||
if (addr < 0 || addr >= size)
|
||||
throw new IndexOutOfRangeException();
|
||||
d[addr] = val;
|
||||
}
|
||||
});
|
||||
_MemoryDomains.Add(md);
|
||||
}
|
||||
|
||||
void SetUpMemoryDomains()
|
||||
{
|
||||
_MemoryDomains.Clear();
|
||||
// this must be first to coincide with "main memory"
|
||||
// note that ewram could also be considered main memory depending on which hairs you split
|
||||
AddMemoryDomain(LibMeteor.MemoryArea.iwram, 32 * 1024, "IWRAM");
|
||||
AddMemoryDomain(LibMeteor.MemoryArea.ewram, 256 * 1024, "EWRAM");
|
||||
AddMemoryDomain(LibMeteor.MemoryArea.bios, 16 * 1024, "BIOS");
|
||||
AddMemoryDomain(LibMeteor.MemoryArea.palram, 1024, "PALRAM");
|
||||
AddMemoryDomain(LibMeteor.MemoryArea.vram, 96 * 1024, "VRAM");
|
||||
AddMemoryDomain(LibMeteor.MemoryArea.oam, 1024, "OAM");
|
||||
// even if the rom is less than 32MB, the whole is still valid in meteor
|
||||
AddMemoryDomain(LibMeteor.MemoryArea.rom, 32 * 1024 * 1024, "ROM");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>like libsnes, the library is single-instance</summary>
|
||||
static GBA attachedcore;
|
||||
/// <summary>hold pointer to message callback so it won't get GCed</summary>
|
||||
|
@ -191,6 +240,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA
|
|||
inputcallback = null;
|
||||
LibMeteor.libmeteor_setmessagecallback(messagecallback);
|
||||
LibMeteor.libmeteor_setkeycallback(inputcallback);
|
||||
_MemoryDomains.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
|
@ -130,5 +130,10 @@ EXPORT void libmeteor_loadbios(const void *data, unsigned size)
|
|||
AMeteor::_memory.LoadBios((const uint8_t*)data, size);
|
||||
}
|
||||
|
||||
// TODO: memory domains
|
||||
EXPORT uint8_t *libmeteor_getmemoryarea(int which)
|
||||
{
|
||||
return AMeteor::_memory.GetMemoryArea(which);
|
||||
}
|
||||
|
||||
// TODO: cartram and system bus memory domains
|
||||
|
||||
|
|
|
@ -120,6 +120,8 @@ namespace AMeteor
|
|||
|
||||
void TimeEvent ();
|
||||
|
||||
uint8_t* GetMemoryArea(int which);
|
||||
|
||||
private :
|
||||
// times for a 8 or 16 bits access
|
||||
uint8_t m_memtime[0xF];
|
||||
|
|
|
@ -820,4 +820,27 @@ namespace AMeteor
|
|||
if (m_cart->Write(add, val))
|
||||
CLOCK.SetBattery(CART_SAVE_TIME);
|
||||
}
|
||||
|
||||
uint8_t *Memory::GetMemoryArea(int which)
|
||||
{
|
||||
switch (which)
|
||||
{
|
||||
case 0:
|
||||
return m_brom; // BIOS - System ROM
|
||||
case 1:
|
||||
return m_wbram; // WRAM - On-board Work RAM
|
||||
case 2:
|
||||
return m_wcram; // WRAM - In-chip Work RAM
|
||||
case 3:
|
||||
return m_pram; // BG/OBJ Palette RAM
|
||||
case 4:
|
||||
return m_vram; // VRAM - Video RAM
|
||||
case 5:
|
||||
return m_oram; // OAM - OBJ Attributes
|
||||
case 6:
|
||||
return m_rom; // Game Pake ROM/FlashROM (max 32MB)
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue