From fbf9daa68d6ed69bc81cd2df94dab568ccf0b4c6 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Mon, 12 Mar 2018 09:40:48 +0300 Subject: [PATCH] config cart moved from tic_mem --- src/config.c | 12 +++++++----- src/config.h | 1 + src/console.c | 8 +++----- src/dialog.c | 2 +- src/map.c | 2 +- src/menu.c | 4 ++-- src/music.c | 2 +- src/sprite.c | 2 +- src/studio.c | 14 +++++++------- src/surf.c | 12 +++++------- src/system.c | 18 +++++++++--------- src/system.h | 1 + src/system/chip.c | 6 +++--- src/ticapi.h | 1 - 14 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/config.c b/src/config.c index 7ffb691..88a7e43 100644 --- a/src/config.c +++ b/src/config.c @@ -240,7 +240,7 @@ static void readConfig(Config* config) if(lua) { - if(luaL_loadstring(lua, config->tic->config.bank0.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK) + if(luaL_loadstring(lua, config->cart.bank0.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK) { readConfigVideoLength(config, lua); readConfigVideoScale(config, lua); @@ -251,7 +251,7 @@ static void readConfig(Config* config) readTheme(config, lua); } - if(luaL_loadstring(lua, config->tic->config.bank1.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK) + if(luaL_loadstring(lua, config->cart.bank1.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK) { readConfigCrtShader(config, lua); } @@ -262,7 +262,7 @@ static void readConfig(Config* config) static void update(Config* config, const u8* buffer, size_t size) { - config->tic->api.load(&config->tic->config, buffer, size, true); + config->tic->api.load(&config->cart, buffer, size, true); readConfig(config); studioConfigChanged(); @@ -272,6 +272,8 @@ static void setDefault(Config* config) { memset(&config->data, 0, sizeof(StudioConfig)); + config->data.cart = &config->cart; + { static const u8 DefaultBiosZip[] = { @@ -296,7 +298,7 @@ static void saveConfig(Config* config, bool overwrite) if(buffer) { - s32 size = config->tic->api.save(&config->tic->config, buffer); + s32 size = config->tic->api.save(&config->cart, buffer); fsSaveRootFile(config->fs, CONFIG_TIC_PATH, buffer, size, overwrite); @@ -312,7 +314,7 @@ static void reset(Config* config) static void save(Config* config) { - memcpy(&config->tic->config, &config->tic->cart, sizeof(tic_cartridge)); + memcpy(&config->cart, &config->tic->cart, sizeof(tic_cartridge)); readConfig(config); saveConfig(config, true); diff --git a/src/config.h b/src/config.h index d3bc0d1..3bc74f1 100644 --- a/src/config.h +++ b/src/config.h @@ -32,6 +32,7 @@ struct Config struct FileSystem* fs; StudioConfig data; + tic_cartridge cart; void(*save)(Config*); void(*reset)(Config*); diff --git a/src/console.c b/src/console.c index 9328a38..9d590ab 100644 --- a/src/console.c +++ b/src/console.c @@ -361,7 +361,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->bank0.palette.data, tic->config.bank0.palette.data, sizeof(tic_palette)); + memcpy(cart->bank0.palette.data, getConfig()->cart->bank0.palette.data, sizeof(tic_palette)); } static bool loadRom(tic_mem* tic, const void* data, s32 size, bool palette) @@ -887,8 +887,6 @@ static bool loadBinarySection(const char* project, const char* comment, const ch static bool loadProject(Console* console, const char* name, const char* data, s32 size, tic_cartridge* dst) { - tic_mem* tic = console->tic; - char* project = (char*)malloc(size+1); bool done = false; @@ -909,7 +907,7 @@ static bool loadProject(Console* console, const char* name, const char* data, s3 if(cart) { memset(cart, 0, sizeof(tic_cartridge)); - memcpy(&cart->bank0.palette, &tic->config.bank0.palette.data, sizeof(tic_palette)); + memcpy(&cart->bank0.palette, &getConfig()->cart->bank0.palette.data, sizeof(tic_palette)); const char* comment = projectComment(name); char tag[16]; @@ -3099,7 +3097,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, if(argc > 1) { - memcpy(console->embed.file->bank0.palette.data, tic->config.bank0.palette.data, sizeof(tic_palette)); + memcpy(console->embed.file->bank0.palette.data, getConfig()->cart->bank0.palette.data, sizeof(tic_palette)); u32 argp = 1; diff --git a/src/dialog.c b/src/dialog.c index 89ef05b..3dd84c3 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -168,7 +168,7 @@ static void drawDialog(Dialog* dlg) { u8 chromakey = 14; - 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); + tic->api.sprite_ex(tic, &getConfig()->cart->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 b82a89f..ae3806f 100644 --- a/src/map.c +++ b/src/map.c @@ -1086,7 +1086,7 @@ static void onStudioEvent(Map* map, StudioEvent event) static void scanline(tic_mem* tic, s32 row, void* data) { if(row == 0) - memcpy(tic->ram.vram.palette.data, tic->config.bank0.palette.data, sizeof(tic_palette)); + memcpy(tic->ram.vram.palette.data, getConfig()->cart->bank0.palette.data, sizeof(tic_palette)); } static void overline(tic_mem* tic, void* data) diff --git a/src/menu.c b/src/menu.c index 01fa9ce..36e3208 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.bank0.tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &getConfig()->cart->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.bank0.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &getConfig()->cart->bank0.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); static const char* const Names[tic_keys_count] = {"...", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "minus", "equals", "leftbracket", "rightbracket", "backslash", "semicolon", "apostrophe", "grave", "comma", "period", "slash", "space", "tab", "return", "backspace", "delete", "insert", "pageup", "pagedown", "home", "end", "up", "down", "left", "right", "capslock", "ctrl", "shift", "alt", "escape", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12"}; diff --git a/src/music.c b/src/music.c index ff75e69..ab8cec9 100644 --- a/src/music.c +++ b/src/music.c @@ -1354,7 +1354,7 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index) } u8 color = Chroma; - tic->api.sprite(tic, &tic->config.bank0.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1); + tic->api.sprite(tic, &getConfig()->cart->bank0.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1); } static void drawTracker(Music* music, s32 x, s32 y) diff --git a/src/sprite.c b/src/sprite.c index 856a490..155dcc2 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -1628,7 +1628,7 @@ static void onStudioEvent(Sprite* sprite, StudioEvent event) static void scanline(tic_mem* tic, s32 row, void* data) { if(row == 0) - memcpy(tic->ram.vram.palette.data, tic->config.bank0.palette.data, sizeof(tic_palette)); + memcpy(tic->ram.vram.palette.data, getConfig()->cart->bank0.palette.data, sizeof(tic_palette)); } static void overline(tic_mem* tic, void* data) diff --git a/src/studio.c b/src/studio.c index e845e83..3592758 100644 --- a/src/studio.c +++ b/src/studio.c @@ -293,7 +293,7 @@ tic_palette* getBankPalette() void playSystemSfx(s32 id) { - const tic_sample* effect = &impl.studio.tic->config.bank0.sfx.samples.data[id]; + const tic_sample* effect = &impl.config->cart.bank0.sfx.samples.data[id]; impl.studio.tic->api.sfx_ex(impl.studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0); } @@ -1481,7 +1481,7 @@ static void drawDesyncLabel(u32* frame) enum{sx = TIC80_WIDTH-24, sy = 8, Cols = sizeof DesyncLabel[0]*BITS_IN_BYTE, Rows = COUNT_OF(DesyncLabel)}; - const u32* pal = tic_palette_blit(&impl.studio.tic->config.bank0.palette); + const u32* pal = tic_palette_blit(&impl.config->cart.bank0.palette); const u32* color = &pal[tic_color_red]; for(s32 y = 0; y < Rows; y++) @@ -1506,7 +1506,7 @@ static void recordFrame(u32* pixels) if(impl.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2) { - const u32* pal = tic_palette_blit(&impl.studio.tic->config.bank0.palette); + const u32* pal = tic_palette_blit(&impl.config->cart.bank0.palette); drawRecordLabel(pixels, TIC80_WIDTH-24, 8, &pal[tic_color_red]); } @@ -1562,8 +1562,8 @@ static void renderStudio() case TIC_DIALOG_MODE: case TIC_MENU_MODE: case TIC_SURF_MODE: - sfx = &impl.studio.tic->config.bank0.sfx; - music = &impl.studio.tic->config.bank0.music; + sfx = &impl.config->cart.bank0.sfx; + music = &impl.config->cart.bank0.music; break; default: sfx = &impl.studio.tic->cart.banks[impl.bank.index.sfx].sfx; @@ -1631,7 +1631,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(&impl.studio.tic->config.bank0.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1)) + if(tic_tool_peek4(&impl.config->cart.bank0.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1)) impl.studio.tic->font.data[i*BITS_IN_BYTE+y] |= 1 << x; } @@ -1760,7 +1760,7 @@ static void studioTick() } break; default: - memcpy(&tic->ram.vram.palette, &tic->config.bank0.palette, sizeof(tic_palette)); + memcpy(&tic->ram.vram.palette, &impl.config->cart.bank0.palette, sizeof(tic_palette)); break; } diff --git a/src/surf.c b/src/surf.c index ae96466..ee80031 100644 --- a/src/surf.c +++ b/src/surf.c @@ -201,14 +201,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.bank0.tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &getConfig()->cart->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.bank0.tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &getConfig()->cart->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.bank0.tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &getConfig()->cart->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.bank0.tiles, 34, i*Size - offset, j*Size - offset, 2, 2, 0, 0, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &getConfig()->cart->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) @@ -490,8 +490,6 @@ static void* requestCover(Surf* surf, const char* hash, s32* size) static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size) { - tic_mem* tic = surf->tic; - MenuItem* item = &surf->menu.items[surf->menu.pos]; item->cover = malloc(sizeof(tic_screen)); @@ -508,7 +506,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.bank0.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(getConfig()->cart->bank0.palette.colors, &rgb); tic_tool_poke4(item->cover->data, i, color); } } diff --git a/src/system.c b/src/system.c index e19d11c..3bbd6b0 100644 --- a/src/system.c +++ b/src/system.c @@ -99,13 +99,13 @@ static void initSound() } } -static u8* getSpritePtr(tic_tile* tiles, s32 x, s32 y) +static const u8* getSpritePtr(const tic_tile* tiles, s32 x, s32 y) { enum { SheetCols = (TIC_SPRITESHEET_SIZE / TIC_SPRITESIZE) }; return tiles[x / TIC_SPRITESIZE + y / TIC_SPRITESIZE * SheetCols].data; } -static u8 getSpritePixel(tic_tile* tiles, s32 x, s32 y) +static u8 getSpritePixel(const tic_tile* tiles, s32 x, s32 y) { return tic_tool_peek4(getSpritePtr(tiles, x, y), (x % TIC_SPRITESIZE) + (y % TIC_SPRITESIZE) * TIC_SPRITESIZE); } @@ -117,12 +117,12 @@ static void setWindowIcon() u32* pixels = SDL_malloc(Size * Size * sizeof(u32)); - const u32* pal = tic_palette_blit(&platform.studio->tic->config.bank0.palette); + const u32* pal = tic_palette_blit(&platform.studio->config()->cart->bank0.palette); for(s32 j = 0, index = 0; j < Size; j++) for(s32 i = 0; i < Size; i++, index++) { - u8 color = getSpritePixel(platform.studio->tic->config.bank0.tiles.data, i/Scale, j/Scale); + u8 color = getSpritePixel(platform.studio->config()->cart->bank0.tiles.data, i/Scale, j/Scale); pixels[index] = color == ColorKey ? 0 : pal[color]; } @@ -165,7 +165,7 @@ static void updateGamepadParts() static void initTouchGamepad() { - platform.studio->tic->api.map(platform.studio->tic, &platform.studio->tic->config.bank0.map, &platform.studio->tic->config.bank0.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); + platform.studio->tic->api.map(platform.studio->tic, &platform.studio->config()->cart->bank0.map, &platform.studio->config()->cart->bank0.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); if(!platform.gamepad.texture) { @@ -182,7 +182,7 @@ static void initTouchGamepad() const u8* in = platform.studio->tic->ram.vram.screen.data; const u8* end = in + sizeof(platform.studio->tic->ram.vram.screen); - const u32* pal = tic_palette_blit(&platform.studio->tic->config.bank0.palette); + const u32* pal = tic_palette_blit(&platform.studio->config()->cart->bank0.palette); const u32 Delta = ((TIC80_FULLWIDTH*sizeof(u32))/sizeof *out - TIC80_WIDTH); s32 col = 0; @@ -784,7 +784,7 @@ static void renderCursor() if(platform.studio->config()->theme.cursor.hand >= 0) { SDL_ShowCursor(SDL_DISABLE); - blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.hand].data); + blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.hand].data); } else { @@ -798,7 +798,7 @@ static void renderCursor() if(platform.studio->config()->theme.cursor.ibeam >= 0) { SDL_ShowCursor(SDL_DISABLE); - blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.ibeam].data); + blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.ibeam].data); } else { @@ -812,7 +812,7 @@ static void renderCursor() if(platform.studio->config()->theme.cursor.arrow >= 0) { SDL_ShowCursor(SDL_DISABLE); - blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.arrow].data); + blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.arrow].data); } else { diff --git a/src/system.h b/src/system.h index 1e09e10..58bb177 100644 --- a/src/system.h +++ b/src/system.h @@ -74,6 +74,7 @@ typedef struct bool crtMonitor; const char* crtShader; + const tic_cartridge* cart; } StudioConfig; diff --git a/src/system/chip.c b/src/system/chip.c index 6755a82..e961d40 100644 --- a/src/system/chip.c +++ b/src/system/chip.c @@ -423,7 +423,7 @@ static void renderCursor() if(platform.studio->config()->theme.cursor.hand >= 0) { SDL_ShowCursor(SDL_DISABLE); - blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.hand].data); + blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.hand].data); } else { @@ -437,7 +437,7 @@ static void renderCursor() if(platform.studio->config()->theme.cursor.ibeam >= 0) { SDL_ShowCursor(SDL_DISABLE); - blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.ibeam].data); + blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.ibeam].data); } else { @@ -451,7 +451,7 @@ static void renderCursor() if(platform.studio->config()->theme.cursor.arrow >= 0) { SDL_ShowCursor(SDL_DISABLE); - blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.arrow].data); + blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.arrow].data); } else { diff --git a/src/ticapi.h b/src/ticapi.h index 7b8a990..5b530f3 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -173,7 +173,6 @@ struct tic_mem { tic_ram ram; tic_cartridge cart; - tic_cartridge config; tic_font font; tic_api api; tic_persistent persistent;