SDL extracted

This commit is contained in:
BADIM-PC\Vadim 2018-02-06 22:15:56 +03:00
parent 28fedc532f
commit 39dfdcfc4f
20 changed files with 1184 additions and 1130 deletions

View File

@ -74,8 +74,8 @@ static void drawCode(Code* code, bool withCursor)
u8* colorPointer = code->colorBuffer;
struct { char* start; char* end; } selection = {SDL_min(code->cursor.selection, code->cursor.position),
SDL_max(code->cursor.selection, code->cursor.position)};
struct { char* start; char* end; } selection = {MIN(code->cursor.selection, code->cursor.position),
MAX(code->cursor.selection, code->cursor.position)};
struct { s32 x; s32 y; char symbol; } cursor = {-1, -1, 0};
@ -425,8 +425,8 @@ static bool replaceSelection(Code* code)
if(sel && sel != pos)
{
char* start = SDL_min(sel, pos);
char* end = SDL_max(sel, pos);
char* start = MIN(sel, pos);
char* end = MAX(sel, pos);
memmove(start, end, strlen(end) + 1);
@ -525,8 +525,8 @@ static void copyToClipboard(Code* code)
if(sel && sel != pos)
{
start = SDL_min(sel, pos);
size = SDL_max(sel, pos) - start;
start = MIN(sel, pos);
size = MAX(sel, pos) - start;
}
else
{
@ -534,14 +534,14 @@ static void copyToClipboard(Code* code)
size = getNextLine(code) - start;
}
char* clipboard = (char*)SDL_malloc(size+1);
char* clipboard = (char*)malloc(size+1);
if(clipboard)
{
memcpy(clipboard, start, size);
clipboard[size] = '\0';
SDL_SetClipboardText(clipboard);
SDL_free(clipboard);
setClipboardText(clipboard);
free(clipboard);
}
}
@ -554,9 +554,9 @@ static void cutToClipboard(Code* code)
static void copyFromClipboard(Code* code)
{
if(SDL_HasClipboardText())
if(hasClipboardText())
{
char* clipboard = SDL_GetClipboardText();
char* clipboard = getClipboardText();
if(clipboard)
{
@ -590,7 +590,7 @@ static void copyFromClipboard(Code* code)
parseSyntaxColor(code);
}
SDL_free(clipboard);
free(clipboard);
}
}
}
@ -633,8 +633,8 @@ static void doTab(Code* code, bool shift, bool crtl)
bool changed = false;
if(cursor_selection) {
start = SDL_min(cursor_selection, cursor_position);
end = SDL_max(cursor_selection, cursor_position);
start = MIN(cursor_selection, cursor_position);
end = MAX(cursor_selection, cursor_position);
} else {
start = end = cursor_position;
}
@ -684,8 +684,8 @@ static void setFindMode(Code* code)
{
if(code->cursor.selection)
{
const char* end = SDL_max(code->cursor.position, code->cursor.selection);
const char* start = SDL_min(code->cursor.position, code->cursor.selection);
const char* end = MAX(code->cursor.position, code->cursor.selection);
const char* start = MIN(code->cursor.position, code->cursor.selection);
size_t len = end - start;
if(len > 0 && len < sizeof code->popup.text - 1)
@ -709,7 +709,8 @@ static int funcCompare(const void* a, const void* b)
if(item1->pos == NULL) return 1;
if(item2->pos == NULL) return -1;
return SDL_strcasecmp(item1->name, item2->name);
// return SDL_strcasecmp(item1->name, item2->name);
return strcmp(item1->name, item2->name);
}
static void normalizeScroll(Code* code)
@ -761,8 +762,10 @@ static void initOutlineMode(Code* code)
char buffer[STUDIO_TEXT_BUFFER_WIDTH] = {0};
char filter[STUDIO_TEXT_BUFFER_WIDTH] = {0};
SDL_strlcpy(filter, code->popup.text, sizeof(filter));
SDL_strlwr(filter);
strncpy(filter, code->popup.text, sizeof(filter));
// TODO: uncomment this
// SDL_strlwr(filter);
const tic_script_config* config = tic->api.get_script_config(tic);
@ -779,12 +782,14 @@ static void initOutlineMode(Code* code)
{
out->pos = code->src + item->pos;
memset(out->name, 0, STUDIO_TEXT_BUFFER_WIDTH);
memcpy(out->name, out->pos, SDL_min(item->size, STUDIO_TEXT_BUFFER_WIDTH-1));
memcpy(out->name, out->pos, MIN(item->size, STUDIO_TEXT_BUFFER_WIDTH-1));
if(*filter)
{
SDL_strlcpy(buffer, out->name, sizeof(buffer));
SDL_strlwr(buffer);
strncpy(buffer, out->name, sizeof(buffer));
// TODO: uncomment this
// SDL_strlwr(buffer);
if(strstr(buffer, filter)) out++;
else out->pos = NULL;
@ -865,106 +870,106 @@ static void commentLine(Code* code)
parseSyntaxColor(code);
}
static void processKeydown(Code* code, SDL_Keycode keycode)
{
switch(keycode)
{
case SDLK_LCTRL:
case SDLK_RCTRL:
case SDLK_LSHIFT:
case SDLK_RSHIFT:
case SDLK_LALT:
case SDLK_RALT:
return;
}
// static void processKeydown(Code* code, tic_keycode keycode)
// {
// switch(keycode)
// {
// case SDLK_LCTRL:
// case SDLK_RCTRL:
// case SDLK_LSHIFT:
// case SDLK_RSHIFT:
// case SDLK_LALT:
// case SDLK_RALT:
// return;
// }
switch(getClipboardEvent(keycode))
{
case TIC_CLIPBOARD_CUT: cutToClipboard(code); break;
case TIC_CLIPBOARD_COPY: copyToClipboard(code); break;
case TIC_CLIPBOARD_PASTE: copyFromClipboard(code); break;
default: break;
}
// switch(getClipboardEvent(keycode))
// {
// case TIC_CLIPBOARD_CUT: cutToClipboard(code); break;
// case TIC_CLIPBOARD_COPY: copyToClipboard(code); break;
// case TIC_CLIPBOARD_PASTE: copyFromClipboard(code); break;
// default: break;
// }
SDL_Keymod keymod = SDL_GetModState();
// SDL_Keymod keymod = SDL_GetModState();
switch(keycode)
{
case SDLK_UP:
case SDLK_DOWN:
case SDLK_LEFT:
case SDLK_RIGHT:
case SDLK_HOME:
case SDLK_END:
case SDLK_PAGEUP:
case SDLK_PAGEDOWN:
// switch(keycode)
// {
// case SDLK_UP:
// case SDLK_DOWN:
// case SDLK_LEFT:
// case SDLK_RIGHT:
// case SDLK_HOME:
// case SDLK_END:
// case SDLK_PAGEUP:
// case SDLK_PAGEDOWN:
if(!(keymod & KMOD_SHIFT)) code->cursor.selection = NULL;
else if(code->cursor.selection == NULL) code->cursor.selection = code->cursor.position;
}
// if(!(keymod & KMOD_SHIFT)) code->cursor.selection = NULL;
// else if(code->cursor.selection == NULL) code->cursor.selection = code->cursor.position;
// }
if(keymod & TIC_MOD_CTRL)
{
if(keymod & KMOD_CTRL)
{
switch(keycode)
{
case SDLK_LEFT: leftWord(code); break;
case SDLK_RIGHT: rightWord(code); break;
case SDLK_TAB: doTab(code, keymod & KMOD_SHIFT, keymod & KMOD_CTRL); break;
}
}
else if(keymod & KMOD_GUI)
{
switch(keycode)
{
case SDLK_LEFT: goHome(code); break;
case SDLK_RIGHT: goEnd(code); break;
}
}
// if(keymod & TIC_MOD_CTRL)
// {
// if(keymod & KMOD_CTRL)
// {
// switch(keycode)
// {
// case SDLK_LEFT: leftWord(code); break;
// case SDLK_RIGHT: rightWord(code); break;
// case SDLK_TAB: doTab(code, keymod & KMOD_SHIFT, keymod & KMOD_CTRL); break;
// }
// }
// else if(keymod & KMOD_GUI)
// {
// switch(keycode)
// {
// case SDLK_LEFT: goHome(code); break;
// case SDLK_RIGHT: goEnd(code); break;
// }
// }
switch(keycode)
{
case SDLK_a: selectAll(code); break;
case SDLK_z: undo(code); break;
case SDLK_y: redo(code); break;
case SDLK_f: setCodeMode(code, TEXT_FIND_MODE); break;
case SDLK_g: setCodeMode(code, TEXT_GOTO_MODE); break;
case SDLK_o: setCodeMode(code, TEXT_OUTLINE_MODE); break;
case SDLK_SLASH: commentLine(code); break;
case SDLK_HOME: goCodeHome(code); break;
case SDLK_END: goCodeEnd(code); break;
}
}
else if(keymod & KMOD_ALT)
{
switch(keycode)
{
case SDLK_LEFT: leftWord(code); break;
case SDLK_RIGHT: rightWord(code); break;
}
}
else
{
switch(keycode)
{
case SDLK_UP: upLine(code); break;
case SDLK_DOWN: downLine(code); break;
case SDLK_LEFT: leftColumn(code); break;
case SDLK_RIGHT: rightColumn(code); break;
case SDLK_HOME: goHome(code); break;
case SDLK_END: goEnd(code); break;
case SDLK_PAGEUP: pageUp(code); break;
case SDLK_PAGEDOWN: pageDown(code); break;
case SDLK_DELETE: deleteChar(code); break;
case SDLK_BACKSPACE: backspaceChar(code); break;
case SDLK_RETURN: newLine(code); break;
case SDLK_TAB: doTab(code, keymod & KMOD_SHIFT, keymod & KMOD_CTRL); break;
}
}
// switch(keycode)
// {
// case SDLK_a: selectAll(code); break;
// case SDLK_z: undo(code); break;
// case SDLK_y: redo(code); break;
// case SDLK_f: setCodeMode(code, TEXT_FIND_MODE); break;
// case SDLK_g: setCodeMode(code, TEXT_GOTO_MODE); break;
// case SDLK_o: setCodeMode(code, TEXT_OUTLINE_MODE); break;
// case SDLK_SLASH: commentLine(code); break;
// case SDLK_HOME: goCodeHome(code); break;
// case SDLK_END: goCodeEnd(code); break;
// }
// }
// else if(keymod & KMOD_ALT)
// {
// switch(keycode)
// {
// case SDLK_LEFT: leftWord(code); break;
// case SDLK_RIGHT: rightWord(code); break;
// }
// }
// else
// {
// switch(keycode)
// {
// case SDLK_UP: upLine(code); break;
// case SDLK_DOWN: downLine(code); break;
// case SDLK_LEFT: leftColumn(code); break;
// case SDLK_RIGHT: rightColumn(code); break;
// case SDLK_HOME: goHome(code); break;
// case SDLK_END: goEnd(code); break;
// case SDLK_PAGEUP: pageUp(code); break;
// case SDLK_PAGEDOWN: pageDown(code); break;
// case SDLK_DELETE: deleteChar(code); break;
// case SDLK_BACKSPACE: backspaceChar(code); break;
// case SDLK_RETURN: newLine(code); break;
// case SDLK_TAB: doTab(code, keymod & KMOD_SHIFT, keymod & KMOD_CTRL); break;
// }
// }
updateEditor(code);
}
// updateEditor(code);
// }
static void processGestures(Code* code)
{
@ -993,7 +998,7 @@ static void processMouse(Code* code)
{
if(checkMousePos(&code->rect))
{
setCursor(SDL_SYSTEM_CURSOR_IBEAM);
setCursor(tic_cursor_ibeam);
if(code->scroll.active)
{
@ -1019,16 +1024,16 @@ static void processMouse(Code* code)
char* position = code->cursor.position;
setCursorPosition(code, x + code->scroll.x, y + code->scroll.y);
if(SDL_GetModState() & KMOD_SHIFT)
{
code->cursor.selection = code->cursor.position;
code->cursor.position = position;
}
else if(!code->cursor.mouseDownPosition)
{
code->cursor.selection = code->cursor.position;
code->cursor.mouseDownPosition = code->cursor.position;
}
// if(SDL_GetModState() & KMOD_SHIFT)
// {
// code->cursor.selection = code->cursor.position;
// code->cursor.position = position;
// }
// else if(!code->cursor.mouseDownPosition)
// {
// code->cursor.selection = code->cursor.position;
// code->cursor.mouseDownPosition = code->cursor.position;
// }
}
else
{
@ -1163,10 +1168,10 @@ static void textFindTick(Code* code)
// case SDLK_RIGHT:
// if(*code->popup.text)
// {
// SDL_Keycode keycode = event->key.keysym.sym;
// tic_keycode keycode = event->key.keysym.sym;
// 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* from = reverse ? MIN(code->cursor.position, code->cursor.selection) : MAX(code->cursor.position, code->cursor.selection);
// char* pos = func(code->src, from, code->popup.text);
// updateFindCode(code, pos);
// }
@ -1285,7 +1290,7 @@ static void drawOutlineBar(Code* code, s32 x, s32 y)
if(mx < OUTLINE_SIZE && code->outline.items[mx].pos)
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, tic_mouse_left))
{
@ -1434,7 +1439,7 @@ static void drawCodeToolbar(Code* code)
bool over = false;
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
showTooltip(Tips[i]);
@ -1516,7 +1521,7 @@ static void onStudioEvent(Code* code, StudioEvent event)
void initCode(Code* code, tic_mem* tic, tic_code* src)
{
if(code->outline.items == NULL)
code->outline.items = (OutlineItem*)SDL_malloc(OUTLINE_ITEMS_SIZE);
code->outline.items = (OutlineItem*)malloc(OUTLINE_ITEMS_SIZE);
if(code->history) history_delete(code->history);
if(code->cursorHistory) history_delete(code->cursorHistory);

View File

@ -228,7 +228,7 @@ static void update(Config* config, const u8* buffer, size_t size)
static void setDefault(Config* config)
{
SDL_memset(&config->data, 0, sizeof(StudioConfig));
memset(&config->data, 0, sizeof(StudioConfig));
{
static const u8 DefaultBiosZip[] =
@ -243,14 +243,14 @@ static void setDefault(Config* config)
{
update(config, embedBios, size);
SDL_free(embedBios);
free(embedBios);
}
}
}
static void saveConfig(Config* config, bool overwrite)
{
u8* buffer = SDL_malloc(sizeof(tic_cartridge));
u8* buffer = malloc(sizeof(tic_cartridge));
if(buffer)
{
@ -258,7 +258,7 @@ static void saveConfig(Config* config, bool overwrite)
fsSaveRootFile(config->fs, CONFIG_TIC_PATH, buffer, size, overwrite);
SDL_free(buffer);
free(buffer);
}
}
@ -270,7 +270,7 @@ static void reset(Config* config)
static void save(Config* config)
{
SDL_memcpy(&config->tic->config, &config->tic->cart, sizeof(tic_cartridge));
memcpy(&config->tic->config, &config->tic->cart, sizeof(tic_cartridge));
readConfig(config);
saveConfig(config, true);
@ -296,7 +296,7 @@ void initConfig(Config* config, tic_mem* tic, FileSystem* fs)
{
update(config, data, size);
SDL_free(data);
free(data);
}
else saveConfig(config, false);

View File

@ -29,6 +29,7 @@
#include <zlib.h>
#include <ctype.h>
#include <string.h>
#define CONSOLE_CURSOR_COLOR ((tic_color_red))
#define CONSOLE_BACK_TEXT_COLOR ((tic_color_dark_gray))
@ -49,7 +50,7 @@ typedef enum
WrenScript,
} ScriptLang;
#if defined(__WINDOWS__) || defined(__LINUX__) || defined(__MACOSX__)
#if defined(__TIC_WINDOWS__) || defined(__LINUX__) || defined(__MACOSX__)
#define CAN_EXPORT 1
#endif
@ -67,7 +68,7 @@ typedef struct
#endif
#if defined(__WINDOWS__)
#if defined(__TIC_WINDOWS__)
static const char* ExeExt = ".exe";
#endif
@ -297,7 +298,7 @@ static void onConsoleExitCommand(Console* console, const char* param)
static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s32 height)
{
s32 size = 0;
gif_color* palette = (gif_color*)SDL_malloc(sizeof(gif_color) * TIC_PALETTE_SIZE);
gif_color* palette = (gif_color*)malloc(sizeof(gif_color) * TIC_PALETTE_SIZE);
if(palette)
{
@ -307,7 +308,7 @@ static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s
gif_write_data(dst, &size, width, height, src, palette, TIC_PALETTE_BPP);
SDL_free(palette);
free(palette);
}
return size;
@ -351,7 +352,7 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param)
for(s32 i = 0; i < COUNT_OF(Sections); i++)
{
sprintf(buf, "%s %s", CART_EXT, Sections[i]);
char* pos = SDL_strstr(param, buf);
char* pos = strstr(param, buf);
if(pos)
{
@ -362,7 +363,7 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param)
if(data)
{
tic_cartridge* cart = (tic_cartridge*)SDL_malloc(sizeof(tic_cartridge));
tic_cartridge* cart = (tic_cartridge*)malloc(sizeof(tic_cartridge));
if(cart)
{
@ -388,12 +389,12 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param)
printFront(console, name);
printLine(console);
SDL_free(cart);
free(cart);
result = true;
}
SDL_free(data);
free(data);
}
else printBack(console, "\ncart loading error");
@ -520,7 +521,7 @@ static void onConsoleLoadDemoCommandConfirmed(Console* console, const char* para
printFront(console, console->romName);
printBack(console, " loaded!\n");
SDL_free(data);
free(data);
}
static void onCartLoaded(Console* console, const char* name)
@ -703,7 +704,7 @@ static bool loadTextSection(const char* project, const char* comment, char* dst,
char tagstart[16];
sprintf(tagstart, "\n%s <", comment);
const char* ptr = SDL_strstr(project, tagstart);
const char* ptr = strstr(project, tagstart);
if(ptr && ptr < end)
end = ptr;
@ -711,7 +712,7 @@ static bool loadTextSection(const char* project, const char* comment, char* dst,
if(end > start)
{
SDL_memcpy(dst, start, SDL_min(size, end - start));
memcpy(dst, start, MIN(size, end - start));
done = true;
}
@ -730,7 +731,7 @@ static bool loadTextSectionBank(const char* project, const char* comment, const
char tagbuf[64];
sprintf(tagbuf, "%s <%s>", comment, tag);
const char* start = SDL_strstr(project, tagbuf);
const char* start = strstr(project, tagbuf);
bool done = false;
if(start)
@ -739,11 +740,11 @@ static bool loadTextSectionBank(const char* project, const char* comment, const
start = getLineEnd(start);
sprintf(tagbuf, "\n%s </%s>", comment, tag);
const char* end = SDL_strstr(start, tagbuf);
const char* end = strstr(start, tagbuf);
if(end > start)
{
SDL_memcpy(dst, start, SDL_min(size, end - start));
memcpy(dst, start, MIN(size, end - start));
done = true;
}
@ -757,7 +758,7 @@ static bool loadBinarySection(const char* project, const char* comment, const ch
char tagbuf[64];
sprintf(tagbuf, "%s <%s>", comment, tag);
const char* start = SDL_strstr(project, tagbuf);
const char* start = strstr(project, tagbuf);
bool done = false;
if(start)
@ -766,7 +767,7 @@ static bool loadBinarySection(const char* project, const char* comment, const ch
start = getLineEnd(start);
sprintf(tagbuf, "\n%s </%s>", comment, tag);
const char* end = SDL_strstr(start, tagbuf);
const char* end = strstr(start, tagbuf);
if(end > start)
{
@ -779,7 +780,7 @@ static bool loadBinarySection(const char* project, const char* comment, const ch
static char lineStr[] = "999";
memcpy(lineStr, ptr + sizeof("-- ") - 1, sizeof lineStr - 1);
s32 index = SDL_atoi(lineStr);
s32 index = atoi(lineStr);
if(index < count)
{
@ -809,13 +810,13 @@ static bool loadProject(Console* console, const char* name, const char* data, s3
{
tic_mem* tic = console->tic;
char* project = (char*)SDL_malloc(size+1);
char* project = (char*)malloc(size+1);
bool done = false;
if(project)
{
SDL_memcpy(project, data, size);
memcpy(project, data, size);
project[size] = '\0';
// remove all the '\r' chars
@ -824,12 +825,12 @@ static bool loadProject(Console* console, const char* name, const char* data, s3
for(s = d = project; (*d = *s); d += (*s++ != '\r'));
}
tic_cartridge* cart = (tic_cartridge*)SDL_malloc(sizeof(tic_cartridge));
tic_cartridge* cart = (tic_cartridge*)malloc(sizeof(tic_cartridge));
if(cart)
{
SDL_memset(cart, 0, sizeof(tic_cartridge));
SDL_memcpy(&cart->palette, &tic->config.palette.data, sizeof(tic_palette));
memset(cart, 0, sizeof(tic_cartridge));
memcpy(&cart->palette, &tic->config.palette.data, sizeof(tic_palette));
const char* comment = projectComment(name);
char tag[16];
@ -864,12 +865,12 @@ static bool loadProject(Console* console, const char* name, const char* data, s3
if(loadBinarySection(project, comment, "COVER", 1, &cart->cover, -1, true))
done = true;
SDL_memcpy(dst, cart, sizeof(tic_cartridge));
memcpy(dst, cart, sizeof(tic_cartridge));
SDL_free(cart);
free(cart);
}
SDL_free(project);
free(project);
}
return done;
@ -886,20 +887,20 @@ static void updateProject(Console* console)
if(data)
{
tic_cartridge* cart = SDL_malloc(sizeof(tic_cartridge));
tic_cartridge* cart = malloc(sizeof(tic_cartridge));
if(cart)
{
if(loadProject(console, console->romName, data, size, cart))
{
SDL_memcpy(&tic->cart, cart, sizeof(tic_cartridge));
memcpy(&tic->cart, cart, sizeof(tic_cartridge));
studioRomLoaded();
}
SDL_free(cart);
free(cart);
}
SDL_free(data);
free(data);
}
}
@ -928,7 +929,7 @@ static void onConsoleLoadCommandConfirmed(Console* console, const char* param)
onCartLoaded(console, name);
SDL_free(data);
free(data);
}
else
{
@ -951,7 +952,7 @@ static void onConsoleLoadCommandConfirmed(Console* console, const char* param)
loadProject(console, name, data, size, &console->tic->cart);
onCartLoaded(console, name);
SDL_free(data);
free(data);
}
else
{
@ -988,16 +989,16 @@ static void onConfirm(bool yes, void* data)
else commandDone(confirmData->console);
if(confirmData->param)
SDL_free(confirmData->param);
free(confirmData->param);
SDL_free(confirmData);
free(confirmData);
}
static void confirmCommand(Console* console, const char** text, s32 rows, const char* param, ConfirmCallback callback)
{
CommandConfirmData* data = SDL_malloc(sizeof(CommandConfirmData));
CommandConfirmData* data = malloc(sizeof(CommandConfirmData));
data->console = console;
data->param = param ? SDL_strdup(param) : NULL;
data->param = param ? strdup(param) : NULL;
data->callback = callback;
showDialog(text, rows, onConfirm, data);
@ -1054,10 +1055,10 @@ static void loadDemo(Console* console, ScriptLang script)
{
loadRom(console->tic, data, size, false);
SDL_free(data);
free(data);
}
SDL_memset(console->romName, 0, sizeof console->romName);
memset(console->romName, 0, sizeof console->romName);
studioRomLoaded();
}
@ -1217,7 +1218,7 @@ static void installDemoCart(FileSystem* fs, const char* name, const void* cart,
u8* data = NULL;
s32 dataSize = unzip(&data, cart, size);
fsSaveFile(fs, name, data, dataSize, true);
SDL_free(data);
free(data);
}
static void onConsoleInstallDemosCommand(Console* console, const char* param)
@ -1391,7 +1392,7 @@ static void onImportCover(const char* name, const void* buffer, size_t size, voi
if(size <= sizeof console->tic->cart.cover.data)
{
console->tic->cart.cover.size = size;
SDL_memcpy(console->tic->cart.cover.data, buffer, size);
memcpy(console->tic->cart.cover.data, buffer, size);
printLine(console);
printBack(console, name);
@ -1434,8 +1435,8 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v
Height = TIC_SPRITESHEET_SIZE*2,
};
s32 w = SDL_min(Width, image->width);
s32 h = SDL_min(Height, image->height);
s32 w = MIN(Width, image->width);
s32 h = MIN(Height, image->height);
for (s32 y = 0; y < h; y++)
for (s32 x = 0; x < w; x++)
@ -1467,8 +1468,8 @@ static void injectMap(Console* console, const void* buffer, s32 size)
{
enum {Size = sizeof(tic_map)};
SDL_memset(getBankMap(), 0, Size);
SDL_memcpy(getBankMap(), buffer, SDL_min(size, Size));
memset(getBankMap(), 0, Size);
memcpy(getBankMap(), buffer, MIN(size, Size));
}
static void onImportMap(const char* name, const void* buffer, size_t size, void* data)
@ -1538,7 +1539,7 @@ static void exportCover(Console* console)
if(cover->size)
{
void* data = SDL_malloc(cover->size);
void* data = malloc(cover->size);
memcpy(data, cover->data, cover->size);
fsGetFileData(onCoverExported, "cover.gif", data, cover->size, DEFAULT_CHMOD, console);
}
@ -1558,11 +1559,11 @@ static void exportSprites(Console* console)
};
enum{ Size = Width * Height * sizeof(gif_color)};
u8* buffer = (u8*)SDL_malloc(Size);
u8* buffer = (u8*)malloc(Size);
if(buffer)
{
u8* data = (u8*)SDL_malloc(Width * Height);
u8* data = (u8*)malloc(Width * Height);
if(data)
{
@ -1580,10 +1581,10 @@ static void exportSprites(Console* console)
{
printError(console, "\nsprite export error :(");
commandDone(console);
SDL_free(buffer);
free(buffer);
}
SDL_free(data);
free(data);
}
}
}
@ -1604,11 +1605,11 @@ static void exportMap(Console* console)
{
enum{Size = sizeof(tic_map)};
void* buffer = SDL_malloc(Size);
void* buffer = malloc(Size);
if(buffer)
{
SDL_memcpy(buffer, getBankMap()->data, Size);
memcpy(buffer, getBankMap()->data, Size);
fsGetFileData(onMapExported, "world.map", buffer, Size, DEFAULT_CHMOD, console);
}
}
@ -1721,14 +1722,14 @@ static void onConsoleExportHtmlCommand(Console* console, const char* name)
if(ptr)
{
MemoryBuffer output = {(u8*)SDL_malloc(EmbedTicJsSize * 2), 0};
MemoryBuffer output = {(u8*)malloc(EmbedTicJsSize * 2), 0};
if(output.data)
{
writeMemoryData(&output, EmbedIndex, ptr - EmbedIndex);
writeMemoryString(&output, "<script type='text/javascript'>\n");
u8* buffer = (u8*)SDL_malloc(sizeof(tic_cartridge));
u8* buffer = (u8*)malloc(sizeof(tic_cartridge));
if(buffer)
{
@ -1741,10 +1742,10 @@ static void onConsoleExportHtmlCommand(Console* console, const char* name)
// zip buffer
{
unsigned long outSize = sizeof(tic_cartridge);
u8* output = (u8*)SDL_malloc(outSize);
u8* output = (u8*)malloc(outSize);
compress2(output, &outSize, buffer, size, Z_BEST_COMPRESSION);
SDL_free(buffer);
free(buffer);
buffer = output;
size = outSize;
@ -1762,7 +1763,7 @@ static void onConsoleExportHtmlCommand(Console* console, const char* name)
}
}
SDL_free(buffer);
free(buffer);
writeMemoryString(&output, "];\n");
@ -1778,8 +1779,8 @@ static void onConsoleExportHtmlCommand(Console* console, const char* name)
}
}
SDL_free(EmbedIndex);
SDL_free(EmbedTicJs);
free(EmbedIndex);
free(EmbedTicJs);
}
#if defined(CAN_EXPORT)
@ -1794,7 +1795,7 @@ static void* embedCart(Console* console, s32* size)
if(app)
{
void* cart = SDL_malloc(sizeof(tic_cartridge));
void* cart = malloc(sizeof(tic_cartridge));
if(cart)
{
@ -1802,7 +1803,7 @@ static void* embedCart(Console* console, s32* size)
{
unsigned long zipSize = sizeof(tic_cartridge);
u8* zip = (u8*)SDL_malloc(zipSize);
u8* zip = (u8*)malloc(zipSize);
if(zip)
{
@ -1815,29 +1816,29 @@ static void* embedCart(Console* console, s32* size)
.cartSize = zipSize,
};
SDL_memcpy(header.sig, TicCartSig, SIG_SIZE);
memcpy(header.sig, TicCartSig, SIG_SIZE);
s32 finalSize = appSize + sizeof header + header.cartSize;
data = SDL_malloc(finalSize);
data = malloc(finalSize);
if(data)
{
SDL_memcpy(data, app, appSize);
SDL_memcpy(data + appSize, &header, sizeof header);
SDL_memcpy(data + appSize + sizeof header, zip, header.cartSize);
memcpy(data, app, appSize);
memcpy(data + appSize, &header, sizeof header);
memcpy(data + appSize + sizeof header, zip, header.cartSize);
*size = finalSize;
}
}
SDL_free(zip);
free(zip);
}
}
SDL_free(cart);
free(cart);
}
SDL_free(app);
free(app);
}
return data;
@ -1870,7 +1871,7 @@ static const char* getExportName(Console* console, bool html)
strcat(name, ".html");
else
{
#if defined(__WINDOWS__)
#if defined(__TIC_WINDOWS__)
strcat(name, ExeExt);
#endif
}
@ -1931,7 +1932,7 @@ static CartSaveResult saveCartName(Console* console, const char* name)
if(name && strlen(name))
{
u8* buffer = (u8*)SDL_malloc(sizeof(tic_cartridge) * 3);
u8* buffer = (u8*)malloc(sizeof(tic_cartridge) * 3);
if(buffer)
{
@ -1966,7 +1967,7 @@ static CartSaveResult saveCartName(Console* console, const char* name)
}
}
SDL_free(buffer);
free(buffer);
}
}
else if (strlen(console->romName))
@ -2277,7 +2278,7 @@ static void processConsoleTab(Console* console)
if(strlen(input))
{
char* param = SDL_strchr(input, ' ');
char* param = strchr(input, ' ');
if(param && strlen(++param))
{
@ -2305,7 +2306,7 @@ static void toUpperStr(char* str)
{
while(*str)
{
*str = SDL_toupper(*str);
*str = toupper(*str);
str++;
}
}
@ -2375,15 +2376,15 @@ static s32 tic_strcasecmp(const char *str1, const char *str2)
char a = 0;
char b = 0;
while (*str1 && *str2) {
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
a = toupper((unsigned char) *str1);
b = toupper((unsigned char) *str2);
if (a != b)
break;
++str1;
++str2;
}
a = SDL_toupper(*str1);
b = SDL_toupper(*str2);
a = toupper(*str1);
b = toupper(*str2);
return (int) ((unsigned char) a - (unsigned char) b);
}
@ -2397,7 +2398,7 @@ static void processCommand(Console* console, const char* command)
while(*end == ' ' && end > command)
*end-- = '\0';
char* param = SDL_strchr(command, ' ');
char* param = strchr(command, ' ');
if(param)
*param++ = '\0';
@ -2458,8 +2459,8 @@ static void onHistoryDown(Console* console)
static void appendHistory(Console* console, const char* value)
{
HistoryItem* item = (HistoryItem*)SDL_malloc(sizeof(HistoryItem));
item->value = SDL_strdup(value);
HistoryItem* item = (HistoryItem*)malloc(sizeof(HistoryItem));
item->value = strdup(value);
item->next = NULL;
item->prev = NULL;
@ -2540,7 +2541,7 @@ static void checkNewVersion(Console* console)
if(net)
{
NetVersion version = netVersionRequest(net);
SDL_free(net);
free(net);
if((version.major > TIC_VERSION_MAJOR) ||
(version.major == TIC_VERSION_MAJOR && version.minor > TIC_VERSION_MINOR) ||
@ -2773,7 +2774,7 @@ static bool cmdLoadCart(Console* console, const char* name)
done = true;
}
SDL_free(data);
free(data);
}
return done;
@ -2796,8 +2797,8 @@ static bool loadFileIntoBuffer(Console* console, char* buffer, const char* fileN
printError(console, messageBuffer);
}
memcpy(buffer, contents, SDL_min(size, TIC_CODE_SIZE-1));
SDL_free(contents);
memcpy(buffer, contents, MIN(size, TIC_CODE_SIZE-1));
free(contents);
return true;
}
@ -2861,8 +2862,8 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na
Height = TIC_SPRITESHEET_SIZE*2,
};
s32 w = SDL_min(Width, image->width);
s32 h = SDL_min(Height, image->height);
s32 w = MIN(Width, image->width);
s32 h = MIN(Height, image->height);
for (s32 y = 0; y < h; y++)
for (s32 x = 0; x < w; x++)
@ -2878,7 +2879,7 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na
gif_close(image);
}
SDL_free(sprites);
free(sprites);
console->embed.yes = true;
console->skipStart = true;
@ -2910,7 +2911,7 @@ static bool cmdInjectMap(Console* console, const char* param, const char* name)
done = true;
}
SDL_free(map);
free(map);
}
}
@ -2919,9 +2920,9 @@ static bool cmdInjectMap(Console* console, const char* param, const char* name)
void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, s32 argc, char **argv)
{
if(!console->buffer) console->buffer = SDL_malloc(CONSOLE_BUFFER_SIZE);
if(!console->colorBuffer) console->colorBuffer = SDL_malloc(CONSOLE_BUFFER_SIZE);
if(!console->embed.file) console->embed.file = SDL_malloc(sizeof(tic_cartridge));
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)
{
@ -2980,7 +2981,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
{
strcpy(console->appPath, argv[0]);
#if defined(__WINDOWS__)
#if defined(__TIC_WINDOWS__)
if(!strstr(console->appPath, ExeExt))
strcat(console->appPath, ExeExt);
#endif
@ -3055,9 +3056,9 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
{
if(~argp & 1 << i)
{
char buf[256];
sprintf(buf, "parameter or file not processed: %s\n", argv[i]);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Warning", buf, NULL);
// char buf[256];
// sprintf(buf, "parameter or file not processed: %s\n", argv[i]);
// SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Warning", buf, NULL);
}
}
}
@ -3089,7 +3090,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
s32 size = unzip(&data, cartPtr, cartSize);
loadCart(tic, console->embed.file, data, size, true);
SDL_free(data);
free(data);
EM_ASM_({Module._free($0);}, cartPtr);
}
@ -3124,7 +3125,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
loadCart(tic, console->embed.file, data, dataSize, true);
console->embed.yes = true;
SDL_free(data);
free(data);
}
break;
@ -3138,7 +3139,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
else break;
}
SDL_free(app);
free(app);
}
}

