Merge branch '#341'

This commit is contained in:
BADIM-PC\Vadim 2017-12-14 17:20:22 +03:00
commit 8f903d9e33
27 changed files with 407 additions and 315 deletions

1
.gitignore vendored
View File

@ -92,3 +92,4 @@ build/windows/tic80/Release Pro/
build/windows/zlib/Debug Pro/
build/windows/zlib/Release Pro/
build/windows/example/Release Pro/
build/windows/example/Debug Pro/

View File

@ -68,7 +68,7 @@ static void drawCode(Code* code, bool withCursor)
s32 xStart = code->rect.x - code->scroll.x * STUDIO_TEXT_WIDTH;
s32 x = xStart;
s32 y = code->rect.y - code->scroll.y * STUDIO_TEXT_HEIGHT;
char* pointer = code->data;
char* pointer = code->src;
u8* colorPointer = code->colorBuffer;
@ -116,7 +116,7 @@ static void getCursorPosition(Code* code, s32* x, s32* y)
*x = 0;
*y = 0;
const char* pointer = code->data;
const char* pointer = code->src;
while(*pointer)
{
@ -135,7 +135,7 @@ static void getCursorPosition(Code* code, s32* x, s32* y)
static s32 getLinesCount(Code* code)
{
char* text = code->data;
char* text = code->src;
s32 count = 0;
while(*text)
@ -177,10 +177,10 @@ static void updateEditor(Code* code)
sprintf(status, "line %i/%i col %i", line + 1, count + 1, column + 1);
memcpy(code->status, status, strlen(status));
size_t codeLen = strlen(code->data);
size_t codeLen = strlen(code->src);
sprintf(status, "%i/%i", (u32)codeLen, TIC_CODE_SIZE);
memset(code->data + codeLen, '\0', TIC_CODE_SIZE - codeLen);
memset(code->src + codeLen, '\0', TIC_CODE_SIZE - codeLen);
memcpy(code->status + sizeof code->status - strlen(status) - 1, status, strlen(status));
}
}
@ -213,7 +213,7 @@ static void highlightStrings(Code* code, const char* text, u8* color, char separ
static void highlightNumbers(Code* code, u8* color)
{
const char* text = code->data;
const char* text = code->src;
const char* pointer = text;
while(*pointer)
@ -267,7 +267,7 @@ static void highlightWords(const char* text, u8* color, const char* const string
static void highlightMoonKeywords(Code* code, u8* color)
{
const char* text = code->data;
const char* text = code->src;
static const char* const MoonKeywords [] =
{
@ -285,7 +285,7 @@ static void highlightMoonKeywords(Code* code, u8* color)
static void highlightLuaKeywords(Code* code, u8* color)
{
const char* text = code->data;
const char* text = code->src;
static const char* const LuaKeywords [] =
{
@ -300,7 +300,7 @@ static void highlightLuaKeywords(Code* code, u8* color)
static void highlightJsKeywords(Code* code, u8* color)
{
const char* text = code->data;
const char* text = code->src;
static const char* const JsKeywords [] =
{
@ -317,13 +317,13 @@ static void highlightApi(Code* code, u8* color)
{
static const char* const ApiKeywords[] = API_KEYWORDS;
const char* text = code->data;
const char* text = code->src;
highlightWords(text, color, ApiKeywords, COUNT_OF(ApiKeywords), getConfig()->theme.code.api);
}
static void highlightNonChars(Code* code, u8* color)
{
const char* text = code->data;
const char* text = code->src;
while(*text)
{
@ -337,7 +337,7 @@ static void highlightNonChars(Code* code, u8* color)
static void highlightSigns(Code* code, u8* color)
{
const char* text = code->data;
const char* text = code->src;
static const char* const LuaSigns [] =
{
@ -364,7 +364,7 @@ static void highlightSigns(Code* code, u8* color)
static void highlightCommentsBase(Code* code, u8* color, const char* pattern1, const char* pattern2, s32 extraSize)
{
const char* text = code->data;
const char* text = code->src;
const char* pointer = text;
while(*pointer)
@ -417,7 +417,7 @@ static void parseSyntaxColor(Code* code)
highlightNumbers(code, color);
highlightSigns(code, color);
highlightCommentsBase(code, color, "--", "\n", 0);
highlightStrings(code, code->data, color, '"');
highlightStrings(code, code->src, color, '"');
break;
case tic_script_lua:
highlightNonChars(code, color);
@ -426,7 +426,7 @@ static void parseSyntaxColor(Code* code)
highlightNumbers(code, color);
highlightSigns(code, color);
highlightComments(code, color);
highlightStrings(code, code->data, color, '"');
highlightStrings(code, code->src, color, '"');
break;
case tic_script_js:
highlightNonChars(code, color);
@ -435,14 +435,14 @@ static void parseSyntaxColor(Code* code)
highlightNumbers(code, color);
highlightSigns(code, color);
highlightJsComments(code, color);
highlightStrings(code, code->data, color, '"');
highlightStrings(code, code->src, color, '"');
break;
}
}
static char* getLineByPos(Code* code, char* pos)
{
char* text = code->data;
char* text = code->src;
char* line = text;
while(text < pos)
@ -459,7 +459,7 @@ static char* getLine(Code* code)
static char* getPrevLine(Code* code)
{
char* text = code->data;
char* text = code->src;
char* pos = code->cursor.position;
char* prevLine = text;
char* line = text;
@ -510,7 +510,7 @@ static void setCursorPosition(Code* code, s32 cx, s32 cy)
{
s32 x = 0;
s32 y = 0;
char* pointer = code->data;
char* pointer = code->src;
while(*pointer)
{
@ -559,7 +559,7 @@ static void downLine(Code* code)
static void leftColumn(Code* code)
{
char* start = code->data;
char* start = code->src;
if(code->cursor.position > start)
{
@ -579,7 +579,7 @@ static void rightColumn(Code* code)
static void leftWord(Code* code)
{
const char* start = code->data;
const char* start = code->src;
char* pos = code->cursor.position-1;
if(pos > start)
@ -595,7 +595,7 @@ static void leftWord(Code* code)
static void rightWord(Code* code)
{
const char* end = code->data + strlen(code->data);
const char* end = code->src + strlen(code->src);
char* pos = code->cursor.position;
if(pos < end)
@ -625,14 +625,14 @@ static void goEnd(Code* code)
static void goCodeHome(Code *code)
{
code->cursor.position = code->data;
code->cursor.position = code->src;
updateColumn(code);
}
static void goCodeEnd(Code *code)
{
code->cursor.position = code->data + strlen(code->data);
code->cursor.position = code->src + strlen(code->src);
updateColumn(code);
}
@ -692,7 +692,7 @@ static void deleteChar(Code* code)
static void backspaceChar(Code* code)
{
if(!replaceSelection(code) && code->cursor.position > code->data)
if(!replaceSelection(code) && code->cursor.position > code->src)
{
char* pos = --code->cursor.position;
memmove(pos, pos + 1, strlen(pos));
@ -703,7 +703,7 @@ static void backspaceChar(Code* code)
static void inputSymbolBase(Code* code, char sym)
{
if (strlen(code->data) >= sizeof(tic_code))
if (strlen(code->src) >= sizeof(tic_code))
return;
char* pos = code->cursor.position;
@ -747,7 +747,7 @@ static void newLine(Code* code)
static void selectAll(Code* code)
{
code->cursor.selection = code->data;
code->cursor.selection = code->src;
code->cursor.position = code->cursor.selection + strlen(code->cursor.selection);
}
@ -807,7 +807,7 @@ static void copyFromClipboard(Code* code)
// cut clipboard code if overall code > max code size
{
size_t codeSize = strlen(code->data);
size_t codeSize = strlen(code->src);
if (codeSize + size > sizeof(tic_code))
{
@ -995,7 +995,7 @@ static void updateOutlineCode(Code* code)
}
else
{
code->cursor.position = code->data;
code->cursor.position = code->src;
code->cursor.selection = NULL;
}
@ -1008,7 +1008,7 @@ static void setMoonscriptOutlineMode(Code* code)
OutlineItem* out = code->outline.items;
OutlineItem* end = out + OUTLINE_SIZE;
char* ptr = code->data;
char* ptr = code->src;
static const char FuncString[] = "=->";
char buffer[STUDIO_TEXT_BUFFER_WIDTH];
@ -1020,18 +1020,18 @@ static void setMoonscriptOutlineMode(Code* code)
{
ptr = strstr(ptr, FuncString);
if(ptr && ptr > code->data)
if(ptr && ptr > code->src)
{
char* endPtr = ptr;
ptr += sizeof FuncString - 1;
while(endPtr >= code->data && !isLetter(*endPtr) && !isNumber(*endPtr)) endPtr--;
while(endPtr >= code->src && !isLetter(*endPtr) && !isNumber(*endPtr)) endPtr--;
char* start = endPtr;
for (const char* val = start-1; val >= code->data && (isLetter(*val) || isNumber(*val)); val--, start--);
for (const char* val = start-1; val >= code->src && (isLetter(*val) || isNumber(*val)); val--, start--);
if(start >= code->data)
if(start >= code->src)
{
memset(buffer, 0, sizeof buffer);
memcpy(buffer, start, endPtr - start + 1);
@ -1065,7 +1065,7 @@ static void setLuaOutlineMode(Code* code)
OutlineItem* out = code->outline.items;
OutlineItem* end = out + OUTLINE_SIZE;
char* ptr = code->data;
char* ptr = code->src;
static const char FuncString[] = "function ";
char buffer[STUDIO_TEXT_BUFFER_WIDTH];
@ -1156,7 +1156,7 @@ static void commentLine(Code* code)
if(memcmp(line, Comment, Size))
{
if (strlen(code->data) + Size >= sizeof(tic_code))
if (strlen(code->src) + Size >= sizeof(tic_code))
return;
memmove(line + Size, line, strlen(line)+1);
@ -1481,7 +1481,7 @@ static void textFindTick(Code* code)
bool reverse = keycode == SDLK_UP || keycode == SDLK_LEFT;
char* (*func)(const char*, const char*, const char*) = reverse ? upStrStr : downStrStr;
char* from = reverse ? SDL_min(code->cursor.position, code->cursor.selection) : SDL_max(code->cursor.position, code->cursor.selection);
char* pos = func(code->data, from, code->popup.text);
char* pos = func(code->src, from, code->popup.text);
updateFindCode(code, pos);
}
break;
@ -1489,7 +1489,7 @@ static void textFindTick(Code* code)
if(*code->popup.text)
{
code->popup.text[strlen(code->popup.text)-1] = '\0';
updateFindCode(code, strstr(code->data, code->popup.text));
updateFindCode(code, strstr(code->src, code->popup.text));
}
break;
default: break;
@ -1501,7 +1501,7 @@ static void textFindTick(Code* code)
if(strlen(code->popup.text) + 1 < sizeof code->popup.text)
{
strcat(code->popup.text, event->text.text);
updateFindCode(code, strstr(code->data, code->popup.text));
updateFindCode(code, strstr(code->src, code->popup.text));
}
}
break;
@ -1827,7 +1827,7 @@ static void onStudioEvent(Code* code, StudioEvent event)
}
}
void initCode(Code* code, tic_mem* tic)
void initCode(Code* code, tic_mem* tic, tic_code* src)
{
if(code->outline.items == NULL)
code->outline.items = (OutlineItem*)SDL_malloc(OUTLINE_ITEMS_SIZE);
@ -1838,10 +1838,10 @@ void initCode(Code* code, tic_mem* tic)
*code = (Code)
{
.tic = tic,
.data = getBankCode()->data,
.src = src->data,
.tick = tick,
.escape = escape,
.cursor = {{getBankCode()->data, NULL, 0, 0}, NULL, 0},
.cursor = {{src->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,
@ -1863,7 +1863,7 @@ void initCode(Code* code, tic_mem* tic)
.update = update,
};
code->history = history_create(code->data, sizeof(tic_code));
code->history = history_create(code->src, sizeof(tic_code));
code->cursorHistory = history_create(&code->cursor, sizeof code->cursor);
update(code);

View File

@ -31,7 +31,7 @@ struct Code
{
tic_mem* tic;
char* data;
char* src;
struct
{
@ -105,4 +105,4 @@ struct Code
void(*update)(Code*);
};
void initCode(Code*, tic_mem*);
void initCode(Code*, tic_mem*, tic_code* src);

View File

@ -170,7 +170,7 @@ static void readConfig(Config* config)
if(lua)
{
if(luaL_loadstring(lua, config->tic->config.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK)
if(luaL_loadstring(lua, config->tic->config.bank0.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK)
{
readConfigVideoLength(config, lua);
readConfigVideoScale(config, lua);
@ -185,7 +185,7 @@ static void readConfig(Config* config)
static void update(Config* config, const u8* buffer, size_t size)
{
config->tic->api.load((tic_cartridge*)&config->tic->config, sizeof(tic_bank), buffer, size, true);
config->tic->api.load(&config->tic->config, 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((tic_cartridge*)&config->tic->config, buffer);
s32 size = config->tic->api.save(&config->tic->config, buffer);
fsSaveRootFile(config->fs, CONFIG_TIC_PATH, buffer, size, overwrite);

View File

@ -289,7 +289,7 @@ static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s
if(palette)
{
const tic_rgb* pal = tic->cart.bank.palette.colors;
const tic_rgb* pal = tic->cart.palette.colors;
for(s32 i = 0; i < TIC_PALETTE_SIZE; i++, pal++)
palette[i].r = pal->r, palette[i].g = pal->g, palette[i].b = pal->b;
@ -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, sizeof(tic_cartridge), buffer, size, palette);
tic->api.load(cart, buffer, size, palette);
if(!palette)
memcpy(cart->bank.palette.data, tic->config.palette.data, sizeof(tic_palette));
memcpy(cart->palette.data, tic->config.palette.data, sizeof(tic_palette));
}
static bool loadRom(tic_mem* tic, const void* data, s32 size, bool palette)
@ -360,12 +360,12 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param)
switch(i)
{
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;
case 1: memcpy(&tic->cart.bank0.tiles, &cart->bank0.tiles, sizeof(tic_tiles)*2); break;
case 2: memcpy(&tic->cart.bank0.map, &cart->bank0.map, sizeof(tic_map)); break;
case 3: memcpy(&tic->cart.bank0.code, &cart->bank0.code, sizeof(tic_code)); break;
case 4: memcpy(&tic->cart.bank0.sfx, &cart->bank0.sfx, sizeof(tic_sfx)); break;
case 5: memcpy(&tic->cart.bank0.music, &cart->bank0.music, sizeof(tic_music)); break;
case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof(tic_palette)); break;
}
studioRomLoaded();
@ -602,14 +602,14 @@ static char* saveBinarySection(char* ptr, const char* comment, const char* tag,
typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection;
static const BinarySection BinarySections[] =
{
{"PALETTE", 1, offsetof(tic_cartridge, bank.palette.data), sizeof(tic_palette), false},
{"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},
{"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, bank.sfx.waveform.envelopes), sizeof(tic_waveform), true},
{"SFX", SFX_COUNT, offsetof(tic_cartridge, bank.sfx.data), sizeof(tic_sound_effect), true},
{"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, bank.music.patterns), sizeof(tic_track_pattern), true},
{"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, bank.music.tracks), sizeof(tic_track), true},
{"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false},
{"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank0.tiles), sizeof(tic_tile), true},
{"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank0.sprites), sizeof(tic_tile), true},
{"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, bank0.map), TIC_MAP_WIDTH, true},
{"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, bank0.sfx.waveform.envelopes), sizeof(tic_waveform), true},
{"SFX", SFX_COUNT, offsetof(tic_cartridge, bank0.sfx.data), sizeof(tic_sound_effect), true},
{"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, bank0.music.patterns), sizeof(tic_track_pattern), true},
{"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, bank0.music.tracks), sizeof(tic_track), true},
};
static s32 saveProject(Console* console, void* buffer, const char* comment)
@ -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.bank.code.data);
char* ptr = saveTextSection(stream, tic->cart.bank0.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->bank.palette, &tic->config.palette.data, sizeof(tic_palette));
SDL_memcpy(&cart->palette, &tic->config.palette.data, sizeof(tic_palette));
const char* comment = projectComment(name);
if(loadTextSection(project, comment, cart->bank.code.data, sizeof(tic_code)))
if(loadTextSection(project, comment, cart->bank0.code.data, sizeof(tic_code)))
done = true;
for(s32 i = 0; i < COUNT_OF(BinarySections); i++)
@ -1328,9 +1328,9 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v
u8 src = image->buffer[x + y * image->width];
const gif_color* c = &image->palette[src];
tic_rgb rgb = {c->r, c->g, c->b};
u8 color = tic_tool_find_closest_color(console->tic->cart.bank.palette.colors, &rgb);
u8 color = tic_tool_find_closest_color(console->tic->cart.palette.colors, &rgb);
setSpritePixel(console->tic->cart.bank.tiles.data, x, y, color);
setSpritePixel(getBankTiles()->data, x, y, color);
}
gif_close(image);
@ -1352,8 +1352,8 @@ static void injectMap(Console* console, const void* buffer, s32 size)
{
enum {Size = sizeof(tic_map)};
SDL_memset(&console->tic->cart.bank.map, 0, Size);
SDL_memcpy(&console->tic->cart.bank.map, buffer, SDL_min(size, Size));
SDL_memset(getBankMap(), 0, Size);
SDL_memcpy(getBankMap(), buffer, SDL_min(size, Size));
}
static void onImportMap(const char* name, const void* buffer, size_t size, void* data)
@ -1453,7 +1453,7 @@ static void exportSprites(Console* console)
{
for (s32 y = 0; y < Height; y++)
for (s32 x = 0; x < Width; x++)
data[x + y * Width] = getSpritePixel(console->tic->cart.bank.tiles.data, x, y);
data[x + y * Width] = getSpritePixel(getBankTiles()->data, x, y);
s32 size = 0;
if((size = writeGifData(console->tic, buffer, data, Width, Height)))
@ -1493,7 +1493,7 @@ static void exportMap(Console* console)
if(buffer)
{
SDL_memcpy(buffer, console->tic->cart.bank.map.data, Size);
SDL_memcpy(buffer, getBankMap()->data, Size);
fsGetFileData(onMapExported, "world.map", buffer, Size, DEFAULT_CHMOD, console);
}
}
@ -1978,7 +1978,7 @@ static void onConsoleResumeCommand(Console* console, const char* param)
commandDone(console);
console->tic->api.resume(console->tic);
console->tic->api.sync(console->tic, false);
console->tic->api.sync(console->tic, NULL, 0, false);
setStudioMode(TIC_RUN_MODE);
}
@ -2714,7 +2714,7 @@ static bool cmdInjectCode(Console* console, const char* param, const char* name)
bool watch = strcmp(param, "-code-watch") == 0;
if(watch || strcmp(param, "-code") == 0)
{
bool loaded = loadFileIntoBuffer(console, console->embed.file->bank.code.data, name);
bool loaded = loadFileIntoBuffer(console, console->embed.file->bank0.code.data, name);
if(loaded)
{
@ -2763,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(console->embed.file->bank.palette.colors, &rgb);
u8 color = tic_tool_find_closest_color(console->embed.file->palette.colors, &rgb);
setSpritePixel(console->embed.file->bank.tiles.data, x, y, color);
setSpritePixel(console->embed.file->bank0.tiles.data, x, y, color);
}
gif_close(image);
@ -2886,7 +2886,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
if(argc > 1)
{
memcpy(console->embed.file->bank.palette.data, tic->config.palette.data, sizeof(tic_palette));
memcpy(console->embed.file->palette.data, tic->config.palette.data, sizeof(tic_palette));
u32 argp = 1;

View File

@ -170,7 +170,7 @@ static void drawDialog(Dialog* dlg)
{
u8 chromakey = 14;
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);
tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 2, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate);
}
{

View File

@ -30,6 +30,10 @@
#include <commdlg.h>
#include <stdio.h>
FILE* _wfopen(const wchar_t *, const wchar_t *);
wchar_t* wcsrchr(const wchar_t *, wchar_t);
wchar_t* wcscpy(wchar_t *, const wchar_t *);
#define UTF8ToString(S) (wchar_t *)SDL_iconv_string("UTF-16LE", "UTF-8", (char *)(S), SDL_strlen(S)+1)
#define StringToUTF8(S) SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(S), (SDL_wcslen(S)+1)*sizeof(wchar_t))

View File

@ -108,6 +108,9 @@ bool fsIsInPublicDir(FileSystem* fs)
#define UTF8ToString(S) (wchar_t *)SDL_iconv_string("UTF-16LE", "UTF-8", (char *)(S), SDL_strlen(S)+1)
#define StringToUTF8(S) SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(S), (SDL_wcslen(S)+1)*sizeof(wchar_t))
FILE* _wfopen(const wchar_t *, const wchar_t *);
int _wremove(const wchar_t *);
#define TIC_DIR _WDIR
#define tic_dirent _wdirent
#define tic_stat_struct _stat

View File

@ -512,7 +512,7 @@ static duk_ret_t duk_pmem(duk_context* duk)
u32 index = duk_to_int(duk, 0);
if(index >= 0 && index < TIC_PERSISTENT_SIZE)
if(index < TIC_PERSISTENT_SIZE)
{
s32 val = memory->ram.persistent.data[index];
@ -704,8 +704,13 @@ static duk_ret_t duk_sync(duk_context* duk)
tic_mem* memory = (tic_mem*)getDukMachine(duk);
bool toCart = duk_is_null_or_undefined(duk, 0) ? true : duk_to_boolean(duk, 0);
const char* section = duk_is_null_or_undefined(duk, 1) ? NULL : duk_to_string(duk, 1);
s32 bank = duk_is_null_or_undefined(duk, 2) ? 0 : duk_to_int(duk, 2);
memory->api.sync(memory, toCart);
if(bank >= 0 && bank < TIC_BANKS)
memory->api.sync(memory, section, bank, toCart);
else
duk_error(duk, DUK_ERR_ERROR, "sync() error, invalid bank");
return 0;
}
@ -747,7 +752,7 @@ static const struct{duk_c_function func; s32 params;} ApiFunc[] =
{duk_textri,14},
{duk_clip, 4},
{duk_music, 4},
{duk_sync, 1},
{duk_sync, 3},
};
static void initDuktape(tic_machine* machine)

View File

@ -748,11 +748,28 @@ static s32 lua_sync(lua_State* lua)
tic_mem* memory = (tic_mem*)getLuaMachine(lua);
bool toCart = true;
const char* section = NULL;
s32 bank = 0;
if(lua_gettop(lua) >= 1)
{
toCart = lua_toboolean(lua, 1);
memory->api.sync(memory, toCart);
if(lua_gettop(lua) >= 2)
{
section = lua_tostring(lua, 2);
if(lua_gettop(lua) >= 3)
{
bank = getLuaNumber(lua, 3);
}
}
}
if(bank >= 0 && bank < TIC_BANKS)
memory->api.sync(memory, section, bank, toCart);
else
luaL_error(lua, "sync() error, invalid bank");
return 0;
}
@ -964,7 +981,7 @@ static s32 lua_pmem(lua_State *lua)
{
u32 index = getLuaNumber(lua, 1);
if(index >= 0 && index < TIC_PERSISTENT_SIZE)
if(index < TIC_PERSISTENT_SIZE)
{
s32 val = memory->ram.persistent.data[index];

View File

@ -314,7 +314,7 @@ static void drawTileIndex(Map* map, s32 x, s32 y)
{
s32 tx = 0, ty = 0;
getMouseMap(map, &tx, &ty);
index = map->tic->api.map_get(map->tic, getBankMap(), tx, ty);
index = map->tic->api.map_get(map->tic, map->src, tx, ty);
}
}
@ -437,7 +437,7 @@ static void setMapSprite(Map* map, s32 x, s32 y)
for(s32 j = 0; j < map->sheet.rect.h; j++)
for(s32 i = 0; i < map->sheet.rect.w; i++)
map->tic->api.map_set(map->tic, getBankMap(), (x+i)%TIC_MAP_WIDTH, (y+j)%TIC_MAP_HEIGHT, (mx+i) + (my+j) * SHEET_COLS);
map->tic->api.map_set(map->tic, map->src, (x+i)%TIC_MAP_WIDTH, (y+j)%TIC_MAP_HEIGHT, (mx+i) + (my+j) * SHEET_COLS);
history_add(map->history);
}
@ -512,7 +512,7 @@ static void processMouseDrawMode(Map* map)
{
s32 tx = 0, ty = 0;
getMouseMap(map, &tx, &ty);
s32 index = map->tic->api.map_get(map->tic, getBankMap(), tx, ty);
s32 index = map->tic->api.map_get(map->tic, map->src, tx, ty);
map->sheet.rect = (SDL_Rect){index % SHEET_COLS, index / SHEET_COLS, 1, 1};
}
@ -593,7 +593,7 @@ static void drawPasteData(Map* map)
for(s32 j = 0; j < h; j++)
for(s32 i = 0; i < w; i++)
map->tic->api.map_set(map->tic, getBankMap(), (mx+i)%TIC_MAP_WIDTH, (my+j)%TIC_MAP_HEIGHT, data[i + j * w]);
map->tic->api.map_set(map->tic, map->src, (mx+i)%TIC_MAP_WIDTH, (my+j)%TIC_MAP_HEIGHT, data[i + j * w]);
history_add(map->history);
@ -764,7 +764,7 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile)
{
for(s32 j = 0; j < map->sheet.rect.h; j++)
for(s32 i = 0; i < map->sheet.rect.w; i++)
map->tic->api.map_set(map->tic, getBankMap(), x+i, y+j, (mx+i) + (my+j) * SHEET_COLS);
map->tic->api.map_set(map->tic, map->src, x+i, y+j, (mx+i) + (my+j) * SHEET_COLS);
for(s32 i = 0; i < COUNT_OF(dx); i++)
{
@ -776,7 +776,7 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile)
bool match = true;
for(s32 j = 0; j < map->sheet.rect.h; j++)
for(s32 i = 0; i < map->sheet.rect.w; i++)
if(map->tic->api.map_get(map->tic, getBankMap(), nx+i, ny+j) != tile)
if(map->tic->api.map_get(map->tic, map->src, nx+i, ny+j) != tile)
match = false;
if(match)
@ -801,7 +801,7 @@ static void processMouseFillMode(Map* map)
s32 tx = 0, ty = 0;
getMouseMap(map, &tx, &ty);
fillMap(map, tx, ty, map->tic->api.map_get(map->tic, getBankMap(), tx, ty));
fillMap(map, tx, ty, map->tic->api.map_get(map->tic, map->src, tx, ty));
history_add(map->history);
}
}
@ -864,7 +864,7 @@ static void drawMapOvr(Map* map)
s32 scrollX = map->scroll.x % TIC_SPRITESIZE;
s32 scrollY = map->scroll.y % TIC_SPRITESIZE;
map->tic->api.map(map->tic, getBankMap(), getBankTiles(), map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE,
map->tic->api.map(map->tic, map->src, getBankTiles(), map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE,
TIC_MAP_SCREEN_WIDTH + 1, TIC_MAP_SCREEN_HEIGHT + 1, -scrollX, -scrollY, -1, 1);
if(map->canvas.grid || map->scroll.active)
@ -950,7 +950,7 @@ static void copySelectionToClipboard(Map* map)
normalizeMapRect(&x, &y);
s32 index = x + y * TIC_MAP_WIDTH;
*ptr++ = getBankMap()->data[index];
*ptr++ = map->src->data[index];
}
toClipboard(buffer, size, true);
@ -978,7 +978,7 @@ static void deleteSelection(Map* map)
normalizeMapRect(&x, &y);
s32 index = x + y * TIC_MAP_WIDTH;
getBankMap()->data[index] = 0;
map->src->data[index] = 0;
}
history_add(map->history);
@ -1147,7 +1147,7 @@ static void overlap(tic_mem* tic, void* data)
drawSheetOvr(map, TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE);
}
void initMap(Map* map, tic_mem* tic)
void initMap(Map* map, tic_mem* tic, tic_map* src)
{
if(map->history) history_delete(map->history);
@ -1155,6 +1155,7 @@ void initMap(Map* map, tic_mem* tic)
{
.tic = tic,
.tick = tick,
.src = src,
.mode = MAP_DRAW_MODE,
.canvas =
{
@ -1185,7 +1186,7 @@ void initMap(Map* map, tic_mem* tic)
.gesture = false,
.start = {0, 0},
},
.history = history_create(&tic->cart.bank.map, sizeof(tic_map)),
.history = history_create(src, sizeof(tic_map)),
.event = onStudioEvent,
.overlap = overlap,
};

View File

@ -29,6 +29,8 @@ typedef struct Map Map;
struct Map
{
tic_mem* tic;
tic_map* src;
s32 tickCounter;
@ -83,4 +85,4 @@ struct Map
void(*overlap)(tic_mem* tic, void* data);
};
void initMap(Map*, tic_mem*);
void initMap(Map*, tic_mem*, tic_map* src);

View File

@ -124,7 +124,7 @@ static void drawDialog(Menu* menu)
{
u8 chromakey = 14;
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);
tic->api.sprite_ex(tic, &tic->config.bank0.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.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.bank0.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];

View File

@ -215,7 +215,7 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value,
static tic_track* getTrack(Music* music)
{
return &getBankMusic()->tracks.data[music->track];
return &music->src->tracks.data[music->track];
}
static s32 getRows(Music* music)
@ -368,7 +368,7 @@ static tic_track_pattern* getPattern(Music* music, s32 channel)
{
s32 patternId = tic_tool_get_pattern_id(getTrack(music), music->tracker.frame, channel);
return patternId ? &getBankMusic()->patterns.data[patternId - PATTERN_START] : NULL;
return patternId ? &music->src->patterns.data[patternId - PATTERN_START] : NULL;
}
static tic_track_pattern* getChannelPattern(Music* music)
@ -1327,7 +1327,7 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index)
}
u8 color = Chroma;
tic->api.sprite(tic, &tic->config.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1);
tic->api.sprite(tic, &tic->config.bank0.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1);
}
static void drawTracker(Music* music, s32 x, s32 y)
@ -1608,7 +1608,7 @@ static void onStudioEvent(Music* music, StudioEvent event)
}
}
void initMusic(Music* music, tic_mem* tic)
void initMusic(Music* music, tic_mem* tic, tic_music* src)
{
if (music->history) history_delete(music->history);
@ -1616,6 +1616,7 @@ void initMusic(Music* music, tic_mem* tic)
{
.tic = tic,
.tick = tick,
.src = src,
.track = 0,
.tracker =
{
@ -1643,7 +1644,7 @@ void initMusic(Music* music, tic_mem* tic)
},
.tab = MUSIC_TRACKER_TAB,
.history = history_create(&tic->cart.bank.music, sizeof(tic_music)),
.history = history_create(src, sizeof(tic_music)),
.event = onStudioEvent,
};

View File

@ -29,6 +29,9 @@ typedef struct Music Music;
struct Music
{
tic_mem* tic;
tic_music* src;
u8 track:MUSIC_TRACKS_BITS;
struct
@ -72,4 +75,4 @@ struct Music
void(*event)(Music*, StudioEvent);
};
void initMusic(Music*, tic_mem*);
void initMusic(Music*, tic_mem*, tic_music* src);

View File

@ -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.bank.code.data;
const char* data = strlen(run->tic->saveid) ? run->tic->saveid : run->tic->cart.bank0.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.bank.code.data, DoFileTag, Size) == 0)
if (memcmp(tic->cart.bank0.code.data, DoFileTag, Size) == 0)
{
const char* start = tic->cart.bank.code.data + Size;
const char* start = tic->cart.bank0.code.data + Size;
const char* end = strchr(start, ')');
if(end && *start == *(end-1) && (*start == '"' || *start == '\''))

View File

@ -106,7 +106,7 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi
static tic_sound_effect* getEffect(Sfx* sfx)
{
return getBankSfx()->data + sfx->index;
return sfx->src->data + sfx->index;
}
static void setIndex(Sfx* sfx, s32 delta)
@ -120,7 +120,7 @@ static void setSpeed(Sfx* sfx, s32 delta)
effect->speed += delta;
history_add(sfx->history.envelope);
history_add(sfx->history);
}
static void drawTopPanel(Sfx* sfx, s32 x, s32 y)
@ -141,7 +141,7 @@ static void setLoopStart(Sfx* sfx, s32 delta)
loop->start += delta;
history_add(sfx->history.envelope);
history_add(sfx->history);
}
static void setLoopSize(Sfx* sfx, s32 delta)
@ -151,7 +151,7 @@ static void setLoopSize(Sfx* sfx, s32 delta)
loop->size += delta;
history_add(sfx->history.envelope);
history_add(sfx->history);
}
static void drawLoopPanel(Sfx* sfx, s32 x, s32 y)
@ -169,7 +169,7 @@ static void drawLoopPanel(Sfx* sfx, s32 x, s32 y)
static tic_waveform* getWaveformById(Sfx* sfx, s32 i)
{
return &getBankSfx()->waveform.envelopes[i];
return &sfx->src->waveform.envelopes[i];
}
static tic_waveform* getWaveform(Sfx* sfx)
@ -398,7 +398,7 @@ static void drawCanvas(Sfx* sfx, s32 x, s32 y)
default: break;
}
history_add(sfx->history.envelope);
history_add(sfx->history);
}
}
@ -563,22 +563,12 @@ static void playSound(Sfx* sfx)
static void undo(Sfx* sfx)
{
history_undo(sfx->history.envelope);
history_undo(sfx->history);
}
static void redo(Sfx* sfx)
{
history_redo(sfx->history.envelope);
}
static void undoWave(Sfx* sfx)
{
history_undo(sfx->history.waveform);
}
static void redoWave(Sfx* sfx)
{
history_redo(sfx->history.waveform);
history_redo(sfx->history);
}
static void copyToClipboard(Sfx* sfx)
@ -598,7 +588,7 @@ static void resetSfx(Sfx* sfx)
tic_sound_effect* effect = getEffect(sfx);
memset(effect, 0, sizeof(tic_sound_effect));
history_add(sfx->history.envelope);
history_add(sfx->history);
}
static void resetWave(Sfx* sfx)
@ -606,7 +596,7 @@ static void resetWave(Sfx* sfx)
tic_waveform* wave = getWaveform(sfx);
memset(wave, 0, sizeof(tic_waveform));
history_add(sfx->history.waveform);
history_add(sfx->history);
}
static void cutToClipboard(Sfx* sfx)
@ -626,7 +616,7 @@ static void copyFromClipboard(Sfx* sfx)
tic_sound_effect* effect = getEffect(sfx);
if(fromClipboard(effect, sizeof(tic_sound_effect), true, false))
history_add(sfx->history.envelope);
history_add(sfx->history);
}
static void copyWaveFromClipboard(Sfx* sfx)
@ -634,7 +624,7 @@ static void copyWaveFromClipboard(Sfx* sfx)
tic_waveform* wave = getWaveform(sfx);
if(fromClipboard(wave, sizeof(tic_waveform), true, false))
history_add(sfx->history.waveform);
history_add(sfx->history);
}
static void processKeyboard(Sfx* sfx)
@ -728,8 +718,8 @@ static void processWaveformKeydown(Sfx* sfx, SDL_Keycode keycode)
{
switch(keycode)
{
case SDLK_z: undoWave(sfx); break;
case SDLK_y: redoWave(sfx); break;
case SDLK_z: undo(sfx); break;
case SDLK_y: redo(sfx); break;
}
}
@ -948,7 +938,7 @@ static void drawWaveformCanvas(Sfx* sfx, s32 x, s32 y)
tic_tool_poke4(wave->data, mx, Rows - my - 1);
history_add(sfx->history.waveform);
history_add(sfx->history);
}
}
@ -1019,8 +1009,8 @@ static void onStudioWaveformEvent(Sfx* sfx, StudioEvent event)
case TIC_TOOLBAR_CUT: cutWaveToClipboard(sfx); break;
case TIC_TOOLBAR_COPY: copyWaveToClipboard(sfx); break;
case TIC_TOOLBAR_PASTE: copyWaveFromClipboard(sfx); break;
case TIC_TOOLBAR_UNDO: undoWave(sfx); break;
case TIC_TOOLBAR_REDO: redoWave(sfx); break;
case TIC_TOOLBAR_UNDO: undo(sfx); break;
case TIC_TOOLBAR_REDO: redo(sfx); break;
default: break;
}
}
@ -1035,15 +1025,15 @@ static void onStudioEvent(Sfx* sfx, StudioEvent event)
}
}
void initSfx(Sfx* sfx, tic_mem* tic)
void initSfx(Sfx* sfx, tic_mem* tic, tic_sfx* src)
{
if(sfx->history.envelope) history_delete(sfx->history.envelope);
if(sfx->history.waveform) history_delete(sfx->history.waveform);
if(sfx->history) history_delete(sfx->history);
*sfx = (Sfx)
{
.tic = tic,
.tick = tick,
.src = src,
.index = 0,
.play =
{
@ -1056,11 +1046,7 @@ void initSfx(Sfx* sfx, tic_mem* tic)
},
.canvasTab = SFX_WAVE_TAB,
.tab = SFX_ENVELOPES_TAB,
.history =
{
.envelope = history_create(&tic->cart.bank.sfx.data, sizeof tic->cart.bank.sfx.data),
.waveform = history_create(&tic->cart.bank.sfx.waveform, sizeof tic->cart.bank.sfx.waveform),
},
.history = history_create(src, sizeof(tic_sfx)),
.event = onStudioEvent,
};
}

View File

@ -30,6 +30,8 @@ struct Sfx
{
tic_mem* tic;
tic_sfx* src;
u8 index:SFX_COUNT_BITS;
struct
@ -57,14 +59,10 @@ struct Sfx
SFX_ENVELOPES_TAB,
} tab;
struct
{
struct History* envelope;
struct History* waveform;
} history;
struct History* history;
void(*tick)(Sfx*);
void(*event)(Sfx*, StudioEvent);
};
void initSfx(Sfx*, tic_mem*);
void initSfx(Sfx*, tic_mem*, tic_sfx* src);

View File

@ -38,12 +38,12 @@ static void clearCanvasSelection(Sprite* sprite)
static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y)
{
return getSpritePixel(getBankTiles()->data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y);
return getSpritePixel(sprite->src->data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y);
}
static void setSheetPixel(Sprite* sprite, s32 x, s32 y, u8 color)
{
setSpritePixel(getBankTiles()->data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y, color);
setSpritePixel(sprite->src->data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y, color);
}
static s32 getIndexPosX(Sprite* sprite)
@ -672,8 +672,8 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value)
static void pasteColor(Sprite* sprite)
{
fromClipboard(getBankPalette()->data, sizeof(tic_palette), false, true);
fromClipboard(&getBankPalette()->colors[sprite->color], sizeof(tic_rgb), false, true);
fromClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false, true);
fromClipboard(&sprite->tic->cart.palette.colors[sprite->color], sizeof(tic_rgb), false, true);
}
static void drawRGBTools(Sprite* sprite, s32 x, s32 y)
@ -708,7 +708,7 @@ static void drawRGBTools(Sprite* sprite, s32 x, s32 y)
down = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT))
toClipboard(getBankPalette()->data, sizeof(tic_palette), false);
toClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false);
}
if(down)
@ -772,7 +772,7 @@ static void drawRGBSliders(Sprite* sprite, s32 x, s32 y)
{
enum{Gap = 6, Count = sizeof(tic_rgb)};
u8* data = &getBankPalette()->data[sprite->color * Count];
u8* data = &sprite->tic->cart.palette.data[sprite->color * Count];
for(s32 i = 0; i < Count; i++)
drawRGBSlider(sprite, x, y + Gap*i, &data[i]);
@ -784,7 +784,7 @@ static void drawRGBSlidersOvr(Sprite* sprite, s32 x, s32 y)
{
enum{Gap = 6, Count = sizeof(tic_rgb), Size = CANVAS_SIZE, Max = 255};
u8* data = &getBankPalette()->data[sprite->color * Count];
u8* data = &sprite->tic->cart.palette.data[sprite->color * Count];
for(s32 i = 0; i < Count; i++)
{
@ -959,7 +959,7 @@ static void drawSheetOvr(Sprite* sprite, s32 x, s32 y)
for(s32 j = 0, index = (sprite->index - sprite->index % TIC_BANK_SPRITES); j < rect.h; j += TIC_SPRITESIZE)
for(s32 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++)
sprite->tic->api.sprite(sprite->tic, getBankTiles(), index, x + i, y + j, NULL, 0);
sprite->tic->api.sprite(sprite->tic, sprite->src, index, x + i, y + j, NULL, 0);
{
s32 bx = getIndexPosX(sprite) + x - 1;
s32 by = getIndexPosY(sprite) + y - 1;
@ -1544,7 +1544,7 @@ static void overlap(tic_mem* tic, void* data)
drawSheetOvr(sprite, TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, 7);
}
void initSprite(Sprite* sprite, tic_mem* tic)
void initSprite(Sprite* sprite, tic_mem* tic, tic_tiles* src)
{
if(sprite->select.back == NULL) sprite->select.back = (u8*)SDL_malloc(CANVAS_SIZE*CANVAS_SIZE);
if(sprite->select.front == NULL) sprite->select.front = (u8*)SDL_malloc(CANVAS_SIZE*CANVAS_SIZE);
@ -1555,6 +1555,7 @@ void initSprite(Sprite* sprite, tic_mem* tic)
.tic = tic,
.tick = tick,
.tickCounter = 0,
.src = src,
.index = 0,
.color = 1,
.color2 = 0,
@ -1570,7 +1571,7 @@ void initSprite(Sprite* sprite, tic_mem* tic)
.front = sprite->select.front,
},
.mode = SPRITE_DRAW_MODE,
.history = history_create(&tic->cart.bank.tiles, TIC_SPRITES * sizeof(tic_tile)),
.history = history_create(src, TIC_SPRITES * sizeof(tic_tile)),
.event = onStudioEvent,
.overlap = overlap,
};

View File

@ -30,6 +30,8 @@ struct Sprite
{
tic_mem* tic;
tic_tiles* src;
u32 tickCounter;
u16 index;
@ -64,4 +66,4 @@ struct Sprite
void (*overlap)(tic_mem* tic, void* data);
};
void initSprite(Sprite*, tic_mem*);
void initSprite(Sprite*, tic_mem*, tic_tiles* src);

View File

@ -59,6 +59,12 @@
#define POPUP_DUR (TIC_FRAMERATE*2)
#if defined(TIC80_PRO)
#define TIC_EDITOR_BANKS (TIC_BANKS)
#else
#define TIC_EDITOR_BANKS 1
#endif
typedef struct
{
u8 data[16];
@ -162,7 +168,7 @@ static struct
struct
{
s32 code;
s32 tiles;
s32 sprites;
s32 map;
s32 sfx;
s32 music;
@ -196,17 +202,21 @@ static struct
bool fullscreen;
struct
{
Code* code [TIC_EDITOR_BANKS];
Sprite* sprite [TIC_EDITOR_BANKS];
Map* map [TIC_EDITOR_BANKS];
Sfx* sfx [TIC_EDITOR_BANKS];
Music* music [TIC_EDITOR_BANKS];
} editor;
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;
@ -312,12 +322,7 @@ static struct
tic_tiles* getBankTiles()
{
return &studio.tic->cart.banks[studio.bank.index.tiles].tiles;
}
tic_tiles* getBankSprites()
{
return &studio.tic->cart.banks[studio.bank.index.tiles].sprites;
return &studio.tic->cart.banks[studio.bank.index.sprites].tiles;
}
tic_map* getBankMap()
@ -325,29 +330,9 @@ tic_map* getBankMap()
return &studio.tic->cart.banks[studio.bank.index.map].map;
}
tic_sfx* getBankSfx()
{
return &studio.tic->cart.banks[studio.bank.index.sfx].sfx;
}
tic_music* getBankMusic()
{
return &studio.tic->cart.banks[studio.bank.index.music].music;
}
tic_code* getBankCode()
{
return &studio.tic->cart.banks[studio.bank.index.code].code;
}
tic_palette* getBankPalette()
{
return &studio.tic->cart.banks[studio.bank.index.tiles].palette;
}
void playSystemSfx(s32 id)
{
const tic_sound_effect* effect = &studio.tic->config.sfx.data[id];
const tic_sound_effect* effect = &studio.tic->config.bank0.sfx.data[id];
studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0);
}
@ -628,7 +613,7 @@ static void drawBankIcon(s32 x, s32 y)
enum{Size = TOOLBAR_SIZE};
for(s32 i = 0; i < TIC_BANKS; i++)
for(s32 i = 0; i < TIC_EDITOR_BANKS; i++)
{
SDL_Rect rect = {x + 2 + (i+1)*Size, 0, Size, Size};
@ -790,11 +775,36 @@ 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:
{
Code* code = studio.editor.code[studio.bank.index.code];
code->event(code, event);
}
break;
case TIC_SPRITE_MODE:
{
Sprite* sprite = studio.editor.sprite[studio.bank.index.sprites];
sprite->event(sprite, event);
}
break;
case TIC_MAP_MODE:
{
Map* map = studio.editor.map[studio.bank.index.map];
map->event(map, event);
}
break;
case TIC_SFX_MODE:
{
Sfx* sfx = studio.editor.sfx[studio.bank.index.sfx];
sfx->event(sfx, event);
}
break;
case TIC_MUSIC_MODE:
{
Music* music = studio.editor.music[studio.bank.index.music];
music->event(music, event);
}
break;
default: break;
}
}
@ -869,7 +879,7 @@ 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.editor.map[studio.bank.index.map]);
}
static void initRunMode()
@ -1062,7 +1072,7 @@ void hideDialog()
if(studio.dialogMode == TIC_RUN_MODE)
{
studio.tic->api.resume(studio.tic);
studio.mode = TIC_RUN_MODE;
studio.mode = TIC_RUN_MODE;
}
else setStudioMode(studio.dialogMode);
}
@ -1079,12 +1089,18 @@ 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);
tic_mem* tic = studio.tic;
for(s32 i = 0; i < TIC_EDITOR_BANKS; i++)
{
initCode(studio.editor.code[i], studio.tic, &tic->cart.banks[i].code);
initSprite(studio.editor.sprite[i], studio.tic, &tic->cart.banks[i].tiles);
initMap(studio.editor.map[i], studio.tic, &tic->cart.banks[i].map);
initSfx(studio.editor.sfx[i], studio.tic, &tic->cart.banks[i].sfx);
initMusic(studio.editor.music[i], studio.tic, &tic->cart.banks[i].music);
}
initWorldMap();
initSfx(studio.sfx, studio.tic);
initMusic(studio.music, studio.tic);
}
static void updateHash()
@ -1784,9 +1800,11 @@ 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)
Code* code = studio.editor.code[studio.bank.index.code];
if(studio.mode == TIC_CODE_MODE && code->mode != TEXT_EDIT_MODE)
{
studio.code->escape(studio.code);
code->escape(code);
return true;
}
@ -1920,9 +1938,10 @@ 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);
Code* code = studio.editor.code[studio.bank.index.code];
studio.console->codeLiveReload.reload(studio.console, code->src);
if(studio.console->codeLiveReload.active && code->update)
code->update(code);
}
break;
}
@ -2083,12 +2102,18 @@ static void blitTexture()
overlap = tic->api.overlap;
break;
case TIC_SPRITE_MODE:
overlap = studio.sprite->overlap;
data = studio.sprite;
{
Sprite* sprite = studio.editor.sprite[studio.bank.index.sprites];
overlap = sprite->overlap;
data = sprite;
}
break;
case TIC_MAP_MODE:
overlap = studio.map->overlap;
data = studio.map;
{
Map* map = studio.editor.map[studio.bank.index.map];
overlap = map->overlap;
data = map;
}
break;
default:
break;
@ -2209,7 +2234,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.tiles.data[getConfig()->theme.cursor.sprite].data);
blitCursor(studio.tic->config.bank0.tiles.data[getConfig()->theme.cursor.sprite].data);
}
static void useSystemPalette()
@ -2264,12 +2289,12 @@ static void renderStudio()
case TIC_DIALOG_MODE:
case TIC_MENU_MODE:
case TIC_SURF_MODE:
sfx = &studio.tic->config.sfx;
music = &studio.tic->config.music;
sfx = &studio.tic->config.bank0.sfx;
music = &studio.tic->config.bank0.music;
break;
default:
sfx = getBankSfx();
music = getBankMusic();
sfx = &studio.tic->cart.banks[studio.bank.index.sfx].sfx;
music = &studio.tic->cart.banks[studio.bank.index.music].music;
}
studio.tic->api.tick_start(studio.tic, sfx, music);
@ -2280,12 +2305,38 @@ static void renderStudio()
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_CODE_MODE:
{
Code* code = studio.editor.code[studio.bank.index.code];
code->tick(code);
}
break;
case TIC_SPRITE_MODE:
{
Sprite* sprite = studio.editor.sprite[studio.bank.index.sprites];
sprite->tick(sprite);
}
break;
case TIC_MAP_MODE:
{
Map* map = studio.editor.map[studio.bank.index.map];
map->tick(map);
}
break;
case TIC_SFX_MODE:
{
Sfx* sfx = studio.editor.sfx[studio.bank.index.sfx];
sfx->tick(sfx);
}
break;
case TIC_MUSIC_MODE:
{
Music* music = studio.editor.music[studio.bank.index.music];
music->tick(music);
}
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;
@ -2443,7 +2494,7 @@ static void initTouchGamepad()
if (!studio.renderer)
return;
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);
studio.tic->api.map(studio.tic, &studio.tic->config.bank0.map, &studio.tic->config.bank0.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1);
if(!studio.gamepad.texture)
{
@ -2470,14 +2521,15 @@ 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.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1))
if(tic_tool_peek4(&studio.tic->config.bank0.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);
Code* code = studio.editor.code[studio.bank.index.code];
if(code->update)
code->update(code);
initTouchGamepad();
updateSystemFont();
@ -2495,7 +2547,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.tiles.data, i/Scale, j/Scale);
u8 color = getSpritePixel(studio.tic->config.bank0.tiles.data, i/Scale, j/Scale);
pixels[index] = color == ColorKey ? 0 : pal[color];
}
@ -2560,20 +2612,24 @@ static void onFSInitialized(FileSystem* fs)
studio.tic = studio.tic80local->memory;
{
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));
for(s32 i = 0; i < TIC_EDITOR_BANKS; i++)
{
studio.editor.code[i] = SDL_malloc(sizeof(Code));
studio.editor.sprite[i] = SDL_malloc(sizeof(Sprite));
studio.editor.map[i] = SDL_malloc(sizeof(Map));
studio.editor.sfx[i] = SDL_malloc(sizeof(Sfx));
studio.editor.music[i] = SDL_malloc(sizeof(Music));
}
studio.start = SDL_malloc(sizeof(Start));
studio.console = SDL_malloc(sizeof(Console));
studio.run = SDL_malloc(sizeof(Run));
studio.world = SDL_malloc(sizeof(World));
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));
}
fsMakeDir(fs, TIC_LOCAL);
@ -2668,15 +2724,19 @@ s32 main(s32 argc, char **argv)
#endif
{
for(s32 i = 0; i < TIC_EDITOR_BANKS; i++)
{
SDL_free(studio.editor.code[i]);
SDL_free(studio.editor.sprite[i]);
SDL_free(studio.editor.map[i]);
SDL_free(studio.editor.sfx[i]);
SDL_free(studio.editor.music[i]);
}
SDL_free(studio.start);
SDL_free(studio.console);
SDL_free(studio.run);
SDL_free(studio.code);
SDL_free(studio.sprite);
SDL_free(studio.map);
SDL_free(studio.world);
SDL_free(studio.sfx);
SDL_free(studio.music);
SDL_free(studio.config);
SDL_free(studio.keymap);
SDL_free(studio.dialog);

View File

@ -200,10 +200,5 @@ void gotoSurf();
void exitFromGameMenu();
void runProject();
tic_tiles* getBankTiles();
tic_tiles* getBankSprites();
tic_map* getBankMap();
tic_sfx* getBankSfx();
tic_music* getBankMusic();
tic_code* getBankCode();
tic_palette* getBankPalette();
tic_tiles* getBankTiles();
tic_map* getBankMap();

View File

@ -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.tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
tic->api.sprite_ex(tic, &tic->config.bank0.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.tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
tic->api.sprite_ex(tic, &tic->config.bank0.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.tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
tic->api.sprite_ex(tic, &tic->config.bank0.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.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.bank0.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, sizeof(tic_cartridge), data, size, true);
tic->api.load(cart, data, size, true);
if(cart->cover.size)
updateMenuItemCover(surf, cart->cover.data, cart->cover.size);

105
src/tic.c
View File

@ -26,6 +26,7 @@
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <stddef.h>
#include "ticapi.h"
#include "tools.h"
@ -144,7 +145,7 @@ static void runNoise(blip_buffer_t* blip, tic_sound_register* reg, tic_sound_reg
static void resetPalette(tic_mem* memory)
{
static const u8 DefaultMapping[] = {16, 50, 84, 118, 152, 186, 220, 254};
memcpy(memory->ram.vram.palette.data, memory->cart.bank.palette.data, sizeof(tic_palette));
memcpy(memory->ram.vram.palette.data, memory->cart.palette.data, sizeof(tic_palette));
memcpy(memory->ram.vram.mapping, DefaultMapping, sizeof DefaultMapping);
}
@ -1255,7 +1256,7 @@ static void api_tick_end(tic_mem* memory)
machine->state.setpix = setPixelOvr;
machine->state.getpix = getPixelOvr;
memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.bank.palette), sizeof machine->state.ovr.palette);
memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.palette), sizeof machine->state.ovr.palette);
}
@ -1312,7 +1313,7 @@ static void initCover(tic_mem* tic)
{
const gif_color* c = &image->palette[image->buffer[i]];
tic_rgb rgb = { c->r, c->g, c->b };
u8 color = tic_tool_find_closest_color(tic->cart.bank.palette.colors, &rgb);
u8 color = tic_tool_find_closest_color(tic->cart.palette.colors, &rgb);
tic_tool_poke4(tic->ram.vram.screen.data, i, color);
}
}
@ -1322,29 +1323,33 @@ static void initCover(tic_mem* tic)
}
}
static void api_sync(tic_mem* tic, bool toCart)
static void api_sync(tic_mem* tic, const char* section, s32 bank, bool toCart)
{
if(toCart)
static const struct {const char* name; s32 cart; s32 ram; s32 size;} Sections[] =
{
memcpy(&tic->cart.bank.tiles, &tic->ram.tiles, sizeof(tic_tiles));
memcpy(&tic->cart.bank.sprites, &tic->ram.sprites, sizeof(tic_tiles));
memcpy(&tic->cart.bank.map, &tic->ram.map, sizeof(tic_map));
memcpy(&tic->cart.bank.sfx, &tic->ram.sfx, sizeof(tic_sfx));
memcpy(&tic->cart.bank.music, &tic->ram.music, sizeof(tic_music));
}
else
{"tiles", offsetof(tic_cartridge, bank0.tiles), offsetof(tic_ram, tiles), sizeof(tic_tiles)},
{"sprites", offsetof(tic_cartridge, bank0.sprites), offsetof(tic_ram, sprites), sizeof(tic_tiles)},
{"map", offsetof(tic_cartridge, bank0.map), offsetof(tic_ram, map), sizeof(tic_map)},
{"sfx", offsetof(tic_cartridge, bank0.sfx), offsetof(tic_ram, sfx), sizeof(tic_sfx)},
{"music", offsetof(tic_cartridge, bank0.music), offsetof(tic_ram, music), sizeof(tic_music)},
};
assert(bank >= 0 && bank < TIC_BANKS);
s32 bankOffset = bank * sizeof(tic_bank);
for(s32 i = 0; i < COUNT_OF(Sections); i++)
{
memcpy(&tic->ram.tiles, &tic->cart.bank.tiles, sizeof(tic_tiles));
memcpy(&tic->ram.sprites, &tic->cart.bank.sprites, sizeof(tic_tiles));
memcpy(&tic->ram.map, &tic->cart.bank.map, sizeof(tic_map));
memcpy(&tic->ram.sfx, &tic->cart.bank.sfx, sizeof(tic_sfx));
memcpy(&tic->ram.music, &tic->cart.bank.music, sizeof(tic_music));
if(section == NULL || (section && strcmp(section, Sections[i].name) == 0))
toCart
? memcpy((u8*)&tic->cart + Sections[i].cart + bankOffset, (u8*)&tic->ram + Sections[i].ram, Sections[i].size)
: memcpy((u8*)&tic->ram + Sections[i].ram, (u8*)&tic->cart + Sections[i].cart + bankOffset, Sections[i].size);
}
}
static void cart2ram(tic_mem* memory)
{
api_sync(memory, false);
api_sync(memory, NULL, 0, false);
initCover(memory);
}
@ -1433,15 +1438,15 @@ static bool isJavascript(const char* code)
static tic_script_lang api_get_script(tic_mem* memory)
{
if(isMoonscript(memory->cart.bank.code.data)) return tic_script_moon;
if(isJavascript(memory->cart.bank.code.data)) return tic_script_js;
if(isMoonscript(memory->cart.bank0.code.data)) return tic_script_moon;
if(isJavascript(memory->cart.bank0.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.bank.code.data, "saveid", TagFormatLua);
const char* saveid = readMetatag(memory->cart.bank0.code.data, "saveid", TagFormatLua);
if(saveid)
{
strcpy(memory->saveid, saveid);
@ -1449,7 +1454,7 @@ static void updateSaveid(tic_mem* memory)
}
else
{
const char* saveid = readMetatag(memory->cart.bank.code.data, "saveid", TagFormatJS);
const char* saveid = readMetatag(memory->cart.bank0.code.data, "saveid", TagFormatJS);
if(saveid)
{
strcpy(memory->saveid, saveid);
@ -1466,12 +1471,20 @@ static void api_tick(tic_mem* memory, tic_tick_data* data)
if(!machine->state.initialized)
{
char* code = malloc(sizeof(tic_code));
enum{CodeSize = sizeof(tic_code) * TIC_BANKS};
char* code = malloc(CodeSize);
if(code)
{
memcpy(code, machine->memory.cart.bank.code.data, sizeof(tic_code));
memset(code, 0, CodeSize);
for(s32 i = TIC_BANKS - 1; i >= 0; i--)
{
const char* bankCode = memory->cart.banks[i].code.data;
if(strlen(bankCode))
strcat(code, bankCode);
}
if(data->preprocessor)
data->preprocessor(data->data, code);
@ -1573,15 +1586,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, s32 cartSize, const u8* buffer, s32 size, bool palette)
static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palette)
{
const u8* end = buffer + size;
memset(cart, 0, cartSize);
memset(cart, 0, sizeof(tic_cartridge));
if(palette)
{
static const u8 DB16[] = {0x14, 0x0c, 0x1c, 0x44, 0x24, 0x34, 0x30, 0x34, 0x6d, 0x4e, 0x4a, 0x4e, 0x85, 0x4c, 0x30, 0x34, 0x65, 0x24, 0xd0, 0x46, 0x48, 0x75, 0x71, 0x61, 0x59, 0x7d, 0xce, 0xd2, 0x7d, 0x2c, 0x85, 0x95, 0xa1, 0x6d, 0xaa, 0x2c, 0xd2, 0xaa, 0x99, 0x6d, 0xc2, 0xca, 0xda, 0xd4, 0x5e, 0xde, 0xee, 0xd6};
memcpy(cart->bank.palette.data, DB16, sizeof(tic_palette));
memcpy(cart->palette.data, DB16, sizeof(tic_palette));
}
#define LOAD_CHUNK(to) memcpy(&to, buffer, min(sizeof(to), chunk.size))
@ -1594,17 +1607,17 @@ static void api_load(tic_cartridge* cart, s32 cartSize, const u8* buffer, s32 si
switch(chunk.type)
{
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->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_TILES: LOAD_CHUNK(cart->bank0.tiles); break;
case CHUNK_SPRITES: LOAD_CHUNK(cart->bank0.sprites); break;
case CHUNK_MAP: LOAD_CHUNK(cart->bank0.map); break;
case CHUNK_CODE: LOAD_CHUNK(cart->bank0.code); break;
case CHUNK_SOUND: LOAD_CHUNK(cart->bank0.sfx.data); break;
case CHUNK_WAVEFORM: LOAD_CHUNK(cart->bank0.sfx.waveform); break;
case CHUNK_MUSIC: LOAD_CHUNK(cart->bank0.music.tracks.data); break;
case CHUNK_PATTERNS: LOAD_CHUNK(cart->bank0.music.patterns.data); break;
case CHUNK_PALETTE:
if(palette)
LOAD_CHUNK(cart->bank.palette);
LOAD_CHUNK(cart->palette);
break;
case CHUNK_COVER:
LOAD_CHUNK(cart->cover.data);
@ -1663,15 +1676,15 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer)
#define SAVE_CHUNK(id, from) saveChunk(buffer, id, &from, sizeof(from))
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->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->bank.palette);
buffer = SAVE_CHUNK(CHUNK_TILES, cart->bank0.tiles);
buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->bank0.sprites);
buffer = SAVE_CHUNK(CHUNK_MAP, cart->bank0.map);
buffer = SAVE_CHUNK(CHUNK_CODE, cart->bank0.code);
buffer = SAVE_CHUNK(CHUNK_SOUND, cart->bank0.sfx.data);
buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->bank0.sfx.waveform);
buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->bank0.music.patterns.data);
buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->bank0.music.tracks.data);
buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette);
buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size);

