diff --git a/BizHawk.Client.EmuHawk/tools/CDL.cs b/BizHawk.Client.EmuHawk/tools/CDL.cs index af2124f9a1..41759c0972 100644 --- a/BizHawk.Client.EmuHawk/tools/CDL.cs +++ b/BizHawk.Client.EmuHawk/tools/CDL.cs @@ -154,6 +154,12 @@ namespace BizHawk.Client.EmuHawk { var gambatte = _emu as Gameboy; var cdl_gb = newCDL as CodeDataLog_GB; + var memd = gambatte.AsMemoryDomains(); + if (!cdl_gb.CheckConsistency(memd)) + { + MessageBox.Show(this, "CDL file does not match emulator's current memory map!"); + return; + } gambatte.CDL = cdl_gb; } } @@ -351,7 +357,10 @@ namespace BizHawk.Client.EmuHawk pce.Cpu.CDLLoggingActive = LoggingActiveCheckbox.Checked; } - _cdl.Active = LoggingActiveCheckbox.Checked; + //zeromus doesnt like this kind of logic + + if (_cdl != null) + _cdl.Active = LoggingActiveCheckbox.Checked; } private void PCECDL_DragEnter(object sender, DragEventArgs e) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/CodeDataLog_GB.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/CodeDataLog_GB.cs index c4321fe2fc..0b5c18f54d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/CodeDataLog_GB.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/CodeDataLog_GB.cs @@ -10,14 +10,30 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy public static CodeDataLog_GB Create(IMemoryDomains memdomains) { var t = new CodeDataLog_GB(); + t["ROM"] = new byte[memdomains["ROM"].Size]; + //t["HRAM"] = new byte[memdomains["HRAM"].Size]; //this is probably useless, but it's here if someone needs it t["WRAM"] = new byte[memdomains["WRAM"].Size]; - t["CartRAM"] = new byte[memdomains["Cart RAM"].Size]; + + if(memdomains.Has("CartRAM")) + t["CartRAM"] = new byte[memdomains["WRAM"].Size]; + return t; } public override string SubType { get { return "GB"; } } public override int SubVer { get { return 0; } } + + //todo - this could be base classed + public bool CheckConsistency(IMemoryDomains memdomains) + { + if (memdomains["ROM"].Size != this["ROM"].Length) return false; + if (memdomains["WRAM"].Size != this["WRAM"].Length) return false; + if(memdomains.Has("CartRAM")) + if (memdomains["CartRAM"].Size != this["CartRAM"].Length) + return false; + return true; + } } } \ No newline at end of file diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IMemoryDomains.cs index e5e7e9b95a..2eccb2deec 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IMemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IMemoryDomains.cs @@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy CreateMemoryDomain(LibGambatte.MemoryAreas.wram, "WRAM"); CreateMemoryDomain(LibGambatte.MemoryAreas.rom, "ROM"); CreateMemoryDomain(LibGambatte.MemoryAreas.vram, "VRAM"); - CreateMemoryDomain(LibGambatte.MemoryAreas.cartram, "Cart RAM"); + CreateMemoryDomain(LibGambatte.MemoryAreas.cartram, "CartRAM"); CreateMemoryDomain(LibGambatte.MemoryAreas.oam, "OAM"); CreateMemoryDomain(LibGambatte.MemoryAreas.hram, "HRAM"); diff --git a/libgambatte/src/mem/cartridge.cpp b/libgambatte/src/mem/cartridge.cpp index 6ce6795e8a..b8b642f4c4 100644 --- a/libgambatte/src/mem/cartridge.cpp +++ b/libgambatte/src/mem/cartridge.cpp @@ -710,7 +710,7 @@ void Cartridge::saveSavedata(char *dest) { } } -bool Cartridge::getMemoryArea(int which, unsigned char **data, int *length) { +bool Cartridge::getMemoryArea(int which, unsigned char **data, int *length) const { if (!data || !length) return false; diff --git a/libgambatte/src/mem/cartridge.h b/libgambatte/src/mem/cartridge.h index 4038593d23..54f694df31 100644 --- a/libgambatte/src/mem/cartridge.h +++ b/libgambatte/src/mem/cartridge.h @@ -95,7 +95,7 @@ public: int saveSavedataLength(); void saveSavedata(char *dest); - bool getMemoryArea(int which, unsigned char **data, int *length); + bool getMemoryArea(int which, unsigned char **data, int *length) const; int loadROM(const char *romfiledata, unsigned romfilelength, bool forceDmg, bool multicartCompat); const char * romTitle() const { return reinterpret_cast(memptrs.romdata() + 0x134); } diff --git a/libgambatte/src/memory.h b/libgambatte/src/memory.h index b6a4bafd24..75263e66d4 100644 --- a/libgambatte/src/memory.h +++ b/libgambatte/src/memory.h @@ -144,10 +144,16 @@ public: { if(cart.wsrambankptr()) { - //not bankable - unsigned addr = P&0x1FFF; - CDMapResult ret = { eCDLog_AddrType_CartRAM, addr }; - return ret; + //not bankable. but. we're not sure how much might be here + unsigned char *data; + int length; + bool has = cart.getMemoryArea(3,&data,&length); + unsigned addr = P&(length-1); + if(has && length!=0) + { + CDMapResult ret = { eCDLog_AddrType_CartRAM, addr }; + return ret; + } } } else if(P<0xE000) diff --git a/output/dll/libgambatte.dll b/output/dll/libgambatte.dll index bb85ac5da6..226f1b0f85 100644 Binary files a/output/dll/libgambatte.dll and b/output/dll/libgambatte.dll differ