Mercurial > repos > blastem
comparison sms.c @ 1478:da1dce39e846 nuklear_ui
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 24 Nov 2017 12:04:02 -0800 |
parents | c886c54d8cf1 |
children | 8464a3f09b94 |
comparison
equal
deleted
inserted
replaced
1477:1cdd7f492af8 | 1478:da1dce39e846 |
---|---|
4 #include "sms.h" | 4 #include "sms.h" |
5 #include "blastem.h" | 5 #include "blastem.h" |
6 #include "render.h" | 6 #include "render.h" |
7 #include "util.h" | 7 #include "util.h" |
8 #include "debug.h" | 8 #include "debug.h" |
9 #include "saves.h" | |
9 | 10 |
10 static void *memory_io_write(uint32_t location, void *vcontext, uint8_t value) | 11 static void *memory_io_write(uint32_t location, void *vcontext, uint8_t value) |
11 { | 12 { |
12 z80_context *z80 = vcontext; | 13 z80_context *z80 = vcontext; |
13 sms_context *sms = z80->system; | 14 sms_context *sms = z80->system; |
290 } | 291 } |
291 } | 292 } |
292 | 293 |
293 static void save_state(sms_context *sms, uint8_t slot) | 294 static void save_state(sms_context *sms, uint8_t slot) |
294 { | 295 { |
295 char *save_path; | 296 char *save_path = get_slot_name(&sms->header, slot, "state"); |
296 if (slot == QUICK_SAVE_SLOT) { | |
297 save_path = save_state_path; | |
298 } else { | |
299 char slotname[] = "slot_0.state"; | |
300 slotname[5] = '0' + slot; | |
301 char const *parts[] = {sms->header.save_dir, PATH_SEP, slotname}; | |
302 save_path = alloc_concat_m(3, parts); | |
303 } | |
304 serialize_buffer state; | 297 serialize_buffer state; |
305 init_serialize(&state); | 298 init_serialize(&state); |
306 sms_serialize(sms, &state); | 299 sms_serialize(sms, &state); |
307 save_to_file(&state, save_path); | 300 save_to_file(&state, save_path); |
308 printf("Saved state to %s\n", save_path); | 301 printf("Saved state to %s\n", save_path); |
302 free(save_path); | |
309 free(state.data); | 303 free(state.data); |
310 } | 304 } |
311 | 305 |
312 static uint8_t load_state_path(sms_context *sms, char *path) | 306 static uint8_t load_state_path(sms_context *sms, char *path) |
313 { | 307 { |