View File

@ -24,3 +24,5 @@
#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#define STATIC_ASSERT(name, condition) typedef char static_assert_dummy_ ## name[(condition) ? 1 : -1]
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))

View File

@ -34,7 +34,7 @@ static void drawButton(Dialog* dlg, const char* label, s32 x, s32 y, u8 color, u
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
if(checkMouseDown(&rect, tic_mouse_left))
@ -91,29 +91,29 @@ static void onNo(Dialog* dlg)
hideDialog();
}
static void processKeydown(Dialog* dlg, SDL_Keysym* keysum)
{
SDL_Scancode scancode = keysum->scancode;
// static void processKeydown(Dialog* dlg, SDL_Keysym* keysum)
// {
// SDL_Scancode scancode = keysum->scancode;
switch(scancode)
{
case SDL_SCANCODE_LEFT:
dlg->focus = (dlg->focus-1) % 2;
playSystemSfx(2);
break;
case SDL_SCANCODE_RIGHT:
case SDL_SCANCODE_TAB:
dlg->focus = (dlg->focus+1) % 2;
playSystemSfx(2);
break;
case SDL_SCANCODE_RETURN:
case SDL_SCANCODE_SPACE:
dlg->focus == 0 ? onYes(dlg) : onNo(dlg);
break;
default:
break;
}
}
// switch(scancode)
// {
// case SDL_SCANCODE_LEFT:
// dlg->focus = (dlg->focus-1) % 2;
// playSystemSfx(2);
// break;
// case SDL_SCANCODE_RIGHT:
// case SDL_SCANCODE_TAB:
// dlg->focus = (dlg->focus+1) % 2;
// playSystemSfx(2);
// break;
// case SDL_SCANCODE_RETURN:
// case SDL_SCANCODE_SPACE:
// dlg->focus == 0 ? onYes(dlg) : onNo(dlg);
// break;
// default:
// break;
// }
// }
static void drawDialog(Dialog* dlg)
{
@ -130,7 +130,7 @@ static void drawDialog(Dialog* dlg)
if(checkMousePos(&header))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseDown(&header, tic_mouse_left))
{
@ -146,7 +146,7 @@ static void drawDialog(Dialog* dlg)
if(dlg->drag.active)
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
dlg->pos.x = dlg->drag.start.x - getMouseX();
dlg->pos.y = dlg->drag.start.y - getMouseY();
@ -209,7 +209,7 @@ static void tick(Dialog* dlg)
dlg->init = true;
}
SDL_memcpy(dlg->tic->ram.vram.screen.data, dlg->bg, sizeof dlg->tic->ram.vram.screen.data);
memcpy(dlg->tic->ram.vram.screen.data, dlg->bg, sizeof dlg->tic->ram.vram.screen.data);
drawDialog(dlg);
}
@ -245,8 +245,8 @@ void initDialog(Dialog* dlg, tic_mem* tic, const char** text, s32 rows, DialogCa
enum{Size = sizeof tic->ram.vram.screen.data};
if(!dlg->bg)
dlg->bg = SDL_malloc(Size);
dlg->bg = malloc(Size);
if(dlg->bg)
SDL_memcpy(dlg->bg, tic->ram.vram.screen.data, Size);
memcpy(dlg->bg, tic->ram.vram.screen.data, Size);
}

