Merge branch '#341'

This commit is contained in:
BADIM-PC\Vadim 2017-12-11 12:21:08 +03:00
commit 9fd5484acc
18 changed files with 195 additions and 168 deletions

View File

@ -359,13 +359,13 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param)
switch(i) switch(i)
{ {
case 0: memcpy(&tic->cart.gfx.tiles, &cart->gfx.tiles, sizeof cart->gfx.tiles + sizeof cart->gfx.sprites); break; case 0: memcpy(&tic->cart.bank.tiles, &cart->bank.tiles, sizeof(tic_tiles)*2); break;
case 1: memcpy(&tic->cart.gfx.map, &cart->gfx.map, sizeof cart->gfx.map); break; case 1: memcpy(&tic->cart.bank.map, &cart->bank.map, sizeof(tic_map)); break;
case 2: memcpy(&tic->cart.cover, &cart->cover, sizeof cart->cover); break; case 2: memcpy(&tic->cart.cover, &cart->cover, sizeof cart->cover); break;
case 3: memcpy(&tic->cart.code, &cart->code, sizeof cart->code); break; case 3: memcpy(&tic->cart.code, &cart->code, sizeof cart->code); break;
case 4: memcpy(&tic->cart.sound.sfx, &cart->sound.sfx, sizeof cart->sound.sfx); break; case 4: memcpy(&tic->cart.bank.sfx, &cart->bank.sfx, sizeof(tic_sfx)); break;
case 5: memcpy(&tic->cart.sound.music, &cart->sound.music, sizeof cart->sound.music); break; case 5: memcpy(&tic->cart.bank.music, &cart->bank.music, sizeof(tic_music)); break;
case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof cart->palette); break; case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof(tic_palette)); break;
} }
studioRomLoaded(); studioRomLoaded();
@ -602,14 +602,14 @@ static char* saveBinarySection(char* ptr, const char* comment, const char* tag,
typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection; typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection;
static const BinarySection BinarySections[] = static const BinarySection BinarySections[] =
{ {
{"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false},
{"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, gfx.tiles), sizeof(tic_tile), true}, {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.tiles), sizeof(tic_tile), true},
{"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, gfx.sprites), sizeof(tic_tile), true}, {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.sprites), sizeof(tic_tile), true},
{"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, gfx.map), TIC_MAP_WIDTH, true}, {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, bank.map), TIC_MAP_WIDTH, true},
{"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge,sound.sfx.waveform.envelopes), sizeof(tic_waveform), true}, {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, bank.sfx.waveform.envelopes), sizeof(tic_waveform), true},
{"SFX", SFX_COUNT, offsetof(tic_cartridge, sound.sfx.data), sizeof(tic_sound_effect), true}, {"SFX", SFX_COUNT, offsetof(tic_cartridge, bank.sfx.data), sizeof(tic_sound_effect), true},
{"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, sound.music.patterns), sizeof(tic_track_pattern), true}, {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, bank.music.patterns), sizeof(tic_track_pattern), true},
{"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, sound.music.tracks), sizeof(tic_track), true}, {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, bank.music.tracks), sizeof(tic_track), true},
}; };
static s32 saveProject(Console* console, void* buffer, const char* comment) static s32 saveProject(Console* console, void* buffer, const char* comment)
@ -1330,7 +1330,7 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v
tic_rgb rgb = {c->r, c->g, c->b}; tic_rgb rgb = {c->r, c->g, c->b};
u8 color = tic_tool_find_closest_color(console->tic->cart.palette.colors, &rgb); u8 color = tic_tool_find_closest_color(console->tic->cart.palette.colors, &rgb);
setSpritePixel(console->tic->cart.gfx.tiles, x, y, color); setSpritePixel(console->tic->cart.bank.tiles.data, x, y, color);
} }
gif_close(image); gif_close(image);
@ -1352,8 +1352,8 @@ static void injectMap(Console* console, const void* buffer, s32 size)
{ {
enum {Size = sizeof(tic_map)}; enum {Size = sizeof(tic_map)};
SDL_memset(&console->tic->cart.gfx.map, 0, Size); SDL_memset(&console->tic->cart.bank.map, 0, Size);
SDL_memcpy(&console->tic->cart.gfx.map, buffer, SDL_min(size, Size)); SDL_memcpy(&console->tic->cart.bank.map, buffer, SDL_min(size, Size));
} }
static void onImportMap(const char* name, const void* buffer, size_t size, void* data) static void onImportMap(const char* name, const void* buffer, size_t size, void* data)
@ -1453,7 +1453,7 @@ static void exportSprites(Console* console)
{ {
for (s32 y = 0; y < Height; y++) for (s32 y = 0; y < Height; y++)
for (s32 x = 0; x < Width; x++) for (s32 x = 0; x < Width; x++)
data[x + y * Width] = getSpritePixel(console->tic->cart.gfx.tiles, x, y); data[x + y * Width] = getSpritePixel(console->tic->cart.bank.tiles.data, x, y);
s32 size = 0; s32 size = 0;
if((size = writeGifData(console->tic, buffer, data, Width, Height))) if((size = writeGifData(console->tic, buffer, data, Width, Height)))
@ -1493,7 +1493,7 @@ static void exportMap(Console* console)
if(buffer) if(buffer)
{ {
SDL_memcpy(buffer, console->tic->cart.gfx.map.data, Size); SDL_memcpy(buffer, console->tic->cart.bank.map.data, Size);
fsGetFileData(onMapExported, "world.map", buffer, Size, DEFAULT_CHMOD, console); fsGetFileData(onMapExported, "world.map", buffer, Size, DEFAULT_CHMOD, console);
} }
} }
@ -2131,19 +2131,20 @@ static void onConsoleRamCommand(Console* console, const char* param)
{offsetof(tic_ram, vram.screen), "SCREEN"}, {offsetof(tic_ram, vram.screen), "SCREEN"},
{offsetof(tic_ram, vram.palette), "PALETTE"}, {offsetof(tic_ram, vram.palette), "PALETTE"},
{offsetof(tic_ram, vram.mapping), "PALETTE MAP"}, {offsetof(tic_ram, vram.mapping), "PALETTE MAP"},
{offsetof(tic_ram, vram.vars.colors), "BORDER/BG COLOR"}, {offsetof(tic_ram, vram.vars.colors), "BORDER"},
{offsetof(tic_ram, vram.vars.offset), "SCREEN OFFSET"}, {offsetof(tic_ram, vram.vars.offset), "SCREEN OFFSET"},
{offsetof(tic_ram, vram.vars.mask), "GAMEPAD MASK"}, {offsetof(tic_ram, vram.vars.mask), "GAMEPAD MASK"},
{offsetof(tic_ram, vram.input.gamepad), "GAMEPAD"}, {offsetof(tic_ram, vram.input.gamepad), "GAMEPAD"},
{offsetof(tic_ram, vram.input.reserved), "..."}, {offsetof(tic_ram, vram.input.reserved), "..."},
{offsetof(tic_ram, gfx.tiles), "SPRITES"}, {offsetof(tic_ram, tiles), "TILES"},
{offsetof(tic_ram, gfx.map), "MAP"}, {offsetof(tic_ram, sprites), "SPRITES"},
{offsetof(tic_ram, map), "MAP"},
{offsetof(tic_ram, persistent), "PERSISTENT MEMORY"}, {offsetof(tic_ram, persistent), "PERSISTENT MEMORY"},
{offsetof(tic_ram, registers), "SOUND REGISTERS"}, {offsetof(tic_ram, registers), "SOUND REGISTERS"},
{offsetof(tic_ram, sound.sfx.waveform), "WAVEFORMS"}, {offsetof(tic_ram, sfx.waveform), "WAVEFORMS"},
{offsetof(tic_ram, sound.sfx.data), "SFX"}, {offsetof(tic_ram, sfx.data), "SFX"},
{offsetof(tic_ram, sound.music.patterns.data), "MUSIC PATTERNS"}, {offsetof(tic_ram, music.patterns.data), "MUSIC PATTERNS"},
{offsetof(tic_ram, sound.music.tracks.data), "MUSIC TRACKS"}, {offsetof(tic_ram, music.tracks.data), "MUSIC TRACKS"},
{offsetof(tic_ram, music_pos), "MUSIC POS"}, {offsetof(tic_ram, music_pos), "MUSIC POS"},
{TIC_RAM_SIZE, "..."}, {TIC_RAM_SIZE, "..."},
}; };
@ -2763,7 +2764,7 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na
tic_rgb rgb = {c->r, c->g, c->b}; tic_rgb rgb = {c->r, c->g, c->b};
u8 color = tic_tool_find_closest_color(embed.file.palette.colors, &rgb); u8 color = tic_tool_find_closest_color(embed.file.palette.colors, &rgb);
setSpritePixel(embed.file.gfx.tiles, x, y, color); setSpritePixel(embed.file.bank.tiles.data, x, y, color);
} }
gif_close(image); gif_close(image);

View File

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

View File

@ -182,7 +182,7 @@ static duk_ret_t duk_spr(duk_context* duk)
s32 h = duk_is_null_or_undefined(duk, 8) ? 1 : duk_to_int(duk, 8); s32 h = duk_is_null_or_undefined(duk, 8) ? 1 : duk_to_int(duk, 8);
tic_mem* memory = (tic_mem*)getDukMachine(duk); tic_mem* memory = (tic_mem*)getDukMachine(duk);
memory->api.sprite_ex(memory, &memory->ram.gfx, index, x, y, w, h, colors, count, scale, flip, rotate); memory->api.sprite_ex(memory, &memory->ram.tiles, index, x, y, w, h, colors, count, scale, flip, rotate);
return 0; return 0;
} }
@ -257,7 +257,7 @@ static duk_ret_t duk_sfx(duk_context* duk)
{ {
if(index >= 0) if(index >= 0)
{ {
tic_sound_effect* effect = memory->ram.sound.sfx.data + index; tic_sound_effect* effect = memory->ram.sfx.data + index;
note = effect->note; note = effect->note;
octave = effect->octave; octave = effect->octave;
@ -361,14 +361,14 @@ static duk_ret_t duk_map(duk_context* duk)
tic_mem* memory = (tic_mem*)getDukMachine(duk); tic_mem* memory = (tic_mem*)getDukMachine(duk);
if (duk_is_null_or_undefined(duk, 8)) if (duk_is_null_or_undefined(duk, 8))
memory->api.map(memory, &memory->ram.gfx, x, y, w, h, sx, sy, chromakey, scale); memory->api.map(memory, &memory->ram.map, &memory->ram.tiles, x, y, w, h, sx, sy, chromakey, scale);
else else
{ {
void* remap = duk_get_heapptr(duk, 8); void* remap = duk_get_heapptr(duk, 8);
RemapData data = {duk, remap}; RemapData data = {duk, remap};
memory->api.remap((tic_mem*)getDukMachine(duk), &memory->ram.gfx, x, y, w, h, sx, sy, chromakey, scale, remapCallback, &data); memory->api.remap((tic_mem*)getDukMachine(duk), &memory->ram.map, &memory->ram.tiles, x, y, w, h, sx, sy, chromakey, scale, remapCallback, &data);
} }
return 0; return 0;
@ -381,7 +381,7 @@ static duk_ret_t duk_mget(duk_context* duk)
tic_mem* memory = (tic_mem*)getDukMachine(duk); tic_mem* memory = (tic_mem*)getDukMachine(duk);
u8 value = memory->api.map_get(memory, &memory->ram.gfx, x, y); u8 value = memory->api.map_get(memory, &memory->ram.map, x, y);
duk_push_uint(duk, value); duk_push_uint(duk, value);
return 1; return 1;
} }
@ -394,7 +394,7 @@ static duk_ret_t duk_mset(duk_context* duk)
tic_mem* memory = (tic_mem*)getDukMachine(duk); tic_mem* memory = (tic_mem*)getDukMachine(duk);
memory->api.map_set(memory, &memory->ram.gfx, x, y, value); memory->api.map_set(memory, &memory->ram.map, x, y, value);
return 1; return 1;
} }

