using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace BizHawk.Emulation.Cores.Sega.Saturn
{
public static class LibYabause
{
///
/// A,B,C,Start,DPad
///
public enum Buttons1 : byte
{
B = 0x01,
C = 0x02,
A = 0x04,
S = 0x08,
U = 0x10,
D = 0x20,
L = 0x40,
R = 0x80
}
///
/// X,Y,Z,Shoulders
///
public enum Buttons2 : byte
{
L = 0x08,
Z = 0x10,
Y = 0x20,
X = 0x40,
R = 0x80
}
///
///
///
/// player1
/// player1
/// player2
/// player2
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libyabause_setpads(Buttons1 p11, Buttons2 p12, Buttons1 p21, Buttons2 p22);
///
/// set video buffer
///
/// 32 bit color, should persist over time. must hold at least 704*512px in software mode, or (704*n*512*n)px
/// in hardware mode with native factor size, or w*hpx in gl mode with explicit size
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libyabause_setvidbuff(IntPtr buff);
///
///
///
/// persistent location of s16 interleaved
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libyabause_setsndbuff(IntPtr buff);
///
/// soft reset, or something like that
///
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libyabause_softreset();
///
/// hard reset, or something like that
///
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libyabause_hardreset();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void InputCallback();
///
/// set a fcn to call every time input is read
///
/// execxutes right before the input read. null to clear
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libyabause_setinputcallback(InputCallback cb);
///
///
///
///
/// success
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool libyabause_loadstate(string fn);
///
///
///
///
/// success
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool libyabause_savestate(string fn);
///
///
///
/// width of framebuffer
/// height of framebuffer
/// number of sample pairs produced
/// true if lagged
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool libyabause_frameadvance(out int w, out int h, out int nsamp);
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libyabause_deinit();
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool libyabause_savesaveram(string fn);
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool libyabause_loadsaveram(string fn);
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libyabause_clearsaveram();
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool libyabause_saveramodified();
public struct NativeMemoryDomain
{
public IntPtr data;
public string name;
public int length;
}
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr libyabause_getmemoryareas();
public static IEnumerable libyabause_getmemoryareas_ex()
{
var ret = new List();
IntPtr start = libyabause_getmemoryareas();
while (true)
{
var nmd = (NativeMemoryDomain)Marshal.PtrToStructure(start, typeof(NativeMemoryDomain));
if (nmd.data == IntPtr.Zero || nmd.name == null)
return ret.AsReadOnly();
ret.Add(nmd);
start += Marshal.SizeOf(typeof(NativeMemoryDomain));
}
}
///
/// set the overall resolution. only works in gl mode and when nativefactor = 0
///
/// width
/// height
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libyabause_glresize(int w, int h);
///
/// cause the overall resolution to automatically switch to a multiple of the original console resolution, as the original console resolution changes.
/// only applies in gl mode.
///
/// factor, 1-4, 0 to disable.
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void libyabause_glsetnativefactor(int n);
public enum CartType : int
{
NONE = 0,
DRAM8MBIT = 6,
DRAM32MBIT = 7
}
///
///
///
/// cd interface. struct need not persist after call, but the function pointers better
/// path to bios, pass null to use built in bios emulation
/// true for opengl
/// if true, skip bios opening
/// if true, sync RTC to actual emulated time; if false, use real real time
/// if non-zero, initial emulation time in unix format
///
[DllImport("libyabause.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool libyabause_init(ref CDInterface intf, string biosfn, bool usegl, CartType carttype, bool quickload, bool clocksync, int clockbase);
public struct CDInterface
{
public int DontTouch;
public IntPtr DontTouch2;
///
/// init cd functions
///
///
/// 0 on success, -1 on failure
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int Init(string unused);
public Init InitFunc;
///
/// deinit cd functions
///
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void DeInit();
public DeInit DeInitFunc;
///
/// 0 = cd present, spinning
/// 1 = cd present, not spinning
/// 2 = no cd
/// 3 = tray open
///
///
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int GetStatus();
public GetStatus GetStatusFunc;
///
/// read all TOC entries
///
/// place to copy to
/// number of bytes written. should be 408
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int ReadTOC(IntPtr dest);
public ReadTOC ReadTOCFunc;
///
/// read a sector, should be 2352 bytes
///
///
///
///
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int ReadSectorFAD(int FAD, IntPtr dest);
public ReadSectorFAD ReadSectorFADFunc;
///
/// hint the next sector, for async loading
///
///
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ReadAheadFAD(int FAD);
public ReadAheadFAD ReadAheadFADFunc;
}
}
}