libretro - fix saveram

This commit is contained in:
zeromus 2017-04-18 03:17:11 -05:00
parent 5731b24c7c
commit 9bea9875a8
7 changed files with 95 additions and 30 deletions

View File

@ -1193,6 +1193,7 @@
<Compile Include="Libretro\LibretroApi_BRK.cs" />
<Compile Include="Libretro\LibretroApi_Delegates.cs" />
<Compile Include="Libretro\LibretroApi_Enums.cs" />
<Compile Include="Libretro\LibretroApi_QUERY.cs" />
<Compile Include="Libretro\LibretroApi_SIG.cs" />
<Compile Include="Libretro\LibretroApi_Structs.cs" />
<Compile Include="Libretro\LibretroCore.cs" />

View File

@ -13,6 +13,7 @@ namespace BizHawk.Emulation.Cores.Libretro
Resume,
QUERY_FIRST,
QUERY_GetMemory,
QUERY_LAST,
CMD_FIRST,
@ -32,6 +33,16 @@ namespace BizHawk.Emulation.Cores.Libretro
BRK_InputState,
};
public enum RETRO_MEMORY
{
SAVE_RAM = 0,
RTC = 1,
SYSTEM_RAM = 2,
VIDEO_RAM = 3,
};
public enum RETRO_DEVICE
{
NONE = 0,

View File

@ -0,0 +1,22 @@
using System;
using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Libretro
{
unsafe partial class LibretroApi
{
bool Handle_SIG(eMessage msg)
{
switch (msg)
{
default:
return false;
} //switch(msg)
Message(eMessage.Resume);
return true;
}
}
}

View File

@ -6,17 +6,11 @@ namespace BizHawk.Emulation.Cores.Libretro
{
unsafe partial class LibretroApi
{
bool Handle_SIG(eMessage msg)
public Tuple<IntPtr,int> QUERY_GetMemory(RETRO_MEMORY mem)
{
switch (msg)
{
default:
return false;
} //switch(msg)
Message(eMessage.Resume);
return true;
comm->value = (uint)mem;
Message(eMessage.QUERY_GetMemory);
return Tuple.Create(new IntPtr(comm->buf[(int)BufId.Param0]), comm->buf_size[(int)BufId.Param0]);
}
}
}

View File

@ -26,7 +26,7 @@ namespace BizHawk.Emulation.Cores.Libretro
public LibretroCore(CoreComm nextComm, string corePath)
{
//TODO: codepath just for inrospection (lighter weight; no speex, no controls, etc.)
//TODO: codepath just for introspection (lighter weight; no speex, no controls, etc.)
ServiceProvider = new BasicServiceProvider(this);
_SyncSettings = new SyncSettings();
@ -45,12 +45,17 @@ namespace BizHawk.Emulation.Cores.Libretro
//I dont even know for sure what paths I should use until... (what?)
//not sure about each of these.. but we'll be doing things different than retroarch.
//i think this may play better with our model [although we might could use a different save directory]
api.CopyAscii(LibretroApi.BufId.SystemDirectory, Path.GetDirectoryName(corePath));
api.CopyAscii(LibretroApi.BufId.SaveDirectory, Path.GetDirectoryName(corePath));
api.CopyAscii(LibretroApi.BufId.CoreDirectory, Path.GetDirectoryName(corePath));
api.CopyAscii(LibretroApi.BufId.CoreAssetsDirectory, Path.GetDirectoryName(corePath));
//not sure about each of these.. but we may be doing things different than retroarch.
//I wish I could initialize these with placeholders during a separate introspection codepath..
string SystemDirectory = CoreComm.CoreFileProvider.GetRetroSystemPath();
string SaveDirectory = CoreComm.CoreFileProvider.GetRetroSaveRAMDirectory();
string CoreDirectory = Path.GetDirectoryName(corePath);
string CoreAssetsDirectory = Path.GetDirectoryName(corePath);
api.CopyAscii(LibretroApi.BufId.SystemDirectory, SystemDirectory);
api.CopyAscii(LibretroApi.BufId.SaveDirectory, SaveDirectory);
api.CopyAscii(LibretroApi.BufId.CoreDirectory, CoreDirectory);
api.CopyAscii(LibretroApi.BufId.CoreAssetsDirectory, CoreAssetsDirectory);
api.CMD_SetEnvironment();
@ -244,27 +249,52 @@ namespace BizHawk.Emulation.Cores.Libretro
public bool DeterministicEmulation { get { return false; } }
public string BoardName { get; private set; }
public bool SaveRamModified
{
get
{
//TODO
return false;
}
}
#region ISaveRam
//TODO - terrible things will happen if this changes at runtime
byte[] saverambuff = new byte[0];
public byte[] CloneSaveRam()
{
//TODO
return new byte[] { };
}
var mem = api.QUERY_GetMemory(LibretroApi.RETRO_MEMORY.SAVE_RAM);
var buf = new byte[mem.Item2];
Marshal.Copy(mem.Item1, buf, 0, mem.Item2);
return buf;
}
public void StoreSaveRam(byte[] data)
{
//TODO
var mem = api.QUERY_GetMemory(LibretroApi.RETRO_MEMORY.SAVE_RAM);
//bail if the size is 0
if (mem.Item2 == 0)
return;
Marshal.Copy(data, 0, mem.Item1, mem.Item2);
}
public bool SaveRamModified
{
[FeatureNotImplemented]
get
{
//if we dont have saveram, it isnt modified. otherwise, assume it is
var mem = api.QUERY_GetMemory(LibretroApi.RETRO_MEMORY.SAVE_RAM);
//bail if the size is 0
if (mem.Item2 == 0)
return false;
return true;
}
[FeatureNotImplemented]
set { throw new NotImplementedException(); }
}
#endregion
public void ResetCounters()
{
timeFrameCounter = 0;

View File

@ -78,6 +78,7 @@ enum eMessage : s32
Resume,
QUERY_FIRST,
QUERY_GetMemory,
QUERY_LAST,
CMD_FIRST,
@ -740,6 +741,12 @@ void cmd_SetEnvironment()
comm.funs.retro_set_environment(retro_environment);
}
void query_GetMemory()
{
comm.buf_size[BufId::Param0] = comm.funs.retro_get_memory_size(comm.value);
comm.buf[BufId::Param0] = comm.funs.retro_get_memory_data(comm.value);
}
const Action kHandlers_CMD[] = {
cmd_SetEnvironment,
cmd_LoadNoGame,
@ -753,7 +760,7 @@ const Action kHandlers_CMD[] = {
};
const Action kHandlers_QUERY[] = {
nullptr
query_GetMemory,
};
//------------------------------------------------

Binary file not shown.