View File

@ -490,7 +490,7 @@ static s32 lua_spr(lua_State* lua)
tic_mem* memory = (tic_mem*)getLuaMachine(lua); tic_mem* memory = (tic_mem*)getLuaMachine(lua);
memory->api.sprite_ex(memory, &memory->ram.gfx, index, x, y, w, h, colors, count, scale, flip, rotate); memory->api.sprite_ex(memory, &memory->ram.tiles, index, x, y, w, h, colors, count, scale, flip, rotate);
return 0; return 0;
} }
@ -506,7 +506,7 @@ static s32 lua_mget(lua_State* lua)
tic_mem* memory = (tic_mem*)getLuaMachine(lua); tic_mem* memory = (tic_mem*)getLuaMachine(lua);
u8 value = memory->api.map_get(memory, &memory->ram.gfx, x, y); u8 value = memory->api.map_get(memory, &memory->ram.map, x, y);
lua_pushinteger(lua, value); lua_pushinteger(lua, value);
return 1; return 1;
} }
@ -527,7 +527,7 @@ static s32 lua_mset(lua_State* lua)
tic_mem* memory = (tic_mem*)getLuaMachine(lua); tic_mem* memory = (tic_mem*)getLuaMachine(lua);
memory->api.map_set(memory, &memory->ram.gfx, x, y, val); memory->api.map_set(memory, &memory->ram.map, x, y, val);
} }
else luaL_error(lua, "invalid params, mget(x,y)\n"); else luaL_error(lua, "invalid params, mget(x,y)\n");
@ -602,7 +602,7 @@ static s32 lua_map(lua_State* lua)
tic_mem* memory = (tic_mem*)getLuaMachine(lua); tic_mem* memory = (tic_mem*)getLuaMachine(lua);
memory->api.remap(memory, &memory->ram.gfx, x, y, w, h, sx, sy, chromakey, scale, remapCallback, &data); memory->api.remap(memory, &memory->ram.map, &memory->ram.tiles, x, y, w, h, sx, sy, chromakey, scale, remapCallback, &data);
luaL_unref(lua, LUA_REGISTRYINDEX, data.reg); luaL_unref(lua, LUA_REGISTRYINDEX, data.reg);
@ -617,7 +617,7 @@ static s32 lua_map(lua_State* lua)
tic_mem* memory = (tic_mem*)getLuaMachine(lua); tic_mem* memory = (tic_mem*)getLuaMachine(lua);
memory->api.map((tic_mem*)getLuaMachine(lua), &memory->ram.gfx, x, y, w, h, sx, sy, chromakey, scale); memory->api.map((tic_mem*)getLuaMachine(lua), &memory->ram.map, &memory->ram.tiles, x, y, w, h, sx, sy, chromakey, scale);
return 0; return 0;
} }
@ -680,7 +680,7 @@ static s32 lua_sfx(lua_State* lua)
{ {
if (index >= 0) if (index >= 0)
{ {
tic_sound_effect* effect = memory->ram.sound.sfx.data + index; tic_sound_effect* effect = memory->ram.sfx.data + index;
note = effect->note; note = effect->note;
octave = effect->octave; octave = effect->octave;

View File

@ -109,7 +109,12 @@ typedef struct
blip_buffer_t* blip; blip_buffer_t* blip;
s32 samplerate; s32 samplerate;
const tic_sound* soundSrc;
struct
{
const tic_sfx* sfx;
const tic_music* music;
} sound;
tic_tick_data* data; tic_tick_data* data;

View File

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

View File

@ -124,7 +124,7 @@ static void drawDialog(Menu* menu)
{ {
u8 chromakey = 14; u8 chromakey = 14;
tic->api.sprite_ex(tic, &tic->config.gfx, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); tic->api.sprite_ex(tic, &tic->config.bank.tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate);
} }
} }
@ -209,7 +209,7 @@ static void drawPlayerButtons(Menu* menu, s32 x, s32 y)
if(menu->gamepad.selected == index && menu->ticks % TIC_FRAMERATE < TIC_FRAMERATE / 2) if(menu->gamepad.selected == index && menu->ticks % TIC_FRAMERATE < TIC_FRAMERATE / 2)
continue; continue;
tic->api.sprite_ex(tic, &tic->config.gfx, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); tic->api.sprite_ex(tic, &tic->config.bank.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate);
s32 code = codes[index]; s32 code = codes[index];
char label[32]; char label[32];

View File

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

View File

@ -106,7 +106,7 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi
static tic_sound_effect* getEffect(Sfx* sfx) static tic_sound_effect* getEffect(Sfx* sfx)
{ {
return sfx->tic->cart.sound.sfx.data + sfx->index; return sfx->tic->cart.bank.sfx.data + sfx->index;
} }
static void setIndex(Sfx* sfx, s32 delta) static void setIndex(Sfx* sfx, s32 delta)
@ -169,7 +169,7 @@ static void drawLoopPanel(Sfx* sfx, s32 x, s32 y)
static tic_waveform* getWaveformById(Sfx* sfx, s32 i) static tic_waveform* getWaveformById(Sfx* sfx, s32 i)
{ {
return &sfx->tic->cart.sound.sfx.waveform.envelopes[i]; return &sfx->tic->cart.bank.sfx.waveform.envelopes[i];
} }
static tic_waveform* getWaveform(Sfx* sfx) static tic_waveform* getWaveform(Sfx* sfx)
@ -1058,8 +1058,8 @@ void initSfx(Sfx* sfx, tic_mem* tic)
.tab = SFX_ENVELOPES_TAB, .tab = SFX_ENVELOPES_TAB,
.history = .history =
{ {
.envelope = history_create(&tic->cart.sound.sfx.data, sizeof tic->cart.sound.sfx.data), .envelope = history_create(&tic->cart.bank.sfx.data, sizeof tic->cart.bank.sfx.data),
.waveform = history_create(&tic->cart.sound.sfx.waveform, sizeof tic->cart.sound.sfx.waveform), .waveform = history_create(&tic->cart.bank.sfx.waveform, sizeof tic->cart.bank.sfx.waveform),
}, },
.event = onStudioEvent, .event = onStudioEvent,
}; };

