Mercurial > repos > blastem
diff libblastem.c @ 1690:319d90025d50
Implement serialization/deserialization in libretro build
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 20 Jan 2019 22:19:58 -0800 |
parents | 7f42a93f18a4 |
children | e96d0d3bec7f |
line wrap: on
line diff
--- a/libblastem.c Sun Jan 20 19:52:54 2019 -0800 +++ b/libblastem.c Sun Jan 20 22:19:58 2019 -0800 @@ -117,20 +117,34 @@ * 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. */ +static size_t serialize_size_cache; RETRO_API size_t retro_serialize_size(void) { - return 0; + if (!serialize_size_cache) { + uint8_t *tmp = current_system->serialize(current_system, &serialize_size_cache); + free(tmp); + } + return serialize_size_cache; } /* Serializes internal state. If failed, or size is lower than * retro_serialize_size(), it should return false, true otherwise. */ RETRO_API bool retro_serialize(void *data, size_t size) { - return 0; + size_t actual_size; + uint8_t *tmp = current_system->serialize(current_system, &actual_size); + if (actual_size > size) { + free(tmp); + return 0; + } + memcpy(data, tmp, actual_size); + free(tmp); + return 1; } RETRO_API bool retro_unserialize(const void *data, size_t size) { + current_system->deserialize(current_system, (uint8_t *)data, size); return 0; } @@ -145,6 +159,7 @@ /* Loads a game. */ RETRO_API bool retro_load_game(const struct retro_game_info *game) { + serialize_size_cache = 0; if (game->path) { media.dir = path_dirname(game->path); media.name = basename_no_extension(game->path);