use BizInvoker for Emu83

This commit is contained in:
CasualPokePlayer 2022-02-03 00:59:49 -08:00
parent 9a8be9d727
commit 0edf95948f
2 changed files with 48 additions and 36 deletions

View File

@ -1,6 +1,8 @@
using System;
using System.Linq;
using BizHawk.BizInvoke;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Calculators.TI83;
@ -10,6 +12,15 @@ namespace BizHawk.Emulation.Cores.Calculators.Emu83
[ServiceNotApplicable(new[] { typeof(IBoardInfo), typeof(IRegionable), typeof(ISaveRam), typeof(ISoundProvider) })]
public partial class Emu83 : TI83Common
{
private static readonly LibEmu83 LibEmu83;
static Emu83()
{
var resolver = new DynamicLibraryImportResolver(
OSTailoredCode.IsUnixHost ? "libemu83.so" : "libemu83.dll", hasLimitedLifetime: false);
LibEmu83 = BizInvoker.GetInvoker<LibEmu83>(resolver, CallingConventionAdapters.Native);
}
private IntPtr Context = IntPtr.Zero;
private readonly BasicServiceProvider _serviceProvider;

View File

@ -1,42 +1,43 @@
using System;
using System.Runtime.InteropServices;
using BizHawk.BizInvoke;
namespace BizHawk.Emulation.Cores.Calculators.Emu83
{
public static class LibEmu83
public abstract class LibEmu83
{
private const string lib = "libemu83";
private const CallingConvention cc = CallingConvention.Cdecl;
[DllImport(lib, CallingConvention = cc)]
public static extern IntPtr TI83_CreateContext(byte[] rom, int len);
[BizImport(cc)]
public abstract IntPtr TI83_CreateContext(byte[] rom, int len);
[DllImport(lib, CallingConvention = cc)]
public static extern void TI83_DestroyContext(IntPtr context);
[BizImport(cc)]
public abstract void TI83_DestroyContext(IntPtr context);
[DllImport(lib, CallingConvention = cc)]
public static extern bool TI83_LoadLinkFile(IntPtr context, byte[] linkfile, int len);
[BizImport(cc)]
public abstract bool TI83_LoadLinkFile(IntPtr context, byte[] linkfile, int len);
[DllImport(lib, CallingConvention = cc)]
public static extern void TI83_SetLinkFilesAreLoaded(IntPtr context);
[BizImport(cc)]
public abstract void TI83_SetLinkFilesAreLoaded(IntPtr context);
[DllImport(lib, CallingConvention = cc)]
public static extern bool TI83_GetLinkActive(IntPtr context);
[BizImport(cc)]
public abstract bool TI83_GetLinkActive(IntPtr context);
[DllImport(lib, CallingConvention = cc)]
public static extern bool TI83_Advance(IntPtr context, bool onpress, bool sendnextlinkfile, int[] videobuf, uint bgcol, uint forecol);
[BizImport(cc)]
public abstract bool TI83_Advance(IntPtr context, bool onpress, bool sendnextlinkfile, int[] videobuf, uint bgcol, uint forecol);
[DllImport(lib, CallingConvention = cc)]
public static extern long TI83_GetStateSize();
[BizImport(cc)]
public abstract long TI83_GetStateSize();
[DllImport(lib, CallingConvention = cc)]
public static extern bool TI83_SaveState(IntPtr context, byte[] buf);
[BizImport(cc)]
public abstract bool TI83_SaveState(IntPtr context, byte[] buf);
[DllImport(lib, CallingConvention = cc)]
public static extern bool TI83_LoadState(IntPtr context, byte[] buf);
[BizImport(cc)]
public abstract bool TI83_LoadState(IntPtr context, byte[] buf);
[DllImport(lib, CallingConvention = cc)]
public static extern void TI83_GetRegs(IntPtr context, int[] buf);
[BizImport(cc)]
public abstract void TI83_GetRegs(IntPtr context, int[] buf);
public enum MemoryArea_t : int
{
@ -45,17 +46,17 @@ namespace BizHawk.Emulation.Cores.Calculators.Emu83
MEM_VRAM,
}
[DllImport(lib, CallingConvention = cc)]
public static extern bool TI83_GetMemoryArea(IntPtr context, MemoryArea_t which, ref IntPtr ptr, ref int len);
[BizImport(cc)]
public abstract bool TI83_GetMemoryArea(IntPtr context, MemoryArea_t which, ref IntPtr ptr, ref int len);
[DllImport(lib, CallingConvention = cc)]
public static extern byte TI83_ReadMemory(IntPtr context, ushort addr);
[BizImport(cc)]
public abstract byte TI83_ReadMemory(IntPtr context, ushort addr);
[DllImport(lib, CallingConvention = cc)]
public static extern void TI83_WriteMemory(IntPtr context, ushort addr, byte val);
[BizImport(cc)]
public abstract void TI83_WriteMemory(IntPtr context, ushort addr, byte val);
[DllImport(lib, CallingConvention = cc)]
public static extern long TI83_GetCycleCount(IntPtr context);
[BizImport(cc)]
public abstract long TI83_GetCycleCount(IntPtr context);
public enum MemoryCallbackId_t : int
{
@ -67,19 +68,19 @@ namespace BizHawk.Emulation.Cores.Calculators.Emu83
[UnmanagedFunctionPointer(cc)]
public delegate void MemoryCallback(ushort addr, long _cycleCount);
[DllImport(lib, CallingConvention = cc)]
public static extern void TI83_SetMemoryCallback(IntPtr context, MemoryCallbackId_t id, MemoryCallback callback);
[BizImport(cc)]
public abstract void TI83_SetMemoryCallback(IntPtr context, MemoryCallbackId_t id, MemoryCallback callback);
[UnmanagedFunctionPointer(cc)]
public delegate void TraceCallback(long _cycleCount);
[DllImport(lib, CallingConvention = cc)]
public static extern void TI83_SetTraceCallback(IntPtr context, TraceCallback callback);
[BizImport(cc)]
public abstract void TI83_SetTraceCallback(IntPtr context, TraceCallback callback);
[UnmanagedFunctionPointer(cc)]
public delegate byte InputCallback(byte _keyboardMask);
[DllImport(lib, CallingConvention = cc)]
public static extern void TI83_SetInputCallback(IntPtr context, InputCallback callback);
[BizImport(cc)]
public abstract void TI83_SetInputCallback(IntPtr context, InputCallback callback);
}
}