diff --git a/.gitmodules b/.gitmodules index 9cbb47c6e56..b20bef79153 100644 --- a/.gitmodules +++ b/.gitmodules @@ -27,7 +27,7 @@ url = https://github.com/TASEmulators/mednafen.git [submodule "submodules/gambatte"] path = submodules/gambatte - url = https://github.com/pokemon-speedrunning/gambatte-core.git + url = https://github.com/roydmerkel/gambatte-core.git [submodule "submodules/libdarm"] path = submodules/libdarm url = https://github.com/jbremer/darm.git diff --git a/Assets/dll/libgambatte.dll b/Assets/dll/libgambatte.dll index 654f402698f..83d08eed4c3 100644 Binary files a/Assets/dll/libgambatte.dll and b/Assets/dll/libgambatte.dll differ diff --git a/Assets/dll/libsameboy.dll b/Assets/dll/libsameboy.dll index 28eb648b4fc..cb8425ace7a 100644 Binary files a/Assets/dll/libsameboy.dll and b/Assets/dll/libsameboy.dll differ diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IDebuggable.cs index adae5f4dd05..431ea0155cc 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IDebuggable.cs @@ -79,25 +79,25 @@ internal void ConnectMemoryCallbackSystem(MemoryCallbackSystem mcs, int which) private LibGambatte.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Func getHasCBOfType, string which = "") { var rawFlags = (uint)flags; - return (address, cycleOffset) => + return (address, cycleOffset, data) => { callbackCycleCount = _cycleCount + cycleOffset; if (getHasCBOfType()) { - MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "System Bus"); + MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "System Bus"); var bank = LibGambatte.gambatte_getaddrbank(GambatteState, (ushort)address); switch (address) { // usually rom bank 0 for most mbcs, some mbcs might have this at a different rom bank case < 0x4000u: address += (uint)(bank * 0x4000); - MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "ROM"); + MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "ROM"); break; // rom bank x case < 0x8000u: address += (uint)(bank * 0x4000); address -= 0x4000u; - MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "ROM"); + MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "ROM"); break; // vram (may be banked on CGB in CGB enhanced mode) case < 0xA000u: @@ -107,19 +107,19 @@ private LibGambatte.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Fun address += (uint)(bank * 0x2000); } address -= 0x8000u; - MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "VRAM"); + MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "VRAM"); break; } // sram (may be banked) case < 0xC000u: address += (uint)(bank * 0x2000); address -= 0xA000u; - MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "SRAM"); + MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "SRAM"); break; // wram bank 0 case < 0xD000u: address -= 0xC000u; - MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "WRAM"); + MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "WRAM"); break; // wram bank x (always one for dmg/cgb in dmg mode) case < 0xE000u: @@ -129,7 +129,7 @@ private LibGambatte.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Fun address += (uint)(bank * 0x1000); } address -= 0xD000u; - MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "WRAM"); + MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "WRAM"); break; } // echo ram @@ -139,7 +139,7 @@ private LibGambatte.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Fun // oam case < 0xFEA0u: address -= 0xFE00u; - MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "OAM"); + MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "OAM"); break; // "extra" oam case < 0xFF00u: @@ -152,7 +152,7 @@ private LibGambatte.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Fun // hram case < 0xFFFF: address -= 0xFF80u; - MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "HRAM"); + MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "HRAM"); break; // ie reg case 0xFFFF: diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs index 58f42decdfb..23b641b4f24 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs @@ -177,7 +177,7 @@ public enum Buttons: uint /// /// the address which the cpu is read\writing [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void MemoryCallback(uint address, ulong cycleOffset); + public delegate void MemoryCallback(uint address, ulong cycleOffset, uint data); /// /// type of the CDLogger callback diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/LibSameBoy.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/LibSameBoy.cs index f88d3676fb9..f4196584a6e 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/LibSameBoy.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/LibSameBoy.cs @@ -131,8 +131,11 @@ public struct GBSInfo [BizImport(cc)] public abstract void sameboy_setreg(IntPtr core, int which, int value); + [BizImport(cc)] + public abstract void sameboy_getbankregs(IntPtr core, int[] buf); + [UnmanagedFunctionPointer(cc)] - public delegate void MemoryCallback(ushort address); + public delegate void MemoryCallback(ushort address, byte data); [BizImport(cc)] public abstract void sameboy_setmemorycallback(IntPtr core, int which, MemoryCallback callback); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IDebuggable.cs index e2e79be60d2..d145146f6d4 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IDebuggable.cs @@ -11,6 +11,9 @@ public IDictionary GetCpuFlagsAndRegisters() int[] data = new int[10]; LibSameboy.sameboy_getregs(SameboyState, data); + int[] banks = new int[5]; + LibSameboy.sameboy_getbankregs(SameboyState, banks); + return new Dictionary { ["PC"] = (ushort)(data[0] & 0xFFFF), @@ -23,6 +26,12 @@ public IDictionary GetCpuFlagsAndRegisters() ["H"] = (byte)(data[7] & 0xFF), ["L"] = (byte)(data[8] & 0xFF), ["SP"] = (ushort)(data[9] & 0xFFFF), + // banks + ["ROM0 BANK"] = (ushort)(banks[0] & 0xFFFF), + ["ROMX BANK"] = (ushort)(banks[1] & 0xFFFF), + ["VRAM BANK"] = (ushort)(banks[4] & 0xFFFF), + ["SRAM BANK"] = (ushort)(banks[3] & 0xFFFF), + ["WRAM BANK"] = (ushort)(banks[2] & 0xFFFF), }; } @@ -67,11 +76,11 @@ private void InitMemoryCallbacks() LibSameboy.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Func getHasCBOfType) { var rawFlags = (uint)flags; - return (address) => + return (address, data) => { if (getHasCBOfType()) { - MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, systemBusScope); + MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, systemBusScope); } }; } diff --git a/submodules/gambatte b/submodules/gambatte index 0838651ca7c..fa8f3dcd20f 160000 --- a/submodules/gambatte +++ b/submodules/gambatte @@ -1 +1 @@ -Subproject commit 0838651ca7c06d8c236834dcf5aa307092b2a82e +Subproject commit fa8f3dcd20f5c52b155def20d8c94ff10bf0d6f5 diff --git a/submodules/sameboy/BizInterface.c b/submodules/sameboy/BizInterface.c index 5fad8f10172..96e8be9e8c0 100644 --- a/submodules/sameboy/BizInterface.c +++ b/submodules/sameboy/BizInterface.c @@ -23,7 +23,7 @@ typedef uint64_t u64; typedef void (*input_callback_t)(void); typedef void (*rumble_callback_t)(u32); typedef void (*trace_callback_t)(u16); -typedef void (*memory_callback_t)(u16); +typedef void (*memory_callback_t)(u16, u8); typedef void (*printer_callback_t)(u32*, u8, u8, u8, u8); typedef void (*scanline_callback_t)(u32); @@ -105,13 +105,13 @@ static void RumbleCallbackRelay(GB_gameboy_t* gb, double rumble_amplitude) static u8 ReadCallbackRelay(GB_gameboy_t* gb, u16 addr, u8 data) { - ((biz_t*)gb)->read_cb(addr); + ((biz_t*)gb)->read_cb(addr, 0); return data; } static bool WriteCallbackRelay(GB_gameboy_t* gb, u16 addr, u8 data) { - ((biz_t*)gb)->write_cb(addr); + ((biz_t*)gb)->write_cb(addr, data); return true; } @@ -124,7 +124,7 @@ static void ExecCallbackRelay(GB_gameboy_t* gb, u16 addr, u8 opcode) } if (biz->exec_cb) { - biz->exec_cb(addr); + biz->exec_cb(addr, 0); } } @@ -488,6 +488,22 @@ EXPORT void sameboy_setreg(biz_t* biz, u32 which, u32 value) } } +EXPORT void sameboy_getbankregs(biz_t* biz, u32* buf) +{ + size_t size; + uint16_t bank; + GB_get_direct_access(&biz->gb, GB_DIRECT_ACCESS_ROM0, &size, &bank); + buf[0] = bank; + GB_get_direct_access(&biz->gb, GB_DIRECT_ACCESS_ROM, &size, &bank); + buf[1] = bank; + GB_get_direct_access(&biz->gb, GB_DIRECT_ACCESS_RAM, &size, &bank); + buf[2] = bank; + GB_get_direct_access(&biz->gb, GB_DIRECT_ACCESS_CART_RAM, &size, &bank); + buf[3] = bank; + GB_get_direct_access(&biz->gb, GB_DIRECT_ACCESS_VRAM, &size, &bank); + buf[4] = bank; +} + EXPORT void sameboy_setmemorycallback(biz_t* biz, u32 which, memory_callback_t callback) { switch (which) diff --git a/submodules/sameboy/libsameboy b/submodules/sameboy/libsameboy index 5d06f45c0f8..b5cd06a41e0 160000 --- a/submodules/sameboy/libsameboy +++ b/submodules/sameboy/libsameboy @@ -1 +1 @@ -Subproject commit 5d06f45c0f8c0cc819409e266780ae653af331e9 +Subproject commit b5cd06a41e0ffc2582e5c5eac7bfa3388f3356e0