using System; using System.Runtime.InteropServices; internal static class Nova64 { private const string LibName = "nova64_core"; /* ========================================================================== */ /* Enums */ /* ========================================================================== */ [Flags] public enum Nova64Transform : uint { None = 0, FlipH = 1 << 0, FlipV = 1 << 1, Rot90 = 1 << 2, Rot180 = 1 << 3, Rot270 = 1 << 4 } /* ========================================================================== */ /* PPU Delegates */ /* ========================================================================== */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void PpuFillRectDelegate(IntPtr dst, uint dstStride, int x, int y, int w, int h, ushort color); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void PpuBlitDelegate(IntPtr src, uint srcStride, IntPtr dst, uint dstStride, int srcX, int srcY, int dstX, int dstY, int w, int h); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void PpuBlitColorKeyDelegate(IntPtr src, uint srcStride, IntPtr dst, uint dstStride, int srcX, int srcY, int dstX, int dstY, int w, int h, ushort keyColor); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void PpuBlendDelegate(IntPtr src, uint srcStride, IntPtr dst, uint dstStride, int srcX, int srcY, int dstX, int dstY, int w, int h, byte globalAlpha); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void PpuBlitTransformDelegate(IntPtr src, uint srcStride, IntPtr dst, uint dstStride, int srcX, int srcY, int dstX, int dstY, int w, int h, Nova64Transform transform); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void PpuBlitScaleDelegate(IntPtr src, uint srcStride, int srcW, int srcH, IntPtr dst, uint dstStride, int dstX, int dstY, int dstW, int dstH); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void PpuWaitIdleDelegate(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public delegate bool PpuIsBusyDelegate(); /* ========================================================================== */ /* PPU Interface Struct */ /* ========================================================================== */ [StructLayout(LayoutKind.Sequential)] public struct Nova64PpuInterface { public IntPtr fill_rect; public IntPtr blit; public IntPtr blit_colorkey; public IntPtr blend; public IntPtr blit_transform; public IntPtr blit_scale; public IntPtr wait_idle; public IntPtr is_busy; } /* ========================================================================== */ /* I/O Delegates */ /* ========================================================================== */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void DisplayFlushDelegate(IntPtr buffer, ushort width, ushort height); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void AudioOutputDelegate(IntPtr samples, uint count); [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public delegate int SdReadFileDelegate(uint slotIdx, string filePath, IntPtr destinationBuffer, uint destinationLength); [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public delegate int SdGetFileSizeDelegate(uint slotIdx, string filePath); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void CartridgeStatusDelegate(uint slotIdx, [MarshalAs(UnmanagedType.I1)] bool isInserted); [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public delegate void LogMessageDelegate([MarshalAs(UnmanagedType.LPStr)] string message); /* ========================================================================== */ /* I/O Interface Struct */ /* ========================================================================== */ [StructLayout(LayoutKind.Sequential)] public struct Nova64IoInterface { public IntPtr audio_output; public IntPtr sd_read_file; public IntPtr sd_get_file_size; public IntPtr cartridge_status; public IntPtr log_message; } /* ========================================================================== */ /* Native Imports */ /* ========================================================================== */ [DllImport(LibName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool nova64_init(IntPtr io_interface, IntPtr ppu_interface); [DllImport(LibName, CallingConvention = CallingConvention.Cdecl)] public static extern int nova64_main(); [DllImport(LibName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool nova64_shutdown(); [DllImport(LibName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool nova64_is_finalized(); [DllImport(LibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint nova64_get_version(); }