virtual boy: add IInputPollable. Unfortunately, adding one more field to EmulateSpec caused C# to vomit its brains out, so yeah...

This commit is contained in:
nattthebear 2017-05-29 12:16:24 -04:00
parent b0aff5c2f6
commit 4ab407bb42
5 changed files with 52 additions and 16 deletions

View File

@ -21,37 +21,47 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.VB
public int H; public int H;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Explicit)] // TODO: find out why Sequential is sometimes ignored on the native layout
public class EmulateSpec public class EmulateSpec
{ {
// Pitch(32-bit) must be equal to width and >= the "fb_width" specified in the MDFNGI struct for the emulated system. // Pitch(32-bit) must be equal to width and >= the "fb_width" specified in the MDFNGI struct for the emulated system.
// Height must be >= to the "fb_height" specified in the MDFNGI struct for the emulated system. // Height must be >= to the "fb_height" specified in the MDFNGI struct for the emulated system.
// The framebuffer pointed to by surface->pixels is written to by the system emulation code. // The framebuffer pointed to by surface->pixels is written to by the system emulation code.
[FieldOffset(0)]
public IntPtr Pixels; public IntPtr Pixels;
// Pointer to sound buffer, set by the driver code, that the emulation code should render sound to. // Pointer to sound buffer, set by the driver code, that the emulation code should render sound to.
// Guaranteed to be at least 500ms in length, but emulation code really shouldn't exceed 40ms or so. Additionally, if emulation code // Guaranteed to be at least 500ms in length, but emulation code really shouldn't exceed 40ms or so. Additionally, if emulation code
// generates >= 100ms, // generates >= 100ms,
// DEPRECATED: Emulation code may set this pointer to a sound buffer internal to the emulation module. // DEPRECATED: Emulation code may set this pointer to a sound buffer internal to the emulation module.
[FieldOffset(8)]
public IntPtr SoundBuf; public IntPtr SoundBuf;
// Number of cycles that this frame consumed, using MDFNGI::MasterClock as a time base. // Number of cycles that this frame consumed, using MDFNGI::MasterClock as a time base.
// Set by emulation code. // Set by emulation code.
[FieldOffset(16)]
public long MasterCycles; public long MasterCycles;
// Set by the system emulation code every frame, to denote the horizontal and vertical offsets of the image, and the size // Set by the system emulation code every frame, to denote the horizontal and vertical offsets of the image, and the size
// of the image. If the emulated system sets the elements of LineWidths, then the width(w) of this structure // of the image. If the emulated system sets the elements of LineWidths, then the width(w) of this structure
// is ignored while drawing the image. // is ignored while drawing the image.
[FieldOffset(24)]
public Rect DisplayRect; public Rect DisplayRect;
// Maximum size of the sound buffer, in frames. Set by the driver code. // Maximum size of the sound buffer, in frames. Set by the driver code.
[FieldOffset(40)]
public int SoundBufMaxSize; public int SoundBufMaxSize;
// Number of frames currently in internal sound buffer. Set by the system emulation code, to be read by the driver code. // Number of frames currently in internal sound buffer. Set by the system emulation code, to be read by the driver code.
[FieldOffset(44)]
public int SoundBufSize; public int SoundBufSize;
// 0 UDLR SelectStartBA UDLR(right dpad) LtrigRtrig 13 // 0 UDLR SelectStartBA UDLR(right dpad) LtrigRtrig 13
[FieldOffset(48)]
public Buttons Buttons; public Buttons Buttons;
[FieldOffset(52)]
public bool Lagged;
} }
public enum MemoryArea : int public enum MemoryArea : int
@ -77,6 +87,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.VB
R = 0x4 R = 0x4
} }
[UnmanagedFunctionPointer(CC)]
public delegate void InputCallback();
[BizImport(CC)] [BizImport(CC)]
public abstract bool Load(byte[] rom, int length); public abstract bool Load(byte[] rom, int length);
@ -88,5 +101,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.VB
[BizImport(CC)] [BizImport(CC)]
public abstract void HardReset(); public abstract void HardReset();
[BizImport(CC)]
public abstract void SetInputCallback(InputCallback callback);
} }
} }

View File