View File

@ -24,7 +24,7 @@
#include <SDL.h>
#if defined(__WINDOWS__)
#if defined(__TIC_WINDOWS__)
#include <windows.h>
#include <commdlg.h>
@ -104,7 +104,7 @@ void file_dialog_save(file_dialog_save_callback callback, const char* name, cons
fwrite(buffer, 1, size, file);
fclose(file);
#if !defined(__WINDOWS__)
#if !defined(__TIC_WINDOWS__)
chmod(filename, mode);
#endif
callback(true, data);

View File

@ -29,7 +29,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#if defined(__WINRT__) || defined(__WINDOWS__)
#if defined(__WINRT__) || defined(__TIC_WINDOWS__)
#include <direct.h>
#include <windows.h>
#else
@ -67,7 +67,7 @@ static const char* getFilePath(FileSystem* fs, const char* name)
strcat(path, name);
#if defined(__WINDOWS__)
#if defined(__TIC_WINDOWS__)
char* ptr = path;
while (*ptr)
{
@ -103,7 +103,7 @@ bool fsIsInPublicDir(FileSystem* fs)
return isPublic(fs);
}
#if defined(__WINDOWS__) || defined(__WINRT__)
#if defined(__TIC_WINDOWS__) || defined(__WINRT__)
#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))
@ -141,7 +141,7 @@ int _wremove(const wchar_t *);
#define tic_stat stat
#define tic_remove remove
#define tic_fopen fopen
#define tic_mkdir(name) mkdir(name, 0700)
#define tic_mkdir(name) mkdir(name)//, 0700)
#define tic_system system
#endif
@ -194,7 +194,7 @@ void fsEnumFiles(FileSystem* fs, ListCallback callback, void* data)
bool fsDeleteDir(FileSystem* fs, const char* name)
{
#if defined(__WINRT__) || defined(__WINDOWS__)
#if defined(__WINRT__) || defined(__TIC_WINDOWS__)
const char* path = getFilePath(fs, name);
bool result = tic_rmdir(UTF8ToString(path));
#else
@ -253,7 +253,7 @@ static void onAddFile(const char* name, const u8* buffer, s32 size, void* data,
fwrite(buffer, 1, size, dest);
fclose(dest);
#if !defined(__WINRT__) && !defined(__WINDOWS__)
#if !defined(__WINRT__) && !defined(__TIC_WINDOWS__)
if(mode)
chmod(path, mode);
#endif
@ -271,12 +271,12 @@ static void onAddFile(const char* name, const u8* buffer, s32 size, void* data,
addFileData->callback(name, FS_FILE_NOT_ADDED, addFileData->data);
}
SDL_free(addFileData);
free(addFileData);
}
void fsAddFile(FileSystem* fs, AddCallback callback, void* data)
{
AddFileData* addFileData = (AddFileData*)SDL_malloc(sizeof(AddFileData));
AddFileData* addFileData = (AddFileData*)malloc(sizeof(AddFileData));
*addFileData = (AddFileData) { fs, callback, data };
@ -296,14 +296,14 @@ static void onGetFile(bool result, void* data)
command->callback(result ? FS_FILE_DOWNLOADED : FS_FILE_NOT_DOWNLOADED, command->data);
SDL_free(command->buffer);
SDL_free(command);
free(command->buffer);
free(command);
}
static u32 fsGetMode(FileSystem* fs, const char* name)
{
#if defined(__WINRT__) || defined(__WINDOWS__)
#if defined(__WINRT__) || defined(__TIC_WINDOWS__)
return 0;
#else
const char* path = getFilePath(fs, name);
@ -409,7 +409,7 @@ bool fsIsDir(FileSystem* fs, const char* name)
void fsGetFileData(GetCallback callback, const char* name, void* buffer, size_t size, u32 mode, void* data)
{
GetFileData* command = (GetFileData*)SDL_malloc(sizeof(GetFileData));
GetFileData* command = (GetFileData*)malloc(sizeof(GetFileData));
*command = (GetFileData) {callback, data, buffer};
file_dialog_save(onGetFile, name, buffer, size, command, mode);
@ -427,12 +427,12 @@ static void onOpenFileData(const char* name, const u8* buffer, s32 size, void* d
command->callback(name, buffer, size, command->data);
SDL_free(command);
free(command);
}
void fsOpenFileData(OpenCallback callback, void* data)
{
OpenFileData* command = (OpenFileData*)SDL_malloc(sizeof(OpenFileData));
OpenFileData* command = (OpenFileData*)malloc(sizeof(OpenFileData));
*command = (OpenFileData){callback, data};
@ -446,7 +446,7 @@ void fsGetFile(FileSystem* fs, GetCallback callback, const char* name, void* dat
if(buffer)
{
GetFileData* command = (GetFileData*)SDL_malloc(sizeof(GetFileData));
GetFileData* command = (GetFileData*)malloc(sizeof(GetFileData));
*command = (GetFileData) {callback, data, buffer};
s32 mode = fsGetMode(fs, name);
@ -489,7 +489,7 @@ bool fsCopyFile(const char* src, const char* dst)
size = ftell(file);
fseek(file, 0, SEEK_SET);
if((buffer = SDL_malloc(size)) && fread(buffer, size, 1, file)) {}
if((buffer = malloc(size)) && fread(buffer, size, 1, file)) {}
fclose(file);
}
@ -507,7 +507,7 @@ bool fsCopyFile(const char* src, const char* dst)
done = true;
}
SDL_free(buffer);
free(buffer);
}
return done;
@ -525,7 +525,7 @@ void* fsReadFile(const char* path, s32* size)
*size = ftell(file);
fseek(file, 0, SEEK_SET);
if((buffer = SDL_malloc(*size)) && fread(buffer, *size, 1, file)) {}
if((buffer = malloc(*size)) && fread(buffer, *size, 1, file)) {}
fclose(file);
}
@ -554,7 +554,7 @@ const char* fsFullname(const char *path)
{
char* result = NULL;
#if defined(__WINDOWS__) || defined(__WINRT__)
#if defined(__TIC_WINDOWS__) || defined(__WINRT__)
static wchar_t wpath[FILENAME_MAX];
GetFullPathNameW(UTF8ToString(path), sizeof(wpath), wpath, NULL);
@ -572,7 +572,7 @@ const char* fsBasename(const char *path)
{
char* result = NULL;
#if defined(__WINDOWS__) || defined(__WINRT__)
#if defined(__TIC_WINDOWS__) || defined(__WINRT__)
#define SEP "\\"
#else
#define SEP "/"
@ -720,7 +720,7 @@ void* fsLoadFile(FileSystem* fs, const char* name, s32* size)
*size = ftell(file);
fseek(file, 0, SEEK_SET);
u8* buffer = SDL_malloc(*size);
u8* buffer = malloc(*size);
if(buffer && fread(buffer, *size, 1, file)) ptr = buffer;
@ -751,13 +751,13 @@ void fsMakeDir(FileSystem* fs, const char* name)
makeDir(getFilePath(fs, name));
}
#if defined(__WINDOWS__) || defined(__LINUX__) || defined(__MACOSX__)
#if defined(__TIC_WINDOWS__) || defined(__LINUX__) || defined(__MACOSX__)
s32 fsOpenSystemPath(FileSystem* fs, const char* path)
{
char command[FILENAME_MAX];
#if defined(__WINDOWS__)
#if defined(__TIC_WINDOWS__)
sprintf(command, "explorer \"%s\"", path);
@ -795,7 +795,7 @@ void fsOpenWorkingFolder(FileSystem* fs)
void createFileSystem(const char* path, void(*callback)(FileSystem*))
{
FileSystem* fs = (FileSystem*)SDL_malloc(sizeof(FileSystem));
FileSystem* fs = (FileSystem*)malloc(sizeof(FileSystem));
memset(fs, 0, sizeof(FileSystem));
fs->net = createNet();
@ -823,7 +823,7 @@ void createFileSystem(const char* path, void(*callback)(FileSystem*))
char* path = SDL_GetPrefPath(TIC_PACKAGE, TIC_NAME);
strcpy(fs->dir, path);
SDL_free(path);
free(path);
#endif

View File

@ -1,6 +1,8 @@
#include "main.h"
#include "studio.h"
#include <SDL.h>
#define STUDIO_UI_SCALE 3
#define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888
#define TEXTURE_SIZE (TIC80_FULLWIDTH)
@ -900,3 +902,32 @@ s32 main(s32 argc, char **argv)
return 0;
}
////////////////////////
void setClipboardText(const char* text)
{
SDL_SetClipboardText(text);
}
bool hasClipboardText()
{
return SDL_HasClipboardText();
}
char* getClipboardText()
{
return SDL_GetClipboardText();
}
u64 getPerformanceCounter()
{
return SDL_GetPerformanceCounter();
}
u64 getPerformanceFrequency()
{
return SDL_GetPerformanceFrequency();
}

144
src/map.c
View File

@ -89,7 +89,7 @@ static s32 drawWorldButton(Map* map, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
@ -127,7 +127,7 @@ static s32 drawGridButton(Map* map, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
@ -175,7 +175,7 @@ static s32 drawSheetButton(Map* map, s32 x, s32 y)
bool over = false;
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
showTooltip("SHOW TILES [shift]");
@ -200,7 +200,7 @@ static s32 drawToolButton(Map* map, s32 x, s32 y, const u8* Icon, s32 width, con
bool over = false;
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
@ -359,7 +359,7 @@ static void drawSheetOvr(Map* map, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, tic_mouse_left))
{
@ -371,10 +371,10 @@ static void drawSheetOvr(Map* map, s32 x, s32 y)
if(map->sheet.drag)
{
s32 rl = SDL_min(mx, map->sheet.start.x);
s32 rt = SDL_min(my, map->sheet.start.y);
s32 rr = SDL_max(mx, map->sheet.start.x);
s32 rb = SDL_max(my, map->sheet.start.y);
s32 rl = MIN(mx, map->sheet.start.x);
s32 rt = MIN(my, map->sheet.start.y);
s32 rr = MAX(mx, map->sheet.start.x);
s32 rb = MAX(my, map->sheet.start.y);
map->sheet.rect = (tic_rect){rl, rt, rr-rl+1, rb-rt+1};
@ -480,7 +480,7 @@ static void processMouseDrawMode(Map* map)
{
tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT};
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
drawTileCursor(map);
@ -508,7 +508,7 @@ static void processMouseDrawMode(Map* map)
map->canvas.draw = false;
}
if(checkMouseDown(&rect, SDL_BUTTON_MIDDLE))
if(checkMouseDown(&rect, tic_mouse_middle))
{
s32 tx = 0, ty = 0;
getMouseMap(map, &tx, &ty);
@ -531,7 +531,7 @@ static void processScrolling(Map* map, bool pressed)
normalizeMap(&map->scroll.x, &map->scroll.y);
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
}
else map->scroll.active = false;
}
@ -597,7 +597,7 @@ static void drawPasteData(Map* map)
history_add(map->history);
SDL_free(map->paste);
free(map->paste);
map->paste = NULL;
}
else
@ -646,10 +646,10 @@ static void processMouseSelectMode(Map* map)
if(map->select.drag)
{
s32 rl = SDL_min(mx, map->select.start.x);
s32 rt = SDL_min(my, map->select.start.y);
s32 rr = SDL_max(mx, map->select.start.x);
s32 rb = SDL_max(my, map->select.start.y);
s32 rl = MIN(mx, map->select.start.x);
s32 rt = MIN(my, map->select.start.y);
s32 rr = MAX(mx, map->select.start.x);
s32 rb = MAX(my, map->select.start.y);
map->select.rect = (tic_rect){rl, rt, rr - rl + 1, rb - rt + 1};
}
@ -732,7 +732,7 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile)
static FillStack stack = {NULL, NULL};
if(!stack.data)
stack.data = (tic_point*)SDL_malloc(FILL_STACK_SIZE * sizeof(tic_point));
stack.data = (tic_point*)malloc(FILL_STACK_SIZE * sizeof(tic_point));
stack.head = NULL;
@ -792,7 +792,7 @@ static void processMouseFillMode(Map* map)
{
tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT};
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
drawTileCursor(map);
@ -938,7 +938,7 @@ static void copySelectionToClipboard(Map* map)
if(sel->w > 0 && sel->h > 0)
{
s32 size = sel->w * sel->h + 2;
u8* buffer = SDL_malloc(size);
u8* buffer = malloc(size);
if(buffer)
{
@ -958,7 +958,7 @@ static void copySelectionToClipboard(Map* map)
}
toClipboard(buffer, size, true);
SDL_free(buffer);
free(buffer);
}
}
}
@ -998,9 +998,9 @@ static void cutToClipboard(Map* map)
static void copyFromClipboard(Map* map)
{
if(SDL_HasClipboardText())
if(hasClipboardText())
{
char* clipboard = SDL_GetClipboardText();
char* clipboard = getClipboardText();
if(clipboard)
{
@ -1008,7 +1008,7 @@ static void copyFromClipboard(Map* map)
if(size > 2)
{
u8* data = SDL_malloc(size);
u8* data = malloc(size);
str2buf(clipboard, strlen(clipboard), data, true);
@ -1017,65 +1017,65 @@ static void copyFromClipboard(Map* map)
map->paste = data;
map->mode = MAP_SELECT_MODE;
}
else SDL_free(data);
else free(data);
}
SDL_free(clipboard);
free(clipboard);
}
}
}
static void processKeydown(Map* map, SDL_Keycode keycode)
{
SDL_Keymod keymod = SDL_GetModState();
// static void processKeydown(Map* map, tic_keycode keycode)
// {
// SDL_Keymod keymod = SDL_GetModState();
switch(getClipboardEvent(keycode))
{
case TIC_CLIPBOARD_CUT: cutToClipboard(map); break;
case TIC_CLIPBOARD_COPY: copyToClipboard(map); break;
case TIC_CLIPBOARD_PASTE: copyFromClipboard(map); break;
default: break;
}
// switch(getClipboardEvent(keycode))
// {
// case TIC_CLIPBOARD_CUT: cutToClipboard(map); break;
// case TIC_CLIPBOARD_COPY: copyToClipboard(map); break;
// case TIC_CLIPBOARD_PASTE: copyFromClipboard(map); break;
// default: break;
// }
if(keymod & TIC_MOD_CTRL)
{
switch(keycode)
{
case SDLK_z: undo(map); break;
case SDLK_y: redo(map); break;
}
}
else
{
switch(keycode)
{
case SDLK_TAB: setStudioMode(TIC_WORLD_MODE); break;
case SDLK_1:
case SDLK_2:
case SDLK_3:
case SDLK_4:
map->mode = keycode - SDLK_1;
break;
case SDLK_DELETE:
deleteSelection(map);
break;
case SDLK_BACKQUOTE:
map->canvas.grid = !map->canvas.grid;
break;
}
}
// if(keymod & TIC_MOD_CTRL)
// {
// switch(keycode)
// {
// case SDLK_z: undo(map); break;
// case SDLK_y: redo(map); break;
// }
// }
// else
// {
// switch(keycode)
// {
// case SDLK_TAB: setStudioMode(TIC_WORLD_MODE); break;
// case SDLK_1:
// case SDLK_2:
// case SDLK_3:
// case SDLK_4:
// map->mode = keycode - SDLK_1;
// break;
// case SDLK_DELETE:
// deleteSelection(map);
// break;
// case SDLK_BACKQUOTE:
// map->canvas.grid = !map->canvas.grid;
// break;
// }
// }
if(keymod & KMOD_SHIFT)
map->sheet.show = true;
}
// if(keymod & KMOD_SHIFT)
// map->sheet.show = true;
// }
static void processKeyup(Map* map, SDL_Keycode keycode)
{
SDL_Keymod keymod = SDL_GetModState();
// static void processKeyup(Map* map, tic_keycode keycode)
// {
// SDL_Keymod keymod = SDL_GetModState();
if(!(keymod & KMOD_SHIFT))
map->sheet.show = false;
}
// if(!(keymod & KMOD_SHIFT))
// map->sheet.show = false;
// }
static void processGesture(Map* map)
{

View File

@ -82,7 +82,7 @@ static void drawDialog(Menu* menu)
if(checkMousePos(&header))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseDown(&header, tic_mouse_left))
{
@ -98,7 +98,7 @@ static void drawDialog(Menu* menu)
if(menu->drag.active)
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
menu->pos.x = menu->drag.start.x - getMouseX();
menu->pos.y = menu->drag.start.y - getMouseY();
@ -138,7 +138,7 @@ static void drawTabDisabled(Menu* menu, s32 x, s32 y, s32 id)
if(menu->gamepad.tab != id && checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
if(checkMouseDown(&rect, tic_mouse_left))
@ -179,47 +179,47 @@ static void drawTab(Menu* menu, s32 x, s32 y, s32 id)
static void drawPlayerButtons(Menu* menu, s32 x, s32 y)
{
tic_mem* tic = menu->tic;
// tic_mem* tic = menu->tic;
u8 chromakey = 0;
// u8 chromakey = 0;
SDL_Scancode* codes = getKeymap();
// SDL_Scancode* codes = getKeymap();
enum {Width = 41, Height = TIC_SPRITESIZE, Rows = 4, Cols = 2, MaxChars = 5, Buttons = 8};
// enum {Width = 41, Height = TIC_SPRITESIZE, Rows = 4, Cols = 2, MaxChars = 5, Buttons = 8};
for(s32 i = 0; i < Buttons; i++)
{
tic_rect rect = {x + i / Rows * (Width+2), y + (i%Rows)*(Height+1), Width, TIC_SPRITESIZE};
bool over = false;
// for(s32 i = 0; i < Buttons; i++)
// {
// tic_rect rect = {x + i / Rows * (Width+2), y + (i%Rows)*(Height+1), Width, TIC_SPRITESIZE};
// bool over = false;
s32 index = i+menu->gamepad.tab * Buttons;
// s32 index = i+menu->gamepad.tab * Buttons;
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
// if(checkMousePos(&rect))
// {
// setCursor(tic_cursor_hand);
over = true;
// over = true;
if(checkMouseClick(&rect, tic_mouse_left))
{
menu->gamepad.selected = menu->gamepad.selected != index ? index : -1;
}
}
// if(checkMouseClick(&rect, tic_mouse_left))
// {
// menu->gamepad.selected = menu->gamepad.selected != index ? index : -1;
// }
// }
if(menu->gamepad.selected == index && menu->ticks % TIC_FRAMERATE < TIC_FRAMERATE / 2)
continue;
// if(menu->gamepad.selected == index && menu->ticks % TIC_FRAMERATE < TIC_FRAMERATE / 2)
// continue;
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);
// 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];
strcpy(label, code ? SDL_GetKeyName(SDL_GetKeyFromScancode(code)) : "...");
// s32 code = codes[index];
// char label[32];
// strcpy(label, code ? SDL_GetKeyName(SDL_GetKeyFromScancode(code)) : "...");
if(strlen(label) > MaxChars)
label[MaxChars] = '\0';
// if(strlen(label) > MaxChars)
// label[MaxChars] = '\0';
tic->api.text(tic, label, rect.x+10, rect.y+2, (over ? tic_color_gray : tic_color_black));
}
// tic->api.text(tic, label, rect.x+10, rect.y+2, (over ? tic_color_gray : tic_color_black));
// }
}
static void drawGamepadSetupTabs(Menu* menu, s32 x, s32 y)
@ -257,7 +257,7 @@ static void drawGamepadMenu(Menu* menu)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
@ -324,7 +324,7 @@ static void drawMainMenu(Menu* menu)
if(checkMousePos(&label))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
@ -432,27 +432,27 @@ static void saveMapping(Menu* menu)
fsSaveRootFile(menu->fs, KEYMAP_DAT_PATH, getKeymap(), KEYMAP_SIZE, true);
}
static void processKeydown(Menu* menu, SDL_Keysym* keysum)
{
if(menu->gamepad.selected < 0)
return;
// static void processKeydown(Menu* menu, SDL_Keysym* keysum)
// {
// if(menu->gamepad.selected < 0)
// return;
SDL_Scancode scancode = keysum->scancode;
// SDL_Scancode scancode = keysum->scancode;
switch(scancode)
{
case SDL_SCANCODE_ESCAPE: break;
default:
{
SDL_Scancode* codes = getKeymap();
codes[menu->gamepad.selected] = scancode;
// switch(scancode)
// {
// case SDL_SCANCODE_ESCAPE: break;
// default:
// {
// SDL_Scancode* codes = getKeymap();
// codes[menu->gamepad.selected] = scancode;
saveMapping(menu);
}
}
// saveMapping(menu);
// }
// }
menu->gamepad.selected = -1;
}
// menu->gamepad.selected = -1;
// }
static void tick(Menu* menu)
{
@ -479,7 +479,7 @@ static void tick(Menu* menu)
menu->init = true;
}
SDL_memcpy(menu->tic->ram.vram.screen.data, menu->bg, sizeof menu->tic->ram.vram.screen.data);
memcpy(menu->tic->ram.vram.screen.data, menu->bg, sizeof menu->tic->ram.vram.screen.data);
switch(menu->mode)
{
@ -525,8 +525,8 @@ void initMenu(Menu* menu, tic_mem* tic, FileSystem* fs)
enum{Size = sizeof tic->ram.vram.screen.data};
if(!menu->bg)
menu->bg = SDL_malloc(Size);
menu->bg = malloc(Size);
if(menu->bg)
SDL_memcpy(menu->bg, tic->ram.vram.screen.data, Size);
memcpy(menu->bg, tic->ram.vram.screen.data, Size);
}

View File

@ -97,7 +97,7 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
bool down = false;
if (checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
if (checkMouseDown(&rect, tic_mouse_left))
@ -117,7 +117,7 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
if (checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if (checkMouseClick(&rect, tic_mouse_left))
{
@ -151,7 +151,7 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
bool down = false;
if (checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
if (checkMouseDown(&rect, tic_mouse_left))
@ -203,7 +203,7 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value,
bool down = false;
if (checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
@ -233,7 +233,7 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value,
bool down = false;
if (checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
@ -565,7 +565,7 @@ static void deleteSelection(Music* music)
}
enum{RowSize = sizeof(tic_track_pattern) / MUSIC_PATTERN_ROWS};
SDL_memset(&pattern->rows[rect.y], 0, RowSize * rect.h);
memset(&pattern->rows[rect.y], 0, RowSize * rect.h);
}
}
@ -593,16 +593,16 @@ static void copyToClipboard(Music* music, bool cut)
enum{RowSize = sizeof(tic_track_pattern) / MUSIC_PATTERN_ROWS, HeaderSize = sizeof(ClipboardHeader)};
s32 size = rect.h * RowSize + HeaderSize;
u8* data = SDL_malloc(size);
u8* data = malloc(size);
if(data)
{
SDL_memcpy(data, &header, HeaderSize);
SDL_memcpy(data + HeaderSize, &pattern->rows[rect.y], RowSize * rect.h);
memcpy(data, &header, HeaderSize);
memcpy(data + HeaderSize, &pattern->rows[rect.y], RowSize * rect.h);
toClipboard(data, size, true);
SDL_free(data);
free(data);
if(cut)
{
@ -619,9 +619,9 @@ static void copyFromClipboard(Music* music)
{
tic_track_pattern* pattern = getChannelPattern(music);
if(pattern && SDL_HasClipboardText())
if(pattern && hasClipboardText())
{
char* clipboard = SDL_GetClipboardText();
char* clipboard = getClipboardText();
if(clipboard)
{
@ -631,27 +631,27 @@ static void copyFromClipboard(Music* music)
if(size > HeaderSize)
{
u8* data = SDL_malloc(size);
u8* data = malloc(size);
str2buf(clipboard, strlen(clipboard), data, true);
ClipboardHeader header = {0};
SDL_memcpy(&header, data, HeaderSize);
memcpy(&header, data, HeaderSize);
if(header.size * RowSize == size - HeaderSize)
{
if(header.size + music->tracker.row > MUSIC_PATTERN_ROWS)
header.size = MUSIC_PATTERN_ROWS - music->tracker.row;
SDL_memcpy(&pattern->rows[music->tracker.row], data + HeaderSize, header.size * RowSize);
memcpy(&pattern->rows[music->tracker.row], data + HeaderSize, header.size * RowSize);
history_add(music->history);
}
SDL_free(data);
free(data);
}
SDL_free(clipboard);
free(clipboard);
}
}
}
@ -726,10 +726,10 @@ static void checkSelection(Music* music)
static void updateSelection(Music* music)
{
s32 rl = SDL_min(music->tracker.col, music->tracker.select.start.x);
s32 rt = SDL_min(music->tracker.row, music->tracker.select.start.y);
s32 rr = SDL_max(music->tracker.col, music->tracker.select.start.x);
s32 rb = SDL_max(music->tracker.row, music->tracker.select.start.y);
s32 rl = MIN(music->tracker.col, music->tracker.select.start.x);
s32 rt = MIN(music->tracker.row, music->tracker.select.start.y);
s32 rr = MAX(music->tracker.col, music->tracker.select.start.x);
s32 rb = MAX(music->tracker.row, music->tracker.select.start.y);
tic_rect* rect = &music->tracker.select.rect;
*rect = (tic_rect){rl, rt, rr - rl + 1, rb - rt + 1};
@ -738,257 +738,257 @@ static void updateSelection(Music* music)
resetSelection(music);
}
static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
{
SDL_Keycode keycode = keysum->sym;
SDL_Scancode scancode = keysum->scancode;
// static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
// {
// tic_keycode keycode = keysum->sym;
// SDL_Scancode scancode = keysum->scancode;
bool shift = SDL_GetModState() & KMOD_SHIFT;
// bool shift = SDL_GetModState() & KMOD_SHIFT;
if(shift)
{
switch (keycode)
{
case SDLK_UP:
case SDLK_DOWN:
case SDLK_LEFT:
case SDLK_RIGHT:
case SDLK_HOME:
case SDLK_END:
case SDLK_PAGEUP:
case SDLK_PAGEDOWN:
case SDLK_TAB:
checkSelection(music);
}
}
// if(shift)
// {
// switch (keycode)
// {
// case SDLK_UP:
// case SDLK_DOWN:
// case SDLK_LEFT:
// case SDLK_RIGHT:
// case SDLK_HOME:
// case SDLK_END:
// case SDLK_PAGEUP:
// case SDLK_PAGEDOWN:
// case SDLK_TAB:
// checkSelection(music);
// }
// }
switch (keycode)
{
case SDLK_UP: upRow(music); break;
case SDLK_DOWN: downRow(music); break;
case SDLK_LEFT: leftCol(music); break;
case SDLK_RIGHT: rightCol(music); break;
case SDLK_HOME: goHome(music); break;
case SDLK_END: goEnd(music); break;
case SDLK_PAGEUP: pageUp(music); break;
case SDLK_PAGEDOWN: pageDown(music); break;
case SDLK_TAB: doTab(music); break;
case SDLK_DELETE:
deleteSelection(music);
history_add(music->history);
downRow(music);
break;
case SDLK_SPACE: playNote(music); break;
case SDLK_RETURN:
case SDLK_KP_ENTER:
{
const tic_music_pos* pos = getMusicPos(music);
pos->track < 0
? (shift ? playFrameRow(music) : playFrame(music))
: stopTrack(music);
}
break;
}
// switch (keycode)
// {
// case SDLK_UP: upRow(music); break;
// case SDLK_DOWN: downRow(music); break;
// case SDLK_LEFT: leftCol(music); break;
// case SDLK_RIGHT: rightCol(music); break;
// case SDLK_HOME: goHome(music); break;
// case SDLK_END: goEnd(music); break;
// case SDLK_PAGEUP: pageUp(music); break;
// case SDLK_PAGEDOWN: pageDown(music); break;
// case SDLK_TAB: doTab(music); break;
// case SDLK_DELETE:
// deleteSelection(music);
// history_add(music->history);
// downRow(music);
// break;
// case SDLK_SPACE: playNote(music); break;
// case SDLK_RETURN:
// case SDLK_KP_ENTER:
// {
// const tic_music_pos* pos = getMusicPos(music);
// pos->track < 0
// ? (shift ? playFrameRow(music) : playFrame(music))
// : stopTrack(music);
// }
// break;
// }
if(shift)
{
switch (keycode)
{
case SDLK_UP:
case SDLK_DOWN:
case SDLK_LEFT:
case SDLK_RIGHT:
case SDLK_HOME:
case SDLK_END:
case SDLK_PAGEUP:
case SDLK_PAGEDOWN:
case SDLK_TAB:
updateSelection(music);
}
}
else resetSelection(music);
// if(shift)
// {
// switch (keycode)
// {
// case SDLK_UP:
// case SDLK_DOWN:
// case SDLK_LEFT:
// case SDLK_RIGHT:
// case SDLK_HOME:
// case SDLK_END:
// case SDLK_PAGEUP:
// case SDLK_PAGEDOWN:
// case SDLK_TAB:
// updateSelection(music);
// }
// }
// else resetSelection(music);
static const SDL_Scancode Piano[] =
{
SDL_SCANCODE_Z,
SDL_SCANCODE_S,
SDL_SCANCODE_X,
SDL_SCANCODE_D,
SDL_SCANCODE_C,
SDL_SCANCODE_V,
SDL_SCANCODE_G,
SDL_SCANCODE_B,
SDL_SCANCODE_H,
SDL_SCANCODE_N,
SDL_SCANCODE_J,
SDL_SCANCODE_M,
// static const SDL_Scancode Piano[] =
// {
// SDL_SCANCODE_Z,
// SDL_SCANCODE_S,
// SDL_SCANCODE_X,
// SDL_SCANCODE_D,
// SDL_SCANCODE_C,
// SDL_SCANCODE_V,
// SDL_SCANCODE_G,
// SDL_SCANCODE_B,
// SDL_SCANCODE_H,
// SDL_SCANCODE_N,
// SDL_SCANCODE_J,
// SDL_SCANCODE_M,
// octave +1
SDL_SCANCODE_Q,
SDL_SCANCODE_2,
SDL_SCANCODE_W,
SDL_SCANCODE_3,
SDL_SCANCODE_E,
SDL_SCANCODE_R,
SDL_SCANCODE_5,
SDL_SCANCODE_T,
SDL_SCANCODE_6,
SDL_SCANCODE_Y,
SDL_SCANCODE_7,
SDL_SCANCODE_U,
};
// // octave +1
// SDL_SCANCODE_Q,
// SDL_SCANCODE_2,
// SDL_SCANCODE_W,
// SDL_SCANCODE_3,
// SDL_SCANCODE_E,
// SDL_SCANCODE_R,
// SDL_SCANCODE_5,
// SDL_SCANCODE_T,
// SDL_SCANCODE_6,
// SDL_SCANCODE_Y,
// SDL_SCANCODE_7,
// SDL_SCANCODE_U,
// };
if (getChannelPattern(music))
{
s32 col = music->tracker.col % CHANNEL_COLS;
// if (getChannelPattern(music))
// {
// s32 col = music->tracker.col % CHANNEL_COLS;
switch (col)
{
case ColumnNote:
case ColumnSemitone:
if (scancode == SDL_SCANCODE_1 || scancode == SDL_SCANCODE_A)
{
setStopNote(music);
downRow(music);
}
else
{
tic_track_pattern* pattern = getChannelPattern(music);
// switch (col)
// {
// case ColumnNote:
// case ColumnSemitone:
// if (scancode == SDL_SCANCODE_1 || scancode == SDL_SCANCODE_A)
// {
// setStopNote(music);
// downRow(music);
// }
// else
// {
// tic_track_pattern* pattern = getChannelPattern(music);
for (s32 i = 0; i < COUNT_OF(Piano); i++)
{
if (scancode == Piano[i])
{
s32 note = i % NOTES;
// for (s32 i = 0; i < COUNT_OF(Piano); i++)
// {
// if (scancode == Piano[i])
// {
// s32 note = i % NOTES;
if(pattern->rows[music->tracker.row].note > NoteNone)
{
pattern->rows[music->tracker.row].note = note + NoteStart;
playNote(music);
}
else
{
s32 octave = i / NOTES + music->tracker.last.octave;
s32 volume = music->tracker.last.volume;
s32 sfx = music->tracker.last.sfx;
setNote(music, note, octave, volume, sfx);
}
// if(pattern->rows[music->tracker.row].note > NoteNone)
// {
// pattern->rows[music->tracker.row].note = note + NoteStart;
// playNote(music);
// }
// else
// {
// s32 octave = i / NOTES + music->tracker.last.octave;
// s32 volume = music->tracker.last.volume;
// s32 sfx = music->tracker.last.sfx;
// setNote(music, note, octave, volume, sfx);
// }
downRow(music);
// downRow(music);
break;
}
// break;
// }
}
}
break;
case ColumnOctave:
if(getNote(music) >= 0)
{
s32 octave = -1;
if (keycode >= SDLK_1 && keycode <= SDLK_8) octave = keycode - SDLK_1;
if (keycode >= SDLK_KP_1 && keycode <= SDLK_KP_8) octave = keycode - SDLK_KP_1;
// }
// }
// break;
// case ColumnOctave:
// if(getNote(music) >= 0)
// {
// s32 octave = -1;
// if (keycode >= SDLK_1 && keycode <= SDLK_8) octave = keycode - SDLK_1;
// if (keycode >= SDLK_KP_1 && keycode <= SDLK_KP_8) octave = keycode - SDLK_KP_1;
if(octave >= 0)
{
setOctave(music, octave);
downRow(music);
}
}
break;
case ColumnSfxHi:
case ColumnSfxLow:
if(getNote(music) >= 0)
{
s32 val = -1;
// if(octave >= 0)
// {
// setOctave(music, octave);
// downRow(music);
// }
// }
// break;
// case ColumnSfxHi:
// case ColumnSfxLow:
// if(getNote(music) >= 0)
// {
// s32 val = -1;
if (keycode >= SDLK_0 && keycode <= SDLK_9) val = keycode - SDLK_0;
if (keycode >= SDLK_KP_1 && keycode <= SDLK_KP_9) val = keycode - SDLK_KP_1 + 1;
if (keycode == SDLK_KP_0) val = 0;
// if (keycode >= SDLK_0 && keycode <= SDLK_9) val = keycode - SDLK_0;
// if (keycode >= SDLK_KP_1 && keycode <= SDLK_KP_9) val = keycode - SDLK_KP_1 + 1;
// if (keycode == SDLK_KP_0) val = 0;
if(val >= 0)
{
enum {Base = 10};
s32 sfx = getSfx(music);
// if(val >= 0)
// {
// enum {Base = 10};
// s32 sfx = getSfx(music);
sfx = col == 3
? val * Base + sfx % Base
: sfx / Base * Base + val % Base;
// sfx = col == 3
// ? val * Base + sfx % Base
// : sfx / Base * Base + val % Base;
setSfx(music, sfx);
// setSfx(music, sfx);
if(col == 3) rightCol(music);
else downRow(music), leftCol(music);
}
}
break;
case ColumnVolume:
if (getNote(music) >= 0)
{
s32 val = -1;
// if(col == 3) rightCol(music);
// else downRow(music), leftCol(music);
// }
// }
// break;
// case ColumnVolume:
// if (getNote(music) >= 0)
// {
// s32 val = -1;
if(keycode >= SDLK_0 && keycode <= SDLK_9) val = keycode - SDLK_0;
if(keycode >= SDLK_a && keycode <= SDLK_f) val = keycode - SDLK_a + 10;
if(keycode >= SDLK_KP_1 && keycode <= SDLK_KP_9) val = keycode - SDLK_KP_1 + 1;
if(keycode == SDLK_KP_0) val = 0;
// if(keycode >= SDLK_0 && keycode <= SDLK_9) val = keycode - SDLK_0;
// if(keycode >= SDLK_a && keycode <= SDLK_f) val = keycode - SDLK_a + 10;
// if(keycode >= SDLK_KP_1 && keycode <= SDLK_KP_9) val = keycode - SDLK_KP_1 + 1;
// if(keycode == SDLK_KP_0) val = 0;
if(val >= 0)
{
setVolume(music, MAX_VOLUME - val);
downRow(music);
}
}
break;
}
// if(val >= 0)
// {
// setVolume(music, MAX_VOLUME - val);
// downRow(music);
// }
// }
// break;
// }
history_add(music->history);
}
}
// history_add(music->history);
// }
// }
static void processPatternKeydown(Music* music, SDL_Keysym* keysum)
{
SDL_Keycode keycode = keysum->sym;
// static void processPatternKeydown(Music* music, SDL_Keysym* keysum)
// {
// tic_keycode keycode = keysum->sym;
s32 channel = music->tracker.col / CHANNEL_COLS;
// s32 channel = music->tracker.col / CHANNEL_COLS;
switch (keycode)
{
case SDLK_DELETE: setChannelPatternValue(music, 0, channel); break;
case SDLK_TAB: nextPattern(music); break;
case SDLK_DOWN:
case SDLK_KP_ENTER:
case SDLK_RETURN: music->tracker.row = music->tracker.scroll; break;
case SDLK_LEFT: patternColLeft(music); break;
case SDLK_RIGHT: patternColRight(music); break;
default:
{
s32 val = -1;
// switch (keycode)
// {
// case SDLK_DELETE: setChannelPatternValue(music, 0, channel); break;
// case SDLK_TAB: nextPattern(music); break;
// case SDLK_DOWN:
// case SDLK_KP_ENTER:
// case SDLK_RETURN: music->tracker.row = music->tracker.scroll; break;
// case SDLK_LEFT: patternColLeft(music); break;
// case SDLK_RIGHT: patternColRight(music); break;
// default:
// {
// s32 val = -1;
if(keycode >= SDLK_0 && keycode <= SDLK_9) val = keycode - SDLK_0;
if(keycode >= SDLK_KP_1 && keycode <= SDLK_KP_9) val = keycode - SDLK_KP_1 + 1;
if(keycode == SDLK_KP_0) val = 0;
// if(keycode >= SDLK_0 && keycode <= SDLK_9) val = keycode - SDLK_0;
// if(keycode >= SDLK_KP_1 && keycode <= SDLK_KP_9) val = keycode - SDLK_KP_1 + 1;
// if(keycode == SDLK_KP_0) val = 0;
if(val >= 0)
{
enum {Base = 10};
s32 patternId = tic_tool_get_pattern_id(getTrack(music), music->tracker.frame, channel);
// if(val >= 0)
// {
// enum {Base = 10};
// s32 patternId = tic_tool_get_pattern_id(getTrack(music), music->tracker.frame, channel);
patternId = music->tracker.patternCol == 0
? val * Base + patternId % Base
: patternId / Base * Base + val % Base;
// patternId = music->tracker.patternCol == 0
// ? val * Base + patternId % Base
// : patternId / Base * Base + val % Base;
if(patternId <= MUSIC_PATTERNS)
{
setChannelPatternValue(music, patternId, channel);
// if(patternId <= MUSIC_PATTERNS)
// {
// setChannelPatternValue(music, patternId, channel);
if(music->tracker.patternCol == 0)
patternColRight(music);
}
}
}
}
}
// if(music->tracker.patternCol == 0)
// patternColRight(music);
// }
// }
// }
// }
// }
static void selectAll(Music* music)
{
@ -1003,45 +1003,45 @@ static void selectAll(Music* music)
updateSelection(music);
}
static void processKeydown(Music* music, SDL_Keysym* keysum)
{
SDL_Keycode keycode = keysum->sym;
// static void processKeydown(Music* music, SDL_Keysym* keysum)
// {
// tic_keycode keycode = keysum->sym;
switch(getClipboardEvent(keycode))
{
case TIC_CLIPBOARD_CUT: copyToClipboard(music, true); break;
case TIC_CLIPBOARD_COPY: copyToClipboard(music, false); break;
case TIC_CLIPBOARD_PASTE: copyFromClipboard(music); break;
default: break;
}
// switch(getClipboardEvent(keycode))
// {
// case TIC_CLIPBOARD_CUT: copyToClipboard(music, true); break;
// case TIC_CLIPBOARD_COPY: copyToClipboard(music, false); break;
// case TIC_CLIPBOARD_PASTE: copyFromClipboard(music); break;
// default: break;
// }
SDL_Keymod keymod = SDL_GetModState();
// SDL_Keymod keymod = SDL_GetModState();
if (keymod & TIC_MOD_CTRL)
{
switch (keycode)
{
case SDLK_a: selectAll(music); break;
case SDLK_z: undo(music); break;
case SDLK_y: redo(music); break;
case SDLK_UP: upFrame(music); break;
case SDLK_DOWN: downFrame(music); break;
}
}
else
{
music->tracker.row >= 0
? processTrackerKeydown(music, keysum)
: processPatternKeydown(music, keysum);
}
}
// if (keymod & TIC_MOD_CTRL)
// {
// switch (keycode)
// {
// case SDLK_a: selectAll(music); break;
// case SDLK_z: undo(music); break;
// case SDLK_y: redo(music); break;
// case SDLK_UP: upFrame(music); break;
// case SDLK_DOWN: downFrame(music); break;
// }
// }
// else
// {
// music->tracker.row >= 0
// ? processTrackerKeydown(music, keysum)
// : processPatternKeydown(music, keysum);
// }
// }
static void processKeyup(Music* music, SDL_Keysym* keysum)
{
music->tracker.note = -1;
s32 channel = music->tracker.col / CHANNEL_COLS;
music->tic->api.sfx_stop(music->tic, channel);
}
// static void processKeyup(Music* music, SDL_Keysym* keysum)
// {
// music->tracker.note = -1;
// s32 channel = music->tracker.col / CHANNEL_COLS;
// music->tic->api.sfx_stop(music->tic, channel);
// }
static void setIndex(Music* music, s32 delta, void* data)
{
@ -1138,7 +1138,7 @@ static void drawTrackerFrames(Music* music, s32 x, s32 y)
if (checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if (checkMouseDown(&rect, tic_mouse_left))
{
@ -1220,7 +1220,7 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, tic_mouse_left))
{
@ -1350,18 +1350,18 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
showTooltip("on/off channel");
if(checkMouseClick(&rect, tic_mouse_left))
{
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];
// 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];
}
}
@ -1444,7 +1444,7 @@ static void drawPlayButtons(Music* music)
if (checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
static const char* Tooltips[] = { "RECORD MUSIC", "PLAY FRAME [enter]", "PLAY TRACK", "STOP [enter]" };
@ -1499,7 +1499,7 @@ static void drawModeTabs(Music* music)
if (checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
static const char* Tooltips[] = { "PIANO MODE", "TRACKER MODE" };

View File

@ -53,7 +53,7 @@ static void getRequest(Net* net, const char* path, NetResponse callback, void* d
static void netClearCache(Net* net)
{
if(net->cache.buffer)
SDL_free(net->cache.buffer);
free(net->cache.buffer);
net->cache.buffer = NULL;
net->cache.size = 0;
@ -95,7 +95,7 @@ static Buffer httpRequest(const char* path, s32 timeout)
if(SDLNet_CheckSockets(set, timeout) == 1 && SDLNet_SocketReady(sock))
{
enum {Size = 4*1024+1};
buffer.data = SDL_malloc(Size);
buffer.data = malloc(Size);
s32 size = 0;
for(;;)
@ -105,7 +105,7 @@ static Buffer httpRequest(const char* path, s32 timeout)
if(size > 0)
{
buffer.size += size;
buffer.data = SDL_realloc(buffer.data, buffer.size + Size);
buffer.data = realloc(buffer.data, buffer.size + Size);
}
else break;
}
@ -141,34 +141,34 @@ static void getRequest(Net* net, const char* path, NetResponse callback, void* d
if(buffer.data && buffer.size)
{
if(SDL_strstr((char*)buffer.data, "200 OK"))
if(strstr((char*)buffer.data, "200 OK"))
{
s32 contentLength = 0;
{
static const char ContentLength[] = "Content-Length:";
char* start = SDL_strstr((char*)buffer.data, ContentLength);
char* start = strstr((char*)buffer.data, ContentLength);
if(start)
contentLength = SDL_atoi(start + sizeof(ContentLength));
contentLength = atoi(start + sizeof(ContentLength));
}
static const char Start[] = "\r\n\r\n";
u8* start = (u8*)SDL_strstr((char*)buffer.data, Start);
u8* start = (u8*)strstr((char*)buffer.data, Start);
if(start)
{
strcpy(net->cache.path, path);
net->cache.size = contentLength ? contentLength : buffer.size - (s32)(start - buffer.data);
net->cache.buffer = (u8*)SDL_malloc(net->cache.size);
SDL_memcpy(net->cache.buffer, start + sizeof Start - 1, net->cache.size);
net->cache.buffer = (u8*)malloc(net->cache.size);
memcpy(net->cache.buffer, start + sizeof Start - 1, net->cache.size);
callback(net->cache.buffer, net->cache.size, data);
done = true;
}
}
SDL_free(buffer.data);
free(buffer.data);
}
if(!done)
@ -306,9 +306,9 @@ static void onGetResponse(u8* buffer, s32 size, void* data)
{
NetGetData* netGetData = (NetGetData*)data;
netGetData->buffer = SDL_malloc(size);
netGetData->buffer = malloc(size);
*netGetData->size = size;
SDL_memcpy(netGetData->buffer, buffer, size);
memcpy(netGetData->buffer, buffer, size);
}
void* netGetRequest(Net* net, const char* path, s32* size)
@ -360,7 +360,7 @@ Net* createNet()
{
SDLNet_Init();
Net* net = (Net*)SDL_malloc(sizeof(Net));
Net* net = (Net*)malloc(sizeof(Net));
*net = (Net)
{
@ -377,7 +377,7 @@ Net* createNet()
void closeNet(Net* net)
{
SDL_free(net);
free(net);
SDLNet_Quit();
}

View File

@ -95,10 +95,10 @@ static void tick(Run* run)
enum {Size = sizeof(tic_persistent)};
if(SDL_memcmp(&run->tic->persistent, &run->persistent, Size) != 0)
if(memcmp(&run->tic->persistent, &run->persistent, Size) != 0)
{
fsSaveRootFile(run->console->fs, run->saveid, &run->tic->persistent, Size, true);
SDL_memcpy(&run->persistent, &run->tic->persistent, Size);
memcpy(&run->persistent, &run->tic->persistent, Size);
}
if(run->exit)
@ -139,7 +139,7 @@ static void processDoFile(void* data, char* dst)
return;
}
else SDL_memcpy(dst, buffer, size);
else memcpy(dst, buffer, size);
}
}
else
@ -186,8 +186,8 @@ void initRun(Run* run, Console* console, tic_mem* tic)
{
.error = onError,
.trace = onTrace,
.counter = SDL_GetPerformanceCounter,
.freq = SDL_GetPerformanceFrequency,
.counter = getPerformanceCounter,
.freq = getPerformanceFrequency,
.start = 0,
.data = run,
.exit = onExit,
@ -198,7 +198,7 @@ void initRun(Run* run, Console* console, tic_mem* tic)
{
enum {Size = sizeof(tic_persistent)};
SDL_memset(&run->tic->persistent, 0, Size);
memset(&run->tic->persistent, 0, Size);
initPMemName(run);
@ -209,11 +209,11 @@ void initRun(Run* run, Console* console, tic_mem* tic)
if(data)
{
SDL_memcpy(&run->tic->persistent, data, size);
SDL_memcpy(&run->persistent, data, size);
memcpy(&run->tic->persistent, data, size);
memcpy(&run->persistent, data, size);
}
if(data) SDL_free(data);
if(data) free(data);
}
preseed();

204
src/sfx.c
View File

@ -72,7 +72,7 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, tic_mouse_left))
set(sfx, -1);
@ -94,7 +94,7 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, tic_mouse_left))
set(sfx, +1);
@ -213,7 +213,7 @@ static void drawWaveButtons(Sfx* sfx, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
if(checkMouseClick(&rect, tic_mouse_left))
@ -243,7 +243,7 @@ static void drawWaveButtons(Sfx* sfx, s32 x, s32 y)
bool over = false;
if(checkMousePos(&iconRect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
if(checkMouseClick(&iconRect, tic_mouse_left))
@ -299,7 +299,7 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, tic_mouse_left))
{
@ -322,7 +322,7 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, tic_mouse_left))
effect->pitch16x++;
@ -339,7 +339,7 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, tic_mouse_left))
effect->reverse++;
@ -376,7 +376,7 @@ static void drawCanvas(Sfx* sfx, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
s32 mx = getMouseX() - x;
s32 my = getMouseY() - y;
@ -420,7 +420,7 @@ static void drawCanvas(Sfx* sfx, s32 x, s32 y)
break;
case SFX_PITCH_TAB:
{
for(s32 j = SDL_min(0, effect->data[i].pitch); j <= SDL_max(0, effect->data[i].pitch); j++)
for(s32 j = MIN(0, effect->data[i].pitch); j <= MAX(0, effect->data[i].pitch); j++)
sfx->tic->api.rect(sfx->tic, x + i * CANVAS_SIZE + 1, y + 1 + (CANVAS_HEIGHT/2 - (j+1)*CANVAS_SIZE),
CANVAS_SIZE-1, CANVAS_SIZE-1, (tic_color_red));
}
@ -464,7 +464,7 @@ static void drawPiano(Sfx* sfx, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
static const char* Tooltips[] = {"C [z]", "C# [s]", "D [x]", "D# [d]", "E [c]", "F [v]", "F# [g]", "G [b]", "G# [h]", "A [n]", "A# [j]", "B [m]" };
@ -529,7 +529,7 @@ static void drawOctavePanel(Sfx* sfx, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, tic_mouse_left))
{
@ -629,110 +629,110 @@ static void copyWaveFromClipboard(Sfx* sfx)
static void processKeyboard(Sfx* sfx)
{
s32 keyboardButton = -1;
// s32 keyboardButton = -1;
static const s32 Keycodes[] =
{
tic_key_z,
tic_key_s,
tic_key_x,
tic_key_d,
tic_key_c,
tic_key_v,
tic_key_g,
tic_key_b,
tic_key_h,
tic_key_n,
tic_key_j,
tic_key_m,
};
// static const s32 Keycodes[] =
// {
// tic_key_z,
// tic_key_s,
// tic_key_x,
// tic_key_d,
// tic_key_c,
// tic_key_v,
// tic_key_g,
// tic_key_b,
// tic_key_h,
// tic_key_n,
// tic_key_j,
// tic_key_m,
// };
tic_mem* tic = sfx->tic;
// tic_mem* tic = sfx->tic;
SDL_Keymod keymod = SDL_GetModState();
// SDL_Keymod keymod = SDL_GetModState();
if(keymod & TIC_MOD_CTRL)
{
// if(keymod & TIC_MOD_CTRL)
// {
}
else
{
for(int i = 0; i < COUNT_OF(Keycodes); i++)
if(tic->api.key(tic, Keycodes[i]))
keyboardButton = i;
}
// }
// else
// {
// for(int i = 0; i < COUNT_OF(Keycodes); i++)
// if(tic->api.key(tic, Keycodes[i]))
// keyboardButton = i;
// }
tic_sample* effect = getEffect(sfx);
// tic_sample* effect = getEffect(sfx);
if(keyboardButton >= 0)
{
effect->note = keyboardButton;
sfx->play.active = true;
}
// if(keyboardButton >= 0)
// {
// effect->note = keyboardButton;
// sfx->play.active = true;
// }
if(tic->api.key(tic, tic_key_space))
sfx->play.active = true;
// if(tic->api.key(tic, tic_key_space))
// sfx->play.active = true;
}
static void processKeydown(Sfx* sfx, SDL_Keycode keycode)
{
switch(getClipboardEvent(keycode))
{
case TIC_CLIPBOARD_CUT: cutToClipboard(sfx); break;
case TIC_CLIPBOARD_COPY: copyToClipboard(sfx); break;
case TIC_CLIPBOARD_PASTE: copyFromClipboard(sfx); break;
default: break;
}
// static void processKeydown(Sfx* sfx, tic_keycode keycode)
// {
// switch(getClipboardEvent(keycode))
// {
// case TIC_CLIPBOARD_CUT: cutToClipboard(sfx); break;
// case TIC_CLIPBOARD_COPY: copyToClipboard(sfx); break;
// case TIC_CLIPBOARD_PASTE: copyFromClipboard(sfx); break;
// default: break;
// }
SDL_Keymod keymod = SDL_GetModState();
// SDL_Keymod keymod = SDL_GetModState();
if(keymod & TIC_MOD_CTRL)
{
switch(keycode)
{
case SDLK_z: undo(sfx); break;
case SDLK_y: redo(sfx); break;
}
}
// if(keymod & TIC_MOD_CTRL)
// {
// switch(keycode)
// {
// case SDLK_z: undo(sfx); break;
// case SDLK_y: redo(sfx); break;
// }
// }
switch(keycode)
{
case SDLK_TAB: sfx->tab = SFX_WAVEFORM_TAB; break;
case SDLK_LEFT: sfx->index--; break;
case SDLK_RIGHT: sfx->index++; break;
case SDLK_DELETE: resetSfx(sfx); break;
}
}
// switch(keycode)
// {
// case SDLK_TAB: sfx->tab = SFX_WAVEFORM_TAB; break;
// case SDLK_LEFT: sfx->index--; break;
// case SDLK_RIGHT: sfx->index++; break;
// case SDLK_DELETE: resetSfx(sfx); break;
// }
// }
static void processWaveformKeydown(Sfx* sfx, SDL_Keycode keycode)
{
switch(getClipboardEvent(keycode))
{
case TIC_CLIPBOARD_CUT: cutWaveToClipboard(sfx); break;
case TIC_CLIPBOARD_COPY: copyWaveToClipboard(sfx); break;
case TIC_CLIPBOARD_PASTE: copyWaveFromClipboard(sfx); break;
default: break;
}
// static void processWaveformKeydown(Sfx* sfx, tic_keycode keycode)
// {
// switch(getClipboardEvent(keycode))
// {
// case TIC_CLIPBOARD_CUT: cutWaveToClipboard(sfx); break;
// case TIC_CLIPBOARD_COPY: copyWaveToClipboard(sfx); break;
// case TIC_CLIPBOARD_PASTE: copyWaveFromClipboard(sfx); break;
// default: break;
// }
SDL_Keymod keymod = SDL_GetModState();
// SDL_Keymod keymod = SDL_GetModState();
if(keymod & TIC_MOD_CTRL)
{
switch(keycode)
{
case SDLK_z: undo(sfx); break;
case SDLK_y: redo(sfx); break;
}
}
// if(keymod & TIC_MOD_CTRL)
// {
// switch(keycode)
// {
// case SDLK_z: undo(sfx); break;
// case SDLK_y: redo(sfx); break;
// }
// }
switch(keycode)
{
case SDLK_TAB: sfx->tab = SFX_ENVELOPES_TAB; break;
case SDLK_LEFT: sfx->waveform.index--; break;
case SDLK_RIGHT: sfx->waveform.index++; break;
case SDLK_DELETE: resetWave(sfx); break;
}
}
// switch(keycode)
// {
// case SDLK_TAB: sfx->tab = SFX_ENVELOPES_TAB; break;
// case SDLK_LEFT: sfx->waveform.index--; break;
// case SDLK_RIGHT: sfx->waveform.index++; break;
// case SDLK_DELETE: resetWave(sfx); break;
// }
// }
static void drawModeTabs(Sfx* sfx)
{
@ -769,7 +769,7 @@ static void drawModeTabs(Sfx* sfx)
if (checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
static const char* Tooltips[] = { "WAVEFORMS [tab]", "ENVELOPES [tab]" };
@ -799,7 +799,7 @@ static void drawSfxToolbar(Sfx* sfx)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
showTooltip("PLAY SFX [space]");
@ -875,7 +875,7 @@ static void drawWaveformBar(Sfx* sfx, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, tic_mouse_left))
sfx->waveform.index = i;
@ -923,7 +923,7 @@ static void drawWaveformCanvas(Sfx* sfx, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, tic_mouse_left))
{

View File

@ -33,7 +33,7 @@
static void clearCanvasSelection(Sprite* sprite)
{
SDL_memset(&sprite->select.rect, 0, sizeof(tic_rect));
memset(&sprite->select.rect, 0, sizeof(tic_rect));
}
static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y)
@ -91,7 +91,7 @@ static void processPickerCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 s
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
s32 mx = getMouseX() - x;
s32 my = getMouseY() - y;
@ -116,7 +116,7 @@ static void processDrawCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 sy)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
s32 mx = getMouseX() - x;
s32 my = getMouseY() - y;
@ -193,7 +193,7 @@ static void copySelection(Sprite* sprite)
{
tic_rect* rect = &sprite->select.rect;
SDL_memset(sprite->select.front, 0, CANVAS_SIZE * CANVAS_SIZE);
memset(sprite->select.front, 0, CANVAS_SIZE * CANVAS_SIZE);
for(s32 j = rect->y, index = 0; j < (rect->y + rect->h); j++)
for(s32 i = rect->x; i < (rect->x + rect->w); i++)
@ -212,7 +212,7 @@ static void processSelectCanvasMouse(Sprite* sprite, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
s32 mx = getMouseX() - x;
s32 my = getMouseY() - y;
@ -229,10 +229,10 @@ static void processSelectCanvasMouse(Sprite* sprite, s32 x, s32 y)
s32 x = mx / Size;
s32 y = my / Size;
s32 rl = SDL_min(x, sprite->select.start.x);
s32 rt = SDL_min(y, sprite->select.start.y);
s32 rr = SDL_max(x, sprite->select.start.x);
s32 rb = SDL_max(y, sprite->select.start.y);
s32 rl = MIN(x, sprite->select.start.x);
s32 rt = MIN(y, sprite->select.start.y);
s32 rr = MAX(x, sprite->select.start.x);
s32 rb = MAX(y, sprite->select.start.y);
sprite->select.rect = (tic_rect){rl, rt, rr - rl + 1, rb - rt + 1};
}
@ -279,7 +279,7 @@ static void processFillCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 l, s32 t)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
s32 mx = getMouseX() - x;
s32 my = getMouseY() - y;
@ -294,20 +294,20 @@ static void processFillCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 l, s32 t)
if(left || right)
{
s32 sx = l + mx / Size;
s32 sy = t + my / Size;
// s32 sx = l + mx / Size;
// s32 sy = t + my / Size;
u8 color = getSheetPixel(sprite, sx, sy);
u8 fill = left ? sprite->color : sprite->color2;
// u8 color = getSheetPixel(sprite, sx, sy);
// u8 fill = left ? sprite->color : sprite->color2;
if(color != fill)
{
SDL_Keymod keymod = SDL_GetModState();
// if(color != fill)
// {
// SDL_Keymod keymod = SDL_GetModState();
keymod & TIC_MOD_CTRL
? replaceColor(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill)
: floodFill(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill);
}
// keymod & TIC_MOD_CTRL
// ? replaceColor(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill)
// : floodFill(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill);
// }
history_add(sprite->history);
}
@ -328,7 +328,7 @@ static void drawBrushSlider(Sprite* sprite, s32 x, s32 y)
bool over = false;
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
showTooltip("BRUSH SIZE");
over = true;
@ -415,7 +415,7 @@ static void drawCanvasOvr(Sprite* sprite, s32 x, s32 y)
}
tic_rect canvasRect = {x, y, CANVAS_SIZE, CANVAS_SIZE};
if(checkMouseDown(&canvasRect, SDL_BUTTON_MIDDLE))
if(checkMouseDown(&canvasRect, tic_mouse_middle))
{
s32 mx = getMouseX() - x;
s32 my = getMouseY() - y;
@ -483,7 +483,7 @@ static void rotateSelectRect(Sprite* sprite)
static void rotateCanvas(Sprite* sprite)
{
u8* buffer = (u8*)SDL_malloc(CANVAS_SIZE*CANVAS_SIZE);
u8* buffer = (u8*)malloc(CANVAS_SIZE*CANVAS_SIZE);
if(buffer)
{
@ -507,7 +507,7 @@ static void rotateCanvas(Sprite* sprite)
history_add(sprite->history);
}
SDL_free(buffer);
free(buffer);
}
}
@ -636,7 +636,7 @@ static void drawMoveButtons(Sprite* sprite)
if(checkMousePos(&Rects[i]))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseDown(&Rects[i], tic_mouse_left)) down = true;
@ -672,7 +672,7 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, tic_mouse_left))
{
@ -715,7 +715,7 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value)
bool down = false;
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, tic_mouse_left))
down = true;
@ -753,7 +753,7 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value)
bool down = false;
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, tic_mouse_left))
down = true;
@ -803,7 +803,7 @@ static void drawRGBTools(Sprite* sprite, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
showTooltip("COPY PALETTE");
over = true;
@ -846,7 +846,7 @@ static void drawRGBTools(Sprite* sprite, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
showTooltip("PASTE PALETTE");
over = true;
@ -902,7 +902,7 @@ static void drawPalette(Sprite* sprite, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
bool left = checkMouseDown(&rect, tic_mouse_left);
bool right = checkMouseDown(&rect, tic_mouse_right);
@ -952,7 +952,7 @@ static void drawPalette(Sprite* sprite, s32 x, s32 y)
bool over = false;
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
showTooltip("EDIT PALETTE");
@ -1047,7 +1047,7 @@ static void drawSheet(Sprite* sprite, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, tic_mouse_left))
{
@ -1109,7 +1109,7 @@ static void flipSpriteVert(Sprite* sprite)
static void rotateSprite(Sprite* sprite)
{
const s32 Size = sprite->size;
u8* buffer = (u8*)SDL_malloc(Size * Size);
u8* buffer = (u8*)malloc(Size * Size);
if(buffer)
{
@ -1129,7 +1129,7 @@ static void rotateSprite(Sprite* sprite)
history_add(sprite->history);
}
SDL_free(buffer);
free(buffer);
}
}
@ -1204,7 +1204,7 @@ static void drawSpriteTools(Sprite* sprite, s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
@ -1288,7 +1288,7 @@ static void drawTools(Sprite* sprite, s32 x, s32 y)
bool over = false;
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
static const char* Tooltips[] = {"BRUSH [1]", "COLOR PICKER [2]", "SELECT [3]", "FILL [4]"};
@ -1337,7 +1337,7 @@ static void drawTools(Sprite* sprite, s32 x, s32 y)
static void copyToClipboard(Sprite* sprite)
{
s32 size = sprite->size * sprite->size * TIC_PALETTE_BPP / BITS_IN_BYTE;
u8* buffer = SDL_malloc(size);
u8* buffer = malloc(size);
if(buffer)
{
@ -1351,7 +1351,7 @@ static void copyToClipboard(Sprite* sprite)
toClipboard(buffer, size, true);
SDL_free(buffer);
free(buffer);
}
}
@ -1367,7 +1367,7 @@ static void copyFromClipboard(Sprite* sprite)
pasteColor(sprite);
s32 size = sprite->size * sprite->size * TIC_PALETTE_BPP / BITS_IN_BYTE;
u8* buffer = SDL_malloc(size);
u8* buffer = malloc(size);
if(buffer)
{
@ -1384,7 +1384,7 @@ static void copyFromClipboard(Sprite* sprite)
history_add(sprite->history);
}
SDL_free(buffer);
free(buffer);
}
}
@ -1428,81 +1428,81 @@ static void switchBanks(Sprite* sprite)
clearCanvasSelection(sprite);
}
static void processKeydown(Sprite* sprite, SDL_Keycode keycode)
{
switch(getClipboardEvent(keycode))
{
case TIC_CLIPBOARD_CUT: cutToClipboard(sprite); break;
case TIC_CLIPBOARD_COPY: copyToClipboard(sprite); break;
case TIC_CLIPBOARD_PASTE: copyFromClipboard(sprite); break;
default: break;
}
// static void processKeydown(Sprite* sprite, tic_keycode keycode)
// {
// switch(getClipboardEvent(keycode))
// {
// case TIC_CLIPBOARD_CUT: cutToClipboard(sprite); break;
// case TIC_CLIPBOARD_COPY: copyToClipboard(sprite); break;
// case TIC_CLIPBOARD_PASTE: copyFromClipboard(sprite); break;
// default: break;
// }
SDL_Keymod keymod = SDL_GetModState();
// SDL_Keymod keymod = SDL_GetModState();
if(keymod & TIC_MOD_CTRL)
{
switch(keycode)
{
case SDLK_z: undo(sprite); break;
case SDLK_y: redo(sprite); break;
}
}
else
{
if(hasCanvasSelection(sprite))
{
switch(keycode)
{
case SDLK_UP: upCanvas(sprite); break;
case SDLK_DOWN: downCanvas(sprite); break;
case SDLK_LEFT: leftCanvas(sprite); break;
case SDLK_RIGHT: rightCanvas(sprite); break;
case SDLK_DELETE: deleteCanvas(sprite); break;
}
}
else
{
switch(keycode)
{
case SDLK_DELETE: deleteSprite(sprite); break;
case SDLK_UP: upSprite(sprite); break;
case SDLK_DOWN: downSprite(sprite); break;
case SDLK_LEFT: leftSprite(sprite); break;
case SDLK_RIGHT: rightSprite(sprite); break;
case SDLK_TAB: switchBanks(sprite); break;
}
// if(keymod & TIC_MOD_CTRL)
// {
// switch(keycode)
// {
// case SDLK_z: undo(sprite); break;
// case SDLK_y: redo(sprite); break;
// }
// }
// else
// {
// if(hasCanvasSelection(sprite))
// {
// switch(keycode)
// {
// case SDLK_UP: upCanvas(sprite); break;
// case SDLK_DOWN: downCanvas(sprite); break;
// case SDLK_LEFT: leftCanvas(sprite); break;
// case SDLK_RIGHT: rightCanvas(sprite); break;
// case SDLK_DELETE: deleteCanvas(sprite); break;
// }
// }
// else
// {
// switch(keycode)
// {
// case SDLK_DELETE: deleteSprite(sprite); break;
// case SDLK_UP: upSprite(sprite); break;
// case SDLK_DOWN: downSprite(sprite); break;
// case SDLK_LEFT: leftSprite(sprite); break;
// case SDLK_RIGHT: rightSprite(sprite); break;
// case SDLK_TAB: switchBanks(sprite); break;
// }
if(!sprite->editPalette)
{
switch(keycode)
{
case SDLK_1:
case SDLK_2:
case SDLK_3:
case SDLK_4:
sprite->mode = keycode - SDLK_1;
break;
case SDLK_5:
case SDLK_6:
case SDLK_7:
case SDLK_8:
SpriteToolsFunc[keycode - SDLK_5](sprite);
break;
}
// if(!sprite->editPalette)
// {
// switch(keycode)
// {
// case SDLK_1:
// case SDLK_2:
// case SDLK_3:
// case SDLK_4:
// sprite->mode = keycode - SDLK_1;
// break;
// case SDLK_5:
// case SDLK_6:
// case SDLK_7:
// case SDLK_8:
// SpriteToolsFunc[keycode - SDLK_5](sprite);
// break;
// }
if(sprite->mode == SPRITE_DRAW_MODE)
{
switch(keycode)
{
case SDLK_LEFTBRACKET: if(sprite->brushSize > 1) sprite->brushSize--; break;
case SDLK_RIGHTBRACKET: if(sprite->brushSize < 4) sprite->brushSize++; break;
}
}
}
}
}
}
// if(sprite->mode == SPRITE_DRAW_MODE)
// {
// switch(keycode)
// {
// case SDLK_LEFTBRACKET: if(sprite->brushSize > 1) sprite->brushSize--; break;
// case SDLK_RIGHTBRACKET: if(sprite->brushSize < 4) sprite->brushSize++; break;
// }
// }
// }
// }
// }
// }
static void drawSpriteToolbar(Sprite* sprite)
{
@ -1514,7 +1514,7 @@ static void drawSpriteToolbar(Sprite* sprite)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
showTooltip("CANVAS ZOOM");
@ -1553,7 +1553,7 @@ static void drawSpriteToolbar(Sprite* sprite)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
showTooltip("TILES [tab]");
@ -1573,7 +1573,7 @@ static void drawSpriteToolbar(Sprite* sprite)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
showTooltip("SPRITES [tab]");
@ -1658,8 +1658,8 @@ static void overlap(tic_mem* tic, void* data)
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);
if(sprite->select.back == NULL) sprite->select.back = (u8*)malloc(CANVAS_SIZE*CANVAS_SIZE);
if(sprite->select.front == NULL) sprite->select.front = (u8*)malloc(CANVAS_SIZE*CANVAS_SIZE);
if(sprite->history) history_delete(sprite->history);
*sprite = (Sprite)

