diff --git a/src/jsapi.c b/src/jsapi.c index 930d1b0..4a752cd 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -715,6 +715,15 @@ static duk_ret_t duk_sync(duk_context* duk) return 0; } +static duk_ret_t duk_reset(duk_context* duk) +{ + tic_machine* machine = getDukMachine(duk); + + machine->state.initialized = false; + + return 0; +} + static const char* const ApiKeywords[] = API_KEYWORDS; static const struct{duk_c_function func; s32 params;} ApiFunc[] = { @@ -753,6 +762,7 @@ static const struct{duk_c_function func; s32 params;} ApiFunc[] = {duk_clip, 4}, {duk_music, 4}, {duk_sync, 3}, + {duk_reset, 0}, }; s32 duk_timeout_check(void* udata) diff --git a/src/luaapi.c b/src/luaapi.c index 9334aae..1731175 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -774,6 +774,15 @@ static s32 lua_sync(lua_State* lua) return 0; } +static s32 lua_reset(lua_State* lua) +{ + tic_machine* machine = getLuaMachine(lua); + + machine->state.initialized = false; + + return 0; +} + static s32 lua_memcpy(lua_State* lua) { s32 top = lua_gettop(lua); @@ -1075,7 +1084,7 @@ static const lua_CFunction ApiFunc[] = lua_rectb, lua_spr, lua_btn, lua_btnp, lua_sfx, lua_map, lua_mget, lua_mset, lua_peek, lua_poke, lua_peek4, lua_poke4, lua_memcpy, lua_memset, lua_trace, lua_pmem, lua_time, lua_exit, lua_font, lua_mouse, - lua_circ, lua_circb, lua_tri, lua_textri, lua_clip, lua_music, lua_sync + lua_circ, lua_circb, lua_tri, lua_textri, lua_clip, lua_music, lua_sync, lua_reset }; STATIC_ASSERT(api_func, COUNT_OF(ApiKeywords) == COUNT_OF(ApiFunc)); diff --git a/src/run.c b/src/run.c index e54c21d..b0113c2 100644 --- a/src/run.c +++ b/src/run.c @@ -95,12 +95,6 @@ static void tick(Run* run) if (getStudioMode() != TIC_RUN_MODE) return; - if(!run->init) - { - run->tickData.start = run->tickData.counter(), - run->init = true; - } - run->tic->api.tick(run->tic, &run->tickData); enum {Size = sizeof(tic_persistent)}; @@ -193,7 +187,6 @@ void initRun(Run* run, Console* console, tic_mem* tic) .console = console, .tick = tick, .exit = false, - .init = false, .tickData = { .error = onError, diff --git a/src/run.h b/src/run.h index 3658572..3e3cca7 100644 --- a/src/run.h +++ b/src/run.h @@ -33,7 +33,6 @@ struct Run tic_tick_data tickData; bool exit; - bool init; s32 persistent[TIC_PERSISTENT_SIZE]; diff --git a/src/tic.c b/src/tic.c index f848dcb..ecc71ef 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1593,9 +1593,11 @@ static void api_tick(tic_mem* memory, tic_tick_data* data) if(done) { + data->start = data->counter(); + machine->state.scanline = memory->script == tic_script_js ? callJavascriptScanline : callLuaScanline; machine->state.ovr.callback = memory->script == tic_script_js ? callJavascriptOverlap : callLuaOverlap; - machine->state.initialized = true; + machine->state.initialized = true; } else return; } diff --git a/src/tic.h b/src/tic.h index e3af097..08ef58e 100644 --- a/src/tic.h +++ b/src/tic.h @@ -115,7 +115,7 @@ #define API_KEYWORDS {"TIC", "scanline", "OVR", "print", "cls", "pix", "line", "rect", "rectb", \ "spr", "btn", "btnp", "sfx", "map", "mget", "mset", "peek", "poke", "peek4", "poke4", \ "memcpy", "memset", "trace", "pmem", "time", "exit", "font", "mouse", "circ", "circb", "tri", "textri", \ - "clip", "music", "sync"} + "clip", "music", "sync", "reset"} #define TIC_FONT_CHARS 128