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..7e0e940 100644 --- a/src/console.c +++ b/src/console.c @@ -48,17 +48,17 @@ static const char* ExeExt = ".exe"; #endif -static struct -{ - char prefix[32]; - bool yes; - bool menu; - tic_cartridge file; -} embed = -{ - .prefix = "C8B39163816B47209E721136D37B8031", - .yes = false, -}; +// static struct +// { +// char prefix[32]; +// bool yes; +// bool menu; +// tic_cartridge file; +// } embed = +// { +// .prefix = "C8B39163816B47209E721136D37B8031", +// .yes = false, +// }; static const char DefaultLuaTicPath[] = TIC_LOCAL "default.tic"; static const char DefaultMoonTicPath[] = TIC_LOCAL "default_moon.tic"; @@ -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); } @@ -1669,107 +1669,107 @@ static void onConsoleExportHtmlCommand(Console* console, const char* name) #ifdef CAN_EXPORT -static void* embedCart(Console* console, s32* size) -{ - tic_mem* tic = console->tic; +// static void* embedCart(Console* console, s32* size) +// { +// tic_mem* tic = console->tic; - void* data = fsReadFile(console->appPath, size); +// void* data = fsReadFile(console->appPath, size); - if(data) - { - void* start = memmem(data, *size, embed.prefix, sizeof(embed.prefix)); +// if(data) +// { +// void* start = memmem(data, *size, embed.prefix, sizeof(embed.prefix)); - if(start) - { - embed.yes = true; - SDL_memcpy(&embed.file, &tic->cart, sizeof(tic_cartridge)); - SDL_memcpy(start, &embed, sizeof(embed)); - embed.yes = false; - } +// if(start) +// { +// embed.yes = true; +// SDL_memcpy(&embed.file, &tic->cart, sizeof(tic_cartridge)); +// SDL_memcpy(start, &embed, sizeof(embed)); +// embed.yes = false; +// } - return data; - } +// return data; +// } - return NULL; -} +// return NULL; +// } #if defined(__WINDOWS__) -static const char* getFileFolder(const char* path) -{ - static char folder[FILENAME_MAX]; +// static const char* getFileFolder(const char* path) +// { +// static char folder[FILENAME_MAX]; - const char* pos = strrchr(path, '\\'); +// const char* pos = strrchr(path, '\\'); - if(!pos) - pos = strrchr(path, '/'); +// if(!pos) +// pos = strrchr(path, '/'); - if(pos) - { - s32 size = pos - path; - memcpy(folder, path, size); - folder[size] = 0; +// if(pos) +// { +// s32 size = pos - path; +// memcpy(folder, path, size); +// folder[size] = 0; - return folder; - } +// return folder; +// } - return NULL; -} +// return NULL; +// } -static bool exportToFolder(Console* console, const char* folder, const char* file) -{ - const char* workFolder = getFileFolder(console->appPath); +// static bool exportToFolder(Console* console, const char* folder, const char* file) +// { +// const char* workFolder = getFileFolder(console->appPath); - if(workFolder) - { - char src[FILENAME_MAX]; - strcpy(src, workFolder); - strcat(src, file); +// if(workFolder) +// { +// char src[FILENAME_MAX]; +// strcpy(src, workFolder); +// strcat(src, file); - char dst[FILENAME_MAX]; - strcpy(dst, folder); - strcat(dst, file); +// char dst[FILENAME_MAX]; +// strcpy(dst, folder); +// strcat(dst, file); - return fsCopyFile(src, dst); - } +// return fsCopyFile(src, dst); +// } - return NULL; -} +// return NULL; +// } -static void onConsoleExportNativeCommand(Console* console, const char* cartName) -{ - const char* folder = folder_dialog(console); - bool done = false; +// static void onConsoleExportNativeCommand(Console* console, const char* cartName) +// { +// const char* folder = folder_dialog(console); +// bool done = false; - if(folder) - { - s32 size = 0; +// if(folder) +// { +// s32 size = 0; - void* data = embedCart(console, &size); +// void* data = embedCart(console, &size); - if(data) - { - char path[FILENAME_MAX]; - strcpy(path, folder); - strcat(path, "\\game.exe"); +// if(data) +// { +// char path[FILENAME_MAX]; +// strcpy(path, folder); +// strcat(path, "\\game.exe"); - done = fsWriteFile(path, data, size); +// done = fsWriteFile(path, data, size); - SDL_free(data); - } - else - { - printBack(console, "\ngame exporting error :("); - } - } +// SDL_free(data); +// } +// else +// { +// printBack(console, "\ngame exporting error :("); +// } +// } - if(done && exportToFolder(console, folder, "\\tic80.dll") && - exportToFolder(console, folder, "\\SDL2.dll")) - printBack(console, "\ngame exported :)"); - else printBack(console, "\ngame not exported :|"); +// if(done && exportToFolder(console, folder, "\\tic80.dll") && +// exportToFolder(console, folder, "\\SDL2.dll")) +// printBack(console, "\ngame exported :)"); +// else printBack(console, "\ngame not exported :|"); - commandDone(console); -} +// commandDone(console); +// } #else @@ -1829,12 +1829,13 @@ static void onConsoleExportCommand(Console* console, const char* param) { if(strcmp(param, "native") == 0) { -#ifdef CAN_EXPORT - onConsoleExportNativeCommand(console, getExportName(console, false)); -#else +// #ifdef CAN_EXPORT +// onConsoleExportNativeCommand(console, getExportName(console, false)); +// #else + printBack(console, "\nnative export isn't supported on this platform\n"); commandDone(console); -#endif +// #endif } else if(strcmp(param, "sprites") == 0) { @@ -2576,7 +2577,7 @@ static void tick(Console* console) if(console->tickCounter == 0) { - if(!embed.yes) + if(!console->embed.yes) { loadDemo(console, tic_script_lua); @@ -2595,16 +2596,16 @@ static void tick(Console* console) console->tic->api.clear(console->tic, TIC_COLOR_BG); drawConsoleText(console); - if(embed.yes) + if(console->embed.yes) { if(console->tickCounter >= (u32)(console->skipStart ? 1 : TIC_FRAMERATE)) { if(!console->skipStart) console->showGameMenu = true; - memcpy(&console->tic->cart, &embed.file, sizeof(tic_cartridge)); + // memcpy(&console->tic->cart, &embed.file, sizeof(tic_cartridge)); setStudioMode(TIC_RUN_MODE); - embed.yes = false; + console->embed.yes = false; console->skipStart = false; studioRomLoaded(); @@ -2648,9 +2649,9 @@ static bool cmdLoadCart(Console* console, const char* name) #if defined(TIC80_PRO) if(hasProjectExt(name)) { - loadProject(console, name, data, size, &embed.file); + loadProject(console, name, data, size, console->embed.file); setCartName(console, fsFilename(name)); - embed.yes = true; + console->embed.yes = true; console->skipStart = true; done = true; } @@ -2659,9 +2660,9 @@ static bool cmdLoadCart(Console* console, const char* name) if(hasExt(name, CART_EXT)) { - loadCart(console->tic, &embed.file, data, size, true); + loadCart(console->tic, console->embed.file, data, size, true); setCartName(console, fsFilename(name)); - embed.yes = true; + console->embed.yes = true; done = true; } @@ -2713,11 +2714,11 @@ 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, console->embed.file->bank.code.data, name); if(loaded) { - embed.yes = true; + console->embed.yes = true; console->skipStart = true; done = true; @@ -2762,9 +2763,9 @@ 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(console->embed.file->bank.palette.colors, &rgb); - setSpritePixel(embed.file.bank.tiles.data, x, y, color); + setSpritePixel(console->embed.file->bank.tiles.data, x, y, color); } gif_close(image); @@ -2772,7 +2773,7 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na SDL_free(sprites); - embed.yes = true; + console->embed.yes = true; console->skipStart = true; done = true; } @@ -2797,7 +2798,7 @@ static bool cmdInjectMap(Console* console, const char* param, const char* name) { injectMap(console, map, size); - embed.yes = true; + console->embed.yes = true; console->skipStart = true; done = true; } @@ -2813,6 +2814,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, { if(!console->buffer) console->buffer = SDL_malloc(CONSOLE_BUFFER_SIZE); if(!console->colorBuffer) console->colorBuffer = SDL_malloc(CONSOLE_BUFFER_SIZE); + if(!console->embed.file) console->embed.file = SDL_malloc(sizeof(tic_cartridge)); *console = (Console) { @@ -2843,6 +2845,12 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, .active = false, .reload = tryReloadCode, }, + .embed = + { + .yes = false, + .menu = false, + .file = NULL, + }, .inputPosition = 0, .history = NULL, .historyHead = NULL, @@ -2878,7 +2886,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(console->embed.file->bank.palette.data, tic->config.palette.data, sizeof(tic_palette)); u32 argp = 1; @@ -2947,7 +2955,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, #if defined(__EMSCRIPTEN__) - if(!embed.yes) + if(!console->embed.yes) { void* cartPtr = (void*)EM_ASM_INT_V ( @@ -2964,13 +2972,13 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, if(cartPtr) { - embed.yes = true; + console->embed.yes = true; s32 cartSize = EM_ASM_INT_V(return cartridge.length;); u8* data = NULL; s32 size = unzip(&data, cartPtr, cartSize); - loadCart(tic, &embed.file, data, size, true); + loadCart(tic, console->embed.file, data, size, true); SDL_free(data); @@ -2980,5 +2988,5 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, #endif - console->active = !embed.yes; + console->active = !console->embed.yes; } \ No newline at end of file diff --git a/src/console.h b/src/console.h index 1eff7f1..964d367 100644 --- a/src/console.h +++ b/src/console.h @@ -69,6 +69,13 @@ struct Console void(*reload)(Console*, char*); } codeLiveReload; + struct + { + bool yes; + bool menu; + tic_cartridge* file; + } embed; + char* buffer; u8* colorBuffer; 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..ff5837b 100644 --- a/src/studio.c +++ b/src/studio.c @@ -175,20 +175,20 @@ static struct struct { - Start start; - Console console; - Run run; - Code code; - Sprite sprite; - Map map; - World world; - Sfx sfx; - Music music; - Config config; - Keymap keymap; - Dialog dialog; - Menu menu; - Surf surf; + Start* start; + Console* console; + Run* run; + Code* code; + Sprite* sprite; + Map* map; + World* world; + Sfx* sfx; + Music* music; + Config* config; + Keymap* keymap; + Dialog* dialog; + Menu* menu; + Surf* surf; }; FileSystem* fs; @@ -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); } @@ -529,7 +529,7 @@ static void drawExtrabar(tic_mem* tic) const StudioConfig* getConfig() { - return &studio.config.data; + return &studio.config->data; } #if defined (TIC80_PRO) @@ -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}; @@ -734,11 +734,11 @@ void setStudioEvent(StudioEvent event) { switch(studio.mode) { - case TIC_CODE_MODE: studio.code.event(&studio.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_CODE_MODE: studio.code->event(studio.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; default: break; } } @@ -813,17 +813,17 @@ 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.map); } static void initRunMode() { - initRun(&studio.run, &studio.console, studio.tic); + initRun(studio.run, studio.console, studio.tic); } static void initSurfMode() { - initSurf(&studio.surf, studio.tic, &studio.console); + initSurf(studio.surf, studio.tic, studio.console); } void gotoSurf() @@ -839,7 +839,7 @@ void gotoCode() static void initMenuMode() { - initMenu(&studio.menu, studio.tic, studio.fs); + initMenu(studio.menu, studio.tic, studio.fs); } static void enableScreenTextInput() @@ -875,7 +875,7 @@ void exitFromGameMenu() setStudioMode(TIC_CONSOLE_MODE); } - studio.console.showGameMenu = false; + studio.console->showGameMenu = false; } void setStudioMode(EditorMode mode) @@ -910,7 +910,7 @@ void setStudioMode(EditorMode mode) { case TIC_WORLD_MODE: initWorldMap(); break; case TIC_RUN_MODE: initRunMode(); break; - case TIC_SURF_MODE: studio.surf.resume(&studio.surf); break; + case TIC_SURF_MODE: studio.surf->resume(studio.surf); break; default: break; } @@ -1015,7 +1015,7 @@ void showDialog(const char** text, s32 rows, DialogCallback callback, void* data { if(studio.mode != TIC_DIALOG_MODE) { - initDialog(&studio.dialog, studio.tic, text, rows, callback, data); + initDialog(studio.dialog, studio.tic, text, rows, callback, data); studio.dialogMode = studio.mode; setStudioMode(TIC_DIALOG_MODE); } @@ -1023,12 +1023,12 @@ void showDialog(const char** text, s32 rows, DialogCallback callback, void* data static void initModules() { - initCode(&studio.code, studio.tic); - initSprite(&studio.sprite, studio.tic); - initMap(&studio.map, studio.tic); + initCode(studio.code, studio.tic); + initSprite(studio.sprite, studio.tic); + initMap(studio.map, studio.tic); initWorldMap(); - initSfx(&studio.sfx, studio.tic); - initMusic(&studio.music, studio.tic); + initSfx(studio.sfx, studio.tic); + initMusic(studio.music, studio.tic); } static void updateHash() @@ -1038,15 +1038,15 @@ static void updateHash() static void updateMDate() { - studio.cart.mdate = fsMDate(studio.console.fs, studio.console.romName); + studio.cart.mdate = fsMDate(studio.console->fs, studio.console->romName); } static void updateTitle() { char name[FILENAME_MAX] = TIC_TITLE; - if(strlen(studio.console.romName)) - sprintf(name, "%s [%s]", TIC_TITLE, studio.console.romName); + if(strlen(studio.console->romName)) + sprintf(name, "%s [%s]", TIC_TITLE, studio.console->romName); SDL_SetWindowTitle(studio.window, name); } @@ -1280,7 +1280,7 @@ static s32 getJoystickHatMask(s32 hat) static bool isGameMenu() { - return (studio.mode == TIC_RUN_MODE && studio.console.showGameMenu) || studio.mode == TIC_MENU_MODE; + return (studio.mode == TIC_RUN_MODE && studio.console->showGameMenu) || studio.mode == TIC_MENU_MODE; } static void processJoysticksWithMouseInput() @@ -1495,12 +1495,12 @@ void runProject() static void saveProject() { - CartSaveResult rom = studio.console.save(&studio.console); + CartSaveResult rom = studio.console->save(studio.console); if(rom == CART_SAVE_OK) { char buffer[FILENAME_MAX]; - sprintf(buffer, "%s SAVED :)", studio.console.romName); + sprintf(buffer, "%s SAVED :)", studio.console->romName); for(s32 i = 0; i < (s32)strlen(buffer); i++) buffer[i] = SDL_toupper(buffer[i]); @@ -1621,7 +1621,7 @@ static bool processShortcuts(SDL_KeyboardEvent* event) SDL_Keymod mod = event->keysym.mod; if(studio.mode == TIC_START_MODE) return true; - if(studio.mode == TIC_CONSOLE_MODE && !studio.console.active) return true; + if(studio.mode == TIC_CONSOLE_MODE && !studio.console->active) return true; if(isGameMenu()) { @@ -1728,22 +1728,22 @@ 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) + if(studio.mode == TIC_CODE_MODE && studio.code->mode != TEXT_EDIT_MODE) { - studio.code.escape(&studio.code); + studio.code->escape(studio.code); return true; } // TODO: move this to keymap if(studio.mode == TIC_KEYMAP_MODE) { - studio.keymap.escape(&studio.keymap); + studio.keymap->escape(studio.keymap); return true; } if(studio.mode == TIC_DIALOG_MODE) { - studio.dialog.escape(&studio.dialog); + studio.dialog->escape(studio.dialog); return true; } @@ -1788,7 +1788,7 @@ static void processMouseInput() static void reloadConfirm(bool yes, void* data) { if(yes) - studio.console.updateProject(&studio.console); + studio.console->updateProject(studio.console); } #endif @@ -1839,7 +1839,7 @@ SDL_Event* pollEvent() if(studio.mode != TIC_START_MODE) { - Console* console = &studio.console; + Console* console = studio.console; u64 mdate = fsMDate(console->fs, console->romName); @@ -1864,9 +1864,9 @@ 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); + studio.console->codeLiveReload.reload(studio.console, studio.code->data); + if(studio.console->codeLiveReload.active && studio.code->update) + studio.code->update(studio.code); } break; } @@ -2027,12 +2027,12 @@ static void blitTexture() overlap = tic->api.overlap; break; case TIC_SPRITE_MODE: - overlap = studio.sprite.overlap; - data = &studio.sprite; + overlap = studio.sprite->overlap; + data = studio.sprite; break; case TIC_MAP_MODE: - overlap = studio.map.overlap; - data = &studio.map; + overlap = studio.map->overlap; + data = studio.map; break; default: break; @@ -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; @@ -2221,19 +2221,19 @@ static void renderStudio() switch(studio.mode) { - 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_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; - 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; - case TIC_SURF_MODE: studio.surf.tick(&studio.surf); break; + 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_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; + 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; + case TIC_SURF_MODE: studio.surf->tick(studio.surf); break; default: break; } @@ -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,14 +2414,14 @@ 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; } void studioConfigChanged() { - if(studio.code.update) - studio.code.update(&studio.code); + if(studio.code->update) + studio.code->update(studio.code); initTouchGamepad(); updateSystemFont(); @@ -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]; } @@ -2503,25 +2503,42 @@ static void onFSInitialized(FileSystem* fs) studio.tic80local = (tic80_local*)tic80_create(studio.audioSpec.freq); studio.tic = studio.tic80local->memory; - fsMakeDir(fs, TIC_LOCAL); - initConfig(&studio.config, studio.tic, studio.fs); - initKeymap(&studio.keymap, studio.tic, studio.fs); + { + 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)); + 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)); + } - initStart(&studio.start, studio.tic); - initConsole(&studio.console, studio.tic, studio.fs, &studio.config, studio.argc, studio.argv); + fsMakeDir(fs, TIC_LOCAL); + initConfig(studio.config, studio.tic, studio.fs); + initKeymap(studio.keymap, studio.tic, studio.fs); + + initStart(studio.start, studio.tic); + initConsole(studio.console, studio.tic, studio.fs, studio.config, studio.argc, studio.argv); initSurfMode(); initRunMode(); initModules(); - if(studio.console.skipStart) + if(studio.console->skipStart) { SDL_StartTextInput(); setStudioMode(TIC_CONSOLE_MODE); } - if(studio.console.goFullscreen) + if(studio.console->goFullscreen) { goFullscreen(); } 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;