public mupen64plusApi(N64 bizhawkCore, byte[] rom, VideoPluginSettings video_settings, int SaveType, int CoreType, bool DisableExpansionSlot) { // There can only be one core (otherwise breaks mupen64plus) if (AttachedCore != null) { AttachedCore.Dispose(); AttachedCore = null; } this.bizhawkCore = bizhawkCore; CoreDll = LoadLibrary("mupen64plus.dll"); if (CoreDll == IntPtr.Zero) { throw new InvalidOperationException(string.Format("Failed to load mupen64plus.dll")); } connectFunctionPointers(); // Start up the core m64p_error result = m64pCoreStartup(0x20001, "", "", "Core", null, "", IntPtr.Zero); // Open the core settings section in the config system IntPtr core_section = IntPtr.Zero; m64pConfigOpenSection("Core", ref core_section); // Set the savetype if needed if (DisableExpansionSlot) { int disable = 1; m64pConfigSetParameter(core_section, "DisableExtraMem", m64p_type.M64TYPE_INT, ref disable); } // Set the savetype if needed if (SaveType != 0) { m64pConfigSetParameter(core_section, "SaveType", m64p_type.M64TYPE_INT, ref SaveType); } m64pConfigSetParameter(core_section, "R4300Emulator", m64p_type.M64TYPE_INT, ref CoreType); // Pass the rom to the core result = m64pCoreDoCommandByteArray(m64p_command.M64CMD_ROM_OPEN, rom.Length, rom); // Open the general video settings section in the config system IntPtr video_section = IntPtr.Zero; m64pConfigOpenSection("Video-General", ref video_section); // Set the desired width and height for mupen64plus result = m64pConfigSetParameter(video_section, "ScreenWidth", m64p_type.M64TYPE_INT, ref video_settings.Width); result = m64pConfigSetParameter(video_section, "ScreenHeight", m64p_type.M64TYPE_INT, ref video_settings.Height); set_video_parameters(video_settings); InitSaveram(); // Initialize event invoker m64pFrameCallback = new FrameCallback(FireFrameFinishedEvent); result = m64pCoreDoCommandFrameCallback(m64p_command.M64CMD_SET_FRAME_CALLBACK, 0, m64pFrameCallback); m64pVICallback = new VICallback(FireVIEvent); result = m64pCoreDoCommandVICallback(m64p_command.M64CMD_SET_VI_CALLBACK, 0, m64pVICallback); m64pRenderCallback = new RenderCallback(FireRenderEvent); result = m64pCoreDoCommandRenderCallback(m64p_command.M64CMD_SET_RENDER_CALLBACK, 0, m64pRenderCallback); // Prepare to start the emulator in a different thread m64pEmulator = new Thread(ExecuteEmulator); AttachedCore = this; }
public mupen64plusApi(N64 bizhawkCore, byte[] rom, VideoPluginSettings video_settings, int SaveType, int CoreType, bool DisableExpansionSlot) { // There can only be one core (otherwise breaks mupen64plus) if (AttachedCore != null) { AttachedCore.Dispose(); AttachedCore = null; } this.bizhawkCore = bizhawkCore; CoreDll = LoadLibrary("mupen64plus.dll"); if (CoreDll == IntPtr.Zero) throw new InvalidOperationException(string.Format("Failed to load mupen64plus.dll")); connectFunctionPointers(); // Start up the core m64p_error result = m64pCoreStartup(0x20001, "", "", "Core", null, "", IntPtr.Zero); // Set the savetype if needed if (DisableExpansionSlot) { IntPtr core_section = IntPtr.Zero; int disable = 1; m64pConfigOpenSection("Core", ref core_section); m64pConfigSetParameter(core_section, "DisableExtraMem", m64p_type.M64TYPE_INT, ref disable); } // Set the savetype if needed if (SaveType != 0) { IntPtr core_section = IntPtr.Zero; m64pConfigOpenSection("Core", ref core_section); m64pConfigSetParameter(core_section, "SaveType", m64p_type.M64TYPE_INT, ref SaveType); } IntPtr coreSection = IntPtr.Zero; m64pConfigOpenSection("Core", ref coreSection); m64pConfigSetParameter(coreSection, "R4300Emulator", m64p_type.M64TYPE_INT, ref CoreType); // Pass the rom to the core result = m64pCoreDoCommandByteArray(m64p_command.M64CMD_ROM_OPEN, rom.Length, rom); // Open the general video settings section in the config system IntPtr video_section = IntPtr.Zero; m64pConfigOpenSection("Video-General", ref video_section); // Set the desired width and height for mupen64plus result = m64pConfigSetParameter(video_section, "ScreenWidth", m64p_type.M64TYPE_INT, ref video_settings.Width); result = m64pConfigSetParameter(video_section, "ScreenHeight", m64p_type.M64TYPE_INT, ref video_settings.Height); set_video_parameters(video_settings); InitSaveram(); // Initialize event invoker m64pFrameCallback = new FrameCallback(FireFrameFinishedEvent); result = m64pCoreDoCommandFrameCallback(m64p_command.M64CMD_SET_FRAME_CALLBACK, 0, m64pFrameCallback); m64pVICallback = new VICallback(FireVIEvent); result = m64pCoreDoCommandVICallback(m64p_command.M64CMD_SET_VI_CALLBACK, 0, m64pVICallback); m64pRenderCallback = new RenderCallback(FireRenderEvent); result = m64pCoreDoCommandRenderCallback(m64p_command.M64CMD_SET_RENDER_CALLBACK, 0, m64pRenderCallback); // Prepare to start the emulator in a different thread m64pEmulator = new Thread(ExecuteEmulator); AttachedCore = this; }