* fix #2902; factor out altrunfor and just use upstream's runFor, keeping a frame buffer on the c# side

* linux build
This commit is contained in:
CasualPokePlayer 2021-08-10 23:20:53 -07:00 committed by GitHub
parent ebd18df440
commit 4681805439
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 32 deletions

Binary file not shown.

Binary file not shown.

View File

@ -22,9 +22,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
// runfor() always ends after creating a video frame, so sync-up is guaranteed // 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 // when the display has been off, some frames can be markedly shorter than expected
samplesEmitted = TICKSINFRAME; samplesEmitted = TICKSINFRAME;
if (LibGambatte.gambatte_altrunfor(GambatteState, _soundbuff, ref samplesEmitted) > 0) if (LibGambatte.gambatte_runfor(GambatteState, FrameBuffer, 160, _soundbuff, ref samplesEmitted) > 0)
{ {
LibGambatte.gambatte_blitto(GambatteState, VideoBuffer, 160); Array.Copy(FrameBuffer, VideoBuffer, FrameBuffer.Length);
} }
_cycleCount += samplesEmitted; _cycleCount += samplesEmitted;
@ -40,9 +40,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
// target number of samples to emit: length of 1 frame minus whatever overflow // target number of samples to emit: length of 1 frame minus whatever overflow
samplesEmitted = TICKSINFRAME - frameOverflow; samplesEmitted = TICKSINFRAME - frameOverflow;
Debug.Assert(samplesEmitted * 2 <= _soundbuff.Length); Debug.Assert(samplesEmitted * 2 <= _soundbuff.Length);
if (LibGambatte.gambatte_altrunfor(GambatteState, _soundbuff, ref samplesEmitted) > 0) if (LibGambatte.gambatte_runfor(GambatteState, FrameBuffer, 160, _soundbuff, ref samplesEmitted) > 0)
{ {
LibGambatte.gambatte_blitto(GambatteState, VideoBuffer, 160); Array.Copy(FrameBuffer, VideoBuffer, FrameBuffer.Length);
} }
// account for actual number of samples emitted // account for actual number of samples emitted
@ -73,9 +73,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
} }
samplesEmitted = inputFrameLengthInt - frameOverflow; samplesEmitted = inputFrameLengthInt - frameOverflow;
Debug.Assert(samplesEmitted * 2 <= _soundbuff.Length); Debug.Assert(samplesEmitted * 2 <= _soundbuff.Length);
if (LibGambatte.gambatte_altrunfor(GambatteState, _soundbuff, ref samplesEmitted) > 0) if (LibGambatte.gambatte_runfor(GambatteState, FrameBuffer, 160, _soundbuff, ref samplesEmitted) > 0)
{ {
LibGambatte.gambatte_blitto(GambatteState, VideoBuffer, 160); Array.Copy(FrameBuffer, VideoBuffer, FrameBuffer.Length);
} }
// account for actual number of samples emitted // account for actual number of samples emitted

View File

