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 = [");
|
||||
|
||||
s32 size = 0;
|
||||
|
||||
// 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);
|
||||
}
|
||||
s32 size = tic->api.save(&tic->cart, buffer);
|
||||
|
||||
if(size)
|
||||
{
|
||||
|
@ -1620,27 +1604,23 @@ static void* embedCart(Console* console, s32* size)
|
|||
{
|
||||
tic_mem* tic = console->tic;
|
||||
|
||||
if(processDoFile())
|
||||
void* data = fsReadFile(console->appPath, size);
|
||||
|
||||
if(data)
|
||||
{
|
||||
void* data = fsReadFile(console->appPath, size);
|
||||
void* start = memmem(data, *size, embed.prefix, sizeof(embed.prefix));
|
||||
|
||||
if(data)
|
||||
if(start)
|
||||
{
|
||||
void* start = memmem(data, *size, embed.prefix, sizeof(embed.prefix));
|
||||
|
||||
if(start)
|
||||
{
|
||||
embed.yes = true;
|
||||
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));
|
||||
embed.yes = false;
|
||||
}
|
||||
embed.yes = true;
|
||||
SDL_memcpy(&embed.file, &tic->cart, sizeof(tic_cartridge));
|
||||
SDL_memcpy(start, &embed, sizeof(embed));
|
||||
embed.yes = false;
|
||||
}
|
||||
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
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);
|
||||
|
||||
if(index < TIC_PERSISTENT_SIZE)
|
||||
if(index >= 0 && index < TIC_PERSISTENT_SIZE)
|
||||
{
|
||||
s32 val = memory->ram.persistent.data[index];
|
||||
|
||||
|
@ -708,11 +708,6 @@ static duk_ret_t duk_sync(duk_context* duk)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static duk_ret_t duk_dofile(duk_context* duk)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char* const ApiKeywords[] = API_KEYWORDS;
|
||||
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_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)
|
||||
|
|
23
src/luaapi.c
23
src/luaapi.c
|
@ -956,18 +956,21 @@ static s32 lua_pmem(lua_State *lua)
|
|||
if(top >= 1)
|
||||
{
|
||||
u32 index = getLuaNumber(lua, 1);
|
||||
index %= TIC_PERSISTENT_SIZE;
|
||||
|
||||
s32 val = memory->ram.persistent.data[index];
|
||||
|
||||
if(top >= 2)
|
||||
if(index >= 0 && index < TIC_PERSISTENT_SIZE)
|
||||
{
|
||||
memory->ram.persistent.data[index] = getLuaNumber(lua, 2);
|
||||
s32 val = memory->ram.persistent.data[index];
|
||||
|
||||
if(top >= 2)
|
||||
{
|
||||
memory->ram.persistent.data[index] = getLuaNumber(lua, 2);
|
||||
}
|
||||
|
||||
lua_pushinteger(lua, val);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushinteger(lua, val);
|
||||
|
||||
return 1;
|
||||
luaL_error(lua, "invalid persistent memory index\n");
|
||||
}
|
||||
else luaL_error(lua, "invalid params, pmem(index [val]) -> val\n");
|
||||
|
||||
|
@ -1013,7 +1016,7 @@ static s32 lua_mouse(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;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ static const char* getPMemName(Run* run)
|
|||
{
|
||||
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));
|
||||
strcpy(buffer, TIC_LOCAL);
|
||||
strcat(buffer, md5);
|
||||
|
@ -95,10 +95,7 @@ static void tick(Run* run)
|
|||
return;
|
||||
|
||||
if(!run->init)
|
||||
{
|
||||
if(!processDoFile())
|
||||
return;
|
||||
|
||||
{
|
||||
run->tickData.start = run->tickData.counter(),
|
||||
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);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
studio.tic->api.reset(studio.tic);
|
||||
|
|
|
@ -197,4 +197,3 @@ void gotoCode();
|
|||
void gotoSurf();
|
||||
void exitFromGameMenu();
|
||||
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;
|
||||
|
||||
updateSaveid(memory);
|
||||
|
||||
memset(memory->code.data, 0, sizeof(tic_code));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if(isMoonscript(memory->code.data)) return tic_script_moon;
|
||||
if(isJavascript(memory->code.data)) return tic_script_js;
|
||||
if(isMoonscript(memory->cart.code.data)) return tic_script_moon;
|
||||
if(isJavascript(memory->cart.code.data)) return tic_script_js;
|
||||
return tic_script_lua;
|
||||
}
|
||||
|
||||
static void updateSaveid(tic_mem* memory)
|
||||
{
|
||||
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)
|
||||
{
|
||||
strcpy(memory->saveid, saveid);
|
||||
|
@ -1361,7 +1359,7 @@ static void updateSaveid(tic_mem* memory)
|
|||
}
|
||||
else
|
||||
{
|
||||
const char* saveid = readMetatag(memory->code.data, "saveid", TagFormatJS);
|
||||
const char* saveid = readMetatag(memory->cart.code.data, "saveid", TagFormatJS);
|
||||
if(saveid)
|
||||
{
|
||||
strcpy(memory->saveid, saveid);
|
||||
|
@ -1380,10 +1378,7 @@ static void api_tick(tic_mem* memory, tic_tick_data* data)
|
|||
{
|
||||
cart2ram(memory);
|
||||
|
||||
const char* code = machine->memory.code.data;
|
||||
|
||||
if(!strlen(code))
|
||||
memcpy(memory->code.data, memory->cart.code.data, sizeof(tic_code));
|
||||
const char* code = machine->memory.cart.code.data;
|
||||
|
||||
if(strlen(code))
|
||||
{
|
||||
|
|
|
@ -119,7 +119,6 @@ struct tic_mem
|
|||
tic_script_lang script;
|
||||
tic_font font;
|
||||
tic_api api;
|
||||
tic_code code;
|
||||
|
||||
char saveid[TIC_SAVEID_SIZE];
|
||||
|
||||
|
|
Loading…
Reference in New Issue