BizHawk/BizHawk.Emulation.Cores/Consoles/WonderSwan/BizSwan.cs

231 lines
6.6 KiB
C#
Raw Normal View History

2014-05-30 05:09:54 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
2014-05-31 16:12:59 +00:00
using BizHawk.Emulation.Common;
2014-05-30 05:09:54 +00:00
namespace BizHawk.Emulation.Cores.WonderSwan
{
public static class BizSwan
{
const CallingConvention cc = CallingConvention.Cdecl;
const string dd = "bizswan.dll";
2014-05-30 16:50:58 +00:00
/// <summary>
/// create new instance
/// </summary>
/// <returns></returns>
2014-05-30 05:09:54 +00:00
[DllImport(dd, CallingConvention = cc)]
public static extern IntPtr bizswan_new();
2014-05-30 16:50:58 +00:00
/// <summary>
/// delete instance, freeing all associated memory
/// </summary>
/// <param name="core"></param>
2014-05-30 05:09:54 +00:00
[DllImport(dd, CallingConvention = cc)]
public static extern void bizswan_delete(IntPtr core);
2014-05-30 16:50:58 +00:00
/// <summary>
/// hard reset
/// </summary>
/// <param name="core"></param>
2014-05-30 05:09:54 +00:00
[DllImport(dd, CallingConvention = cc)]
public static extern void bizswan_reset(IntPtr core);
2014-05-30 16:50:58 +00:00
/// <summary>
/// frame advance
/// </summary>
/// <param name="core"></param>
/// <param name="buttons">input to use on this frame</param>
/// <param name="novideo">true to skip all video rendering</param>
/// <param name="surface">uint32 video output buffer</param>
/// <param name="soundbuff">int16 sound output buffer</param>
/// <param name="soundbuffsize">[In] max hold size of soundbuff [Out] number of samples actually deposited</param>
/// <returns>true if lagged</returns>
2014-05-30 05:09:54 +00:00
[DllImport(dd, CallingConvention = cc)]
public static extern bool bizswan_advance(IntPtr core, Buttons buttons, bool novideo, int[] surface, short[] soundbuff, ref int soundbuffsize);
2014-05-30 05:09:54 +00:00
2014-05-30 16:50:58 +00:00
/// <summary>
/// load rom
/// </summary>
/// <param name="core"></param>
/// <param name="data"></param>
/// <param name="length"></param>
/// <param name="settings"></param>
/// <param name="IsRotated">(out) true if screen is rotated left 90</param>
2014-05-30 16:50:58 +00:00
/// <returns></returns>
2014-05-30 05:09:54 +00:00
[DllImport(dd, CallingConvention = cc)]
public static extern bool bizswan_load(IntPtr core, byte[] data, int length, [In] ref SyncSettings settings, ref bool IsRotated);
2014-05-30 05:09:54 +00:00
2014-05-30 16:50:58 +00:00
/// <summary>
/// get size of saveram
/// </summary>
/// <param name="core"></param>
/// <returns></returns>
[DllImport(dd, CallingConvention = cc)]
public static extern int bizswan_saveramsize(IntPtr core);
/// <summary>
/// load saveram into core
/// </summary>
/// <param name="core"></param>
/// <param name="data"></param>
/// <param name="size">should be same as bizswan_saveramsize()</param>
/// <returns>false if size mismatch</returns>
[DllImport(dd, CallingConvention = cc)]
public static extern bool bizswan_saveramload(IntPtr core, byte[] data, int size);
/// <summary>
/// save saveram from core
/// </summary>
/// <param name="core"></param>
/// <param name="data"></param>
/// <param name="maxsize">should be same as bizswan_saveramsize()</param>
/// <returns>false if size mismatch</returns>
[DllImport(dd, CallingConvention = cc)]
public static extern bool bizswan_saveramsave(IntPtr core, byte[] data, int maxsize);
/// <summary>
/// put non-sync settings, can be done at any time
/// </summary>
/// <param name="core"></param>
/// <param name="settings"></param>
[DllImport(dd, CallingConvention = cc)]
public static extern void bizswan_putsettings(IntPtr core, [In] ref Settings settings);
/// <summary>
/// get a memory area
/// </summary>
/// <param name="core"></param>
/// <param name="index">start at 0, increment until return is false</param>
/// <param name="name"></param>
/// <param name="size"></param>
/// <param name="data"></param>
/// <returns></returns>
[DllImport(dd, CallingConvention = cc)]
public static extern bool bizswan_getmemoryarea(IntPtr core, int index, out IntPtr name, out int size, out IntPtr data);
2014-05-31 05:57:18 +00:00
[DllImport(dd, CallingConvention = cc)]
public static extern int bizswan_binstatesize(IntPtr core);
[DllImport(dd, CallingConvention = cc)]
public static extern bool bizswan_binstatesave(IntPtr core, byte[] data, int length);
[DllImport(dd, CallingConvention = cc)]
public static extern bool bizswan_binstateload(IntPtr core, byte[] data, int length);
[DllImport(dd, CallingConvention = cc)]
public static extern void bizswan_txtstatesave(IntPtr core, [In]ref TextStateFPtrs ff);
[DllImport(dd, CallingConvention = cc)]
public static extern void bizswan_txtstateload(IntPtr core, [In]ref TextStateFPtrs ff);
/// <summary>
/// return a CPU register
/// </summary>
/// <param name="core"></param>
/// <param name="which"></param>
/// <returns></returns>
[DllImport(dd, CallingConvention = cc)]
public static extern uint bizswan_getnecreg(IntPtr core, NecRegs which);
public const NecRegs NecRegsMin = NecRegs.PC;
public const NecRegs NecRegsMax = NecRegs.DS0;
public enum NecRegs : int
{
PC = 1,
AW = 2,
CW = 3,
DW = 4,
BW = 5,
SP = 6,
BP = 7,
IX = 8,
IY = 9,
FLAGS = 10,
DS1 = 11,
PS = 12,
SS = 13,
DS0 = 14
};
2014-05-30 05:09:54 +00:00
[Flags]
public enum Buttons : ushort
{
UpX = 0x0001,
2014-05-30 18:33:28 +00:00
RightX = 0x0002,
DownX = 0x0004,
LeftX = 0x0008,
2014-05-30 05:09:54 +00:00
UpY = 0x0010,
2014-05-30 18:33:28 +00:00
RightY = 0x0020,
DownY = 0x0040,
LeftY = 0x0080,
2014-05-30 05:09:54 +00:00
Start = 0x0100,
A = 0x0200,
B = 0x0400,
2014-05-30 05:09:54 +00:00
}
public enum Language : uint
2014-05-30 05:09:54 +00:00
{
Japanese = 0,
English = 1
}
public enum Bloodtype : uint
2014-05-30 05:09:54 +00:00
{
A = 1,
B = 2,
O = 3,
AB = 4
}
public enum Gender : uint
2014-05-30 05:09:54 +00:00
{
Male = 1,
Female = 2
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
2014-05-30 18:10:39 +00:00
public struct SyncSettings
2014-05-30 05:09:54 +00:00
{
public ulong initialtime; // inital time in unix format; only used when userealtime = false
public uint byear;
public uint bmonth;
public uint bday;
[MarshalAs(UnmanagedType.Bool)]
public bool color; // true for color system
[MarshalAs(UnmanagedType.Bool)]
public bool userealtime; // true for use real real RTC instead of emulation pegged time
2014-05-30 05:09:54 +00:00
public Language language;
public Gender sex;
public Bloodtype blood;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
public byte[] name;
2014-05-30 05:09:54 +00:00
public void SetName(string newname)
{
byte[] data = Encoding.ASCII.GetBytes(newname);
name = new byte[17];
Buffer.BlockCopy(data, 0, name, 0, Math.Min(data.Length, name.Length));
}
}
[Flags]
public enum LayerFlags : uint
{
BG = 1,
FG = 2,
Sprite = 4
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct Settings
{
public LayerFlags LayerMask; // 1 = show
}
2014-05-30 05:09:54 +00:00
}
}