teach libretrobridge stuff how to check for changed serialize size

This commit is contained in:
zeromus 2017-06-12 03:14:21 -05:00
parent 6db010e384
commit 64e9a70d26
6 changed files with 20 additions and 1 deletions

View File

@ -150,6 +150,7 @@ namespace BizHawk.Emulation.Cores.Libretro
{
public retro_system_info retro_system_info;
public retro_system_av_info retro_system_av_info;
public uint retro_serialize_size_initial; //size_t :(
public uint retro_serialize_size; //size_t :(
public uint retro_region;
public uint retro_api_version;

View File

@ -58,6 +58,13 @@ namespace BizHawk.Emulation.Cores.Libretro
return true;
}
public uint CMD_UpdateSerializeSize()
{
Message(eMessage.CMD_UpdateSerializeSize);
WaitForCMD();
return comm->env.retro_serialize_size;
}
public bool CMD_Serialize(byte[] data)
{
bool ret = false;

View File

@ -24,6 +24,7 @@ namespace BizHawk.Emulation.Cores.Libretro
CMD_Deinit,
CMD_Reset,
CMD_Run,
CMD_UpdateSerializeSize,
CMD_Serialize,
CMD_Unserialize,
CMD_LAST,

View File

@ -374,6 +374,7 @@ namespace BizHawk.Emulation.Cores.Libretro
public void SaveStateBinary(System.IO.BinaryWriter writer)
{
api.CMD_UpdateSerializeSize();
if (savebuff == null || savebuff.Length != api.comm->env.retro_serialize_size)
{
savebuff = new byte[api.comm->env.retro_serialize_size];
@ -404,6 +405,7 @@ namespace BizHawk.Emulation.Cores.Libretro
public byte[] SaveStateBinary()
{
api.CMD_UpdateSerializeSize();
if (savebuff == null || savebuff.Length != api.comm->env.retro_serialize_size)
{
savebuff = new byte[api.comm->env.retro_serialize_size];

View File

@ -89,6 +89,7 @@ enum eMessage : s32
CMD_Deinit,
CMD_Reset,
CMD_Run,
CMD_UpdateSerializeSize,
CMD_Serialize,
CMD_Unserialize,
CMD_LAST,
@ -140,6 +141,7 @@ struct CommStruct
//set by the core
retro_system_info retro_system_info;
retro_system_av_info retro_system_av_info;
size_t retro_serialize_size_initial;
size_t retro_serialize_size;
u32 retro_region;
u32 retro_api_version;
@ -694,7 +696,7 @@ static void LoadHandler(eMessage msg)
//Between calls to retro_load_game() and retro_unload_game(), the returned size is never allowed to be larger than a previous returned
//value, to ensure that the frontend can allocate a save state buffer once.
comm.env.retro_serialize_size = comm.funs.retro_serialize_size();
comm.env.retro_serialize_size_initial = comm.env.retro_serialize_size = comm.funs.retro_serialize_size();
//not sure when this can be called, but it's surely safe here
comm.env.retro_region = comm.funs.retro_get_region();
@ -722,6 +724,11 @@ void cmd_Run()
comm.funs.retro_run();
}
void cmd_UpdateSerializeSize()
{
comm.env.retro_serialize_size = comm.funs.retro_serialize_size();
}
void cmd_Serialize()
{
comm.value = !!comm.funs.retro_serialize(comm.buf[BufId::Param0], comm.buf_size[BufId::Param0]);
@ -765,6 +772,7 @@ const Action kHandlers_CMD[] = {
cmd_Deinit,
cmd_Reset,
cmd_Run,
cmd_UpdateSerializeSize,
cmd_Serialize,
cmd_Unserialize,
};

Binary file not shown.