2019-02-12 22:13:09 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Mesen.GUI.Config;
|
|
|
|
|
using Mesen.GUI.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI
|
|
|
|
|
{
|
|
|
|
|
public class EmuApi
|
|
|
|
|
{
|
|
|
|
|
private const string DllPath = "MesenSCore.dll";
|
|
|
|
|
[DllImport(DllPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool TestDll();
|
|
|
|
|
[DllImport(DllPath)] public static extern void InitDll();
|
|
|
|
|
|
|
|
|
|
[DllImport(DllPath, EntryPoint = "GetMesenVersion")] private static extern UInt32 GetMesenVersionWrapper();
|
2019-03-14 12:34:29 -04:00
|
|
|
|
public static Version GetMesenVersion()
|
|
|
|
|
{
|
|
|
|
|
UInt32 version = GetMesenVersionWrapper();
|
|
|
|
|
UInt32 revision = version & 0xFF;
|
|
|
|
|
UInt32 minor = (version >> 8) & 0xFF;
|
|
|
|
|
UInt32 major = (version >> 16) & 0xFFFF;
|
2019-10-14 15:04:26 -04:00
|
|
|
|
return new Version((int)major, (int)minor, (int)revision);
|
2019-03-14 12:34:29 -04:00
|
|
|
|
}
|
2019-02-12 22:13:09 -05:00
|
|
|
|
|
2019-02-15 21:33:13 -05:00
|
|
|
|
[DllImport(DllPath)] public static extern IntPtr RegisterNotificationCallback(NotificationListener.NotificationCallback callback);
|
|
|
|
|
[DllImport(DllPath)] public static extern void UnregisterNotificationCallback(IntPtr notificationListener);
|
|
|
|
|
|
2019-02-12 22:13:09 -05:00
|
|
|
|
[DllImport(DllPath)] public static extern void InitializeEmu([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string homeFolder, IntPtr windowHandle, IntPtr dxViewerHandle, [MarshalAs(UnmanagedType.I1)]bool noAudio, [MarshalAs(UnmanagedType.I1)]bool noVideo, [MarshalAs(UnmanagedType.I1)]bool noInput);
|
|
|
|
|
[DllImport(DllPath)] public static extern void Release();
|
|
|
|
|
|
|
|
|
|
[DllImport(DllPath)] public static extern void Run();
|
2019-02-16 01:22:31 -05:00
|
|
|
|
[DllImport(DllPath)] public static extern void Stop();
|
2019-02-12 22:13:09 -05:00
|
|
|
|
|
2019-03-16 12:20:18 -04:00
|
|
|
|
[DllImport(DllPath)] public static extern void Reset();
|
|
|
|
|
[DllImport(DllPath)] public static extern void PowerCycle();
|
|
|
|
|
|
2019-03-12 13:13:32 -04:00
|
|
|
|
[DllImport(DllPath)] public static extern void Pause();
|
|
|
|
|
[DllImport(DllPath)] public static extern void Resume();
|
|
|
|
|
[DllImport(DllPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool IsPaused();
|
|
|
|
|
|
2019-03-11 17:56:54 -04:00
|
|
|
|
[DllImport(DllPath)] public static extern void TakeScreenshot();
|
|
|
|
|
|
2019-10-08 21:04:32 -04:00
|
|
|
|
[DllImport(DllPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool LoadRom(
|
2019-02-12 22:13:09 -05:00
|
|
|
|
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string filepath,
|
|
|
|
|
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string patchFile = ""
|
|
|
|
|
);
|
|
|
|
|
|
2019-03-28 21:20:18 -04:00
|
|
|
|
[DllImport(DllPath, EntryPoint = "GetRomInfo")] private static extern void GetRomInfoWrapper(out InteropRomInfo romInfo);
|
|
|
|
|
public static RomInfo GetRomInfo()
|
|
|
|
|
{
|
|
|
|
|
InteropRomInfo info;
|
|
|
|
|
EmuApi.GetRomInfoWrapper(out info);
|
|
|
|
|
return new RomInfo(info);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-14 18:07:25 -04:00
|
|
|
|
[DllImport(DllPath)] public static extern void LoadRecentGame([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string filepath, [MarshalAs(UnmanagedType.I1)]bool resetGame);
|
|
|
|
|
|
2019-03-11 17:56:54 -04:00
|
|
|
|
[DllImport(DllPath)] public static extern void AddKnownGameFolder([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string folder);
|
|
|
|
|
|
|
|
|
|
[DllImport(DllPath)] public static extern void SetFolderOverrides(
|
|
|
|
|
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string saveDataFolder,
|
|
|
|
|
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string saveStateFolder,
|
|
|
|
|
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string screenshotFolder
|
|
|
|
|
);
|
2019-02-12 22:13:09 -05:00
|
|
|
|
|
|
|
|
|
[DllImport(DllPath)] public static extern void SetDisplayLanguage(Language lang);
|
2019-03-15 11:39:57 -04:00
|
|
|
|
[DllImport(DllPath)] public static extern void SetFullscreenMode([MarshalAs(UnmanagedType.I1)]bool fullscreen, IntPtr windowHandle, UInt32 monitorWidth, UInt32 monitorHeight);
|
2019-02-17 14:42:35 -05:00
|
|
|
|
|
2019-03-10 11:12:50 -04:00
|
|
|
|
[DllImport(DllPath)] public static extern ScreenSize GetScreenSize([MarshalAs(UnmanagedType.I1)]bool ignoreScale);
|
|
|
|
|
|
2019-02-17 14:42:35 -05:00
|
|
|
|
[DllImport(DllPath, EntryPoint = "GetLog")] private static extern IntPtr GetLogWrapper();
|
|
|
|
|
public static string GetLog() { return Utf8Marshaler.PtrToStringUtf8(EmuApi.GetLogWrapper()).Replace("\n", Environment.NewLine); }
|
2019-03-11 17:56:54 -04:00
|
|
|
|
[DllImport(DllPath)] public static extern void WriteLogEntry([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string message);
|
|
|
|
|
[DllImport(DllPath)] public static extern void DisplayMessage([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string title, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string message, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string param1 = null);
|
2019-03-10 23:45:56 -04:00
|
|
|
|
|
|
|
|
|
[DllImport(DllPath)] public static extern IntPtr GetArchiveRomList([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string filename);
|
2019-03-12 09:15:57 -04:00
|
|
|
|
|
|
|
|
|
[DllImport(DllPath)] public static extern void SaveState(UInt32 stateIndex);
|
|
|
|
|
[DllImport(DllPath)] public static extern void LoadState(UInt32 stateIndex);
|
|
|
|
|
[DllImport(DllPath)] public static extern void SaveStateFile([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string filepath);
|
|
|
|
|
[DllImport(DllPath)] public static extern void LoadStateFile([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string filepath);
|
|
|
|
|
[DllImport(DllPath)] public static extern Int64 GetStateInfo(UInt32 stateIndex);
|
2019-10-12 22:40:25 -04:00
|
|
|
|
|
|
|
|
|
[DllImport(DllPath)] public static extern void SetCheats([In]UInt32[] cheats, UInt32 cheatCount);
|
|
|
|
|
[DllImport(DllPath)] public static extern void ClearCheats();
|
2019-02-12 22:13:09 -05:00
|
|
|
|
}
|
2019-03-10 11:12:50 -04:00
|
|
|
|
|
|
|
|
|
public struct ScreenSize
|
|
|
|
|
{
|
|
|
|
|
public Int32 Width;
|
|
|
|
|
public Int32 Height;
|
|
|
|
|
public double Scale;
|
|
|
|
|
}
|
2019-03-28 21:20:18 -04:00
|
|
|
|
|
|
|
|
|
public struct InteropRomInfo
|
|
|
|
|
{
|
|
|
|
|
public IntPtr RomPath;
|
|
|
|
|
public IntPtr PatchPath;
|
2019-07-25 22:22:09 -04:00
|
|
|
|
public CoprocessorType CoprocessorType;
|
2019-03-28 21:20:18 -04:00
|
|
|
|
public SnesCartInformation Header;
|
2019-10-14 00:37:10 -04:00
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 40)]
|
|
|
|
|
public byte[] Sha1;
|
2019-03-28 21:20:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct RomInfo
|
|
|
|
|
{
|
|
|
|
|
public string RomPath;
|
|
|
|
|
public string PatchPath;
|
2019-07-25 22:22:09 -04:00
|
|
|
|
public CoprocessorType CoprocessorType;
|
2019-03-28 21:20:18 -04:00
|
|
|
|
public SnesCartInformation Header;
|
2019-10-14 00:37:10 -04:00
|
|
|
|
public string Sha1;
|
2019-03-28 21:20:18 -04:00
|
|
|
|
|
|
|
|
|
public RomInfo(InteropRomInfo romInfo)
|
|
|
|
|
{
|
|
|
|
|
RomPath = (ResourcePath)Utf8Marshaler.GetStringFromIntPtr(romInfo.RomPath);
|
|
|
|
|
PatchPath = (ResourcePath)Utf8Marshaler.GetStringFromIntPtr(romInfo.PatchPath);
|
|
|
|
|
Header = romInfo.Header;
|
2019-07-25 22:22:09 -04:00
|
|
|
|
CoprocessorType = romInfo.CoprocessorType;
|
2019-10-14 00:37:10 -04:00
|
|
|
|
Sha1 = Encoding.UTF8.GetString(romInfo.Sha1);
|
2019-03-28 21:20:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetRomName()
|
|
|
|
|
{
|
|
|
|
|
return Path.GetFileNameWithoutExtension(((ResourcePath)RomPath).FileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct SnesCartInformation
|
|
|
|
|
{
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
|
|
|
|
public byte[] MakerCode;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
|
|
|
|
public byte[] GameCode;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)]
|
|
|
|
|
public byte[] Reserved;
|
|
|
|
|
|
|
|
|
|
public byte ExpansionRamSize;
|
|
|
|
|
public byte SpecialVersion;
|
|
|
|
|
public byte CartridgeType;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 21)]
|
|
|
|
|
public byte[] CartName;
|
|
|
|
|
|
|
|
|
|
public byte MapMode;
|
|
|
|
|
public byte RomType;
|
|
|
|
|
public byte RomSize;
|
|
|
|
|
public byte SramSize;
|
|
|
|
|
|
|
|
|
|
public byte DestinationCode;
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
public byte Version;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
|
|
|
|
public byte[] ChecksumComplement;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
|
|
|
|
public byte[] Checksum;
|
|
|
|
|
}
|
2019-07-17 22:08:41 -04:00
|
|
|
|
|
|
|
|
|
public enum CoprocessorType
|
|
|
|
|
{
|
|
|
|
|
None,
|
|
|
|
|
DSP1,
|
|
|
|
|
DSP1B,
|
|
|
|
|
DSP2,
|
|
|
|
|
DSP3,
|
|
|
|
|
DSP4,
|
2019-07-30 22:34:52 -04:00
|
|
|
|
GSU,
|
2019-07-17 22:08:41 -04:00
|
|
|
|
OBC1,
|
|
|
|
|
SA1,
|
2019-07-31 23:04:30 -04:00
|
|
|
|
SDD1,
|
2019-07-17 22:08:41 -04:00
|
|
|
|
RTC,
|
|
|
|
|
Satellaview,
|
|
|
|
|
SPC7110,
|
|
|
|
|
ST010,
|
|
|
|
|
ST011,
|
|
|
|
|
ST018,
|
|
|
|
|
CX4
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-17 22:14:13 -04:00
|
|
|
|
public struct MissingFirmwareMessage
|
2019-07-17 22:08:41 -04:00
|
|
|
|
{
|
|
|
|
|
public IntPtr Filename;
|
2019-07-17 22:14:13 -04:00
|
|
|
|
public CoprocessorType FirmwareType;
|
2019-07-17 22:08:41 -04:00
|
|
|
|
public UInt32 Size;
|
|
|
|
|
}
|
2019-02-12 22:13:09 -05:00
|
|
|
|
}
|