View File

@ -33,12 +33,12 @@
static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y) static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y)
{ {
return getSpritePixel(sprite->tic->cart.gfx.tiles, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y); return getSpritePixel(sprite->tic->cart.bank.tiles.data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y);
} }
static void setSheetPixel(Sprite* sprite, s32 x, s32 y, u8 color) static void setSheetPixel(Sprite* sprite, s32 x, s32 y, u8 color)
{ {
setSpritePixel(sprite->tic->cart.gfx.tiles, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y, color); setSpritePixel(sprite->tic->cart.bank.tiles.data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y, color);
} }
static s32 getIndexPosX(Sprite* sprite) static s32 getIndexPosX(Sprite* sprite)
@ -940,7 +940,7 @@ static void drawSheetOvr(Sprite* sprite, s32 x, s32 y)
for(s32 j = 0, index = (sprite->index - sprite->index % TIC_BANK_SPRITES); j < rect.h; j += TIC_SPRITESIZE) for(s32 j = 0, index = (sprite->index - sprite->index % TIC_BANK_SPRITES); j < rect.h; j += TIC_SPRITESIZE)
for(s32 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++) for(s32 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++)
sprite->tic->api.sprite(sprite->tic, &sprite->tic->cart.gfx, index, x + i, y + j, NULL, 0); sprite->tic->api.sprite(sprite->tic, &sprite->tic->cart.bank.tiles, index, x + i, y + j, NULL, 0);
{ {
s32 bx = getIndexPosX(sprite) + x - 1; s32 bx = getIndexPosX(sprite) + x - 1;
s32 by = getIndexPosY(sprite) + y - 1; s32 by = getIndexPosY(sprite) + y - 1;
@ -1551,7 +1551,7 @@ void initSprite(Sprite* sprite, tic_mem* tic)
.front = sprite->select.front, .front = sprite->select.front,
}, },
.mode = SPRITE_DRAW_MODE, .mode = SPRITE_DRAW_MODE,
.history = history_create(tic->cart.gfx.tiles, TIC_SPRITES * sizeof(tic_tile)), .history = history_create(&tic->cart.bank.tiles, TIC_SPRITES * sizeof(tic_tile)),
.event = onStudioEvent, .event = onStudioEvent,
.overlap = overlap, .overlap = overlap,
}; };

View File

