comparison 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
comparison
equal deleted inserted replaced
1689:7f42a93f18a4 1690:319d90025d50
115 * internal state (save states). 115 * internal state (save states).
116 * Between calls to retro_load_game() and retro_unload_game(), the 116 * Between calls to retro_load_game() and retro_unload_game(), the
117 * returned size is never allowed to be larger than a previous returned 117 * returned size is never allowed to be larger than a previous returned
118 * value, to ensure that the frontend can allocate a save state buffer once. 118 * value, to ensure that the frontend can allocate a save state buffer once.
119 */ 119 */
120 static size_t serialize_size_cache;
120 RETRO_API size_t retro_serialize_size(void) 121 RETRO_API size_t retro_serialize_size(void)
121 { 122 {
122 return 0; 123 if (!serialize_size_cache) {
124 uint8_t *tmp = current_system->serialize(current_system, &serialize_size_cache);
125 free(tmp);
126 }
127 return serialize_size_cache;
123 } 128 }
124 129
125 /* Serializes internal state. If failed, or size is lower than 130 /* Serializes internal state. If failed, or size is lower than
126 * retro_serialize_size(), it should return false, true otherwise. */ 131 * retro_serialize_size(), it should return false, true otherwise. */
127 RETRO_API bool retro_serialize(void *data, size_t size) 132 RETRO_API bool retro_serialize(void *data, size_t size)
128 { 133 {
129 return 0; 134 size_t actual_size;
135 uint8_t *tmp = current_system->serialize(current_system, &actual_size);
136 if (actual_size > size) {
137 free(tmp);
138 return 0;
139 }
140 memcpy(data, tmp, actual_size);
141 free(tmp);
142 return 1;
130 } 143 }
131 144
132 RETRO_API bool retro_unserialize(const void *data, size_t size) 145 RETRO_API bool retro_unserialize(const void *data, size_t size)
133 { 146 {
147 current_system->deserialize(current_system, (uint8_t *)data, size);
134 return 0; 148 return 0;
135 } 149 }
136 150
137 RETRO_API void retro_cheat_reset(void) 151 RETRO_API void retro_cheat_reset(void)
138 { 152 {
143 } 157 }
144 158
145 /* Loads a game. */ 159 /* Loads a game. */
146 RETRO_API bool retro_load_game(const struct retro_game_info *game) 160 RETRO_API bool retro_load_game(const struct retro_game_info *game)
147 { 161 {
162 serialize_size_cache = 0;
148 if (game->path) { 163 if (game->path) {
149 media.dir = path_dirname(game->path); 164 media.dir = path_dirname(game->path);
150 media.name = basename_no_extension(game->path); 165 media.name = basename_no_extension(game->path);
151 media.extension = path_extension(game->path); 166 media.extension = path_extension(game->path);
152 } 167 }