2013-04-30 21:28:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2013-05-02 23:35:12 +00:00
|
|
|
|
using System.IO;
|
2014-05-28 17:31:22 +00:00
|
|
|
|
using System.ComponentModel;
|
2013-04-30 21:28:35 +00:00
|
|
|
|
|
2013-10-27 22:07:40 +00:00
|
|
|
|
using BizHawk.Common;
|
2014-07-03 18:54:53 +00:00
|
|
|
|
using BizHawk.Common.BufferExtensions;
|
2013-11-04 01:39:19 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
2013-11-03 23:45:44 +00:00
|
|
|
|
using BizHawk.Emulation.DiscSystem;
|
2013-10-27 22:07:40 +00:00
|
|
|
|
|
2014-05-28 17:31:22 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2013-11-13 23:36:21 +00:00
|
|
|
|
namespace BizHawk.Emulation.Cores.Sega.Saturn
|
2013-04-30 21:28:35 +00:00
|
|
|
|
{
|
2014-04-25 01:19:57 +00:00
|
|
|
|
[CoreAttributes(
|
|
|
|
|
"Yabause",
|
2014-06-01 01:57:22 +00:00
|
|
|
|
"",
|
2014-04-25 01:19:57 +00:00
|
|
|
|
isPorted: true,
|
2014-06-01 01:57:22 +00:00
|
|
|
|
isReleased: true,
|
|
|
|
|
portedVersion: "9.12",
|
2015-03-03 00:23:50 +00:00
|
|
|
|
portedUrl: "http://yabause.org",
|
|
|
|
|
singleInstance: true
|
2014-04-25 01:19:57 +00:00
|
|
|
|
)]
|
2016-12-11 17:14:42 +00:00
|
|
|
|
public partial class Yabause : IEmulator, IVideoProvider, ISoundProvider, ISaveRam, IStatable, IInputPollable,
|
2014-12-12 01:49:54 +00:00
|
|
|
|
ISettable<object, Yabause.SaturnSyncSettings>, IDriveLight
|
2013-04-30 21:28:35 +00:00
|
|
|
|
{
|
|
|
|
|
public static ControllerDefinition SaturnController = new ControllerDefinition
|
|
|
|
|
{
|
|
|
|
|
Name = "Saturn Controller",
|
|
|
|
|
BoolButtons =
|
2013-05-01 02:53:53 +00:00
|
|
|
|
{
|
|
|
|
|
"Power", "Reset",
|
2014-06-29 13:20:30 +00:00
|
|
|
|
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Start", "P1 A", "P1 B", "P1 C", "P1 X", "P1 Y", "P1 Z", "P1 L", "P1 R",
|
|
|
|
|
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Start", "P2 A", "P2 B", "P2 C", "P2 X", "P2 Y", "P2 Z", "P2 L", "P2 R",
|
2013-04-30 21:28:35 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static Yabause AttachedCore = null;
|
|
|
|
|
GCHandle VideoHandle;
|
2013-11-03 23:45:44 +00:00
|
|
|
|
Disc CD;
|
2015-07-03 09:11:07 +00:00
|
|
|
|
DiscSectorReader DiscSectorReader;
|
2013-05-01 01:46:20 +00:00
|
|
|
|
GCHandle SoundHandle;
|
|
|
|
|
|
|
|
|
|
bool Disposed = false;
|
2013-05-09 00:47:16 +00:00
|
|
|
|
byte[] DisposedSaveRam;
|
2013-04-30 21:28:35 +00:00
|
|
|
|
|
2013-05-01 00:27:36 +00:00
|
|
|
|
LibYabause.CDInterface.Init InitH;
|
|
|
|
|
LibYabause.CDInterface.DeInit DeInitH;
|
|
|
|
|
LibYabause.CDInterface.GetStatus GetStatusH;
|
|
|
|
|
LibYabause.CDInterface.ReadTOC ReadTOCH;
|
|
|
|
|
LibYabause.CDInterface.ReadSectorFAD ReadSectorFADH;
|
|
|
|
|
LibYabause.CDInterface.ReadAheadFAD ReadAheadFADH;
|
|
|
|
|
|
2013-11-17 02:10:38 +00:00
|
|
|
|
LibYabause.InputCallback InputCallbackH;
|
|
|
|
|
|
2015-01-13 19:55:36 +00:00
|
|
|
|
public Yabause(CoreComm CoreComm, DiscSystem.Disc CD, object syncSettings)
|
2013-04-30 21:28:35 +00:00
|
|
|
|
{
|
2014-12-04 03:38:30 +00:00
|
|
|
|
ServiceProvider = new BasicServiceProvider(this);
|
2013-12-10 17:58:12 +00:00
|
|
|
|
byte[] bios = CoreComm.CoreFileProvider.GetFirmware("SAT", "J", true, "Saturn BIOS is required.");
|
2015-07-03 09:11:07 +00:00
|
|
|
|
CoreComm.RomStatusDetails = string.Format("Disk partial hash:{0}", new DiscSystem.DiscHasher(CD).OldHash());
|
2013-04-30 21:28:35 +00:00
|
|
|
|
this.CoreComm = CoreComm;
|
2013-05-01 00:27:36 +00:00
|
|
|
|
this.CD = CD;
|
2015-07-03 09:11:07 +00:00
|
|
|
|
DiscSectorReader = new DiscSystem.DiscSectorReader(CD);
|
2013-12-27 03:02:28 +00:00
|
|
|
|
|
2015-01-13 19:55:36 +00:00
|
|
|
|
SyncSettings = (SaturnSyncSettings)syncSettings ?? new SaturnSyncSettings();
|
2013-12-27 03:02:28 +00:00
|
|
|
|
|
2014-06-08 23:30:34 +00:00
|
|
|
|
if (this.SyncSettings.UseGL && glContext == null)
|
|
|
|
|
{
|
2016-02-21 23:19:20 +00:00
|
|
|
|
glContext = CoreComm.RequestGLContext(2,0,false);
|
2014-06-08 23:30:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 16:29:51 +00:00
|
|
|
|
ResetCounters();
|
2014-06-08 23:30:34 +00:00
|
|
|
|
|
2014-06-09 19:19:12 +00:00
|
|
|
|
ActivateGL();
|
2013-12-27 03:02:28 +00:00
|
|
|
|
Init(bios);
|
2013-11-17 02:10:38 +00:00
|
|
|
|
|
2014-12-04 00:43:12 +00:00
|
|
|
|
InputCallbackH = new LibYabause.InputCallback(() => InputCallbacks.Call());
|
2013-11-17 02:10:38 +00:00
|
|
|
|
LibYabause.libyabause_setinputcallback(InputCallbackH);
|
2016-08-23 21:04:44 +00:00
|
|
|
|
ConnectTracer();
|
2014-12-12 01:49:54 +00:00
|
|
|
|
DriveLightEnabled = true;
|
2014-06-08 23:30:34 +00:00
|
|
|
|
|
2014-06-09 19:19:12 +00:00
|
|
|
|
DeactivateGL();
|
2013-04-30 21:28:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 03:38:30 +00:00
|
|
|
|
public IEmulatorServiceProvider ServiceProvider { get; private set; }
|
|
|
|
|
|
2016-02-22 06:23:20 +00:00
|
|
|
|
object glContext;
|
2014-06-08 23:30:34 +00:00
|
|
|
|
|
2014-06-09 19:19:12 +00:00
|
|
|
|
void ActivateGL()
|
|
|
|
|
{
|
|
|
|
|
//if (!SyncSettings.UseGL) return; //not safe
|
|
|
|
|
if (glContext == null) return;
|
|
|
|
|
CoreComm.ActivateGLContext(glContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DeactivateGL()
|
|
|
|
|
{
|
|
|
|
|
//if (!SyncSettings.UseGL) return; //not safe
|
|
|
|
|
if (glContext == null) return;
|
|
|
|
|
CoreComm.DeactivateGLContext();
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-27 03:02:28 +00:00
|
|
|
|
void Init(byte[] bios)
|
2013-04-30 21:28:35 +00:00
|
|
|
|
{
|
2013-12-27 03:02:28 +00:00
|
|
|
|
bool GL = SyncSettings.UseGL;
|
|
|
|
|
|
2013-04-30 21:28:35 +00:00
|
|
|
|
if (AttachedCore != null)
|
|
|
|
|
{
|
|
|
|
|
AttachedCore.Dispose();
|
|
|
|
|
AttachedCore = null;
|
|
|
|
|
}
|
|
|
|
|
VideoHandle = GCHandle.Alloc(VideoBuffer, GCHandleType.Pinned);
|
2013-05-01 01:46:20 +00:00
|
|
|
|
SoundHandle = GCHandle.Alloc(SoundBuffer, GCHandleType.Pinned);
|
2013-04-30 21:28:35 +00:00
|
|
|
|
|
2013-05-01 00:27:36 +00:00
|
|
|
|
LibYabause.CDInterface CDInt = new LibYabause.CDInterface();
|
|
|
|
|
CDInt.InitFunc = InitH = new LibYabause.CDInterface.Init(CD_Init);
|
|
|
|
|
CDInt.DeInitFunc = DeInitH = new LibYabause.CDInterface.DeInit(CD_DeInit);
|
|
|
|
|
CDInt.GetStatusFunc = GetStatusH = new LibYabause.CDInterface.GetStatus(CD_GetStatus);
|
|
|
|
|
CDInt.ReadTOCFunc = ReadTOCH = new LibYabause.CDInterface.ReadTOC(CD_ReadTOC);
|
|
|
|
|
CDInt.ReadSectorFADFunc = ReadSectorFADH = new LibYabause.CDInterface.ReadSectorFAD(CD_ReadSectorFAD);
|
|
|
|
|
CDInt.ReadAheadFADFunc = ReadAheadFADH = new LibYabause.CDInterface.ReadAheadFAD(CD_ReadAheadFAD);
|
|
|
|
|
|
2013-05-02 20:47:56 +00:00
|
|
|
|
var fp = new FilePiping();
|
|
|
|
|
string BiosPipe = fp.GetPipeNameNative();
|
|
|
|
|
fp.Offer(bios);
|
|
|
|
|
|
2014-05-28 17:31:22 +00:00
|
|
|
|
int basetime;
|
|
|
|
|
if (SyncSettings.RealTimeRTC)
|
|
|
|
|
basetime = 0;
|
|
|
|
|
else
|
|
|
|
|
basetime = (int)((SyncSettings.RTCInitialTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds);
|
|
|
|
|
|
|
|
|
|
if (!LibYabause.libyabause_init
|
|
|
|
|
(
|
|
|
|
|
ref CDInt,
|
|
|
|
|
BiosPipe,
|
|
|
|
|
GL,
|
|
|
|
|
SyncSettings.CartType,
|
|
|
|
|
SyncSettings.SkipBios,
|
|
|
|
|
!SyncSettings.RealTimeRTC,
|
|
|
|
|
basetime
|
|
|
|
|
))
|
2013-04-30 21:28:35 +00:00
|
|
|
|
throw new Exception("libyabause_init() failed!");
|
|
|
|
|
|
2013-12-11 04:01:33 +00:00
|
|
|
|
fp.Finish();
|
2013-05-02 20:47:56 +00:00
|
|
|
|
|
2013-04-30 21:28:35 +00:00
|
|
|
|
LibYabause.libyabause_setvidbuff(VideoHandle.AddrOfPinnedObject());
|
2013-05-01 01:46:20 +00:00
|
|
|
|
LibYabause.libyabause_setsndbuff(SoundHandle.AddrOfPinnedObject());
|
2013-04-30 21:28:35 +00:00
|
|
|
|
AttachedCore = this;
|
2013-05-01 01:46:20 +00:00
|
|
|
|
|
2013-05-14 03:06:37 +00:00
|
|
|
|
// with or without GL, this is the guaranteed frame -1 size; (unless you do a gl resize)
|
2013-05-01 01:46:20 +00:00
|
|
|
|
BufferWidth = 320;
|
|
|
|
|
BufferHeight = 224;
|
2013-05-07 21:35:55 +00:00
|
|
|
|
|
|
|
|
|
InitMemoryDomains();
|
2013-05-14 03:06:37 +00:00
|
|
|
|
|
|
|
|
|
GLMode = GL;
|
2013-12-27 03:02:28 +00:00
|
|
|
|
// if in GL mode, this will trigger the initial GL resize
|
|
|
|
|
PutSyncSettings(this.SyncSettings);
|
2013-04-30 21:28:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ControllerDefinition ControllerDefinition
|
|
|
|
|
{
|
|
|
|
|
get { return SaturnController; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IController Controller { get; set; }
|
|
|
|
|
|
2013-05-14 03:06:37 +00:00
|
|
|
|
public bool GLMode { get; private set; }
|
|
|
|
|
|
|
|
|
|
public void SetGLRes(int factor, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
if (!GLMode)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (factor < 0) factor = 0;
|
|
|
|
|
if (factor > 4) factor = 4;
|
|
|
|
|
|
|
|
|
|
int maxwidth, maxheight;
|
|
|
|
|
|
|
|
|
|
if (factor == 0)
|
|
|
|
|
{
|
|
|
|
|
maxwidth = width;
|
|
|
|
|
maxheight = height;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
maxwidth = 704 * factor;
|
|
|
|
|
maxheight = 512 * factor;
|
|
|
|
|
}
|
|
|
|
|
if (maxwidth * maxheight > VideoBuffer.Length)
|
|
|
|
|
{
|
|
|
|
|
VideoHandle.Free();
|
|
|
|
|
VideoBuffer = new int[maxwidth * maxheight];
|
|
|
|
|
VideoHandle = GCHandle.Alloc(VideoBuffer, GCHandleType.Pinned);
|
|
|
|
|
LibYabause.libyabause_setvidbuff(VideoHandle.AddrOfPinnedObject());
|
|
|
|
|
}
|
|
|
|
|
LibYabause.libyabause_glsetnativefactor(factor);
|
|
|
|
|
if (factor == 0)
|
|
|
|
|
LibYabause.libyabause_glresize(width, height);
|
|
|
|
|
}
|
2013-12-22 00:44:39 +00:00
|
|
|
|
|
2013-04-30 21:28:35 +00:00
|
|
|
|
public void FrameAdvance(bool render, bool rendersound = true)
|
|
|
|
|
{
|
2013-05-01 01:46:20 +00:00
|
|
|
|
int w, h, nsamp;
|
2013-05-01 02:53:53 +00:00
|
|
|
|
|
2014-06-09 19:19:12 +00:00
|
|
|
|
ActivateGL();
|
2014-06-08 23:30:34 +00:00
|
|
|
|
|
2013-05-01 02:53:53 +00:00
|
|
|
|
LibYabause.Buttons1 p11 = (LibYabause.Buttons1)0xff;
|
|
|
|
|
LibYabause.Buttons2 p12 = (LibYabause.Buttons2)0xff;
|
|
|
|
|
LibYabause.Buttons1 p21 = (LibYabause.Buttons1)0xff;
|
|
|
|
|
LibYabause.Buttons2 p22 = (LibYabause.Buttons2)0xff;
|
|
|
|
|
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 A"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p11 &= ~LibYabause.Buttons1.A;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 B"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p11 &= ~LibYabause.Buttons1.B;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 C"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p11 &= ~LibYabause.Buttons1.C;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 Start"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p11 &= ~LibYabause.Buttons1.S;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 Left"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p11 &= ~LibYabause.Buttons1.L;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 Right"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p11 &= ~LibYabause.Buttons1.R;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 Up"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p11 &= ~LibYabause.Buttons1.U;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 Down"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p11 &= ~LibYabause.Buttons1.D;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 L"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p12 &= ~LibYabause.Buttons2.L;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 R"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p12 &= ~LibYabause.Buttons2.R;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 X"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p12 &= ~LibYabause.Buttons2.X;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 Y"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p12 &= ~LibYabause.Buttons2.Y;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P1 Z"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p12 &= ~LibYabause.Buttons2.Z;
|
|
|
|
|
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 A"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p21 &= ~LibYabause.Buttons1.A;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 B"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p21 &= ~LibYabause.Buttons1.B;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 C"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p21 &= ~LibYabause.Buttons1.C;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 Start"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p21 &= ~LibYabause.Buttons1.S;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 Left"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p21 &= ~LibYabause.Buttons1.L;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 Right"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p21 &= ~LibYabause.Buttons1.R;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 Up"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p21 &= ~LibYabause.Buttons1.U;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 Down"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p21 &= ~LibYabause.Buttons1.D;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 L"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p22 &= ~LibYabause.Buttons2.L;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 R"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p22 &= ~LibYabause.Buttons2.R;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 X"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p22 &= ~LibYabause.Buttons2.X;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 Y"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p22 &= ~LibYabause.Buttons2.Y;
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("P2 Z"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
p22 &= ~LibYabause.Buttons2.Z;
|
|
|
|
|
|
|
|
|
|
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("Reset"))
|
2013-05-01 02:53:53 +00:00
|
|
|
|
LibYabause.libyabause_softreset();
|
2016-12-14 18:42:15 +00:00
|
|
|
|
if (Controller.IsPressed("Power"))
|
2013-05-03 01:32:16 +00:00
|
|
|
|
LibYabause.libyabause_hardreset();
|
2013-05-01 02:53:53 +00:00
|
|
|
|
|
|
|
|
|
LibYabause.libyabause_setpads(p11, p12, p21, p22);
|
|
|
|
|
|
2014-12-12 01:49:54 +00:00
|
|
|
|
DriveLightOn = false;
|
2013-12-30 20:44:38 +00:00
|
|
|
|
|
2016-08-23 21:04:44 +00:00
|
|
|
|
if (Tracer.Enabled)
|
|
|
|
|
LibYabause.libyabause_settracecallback(trace_cb);
|
|
|
|
|
else
|
|
|
|
|
LibYabause.libyabause_settracecallback(null);
|
|
|
|
|
|
2013-05-01 17:22:12 +00:00
|
|
|
|
IsLagFrame = LibYabause.libyabause_frameadvance(out w, out h, out nsamp);
|
2013-04-30 21:28:35 +00:00
|
|
|
|
BufferWidth = w;
|
|
|
|
|
BufferHeight = h;
|
2013-05-01 01:46:20 +00:00
|
|
|
|
SoundNSamp = nsamp;
|
2013-04-30 21:28:35 +00:00
|
|
|
|
Frame++;
|
2013-05-01 17:22:12 +00:00
|
|
|
|
if (IsLagFrame)
|
|
|
|
|
LagCount++;
|
2013-05-01 01:46:20 +00:00
|
|
|
|
//Console.WriteLine(nsamp);
|
2013-05-03 22:12:35 +00:00
|
|
|
|
|
|
|
|
|
//CheckStates();
|
2014-06-08 23:30:34 +00:00
|
|
|
|
|
2014-06-09 19:19:12 +00:00
|
|
|
|
DeactivateGL();
|
2013-04-30 21:28:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-01 17:22:12 +00:00
|
|
|
|
public int Frame { get; private set; }
|
2014-12-04 00:43:12 +00:00
|
|
|
|
|
2013-05-01 17:22:12 +00:00
|
|
|
|
public string SystemId { get { return "SAT"; } }
|
|
|
|
|
public bool DeterministicEmulation { get { return true; } }
|
2013-04-30 21:28:35 +00:00
|
|
|
|
|
2013-08-24 16:54:22 +00:00
|
|
|
|
public string BoardName { get { return null; } }
|
|
|
|
|
|
2013-11-03 16:29:51 +00:00
|
|
|
|
public void ResetCounters()
|
2013-04-30 21:28:35 +00:00
|
|
|
|
{
|
|
|
|
|
Frame = 0;
|
|
|
|
|
LagCount = 0;
|
2013-05-01 17:22:12 +00:00
|
|
|
|
IsLagFrame = false;
|
2013-04-30 21:28:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CoreComm CoreComm { get; private set; }
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2013-05-01 01:46:20 +00:00
|
|
|
|
if (!Disposed)
|
|
|
|
|
{
|
2014-06-09 19:19:12 +00:00
|
|
|
|
ActivateGL();
|
2013-05-09 00:47:16 +00:00
|
|
|
|
if (SaveRamModified)
|
2014-08-13 17:52:13 +00:00
|
|
|
|
DisposedSaveRam = CloneSaveRam();
|
2013-05-01 01:46:20 +00:00
|
|
|
|
LibYabause.libyabause_setvidbuff(IntPtr.Zero);
|
|
|
|
|
LibYabause.libyabause_setsndbuff(IntPtr.Zero);
|
|
|
|
|
LibYabause.libyabause_deinit();
|
|
|
|
|
VideoHandle.Free();
|
|
|
|
|
SoundHandle.Free();
|
2014-12-19 21:53:43 +00:00
|
|
|
|
CD.Dispose();
|
2013-05-01 01:46:20 +00:00
|
|
|
|
Disposed = true;
|
2014-06-09 19:19:12 +00:00
|
|
|
|
DeactivateGL();
|
2016-03-14 00:50:25 +00:00
|
|
|
|
if (glContext != null)
|
|
|
|
|
CoreComm.ReleaseGLContext(glContext);
|
2013-05-01 01:46:20 +00:00
|
|
|
|
}
|
2013-04-30 21:28:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IVideoProvider
|
|
|
|
|
|
|
|
|
|
int[] VideoBuffer = new int[704 * 512];
|
2016-02-22 06:23:20 +00:00
|
|
|
|
int[] TextureIdBuffer = new int[1]; //todo
|
|
|
|
|
public int[] GetVideoBuffer() {
|
|
|
|
|
//doesn't work yet
|
|
|
|
|
//if (SyncSettings.UseGL)
|
|
|
|
|
// return new[] { VideoBuffer[0] };
|
|
|
|
|
//else
|
|
|
|
|
return VideoBuffer;
|
|
|
|
|
}
|
2014-04-30 23:48:37 +00:00
|
|
|
|
public int VirtualWidth { get { return BufferWidth; } }
|
|
|
|
|
public int VirtualHeight { get { return BufferHeight; } }
|
2013-04-30 21:28:35 +00:00
|
|
|
|
public int BufferWidth { get; private set; }
|
|
|
|
|
public int BufferHeight { get; private set; }
|
|
|
|
|
public int BackgroundColor { get { return unchecked((int)0xff000000); } }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ISyncSoundProvider
|
|
|
|
|
|
2016-12-11 17:14:42 +00:00
|
|
|
|
private short[] SoundBuffer = new short[44100 * 2];
|
|
|
|
|
private int SoundNSamp = 0;
|
2013-04-30 21:28:35 +00:00
|
|
|
|
|
2016-12-11 17:14:42 +00:00
|
|
|
|
public void GetSamplesSync(out short[] samples, out int nsamp)
|
2013-04-30 21:28:35 +00:00
|
|
|
|
{
|
2013-05-01 01:46:20 +00:00
|
|
|
|
nsamp = SoundNSamp;
|
2013-04-30 21:28:35 +00:00
|
|
|
|
samples = SoundBuffer;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-03 01:32:16 +00:00
|
|
|
|
public void DiscardSamples() { }
|
2016-12-11 17:14:42 +00:00
|
|
|
|
|
|
|
|
|
public bool CanProvideAsync
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetSyncMode(SyncSoundMode mode)
|
|
|
|
|
{
|
|
|
|
|
if (mode == SyncSoundMode.Async)
|
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException("Async mode is not supported.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SyncSoundMode SyncMode
|
|
|
|
|
{
|
|
|
|
|
get { return SyncSoundMode.Sync; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GetSamplesAsync(short[] samples)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Async mode is not supported.");
|
|
|
|
|
}
|
2013-04-30 21:28:35 +00:00
|
|
|
|
|
2013-05-01 00:27:36 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region CD
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// init cd functions
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="unused"></param>
|
|
|
|
|
/// <returns>0 on success, -1 on failure</returns>
|
|
|
|
|
int CD_Init(string unused)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// deinit cd functions
|
|
|
|
|
/// </summary>
|
|
|
|
|
void CD_DeInit()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 0 = cd present, spinning
|
|
|
|
|
/// 1 = cd present, not spinning
|
|
|
|
|
/// 2 = no cd
|
|
|
|
|
/// 3 = tray open
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
int CD_GetStatus()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// read all TOC entries
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dest">place to copy to</param>
|
|
|
|
|
/// <returns>number of bytes written. should be 408 (99 tracks, 3 specials)</returns>
|
|
|
|
|
int CD_ReadTOC(IntPtr dest)
|
|
|
|
|
{
|
|
|
|
|
// this stuff from yabause's cdbase.c. don't ask me to explain it
|
2015-07-08 03:29:11 +00:00
|
|
|
|
//TODO - we could just get this out of the actual TOC, it's the same thing
|
2013-05-01 00:27:36 +00:00
|
|
|
|
|
|
|
|
|
int[] rTOC = new int[102];
|
2015-07-08 03:29:11 +00:00
|
|
|
|
var ses = CD.Session1;
|
2015-07-18 16:42:05 +00:00
|
|
|
|
int ntrk = ses.InformationTrackCount;
|
2013-05-01 00:27:36 +00:00
|
|
|
|
|
2015-07-18 16:42:05 +00:00
|
|
|
|
for (int i = 0; i < 99; i++)
|
2013-05-01 00:27:36 +00:00
|
|
|
|
{
|
2015-07-18 16:42:05 +00:00
|
|
|
|
int tnum = i + 1;
|
|
|
|
|
if (tnum <= ntrk)
|
2013-05-01 00:27:36 +00:00
|
|
|
|
{
|
2015-07-18 16:42:05 +00:00
|
|
|
|
var trk = ses.Tracks[tnum];
|
2013-05-01 00:27:36 +00:00
|
|
|
|
|
2015-07-03 09:11:07 +00:00
|
|
|
|
uint t = (uint)trk.LBA + 150;
|
|
|
|
|
|
|
|
|
|
if(trk.IsAudio)
|
|
|
|
|
t |= 0x01000000;
|
|
|
|
|
else
|
|
|
|
|
t |= 0x41000000;
|
|
|
|
|
|
2013-05-01 00:27:36 +00:00
|
|
|
|
rTOC[i] = (int)t;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rTOC[i] = unchecked((int)0xffffffff);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rTOC[99] = (int)(rTOC[0] & 0xff000000 | 0x010000);
|
|
|
|
|
rTOC[100] = (int)(rTOC[ntrk - 1] & 0xff000000 | (uint)(ntrk << 16));
|
2015-07-19 04:23:15 +00:00
|
|
|
|
rTOC[101] = (int)(rTOC[ntrk - 1] & 0xff000000 | (uint)(CD.TOC.LeadoutLBA)); //zero 03-jul-2014 - maybe off by 150
|
2015-07-03 09:11:07 +00:00
|
|
|
|
|
2013-05-01 00:27:36 +00:00
|
|
|
|
|
|
|
|
|
Marshal.Copy(rTOC, 0, dest, 102);
|
|
|
|
|
return 408;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// read a sector, should be 2352 bytes
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="FAD"></param>
|
|
|
|
|
/// <param name="dest"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
int CD_ReadSectorFAD(int FAD, IntPtr dest)
|
|
|
|
|
{
|
|
|
|
|
byte[] data = new byte[2352];
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-06-23 18:57:11 +00:00
|
|
|
|
//CD.ReadABA_2352(FAD, data, 0);
|
2015-07-03 09:11:07 +00:00
|
|
|
|
DiscSectorReader.ReadLBA_2352(FAD - 150, data, 0); //zero 21-jun-2015 - did I adapt this right?
|
2013-05-01 00:27:36 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("CD_ReadSectorFAD: Managed Exception:\n" + e.ToString());
|
|
|
|
|
return 0; // failure
|
|
|
|
|
}
|
|
|
|
|
Marshal.Copy(data, 0, dest, 2352);
|
2014-12-12 01:49:54 +00:00
|
|
|
|
DriveLightOn = true;
|
2013-05-01 00:27:36 +00:00
|
|
|
|
return 1; // success
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// hint the next sector, for async loading
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="FAD"></param>
|
|
|
|
|
void CD_ReadAheadFAD(int FAD)
|
|
|
|
|
{
|
|
|
|
|
// ignored for now
|
|
|
|
|
}
|
2013-04-30 21:28:35 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|