@ -24,7 +24,7 @@
static void reset(Start* start) static void reset(Start* start)
{ {
u8* tile = (u8*)start->tic->ram.gfx.tiles; u8* tile = (u8*)start->tic->ram.tiles.data;
start->tic->api.clear(start->tic, (tic_color_black)); start->tic->api.clear(start->tic, (tic_color_black));
@ -33,7 +33,7 @@ static void reset(Start* start)
for(s32 i = 0; i < sizeof(tic_tile); i++) tile[i] = val; for(s32 i = 0; i < sizeof(tic_tile); i++) tile[i] = val;
start->tic->api.map(start->tic, &start->tic->ram.gfx, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT + (TIC80_HEIGHT % TIC_SPRITESIZE ? 1 : 0), 0, 0, -1, 1); start->tic->api.map(start->tic, &start->tic->ram.map, &start->tic->ram.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT + (TIC80_HEIGHT % TIC_SPRITESIZE ? 1 : 0), 0, 0, -1, 1);
} }
static void drawHeader(Start* start) static void drawHeader(Start* start)

View File

@ -278,7 +278,7 @@ static struct
void playSystemSfx(s32 id) void playSystemSfx(s32 id)
{ {
const tic_sound_effect* effect = &studio.tic->config.sound.sfx.data[id]; const tic_sound_effect* effect = &studio.tic->config.bank.sfx.data[id];
studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0); studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0);
} }
@ -2042,14 +2042,14 @@ static void renderCursor()
studio.tic->ram.vram.vars.cursor) studio.tic->ram.vram.vars.cursor)
{ {
SDL_ShowCursor(SDL_DISABLE); SDL_ShowCursor(SDL_DISABLE);
blitCursor(studio.tic->ram.gfx.sprites[studio.tic->ram.vram.vars.cursor].data); blitCursor(studio.tic->ram.sprites.data[studio.tic->ram.vram.vars.cursor].data);
return; 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) if(getConfig()->theme.cursor.sprite >= 0)
blitCursor(studio.tic->config.gfx.tiles[getConfig()->theme.cursor.sprite].data); blitCursor(studio.tic->config.bank.tiles.data[getConfig()->theme.cursor.sprite].data);
} }
static void useSystemPalette() static void useSystemPalette()
@ -2091,24 +2091,28 @@ static void renderStudio()
studio.mouse.state[i].click = false; studio.mouse.state[i].click = false;
{ {
const tic_sound* src = NULL; const tic_sfx* sfx = NULL;
const tic_music* music = NULL;
switch(studio.mode) switch(studio.mode)
{ {
case TIC_RUN_MODE: case TIC_RUN_MODE:
src = &studio.tic->ram.sound; sfx = &studio.tic->ram.sfx;
music = &studio.tic->ram.music;
break; break;
case TIC_START_MODE: case TIC_START_MODE:
case TIC_DIALOG_MODE: case TIC_DIALOG_MODE:
case TIC_MENU_MODE: case TIC_MENU_MODE:
case TIC_SURF_MODE: case TIC_SURF_MODE:
src = &studio.tic->config.sound; sfx = &studio.tic->config.bank.sfx;
music = &studio.tic->config.bank.music;
break; break;
default: default:
src = &studio.tic->cart.sound; sfx = &studio.tic->cart.bank.sfx;
music = &studio.tic->cart.bank.music;
} }
studio.tic->api.tick_start(studio.tic, src); studio.tic->api.tick_start(studio.tic, sfx, music);
} }
switch(studio.mode) switch(studio.mode)
@ -2279,7 +2283,7 @@ static void initTouchGamepad()
if (!studio.renderer) if (!studio.renderer)
return; return;
studio.tic->api.map(studio.tic, &studio.tic->config.gfx, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); studio.tic->api.map(studio.tic, &studio.tic->config.bank.map, &studio.tic->config.bank.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1);
if(!studio.gamepad.texture) if(!studio.gamepad.texture)
{ {
@ -2306,7 +2310,7 @@ static void updateSystemFont()
for(s32 i = 0; i < TIC_FONT_CHARS; i++) for(s32 i = 0; i < TIC_FONT_CHARS; i++)
for(s32 y = 0; y < TIC_SPRITESIZE; y++) for(s32 y = 0; y < TIC_SPRITESIZE; y++)
for(s32 x = 0; x < TIC_SPRITESIZE; x++) for(s32 x = 0; x < TIC_SPRITESIZE; x++)
if(tic_tool_peek4(&studio.tic->config.gfx.sprites[i], TIC_SPRITESIZE*(y+1) - x-1)) if(tic_tool_peek4(&studio.tic->config.bank.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1))
studio.tic->font.data[i*BITS_IN_BYTE+y] |= 1 << x; studio.tic->font.data[i*BITS_IN_BYTE+y] |= 1 << x;
} }
@ -2331,7 +2335,7 @@ static void setWindowIcon()
for(s32 j = 0, index = 0; j < Size; j++) for(s32 j = 0, index = 0; j < Size; j++)
for(s32 i = 0; i < Size; i++, index++) for(s32 i = 0; i < Size; i++, index++)
{ {
u8 color = getSpritePixel(studio.tic->config.gfx.tiles, i/Scale, j/Scale); u8 color = getSpritePixel(studio.tic->config.bank.tiles.data, i/Scale, j/Scale);
pixels[index] = color == ColorKey ? 0 : pal[color]; pixels[index] = color == ColorKey ? 0 : pal[color];
} }

View File

