diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj
index 824b9f1642..1b054478bb 100644
--- a/BizHawk.Emulation/BizHawk.Emulation.csproj
+++ b/BizHawk.Emulation/BizHawk.Emulation.csproj
@@ -110,9 +110,10 @@
+
-
+
diff --git a/BizHawk.Emulation/Consoles/Gambatte/Gambatte.cs b/BizHawk.Emulation/Consoles/Gambatte/Gambatte.cs
new file mode 100644
index 0000000000..79bca803f8
--- /dev/null
+++ b/BizHawk.Emulation/Consoles/Gambatte/Gambatte.cs
@@ -0,0 +1,209 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+
+namespace BizHawk.Emulation.Consoles.Gambatte
+{
+ public class Gambatte : IEmulator, IVideoProvider
+ {
+ ///
+ /// internal gambatte state
+ ///
+ IntPtr GambatteState = IntPtr.Zero;
+
+
+ public Gambatte(byte[] romdata)
+ {
+ // use temp file until we hack up the libgambatte api to take data directly
+
+ using (FileStream fs = new FileStream("gambattetmp.gb", FileMode.OpenOrCreate, FileAccess.Write))
+ {
+ fs.Write(romdata, 0, romdata.Length);
+ }
+
+ GambatteState = LibGambatte.gambatte_create();
+
+ if (GambatteState == IntPtr.Zero)
+ throw new Exception("gambatte_create() returned null???");
+
+ if (LibGambatte.gambatte_load(GambatteState, "gambattetmp.gb", 0) != 0)
+ throw new Exception("gambatte_load() returned non-zero (is this not a gb or gbc rom?)");
+
+ }
+
+ public IVideoProvider VideoProvider
+ {
+ get { return this; }
+ }
+
+ public ISoundProvider SoundProvider
+ {
+ get { return new NullSound(); }
+ }
+
+
+
+ static readonly ControllerDefinition GbController = new ControllerDefinition
+ {
+ Name = "Gameboy Controller",
+ BoolButtons =
+ {
+ "Up", "Down", "Left", "Right", "A", "B", "Select", "Start"
+ }
+ };
+
+ public ControllerDefinition ControllerDefinition
+ {
+ get { return GbController; }
+ }
+
+ public IController Controller { get; set; }
+
+
+ short[] soundscratch = new short[(35112 + 2064) * 2];
+ uint[] videoscratch = new uint[160 * 144];
+ public void FrameAdvance(bool render)
+ {
+ uint nsamp = 35112;
+
+ LibGambatte.gambatte_runfor(GambatteState, videoscratch, 160, soundscratch, ref nsamp);
+
+ // can't convert uint[] to int[], so we do this instead
+ // TODO: lie in the p/invoke layer and claim unsigned* is really int*
+
+ Buffer.BlockCopy(videoscratch, 0, VideoBuffer, 0, VideoBuffer.Length * sizeof(int));
+ }
+
+ public int Frame
+ {
+ get { return 0; }
+ }
+
+ public int LagCount { get; set; }
+
+ public bool IsLagFrame
+ {
+ get { return false; }
+ }
+
+ public string SystemId
+ {
+ get { return "GB"; }
+ }
+
+ public bool DeterministicEmulation { get; set; }
+
+ public byte[] ReadSaveRam
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public bool SaveRamModified
+ {
+ get
+ {
+ throw new NotImplementedException();
+ }
+ set
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public void ResetFrameCounter()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SaveStateText(System.IO.TextWriter writer)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void LoadStateText(System.IO.TextReader reader)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SaveStateBinary(System.IO.BinaryWriter writer)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void LoadStateBinary(System.IO.BinaryReader reader)
+ {
+ throw new NotImplementedException();
+ }
+
+ public byte[] SaveStateBinary()
+ {
+ throw new NotImplementedException();
+ }
+
+
+ public CoreInputComm CoreInputComm{ get; set; }
+
+ CoreOutputComm GbOutputComm = new CoreOutputComm
+ {
+ VsyncNum = 60,
+ VsyncDen = 1,
+ RomStatusAnnotation = "Bizwhackin it up",
+ RomStatusDetails = "LEVAR BURTON"
+ };
+
+ public CoreOutputComm CoreOutputComm
+ {
+ get { return GbOutputComm; }
+ }
+
+ public IList MemoryDomains
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public MemoryDomain MainMemory
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public void Dispose()
+ {
+ LibGambatte.gambatte_destroy(GambatteState);
+ GambatteState = IntPtr.Zero;
+ }
+
+ #region IVideoProvider
+
+ int[] VideoBuffer = new int[160 * 144];
+
+ public int[] GetVideoBuffer()
+ {
+ return VideoBuffer;
+ }
+
+ public int VirtualWidth
+ {
+ // only sgb changes this
+ get { return 160; }
+ }
+
+ public int BufferWidth
+ {
+ get { return 160; }
+ }
+
+ public int BufferHeight
+ {
+ get { return 144; }
+ }
+
+ public int BackgroundColor
+ {
+ get { return 0; }
+ }
+
+ #endregion
+ }
+}
diff --git a/BizHawk.Emulation/Consoles/GB/LibGambatte.cs b/BizHawk.Emulation/Consoles/Gambatte/LibGambatte.cs
similarity index 96%
rename from BizHawk.Emulation/Consoles/GB/LibGambatte.cs
rename to BizHawk.Emulation/Consoles/Gambatte/LibGambatte.cs
index 08e49bfbca..69f73d3cdc 100644
--- a/BizHawk.Emulation/Consoles/GB/LibGambatte.cs
+++ b/BizHawk.Emulation/Consoles/Gambatte/LibGambatte.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
-namespace BizHawk.Emulation.Consoles.GB
+namespace BizHawk.Emulation.Consoles.Gambatte
{
///
/// static bindings into libgambatte.dll
@@ -42,7 +42,7 @@ namespace BizHawk.Emulation.Consoles.GB
/// opaque state pointer
/// Path to rom image file. Typically a .gbc, .gb, or .zip-file (if zip-support is compiled in).
/// 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, string filename, LoadFlags flags);
diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs
index 3829b595df..efc850eb9c 100644
--- a/BizHawk.MultiClient/MainForm.cs
+++ b/BizHawk.MultiClient/MainForm.cs
@@ -1381,9 +1381,14 @@ namespace BizHawk.MultiClient
}
break;
case "GB":
+ /*
Gameboy gb = new Gameboy(game, rom.FileData, Global.Config.GameBoySkipBIOS);
nextEmulator = gb;
break;
+ */
+ Emulation.Consoles.Gambatte.Gambatte gambatte = new Emulation.Consoles.Gambatte.Gambatte(rom.FileData);
+ nextEmulator = gambatte;
+ break;
case "COLV":
SMS c = new SMS(game, rom.RomData);//new ColecoVision(game, rom.FileData);
nextEmulator = c;