diff --git a/src/console.c b/src/console.c index 8d04e51..c44fdb2 100644 --- a/src/console.c +++ b/src/console.c @@ -1349,22 +1349,30 @@ static void onConsoleExportHtmlCommand(Console* console, const char* name) static void* embedCart(Console* console, s32* size) { - void* data = fsReadFile(console->appPath, size); + tic_mem* tic = console->tic; - if(data) + if(processDoFile()) { - void* start = memmem(data, *size, embed.prefix, sizeof(embed.prefix)); + void* data = fsReadFile(console->appPath, size); - if(start) + if(data) { - embed.yes = true; - memcpy(&embed.file, &console->tic->cart, sizeof(tic_cartridge)); - memcpy(start, &embed, sizeof(embed)); - embed.yes = false; + 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; + } } + + return data; } - return data; + return NULL; } #if defined(__WINDOWS__) diff --git a/src/run.c b/src/run.c index e3ab75e..9939c54 100644 --- a/src/run.c +++ b/src/run.c @@ -89,8 +89,6 @@ static const char* getPMemName(Run* run) static void tick(Run* run) { - // tic_mem* tic = run->tic; - while(pollEvent()); if (getStudioMode() != TIC_RUN_MODE) @@ -98,7 +96,7 @@ static void tick(Run* run) if(!run->init) { - if(processDoFile()) + if(!processDoFile()) return; run->tickData.start = run->tickData.counter(), diff --git a/src/tic.c b/src/tic.c index d008f98..6b565b8 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1411,6 +1411,11 @@ static void api_tick(tic_mem* memory, tic_tick_data* data) else if(!initLua(machine, code)) return; } + else + { + machine->data->error(machine->data->data, "the code is empty"); + return; + } machine->state.scanline = memory->script == tic_script_js ? callJavascriptScanline : callLuaScanline; machine->state.initialized = true; @@ -1582,28 +1587,28 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) inline void memset4(void *dst, u32 val, u32 dwords) { #if defined(__GNUC__) && defined(i386) - s32 u0, u1, u2; - __asm__ __volatile__ ( - "cld \n\t" - "rep ; stosl \n\t" - : "=&D" (u0), "=&a" (u1), "=&c" (u2) - : "0" (dst), "1" (val), "2" (dwords) - : "memory" - ); + s32 u0, u1, u2; + __asm__ __volatile__ ( + "cld \n\t" + "rep ; stosl \n\t" + : "=&D" (u0), "=&a" (u1), "=&c" (u2) + : "0" (dst), "1" (val), "2" (dwords) + : "memory" + ); #else - u32 _n = (dwords + 3) / 4; - u32 *_p = (u32*)dst; - u32 _val = (val); - if (dwords == 0) - return; - switch (dwords % 4) - { - case 0: do { *_p++ = _val; - case 3: *_p++ = _val; - case 2: *_p++ = _val; - case 1: *_p++ = _val; - } while ( --_n ); - } + u32 _n = (dwords + 3) / 4; + u32 *_p = (u32*)dst; + u32 _val = (val); + if (dwords == 0) + return; + switch (dwords % 4) + { + case 0: do { *_p++ = _val; + case 3: *_p++ = _val; + case 2: *_p++ = _val; + case 1: *_p++ = _val; + } while ( --_n ); + } #endif }