View File

@ -334,17 +334,17 @@ typedef struct
tic_sfx sfx;
tic_music music;
tic_code code;
tic_palette palette;
} tic_bank;
typedef struct
{
union
{
tic_bank bank;
tic_bank bank0;
tic_bank banks[TIC_BANKS];
};
tic_palette palette;
tic_cover_image cover;
} tic_cartridge;

View File

@ -108,7 +108,7 @@ TIC80_API void tic80_load(tic80* tic, void* cart, s32 size)
}
{
tic80->memory->api.load(&tic80->memory->cart, sizeof(tic_cartridge), cart, size, true);
tic80->memory->api.load(&tic80->memory->cart, cart, size, true);
tic80->memory->api.reset(tic80->memory);
}
}

View File

@ -103,10 +103,10 @@ typedef struct
void (*reset) (tic_mem* memory);
void (*pause) (tic_mem* memory);
void (*resume) (tic_mem* memory);
void (*sync) (tic_mem* memory, bool toCart);
void (*sync) (tic_mem* memory, const char* section, s32 bank, bool toCart);
u32 (*btnp) (tic_mem* memory, s32 id, s32 hold, s32 period);
void (*load) (tic_cartridge* rom, s32 cartSize, const u8* buffer, s32 size, bool palette);
void (*load) (tic_cartridge* rom, 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_bank config;
tic_cartridge config;
tic_input_method input;
tic_script_lang script;
tic_font font;