palette excluded from bank

This commit is contained in:
BADIM-PC\Vadim 2017-12-14 15:05:43 +03:00
parent e8cb3599df
commit 4f55ed7667
7 changed files with 25 additions and 32 deletions

View File

@ -289,7 +289,7 @@ static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s
if(palette) 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++) 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; 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); tic->api.load(cart, buffer, size, palette);
if(!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) 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 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 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 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(); 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; typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection;
static const BinarySection BinarySections[] = 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}, {"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}, {"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}, {"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) if(cart)
{ {
SDL_memset(cart, 0, sizeof(tic_cartridge)); 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); 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]; u8 src = image->buffer[x + y * image->width];
const gif_color* c = &image->palette[src]; const gif_color* c = &image->palette[src];
tic_rgb rgb = {c->r, c->g, c->b}; 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); 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]; u8 src = image->buffer[x + y * image->width];
const gif_color* c = &image->palette[src]; const gif_color* c = &image->palette[src];
tic_rgb rgb = {c->r, c->g, c->b}; 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); 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) 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; u32 argp = 1;

View File

@ -672,8 +672,8 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value)
static void pasteColor(Sprite* sprite) static void pasteColor(Sprite* sprite)
{ {
fromClipboard(getBankPalette()->data, sizeof(tic_palette), false, true); fromClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false, true);
fromClipboard(&getBankPalette()->colors[sprite->color], sizeof(tic_rgb), false, true); fromClipboard(&sprite->tic->cart.palette.colors[sprite->color], sizeof(tic_rgb), false, true);
} }
static void drawRGBTools(Sprite* sprite, s32 x, s32 y) static void drawRGBTools(Sprite* sprite, s32 x, s32 y)
@ -708,7 +708,7 @@ static void drawRGBTools(Sprite* sprite, s32 x, s32 y)
down = true; down = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) 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) if(down)
@ -772,7 +772,7 @@ static void drawRGBSliders(Sprite* sprite, s32 x, s32 y)
{ {
enum{Gap = 6, Count = sizeof(tic_rgb)}; 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++) for(s32 i = 0; i < Count; i++)
drawRGBSlider(sprite, x, y + Gap*i, &data[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}; 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++) for(s32 i = 0; i < Count; i++)
{ {

View File

@ -335,11 +335,6 @@ tic_music* getBankMusic()
return &studio.tic->cart.banks[studio.bank.index.music].music; 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) void playSystemSfx(s32 id)
{ {
const tic_sound_effect* effect = &studio.tic->config.bank.sfx.data[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* in = studio.tic->ram.vram.screen.data;
const u8* end = in + sizeof(studio.tic->ram.vram.screen); 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); const u32 Delta = (pitch/sizeof *out - TIC80_WIDTH);
s32 col = 0; s32 col = 0;
@ -2053,7 +2048,7 @@ static void recordFrame(u32* pixels)
if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2) 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]); drawRecordLabel(pixels, TIC80_FULLWIDTH, TIC80_WIDTH-24, 8, &pal[tic_color_red]);
} }
@ -2219,7 +2214,7 @@ static void renderCursor()
static void useSystemPalette() 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() static void drawPopup()
@ -2501,7 +2496,7 @@ static void setWindowIcon()
u32* pixels = SDL_malloc(Size * Size * sizeof(u32)); 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 j = 0, index = 0; j < Size; j++)
for(s32 i = 0; i < Size; i++, index++) for(s32 i = 0; i < Size; i++, index++)

View File

@ -205,4 +205,3 @@ tic_tiles* getBankSprites();
tic_map* getBankMap(); tic_map* getBankMap();
tic_sfx* getBankSfx(); tic_sfx* getBankSfx();
tic_music* getBankMusic(); tic_music* getBankMusic();
tic_palette* getBankPalette();

View File

@ -508,7 +508,7 @@ static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size)
{ {
const gif_color* c = &image->palette[image->buffer[i]]; const gif_color* c = &image->palette[image->buffer[i]];
tic_rgb rgb = { c->r, c->g, c->b }; 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); tic_tool_poke4(item->cover->data, i, color);
} }
} }

View File

@ -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 void resetPalette(tic_mem* memory)
{ {
static const u8 DefaultMapping[] = {16, 50, 84, 118, 152, 186, 220, 254}; 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); 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.setpix = setPixelOvr;
machine->state.getpix = getPixelOvr; 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]]; const gif_color* c = &image->palette[image->buffer[i]];
tic_rgb rgb = { c->r, c->g, c->b }; 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); 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)}, {"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)}, {"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)}, {"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); 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) 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}; 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)) #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_PATTERNS: LOAD_CHUNK(cart->bank.music.patterns.data); break;
case CHUNK_PALETTE: case CHUNK_PALETTE:
if(palette) if(palette)
LOAD_CHUNK(cart->bank.palette); LOAD_CHUNK(cart->palette);
break; break;
case CHUNK_COVER: case CHUNK_COVER:
LOAD_CHUNK(cart->cover.data); 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_WAVEFORM, cart->bank.sfx.waveform);
buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->bank.music.patterns.data); buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->bank.music.patterns.data);
buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->bank.music.tracks.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); buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size);

View File

@ -334,7 +334,6 @@ typedef struct
tic_sfx sfx; tic_sfx sfx;
tic_music music; tic_music music;
tic_code code; tic_code code;
tic_palette palette;
} tic_bank; } tic_bank;
typedef struct typedef struct
@ -345,6 +344,7 @@ typedef struct
tic_bank banks[TIC_BANKS]; tic_bank banks[TIC_BANKS];
}; };
tic_palette palette;
tic_cover_image cover; tic_cover_image cover;
} tic_cartridge; } tic_cartridge;