Please, add "cartidge reset" api call #473

This commit is contained in:
BADIM-PC\Vadim 2017-12-20 15:07:35 +03:00
parent 0e997f5d33
commit 2eacc2bf34
6 changed files with 24 additions and 11 deletions

View File

@ -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)

View File

@ -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));

View File

@ -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,

View File

@ -33,7 +33,6 @@ struct Run
tic_tick_data tickData;
bool exit;
bool init;
s32 persistent[TIC_PERSISTENT_SIZE];

View File

@ -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;
}

View File

@ -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