Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
nesbox committed Nov 28, 2017
2 parents 10ddf94 + 0de8eb4 commit 6aad6d8
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 47 deletions.
2 changes: 1 addition & 1 deletion bin/assets/tic.js.dat

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nesbox.tic"
android:versionCode="5000"
android:versionName="0.50.0"
android:versionCode="5001"
android:versionName="0.50.1"
android:installLocation="auto">

<!-- Android 2.3.3 -->
Expand Down
4 changes: 2 additions & 2 deletions build/macosx/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.50.0</string>
<string>0.50.1</string>
<key>CFBundleVersion</key>
<string>0.50.0</string>
<string>0.50.1</string>
<key>NSHumanReadableCopyright</key>
<string>http://tic.computer © 2017</string>
<key>NSHighResolutionCapable</key>
Expand Down
Binary file modified build/windows/tic80/tic80.aps
Binary file not shown.
Binary file modified build/windows/tic80/tic80.rc
Binary file not shown.
Binary file modified lib/windows/tic.rc
Binary file not shown.
36 changes: 25 additions & 11 deletions src/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ static void* getDemoCart(Console* console, tic_script_lang script, s32* size)
return data;
}

static void setCartName(Console* console, const char* name)
{
if(name != console->romName)
strcpy(console->romName, name);
}

static void onConsoleLoadDemoCommandConfirmed(Console* console, const char* param)
{
void* data = NULL;
Expand All @@ -480,7 +486,7 @@ static void onConsoleLoadDemoCommandConfirmed(Console* console, const char* para

const char* name = getCartName(param);

strcpy(console->romName, name);
setCartName(console, name);

loadRom(console->tic, data, size, true);

Expand All @@ -495,7 +501,7 @@ static void onConsoleLoadDemoCommandConfirmed(Console* console, const char* para

static void onCartLoaded(Console* console, const char* name)
{
strcpy(console->romName, name);
setCartName(console, name);

studioRomLoaded();

Expand Down Expand Up @@ -1343,15 +1349,21 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v
commandDone(console);
}

static void injectMap(Console* console, const void* buffer, s32 size)
{
enum {Size = sizeof(tic_map)};

SDL_memset(&console->tic->cart.gfx.map, 0, Size);
SDL_memcpy(&console->tic->cart.gfx.map, buffer, SDL_min(size, Size));
}

static void onImportMap(const char* name, const void* buffer, size_t size, void* data)
{
Console* console = (Console*)data;

enum {Size = sizeof(tic_map)};

if(name && buffer && size == Size)
if(name && buffer && size <= sizeof(tic_map))
{
memcpy(&console->tic->cart.gfx.map, buffer, size);
injectMap(console, buffer, size);

printLine(console);
printBack(console, "map successfully imported");
Expand Down Expand Up @@ -1889,7 +1901,7 @@ static CartSaveResult saveCartName(Console* console, const char* name)

if(size && fsSaveFile(console->fs, name, buffer, size, true))
{
strcpy(console->romName, name);
setCartName(console, name);
success = true;
studioRomSaved();
}
Expand Down Expand Up @@ -2627,7 +2639,7 @@ static void cmdLoadCart(Console* console, const char* name)
if(hasProjectExt(name))
{
loadProject(console, name, data, size, &embed.file);
strcpy(console->romName, fsFilename(name));
setCartName(console, fsFilename(name));
embed.yes = true;
embed.fast = true;
}
Expand All @@ -2637,7 +2649,7 @@ static void cmdLoadCart(Console* console, const char* name)
if(hasExt(name, CART_EXT))
{
loadCart(console->tic, &embed.file, data, size, true);
strcpy(console->romName, fsFilename(name));
setCartName(console, fsFilename(name));
embed.yes = true;
}

Expand Down Expand Up @@ -2755,9 +2767,9 @@ static void cmdInjectMap(Console* console, const char* param, const char* name)

if(map)
{
if(size == sizeof(tic_map))
if(size <= sizeof(tic_map))
{
SDL_memcpy(embed.file.gfx.map.data, map, size);
injectMap(console, map, size);

embed.yes = true;
embed.fast = true;
Expand Down Expand Up @@ -2862,6 +2874,8 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
config->data.noSound = true;
else if(strcmp(argv[i], "-surf") == 0)
console->startSurf = true;
else if(strcmp(argv[i], "-fullscreen") == 0)
goFullscreen();
}
}

Expand Down
52 changes: 52 additions & 0 deletions src/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,57 @@ static void tick(Run* run)
setStudioMode(TIC_CONSOLE_MODE);
}

static void processDoFile(void* data, char* dst)
{
Run* run = (Run*)data;
tic_mem* tic = run->tic;

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);
memset(dst, 0, sizeof(tic_code));

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);
onError(run, buffer);

return;
}
else SDL_memcpy(dst, buffer, size);
}
}
else
{
char buffer[256];
sprintf(buffer, "dofile: file '%s' not found", filename);
onError(run, buffer);

return;
}
}
}

