added sections/banks to SYNC api

This commit is contained in:
BADIM-PC\Vadim 2017-12-14 10:54:23 +03:00
parent e956330af1
commit 62a64515ef
6 changed files with 36 additions and 21 deletions

View File

@ -1978,7 +1978,7 @@ static void onConsoleResumeCommand(Console* console, const char* param)
commandDone(console);
console->tic->api.resume(console->tic);
console->tic->api.sync(console->tic, false);
console->tic->api.sync(console->tic, tic_bank_all, 0, false);
setStudioMode(TIC_RUN_MODE);
}

View File

@ -705,7 +705,7 @@ static duk_ret_t duk_sync(duk_context* duk)
bool toCart = duk_is_null_or_undefined(duk, 0) ? true : duk_to_boolean(duk, 0);
memory->api.sync(memory, toCart);
memory->api.sync(memory, tic_bank_all, 0, toCart);
return 0;
}

View File

@ -752,7 +752,7 @@ static s32 lua_sync(lua_State* lua)
if(lua_gettop(lua) >= 1)
toCart = lua_toboolean(lua, 1);
memory->api.sync(memory, toCart);
memory->api.sync(memory, tic_bank_all, 0, toCart);
return 0;
}

View File

@ -26,6 +26,7 @@
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <stddef.h>
#include "ticapi.h"
#include "tools.h"
@ -1322,29 +1323,31 @@ static void initCover(tic_mem* tic)
}
}
static void api_sync(tic_mem* tic, bool toCart)
static void api_sync(tic_mem* tic, tic_bank_section section, s32 bank, bool toCart)
{
if(toCart)
static const struct {s32 cart; s32 ram; s32 size;} Offsets[TIC_BANK_SECTIONS] =
{
memcpy(&tic->cart.bank.tiles, &tic->ram.tiles, sizeof(tic_tiles));
memcpy(&tic->cart.bank.sprites, &tic->ram.sprites, sizeof(tic_tiles));
memcpy(&tic->cart.bank.map, &tic->ram.map, sizeof(tic_map));
memcpy(&tic->cart.bank.sfx, &tic->ram.sfx, sizeof(tic_sfx));
memcpy(&tic->cart.bank.music, &tic->ram.music, sizeof(tic_music));
}
else
{
memcpy(&tic->ram.tiles, &tic->cart.bank.tiles, sizeof(tic_tiles));
memcpy(&tic->ram.sprites, &tic->cart.bank.sprites, sizeof(tic_tiles));
memcpy(&tic->ram.map, &tic->cart.bank.map, sizeof(tic_map));
memcpy(&tic->ram.sfx, &tic->cart.bank.sfx, sizeof(tic_sfx));
memcpy(&tic->ram.music, &tic->cart.bank.music, sizeof(tic_music));
}
{offsetof(tic_cartridge, bank.tiles), offsetof(tic_ram, tiles), sizeof(tic_tiles)},
{offsetof(tic_cartridge, bank.sprites), offsetof(tic_ram, sprites), sizeof(tic_tiles)},
{offsetof(tic_cartridge, bank.map), offsetof(tic_ram, map), sizeof(tic_map)},
{offsetof(tic_cartridge, bank.sfx), offsetof(tic_ram, sfx), sizeof(tic_sfx)},
{offsetof(tic_cartridge, bank.palette), offsetof(tic_ram, vram.palette), sizeof(tic_palette)},
};
assert(bank >= 0 && bank < TIC_BANKS);
s32 bankOffset = bank * sizeof(tic_bank);
for(s32 i = 0; i < TIC_BANK_SECTIONS; i++)
if(section & (1 << i))
toCart
? memcpy((u8*)&tic->cart + Offsets[i].cart + bankOffset, (u8*)&tic->ram + Offsets[i].ram, Offsets[i].size)
: memcpy((u8*)&tic->ram + Offsets[i].ram, (u8*)&tic->cart + Offsets[i].cart + bankOffset, Offsets[i].size);
}
static void cart2ram(tic_mem* memory)
{
api_sync(memory, false);
api_sync(memory, tic_bank_all, 0, false);
initCover(memory);
}

View File

@ -108,6 +108,7 @@
#define TIC_CODE_SIZE (0x10000)
#define TIC_BANKS 8
#define TIC_BANK_SECTIONS 5
#define SFX_NOTES {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"}
@ -326,6 +327,17 @@ typedef struct
tic_tile data[TIC_BANK_SPRITES];
} tic_tiles;
typedef enum
{
tic_bank_tiles = 1 << 0,
tic_bank_sprites = 1 << 1,
tic_bank_map = 1 << 2,
tic_bank_sfx = 1 << 3,
tic_bank_music = 1 << 4,
tic_bank_palette = 1 << 5,
tic_bank_all = (1 << (TIC_BANK_SECTIONS+1)) - 1,
} tic_bank_section;
typedef struct
{
tic_tiles tiles;

View File

@ -103,7 +103,7 @@ typedef struct
void (*reset) (tic_mem* memory);
void (*pause) (tic_mem* memory);
void (*resume) (tic_mem* memory);
void (*sync) (tic_mem* memory, bool toCart);
void (*sync) (tic_mem* memory, tic_bank_section section, s32 bank, bool toCart);
u32 (*btnp) (tic_mem* memory, s32 id, s32 hold, s32 period);
void (*load) (tic_cartridge* rom, s32 cartSize, const u8* buffer, s32 size, bool palette);