comparison sms.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 395f684c5379
children 956c1cce05e2 d6d4c006a7b3
comparison
equal deleted inserted replaced
1689:7f42a93f18a4 1690:319d90025d50
233 save_int8(buf, SMS_CART_RAM_SIZE / 1024); 233 save_int8(buf, SMS_CART_RAM_SIZE / 1024);
234 save_buffer8(buf, sms->cart_ram, SMS_CART_RAM_SIZE); 234 save_buffer8(buf, sms->cart_ram, SMS_CART_RAM_SIZE);
235 end_section(buf); 235 end_section(buf);
236 } 236 }
237 237
238 static uint8_t *serialize(system_header *sys, size_t *size_out)
239 {
240 sms_context *sms = (sms_context *)sys;
241 serialize_buffer state;
242 init_serialize(&state);
243 sms_serialize(sms, &state);
244 if (size_out) {
245 *size_out = state.size;
246 }
247 return state.data;
248 }
249
238 static void ram_deserialize(deserialize_buffer *buf, void *vsms) 250 static void ram_deserialize(deserialize_buffer *buf, void *vsms)
239 { 251 {
240 sms_context *sms = vsms; 252 sms_context *sms = vsms;
241 uint32_t ram_size = load_int8(buf) * 1024; 253 uint32_t ram_size = load_int8(buf) * 1024;
242 if (ram_size > sizeof(sms->ram)) { 254 if (ram_size > sizeof(sms->ram)) {
288 z80_invalidate_code_range(sms->z80, 0xC000, 0x10000); 300 z80_invalidate_code_range(sms->z80, 0xC000, 0x10000);
289 if (sms->bank_regs[0] & 8) { 301 if (sms->bank_regs[0] & 8) {
290 //cart RAM is enabled, invalidate the region in case there is any code there 302 //cart RAM is enabled, invalidate the region in case there is any code there
291 z80_invalidate_code_range(sms->z80, 0x8000, 0xC000); 303 z80_invalidate_code_range(sms->z80, 0x8000, 0xC000);
292 } 304 }
305 free(buf->handlers);
306 buf->handlers = NULL;
307 }
308
309 static void deserialize(system_header *sys, uint8_t *data, size_t size)
310 {
311 sms_context *sms = (sms_context *)sys;
312 deserialize_buffer buffer;
313 init_deserialize(&buffer, data, size);
314 sms_deserialize(&buffer, sms);
293 } 315 }
294 316
295 static void save_state(sms_context *sms, uint8_t slot) 317 static void save_state(sms_context *sms, uint8_t slot)
296 { 318 {
297 char *save_path = get_slot_name(&sms->header, slot, "state"); 319 char *save_path = get_slot_name(&sms->header, slot, "state");
601 sms->header.mouse_motion_absolute = mouse_motion_absolute; 623 sms->header.mouse_motion_absolute = mouse_motion_absolute;
602 sms->header.mouse_motion_relative = mouse_motion_relative; 624 sms->header.mouse_motion_relative = mouse_motion_relative;
603 sms->header.keyboard_down = keyboard_down; 625 sms->header.keyboard_down = keyboard_down;
604 sms->header.keyboard_up = keyboard_up; 626 sms->header.keyboard_up = keyboard_up;
605 sms->header.config_updated = config_updated; 627 sms->header.config_updated = config_updated;
628 sms->header.serialize = serialize;
629 sms->header.deserialize = deserialize;
606 sms->header.type = SYSTEM_SMS; 630 sms->header.type = SYSTEM_SMS;
607 631
608 return sms; 632 return sms;
609 } 633 }