#652: reverted font width/height in the config

This commit is contained in:
Vadim Grigoruk 2018-08-03 23:22:58 +03:00
parent 6180a561e9
commit 4249516d7e
22 changed files with 436 additions and 559 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -27,19 +27,16 @@
#define TEXT_CURSOR_DELAY (TIC_FRAMERATE / 2)
#define TEXT_CURSOR_BLINK_PERIOD TIC_FRAMERATE
static inline s32 TextBufferHeight(const tic_mem* tic)
{
return ((TIC80_HEIGHT - TOOLBAR_SIZE - TextHeight(tic)) / TextHeight(tic));
}
#define TEXT_BUFFER_WIDTH STUDIO_TEXT_BUFFER_WIDTH
#define TEXT_BUFFER_HEIGHT ((TIC80_HEIGHT - TOOLBAR_SIZE - STUDIO_TEXT_HEIGHT) / STUDIO_TEXT_HEIGHT)
struct OutlineItem
{
char name[TIC80_WIDTH];
char name[STUDIO_TEXT_BUFFER_WIDTH];
char* pos;
};
#define OUTLINE_SIZE (TIC80_HEIGHT)
#define OUTLINE_SIZE ((TIC80_HEIGHT - TOOLBAR_SIZE*2)/TIC_FONT_HEIGHT)
#define OUTLINE_ITEMS_SIZE (OUTLINE_SIZE * sizeof(OutlineItem))
static void history(Code* code)
@ -50,23 +47,18 @@ static void history(Code* code)
static void drawStatus(Code* code)
{
tic_mem* tic = code->tic;
const s32 Height = tic->font.height + 1;
tic->api.rect(tic, 0, TIC80_HEIGHT - Height, TIC80_WIDTH, Height, (tic_color_white));
tic->api.fixed_text(tic, code->status.left, 0, TIC80_HEIGHT - tic->font.height, getConfig()->theme.code.bg);
tic->api.fixed_text(tic, code->status.right, TIC80_WIDTH - (strlen(code->status.right) * tic->font.width),
TIC80_HEIGHT - tic->font.height, getConfig()->theme.code.bg);
const s32 Height = TIC_FONT_HEIGHT + 1;
code->tic->api.rect(code->tic, 0, TIC80_HEIGHT - Height, TIC80_WIDTH, Height, (tic_color_white));
code->tic->api.fixed_text(code->tic, code->status, 0, TIC80_HEIGHT - TIC_FONT_HEIGHT, getConfig()->theme.code.bg);
}
static void drawCursor(Code* code, s32 x, s32 y, char symbol)
{
tic_mem* tic = code->tic;
bool inverse = code->cursor.delay || code->tickCounter % TEXT_CURSOR_BLINK_PERIOD < TEXT_CURSOR_BLINK_PERIOD / 2;
if(inverse)
{
code->tic->api.rect(code->tic, x-1, y-1, tic->font.width+1, tic->font.height+1, getConfig()->theme.code.cursor);
code->tic->api.rect(code->tic, x-1, y-1, TIC_FONT_WIDTH+1, TIC_FONT_HEIGHT+1, getConfig()->theme.code.cursor);
if(symbol)
code->tic->api.draw_char(code->tic, symbol, x, y, getConfig()->theme.code.bg);
@ -75,10 +67,9 @@ static void drawCursor(Code* code, s32 x, s32 y, char symbol)
static void drawCode(Code* code, bool withCursor)
{
tic_mem* tic = code->tic;
s32 xStart = code->rect.x - code->scroll.x * TextWidth(tic);
s32 xStart = code->rect.x - code->scroll.x * STUDIO_TEXT_WIDTH;
s32 x = xStart;
s32 y = code->rect.y - code->scroll.y * TextHeight(tic);
s32 y = code->rect.y - code->scroll.y * STUDIO_TEXT_HEIGHT;
char* pointer = code->src;
u8* colorPointer = code->colorBuffer;
@ -92,10 +83,10 @@ static void drawCode(Code* code, bool withCursor)
{
char symbol = *pointer;
if(x >= -tic->font.width && x < TIC80_WIDTH && y >= -tic->font.height && y < TIC80_HEIGHT )
if(x >= -TIC_FONT_WIDTH && x < TIC80_WIDTH && y >= -TIC_FONT_HEIGHT && y < TIC80_HEIGHT )
{
if(code->cursor.selection && pointer >= selection.start && pointer < selection.end)
code->tic->api.rect(code->tic, x-1, y-1, tic->font.width+1, tic->font.height+1, getConfig()->theme.code.select);
code->tic->api.rect(code->tic, x-1, y-1, TIC_FONT_WIDTH+1, TIC_FONT_HEIGHT+1, getConfig()->theme.code.select);
else if(getConfig()->theme.code.shadow)
{
code->tic->api.draw_char(code->tic, symbol, x+1, y+1, 0);
@ -110,9 +101,9 @@ static void drawCode(Code* code, bool withCursor)
if(symbol == '\n')
{
x = xStart;
y += TextHeight(tic);
y += STUDIO_TEXT_HEIGHT;
}
else x += TextWidth(tic);
else x += STUDIO_TEXT_WIDTH;
pointer++;
colorPointer++;
@ -168,31 +159,34 @@ static void removeInvalidChars(char* code)
static void updateEditor(Code* code)
{
tic_mem* tic = code->tic;
s32 column = 0;
s32 line = 0;
getCursorPosition(code, &column, &line);
if(column < code->scroll.x) code->scroll.x = column;
else if(column >= code->scroll.x + BufferWidth(tic))
code->scroll.x = column - BufferWidth(tic) + 1;
else if(column >= code->scroll.x + TEXT_BUFFER_WIDTH)
code->scroll.x = column - TEXT_BUFFER_WIDTH + 1;
if(line < code->scroll.y) code->scroll.y = line;
else if(line >= code->scroll.y + TextBufferHeight(tic))
code->scroll.y = line - TextBufferHeight(tic) + 1;
else if(line >= code->scroll.y + TEXT_BUFFER_HEIGHT)
code->scroll.y = line - TEXT_BUFFER_HEIGHT + 1;
code->cursor.delay = TEXT_CURSOR_DELAY;
// update status
{
memset(code->status, ' ', sizeof code->status - 1);
char status[STUDIO_TEXT_BUFFER_WIDTH];
s32 count = getLinesCount(code);
sprintf(code->status.left, "line %i/%i col %i", line + 1, count + 1, column + 1);
sprintf(status, "line %i/%i col %i", line + 1, count + 1, column + 1);
memcpy(code->status, status, strlen(status));
size_t codeLen = strlen(code->src);
sprintf(code->status.right, "%i/%i", (u32)codeLen, TIC_CODE_SIZE);
sprintf(status, "%i/%i", (u32)codeLen, TIC_CODE_SIZE);
memset(code->src + codeLen, '\0', TIC_CODE_SIZE - codeLen);
memcpy(code->status + sizeof code->status - strlen(status) - 1, status, strlen(status));
}
}
@ -409,21 +403,19 @@ static void goCodeEnd(Code *code)
static void pageUp(Code* code)
{
tic_mem* tic = code->tic;
s32 column = 0;
s32 line = 0;
getCursorPosition(code, &column, &line);
setCursorPosition(code, column, line > TextBufferHeight(tic) ? line - TextBufferHeight(tic) : 0);
setCursorPosition(code, column, line > TEXT_BUFFER_HEIGHT ? line - TEXT_BUFFER_HEIGHT : 0);
}
static void pageDown(Code* code)
{
tic_mem* tic = code->tic;
s32 column = 0;
s32 line = 0;
getCursorPosition(code, &column, &line);
s32 lines = getLinesCount(code);
setCursorPosition(code, column, line < lines - TextBufferHeight(tic) ? line + TextBufferHeight(tic) : lines);
setCursorPosition(code, column, line < lines - TEXT_BUFFER_HEIGHT ? line + TEXT_BUFFER_HEIGHT : lines);
}
static bool replaceSelection(Code* code)
@ -734,12 +726,10 @@ static void normalizeScroll(Code* code)
static void centerScroll(Code* code)
{
tic_mem* tic = code->tic;
s32 col, line;
getCursorPosition(code, &col, &line);
code->scroll.x = col - BufferWidth(tic) / 2;
code->scroll.y = line - TextBufferHeight(tic) / 2;
code->scroll.x = col - TEXT_BUFFER_WIDTH / 2;
code->scroll.y = line - TEXT_BUFFER_HEIGHT / 2;
normalizeScroll(code);
}
@ -782,8 +772,8 @@ static void initOutlineMode(Code* code)
tic_mem* tic = code->tic;
char buffer[TIC80_WIDTH] = {0};
char filter[TIC80_WIDTH] = {0};
char buffer[STUDIO_TEXT_BUFFER_WIDTH] = {0};
char filter[STUDIO_TEXT_BUFFER_WIDTH] = {0};
strncpy(filter, code->popup.text, sizeof(filter));
ticStrlwr(filter);
@ -802,8 +792,8 @@ static void initOutlineMode(Code* code)
if(out < end)
{
out->pos = code->src + item->pos;
memset(out->name, 0, TIC80_WIDTH);
memcpy(out->name, out->pos, MIN(item->size, TIC80_WIDTH-1));
memset(out->name, 0, STUDIO_TEXT_BUFFER_WIDTH);
memcpy(out->name, out->pos, MIN(item->size, STUDIO_TEXT_BUFFER_WIDTH-1));
if(*filter)
{
@ -976,8 +966,8 @@ static void processMouse(Code* code)
{
if(checkMouseDown(&code->rect, tic_mouse_right))
{
code->scroll.x = (code->scroll.start.x - getMouseX()) / TextWidth(tic);
code->scroll.y = (code->scroll.start.y - getMouseY()) / TextHeight(tic);
code->scroll.x = (code->scroll.start.x - getMouseX()) / STUDIO_TEXT_WIDTH;
code->scroll.y = (code->scroll.start.y - getMouseY()) / STUDIO_TEXT_HEIGHT;
normalizeScroll(code);
}
@ -990,8 +980,8 @@ static void processMouse(Code* code)
s32 mx = getMouseX();
s32 my = getMouseY();
s32 x = (mx - code->rect.x) / TextWidth(tic);
s32 y = (my - code->rect.y) / TextHeight(tic);
s32 x = (mx - code->rect.x) / STUDIO_TEXT_WIDTH;
s32 y = (my - code->rect.y) / STUDIO_TEXT_HEIGHT;
char* position = code->cursor.position;
setCursorPosition(code, x + code->scroll.x, y + code->scroll.y);
@ -1019,8 +1009,8 @@ static void processMouse(Code* code)
{
code->scroll.active = true;
code->scroll.start.x = getMouseX() + code->scroll.x * TextWidth(tic);
code->scroll.start.y = getMouseY() + code->scroll.y * TextHeight(tic);
code->scroll.start.x = getMouseX() + code->scroll.x * STUDIO_TEXT_WIDTH;
code->scroll.start.y = getMouseY() + code->scroll.y * STUDIO_TEXT_HEIGHT;
}
}
@ -1068,16 +1058,14 @@ static void textEditTick(Code* code)
static void drawPopupBar(Code* code, const char* title)
{
tic_mem* tic = code->tic;
enum {TextY = TOOLBAR_SIZE + 1};
code->tic->api.rect(code->tic, 0, TOOLBAR_SIZE, TIC80_WIDTH, tic->font.height + 1, (tic_color_blue));
code->tic->api.rect(code->tic, 0, TOOLBAR_SIZE, TIC80_WIDTH, TIC_FONT_HEIGHT + 1, (tic_color_blue));
code->tic->api.fixed_text(code->tic, title, 0, TextY, (tic_color_white));
code->tic->api.fixed_text(code->tic, code->popup.text, (s32)strlen(title)*tic->font.width, TextY, (tic_color_white));
code->tic->api.fixed_text(code->tic, code->popup.text, (s32)strlen(title)*TIC_FONT_WIDTH, TextY, (tic_color_white));
drawCursor(code, (s32)(strlen(title) + strlen(code->popup.text)) * tic->font.width, TextY, ' ');
drawCursor(code, (s32)(strlen(title) + strlen(code->popup.text)) * TIC_FONT_WIDTH, TextY, ' ');
}
static void updateFindCode(Code* code, char* pos)
@ -1215,8 +1203,8 @@ static void textGoToTick(Code* code)
tic->api.clear(tic, getConfig()->theme.code.bg);
if(code->jump.line >= 0)
tic->api.rect(tic, 0, (code->jump.line - code->scroll.y) * (tic->font.height+1) + TOOLBAR_SIZE,
TIC80_WIDTH, tic->font.height+2, getConfig()->theme.code.select);
tic->api.rect(tic, 0, (code->jump.line - code->scroll.y) * (TIC_FONT_HEIGHT+1) + TOOLBAR_SIZE,
TIC80_WIDTH, TIC_FONT_HEIGHT+2, getConfig()->theme.code.select);
drawCode(code, false);
drawPopupBar(code, " GOTO:");
@ -1225,14 +1213,12 @@ static void textGoToTick(Code* code)
static void drawOutlineBar(Code* code, s32 x, s32 y)
{
tic_mem* tic = code->tic;
tic_rect rect = {x, y, TIC80_WIDTH - x, TIC80_HEIGHT - y};
if(checkMousePos(&rect))
{
s32 mx = getMouseY() - rect.y;
mx /= TextHeight(tic);
mx /= STUDIO_TEXT_HEIGHT;
if(mx < OUTLINE_SIZE && code->outline.items[mx].pos)
{
@ -1258,13 +1244,13 @@ static void drawOutlineBar(Code* code, s32 x, s32 y)
if(ptr->pos)
{
code->tic->api.rect(code->tic, rect.x - 1, rect.y + code->outline.index*TextHeight(tic),
rect.w + 1, tic->font.height + 1, (tic_color_red));
code->tic->api.rect(code->tic, rect.x - 1, rect.y + code->outline.index*STUDIO_TEXT_HEIGHT,
rect.w + 1, TIC_FONT_HEIGHT + 1, (tic_color_red));
while(ptr->pos)
{
code->tic->api.fixed_text(code->tic, ptr->name, x, y, (tic_color_white));
ptr++;
y += TextHeight(tic);
y += STUDIO_TEXT_HEIGHT;
}
}
else code->tic->api.fixed_text(code->tic, "(empty)", x, y, (tic_color_white));
@ -1272,8 +1258,6 @@ static void drawOutlineBar(Code* code, s32 x, s32 y)
static void textOutlineTick(Code* code)
{
tic_mem* tic = code->tic;
if(keyWasPressed(tic_key_up))
{
if(code->outline.index > 0)
@ -1321,7 +1305,7 @@ static void textOutlineTick(Code* code)
drawCode(code, false);
drawPopupBar(code, " FUNC:");
drawStatus(code);
drawOutlineBar(code, TIC80_WIDTH - 12 * tic->font.width, 2*(tic->font.height+1));
drawOutlineBar(code, TIC80_WIDTH - 12 * TIC_FONT_WIDTH, 2*(TIC_FONT_HEIGHT+1));
}
static void drawCodeToolbar(Code* code)
@ -1471,7 +1455,7 @@ void initCode(Code* code, tic_mem* tic, tic_code* src)
.tick = tick,
.escape = escape,
.cursor = {{src->data, NULL, 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},
.tickCounter = 0,
.history = NULL,

View File

@ -62,11 +62,7 @@ struct Code
u8 colorBuffer[TIC_CODE_SIZE];
struct
{
char left[TIC80_WIDTH];
char right[TIC80_WIDTH];
} status;
char status[STUDIO_TEXT_BUFFER_WIDTH+1];
u32 tickCounter;
@ -84,7 +80,7 @@ struct Code
struct
{
char text[TIC80_WIDTH];
char text[STUDIO_TEXT_BUFFER_WIDTH - sizeof "FIND:"];
char* prevPos;
char* prevSel;

View File

@ -206,34 +206,6 @@ static void readCodeTheme(Config* config, lua_State* lua)
lua_pop(lua, 1);
}
static void readFontTheme(Config* config, lua_State* lua)
{
lua_getfield(lua, -1, "FONT");
if(lua_type(lua, -1) == LUA_TTABLE)
{
{
lua_getfield(lua, -1, "WIDTH");
if(lua_isinteger(lua, -1))
config->data.theme.font.width = lua_tointeger(lua, -1);
lua_pop(lua, 1);
}
{
lua_getfield(lua, -1, "HEIGHT");
if(lua_isinteger(lua, -1))
config->data.theme.font.height = lua_tointeger(lua, -1);
lua_pop(lua, 1);
}
}
lua_pop(lua, 1);
}
static void readGamepadTheme(Config* config, lua_State* lua)
{
lua_getfield(lua, -1, "GAMEPAD");
@ -267,7 +239,6 @@ static void readTheme(Config* config, lua_State* lua)
readCursorTheme(config, lua);
readCodeTheme(config, lua);
readGamepadTheme(config, lua);
readFontTheme(config, lua);
}
lua_pop(lua, 1);

View File

@ -45,7 +45,10 @@
#define CONSOLE_ERROR_TEXT_COLOR ((tic_color_red))
#define CONSOLE_CURSOR_BLINK_PERIOD (TIC_FRAMERATE)
#define CONSOLE_CURSOR_DELAY (TIC_FRAMERATE / 2)
#define CONSOLE_BUFFER_WIDTH (STUDIO_TEXT_BUFFER_WIDTH)
#define CONSOLE_BUFFER_HEIGHT (STUDIO_TEXT_BUFFER_HEIGHT)
#define CONSOLE_BUFFER_SCREENS 64
#define CONSOLE_BUFFER_SIZE (CONSOLE_BUFFER_WIDTH * CONSOLE_BUFFER_HEIGHT * CONSOLE_BUFFER_SCREENS)
typedef enum
{
@ -115,10 +118,6 @@ static const char DefaultJSTicPath[] = TIC_LOCAL "default_js.tic";
static const char DefaultWrenTicPath[] = TIC_LOCAL "default_wren.tic";
#endif
static inline s32 BufferSize(const tic_mem* tic)
{
return BufferWidth(tic) * BufferHeight(tic) * CONSOLE_BUFFER_SCREENS;
}
static const char* getName(const char* name, const char* ext)
{
@ -140,33 +139,29 @@ static const char* getCartName(const char* name)
return getName(name, CART_EXT);
}
static void scrollBuffer(tic_mem* tic, char* buffer)
static void scrollBuffer(char* buffer)
{
memmove(buffer, buffer + BufferWidth(tic), BufferSize(tic) - BufferWidth(tic));
memset(buffer + BufferSize(tic) - BufferWidth(tic), 0, BufferWidth(tic));
memmove(buffer, buffer + CONSOLE_BUFFER_WIDTH, CONSOLE_BUFFER_SIZE - CONSOLE_BUFFER_WIDTH);
memset(buffer + CONSOLE_BUFFER_SIZE - CONSOLE_BUFFER_WIDTH, 0, CONSOLE_BUFFER_WIDTH);
}
static void scrollConsole(Console* console)
{
tic_mem* tic = console->tic;
while(console->cursor.y >= BufferHeight(tic) * CONSOLE_BUFFER_SCREENS)
while(console->cursor.y >= CONSOLE_BUFFER_HEIGHT * CONSOLE_BUFFER_SCREENS)
{
scrollBuffer(tic, console->buffer);
scrollBuffer(tic, (char*)console->colorBuffer);
scrollBuffer(console->buffer);
scrollBuffer((char*)console->colorBuffer);
console->cursor.y--;
}
s32 minScroll = console->cursor.y - BufferHeight(tic) + 1;
s32 minScroll = console->cursor.y - CONSOLE_BUFFER_HEIGHT + 1;
if(console->scroll.pos < minScroll)
console->scroll.pos = minScroll;
}
static void consolePrint(Console* console, const char* text, u8 color)
{
tic_mem* tic = console->tic;
printf("%s", text);
const char* textPointer = text;
@ -185,13 +180,13 @@ static void consolePrint(Console* console, const char* text, u8 color)
}
else
{
s32 offset = console->cursor.x + console->cursor.y * BufferWidth(tic);
s32 offset = console->cursor.x + console->cursor.y * CONSOLE_BUFFER_WIDTH;
*(console->buffer + offset) = symbol;
*(console->colorBuffer + offset) = color;
console->cursor.x++;
if(console->cursor.x >= BufferWidth(tic))
if(console->cursor.x >= CONSOLE_BUFFER_WIDTH)
{
console->cursor.x = 0;
console->cursor.y++;
@ -241,22 +236,20 @@ static void commandDone(Console* console)
static void drawCursor(Console* console, s32 x, s32 y, u8 symbol)
{
tic_mem* tic = console->tic;
bool inverse = console->cursor.delay || console->tickCounter % CONSOLE_CURSOR_BLINK_PERIOD < CONSOLE_CURSOR_BLINK_PERIOD / 2;
if(inverse)
console->tic->api.rect(console->tic, x-1, y-1, tic->font.width+1, tic->font.height+1, CONSOLE_CURSOR_COLOR);
console->tic->api.rect(console->tic, x-1, y-1, TIC_FONT_WIDTH+1, TIC_FONT_HEIGHT+1, CONSOLE_CURSOR_COLOR);
console->tic->api.draw_char(console->tic, symbol, x, y, inverse ? TIC_COLOR_BG : CONSOLE_FRONT_TEXT_COLOR);
}
static void drawConsoleText(Console* console)
{
tic_mem* tic = console->tic;
char* pointer = console->buffer + console->scroll.pos * BufferWidth(tic);
u8* colorPointer = console->colorBuffer + console->scroll.pos * BufferWidth(tic);
char* pointer = console->buffer + console->scroll.pos * CONSOLE_BUFFER_WIDTH;
u8* colorPointer = console->colorBuffer + console->scroll.pos * CONSOLE_BUFFER_WIDTH;
const char* end = console->buffer + BufferSize(tic);
const char* end = console->buffer + CONSOLE_BUFFER_SIZE;
s32 x = 0;
s32 y = 0;
@ -266,9 +259,9 @@ static void drawConsoleText(Console* console)
u8 color = *colorPointer++;
if(symbol)
console->tic->api.draw_char(console->tic, symbol, x * TextWidth(tic), y * TextHeight(tic), color);
console->tic->api.draw_char(console->tic, symbol, x * STUDIO_TEXT_WIDTH, y * STUDIO_TEXT_HEIGHT, color);
if(++x == BufferWidth(tic))
if(++x == CONSOLE_BUFFER_WIDTH)
{
y++;
x = 0;
@ -278,9 +271,8 @@ static void drawConsoleText(Console* console)
static void drawConsoleInputText(Console* console)
{
tic_mem* tic = console->tic;
s32 x = console->cursor.x * TextWidth(tic);
s32 y = (console->cursor.y - console->scroll.pos) * TextHeight(tic);
s32 x = console->cursor.x * STUDIO_TEXT_WIDTH;
s32 y = (console->cursor.y - console->scroll.pos) * STUDIO_TEXT_HEIGHT;
const char* pointer = console->inputBuffer;
const char* end = pointer + strlen(console->inputBuffer);
@ -297,10 +289,10 @@ static void drawConsoleInputText(Console* console)
index++;
x += TextWidth(tic);
if(x == (BufferWidth(tic) * TextWidth(tic)))
x += STUDIO_TEXT_WIDTH;
if(x == (CONSOLE_BUFFER_WIDTH * STUDIO_TEXT_WIDTH))
{
y += TextHeight(tic);
y += STUDIO_TEXT_HEIGHT;
x = 0;
}
@ -1382,9 +1374,8 @@ static void onConsoleFolderCommand(Console* console, const char* param)
static void onConsoleClsCommand(Console* console, const char* param)
{
tic_mem* tic = console->tic;
memset(console->buffer, 0, BufferSize(tic));
memset(console->colorBuffer, TIC_COLOR_BG, BufferSize(tic));
memset(console->buffer, 0, CONSOLE_BUFFER_SIZE);
memset(console->colorBuffer, TIC_COLOR_BG, CONSOLE_BUFFER_SIZE);
console->scroll.pos = 0;
console->cursor.x = console->cursor.y = 0;
@ -2325,8 +2316,6 @@ static void onConsoleDelCommand(Console* console, const char* param)
static void printTable(Console* console, const char* text)
{
tic_mem* tic = console->tic;
printf("%s", text);
const char* textPointer = text;
@ -2345,7 +2334,7 @@ static void printTable(Console* console, const char* text)
}
else
{
s32 offset = console->cursor.x + console->cursor.y * BufferWidth(tic);
s32 offset = console->cursor.x + console->cursor.y * CONSOLE_BUFFER_WIDTH;
*(console->buffer + offset) = symbol;
u8 color = 0;
@ -2365,7 +2354,7 @@ static void printTable(Console* console, const char* text)
console->cursor.x++;
if(console->cursor.x >= BufferWidth(tic))
if(console->cursor.x >= CONSOLE_BUFFER_WIDTH)
{
console->cursor.x = 0;
console->cursor.y++;
@ -2377,7 +2366,7 @@ static void printTable(Console* console, const char* text)
static void printRamInfo(Console* console, s32 addr, const char* name, s32 size)
{
char buf[TIC80_WIDTH];
char buf[STUDIO_TEXT_BUFFER_WIDTH];
sprintf(buf, "\n| %05X | %-17s | %-5i |", addr, name, size);
printTable(console, buf);
}
@ -3129,8 +3118,8 @@ static bool checkUIScale(Console* console, const char* param, const char* value)
void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, s32 argc, char **argv)
{
if(!console->buffer) console->buffer = malloc(BufferSize(tic));
if(!console->colorBuffer) console->colorBuffer = malloc(BufferSize(tic));
if(!console->buffer) console->buffer = malloc(CONSOLE_BUFFER_SIZE);
if(!console->colorBuffer) console->colorBuffer = malloc(CONSOLE_BUFFER_SIZE);
if(!console->embed.file) console->embed.file = malloc(sizeof(tic_cartridge));
*console = (Console)
@ -3182,8 +3171,8 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
.crtMonitor = false,
};
memset(console->buffer, 0, BufferSize(tic));
memset(console->colorBuffer, TIC_COLOR_BG, BufferSize(tic));
memset(console->buffer, 0, CONSOLE_BUFFER_SIZE);
memset(console->colorBuffer, TIC_COLOR_BG, CONSOLE_BUFFER_SIZE);
memset(console->codeLiveReload.fileName, 0, FILENAME_MAX);

View File

@ -78,7 +78,7 @@ struct Console
char* buffer;
u8* colorBuffer;
char inputBuffer[TIC80_WIDTH];
char inputBuffer[STUDIO_TEXT_BUFFER_WIDTH * STUDIO_TEXT_BUFFER_HEIGHT];
size_t inputPosition;
tic_mem* tic;

View File

@ -57,7 +57,7 @@ static void drawButton(Dialog* dlg, const char* label, s32 x, s32 y, u8 color, u
tic->api.rect(tic, rect.x, rect.y, rect.w, rect.h, (tic_color_white));
}
s32 size = tic->api.text(tic, label, 0, -tic->font.height, 0);
s32 size = tic->api.text(tic, label, 0, -TIC_FONT_HEIGHT, 0);
tic->api.text(tic, label, rect.x + (BtnWidth - size+1)/2, rect.y + (down?3:2), over ? overColor : color);
if(dlg->focus == id)
@ -162,7 +162,7 @@ static void drawDialog(Dialog* dlg)
{
static const char Label[] = "WARNING!";
s32 size = tic->api.text(tic, Label, 0, -tic->font.height, 0);
s32 size = tic->api.text(tic, Label, 0, -TIC_FONT_HEIGHT, 0);
tic->api.text(tic, Label, rect.x + (Width - size)/2, rect.y-(TOOLBAR_SIZE-2), (tic_color_gray));
}
@ -174,10 +174,10 @@ static void drawDialog(Dialog* dlg)
{
for(s32 i = 0; i < dlg->rows; i++)
{
s32 size = tic->api.text(tic, dlg->text[i], 0, -tic->font.height, 0);
s32 size = tic->api.text(tic, dlg->text[i], 0, -TIC_FONT_HEIGHT, 0);
s32 x = rect.x + (Width - size)/2;
s32 y = rect.y + (tic->font.height+1)*(i+1);
s32 y = rect.y + (TIC_FONT_HEIGHT+1)*(i+1);
tic->api.text(tic, dlg->text[i], x, y+1, (tic_color_black));
tic->api.text(tic, dlg->text[i], x, y, (tic_color_white));
}

View File

@ -334,11 +334,9 @@ static void drawTileIndex(Map* map, s32 x, s32 y)
static void drawMapToolbar(Map* map, s32 x, s32 y)
{
tic_mem* tic = map->tic;
map->tic->api.rect(map->tic, 0, 0, TIC80_WIDTH, TOOLBAR_SIZE, (tic_color_white));
drawTileIndex(map, TIC80_WIDTH/2 - tic->font.width, y);
drawTileIndex(map, TIC80_WIDTH/2 - TIC_FONT_WIDTH, y);
x = drawSheetButton(map, TIC80_WIDTH, 0);
x = drawFillButton(map, x, 0);
@ -419,8 +417,6 @@ static void drawSheetOvr(Map* map, s32 x, s32 y)
static void drawCursorPos(Map* map, s32 x, s32 y)
{
tic_mem* tic = map->tic;
char pos[] = "999:999";
s32 tx = 0, ty = 0;
@ -433,10 +429,10 @@ static void drawCursorPos(Map* map, s32 x, s32 y)
s32 px = x + (TIC_SPRITESIZE + 3);
if(px + width >= TIC80_WIDTH) px = x - (width + 2);
s32 py = y - (tic->font.height + 2);
s32 py = y - (TIC_FONT_HEIGHT + 2);
if(py <= TOOLBAR_SIZE) py = y + (TIC_SPRITESIZE + 3);
map->tic->api.rect(map->tic, px - 1, py - 1, width + 1, tic->font.height + 1, (tic_color_white));
map->tic->api.rect(map->tic, px - 1, py - 1, width + 1, TIC_FONT_HEIGHT + 1, (tic_color_white));
map->tic->api.text(map->tic, pos, px, py, (tic_color_light_blue));
}
@ -1064,14 +1060,13 @@ static void processKeyboard(Map* map)
static void tick(Map* map)
{
tic_mem* tic = map->tic;
map->tickCounter++;
processKeyboard(map);
map->tic->api.clear(map->tic, TIC_COLOR_BG);
drawSheet(map, TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE);
drawMapToolbar(map, TIC80_WIDTH - 9*tic->font.width, 1);
drawMapToolbar(map, TIC80_WIDTH - 9*TIC_FONT_WIDTH, 1);
drawToolbar(map->tic, TIC_COLOR_BG, false);
}

View File

@ -119,7 +119,7 @@ static void drawDialog(Menu* menu)
{
static const char Label[] = "GAME MENU";
s32 size = tic->api.text(tic, Label, 0, -tic->font.height, 0);
s32 size = tic->api.text(tic, Label, 0, -TIC_FONT_HEIGHT, 0);
tic->api.text(tic, Label, rect.x + (DIALOG_WIDTH - size)/2, rect.y-(TOOLBAR_SIZE-2), (tic_color_gray));
}
@ -253,7 +253,7 @@ static void drawGamepadMenu(Menu* menu)
static const char Label[] = "BACK";
tic_rect rect = {dlgRect.x + 25, dlgRect.y + 56, (sizeof(Label)-1)*tic->font.width, tic->font.height};
tic_rect rect = {dlgRect.x + 25, dlgRect.y + 56, (sizeof(Label)-1)*TIC_FONT_WIDTH, TIC_FONT_HEIGHT};
bool over = false;
bool down = false;
@ -321,7 +321,7 @@ static void drawMainMenu(Menu* menu)
{
if(!*Rows[i])continue;
tic_rect label = {rect.x + 22, rect.y + (tic->font.height+1)*i + 16, 86, tic->font.height+1};
tic_rect label = {rect.x + 22, rect.y + (TIC_FONT_HEIGHT+1)*i + 16, 86, TIC_FONT_HEIGHT+1};
bool over = false;
bool down = false;

View File

@ -66,7 +66,6 @@ static void drawDownBorder(Music* music, s32 x, s32 y, s32 w, s32 h)
static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*, s32, s32 channel), s32 channel)
{
tic_mem* tic = music->tic;
static const u8 LeftArrow[] =
{
0b00100000,
@ -91,12 +90,8 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
0b00000000,
};
enum{ArrowWidth = 4, ArrowHeight = 6};
x -= ArrowWidth + 2;
{
tic_rect rect = { x, y, ArrowWidth, ArrowHeight };
tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT };
bool over = false;
bool down = false;
@ -116,9 +111,9 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
}
{
x += ArrowWidth + 2;
x += TIC_FONT_WIDTH;
tic_rect rect = { x-1, y-1, tic->font.width*2+1, tic->font.height+1 };
tic_rect rect = { x-1, y-1, TIC_FONT_WIDTH*2+1, TIC_FONT_HEIGHT+1 };
if (checkMousePos(&rect))
{
@ -130,7 +125,7 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
music->tracker.col = channel * CHANNEL_COLS;
s32 mx = getMouseX() - rect.x;
music->tracker.patternCol = mx / tic->font.width;
music->tracker.patternCol = mx / TIC_FONT_WIDTH;
}
}
@ -139,7 +134,7 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
if(music->tracker.row == -1 && music->tracker.col / CHANNEL_COLS == channel)
{
music->tic->api.rect(music->tic, x - 1 + music->tracker.patternCol * tic->font.width, y - 1, tic->font.width + 1, tic->font.height + 1, (tic_color_red));
music->tic->api.rect(music->tic, x - 1 + music->tracker.patternCol * TIC_FONT_WIDTH, y - 1, TIC_FONT_WIDTH + 1, TIC_FONT_HEIGHT + 1, (tic_color_red));
}
char val[] = "99";
@ -148,9 +143,9 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
}
{
x += 2*tic->font.width;
x += 2*TIC_FONT_WIDTH;
tic_rect rect = { x, y, ArrowWidth, ArrowHeight };
tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT };
bool over = false;
bool down = false;
@ -172,14 +167,13 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value, void(*set)(Music*, s32, void* data), void* data)
{
tic_mem* tic = music->tic;
static const u8 LeftArrow[] =
{
0b00100000,
0b01100000,
0b11100000,
0b01100000,
0b00100000,
0b00010000,
0b00110000,
0b01110000,
0b00110000,
0b00010000,
0b00000000,
0b00000000,
0b00000000,
@ -187,25 +181,23 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value,
static const u8 RightArrow[] =
{
0b10000000,
0b11000000,
0b11100000,
0b11000000,
0b10000000,
0b01000000,
0b01100000,
0b01110000,
0b01100000,
0b01000000,
0b00000000,
0b00000000,
0b00000000,
};
enum{ArrowWidth = 4, ArrowHeight = 6};
music->tic->api.text(music->tic, label, x, y+1, (tic_color_black));
music->tic->api.text(music->tic, label, x, y, (tic_color_white));
{
x += (s32)strlen(label)*tic->font.width + 1;
x += (s32)strlen(label)*TIC_FONT_WIDTH;
tic_rect rect = { x, y, ArrowWidth, ArrowHeight};
tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT };
bool over = false;
bool down = false;
@ -226,17 +218,16 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value,
}
{
x += ArrowWidth;
char val[] = "999";
sprintf(val, "%02i", value);
music->tic->api.fixed_text(music->tic, val, x, y+1, (tic_color_black));
music->tic->api.fixed_text(music->tic, val, x, y, (tic_color_white));
music->tic->api.fixed_text(music->tic, val, x + TIC_FONT_WIDTH, y+1, (tic_color_black));
music->tic->api.fixed_text(music->tic, val, x += TIC_FONT_WIDTH, y, (tic_color_white));
}
{
x += (value > 99 ? 3 : 2)*tic->font.width;
x += (value > 99 ? 3 : 2)*TIC_FONT_WIDTH;
tic_rect rect = { x, y, ArrowWidth, ArrowHeight};
tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT };
bool over = false;
bool down = false;
@ -1114,28 +1105,24 @@ static void setRows(Music* music, s32 delta, void* data)
static void drawTopPanel(Music* music, s32 x, s32 y)
{
tic_mem* tic = music->tic;
tic_track* track = getTrack(music);
drawSwitch(music, x, y, "TRACK", music->track, setIndex, NULL);
drawSwitch(music, x += tic->font.width * 10, y, "TEMPO", track->tempo + DEFAULT_TEMPO, setTempo, NULL);
drawSwitch(music, x += tic->font.width * 11, y, "SPD", track->speed + DEFAULT_SPEED, setSpeed, NULL);
drawSwitch(music, x += tic->font.width * 8, y, "ROWS", MUSIC_PATTERN_ROWS - track->rows, setRows, NULL);
drawSwitch(music, x += TIC_FONT_WIDTH * 10, y, "TEMPO", track->tempo + DEFAULT_TEMPO, setTempo, NULL);
drawSwitch(music, x += TIC_FONT_WIDTH * 11, y, "SPD", track->speed + DEFAULT_SPEED, setSpeed, NULL);
drawSwitch(music, x += TIC_FONT_WIDTH * 8, y, "ROWS", MUSIC_PATTERN_ROWS - track->rows, setRows, NULL);
}
static void drawTrackerFrames(Music* music, s32 x, s32 y)
{
tic_mem* tic = music->tic;
enum
{
Border = 1,
Width = TIC_FONT_WIDTH * 2 + Border,
};
s32 width = tic->font.width * 2 + Border;
{
tic_rect rect = { x - Border, y - Border, width, MUSIC_FRAMES * tic->font.height + Border };
tic_rect rect = { x - Border, y - Border, Width, MUSIC_FRAMES * TIC_FONT_HEIGHT + Border };
if (checkMousePos(&rect))
{
@ -1144,7 +1131,7 @@ static void drawTrackerFrames(Music* music, s32 x, s32 y)
if (checkMouseDown(&rect, tic_mouse_left))
{
s32 my = getMouseY() - rect.y - Border;
music->tracker.frame = my / tic->font.height;
music->tracker.frame = my / TIC_FONT_HEIGHT;
}
}
@ -1168,18 +1155,18 @@ static void drawTrackerFrames(Music* music, s32 x, s32 y)
0b00000000,
};
drawBitIcon(x - 7, y + i*tic->font.height, Icon, tic_color_black);
drawBitIcon(x - 7, y - 1 + i*tic->font.height, Icon, tic_color_white);
drawBitIcon(x - TIC_FONT_WIDTH-1, y + i*TIC_FONT_HEIGHT, Icon, tic_color_black);
drawBitIcon(x - TIC_FONT_WIDTH-1, y - 1 + i*TIC_FONT_HEIGHT, Icon, tic_color_white);
}
if (i == music->tracker.frame)
{
music->tic->api.rect(music->tic, x - 1, y - 1 + i*tic->font.height, width, tic->font.height + 1, (tic_color_white));
music->tic->api.rect(music->tic, x - 1, y - 1 + i*TIC_FONT_HEIGHT, Width, TIC_FONT_HEIGHT + 1, (tic_color_white));
}
char buf[] = "99";
sprintf(buf, "%02i", i);
music->tic->api.fixed_text(music->tic, buf, x, y + i*tic->font.height, (tic_color_dark_gray));
music->tic->api.fixed_text(music->tic, buf, x, y + i*TIC_FONT_HEIGHT, (tic_color_dark_gray));
}
if(music->tracker.row >= 0)
@ -1214,11 +1201,10 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
{
Border = 1,
Rows = TRACKER_ROWS,
Width = TIC_FONT_WIDTH * 8 + Border,
};
s32 width = tic->font.width * 8 + Border;
tic_rect rect = {x - Border, y - Border, width, Rows*tic->font.height + Border};
tic_rect rect = {x - Border, y - Border, Width, Rows*TIC_FONT_HEIGHT + Border};
if(checkMousePos(&rect))
{
@ -1229,8 +1215,8 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
s32 mx = getMouseX() - rect.x - Border;
s32 my = getMouseY() - rect.y - Border;
s32 col = music->tracker.col = channel * CHANNEL_COLS + mx / tic->font.width;
s32 row = music->tracker.row = my / tic->font.height + music->tracker.scroll;
s32 col = music->tracker.col = channel * CHANNEL_COLS + mx / TIC_FONT_WIDTH;
s32 row = music->tracker.row = my / TIC_FONT_HEIGHT + music->tracker.scroll;
if(music->tracker.select.drag)
{
@ -1266,11 +1252,11 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
for (s32 i = start, pos = 0; i < end; i++, pos++)
{
s32 rowy = y + pos*tic->font.height;
s32 rowy = y + pos*TIC_FONT_HEIGHT;
if (i == music->tracker.row)
{
music->tic->api.rect(music->tic, x - 1, rowy - 1, width, tic->font.height + 1, (tic_color_dark_red));
music->tic->api.rect(music->tic, x - 1, rowy - 1, Width, TIC_FONT_HEIGHT + 1, (tic_color_dark_red));
}
// draw selection
@ -1280,13 +1266,13 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
if (rect.h > 1 && i >= rect.y && i < rect.y + rect.h)
{
s32 sx = x - 1;
tic->api.rect(tic, sx, rowy - 1, CHANNEL_COLS * tic->font.width + 1, tic->font.height + 1, (tic_color_yellow));
tic->api.rect(tic, sx, rowy - 1, CHANNEL_COLS * TIC_FONT_WIDTH + 1, TIC_FONT_HEIGHT + 1, (tic_color_yellow));
}
}
if (checkPlayRow(music, i))
{
music->tic->api.rect(music->tic, x - 1, rowy - 1, width, tic->font.height + 1, (tic_color_white));
music->tic->api.rect(music->tic, x - 1, rowy - 1, Width, TIC_FONT_HEIGHT + 1, (tic_color_white));
}
char rowStr[] = "--------";
@ -1315,7 +1301,7 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
bool beetRow = i % NOTES_PER_BEET == 0;
for (s32 c = 0, colx = x; c < sizeof rowStr - 1; c++, colx += tic->font.width)
for (s32 c = 0, colx = x; c < sizeof rowStr - 1; c++, colx += TIC_FONT_WIDTH)
{
char sym = rowStr[c];
const u8* colors = beetRow || sym != '-' ? Colors : DarkColors;
@ -1331,14 +1317,14 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
if (music->tracker.col / CHANNEL_COLS == channel)
{
s32 col = music->tracker.col % CHANNEL_COLS;
s32 colx = x - 1 + col * tic->font.width;
music->tic->api.rect(music->tic, colx, rowy - 1, tic->font.width + 1, tic->font.height + 1, (tic_color_red));
s32 colx = x - 1 + col * TIC_FONT_WIDTH;
music->tic->api.rect(music->tic, colx, rowy - 1, TIC_FONT_WIDTH + 1, TIC_FONT_HEIGHT + 1, (tic_color_red));
music->tic->api.draw_char(music->tic, rowStr[col], colx + 1, rowy, (tic_color_black));
}
}
if (i % NOTES_PER_BEET == 0)
music->tic->api.pixel(music->tic, x - 4, y + pos*tic->font.height + 2, (tic_color_black));
music->tic->api.pixel(music->tic, x - 4, y + pos*TIC_FONT_HEIGHT + 2, (tic_color_black));
}
}
@ -1358,12 +1344,12 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index)
if(checkMouseClick(&rect, tic_mouse_left))
{
if (tic->api.key(tic, tic_key_ctrl))
{
for (s32 i = 0; i < TIC_SOUND_CHANNELS; i++)
music->tracker.patterns[i] = i == index;
}
else music->tracker.patterns[index] = !music->tracker.patterns[index];
// if (SDL_GetModState() & KMOD_CTRL)
// {
// for (s32 i = 0; i < TIC_SOUND_CHANNELS; i++)
// music->tracker.patterns[i] = i == index;
// }
// else music->tracker.patterns[index] = !music->tracker.patterns[index];
}
}
@ -1373,25 +1359,21 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index)
static void drawTracker(Music* music, s32 x, s32 y)
{
tic_mem* tic = music->tic;
drawTrackerFrames(music, x, y);
enum{Gap = 6, Cols = 8};
x += TIC_FONT_WIDTH * 3;
x += tic->font.width * 2 + Gap;
s32 channelWidth = tic->font.width * Cols + Gap;
enum{ChannelWidth = TIC_FONT_WIDTH * 9};
for (s32 i = 0; i < TIC_SOUND_CHANNELS; i++)
{
s32 patternId = tic_tool_get_pattern_id(getTrack(music), music->tracker.frame, i);
drawEditbox(music, x + channelWidth * i + 3*tic->font.width, y - 11, patternId, setChannelPattern, i);
drawTumbler(music, x + channelWidth * (i+1) - 4 - Gap, y - 11, i);
drawEditbox(music, x + ChannelWidth * i + 2*TIC_FONT_WIDTH, y - 11, patternId, setChannelPattern, i);
drawTumbler(music, x + ChannelWidth * i + 7*TIC_FONT_WIDTH, y - 11, i);
}
for (s32 i = 0; i < TIC_SOUND_CHANNELS; i++)
drawTrackerChannel(music, x + channelWidth * i, y, i);
drawTrackerChannel(music, x + ChannelWidth * i, y, i);
}
static void enableFollowMode(Music* music)
@ -1535,11 +1517,10 @@ static void drawMusicToolbar(Music* music)
static void drawPianoLayout(Music* music)
{
tic_mem* tic = music->tic;
music->tic->api.clear(music->tic, (tic_color_gray));
static const char Wip[] = "PIANO MODE - WORK IN PROGRESS...";
music->tic->api.fixed_text(music->tic, Wip, (TIC80_WIDTH - (sizeof Wip - 1) * tic->font.width) / 2, TIC80_HEIGHT / 2, (tic_color_white));
music->tic->api.fixed_text(music->tic, Wip, (TIC80_WIDTH - (sizeof Wip - 1) * TIC_FONT_WIDTH) / 2, TIC80_HEIGHT / 2, (tic_color_white));
}
static void scrollNotes(Music* music, s32 delta)

View File

@ -39,15 +39,13 @@
static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, void(*set)(Sfx*, s32))
{
tic_mem* tic = sfx->tic;
static const u8 LeftArrow[] =
{
0b00100000,
0b01100000,
0b11100000,
0b01100000,
0b00100000,
0b00010000,
0b00110000,
0b01110000,
0b00110000,
0b00010000,
0b00000000,
0b00000000,
0b00000000,
@ -55,24 +53,22 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi
static const u8 RightArrow[] =
{
0b10000000,
0b11000000,
0b11100000,
0b11000000,
0b10000000,
0b01000000,
0b01100000,
0b01110000,
0b01100000,
0b01000000,
0b00000000,
0b00000000,
0b00000000,
};
enum{ArrowWidth = 4, ArrowHeight = 6};
sfx->tic->api.text(sfx->tic, label, x, y, (tic_color_white));
{
x += (s32)strlen(label)*tic->font.width;
x += (s32)strlen(label)*TIC_FONT_WIDTH;
tic_rect rect = {x, y, ArrowWidth, ArrowHeight};
tic_rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT};
if(checkMousePos(&rect))
{
@ -88,13 +84,13 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi
{
char val[] = "99";
sprintf(val, "%02i", value);
sfx->tic->api.fixed_text(sfx->tic, val, x += ArrowWidth, y, (tic_color_white));
sfx->tic->api.fixed_text(sfx->tic, val, x += TIC_FONT_WIDTH, y, (tic_color_white));
}
{
x += 2*tic->font.width;
x += 2*TIC_FONT_WIDTH;
tic_rect rect = {x, y, ArrowWidth, ArrowHeight};
tic_rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT};
if(checkMousePos(&rect))
{
@ -129,8 +125,7 @@ static void setSpeed(Sfx* sfx, s32 delta)
static void drawTopPanel(Sfx* sfx, s32 x, s32 y)
{
tic_mem* tic = sfx->tic;
const s32 Gap = 8*tic->font.width;
const s32 Gap = 8*TIC_FONT_WIDTH;
drawSwitch(sfx, x, y, "IDX", sfx->index, setIndex);
@ -161,7 +156,6 @@ static void setLoopSize(Sfx* sfx, s32 delta)
static void drawLoopPanel(Sfx* sfx, s32 x, s32 y)
{
tic_mem* tic = sfx->tic;
sfx->tic->api.text(sfx->tic, "LOOP:", x, y, (tic_color_dark_gray));
enum {Gap = 2};
@ -169,8 +163,8 @@ static void drawLoopPanel(Sfx* sfx, s32 x, s32 y)
tic_sample* effect = getEffect(sfx);
tic_sound_loop* loop = effect->loops + sfx->canvasTab;
drawSwitch(sfx, x, y += Gap + tic->font.height, "", loop->size, setLoopSize);
drawSwitch(sfx, x, y += Gap + tic->font.height, "", loop->start, setLoopStart);
drawSwitch(sfx, x, y += Gap + TIC_FONT_HEIGHT, "", loop->size, setLoopSize);
drawSwitch(sfx, x, y += Gap + TIC_FONT_HEIGHT, "", loop->start, setLoopStart);
}
static tic_waveform* getWaveformById(Sfx* sfx, s32 i)
@ -293,16 +287,15 @@ static void drawWaveButtons(Sfx* sfx, s32 x, s32 y)
static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y)
{
tic_mem* tic = sfx->tic;
static const char* Labels[] = {"WAVE", "VOLUME", "ARPEGG", "PITCH"};
s32 height = tic->font.height+2;
enum {Height = TIC_FONT_HEIGHT+2};
for(s32 i = 0, sy = y; i < COUNT_OF(Labels); sy += height, i++)
for(s32 i = 0, sy = y; i < COUNT_OF(Labels); sy += Height, i++)
{
s32 size = sfx->tic->api.text(sfx->tic, Labels[i], 0, -tic->font.height, (tic_color_black));
s32 size = sfx->tic->api.text(sfx->tic, Labels[i], 0, -TIC_FONT_HEIGHT, (tic_color_black));
tic_rect rect = {x - size, sy, size, tic->font.height};
tic_rect rect = {x - size, sy, size, TIC_FONT_HEIGHT};
if(checkMousePos(&rect))
{
@ -324,8 +317,8 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y)
case SFX_PITCH_TAB:
{
static const char Label[] = "x16";
s32 width = (sizeof Label - 1) * tic->font.width;
tic_rect rect = {(x - width)/2, y + height * 6, width, tic->font.height};
enum{Width = (sizeof Label - 1) * TIC_FONT_WIDTH};
tic_rect rect = {(x - Width)/2, y + Height * 6, Width, TIC_FONT_HEIGHT};
if(checkMousePos(&rect))
{
@ -341,8 +334,8 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y)
case SFX_ARPEGGIO_TAB:
{
static const char Label[] = "DOWN";
s32 width = (sizeof Label - 1) * tic->font.width;
tic_rect rect = {(x - width)/2, y + height * 6, width, tic->font.height};
enum{Width = (sizeof Label - 1) * TIC_FONT_WIDTH};
tic_rect rect = {(x - Width)/2, y + Height * 6, Width, TIC_FONT_HEIGHT};
if(checkMousePos(&rect))
{
@ -521,19 +514,18 @@ static void drawPiano(Sfx* sfx, s32 x, s32 y)
static void drawOctavePanel(Sfx* sfx, s32 x, s32 y)
{
tic_mem* tic = sfx->tic;
tic_sample* effect = getEffect(sfx);
static const char Label[] = "OCT";
sfx->tic->api.text(sfx->tic, Label, x, y, (tic_color_white));
x += sizeof(Label)*tic->font.width;
x += sizeof(Label)*TIC_FONT_WIDTH;
enum {Gap = 5};
for(s32 i = 0; i < OCTAVES; i++)
{
tic_rect rect = {x + i * (tic->font.width + Gap), y, tic->font.width, tic->font.height};
tic_rect rect = {x + i * (TIC_FONT_WIDTH + Gap), y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT};
if(checkMousePos(&rect))
{
@ -789,14 +781,13 @@ static void drawModeTabs(Sfx* sfx)
static void drawSfxToolbar(Sfx* sfx)
{
tic_mem* tic = sfx->tic;
sfx->tic->api.rect(sfx->tic, 0, 0, TIC80_WIDTH, TOOLBAR_SIZE, (tic_color_white));
s32 width = 3 * tic->font.width;
s32 x = TIC80_WIDTH - width - TIC_SPRITESIZE*3;
enum{Width = 3 * TIC_FONT_WIDTH};
s32 x = TIC80_WIDTH - Width - TIC_SPRITESIZE*3;
s32 y = 1;
tic_rect rect = {x, y, width, tic->font.height};
tic_rect rect = {x, y, Width, TIC_FONT_HEIGHT};
bool over = false;
if(checkMousePos(&rect))
@ -827,7 +818,6 @@ static void drawSfxToolbar(Sfx* sfx)
static void envelopesTick(Sfx* sfx)
{
tic_mem* tic = sfx->tic;
processKeyboard(sfx);
processEnvelopesKeyboard(sfx);
@ -840,13 +830,13 @@ static void envelopesTick(Sfx* sfx)
drawToolbar(sfx->tic, TIC_COLOR_BG, false);
drawTopPanel(sfx, Start, TOOLBAR_SIZE + Gap);
drawCanvasTabs(sfx, Start-Gap, TOOLBAR_SIZE + Gap + tic->font.height+2);
drawCanvasTabs(sfx, Start-Gap, TOOLBAR_SIZE + Gap + TIC_FONT_HEIGHT+2);
if(sfx->canvasTab == SFX_WAVE_TAB)
drawWaveButtons(sfx, Start + CANVAS_WIDTH + Gap-1, TOOLBAR_SIZE + Gap + tic->font.height+2);
drawWaveButtons(sfx, Start + CANVAS_WIDTH + Gap-1, TOOLBAR_SIZE + Gap + TIC_FONT_HEIGHT+2);
drawLoopPanel(sfx, Gap, TOOLBAR_SIZE + Gap + tic->font.height+92);
drawCanvas(sfx, Start-1, TOOLBAR_SIZE + Gap + tic->font.height + 1);
drawOctavePanel(sfx, Start + Gap + PIANO_WIDTH + Gap-1, TIC80_HEIGHT - tic->font.height - (PIANO_HEIGHT - tic->font.height)/2 - Gap);
drawLoopPanel(sfx, Gap, TOOLBAR_SIZE + Gap + TIC_FONT_HEIGHT+92);
drawCanvas(sfx, Start-1, TOOLBAR_SIZE + Gap + TIC_FONT_HEIGHT + 1);
drawOctavePanel(sfx, Start + Gap + PIANO_WIDTH + Gap-1, TIC80_HEIGHT - TIC_FONT_HEIGHT - (PIANO_HEIGHT - TIC_FONT_HEIGHT)/2 - Gap);
}
static void drawWaveformBar(Sfx* sfx, s32 x, s32 y)

View File

@ -359,14 +359,12 @@ static void drawBrushSlider(Sprite* sprite, s32 x, s32 y)
static void drawCanvas(Sprite* sprite, s32 x, s32 y)
{
tic_mem* tic = sprite->tic;
if(!hasCanvasSelection(sprite))
{
char buf[] = "#255";
sprintf(buf, "#%03i", sprite->index);
s32 ix = x + (CANVAS_SIZE - 4*tic->font.width)/2;
s32 ix = x + (CANVAS_SIZE - 4*TIC_FONT_WIDTH)/2;
s32 iy = TIC_SPRITESIZE + 2;
sprite->tic->api.text(sprite->tic, buf, ix, iy+1, (tic_color_black));
sprite->tic->api.text(sprite->tic, buf, ix, iy, (tic_color_white));
@ -1494,7 +1492,6 @@ static void processKeyboard(Sprite* sprite)
static void drawSpriteToolbar(Sprite* sprite)
{
tic_mem* tic = sprite->tic;
sprite->tic->api.rect(sprite->tic, 0, 0, TIC80_WIDTH, TOOLBAR_SIZE, (tic_color_white));
// draw sprite size control
@ -1536,7 +1533,7 @@ static void drawSpriteToolbar(Sprite* sprite)
{
static const char Label[] = "BG";
tic_rect rect = {TIC80_WIDTH - 2 * tic->font.width - 2, 0, 2 * tic->font.width + 1, TIC_SPRITESIZE-1};
tic_rect rect = {TIC80_WIDTH - 2 * TIC_FONT_WIDTH - 2, 0, 2 * TIC_FONT_WIDTH + 1, TIC_SPRITESIZE-1};
sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, bg ? (tic_color_black) : (tic_color_gray));
sprite->tic->api.fixed_text(sprite->tic, Label, rect.x+1, rect.y+1, (tic_color_white));
@ -1556,7 +1553,7 @@ static void drawSpriteToolbar(Sprite* sprite)
{
static const char Label[] = "FG";
tic_rect rect = {TIC80_WIDTH - 4 * tic->font.width - 4, 0, 2 * tic->font.width + 1, TIC_SPRITESIZE-1};
tic_rect rect = {TIC80_WIDTH - 4 * TIC_FONT_WIDTH - 4, 0, 2 * TIC_FONT_WIDTH + 1, TIC_SPRITESIZE-1};
sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, bg ? (tic_color_gray) : (tic_color_black));
sprite->tic->api.fixed_text(sprite->tic, Label, rect.x+1, rect.y+1, (tic_color_white));

View File

@ -24,25 +24,23 @@
static void reset(Start* start)
{
tic_mem* tic = start->tic;
u8* tile = (u8*)tic->ram.tiles.data;
u8* tile = (u8*)start->tic->ram.tiles.data;
tic->api.clear(tic, (tic_color_black));
start->tic->api.clear(start->tic, (tic_color_black));
static const u8 Reset[] = {0x00, 0x06, 0x96, 0x00};
u8 val = Reset[sizeof(Reset) * (start->ticks % TIC_FRAMERATE) / TIC_FRAMERATE];
for(s32 i = 0; i < sizeof(tic_tile); i++) tile[i] = val;
tic->api.map(tic, &tic->ram.map, &tic->ram.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT + (TIC80_HEIGHT % TIC_SPRITESIZE ? 1 : 0), 0, 0, -1, 1);
start->tic->api.map(start->tic, &start->tic->ram.map, &start->tic->ram.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT + (TIC80_HEIGHT % TIC_SPRITESIZE ? 1 : 0), 0, 0, -1, 1);
}
static void drawHeader(Start* start)
{
tic_mem* tic = start->tic;
tic->api.fixed_text(tic, TIC_NAME_FULL, TextWidth(tic), TextHeight(tic), (tic_color_white));
tic->api.fixed_text(tic, TIC_VERSION_LABEL, (sizeof(TIC_NAME_FULL) + 1) * TextWidth(tic), TextHeight(tic), (tic_color_dark_gray));
tic->api.fixed_text(tic, TIC_COPYRIGHT, TextWidth(tic), TextHeight(tic)*2, (tic_color_dark_gray));
start->tic->api.fixed_text(start->tic, TIC_NAME_FULL, STUDIO_TEXT_WIDTH, STUDIO_TEXT_HEIGHT, (tic_color_white));
start->tic->api.fixed_text(start->tic, TIC_VERSION_LABEL, (sizeof(TIC_NAME_FULL) + 1) * STUDIO_TEXT_WIDTH, STUDIO_TEXT_HEIGHT, (tic_color_dark_gray));
start->tic->api.fixed_text(start->tic, TIC_COPYRIGHT, STUDIO_TEXT_WIDTH, STUDIO_TEXT_HEIGHT*2, (tic_color_dark_gray));
}
static void header(Start* start)
@ -59,10 +57,9 @@ static void header(Start* start)
static void end(Start* start)
{
tic_mem* tic = start->tic;
if(start->play)
{
tic->api.sfx_stop(tic, 0);
start->tic->api.sfx_stop(start->tic, 0);
start->play = false;
}
@ -73,8 +70,6 @@ static void end(Start* start)
static void tick(Start* start)
{
tic_mem* tic = start->tic;
if(!start->initialized)
{
start->phase = 1;
@ -83,7 +78,7 @@ static void tick(Start* start)
start->initialized = true;
}
tic->api.clear(tic, TIC_COLOR_BG);
start->tic->api.clear(start->tic, TIC_COLOR_BG);
static void(*const steps[])(Start*) = {reset, header, end};

View File

@ -133,12 +133,12 @@ static struct
struct
{
s32 counter;
char message[TIC80_WIDTH];
char message[STUDIO_TEXT_BUFFER_WIDTH];
} popup;
struct
{
char text[TIC80_WIDTH];
char text[STUDIO_TEXT_BUFFER_WIDTH];
} tooltip;
struct
@ -436,7 +436,7 @@ static void drawExtrabar(tic_mem* tic)
{
enum {Size = 7};
s32 x = (COUNT_OF(Modes) + 1) * Size + 102;
s32 x = (COUNT_OF(Modes) + 1) * Size + 17 * TIC_FONT_WIDTH;
s32 y = 0;
static const u8 Icons[] =
@ -532,7 +532,7 @@ static void drawBankIcon(s32 x, s32 y)
{
tic_mem* tic = impl.studio.tic;
tic_rect rect = {x, y, tic->font.width, tic->font.height};
tic_rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT};
static const u8 Icon[] =
{
@ -574,11 +574,9 @@ static void drawBankIcon(s32 x, s32 y)
enum{Size = TOOLBAR_SIZE};
x += Size+2;
for(s32 i = 0; i < TIC_EDITOR_BANKS; i++)
{
tic_rect rect = {x + i*Size, 0, Size, Size};
tic_rect rect = {x + 2 + (i+1)*Size, 0, Size, Size};
bool over = false;
if(checkMousePos(&rect))
@ -597,7 +595,7 @@ static void drawBankIcon(s32 x, s32 y)
if(i == impl.bank.indexes[mode])
tic->api.rect(tic, rect.x, rect.y, rect.w, rect.h, tic_color_red);
tic->api.draw_char(tic, '0' + i, rect.x+(Size-tic->font.width+1)/2, rect.y+1, i == impl.bank.indexes[mode] ? tic_color_white : over ? tic_color_red : tic_color_peach);
tic->api.draw_char(tic, '0' + i, rect.x+1, rect.y+1, i == impl.bank.indexes[mode] ? tic_color_white : over ? tic_color_red : tic_color_peach);
}
@ -614,7 +612,7 @@ static void drawBankIcon(s32 x, s32 y)
0b00000000,
};
tic_rect rect = {x + 2 + TIC_EDITOR_BANKS*Size, 0, Size, Size};
tic_rect rect = {x + 4 + (TIC_EDITOR_BANKS+1)*Size, 0, Size, Size};
bool over = false;
@ -1524,8 +1522,6 @@ static void recordFrame(u32* pixels)
static void drawPopup()
{
tic_mem* tic = impl.studio.tic;
if(impl.popup.counter > 0)
{
impl.popup.counter--;
@ -1535,13 +1531,13 @@ static void drawPopup()
enum{Dur = TIC_FRAMERATE/2};
if(impl.popup.counter < Dur)
anim = -((Dur - impl.popup.counter) * (tic->font.height+1) / Dur);
anim = -((Dur - impl.popup.counter) * (TIC_FONT_HEIGHT+1) / Dur);
else if(impl.popup.counter >= (POPUP_DUR - Dur))
anim = (((POPUP_DUR - Dur) - impl.popup.counter) * (tic->font.height+1) / Dur);
anim = (((POPUP_DUR - Dur) - impl.popup.counter) * (TIC_FONT_HEIGHT+1) / Dur);
impl.studio.tic->api.rect(impl.studio.tic, 0, anim, TIC80_WIDTH, tic->font.height+1, (tic_color_red));
impl.studio.tic->api.rect(impl.studio.tic, 0, anim, TIC80_WIDTH, TIC_FONT_HEIGHT+1, (tic_color_red));
impl.studio.tic->api.text(impl.studio.tic, impl.popup.message,
(s32)(TIC80_WIDTH - strlen(impl.popup.message)*tic->font.width)/2,
(s32)(TIC80_WIDTH - strlen(impl.popup.message)*TIC_FONT_WIDTH)/2,
anim + 1, (tic_color_white));
}
}
@ -1630,12 +1626,7 @@ static void renderStudio()
static void updateSystemFont()
{
tic_mem* tic = impl.studio.tic;
memset(tic->font.data, 0, sizeof tic->font.data);
tic->font.width = impl.config->data.theme.font.width;
tic->font.height = impl.config->data.theme.font.height;
memset(impl.studio.tic->font.data, 0, sizeof(tic_font));
for(s32 i = 0; i < TIC_FONT_CHARS; i++)
for(s32 y = 0; y < TIC_SPRITESIZE; y++)

View File

@ -38,7 +38,10 @@
#define TIC_CACHE TIC_LOCAL "cache/"
#define TOOLBAR_SIZE 7
#define TEXT_LINE_SPACE 1
#define STUDIO_TEXT_WIDTH (TIC_FONT_WIDTH)
#define STUDIO_TEXT_HEIGHT (TIC_FONT_HEIGHT+1)
#define STUDIO_TEXT_BUFFER_WIDTH (TIC80_WIDTH / STUDIO_TEXT_WIDTH)
#define STUDIO_TEXT_BUFFER_HEIGHT (TIC80_HEIGHT / STUDIO_TEXT_HEIGHT)
#define TIC_COLOR_BG (tic_color_black)
#define DEFAULT_CHMOD 0755
@ -160,8 +163,3 @@ bool anyKeyWasPressed();
const StudioConfig* getConfig();
System* getSystem();
inline s32 TextWidth(const tic_mem* tic) { return tic->font.width; }
inline s32 TextHeight(const tic_mem* tic) { return tic->font.height + TEXT_LINE_SPACE; }
inline s32 BufferWidth(const tic_mem* tic) { return TIC80_WIDTH/TextWidth(tic); }
inline s32 BufferHeight(const tic_mem* tic) { return TIC80_HEIGHT/TextHeight(tic); }

View File

@ -193,7 +193,7 @@ static void drawTopToolbar(Surf* surf, s32 x, s32 y)
sprintf(label, "%s", "TIC-80 SURF");
s32 xl = x + MAIN_OFFSET;
s32 yl = y + (Height - tic->font.height)/2;
s32 yl = y + (Height - TIC_FONT_HEIGHT)/2;
tic->api.text(tic, label, xl, yl+1, tic_color_black);
tic->api.text(tic, label, xl, yl, tic_color_white);
}
@ -231,7 +231,7 @@ static void drawBottomToolbar(Surf* surf, s32 x, s32 y)
sprintf(label, "/%s", dir);
s32 xl = x + MAIN_OFFSET;
s32 yl = y + (Height - tic->font.height)/2;
s32 yl = y + (Height - TIC_FONT_HEIGHT)/2;
tic->api.text(tic, label, xl, yl+1, tic_color_black);
tic->api.text(tic, label, xl, yl, tic_color_white);
}
@ -327,13 +327,13 @@ static void drawMenu(Surf* surf, s32 x, s32 y, bool bg)
{
const char* name = surf->menu.items[i].label;
s32 ym = Height * i + y - surf->menu.pos*MENU_HEIGHT - surf->menu.anim + (MENU_HEIGHT - tic->font.height)/2;
s32 ym = Height * i + y - surf->menu.pos*MENU_HEIGHT - surf->menu.anim + (MENU_HEIGHT - TIC_FONT_HEIGHT)/2;
if(bg)
{
s32 size = tic->api.text(tic, name, 0, -tic->font.height, 0);
s32 size = tic->api.text(tic, name, 0, -TIC_FONT_HEIGHT, 0);
drawInverseRect(tic, x + MAIN_OFFSET - 1, ym-1, size+1, tic->font.height+2);
drawInverseRect(tic, x + MAIN_OFFSET - 1, ym-1, size+1, TIC_FONT_HEIGHT+2);
}
else
{
@ -837,8 +837,8 @@ static void tick(Surf* surf)
else
{
static const char Label[] = "You don't have any files...";
s32 size = tic->api.text(tic, Label, 0, -tic->font.height, tic_color_white);
tic->api.text(tic, Label, (TIC80_WIDTH - size) / 2, (TIC80_HEIGHT - tic->font.height)/2, tic_color_white);
s32 size = tic->api.text(tic, Label, 0, -TIC_FONT_HEIGHT, tic_color_white);
tic->api.text(tic, Label, (TIC80_WIDTH - size) / 2, (TIC80_HEIGHT - TIC_FONT_HEIGHT)/2, tic_color_white);
}
}

View File

@ -63,12 +63,6 @@ typedef struct
} gamepad;
struct
{
s32 width;
s32 height;
} font;
} theme;
s32 gifScale;

398
src/tic.c
View File

@ -147,11 +147,11 @@ static void runNoise(blip_buffer_t* blip, tic_sound_register* reg, tic_sound_reg
}
}
static void resetPalette(tic_mem* tic)
static void resetPalette(tic_mem* memory)
{
static const u8 DefaultMapping[] = {16, 50, 84, 118, 152, 186, 220, 254};
memcpy(tic->ram.vram.palette.data, tic->cart.bank0.palette.data, sizeof(tic_palette));
memcpy(tic->ram.vram.mapping, DefaultMapping, sizeof DefaultMapping);
memcpy(memory->ram.vram.palette.data, memory->cart.bank0.palette.data, sizeof(tic_palette));
memcpy(memory->ram.vram.mapping, DefaultMapping, sizeof DefaultMapping);
}
static inline u8 mapColor(tic_mem* tic, u8 color)
@ -214,19 +214,19 @@ static u8 getPixel(tic_machine* machine, s32 x, s32 y)
return machine->state.getpix(&machine->memory, x, y);
}
static void drawHLineDma(tic_mem* tic, s32 xl, s32 xr, s32 y, u8 color)
static void drawHLineDma(tic_mem* memory, s32 xl, s32 xr, s32 y, u8 color)
{
color = color << 4 | color;
if (xl >= xr) return;
if (xl & 1) {
tic_tool_poke4(&tic->ram.vram.screen.data, y * TIC80_WIDTH + xl, color);
tic_tool_poke4(&memory->ram.vram.screen.data, y * TIC80_WIDTH + xl, color);
xl++;
}
s32 count = (xr - xl) >> 1;
u8 *screen = tic->ram.vram.screen.data + ((y * TIC80_WIDTH + xl) >> 1);
u8 *screen = memory->ram.vram.screen.data + ((y * TIC80_WIDTH + xl) >> 1);
for(s32 i = 0; i < count; i++) *screen++ = color;
if (xr & 1) {
tic_tool_poke4(&tic->ram.vram.screen.data, y * TIC80_WIDTH + xr - 1, color);
tic_tool_poke4(&memory->ram.vram.screen.data, y * TIC80_WIDTH + xr - 1, color);
}
}
@ -377,9 +377,9 @@ static void resetSfx(Channel* channel)
channel->tick = -1;
}
static void channelSfx(tic_mem* tic, s32 index, s32 note, s32 octave, s32 duration, Channel* c, s32 volume, s32 speed)
static void channelSfx(tic_mem* memory, s32 index, s32 note, s32 octave, s32 duration, Channel* c, s32 volume, s32 speed)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
c->volume = volume;
@ -401,34 +401,34 @@ static void channelSfx(tic_mem* tic, s32 index, s32 note, s32 octave, s32 durati
resetSfx(c);
}
static void musicSfx(tic_mem* tic, s32 index, s32 note, s32 octave, s32 volume, s32 channel)
static void musicSfx(tic_mem* memory, s32 index, s32 note, s32 octave, s32 volume, s32 channel)
{
tic_machine* machine = (tic_machine*)tic;
channelSfx(tic, index, note, octave, -1, &machine->state.music.channels[channel], MAX_VOLUME - volume, SFX_DEF_SPEED);
tic_machine* machine = (tic_machine*)memory;
channelSfx(memory, index, note, octave, -1, &machine->state.music.channels[channel], MAX_VOLUME - volume, SFX_DEF_SPEED);
}
static void resetMusic(tic_mem* tic)
static void resetMusic(tic_mem* memory)
{
for (s32 c = 0; c < TIC_SOUND_CHANNELS; c++)
musicSfx(tic, -1, 0, 0, 0, c);
musicSfx(memory, -1, 0, 0, 0, c);
}
static void setMusic(tic_machine* machine, s32 index, s32 frame, s32 row, bool loop)
{
tic_mem* tic = (tic_mem*)machine;
tic_mem* memory = (tic_mem*)machine;
tic->ram.music_pos.track = index;
memory->ram.music_pos.track = index;
if(index < 0)
{
machine->state.music.play = MusicStop;
resetMusic(tic);
resetMusic(memory);
}
else
{
tic->ram.music_pos.row = row;
tic->ram.music_pos.frame = frame < 0 ? 0 : frame;
tic->ram.music_pos.flag.loop = loop;
memory->ram.music_pos.row = row;
memory->ram.music_pos.frame = frame < 0 ? 0 : frame;
memory->ram.music_pos.flag.loop = loop;
machine->state.music.play = MusicPlay;
const tic_track* track = &machine->sound.music->tracks.data[index];
@ -436,9 +436,9 @@ static void setMusic(tic_machine* machine, s32 index, s32 frame, s32 row, bool l
}
}
static void api_music(tic_mem* tic, s32 index, s32 frame, s32 row, bool loop)
static void api_music(tic_mem* memory, s32 index, s32 frame, s32 row, bool loop)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
setMusic(machine, index, frame, row, loop);
@ -446,10 +446,10 @@ static void api_music(tic_mem* tic, s32 index, s32 frame, s32 row, bool loop)
machine->state.music.play = MusicPlay;
}
static void soundClear(tic_mem* tic)
static void soundClear(tic_mem* memory)
{
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
Channel channel =
{
@ -474,7 +474,7 @@ static void soundClear(tic_mem* tic)
memcpy(machine->state.music.channels+i, &channel, sizeof channel);
{
tic_sound_register* reg = &tic->ram.registers[i];
tic_sound_register* reg = &memory->ram.registers[i];
memset(reg, 0, sizeof(tic_sound_register));
}
@ -484,17 +484,17 @@ static void soundClear(tic_mem* tic)
}
}
api_music(tic, -1, 0, 0, false);
api_music(memory, -1, 0, 0, false);
}
memset(tic->samples.buffer, 0, tic->samples.size);
memset(memory->samples.buffer, 0, memory->samples.size);
}
static void updateSaveid(tic_mem* tic);
static void updateSaveid(tic_mem* memory);
static void api_clip(tic_mem* tic, s32 x, s32 y, s32 width, s32 height)
static void api_clip(tic_mem* memory, s32 x, s32 y, s32 width, s32 height)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
machine->state.clip.l = x;
machine->state.clip.t = y;
@ -507,17 +507,17 @@ static void api_clip(tic_mem* tic, s32 x, s32 y, s32 width, s32 height)
if(machine->state.clip.b > TIC80_HEIGHT) machine->state.clip.b = TIC80_HEIGHT;
}
static void api_reset(tic_mem* tic)
static void api_reset(tic_mem* memory)
{
resetPalette(tic);
resetPalette(memory);
memset(&tic->ram.vram.vars, 0, sizeof tic->ram.vram.vars);
memset(&memory->ram.vram.vars, 0, sizeof memory->ram.vram.vars);
api_clip(tic, 0, 0, TIC80_WIDTH, TIC80_HEIGHT);
api_clip(memory, 0, 0, TIC80_WIDTH, TIC80_HEIGHT);
soundClear(tic);
soundClear(memory);
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
machine->state.initialized = false;
machine->state.scanline = NULL;
machine->state.ovr.callback = NULL;
@ -526,64 +526,64 @@ static void api_reset(tic_mem* tic)
machine->state.getpix = getPixelDma;
machine->state.drawhline = drawHLineDma;
updateSaveid(tic);
updateSaveid(memory);
}
static void api_pause(tic_mem* tic)
static void api_pause(tic_mem* memory)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
memcpy(&machine->pause.state, &machine->state, sizeof(MachineState));
memcpy(&machine->pause.ram, &tic->ram, sizeof(tic_ram));
memcpy(&machine->pause.ram, &memory->ram, sizeof(tic_ram));
machine->pause.time.start = machine->data->start;
machine->pause.time.paused = machine->data->counter();
}
static void api_resume(tic_mem* tic)
static void api_resume(tic_mem* memory)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
if (machine->data)
{
memcpy(&machine->state, &machine->pause.state, sizeof(MachineState));
memcpy(&tic->ram, &machine->pause.ram, sizeof(tic_ram));
memcpy(&memory->ram, &machine->pause.ram, sizeof(tic_ram));
machine->data->start = machine->pause.time.start + machine->data->counter() - machine->pause.time.paused;
}
}
void tic_close(tic_mem* tic)
void tic_close(tic_mem* memory)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
machine->state.initialized = false;
#if defined(TIC_BUILD_WITH_LUA)
getLuaScriptConfig()->close(tic);
getLuaScriptConfig()->close(memory);
# if defined(TIC_BUILD_WITH_MOON)
getMoonScriptConfig()->close(tic);
getMoonScriptConfig()->close(memory);
# endif
# if defined(TIC_BUILD_WITH_FENNEL)
getFennelConfig()->close(tic);
getFennelConfig()->close(memory);
# endif
#endif /* defined(TIC_BUILD_WITH_LUA) */
#if defined(TIC_BUILD_WITH_JS)
getJsScriptConfig()->close(tic);
getJsScriptConfig()->close(memory);
#endif
#if defined(TIC_BUILD_WITH_WREN)
getWrenScriptConfig()->close(tic);
getWrenScriptConfig()->close(memory);
#endif
blip_delete(machine->blip);
free(tic->samples.buffer);
free(memory->samples.buffer);
free(machine);
}
@ -591,49 +591,49 @@ void tic_close(tic_mem* tic)
// API ////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
static void api_rect(tic_mem* tic, s32 x, s32 y, s32 width, s32 height, u8 color)
static void api_rect(tic_mem* memory, s32 x, s32 y, s32 width, s32 height, u8 color)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
drawRect(machine, x, y, width, height, color);
}
static void api_clear(tic_mem* tic, u8 color)
static void api_clear(tic_mem* memory, u8 color)
{
static const Clip EmptyClip = {0, 0, TIC80_WIDTH, TIC80_HEIGHT};
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
if(memcmp(&machine->state.clip, &EmptyClip, sizeof(Clip)) == 0)
{
color &= 0b00001111;
memset(tic->ram.vram.screen.data, color | (color << TIC_PALETTE_BPP), sizeof(tic->ram.vram.screen.data));
memset(memory->ram.vram.screen.data, color | (color << TIC_PALETTE_BPP), sizeof(memory->ram.vram.screen.data));
}
else
{
api_rect(tic, machine->state.clip.l, machine->state.clip.t, machine->state.clip.r - machine->state.clip.l, machine->state.clip.b - machine->state.clip.t, color);
api_rect(memory, machine->state.clip.l, machine->state.clip.t, machine->state.clip.r - machine->state.clip.l, machine->state.clip.b - machine->state.clip.t, color);
}
}
static s32 drawChar(tic_mem* tic, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 color, s32 scale)
static s32 drawChar(tic_mem* memory, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 color, s32 scale)
{
const u8* ptr = tic->font.data + symbol*BITS_IN_BYTE;
const u8* ptr = memory->font.data + symbol*BITS_IN_BYTE;
x += (BITS_IN_BYTE - 1)*scale;
for(s32 i = 0, ys = y; i < tic->font.height; i++, ptr++, ys += scale)
for(s32 col = BITS_IN_BYTE - tic->font.width, xs = x - col; col < BITS_IN_BYTE; col++, xs -= scale)
for(s32 i = 0, ys = y; i < TIC_FONT_HEIGHT; i++, ptr++, ys += scale)
for(s32 col = BITS_IN_BYTE - TIC_FONT_WIDTH, xs = x - col; col < BITS_IN_BYTE; col++, xs -= scale)
if(*ptr & 1 << col)
api_rect(tic, xs, ys, scale, scale, color);
api_rect(memory, xs, ys, scale, scale, color);
return tic->font.width*scale;
return TIC_FONT_WIDTH*scale;
}
static s32 api_draw_char(tic_mem* tic, u8 symbol, s32 x, s32 y, u8 color)
static s32 api_draw_char(tic_mem* memory, u8 symbol, s32 x, s32 y, u8 color)
{
return drawChar(tic, symbol, x, y, tic->font.width, tic->font.height, color, 1);
return drawChar(memory, symbol, x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT, color, 1);
}
s32 drawText(tic_mem* tic, const char* text, s32 x, s32 y, s32 width, s32 height, u8 color, s32 scale, DrawCharFunc* func)
s32 drawText(tic_mem* memory, const char* text, s32 x, s32 y, s32 width, s32 height, u8 color, s32 scale, DrawCharFunc* func)
{
s32 pos = x;
s32 max = x;
@ -649,69 +649,69 @@ s32 drawText(tic_mem* tic, const char* text, s32 x, s32 y, s32 width, s32 height
pos = x;
y += height * scale;
}
else pos += func(tic, sym, pos, y, width, height, color, scale);
else pos += func(memory, sym, pos, y, width, height, color, scale);
}
return pos > max ? pos - x : max - x;
}
static s32 api_fixed_text(tic_mem* tic, const char* text, s32 x, s32 y, u8 color)
static s32 api_fixed_text(tic_mem* memory, const char* text, s32 x, s32 y, u8 color)
{
return drawText(tic, text, x, y, tic->font.width, tic->font.height, color, 1, drawChar);
return drawText(memory, text, x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT, color, 1, drawChar);
}
static s32 drawNonFixedChar(tic_mem* tic, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 color, s32 scale)
static s32 drawNonFixedChar(tic_mem* memory, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 color, s32 scale)
{
const u8* ptr = tic->font.data + (symbol)*BITS_IN_BYTE;
const u8* ptr = memory->font.data + (symbol)*BITS_IN_BYTE;
s32 start = 0;
s32 end = tic->font.width;
s32 end = TIC_FONT_WIDTH;
s32 i = 0;
for(s32 col = 0; col < tic->font.width; col++)
for(s32 col = 0; col < TIC_FONT_WIDTH; col++)
{
for(i = 0; i < tic->font.height; i++)
for(i = 0; i < TIC_FONT_HEIGHT; i++)
if(*(ptr + i) & 0b10000000 >> col) break;
if(i < tic->font.height) break; else start++;
if(i < TIC_FONT_HEIGHT) break; else start++;
}
x -= start * scale;
for(s32 col = tic->font.width - 1; col >= start; col--)
for(s32 col = TIC_FONT_WIDTH - 1; col >= start; col--)
{
for(i = 0; i < tic->font.height; i++)
for(i = 0; i < TIC_FONT_HEIGHT; i++)
if(*(ptr + i) & 0b10000000 >> col) break;
if(i < tic->font.height) break; else end--;
if(i < TIC_FONT_HEIGHT) break; else end--;
}
for(s32 ys = y, i = 0; i < tic->font.height; i++, ptr++, ys += scale)
for(s32 ys = y, i = 0; i < TIC_FONT_HEIGHT; i++, ptr++, ys += scale)
for(s32 col = start, xs = x + start*scale; col < end; col++, xs += scale)
if(*ptr & 0b10000000 >> col)
api_rect(tic, xs, ys, scale, scale, color);
api_rect(memory, xs, ys, scale, scale, color);
s32 size = end - start;
return (size ? size + 1 : tic->font.width - 2) * scale;
return (size ? size + 1 : TIC_FONT_WIDTH - 2) * scale;
}
static s32 api_text(tic_mem* tic, const char* text, s32 x, s32 y, u8 color)
static s32 api_text(tic_mem* memory, const char* text, s32 x, s32 y, u8 color)
{
return drawText(tic, text, x, y, tic->font.width, tic->font.height, color, 1, drawNonFixedChar);
return drawText(memory, text, x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT, color, 1, drawNonFixedChar);
}
static s32 api_text_ex(tic_mem* tic, const char* text, s32 x, s32 y, u8 color, bool fixed, s32 scale)
static s32 api_text_ex(tic_mem* memory, const char* text, s32 x, s32 y, u8 color, bool fixed, s32 scale)
{
return drawText(tic, text, x, y, tic->font.width, tic->font.height, color, scale, fixed ? drawChar : drawNonFixedChar);
return drawText(memory, text, x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT, color, scale, fixed ? drawChar : drawNonFixedChar);
}
static void drawSprite(tic_mem* tic, const tic_tiles* src, s32 index, s32 x, s32 y, u8* colors, s32 count, s32 scale, tic_flip flip, tic_rotate rotate)
static void drawSprite(tic_mem* memory, const tic_tiles* src, s32 index, s32 x, s32 y, u8* colors, s32 count, s32 scale, tic_flip flip, tic_rotate rotate)
{
if(index < TIC_SPRITES)
drawTile((tic_machine*)tic, src->data + index, x, y, colors, count, scale, flip, rotate);
drawTile((tic_machine*)memory, src->data + index, x, y, colors, count, scale, flip, rotate);
}
static void api_sprite_ex(tic_mem* tic, const tic_tiles* src, s32 index, s32 x, s32 y, s32 w, s32 h, u8* colors, s32 count, s32 scale, tic_flip flip, tic_rotate rotate)
static void api_sprite_ex(tic_mem* memory, const tic_tiles* src, s32 index, s32 x, s32 y, s32 w, s32 h, u8* colors, s32 count, s32 scale, tic_flip flip, tic_rotate rotate)
{
s32 step = TIC_SPRITESIZE * scale;
@ -746,23 +746,23 @@ static void api_sprite_ex(tic_mem* tic, const tic_tiles* src, s32 index, s32 x,
enum {Cols = TIC_SPRITESHEET_SIZE / TIC_SPRITESIZE};
if(rotate==0 || rotate==2)
drawSprite(tic, src, index + mx+my*Cols, x+i*step, y+j*step, colors, count, scale, flip, rotate);
drawSprite(memory, src, index + mx+my*Cols, x+i*step, y+j*step, colors, count, scale, flip, rotate);
else
drawSprite(tic, src, index + mx+my*Cols, x+j*step, y+i*step, colors, count, scale, flip, rotate);
drawSprite(memory, src, index + mx+my*Cols, x+j*step, y+i*step, colors, count, scale, flip, rotate);
}
}
}
s32 drawSpriteFont(tic_mem* tic, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale)
s32 drawSpriteFont(tic_mem* memory, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale)
{
api_sprite_ex(tic, &tic->ram.sprites, symbol, x, y, 1, 1, &chromakey, 1, scale, tic_no_flip, tic_no_rotate);
api_sprite_ex(memory, &memory->ram.sprites, symbol, x, y, 1, 1, &chromakey, 1, scale, tic_no_flip, tic_no_rotate);
return width * scale;
}
s32 drawFixedSpriteFont(tic_mem* tic, u8 index, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale)
s32 drawFixedSpriteFont(tic_mem* memory, u8 index, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale)
{
const u8* ptr = tic->ram.sprites.data[index].data;
const u8* ptr = memory->ram.sprites.data[index].data;
enum {Size = TIC_SPRITESIZE};
@ -795,7 +795,7 @@ s32 drawFixedSpriteFont(tic_mem* tic, u8 index, s32 x, s32 y, s32 width, s32 hei
u8 color = tic_tool_peek4(ptr, col + row * Size);
if(color != chromakey)
api_rect(tic, xs, ys, scale, scale, color);
api_rect(memory, xs, ys, scale, scale, color);
}
}
@ -803,23 +803,23 @@ s32 drawFixedSpriteFont(tic_mem* tic, u8 index, s32 x, s32 y, s32 width, s32 hei
return (size ? size + 1 : width) * scale;
}
static void api_pixel(tic_mem* tic, s32 x, s32 y, u8 color)
static void api_pixel(tic_mem* memory, s32 x, s32 y, u8 color)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
setPixel(machine, x, y, color);
}
static u8 api_get_pixel(tic_mem* tic, s32 x, s32 y)
static u8 api_get_pixel(tic_mem* memory, s32 x, s32 y)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
return getPixel(machine, x, y);
}
static void api_rect_border(tic_mem* tic, s32 x, s32 y, s32 width, s32 height, u8 color)
static void api_rect_border(tic_mem* memory, s32 x, s32 y, s32 width, s32 height, u8 color)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
drawRectBorder(machine, x, y, width, height, color);
}
@ -865,9 +865,9 @@ static void setSideTexPixel(s32 x, s32 y, float u, float v)
}
}
static void api_circle(tic_mem* tic, s32 xm, s32 ym, s32 radius, u8 color)
static void api_circle(tic_mem* memory, s32 xm, s32 ym, s32 radius, u8 color)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
initSidesBuffer();
@ -895,23 +895,23 @@ static void api_circle(tic_mem* tic, s32 xm, s32 ym, s32 radius, u8 color)
}
}
static void api_circle_border(tic_mem* tic, s32 xm, s32 ym, s32 radius, u8 color)
static void api_circle_border(tic_mem* memory, s32 xm, s32 ym, s32 radius, u8 color)
{
s32 r = radius;
s32 x = -r, y = 0, err = 2-2*r;
do {
api_pixel(tic, xm-x, ym+y, color);
api_pixel(tic, xm-y, ym-x, color);
api_pixel(tic, xm+x, ym-y, color);
api_pixel(tic, xm+y, ym+x, color);
api_pixel(memory, xm-x, ym+y, color);
api_pixel(memory, xm-y, ym-x, color);
api_pixel(memory, xm+x, ym-y, color);
api_pixel(memory, xm+y, ym+x, color);
r = err;
if (r <= y) err += ++y*2+1;
if (r > x || err > y) err += ++x*2+1;
} while (x < 0);
}
typedef void(*linePixelFunc)(tic_mem* tic, s32 x, s32 y, u8 color);
static void ticLine(tic_mem* tic, s32 x0, s32 y0, s32 x1, s32 y1, u8 color, linePixelFunc func)
typedef void(*linePixelFunc)(tic_mem* memory, s32 x, s32 y, u8 color);
static void ticLine(tic_mem* memory, s32 x0, s32 y0, s32 x1, s32 y1, u8 color, linePixelFunc func)
{
s32 dx = abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
s32 dy = abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
@ -919,7 +919,7 @@ static void ticLine(tic_mem* tic, s32 x0, s32 y0, s32 x1, s32 y1, u8 color, line
for(;;)
{
func(tic, x0, y0, color);
func(memory, x0, y0, color);
if (x0 == x1 && y0 == y1) break;
e2 = err;
if (e2 >-dx) { err -= dy; x0 += sx; }
@ -927,20 +927,20 @@ static void ticLine(tic_mem* tic, s32 x0, s32 y0, s32 x1, s32 y1, u8 color, line
}
}
static void triPixelFunc(tic_mem* tic, s32 x, s32 y, u8 color)
static void triPixelFunc(tic_mem* memory, s32 x, s32 y, u8 color)
{
setSidePixel(x, y);
}
static void api_tri(tic_mem* tic, s32 x1, s32 y1, s32 x2, s32 y2, s32 x3, s32 y3, u8 color)
static void api_tri(tic_mem* memory, s32 x1, s32 y1, s32 x2, s32 y2, s32 x3, s32 y3, u8 color)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
initSidesBuffer();
ticLine(tic, x1, y1, x2, y2, color, triPixelFunc);
ticLine(tic, x2, y2, x3, y3, color, triPixelFunc);
ticLine(tic, x3, y3, x1, y1, color, triPixelFunc);
ticLine(memory, x1, y1, x2, y2, color, triPixelFunc);
ticLine(memory, x2, y2, x3, y3, color, triPixelFunc);
ticLine(memory, x3, y3, x1, y1, color, triPixelFunc);
u8 final_color = mapColor(&machine->memory, color);
s32 yt = max(machine->state.clip.t, min(y1, min(y2, y3)));
@ -960,7 +960,7 @@ typedef struct
} TexVert;
static void ticTexLine(tic_mem* tic, TexVert *v0, TexVert *v1)
static void ticTexLine(tic_mem* memory, TexVert *v0, TexVert *v1)
{
TexVert *top = v0;
TexVert *bot = v1;
@ -1012,12 +1012,12 @@ static void ticTexLine(tic_mem* tic, TexVert *v0, TexVert *v1)
}
}
static void api_textri(tic_mem* tic, float x1, float y1, float x2, float y2, float x3, float y3, float u1, float v1, float u2, float v2, float u3, float v3, bool use_map, u8 chroma)
static void api_textri(tic_mem* memory, float x1, float y1, float x2, float y2, float x3, float y3, float u1, float v1, float u2, float v2, float u3, float v3, bool use_map, u8 chroma)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
TexVert V0, V1, V2;
const u8* ptr = tic->ram.tiles.data[0].data;
const u8* map = tic->ram.map.data;
const u8* ptr = memory->ram.tiles.data[0].data;
const u8* map = memory->ram.map.data;
V0.x = x1; V0.y = y1; V0.u = u1; V0.v = v1;
V1.x = x2; V1.y = y2; V1.u = u2; V1.v = v2;
@ -1041,9 +1041,9 @@ static void api_textri(tic_mem* tic, float x1, float y1, float x2, float y2, flo
// fill the buffer
initSidesBuffer();
// parse each line and decide where in the buffer to store them ( left or right )
ticTexLine(tic, &V0, &V1);
ticTexLine(tic, &V1, &V2);
ticTexLine(tic, &V2, &V0);
ticTexLine(memory, &V0, &V1);
ticTexLine(memory, &V1, &V2);
ticTexLine(memory, &V2, &V0);
for (s32 y = 0; y < TIC80_HEIGHT; y++)
{
@ -1110,38 +1110,38 @@ static void api_textri(tic_mem* tic, float x1, float y1, float x2, float y2, flo
}
static void api_sprite(tic_mem* tic, const tic_tiles* src, s32 index, s32 x, s32 y, u8* colors, s32 count)
static void api_sprite(tic_mem* memory, const tic_tiles* src, s32 index, s32 x, s32 y, u8* colors, s32 count)
{
drawSprite(tic, src, index, x, y, colors, count, 1, tic_no_flip, tic_no_rotate);
drawSprite(memory, src, index, x, y, colors, count, 1, tic_no_flip, tic_no_rotate);
}
static void api_map(tic_mem* tic, const tic_map* src, const tic_tiles* tiles, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale)
static void api_map(tic_mem* memory, const tic_map* src, const tic_tiles* tiles, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale)
{
drawMap((tic_machine*)tic, src, tiles, x, y, width, height, sx, sy, chromakey, scale, NULL, NULL);
drawMap((tic_machine*)memory, src, tiles, x, y, width, height, sx, sy, chromakey, scale, NULL, NULL);
}
static void api_remap(tic_mem* tic, const tic_map* src, const tic_tiles* tiles, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale, RemapFunc remap, void* data)
static void api_remap(tic_mem* memory, const tic_map* src, const tic_tiles* tiles, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale, RemapFunc remap, void* data)
{
drawMap((tic_machine*)tic, src, tiles, x, y, width, height, sx, sy, chromakey, scale, remap, data);
drawMap((tic_machine*)memory, src, tiles, x, y, width, height, sx, sy, chromakey, scale, remap, data);
}
static void api_map_set(tic_mem* tic, tic_map* src, s32 x, s32 y, u8 value)
static void api_map_set(tic_mem* memory, tic_map* src, s32 x, s32 y, u8 value)
{
if(x < 0 || x >= TIC_MAP_WIDTH || y < 0 || y >= TIC_MAP_HEIGHT) return;
*(src->data + y * TIC_MAP_WIDTH + x) = value;
}
static u8 api_map_get(tic_mem* tic, const tic_map* src, s32 x, s32 y)
static u8 api_map_get(tic_mem* memory, const tic_map* src, s32 x, s32 y)
{
if(x < 0 || x >= TIC_MAP_WIDTH || y < 0 || y >= TIC_MAP_HEIGHT) return 0;
return *(src->data + y * TIC_MAP_WIDTH + x);
}
static void api_line(tic_mem* tic, s32 x0, s32 y0, s32 x1, s32 y1, u8 color)
static void api_line(tic_mem* memory, s32 x0, s32 y0, s32 x1, s32 y1, u8 color)
{
ticLine(tic, x0, y0, x1, y1, color, api_pixel);
ticLine(memory, x0, y0, x1, y1, color, api_pixel);
}
static s32 calcLoopPos(const tic_sound_loop* loop, s32 pos)
@ -1162,9 +1162,9 @@ static s32 calcLoopPos(const tic_sound_loop* loop, s32 pos)
return offset;
}
static void sfx(tic_mem* tic, s32 index, s32 freq, Channel* channel, tic_sound_register* reg)
static void sfx(tic_mem* memory, s32 index, s32 freq, Channel* channel, tic_sound_register* reg)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
if(channel->duration > 0)
channel->duration--;
@ -1208,13 +1208,13 @@ static void sfx(tic_mem* tic, s32 index, s32 freq, Channel* channel, tic_sound_r
}
}
static void processMusic(tic_mem* tic)
static void processMusic(tic_mem* memory)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
if(machine->state.music.play == MusicStop) return;
const tic_track* track = &machine->sound.music->tracks.data[tic->ram.music_pos.track];
const tic_track* track = &machine->sound.music->tracks.data[memory->ram.music_pos.track];
s32 row = machine->state.music.ticks * (track->tempo + DEFAULT_TEMPO) * DEFAULT_SPEED / (track->speed + DEFAULT_SPEED) / NOTES_PER_MUNUTE;
s32 rows = MUSIC_PATTERN_ROWS - track->rows;
@ -1222,19 +1222,19 @@ static void processMusic(tic_mem* tic)
{
row = 0;
machine->state.music.ticks = 0;
resetMusic(tic);
resetMusic(memory);
if(machine->state.music.play == MusicPlay)
{
tic->ram.music_pos.frame++;
memory->ram.music_pos.frame++;
if(tic->ram.music_pos.frame >= MUSIC_FRAMES)
if(memory->ram.music_pos.frame >= MUSIC_FRAMES)
{
if(tic->ram.music_pos.flag.loop)
tic->ram.music_pos.frame = 0;
if(memory->ram.music_pos.flag.loop)
memory->ram.music_pos.frame = 0;
else
{
api_music(tic, -1, 0, 0, false);
api_music(memory, -1, 0, 0, false);
return;
}
}
@ -1242,15 +1242,15 @@ static void processMusic(tic_mem* tic)
{
s32 val = 0;
for (s32 c = 0; c < TIC_SOUND_CHANNELS; c++)
val += tic_tool_get_pattern_id(track, tic->ram.music_pos.frame, c);
val += tic_tool_get_pattern_id(track, memory->ram.music_pos.frame, c);
if(!val)
{
if(tic->ram.music_pos.flag.loop)
tic->ram.music_pos.frame = 0;
if(memory->ram.music_pos.flag.loop)
memory->ram.music_pos.frame = 0;
else
{
api_music(tic, -1, 0, 0, false);
api_music(memory, -1, 0, 0, false);
return;
}
}
@ -1258,37 +1258,37 @@ static void processMusic(tic_mem* tic)
}
else if(machine->state.music.play == MusicPlayFrame)
{
if(!tic->ram.music_pos.flag.loop)
if(!memory->ram.music_pos.flag.loop)
{
api_music(tic, -1, 0, 0, false);
api_music(memory, -1, 0, 0, false);
return;
}
}
}
if (row != tic->ram.music_pos.row)
if (row != memory->ram.music_pos.row)
{
tic->ram.music_pos.row = row;
memory->ram.music_pos.row = row;
for (s32 channel = 0; channel < TIC_SOUND_CHANNELS; channel++)
{
s32 patternId = tic_tool_get_pattern_id(track, tic->ram.music_pos.frame, channel);
s32 patternId = tic_tool_get_pattern_id(track, memory->ram.music_pos.frame, channel);
if (!patternId) continue;
const tic_track_pattern* pattern = &machine->sound.music->patterns.data[patternId - PATTERN_START];
s32 note = pattern->rows[tic->ram.music_pos.row].note;
s32 note = pattern->rows[memory->ram.music_pos.row].note;
if (note > NoteNone)
{
musicSfx(tic, -1, 0, 0, 0, channel);
musicSfx(memory, -1, 0, 0, 0, channel);
if (note >= NoteStart)
{
s32 octave = pattern->rows[tic->ram.music_pos.row].octave;
s32 octave = pattern->rows[memory->ram.music_pos.row].octave;
s32 sfx = (pattern->rows[row].sfxhi << MUSIC_SFXID_LOW_BITS) | pattern->rows[row].sfxlow;
s32 volume = pattern->rows[tic->ram.music_pos.row].volume;
musicSfx(tic, sfx, note - NoteStart, octave, volume, channel);
s32 volume = pattern->rows[memory->ram.music_pos.row].volume;
musicSfx(memory, sfx, note - NoteStart, octave, volume, channel);
}
}
}
@ -1299,7 +1299,7 @@ static void processMusic(tic_mem* tic)
Channel* c = &machine->state.music.channels[i];
if(c->index >= 0)
sfx(tic, c->index, c->freq, c, &tic->ram.registers[i]);
sfx(memory, c->index, c->freq, c, &memory->ram.registers[i]);
}
machine->state.music.ticks++;
@ -1321,24 +1321,24 @@ static bool isKeyPressed(const tic80_keyboard* input, tic_key key)
return false;
}
static void api_tick_start(tic_mem* tic, const tic_sfx* sfxsrc, const tic_music* music)
static void api_tick_start(tic_mem* memory, const tic_sfx* sfxsrc, const tic_music* music)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
machine->sound.sfx = sfxsrc;
machine->sound.music = music;
for (s32 i = 0; i < TIC_SOUND_CHANNELS; ++i )
memset(&tic->ram.registers[i], 0, sizeof(tic_sound_register));
memset(&memory->ram.registers[i], 0, sizeof(tic_sound_register));
processMusic(tic);
processMusic(memory);
for (s32 i = 0; i < TIC_SOUND_CHANNELS; ++i )
{
Channel* c = &machine->state.channels[i];
if(c->index >= 0)
sfx(tic, c->index, c->freq, c, &tic->ram.registers[i]);
sfx(memory, c->index, c->freq, c, &memory->ram.registers[i]);
}
// process gamepad
@ -1346,7 +1346,7 @@ static void api_tick_start(tic_mem* tic, const tic_sfx* sfxsrc, const tic_music*
{
u32 mask = 1 << i;
u32 prevDown = machine->state.gamepads.previous.data & mask;
u32 down = tic->ram.input.gamepads.data & mask;
u32 down = memory->ram.input.gamepads.data & mask;
u32* hold = &machine->state.gamepads.holds[i];
if(prevDown && prevDown == down) (*hold)++;
@ -1357,7 +1357,7 @@ static void api_tick_start(tic_mem* tic, const tic_sfx* sfxsrc, const tic_music*
for(s32 i = 0; i < tic_keys_count; i++)
{
bool prevDown = isKeyPressed(&machine->state.keyboard.previous, i);
bool down = isKeyPressed(&tic->ram.input.keyboard, i);
bool down = isKeyPressed(&memory->ram.input.keyboard, i);
u32* hold = &machine->state.keyboard.holds[i];
@ -1371,9 +1371,9 @@ static void api_tick_start(tic_mem* tic, const tic_sfx* sfxsrc, const tic_music*
machine->state.drawhline = drawHLineDma;
}
static void api_tick_end(tic_mem* tic)
static void api_tick_end(tic_mem* memory)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
machine->state.gamepads.previous.data = machine->memory.ram.input.gamepads.data;
machine->state.keyboard.previous.data = machine->memory.ram.input.keyboard.data;
@ -1381,7 +1381,7 @@ static void api_tick_end(tic_mem* tic)
enum {EndTime = CLOCKRATE / TIC_FRAMERATE};
for (s32 i = 0; i < TIC_SOUND_CHANNELS; ++i )
{
tic_sound_register* reg = &tic->ram.registers[i];
tic_sound_register* reg = &memory->ram.registers[i];
tic_sound_register_data* data = &machine->state.registers[i];
isNoiseWaveform(&reg->waveform)
@ -1400,34 +1400,34 @@ static void api_tick_end(tic_mem* tic)
}
static tic_sfx_pos api_sfx_pos(tic_mem* tic, s32 channel)
static tic_sfx_pos api_sfx_pos(tic_mem* memory, s32 channel)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
Channel* c = &machine->state.channels[channel];
return c->pos;
}
static void api_sfx_ex(tic_mem* tic, s32 index, s32 note, s32 octave, s32 duration, s32 channel, s32 volume, s32 speed)
static void api_sfx_ex(tic_mem* memory, s32 index, s32 note, s32 octave, s32 duration, s32 channel, s32 volume, s32 speed)
{
tic_machine* machine = (tic_machine*)tic;
channelSfx(tic, index, note, octave, duration, &machine->state.channels[channel], volume, speed);
tic_machine* machine = (tic_machine*)memory;
channelSfx(memory, index, note, octave, duration, &machine->state.channels[channel], volume, speed);
}
static void api_sfx(tic_mem* tic, s32 index, s32 note, s32 octave, s32 duration, s32 channel)
static void api_sfx(tic_mem* memory, s32 index, s32 note, s32 octave, s32 duration, s32 channel)
{
api_sfx_ex(tic, index, note, octave, duration, channel, MAX_VOLUME, SFX_DEF_SPEED);
api_sfx_ex(memory, index, note, octave, duration, channel, MAX_VOLUME, SFX_DEF_SPEED);
}
static void api_sfx_stop(tic_mem* tic, s32 channel)
static void api_sfx_stop(tic_mem* memory, s32 channel)
{
api_sfx(tic, -1, 0, 0, -1, channel);
api_sfx(memory, -1, 0, 0, -1, channel);
}
static void api_music_frame(tic_mem* tic, s32 index, s32 frame, s32 row, bool loop)
static void api_music_frame(tic_mem* memory, s32 index, s32 frame, s32 row, bool loop)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
setMusic(machine, index, frame, row, loop);
@ -1496,11 +1496,11 @@ static void api_sync(tic_mem* tic, u32 mask, s32 bank, bool toCart)
machine->state.synced |= mask;
}
static void cart2ram(tic_mem* tic)
static void cart2ram(tic_mem* memory)
{
api_sync(tic, 0, 0, false);
api_sync(memory, 0, 0, false);
initCover(tic);
initCover(memory);
}
static const char* readMetatag(const char* code, const char* tag, const char* comment)
@ -1595,18 +1595,18 @@ static const tic_script_config* getScriptConfig(const char* code)
#endif
}
static const tic_script_config* api_get_script_config(tic_mem* tic)
static const tic_script_config* api_get_script_config(tic_mem* memory)
{
return getScriptConfig(tic->cart.bank0.code.data);
return getScriptConfig(memory->cart.bank0.code.data);
}
static void updateSaveid(tic_mem* tic)
static void updateSaveid(tic_mem* memory)
{
memset(tic->saveid, 0, sizeof tic->saveid);
const char* saveid = readMetatag(tic->cart.bank0.code.data, "saveid", api_get_script_config(tic)->singleComment);
memset(memory->saveid, 0, sizeof memory->saveid);
const char* saveid = readMetatag(memory->cart.bank0.code.data, "saveid", api_get_script_config(memory)->singleComment);
if(saveid)
{
strncpy(tic->saveid, saveid, TIC_SAVEID_SIZE-1);
strncpy(memory->saveid, saveid, TIC_SAVEID_SIZE-1);
free((void*)saveid);
}
}
@ -1682,25 +1682,25 @@ static void api_tick(tic_mem* tic, tic_tick_data* data)
machine->state.tick(tic);
}
static void api_scanline(tic_mem* tic, s32 row, void* data)
static void api_scanline(tic_mem* memory, s32 row, void* data)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
if(machine->state.initialized)
machine->state.scanline(tic, row, data);
machine->state.scanline(memory, row, data);
}
static void api_overline(tic_mem* tic, void* data)
static void api_overline(tic_mem* memory, void* data)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
if(machine->state.initialized)
machine->state.ovr.callback(tic, data);
machine->state.ovr.callback(memory, data);
}
static double api_time(tic_mem* tic)
static double api_time(tic_mem* memory)
{
tic_machine* machine = (tic_machine*)tic;
tic_machine* machine = (tic_machine*)memory;
return (double)((machine->data->counter() - machine->data->start)*1000)/machine->data->freq();
}

View File

@ -53,6 +53,8 @@
#define TIC_VRAM_SIZE (16*1024) //16K
#define TIC_RAM_SIZE (80*1024) //80K
#define TIC_FONT_WIDTH 6
#define TIC_FONT_HEIGHT 6
#define TIC_PALETTE_BPP 4
#define TIC_PALETTE_SIZE (1 << TIC_PALETTE_BPP)
#define TIC_FRAMERATE 60
@ -109,6 +111,7 @@
#define TIC_GAMEPADS (sizeof(tic80_gamepads) / sizeof(tic80_gamepad))
#define SFX_NOTES {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"}
#define TIC_FONT_CHARS 128
enum
{
@ -350,6 +353,11 @@ typedef struct
tic_cover_image cover;
} tic_cartridge;
typedef struct
{
u8 data[TIC_FONT_CHARS * BITS_IN_BYTE];
} tic_font;
typedef struct
{
u8 data[TIC80_WIDTH * TIC80_HEIGHT * TIC_PALETTE_BPP / BITS_IN_BYTE];

File diff suppressed because one or more lines are too long

View File

@ -24,8 +24,6 @@
#include "tic.h"
#define TIC_FONT_CHARS 128
typedef struct { u8 index; tic_flip flip; tic_rotate rotate; } RemapResult;
typedef void(*RemapFunc)(void*, s32 x, s32 y, RemapResult* result);
typedef struct
@ -176,6 +174,7 @@ struct tic_mem
{
tic_ram ram;
tic_cartridge cart;
tic_font font;
tic_api api;
tic_persistent persistent;
@ -200,13 +199,6 @@ struct tic_mem
} samples;
u32 screen[TIC80_FULLWIDTH * TIC80_FULLHEIGHT];
struct
{
u8 data[TIC_FONT_CHARS * BITS_IN_BYTE];
s32 width;
s32 height;
} font;
};
tic_mem* tic_create(s32 samplerate);