changed params order for sync() api - section,bank,tocart

added 'pal' section to sync()
This commit is contained in:
BADIM-PC\Vadim 2017-12-15 16:01:51 +03:00
parent f87414d050
commit c20fa09c0f
4 changed files with 32 additions and 12 deletions

View File

@ -675,10 +675,25 @@ 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 <PALETTE>\n", comment);
const char* ptr = SDL_strstr(project, tagbuf);

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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)