add memory domains to gambatte
appears to work, but i don't really have much of anything to test on it ramwatch is horribly slow
This commit is contained in:
parent
0afd4f3c09
commit
ed2b690f75
|
@ -45,6 +45,8 @@ namespace BizHawk.Emulation.Consoles.GB
|
|||
InputCallback = new LibGambatte.InputGetter(ControllerCallback);
|
||||
|
||||
LibGambatte.gambatte_setinputgetter(GambatteState, InputCallback);
|
||||
|
||||
InitMemoryDomains();
|
||||
}
|
||||
|
||||
public static readonly ControllerDefinition GbController = new ControllerDefinition
|
||||
|
@ -251,16 +253,55 @@ namespace BizHawk.Emulation.Consoles.GB
|
|||
get { return GbOutputComm; }
|
||||
}
|
||||
|
||||
public IList<MemoryDomain> MemoryDomains
|
||||
|
||||
MemoryDomain CreateMemoryDomain(LibGambatte.MemoryAreas which)
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
IntPtr data = IntPtr.Zero;
|
||||
int length = 0;
|
||||
|
||||
if (!LibGambatte.gambatte_getmemoryarea(GambatteState, which, ref data, ref length))
|
||||
throw new Exception("gambatte_getmemoryarea() failed!");
|
||||
|
||||
if (data == IntPtr.Zero || length <= 0)
|
||||
throw new Exception("bad return from gambatte_getmemoryarea()");
|
||||
|
||||
Func<int, byte> peeker = delegate(int addr)
|
||||
{
|
||||
if (addr >= length || addr < 0)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
byte[] result = new byte[1];
|
||||
System.Runtime.InteropServices.Marshal.Copy(data + addr, result, 0, 1);
|
||||
return result[0];
|
||||
};
|
||||
|
||||
Action<int, byte> poker = delegate(int addr, byte val)
|
||||
{
|
||||
if (addr >= length || addr < 0)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
byte[] source = new byte[1];
|
||||
source[0] = val;
|
||||
System.Runtime.InteropServices.Marshal.Copy(source, 0, data + addr, 1);
|
||||
};
|
||||
return new MemoryDomain(which.ToString(), length, Endian.Little, peeker, poker);
|
||||
}
|
||||
|
||||
public MemoryDomain MainMemory
|
||||
void InitMemoryDomains()
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
MemoryDomains = new MemoryDomain[4];
|
||||
|
||||
MemoryDomains[0] = CreateMemoryDomain(LibGambatte.MemoryAreas.rambank);
|
||||
MemoryDomains[1] = CreateMemoryDomain(LibGambatte.MemoryAreas.rom);
|
||||
MemoryDomains[2] = CreateMemoryDomain(LibGambatte.MemoryAreas.vram);
|
||||
MemoryDomains[3] = CreateMemoryDomain(LibGambatte.MemoryAreas.wram);
|
||||
|
||||
// what is this supposed to be, exactly?
|
||||
MainMemory = MemoryDomains[1];
|
||||
}
|
||||
|
||||
public IList<MemoryDomain> MemoryDomains { get; private set; }
|
||||
|
||||
public MemoryDomain MainMemory { get; private set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
LibGambatte.gambatte_destroy(GambatteState);
|
||||
|
|
|
@ -268,5 +268,26 @@ namespace BizHawk.Emulation.Consoles.GB
|
|||
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void gambatte_setgameshark(IntPtr core, string codes);
|
||||
|
||||
/// <summary>
|
||||
/// memory areas that gambatte_getmemoryarea() can return
|
||||
/// </summary>
|
||||
public enum MemoryAreas : int
|
||||
{
|
||||
vram = 0,
|
||||
rom = 1,
|
||||
wram = 2,
|
||||
rambank = 3,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get pointer to internal memory areas, for debugging purposes
|
||||
/// </summary>
|
||||
/// <param name="core">opaque state pointer</param>
|
||||
/// <param name="which">which memory area to access</param>
|
||||
/// <param name="data">pointer to the start of the area</param>
|
||||
/// <param name="length">valid length of the area, in bytes</param>
|
||||
/// <returns>success</returns>
|
||||
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool gambatte_getmemoryarea(IntPtr core, MemoryAreas which, ref IntPtr data, ref int length);
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -97,6 +97,9 @@ public:
|
|||
int saveSavedataLength();
|
||||
void saveSavedata(char *dest);
|
||||
|
||||
// 0 = vram, 1 = rom, 2 = wram, 3 = rambank
|
||||
bool getMemoryArea(int which, unsigned char **data, int *length);
|
||||
|
||||
/** Saves emulator state to the state slot selected with selectState().
|
||||
* The data will be stored in the directory given by setSaveDir().
|
||||
*
|
||||
|
|
|
@ -187,3 +187,8 @@ __declspec(dllexport) void gambatte_setgameshark(void *core, const char *codes)
|
|||
g->setGameShark(std::string(codes));
|
||||
}
|
||||
|
||||
__declspec(dllexport) int gambatte_getmemoryarea(void *core, int which, unsigned char **data, int *length)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
return g->getMemoryArea(which, data, length);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ extern "C"
|
|||
__declspec(dllexport) void gambatte_setgamegenie(void *core, const char *codes);
|
||||
|
||||
__declspec(dllexport) void gambatte_setgameshark(void *core, const char *codes);
|
||||
|
||||
__declspec(dllexport) int gambatte_getmemoryarea(void *core, int which, unsigned char **data, int *length);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,6 +55,8 @@ public:
|
|||
int saveSavedataLength() {return memory.saveSavedataLength(); }
|
||||
void saveSavedata(char *dest) { memory.saveSavedata(dest); }
|
||||
|
||||
bool getMemoryArea(int which, unsigned char **data, int *length) { return memory.getMemoryArea(which, data, length); }
|
||||
|
||||
void setVideoBuffer(uint_least32_t *const videoBuf, const int pitch) {
|
||||
memory.setVideoBuffer(videoBuf, pitch);
|
||||
}
|
||||
|
|
|
@ -142,6 +142,13 @@ int GB::saveSavedataLength() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
bool GB::getMemoryArea(int which, unsigned char **data, int *length) {
|
||||
if (p_->cpu.loaded())
|
||||
return p_->cpu.getMemoryArea(which, data, length);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void GB::setDmgPaletteColor(unsigned palNum, unsigned colorNum, unsigned rgb32) {
|
||||
p_->cpu.setDmgPaletteColor(palNum, colorNum, rgb32);
|
||||
}
|
||||
|
|
|
@ -694,6 +694,35 @@ void Cartridge::saveSavedata(char *dest) {
|
|||
}
|
||||
}
|
||||
|
||||
bool Cartridge::getMemoryArea(int which, unsigned char **data, int *length)
|
||||
{
|
||||
if (!data || !length)
|
||||
return false;
|
||||
|
||||
switch (which)
|
||||
{
|
||||
case 0:
|
||||
*data = memptrs.vramdata();
|
||||
*length = memptrs.vramdataend() - memptrs.vramdata();
|
||||
return true;
|
||||
case 1:
|
||||
*data = memptrs.romdata();
|
||||
*length = memptrs.romdataend() - memptrs.romdata();
|
||||
return true;
|
||||
case 2:
|
||||
*data = memptrs.wramdata(0);
|
||||
*length = memptrs.wramdataend() - memptrs.wramdata(0);
|
||||
return true;
|
||||
case 3:
|
||||
*data = memptrs.rambankdata();
|
||||
*length = memptrs.rambankdataend() - memptrs.rambankdata();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int asHex(const char c) {
|
||||
return c >= 'A' ? c - 'A' + 0xA : c - '0';
|
||||
}
|
||||
|
|
|
@ -87,6 +87,9 @@ public:
|
|||
void saveSavedata(char *dest);
|
||||
const std::string saveBasePath() const;
|
||||
void setSaveDir(const std::string &dir);
|
||||
|
||||
bool getMemoryArea(int which, unsigned char **data, int *length);
|
||||
|
||||
int loadROM(const char *romfiledata, unsigned romfilelength, bool forceDmg, bool multicartCompat);
|
||||
const char * romTitle() const { return reinterpret_cast<const char *>(memptrs.romdata() + 0x134); }
|
||||
void setGameGenie(const std::string &codes);
|
||||
|
|
|
@ -83,6 +83,8 @@ public:
|
|||
void saveSavedata(char *dest) { cart.saveSavedata(dest); }
|
||||
const std::string saveBasePath() const { return cart.saveBasePath(); }
|
||||
|
||||
bool getMemoryArea(int which, unsigned char **data, int *length) { return cart.getMemoryArea(which, data, length); }
|
||||
|
||||
void setOsdElement(std::auto_ptr<OsdElement> osdElement) {
|
||||
display.setOsdElement(osdElement);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue