2012-09-08 20:22:07 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
2012-09-09 02:06:07 +00:00
|
|
|
|
namespace BizHawk.Emulation.Consoles.GB
|
2012-09-08 20:22:07 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// static bindings into libgambatte.dll
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class LibGambatte
|
|
|
|
|
{
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>opaque state pointer</returns>
|
2012-09-08 20:22:07 +00:00
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern IntPtr gambatte_create();
|
|
|
|
|
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
2012-09-08 20:22:07 +00:00
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void gambatte_destroy(IntPtr core);
|
|
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
|
public enum LoadFlags : uint
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Treat the ROM as not having CGB support regardless of what its header advertises</summary>
|
|
|
|
|
FORCE_DMG = 1,
|
|
|
|
|
/// <summary>Use GBA intial CPU register values when in CGB mode.</summary>
|
|
|
|
|
GBA_CGB = 2,
|
|
|
|
|
/// <summary>Use heuristics to detect and support some multicart MBCs disguised as MBC1.</summary>
|
|
|
|
|
MULTICART_COMPAT = 4
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Load ROM image.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
2012-09-09 21:15:54 +00:00
|
|
|
|
/// <param name="romdata">the rom data, can be disposed of once this function returns</param>
|
|
|
|
|
/// <param name="length">length of romdata in bytes</param>
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <param name="flags">ORed combination of LoadFlags.</param>
|
2012-09-08 21:36:04 +00:00
|
|
|
|
/// <returns>0 on success, negative value on failure.</returns>
|
2012-09-08 20:22:07 +00:00
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
2012-09-09 21:15:54 +00:00
|
|
|
|
public static extern int gambatte_load(IntPtr core, byte[] romdata, uint length, LoadFlags flags);
|
2012-09-08 20:22:07 +00:00
|
|
|
|
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Emulates until at least 'samples' stereo sound samples are produced in the supplied buffer,
|
|
|
|
|
/// or until a video frame has been drawn.
|
|
|
|
|
///
|
|
|
|
|
/// There are 35112 stereo sound samples in a video frame.
|
|
|
|
|
/// May run for up to 2064 stereo samples too long.
|
|
|
|
|
/// A stereo sample consists of two native endian 2s complement 16-bit PCM samples,
|
|
|
|
|
/// with the left sample preceding the right one.
|
|
|
|
|
///
|
|
|
|
|
/// Returns early when a new video frame has finished drawing in the video buffer,
|
|
|
|
|
/// such that the caller may update the video output before the frame is overwritten.
|
|
|
|
|
/// The return value indicates whether a new video frame has been drawn, and the
|
|
|
|
|
/// exact time (in number of samples) at which it was drawn.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <param name="videobuf">160x144 RGB32 (native endian) video frame buffer or null</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="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>
|
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
2012-09-09 13:35:58 +00:00
|
|
|
|
public static extern int gambatte_runfor(IntPtr core, int[] videobuf, int pitch, short[] soundbuf, ref uint samples);
|
2012-09-08 20:46:54 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reset to initial state.
|
|
|
|
|
/// Equivalent to reloading a ROM image, or turning a Game Boy Color off and on again.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
2012-09-08 20:22:07 +00:00
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void gambatte_reset(IntPtr core);
|
|
|
|
|
|
|
|
|
|
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// palette type for gambatte_setdmgpalettecolor
|
|
|
|
|
/// </summary>
|
|
|
|
|
public enum PalType : uint
|
|
|
|
|
{
|
|
|
|
|
BG_PALETTE = 0,
|
|
|
|
|
SP1_PALETTE = 1,
|
|
|
|
|
SP2_PALETTE = 2
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <param name="palnum">0 <= palNum < 3. One of BG_PALETTE, SP1_PALETTE and SP2_PALETTE.</param>
|
|
|
|
|
/// <param name="colornum">0 <= colorNum < 4</param>
|
|
|
|
|
/// <param name="rgb32"></param>
|
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void gambatte_setdmgpalettecolor(IntPtr core, PalType palnum, uint colornum, uint rgb32);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// combination of button flags used by the input callback
|
|
|
|
|
/// </summary>
|
2012-09-08 20:22:07 +00:00
|
|
|
|
[Flags]
|
|
|
|
|
public enum Buttons
|
|
|
|
|
{
|
|
|
|
|
A = 0x01,
|
|
|
|
|
B = 0x02,
|
|
|
|
|
SELECT = 0x04,
|
|
|
|
|
START = 0x08,
|
|
|
|
|
RIGHT = 0x10,
|
|
|
|
|
LEFT = 0x20,
|
|
|
|
|
UP = 0x40,
|
|
|
|
|
DOWN = 0x80
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-09 14:17:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// type of the callback for input state
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>bitfield combination of pressed buttons</returns>
|
|
|
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
|
|
|
public delegate Buttons InputGetter();
|
|
|
|
|
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the callback used for getting input state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <param name="getinput"></param>
|
2012-09-08 20:22:07 +00:00
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
2012-09-09 14:17:57 +00:00
|
|
|
|
public static extern void gambatte_setinputgetter(IntPtr core, InputGetter getinput);
|
2012-09-08 20:22:07 +00:00
|
|
|
|
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the directory used for storing save data. The default is the same directory as the ROM Image file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <param name="sdir"></param>
|
2012-09-08 20:22:07 +00:00
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void gambatte_setsavedir(IntPtr core, string sdir);
|
|
|
|
|
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true if the currently loaded ROM image is treated as having CGB support.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern bool gambatte_iscgb(IntPtr core);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true if a ROM image is loaded.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern bool gambatte_isloaded(IntPtr core);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Writes persistent cartridge data to disk. Done implicitly on ROM close.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void gambatte_savesavedata(IntPtr core);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2012-09-09 18:47:00 +00:00
|
|
|
|
/// Saves emulator state to the state to a byte array
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <param name="videobuf">160x144 RGB32 (native endian) video frame buffer or 0. Used for saving a thumbnail.</param>
|
|
|
|
|
/// <param name="pitch">distance in number of pixels (not bytes) from the start of one line to the next in videoBuf.</param>
|
2012-09-09 18:47:00 +00:00
|
|
|
|
/// <param name="data">private savestate data returned by the core</param>
|
|
|
|
|
/// <param name="len">the length of the data in bytes</param>
|
|
|
|
|
/// <returns>success</returns>
|
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern bool gambatte_savestate(IntPtr core, int[] videobuf, int pitch, ref IntPtr data, ref uint len);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// destroy data returned by gambatte_savestate() to avoid memory leaks
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data">pointer from gambatte_savestate()</param>
|
2012-09-08 20:46:54 +00:00
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
2012-09-09 18:47:00 +00:00
|
|
|
|
public static extern void gambatte_savestate_destroy(IntPtr data);
|
2012-09-08 20:46:54 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2012-09-09 18:47:00 +00:00
|
|
|
|
/// Loads emulator state from the byte array
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
2012-09-09 18:47:00 +00:00
|
|
|
|
/// <param name="data">savestate data</param>
|
|
|
|
|
/// <param name="len">length of the savestate data in bytes</param>
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <returns>success</returns>
|
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
2012-09-09 18:47:00 +00:00
|
|
|
|
public static extern bool gambatte_loadstate(IntPtr core, byte[] data, uint len);
|
2012-09-08 20:46:54 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves emulator state to the file given by 'filepath'.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <param name="videobuf">160x144 RGB32 (native endian) video frame buffer or 0. Used for saving a thumbnail.</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="filepath"></param>
|
|
|
|
|
/// <returns>success</returns>
|
2012-09-09 18:47:00 +00:00
|
|
|
|
//[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
//public static extern bool gambatte_savestate_file(IntPtr core, int[] videobuf, int pitch, string filepath);
|
2012-09-08 20:46:54 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads emulator state from the file given by 'filepath'.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <param name="filepath"></param>
|
|
|
|
|
/// <returns>success</returns>
|
2012-09-09 18:47:00 +00:00
|
|
|
|
//[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
//public static extern bool gambatte_loadstate_file(IntPtr core, string filepath);
|
2012-09-08 20:46:54 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Selects which state slot to save state to or load state from.
|
|
|
|
|
/// There are 10 such slots, numbered from 0 to 9 (periodically extended for all n).
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <param name="n"></param>
|
2012-09-09 21:15:54 +00:00
|
|
|
|
//[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
//public static extern void gambatte_selectstate(IntPtr core, int n);
|
2012-09-08 20:22:07 +00:00
|
|
|
|
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Current state slot selected with selectState(). Returns a value between 0 and 9 inclusive.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <returns></returns>
|
2012-09-09 21:15:54 +00:00
|
|
|
|
//[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
//public static extern int gambatte_currentstate(IntPtr core);
|
2012-09-08 20:22:07 +00:00
|
|
|
|
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// ROM header title of currently loaded ROM image.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <returns></returns>
|
2012-09-08 20:22:07 +00:00
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern string gambatte_romtitle(IntPtr core);
|
|
|
|
|
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set Game Genie codes to apply to currently loaded ROM image. Cleared on ROM load.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <param name="codes">Game Genie codes in format HHH-HHH-HHH;HHH-HHH-HHH;... where H is [0-9]|[A-F]</param>
|
2012-09-08 20:22:07 +00:00
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void gambatte_setgamegenie(IntPtr core, string codes);
|
|
|
|
|
|
2012-09-08 20:46:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Game Shark codes to apply to currently loaded ROM image. Cleared on ROM load.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="core">opaque state pointer</param>
|
|
|
|
|
/// <param name="codes">Game Shark codes in format 01HHHHHH;01HHHHHH;... where H is [0-9]|[A-F]</param>
|
2012-09-08 20:22:07 +00:00
|
|
|
|
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void gambatte_setgameshark(IntPtr core, string codes);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|