Esempio n. 1
0
        public LibretroApi(string dllPath, string corePath)
        {
            InstanceName = "libretro_" + Guid.NewGuid().ToString();

            var pipeName = InstanceName;

            instanceDll     = new InstanceDll(dllPath);
            instanceDllCore = new InstanceDll(corePath);

            var dllinit = (DllInit)Marshal.GetDelegateForFunctionPointer(instanceDll.GetProcAddress("DllInit"), typeof(DllInit));

            Message     = (MessageApi)Marshal.GetDelegateForFunctionPointer(instanceDll.GetProcAddress("Message"), typeof(MessageApi));
            _copyBuffer = (BufferApi)Marshal.GetDelegateForFunctionPointer(instanceDll.GetProcAddress("CopyBuffer"), typeof(BufferApi));
            _setBuffer  = (BufferApi)Marshal.GetDelegateForFunctionPointer(instanceDll.GetProcAddress("SetBuffer"), typeof(BufferApi));
            SetVariable = (SetVariableApi)Marshal.GetDelegateForFunctionPointer(instanceDll.GetProcAddress("SetVariable"), typeof(SetVariableApi));

            comm = (CommStruct *)dllinit(instanceDllCore.HModule).ToPointer();

            //TODO: (stash function pointers locally and thunk to IntPtr)
            //ALSO: this should be done by the core, I think, not the API. No smarts should be in here
            comm->env.retro_perf_callback.get_cpu_features = IntPtr.Zero;
            //retro_perf_callback.get_cpu_features = new LibRetro.retro_get_cpu_features_t(() => (ulong)(
            //		(Win32PInvokes.IsProcessorFeaturePresent(Win32PInvokes.ProcessorFeature.InstructionsXMMIAvailable) ? LibRetro.RETRO_SIMD.SSE : 0) |
            //		(Win32PInvokes.IsProcessorFeaturePresent(Win32PInvokes.ProcessorFeature.InstructionsXMMI64Available) ? LibRetro.RETRO_SIMD.SSE2 : 0) |
            //		(Win32PInvokes.IsProcessorFeaturePresent(Win32PInvokes.ProcessorFeature.InstructionsSSE3Available) ? LibRetro.RETRO_SIMD.SSE3 : 0) |
            //		(Win32PInvokes.IsProcessorFeaturePresent(Win32PInvokes.ProcessorFeature.InstructionsMMXAvailable) ? LibRetro.RETRO_SIMD.MMX : 0)
            //	));
            //retro_perf_callback.get_perf_counter = new LibRetro.retro_perf_get_counter_t(() => System.Diagnostics.Stopwatch.GetTimestamp());
            //retro_perf_callback.get_time_usec = new LibRetro.retro_perf_get_time_usec_t(() => DateTime.Now.Ticks / 10);
            //retro_perf_callback.perf_log = new LibRetro.retro_perf_log_t(() => { });
            //retro_perf_callback.perf_register = new LibRetro.retro_perf_register_t((ref LibRetro.retro_perf_counter counter) => { });
            //retro_perf_callback.perf_start = new LibRetro.retro_perf_start_t((ref LibRetro.retro_perf_counter counter) => { });
            //retro_perf_callback.perf_stop = new LibRetro.retro_perf_stop_t((ref LibRetro.retro_perf_counter counter) => { });
        }
Esempio n. 2
0
 public void Dispose()
 {
     if (!_disposed)
     {
         _disposed = true;
         _exe.Dispose();
         _exe  = null;
         _core = null;
         _comm = null;
     }
 }
Esempio n. 3
0
        BufferApi _setBuffer;         //TODO: consider making private and wrapping

        public LibsnesApi(string dllPath)
        {
            InstanceName = "libsneshawk_" + Guid.NewGuid().ToString();
            instanceDll  = new InstanceDll(dllPath);
            var dllinit = (DllInit)Marshal.GetDelegateForFunctionPointer(instanceDll.GetProcAddress("DllInit"), typeof(DllInit));

            Message     = (MessageApi)Marshal.GetDelegateForFunctionPointer(instanceDll.GetProcAddress("Message"), typeof(MessageApi));
            _copyBuffer = (BufferApi)Marshal.GetDelegateForFunctionPointer(instanceDll.GetProcAddress("CopyBuffer"), typeof(BufferApi));
            _setBuffer  = (BufferApi)Marshal.GetDelegateForFunctionPointer(instanceDll.GetProcAddress("SetBuffer"), typeof(BufferApi));

            comm = (CommStruct *)dllinit().ToPointer();
        }
Esempio n. 4
0
 public LibsnesApi(string dllPath)
 {
     _exe = new PeRunner(new PeRunnerOptions
     {
         Filename            = "libsnes.wbx",
         Path                = dllPath,
         SbrkHeapSizeKB      = 4 * 1024,
         InvisibleHeapSizeKB = 8 * 1024,
         MmapHeapSizeKB      = 32 * 1024,            // TODO: see if we can safely make libco stacks smaller
         PlainHeapSizeKB     = 2 * 1024,             // TODO: wasn't there more in here?
         SealedHeapSizeKB    = 128 * 1024
     });
     using (_exe.EnterExit())
     {
         // Marshal checks that function pointers passed to GetDelegateForFunctionPointer are
         // _currently_ valid when created, even though they don't need to be valid until
         // the delegate is later invoked.  so GetInvoker needs to be acquired within a lock.
         _core = BizInvoker.GetInvoker <CoreImpl>(_exe, _exe, CallingConventionAdapters.Waterbox);
         _comm = (CommStruct *)_core.DllInit().ToPointer();
     }
 }
