wire controls into gambatte.
This commit is contained in:
parent
3acc87c013
commit
a277dfa1e5
|
@ -16,6 +16,15 @@ namespace BizHawk.Emulation.Consoles.GB
|
|||
/// </summary>
|
||||
IntPtr GambatteState = IntPtr.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// keep a copy of the input callback delegate so it doesn't get GCed
|
||||
/// </summary>
|
||||
LibGambatte.InputGetter InputCallback;
|
||||
|
||||
/// <summary>
|
||||
/// whatever keys are currently depressed
|
||||
/// </summary>
|
||||
LibGambatte.Buttons CurrentButtons = 0;
|
||||
|
||||
public Gameboy(byte[] romdata)
|
||||
{
|
||||
|
@ -36,6 +45,13 @@ namespace BizHawk.Emulation.Consoles.GB
|
|||
|
||||
|
||||
InitSound();
|
||||
|
||||
Frame = 0;
|
||||
LagCount = 0;
|
||||
|
||||
InputCallback = new LibGambatte.InputGetter(ControllerCallback);
|
||||
|
||||
LibGambatte.gambatte_setinputgetter(GambatteState, InputCallback);
|
||||
}
|
||||
|
||||
public IVideoProvider VideoProvider
|
||||
|
@ -67,22 +83,49 @@ namespace BizHawk.Emulation.Consoles.GB
|
|||
public IController Controller { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
public void FrameAdvance(bool render)
|
||||
{
|
||||
uint nsamp = 35112;
|
||||
|
||||
Controller.UpdateControls(Frame++);
|
||||
|
||||
// update our local copy of the controller data
|
||||
CurrentButtons = 0;
|
||||
|
||||
if (Controller["Up"])
|
||||
CurrentButtons |= LibGambatte.Buttons.UP;
|
||||
if (Controller["Down"])
|
||||
CurrentButtons |= LibGambatte.Buttons.DOWN;
|
||||
if (Controller["Left"])
|
||||
CurrentButtons |= LibGambatte.Buttons.LEFT;
|
||||
if (Controller["Right"])
|
||||
CurrentButtons |= LibGambatte.Buttons.RIGHT;
|
||||
if (Controller["A"])
|
||||
CurrentButtons |= LibGambatte.Buttons.A;
|
||||
if (Controller["B"])
|
||||
CurrentButtons |= LibGambatte.Buttons.B;
|
||||
if (Controller["Select"])
|
||||
CurrentButtons |= LibGambatte.Buttons.SELECT;
|
||||
if (Controller["Start"])
|
||||
CurrentButtons |= LibGambatte.Buttons.START;
|
||||
|
||||
LibGambatte.gambatte_runfor(GambatteState, VideoBuffer, 160, soundbuff, ref nsamp);
|
||||
|
||||
soundbuffcontains = (int)nsamp;
|
||||
|
||||
}
|
||||
|
||||
public int Frame
|
||||
// can when this is called (or not called) be used to give information about lagged frames?
|
||||
LibGambatte.Buttons ControllerCallback()
|
||||
{
|
||||
get { return 0; }
|
||||
return CurrentButtons;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int Frame { get; set; }
|
||||
|
||||
public int LagCount { get; set; }
|
||||
|
||||
public bool IsLagFrame
|
||||
|
@ -218,7 +261,7 @@ namespace BizHawk.Emulation.Consoles.GB
|
|||
int soundbuffcontains = 0;
|
||||
|
||||
Sound.Utilities.SpeexResampler resampler;
|
||||
Sound.MetaspuSoundProvider metaspu;
|
||||
Sound.MetaspuSoundProvider metaspu;
|
||||
|
||||
void InitSound()
|
||||
{
|
||||
|
|
|
@ -114,13 +114,20 @@ namespace BizHawk.Emulation.Consoles.GB
|
|||
DOWN = 0x80
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// type of the callback for input state
|
||||
/// </summary>
|
||||
/// <returns>bitfield combination of pressed buttons</returns>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate Buttons InputGetter();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the callback used for getting input state.
|
||||
/// </summary>
|
||||
/// <param name="core">opaque state pointer</param>
|
||||
/// <param name="getinput"></param>
|
||||
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void gambatte_setinputgetter(IntPtr core, Func<Buttons> getinput);
|
||||
public static extern void gambatte_setinputgetter(IntPtr core, InputGetter getinput);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the directory used for storing save data. The default is the same directory as the ROM Image file.
|
||||
|
|
Loading…
Reference in New Issue