diff --git a/src/code.c b/src/code.c index e715c3d..d65211c 100644 --- a/src/code.c +++ b/src/code.c @@ -1838,10 +1838,10 @@ void initCode(Code* code, tic_mem* tic) *code = (Code) { .tic = tic, - .data = tic->cart.code.data, + .data = tic->cart.bank.code.data, .tick = tick, .escape = escape, - .cursor = {{tic->cart.code.data, NULL, 0, 0}, NULL, 0}, + .cursor = {{tic->cart.bank.code.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/config.c b/src/config.c index 0cfd520..7a6c543 100644 --- a/src/config.c +++ b/src/config.c @@ -185,7 +185,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((tic_cartridge*)&config->tic->config, sizeof(tic_bank), buffer, size, true); readConfig(config); studioConfigChanged(); @@ -219,7 +219,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((tic_cartridge*)&config->tic->config, buffer); fsSaveRootFile(config->fs, CONFIG_TIC_PATH, buffer, size, overwrite); diff --git a/src/console.c b/src/console.c index 4a6280f..d22788f 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.palette.colors; + const tic_rgb* pal = tic->cart.bank.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; @@ -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, buffer, size, palette); + tic->api.load(cart, sizeof(tic_cartridge), buffer, size, palette); if(!palette) - memcpy(cart->palette.data, tic->config.palette.data, sizeof(tic_palette)); + memcpy(cart->bank.palette.data, tic->config.palette.data, sizeof(tic_palette)); } static bool loadRom(tic_mem* tic, const void* data, s32 size, bool palette) @@ -325,9 +325,9 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param) { static const char* Sections[] = { + "cover", "sprites", "map", - "cover", "code", "sfx", "music", @@ -359,13 +359,13 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param) switch(i) { - case 0: memcpy(&tic->cart.bank.tiles, &cart->bank.tiles, sizeof(tic_tiles)*2); break; - case 1: memcpy(&tic->cart.bank.map, &cart->bank.map, sizeof(tic_map)); break; - case 2: memcpy(&tic->cart.cover, &cart->cover, sizeof cart->cover); break; - case 3: memcpy(&tic->cart.code, &cart->code, sizeof cart->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 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.bank.palette, &cart->bank.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, palette.data), sizeof(tic_palette), false}, + {"PALETTE", 1, offsetof(tic_cartridge, bank.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}, @@ -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.code.data); + char* ptr = saveTextSection(stream, tic->cart.bank.code.data); for(s32 i = 0; i < COUNT_OF(BinarySections); i++) { @@ -734,11 +734,11 @@ static bool loadProject(Console* console, const char* name, const char* data, s3 if(cart) { SDL_memset(cart, 0, sizeof(tic_cartridge)); - SDL_memcpy(&cart->palette, &tic->config.palette.data, sizeof(tic_palette)); + SDL_memcpy(&cart->bank.palette, &tic->config.palette.data, sizeof(tic_palette)); const char* comment = projectComment(name); - if(loadTextSection(project, comment, cart->code.data, sizeof(tic_code))) + if(loadTextSection(project, comment, cart->bank.code.data, sizeof(tic_code))) done = true; for(s32 i = 0; i < COUNT_OF(BinarySections); i++) @@ -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.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(console->tic->cart.bank.palette.colors, &rgb); setSpritePixel(console->tic->cart.bank.tiles.data, x, y, color); } @@ -2713,7 +2713,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, embed.file.code.data, name); + bool loaded = loadFileIntoBuffer(console, embed.file.bank.code.data, name); if(loaded) { @@ -2762,7 +2762,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(embed.file.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(embed.file.bank.palette.colors, &rgb); setSpritePixel(embed.file.bank.tiles.data, x, y, color); } @@ -2878,7 +2878,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, if(argc > 1) { - memcpy(embed.file.palette.data, tic->config.palette.data, sizeof(tic_palette)); + memcpy(embed.file.bank.palette.data, tic->config.palette.data, sizeof(tic_palette)); u32 argp = 1; diff --git a/src/dialog.c b/src/dialog.c index a61c16b..e28b224 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.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 935ce3a..0e38308 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.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.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 620b128..9cd78e1 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.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1); } static void drawTracker(Music* music, s32 x, s32 y) diff --git a/src/run.c b/src/run.c index 1c05f72..93c1897 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.code.data; + const char* data = strlen(run->tic->saveid) ? run->tic->saveid : run->tic->cart.bank.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.code.data, DoFileTag, Size) == 0) + if (memcmp(tic->cart.bank.code.data, DoFileTag, Size) == 0) { - const char* start = tic->cart.code.data + Size; + const char* start = tic->cart.bank.code.data + Size; const char* end = strchr(start, ')'); if(end && *start == *(end-1) && (*start == '"' || *start == '\'')) diff --git a/src/sprite.c b/src/sprite.c index 6868ea6..ac693c4 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(sprite->tic->cart.palette.data, sizeof(tic_palette), false, true); - fromClipboard(&sprite->tic->cart.palette.colors[sprite->color], sizeof(tic_rgb), false, true); + fromClipboard(sprite->tic->cart.bank.palette.data, sizeof(tic_palette), false, true); + fromClipboard(&sprite->tic->cart.bank.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(sprite->tic->cart.palette.data, sizeof(tic_palette), false); + toClipboard(sprite->tic->cart.bank.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 = &sprite->tic->cart.palette.data[sprite->color * Count]; + u8* data = &sprite->tic->cart.bank.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 = &sprite->tic->cart.palette.data[sprite->color * Count]; + u8* data = &sprite->tic->cart.bank.palette.data[sprite->color * Count]; for(s32 i = 0; i < Count; i++) { diff --git a/src/studio.c b/src/studio.c index 9792375..6cdaa59 100644 --- a/src/studio.c +++ b/src/studio.c @@ -290,7 +290,7 @@ static struct void playSystemSfx(s32 id) { - const tic_sound_effect* effect = &studio.tic->config.bank.sfx.data[id]; + const tic_sound_effect* effect = &studio.tic->config.sfx.data[id]; studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0); } @@ -568,7 +568,7 @@ static void drawBankIcon(s32 x, s32 y) if(studio.bank.show) { - drawBitIcon(x, y, Icon, over ? tic_color_peach : tic_color_red); + drawBitIcon(x, y, Icon, tic_color_red); enum{Size = TOOLBAR_SIZE}; @@ -2153,7 +2153,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.tiles.data[getConfig()->theme.cursor.sprite].data); } static void useSystemPalette() @@ -2208,8 +2208,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.sfx; + music = &studio.tic->config.music; break; default: sfx = &studio.tic->cart.bank.sfx; @@ -2387,7 +2387,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.map, &studio.tic->config.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); if(!studio.gamepad.texture) { @@ -2414,7 +2414,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.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1)) studio.tic->font.data[i*BITS_IN_BYTE+y] |= 1 << x; } @@ -2439,7 +2439,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.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..1320ea5 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.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.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.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.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) @@ -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, data, size, true); + tic->api.load(cart, sizeof(tic_cartridge), 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 7cc5028..8245d9d 100644 --- a/src/tic.c +++ b/src/tic.c @@ -144,7 +144,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.palette.data, sizeof(tic_palette)); + memcpy(memory->ram.vram.palette.data, memory->cart.bank.palette.data, sizeof(tic_palette)); memcpy(memory->ram.vram.mapping, DefaultMapping, sizeof DefaultMapping); } @@ -1255,7 +1255,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.palette), sizeof machine->state.ovr.palette); + memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.bank.palette), sizeof machine->state.ovr.palette); } @@ -1312,7 +1312,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.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(tic->cart.bank.palette.colors, &rgb); tic_tool_poke4(tic->ram.vram.screen.data, i, color); } } @@ -1433,15 +1433,15 @@ static bool isJavascript(const char* code) static tic_script_lang api_get_script(tic_mem* memory) { - if(isMoonscript(memory->cart.code.data)) return tic_script_moon; - if(isJavascript(memory->cart.code.data)) return tic_script_js; + if(isMoonscript(memory->cart.bank.code.data)) return tic_script_moon; + if(isJavascript(memory->cart.bank.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.code.data, "saveid", TagFormatLua); + const char* saveid = readMetatag(memory->cart.bank.code.data, "saveid", TagFormatLua); if(saveid) { strcpy(memory->saveid, saveid); @@ -1449,7 +1449,7 @@ static void updateSaveid(tic_mem* memory) } else { - const char* saveid = readMetatag(memory->cart.code.data, "saveid", TagFormatJS); + const char* saveid = readMetatag(memory->cart.bank.code.data, "saveid", TagFormatJS); if(saveid) { strcpy(memory->saveid, saveid); @@ -1471,7 +1471,7 @@ static void api_tick(tic_mem* memory, tic_tick_data* data) if(code) { - memcpy(code, machine->memory.cart.code.data, sizeof(tic_code)); + memcpy(code, machine->memory.cart.bank.code.data, sizeof(tic_code)); if(data->preprocessor) data->preprocessor(data->data, code); @@ -1573,15 +1573,15 @@ 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, const u8* buffer, s32 size, bool palette) +static void api_load(tic_cartridge* cart, s32 cartSize, const u8* buffer, s32 size, bool palette) { const u8* end = buffer + size; - memset(cart, 0, sizeof(tic_cartridge)); + memset(cart, 0, cartSize); 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->palette.data, DB16, sizeof(tic_palette)); + memcpy(cart->bank.palette.data, DB16, sizeof(tic_palette)); } #define LOAD_CHUNK(to) memcpy(&to, buffer, min(sizeof(to), chunk.size)) @@ -1597,14 +1597,14 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet 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->code); 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_PALETTE: if(palette) - LOAD_CHUNK(cart->palette); + LOAD_CHUNK(cart->bank.palette); break; case CHUNK_COVER: LOAD_CHUNK(cart->cover.data); @@ -1666,12 +1666,12 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) 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->code); + 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_PALETTE, cart->palette); + buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->bank.palette); buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size); diff --git a/src/tic.h b/src/tic.h index b0f0462..777cd7f 100644 --- a/src/tic.h +++ b/src/tic.h @@ -333,6 +333,8 @@ typedef struct tic_map map; tic_sfx sfx; tic_music music; + tic_code code; + tic_palette palette; } tic_bank; typedef struct @@ -343,9 +345,7 @@ typedef struct tic_bank banks[TIC_BANKS]; }; - tic_code code; tic_cover_image cover; - tic_palette palette; } tic_cartridge; typedef struct diff --git a/src/tic80.c b/src/tic80.c index 8b1e7df..7812a5a 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, cart, size, true); + tic80->memory->api.load(&tic80->memory->cart, sizeof(tic_cartridge), cart, size, true); tic80->memory->api.reset(tic80->memory); } } diff --git a/src/ticapi.h b/src/ticapi.h index ea61302..75d9e3a 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -106,7 +106,7 @@ typedef struct void (*sync) (tic_mem* memory, bool toCart); u32 (*btnp) (tic_mem* memory, s32 id, s32 hold, s32 period); - void (*load) (tic_cartridge* rom, const u8* buffer, s32 size, bool palette); + void (*load) (tic_cartridge* rom, s32 cartSize, 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_cartridge config; + tic_bank config; tic_input_method input; tic_script_lang script; tic_font font;