From cb17d6146c04d950b8fa5c4ac3b6ddb11420ac90 Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 12 Jun 2017 03:14:21 -0500 Subject: [PATCH] teach libretrobridge stuff how to check for changed serialize size --- .../Libretro/LibretroApi.cs | 1 + .../Libretro/LibretroApi_CMD.cs | 7 +++++++ .../Libretro/LibretroApi_Enums.cs | 1 + .../Libretro/LibretroCore.cs | 2 ++ LibretroBridge/vs2015/LibretroBridge.cpp | 10 +++++++++- output/dll/LibretroBridge.dll | Bin 112640 -> 112640 bytes 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroApi.cs b/BizHawk.Emulation.Cores/Libretro/LibretroApi.cs index 975d09deb7..5e81a13b93 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroApi.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroApi.cs @@ -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; diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroApi_CMD.cs b/BizHawk.Emulation.Cores/Libretro/LibretroApi_CMD.cs index 076950a988..9bb5b6540c 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroApi_CMD.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroApi_CMD.cs @@ -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; diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroApi_Enums.cs b/BizHawk.Emulation.Cores/Libretro/LibretroApi_Enums.cs index ce44cadfe5..232189f0fd 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroApi_Enums.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroApi_Enums.cs @@ -24,6 +24,7 @@ namespace BizHawk.Emulation.Cores.Libretro CMD_Deinit, CMD_Reset, CMD_Run, + CMD_UpdateSerializeSize, CMD_Serialize, CMD_Unserialize, CMD_LAST, diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs index 8f821c13e8..068b6214da 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs @@ -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]; diff --git a/LibretroBridge/vs2015/LibretroBridge.cpp b/LibretroBridge/vs2015/LibretroBridge.cpp index 09baef543e..addc698708 100644 --- a/LibretroBridge/vs2015/LibretroBridge.cpp +++ b/LibretroBridge/vs2015/LibretroBridge.cpp @@ -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, }; diff --git a/output/dll/LibretroBridge.dll b/output/dll/LibretroBridge.dll index c685e1f9a35d6118d6bbb69cd8ef1506dbd57d65..3e94b57a67ec5e2ecefde5330f5a2fa3ede66a06 100644 GIT binary patch delta 2230 zcmcIljZ;)r6n|%3bcF?;A1Es;EU+qJ;qF@&l#jZv^`vSFGabZ`(Vw6JkA`YW?TTRIobfU`O=s|&>C4z+H$`uQb} zQ?1#2t_jK@i`Sdr9f;y|7TgQFdEG2%g6TXl0hZ{*4E}TiR7Ayz-5>^ynBT>JOn`MO z&ddi?i?^8J zu3J|iY;(I4H6cO`l|-a}9G zBZ=@({B&f4O}M81xUeKnlZ5`h$`>ZVQxkDd385GHz9d*1HC4mYuBvKlJWsN~ZD8iP z7MQ0Syu33R;&ms&4i51)3s_?uLt|=fw{g`2D@(gt&HOtQLN!+{V1n{%E{{8sQCN5B zf5J7%kgD507_Rt2*g+ZpC>bnpn*WTCfp$KU44LLlb`T$(R1!4f%sZezTPFx==30^C z+=DzX1ri~iuS)@QjJA{OPE{WdSdIQFoP}47CYM|ibft2~Zh2B6;yBFo5Z~m{@5Z1JZ zMlp@N*eHY~Q$mCeW-AW78IZ*o^oSw6CtmZ}6HwIWE?Z z_>b%33AlG+&`fCa(Z=V{>*EUa;e(Wh_hMymnevQrJ%su!sR8=cdGj61Y^Rb!zz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