Merge branch '#341'

This commit is contained in:
BADIM-PC\Vadim 2017-12-13 20:25:51 +03:00
commit 4de2805813
15 changed files with 280 additions and 248 deletions

View File

@ -1838,10 +1838,10 @@ void initCode(Code* code, tic_mem* tic)
*code = (Code) *code = (Code)
{ {
.tic = tic, .tic = tic,
.data = tic->cart.code.data, .data = tic->cart.bank.code.data,
.tick = tick, .tick = tick,
.escape = escape, .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}, .rect = {0, TOOLBAR_SIZE + 1, TIC80_WIDTH, TIC80_HEIGHT - TOOLBAR_SIZE - TIC_FONT_HEIGHT - 1},
.scroll = {0, 0, {0, 0}, false}, .scroll = {0, 0, {0, 0}, false},
.tickCounter = 0, .tickCounter = 0,

View File

@ -185,7 +185,7 @@ static void readConfig(Config* config)
static void update(Config* config, const u8* buffer, size_t size) 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); readConfig(config);
studioConfigChanged(); studioConfigChanged();
@ -219,7 +219,7 @@ static void saveConfig(Config* config, bool overwrite)
if(buffer) 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); fsSaveRootFile(config->fs, CONFIG_TIC_PATH, buffer, size, overwrite);

View File