@ -11,9 +11,10 @@ using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Consoles.Nintendo.VB namespace BizHawk.Emulation.Cores.Consoles.Nintendo.VB
{ {
[CoreAttributes("Virtual Boyee", "???", true, false, "0.9.44.1", [CoreAttributes("Virtual Boyee", "???", true, false, "0.9.44.1",
"https://mednafen.github.io/releases/", false)] "https://mednafen.github.io/releases/", false)]
public class VirtualBoyee : IEmulator, IVideoProvider, ISoundProvider, IStatable public class VirtualBoyee : IEmulator, IVideoProvider, ISoundProvider, IStatable,
IInputPollable
{ {
private PeRunner _exe; private PeRunner _exe;
private LibVirtualBoyee _boyee; private LibVirtualBoyee _boyee;
@ -42,6 +43,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.VB
} }
_exe.Seal(); _exe.Seal();
_inputCallback = InputCallbacks.Call;
} }
private bool _disposed = false; private bool _disposed = false;
@ -60,6 +63,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.VB
public unsafe void FrameAdvance(IController controller, bool render, bool rendersound = true) public unsafe void FrameAdvance(IController controller, bool render, bool rendersound = true)
{ {
_boyee.SetInputCallback(InputCallbacks.Count > 0 ? _inputCallback : null);
if (controller.IsPressed("Power")) if (controller.IsPressed("Power"))
_boyee.HardReset(); _boyee.HardReset();
@ -78,20 +83,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.VB
BufferWidth = spec.DisplayRect.W; BufferWidth = spec.DisplayRect.W;
BufferHeight = spec.DisplayRect.H; BufferHeight = spec.DisplayRect.H;
_numSamples = spec.SoundBufSize; _numSamples = spec.SoundBufSize;
Frame++;
IsLagFrame = spec.Lagged;
if (IsLagFrame)
LagCount++;
} }
Frame++;
/*_core.biz_set_input_callback(InputCallbacks.Count > 0 ? _inputCallback : null);
UpdateControls(controller);
Frame++;
LibSnes9x.frame_info frame = new LibSnes9x.frame_info();
_core.biz_run(frame, _inputState);
IsLagFrame = frame.padread == 0;
if (IsLagFrame)
LagCount++;*/
} }
public int Frame { get; private set; } public int Frame { get; private set; }
@ -199,6 +198,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.VB
public int LagCount { get; set; } public int LagCount { get; set; }
public bool IsLagFrame { get; set; } public bool IsLagFrame { get; set; }
private LibVirtualBoyee.InputCallback _inputCallback;
public IInputCallbackSystem InputCallbacks { get; } = new InputCallbackSystem();
#region IStatable #region IStatable
public bool BinarySaveStatesPreferred public bool BinarySaveStatesPreferred
@ -230,6 +233,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.VB
LagCount = reader.ReadInt32(); LagCount = reader.ReadInt32();
IsLagFrame = reader.ReadBoolean(); IsLagFrame = reader.ReadBoolean();
// any managed pointers that we sent to the core need to be resent now! // any managed pointers that we sent to the core need to be resent now!
_boyee.SetInputCallback(null);
} }
public void SaveStateBinary(BinaryWriter writer) public void SaveStateBinary(BinaryWriter writer)

Binary file not shown.

View File

@ -41,6 +41,9 @@ struct EmulateSpecStruct
// 0 UDLR SelectStartBA UDLR(right dpad) LtrigRtrig 13 // 0 UDLR SelectStartBA UDLR(right dpad) LtrigRtrig 13
int32 Buttons; int32 Buttons;
// set by core, true if lagged
int32 Lagged;
}; };
/*typedef struct /*typedef struct

View File

@ -25,6 +25,9 @@
namespace MDFN_IEN_VB namespace MDFN_IEN_VB
{ {
static void (*input_callback)();
static bool lagged;
enum enum
{ {
ANAGLYPH_PRESET_DISABLED = 0, ANAGLYPH_PRESET_DISABLED = 0,
@ -126,6 +129,9 @@ static MDFN_FASTCALL uint8 HWCTRL_Read(v810_timestamp_t &timestamp, uint32 A)
case 0x10: case 0x10:
case 0x14: case 0x14:
case 0x28: case 0x28:
lagged = false;
if (input_callback)
input_callback();
ret = VBINPUT_Read(timestamp, A); ret = VBINPUT_Read(timestamp, A);
break; break;
} }
@ -738,6 +744,7 @@ EXPORT void GetMemoryArea(int which, void **ptr, int *size)
EXPORT void Emulate(EmulateSpecStruct *espec) EXPORT void Emulate(EmulateSpecStruct *espec)
{ {
v810_timestamp_t v810_timestamp; v810_timestamp_t v810_timestamp;
lagged = true;
VBINPUT_Frame(&espec->Buttons); VBINPUT_Frame(&espec->Buttons);
@ -753,6 +760,7 @@ EXPORT void Emulate(EmulateSpecStruct *espec)
VSU_CycleFix = (v810_timestamp + VSU_CycleFix) & 3; VSU_CycleFix = (v810_timestamp + VSU_CycleFix) & 3;
espec->MasterCycles = v810_timestamp; espec->MasterCycles = v810_timestamp;
espec->Lagged = lagged;
TIMER_ResetTS(); TIMER_ResetTS();
VBINPUT_ResetTS(); VBINPUT_ResetTS();
@ -768,6 +776,11 @@ EXPORT void HardReset()
VB_Power(); VB_Power();
} }
EXPORT void SetInputCallback(void (*callback)())
{
input_callback = callback;
}
int main() int main()
{ {
return 0; return 0;