@ -202,14 +202,14 @@ static void drawTopToolbar(Surf* surf, s32 x, s32 y)
enum{Gap = 10, TipX = 150, SelectWidth = 54}; enum{Gap = 10, TipX = 150, SelectWidth = 54};
u8 colorkey = 0; u8 colorkey = 0;
tic->api.sprite_ex(tic, &tic->config.gfx, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); tic->api.sprite_ex(tic, &tic->config.bank.tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
{ {
static const char Label[] = "SELECT"; static const char Label[] = "SELECT";
tic->api.text(tic, Label, TipX + Gap, y+3, tic_color_black); tic->api.text(tic, Label, TipX + Gap, y+3, tic_color_black);
tic->api.text(tic, Label, TipX + Gap, y+2, tic_color_white); tic->api.text(tic, Label, TipX + Gap, y+2, tic_color_white);
} }
tic->api.sprite_ex(tic, &tic->config.gfx, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); tic->api.sprite_ex(tic, &tic->config.bank.tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
{ {
static const char Label[] = "BACK"; static const char Label[] = "BACK";
tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black);
@ -244,7 +244,7 @@ static void drawBottomToolbar(Surf* surf, s32 x, s32 y)
u8 colorkey = 0; u8 colorkey = 0;
tic->api.sprite_ex(tic, &tic->config.gfx, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); tic->api.sprite_ex(tic, &tic->config.bank.tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
{ {
static const char Label[] = "WEBSITE"; static const char Label[] = "WEBSITE";
tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black);
@ -355,7 +355,7 @@ static void drawBG(Surf* surf)
for(s32 j = 0; j < Height + 1; j++) for(s32 j = 0; j < Height + 1; j++)
for(s32 i = 0; i < Width + 1; i++) for(s32 i = 0; i < Width + 1; i++)
if(counter++ % 2) if(counter++ % 2)
tic->api.sprite_ex(tic, &tic->config.gfx, 34, i*Size - offset, j*Size - offset, 2, 2, 0, 0, 1, tic_no_flip, tic_no_rotate); tic->api.sprite_ex(tic, &tic->config.bank.tiles, 34, i*Size - offset, j*Size - offset, 2, 2, 0, 0, 1, tic_no_flip, tic_no_rotate);
} }
static void replace(char* src, const char* what, const char* with) static void replace(char* src, const char* what, const char* with)

125
src/tic.c
View File

@ -316,7 +316,7 @@ static void drawTile(tic_machine* machine, const tic_tile* buffer, s32 x, s32 y,
} }
} }
static void drawMap(tic_machine* machine, const tic_gfx* src, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale, RemapFunc remap, void* data) static void drawMap(tic_machine* machine, const tic_map* src, const tic_tiles* tiles, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale, RemapFunc remap, void* data)
{ {
const s32 size = TIC_SPRITESIZE * scale; const s32 size = TIC_SPRITESIZE * scale;
@ -332,12 +332,12 @@ static void drawMap(tic_machine* machine, const tic_gfx* src, s32 x, s32 y, s32
while(mj >= TIC_MAP_HEIGHT) mj -= TIC_MAP_HEIGHT; while(mj >= TIC_MAP_HEIGHT) mj -= TIC_MAP_HEIGHT;
s32 index = mi + mj * TIC_MAP_WIDTH; s32 index = mi + mj * TIC_MAP_WIDTH;
RemapResult tile = { *(src->map.data + index), tic_no_flip, tic_no_rotate }; RemapResult tile = { *(src->data + index), tic_no_flip, tic_no_rotate };
if (remap) if (remap)
remap(data, mi, mj, &tile); remap(data, mi, mj, &tile);
drawTile(machine, src->tiles + tile.index, ii, jj, &chromakey, 1, scale, tile.flip, tile.rotate); drawTile(machine, tiles->data + tile.index, ii, jj, &chromakey, 1, scale, tile.flip, tile.rotate);
} }
} }
@ -356,7 +356,7 @@ static void channelSfx(tic_mem* memory, s32 index, s32 note, s32 octave, s32 dur
if(index >= 0) if(index >= 0)
{ {
struct {s8 speed:SFX_SPEED_BITS;} temp = {speed}; struct {s8 speed:SFX_SPEED_BITS;} temp = {speed};
c->speed = speed == temp.speed ? speed : machine->soundSrc->sfx.data[index].speed; c->speed = speed == temp.speed ? speed : machine->sound.sfx->data[index].speed;
} }
// start index of idealized piano // start index of idealized piano
@ -401,7 +401,7 @@ static void setMusic(tic_machine* machine, s32 index, s32 frame, s32 row, bool l
memory->ram.music_pos.flag.loop = loop; memory->ram.music_pos.flag.loop = loop;
machine->state.music.play = MusicPlay; machine->state.music.play = MusicPlay;
const tic_track* track = &machine->soundSrc->music.tracks.data[index]; const tic_track* track = &machine->sound.music->tracks.data[index];
machine->state.music.ticks = row >= 0 ? row * (track->speed + DEFAULT_SPEED) * NOTES_PER_MUNUTE / (track->tempo + DEFAULT_TEMPO) / DEFAULT_SPEED : 0; machine->state.music.ticks = row >= 0 ? row * (track->speed + DEFAULT_SPEED) * NOTES_PER_MUNUTE / (track->tempo + DEFAULT_TEMPO) / DEFAULT_SPEED : 0;
} }
} }
@ -651,13 +651,13 @@ static s32 api_text_ex(tic_mem* memory, const char* text, s32 x, s32 y, u8 color
return drawText(memory, text, x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT, color, scale, fixed ? drawChar : drawNonFixedChar); return drawText(memory, text, x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT, color, scale, fixed ? drawChar : drawNonFixedChar);
} }
static void drawSprite(tic_mem* memory, const tic_gfx* src, s32 index, s32 x, s32 y, u8* colors, s32 count, s32 scale, tic_flip flip, tic_rotate rotate) static void drawSprite(tic_mem* memory, const tic_tiles* src, s32 index, s32 x, s32 y, u8* colors, s32 count, s32 scale, tic_flip flip, tic_rotate rotate)
{ {
if(index < TIC_SPRITES) if(index < TIC_SPRITES)
drawTile((tic_machine*)memory, src->tiles + index, x, y, colors, count, scale, flip, rotate); drawTile((tic_machine*)memory, src->data + index, x, y, colors, count, scale, flip, rotate);
} }
static void api_sprite_ex(tic_mem* memory, const tic_gfx* src, s32 index, s32 x, s32 y, s32 w, s32 h, u8* colors, s32 count, s32 scale, tic_flip flip, tic_rotate rotate) static void api_sprite_ex(tic_mem* memory, const tic_tiles* src, s32 index, s32 x, s32 y, s32 w, s32 h, u8* colors, s32 count, s32 scale, tic_flip flip, tic_rotate rotate)
{ {
s32 step = TIC_SPRITESIZE * scale; s32 step = TIC_SPRITESIZE * scale;
@ -701,14 +701,14 @@ static void api_sprite_ex(tic_mem* memory, const tic_gfx* src, s32 index, s32 x,
s32 drawSpriteFont(tic_mem* memory, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale) s32 drawSpriteFont(tic_mem* memory, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale)
{ {
api_sprite_ex(memory, &memory->ram.gfx, symbol + TIC_BANK_SPRITES, x, y, 1, 1, &chromakey, 1, scale, tic_no_flip, tic_no_rotate); api_sprite_ex(memory, &memory->ram.sprites, symbol, x, y, 1, 1, &chromakey, 1, scale, tic_no_flip, tic_no_rotate);
return width * scale; return width * scale;
} }
s32 drawFixedSpriteFont(tic_mem* memory, u8 index, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale) s32 drawFixedSpriteFont(tic_mem* memory, u8 index, s32 x, s32 y, s32 width, s32 height, u8 chromakey, s32 scale)
{ {
const u8* ptr = memory->ram.gfx.sprites[index].data; const u8* ptr = memory->ram.sprites.data[index].data;
enum {Size = TIC_SPRITESIZE}; enum {Size = TIC_SPRITESIZE};
@ -935,8 +935,8 @@ static void api_textri(tic_mem* memory, float x1, float y1, float x2, float y2,
{ {
tic_machine* machine = (tic_machine*)memory; tic_machine* machine = (tic_machine*)memory;
TexVert V0, V1, V2; TexVert V0, V1, V2;
const u8* ptr = memory->ram.gfx.tiles[0].data; const u8* ptr = memory->ram.tiles.data[0].data;
const u8* map = memory->ram.gfx.map.data; const u8* map = memory->ram.map.data;
V0.x = (float)x1; V0.y = (float)y1; V0.u = (float)u1; V0.v = (float)v1; V0.x = (float)x1; V0.y = (float)y1; V0.u = (float)u1; V0.v = (float)v1;
V1.x = (float)x2; V1.y = (float)y2; V1.u = (float)u2; V1.v = (float)v2; V1.x = (float)x2; V1.y = (float)y2; V1.u = (float)u2; V1.v = (float)v2;
@ -996,33 +996,33 @@ static void api_textri(tic_mem* memory, float x1, float y1, float x2, float y2,
} }
static void api_sprite(tic_mem* memory, const tic_gfx* src, s32 index, s32 x, s32 y, u8* colors, s32 count) static void api_sprite(tic_mem* memory, const tic_tiles* src, s32 index, s32 x, s32 y, u8* colors, s32 count)
{ {
drawSprite(memory, src, index, x, y, colors, count, 1, tic_no_flip, tic_no_rotate); drawSprite(memory, src, index, x, y, colors, count, 1, tic_no_flip, tic_no_rotate);
} }
static void api_map(tic_mem* memory, const tic_gfx* src, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale) static void api_map(tic_mem* memory, const tic_map* src, const tic_tiles* tiles, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale)
{ {
drawMap((tic_machine*)memory, src, x, y, width, height, sx, sy, chromakey, scale, NULL, NULL); drawMap((tic_machine*)memory, src, tiles, x, y, width, height, sx, sy, chromakey, scale, NULL, NULL);
} }
static void api_remap(tic_mem* memory, const tic_gfx* src, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale, RemapFunc remap, void* data) static void api_remap(tic_mem* memory, const tic_map* src, const tic_tiles* tiles, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale, RemapFunc remap, void* data)
{ {
drawMap((tic_machine*)memory, src, x, y, width, height, sx, sy, chromakey, scale, remap, data); drawMap((tic_machine*)memory, src, tiles, x, y, width, height, sx, sy, chromakey, scale, remap, data);
} }
static void api_map_set(tic_mem* memory, tic_gfx* src, s32 x, s32 y, u8 value) static void api_map_set(tic_mem* memory, tic_map* src, s32 x, s32 y, u8 value)
{ {
if(x < 0 || x >= TIC_MAP_WIDTH || y < 0 || y >= TIC_MAP_HEIGHT) return; if(x < 0 || x >= TIC_MAP_WIDTH || y < 0 || y >= TIC_MAP_HEIGHT) return;
*(src->map.data + y * TIC_MAP_WIDTH + x) = value; *(src->data + y * TIC_MAP_WIDTH + x) = value;
} }
static u8 api_map_get(tic_mem* memory, const tic_gfx* src, s32 x, s32 y) static u8 api_map_get(tic_mem* memory, const tic_map* src, s32 x, s32 y)
{ {
if(x < 0 || x >= TIC_MAP_WIDTH || y < 0 || y >= TIC_MAP_HEIGHT) return 0; if(x < 0 || x >= TIC_MAP_WIDTH || y < 0 || y >= TIC_MAP_HEIGHT) return 0;
return *(src->map.data + y * TIC_MAP_WIDTH + x); return *(src->data + y * TIC_MAP_WIDTH + x);
} }
static void api_line(tic_mem* memory, s32 x0, s32 y0, s32 x1, s32 y1, u8 color) static void api_line(tic_mem* memory, s32 x0, s32 y0, s32 x1, s32 y1, u8 color)
@ -1061,7 +1061,7 @@ static void sfx(tic_mem* memory, s32 index, s32 freq, Channel* channel, tic_soun
return; return;
} }
const tic_sound_effect* effect = &machine->soundSrc->sfx.data[index]; const tic_sound_effect* effect = &machine->sound.sfx->data[index];
s32 pos = ++channel->tick; s32 pos = ++channel->tick;
s8 speed = channel->speed; s8 speed = channel->speed;
@ -1089,7 +1089,7 @@ static void sfx(tic_mem* memory, s32 index, s32 freq, Channel* channel, tic_soun
reg->volume = volume; reg->volume = volume;
u8 wave = effect->data[channel->pos.wave].wave; u8 wave = effect->data[channel->pos.wave].wave;
const tic_waveform* waveform = &machine->soundSrc->sfx.waveform.envelopes[wave]; const tic_waveform* waveform = &machine->sound.sfx->waveform.envelopes[wave];
memcpy(reg->waveform.data, waveform->data, sizeof(tic_waveform)); memcpy(reg->waveform.data, waveform->data, sizeof(tic_waveform));
} }
} }
@ -1100,7 +1100,7 @@ static void processMusic(tic_mem* memory)
if(machine->state.music.play == MusicStop) return; if(machine->state.music.play == MusicStop) return;
const tic_track* track = &machine->soundSrc->music.tracks.data[memory->ram.music_pos.track]; const tic_track* track = &machine->sound.music->tracks.data[memory->ram.music_pos.track];
s32 row = machine->state.music.ticks++ * (track->tempo + DEFAULT_TEMPO) * DEFAULT_SPEED / (track->speed + DEFAULT_SPEED) / NOTES_PER_MUNUTE; s32 row = machine->state.music.ticks++ * (track->tempo + DEFAULT_TEMPO) * DEFAULT_SPEED / (track->speed + DEFAULT_SPEED) / NOTES_PER_MUNUTE;
s32 rows = MUSIC_PATTERN_ROWS - track->rows; s32 rows = MUSIC_PATTERN_ROWS - track->rows;
@ -1161,7 +1161,7 @@ static void processMusic(tic_mem* memory)
s32 patternId = tic_tool_get_pattern_id(track, memory->ram.music_pos.frame, channel); s32 patternId = tic_tool_get_pattern_id(track, memory->ram.music_pos.frame, channel);
if (!patternId) continue; if (!patternId) continue;
const tic_track_pattern* pattern = &machine->soundSrc->music.patterns.data[patternId - PATTERN_START]; const tic_track_pattern* pattern = &machine->sound.music->patterns.data[patternId - PATTERN_START];
s32 note = pattern->rows[memory->ram.music_pos.row].note; s32 note = pattern->rows[memory->ram.music_pos.row].note;
@ -1196,11 +1196,12 @@ static bool isNoiseWaveform(const tic_waveform* wave)
return memcmp(&NoiseWave.data, &wave->data, sizeof(tic_waveform)) == 0; return memcmp(&NoiseWave.data, &wave->data, sizeof(tic_waveform)) == 0;
} }
static void api_tick_start(tic_mem* memory, const tic_sound* src) static void api_tick_start(tic_mem* memory, const tic_sfx* sfxsrc, const tic_music* music)
{ {
tic_machine* machine = (tic_machine*)memory; tic_machine* machine = (tic_machine*)memory;
machine->soundSrc = src; machine->sound.sfx = sfxsrc;
machine->sound.music = music;
for (s32 i = 0; i < TIC_SOUND_CHANNELS; ++i ) for (s32 i = 0; i < TIC_SOUND_CHANNELS; ++i )
memset(&memory->ram.registers[i], 0, sizeof(tic_sound_register)); memset(&memory->ram.registers[i], 0, sizeof(tic_sound_register));
@ -1322,10 +1323,29 @@ static void initCover(tic_mem* tic)
} }
} }
static void api_sync(tic_mem* tic, bool toCart)
{
if(toCart)
{
memcpy(&tic->cart.bank.tiles, &tic->ram.tiles, sizeof(tic_tiles));
memcpy(&tic->cart.bank.sprites, &tic->ram.sprites, sizeof(tic_tiles));
memcpy(&tic->cart.bank.map, &tic->ram.map, sizeof(tic_map));
memcpy(&tic->cart.bank.sfx, &tic->ram.sfx, sizeof(tic_sfx));
memcpy(&tic->cart.bank.music, &tic->ram.music, sizeof(tic_music));
}
else
{
memcpy(&tic->ram.tiles, &tic->cart.bank.tiles, sizeof(tic_tiles));
memcpy(&tic->ram.sprites, &tic->cart.bank.sprites, sizeof(tic_tiles));
memcpy(&tic->ram.map, &tic->cart.bank.map, sizeof(tic_map));
memcpy(&tic->ram.sfx, &tic->cart.bank.sfx, sizeof(tic_sfx));
memcpy(&tic->ram.music, &tic->cart.bank.music, sizeof(tic_music));
}
}
static void cart2ram(tic_mem* memory) static void cart2ram(tic_mem* memory)
{ {
memcpy(&memory->ram.gfx, &memory->cart.gfx, sizeof memory->ram.gfx); api_sync(memory, false);
memcpy(&memory->ram.sound, &memory->cart.sound, sizeof memory->ram.sound);
initCover(memory); initCover(memory);
} }
@ -1532,20 +1552,6 @@ static double api_time(tic_mem* memory)
return (double)((machine->data->counter() - machine->data->start)*1000)/machine->data->freq(); return (double)((machine->data->counter() - machine->data->start)*1000)/machine->data->freq();
} }
static void api_sync(tic_mem* tic, bool toCart)
{
if(toCart)
{
memcpy(&tic->cart.gfx, &tic->ram.gfx, sizeof tic->cart.gfx);
memcpy(&tic->cart.sound, &tic->ram.sound, sizeof tic->cart.sound);
}
else
{
memcpy(&tic->ram.gfx, &tic->cart.gfx, sizeof tic->cart.gfx);
memcpy(&tic->ram.sound, &tic->cart.sound, sizeof tic->cart.sound);
}
}
static u32 api_btnp(tic_mem* tic, s32 index, s32 hold, s32 period) static u32 api_btnp(tic_mem* tic, s32 index, s32 hold, s32 period)
{ {
tic_machine* machine = (tic_machine*)tic; tic_machine* machine = (tic_machine*)tic;
@ -1589,14 +1595,14 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet
switch(chunk.type) switch(chunk.type)
{ {
case CHUNK_TILES: LOAD_CHUNK(cart->gfx.tiles); break; case CHUNK_TILES: LOAD_CHUNK(cart->bank.tiles); break;
case CHUNK_SPRITES: LOAD_CHUNK(cart->gfx.sprites); break; case CHUNK_SPRITES: LOAD_CHUNK(cart->bank.sprites); break;
case CHUNK_MAP: LOAD_CHUNK(cart->gfx.map); break; case CHUNK_MAP: LOAD_CHUNK(cart->bank.map); break;
case CHUNK_CODE: LOAD_CHUNK(cart->code); break; case CHUNK_CODE: LOAD_CHUNK(cart->code); break;
case CHUNK_SOUND: LOAD_CHUNK(cart->sound.sfx.data); break; case CHUNK_SOUND: LOAD_CHUNK(cart->bank.sfx.data); break;
case CHUNK_WAVEFORM: LOAD_CHUNK(cart->sound.sfx.waveform); break; case CHUNK_WAVEFORM: LOAD_CHUNK(cart->bank.sfx.waveform); break;
case CHUNK_MUSIC: LOAD_CHUNK(cart->sound.music.tracks.data); break; case CHUNK_MUSIC: LOAD_CHUNK(cart->bank.music.tracks.data); break;
case CHUNK_PATTERNS: LOAD_CHUNK(cart->sound.music.patterns.data); break; case CHUNK_PATTERNS: LOAD_CHUNK(cart->bank.music.patterns.data); break;
case CHUNK_PALETTE: case CHUNK_PALETTE:
if(palette) if(palette)
LOAD_CHUNK(cart->palette); LOAD_CHUNK(cart->palette);
@ -1658,14 +1664,14 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer)
#define SAVE_CHUNK(id, from) saveChunk(buffer, id, &from, sizeof(from)) #define SAVE_CHUNK(id, from) saveChunk(buffer, id, &from, sizeof(from))
buffer = SAVE_CHUNK(CHUNK_TILES, cart->gfx.tiles); buffer = SAVE_CHUNK(CHUNK_TILES, cart->bank.tiles);
buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->gfx.sprites); buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->bank.sprites);
buffer = SAVE_CHUNK(CHUNK_MAP, cart->gfx.map); buffer = SAVE_CHUNK(CHUNK_MAP, cart->bank.map);
buffer = SAVE_CHUNK(CHUNK_CODE, cart->code); buffer = SAVE_CHUNK(CHUNK_CODE, cart->code);
buffer = SAVE_CHUNK(CHUNK_SOUND, cart->sound.sfx.data); buffer = SAVE_CHUNK(CHUNK_SOUND, cart->bank.sfx.data);
buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->sound.sfx.waveform); buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->bank.sfx.waveform);
buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->sound.music.patterns.data); buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->bank.music.patterns.data);
buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->sound.music.tracks.data); buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->bank.music.tracks.data);
buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette); buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette);
buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size); buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size);
@ -1809,7 +1815,8 @@ tic_mem* tic_create(s32 samplerate)
if(machine != (tic_machine*)&machine->memory) if(machine != (tic_machine*)&machine->memory)
return NULL; return NULL;
machine->soundSrc = &machine->memory.ram.sound; machine->sound.sfx = &machine->memory.ram.sfx;
machine->sound.music = &machine->memory.ram.music;
initApi(&machine->memory.api); initApi(&machine->memory.api);

