This commit is contained in:
parent
c99b402c41
commit
f4808d40d4
|
@ -1550,23 +1550,7 @@ static void onConsoleExportHtmlCommand(Console* console, const char* name)
|
||||||
{
|
{
|
||||||
writeMemoryString(&output, "var cartridge = [");
|
writeMemoryString(&output, "var cartridge = [");
|
||||||
|
|
||||||
s32 size = 0;
|
s32 size = tic->api.save(&tic->cart, buffer);
|
||||||
|
|
||||||
// create cart copy
|
|
||||||
{
|
|
||||||
tic_cartridge* dup = SDL_malloc(sizeof(tic_cartridge));
|
|
||||||
|
|
||||||
SDL_memcpy(dup, &tic->cart, sizeof(tic_cartridge));
|
|
||||||
|
|
||||||
if(processDoFile())
|
|
||||||
{
|
|
||||||
SDL_memcpy(dup->code.data, tic->code.data, sizeof(tic_code));
|
|
||||||
|
|
||||||
size = tic->api.save(dup, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_free(dup);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(size)
|
if(size)
|
||||||
{
|
{
|
||||||
|
@ -1620,8 +1604,6 @@ static void* embedCart(Console* console, s32* size)
|
||||||
{
|
{
|
||||||
tic_mem* tic = console->tic;
|
tic_mem* tic = console->tic;
|
||||||
|
|
||||||
if(processDoFile())
|
|
||||||
{
|
|
||||||
void* data = fsReadFile(console->appPath, size);
|
void* data = fsReadFile(console->appPath, size);
|
||||||
|
|
||||||
if(data)
|
if(data)
|
||||||
|
@ -1632,11 +1614,9 @@ static void* embedCart(Console* console, s32* size)
|
||||||
{
|
{
|
||||||
embed.yes = true;
|
embed.yes = true;
|
||||||
SDL_memcpy(&embed.file, &tic->cart, sizeof(tic_cartridge));
|
SDL_memcpy(&embed.file, &tic->cart, sizeof(tic_cartridge));
|
||||||
SDL_memcpy(embed.file.code.data, tic->code.data, sizeof(tic_code));
|
|
||||||
SDL_memcpy(start, &embed, sizeof(embed));
|
SDL_memcpy(start, &embed, sizeof(embed));
|
||||||
embed.yes = false;
|
embed.yes = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
12
src/jsapi.c
12
src/jsapi.c
|
@ -512,7 +512,7 @@ static duk_ret_t duk_pmem(duk_context* duk)
|
||||||
|
|
||||||
u32 index = duk_to_int(duk, 0);
|
u32 index = duk_to_int(duk, 0);
|
||||||
|
|
||||||
if(index < TIC_PERSISTENT_SIZE)
|
if(index >= 0 && index < TIC_PERSISTENT_SIZE)
|
||||||
{
|
{
|
||||||
s32 val = memory->ram.persistent.data[index];
|
s32 val = memory->ram.persistent.data[index];
|
||||||
|
|
||||||
|
@ -708,11 +708,6 @@ static duk_ret_t duk_sync(duk_context* duk)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static duk_ret_t duk_dofile(duk_context* duk)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* const ApiKeywords[] = API_KEYWORDS;
|
static const char* const ApiKeywords[] = API_KEYWORDS;
|
||||||
static const struct{duk_c_function func; s32 params;} ApiFunc[] =
|
static const struct{duk_c_function func; s32 params;} ApiFunc[] =
|
||||||
{
|
{
|
||||||
|
@ -771,11 +766,6 @@ static void initDuktape(tic_machine* machine)
|
||||||
duk_push_c_function(machine->js, ApiFunc[i].func, ApiFunc[i].params);
|
duk_push_c_function(machine->js, ApiFunc[i].func, ApiFunc[i].params);
|
||||||
duk_put_global_string(machine->js, ApiKeywords[i]);
|
duk_put_global_string(machine->js, ApiKeywords[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
duk_push_c_function(machine->js, duk_dofile, 1);
|
|
||||||
duk_put_global_string(machine->js, "dofile");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool initJavascript(tic_machine* machine, const char* code)
|
bool initJavascript(tic_machine* machine, const char* code)
|
||||||
|
|
|
@ -956,8 +956,9 @@ static s32 lua_pmem(lua_State *lua)
|
||||||
if(top >= 1)
|
if(top >= 1)
|
||||||
{
|
{
|
||||||
u32 index = getLuaNumber(lua, 1);
|
u32 index = getLuaNumber(lua, 1);
|
||||||
index %= TIC_PERSISTENT_SIZE;
|
|
||||||
|
|
||||||
|
if(index >= 0 && index < TIC_PERSISTENT_SIZE)
|
||||||
|
{
|
||||||
s32 val = memory->ram.persistent.data[index];
|
s32 val = memory->ram.persistent.data[index];
|
||||||
|
|
||||||
if(top >= 2)
|
if(top >= 2)
|
||||||
|
@ -969,6 +970,8 @@ static s32 lua_pmem(lua_State *lua)
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
luaL_error(lua, "invalid persistent memory index\n");
|
||||||
|
}
|
||||||
else luaL_error(lua, "invalid params, pmem(index [val]) -> val\n");
|
else luaL_error(lua, "invalid params, pmem(index [val]) -> val\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1013,7 +1016,7 @@ static s32 lua_mouse(lua_State *lua)
|
||||||
|
|
||||||
static s32 lua_dofile(lua_State *lua)
|
static s32 lua_dofile(lua_State *lua)
|
||||||
{
|
{
|
||||||
luaL_error(lua, "you can use 'dofile' only on first line\n");
|
luaL_error(lua, "unknown method: \"dofile\"\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ static const char* getPMemName(Run* run)
|
||||||
{
|
{
|
||||||
static char buffer[FILENAME_MAX];
|
static char buffer[FILENAME_MAX];
|
||||||
|
|
||||||
const char* data = strlen(run->tic->saveid) ? run->tic->saveid : run->tic->code.data;
|
const char* data = strlen(run->tic->saveid) ? run->tic->saveid : run->tic->cart.code.data;
|
||||||
char* md5 = data2md5(data, (s32)strlen(data));
|
char* md5 = data2md5(data, (s32)strlen(data));
|
||||||
strcpy(buffer, TIC_LOCAL);
|
strcpy(buffer, TIC_LOCAL);
|
||||||
strcat(buffer, md5);
|
strcat(buffer, md5);
|
||||||
|
@ -96,9 +96,6 @@ static void tick(Run* run)
|
||||||
|
|
||||||
if(!run->init)
|
if(!run->init)
|
||||||
{
|
{
|
||||||
if(!processDoFile())
|
|
||||||
return;
|
|
||||||
|
|
||||||
run->tickData.start = run->tickData.counter(),
|
run->tickData.start = run->tickData.counter(),
|
||||||
run->init = true;
|
run->init = true;
|
||||||
}
|
}
|
||||||
|
|
54
src/studio.c
54
src/studio.c
|
@ -1359,60 +1359,6 @@ static void onFullscreen()
|
||||||
SDL_SetWindowFullscreen(studio.window, studio.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
SDL_SetWindowFullscreen(studio.window, studio.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool processDoFile()
|
|
||||||
{
|
|
||||||
tic_mem* tic = studio.tic;
|
|
||||||
|
|
||||||
memset(tic->code.data, 0, sizeof(tic_code));
|
|
||||||
|
|
||||||
static const char DoFileTag[] = "dofile(";
|
|
||||||
enum {Size = sizeof DoFileTag - 1};
|
|
||||||
|
|
||||||
if (memcmp(tic->cart.code.data, DoFileTag, Size) == 0)
|
|
||||||
{
|
|
||||||
const char* start = tic->cart.code.data + Size;
|
|
||||||
const char* end = strchr(start, ')');
|
|
||||||
|
|
||||||
if(end && *start == *(end-1) && (*start == '"' || *start == '\''))
|
|
||||||
{
|
|
||||||
char filename[FILENAME_MAX] = {0};
|
|
||||||
memcpy(filename, start + 1, end - start - 2);
|
|
||||||
|
|
||||||
s32 size = 0;
|
|
||||||
void* buffer = fsReadFile(filename, &size);
|
|
||||||
|
|
||||||
if(buffer)
|
|
||||||
{
|
|
||||||
if(size > 0)
|
|
||||||
{
|
|
||||||
if(size > TIC_CODE_SIZE)
|
|
||||||
{
|
|
||||||
char buffer[256];
|
|
||||||
sprintf(buffer, "code is larger than %i symbols", TIC_CODE_SIZE);
|
|
||||||
setStudioMode(TIC_CONSOLE_MODE);
|
|
||||||
studio.console.error(&studio.console, buffer);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else SDL_memcpy(tic->code.data, buffer, size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char buffer[256];
|
|
||||||
sprintf(buffer, "dofile: file '%s' not found", filename);
|
|
||||||
setStudioMode(TIC_CONSOLE_MODE);
|
|
||||||
studio.console.error(&studio.console, buffer);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else SDL_memcpy(tic->code.data, tic->cart.code.data, sizeof(tic_code));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void runProject()
|
void runProject()
|
||||||
{
|
{
|
||||||
studio.tic->api.reset(studio.tic);
|
studio.tic->api.reset(studio.tic);
|
||||||
|
|
|
@ -197,4 +197,3 @@ void gotoCode();
|
||||||
void gotoSurf();
|
void gotoSurf();
|
||||||
void exitFromGameMenu();
|
void exitFromGameMenu();
|
||||||
void runProject();
|
void runProject();
|
||||||
bool processDoFile();
|
|
||||||
|
|
15
src/tic.c
15
src/tic.c
|
@ -431,8 +431,6 @@ static void api_reset(tic_mem* memory)
|
||||||
machine->state.scanline = NULL;
|
machine->state.scanline = NULL;
|
||||||
|
|
||||||
updateSaveid(memory);
|
updateSaveid(memory);
|
||||||
|
|
||||||
memset(memory->code.data, 0, sizeof(tic_code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void api_pause(tic_mem* memory)
|
static void api_pause(tic_mem* memory)
|
||||||
|
@ -1345,15 +1343,15 @@ static bool isJavascript(const char* code)
|
||||||
|
|
||||||
static tic_script_lang api_get_script(tic_mem* memory)
|
static tic_script_lang api_get_script(tic_mem* memory)
|
||||||
{
|
{
|
||||||
if(isMoonscript(memory->code.data)) return tic_script_moon;
|
if(isMoonscript(memory->cart.code.data)) return tic_script_moon;
|
||||||
if(isJavascript(memory->code.data)) return tic_script_js;
|
if(isJavascript(memory->cart.code.data)) return tic_script_js;
|
||||||
return tic_script_lua;
|
return tic_script_lua;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateSaveid(tic_mem* memory)
|
static void updateSaveid(tic_mem* memory)
|
||||||
{
|
{
|
||||||
memset(memory->saveid, 0, sizeof memory->saveid);
|
memset(memory->saveid, 0, sizeof memory->saveid);
|
||||||
const char* saveid = readMetatag(memory->code.data, "saveid", TagFormatLua);
|
const char* saveid = readMetatag(memory->cart.code.data, "saveid", TagFormatLua);
|
||||||
if(saveid)
|
if(saveid)
|
||||||
{
|
{
|
||||||
strcpy(memory->saveid, saveid);
|
strcpy(memory->saveid, saveid);
|
||||||
|
@ -1361,7 +1359,7 @@ static void updateSaveid(tic_mem* memory)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char* saveid = readMetatag(memory->code.data, "saveid", TagFormatJS);
|
const char* saveid = readMetatag(memory->cart.code.data, "saveid", TagFormatJS);
|
||||||
if(saveid)
|
if(saveid)
|
||||||
{
|
{
|
||||||
strcpy(memory->saveid, saveid);
|
strcpy(memory->saveid, saveid);
|
||||||
|
@ -1380,10 +1378,7 @@ static void api_tick(tic_mem* memory, tic_tick_data* data)
|
||||||
{
|
{
|
||||||
cart2ram(memory);
|
cart2ram(memory);
|
||||||
|
|
||||||
const char* code = machine->memory.code.data;
|
const char* code = machine->memory.cart.code.data;
|
||||||
|
|
||||||
if(!strlen(code))
|
|
||||||
memcpy(memory->code.data, memory->cart.code.data, sizeof(tic_code));
|
|
||||||
|
|
||||||
if(strlen(code))
|
if(strlen(code))
|
||||||
{
|
{
|
||||||
|
|
|
@ -119,7 +119,6 @@ struct tic_mem
|
||||||
tic_script_lang script;
|
tic_script_lang script;
|
||||||
tic_font font;
|
tic_font font;
|
||||||
tic_api api;
|
tic_api api;
|
||||||
tic_code code;
|
|
||||||
|
|
||||||
char saveid[TIC_SAVEID_SIZE];
|
char saveid[TIC_SAVEID_SIZE];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue