diff --git a/src/jsapi.c b/src/jsapi.c index 0fee3bd..5dcc672 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -564,7 +564,10 @@ static duk_ret_t duk_pmem(duk_context* duk) s32 val = memory->persistent.data[index]; if(!duk_is_null_or_undefined(duk, 1)) + { memory->persistent.data[index] = duk_to_int(duk, 1); + machine->data->syncPMEM = true; + } duk_push_int(duk, val); diff --git a/src/luaapi.c b/src/luaapi.c index 7cecac9..640f608 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -1069,6 +1069,7 @@ static s32 lua_pmem(lua_State *lua) if(top >= 2) { memory->persistent.data[index] = getLuaNumber(lua, 2); + machine->data->syncPMEM = true; } lua_pushinteger(lua, val); diff --git a/src/run.c b/src/run.c index e37d544..be053e5 100644 --- a/src/run.c +++ b/src/run.c @@ -93,11 +93,11 @@ static void tick(Run* run) enum {Size = sizeof(tic_persistent)}; - // TODO: remove PMEM checking... - if(memcmp(&run->tic->persistent, &run->persistent, Size) != 0) + if(run->tickData.syncPMEM) { fsSaveRootFile(run->console->fs, run->saveid, &run->tic->persistent, Size, true); memcpy(&run->persistent, &run->tic->persistent, Size); + run->tickData.syncPMEM = false; } if(run->exit) @@ -184,6 +184,7 @@ void initRun(Run* run, Console* console, tic_mem* tic) .exit = onExit, .preprocessor = processDoFile, .forceExit = forceExit, + .syncPMEM = false, }, }; diff --git a/src/tic80.c b/src/tic80.c index 90adbac..e9e1506 100644 --- a/src/tic80.c +++ b/src/tic80.c @@ -104,6 +104,7 @@ TIC80_API void tic80_load(tic80* tic, void* cart, s32 size) tic80->tickData.start = 0; tic80->tickData.freq = getFreq; tic80->tickData.counter = getCounter; + tic80->tickData.syncPMEM = false; TickCounter = 0; } diff --git a/src/ticapi.h b/src/ticapi.h index 4fc66f4..0511a2d 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -58,6 +58,8 @@ typedef struct u64 (*freq)(); u64 start; + bool syncPMEM; + void (*preprocessor)(void* data, char* dst); void* data; diff --git a/src/wrenapi.c b/src/wrenapi.c index f3f935c..2d7e16e 100644 --- a/src/wrenapi.c +++ b/src/wrenapi.c @@ -905,6 +905,7 @@ static void wren_pmem(WrenVM* vm) if(top > 2) { memory->persistent.data[index] = getWrenNumber(vm, 2); + machine->data->syncPMEM = true; } wrenSetSlotDouble(vm, 0, val);