From 62a64515efa4640aa942c66174776b9ba0eb38f6 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 10:54:23 +0300 Subject: [PATCH 01/11] added sections/banks to SYNC api --- src/console.c | 2 +- src/jsapi.c | 2 +- src/luaapi.c | 2 +- src/tic.c | 37 ++++++++++++++++++++----------------- src/tic.h | 12 ++++++++++++ src/ticapi.h | 2 +- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/console.c b/src/console.c index 7e0e940..1e07b33 100644 --- a/src/console.c +++ b/src/console.c @@ -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); } diff --git a/src/jsapi.c b/src/jsapi.c index 8889bc3..c21485f 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -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; } diff --git a/src/luaapi.c b/src/luaapi.c index 13453e5..83510eb 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -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; } diff --git a/src/tic.c b/src/tic.c index 8245d9d..b2facdb 100644 --- a/src/tic.c +++ b/src/tic.c @@ -26,6 +26,7 @@ #include #include #include +#include #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); } diff --git a/src/tic.h b/src/tic.h index 777cd7f..b1263fe 100644 --- a/src/tic.h +++ b/src/tic.h @@ -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; diff --git a/src/ticapi.h b/src/ticapi.h index 75d9e3a..13572fd 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -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); From 6e8a478ee93157781f453b1b0b72ee9d1ba74b4c Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 11:50:50 +0300 Subject: [PATCH 02/11] lua/js sync impl --- src/console.c | 2 +- src/jsapi.c | 9 +++++++-- src/luaapi.c | 21 +++++++++++++++++++-- src/tic.c | 27 +++++++++++++++------------ src/tic.h | 12 ------------ src/ticapi.h | 2 +- 6 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/console.c b/src/console.c index 1e07b33..eca851e 100644 --- a/src/console.c +++ b/src/console.c @@ -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, tic_bank_all, 0, false); + console->tic->api.sync(console->tic, NULL, 0, false); setStudioMode(TIC_RUN_MODE); } diff --git a/src/jsapi.c b/src/jsapi.c index c21485f..03133f3 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -704,8 +704,13 @@ 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); - memory->api.sync(memory, tic_bank_all, 0, toCart); + if(bank >= 0 && bank < TIC_BANKS) + memory->api.sync(memory, section, bank, toCart); + else + duk_error(duk, DUK_ERR_ERROR, "sync() error, invalid bank"); return 0; } @@ -747,7 +752,7 @@ static const struct{duk_c_function func; s32 params;} ApiFunc[] = {duk_textri,14}, {duk_clip, 4}, {duk_music, 4}, - {duk_sync, 1}, + {duk_sync, 3}, }; static void initDuktape(tic_machine* machine) diff --git a/src/luaapi.c b/src/luaapi.c index 83510eb..4c3cab9 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -748,11 +748,28 @@ static s32 lua_sync(lua_State* lua) tic_mem* memory = (tic_mem*)getLuaMachine(lua); bool toCart = true; - + const char* section = NULL; + s32 bank = 0; + if(lua_gettop(lua) >= 1) + { toCart = lua_toboolean(lua, 1); - memory->api.sync(memory, tic_bank_all, 0, toCart); + if(lua_gettop(lua) >= 2) + { + section = lua_tostring(lua, 2); + + if(lua_gettop(lua) >= 3) + { + bank = getLuaNumber(lua, 3); + } + } + } + + if(bank >= 0 && bank < TIC_BANKS) + memory->api.sync(memory, section, bank, toCart); + else + luaL_error(lua, "sync() error, invalid bank"); return 0; } diff --git a/src/tic.c b/src/tic.c index b2facdb..c4369e2 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1323,31 +1323,34 @@ static void initCover(tic_mem* tic) } } -static void api_sync(tic_mem* tic, tic_bank_section section, s32 bank, bool toCart) +static void api_sync(tic_mem* tic, const char* section, s32 bank, bool toCart) { - static const struct {s32 cart; s32 ram; s32 size;} Offsets[TIC_BANK_SECTIONS] = + static const struct {const char* name; s32 cart; s32 ram; s32 size;} Sections[] = { - {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)}, + {"tiles", offsetof(tic_cartridge, bank.tiles), offsetof(tic_ram, tiles), sizeof(tic_tiles)}, + {"sprites", offsetof(tic_cartridge, bank.sprites), offsetof(tic_ram, sprites), sizeof(tic_tiles)}, + {"map", offsetof(tic_cartridge, bank.map), offsetof(tic_ram, map), sizeof(tic_map)}, + {"sfx", offsetof(tic_cartridge, bank.sfx), offsetof(tic_ram, sfx), sizeof(tic_sfx)}, + {"music", offsetof(tic_cartridge, bank.music), offsetof(tic_ram, music), sizeof(tic_music)}, + {"pal", 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)) + for(s32 i = 0; i < COUNT_OF(Sections); i++) + { + if(section == NULL || (section && strcmp(section, Sections[i].name) == 0)) 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); + ? memcpy((u8*)&tic->cart + Sections[i].cart + bankOffset, (u8*)&tic->ram + Sections[i].ram, Sections[i].size) + : memcpy((u8*)&tic->ram + Sections[i].ram, (u8*)&tic->cart + Sections[i].cart + bankOffset, Sections[i].size); + } } static void cart2ram(tic_mem* memory) { - api_sync(memory, tic_bank_all, 0, false); + api_sync(memory, NULL, 0, false); initCover(memory); } diff --git a/src/tic.h b/src/tic.h index b1263fe..777cd7f 100644 --- a/src/tic.h +++ b/src/tic.h @@ -108,7 +108,6 @@ #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-"} @@ -327,17 +326,6 @@ 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; diff --git a/src/ticapi.h b/src/ticapi.h index 13572fd..cc08966 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -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, tic_bank_section section, s32 bank, bool toCart); + void (*sync) (tic_mem* memory, const char* 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); From d2daa0a65330f7d59090f7b164366b811775c778 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 14:38:06 +0300 Subject: [PATCH 03/11] code banks switching --- src/code.c | 6 +++--- src/code.h | 2 +- src/studio.c | 48 ++++++++++++++++++++++++++++++++++-------------- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/code.c b/src/code.c index 96e218d..ef81dab 100644 --- a/src/code.c +++ b/src/code.c @@ -1827,7 +1827,7 @@ static void onStudioEvent(Code* code, StudioEvent event) } } -void initCode(Code* code, tic_mem* tic) +void initCode(Code* code, tic_mem* tic, tic_code* src) { if(code->outline.items == NULL) code->outline.items = (OutlineItem*)SDL_malloc(OUTLINE_ITEMS_SIZE); @@ -1838,10 +1838,10 @@ void initCode(Code* code, tic_mem* tic) *code = (Code) { .tic = tic, - .data = getBankCode()->data, + .data = src->data, .tick = tick, .escape = escape, - .cursor = {{getBankCode()->data, NULL, 0, 0}, NULL, 0}, + .cursor = {{src->data, NULL, 0, 0}, NULL, 0}, .rect = {0, TOOLBAR_SIZE + 1, TIC80_WIDTH, TIC80_HEIGHT - TOOLBAR_SIZE - TIC_FONT_HEIGHT - 1}, .scroll = {0, 0, {0, 0}, false}, .tickCounter = 0, diff --git a/src/code.h b/src/code.h index c05ffba..a05bad7 100644 --- a/src/code.h +++ b/src/code.h @@ -105,4 +105,4 @@ struct Code void(*update)(Code*); }; -void initCode(Code*, tic_mem*); +void initCode(Code*, tic_mem*, tic_code* src); diff --git a/src/studio.c b/src/studio.c index 8c73fcf..64153ce 100644 --- a/src/studio.c +++ b/src/studio.c @@ -201,7 +201,7 @@ static struct Start* start; Console* console; Run* run; - Code* code; + Code* code[TIC_BANKS]; Sprite* sprite; Map* map; World* world; @@ -790,7 +790,12 @@ void setStudioEvent(StudioEvent event) { switch(studio.mode) { - case TIC_CODE_MODE: studio.code->event(studio.code, event); break; + case TIC_CODE_MODE: + { + Code* code = studio.code[studio.bank.index.code]; + code->event(code, event); + } + break; case TIC_SPRITE_MODE: studio.sprite->event(studio.sprite, event); break; case TIC_MAP_MODE: studio.map->event(studio.map, event); break; case TIC_SFX_MODE: studio.sfx->event(studio.sfx, event); break; @@ -1062,7 +1067,7 @@ void hideDialog() if(studio.dialogMode == TIC_RUN_MODE) { studio.tic->api.resume(studio.tic); - studio.mode = TIC_RUN_MODE; + studio.mode = TIC_RUN_MODE; } else setStudioMode(studio.dialogMode); } @@ -1079,7 +1084,9 @@ void showDialog(const char** text, s32 rows, DialogCallback callback, void* data static void initModules() { - initCode(studio.code, studio.tic); + for(s32 i = 0; i < TIC_BANKS; i++) + initCode(studio.code[i], studio.tic, &studio.tic->cart.banks[i].code); + initSprite(studio.sprite, studio.tic); initMap(studio.map, studio.tic); initWorldMap(); @@ -1784,9 +1791,11 @@ static bool processShortcuts(SDL_KeyboardEvent* event) case SDLK_ESCAPE: case SDLK_AC_BACK: { - if(studio.mode == TIC_CODE_MODE && studio.code->mode != TEXT_EDIT_MODE) + Code* code = studio.code[studio.bank.index.code]; + + if(studio.mode == TIC_CODE_MODE && code->mode != TEXT_EDIT_MODE) { - studio.code->escape(studio.code); + code->escape(code); return true; } @@ -1920,9 +1929,10 @@ SDL_Event* pollEvent() #endif { - studio.console->codeLiveReload.reload(studio.console, studio.code->data); - if(studio.console->codeLiveReload.active && studio.code->update) - studio.code->update(studio.code); + Code* code = studio.code[studio.bank.index.code]; + studio.console->codeLiveReload.reload(studio.console, code->data); + if(studio.console->codeLiveReload.active && code->update) + code->update(code); } break; } @@ -2280,7 +2290,12 @@ static void renderStudio() case TIC_START_MODE: studio.start->tick(studio.start); break; case TIC_CONSOLE_MODE: studio.console->tick(studio.console); break; case TIC_RUN_MODE: studio.run->tick(studio.run); break; - case TIC_CODE_MODE: studio.code->tick(studio.code); break; + case TIC_CODE_MODE: + { + Code* code = studio.code[studio.bank.index.code]; + code->tick(code); + } + break; case TIC_SPRITE_MODE: studio.sprite->tick(studio.sprite); break; case TIC_MAP_MODE: studio.map->tick(studio.map); break; case TIC_WORLD_MODE: studio.world->tick(studio.world); break; @@ -2476,8 +2491,9 @@ static void updateSystemFont() void studioConfigChanged() { - if(studio.code->update) - studio.code->update(studio.code); + Code* code = studio.code[studio.bank.index.code]; + if(code->update) + code->update(code); initTouchGamepad(); updateSystemFont(); @@ -2560,10 +2576,12 @@ static void onFSInitialized(FileSystem* fs) studio.tic = studio.tic80local->memory; { + for(s32 i = 0; i < TIC_BANKS; i++) + studio.code[i] = SDL_malloc(sizeof(Code)); + studio.start = SDL_malloc(sizeof(Start)); studio.console = SDL_malloc(sizeof(Console)); studio.run = SDL_malloc(sizeof(Run)); - studio.code = SDL_malloc(sizeof(Code)); studio.sprite = SDL_malloc(sizeof(Sprite)); studio.map = SDL_malloc(sizeof(Map)); studio.world = SDL_malloc(sizeof(World)); @@ -2668,10 +2686,12 @@ s32 main(s32 argc, char **argv) #endif { + for(s32 i = 0; i < TIC_BANKS; i++) + SDL_free(studio.code[i]); + SDL_free(studio.start); SDL_free(studio.console); SDL_free(studio.run); - SDL_free(studio.code); SDL_free(studio.sprite); SDL_free(studio.map); SDL_free(studio.world); From 2242873d8843d516d8504d7ed4385a32c9ccdc77 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 14:40:06 +0300 Subject: [PATCH 04/11] no message --- src/studio.c | 5 ----- src/studio.h | 1 - 2 files changed, 6 deletions(-) diff --git a/src/studio.c b/src/studio.c index 64153ce..aea4907 100644 --- a/src/studio.c +++ b/src/studio.c @@ -335,11 +335,6 @@ tic_music* getBankMusic() return &studio.tic->cart.banks[studio.bank.index.music].music; } -tic_code* getBankCode() -{ - return &studio.tic->cart.banks[studio.bank.index.code].code; -} - tic_palette* getBankPalette() { return &studio.tic->cart.banks[studio.bank.index.tiles].palette; diff --git a/src/studio.h b/src/studio.h index 33f7bae..f32ee6a 100644 --- a/src/studio.h +++ b/src/studio.h @@ -205,5 +205,4 @@ tic_tiles* getBankSprites(); tic_map* getBankMap(); tic_sfx* getBankSfx(); tic_music* getBankMusic(); -tic_code* getBankCode(); tic_palette* getBankPalette(); From ebd40d5e749eaffc2160da23d6e8dcf9ef238352 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 14:53:47 +0300 Subject: [PATCH 05/11] code loads from all the banks on the game start --- .gitignore | 1 + src/config.c | 4 ++-- src/console.c | 8 ++++---- src/dialog.c | 2 +- src/menu.c | 4 ++-- src/music.c | 2 +- src/studio.c | 22 +++++++++++----------- src/surf.c | 12 ++++++------ src/tic.c | 18 +++++++++++++----- src/tic80.c | 2 +- src/ticapi.h | 4 ++-- 11 files changed, 44 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 2358e1c..d49ead5 100644 --- a/.gitignore +++ b/.gitignore @@ -92,3 +92,4 @@ build/windows/tic80/Release Pro/ build/windows/zlib/Debug Pro/ build/windows/zlib/Release Pro/ build/windows/example/Release Pro/ +build/windows/example/Debug Pro/ diff --git a/src/config.c b/src/config.c index 7a6c543..9adb386 100644 --- a/src/config.c +++ b/src/config.c @@ -170,7 +170,7 @@ static void readConfig(Config* config) if(lua) { - if(luaL_loadstring(lua, config->tic->config.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK) + if(luaL_loadstring(lua, config->tic->config.bank.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK) { readConfigVideoLength(config, lua); readConfigVideoScale(config, lua); @@ -185,7 +185,7 @@ static void readConfig(Config* config) static void update(Config* config, const u8* buffer, size_t size) { - config->tic->api.load((tic_cartridge*)&config->tic->config, sizeof(tic_bank), buffer, size, true); + config->tic->api.load(&config->tic->config, buffer, size, true); readConfig(config); studioConfigChanged(); diff --git a/src/console.c b/src/console.c index eca851e..ab8b36e 100644 --- a/src/console.c +++ b/src/console.c @@ -303,10 +303,10 @@ static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s static void loadCart(tic_mem* tic, tic_cartridge* cart, const u8* buffer, s32 size, bool palette) { - tic->api.load(cart, sizeof(tic_cartridge), buffer, size, palette); + tic->api.load(cart, buffer, size, palette); if(!palette) - memcpy(cart->bank.palette.data, tic->config.palette.data, sizeof(tic_palette)); + memcpy(cart->bank.palette.data, tic->config.bank.palette.data, sizeof(tic_palette)); } static bool loadRom(tic_mem* tic, const void* data, s32 size, bool palette) @@ -734,7 +734,7 @@ static bool loadProject(Console* console, const char* name, const char* data, s3 if(cart) { SDL_memset(cart, 0, sizeof(tic_cartridge)); - SDL_memcpy(&cart->bank.palette, &tic->config.palette.data, sizeof(tic_palette)); + SDL_memcpy(&cart->bank.palette, &tic->config.bank.palette.data, sizeof(tic_palette)); const char* comment = projectComment(name); @@ -2886,7 +2886,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, if(argc > 1) { - memcpy(console->embed.file->bank.palette.data, tic->config.palette.data, sizeof(tic_palette)); + memcpy(console->embed.file->bank.palette.data, tic->config.bank.palette.data, sizeof(tic_palette)); u32 argp = 1; diff --git a/src/dialog.c b/src/dialog.c index e28b224..a61c16b 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -170,7 +170,7 @@ static void drawDialog(Dialog* dlg) { u8 chromakey = 14; - tic->api.sprite_ex(tic, &tic->config.tiles, 2, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank.tiles, 2, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); } { diff --git a/src/menu.c b/src/menu.c index 0e38308..935ce3a 100644 --- a/src/menu.c +++ b/src/menu.c @@ -124,7 +124,7 @@ static void drawDialog(Menu* menu) { u8 chromakey = 14; - tic->api.sprite_ex(tic, &tic->config.tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank.tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); } } @@ -209,7 +209,7 @@ static void drawPlayerButtons(Menu* menu, s32 x, s32 y) if(menu->gamepad.selected == index && menu->ticks % TIC_FRAMERATE < TIC_FRAMERATE / 2) continue; - tic->api.sprite_ex(tic, &tic->config.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); s32 code = codes[index]; char label[32]; diff --git a/src/music.c b/src/music.c index a2325a7..7672eb4 100644 --- a/src/music.c +++ b/src/music.c @@ -1327,7 +1327,7 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index) } u8 color = Chroma; - tic->api.sprite(tic, &tic->config.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1); + tic->api.sprite(tic, &tic->config.bank.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1); } static void drawTracker(Music* music, s32 x, s32 y) diff --git a/src/studio.c b/src/studio.c index aea4907..585c597 100644 --- a/src/studio.c +++ b/src/studio.c @@ -342,7 +342,7 @@ tic_palette* getBankPalette() void playSystemSfx(s32 id) { - const tic_sound_effect* effect = &studio.tic->config.sfx.data[id]; + const tic_sound_effect* effect = &studio.tic->config.bank.sfx.data[id]; studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0); } @@ -1976,7 +1976,7 @@ static void transparentBlit(u32* out, s32 pitch) { const u8* in = studio.tic->ram.vram.screen.data; const u8* end = in + sizeof(studio.tic->ram.vram.screen); - const u32* pal = tic_palette_blit(&studio.tic->config.palette); + const u32* pal = tic_palette_blit(&studio.tic->config.bank.palette); const u32 Delta = (pitch/sizeof *out - TIC80_WIDTH); s32 col = 0; @@ -2053,7 +2053,7 @@ static void recordFrame(u32* pixels) if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2) { - const u32* pal = tic_palette_blit(&studio.tic->config.palette); + const u32* pal = tic_palette_blit(&studio.tic->config.bank.palette); drawRecordLabel(pixels, TIC80_FULLWIDTH, TIC80_WIDTH-24, 8, &pal[tic_color_red]); } @@ -2214,12 +2214,12 @@ static void renderCursor() SDL_ShowCursor(getConfig()->theme.cursor.sprite >= 0 ? SDL_DISABLE : SDL_ENABLE); if(getConfig()->theme.cursor.sprite >= 0) - blitCursor(studio.tic->config.tiles.data[getConfig()->theme.cursor.sprite].data); + blitCursor(studio.tic->config.bank.tiles.data[getConfig()->theme.cursor.sprite].data); } static void useSystemPalette() { - memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.palette.data, sizeof(tic_palette)); + memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.bank.palette.data, sizeof(tic_palette)); } static void drawPopup() @@ -2269,8 +2269,8 @@ static void renderStudio() case TIC_DIALOG_MODE: case TIC_MENU_MODE: case TIC_SURF_MODE: - sfx = &studio.tic->config.sfx; - music = &studio.tic->config.music; + sfx = &studio.tic->config.bank.sfx; + music = &studio.tic->config.bank.music; break; default: sfx = getBankSfx(); @@ -2453,7 +2453,7 @@ static void initTouchGamepad() if (!studio.renderer) return; - studio.tic->api.map(studio.tic, &studio.tic->config.map, &studio.tic->config.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); + studio.tic->api.map(studio.tic, &studio.tic->config.bank.map, &studio.tic->config.bank.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); if(!studio.gamepad.texture) { @@ -2480,7 +2480,7 @@ static void updateSystemFont() for(s32 i = 0; i < TIC_FONT_CHARS; i++) for(s32 y = 0; y < TIC_SPRITESIZE; y++) for(s32 x = 0; x < TIC_SPRITESIZE; x++) - if(tic_tool_peek4(&studio.tic->config.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1)) + if(tic_tool_peek4(&studio.tic->config.bank.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1)) studio.tic->font.data[i*BITS_IN_BYTE+y] |= 1 << x; } @@ -2501,12 +2501,12 @@ static void setWindowIcon() u32* pixels = SDL_malloc(Size * Size * sizeof(u32)); - const u32* pal = tic_palette_blit(&studio.tic->config.palette); + const u32* pal = tic_palette_blit(&studio.tic->config.bank.palette); for(s32 j = 0, index = 0; j < Size; j++) for(s32 i = 0; i < Size; i++, index++) { - u8 color = getSpritePixel(studio.tic->config.tiles.data, i/Scale, j/Scale); + u8 color = getSpritePixel(studio.tic->config.bank.tiles.data, i/Scale, j/Scale); pixels[index] = color == ColorKey ? 0 : pal[color]; } diff --git a/src/surf.c b/src/surf.c index 1320ea5..e89c72b 100644 --- a/src/surf.c +++ b/src/surf.c @@ -202,14 +202,14 @@ static void drawTopToolbar(Surf* surf, s32 x, s32 y) enum{Gap = 10, TipX = 150, SelectWidth = 54}; u8 colorkey = 0; - tic->api.sprite_ex(tic, &tic->config.tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank.tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "SELECT"; tic->api.text(tic, Label, TipX + Gap, y+3, tic_color_black); tic->api.text(tic, Label, TipX + Gap, y+2, tic_color_white); } - tic->api.sprite_ex(tic, &tic->config.tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank.tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "BACK"; tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); @@ -244,7 +244,7 @@ static void drawBottomToolbar(Surf* surf, s32 x, s32 y) u8 colorkey = 0; - tic->api.sprite_ex(tic, &tic->config.tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank.tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "WEBSITE"; tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); @@ -355,7 +355,7 @@ static void drawBG(Surf* surf) for(s32 j = 0; j < Height + 1; j++) for(s32 i = 0; i < Width + 1; i++) if(counter++ % 2) - tic->api.sprite_ex(tic, &tic->config.tiles, 34, i*Size - offset, j*Size - offset, 2, 2, 0, 0, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank.tiles, 34, i*Size - offset, j*Size - offset, 2, 2, 0, 0, 1, tic_no_flip, tic_no_rotate); } static void replace(char* src, const char* what, const char* with) @@ -508,7 +508,7 @@ static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size) { const gif_color* c = &image->palette[image->buffer[i]]; tic_rgb rgb = { c->r, c->g, c->b }; - u8 color = tic_tool_find_closest_color(tic->config.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(tic->config.bank.palette.colors, &rgb); tic_tool_poke4(item->cover->data, i, color); } } @@ -538,7 +538,7 @@ static void loadCover(Surf* surf) if(hasExt(item->name, PROJECT_LUA_EXT)) surf->console->loadProject(surf->console, item->name, data, size, cart); else - tic->api.load(cart, sizeof(tic_cartridge), data, size, true); + tic->api.load(cart, data, size, true); if(cart->cover.size) updateMenuItemCover(surf, cart->cover.data, cart->cover.size); diff --git a/src/tic.c b/src/tic.c index c4369e2..b2f3de9 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1472,12 +1472,20 @@ static void api_tick(tic_mem* memory, tic_tick_data* data) if(!machine->state.initialized) { - - char* code = malloc(sizeof(tic_code)); + enum{CodeSize = sizeof(tic_code) * TIC_BANKS}; + char* code = malloc(CodeSize); if(code) { - memcpy(code, machine->memory.cart.bank.code.data, sizeof(tic_code)); + memset(code, 0, CodeSize); + + for(s32 i = TIC_BANKS - 1; i >= 0; i--) + { + const char* bankCode = memory->cart.banks[i].code.data; + + if(strlen(bankCode)) + strcat(code, bankCode); + } if(data->preprocessor) data->preprocessor(data->data, code); @@ -1579,10 +1587,10 @@ static u32 api_btnp(tic_mem* tic, s32 index, s32 hold, s32 period) return ((~previous.data) & machine->memory.ram.vram.input.gamepad.data) & (1 << index); } -static void api_load(tic_cartridge* cart, s32 cartSize, const u8* buffer, s32 size, bool palette) +static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palette) { const u8* end = buffer + size; - memset(cart, 0, cartSize); + memset(cart, 0, sizeof(tic_cartridge)); if(palette) { diff --git a/src/tic80.c b/src/tic80.c index 7812a5a..8b1e7df 100644 --- a/src/tic80.c +++ b/src/tic80.c @@ -108,7 +108,7 @@ TIC80_API void tic80_load(tic80* tic, void* cart, s32 size) } { - tic80->memory->api.load(&tic80->memory->cart, sizeof(tic_cartridge), cart, size, true); + tic80->memory->api.load(&tic80->memory->cart, cart, size, true); tic80->memory->api.reset(tic80->memory); } } diff --git a/src/ticapi.h b/src/ticapi.h index cc08966..53188c9 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -106,7 +106,7 @@ typedef struct void (*sync) (tic_mem* memory, const char* 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); + void (*load) (tic_cartridge* rom, const u8* buffer, s32 size, bool palette); s32 (*save) (const tic_cartridge* rom, u8* buffer); void (*tick_start) (tic_mem* memory, const tic_sfx* sfx, const tic_music* music); @@ -120,7 +120,7 @@ struct tic_mem { tic_ram ram; tic_cartridge cart; - tic_bank config; + tic_cartridge config; tic_input_method input; tic_script_lang script; tic_font font; From e8cb3599df70197711174d0f3a1dbe2f99eb1341 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 14:56:45 +0300 Subject: [PATCH 06/11] no message --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 9adb386..0294598 100644 --- a/src/config.c +++ b/src/config.c @@ -219,7 +219,7 @@ static void saveConfig(Config* config, bool overwrite) if(buffer) { - s32 size = config->tic->api.save((tic_cartridge*)&config->tic->config, buffer); + s32 size = config->tic->api.save(&config->tic->config, buffer); fsSaveRootFile(config->fs, CONFIG_TIC_PATH, buffer, size, overwrite); From 4f55ed7667228637c2edad986461cc4f74646a64 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 15:05:43 +0300 Subject: [PATCH 07/11] palette excluded from bank --- src/console.c | 16 ++++++++-------- src/sprite.c | 10 +++++----- src/studio.c | 13 ++++--------- src/studio.h | 1 - src/surf.c | 2 +- src/tic.c | 13 ++++++------- src/tic.h | 2 +- 7 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/console.c b/src/console.c index ab8b36e..48fa4c9 100644 --- a/src/console.c +++ b/src/console.c @@ -289,7 +289,7 @@ static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s if(palette) { - const tic_rgb* pal = tic->cart.bank.palette.colors; + const tic_rgb* pal = tic->cart.palette.colors; for(s32 i = 0; i < TIC_PALETTE_SIZE; i++, pal++) palette[i].r = pal->r, palette[i].g = pal->g, palette[i].b = pal->b; @@ -306,7 +306,7 @@ static void loadCart(tic_mem* tic, tic_cartridge* cart, const u8* buffer, s32 si tic->api.load(cart, buffer, size, palette); if(!palette) - memcpy(cart->bank.palette.data, tic->config.bank.palette.data, sizeof(tic_palette)); + memcpy(cart->palette.data, tic->config.palette.data, sizeof(tic_palette)); } static bool loadRom(tic_mem* tic, const void* data, s32 size, bool palette) @@ -365,7 +365,7 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param) case 3: memcpy(&tic->cart.bank.code, &cart->bank.code, sizeof(tic_code)); break; case 4: memcpy(&tic->cart.bank.sfx, &cart->bank.sfx, sizeof(tic_sfx)); break; case 5: memcpy(&tic->cart.bank.music, &cart->bank.music, sizeof(tic_music)); break; - case 6: memcpy(&tic->cart.bank.palette, &cart->bank.palette, sizeof(tic_palette)); break; + case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof(tic_palette)); break; } studioRomLoaded(); @@ -602,7 +602,7 @@ static char* saveBinarySection(char* ptr, const char* comment, const char* tag, typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection; static const BinarySection BinarySections[] = { - {"PALETTE", 1, offsetof(tic_cartridge, bank.palette.data), sizeof(tic_palette), false}, + {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.tiles), sizeof(tic_tile), true}, {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.sprites), sizeof(tic_tile), true}, {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, bank.map), TIC_MAP_WIDTH, true}, @@ -734,7 +734,7 @@ static bool loadProject(Console* console, const char* name, const char* data, s3 if(cart) { SDL_memset(cart, 0, sizeof(tic_cartridge)); - SDL_memcpy(&cart->bank.palette, &tic->config.bank.palette.data, sizeof(tic_palette)); + SDL_memcpy(&cart->palette, &tic->config.palette.data, sizeof(tic_palette)); const char* comment = projectComment(name); @@ -1328,7 +1328,7 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v u8 src = image->buffer[x + y * image->width]; const gif_color* c = &image->palette[src]; tic_rgb rgb = {c->r, c->g, c->b}; - u8 color = tic_tool_find_closest_color(console->tic->cart.bank.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(console->tic->cart.palette.colors, &rgb); setSpritePixel(console->tic->cart.bank.tiles.data, x, y, color); } @@ -2763,7 +2763,7 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na u8 src = image->buffer[x + y * image->width]; const gif_color* c = &image->palette[src]; tic_rgb rgb = {c->r, c->g, c->b}; - u8 color = tic_tool_find_closest_color(console->embed.file->bank.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(console->embed.file->palette.colors, &rgb); setSpritePixel(console->embed.file->bank.tiles.data, x, y, color); } @@ -2886,7 +2886,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, if(argc > 1) { - memcpy(console->embed.file->bank.palette.data, tic->config.bank.palette.data, sizeof(tic_palette)); + memcpy(console->embed.file->palette.data, tic->config.palette.data, sizeof(tic_palette)); u32 argp = 1; diff --git a/src/sprite.c b/src/sprite.c index 8a9179a..97fce55 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -672,8 +672,8 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value) static void pasteColor(Sprite* sprite) { - fromClipboard(getBankPalette()->data, sizeof(tic_palette), false, true); - fromClipboard(&getBankPalette()->colors[sprite->color], sizeof(tic_rgb), false, true); + fromClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false, true); + fromClipboard(&sprite->tic->cart.palette.colors[sprite->color], sizeof(tic_rgb), false, true); } static void drawRGBTools(Sprite* sprite, s32 x, s32 y) @@ -708,7 +708,7 @@ static void drawRGBTools(Sprite* sprite, s32 x, s32 y) down = true; if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) - toClipboard(getBankPalette()->data, sizeof(tic_palette), false); + toClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false); } if(down) @@ -772,7 +772,7 @@ static void drawRGBSliders(Sprite* sprite, s32 x, s32 y) { enum{Gap = 6, Count = sizeof(tic_rgb)}; - u8* data = &getBankPalette()->data[sprite->color * Count]; + u8* data = &sprite->tic->cart.palette.data[sprite->color * Count]; for(s32 i = 0; i < Count; i++) drawRGBSlider(sprite, x, y + Gap*i, &data[i]); @@ -784,7 +784,7 @@ static void drawRGBSlidersOvr(Sprite* sprite, s32 x, s32 y) { enum{Gap = 6, Count = sizeof(tic_rgb), Size = CANVAS_SIZE, Max = 255}; - u8* data = &getBankPalette()->data[sprite->color * Count]; + u8* data = &sprite->tic->cart.palette.data[sprite->color * Count]; for(s32 i = 0; i < Count; i++) { diff --git a/src/studio.c b/src/studio.c index 585c597..5acb661 100644 --- a/src/studio.c +++ b/src/studio.c @@ -335,11 +335,6 @@ tic_music* getBankMusic() return &studio.tic->cart.banks[studio.bank.index.music].music; } -tic_palette* getBankPalette() -{ - return &studio.tic->cart.banks[studio.bank.index.tiles].palette; -} - void playSystemSfx(s32 id) { const tic_sound_effect* effect = &studio.tic->config.bank.sfx.data[id]; @@ -1976,7 +1971,7 @@ static void transparentBlit(u32* out, s32 pitch) { const u8* in = studio.tic->ram.vram.screen.data; const u8* end = in + sizeof(studio.tic->ram.vram.screen); - const u32* pal = tic_palette_blit(&studio.tic->config.bank.palette); + const u32* pal = tic_palette_blit(&studio.tic->config.palette); const u32 Delta = (pitch/sizeof *out - TIC80_WIDTH); s32 col = 0; @@ -2053,7 +2048,7 @@ static void recordFrame(u32* pixels) if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2) { - const u32* pal = tic_palette_blit(&studio.tic->config.bank.palette); + const u32* pal = tic_palette_blit(&studio.tic->config.palette); drawRecordLabel(pixels, TIC80_FULLWIDTH, TIC80_WIDTH-24, 8, &pal[tic_color_red]); } @@ -2219,7 +2214,7 @@ static void renderCursor() static void useSystemPalette() { - memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.bank.palette.data, sizeof(tic_palette)); + memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.palette.data, sizeof(tic_palette)); } static void drawPopup() @@ -2501,7 +2496,7 @@ static void setWindowIcon() u32* pixels = SDL_malloc(Size * Size * sizeof(u32)); - const u32* pal = tic_palette_blit(&studio.tic->config.bank.palette); + const u32* pal = tic_palette_blit(&studio.tic->config.palette); for(s32 j = 0, index = 0; j < Size; j++) for(s32 i = 0; i < Size; i++, index++) diff --git a/src/studio.h b/src/studio.h index f32ee6a..1115995 100644 --- a/src/studio.h +++ b/src/studio.h @@ -205,4 +205,3 @@ tic_tiles* getBankSprites(); tic_map* getBankMap(); tic_sfx* getBankSfx(); tic_music* getBankMusic(); -tic_palette* getBankPalette(); diff --git a/src/surf.c b/src/surf.c index e89c72b..83083fd 100644 --- a/src/surf.c +++ b/src/surf.c @@ -508,7 +508,7 @@ static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size) { const gif_color* c = &image->palette[image->buffer[i]]; tic_rgb rgb = { c->r, c->g, c->b }; - u8 color = tic_tool_find_closest_color(tic->config.bank.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(tic->config.palette.colors, &rgb); tic_tool_poke4(item->cover->data, i, color); } } diff --git a/src/tic.c b/src/tic.c index b2f3de9..2a20b70 100644 --- a/src/tic.c +++ b/src/tic.c @@ -145,7 +145,7 @@ static void runNoise(blip_buffer_t* blip, tic_sound_register* reg, tic_sound_reg static void resetPalette(tic_mem* memory) { static const u8 DefaultMapping[] = {16, 50, 84, 118, 152, 186, 220, 254}; - memcpy(memory->ram.vram.palette.data, memory->cart.bank.palette.data, sizeof(tic_palette)); + memcpy(memory->ram.vram.palette.data, memory->cart.palette.data, sizeof(tic_palette)); memcpy(memory->ram.vram.mapping, DefaultMapping, sizeof DefaultMapping); } @@ -1256,7 +1256,7 @@ static void api_tick_end(tic_mem* memory) machine->state.setpix = setPixelOvr; machine->state.getpix = getPixelOvr; - memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.bank.palette), sizeof machine->state.ovr.palette); + memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.palette), sizeof machine->state.ovr.palette); } @@ -1313,7 +1313,7 @@ static void initCover(tic_mem* tic) { const gif_color* c = &image->palette[image->buffer[i]]; tic_rgb rgb = { c->r, c->g, c->b }; - u8 color = tic_tool_find_closest_color(tic->cart.bank.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(tic->cart.palette.colors, &rgb); tic_tool_poke4(tic->ram.vram.screen.data, i, color); } } @@ -1332,7 +1332,6 @@ static void api_sync(tic_mem* tic, const char* section, s32 bank, bool toCart) {"map", offsetof(tic_cartridge, bank.map), offsetof(tic_ram, map), sizeof(tic_map)}, {"sfx", offsetof(tic_cartridge, bank.sfx), offsetof(tic_ram, sfx), sizeof(tic_sfx)}, {"music", offsetof(tic_cartridge, bank.music), offsetof(tic_ram, music), sizeof(tic_music)}, - {"pal", offsetof(tic_cartridge, bank.palette), offsetof(tic_ram, vram.palette), sizeof(tic_palette)}, }; assert(bank >= 0 && bank < TIC_BANKS); @@ -1595,7 +1594,7 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet if(palette) { static const u8 DB16[] = {0x14, 0x0c, 0x1c, 0x44, 0x24, 0x34, 0x30, 0x34, 0x6d, 0x4e, 0x4a, 0x4e, 0x85, 0x4c, 0x30, 0x34, 0x65, 0x24, 0xd0, 0x46, 0x48, 0x75, 0x71, 0x61, 0x59, 0x7d, 0xce, 0xd2, 0x7d, 0x2c, 0x85, 0x95, 0xa1, 0x6d, 0xaa, 0x2c, 0xd2, 0xaa, 0x99, 0x6d, 0xc2, 0xca, 0xda, 0xd4, 0x5e, 0xde, 0xee, 0xd6}; - memcpy(cart->bank.palette.data, DB16, sizeof(tic_palette)); + memcpy(cart->palette.data, DB16, sizeof(tic_palette)); } #define LOAD_CHUNK(to) memcpy(&to, buffer, min(sizeof(to), chunk.size)) @@ -1618,7 +1617,7 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet case CHUNK_PATTERNS: LOAD_CHUNK(cart->bank.music.patterns.data); break; case CHUNK_PALETTE: if(palette) - LOAD_CHUNK(cart->bank.palette); + LOAD_CHUNK(cart->palette); break; case CHUNK_COVER: LOAD_CHUNK(cart->cover.data); @@ -1685,7 +1684,7 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->bank.sfx.waveform); buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->bank.music.patterns.data); buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->bank.music.tracks.data); - buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->bank.palette); + buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette); buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size); diff --git a/src/tic.h b/src/tic.h index 777cd7f..e595374 100644 --- a/src/tic.h +++ b/src/tic.h @@ -334,7 +334,6 @@ typedef struct tic_sfx sfx; tic_music music; tic_code code; - tic_palette palette; } tic_bank; typedef struct @@ -345,6 +344,7 @@ typedef struct tic_bank banks[TIC_BANKS]; }; + tic_palette palette; tic_cover_image cover; } tic_cartridge; From 83396664b5564204df0d5e6d0951ec688a28c12c Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 15:19:13 +0300 Subject: [PATCH 08/11] removed some compilation warnings for mingw --- src/ext/file_dialog.c | 4 ++++ src/fs.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/ext/file_dialog.c b/src/ext/file_dialog.c index b55a115..0015018 100644 --- a/src/ext/file_dialog.c +++ b/src/ext/file_dialog.c @@ -30,6 +30,10 @@ #include #include +FILE* _wfopen(const wchar_t *, const wchar_t *); +wchar_t* wcsrchr(const wchar_t *, wchar_t); +wchar_t* wcscpy(wchar_t *, const wchar_t *); + #define UTF8ToString(S) (wchar_t *)SDL_iconv_string("UTF-16LE", "UTF-8", (char *)(S), SDL_strlen(S)+1) #define StringToUTF8(S) SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(S), (SDL_wcslen(S)+1)*sizeof(wchar_t)) diff --git a/src/fs.c b/src/fs.c index 44c8f9c..99b0c4a 100644 --- a/src/fs.c +++ b/src/fs.c @@ -108,6 +108,9 @@ bool fsIsInPublicDir(FileSystem* fs) #define UTF8ToString(S) (wchar_t *)SDL_iconv_string("UTF-16LE", "UTF-8", (char *)(S), SDL_strlen(S)+1) #define StringToUTF8(S) SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(S), (SDL_wcslen(S)+1)*sizeof(wchar_t)) +FILE* _wfopen(const wchar_t *, const wchar_t *); +int _wremove(const wchar_t *); + #define TIC_DIR _WDIR #define tic_dirent _wdirent #define tic_stat_struct _stat From bb1f8053d024ffb907d0090c03eb8279ee1a812d Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 15:37:05 +0300 Subject: [PATCH 09/11] first bank renamed to bank0 --- src/config.c | 2 +- src/console.c | 46 +++++++++++++++++++++++----------------------- src/dialog.c | 2 +- src/map.c | 2 +- src/menu.c | 4 ++-- src/music.c | 4 ++-- src/run.c | 6 +++--- src/sfx.c | 4 ++-- src/sprite.c | 2 +- src/studio.c | 14 +++++++------- src/surf.c | 8 ++++---- src/tic.c | 50 +++++++++++++++++++++++++------------------------- src/tic.h | 2 +- 13 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/config.c b/src/config.c index 0294598..1abf7a3 100644 --- a/src/config.c +++ b/src/config.c @@ -170,7 +170,7 @@ static void readConfig(Config* config) if(lua) { - if(luaL_loadstring(lua, config->tic->config.bank.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK) + if(luaL_loadstring(lua, config->tic->config.bank0.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK) { readConfigVideoLength(config, lua); readConfigVideoScale(config, lua); diff --git a/src/console.c b/src/console.c index 48fa4c9..cbd9732 100644 --- a/src/console.c +++ b/src/console.c @@ -360,12 +360,12 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param) switch(i) { case 0: memcpy(&tic->cart.cover, &cart->cover, sizeof cart->cover); break; - case 1: memcpy(&tic->cart.bank.tiles, &cart->bank.tiles, sizeof(tic_tiles)*2); break; - case 2: memcpy(&tic->cart.bank.map, &cart->bank.map, sizeof(tic_map)); break; - case 3: memcpy(&tic->cart.bank.code, &cart->bank.code, sizeof(tic_code)); break; - case 4: memcpy(&tic->cart.bank.sfx, &cart->bank.sfx, sizeof(tic_sfx)); break; - case 5: memcpy(&tic->cart.bank.music, &cart->bank.music, sizeof(tic_music)); break; - case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof(tic_palette)); break; + case 1: memcpy(&tic->cart.bank0.tiles, &cart->bank0.tiles, sizeof(tic_tiles)*2); break; + case 2: memcpy(&tic->cart.bank0.map, &cart->bank0.map, sizeof(tic_map)); break; + case 3: memcpy(&tic->cart.bank0.code, &cart->bank0.code, sizeof(tic_code)); break; + case 4: memcpy(&tic->cart.bank0.sfx, &cart->bank0.sfx, sizeof(tic_sfx)); break; + case 5: memcpy(&tic->cart.bank0.music, &cart->bank0.music, sizeof(tic_music)); break; + case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof(tic_palette)); break; } studioRomLoaded(); @@ -602,14 +602,14 @@ static char* saveBinarySection(char* ptr, const char* comment, const char* tag, typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection; static const BinarySection BinarySections[] = { - {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, - {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.tiles), sizeof(tic_tile), true}, - {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.sprites), sizeof(tic_tile), true}, - {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, bank.map), TIC_MAP_WIDTH, true}, - {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, bank.sfx.waveform.envelopes), sizeof(tic_waveform), true}, - {"SFX", SFX_COUNT, offsetof(tic_cartridge, bank.sfx.data), sizeof(tic_sound_effect), true}, - {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, bank.music.patterns), sizeof(tic_track_pattern), true}, - {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, bank.music.tracks), sizeof(tic_track), true}, + {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, + {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank0.tiles), sizeof(tic_tile), true}, + {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank0.sprites), sizeof(tic_tile), true}, + {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, bank0.map), TIC_MAP_WIDTH, true}, + {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, bank0.sfx.waveform.envelopes), sizeof(tic_waveform), true}, + {"SFX", SFX_COUNT, offsetof(tic_cartridge, bank0.sfx.data), sizeof(tic_sound_effect), true}, + {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, bank0.music.patterns), sizeof(tic_track_pattern), true}, + {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, bank0.music.tracks), sizeof(tic_track), true}, }; static s32 saveProject(Console* console, void* buffer, const char* comment) @@ -617,7 +617,7 @@ static s32 saveProject(Console* console, void* buffer, const char* comment) tic_mem* tic = console->tic; char* stream = buffer; - char* ptr = saveTextSection(stream, tic->cart.bank.code.data); + char* ptr = saveTextSection(stream, tic->cart.bank0.code.data); for(s32 i = 0; i < COUNT_OF(BinarySections); i++) { @@ -738,7 +738,7 @@ static bool loadProject(Console* console, const char* name, const char* data, s3 const char* comment = projectComment(name); - if(loadTextSection(project, comment, cart->bank.code.data, sizeof(tic_code))) + if(loadTextSection(project, comment, cart->bank0.code.data, sizeof(tic_code))) done = true; for(s32 i = 0; i < COUNT_OF(BinarySections); i++) @@ -1330,7 +1330,7 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v tic_rgb rgb = {c->r, c->g, c->b}; u8 color = tic_tool_find_closest_color(console->tic->cart.palette.colors, &rgb); - setSpritePixel(console->tic->cart.bank.tiles.data, x, y, color); + setSpritePixel(getBankTiles()->data, x, y, color); } gif_close(image); @@ -1352,8 +1352,8 @@ static void injectMap(Console* console, const void* buffer, s32 size) { enum {Size = sizeof(tic_map)}; - SDL_memset(&console->tic->cart.bank.map, 0, Size); - SDL_memcpy(&console->tic->cart.bank.map, buffer, SDL_min(size, Size)); + SDL_memset(getBankMap(), 0, Size); + SDL_memcpy(getBankMap(), buffer, SDL_min(size, Size)); } static void onImportMap(const char* name, const void* buffer, size_t size, void* data) @@ -1453,7 +1453,7 @@ static void exportSprites(Console* console) { for (s32 y = 0; y < Height; y++) for (s32 x = 0; x < Width; x++) - data[x + y * Width] = getSpritePixel(console->tic->cart.bank.tiles.data, x, y); + data[x + y * Width] = getSpritePixel(getBankTiles()->data, x, y); s32 size = 0; if((size = writeGifData(console->tic, buffer, data, Width, Height))) @@ -1493,7 +1493,7 @@ static void exportMap(Console* console) if(buffer) { - SDL_memcpy(buffer, console->tic->cart.bank.map.data, Size); + SDL_memcpy(buffer, getBankMap()->data, Size); fsGetFileData(onMapExported, "world.map", buffer, Size, DEFAULT_CHMOD, console); } } @@ -2714,7 +2714,7 @@ static bool cmdInjectCode(Console* console, const char* param, const char* name) bool watch = strcmp(param, "-code-watch") == 0; if(watch || strcmp(param, "-code") == 0) { - bool loaded = loadFileIntoBuffer(console, console->embed.file->bank.code.data, name); + bool loaded = loadFileIntoBuffer(console, console->embed.file->bank0.code.data, name); if(loaded) { @@ -2765,7 +2765,7 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na tic_rgb rgb = {c->r, c->g, c->b}; u8 color = tic_tool_find_closest_color(console->embed.file->palette.colors, &rgb); - setSpritePixel(console->embed.file->bank.tiles.data, x, y, color); + setSpritePixel(console->embed.file->bank0.tiles.data, x, y, color); } gif_close(image); diff --git a/src/dialog.c b/src/dialog.c index a61c16b..2f5be5f 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -170,7 +170,7 @@ static void drawDialog(Dialog* dlg) { u8 chromakey = 14; - tic->api.sprite_ex(tic, &tic->config.bank.tiles, 2, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 2, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); } { diff --git a/src/map.c b/src/map.c index 28c939e..64a6d0a 100644 --- a/src/map.c +++ b/src/map.c @@ -1185,7 +1185,7 @@ void initMap(Map* map, tic_mem* tic) .gesture = false, .start = {0, 0}, }, - .history = history_create(&tic->cart.bank.map, sizeof(tic_map)), + .history = history_create(&tic->cart.bank0.map, sizeof(tic_map)), .event = onStudioEvent, .overlap = overlap, }; diff --git a/src/menu.c b/src/menu.c index 935ce3a..746ecf8 100644 --- a/src/menu.c +++ b/src/menu.c @@ -124,7 +124,7 @@ static void drawDialog(Menu* menu) { u8 chromakey = 14; - tic->api.sprite_ex(tic, &tic->config.bank.tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); } } @@ -209,7 +209,7 @@ static void drawPlayerButtons(Menu* menu, s32 x, s32 y) if(menu->gamepad.selected == index && menu->ticks % TIC_FRAMERATE < TIC_FRAMERATE / 2) continue; - tic->api.sprite_ex(tic, &tic->config.bank.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); s32 code = codes[index]; char label[32]; diff --git a/src/music.c b/src/music.c index 7672eb4..9156718 100644 --- a/src/music.c +++ b/src/music.c @@ -1327,7 +1327,7 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index) } u8 color = Chroma; - tic->api.sprite(tic, &tic->config.bank.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1); + tic->api.sprite(tic, &tic->config.bank0.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1); } static void drawTracker(Music* music, s32 x, s32 y) @@ -1643,7 +1643,7 @@ void initMusic(Music* music, tic_mem* tic) }, .tab = MUSIC_TRACKER_TAB, - .history = history_create(&tic->cart.bank.music, sizeof(tic_music)), + .history = history_create(&tic->cart.bank0.music, sizeof(tic_music)), .event = onStudioEvent, }; diff --git a/src/run.c b/src/run.c index 93c1897..e54c21d 100644 --- a/src/run.c +++ b/src/run.c @@ -80,7 +80,7 @@ static const char* getPMemName(Run* run) { static char buffer[FILENAME_MAX]; - const char* data = strlen(run->tic->saveid) ? run->tic->saveid : run->tic->cart.bank.code.data; + const char* data = strlen(run->tic->saveid) ? run->tic->saveid : run->tic->cart.bank0.code.data; char* md5 = data2md5(data, (s32)strlen(data)); strcpy(buffer, TIC_LOCAL); strcat(buffer, md5); @@ -124,9 +124,9 @@ static void processDoFile(void* data, char* dst) static const char DoFileTag[] = "dofile("; enum {Size = sizeof DoFileTag - 1}; - if (memcmp(tic->cart.bank.code.data, DoFileTag, Size) == 0) + if (memcmp(tic->cart.bank0.code.data, DoFileTag, Size) == 0) { - const char* start = tic->cart.bank.code.data + Size; + const char* start = tic->cart.bank0.code.data + Size; const char* end = strchr(start, ')'); if(end && *start == *(end-1) && (*start == '"' || *start == '\'')) diff --git a/src/sfx.c b/src/sfx.c index 1de5c4c..48957c8 100644 --- a/src/sfx.c +++ b/src/sfx.c @@ -1058,8 +1058,8 @@ void initSfx(Sfx* sfx, tic_mem* tic) .tab = SFX_ENVELOPES_TAB, .history = { - .envelope = history_create(&tic->cart.bank.sfx.data, sizeof tic->cart.bank.sfx.data), - .waveform = history_create(&tic->cart.bank.sfx.waveform, sizeof tic->cart.bank.sfx.waveform), + .envelope = history_create(&tic->cart.bank0.sfx.data, sizeof tic->cart.bank0.sfx.data), + .waveform = history_create(&tic->cart.bank0.sfx.waveform, sizeof tic->cart.bank0.sfx.waveform), }, .event = onStudioEvent, }; diff --git a/src/sprite.c b/src/sprite.c index 97fce55..0bb39c9 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -1570,7 +1570,7 @@ void initSprite(Sprite* sprite, tic_mem* tic) .front = sprite->select.front, }, .mode = SPRITE_DRAW_MODE, - .history = history_create(&tic->cart.bank.tiles, TIC_SPRITES * sizeof(tic_tile)), + .history = history_create(&tic->cart.bank0.tiles, TIC_SPRITES * sizeof(tic_tile)), .event = onStudioEvent, .overlap = overlap, }; diff --git a/src/studio.c b/src/studio.c index 5acb661..3ad34b3 100644 --- a/src/studio.c +++ b/src/studio.c @@ -337,7 +337,7 @@ tic_music* getBankMusic() void playSystemSfx(s32 id) { - const tic_sound_effect* effect = &studio.tic->config.bank.sfx.data[id]; + const tic_sound_effect* effect = &studio.tic->config.bank0.sfx.data[id]; studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0); } @@ -2209,7 +2209,7 @@ static void renderCursor() SDL_ShowCursor(getConfig()->theme.cursor.sprite >= 0 ? SDL_DISABLE : SDL_ENABLE); if(getConfig()->theme.cursor.sprite >= 0) - blitCursor(studio.tic->config.bank.tiles.data[getConfig()->theme.cursor.sprite].data); + blitCursor(studio.tic->config.bank0.tiles.data[getConfig()->theme.cursor.sprite].data); } static void useSystemPalette() @@ -2264,8 +2264,8 @@ static void renderStudio() case TIC_DIALOG_MODE: case TIC_MENU_MODE: case TIC_SURF_MODE: - sfx = &studio.tic->config.bank.sfx; - music = &studio.tic->config.bank.music; + sfx = &studio.tic->config.bank0.sfx; + music = &studio.tic->config.bank0.music; break; default: sfx = getBankSfx(); @@ -2448,7 +2448,7 @@ static void initTouchGamepad() if (!studio.renderer) return; - studio.tic->api.map(studio.tic, &studio.tic->config.bank.map, &studio.tic->config.bank.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); + studio.tic->api.map(studio.tic, &studio.tic->config.bank0.map, &studio.tic->config.bank0.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); if(!studio.gamepad.texture) { @@ -2475,7 +2475,7 @@ static void updateSystemFont() for(s32 i = 0; i < TIC_FONT_CHARS; i++) for(s32 y = 0; y < TIC_SPRITESIZE; y++) for(s32 x = 0; x < TIC_SPRITESIZE; x++) - if(tic_tool_peek4(&studio.tic->config.bank.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1)) + if(tic_tool_peek4(&studio.tic->config.bank0.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1)) studio.tic->font.data[i*BITS_IN_BYTE+y] |= 1 << x; } @@ -2501,7 +2501,7 @@ static void setWindowIcon() for(s32 j = 0, index = 0; j < Size; j++) for(s32 i = 0; i < Size; i++, index++) { - u8 color = getSpritePixel(studio.tic->config.bank.tiles.data, i/Scale, j/Scale); + u8 color = getSpritePixel(studio.tic->config.bank0.tiles.data, i/Scale, j/Scale); pixels[index] = color == ColorKey ? 0 : pal[color]; } diff --git a/src/surf.c b/src/surf.c index 83083fd..07d714e 100644 --- a/src/surf.c +++ b/src/surf.c @@ -202,14 +202,14 @@ static void drawTopToolbar(Surf* surf, s32 x, s32 y) enum{Gap = 10, TipX = 150, SelectWidth = 54}; u8 colorkey = 0; - tic->api.sprite_ex(tic, &tic->config.bank.tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "SELECT"; tic->api.text(tic, Label, TipX + Gap, y+3, tic_color_black); tic->api.text(tic, Label, TipX + Gap, y+2, tic_color_white); } - tic->api.sprite_ex(tic, &tic->config.bank.tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "BACK"; tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); @@ -244,7 +244,7 @@ static void drawBottomToolbar(Surf* surf, s32 x, s32 y) u8 colorkey = 0; - tic->api.sprite_ex(tic, &tic->config.bank.tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "WEBSITE"; tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); @@ -355,7 +355,7 @@ static void drawBG(Surf* surf) for(s32 j = 0; j < Height + 1; j++) for(s32 i = 0; i < Width + 1; i++) if(counter++ % 2) - tic->api.sprite_ex(tic, &tic->config.bank.tiles, 34, i*Size - offset, j*Size - offset, 2, 2, 0, 0, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 34, i*Size - offset, j*Size - offset, 2, 2, 0, 0, 1, tic_no_flip, tic_no_rotate); } static void replace(char* src, const char* what, const char* with) diff --git a/src/tic.c b/src/tic.c index 2a20b70..73f0d53 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1327,11 +1327,11 @@ 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[] = { - {"tiles", offsetof(tic_cartridge, bank.tiles), offsetof(tic_ram, tiles), sizeof(tic_tiles)}, - {"sprites", offsetof(tic_cartridge, bank.sprites), offsetof(tic_ram, sprites), sizeof(tic_tiles)}, - {"map", offsetof(tic_cartridge, bank.map), offsetof(tic_ram, map), sizeof(tic_map)}, - {"sfx", offsetof(tic_cartridge, bank.sfx), offsetof(tic_ram, sfx), sizeof(tic_sfx)}, - {"music", offsetof(tic_cartridge, bank.music), offsetof(tic_ram, music), sizeof(tic_music)}, + {"tiles", offsetof(tic_cartridge, bank0.tiles), offsetof(tic_ram, tiles), sizeof(tic_tiles)}, + {"sprites", offsetof(tic_cartridge, bank0.sprites), offsetof(tic_ram, sprites), sizeof(tic_tiles)}, + {"map", offsetof(tic_cartridge, bank0.map), offsetof(tic_ram, map), sizeof(tic_map)}, + {"sfx", offsetof(tic_cartridge, bank0.sfx), offsetof(tic_ram, sfx), sizeof(tic_sfx)}, + {"music", offsetof(tic_cartridge, bank0.music), offsetof(tic_ram, music), sizeof(tic_music)}, }; assert(bank >= 0 && bank < TIC_BANKS); @@ -1438,15 +1438,15 @@ static bool isJavascript(const char* code) static tic_script_lang api_get_script(tic_mem* memory) { - if(isMoonscript(memory->cart.bank.code.data)) return tic_script_moon; - if(isJavascript(memory->cart.bank.code.data)) return tic_script_js; + if(isMoonscript(memory->cart.bank0.code.data)) return tic_script_moon; + if(isJavascript(memory->cart.bank0.code.data)) return tic_script_js; return tic_script_lua; } static void updateSaveid(tic_mem* memory) { memset(memory->saveid, 0, sizeof memory->saveid); - const char* saveid = readMetatag(memory->cart.bank.code.data, "saveid", TagFormatLua); + const char* saveid = readMetatag(memory->cart.bank0.code.data, "saveid", TagFormatLua); if(saveid) { strcpy(memory->saveid, saveid); @@ -1454,7 +1454,7 @@ static void updateSaveid(tic_mem* memory) } else { - const char* saveid = readMetatag(memory->cart.bank.code.data, "saveid", TagFormatJS); + const char* saveid = readMetatag(memory->cart.bank0.code.data, "saveid", TagFormatJS); if(saveid) { strcpy(memory->saveid, saveid); @@ -1607,14 +1607,14 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet switch(chunk.type) { - case CHUNK_TILES: LOAD_CHUNK(cart->bank.tiles); break; - case CHUNK_SPRITES: LOAD_CHUNK(cart->bank.sprites); break; - case CHUNK_MAP: LOAD_CHUNK(cart->bank.map); break; - case CHUNK_CODE: LOAD_CHUNK(cart->bank.code); break; - case CHUNK_SOUND: LOAD_CHUNK(cart->bank.sfx.data); break; - case CHUNK_WAVEFORM: LOAD_CHUNK(cart->bank.sfx.waveform); break; - case CHUNK_MUSIC: LOAD_CHUNK(cart->bank.music.tracks.data); break; - case CHUNK_PATTERNS: LOAD_CHUNK(cart->bank.music.patterns.data); break; + case CHUNK_TILES: LOAD_CHUNK(cart->bank0.tiles); break; + case CHUNK_SPRITES: LOAD_CHUNK(cart->bank0.sprites); break; + case CHUNK_MAP: LOAD_CHUNK(cart->bank0.map); break; + case CHUNK_CODE: LOAD_CHUNK(cart->bank0.code); break; + case CHUNK_SOUND: LOAD_CHUNK(cart->bank0.sfx.data); break; + case CHUNK_WAVEFORM: LOAD_CHUNK(cart->bank0.sfx.waveform); break; + case CHUNK_MUSIC: LOAD_CHUNK(cart->bank0.music.tracks.data); break; + case CHUNK_PATTERNS: LOAD_CHUNK(cart->bank0.music.patterns.data); break; case CHUNK_PALETTE: if(palette) LOAD_CHUNK(cart->palette); @@ -1676,14 +1676,14 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) #define SAVE_CHUNK(id, from) saveChunk(buffer, id, &from, sizeof(from)) - buffer = SAVE_CHUNK(CHUNK_TILES, cart->bank.tiles); - buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->bank.sprites); - buffer = SAVE_CHUNK(CHUNK_MAP, cart->bank.map); - buffer = SAVE_CHUNK(CHUNK_CODE, cart->bank.code); - buffer = SAVE_CHUNK(CHUNK_SOUND, cart->bank.sfx.data); - buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->bank.sfx.waveform); - buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->bank.music.patterns.data); - buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->bank.music.tracks.data); + buffer = SAVE_CHUNK(CHUNK_TILES, cart->bank0.tiles); + buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->bank0.sprites); + buffer = SAVE_CHUNK(CHUNK_MAP, cart->bank0.map); + buffer = SAVE_CHUNK(CHUNK_CODE, cart->bank0.code); + buffer = SAVE_CHUNK(CHUNK_SOUND, cart->bank0.sfx.data); + buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->bank0.sfx.waveform); + buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->bank0.music.patterns.data); + buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->bank0.music.tracks.data); buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette); buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size); diff --git a/src/tic.h b/src/tic.h index e595374..4a76585 100644 --- a/src/tic.h +++ b/src/tic.h @@ -340,7 +340,7 @@ typedef struct { union { - tic_bank bank; + tic_bank bank0; tic_bank banks[TIC_BANKS]; }; From 295dd90766893196f950ebc1f6c8fd9fe36a5e83 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 17:08:04 +0300 Subject: [PATCH 10/11] added separate editor per bank --- src/code.c | 82 +++++++++++------------ src/code.h | 2 +- src/map.c | 25 +++---- src/map.h | 4 +- src/music.c | 9 +-- src/music.h | 5 +- src/sfx.c | 56 ++++++---------- src/sfx.h | 10 ++- src/sprite.c | 11 ++-- src/sprite.h | 4 +- src/studio.c | 180 ++++++++++++++++++++++++++++++++------------------- src/studio.h | 7 +- 12 files changed, 215 insertions(+), 180 deletions(-) diff --git a/src/code.c b/src/code.c index ef81dab..fa31e14 100644 --- a/src/code.c +++ b/src/code.c @@ -68,7 +68,7 @@ static void drawCode(Code* code, bool withCursor) s32 xStart = code->rect.x - code->scroll.x * STUDIO_TEXT_WIDTH; s32 x = xStart; s32 y = code->rect.y - code->scroll.y * STUDIO_TEXT_HEIGHT; - char* pointer = code->data; + char* pointer = code->src; u8* colorPointer = code->colorBuffer; @@ -116,7 +116,7 @@ static void getCursorPosition(Code* code, s32* x, s32* y) *x = 0; *y = 0; - const char* pointer = code->data; + const char* pointer = code->src; while(*pointer) { @@ -135,7 +135,7 @@ static void getCursorPosition(Code* code, s32* x, s32* y) static s32 getLinesCount(Code* code) { - char* text = code->data; + char* text = code->src; s32 count = 0; while(*text) @@ -177,10 +177,10 @@ static void updateEditor(Code* code) sprintf(status, "line %i/%i col %i", line + 1, count + 1, column + 1); memcpy(code->status, status, strlen(status)); - size_t codeLen = strlen(code->data); + size_t codeLen = strlen(code->src); sprintf(status, "%i/%i", (u32)codeLen, TIC_CODE_SIZE); - memset(code->data + codeLen, '\0', TIC_CODE_SIZE - codeLen); + memset(code->src + codeLen, '\0', TIC_CODE_SIZE - codeLen); memcpy(code->status + sizeof code->status - strlen(status) - 1, status, strlen(status)); } } @@ -213,7 +213,7 @@ static void highlightStrings(Code* code, const char* text, u8* color, char separ static void highlightNumbers(Code* code, u8* color) { - const char* text = code->data; + const char* text = code->src; const char* pointer = text; while(*pointer) @@ -267,7 +267,7 @@ static void highlightWords(const char* text, u8* color, const char* const string static void highlightMoonKeywords(Code* code, u8* color) { - const char* text = code->data; + const char* text = code->src; static const char* const MoonKeywords [] = { @@ -285,7 +285,7 @@ static void highlightMoonKeywords(Code* code, u8* color) static void highlightLuaKeywords(Code* code, u8* color) { - const char* text = code->data; + const char* text = code->src; static const char* const LuaKeywords [] = { @@ -300,7 +300,7 @@ static void highlightLuaKeywords(Code* code, u8* color) static void highlightJsKeywords(Code* code, u8* color) { - const char* text = code->data; + const char* text = code->src; static const char* const JsKeywords [] = { @@ -317,13 +317,13 @@ static void highlightApi(Code* code, u8* color) { static const char* const ApiKeywords[] = API_KEYWORDS; - const char* text = code->data; + const char* text = code->src; highlightWords(text, color, ApiKeywords, COUNT_OF(ApiKeywords), getConfig()->theme.code.api); } static void highlightNonChars(Code* code, u8* color) { - const char* text = code->data; + const char* text = code->src; while(*text) { @@ -337,7 +337,7 @@ static void highlightNonChars(Code* code, u8* color) static void highlightSigns(Code* code, u8* color) { - const char* text = code->data; + const char* text = code->src; static const char* const LuaSigns [] = { @@ -364,7 +364,7 @@ static void highlightSigns(Code* code, u8* color) static void highlightCommentsBase(Code* code, u8* color, const char* pattern1, const char* pattern2, s32 extraSize) { - const char* text = code->data; + const char* text = code->src; const char* pointer = text; while(*pointer) @@ -417,7 +417,7 @@ static void parseSyntaxColor(Code* code) highlightNumbers(code, color); highlightSigns(code, color); highlightCommentsBase(code, color, "--", "\n", 0); - highlightStrings(code, code->data, color, '"'); + highlightStrings(code, code->src, color, '"'); break; case tic_script_lua: highlightNonChars(code, color); @@ -426,7 +426,7 @@ static void parseSyntaxColor(Code* code) highlightNumbers(code, color); highlightSigns(code, color); highlightComments(code, color); - highlightStrings(code, code->data, color, '"'); + highlightStrings(code, code->src, color, '"'); break; case tic_script_js: highlightNonChars(code, color); @@ -435,14 +435,14 @@ static void parseSyntaxColor(Code* code) highlightNumbers(code, color); highlightSigns(code, color); highlightJsComments(code, color); - highlightStrings(code, code->data, color, '"'); + highlightStrings(code, code->src, color, '"'); break; } } static char* getLineByPos(Code* code, char* pos) { - char* text = code->data; + char* text = code->src; char* line = text; while(text < pos) @@ -459,7 +459,7 @@ static char* getLine(Code* code) static char* getPrevLine(Code* code) { - char* text = code->data; + char* text = code->src; char* pos = code->cursor.position; char* prevLine = text; char* line = text; @@ -510,7 +510,7 @@ static void setCursorPosition(Code* code, s32 cx, s32 cy) { s32 x = 0; s32 y = 0; - char* pointer = code->data; + char* pointer = code->src; while(*pointer) { @@ -559,7 +559,7 @@ static void downLine(Code* code) static void leftColumn(Code* code) { - char* start = code->data; + char* start = code->src; if(code->cursor.position > start) { @@ -579,7 +579,7 @@ static void rightColumn(Code* code) static void leftWord(Code* code) { - const char* start = code->data; + const char* start = code->src; char* pos = code->cursor.position-1; if(pos > start) @@ -595,7 +595,7 @@ static void leftWord(Code* code) static void rightWord(Code* code) { - const char* end = code->data + strlen(code->data); + const char* end = code->src + strlen(code->src); char* pos = code->cursor.position; if(pos < end) @@ -625,14 +625,14 @@ static void goEnd(Code* code) static void goCodeHome(Code *code) { - code->cursor.position = code->data; + code->cursor.position = code->src; updateColumn(code); } static void goCodeEnd(Code *code) { - code->cursor.position = code->data + strlen(code->data); + code->cursor.position = code->src + strlen(code->src); updateColumn(code); } @@ -692,7 +692,7 @@ static void deleteChar(Code* code) static void backspaceChar(Code* code) { - if(!replaceSelection(code) && code->cursor.position > code->data) + if(!replaceSelection(code) && code->cursor.position > code->src) { char* pos = --code->cursor.position; memmove(pos, pos + 1, strlen(pos)); @@ -703,7 +703,7 @@ static void backspaceChar(Code* code) static void inputSymbolBase(Code* code, char sym) { - if (strlen(code->data) >= sizeof(tic_code)) + if (strlen(code->src) >= sizeof(tic_code)) return; char* pos = code->cursor.position; @@ -747,7 +747,7 @@ static void newLine(Code* code) static void selectAll(Code* code) { - code->cursor.selection = code->data; + code->cursor.selection = code->src; code->cursor.position = code->cursor.selection + strlen(code->cursor.selection); } @@ -807,7 +807,7 @@ static void copyFromClipboard(Code* code) // cut clipboard code if overall code > max code size { - size_t codeSize = strlen(code->data); + size_t codeSize = strlen(code->src); if (codeSize + size > sizeof(tic_code)) { @@ -995,7 +995,7 @@ static void updateOutlineCode(Code* code) } else { - code->cursor.position = code->data; + code->cursor.position = code->src; code->cursor.selection = NULL; } @@ -1008,7 +1008,7 @@ static void setMoonscriptOutlineMode(Code* code) OutlineItem* out = code->outline.items; OutlineItem* end = out + OUTLINE_SIZE; - char* ptr = code->data; + char* ptr = code->src; static const char FuncString[] = "=->"; char buffer[STUDIO_TEXT_BUFFER_WIDTH]; @@ -1020,18 +1020,18 @@ static void setMoonscriptOutlineMode(Code* code) { ptr = strstr(ptr, FuncString); - if(ptr && ptr > code->data) + if(ptr && ptr > code->src) { char* endPtr = ptr; ptr += sizeof FuncString - 1; - while(endPtr >= code->data && !isLetter(*endPtr) && !isNumber(*endPtr)) endPtr--; + while(endPtr >= code->src && !isLetter(*endPtr) && !isNumber(*endPtr)) endPtr--; char* start = endPtr; - for (const char* val = start-1; val >= code->data && (isLetter(*val) || isNumber(*val)); val--, start--); + for (const char* val = start-1; val >= code->src && (isLetter(*val) || isNumber(*val)); val--, start--); - if(start >= code->data) + if(start >= code->src) { memset(buffer, 0, sizeof buffer); memcpy(buffer, start, endPtr - start + 1); @@ -1065,7 +1065,7 @@ static void setLuaOutlineMode(Code* code) OutlineItem* out = code->outline.items; OutlineItem* end = out + OUTLINE_SIZE; - char* ptr = code->data; + char* ptr = code->src; static const char FuncString[] = "function "; char buffer[STUDIO_TEXT_BUFFER_WIDTH]; @@ -1156,7 +1156,7 @@ static void commentLine(Code* code) if(memcmp(line, Comment, Size)) { - if (strlen(code->data) + Size >= sizeof(tic_code)) + if (strlen(code->src) + Size >= sizeof(tic_code)) return; memmove(line + Size, line, strlen(line)+1); @@ -1481,7 +1481,7 @@ static void textFindTick(Code* code) bool reverse = keycode == SDLK_UP || keycode == SDLK_LEFT; char* (*func)(const char*, const char*, const char*) = reverse ? upStrStr : downStrStr; char* from = reverse ? SDL_min(code->cursor.position, code->cursor.selection) : SDL_max(code->cursor.position, code->cursor.selection); - char* pos = func(code->data, from, code->popup.text); + char* pos = func(code->src, from, code->popup.text); updateFindCode(code, pos); } break; @@ -1489,7 +1489,7 @@ static void textFindTick(Code* code) if(*code->popup.text) { code->popup.text[strlen(code->popup.text)-1] = '\0'; - updateFindCode(code, strstr(code->data, code->popup.text)); + updateFindCode(code, strstr(code->src, code->popup.text)); } break; default: break; @@ -1501,7 +1501,7 @@ static void textFindTick(Code* code) if(strlen(code->popup.text) + 1 < sizeof code->popup.text) { strcat(code->popup.text, event->text.text); - updateFindCode(code, strstr(code->data, code->popup.text)); + updateFindCode(code, strstr(code->src, code->popup.text)); } } break; @@ -1838,7 +1838,7 @@ void initCode(Code* code, tic_mem* tic, tic_code* src) *code = (Code) { .tic = tic, - .data = src->data, + .src = src->data, .tick = tick, .escape = escape, .cursor = {{src->data, NULL, 0, 0}, NULL, 0}, @@ -1863,7 +1863,7 @@ void initCode(Code* code, tic_mem* tic, tic_code* src) .update = update, }; - code->history = history_create(code->data, sizeof(tic_code)); + code->history = history_create(code->src, sizeof(tic_code)); code->cursorHistory = history_create(&code->cursor, sizeof code->cursor); update(code); diff --git a/src/code.h b/src/code.h index a05bad7..70e196d 100644 --- a/src/code.h +++ b/src/code.h @@ -31,7 +31,7 @@ struct Code { tic_mem* tic; - char* data; + char* src; struct { diff --git a/src/map.c b/src/map.c index 64a6d0a..063732c 100644 --- a/src/map.c +++ b/src/map.c @@ -314,7 +314,7 @@ static void drawTileIndex(Map* map, s32 x, s32 y) { s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - index = map->tic->api.map_get(map->tic, getBankMap(), tx, ty); + index = map->tic->api.map_get(map->tic, map->src, tx, ty); } } @@ -437,7 +437,7 @@ static void setMapSprite(Map* map, s32 x, s32 y) for(s32 j = 0; j < map->sheet.rect.h; j++) for(s32 i = 0; i < map->sheet.rect.w; i++) - map->tic->api.map_set(map->tic, getBankMap(), (x+i)%TIC_MAP_WIDTH, (y+j)%TIC_MAP_HEIGHT, (mx+i) + (my+j) * SHEET_COLS); + map->tic->api.map_set(map->tic, map->src, (x+i)%TIC_MAP_WIDTH, (y+j)%TIC_MAP_HEIGHT, (mx+i) + (my+j) * SHEET_COLS); history_add(map->history); } @@ -512,7 +512,7 @@ static void processMouseDrawMode(Map* map) { s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - s32 index = map->tic->api.map_get(map->tic, getBankMap(), tx, ty); + s32 index = map->tic->api.map_get(map->tic, map->src, tx, ty); map->sheet.rect = (SDL_Rect){index % SHEET_COLS, index / SHEET_COLS, 1, 1}; } @@ -593,7 +593,7 @@ static void drawPasteData(Map* map) for(s32 j = 0; j < h; j++) for(s32 i = 0; i < w; i++) - map->tic->api.map_set(map->tic, getBankMap(), (mx+i)%TIC_MAP_WIDTH, (my+j)%TIC_MAP_HEIGHT, data[i + j * w]); + map->tic->api.map_set(map->tic, map->src, (mx+i)%TIC_MAP_WIDTH, (my+j)%TIC_MAP_HEIGHT, data[i + j * w]); history_add(map->history); @@ -764,7 +764,7 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile) { for(s32 j = 0; j < map->sheet.rect.h; j++) for(s32 i = 0; i < map->sheet.rect.w; i++) - map->tic->api.map_set(map->tic, getBankMap(), x+i, y+j, (mx+i) + (my+j) * SHEET_COLS); + map->tic->api.map_set(map->tic, map->src, x+i, y+j, (mx+i) + (my+j) * SHEET_COLS); for(s32 i = 0; i < COUNT_OF(dx); i++) { @@ -776,7 +776,7 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile) bool match = true; for(s32 j = 0; j < map->sheet.rect.h; j++) for(s32 i = 0; i < map->sheet.rect.w; i++) - if(map->tic->api.map_get(map->tic, getBankMap(), nx+i, ny+j) != tile) + if(map->tic->api.map_get(map->tic, map->src, nx+i, ny+j) != tile) match = false; if(match) @@ -801,7 +801,7 @@ static void processMouseFillMode(Map* map) s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - fillMap(map, tx, ty, map->tic->api.map_get(map->tic, getBankMap(), tx, ty)); + fillMap(map, tx, ty, map->tic->api.map_get(map->tic, map->src, tx, ty)); history_add(map->history); } } @@ -864,7 +864,7 @@ static void drawMapOvr(Map* map) s32 scrollX = map->scroll.x % TIC_SPRITESIZE; s32 scrollY = map->scroll.y % TIC_SPRITESIZE; - map->tic->api.map(map->tic, getBankMap(), getBankTiles(), map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE, + map->tic->api.map(map->tic, map->src, getBankTiles(), map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE, TIC_MAP_SCREEN_WIDTH + 1, TIC_MAP_SCREEN_HEIGHT + 1, -scrollX, -scrollY, -1, 1); if(map->canvas.grid || map->scroll.active) @@ -950,7 +950,7 @@ static void copySelectionToClipboard(Map* map) normalizeMapRect(&x, &y); s32 index = x + y * TIC_MAP_WIDTH; - *ptr++ = getBankMap()->data[index]; + *ptr++ = map->src->data[index]; } toClipboard(buffer, size, true); @@ -978,7 +978,7 @@ static void deleteSelection(Map* map) normalizeMapRect(&x, &y); s32 index = x + y * TIC_MAP_WIDTH; - getBankMap()->data[index] = 0; + map->src->data[index] = 0; } history_add(map->history); @@ -1147,7 +1147,7 @@ static void overlap(tic_mem* tic, void* data) drawSheetOvr(map, TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE); } -void initMap(Map* map, tic_mem* tic) +void initMap(Map* map, tic_mem* tic, tic_map* src) { if(map->history) history_delete(map->history); @@ -1155,6 +1155,7 @@ void initMap(Map* map, tic_mem* tic) { .tic = tic, .tick = tick, + .src = src, .mode = MAP_DRAW_MODE, .canvas = { @@ -1185,7 +1186,7 @@ void initMap(Map* map, tic_mem* tic) .gesture = false, .start = {0, 0}, }, - .history = history_create(&tic->cart.bank0.map, sizeof(tic_map)), + .history = history_create(src, sizeof(tic_map)), .event = onStudioEvent, .overlap = overlap, }; diff --git a/src/map.h b/src/map.h index fbd6b5f..7c9f173 100644 --- a/src/map.h +++ b/src/map.h @@ -29,6 +29,8 @@ typedef struct Map Map; struct Map { tic_mem* tic; + + tic_map* src; s32 tickCounter; @@ -83,4 +85,4 @@ struct Map void(*overlap)(tic_mem* tic, void* data); }; -void initMap(Map*, tic_mem*); +void initMap(Map*, tic_mem*, tic_map* src); diff --git a/src/music.c b/src/music.c index 9156718..4f8ca64 100644 --- a/src/music.c +++ b/src/music.c @@ -215,7 +215,7 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value, static tic_track* getTrack(Music* music) { - return &getBankMusic()->tracks.data[music->track]; + return &music->src->tracks.data[music->track]; } static s32 getRows(Music* music) @@ -368,7 +368,7 @@ static tic_track_pattern* getPattern(Music* music, s32 channel) { s32 patternId = tic_tool_get_pattern_id(getTrack(music), music->tracker.frame, channel); - return patternId ? &getBankMusic()->patterns.data[patternId - PATTERN_START] : NULL; + return patternId ? &music->src->patterns.data[patternId - PATTERN_START] : NULL; } static tic_track_pattern* getChannelPattern(Music* music) @@ -1608,7 +1608,7 @@ static void onStudioEvent(Music* music, StudioEvent event) } } -void initMusic(Music* music, tic_mem* tic) +void initMusic(Music* music, tic_mem* tic, tic_music* src) { if (music->history) history_delete(music->history); @@ -1616,6 +1616,7 @@ void initMusic(Music* music, tic_mem* tic) { .tic = tic, .tick = tick, + .src = src, .track = 0, .tracker = { @@ -1643,7 +1644,7 @@ void initMusic(Music* music, tic_mem* tic) }, .tab = MUSIC_TRACKER_TAB, - .history = history_create(&tic->cart.bank0.music, sizeof(tic_music)), + .history = history_create(src, sizeof(tic_music)), .event = onStudioEvent, }; diff --git a/src/music.h b/src/music.h index 7f2b795..01782dd 100644 --- a/src/music.h +++ b/src/music.h @@ -29,6 +29,9 @@ typedef struct Music Music; struct Music { tic_mem* tic; + + tic_music* src; + u8 track:MUSIC_TRACKS_BITS; struct @@ -72,4 +75,4 @@ struct Music void(*event)(Music*, StudioEvent); }; -void initMusic(Music*, tic_mem*); \ No newline at end of file +void initMusic(Music*, tic_mem*, tic_music* src); \ No newline at end of file diff --git a/src/sfx.c b/src/sfx.c index 48957c8..cda5368 100644 --- a/src/sfx.c +++ b/src/sfx.c @@ -106,7 +106,7 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi static tic_sound_effect* getEffect(Sfx* sfx) { - return getBankSfx()->data + sfx->index; + return sfx->src->data + sfx->index; } static void setIndex(Sfx* sfx, s32 delta) @@ -120,7 +120,7 @@ static void setSpeed(Sfx* sfx, s32 delta) effect->speed += delta; - history_add(sfx->history.envelope); + history_add(sfx->history); } static void drawTopPanel(Sfx* sfx, s32 x, s32 y) @@ -141,7 +141,7 @@ static void setLoopStart(Sfx* sfx, s32 delta) loop->start += delta; - history_add(sfx->history.envelope); + history_add(sfx->history); } static void setLoopSize(Sfx* sfx, s32 delta) @@ -151,7 +151,7 @@ static void setLoopSize(Sfx* sfx, s32 delta) loop->size += delta; - history_add(sfx->history.envelope); + history_add(sfx->history); } static void drawLoopPanel(Sfx* sfx, s32 x, s32 y) @@ -169,7 +169,7 @@ static void drawLoopPanel(Sfx* sfx, s32 x, s32 y) static tic_waveform* getWaveformById(Sfx* sfx, s32 i) { - return &getBankSfx()->waveform.envelopes[i]; + return &sfx->src->waveform.envelopes[i]; } static tic_waveform* getWaveform(Sfx* sfx) @@ -398,7 +398,7 @@ static void drawCanvas(Sfx* sfx, s32 x, s32 y) default: break; } - history_add(sfx->history.envelope); + history_add(sfx->history); } } @@ -563,22 +563,12 @@ static void playSound(Sfx* sfx) static void undo(Sfx* sfx) { - history_undo(sfx->history.envelope); + history_undo(sfx->history); } static void redo(Sfx* sfx) { - history_redo(sfx->history.envelope); -} - -static void undoWave(Sfx* sfx) -{ - history_undo(sfx->history.waveform); -} - -static void redoWave(Sfx* sfx) -{ - history_redo(sfx->history.waveform); + history_redo(sfx->history); } static void copyToClipboard(Sfx* sfx) @@ -598,7 +588,7 @@ static void resetSfx(Sfx* sfx) tic_sound_effect* effect = getEffect(sfx); memset(effect, 0, sizeof(tic_sound_effect)); - history_add(sfx->history.envelope); + history_add(sfx->history); } static void resetWave(Sfx* sfx) @@ -606,7 +596,7 @@ static void resetWave(Sfx* sfx) tic_waveform* wave = getWaveform(sfx); memset(wave, 0, sizeof(tic_waveform)); - history_add(sfx->history.waveform); + history_add(sfx->history); } static void cutToClipboard(Sfx* sfx) @@ -626,7 +616,7 @@ static void copyFromClipboard(Sfx* sfx) tic_sound_effect* effect = getEffect(sfx); if(fromClipboard(effect, sizeof(tic_sound_effect), true, false)) - history_add(sfx->history.envelope); + history_add(sfx->history); } static void copyWaveFromClipboard(Sfx* sfx) @@ -634,7 +624,7 @@ static void copyWaveFromClipboard(Sfx* sfx) tic_waveform* wave = getWaveform(sfx); if(fromClipboard(wave, sizeof(tic_waveform), true, false)) - history_add(sfx->history.waveform); + history_add(sfx->history); } static void processKeyboard(Sfx* sfx) @@ -728,8 +718,8 @@ static void processWaveformKeydown(Sfx* sfx, SDL_Keycode keycode) { switch(keycode) { - case SDLK_z: undoWave(sfx); break; - case SDLK_y: redoWave(sfx); break; + case SDLK_z: undo(sfx); break; + case SDLK_y: redo(sfx); break; } } @@ -948,7 +938,7 @@ static void drawWaveformCanvas(Sfx* sfx, s32 x, s32 y) tic_tool_poke4(wave->data, mx, Rows - my - 1); - history_add(sfx->history.waveform); + history_add(sfx->history); } } @@ -1019,8 +1009,8 @@ static void onStudioWaveformEvent(Sfx* sfx, StudioEvent event) case TIC_TOOLBAR_CUT: cutWaveToClipboard(sfx); break; case TIC_TOOLBAR_COPY: copyWaveToClipboard(sfx); break; case TIC_TOOLBAR_PASTE: copyWaveFromClipboard(sfx); break; - case TIC_TOOLBAR_UNDO: undoWave(sfx); break; - case TIC_TOOLBAR_REDO: redoWave(sfx); break; + case TIC_TOOLBAR_UNDO: undo(sfx); break; + case TIC_TOOLBAR_REDO: redo(sfx); break; default: break; } } @@ -1035,15 +1025,15 @@ static void onStudioEvent(Sfx* sfx, StudioEvent event) } } -void initSfx(Sfx* sfx, tic_mem* tic) +void initSfx(Sfx* sfx, tic_mem* tic, tic_sfx* src) { - if(sfx->history.envelope) history_delete(sfx->history.envelope); - if(sfx->history.waveform) history_delete(sfx->history.waveform); + if(sfx->history) history_delete(sfx->history); *sfx = (Sfx) { .tic = tic, .tick = tick, + .src = src, .index = 0, .play = { @@ -1056,11 +1046,7 @@ void initSfx(Sfx* sfx, tic_mem* tic) }, .canvasTab = SFX_WAVE_TAB, .tab = SFX_ENVELOPES_TAB, - .history = - { - .envelope = history_create(&tic->cart.bank0.sfx.data, sizeof tic->cart.bank0.sfx.data), - .waveform = history_create(&tic->cart.bank0.sfx.waveform, sizeof tic->cart.bank0.sfx.waveform), - }, + .history = history_create(src, sizeof(tic_sfx)), .event = onStudioEvent, }; } \ No newline at end of file diff --git a/src/sfx.h b/src/sfx.h index 19108b7..4a0feb9 100644 --- a/src/sfx.h +++ b/src/sfx.h @@ -30,6 +30,8 @@ struct Sfx { tic_mem* tic; + tic_sfx* src; + u8 index:SFX_COUNT_BITS; struct @@ -57,14 +59,10 @@ struct Sfx SFX_ENVELOPES_TAB, } tab; - struct - { - struct History* envelope; - struct History* waveform; - } history; + struct History* history; void(*tick)(Sfx*); void(*event)(Sfx*, StudioEvent); }; -void initSfx(Sfx*, tic_mem*); \ No newline at end of file +void initSfx(Sfx*, tic_mem*, tic_sfx* src); \ No newline at end of file diff --git a/src/sprite.c b/src/sprite.c index 0bb39c9..bdcb30f 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -38,12 +38,12 @@ static void clearCanvasSelection(Sprite* sprite) static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y) { - return getSpritePixel(getBankTiles()->data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y); + return getSpritePixel(sprite->src->data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y); } static void setSheetPixel(Sprite* sprite, s32 x, s32 y, u8 color) { - setSpritePixel(getBankTiles()->data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y, color); + setSpritePixel(sprite->src->data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y, color); } static s32 getIndexPosX(Sprite* sprite) @@ -959,7 +959,7 @@ static void drawSheetOvr(Sprite* sprite, s32 x, s32 y) for(s32 j = 0, index = (sprite->index - sprite->index % TIC_BANK_SPRITES); j < rect.h; j += TIC_SPRITESIZE) for(s32 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++) - sprite->tic->api.sprite(sprite->tic, getBankTiles(), index, x + i, y + j, NULL, 0); + sprite->tic->api.sprite(sprite->tic, sprite->src, index, x + i, y + j, NULL, 0); { s32 bx = getIndexPosX(sprite) + x - 1; s32 by = getIndexPosY(sprite) + y - 1; @@ -1544,7 +1544,7 @@ static void overlap(tic_mem* tic, void* data) drawSheetOvr(sprite, TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, 7); } -void initSprite(Sprite* sprite, tic_mem* tic) +void initSprite(Sprite* sprite, tic_mem* tic, tic_tiles* src) { if(sprite->select.back == NULL) sprite->select.back = (u8*)SDL_malloc(CANVAS_SIZE*CANVAS_SIZE); if(sprite->select.front == NULL) sprite->select.front = (u8*)SDL_malloc(CANVAS_SIZE*CANVAS_SIZE); @@ -1555,6 +1555,7 @@ void initSprite(Sprite* sprite, tic_mem* tic) .tic = tic, .tick = tick, .tickCounter = 0, + .src = src, .index = 0, .color = 1, .color2 = 0, @@ -1570,7 +1571,7 @@ void initSprite(Sprite* sprite, tic_mem* tic) .front = sprite->select.front, }, .mode = SPRITE_DRAW_MODE, - .history = history_create(&tic->cart.bank0.tiles, TIC_SPRITES * sizeof(tic_tile)), + .history = history_create(src, TIC_SPRITES * sizeof(tic_tile)), .event = onStudioEvent, .overlap = overlap, }; diff --git a/src/sprite.h b/src/sprite.h index a147108..2b13752 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -30,6 +30,8 @@ struct Sprite { tic_mem* tic; + tic_tiles* src; + u32 tickCounter; u16 index; @@ -64,4 +66,4 @@ struct Sprite void (*overlap)(tic_mem* tic, void* data); }; -void initSprite(Sprite*, tic_mem*); \ No newline at end of file +void initSprite(Sprite*, tic_mem*, tic_tiles* src); \ No newline at end of file diff --git a/src/studio.c b/src/studio.c index 3ad34b3..2a8d421 100644 --- a/src/studio.c +++ b/src/studio.c @@ -162,7 +162,7 @@ static struct struct { s32 code; - s32 tiles; + s32 sprites; s32 map; s32 sfx; s32 music; @@ -196,17 +196,21 @@ static struct bool fullscreen; + struct + { + Code* code[TIC_BANKS]; + Sprite* sprite[TIC_BANKS]; + Map* map[TIC_BANKS]; + Sfx* sfx[TIC_BANKS]; + Music* music[TIC_BANKS]; + } editor; + struct { Start* start; Console* console; Run* run; - Code* code[TIC_BANKS]; - Sprite* sprite; - Map* map; World* world; - Sfx* sfx; - Music* music; Config* config; Keymap* keymap; Dialog* dialog; @@ -312,12 +316,7 @@ static struct tic_tiles* getBankTiles() { - return &studio.tic->cart.banks[studio.bank.index.tiles].tiles; -} - -tic_tiles* getBankSprites() -{ - return &studio.tic->cart.banks[studio.bank.index.tiles].sprites; + return &studio.tic->cart.banks[studio.bank.index.sprites].tiles; } tic_map* getBankMap() @@ -325,16 +324,6 @@ tic_map* getBankMap() return &studio.tic->cart.banks[studio.bank.index.map].map; } -tic_sfx* getBankSfx() -{ - return &studio.tic->cart.banks[studio.bank.index.sfx].sfx; -} - -tic_music* getBankMusic() -{ - return &studio.tic->cart.banks[studio.bank.index.music].music; -} - void playSystemSfx(s32 id) { const tic_sound_effect* effect = &studio.tic->config.bank0.sfx.data[id]; @@ -782,14 +771,34 @@ void setStudioEvent(StudioEvent event) { case TIC_CODE_MODE: { - Code* code = studio.code[studio.bank.index.code]; + Code* code = studio.editor.code[studio.bank.index.code]; code->event(code, event); } break; - case TIC_SPRITE_MODE: studio.sprite->event(studio.sprite, event); break; - case TIC_MAP_MODE: studio.map->event(studio.map, event); break; - case TIC_SFX_MODE: studio.sfx->event(studio.sfx, event); break; - case TIC_MUSIC_MODE: studio.music->event(studio.music, event); break; + case TIC_SPRITE_MODE: + { + Sprite* sprite = studio.editor.sprite[studio.bank.index.sprites]; + sprite->event(sprite, event); + } + break; + case TIC_MAP_MODE: + { + Map* map = studio.editor.map[studio.bank.index.map]; + map->event(map, event); + } + break; + case TIC_SFX_MODE: + { + Sfx* sfx = studio.editor.sfx[studio.bank.index.sfx]; + sfx->event(sfx, event); + } + break; + case TIC_MUSIC_MODE: + { + Music* music = studio.editor.music[studio.bank.index.music]; + music->event(music, event); + } + break; default: break; } } @@ -864,7 +873,7 @@ void drawBitIcon(s32 x, s32 y, const u8* ptr, u8 color) static void initWorldMap() { - initWorld(studio.world, studio.tic, studio.map); + initWorld(studio.world, studio.tic, studio.editor.map[studio.bank.index.map]); } static void initRunMode() @@ -1074,14 +1083,18 @@ void showDialog(const char** text, s32 rows, DialogCallback callback, void* data static void initModules() { - for(s32 i = 0; i < TIC_BANKS; i++) - initCode(studio.code[i], studio.tic, &studio.tic->cart.banks[i].code); + tic_mem* tic = studio.tic; + + for(s32 i = 0; i < TIC_BANKS; i++) + { + initCode(studio.editor.code[i], studio.tic, &tic->cart.banks[i].code); + initSprite(studio.editor.sprite[i], studio.tic, &tic->cart.banks[i].tiles); + initMap(studio.editor.map[i], studio.tic, &tic->cart.banks[i].map); + initSfx(studio.editor.sfx[i], studio.tic, &tic->cart.banks[i].sfx); + initMusic(studio.editor.music[i], studio.tic, &tic->cart.banks[i].music); + } - initSprite(studio.sprite, studio.tic); - initMap(studio.map, studio.tic); initWorldMap(); - initSfx(studio.sfx, studio.tic); - initMusic(studio.music, studio.tic); } static void updateHash() @@ -1781,7 +1794,7 @@ static bool processShortcuts(SDL_KeyboardEvent* event) case SDLK_ESCAPE: case SDLK_AC_BACK: { - Code* code = studio.code[studio.bank.index.code]; + Code* code = studio.editor.code[studio.bank.index.code]; if(studio.mode == TIC_CODE_MODE && code->mode != TEXT_EDIT_MODE) { @@ -1919,8 +1932,8 @@ SDL_Event* pollEvent() #endif { - Code* code = studio.code[studio.bank.index.code]; - studio.console->codeLiveReload.reload(studio.console, code->data); + Code* code = studio.editor.code[studio.bank.index.code]; + studio.console->codeLiveReload.reload(studio.console, code->src); if(studio.console->codeLiveReload.active && code->update) code->update(code); } @@ -2083,12 +2096,18 @@ static void blitTexture() overlap = tic->api.overlap; break; case TIC_SPRITE_MODE: - overlap = studio.sprite->overlap; - data = studio.sprite; + { + Sprite* sprite = studio.editor.sprite[studio.bank.index.sprites]; + overlap = sprite->overlap; + data = sprite; + } break; case TIC_MAP_MODE: - overlap = studio.map->overlap; - data = studio.map; + { + Map* map = studio.editor.map[studio.bank.index.map]; + overlap = map->overlap; + data = map; + } break; default: break; @@ -2268,8 +2287,8 @@ static void renderStudio() music = &studio.tic->config.bank0.music; break; default: - sfx = getBankSfx(); - music = getBankMusic(); + sfx = &studio.tic->cart.banks[studio.bank.index.sfx].sfx; + music = &studio.tic->cart.banks[studio.bank.index.music].music; } studio.tic->api.tick_start(studio.tic, sfx, music); @@ -2282,15 +2301,36 @@ static void renderStudio() case TIC_RUN_MODE: studio.run->tick(studio.run); break; case TIC_CODE_MODE: { - Code* code = studio.code[studio.bank.index.code]; + Code* code = studio.editor.code[studio.bank.index.code]; code->tick(code); } break; - case TIC_SPRITE_MODE: studio.sprite->tick(studio.sprite); break; - case TIC_MAP_MODE: studio.map->tick(studio.map); break; + case TIC_SPRITE_MODE: + { + Sprite* sprite = studio.editor.sprite[studio.bank.index.sprites]; + sprite->tick(sprite); + } + break; + case TIC_MAP_MODE: + { + Map* map = studio.editor.map[studio.bank.index.map]; + map->tick(map); + } + break; + case TIC_SFX_MODE: + { + Sfx* sfx = studio.editor.sfx[studio.bank.index.sfx]; + sfx->tick(sfx); + } + break; + case TIC_MUSIC_MODE: + { + Music* music = studio.editor.music[studio.bank.index.music]; + music->tick(music); + } + break; + case TIC_WORLD_MODE: studio.world->tick(studio.world); break; - case TIC_SFX_MODE: studio.sfx->tick(studio.sfx); break; - case TIC_MUSIC_MODE: studio.music->tick(studio.music); break; case TIC_KEYMAP_MODE: studio.keymap->tick(studio.keymap); break; case TIC_DIALOG_MODE: studio.dialog->tick(studio.dialog); break; case TIC_MENU_MODE: studio.menu->tick(studio.menu); break; @@ -2481,7 +2521,7 @@ static void updateSystemFont() void studioConfigChanged() { - Code* code = studio.code[studio.bank.index.code]; + Code* code = studio.editor.code[studio.bank.index.code]; if(code->update) code->update(code); @@ -2567,21 +2607,23 @@ static void onFSInitialized(FileSystem* fs) { for(s32 i = 0; i < TIC_BANKS; i++) - studio.code[i] = SDL_malloc(sizeof(Code)); + { + studio.editor.code[i] = SDL_malloc(sizeof(Code)); + studio.editor.sprite[i] = SDL_malloc(sizeof(Sprite)); + studio.editor.map[i] = SDL_malloc(sizeof(Map)); + studio.editor.sfx[i] = SDL_malloc(sizeof(Sfx)); + studio.editor.music[i] = SDL_malloc(sizeof(Music)); + } - studio.start = SDL_malloc(sizeof(Start)); - studio.console = SDL_malloc(sizeof(Console)); - studio.run = SDL_malloc(sizeof(Run)); - studio.sprite = SDL_malloc(sizeof(Sprite)); - studio.map = SDL_malloc(sizeof(Map)); - studio.world = SDL_malloc(sizeof(World)); - studio.sfx = SDL_malloc(sizeof(Sfx)); - studio.music = SDL_malloc(sizeof(Music)); - studio.config = SDL_malloc(sizeof(Config)); - studio.keymap = SDL_malloc(sizeof(Keymap)); - studio.dialog = SDL_malloc(sizeof(Dialog)); - studio.menu = SDL_malloc(sizeof(Menu)); - studio.surf = SDL_malloc(sizeof(Surf)); + studio.start = SDL_malloc(sizeof(Start)); + studio.console = SDL_malloc(sizeof(Console)); + studio.run = SDL_malloc(sizeof(Run)); + studio.world = SDL_malloc(sizeof(World)); + studio.config = SDL_malloc(sizeof(Config)); + studio.keymap = SDL_malloc(sizeof(Keymap)); + studio.dialog = SDL_malloc(sizeof(Dialog)); + studio.menu = SDL_malloc(sizeof(Menu)); + studio.surf = SDL_malloc(sizeof(Surf)); } fsMakeDir(fs, TIC_LOCAL); @@ -2677,16 +2719,18 @@ s32 main(s32 argc, char **argv) { for(s32 i = 0; i < TIC_BANKS; i++) - SDL_free(studio.code[i]); + { + SDL_free(studio.editor.code[i]); + SDL_free(studio.editor.sprite[i]); + SDL_free(studio.editor.map[i]); + SDL_free(studio.editor.sfx[i]); + SDL_free(studio.editor.music[i]); + } SDL_free(studio.start); SDL_free(studio.console); SDL_free(studio.run); - SDL_free(studio.sprite); - SDL_free(studio.map); SDL_free(studio.world); - SDL_free(studio.sfx); - SDL_free(studio.music); SDL_free(studio.config); SDL_free(studio.keymap); SDL_free(studio.dialog); diff --git a/src/studio.h b/src/studio.h index 1115995..67288b9 100644 --- a/src/studio.h +++ b/src/studio.h @@ -200,8 +200,5 @@ void gotoSurf(); void exitFromGameMenu(); void runProject(); -tic_tiles* getBankTiles(); -tic_tiles* getBankSprites(); -tic_map* getBankMap(); -tic_sfx* getBankSfx(); -tic_music* getBankMusic(); +tic_tiles* getBankTiles(); +tic_map* getBankMap(); From 272f6af99123c5288590b17c270f8974f1fd9058 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 17:19:35 +0300 Subject: [PATCH 11/11] 1 bank for non Pro build --- src/jsapi.c | 2 +- src/luaapi.c | 2 +- src/studio.c | 24 +++++++++++++++--------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/jsapi.c b/src/jsapi.c index 03133f3..e28bd80 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -512,7 +512,7 @@ static duk_ret_t duk_pmem(duk_context* duk) u32 index = duk_to_int(duk, 0); - if(index >= 0 && index < TIC_PERSISTENT_SIZE) + if(index < TIC_PERSISTENT_SIZE) { s32 val = memory->ram.persistent.data[index]; diff --git a/src/luaapi.c b/src/luaapi.c index 4c3cab9..f702c35 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -981,7 +981,7 @@ static s32 lua_pmem(lua_State *lua) { u32 index = getLuaNumber(lua, 1); - if(index >= 0 && index < TIC_PERSISTENT_SIZE) + if(index < TIC_PERSISTENT_SIZE) { s32 val = memory->ram.persistent.data[index]; diff --git a/src/studio.c b/src/studio.c index 2a8d421..0f7573e 100644 --- a/src/studio.c +++ b/src/studio.c @@ -59,6 +59,12 @@ #define POPUP_DUR (TIC_FRAMERATE*2) +#if defined(TIC80_PRO) +#define TIC_EDITOR_BANKS (TIC_BANKS) +#else +#define TIC_EDITOR_BANKS 1 +#endif + typedef struct { u8 data[16]; @@ -198,11 +204,11 @@ static struct struct { - Code* code[TIC_BANKS]; - Sprite* sprite[TIC_BANKS]; - Map* map[TIC_BANKS]; - Sfx* sfx[TIC_BANKS]; - Music* music[TIC_BANKS]; + Code* code [TIC_EDITOR_BANKS]; + Sprite* sprite [TIC_EDITOR_BANKS]; + Map* map [TIC_EDITOR_BANKS]; + Sfx* sfx [TIC_EDITOR_BANKS]; + Music* music [TIC_EDITOR_BANKS]; } editor; struct @@ -607,7 +613,7 @@ static void drawBankIcon(s32 x, s32 y) enum{Size = TOOLBAR_SIZE}; - for(s32 i = 0; i < TIC_BANKS; i++) + for(s32 i = 0; i < TIC_EDITOR_BANKS; i++) { SDL_Rect rect = {x + 2 + (i+1)*Size, 0, Size, Size}; @@ -1085,7 +1091,7 @@ static void initModules() { tic_mem* tic = studio.tic; - for(s32 i = 0; i < TIC_BANKS; i++) + for(s32 i = 0; i < TIC_EDITOR_BANKS; i++) { initCode(studio.editor.code[i], studio.tic, &tic->cart.banks[i].code); initSprite(studio.editor.sprite[i], studio.tic, &tic->cart.banks[i].tiles); @@ -2606,7 +2612,7 @@ static void onFSInitialized(FileSystem* fs) studio.tic = studio.tic80local->memory; { - for(s32 i = 0; i < TIC_BANKS; i++) + for(s32 i = 0; i < TIC_EDITOR_BANKS; i++) { studio.editor.code[i] = SDL_malloc(sizeof(Code)); studio.editor.sprite[i] = SDL_malloc(sizeof(Sprite)); @@ -2718,7 +2724,7 @@ s32 main(s32 argc, char **argv) #endif { - for(s32 i = 0; i < TIC_BANKS; i++) + for(s32 i = 0; i < TIC_EDITOR_BANKS; i++) { SDL_free(studio.editor.code[i]); SDL_free(studio.editor.sprite[i]);