diff --git a/BizHawk.Emulation/Consoles/GB/LibGambatte.cs b/BizHawk.Emulation/Consoles/GB/LibGambatte.cs index 4e461d0cc4..08e49bfbca 100644 --- a/BizHawk.Emulation/Consoles/GB/LibGambatte.cs +++ b/BizHawk.Emulation/Consoles/GB/LibGambatte.cs @@ -11,9 +11,17 @@ namespace BizHawk.Emulation.Consoles.GB /// public static class LibGambatte { + /// + /// + /// + /// opaque state pointer [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr gambatte_create(); + /// + /// + /// + /// opaque state pointer [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void gambatte_destroy(IntPtr core); @@ -28,18 +36,71 @@ namespace BizHawk.Emulation.Consoles.GB MULTICART_COMPAT = 4 } + /// + /// Load ROM image. + /// + /// 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. + /// [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int gambatte_load(IntPtr core, string filename, LoadFlags flags); + /// + /// 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. + /// + /// opaque state pointer + /// 160x144 RGB32 (native endian) video frame buffer or null + /// distance in number of pixels (not bytes) from the start of one line to the next in videoBuf. + /// buffer with space >= samples + 2064 + /// in: number of stereo samples to produce, out: actual number of samples produced + /// sample number at which the video frame was produced. -1 means no frame was produced. [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern long gambatte_runfor(IntPtr core, uint[] videobuf, int pitch, short[] soundbuf, ref uint samples); + public static extern int gambatte_runfor(IntPtr core, uint[] videobuf, int pitch, short[] soundbuf, ref uint samples); + /// + /// Reset to initial state. + /// Equivalent to reloading a ROM image, or turning a Game Boy Color off and on again. + /// + /// opaque state pointer [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void gambatte_reset(IntPtr core); - [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern void gambatte_setdmgpalettecolor(IntPtr core, uint palnum, uint colornum, uint rgb32); + /// + /// palette type for gambatte_setdmgpalettecolor + /// + public enum PalType : uint + { + BG_PALETTE = 0, + SP1_PALETTE = 1, + SP2_PALETTE = 2 + }; + + /// + /// + /// + /// opaque state pointer + /// 0 <= palNum < 3. One of BG_PALETTE, SP1_PALETTE and SP2_PALETTE. + /// 0 <= colorNum < 4 + /// + [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] + public static extern void gambatte_setdmgpalettecolor(IntPtr core, PalType palnum, uint colornum, uint rgb32); + + /// + /// combination of button flags used by the input callback + /// [Flags] public enum Buttons { @@ -53,45 +114,122 @@ namespace BizHawk.Emulation.Consoles.GB DOWN = 0x80 } + /// + /// Sets the callback used for getting input state. + /// + /// opaque state pointer + /// [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void gambatte_setinputgetter(IntPtr core, Func getinput); + /// + /// Sets the directory used for storing save data. The default is the same directory as the ROM Image file. + /// + /// opaque state pointer + /// [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void gambatte_setsavedir(IntPtr core, string sdir); + /// + /// Returns true if the currently loaded ROM image is treated as having CGB support. + /// + /// opaque state pointer + /// [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int gambatte_iscgb(IntPtr core); + public static extern bool gambatte_iscgb(IntPtr core); + /// + /// Returns true if a ROM image is loaded. + /// + /// opaque state pointer + /// [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int gambatte_isloaded(IntPtr core); + public static extern bool gambatte_isloaded(IntPtr core); + /// + /// Writes persistent cartridge data to disk. Done implicitly on ROM close. + /// + /// opaque state pointer [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern void gambatte_savesavedate(IntPtr core); + public static extern void gambatte_savesavedata(IntPtr core); + /// + /// Saves emulator state to the state slot selected with gambatte_selectstate(). + /// The data will be stored in the directory given by gambatte_setsavedir(). + /// + /// opaque state pointer + /// 160x144 RGB32 (native endian) video frame buffer or 0. Used for saving a thumbnail. + /// distance in number of pixels (not bytes) from the start of one line to the next in videoBuf. + /// [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int gambatte_savestate(IntPtr core, uint[] videobuf, int pitch); + public static extern bool gambatte_savestate(IntPtr core, uint[] videobuf, int pitch); + /// + /// Loads emulator state from the state slot selected with selectState(). + /// + /// opaque state pointer + /// success [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int gambatte_loadstate(IntPtr core); + public static extern bool gambatte_loadstate(IntPtr core); + /// + /// Saves emulator state to the file given by 'filepath'. + /// + /// opaque state pointer + /// 160x144 RGB32 (native endian) video frame buffer or 0. Used for saving a thumbnail. + /// distance in number of pixels (not bytes) from the start of one line to the next in videoBuf. + /// + /// success [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int gambatte_savestate_file(IntPtr core, uint[] videobuf, int pitch, string filepath); + public static extern bool gambatte_savestate_file(IntPtr core, uint[] videobuf, int pitch, string filepath); + /// + /// Loads emulator state from the file given by 'filepath'. + /// + /// opaque state pointer + /// + /// success [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int gambatte_loadstate_file(IntPtr core, string filepath); + public static extern bool gambatte_loadstate_file(IntPtr core, string filepath); + /// + /// 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). + /// + /// opaque state pointer + /// [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void gambatte_selectstate(IntPtr core, int n); + /// + /// Current state slot selected with selectState(). Returns a value between 0 and 9 inclusive. + /// + /// opaque state pointer + /// [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int gambatte_currentstate(IntPtr core); + /// + /// ROM header title of currently loaded ROM image. + /// + /// opaque state pointer + /// [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] public static extern string gambatte_romtitle(IntPtr core); + /// + /// Set Game Genie codes to apply to currently loaded ROM image. Cleared on ROM load. + /// + /// opaque state pointer + /// Game Genie codes in format HHH-HHH-HHH;HHH-HHH-HHH;... where H is [0-9]|[A-F] [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void gambatte_setgamegenie(IntPtr core, string codes); + /// + /// Game Shark codes to apply to currently loaded ROM image. Cleared on ROM load. + /// + /// opaque state pointer + /// Game Shark codes in format 01HHHHHH;01HHHHHH;... where H is [0-9]|[A-F] [DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void gambatte_setgameshark(IntPtr core, string codes); diff --git a/libgambatte/src/cinterface.cpp b/libgambatte/src/cinterface.cpp index 8d851bb36d..37a8f49417 100644 --- a/libgambatte/src/cinterface.cpp +++ b/libgambatte/src/cinterface.cpp @@ -82,7 +82,7 @@ __declspec(dllexport) int gambatte_isloaded(void *core) return g->isLoaded(); } -__declspec(dllexport) void gambatte_savesavedate(void *core) +__declspec(dllexport) void gambatte_savesavedata(void *core) { GB *g = (GB *) core; g->saveSavedata(); diff --git a/libgambatte/src/cinterface.h b/libgambatte/src/cinterface.h index 82e4cc61d8..33400004d8 100644 --- a/libgambatte/src/cinterface.h +++ b/libgambatte/src/cinterface.h @@ -22,7 +22,7 @@ extern "C" __declspec(dllexport) int gambatte_isloaded(void *core); - __declspec(dllexport) void gambatte_savesavedate(void *core); + __declspec(dllexport) void gambatte_savesavedata(void *core); __declspec(dllexport) int gambatte_savestate(void *core, const unsigned long *videobuf, int pitch);