@ -48,17 +48,17 @@
static const char* ExeExt = ".exe"; static const char* ExeExt = ".exe";
#endif #endif
static struct // static struct
{ // {
char prefix[32]; // char prefix[32];
bool yes; // bool yes;
bool menu; // bool menu;
tic_cartridge file; // tic_cartridge file;
} embed = // } embed =
{ // {
.prefix = "C8B39163816B47209E721136D37B8031", // .prefix = "C8B39163816B47209E721136D37B8031",
.yes = false, // .yes = false,
}; // };
static const char DefaultLuaTicPath[] = TIC_LOCAL "default.tic"; static const char DefaultLuaTicPath[] = TIC_LOCAL "default.tic";
static const char DefaultMoonTicPath[] = TIC_LOCAL "default_moon.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) 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++) 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;
@ -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) 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) 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) 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[] = static const char* Sections[] =
{ {
"cover",
"sprites", "sprites",
"map", "map",
"cover",
"code", "code",
"sfx", "sfx",
"music", "music",
@ -359,13 +359,13 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param)
switch(i) switch(i)
{ {
case 0: memcpy(&tic->cart.bank.tiles, &cart->bank.tiles, sizeof(tic_tiles)*2); break; case 0: memcpy(&tic->cart.cover, &cart->cover, sizeof cart->cover); break;
case 1: memcpy(&tic->cart.bank.map, &cart->bank.map, sizeof(tic_map)); break; case 1: memcpy(&tic->cart.bank.tiles, &cart->bank.tiles, sizeof(tic_tiles)*2); break;
case 2: memcpy(&tic->cart.cover, &cart->cover, sizeof cart->cover); break; case 2: memcpy(&tic->cart.bank.map, &cart->bank.map, sizeof(tic_map)); break;
case 3: memcpy(&tic->cart.code, &cart->code, sizeof cart->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.palette, &cart->palette, sizeof(tic_palette)); break; case 6: memcpy(&tic->cart.bank.palette, &cart->bank.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, 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}, {"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},
@ -617,7 +617,7 @@ static s32 saveProject(Console* console, void* buffer, const char* comment)
tic_mem* tic = console->tic; tic_mem* tic = console->tic;
char* stream = buffer; 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++) 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) if(cart)
{ {
SDL_memset(cart, 0, sizeof(tic_cartridge)); 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); 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; done = true;
for(s32 i = 0; i < COUNT_OF(BinarySections); i++) 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]; 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.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); 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 #ifdef CAN_EXPORT
static void* embedCart(Console* console, s32* size) // static void* embedCart(Console* console, s32* size)
{ // {
tic_mem* tic = console->tic; // tic_mem* tic = console->tic;
void* data = fsReadFile(console->appPath, size); // void* data = fsReadFile(console->appPath, size);
if(data) // if(data)
{ // {
void* start = memmem(data, *size, embed.prefix, sizeof(embed.prefix)); // void* start = memmem(data, *size, embed.prefix, sizeof(embed.prefix));
if(start) // if(start)
{ // {
embed.yes = true; // embed.yes = true;
SDL_memcpy(&embed.file, &tic->cart, sizeof(tic_cartridge)); // SDL_memcpy(&embed.file, &tic->cart, sizeof(tic_cartridge));
SDL_memcpy(start, &embed, sizeof(embed)); // SDL_memcpy(start, &embed, sizeof(embed));
embed.yes = false; // embed.yes = false;
} // }
return data; // return data;
} // }
return NULL; // return NULL;
} // }
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
static const char* getFileFolder(const char* path) // static const char* getFileFolder(const char* path)
{ // {
static char folder[FILENAME_MAX]; // static char folder[FILENAME_MAX];
const char* pos = strrchr(path, '\\'); // const char* pos = strrchr(path, '\\');
if(!pos) // if(!pos)
pos = strrchr(path, '/'); // pos = strrchr(path, '/');
if(pos) // if(pos)
{ // {
s32 size = pos - path; // s32 size = pos - path;
memcpy(folder, path, size); // memcpy(folder, path, size);
folder[size] = 0; // folder[size] = 0;
return folder; // return folder;
} // }
return NULL; // return NULL;
} // }
static bool exportToFolder(Console* console, const char* folder, const char* file) // static bool exportToFolder(Console* console, const char* folder, const char* file)
{ // {
const char* workFolder = getFileFolder(console->appPath); // const char* workFolder = getFileFolder(console->appPath);
if(workFolder) // if(workFolder)
{ // {
char src[FILENAME_MAX]; // char src[FILENAME_MAX];
strcpy(src, workFolder); // strcpy(src, workFolder);
strcat(src, file); // strcat(src, file);
char dst[FILENAME_MAX]; // char dst[FILENAME_MAX];
strcpy(dst, folder); // strcpy(dst, folder);
strcat(dst, file); // strcat(dst, file);
return fsCopyFile(src, dst); // return fsCopyFile(src, dst);
} // }
return NULL; // return NULL;
} // }
static void onConsoleExportNativeCommand(Console* console, const char* cartName) // static void onConsoleExportNativeCommand(Console* console, const char* cartName)
{ // {
const char* folder = folder_dialog(console); // const char* folder = folder_dialog(console);
bool done = false; // bool done = false;
if(folder) // if(folder)
{ // {
s32 size = 0; // s32 size = 0;
void* data = embedCart(console, &size); // void* data = embedCart(console, &size);
if(data) // if(data)
{ // {
char path[FILENAME_MAX]; // char path[FILENAME_MAX];
strcpy(path, folder); // strcpy(path, folder);
strcat(path, "\\game.exe"); // strcat(path, "\\game.exe");
done = fsWriteFile(path, data, size); // done = fsWriteFile(path, data, size);
SDL_free(data); // SDL_free(data);
} // }
else // else
{ // {
printBack(console, "\ngame exporting error :("); // printBack(console, "\ngame exporting error :(");
} // }
} // }
if(done && exportToFolder(console, folder, "\\tic80.dll") && // if(done && exportToFolder(console, folder, "\\tic80.dll") &&
exportToFolder(console, folder, "\\SDL2.dll")) // exportToFolder(console, folder, "\\SDL2.dll"))
printBack(console, "\ngame exported :)"); // printBack(console, "\ngame exported :)");
else printBack(console, "\ngame not exported :|"); // else printBack(console, "\ngame not exported :|");
commandDone(console); // commandDone(console);
} // }
#else #else
@ -1829,12 +1829,13 @@ static void onConsoleExportCommand(Console* console, const char* param)
{ {
if(strcmp(param, "native") == 0) if(strcmp(param, "native") == 0)
{ {
#ifdef CAN_EXPORT // #ifdef CAN_EXPORT
onConsoleExportNativeCommand(console, getExportName(console, false)); // onConsoleExportNativeCommand(console, getExportName(console, false));
#else // #else
printBack(console, "\nnative export isn't supported on this platform\n"); printBack(console, "\nnative export isn't supported on this platform\n");
commandDone(console); commandDone(console);
#endif // #endif
} }
else if(strcmp(param, "sprites") == 0) else if(strcmp(param, "sprites") == 0)
{ {
@ -2576,7 +2577,7 @@ static void tick(Console* console)
if(console->tickCounter == 0) if(console->tickCounter == 0)
{ {
if(!embed.yes) if(!console->embed.yes)
{ {
loadDemo(console, tic_script_lua); loadDemo(console, tic_script_lua);
@ -2595,16 +2596,16 @@ static void tick(Console* console)
console->tic->api.clear(console->tic, TIC_COLOR_BG); console->tic->api.clear(console->tic, TIC_COLOR_BG);
drawConsoleText(console); drawConsoleText(console);
if(embed.yes) if(console->embed.yes)
{ {
if(console->tickCounter >= (u32)(console->skipStart ? 1 : TIC_FRAMERATE)) if(console->tickCounter >= (u32)(console->skipStart ? 1 : TIC_FRAMERATE))
{ {
if(!console->skipStart) if(!console->skipStart)
console->showGameMenu = true; 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); setStudioMode(TIC_RUN_MODE);
embed.yes = false; console->embed.yes = false;
console->skipStart = false; console->skipStart = false;
studioRomLoaded(); studioRomLoaded();
@ -2648,9 +2649,9 @@ static bool cmdLoadCart(Console* console, const char* name)
#if defined(TIC80_PRO) #if defined(TIC80_PRO)
if(hasProjectExt(name)) if(hasProjectExt(name))
{ {
loadProject(console, name, data, size, &embed.file); loadProject(console, name, data, size, console->embed.file);
setCartName(console, fsFilename(name)); setCartName(console, fsFilename(name));
embed.yes = true; console->embed.yes = true;
console->skipStart = true; console->skipStart = true;
done = true; done = true;
} }
@ -2659,9 +2660,9 @@ static bool cmdLoadCart(Console* console, const char* name)
if(hasExt(name, CART_EXT)) 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)); setCartName(console, fsFilename(name));
embed.yes = true; console->embed.yes = true;
done = 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; bool watch = strcmp(param, "-code-watch") == 0;
if(watch || strcmp(param, "-code") == 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) if(loaded)
{ {
embed.yes = true; console->embed.yes = true;
console->skipStart = true; console->skipStart = true;
done = 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]; 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(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); gif_close(image);
@ -2772,7 +2773,7 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na
SDL_free(sprites); SDL_free(sprites);
embed.yes = true; console->embed.yes = true;
console->skipStart = true; console->skipStart = true;
done = true; done = true;
} }
@ -2797,7 +2798,7 @@ static bool cmdInjectMap(Console* console, const char* param, const char* name)
{ {
injectMap(console, map, size); injectMap(console, map, size);
embed.yes = true; console->embed.yes = true;
console->skipStart = true; console->skipStart = true;
done = 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->buffer) console->buffer = SDL_malloc(CONSOLE_BUFFER_SIZE);
if(!console->colorBuffer) console->colorBuffer = 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) *console = (Console)
{ {
@ -2843,6 +2845,12 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
.active = false, .active = false,
.reload = tryReloadCode, .reload = tryReloadCode,
}, },
.embed =
{
.yes = false,
.menu = false,
.file = NULL,
},
.inputPosition = 0, .inputPosition = 0,
.history = NULL, .history = NULL,
.historyHead = NULL, .historyHead = NULL,
@ -2878,7 +2886,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
if(argc > 1) 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; u32 argp = 1;
@ -2947,7 +2955,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
#if defined(__EMSCRIPTEN__) #if defined(__EMSCRIPTEN__)
if(!embed.yes) if(!console->embed.yes)
{ {
void* cartPtr = (void*)EM_ASM_INT_V void* cartPtr = (void*)EM_ASM_INT_V
( (
@ -2964,13 +2972,13 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
if(cartPtr) if(cartPtr)
{ {
embed.yes = true; console->embed.yes = true;
s32 cartSize = EM_ASM_INT_V(return cartridge.length;); s32 cartSize = EM_ASM_INT_V(return cartridge.length;);
u8* data = NULL; u8* data = NULL;
s32 size = unzip(&data, cartPtr, cartSize); s32 size = unzip(&data, cartPtr, cartSize);
loadCart(tic, &embed.file, data, size, true); loadCart(tic, console->embed.file, data, size, true);
SDL_free(data); SDL_free(data);
@ -2980,5 +2988,5 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
#endif #endif
console->active = !embed.yes; console->active = !console->embed.yes;
} }

View File

@ -69,6 +69,13 @@ struct Console
void(*reload)(Console*, char*); void(*reload)(Console*, char*);
} codeLiveReload; } codeLiveReload;
struct
{
bool yes;
bool menu;
tic_cartridge* file;
} embed;
char* buffer; char* buffer;
u8* colorBuffer; u8* colorBuffer;

View File

@ -170,7 +170,7 @@ static void drawDialog(Dialog* dlg)
{ {
u8 chromakey = 14; 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);
} }
{ {

View File

@ -124,7 +124,7 @@ static void drawDialog(Menu* menu)
{ {
u8 chromakey = 14; 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) if(menu->gamepad.selected == index && menu->ticks % TIC_FRAMERATE < TIC_FRAMERATE / 2)
continue; 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]; s32 code = codes[index];
char label[32]; char label[32];

View File

@ -1327,7 +1327,7 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index)
} }
u8 color = Chroma; 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) static void drawTracker(Music* music, s32 x, s32 y)

View File

@ -80,7 +80,7 @@ static const char* getPMemName(Run* run)
{ {
static char buffer[FILENAME_MAX]; 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)); char* md5 = data2md5(data, (s32)strlen(data));
strcpy(buffer, TIC_LOCAL); strcpy(buffer, TIC_LOCAL);
strcat(buffer, md5); strcat(buffer, md5);
@ -124,9 +124,9 @@ static void processDoFile(void* data, char* dst)
static const char DoFileTag[] = "dofile("; static const char DoFileTag[] = "dofile(";
enum {Size = sizeof DoFileTag - 1}; 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, ')'); const char* end = strchr(start, ')');
if(end && *start == *(end-1) && (*start == '"' || *start == '\'')) if(end && *start == *(end-1) && (*start == '"' || *start == '\''))

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(sprite->tic->cart.palette.data, sizeof(tic_palette), false, true); fromClipboard(sprite->tic->cart.bank.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.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(sprite->tic->cart.palette.data, sizeof(tic_palette), false); toClipboard(sprite->tic->cart.bank.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 = &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++) 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 = &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++) for(s32 i = 0; i < Count; i++)
{ {

View File

@ -175,20 +175,20 @@ static struct
struct struct
{ {
Start start; Start* start;
Console console; Console* console;
Run run; Run* run;
Code code; Code* code;
Sprite sprite; Sprite* sprite;
Map map; Map* map;
World world; World* world;
Sfx sfx; Sfx* sfx;
Music music; Music* music;
Config config; Config* config;
Keymap keymap; Keymap* keymap;
Dialog dialog; Dialog* dialog;
Menu menu; Menu* menu;
Surf surf; Surf* surf;
}; };
FileSystem* fs; FileSystem* fs;
@ -290,7 +290,7 @@ static struct
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.sfx.data[id];
studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0); 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() const StudioConfig* getConfig()
{ {
return &studio.config.data; return &studio.config->data;
} }
#if defined (TIC80_PRO) #if defined (TIC80_PRO)
@ -568,7 +568,7 @@ static void drawBankIcon(s32 x, s32 y)
if(studio.bank.show) 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}; enum{Size = TOOLBAR_SIZE};
@ -734,11 +734,11 @@ void setStudioEvent(StudioEvent event)
{ {
switch(studio.mode) switch(studio.mode)
{ {
case TIC_CODE_MODE: studio.code.event(&studio.code, 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_SPRITE_MODE: studio.sprite->event(studio.sprite, event); break;
case TIC_MAP_MODE: studio.map.event(&studio.map, 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_SFX_MODE: studio.sfx->event(studio.sfx, event); break;
case TIC_MUSIC_MODE: studio.music.event(&studio.music, event); break; case TIC_MUSIC_MODE: studio.music->event(studio.music, event); break;
default: break; default: break;
} }
} }
@ -813,17 +813,17 @@ void drawBitIcon(s32 x, s32 y, const u8* ptr, u8 color)
static void initWorldMap() static void initWorldMap()
{ {
initWorld(&studio.world, studio.tic, &studio.map); initWorld(studio.world, studio.tic, studio.map);
} }
static void initRunMode() static void initRunMode()
{ {
initRun(&studio.run, &studio.console, studio.tic); initRun(studio.run, studio.console, studio.tic);
} }
static void initSurfMode() static void initSurfMode()
{ {
initSurf(&studio.surf, studio.tic, &studio.console); initSurf(studio.surf, studio.tic, studio.console);
} }
void gotoSurf() void gotoSurf()
@ -839,7 +839,7 @@ void gotoCode()
static void initMenuMode() static void initMenuMode()
{ {
initMenu(&studio.menu, studio.tic, studio.fs); initMenu(studio.menu, studio.tic, studio.fs);
} }
static void enableScreenTextInput() static void enableScreenTextInput()
@ -875,7 +875,7 @@ void exitFromGameMenu()
setStudioMode(TIC_CONSOLE_MODE); setStudioMode(TIC_CONSOLE_MODE);
} }
studio.console.showGameMenu = false; studio.console->showGameMenu = false;
} }
void setStudioMode(EditorMode mode) void setStudioMode(EditorMode mode)
@ -910,7 +910,7 @@ void setStudioMode(EditorMode mode)
{ {
case TIC_WORLD_MODE: initWorldMap(); break; case TIC_WORLD_MODE: initWorldMap(); break;
case TIC_RUN_MODE: initRunMode(); 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; default: break;
} }
@ -1015,7 +1015,7 @@ void showDialog(const char** text, s32 rows, DialogCallback callback, void* data
{ {
if(studio.mode != TIC_DIALOG_MODE) 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; studio.dialogMode = studio.mode;
setStudioMode(TIC_DIALOG_MODE); setStudioMode(TIC_DIALOG_MODE);
} }
@ -1023,12 +1023,12 @@ void showDialog(const char** text, s32 rows, DialogCallback callback, void* data
static void initModules() static void initModules()
{ {
initCode(&studio.code, studio.tic); initCode(studio.code, studio.tic);
initSprite(&studio.sprite, studio.tic); initSprite(studio.sprite, studio.tic);
initMap(&studio.map, studio.tic); initMap(studio.map, studio.tic);
initWorldMap(); initWorldMap();
initSfx(&studio.sfx, studio.tic); initSfx(studio.sfx, studio.tic);
initMusic(&studio.music, studio.tic); initMusic(studio.music, studio.tic);
} }
static void updateHash() static void updateHash()
@ -1038,15 +1038,15 @@ static void updateHash()
static void updateMDate() 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() static void updateTitle()
{ {
char name[FILENAME_MAX] = TIC_TITLE; char name[FILENAME_MAX] = TIC_TITLE;
if(strlen(studio.console.romName)) if(strlen(studio.console->romName))
sprintf(name, "%s [%s]", TIC_TITLE, studio.console.romName); sprintf(name, "%s [%s]", TIC_TITLE, studio.console->romName);
SDL_SetWindowTitle(studio.window, name); SDL_SetWindowTitle(studio.window, name);
} }
@ -1280,7 +1280,7 @@ static s32 getJoystickHatMask(s32 hat)
static bool isGameMenu() 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() static void processJoysticksWithMouseInput()
@ -1495,12 +1495,12 @@ void runProject()
static void saveProject() static void saveProject()
{ {
CartSaveResult rom = studio.console.save(&studio.console); CartSaveResult rom = studio.console->save(studio.console);
if(rom == CART_SAVE_OK) if(rom == CART_SAVE_OK)
{ {
char buffer[FILENAME_MAX]; 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++) for(s32 i = 0; i < (s32)strlen(buffer); i++)
buffer[i] = SDL_toupper(buffer[i]); buffer[i] = SDL_toupper(buffer[i]);
@ -1621,7 +1621,7 @@ static bool processShortcuts(SDL_KeyboardEvent* event)
SDL_Keymod mod = event->keysym.mod; SDL_Keymod mod = event->keysym.mod;
if(studio.mode == TIC_START_MODE) return true; 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()) if(isGameMenu())
{ {
@ -1728,22 +1728,22 @@ static bool processShortcuts(SDL_KeyboardEvent* event)
case SDLK_ESCAPE: case SDLK_ESCAPE:
case SDLK_AC_BACK: 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; return true;
} }
// TODO: move this to keymap // TODO: move this to keymap
if(studio.mode == TIC_KEYMAP_MODE) if(studio.mode == TIC_KEYMAP_MODE)
{ {
studio.keymap.escape(&studio.keymap); studio.keymap->escape(studio.keymap);
return true; return true;
} }
if(studio.mode == TIC_DIALOG_MODE) if(studio.mode == TIC_DIALOG_MODE)
{ {
studio.dialog.escape(&studio.dialog); studio.dialog->escape(studio.dialog);
return true; return true;
} }
@ -1788,7 +1788,7 @@ static void processMouseInput()
static void reloadConfirm(bool yes, void* data) static void reloadConfirm(bool yes, void* data)
{ {
if(yes) if(yes)
studio.console.updateProject(&studio.console); studio.console->updateProject(studio.console);
} }
#endif #endif
@ -1839,7 +1839,7 @@ SDL_Event* pollEvent()
if(studio.mode != TIC_START_MODE) if(studio.mode != TIC_START_MODE)
{ {
Console* console = &studio.console; Console* console = studio.console;
u64 mdate = fsMDate(console->fs, console->romName); u64 mdate = fsMDate(console->fs, console->romName);
@ -1864,9 +1864,9 @@ SDL_Event* pollEvent()
#endif #endif
{ {
studio.console.codeLiveReload.reload(&studio.console, studio.code.data); studio.console->codeLiveReload.reload(studio.console, studio.code->data);
if(studio.console.codeLiveReload.active && studio.code.update) if(studio.console->codeLiveReload.active && studio.code->update)
studio.code.update(&studio.code); studio.code->update(studio.code);
} }
break; break;
} }
@ -2027,12 +2027,12 @@ static void blitTexture()
overlap = tic->api.overlap; overlap = tic->api.overlap;
break; break;
case TIC_SPRITE_MODE: case TIC_SPRITE_MODE:
overlap = studio.sprite.overlap; overlap = studio.sprite->overlap;
data = &studio.sprite; data = studio.sprite;
break; break;
case TIC_MAP_MODE: case TIC_MAP_MODE:
overlap = studio.map.overlap; overlap = studio.map->overlap;
data = &studio.map; data = studio.map;
break; break;
default: default:
break; break;
@ -2153,7 +2153,7 @@ static void renderCursor()
SDL_ShowCursor(getConfig()->theme.cursor.sprite >= 0 ? SDL_DISABLE : SDL_ENABLE); SDL_ShowCursor(getConfig()->theme.cursor.sprite >= 0 ? SDL_DISABLE : SDL_ENABLE);
if(getConfig()->theme.cursor.sprite >= 0) 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() static void useSystemPalette()
@ -2208,8 +2208,8 @@ static void renderStudio()
case TIC_DIALOG_MODE: case TIC_DIALOG_MODE:
case TIC_MENU_MODE: case TIC_MENU_MODE:
case TIC_SURF_MODE: case TIC_SURF_MODE:
sfx = &studio.tic->config.bank.sfx; sfx = &studio.tic->config.sfx;
music = &studio.tic->config.bank.music; music = &studio.tic->config.music;
break; break;
default: default:
sfx = &studio.tic->cart.bank.sfx; sfx = &studio.tic->cart.bank.sfx;
@ -2221,19 +2221,19 @@ static void renderStudio()
switch(studio.mode) switch(studio.mode)
{ {
case TIC_START_MODE: studio.start.tick(&studio.start); break; case TIC_START_MODE: studio.start->tick(studio.start); break;
case TIC_CONSOLE_MODE: studio.console.tick(&studio.console); break; case TIC_CONSOLE_MODE: studio.console->tick(studio.console); break;
case TIC_RUN_MODE: studio.run.tick(&studio.run); break; case TIC_RUN_MODE: studio.run->tick(studio.run); break;
case TIC_CODE_MODE: studio.code.tick(&studio.code); break; case TIC_CODE_MODE: studio.code->tick(studio.code); break;
case TIC_SPRITE_MODE: studio.sprite.tick(&studio.sprite); break; case TIC_SPRITE_MODE: studio.sprite->tick(studio.sprite); break;
case TIC_MAP_MODE: studio.map.tick(&studio.map); break; case TIC_MAP_MODE: studio.map->tick(studio.map); break;
case TIC_WORLD_MODE: studio.world.tick(&studio.world); break; case TIC_WORLD_MODE: studio.world->tick(studio.world); break;
case TIC_SFX_MODE: studio.sfx.tick(&studio.sfx); break; case TIC_SFX_MODE: studio.sfx->tick(studio.sfx); break;
case TIC_MUSIC_MODE: studio.music.tick(&studio.music); break; case TIC_MUSIC_MODE: studio.music->tick(studio.music); break;
case TIC_KEYMAP_MODE: studio.keymap.tick(&studio.keymap); break; case TIC_KEYMAP_MODE: studio.keymap->tick(studio.keymap); break;
case TIC_DIALOG_MODE: studio.dialog.tick(&studio.dialog); break; case TIC_DIALOG_MODE: studio.dialog->tick(studio.dialog); break;
case TIC_MENU_MODE: studio.menu.tick(&studio.menu); break; case TIC_MENU_MODE: studio.menu->tick(studio.menu); break;
case TIC_SURF_MODE: studio.surf.tick(&studio.surf); break; case TIC_SURF_MODE: studio.surf->tick(studio.surf); break;
default: break; default: break;
} }
@ -2387,7 +2387,7 @@ static void initTouchGamepad()
if (!studio.renderer) if (!studio.renderer)
return; 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) if(!studio.gamepad.texture)
{ {
@ -2414,14 +2414,14 @@ static void updateSystemFont()
for(s32 i = 0; i < TIC_FONT_CHARS; i++) for(s32 i = 0; i < TIC_FONT_CHARS; i++)
for(s32 y = 0; y < TIC_SPRITESIZE; y++) for(s32 y = 0; y < TIC_SPRITESIZE; y++)
for(s32 x = 0; x < TIC_SPRITESIZE; x++) 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; studio.tic->font.data[i*BITS_IN_BYTE+y] |= 1 << x;
} }
void studioConfigChanged() void studioConfigChanged()
{ {
if(studio.code.update) if(studio.code->update)
studio.code.update(&studio.code); studio.code->update(studio.code);
initTouchGamepad(); initTouchGamepad();
updateSystemFont(); updateSystemFont();
@ -2439,7 +2439,7 @@ static void setWindowIcon()
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++)
{ {
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]; 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.tic80local = (tic80_local*)tic80_create(studio.audioSpec.freq);
studio.tic = studio.tic80local->memory; studio.tic = studio.tic80local->memory;
fsMakeDir(fs, TIC_LOCAL); {
initConfig(&studio.config, studio.tic, studio.fs); studio.start = SDL_malloc(sizeof(Start));
initKeymap(&studio.keymap, studio.tic, studio.fs); 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); fsMakeDir(fs, TIC_LOCAL);
initConsole(&studio.console, studio.tic, studio.fs, &studio.config, studio.argc, studio.argv); 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(); initSurfMode();
initRunMode(); initRunMode();
initModules(); initModules();
if(studio.console.skipStart) if(studio.console->skipStart)
{ {
SDL_StartTextInput(); SDL_StartTextInput();
setStudioMode(TIC_CONSOLE_MODE); setStudioMode(TIC_CONSOLE_MODE);
} }
if(studio.console.goFullscreen) if(studio.console->goFullscreen)
{ {
goFullscreen(); goFullscreen();
} }

View File

@ -202,14 +202,14 @@ static void drawTopToolbar(Surf* surf, s32 x, s32 y)
enum{Gap = 10, TipX = 150, SelectWidth = 54}; enum{Gap = 10, TipX = 150, SelectWidth = 54};
u8 colorkey = 0; 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"; 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+3, tic_color_black);
tic->api.text(tic, Label, TipX + Gap, y+2, tic_color_white); 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"; static const char Label[] = "BACK";
tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); 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; 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"; static const char Label[] = "WEBSITE";
tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); 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 j = 0; j < Height + 1; j++)
for(s32 i = 0; i < Width + 1; i++) for(s32 i = 0; i < Width + 1; i++)
if(counter++ % 2) 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) 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)) if(hasExt(item->name, PROJECT_LUA_EXT))
surf->console->loadProject(surf->console, item->name, data, size, cart); surf->console->loadProject(surf->console, item->name, data, size, cart);
else else
tic->api.load(cart, data, size, true); tic->api.load(cart, sizeof(tic_cartridge), data, size, true);
if(cart->cover.size) if(cart->cover.size)
updateMenuItemCover(surf, cart->cover.data, cart->cover.size); updateMenuItemCover(surf, cart->cover.data, cart->cover.size);

View File

@ -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 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.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); 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.setpix = setPixelOvr;
machine->state.getpix = getPixelOvr; 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]]; 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.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); 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) static tic_script_lang api_get_script(tic_mem* memory)
{ {
if(isMoonscript(memory->cart.code.data)) return tic_script_moon; if(isMoonscript(memory->cart.bank.code.data)) return tic_script_moon;
if(isJavascript(memory->cart.code.data)) return tic_script_js; if(isJavascript(memory->cart.bank.code.data)) return tic_script_js;
return tic_script_lua; return tic_script_lua;
} }
static void updateSaveid(tic_mem* memory) static void updateSaveid(tic_mem* memory)
{ {
memset(memory->saveid, 0, sizeof memory->saveid); 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) if(saveid)
{ {
strcpy(memory->saveid, saveid); strcpy(memory->saveid, saveid);
@ -1449,7 +1449,7 @@ static void updateSaveid(tic_mem* memory)
} }
else else
{ {
const char* saveid = readMetatag(memory->cart.code.data, "saveid", TagFormatJS); const char* saveid = readMetatag(memory->cart.bank.code.data, "saveid", TagFormatJS);
if(saveid) if(saveid)
{ {
strcpy(memory->saveid, saveid); strcpy(memory->saveid, saveid);
@ -1471,7 +1471,7 @@ static void api_tick(tic_mem* memory, tic_tick_data* data)
if(code) 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) if(data->preprocessor)
data->preprocessor(data->data, code); 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); 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; const u8* end = buffer + size;
memset(cart, 0, sizeof(tic_cartridge)); memset(cart, 0, cartSize);
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->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)) #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_TILES: LOAD_CHUNK(cart->bank.tiles); break;
case CHUNK_SPRITES: LOAD_CHUNK(cart->bank.sprites); break; case CHUNK_SPRITES: LOAD_CHUNK(cart->bank.sprites); break;
case CHUNK_MAP: LOAD_CHUNK(cart->bank.map); 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_SOUND: LOAD_CHUNK(cart->bank.sfx.data); break;
case CHUNK_WAVEFORM: LOAD_CHUNK(cart->bank.sfx.waveform); break; case CHUNK_WAVEFORM: LOAD_CHUNK(cart->bank.sfx.waveform); break;
case CHUNK_MUSIC: LOAD_CHUNK(cart->bank.music.tracks.data); 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_PATTERNS: LOAD_CHUNK(cart->bank.music.patterns.data); break;
case CHUNK_PALETTE: case CHUNK_PALETTE:
if(palette) if(palette)
LOAD_CHUNK(cart->palette); LOAD_CHUNK(cart->bank.palette);
break; break;
case CHUNK_COVER: case CHUNK_COVER:
LOAD_CHUNK(cart->cover.data); 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_TILES, cart->bank.tiles);
buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->bank.sprites); buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->bank.sprites);
buffer = SAVE_CHUNK(CHUNK_MAP, cart->bank.map); 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_SOUND, cart->bank.sfx.data);
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->palette); buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->bank.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