View File

@ -107,6 +107,8 @@
#define TIC_CODE_SIZE (0x10000) #define TIC_CODE_SIZE (0x10000)
#define TIC_BANKS 4
#define SFX_NOTES {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"} #define SFX_NOTES {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"}
#define API_KEYWORDS {"TIC", "scanline", "OVR", "print", "cls", "pix", "line", "rect", "rectb", \ #define API_KEYWORDS {"TIC", "scanline", "OVR", "print", "cls", "pix", "line", "rect", "rectb", \
@ -294,13 +296,6 @@ typedef struct
u8 data[TIC_SPRITESIZE * TIC_SPRITESIZE * TIC_PALETTE_BPP / BITS_IN_BYTE]; u8 data[TIC_SPRITESIZE * TIC_SPRITESIZE * TIC_PALETTE_BPP / BITS_IN_BYTE];
} tic_tile; } tic_tile;
typedef struct
{
tic_tile tiles[TIC_BANK_SPRITES];
tic_tile sprites[TIC_BANK_SPRITES];
tic_map map;
} tic_gfx;
typedef struct typedef struct
{ {
char data[TIC_CODE_SIZE]; char data[TIC_CODE_SIZE];
@ -328,14 +323,26 @@ typedef union
typedef struct typedef struct
{ {
tic_sfx sfx; tic_tile data[TIC_BANK_SPRITES];
tic_music music; } tic_tiles;
} tic_sound;
typedef struct typedef struct
{ {
tic_gfx gfx; tic_tiles tiles;
tic_sound sound; tic_tiles sprites;
tic_map map;
tic_sfx sfx;
tic_music music;
} tic_bank;
typedef struct
{
union
{
tic_bank bank;
tic_bank banks[TIC_BANKS];
};
tic_code code; tic_code code;
tic_cover_image cover; tic_cover_image cover;
tic_palette palette; tic_palette palette;
@ -405,10 +412,13 @@ typedef union
struct struct
{ {
tic_vram vram; tic_vram vram;
tic_gfx gfx; tic_tiles tiles;
tic_tiles sprites;
tic_map map;
tic_persistent persistent; tic_persistent persistent;
tic_sound_register registers[TIC_SOUND_CHANNELS]; tic_sound_register registers[TIC_SOUND_CHANNELS];
tic_sound sound; tic_sfx sfx;
tic_music music;
tic_music_pos music_pos; tic_music_pos music_pos;
}; };

View File

@ -119,7 +119,7 @@ TIC80_API void tic80_tick(tic80* tic, tic80_input input)
tic80->memory->ram.vram.input.gamepad.data = input.data; tic80->memory->ram.vram.input.gamepad.data = input.data;
tic80->memory->api.tick_start(tic80->memory, &tic80->memory->ram.sound); tic80->memory->api.tick_start(tic80->memory, &tic80->memory->ram.sfx, &tic80->memory->ram.music);
tic80->memory->api.tick(tic80->memory, &tic80->tickData); tic80->memory->api.tick(tic80->memory, &tic80->tickData);
tic80->memory->api.tick_end(tic80->memory); tic80->memory->api.tick_end(tic80->memory);

View File

@ -77,12 +77,12 @@ typedef struct
void (*line) (tic_mem* memory, s32 x1, s32 y1, s32 x2, s32 y2, u8 color); void (*line) (tic_mem* memory, s32 x1, s32 y1, s32 x2, s32 y2, u8 color);
void (*rect) (tic_mem* memory, s32 x, s32 y, s32 width, s32 height, u8 color); void (*rect) (tic_mem* memory, s32 x, s32 y, s32 width, s32 height, u8 color);
void (*rect_border) (tic_mem* memory, s32 x, s32 y, s32 width, s32 height, u8 color); void (*rect_border) (tic_mem* memory, s32 x, s32 y, s32 width, s32 height, u8 color);
void (*sprite) (tic_mem* memory, const tic_gfx* src, s32 index, s32 x, s32 y, u8* colors, s32 count); void (*sprite) (tic_mem* memory, const tic_tiles* src, s32 index, s32 x, s32 y, u8* colors, s32 count);
void (*sprite_ex) (tic_mem* memory, const tic_gfx* src, s32 index, s32 x, s32 y, s32 w, s32 h, u8* colors, s32 count, s32 scale, tic_flip flip, tic_rotate rotate); void (*sprite_ex) (tic_mem* memory, const tic_tiles* src, s32 index, s32 x, s32 y, s32 w, s32 h, u8* colors, s32 count, s32 scale, tic_flip flip, tic_rotate rotate);
void (*map) (tic_mem* memory, const tic_gfx* src, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale); void (*map) (tic_mem* memory, const tic_map* src, const tic_tiles* tiles, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale);
void (*remap) (tic_mem* memory, const tic_gfx* src, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale, RemapFunc remap, void* data); void (*remap) (tic_mem* memory, const tic_map* src, const tic_tiles* tiles, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8 chromakey, s32 scale, RemapFunc remap, void* data);
void (*map_set) (tic_mem* memory, tic_gfx* src, s32 x, s32 y, u8 value); void (*map_set) (tic_mem* memory, tic_map* src, s32 x, s32 y, u8 value);
u8 (*map_get) (tic_mem* memory, const tic_gfx* src, s32 x, s32 y); u8 (*map_get) (tic_mem* memory, const tic_map* src, s32 x, s32 y);
void (*circle) (tic_mem* memory, s32 x, s32 y, u32 radius, u8 color); void (*circle) (tic_mem* memory, s32 x, s32 y, u32 radius, u8 color);
void (*circle_border) (tic_mem* memory, s32 x, s32 y, u32 radius, u8 color); void (*circle_border) (tic_mem* memory, s32 x, s32 y, u32 radius, u8 color);
void (*tri) (tic_mem* memory, s32 x1, s32 y1, s32 x2, s32 y2, s32 x3, s32 y3, u8 color); void (*tri) (tic_mem* memory, s32 x1, s32 y1, s32 x2, s32 y2, s32 x3, s32 y3, u8 color);
@ -107,7 +107,7 @@ typedef struct
void (*load) (tic_cartridge* rom, const u8* buffer, s32 size, bool palette); void (*load) (tic_cartridge* rom, const u8* buffer, s32 size, bool palette);
s32 (*save) (const tic_cartridge* rom, u8* buffer); s32 (*save) (const tic_cartridge* rom, u8* buffer);
void (*tick_start) (tic_mem* memory, const tic_sound* src); void (*tick_start) (tic_mem* memory, const tic_sfx* sfx, const tic_music* music);
void (*tick_end) (tic_mem* memory); void (*tick_end) (tic_mem* memory);
void (*blit) (tic_mem* tic, tic_scanline scanline, tic_overlap overlap, void* data); void (*blit) (tic_mem* tic, tic_scanline scanline, tic_overlap overlap, void* data);

View File

@ -105,13 +105,13 @@ void initWorld(World* world, tic_mem* tic, Map* map)
for(s32 i = 0; i < TIC80_WIDTH * TIC80_HEIGHT; i++) for(s32 i = 0; i < TIC80_WIDTH * TIC80_HEIGHT; i++)
{ {
u8 index = tic->cart.gfx.map.data[i]; u8 index = tic->cart.bank.map.data[i];
if(index) if(index)
{ {
SDL_memset(colors, 0, sizeof colors); SDL_memset(colors, 0, sizeof colors);
tic_tile* tile = &tic->cart.gfx.tiles[index]; tic_tile* tile = &tic->cart.bank.tiles.data[index];
for(s32 p = 0; p < TIC_SPRITESIZE * TIC_SPRITESIZE; p++) for(s32 p = 0; p < TIC_SPRITESIZE * TIC_SPRITESIZE; p++)
{ {