return;
}

void initRun(Run* run, Console* console, tic_mem* tic)
{
*run = (Run)
Expand All @@ -133,6 +184,7 @@ void initRun(Run* run, Console* console, tic_mem* tic)
.start = 0,
.data = run,
.exit = onExit,
.preprocessor = processDoFile,
},
};

Expand Down
2 changes: 2 additions & 0 deletions src/sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,8 @@ static void drawSpriteToolbar(Sprite* sprite)
{
setCursor(SDL_SYSTEM_CURSOR_HAND);

showTooltip("CANVAS ZOOM");

if(checkMouseDown(&rect, SDL_BUTTON_LEFT))
{
s32 mx = getMouseX() - rect.x;
Expand Down
10 changes: 5 additions & 5 deletions src/studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ static void processMouse()
}
}

static void onFullscreen()
void goFullscreen()
{
studio.fullscreen = !studio.fullscreen;
SDL_SetWindowFullscreen(studio.window, studio.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
Expand Down Expand Up @@ -1555,12 +1555,12 @@ static bool processShortcuts(SDL_KeyboardEvent* event)
studio.gamepad.backProcessed = true;
return true;
case SDLK_F11:
onFullscreen();
goFullscreen();
return true;
case SDLK_RETURN:
if(mod & KMOD_RALT)
{
onFullscreen();
goFullscreen();
return true;
}
break;
Expand Down Expand Up @@ -1627,11 +1627,11 @@ static bool processShortcuts(SDL_KeyboardEvent* event)
return true;
}
break;
case SDLK_F11: onFullscreen(); return true;
case SDLK_F11: goFullscreen(); return true;
case SDLK_RETURN:
if(mod & KMOD_RALT)
{
onFullscreen();
goFullscreen();
return true;
}
else if(mod & TIC_MOD_CTRL)
Expand Down
1 change: 1 addition & 0 deletions src/studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ void gotoCode();
void gotoSurf();
void exitFromGameMenu();
void runProject();
void goFullscreen();
67 changes: 42 additions & 25 deletions src/tic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,44 +1377,61 @@ static void api_tick(tic_mem* memory, tic_tick_data* data)

if(!machine->state.initialized)
{
cart2ram(memory);

const char* code = machine->memory.cart.code.data;
char* code = malloc(sizeof(tic_code));

if(strlen(code))
if(code)
{
memory->input = compareMetatag(code, "input", "mouse") ? tic_mouse_input : tic_gamepad_input;
memcpy(code, machine->memory.cart.code.data, sizeof(tic_code));

if(memory->input == tic_mouse_input)
memory->ram.vram.vars.mask.data = 0;
if(data->preprocessor)
data->preprocessor(data->data, code);

memory->script = tic_script_lua;
bool done = false;

if (isMoonscript(code))
if(strlen(code))
{
if(!initMoonscript(machine, code))
return;
cart2ram(memory);
memory->input = compareMetatag(code, "input", "mouse") ? tic_mouse_input : tic_gamepad_input;

if(memory->input == tic_mouse_input)
memory->ram.vram.vars.mask.data = 0;

memory->script = tic_script_lua;

memory->script = tic_script_moon;
if (isMoonscript(code))
{
if(initMoonscript(machine, code))
{
memory->script = tic_script_moon;
done = true;
}
}
else if(isJavascript(code))
{
if(initJavascript(machine, code))
{
memory->script = tic_script_js;
done = true;
}
}
else if(initLua(machine, code))
done = true;
}
else if(isJavascript(code))
else
{
if(!initJavascript(machine, code))
return;
machine->data->error(machine->data->data, "the code is empty");
}

free(code);

memory->script = tic_script_js;
if(done)
{
machine->state.scanline = memory->script == tic_script_js ? callJavascriptScanline : callLuaScanline;
machine->state.initialized = true;
}
else if(!initLua(machine, code))
return;
else 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;
}

memory->script == tic_script_js
Expand Down
2 changes: 1 addition & 1 deletion src/tic.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#define TIC_VERSION_MAJOR 0
#define TIC_VERSION_MINOR 50
#define TIC_VERSION_PATCH 0
#define TIC_VERSION_PATCH 1
#define TIC_VERSION_STATUS ""

#if defined(TIC80_PRO)
Expand Down
2 changes: 2 additions & 0 deletions src/ticapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ typedef struct
u64 (*freq)();
u64 start;

void (*preprocessor)(void* data, char* dst);

void* data;
} tic_tick_data;

Expand Down

0 comments on commit 6aad6d8

Please sign in to comment.