using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace BizHawk.Emulation.Consoles.Nintendo.GBA { /// /// bindings into libmeteor.dll /// public static class LibMeteor { /// /// power cycle the emulation core /// [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_hardreset(); /// /// signal that you are removing data from the sound buffer. /// the next time frameadvance() is called, writing will start from the beginning /// /// the valid length of the buffer, in bytes [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern uint libmeteor_emptysound(); /// /// set up buffers for libmeteor to dump data to. these must be valid before every frameadvance /// /// buffer to hold video data as BGRA32 /// length in bytes. must be at least 240 * 160 * 4 /// buffer to hold audio data as stereo s16le /// length in bytes. must be 0 mod 4 (hold a full stereo sample set) /// false if some problem. buffers will not be valid in this case [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern bool libmeteor_setbuffers(IntPtr vid, uint vidlen, IntPtr aud, uint audlen); /// /// initialize the library /// [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_init(); /// /// run emulation for one frame, updating sound and video along the way /// [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_frameadvance(); /// /// load a rom image /// /// raw rom data. need not persist past this call /// length of data in bytes [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_loadrom(byte[] data, uint datalen); /// /// load a bios image /// /// raw bios data. need not persist past this call /// length of data in bytes [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_loadbios(byte[] data, uint datalen); /// /// core callback to print meaningful (or meaningless) log messages /// /// message to be printed /// true if emulation should be aborted [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void MessageCallback(string msg, bool abort); /// /// set callback for log messages. this can (and should) be called first /// /// [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_setmessagecallback(MessageCallback cb); /// /// combination of button flags used by the key callback /// [Flags] public enum Buttons : ushort { BTN_A = 0x001, BTN_B = 0x002, BTN_SELECT = 0x004, BTN_START = 0x008, BTN_RIGHT = 0x010, BTN_LEFT = 0x020, BTN_UP = 0x040, BTN_DOWN = 0x080, BTN_R = 0x100, BTN_L = 0x200 } /// /// core callback to get input state /// /// buttons pressed bitfield [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate Buttons InputCallback(); /// /// set callback for whenever input is requested /// /// [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_setkeycallback(InputCallback callback); /// /// parameter to libmeteor_getmemoryarea /// public enum MemoryArea : int { /// /// BIOS, may be invalid if bios not loaded. valid size: 16K. system bus: @00000000h /// bios = 0, /// /// external workram. valid size: 256K. system bus: @02000000h /// ewram = 1, /// /// internal workram. valid size: 32K. system bus: @03000000h /// iwram = 2, /// /// palettes. valid size: 1K. system bus: @05000000h /// palram = 3, /// /// video ram. valid size: 96K. system bus: @06000000h /// vram = 4, /// /// sprite attribute ram. valid size: 1K. system bus: @07000000h /// oam = 5, /// /// rom. always valid to full size, even if no rom or small rom loaded. valid size: 32M. system bus: @08000000h, others /// rom = 6, /// /// direct access to cached io port values. this should NEVER be modified! valid size: 4K. system bus: @04000000h (sort of) /// io = 7 } /// /// return a pointer to a memory area /// /// /// IntPtr.Zero if which is unrecognized [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr libmeteor_getmemoryarea(MemoryArea which); /// /// core callback for tracelogging /// /// disassembly of an instruction about to be run [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void TraceCallback(string msg); /// /// set callback to run before each instruction is executed /// /// null to clear [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_settracecallback(TraceCallback callback); /// /// load saveram from a byte buffer /// /// /// /// success [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern bool libmeteor_loadsaveram(byte[] data, uint size); /// /// save saveram to a byte buffer /// /// buffer generated by core. copy from, but do not modify /// length of buffer /// success [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern bool libmeteor_savesaveram(ref IntPtr data, ref uint size); /// /// destroy a buffer previously returned by libmeteor_savesaveram() to avoid leakage /// /// [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_savesaveram_destroy(IntPtr data); /// /// return true if there is saveram installed on currently loaded cart /// /// [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern bool libmeteor_hassaveram(); /// /// resets the current cart's saveram /// [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_clearsaveram(); /// /// serialize state /// /// buffer generated by core /// size of buffer /// success [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern bool libmeteor_savestate(ref IntPtr data, ref uint size); /// /// destroy a buffer previously returned by libmeteor_savestate() to avoid leakage /// /// [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_savestate_destroy(IntPtr data); /// /// unserialize state /// /// /// /// success [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern bool libmeteor_loadstate(byte[] data, uint size); /// /// read a byte off the system bus. guaranteed to have no side effects /// /// /// [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern byte libmeteor_peekbus(uint addr); /// /// write a byte to the system bus. /// /// /// [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_writebus(uint addr, byte val); /// /// type of the scanline callback /// [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ScanlineCallback(); /// /// set a callback to coincide with vcount interrupts /// /// null to clear /// 0-227, 160 occurring first in a frame [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void libmeteor_setscanlinecallback(ScanlineCallback callback, int scanline); } }