View File

@ -40,6 +40,7 @@
#include "fs.h"
#include <zlib.h>
#include <ctype.h>
#include "net.h"
#include "ext/gif.h"
#include "ext/md5.h"
@ -122,7 +123,7 @@ static struct
// SDL_Texture* texture;
// const u8* src;
SDL_SystemCursor system;
tic_cursor system;
} mouse;
struct
@ -423,7 +424,7 @@ void toClipboard(const void* data, s32 size, bool flip)
{
enum {Len = 2};
char* clipboard = (char*)SDL_malloc(size*Len + 1);
char* clipboard = (char*)malloc(size*Len + 1);
if(clipboard)
{
@ -441,8 +442,8 @@ void toClipboard(const void* data, s32 size, bool flip)
}
}
SDL_SetClipboardText(clipboard);
SDL_free(clipboard);
setClipboardText(clipboard);
free(clipboard);
}
}
}
@ -475,7 +476,7 @@ static void removeWhiteSpaces(char* str)
s32 len = strlen(str);
for (s32 j = 0; j < len; j++)
if(!SDL_isspace(str[j]))
if(!isspace(str[j]))
str[i++] = str[j];
str[i] = '\0';
@ -485,9 +486,9 @@ bool fromClipboard(void* data, s32 size, bool flip, bool remove_white_spaces)
{
if(data)
{
if(SDL_HasClipboardText())
if(hasClipboardText())
{
char* clipboard = SDL_GetClipboardText();
char* clipboard = getClipboardText();
if(clipboard)
{
@ -498,7 +499,7 @@ bool fromClipboard(void* data, s32 size, bool flip, bool remove_white_spaces)
if(valid) str2buf(clipboard, strlen(clipboard), data, flip);
SDL_free(clipboard);
free(clipboard);
return valid;
}
@ -581,7 +582,7 @@ static void drawExtrabar(tic_mem* tic)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
color = Colors[i];
showTooltip(Tips[i]);
@ -639,7 +640,7 @@ static void drawBankIcon(s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
@ -662,13 +663,13 @@ static void drawBankIcon(s32 x, s32 y)
bool over = false;
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
if(checkMouseClick(&rect, tic_mouse_left))
{
if(studioImpl.bank.chained)
SDL_memset(studioImpl.bank.indexes, i, sizeof studioImpl.bank.indexes);
memset(studioImpl.bank.indexes, i, sizeof studioImpl.bank.indexes);
else studioImpl.bank.indexes[mode] = i;
}
}
@ -699,7 +700,7 @@ static void drawBankIcon(s32 x, s32 y)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
@ -708,7 +709,7 @@ static void drawBankIcon(s32 x, s32 y)
studioImpl.bank.chained = !studioImpl.bank.chained;
if(studioImpl.bank.chained)
SDL_memset(studioImpl.bank.indexes, studioImpl.bank.indexes[mode], sizeof studioImpl.bank.indexes);
memset(studioImpl.bank.indexes, studioImpl.bank.indexes[mode], sizeof studioImpl.bank.indexes);
}
}
@ -802,7 +803,7 @@ void drawToolbar(tic_mem* tic, u8 color, bool bg)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
over = true;
@ -892,28 +893,28 @@ void setStudioEvent(StudioEvent event)
}
}
ClipboardEvent getClipboardEvent(SDL_Keycode keycode)
ClipboardEvent getClipboardEvent(tic_keycode keycode)
{
SDL_Keymod keymod = SDL_GetModState();
// SDL_Keymod keymod = SDL_GetModState();
if(keymod & TIC_MOD_CTRL)
{
switch(keycode)
{
case SDLK_INSERT:
case SDLK_c: return TIC_CLIPBOARD_COPY;
case SDLK_x: return TIC_CLIPBOARD_CUT;
case SDLK_v: return TIC_CLIPBOARD_PASTE;
}
}
else if(keymod & KMOD_SHIFT)
{
switch(keycode)
{
case SDLK_DELETE: return TIC_CLIPBOARD_CUT;
case SDLK_INSERT: return TIC_CLIPBOARD_PASTE;
}
}
// if(keymod & TIC_MOD_CTRL)
// {
// switch(keycode)
// {
// case SDLK_INSERT:
// case SDLK_c: return TIC_CLIPBOARD_COPY;
// case SDLK_x: return TIC_CLIPBOARD_CUT;
// case SDLK_v: return TIC_CLIPBOARD_PASTE;
// }
// }
// else if(keymod & KMOD_SHIFT)
// {
// switch(keycode)
// {
// case SDLK_DELETE: return TIC_CLIPBOARD_CUT;
// case SDLK_INSERT: return TIC_CLIPBOARD_PASTE;
// }
// }
return TIC_CLIPBOARD_NONE;
}
@ -1017,12 +1018,12 @@ void resumeRunMode()
studioImpl.mode = TIC_RUN_MODE;
}
static void showSoftKeyboard()
{
if(studioImpl.mode == TIC_CONSOLE_MODE || studioImpl.mode == TIC_CODE_MODE)
if(!SDL_IsTextInputActive())
SDL_StartTextInput();
}
// static void showSoftKeyboard()
// {
// if(studioImpl.mode == TIC_CONSOLE_MODE || studioImpl.mode == TIC_CODE_MODE)
// if(!SDL_IsTextInputActive())
// SDL_StartTextInput();
// }
void setStudioMode(EditorMode mode)
{
@ -1060,7 +1061,7 @@ void setStudioMode(EditorMode mode)
studioImpl.mode = mode;
showSoftKeyboard();
// showSoftKeyboard();
}
}
@ -1082,14 +1083,14 @@ void changeStudioMode(s32 dir)
}
}
static void showGameMenu()
{
studioImpl.studio.tic->api.pause(studioImpl.studio.tic);
studioImpl.studio.tic->api.reset(studioImpl.studio.tic);
// static void showGameMenu()
// {
// studioImpl.studio.tic->api.pause(studioImpl.studio.tic);
// studioImpl.studio.tic->api.reset(studioImpl.studio.tic);
initMenuMode();
studioImpl.mode = TIC_MENU_MODE;
}
// initMenuMode();
// studioImpl.mode = TIC_MENU_MODE;
// }
void hideGameMenu()
{
@ -1158,9 +1159,9 @@ bool getGesturePos(tic_point* pos)
return false;
}
void setCursor(SDL_SystemCursor id)
void setCursor(tic_cursor id)
{
if(id != SDL_SYSTEM_CURSOR_ARROW)
if(id != tic_cursor_arrow)
studioImpl.mouse.system = id;
}
@ -1186,7 +1187,7 @@ void showDialog(const char** text, s32 rows, DialogCallback callback, void* data
static void resetBanks()
{
SDL_memset(studioImpl.bank.indexes, 0, sizeof studioImpl.bank.indexes);
memset(studioImpl.bank.indexes, 0, sizeof studioImpl.bank.indexes);
}
static void initModules()
@ -1586,33 +1587,33 @@ static bool isGameMenu()
// studioImpl.studio.tic->ram.input.gamepads.data |= studioImpl.gamepad.joystick.data;
// }
static void processGesture()
{
SDL_TouchID id = SDL_GetTouchDevice(0);
s32 fingers = SDL_GetNumTouchFingers(id);
// static void processGesture()
// {
// SDL_TouchID id = SDL_GetTouchDevice(0);
// s32 fingers = SDL_GetNumTouchFingers(id);
enum{Fingers = 2};
// enum{Fingers = 2};
if(fingers == Fingers)
{
tic_point point = {0, 0};
// if(fingers == Fingers)
// {
// tic_point point = {0, 0};
for(s32 f = 0; f < fingers; f++)
{
SDL_Finger* finger = SDL_GetTouchFinger(id, 0);
// for(s32 f = 0; f < fingers; f++)
// {
// SDL_Finger* finger = SDL_GetTouchFinger(id, 0);
point.x += (s32)(finger->x * TIC80_WIDTH);
point.y += (s32)(finger->y * TIC80_HEIGHT);
}
// point.x += (s32)(finger->x * TIC80_WIDTH);
// point.y += (s32)(finger->y * TIC80_HEIGHT);
// }
point.x /= Fingers;
point.y /= Fingers;
// point.x /= Fingers;
// point.y /= Fingers;
studioImpl.gesture.pos = point;
// studioImpl.gesture.pos = point;
studioImpl.gesture.active = true;
}
}
// studioImpl.gesture.active = true;
// }
// }
// static void processMouse()
// {
@ -1675,7 +1676,7 @@ static void saveProject()
sprintf(buffer, "%s SAVED :)", studioImpl.console->romName);
for(s32 i = 0; i < (s32)strlen(buffer); i++)
buffer[i] = SDL_toupper(buffer[i]);
buffer[i] = toupper(buffer[i]);
showPopupMessage(buffer);
}
@ -1689,7 +1690,7 @@ static void screen2buffer(u32* buffer, const u32* pixels, tic_rect rect)
for(s32 i = 0; i < rect.h; i++)
{
SDL_memcpy(buffer, pixels + rect.x, rect.w * sizeof(pixels[0]));
memcpy(buffer, pixels + rect.x, rect.w * sizeof(pixels[0]));
pixels += TIC80_FULLWIDTH;
buffer += rect.w;
}
@ -1705,7 +1706,7 @@ static void setCoverImage()
// tic->api.blit(tic, tic->api.scanline, tic->api.overlap, NULL);
// u32* buffer = SDL_malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32));
// u32* buffer = malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32));
// if(buffer)
// {
@ -1716,7 +1717,7 @@ static void setCoverImage()
// gif_write_animation(studioImpl.studio.tic->cart.cover.data, &studioImpl.studio.tic->cart.cover.size,
// TIC80_WIDTH, TIC80_HEIGHT, (const u8*)buffer, 1, TIC_FRAMERATE, 1);
// SDL_free(buffer);
// free(buffer);
// showPopupMessage("COVER IMAGE SAVED :)");
// }
@ -1737,14 +1738,14 @@ static void stopVideoRecord()
{
{
s32 size = 0;
u8* data = SDL_malloc(FRAME_SIZE * studioImpl.video.frame);
u8* data = malloc(FRAME_SIZE * studioImpl.video.frame);
gif_write_animation(data, &size, TIC80_FULLWIDTH, TIC80_FULLHEIGHT, (const u8*)studioImpl.video.buffer, studioImpl.video.frame, TIC_FRAMERATE, getConfig()->gifScale);
fsGetFileData(onVideoExported, "screen.gif", data, size, DEFAULT_CHMOD, NULL);
}
SDL_free(studioImpl.video.buffer);
free(studioImpl.video.buffer);
studioImpl.video.buffer = NULL;
}
@ -1762,7 +1763,7 @@ static void startVideoRecord()
else
{
studioImpl.video.frames = getConfig()->gifLength * TIC_FRAMERATE;
studioImpl.video.buffer = SDL_malloc(FRAME_SIZE * studioImpl.video.frames);
studioImpl.video.buffer = malloc(FRAME_SIZE * studioImpl.video.frames);
if(studioImpl.video.buffer)
{
@ -1777,7 +1778,7 @@ static void startVideoRecord()
static void takeScreenshot()
{
studioImpl.video.frames = 1;
studioImpl.video.buffer = SDL_malloc(FRAME_SIZE);
studioImpl.video.buffer = malloc(FRAME_SIZE);
if(studioImpl.video.buffer)
{
@ -2043,15 +2044,15 @@ static void processShortcuts()
// input->keyboard.keys[c++] = KeyboardCodes[i];
// }
#if defined(TIC80_PRO)
// #if defined(TIC80_PRO)
static void reloadConfirm(bool yes, void* data)
{
if(yes)
studioImpl.console->updateProject(studioImpl.console);
}
// static void reloadConfirm(bool yes, void* data)
// {
// if(yes)
// studioImpl.console->updateProject(studioImpl.console);
// }
#endif
// #endif
// SDL_Event* pollEvent()
// {
@ -2198,7 +2199,7 @@ static void reloadConfirm(bool yes, void* data)
// if(studioImpl.audio.cvt.needed)
// {
// SDL_memcpy(studioImpl.audio.cvt.buf, studioImpl.studio.tic->samples.buffer, studioImpl.studio.tic->samples.size);
// memcpy(studioImpl.audio.cvt.buf, studioImpl.studio.tic->samples.buffer, studioImpl.studio.tic->samples.size);
// SDL_ConvertAudio(&studioImpl.audio.cvt);
// SDL_QueueAudio(studioImpl.audio.device, studioImpl.audio.cvt.buf, studioImpl.audio.cvt.len_cvt);
// }
@ -2319,7 +2320,7 @@ static void recordFrame(u32* pixels)
// }
// tic->api.blit(tic, scanline, overlap, data);
// SDL_memcpy(pixels, tic->screen, sizeof tic->screen);
// memcpy(pixels, tic->screen, sizeof tic->screen);
// recordFrame(pixels);
// drawDesyncLabel(pixels);
@ -2366,8 +2367,8 @@ static void recordFrame(u32* pixels)
// }
// }
static void blitCursor(const u8* in)
{
// static void blitCursor(const u8* in)
// {
// if(!studioImpl.mouse.texture)
// {
// studioImpl.mouse.texture = SDL_CreateTexture(studioImpl.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, TIC_SPRITESIZE, TIC_SPRITESIZE);
@ -2418,27 +2419,27 @@ static void blitCursor(const u8* in)
// if(SDL_GetWindowFlags(studioImpl.window) & SDL_WINDOW_MOUSE_FOCUS)
// SDL_RenderCopy(studioImpl.renderer, studioImpl.mouse.texture, &src, &dst);
}
// }
static void renderCursor()
{
if(studioImpl.mode == TIC_RUN_MODE && !studioImpl.studio.tic->input.mouse)
{
SDL_ShowCursor(SDL_DISABLE);
return;
}
if(studioImpl.mode == TIC_RUN_MODE && studioImpl.studio.tic->ram.vram.vars.cursor)
{
SDL_ShowCursor(SDL_DISABLE);
blitCursor(studioImpl.studio.tic->ram.sprites.data[studioImpl.studio.tic->ram.vram.vars.cursor].data);
return;
}
// static void renderCursor()
// {
// if(studioImpl.mode == TIC_RUN_MODE && !studioImpl.studio.tic->input.mouse)
// {
// SDL_ShowCursor(SDL_DISABLE);
// return;
// }
// if(studioImpl.mode == TIC_RUN_MODE && studioImpl.studio.tic->ram.vram.vars.cursor)
// {
// SDL_ShowCursor(SDL_DISABLE);
// blitCursor(studioImpl.studio.tic->ram.sprites.data[studioImpl.studio.tic->ram.vram.vars.cursor].data);
// return;
// }
SDL_ShowCursor(getConfig()->theme.cursor.sprite >= 0 ? SDL_DISABLE : SDL_ENABLE);
// SDL_ShowCursor(getConfig()->theme.cursor.sprite >= 0 ? SDL_DISABLE : SDL_ENABLE);
if(getConfig()->theme.cursor.sprite >= 0)
blitCursor(studioImpl.studio.tic->config.bank0.tiles.data[getConfig()->theme.cursor.sprite].data);
}
// if(getConfig()->theme.cursor.sprite >= 0)
// blitCursor(studioImpl.studio.tic->config.bank0.tiles.data[getConfig()->theme.cursor.sprite].data);
// }
static void useSystemPalette()
{
@ -2549,7 +2550,7 @@ static void renderStudio()
drawPopup();
if(getConfig()->noSound)
SDL_memset(tic->ram.registers, 0, sizeof tic->ram.registers);
memset(tic->ram.registers, 0, sizeof tic->ram.registers);
studioImpl.studio.tic->api.tick_end(studioImpl.studio.tic);
@ -2651,7 +2652,7 @@ static void renderStudio()
// return;
// }
// SDL_SystemCursor cursor = studioImpl.mouse.system;
// tic_cursor cursor = studioImpl.mouse.system;
// studioImpl.mouse.system = SDL_SYSTEM_CURSOR_ARROW;
// SDL_RenderClear(studioImpl.renderer);
@ -2689,7 +2690,7 @@ static void renderStudio()
// if(studioImpl.audio.cvt.needed)
// {
// studioImpl.audio.cvt.len = studioImpl.audio.spec.freq * sizeof studioImpl.studio.tic->samples.buffer[0] / TIC_FRAMERATE;
// studioImpl.audio.cvt.buf = SDL_malloc(studioImpl.audio.cvt.len * studioImpl.audio.cvt.len_mult);
// studioImpl.audio.cvt.buf = malloc(studioImpl.audio.cvt.len * studioImpl.audio.cvt.len_mult);
// }
// }
@ -2720,7 +2721,7 @@ static void renderStudio()
static void updateSystemFont()
{
SDL_memset(studioImpl.studio.tic->font.data, 0, sizeof(tic_font));
memset(studioImpl.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++)
@ -2744,7 +2745,7 @@ void studioConfigChanged()
// enum{ Size = 64, TileSize = 16, ColorKey = 14, Cols = TileSize / TIC_SPRITESIZE, Scale = Size/TileSize};
// studioImpl.studio.tic->api.clear(studioImpl.studio.tic, 0);
// u32* pixels = SDL_malloc(Size * Size * sizeof(u32));
// u32* pixels = malloc(Size * Size * sizeof(u32));
// const u32* pal = tic_palette_blit(&studioImpl.studio.tic->config.palette);
@ -2760,8 +2761,8 @@ void studioConfigChanged()
// 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
// SDL_SetWindowIcon(studioImpl.window, surface);
// SDL_FreeSurface(surface);
// SDL_free(pixels);
// freeSurface(surface);
// free(pixels);
// }
u32 unzip(u8** dest, const u8* source, size_t size)
@ -2771,18 +2772,18 @@ u32 unzip(u8** dest, const u8* source, size_t size)
unsigned long destSize = DestSize;
u8* buffer = (u8*)SDL_malloc(destSize);
u8* buffer = (u8*)malloc(destSize);
if(buffer)
{
if(uncompress(buffer, &destSize, source, (unsigned long)size) == Z_OK)
{
*dest = (u8*)SDL_malloc(destSize+1);
*dest = (u8*)malloc(destSize+1);
memcpy(*dest, buffer, destSize);
(*dest)[destSize] = '\0';
}
SDL_free(buffer);
free(buffer);
return destSize;
}
@ -2802,7 +2803,7 @@ static void initKeymap()
// if(size == KEYMAP_SIZE)
// memcpy(getKeymap(), data, KEYMAP_SIZE);
// SDL_free(data);
// free(data);
// }
}
@ -2832,21 +2833,21 @@ static void onFSInitialized(FileSystem* fs)
{
for(s32 i = 0; i < TIC_EDITOR_BANKS; i++)
{
studioImpl.editor[i].code = SDL_calloc(1, sizeof(Code));
studioImpl.editor[i].sprite = SDL_calloc(1, sizeof(Sprite));
studioImpl.editor[i].map = SDL_calloc(1, sizeof(Map));
studioImpl.editor[i].sfx = SDL_calloc(1, sizeof(Sfx));
studioImpl.editor[i].music = SDL_calloc(1, sizeof(Music));
studioImpl.editor[i].code = calloc(1, sizeof(Code));
studioImpl.editor[i].sprite = calloc(1, sizeof(Sprite));
studioImpl.editor[i].map = calloc(1, sizeof(Map));
studioImpl.editor[i].sfx = calloc(1, sizeof(Sfx));
studioImpl.editor[i].music = calloc(1, sizeof(Music));
}
studioImpl.start = SDL_calloc(1, sizeof(Start));
studioImpl.console = SDL_calloc(1, sizeof(Console));
studioImpl.run = SDL_calloc(1, sizeof(Run));
studioImpl.world = SDL_calloc(1, sizeof(World));
studioImpl.config = SDL_calloc(1, sizeof(Config));
studioImpl.dialog = SDL_calloc(1, sizeof(Dialog));
studioImpl.menu = SDL_calloc(1, sizeof(Menu));
studioImpl.surf = SDL_calloc(1, sizeof(Surf));
studioImpl.start = calloc(1, sizeof(Start));
studioImpl.console = calloc(1, sizeof(Console));
studioImpl.run = calloc(1, sizeof(Run));
studioImpl.world = calloc(1, sizeof(World));
studioImpl.config = calloc(1, sizeof(Config));
studioImpl.dialog = calloc(1, sizeof(Dialog));
studioImpl.menu = calloc(1, sizeof(Menu));
studioImpl.surf = calloc(1, sizeof(Surf));
}
fsMakeDir(fs, TIC_LOCAL);
@ -3021,7 +3022,7 @@ void studioTick(void* pixels)
}
tic->api.blit(tic, scanline, overlap, data);
SDL_memcpy(pixels, tic->screen, sizeof tic->screen);
memcpy(pixels, tic->screen, sizeof tic->screen);
recordFrame(pixels);
drawDesyncLabel(pixels);
@ -3035,28 +3036,28 @@ void studioClose()
{
for(s32 i = 0; i < TIC_EDITOR_BANKS; i++)
{
SDL_free(studioImpl.editor[i].code);
SDL_free(studioImpl.editor[i].sprite);
SDL_free(studioImpl.editor[i].map);
SDL_free(studioImpl.editor[i].sfx);
SDL_free(studioImpl.editor[i].music);
free(studioImpl.editor[i].code);
free(studioImpl.editor[i].sprite);
free(studioImpl.editor[i].map);
free(studioImpl.editor[i].sfx);
free(studioImpl.editor[i].music);
}
SDL_free(studioImpl.start);
SDL_free(studioImpl.console);
SDL_free(studioImpl.run);
SDL_free(studioImpl.world);
SDL_free(studioImpl.config);
SDL_free(studioImpl.dialog);
SDL_free(studioImpl.menu);
SDL_free(studioImpl.surf);
free(studioImpl.start);
free(studioImpl.console);
free(studioImpl.run);
free(studioImpl.world);
free(studioImpl.config);
free(studioImpl.dialog);
free(studioImpl.menu);
free(studioImpl.surf);
}
if(studioImpl.tic80local)
tic80_delete((tic80*)studioImpl.tic80local);
// if(studioImpl.audio.cvt.buf)
// SDL_free(studioImpl.audio.cvt.buf);
// free(studioImpl.audio.cvt.buf);
// SDL_DestroyTexture(studioImpl.gamepad.texture);
// SDL_DestroyTexture(studioImpl.texture);

View File

@ -27,7 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
// #include <SDL.h>
#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
@ -41,7 +41,7 @@
#define TIC_LOCAL ".local/"
#define TIC_CACHE TIC_LOCAL "cache/"
#define TIC_MOD_CTRL (KMOD_GUI|KMOD_CTRL)
// #define TIC_MOD_CTRL (KMOD_GUI|KMOD_CTRL)
#define TOOLBAR_SIZE 7
#define STUDIO_TEXT_WIDTH (TIC_FONT_WIDTH)
@ -134,7 +134,7 @@ typedef struct
} tic_rect;
// SDL_Event* pollEvent();
void setCursor(SDL_SystemCursor id);
void setCursor(tic_cursor id);
s32 getMouseX();
s32 getMouseY();
@ -171,7 +171,7 @@ typedef enum
TIC_CLIPBOARD_PASTE,
} ClipboardEvent;
ClipboardEvent getClipboardEvent(SDL_Keycode keycode);
ClipboardEvent getClipboardEvent(tic_keycode keycode);
typedef enum
{
@ -224,3 +224,10 @@ void studioClose();
char getKeyboardText();
bool isKeyWasDown(tic_key key);
bool isAnyKeyWasDown();
void setClipboardText(const char* text);
bool hasClipboardText();
char* getClipboardText();
u64 getPerformanceCounter();
u64 getPerformanceFrequency();

View File

@ -38,7 +38,7 @@
#define COVER_Y 5
#define COVER_X (TIC80_WIDTH - COVER_WIDTH - COVER_Y)
#if defined(__WINDOWS__) || defined(__LINUX__) || defined(__MACOSX__)
#if defined(__TIC_WINDOWS__) || defined(__LINUX__) || defined(__MACOSX__)
#define CAN_OPEN_URL 1
#endif
@ -401,18 +401,18 @@ static bool addMenuItem(const char* name, const char* info, s32 id, void* ptr, b
{
MenuItem* item = &data->items[data->count++];
item->name = SDL_strdup(name);
item->name = strdup(name);
bool project = false;
if(dir)
{
char folder[FILENAME_MAX];
sprintf(folder, "[%s]", name);
item->label = SDL_strdup(folder);
item->label = strdup(folder);
}
else
{
item->label = SDL_strdup(name);
item->label = strdup(name);
if(hasExt(name, CartExt))
cutExt(item->label, CartExt);
@ -426,7 +426,7 @@ static bool addMenuItem(const char* name, const char* info, s32 id, void* ptr, b
replace(item->label, "&#39;", "'");
}
item->hash = info ? SDL_strdup(info) : NULL;
item->hash = info ? strdup(info) : NULL;
item->id = id;
item->dir = dir;
item->cover = NULL;
@ -442,19 +442,19 @@ static void resetMenu(Surf* surf)
{
for(s32 i = 0; i < surf->menu.count; i++)
{
SDL_free((void*)surf->menu.items[i].name);
free((void*)surf->menu.items[i].name);
const char* hash = surf->menu.items[i].hash;
if(hash) SDL_free((void*)hash);
if(hash) free((void*)hash);
tic_screen* cover = surf->menu.items[i].cover;
if(cover) SDL_free(cover);
if(cover) free(cover);
const char* label = surf->menu.items[i].label;
if(label) SDL_free((void*)label);
if(label) free((void*)label);
}
SDL_free(surf->menu.items);
free(surf->menu.items);
surf->menu.items = NULL;
surf->menu.count = 0;
@ -495,7 +495,7 @@ static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size)
MenuItem* item = &surf->menu.items[surf->menu.pos];
item->cover = SDL_malloc(sizeof(tic_screen));
item->cover = malloc(sizeof(tic_screen));
gif_image* image = gif_read_data(cover, size);
@ -532,7 +532,7 @@ static void loadCover(Surf* surf)
if(data)
{
tic_cartridge* cart = (tic_cartridge*)SDL_malloc(sizeof(tic_cartridge));
tic_cartridge* cart = (tic_cartridge*)malloc(sizeof(tic_cartridge));
if(cart)
{
@ -544,10 +544,10 @@ static void loadCover(Surf* surf)
if(cart->cover.size)
updateMenuItemCover(surf, cart->cover.data, cart->cover.size);
SDL_free(cart);
free(cart);
}
SDL_free(data);
free(data);
}
}
else if(item->hash && !item->cover)
@ -559,7 +559,7 @@ static void loadCover(Surf* surf)
if(cover)
{
updateMenuItemCover(surf, cover, size);
SDL_free(cover);
free(cover);
}
}
}
@ -573,7 +573,7 @@ static void initMenu(Surf* surf)
AddMenuItem data =
{
.items = SDL_malloc(Size),
.items = malloc(Size),
.count = 0,
.surf = surf,
};
@ -649,7 +649,7 @@ static void onPlayCart(Surf* surf)
if(item->project)
{
tic_cartridge* cart = SDL_malloc(sizeof(tic_cartridge));
tic_cartridge* cart = malloc(sizeof(tic_cartridge));
if(cart)
{
@ -658,11 +658,11 @@ static void onPlayCart(Surf* surf)
surf->console->loadProject(surf->console, item->name, data, size, cart);
SDL_memcpy(&surf->tic->cart, cart, sizeof(tic_cartridge));
memcpy(&surf->tic->cart, cart, sizeof(tic_cartridge));
studioRomLoaded();
SDL_free(cart);
free(cart);
}
}
else

View File

@ -418,7 +418,7 @@ typedef union
u8 data[TIC_RAM_SIZE];
} tic_ram;
enum
typedef enum
{
tic_key_unknown,
@ -511,7 +511,7 @@ enum
////////////////
tic_keys_count
};
} tic_keycode;
enum
{
@ -519,3 +519,10 @@ enum
tic_mouse_middle,
tic_mouse_right,
};
typedef enum
{
tic_cursor_arrow,
tic_cursor_hand,
tic_cursor_ibeam,
} tic_cursor;

View File

@ -42,7 +42,7 @@ static void drawGrid(World* world)
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
setCursor(tic_cursor_hand);
s32 mx = getMouseX();
s32 my = getMouseY();
@ -61,13 +61,13 @@ static void drawGrid(World* world)
TIC_MAP_SCREEN_WIDTH+1, TIC_MAP_SCREEN_HEIGHT+1, (tic_color_red));
}
static void processKeydown(World* world, SDL_Keycode keycode)
{
switch(keycode)
{
case SDLK_TAB: setStudioMode(TIC_MAP_MODE); break;
}
}
// static void processKeydown(World* world, tic_keycode keycode)
// {
// switch(keycode)
// {
// case SDLK_TAB: setStudioMode(TIC_MAP_MODE); break;
// }
// }
static void tick(World* world)
{
@ -82,7 +82,7 @@ static void tick(World* world)
// }
// }
SDL_memcpy(&world->tic->ram.vram, world->preview, PREVIEW_SIZE);
memcpy(&world->tic->ram.vram, world->preview, PREVIEW_SIZE);
drawGrid(world);
}
@ -90,7 +90,7 @@ static void tick(World* world)
void initWorld(World* world, tic_mem* tic, Map* map)
{
if(!world->preview)
world->preview = SDL_malloc(PREVIEW_SIZE);
world->preview = malloc(PREVIEW_SIZE);
*world = (World)
{
@ -100,7 +100,7 @@ void initWorld(World* world, tic_mem* tic, Map* map)
.preview = world->preview,
};
SDL_memset(world->preview, 0, PREVIEW_SIZE);
memset(world->preview, 0, PREVIEW_SIZE);
s32 colors[TIC_PALETTE_SIZE];
for(s32 i = 0; i < TIC80_WIDTH * TIC80_HEIGHT; i++)
@ -109,7 +109,7 @@ void initWorld(World* world, tic_mem* tic, Map* map)
if(index)
{
SDL_memset(colors, 0, sizeof colors);
memset(colors, 0, sizeof colors);
tic_tile* tile = &getBankTiles()->data[index];
@ -123,7 +123,7 @@ void initWorld(World* world, tic_mem* tic, Map* map)
s32 max = 0;
for(s32 c = 0; c < SDL_arraysize(colors); c++)
for(s32 c = 0; c < COUNT_OF(colors); c++)
if(colors[c] > colors[max]) max = c;
tic_tool_poke4(world->preview, i, max);