waterbox linux progress

uzem runs.  i don't know about anything else yet.  DO NOT ATTEMPT TO LOAD A SAVESTATE.
This commit is contained in:
nattthebear 2020-06-06 15:51:51 -04:00
parent 664c829a30
commit 364d551940
3 changed files with 60 additions and 5 deletions

View File

@ -49,11 +49,17 @@ namespace BizHawk.BizInvoke
/// </summary>
private static readonly ModuleBuilder ImplModuleBuilder;
/// <summary>
/// How far into a class pointer the first field is. Different on mono and fw.
/// </summary>
private static readonly int ClassFieldOffset;
static BizInvoker()
{
var aname = new AssemblyName("BizInvokeProxyAssembly");
ImplAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(aname, AssemblyBuilderAccess.Run);
ImplModuleBuilder = ImplAssemblyBuilder.DefineDynamicModule("BizInvokerModule");
ClassFieldOffset = BizInvokerUtilities.ComputeClassFieldOffset();
}
/// <summary>
@ -476,6 +482,7 @@ namespace BizHawk.BizInvoke
if (typeof(Delegate).IsAssignableFrom(type))
{
// callback -- use the same callingconventionadapter on it that the invoker is being made from
var mi = typeof(ICallingConventionAdapter).GetMethod("GetFunctionPointerForDelegate");
var end = il.DefineLabel();
var isNull = il.DefineLabel();
@ -515,7 +522,7 @@ namespace BizHawk.BizInvoke
il.Emit(OpCodes.Stloc, loc);
il.Emit(OpCodes.Conv_I);
// skip past the methodtable pointer to the first field
il.Emit(IntPtr.Size == 4 ? OpCodes.Ldc_I4_4 : OpCodes.Ldc_I4_8);
il.Emit(OpCodes.Ldc_I4, ClassFieldOffset);
il.Emit(OpCodes.Conv_I);
il.Emit(OpCodes.Add);
il.Emit(OpCodes.Br, end);

View File

@ -0,0 +1,48 @@
using System;
using System.Runtime.InteropServices;
namespace BizHawk.BizInvoke
{
public static unsafe class BizInvokerUtilities
{
[StructLayout(LayoutKind.Explicit)]
private class U
{
[FieldOffset(0)]
public U1 First;
[FieldOffset(0)]
public U2 Second;
}
[StructLayout(LayoutKind.Explicit)]
private class U1
{
[FieldOffset(0)]
public UIntPtr P;
}
[StructLayout(LayoutKind.Explicit)]
private class U2
{
[FieldOffset(0)]
public CF Target;
}
private class CF
{
public int FirstField;
}
/// <summary>
/// Didn't I have code somewhere else to do this already?
/// </summary>
/// <returns></returns>
public static unsafe int ComputeClassFieldOffset()
{
var c = new CF();
int ret;
fixed(int* fx = &c.FirstField)
{
var u = new U { Second = new U2 { Target = c }};
ret = (int)((ulong)(UIntPtr)fx - (ulong)u.First.P);
}
return ret;
}
}
}

View File

@ -394,17 +394,17 @@ namespace BizHawk.Emulation.Cores.Waterbox
}
[StructLayout(LayoutKind.Sequential)]
public class TimeSpec
public struct TimeSpec
{
public long Seconds;
public long NanoSeconds;
}
[BizExport(CallingConvention.Cdecl, EntryPoint = "__wsyscalltab[228]")]
public int SysClockGetTime(int which, [In, Out] TimeSpec time)
public unsafe int SysClockGetTime(int which, TimeSpec* time)
{
time.Seconds = 1495889068;
time.NanoSeconds = 0;
time->Seconds = 1495889068;
time->NanoSeconds = 0;
return 0;
}