# HG changeset patch # User Michael Pavone # Date 1511638268 28800 # Node ID 8464a3f09b94efb0e581db049a89625f96892cac # Parent a568dca999b2fe08b57dcbaef543a2d6b5fe396e Get SMS savestates working in Nuklear UI diff -r a568dca999b2 -r 8464a3f09b94 sms.c --- a/sms.c Fri Nov 24 20:52:40 2017 -0800 +++ b/sms.c Sat Nov 25 11:31:08 2017 -0800 @@ -318,17 +318,18 @@ static uint8_t load_state(system_header *system, uint8_t slot) { sms_context *sms = (sms_context *)system; - char numslotname[] = "slot_0.state"; - char *slotname; - if (slot == QUICK_SAVE_SLOT) { - slotname = "quicksave.state"; - } else { - numslotname[5] = '0' + slot; - slotname = numslotname; + char *statepath = get_slot_name(system, slot, "state"); + uint8_t ret; + if (!sms->z80->native_pc) { + ret = get_modification_time(statepath) != 0; + if (ret) { + system->delayed_load_slot = slot + 1; + } + goto done; + } - char const *parts[] = {sms->header.save_dir, PATH_SEP, slotname}; - char *statepath = alloc_concat_m(3, parts); - uint8_t ret = load_state_path(sms, statepath); + ret = load_state_path(sms, statepath); +done: free(statepath); return ret; } @@ -342,6 +343,11 @@ render_set_video_standard(VID_NTSC); while (!sms->should_return) { + if (system->delayed_load_slot) { + load_state(system, system->delayed_load_slot - 1); + system->delayed_load_slot = 0; + + } if (system->enter_debugger && sms->z80->pc) { system->enter_debugger = 0; zdebugger(sms->z80, sms->z80->pc);