@ -333,6 +333,8 @@ typedef struct
tic_map map; tic_map map;
tic_sfx sfx; tic_sfx sfx;
tic_music music; tic_music music;
tic_code code;
tic_palette palette;
} tic_bank; } tic_bank;
typedef struct typedef struct
@ -343,9 +345,7 @@ typedef struct
tic_bank banks[TIC_BANKS]; tic_bank banks[TIC_BANKS];
}; };
tic_code code;
tic_cover_image cover; tic_cover_image cover;
tic_palette palette;
} tic_cartridge; } tic_cartridge;
typedef struct typedef struct

View File

@ -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); tic80->memory->api.reset(tic80->memory);
} }
} }

View File

@ -106,7 +106,7 @@ typedef struct
void (*sync) (tic_mem* memory, bool toCart); void (*sync) (tic_mem* memory, bool toCart);
u32 (*btnp) (tic_mem* memory, s32 id, s32 hold, s32 period); 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); s32 (*save) (const tic_cartridge* rom, u8* buffer);
void (*tick_start) (tic_mem* memory, const tic_sfx* sfx, const tic_music* music); 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_ram ram;
tic_cartridge cart; tic_cartridge cart;
tic_cartridge config; tic_bank config;
tic_input_method input; tic_input_method input;
tic_script_lang script; tic_script_lang script;
tic_font font; tic_font font;