Esempio n. 5
0
 public LibsnesApi(string dllPath, CoreComm comm, IEnumerable <Delegate> allCallbacks)
 {
     _exe = new WaterboxHost(new WaterboxOptions
     {
         Filename                   = "libsnes.wbx",
         Path                       = dllPath,
         SbrkHeapSizeKB             = 4 * 1024,
         InvisibleHeapSizeKB        = 8 * 1024,
         MmapHeapSizeKB             = 32 * 1024,     // TODO: see if we can safely make libco stacks smaller
         PlainHeapSizeKB            = 2 * 1024,      // TODO: wasn't there more in here?
         SealedHeapSizeKB           = 128 * 1024,
         SkipCoreConsistencyCheck   = comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxCoreConsistencyCheck),
         SkipMemoryConsistencyCheck = comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck),
     });
     using (_exe.EnterExit())
     {
         // Marshal checks that function pointers passed to GetDelegateForFunctionPointer are
         // _currently_ valid when created, even though they don't need to be valid until
         // the delegate is later invoked.  so GetInvoker needs to be acquired within a lock.
         _core = BizInvoker.GetInvoker <CoreImpl>(_exe, _exe, CallingConventionAdapters.MakeWaterbox(allCallbacks, _exe));
         _comm = (CommStruct *)_core.DllInit().ToPointer();
     }
 }
Esempio n. 6
0
        public LibretroApi(string dllPath, string corePath)
        {
            T GetTypedDelegate <T>(string proc) where T : Delegate => (T)Marshal.GetDelegateForFunctionPointer(instanceDll.GetProcAddrOrThrow(proc), typeof(T));

            InstanceName = "libretro_" + Guid.NewGuid();

            var pipeName = InstanceName;

            instanceDll     = new InstanceDll(dllPath);
            instanceDllCore = new InstanceDll(corePath);

            Message     = GetTypedDelegate <MessageApi>("Message");
            _copyBuffer = GetTypedDelegate <BufferApi>("CopyBuffer");
            _setBuffer  = GetTypedDelegate <BufferApi>("SetBuffer");
            SetVariable = GetTypedDelegate <SetVariableApi>("SetVariable");

            comm = (CommStruct *)(OSTailoredCode.IsUnixHost
                                ? GetTypedDelegate <DllInitUnix>("DllInit")(corePath)
                                : GetTypedDelegate <DllInit>("DllInit")(instanceDllCore.HModule)).ToPointer();

            //TODO: (stash function pointers locally and thunk to IntPtr)
            //ALSO: this should be done by the core, I think, not the API. No smarts should be in here
            comm->env.retro_perf_callback.get_cpu_features = IntPtr.Zero;
            //retro_perf_callback.get_cpu_features = new LibRetro.retro_get_cpu_features_t(() => (ulong)(
            //		(ProcessorFeatureImports.IsProcessorFeaturePresent(ProcessorFeatureImports.ProcessorFeature.InstructionsXMMIAvailable) ? LibRetro.RETRO_SIMD.SSE : 0) |
            //		(ProcessorFeatureImports.IsProcessorFeaturePresent(ProcessorFeatureImports.ProcessorFeature.InstructionsXMMI64Available) ? LibRetro.RETRO_SIMD.SSE2 : 0) |
            //		(ProcessorFeatureImports.IsProcessorFeaturePresent(ProcessorFeatureImports.ProcessorFeature.InstructionsSSE3Available) ? LibRetro.RETRO_SIMD.SSE3 : 0) |
            //		(ProcessorFeatureImports.IsProcessorFeaturePresent(ProcessorFeatureImports.ProcessorFeature.InstructionsMMXAvailable) ? LibRetro.RETRO_SIMD.MMX : 0)
            //	));
            //retro_perf_callback.get_perf_counter = new LibRetro.retro_perf_get_counter_t(() => System.Diagnostics.Stopwatch.GetTimestamp());
            //retro_perf_callback.get_time_usec = new LibRetro.retro_perf_get_time_usec_t(() => DateTime.Now.Ticks / 10);
            //retro_perf_callback.perf_log = new LibRetro.retro_perf_log_t(() => { });
            //retro_perf_callback.perf_register = new LibRetro.retro_perf_register_t((ref LibRetro.retro_perf_counter counter) => { });
            //retro_perf_callback.perf_start = new LibRetro.retro_perf_start_t((ref LibRetro.retro_perf_counter counter) => { });
            //retro_perf_callback.perf_stop = new LibRetro.retro_perf_stop_t((ref LibRetro.retro_perf_counter counter) => { });
        }