From c20fa09c0f8e04f1cf832158e2722c013cc6b7a1 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 15 Dec 2017 16:01:51 +0300 Subject: [PATCH] changed params order for sync() api - section,bank,tocart added 'pal' section to sync() --- src/console.c | 19 +++++++++++++++++-- src/jsapi.c | 6 +++--- src/luaapi.c | 8 ++++---- src/tic.c | 11 ++++++++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/console.c b/src/console.c index ccf897e..6f2a21e 100644 --- a/src/console.c +++ b/src/console.c @@ -675,16 +675,31 @@ static bool loadTextSection(const char* project, const char* comment, char* dst, { char tagbuf[64]; + char tag[16]; for(s32 i = 0; i < COUNT_OF(BinarySections); i++) { - sprintf(tagbuf, "\n%s <%s>\n", comment, BinarySections[i].tag); + for(s32 b = 0; b < TIC_BANKS; b++) + { + makeTag(BinarySections[i].tag, tag, b); + + sprintf(tagbuf, "\n%s <%s>\n", comment, tag); + + const char* ptr = SDL_strstr(project, tagbuf); + + if(ptr && ptr < end) + end = ptr; + } + } + + { + sprintf(tagbuf, "\n%s \n", comment); const char* ptr = SDL_strstr(project, tagbuf); if(ptr && ptr < end) end = ptr; - } + } } if(end > start) diff --git a/src/jsapi.c b/src/jsapi.c index 2b92673..3289671 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -703,9 +703,9 @@ static duk_ret_t duk_sync(duk_context* duk) { tic_mem* memory = (tic_mem*)getDukMachine(duk); - bool toCart = duk_is_null_or_undefined(duk, 0) ? true : duk_to_boolean(duk, 0); - const char* section = duk_is_null_or_undefined(duk, 1) ? NULL : duk_to_string(duk, 1); - s32 bank = duk_is_null_or_undefined(duk, 2) ? 0 : duk_to_int(duk, 2); + const char* section = duk_is_null_or_undefined(duk, 0) ? NULL : duk_to_string(duk, 0); + s32 bank = duk_is_null_or_undefined(duk, 1) ? 0 : duk_to_int(duk, 1); + bool toCart = duk_is_null_or_undefined(duk, 2) ? false : duk_to_boolean(duk, 2); if(bank >= 0 && bank < TIC_BANKS) memory->api.sync(memory, section, bank, toCart); diff --git a/src/luaapi.c b/src/luaapi.c index 67644ad..e6d7359 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -747,21 +747,21 @@ static s32 lua_sync(lua_State* lua) { tic_mem* memory = (tic_mem*)getLuaMachine(lua); - bool toCart = true; + bool toCart = false; const char* section = NULL; s32 bank = 0; if(lua_gettop(lua) >= 1) { - toCart = lua_toboolean(lua, 1); + section = lua_tostring(lua, 1); if(lua_gettop(lua) >= 2) { - section = lua_tostring(lua, 2); + bank = getLuaNumber(lua, 2); if(lua_gettop(lua) >= 3) { - bank = getLuaNumber(lua, 3); + toCart = lua_toboolean(lua, 3); } } } diff --git a/src/tic.c b/src/tic.c index 1e34f94..65c49b0 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1328,7 +1328,7 @@ static void initCover(tic_mem* tic) static void api_sync(tic_mem* tic, const char* section, s32 bank, bool toCart) { - static const struct {const char* name; s32 cart; s32 ram; s32 size;} Sections[] = + static const struct {const char* name; s32 bank; s32 ram; s32 size;} Sections[] = { {"tiles", offsetof(tic_bank, tiles), offsetof(tic_ram, tiles), sizeof(tic_tiles)}, {"sprites", offsetof(tic_bank, sprites), offsetof(tic_ram, sprites), sizeof(tic_tiles)}, @@ -1343,9 +1343,14 @@ static void api_sync(tic_mem* tic, const char* section, s32 bank, bool toCart) { if(section == NULL || (section && strcmp(section, Sections[i].name) == 0)) toCart - ? memcpy((u8*)&tic->cart.banks[bank] + Sections[i].cart, (u8*)&tic->ram + Sections[i].ram, Sections[i].size) - : memcpy((u8*)&tic->ram + Sections[i].ram, (u8*)&tic->cart.banks[bank] + Sections[i].cart, Sections[i].size); + ? memcpy((u8*)&tic->cart.banks[bank] + Sections[i].bank, (u8*)&tic->ram + Sections[i].ram, Sections[i].size) + : memcpy((u8*)&tic->ram + Sections[i].ram, (u8*)&tic->cart.banks[bank] + Sections[i].bank, Sections[i].size); } + + if(section == NULL || (section && strcmp(section, "pal") == 0)) + toCart + ? memcpy(&tic->cart.palette, &tic->ram.vram.palette, sizeof(tic_palette)) + : memcpy(&tic->ram.vram.palette, &tic->cart.palette, sizeof(tic_palette)); } static void cart2ram(tic_mem* memory)