diff --git a/src/BizHawk.BizInvoke/BizInvoker.cs b/src/BizHawk.BizInvoke/BizInvoker.cs index f37d633e01..f6126dc868 100644 --- a/src/BizHawk.BizInvoke/BizInvoker.cs +++ b/src/BizHawk.BizInvoke/BizInvoker.cs @@ -486,10 +486,11 @@ namespace BizHawk.BizInvoke if (type.IsByRef) { + // Just pass a raw pointer. In the `ref structType` case, caller needs to ensure fields are compatible. var et = type.GetElementType()!; - if (!et.IsPrimitive && !et.IsEnum) + if (!et.IsValueType) { - throw new NotImplementedException("Only refs of primitive or enum types are supported!"); + throw new NotImplementedException("Only refs of value types are supported!"); } return new( typeof(IntPtr), @@ -642,6 +643,7 @@ namespace BizHawk.BizInvoke if (type.IsClass) { // non ref of class can just be passed as pointer + // Just like in the `ref struct` case, if the fields aren't compatible, that's the caller's problem. return new( typeof(IntPtr), () => diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs index d40efde9fc..f8e4714069 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs @@ -18,7 +18,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES [BizImport(CallingConvention.Cdecl)] public abstract void snes_set_video_enabled(bool enabled); [BizImport(CallingConvention.Cdecl)] - public abstract void snes_set_layer_enables(BsnesApi.LayerEnables layerEnables); + public abstract void snes_set_layer_enables(ref BsnesApi.LayerEnables layerEnables); [BizImport(CallingConvention.Cdecl)] public abstract void snes_set_trace_enabled(bool enabled); @@ -144,10 +144,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES public delegate string snes_path_request_t(int slot, string hint, bool required); public delegate void snes_trace_t(string disassembly, string register_info); - - // I cannot use a struct here because marshalling is retarded for bool (4 bytes). I honestly cannot [StructLayout(LayoutKind.Sequential)] - public class LayerEnables + public struct LayerEnables { public bool BG1_Prio0, BG1_Prio1; public bool BG2_Prio0, BG2_Prio1; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.IEmulator.cs index f84c73916d..d00a7190ac 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.IEmulator.cs @@ -47,7 +47,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES Obj_Prio3 = _settings.ShowOBJ_3 }; // TODO: I really don't think stuff like this should be set every single frame (only on change) - Api.core.snes_set_layer_enables(enables); + Api.core.snes_set_layer_enables(ref enables); Api.core.snes_set_trace_enabled(_tracer.Enabled); Api.core.snes_set_video_enabled(render); Api.core.snes_set_audio_enabled(renderSound);