@ -24,7 +24,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
out _).PadRight(36), out _).PadRight(36),
registerInfo: string.Format( registerInfo: string.Format(
"A:{3:x2} F:{8:x2} B:{4:x2} C:{5:x2} D:{6:x2} E:{7:x2} H:{9:x2} L:{10:x2} LY:{13:x2} SP:{2:x2} {11} Cy:{0}", "A:{3:x2} F:{8:x2} B:{4:x2} C:{5:x2} D:{6:x2} E:{7:x2} H:{9:x2} L:{10:x2} LY:{13:x2} SP:{2:x2} {11} Cy:{0}",
s[0], (ulong)s[0] + _cycleCount,
s[1] & 0xffff, s[1] & 0xffff,
s[2] & 0xffff, s[2] & 0xffff,
s[3] & 0xff, s[3] & 0xff,

View File

@ -2,6 +2,11 @@
{ {
public partial class Gameboy public partial class Gameboy
{ {
/// <summary>
/// buffer of last frame produced
/// </summary>
private readonly int[] FrameBuffer = CreateVideoBuffer();
/// <summary> /// <summary>
/// stored image of most recent frame /// stored image of most recent frame
/// </summary> /// </summary>

View File

@ -43,10 +43,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
unsafe unsafe
{ {
fixed (int* leftvbuff = &VideoBuffer[0]) fixed (int* leftfbuff = &FrameBuffer[0])
{ {
// use pitch to have both cores write to the same video buffer, interleaved // use pitch to have both cores write to the same frame buffer, interleaved
int* rightvbuff = leftvbuff + 160; int* rightfbuff = leftfbuff + 160;
const int Pitch = 160 * 2; const int Pitch = 160 * 2;
fixed (short* leftsbuff = LeftBuffer, rightsbuff = RightBuffer) fixed (short* leftsbuff = LeftBuffer, rightsbuff = RightBuffer)
@ -69,9 +69,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
while (nL < target) while (nL < target)
{ {
uint nsamp = (uint)(target - nL); uint nsamp = (uint)(target - nL);
if (LibGambatte.gambatte_altrunfor(L.GambatteState, leftsbuff + (nL * 2), ref nsamp) > 0) if (LibGambatte.gambatte_runfor(L.GambatteState, leftfbuff, Pitch, leftsbuff + (nL * 2), ref nsamp) > 0)
{ {
LibGambatte.gambatte_blitto(L.GambatteState, leftvbuff, Pitch); for (int i = 0; i < 144; i++)
{
Array.Copy(FrameBuffer, Pitch * i, VideoBuffer, Pitch * i, 160);
}
} }
nL += (int)nsamp; nL += (int)nsamp;
@ -80,9 +83,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
while (nR < target) while (nR < target)
{ {
uint nsamp = (uint)(target - nR); uint nsamp = (uint)(target - nR);
if (LibGambatte.gambatte_altrunfor(R.GambatteState, rightsbuff + (nR * 2), ref nsamp) > 0) if (LibGambatte.gambatte_runfor(R.GambatteState, rightfbuff, Pitch, rightsbuff + (nR * 2), ref nsamp) > 0)
{ {
LibGambatte.gambatte_blitto(R.GambatteState, rightvbuff, Pitch); for (int i = 0; i < 144; i++)
{
Array.Copy(FrameBuffer, 160 + Pitch * i, VideoBuffer, 160 + Pitch * i, 160);
}
} }
nR += (int)nsamp; nR += (int)nsamp;

View File

@ -15,6 +15,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
public int BackgroundColor => unchecked((int)0xff000000); public int BackgroundColor => unchecked((int)0xff000000);
private readonly int[] FrameBuffer = CreateVideoBuffer();
public int[] GetVideoBuffer() => VideoBuffer; public int[] GetVideoBuffer() => VideoBuffer;
private readonly int[] VideoBuffer = CreateVideoBuffer(); private readonly int[] VideoBuffer = CreateVideoBuffer();

View File

@ -83,28 +83,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
/// exact time (in number of samples) at which it was drawn. /// exact time (in number of samples) at which it was drawn.
/// </summary> /// </summary>
/// <param name="core">opaque state pointer</param> /// <param name="core">opaque state pointer</param>
/// <param name="videobuf">160x144 RGB32 (native endian) video frame buffer or 0</param>
/// <param name="pitch">distance in number of pixels (not bytes) from the start of one line to the next in videoBuf</param>
/// <param name="soundbuf">buffer with space >= samples + 2064</param> /// <param name="soundbuf">buffer with space >= samples + 2064</param>
/// <param name="samples">in: number of stereo samples to produce, out: actual number of samples produced</param> /// <param name="samples">in: number of stereo samples to produce, out: actual number of samples produced</param>
/// <returns>sample number at which the video frame was produced. -1 means no frame was produced.</returns> /// <returns>sample number at which the video frame was produced. -1 means no frame was produced.</returns>
[DllImport("libgambatte", CallingConvention = CallingConvention.Cdecl)] [DllImport("libgambatte", CallingConvention = CallingConvention.Cdecl)]
public static extern int gambatte_altrunfor(IntPtr core, short[] soundbuf, ref uint samples); public static extern int gambatte_runfor(IntPtr core, int[] videobuf, int pitch, short[] soundbuf, ref uint samples);
[DllImport("libgambatte", CallingConvention = CallingConvention.Cdecl)] [DllImport("libgambatte", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int gambatte_altrunfor(IntPtr core, short* soundbuf, ref uint samples); public static extern unsafe int gambatte_runfor(IntPtr core, int* videobuf, int pitch, short* soundbuf, ref uint samples);
/// <summary>
/// blit from internal framebuffer to provided framebuffer
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="pitch">in pixels</param>
[DllImport("libgambatte", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void gambatte_blitto(IntPtr core, int* videobuf, int pitch);
/// <summary>
/// blit from internal framebuffer to provided framebuffer
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="pitch">in pixels</param>
[DllImport("libgambatte", CallingConvention = CallingConvention.Cdecl)]
public static extern void gambatte_blitto(IntPtr core, int[] videobuf, int pitch);
/// <summary> /// <summary>
/// Reset to initial state. /// Reset to initial state.

@ -1 +1 @@
Subproject commit 7ef069716d3589fad7ab156979e18e13fffd0151 Subproject commit eadf3d0e61a7e2a04304a6ffbe8fac019cc7f59d