From 4f55ed7667228637c2edad986461cc4f74646a64 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 14 Dec 2017 15:05:43 +0300 Subject: [PATCH] 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;