diff --git a/.gitmodules b/.gitmodules
index 576ce2071f..55aeb4581b 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -27,8 +27,7 @@
url = https://github.com/TASVideos/mednafen.git
[submodule "submodules/gambatte"]
path = submodules/gambatte
- url = https://github.com/TASVideos/gambatte-speedrun.git
- branch = bizhawk
+ url = https://github.com/pokemon-speedrunning/gambatte-core.git
[submodule "waterbox/llvm-project"]
path = waterbox/llvm-project
url = https://github.com/llvm/llvm-project.git
diff --git a/Assets/dll/libgambatte.dll b/Assets/dll/libgambatte.dll
index f1a29c47da..8e6edb69c0 100644
Binary files a/Assets/dll/libgambatte.dll and b/Assets/dll/libgambatte.dll differ
diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs
index d27c14011d..16af3b1a8e 100644
--- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs
+++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs
@@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
// runfor() always ends after creating a video frame, so sync-up is guaranteed
// when the display has been off, some frames can be markedly shorter than expected
samplesEmitted = TICKSINFRAME;
- if (LibGambatte.gambatte_runfor(GambatteState, _soundbuff, ref samplesEmitted) > 0)
+ if (LibGambatte.gambatte_altrunfor(GambatteState, _soundbuff, ref samplesEmitted) > 0)
{
LibGambatte.gambatte_blitto(GambatteState, VideoBuffer, 160);
}
@@ -40,7 +40,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
// target number of samples to emit: length of 1 frame minus whatever overflow
samplesEmitted = TICKSINFRAME - frameOverflow;
Debug.Assert(samplesEmitted * 2 <= _soundbuff.Length);
- if (LibGambatte.gambatte_runfor(GambatteState, _soundbuff, ref samplesEmitted) > 0)
+ if (LibGambatte.gambatte_altrunfor(GambatteState, _soundbuff, ref samplesEmitted) > 0)
{
LibGambatte.gambatte_blitto(GambatteState, VideoBuffer, 160);
}
@@ -73,7 +73,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
}
samplesEmitted = inputFrameLengthInt - frameOverflow;
Debug.Assert(samplesEmitted * 2 <= _soundbuff.Length);
- if (LibGambatte.gambatte_runfor(GambatteState, _soundbuff, ref samplesEmitted) > 0)
+ if (LibGambatte.gambatte_altrunfor(GambatteState, _soundbuff, ref samplesEmitted) > 0)
{
LibGambatte.gambatte_blitto(GambatteState, VideoBuffer, 160);
}
diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs
index 19513e5b03..fc9e2de1ca 100644
--- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs
+++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs
@@ -48,7 +48,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
{
_syncSettings = syncSettings ?? new GambatteSyncSettings();
- LibGambatte.LoadFlags flags = 0;
+ LibGambatte.LoadFlags flags = LibGambatte.LoadFlags.READONLY_SAV;
switch (_syncSettings.ConsoleMode)
{
@@ -99,9 +99,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
bios[0xFB] ^= 0x74;
}
}
- if (LibGambatte.gambatte_loadbios(GambatteState, bios, (uint)bios.Length) != 0)
+ if (LibGambatte.gambatte_loadbiosbuf(GambatteState, bios, (uint)bios.Length) != 0)
{
- throw new InvalidOperationException($"{nameof(LibGambatte.gambatte_loadbios)}() returned non-zero (bios error)");
+ throw new InvalidOperationException($"{nameof(LibGambatte.gambatte_loadbiosbuf)}() returned non-zero (bios error)");
}
}
else
@@ -113,9 +113,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
flags |= LibGambatte.LoadFlags.NO_BIOS;
}
- if (LibGambatte.gambatte_load(GambatteState, file, (uint)file.Length, flags) != 0)
+ if (LibGambatte.gambatte_loadbuf(GambatteState, file, (uint)file.Length, flags) != 0)
{
- throw new InvalidOperationException($"{nameof(LibGambatte.gambatte_load)}() returned non-zero (is this not a gb or gbc rom?)");
+ throw new InvalidOperationException($"{nameof(LibGambatte.gambatte_loadbuf)}() returned non-zero (is this not a gb or gbc rom?)");
}
// set real default colors (before anyone mucks with them at all)
diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs
index 9e20eb8e83..44c3c704e9 100644
--- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs
+++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs
@@ -69,7 +69,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
while (nL < target)
{
uint nsamp = (uint)(target - nL);
- if (LibGambatte.gambatte_runfor(L.GambatteState, leftsbuff + (nL * 2), ref nsamp) > 0)
+ if (LibGambatte.gambatte_altrunfor(L.GambatteState, leftsbuff + (nL * 2), ref nsamp) > 0)
{
LibGambatte.gambatte_blitto(L.GambatteState, leftvbuff, Pitch);
}
@@ -80,7 +80,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
while (nR < target)
{
uint nsamp = (uint)(target - nR);
- if (LibGambatte.gambatte_runfor(R.GambatteState, rightsbuff + (nR * 2), ref nsamp) > 0)
+ if (LibGambatte.gambatte_altrunfor(R.GambatteState, rightsbuff + (nR * 2), ref nsamp) > 0)
{
LibGambatte.gambatte_blitto(R.GambatteState, rightvbuff, Pitch);
}
diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs
index bc528700a7..9734533548 100644
--- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs
+++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs
@@ -26,8 +26,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
GBA_FLAG = 2,
/// Use heuristics to detect and support some multicart MBCs disguised as MBC1.
MULTICART_COMPAT = 4,
+ /// Treat the ROM as having SGB support regardless of what its header advertises.
+ SGB_MODE = 8,
+ /// Prevent implicit saveSavedata calls for the ROM.
+ READONLY_SAV = 16,
/// Use heuristics to boot without a BIOS.
- NO_BIOS = 8
+ NO_BIOS = 32
}
public enum CDLog_AddrType : int
@@ -52,7 +56,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
/// ORed combination of LoadFlags.
/// 0 on success, negative value on failure.
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern int gambatte_load(IntPtr core, byte[] romdata, uint length, LoadFlags flags);
+ public static extern int gambatte_loadbuf(IntPtr core, byte[] romdata, uint length, LoadFlags flags);
///
/// Load GB(C) BIOS image.
@@ -62,7 +66,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
/// length of romdata in bytes
/// 0 on success, negative value on failure.
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern int gambatte_loadbios(IntPtr core, byte[] biosdata, uint length);
+ public static extern int gambatte_loadbiosbuf(IntPtr core, byte[] biosdata, uint length);
///
/// Emulates until at least 'samples' stereo sound samples are produced in the supplied buffer,
@@ -83,9 +87,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
/// in: number of stereo samples to produce, out: actual number of samples produced
/// sample number at which the video frame was produced. -1 means no frame was produced.
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern int gambatte_runfor(IntPtr core, short[] soundbuf, ref uint samples);
+ public static extern int gambatte_altrunfor(IntPtr core, short[] soundbuf, ref uint samples);
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe int gambatte_runfor(IntPtr core, short* soundbuf, ref uint samples);
+ public static extern unsafe int gambatte_altrunfor(IntPtr core, short* soundbuf, ref uint samples);
///
/// blit from internal framebuffer to provided framebuffer
diff --git a/submodules/gambatte b/submodules/gambatte
index 1fe731bd6f..6e475f769d 160000
--- a/submodules/gambatte
+++ b/submodules/gambatte
@@ -1 +1 @@
-Subproject commit 1fe731bd6f0ca40737aa2e577d791ea6b084829a
+Subproject commit 6e475f769d69b1b7f2ad3e5af1d48fdb46ebbbe8