saturn: fix saveram problem

This commit is contained in:
goyuken 2013-05-09 00:47:16 +00:00
parent 7becee2284
commit aa73071870
1 changed files with 53 additions and 22 deletions

View File

@ -26,6 +26,7 @@ namespace BizHawk.Emulation.Consoles.Sega.Saturn
GCHandle SoundHandle; GCHandle SoundHandle;
bool Disposed = false; bool Disposed = false;
byte[] DisposedSaveRam;
LibYabause.CDInterface.Init InitH; LibYabause.CDInterface.Init InitH;
LibYabause.CDInterface.DeInit DeInitH; LibYabause.CDInterface.DeInit DeInitH;
@ -183,40 +184,68 @@ namespace BizHawk.Emulation.Consoles.Sega.Saturn
public byte[] ReadSaveRam() public byte[] ReadSaveRam()
{ {
var ms = new MemoryStream(); if (Disposed)
var fp = new FilePiping(); {
fp.Get(ms); return DisposedSaveRam ?? new byte[0];
bool success = LibYabause.libyabause_savesaveram(fp.GetPipeNameNative()); }
var e = fp.GetResults(); else
if (e != null) {
throw e; var ms = new MemoryStream();
if (!success) var fp = new FilePiping();
throw new Exception("libyabause_savesaveram() failed!"); fp.Get(ms);
var ret = ms.ToArray(); bool success = LibYabause.libyabause_savesaveram(fp.GetPipeNameNative());
ms.Dispose(); var e = fp.GetResults();
return ret; if (e != null)
throw e;
if (!success)
throw new Exception("libyabause_savesaveram() failed!");
var ret = ms.ToArray();
ms.Dispose();
return ret;
}
} }
public void StoreSaveRam(byte[] data) public void StoreSaveRam(byte[] data)
{ {
var fp = new FilePiping(); if (Disposed)
fp.Offer(data); {
bool success = LibYabause.libyabause_loadsaveram(fp.GetPipeNameNative()); throw new Exception("It's a bit late for that");
var e = fp.GetResults(); }
if (e != null) else
throw e; {
if (!success) var fp = new FilePiping();
throw new Exception("libyabause_loadsaveram() failed!"); fp.Offer(data);
bool success = LibYabause.libyabause_loadsaveram(fp.GetPipeNameNative());
var e = fp.GetResults();
if (e != null)
throw e;
if (!success)
throw new Exception("libyabause_loadsaveram() failed!");
}
} }
public void ClearSaveRam() public void ClearSaveRam()
{ {
LibYabause.libyabause_clearsaveram(); if (Disposed)
{
throw new Exception("It's a bit late for that");
}
else
{
LibYabause.libyabause_clearsaveram();
}
} }
public bool SaveRamModified public bool SaveRamModified
{ {
get { return LibYabause.libyabause_saveramodified(); } get
{
if (Disposed)
return DisposedSaveRam != null;
else
return LibYabause.libyabause_saveramodified();
}
set { throw new InvalidOperationException("No you may not!"); } set { throw new InvalidOperationException("No you may not!"); }
} }
@ -407,6 +436,8 @@ namespace BizHawk.Emulation.Consoles.Sega.Saturn
{ {
if (!Disposed) if (!Disposed)
{ {
if (SaveRamModified)
DisposedSaveRam = ReadSaveRam();
LibYabause.libyabause_setvidbuff(IntPtr.Zero); LibYabause.libyabause_setvidbuff(IntPtr.Zero);
LibYabause.libyabause_setsndbuff(IntPtr.Zero); LibYabause.libyabause_setsndbuff(IntPtr.Zero);
LibYabause.libyabause_deinit(); LibYabause.libyabause_deinit();