BizHawk/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/LibmGBA.cs

147 lines
4.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.GBA
{
public static class LibmGBA
{
const string dll = "mgba.dll";
const CallingConvention cc = CallingConvention.Cdecl;
[DllImport(dll, CallingConvention = cc)]
public static extern void BizDestroy(IntPtr ctx);
[DllImport(dll, CallingConvention = cc)]
public static extern IntPtr BizCreate(byte[] bios, byte[] data, int length, [In]OverrideInfo dbinfo, bool skipBios);
[DllImport(dll, CallingConvention = cc)]
public static extern void BizReset(IntPtr ctx);
2016-09-17 15:31:06 +00:00
public enum SaveType : int
{
Autodetect = -1,
ForceNone = 0,
Sram = 1,
Flash512 = 2,
Flash1m = 3,
Eeprom = 4
}
[Flags]
public enum Hardware : int
{
None = 0,
Rtc = 1,
Rumble = 2,
LightSensor = 4,
Gyro = 8,
Tilt = 16,
GbPlayer = 32,
GbPlayerDetect = 64,
NoOverride = 0x8000 // can probably ignore this
}
[StructLayout(LayoutKind.Sequential)]
public class OverrideInfo
{
public SaveType Savetype;
public Hardware Hardware;
public uint IdleLoop = IDLE_LOOP_NONE;
public const uint IDLE_LOOP_NONE = unchecked((uint)0xffffffff);
}
[DllImport(dll, CallingConvention = cc)]
2015-06-10 01:19:09 +00:00
public static extern bool BizAdvance(IntPtr ctx, LibVBANext.Buttons keys, int[] vbuff, ref int nsamp, short[] sbuff,
long time, short gyrox, short gyroy, short gyroz, byte luma);
[DllImport(dll, CallingConvention = cc)]
public static extern void BizSetPalette(IntPtr ctx, int[] palette);
[StructLayout(LayoutKind.Sequential)]
public class MemoryAreas
{
public IntPtr bios;
public IntPtr wram;
public IntPtr iwram;
public IntPtr mmio;
public IntPtr palram;
public IntPtr vram;
public IntPtr oam;
public IntPtr rom;
2016-04-19 02:46:27 +00:00
public IntPtr sram;
public int sram_size;
}
[DllImport(dll, CallingConvention = cc)]
public static extern void BizGetMemoryAreas(IntPtr ctx, [Out]MemoryAreas dst);
2015-06-06 12:49:31 +00:00
[DllImport(dll, CallingConvention = cc)]
2016-10-08 15:58:52 +00:00
public static extern int BizGetSaveRam(IntPtr ctx, byte[] dest, int maxsize);
2015-06-06 12:49:31 +00:00
[DllImport(dll, CallingConvention = cc)]
2016-11-06 15:32:04 +00:00
public static extern void BizPutSaveRam(IntPtr ctx, byte[] src, int size);
2015-06-06 17:34:19 +00:00
2016-10-23 00:49:42 +00:00
/// <summary>
/// start a savestate operation
/// </summary>
/// <param name="ctx"></param>
/// <param name="p">private parameter to be passed to BizFinishGetState</param>
/// <param name="size">size of buffer to be allocated for BizFinishGetState</param>
/// <returns>if false, operation failed and BizFinishGetState should not be called</returns>
2015-06-06 17:34:19 +00:00
[DllImport(dll, CallingConvention = cc)]
2016-10-23 00:49:42 +00:00
public static extern bool BizStartGetState(IntPtr ctx, ref IntPtr p, ref int size);
/// <summary>
/// finish a savestate operation. if StartGetState returned true, this must be called else memory leaks
/// </summary>
/// <param name="p">returned by BizStartGetState</param>
/// <param name="dest">buffer of length size</param>
/// <param name="size">returned by BizStartGetState</param>
2015-06-06 17:34:19 +00:00
[DllImport(dll, CallingConvention = cc)]
2016-10-23 00:49:42 +00:00
public static extern void BizFinishGetState(IntPtr p, byte[] dest, int size);
2015-06-06 17:34:19 +00:00
[DllImport(dll, CallingConvention = cc)]
2016-02-21 21:14:43 +00:00
public static extern bool BizPutState(IntPtr ctx, byte[] src, int size);
2016-02-21 13:54:00 +00:00
[Flags]
public enum Layers : int
{
BG0 = 1,
BG1 = 2,
BG2 = 4,
BG3 = 8,
OBJ = 16
}
[DllImport(dll, CallingConvention = cc)]
public static extern void BizSetLayerMask(IntPtr ctx, Layers mask);
[Flags]
public enum Sounds : int
{
CH0 = 1,
CH1 = 2,
CH2 = 4,
CH3 = 8,
CHA = 16,
CHB = 32
}
[DllImport(dll, CallingConvention = cc)]
public static extern void BizSetSoundMask(IntPtr ctx, Sounds mask);
2017-04-23 01:58:29 +00:00
[DllImport(dll, CallingConvention = cc)]
public static extern void BizGetRegisters(IntPtr ctx, int[] dest);
2017-06-15 23:34:15 +00:00
[DllImport(dll, CallingConvention = cc)]
public static extern void BizWriteBus(IntPtr ctx, uint addr, byte val);
[DllImport(dll, CallingConvention = cc)]
public static extern byte BizReadBus(IntPtr ctx, uint addr);
}
}