From 694a0163340b95ca244fd8ede41ea0d5aa77be19 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Sun, 10 Dec 2017 11:32:49 +0300 Subject: [PATCH 1/7] no message --- src/console.c | 27 +++++++++--------- src/dialog.c | 2 +- src/jsapi.c | 10 +++---- src/luaapi.c | 10 +++---- src/map.c | 28 +++++++++---------- src/menu.c | 4 +-- src/music.c | 2 +- src/sprite.c | 8 +++--- src/start.c | 4 +-- src/studio.c | 10 +++---- src/surf.c | 8 +++--- src/tic.c | 76 +++++++++++++++++++++++++++------------------------ src/tic.h | 42 +++++++++++++++++++++------- src/ticapi.h | 12 ++++---- src/world.c | 4 +-- 15 files changed, 137 insertions(+), 110 deletions(-) diff --git a/src/console.c b/src/console.c index 549d40d..0d62e7a 100644 --- a/src/console.c +++ b/src/console.c @@ -359,8 +359,8 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param) switch(i) { - case 0: memcpy(&tic->cart.gfx.tiles, &cart->gfx.tiles, sizeof cart->gfx.tiles + sizeof cart->gfx.sprites); break; - case 1: memcpy(&tic->cart.gfx.map, &cart->gfx.map, sizeof cart->gfx.map); break; + case 0: memcpy(&tic->cart.tiles, &cart->tiles, sizeof cart->tiles + sizeof cart->sprites); break; + case 1: memcpy(&tic->cart.map, &cart->map, sizeof cart->map); 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 4: memcpy(&tic->cart.sound.sfx, &cart->sound.sfx, sizeof cart->sound.sfx); break; @@ -603,9 +603,9 @@ typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySe static const BinarySection BinarySections[] = { {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, - {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, gfx.tiles), sizeof(tic_tile), true}, - {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, gfx.sprites), sizeof(tic_tile), true}, - {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, gfx.map), TIC_MAP_WIDTH, true}, + {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, tiles), sizeof(tic_tile), true}, + {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, sprites), sizeof(tic_tile), true}, + {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, map), TIC_MAP_WIDTH, true}, {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge,sound.sfx.waveform.envelopes), sizeof(tic_waveform), true}, {"SFX", SFX_COUNT, offsetof(tic_cartridge, sound.sfx.data), sizeof(tic_sound_effect), true}, {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, sound.music.patterns), sizeof(tic_track_pattern), true}, @@ -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}; 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.tiles.data, x, y, color); } gif_close(image); @@ -1352,8 +1352,8 @@ static void injectMap(Console* console, const void* buffer, s32 size) { enum {Size = sizeof(tic_map)}; - SDL_memset(&console->tic->cart.gfx.map, 0, Size); - SDL_memcpy(&console->tic->cart.gfx.map, buffer, SDL_min(size, Size)); + SDL_memset(&console->tic->cart.map, 0, Size); + SDL_memcpy(&console->tic->cart.map, buffer, SDL_min(size, Size)); } static void onImportMap(const char* name, const void* buffer, size_t size, void* data) @@ -1453,7 +1453,7 @@ static void exportSprites(Console* console) { for (s32 y = 0; y < Height; y++) for (s32 x = 0; x < Width; x++) - data[x + y * Width] = getSpritePixel(console->tic->cart.gfx.tiles, x, y); + data[x + y * Width] = getSpritePixel(console->tic->cart.tiles.data, x, y); s32 size = 0; if((size = writeGifData(console->tic, buffer, data, Width, Height))) @@ -1493,7 +1493,7 @@ static void exportMap(Console* console) if(buffer) { - SDL_memcpy(buffer, console->tic->cart.gfx.map.data, Size); + SDL_memcpy(buffer, console->tic->cart.map.data, Size); fsGetFileData(onMapExported, "world.map", buffer, Size, DEFAULT_CHMOD, console); } } @@ -2136,8 +2136,9 @@ static void onConsoleRamCommand(Console* console, const char* param) {offsetof(tic_ram, vram.vars.mask), "GAMEPAD MASK"}, {offsetof(tic_ram, vram.input.gamepad), "GAMEPAD"}, {offsetof(tic_ram, vram.input.reserved), "..."}, - {offsetof(tic_ram, gfx.tiles), "SPRITES"}, - {offsetof(tic_ram, gfx.map), "MAP"}, + {offsetof(tic_ram, tiles), "TILES"}, + {offsetof(tic_ram, sprites), "SPRITES"}, + {offsetof(tic_ram, map), "MAP"}, {offsetof(tic_ram, persistent), "PERSISTENT MEMORY"}, {offsetof(tic_ram, registers), "SOUND REGISTERS"}, {offsetof(tic_ram, sound.sfx.waveform), "WAVEFORMS"}, @@ -2763,7 +2764,7 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na tic_rgb rgb = {c->r, c->g, c->b}; u8 color = tic_tool_find_closest_color(embed.file.palette.colors, &rgb); - setSpritePixel(embed.file.gfx.tiles, x, y, color); + setSpritePixel(embed.file.tiles.data, x, y, color); } gif_close(image); diff --git a/src/dialog.c b/src/dialog.c index ce80edd..e28b224 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -170,7 +170,7 @@ static void drawDialog(Dialog* dlg) { 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.tiles, 2, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); } { diff --git a/src/jsapi.c b/src/jsapi.c index 858b150..5f91944 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -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); 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; } @@ -361,14 +361,14 @@ static duk_ret_t duk_map(duk_context* duk) tic_mem* memory = (tic_mem*)getDukMachine(duk); 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 { void* remap = duk_get_heapptr(duk, 8); 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; @@ -381,7 +381,7 @@ static duk_ret_t duk_mget(duk_context* 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); return 1; } @@ -394,7 +394,7 @@ static duk_ret_t duk_mset(duk_context* 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; } diff --git a/src/luaapi.c b/src/luaapi.c index 638d803..32cd45b 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -490,7 +490,7 @@ static s32 lua_spr(lua_State* 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; } @@ -506,7 +506,7 @@ static s32 lua_mget(lua_State* 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); return 1; } @@ -527,7 +527,7 @@ static s32 lua_mset(lua_State* 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"); @@ -602,7 +602,7 @@ static s32 lua_map(lua_State* 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); @@ -617,7 +617,7 @@ static s32 lua_map(lua_State* 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; } diff --git a/src/map.c b/src/map.c index c18b9ff..973909b 100644 --- a/src/map.c +++ b/src/map.c @@ -314,7 +314,7 @@ static void drawTileIndex(Map* map, s32 x, s32 y) { s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - index = map->tic->api.map_get(map->tic, &map->tic->cart.gfx, tx, ty); + index = map->tic->api.map_get(map->tic, &map->tic->cart.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 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.tiles, index, x + i, y + j, NULL, 0); { 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 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.map, (x+i)%TIC_MAP_WIDTH, (y+j)%TIC_MAP_HEIGHT, (mx+i) + (my+j) * SHEET_COLS); 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 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.tiles, (sx+i) + (sy+j) * SHEET_COLS, tx, ty, NULL, 0); } drawCursorPos(map, mx, my); @@ -512,7 +512,7 @@ static void processMouseDrawMode(Map* map) { s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - s32 index = map->tic->api.map_get(map->tic, &map->tic->cart.gfx, tx, ty); + s32 index = map->tic->api.map_get(map->tic, &map->tic->cart.map, tx, ty); map->sheet.rect = (SDL_Rect){index % SHEET_COLS, index / SHEET_COLS, 1, 1}; } @@ -593,7 +593,7 @@ static void drawPasteData(Map* map) for(s32 j = 0; j < h; j++) for(s32 i = 0; i < w; i++) - map->tic->api.map_set(map->tic, &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.map, (mx+i)%TIC_MAP_WIDTH, (my+j)%TIC_MAP_HEIGHT, data[i + j * w]); history_add(map->history); @@ -612,7 +612,7 @@ static void drawPasteData(Map* map) for(s32 j = 0; j < h; j++) 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.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 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.map, x+i, y+j, (mx+i) + (my+j) * SHEET_COLS); for(s32 i = 0; i < COUNT_OF(dx); i++) { @@ -776,7 +776,7 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile) bool match = true; for(s32 j = 0; j < map->sheet.rect.h; j++) for(s32 i = 0; i < map->sheet.rect.w; i++) - if(map->tic->api.map_get(map->tic, &map->tic->cart.gfx, nx+i, ny+j) != tile) + if(map->tic->api.map_get(map->tic, &map->tic->cart.map, nx+i, ny+j) != tile) match = false; if(match) @@ -801,7 +801,7 @@ static void processMouseFillMode(Map* map) s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - fillMap(map, tx, ty, map->tic->api.map_get(map->tic, &map->tic->cart.gfx, tx, ty)); + fillMap(map, tx, ty, map->tic->api.map_get(map->tic, &map->tic->cart.map, tx, ty)); history_add(map->history); } } @@ -864,7 +864,7 @@ static void drawMapOvr(Map* map) s32 scrollX = map->scroll.x % TIC_SPRITESIZE; s32 scrollY = map->scroll.y % TIC_SPRITESIZE; - map->tic->api.map(map->tic, &map->tic->cart.gfx, map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE, + map->tic->api.map(map->tic, &map->tic->cart.map, &map->tic->cart.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); if(map->canvas.grid || map->scroll.active) @@ -950,7 +950,7 @@ static void copySelectionToClipboard(Map* map) normalizeMapRect(&x, &y); s32 index = x + y * TIC_MAP_WIDTH; - *ptr++ = map->tic->cart.gfx.map.data[index]; + *ptr++ = map->tic->cart.map.data[index]; } toClipboard(buffer, size, true); @@ -978,7 +978,7 @@ static void deleteSelection(Map* map) normalizeMapRect(&x, &y); s32 index = x + y * TIC_MAP_WIDTH; - map->tic->cart.gfx.map.data[index] = 0; + map->tic->cart.map.data[index] = 0; } history_add(map->history); @@ -1185,7 +1185,7 @@ void initMap(Map* map, tic_mem* tic) .gesture = false, .start = {0, 0}, }, - .history = history_create(&tic->cart.gfx.map, sizeof tic->cart.gfx.map), + .history = history_create(&tic->cart.map, sizeof tic->cart.map), .event = onStudioEvent, .overlap = overlap, }; diff --git a/src/menu.c b/src/menu.c index 04e4d00..0e38308 100644 --- a/src/menu.c +++ b/src/menu.c @@ -124,7 +124,7 @@ static void drawDialog(Menu* menu) { 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.tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); } } @@ -209,7 +209,7 @@ static void drawPlayerButtons(Menu* menu, s32 x, s32 y) if(menu->gamepad.selected == index && menu->ticks % TIC_FRAMERATE < TIC_FRAMERATE / 2) continue; - tic->api.sprite_ex(tic, &tic->config.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.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]; diff --git a/src/music.c b/src/music.c index 5ca4ba8..2dc9494 100644 --- a/src/music.c +++ b/src/music.c @@ -1327,7 +1327,7 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index) } 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.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1); } static void drawTracker(Music* music, s32 x, s32 y) diff --git a/src/sprite.c b/src/sprite.c index a5d7656..c56e010 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -33,12 +33,12 @@ 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.tiles.data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y); } 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.tiles.data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y, color); } 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 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.tiles, index, x + i, y + j, NULL, 0); { s32 bx = getIndexPosX(sprite) + x - 1; s32 by = getIndexPosY(sprite) + y - 1; @@ -1551,7 +1551,7 @@ void initSprite(Sprite* sprite, tic_mem* tic) .front = sprite->select.front, }, .mode = SPRITE_DRAW_MODE, - .history = history_create(tic->cart.gfx.tiles, TIC_SPRITES * sizeof(tic_tile)), + .history = history_create(&tic->cart.tiles, TIC_SPRITES * sizeof(tic_tile)), .event = onStudioEvent, .overlap = overlap, }; diff --git a/src/start.c b/src/start.c index 9761ac9..1655e72 100644 --- a/src/start.c +++ b/src/start.c @@ -24,7 +24,7 @@ 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)); @@ -33,7 +33,7 @@ static void reset(Start* start) 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) diff --git a/src/studio.c b/src/studio.c index 492013a..34e3538 100644 --- a/src/studio.c +++ b/src/studio.c @@ -2042,14 +2042,14 @@ static void renderCursor() studio.tic->ram.vram.vars.cursor) { 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; } SDL_ShowCursor(getConfig()->theme.cursor.sprite >= 0 ? SDL_DISABLE : SDL_ENABLE); if(getConfig()->theme.cursor.sprite >= 0) - blitCursor(studio.tic->config.gfx.tiles[getConfig()->theme.cursor.sprite].data); + blitCursor(studio.tic->config.tiles.data[getConfig()->theme.cursor.sprite].data); } static void useSystemPalette() @@ -2279,7 +2279,7 @@ static void initTouchGamepad() if (!studio.renderer) 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.map, &studio.tic->config.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); if(!studio.gamepad.texture) { @@ -2306,7 +2306,7 @@ static void updateSystemFont() for(s32 i = 0; i < TIC_FONT_CHARS; i++) for(s32 y = 0; y < TIC_SPRITESIZE; y++) for(s32 x = 0; x < TIC_SPRITESIZE; x++) - if(tic_tool_peek4(&studio.tic->config.gfx.sprites[i], TIC_SPRITESIZE*(y+1) - x-1)) + if(tic_tool_peek4(&studio.tic->config.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1)) studio.tic->font.data[i*BITS_IN_BYTE+y] |= 1 << x; } @@ -2331,7 +2331,7 @@ static void setWindowIcon() for(s32 j = 0, index = 0; j < Size; j++) for(s32 i = 0; i < Size; i++, index++) { - u8 color = getSpritePixel(studio.tic->config.gfx.tiles, i/Scale, j/Scale); + u8 color = getSpritePixel(studio.tic->config.tiles.data, i/Scale, j/Scale); pixels[index] = color == ColorKey ? 0 : pal[color]; } diff --git a/src/surf.c b/src/surf.c index 6d8ff81..3e15d63 100644 --- a/src/surf.c +++ b/src/surf.c @@ -202,14 +202,14 @@ static void drawTopToolbar(Surf* surf, s32 x, s32 y) enum{Gap = 10, TipX = 150, SelectWidth = 54}; u8 colorkey = 0; - tic->api.sprite_ex(tic, &tic->config.gfx, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "SELECT"; tic->api.text(tic, Label, TipX + Gap, y+3, tic_color_black); tic->api.text(tic, Label, TipX + Gap, y+2, tic_color_white); } - tic->api.sprite_ex(tic, &tic->config.gfx, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "BACK"; tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); @@ -244,7 +244,7 @@ static void drawBottomToolbar(Surf* surf, s32 x, s32 y) u8 colorkey = 0; - tic->api.sprite_ex(tic, &tic->config.gfx, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "WEBSITE"; tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); @@ -355,7 +355,7 @@ static void drawBG(Surf* surf) for(s32 j = 0; j < Height + 1; j++) for(s32 i = 0; i < Width + 1; i++) if(counter++ % 2) - tic->api.sprite_ex(tic, &tic->config.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.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) diff --git a/src/tic.c b/src/tic.c index c6bb8a2..819e7fb 100644 --- a/src/tic.c +++ b/src/tic.c @@ -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; @@ -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; 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) 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); } } @@ -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); } -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) - 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; @@ -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) { - 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; } 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}; @@ -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; TexVert V0, V1, V2; - const u8* ptr = memory->ram.gfx.tiles[0].data; - const u8* map = memory->ram.gfx.map.data; + const u8* ptr = memory->ram.tiles.data[0].data; + const u8* map = memory->ram.map.data; 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; @@ -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); } -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; - *(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; - 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) @@ -1324,7 +1324,10 @@ static void initCover(tic_mem* tic) static void cart2ram(tic_mem* memory) { - memcpy(&memory->ram.gfx, &memory->cart.gfx, sizeof memory->ram.gfx); + memcpy(&memory->ram.tiles, &memory->cart.tiles, sizeof(tic_tiles)); + memcpy(&memory->ram.sprites, &memory->cart.sprites, sizeof(tic_tiles)); + memcpy(&memory->ram.map, &memory->cart.map, sizeof(tic_tiles)); + memcpy(&memory->ram.sound, &memory->cart.sound, sizeof memory->ram.sound); initCover(memory); @@ -1534,16 +1537,17 @@ static double api_time(tic_mem* memory) 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); - } + // TODO: fix this + // 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) @@ -1589,9 +1593,9 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet switch(chunk.type) { - case CHUNK_TILES: LOAD_CHUNK(cart->gfx.tiles); break; - case CHUNK_SPRITES: LOAD_CHUNK(cart->gfx.sprites); break; - case CHUNK_MAP: LOAD_CHUNK(cart->gfx.map); break; + case CHUNK_TILES: LOAD_CHUNK(cart->tiles); break; + case CHUNK_SPRITES: LOAD_CHUNK(cart->sprites); break; + case CHUNK_MAP: LOAD_CHUNK(cart->map); break; case CHUNK_CODE: LOAD_CHUNK(cart->code); break; case CHUNK_SOUND: LOAD_CHUNK(cart->sound.sfx.data); break; case CHUNK_WAVEFORM: LOAD_CHUNK(cart->sound.sfx.waveform); break; @@ -1658,9 +1662,9 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) #define SAVE_CHUNK(id, from) saveChunk(buffer, id, &from, sizeof(from)) - buffer = SAVE_CHUNK(CHUNK_TILES, cart->gfx.tiles); - buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->gfx.sprites); - buffer = SAVE_CHUNK(CHUNK_MAP, cart->gfx.map); + buffer = SAVE_CHUNK(CHUNK_TILES, cart->tiles); + buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->sprites); + buffer = SAVE_CHUNK(CHUNK_MAP, cart->map); buffer = SAVE_CHUNK(CHUNK_CODE, cart->code); buffer = SAVE_CHUNK(CHUNK_SOUND, cart->sound.sfx.data); buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->sound.sfx.waveform); diff --git a/src/tic.h b/src/tic.h index ea22bfd..e39915b 100644 --- a/src/tic.h +++ b/src/tic.h @@ -107,6 +107,8 @@ #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 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]; } tic_tile; -typedef struct -{ - tic_tile tiles[TIC_BANK_SPRITES]; - tic_tile sprites[TIC_BANK_SPRITES]; - tic_map map; -} tic_gfx; - typedef struct { char data[TIC_CODE_SIZE]; @@ -334,8 +329,33 @@ typedef struct typedef struct { - tic_gfx gfx; - tic_sound sound; + tic_tile data[TIC_BANK_SPRITES]; +} tic_tiles; + +typedef struct +{ + tic_tiles tiles; + tic_tiles sprites; + tic_map map; + tic_sfx sfx; + tic_music music; +} tic_bank; + +typedef struct +{ + union + { + struct + { + tic_tiles tiles; + tic_tiles sprites; + tic_map map; + tic_sound sound; + }; + + tic_bank banks[TIC_BANKS]; + }; + tic_code code; tic_cover_image cover; tic_palette palette; @@ -405,7 +425,9 @@ typedef union struct { tic_vram vram; - tic_gfx gfx; + tic_tiles tiles; + tic_tiles sprites; + tic_map map; tic_persistent persistent; tic_sound_register registers[TIC_SOUND_CHANNELS]; tic_sound sound; diff --git a/src/ticapi.h b/src/ticapi.h index 144cc62..52280c1 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -77,12 +77,12 @@ typedef struct 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_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_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 (*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 (*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 (*map_set) (tic_mem* memory, tic_gfx* src, s32 x, s32 y, u8 value); - u8 (*map_get) (tic_mem* memory, const tic_gfx* src, s32 x, s32 y); + 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_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_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_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_map* src, s32 x, s32 y, u8 value); + 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_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); diff --git a/src/world.c b/src/world.c index bae1698..8d6dda0 100644 --- a/src/world.c +++ b/src/world.c @@ -105,13 +105,13 @@ void initWorld(World* world, tic_mem* tic, Map* map) for(s32 i = 0; i < TIC80_WIDTH * TIC80_HEIGHT; i++) { - u8 index = tic->cart.gfx.map.data[i]; + u8 index = tic->cart.map.data[i]; if(index) { SDL_memset(colors, 0, sizeof colors); - tic_tile* tile = &tic->cart.gfx.tiles[index]; + tic_tile* tile = &tic->cart.tiles.data[index]; for(s32 p = 0; p < TIC_SPRITESIZE * TIC_SPRITESIZE; p++) { From be7151386df5f9a790e57c8793d7304add95e7b2 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Sun, 10 Dec 2017 12:12:09 +0300 Subject: [PATCH 2/7] no message --- src/console.c | 20 ++++++++++---------- src/jsapi.c | 2 +- src/luaapi.c | 2 +- src/machine.h | 7 ++++++- src/music.c | 6 +++--- src/sfx.c | 8 ++++---- src/studio.c | 16 ++++++++++------ src/tic.c | 39 +++++++++++++++++++++------------------ src/tic.h | 16 +++++++++------- src/tic80.c | 2 +- src/ticapi.h | 2 +- 11 files changed, 67 insertions(+), 53 deletions(-) diff --git a/src/console.c b/src/console.c index 0d62e7a..0467f46 100644 --- a/src/console.c +++ b/src/console.c @@ -363,8 +363,8 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param) case 1: memcpy(&tic->cart.map, &cart->map, sizeof cart->map); 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 4: memcpy(&tic->cart.sound.sfx, &cart->sound.sfx, sizeof cart->sound.sfx); break; - case 5: memcpy(&tic->cart.sound.music, &cart->sound.music, sizeof cart->sound.music); break; + case 4: memcpy(&tic->cart.sfx, &cart->sfx, sizeof cart->sfx); break; + case 5: memcpy(&tic->cart.music, &cart->music, sizeof cart->music); break; case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof cart->palette); break; } @@ -606,10 +606,10 @@ static const BinarySection BinarySections[] = {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, tiles), sizeof(tic_tile), true}, {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, sprites), sizeof(tic_tile), true}, {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, map), TIC_MAP_WIDTH, true}, - {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge,sound.sfx.waveform.envelopes), sizeof(tic_waveform), true}, - {"SFX", SFX_COUNT, offsetof(tic_cartridge, sound.sfx.data), sizeof(tic_sound_effect), true}, - {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, sound.music.patterns), sizeof(tic_track_pattern), true}, - {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, sound.music.tracks), sizeof(tic_track), true}, + {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, sfx.waveform.envelopes), sizeof(tic_waveform), true}, + {"SFX", SFX_COUNT, offsetof(tic_cartridge, sfx.data), sizeof(tic_sound_effect), true}, + {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, music.patterns), sizeof(tic_track_pattern), true}, + {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, music.tracks), sizeof(tic_track), true}, }; static s32 saveProject(Console* console, void* buffer, const char* comment) @@ -2141,10 +2141,10 @@ static void onConsoleRamCommand(Console* console, const char* param) {offsetof(tic_ram, map), "MAP"}, {offsetof(tic_ram, persistent), "PERSISTENT MEMORY"}, {offsetof(tic_ram, registers), "SOUND REGISTERS"}, - {offsetof(tic_ram, sound.sfx.waveform), "WAVEFORMS"}, - {offsetof(tic_ram, sound.sfx.data), "SFX"}, - {offsetof(tic_ram, sound.music.patterns.data), "MUSIC PATTERNS"}, - {offsetof(tic_ram, sound.music.tracks.data), "MUSIC TRACKS"}, + {offsetof(tic_ram, sfx.waveform), "WAVEFORMS"}, + {offsetof(tic_ram, sfx.data), "SFX"}, + {offsetof(tic_ram, music.patterns.data), "MUSIC PATTERNS"}, + {offsetof(tic_ram, music.tracks.data), "MUSIC TRACKS"}, {offsetof(tic_ram, music_pos), "MUSIC POS"}, {TIC_RAM_SIZE, "..."}, }; diff --git a/src/jsapi.c b/src/jsapi.c index 5f91944..8889bc3 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -257,7 +257,7 @@ static duk_ret_t duk_sfx(duk_context* duk) { 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; octave = effect->octave; diff --git a/src/luaapi.c b/src/luaapi.c index 32cd45b..bf40d61 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -680,7 +680,7 @@ static s32 lua_sfx(lua_State* lua) { 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; octave = effect->octave; diff --git a/src/machine.h b/src/machine.h index 1f966b6..ef8d9ab 100644 --- a/src/machine.h +++ b/src/machine.h @@ -109,7 +109,12 @@ typedef struct blip_buffer_t* blip; s32 samplerate; - const tic_sound* soundSrc; + + struct + { + const tic_sfx* sfx; + const tic_music* music; + } sound; tic_tick_data* data; diff --git a/src/music.c b/src/music.c index 2dc9494..a061a06 100644 --- a/src/music.c +++ b/src/music.c @@ -215,7 +215,7 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value, static tic_track* getTrack(Music* music) { - return &music->tic->cart.sound.music.tracks.data[music->track]; + return &music->tic->cart.music.tracks.data[music->track]; } static s32 getRows(Music* music) @@ -368,7 +368,7 @@ static tic_track_pattern* getPattern(Music* music, s32 channel) { s32 patternId = tic_tool_get_pattern_id(getTrack(music), music->tracker.frame, channel); - return patternId ? &music->tic->cart.sound.music.patterns.data[patternId - PATTERN_START] : NULL; + return patternId ? &music->tic->cart.music.patterns.data[patternId - PATTERN_START] : NULL; } static tic_track_pattern* getChannelPattern(Music* music) @@ -1643,7 +1643,7 @@ void initMusic(Music* music, tic_mem* tic) }, .tab = MUSIC_TRACKER_TAB, - .history = history_create(&tic->cart.sound.music, sizeof tic->cart.sound.music), + .history = history_create(&tic->cart.music, sizeof(tic_music)), .event = onStudioEvent, }; diff --git a/src/sfx.c b/src/sfx.c index eb466d1..fa4aba6 100644 --- a/src/sfx.c +++ b/src/sfx.c @@ -106,7 +106,7 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi static tic_sound_effect* getEffect(Sfx* sfx) { - return sfx->tic->cart.sound.sfx.data + sfx->index; + return sfx->tic->cart.sfx.data + sfx->index; } 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) { - return &sfx->tic->cart.sound.sfx.waveform.envelopes[i]; + return &sfx->tic->cart.sfx.waveform.envelopes[i]; } static tic_waveform* getWaveform(Sfx* sfx) @@ -1058,8 +1058,8 @@ void initSfx(Sfx* sfx, tic_mem* tic) .tab = SFX_ENVELOPES_TAB, .history = { - .envelope = history_create(&tic->cart.sound.sfx.data, sizeof tic->cart.sound.sfx.data), - .waveform = history_create(&tic->cart.sound.sfx.waveform, sizeof tic->cart.sound.sfx.waveform), + .envelope = history_create(&tic->cart.sfx.data, sizeof tic->cart.sfx.data), + .waveform = history_create(&tic->cart.sfx.waveform, sizeof tic->cart.sfx.waveform), }, .event = onStudioEvent, }; diff --git a/src/studio.c b/src/studio.c index 34e3538..aa0c34f 100644 --- a/src/studio.c +++ b/src/studio.c @@ -278,7 +278,7 @@ static struct void playSystemSfx(s32 id) { - const tic_sound_effect* effect = &studio.tic->config.sound.sfx.data[id]; + const tic_sound_effect* effect = &studio.tic->config.sfx.data[id]; studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0); } @@ -2091,24 +2091,28 @@ static void renderStudio() studio.mouse.state[i].click = false; { - const tic_sound* src = NULL; + const tic_sfx* sfx = NULL; + const tic_music* music = NULL; switch(studio.mode) { case TIC_RUN_MODE: - src = &studio.tic->ram.sound; + sfx = &studio.tic->ram.sfx; + music = &studio.tic->ram.music; break; case TIC_START_MODE: case TIC_DIALOG_MODE: case TIC_MENU_MODE: case TIC_SURF_MODE: - src = &studio.tic->config.sound; + sfx = &studio.tic->config.sfx; + music = &studio.tic->config.music; break; default: - src = &studio.tic->cart.sound; + sfx = &studio.tic->cart.sfx; + music = &studio.tic->cart.music; } - studio.tic->api.tick_start(studio.tic, src); + studio.tic->api.tick_start(studio.tic, sfx, music); } switch(studio.mode) diff --git a/src/tic.c b/src/tic.c index 819e7fb..b29bb9b 100644 --- a/src/tic.c +++ b/src/tic.c @@ -356,7 +356,7 @@ static void channelSfx(tic_mem* memory, s32 index, s32 note, s32 octave, s32 dur if(index >= 0) { 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 @@ -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; 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; } } @@ -1061,7 +1061,7 @@ static void sfx(tic_mem* memory, s32 index, s32 freq, Channel* channel, tic_soun 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; 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; 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)); } } @@ -1100,7 +1100,7 @@ static void processMusic(tic_mem* memory) 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 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); 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; @@ -1196,11 +1196,12 @@ static bool isNoiseWaveform(const tic_waveform* wave) 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; - machine->soundSrc = src; + machine->sound.sfx = sfxsrc; + machine->sound.music = music; for (s32 i = 0; i < TIC_SOUND_CHANNELS; ++i ) memset(&memory->ram.registers[i], 0, sizeof(tic_sound_register)); @@ -1328,7 +1329,8 @@ static void cart2ram(tic_mem* memory) memcpy(&memory->ram.sprites, &memory->cart.sprites, sizeof(tic_tiles)); memcpy(&memory->ram.map, &memory->cart.map, sizeof(tic_tiles)); - memcpy(&memory->ram.sound, &memory->cart.sound, sizeof memory->ram.sound); + memcpy(&memory->ram.sfx, &memory->cart.sfx, sizeof(tic_sfx)); + memcpy(&memory->ram.music, &memory->cart.music, sizeof(tic_music)); initCover(memory); } @@ -1597,10 +1599,10 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet case CHUNK_SPRITES: LOAD_CHUNK(cart->sprites); break; case CHUNK_MAP: LOAD_CHUNK(cart->map); break; case CHUNK_CODE: LOAD_CHUNK(cart->code); break; - case CHUNK_SOUND: LOAD_CHUNK(cart->sound.sfx.data); break; - case CHUNK_WAVEFORM: LOAD_CHUNK(cart->sound.sfx.waveform); break; - case CHUNK_MUSIC: LOAD_CHUNK(cart->sound.music.tracks.data); break; - case CHUNK_PATTERNS: LOAD_CHUNK(cart->sound.music.patterns.data); break; + case CHUNK_SOUND: LOAD_CHUNK(cart->sfx.data); break; + case CHUNK_WAVEFORM: LOAD_CHUNK(cart->sfx.waveform); break; + case CHUNK_MUSIC: LOAD_CHUNK(cart->music.tracks.data); break; + case CHUNK_PATTERNS: LOAD_CHUNK(cart->music.patterns.data); break; case CHUNK_PALETTE: if(palette) LOAD_CHUNK(cart->palette); @@ -1666,10 +1668,10 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->sprites); buffer = SAVE_CHUNK(CHUNK_MAP, cart->map); buffer = SAVE_CHUNK(CHUNK_CODE, cart->code); - buffer = SAVE_CHUNK(CHUNK_SOUND, cart->sound.sfx.data); - buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->sound.sfx.waveform); - buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->sound.music.patterns.data); - buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->sound.music.tracks.data); + buffer = SAVE_CHUNK(CHUNK_SOUND, cart->sfx.data); + buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->sfx.waveform); + buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->music.patterns.data); + buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->music.tracks.data); buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette); buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size); @@ -1813,7 +1815,8 @@ tic_mem* tic_create(s32 samplerate) if(machine != (tic_machine*)&machine->memory) 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); diff --git a/src/tic.h b/src/tic.h index e39915b..96bd448 100644 --- a/src/tic.h +++ b/src/tic.h @@ -321,11 +321,11 @@ typedef union u8 data[TIC_PALETTE_SIZE * sizeof(tic_rgb)]; } tic_palette; -typedef struct -{ - tic_sfx sfx; - tic_music music; -} tic_sound; +// typedef struct +// { +// tic_sfx sfx; +// tic_music music; +// } tic_sound; typedef struct { @@ -350,7 +350,8 @@ typedef struct tic_tiles tiles; tic_tiles sprites; tic_map map; - tic_sound sound; + tic_sfx sfx; + tic_music music; }; tic_bank banks[TIC_BANKS]; @@ -430,7 +431,8 @@ typedef union tic_map map; tic_persistent persistent; tic_sound_register registers[TIC_SOUND_CHANNELS]; - tic_sound sound; + tic_sfx sfx; + tic_music music; tic_music_pos music_pos; }; diff --git a/src/tic80.c b/src/tic80.c index 64a97ec..8b1e7df 100644 --- a/src/tic80.c +++ b/src/tic80.c @@ -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->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_end(tic80->memory); diff --git a/src/ticapi.h b/src/ticapi.h index 52280c1..3c61988 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -107,7 +107,7 @@ typedef struct void (*load) (tic_cartridge* rom, const u8* buffer, s32 size, bool palette); s32 (*save) (const tic_cartridge* rom, u8* buffer); - void (*tick_start) (tic_mem* memory, const tic_sound* src); + void (*tick_start) (tic_mem* memory, const tic_sfx* sfx, const tic_music* music); void (*tick_end) (tic_mem* memory); void (*blit) (tic_mem* tic, tic_scanline scanline, tic_overlap overlap, void* data); From 8f060245dfa652cb166b71686e076536c9f5becf Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Sun, 10 Dec 2017 12:55:45 +0300 Subject: [PATCH 3/7] no message --- src/console.c | 44 ++++++++++++++++++++++++-------------------- src/dialog.c | 2 +- src/map.c | 28 ++++++++++++++-------------- src/menu.c | 4 ++-- src/music.c | 8 ++++---- src/sfx.c | 8 ++++---- src/sprite.c | 8 ++++---- src/studio.c | 18 +++++++++--------- src/surf.c | 8 ++++---- src/tic.c | 40 ++++++++++++++++++++-------------------- src/tic.h | 21 +-------------------- src/world.c | 4 ++-- 12 files changed, 89 insertions(+), 104 deletions(-) diff --git a/src/console.c b/src/console.c index 0467f46..4899052 100644 --- a/src/console.c +++ b/src/console.c @@ -357,15 +357,16 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param) loadCart(console->tic, cart, data, size, true); tic_mem* tic = console->tic; + // TODO: should load to the currena bank switch(i) { - case 0: memcpy(&tic->cart.tiles, &cart->tiles, sizeof cart->tiles + sizeof cart->sprites); break; - case 1: memcpy(&tic->cart.map, &cart->map, sizeof cart->map); 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 4: memcpy(&tic->cart.sfx, &cart->sfx, sizeof cart->sfx); break; - case 5: memcpy(&tic->cart.music, &cart->music, sizeof cart->music); break; - case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof cart->palette); break; + case 0: memcpy(&tic->cart.banks[0].tiles, &cart->banks[0].tiles, sizeof(tic_tiles)*2); break; + case 1: memcpy(&tic->cart.banks[0].map, &cart->banks[0].map, sizeof(tic_map)); 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 4: memcpy(&tic->cart.banks[0].sfx, &cart->banks[0].sfx, sizeof(tic_sfx)); break; + case 5: memcpy(&tic->cart.banks[0].music, &cart->banks[0].music, sizeof(tic_music)); break; + case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof(tic_palette)); break; } studioRomLoaded(); @@ -602,14 +603,15 @@ static char* saveBinarySection(char* ptr, const char* comment, const char* tag, typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection; static const BinarySection BinarySections[] = { + // TODO: fix banks loading here {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, - {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, tiles), sizeof(tic_tile), true}, - {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, sprites), sizeof(tic_tile), true}, - {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, map), TIC_MAP_WIDTH, true}, - {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, sfx.waveform.envelopes), sizeof(tic_waveform), true}, - {"SFX", SFX_COUNT, offsetof(tic_cartridge, sfx.data), sizeof(tic_sound_effect), true}, - {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, music.patterns), sizeof(tic_track_pattern), true}, - {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, music.tracks), sizeof(tic_track), true}, + {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, banks->tiles), sizeof(tic_tile), true}, + {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, banks->sprites), sizeof(tic_tile), true}, + {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, banks->map), TIC_MAP_WIDTH, true}, + {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, banks->sfx.waveform.envelopes), sizeof(tic_waveform), true}, + {"SFX", SFX_COUNT, offsetof(tic_cartridge, banks->sfx.data), sizeof(tic_sound_effect), true}, + {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, banks->music.patterns), sizeof(tic_track_pattern), true}, + {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, banks->music.tracks), sizeof(tic_track), true}, }; static s32 saveProject(Console* console, void* buffer, const char* comment) @@ -1330,7 +1332,8 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v tic_rgb rgb = {c->r, c->g, c->b}; u8 color = tic_tool_find_closest_color(console->tic->cart.palette.colors, &rgb); - setSpritePixel(console->tic->cart.tiles.data, x, y, color); + // TODO: should be current bank + setSpritePixel(console->tic->cart.banks[0].tiles.data, x, y, color); } gif_close(image); @@ -1352,8 +1355,9 @@ static void injectMap(Console* console, const void* buffer, s32 size) { enum {Size = sizeof(tic_map)}; - SDL_memset(&console->tic->cart.map, 0, Size); - SDL_memcpy(&console->tic->cart.map, buffer, SDL_min(size, Size)); + // TODO: should be current bank + SDL_memset(&console->tic->cart.banks[0].map, 0, Size); + SDL_memcpy(&console->tic->cart.banks[0].map, buffer, SDL_min(size, Size)); } static void onImportMap(const char* name, const void* buffer, size_t size, void* data) @@ -1453,7 +1457,7 @@ static void exportSprites(Console* console) { for (s32 y = 0; y < Height; y++) for (s32 x = 0; x < Width; x++) - data[x + y * Width] = getSpritePixel(console->tic->cart.tiles.data, x, y); + data[x + y * Width] = getSpritePixel(console->tic->cart.banks[0].tiles.data, x, y); s32 size = 0; if((size = writeGifData(console->tic, buffer, data, Width, Height))) @@ -1493,7 +1497,7 @@ static void exportMap(Console* console) if(buffer) { - SDL_memcpy(buffer, console->tic->cart.map.data, Size); + SDL_memcpy(buffer, console->tic->cart.banks[0].map.data, Size); fsGetFileData(onMapExported, "world.map", buffer, Size, DEFAULT_CHMOD, console); } } @@ -2764,7 +2768,7 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na tic_rgb rgb = {c->r, c->g, c->b}; u8 color = tic_tool_find_closest_color(embed.file.palette.colors, &rgb); - setSpritePixel(embed.file.tiles.data, x, y, color); + setSpritePixel(embed.file.banks[0].tiles.data, x, y, color); } gif_close(image); diff --git a/src/dialog.c b/src/dialog.c index e28b224..2912be3 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -170,7 +170,7 @@ static void drawDialog(Dialog* dlg) { u8 chromakey = 14; - tic->api.sprite_ex(tic, &tic->config.tiles, 2, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.banks[0].tiles, 2, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); } { diff --git a/src/map.c b/src/map.c index 973909b..855cdea 100644 --- a/src/map.c +++ b/src/map.c @@ -314,7 +314,7 @@ static void drawTileIndex(Map* map, s32 x, s32 y) { s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - index = map->tic->api.map_get(map->tic, &map->tic->cart.map, tx, ty); + index = map->tic->api.map_get(map->tic, &map->tic->cart.banks[0].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 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++) - map->tic->api.sprite(map->tic, &map->tic->cart.tiles, index, x + i, y + j, NULL, 0); + map->tic->api.sprite(map->tic, &map->tic->cart.banks[0].tiles, index, x + i, y + j, NULL, 0); { 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 i = 0; i < map->sheet.rect.w; i++) - map->tic->api.map_set(map->tic, &map->tic->cart.map, (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.banks[0].map, (x+i)%TIC_MAP_WIDTH, (y+j)%TIC_MAP_HEIGHT, (mx+i) + (my+j) * SHEET_COLS); 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 i = 0, tx=mx; i < map->sheet.rect.w; i++, tx+=TIC_SPRITESIZE) - map->tic->api.sprite(map->tic, &map->tic->cart.tiles, (sx+i) + (sy+j) * SHEET_COLS, tx, ty, NULL, 0); + map->tic->api.sprite(map->tic, &map->tic->cart.banks[0].tiles, (sx+i) + (sy+j) * SHEET_COLS, tx, ty, NULL, 0); } drawCursorPos(map, mx, my); @@ -512,7 +512,7 @@ static void processMouseDrawMode(Map* map) { s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - s32 index = map->tic->api.map_get(map->tic, &map->tic->cart.map, tx, ty); + s32 index = map->tic->api.map_get(map->tic, &map->tic->cart.banks[0].map, tx, ty); map->sheet.rect = (SDL_Rect){index % SHEET_COLS, index / SHEET_COLS, 1, 1}; } @@ -593,7 +593,7 @@ static void drawPasteData(Map* map) for(s32 j = 0; j < h; j++) for(s32 i = 0; i < w; i++) - map->tic->api.map_set(map->tic, &map->tic->cart.map, (mx+i)%TIC_MAP_WIDTH, (my+j)%TIC_MAP_HEIGHT, data[i + j * w]); + map->tic->api.map_set(map->tic, &map->tic->cart.banks[0].map, (mx+i)%TIC_MAP_WIDTH, (my+j)%TIC_MAP_HEIGHT, data[i + j * w]); history_add(map->history); @@ -612,7 +612,7 @@ static void drawPasteData(Map* map) for(s32 j = 0; j < h; j++) for(s32 i = 0; i < w; i++) - map->tic->api.sprite(map->tic, &map->tic->cart.tiles, data[i + j * w], mx + i*TIC_SPRITESIZE, my + j*TIC_SPRITESIZE, NULL, 0); + map->tic->api.sprite(map->tic, &map->tic->cart.banks[0].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 i = 0; i < map->sheet.rect.w; i++) - map->tic->api.map_set(map->tic, &map->tic->cart.map, x+i, y+j, (mx+i) + (my+j) * SHEET_COLS); + map->tic->api.map_set(map->tic, &map->tic->cart.banks[0].map, x+i, y+j, (mx+i) + (my+j) * SHEET_COLS); for(s32 i = 0; i < COUNT_OF(dx); i++) { @@ -776,7 +776,7 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile) bool match = true; for(s32 j = 0; j < map->sheet.rect.h; j++) for(s32 i = 0; i < map->sheet.rect.w; i++) - if(map->tic->api.map_get(map->tic, &map->tic->cart.map, nx+i, ny+j) != tile) + if(map->tic->api.map_get(map->tic, &map->tic->cart.banks[0].map, nx+i, ny+j) != tile) match = false; if(match) @@ -801,7 +801,7 @@ static void processMouseFillMode(Map* map) s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - fillMap(map, tx, ty, map->tic->api.map_get(map->tic, &map->tic->cart.map, tx, ty)); + fillMap(map, tx, ty, map->tic->api.map_get(map->tic, &map->tic->cart.banks[0].map, tx, ty)); history_add(map->history); } } @@ -864,7 +864,7 @@ static void drawMapOvr(Map* map) s32 scrollX = map->scroll.x % TIC_SPRITESIZE; s32 scrollY = map->scroll.y % TIC_SPRITESIZE; - map->tic->api.map(map->tic, &map->tic->cart.map, &map->tic->cart.tiles, map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE, + map->tic->api.map(map->tic, &map->tic->cart.banks[0].map, &map->tic->cart.banks[0].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); if(map->canvas.grid || map->scroll.active) @@ -950,7 +950,7 @@ static void copySelectionToClipboard(Map* map) normalizeMapRect(&x, &y); s32 index = x + y * TIC_MAP_WIDTH; - *ptr++ = map->tic->cart.map.data[index]; + *ptr++ = map->tic->cart.banks[0].map.data[index]; } toClipboard(buffer, size, true); @@ -978,7 +978,7 @@ static void deleteSelection(Map* map) normalizeMapRect(&x, &y); s32 index = x + y * TIC_MAP_WIDTH; - map->tic->cart.map.data[index] = 0; + map->tic->cart.banks[0].map.data[index] = 0; } history_add(map->history); @@ -1185,7 +1185,7 @@ void initMap(Map* map, tic_mem* tic) .gesture = false, .start = {0, 0}, }, - .history = history_create(&tic->cart.map, sizeof tic->cart.map), + .history = history_create(&tic->cart.banks[0].map, sizeof(tic_map)), .event = onStudioEvent, .overlap = overlap, }; diff --git a/src/menu.c b/src/menu.c index 0e38308..c81612b 100644 --- a/src/menu.c +++ b/src/menu.c @@ -124,7 +124,7 @@ static void drawDialog(Menu* menu) { u8 chromakey = 14; - tic->api.sprite_ex(tic, &tic->config.tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.banks[0].tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); } } @@ -209,7 +209,7 @@ static void drawPlayerButtons(Menu* menu, s32 x, s32 y) if(menu->gamepad.selected == index && menu->ticks % TIC_FRAMERATE < TIC_FRAMERATE / 2) continue; - tic->api.sprite_ex(tic, &tic->config.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.banks[0].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]; diff --git a/src/music.c b/src/music.c index a061a06..6fa2eed 100644 --- a/src/music.c +++ b/src/music.c @@ -215,7 +215,7 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value, static tic_track* getTrack(Music* music) { - return &music->tic->cart.music.tracks.data[music->track]; + return &music->tic->cart.banks[0].music.tracks.data[music->track]; } static s32 getRows(Music* music) @@ -368,7 +368,7 @@ static tic_track_pattern* getPattern(Music* music, s32 channel) { s32 patternId = tic_tool_get_pattern_id(getTrack(music), music->tracker.frame, channel); - return patternId ? &music->tic->cart.music.patterns.data[patternId - PATTERN_START] : NULL; + return patternId ? &music->tic->cart.banks[0].music.patterns.data[patternId - PATTERN_START] : NULL; } static tic_track_pattern* getChannelPattern(Music* music) @@ -1327,7 +1327,7 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index) } u8 color = Chroma; - tic->api.sprite(tic, &tic->config.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1); + tic->api.sprite(tic, &tic->config.banks[0].tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1); } static void drawTracker(Music* music, s32 x, s32 y) @@ -1643,7 +1643,7 @@ void initMusic(Music* music, tic_mem* tic) }, .tab = MUSIC_TRACKER_TAB, - .history = history_create(&tic->cart.music, sizeof(tic_music)), + .history = history_create(&tic->cart.banks[0].music, sizeof(tic_music)), .event = onStudioEvent, }; diff --git a/src/sfx.c b/src/sfx.c index fa4aba6..bc3a371 100644 --- a/src/sfx.c +++ b/src/sfx.c @@ -106,7 +106,7 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi static tic_sound_effect* getEffect(Sfx* sfx) { - return sfx->tic->cart.sfx.data + sfx->index; + return sfx->tic->cart.banks[0].sfx.data + sfx->index; } 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) { - return &sfx->tic->cart.sfx.waveform.envelopes[i]; + return &sfx->tic->cart.banks[0].sfx.waveform.envelopes[i]; } static tic_waveform* getWaveform(Sfx* sfx) @@ -1058,8 +1058,8 @@ void initSfx(Sfx* sfx, tic_mem* tic) .tab = SFX_ENVELOPES_TAB, .history = { - .envelope = history_create(&tic->cart.sfx.data, sizeof tic->cart.sfx.data), - .waveform = history_create(&tic->cart.sfx.waveform, sizeof tic->cart.sfx.waveform), + .envelope = history_create(&tic->cart.banks[0].sfx.data, sizeof tic->cart.banks[0].sfx.data), + .waveform = history_create(&tic->cart.banks[0].sfx.waveform, sizeof tic->cart.banks[0].sfx.waveform), }, .event = onStudioEvent, }; diff --git a/src/sprite.c b/src/sprite.c index c56e010..6c7dc2f 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -33,12 +33,12 @@ static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y) { - return getSpritePixel(sprite->tic->cart.tiles.data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y); + return getSpritePixel(sprite->tic->cart.banks[0].tiles.data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y); } static void setSheetPixel(Sprite* sprite, s32 x, s32 y, u8 color) { - setSpritePixel(sprite->tic->cart.tiles.data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y, color); + setSpritePixel(sprite->tic->cart.banks[0].tiles.data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y, color); } 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 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++) - sprite->tic->api.sprite(sprite->tic, &sprite->tic->cart.tiles, index, x + i, y + j, NULL, 0); + sprite->tic->api.sprite(sprite->tic, &sprite->tic->cart.banks[0].tiles, index, x + i, y + j, NULL, 0); { s32 bx = getIndexPosX(sprite) + x - 1; s32 by = getIndexPosY(sprite) + y - 1; @@ -1551,7 +1551,7 @@ void initSprite(Sprite* sprite, tic_mem* tic) .front = sprite->select.front, }, .mode = SPRITE_DRAW_MODE, - .history = history_create(&tic->cart.tiles, TIC_SPRITES * sizeof(tic_tile)), + .history = history_create(&tic->cart.banks[0].tiles, TIC_SPRITES * sizeof(tic_tile)), .event = onStudioEvent, .overlap = overlap, }; diff --git a/src/studio.c b/src/studio.c index aa0c34f..cff9da7 100644 --- a/src/studio.c +++ b/src/studio.c @@ -278,7 +278,7 @@ static struct void playSystemSfx(s32 id) { - const tic_sound_effect* effect = &studio.tic->config.sfx.data[id]; + const tic_sound_effect* effect = &studio.tic->config.banks[0].sfx.data[id]; studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0); } @@ -2049,7 +2049,7 @@ static void renderCursor() SDL_ShowCursor(getConfig()->theme.cursor.sprite >= 0 ? SDL_DISABLE : SDL_ENABLE); if(getConfig()->theme.cursor.sprite >= 0) - blitCursor(studio.tic->config.tiles.data[getConfig()->theme.cursor.sprite].data); + blitCursor(studio.tic->config.banks[0].tiles.data[getConfig()->theme.cursor.sprite].data); } static void useSystemPalette() @@ -2104,12 +2104,12 @@ static void renderStudio() case TIC_DIALOG_MODE: case TIC_MENU_MODE: case TIC_SURF_MODE: - sfx = &studio.tic->config.sfx; - music = &studio.tic->config.music; + sfx = &studio.tic->config.banks[0].sfx; + music = &studio.tic->config.banks[0].music; break; default: - sfx = &studio.tic->cart.sfx; - music = &studio.tic->cart.music; + sfx = &studio.tic->cart.banks[0].sfx; + music = &studio.tic->cart.banks[0].music; } studio.tic->api.tick_start(studio.tic, sfx, music); @@ -2283,7 +2283,7 @@ static void initTouchGamepad() if (!studio.renderer) return; - studio.tic->api.map(studio.tic, &studio.tic->config.map, &studio.tic->config.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); + studio.tic->api.map(studio.tic, &studio.tic->config.banks[0].map, &studio.tic->config.banks[0].tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); if(!studio.gamepad.texture) { @@ -2310,7 +2310,7 @@ static void updateSystemFont() for(s32 i = 0; i < TIC_FONT_CHARS; i++) for(s32 y = 0; y < TIC_SPRITESIZE; y++) for(s32 x = 0; x < TIC_SPRITESIZE; x++) - if(tic_tool_peek4(&studio.tic->config.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1)) + if(tic_tool_peek4(&studio.tic->config.banks[0].sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1)) studio.tic->font.data[i*BITS_IN_BYTE+y] |= 1 << x; } @@ -2335,7 +2335,7 @@ static void setWindowIcon() for(s32 j = 0, index = 0; j < Size; j++) for(s32 i = 0; i < Size; i++, index++) { - u8 color = getSpritePixel(studio.tic->config.tiles.data, i/Scale, j/Scale); + u8 color = getSpritePixel(studio.tic->config.banks[0].tiles.data, i/Scale, j/Scale); pixels[index] = color == ColorKey ? 0 : pal[color]; } diff --git a/src/surf.c b/src/surf.c index 3e15d63..07b3605 100644 --- a/src/surf.c +++ b/src/surf.c @@ -202,14 +202,14 @@ static void drawTopToolbar(Surf* surf, s32 x, s32 y) enum{Gap = 10, TipX = 150, SelectWidth = 54}; u8 colorkey = 0; - tic->api.sprite_ex(tic, &tic->config.tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.banks[0].tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "SELECT"; tic->api.text(tic, Label, TipX + Gap, y+3, tic_color_black); tic->api.text(tic, Label, TipX + Gap, y+2, tic_color_white); } - tic->api.sprite_ex(tic, &tic->config.tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.banks[0].tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "BACK"; tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); @@ -244,7 +244,7 @@ static void drawBottomToolbar(Surf* surf, s32 x, s32 y) u8 colorkey = 0; - tic->api.sprite_ex(tic, &tic->config.tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.banks[0].tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); { static const char Label[] = "WEBSITE"; tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); @@ -355,7 +355,7 @@ static void drawBG(Surf* surf) for(s32 j = 0; j < Height + 1; j++) for(s32 i = 0; i < Width + 1; i++) if(counter++ % 2) - tic->api.sprite_ex(tic, &tic->config.tiles, 34, i*Size - offset, j*Size - offset, 2, 2, 0, 0, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.banks[0].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) diff --git a/src/tic.c b/src/tic.c index b29bb9b..3dc63e8 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1325,12 +1325,12 @@ static void initCover(tic_mem* tic) static void cart2ram(tic_mem* memory) { - memcpy(&memory->ram.tiles, &memory->cart.tiles, sizeof(tic_tiles)); - memcpy(&memory->ram.sprites, &memory->cart.sprites, sizeof(tic_tiles)); - memcpy(&memory->ram.map, &memory->cart.map, sizeof(tic_tiles)); + memcpy(&memory->ram.tiles, &memory->cart.banks[0].tiles, sizeof(tic_tiles)); + memcpy(&memory->ram.sprites, &memory->cart.banks[0].sprites, sizeof(tic_tiles)); + memcpy(&memory->ram.map, &memory->cart.banks[0].map, sizeof(tic_tiles)); - memcpy(&memory->ram.sfx, &memory->cart.sfx, sizeof(tic_sfx)); - memcpy(&memory->ram.music, &memory->cart.music, sizeof(tic_music)); + memcpy(&memory->ram.sfx, &memory->cart.banks[0].sfx, sizeof(tic_sfx)); + memcpy(&memory->ram.music, &memory->cart.banks[0].music, sizeof(tic_music)); initCover(memory); } @@ -1595,14 +1595,14 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet switch(chunk.type) { - case CHUNK_TILES: LOAD_CHUNK(cart->tiles); break; - case CHUNK_SPRITES: LOAD_CHUNK(cart->sprites); break; - case CHUNK_MAP: LOAD_CHUNK(cart->map); break; - case CHUNK_CODE: LOAD_CHUNK(cart->code); break; - case CHUNK_SOUND: LOAD_CHUNK(cart->sfx.data); break; - case CHUNK_WAVEFORM: LOAD_CHUNK(cart->sfx.waveform); break; - case CHUNK_MUSIC: LOAD_CHUNK(cart->music.tracks.data); break; - case CHUNK_PATTERNS: LOAD_CHUNK(cart->music.patterns.data); break; + case CHUNK_TILES: LOAD_CHUNK(cart->banks[0].tiles); break; + case CHUNK_SPRITES: LOAD_CHUNK(cart->banks[0].sprites); break; + case CHUNK_MAP: LOAD_CHUNK(cart->banks[0].map); break; + case CHUNK_CODE: LOAD_CHUNK(cart->code); break; + case CHUNK_SOUND: LOAD_CHUNK(cart->banks[0].sfx.data); break; + case CHUNK_WAVEFORM: LOAD_CHUNK(cart->banks[0].sfx.waveform); break; + case CHUNK_MUSIC: LOAD_CHUNK(cart->banks[0].music.tracks.data); break; + case CHUNK_PATTERNS: LOAD_CHUNK(cart->banks[0].music.patterns.data); break; case CHUNK_PALETTE: if(palette) LOAD_CHUNK(cart->palette); @@ -1664,14 +1664,14 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) #define SAVE_CHUNK(id, from) saveChunk(buffer, id, &from, sizeof(from)) - buffer = SAVE_CHUNK(CHUNK_TILES, cart->tiles); - buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->sprites); - buffer = SAVE_CHUNK(CHUNK_MAP, cart->map); + buffer = SAVE_CHUNK(CHUNK_TILES, cart->banks[0].tiles); + buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->banks[0].sprites); + buffer = SAVE_CHUNK(CHUNK_MAP, cart->banks[0].map); buffer = SAVE_CHUNK(CHUNK_CODE, cart->code); - buffer = SAVE_CHUNK(CHUNK_SOUND, cart->sfx.data); - buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->sfx.waveform); - buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->music.patterns.data); - buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->music.tracks.data); + buffer = SAVE_CHUNK(CHUNK_SOUND, cart->banks[0].sfx.data); + buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->banks[0].sfx.waveform); + buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->banks[0].music.patterns.data); + buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->banks[0].music.tracks.data); buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette); buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size); diff --git a/src/tic.h b/src/tic.h index 96bd448..c91dc8c 100644 --- a/src/tic.h +++ b/src/tic.h @@ -321,12 +321,6 @@ typedef union u8 data[TIC_PALETTE_SIZE * sizeof(tic_rgb)]; } tic_palette; -// typedef struct -// { -// tic_sfx sfx; -// tic_music music; -// } tic_sound; - typedef struct { tic_tile data[TIC_BANK_SPRITES]; @@ -343,20 +337,7 @@ typedef struct typedef struct { - union - { - struct - { - tic_tiles tiles; - tic_tiles sprites; - tic_map map; - tic_sfx sfx; - tic_music music; - }; - - tic_bank banks[TIC_BANKS]; - }; - + tic_bank banks[TIC_BANKS]; tic_code code; tic_cover_image cover; tic_palette palette; diff --git a/src/world.c b/src/world.c index 8d6dda0..89c7587 100644 --- a/src/world.c +++ b/src/world.c @@ -105,13 +105,13 @@ void initWorld(World* world, tic_mem* tic, Map* map) for(s32 i = 0; i < TIC80_WIDTH * TIC80_HEIGHT; i++) { - u8 index = tic->cart.map.data[i]; + u8 index = tic->cart.banks[0].map.data[i]; if(index) { SDL_memset(colors, 0, sizeof colors); - tic_tile* tile = &tic->cart.tiles.data[index]; + tic_tile* tile = &tic->cart.banks[0].tiles.data[index]; for(s32 p = 0; p < TIC_SPRITESIZE * TIC_SPRITESIZE; p++) { From de236794b61a878d0527ac2af91c9c3b5905e035 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Sun, 10 Dec 2017 13:02:13 +0300 Subject: [PATCH 4/7] no message --- src/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/console.c b/src/console.c index 4899052..60ef368 100644 --- a/src/console.c +++ b/src/console.c @@ -2135,7 +2135,7 @@ static void onConsoleRamCommand(Console* console, const char* param) {offsetof(tic_ram, vram.screen), "SCREEN"}, {offsetof(tic_ram, vram.palette), "PALETTE"}, {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.mask), "GAMEPAD MASK"}, {offsetof(tic_ram, vram.input.gamepad), "GAMEPAD"}, From 409564cdde85e1773f0c73d26ae54d511575cca0 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Mon, 11 Dec 2017 11:44:46 +0300 Subject: [PATCH 5/7] no message --- src/console.c | 34 +++++++++++++++++----------------- src/dialog.c | 2 +- src/map.c | 28 ++++++++++++++-------------- src/menu.c | 4 ++-- src/music.c | 8 ++++---- src/sfx.c | 8 ++++---- src/sprite.c | 8 ++++---- src/studio.c | 18 +++++++++--------- src/surf.c | 8 ++++---- src/tic.c | 38 +++++++++++++++++++------------------- src/tic.h | 7 ++++++- src/world.c | 4 ++-- 12 files changed, 86 insertions(+), 81 deletions(-) diff --git a/src/console.c b/src/console.c index 60ef368..61917e7 100644 --- a/src/console.c +++ b/src/console.c @@ -360,12 +360,12 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param) // TODO: should load to the currena bank switch(i) { - case 0: memcpy(&tic->cart.banks[0].tiles, &cart->banks[0].tiles, sizeof(tic_tiles)*2); break; - case 1: memcpy(&tic->cart.banks[0].map, &cart->banks[0].map, sizeof(tic_map)); break; + case 0: memcpy(&tic->cart.bank.tiles, &cart->bank.tiles, sizeof(tic_tiles)*2); 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 3: memcpy(&tic->cart.code, &cart->code, sizeof cart->code); break; - case 4: memcpy(&tic->cart.banks[0].sfx, &cart->banks[0].sfx, sizeof(tic_sfx)); break; - case 5: memcpy(&tic->cart.banks[0].music, &cart->banks[0].music, sizeof(tic_music)); break; + case 4: memcpy(&tic->cart.bank.sfx, &cart->bank.sfx, sizeof(tic_sfx)); break; + case 5: memcpy(&tic->cart.bank.music, &cart->bank.music, sizeof(tic_music)); break; case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof(tic_palette)); break; } @@ -605,13 +605,13 @@ static const BinarySection BinarySections[] = { // TODO: fix banks loading here {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, - {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, banks->tiles), sizeof(tic_tile), true}, - {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, banks->sprites), sizeof(tic_tile), true}, - {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, banks->map), TIC_MAP_WIDTH, true}, - {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, banks->sfx.waveform.envelopes), sizeof(tic_waveform), true}, - {"SFX", SFX_COUNT, offsetof(tic_cartridge, banks->sfx.data), sizeof(tic_sound_effect), true}, - {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, banks->music.patterns), sizeof(tic_track_pattern), true}, - {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, banks->music.tracks), sizeof(tic_track), true}, + {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.tiles), sizeof(tic_tile), true}, + {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.sprites), sizeof(tic_tile), true}, + {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, bank.map), TIC_MAP_WIDTH, true}, + {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, bank.sfx.waveform.envelopes), sizeof(tic_waveform), true}, + {"SFX", SFX_COUNT, offsetof(tic_cartridge, bank.sfx.data), sizeof(tic_sound_effect), true}, + {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, bank.music.patterns), sizeof(tic_track_pattern), true}, + {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, bank.music.tracks), sizeof(tic_track), true}, }; static s32 saveProject(Console* console, void* buffer, const char* comment) @@ -1333,7 +1333,7 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v u8 color = tic_tool_find_closest_color(console->tic->cart.palette.colors, &rgb); // TODO: should be current bank - setSpritePixel(console->tic->cart.banks[0].tiles.data, x, y, color); + setSpritePixel(console->tic->cart.bank.tiles.data, x, y, color); } gif_close(image); @@ -1356,8 +1356,8 @@ static void injectMap(Console* console, const void* buffer, s32 size) enum {Size = sizeof(tic_map)}; // TODO: should be current bank - SDL_memset(&console->tic->cart.banks[0].map, 0, Size); - SDL_memcpy(&console->tic->cart.banks[0].map, buffer, SDL_min(size, Size)); + SDL_memset(&console->tic->cart.bank.map, 0, 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) @@ -1457,7 +1457,7 @@ static void exportSprites(Console* console) { for (s32 y = 0; y < Height; y++) for (s32 x = 0; x < Width; x++) - data[x + y * Width] = getSpritePixel(console->tic->cart.banks[0].tiles.data, x, y); + data[x + y * Width] = getSpritePixel(console->tic->cart.bank.tiles.data, x, y); s32 size = 0; if((size = writeGifData(console->tic, buffer, data, Width, Height))) @@ -1497,7 +1497,7 @@ static void exportMap(Console* console) if(buffer) { - SDL_memcpy(buffer, console->tic->cart.banks[0].map.data, Size); + SDL_memcpy(buffer, console->tic->cart.bank.map.data, Size); fsGetFileData(onMapExported, "world.map", buffer, Size, DEFAULT_CHMOD, console); } } @@ -2768,7 +2768,7 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na tic_rgb rgb = {c->r, c->g, c->b}; u8 color = tic_tool_find_closest_color(embed.file.palette.colors, &rgb); - setSpritePixel(embed.file.banks[0].tiles.data, x, y, color); + setSpritePixel(embed.file.bank.tiles.data, x, y, color); } gif_close(image); diff --git a/src/dialog.c b/src/dialog.c index 2912be3..a61c16b 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -170,7 +170,7 @@ static void drawDialog(Dialog* dlg) { u8 chromakey = 14; - tic->api.sprite_ex(tic, &tic->config.banks[0].tiles, 2, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.bank.tiles, 2, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); } { diff --git a/src/map.c b/src/map.c index 855cdea..d9600ce 100644 --- a/src/map.c +++ b/src/map.c @@ -314,7 +314,7 @@ static void drawTileIndex(Map* map, s32 x, s32 y) { s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - index = map->tic->api.map_get(map->tic, &map->tic->cart.banks[0].map, 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 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++) - map->tic->api.sprite(map->tic, &map->tic->cart.banks[0].tiles, 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; @@ -437,7 +437,7 @@ static void setMapSprite(Map* map, s32 x, s32 y) for(s32 j = 0; j < map->sheet.rect.h; j++) for(s32 i = 0; i < map->sheet.rect.w; i++) - map->tic->api.map_set(map->tic, &map->tic->cart.banks[0].map, (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); } @@ -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 i = 0, tx=mx; i < map->sheet.rect.w; i++, tx+=TIC_SPRITESIZE) - map->tic->api.sprite(map->tic, &map->tic->cart.banks[0].tiles, (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); @@ -512,7 +512,7 @@ static void processMouseDrawMode(Map* map) { s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - s32 index = map->tic->api.map_get(map->tic, &map->tic->cart.banks[0].map, 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}; } @@ -593,7 +593,7 @@ static void drawPasteData(Map* map) for(s32 j = 0; j < h; j++) for(s32 i = 0; i < w; i++) - map->tic->api.map_set(map->tic, &map->tic->cart.banks[0].map, (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); @@ -612,7 +612,7 @@ static void drawPasteData(Map* map) for(s32 j = 0; j < h; j++) for(s32 i = 0; i < w; i++) - map->tic->api.sprite(map->tic, &map->tic->cart.banks[0].tiles, 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 i = 0; i < map->sheet.rect.w; i++) - map->tic->api.map_set(map->tic, &map->tic->cart.banks[0].map, 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++) { @@ -776,7 +776,7 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile) bool match = true; for(s32 j = 0; j < map->sheet.rect.h; j++) for(s32 i = 0; i < map->sheet.rect.w; i++) - if(map->tic->api.map_get(map->tic, &map->tic->cart.banks[0].map, 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; if(match) @@ -801,7 +801,7 @@ static void processMouseFillMode(Map* map) s32 tx = 0, ty = 0; getMouseMap(map, &tx, &ty); - fillMap(map, tx, ty, map->tic->api.map_get(map->tic, &map->tic->cart.banks[0].map, tx, ty)); + fillMap(map, tx, ty, map->tic->api.map_get(map->tic, &map->tic->cart.bank.map, tx, ty)); history_add(map->history); } } @@ -864,7 +864,7 @@ static void drawMapOvr(Map* map) s32 scrollX = map->scroll.x % TIC_SPRITESIZE; s32 scrollY = map->scroll.y % TIC_SPRITESIZE; - map->tic->api.map(map->tic, &map->tic->cart.banks[0].map, &map->tic->cart.banks[0].tiles, 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); if(map->canvas.grid || map->scroll.active) @@ -950,7 +950,7 @@ static void copySelectionToClipboard(Map* map) normalizeMapRect(&x, &y); s32 index = x + y * TIC_MAP_WIDTH; - *ptr++ = map->tic->cart.banks[0].map.data[index]; + *ptr++ = map->tic->cart.bank.map.data[index]; } toClipboard(buffer, size, true); @@ -978,7 +978,7 @@ static void deleteSelection(Map* map) normalizeMapRect(&x, &y); s32 index = x + y * TIC_MAP_WIDTH; - map->tic->cart.banks[0].map.data[index] = 0; + map->tic->cart.bank.map.data[index] = 0; } history_add(map->history); @@ -1185,7 +1185,7 @@ void initMap(Map* map, tic_mem* tic) .gesture = false, .start = {0, 0}, }, - .history = history_create(&tic->cart.banks[0].map, sizeof(tic_map)), + .history = history_create(&tic->cart.bank.map, sizeof(tic_map)), .event = onStudioEvent, .overlap = overlap, }; diff --git a/src/menu.c b/src/menu.c index c81612b..935ce3a 100644 --- a/src/menu.c +++ b/src/menu.c @@ -124,7 +124,7 @@ static void drawDialog(Menu* menu) { u8 chromakey = 14; - tic->api.sprite_ex(tic, &tic->config.banks[0].tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.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) continue; - tic->api.sprite_ex(tic, &tic->config.banks[0].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.bank.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]; diff --git a/src/music.c b/src/music.c index 6fa2eed..620b128 100644 --- a/src/music.c +++ b/src/music.c @@ -215,7 +215,7 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value, static tic_track* getTrack(Music* music) { - return &music->tic->cart.banks[0].music.tracks.data[music->track]; + return &music->tic->cart.bank.music.tracks.data[music->track]; } static s32 getRows(Music* music) @@ -368,7 +368,7 @@ static tic_track_pattern* getPattern(Music* music, s32 channel) { s32 patternId = tic_tool_get_pattern_id(getTrack(music), music->tracker.frame, channel); - return patternId ? &music->tic->cart.banks[0].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) @@ -1327,7 +1327,7 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index) } u8 color = Chroma; - tic->api.sprite(tic, &tic->config.banks[0].tiles, 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) @@ -1643,7 +1643,7 @@ void initMusic(Music* music, tic_mem* tic) }, .tab = MUSIC_TRACKER_TAB, - .history = history_create(&tic->cart.banks[0].music, sizeof(tic_music)), + .history = history_create(&tic->cart.bank.music, sizeof(tic_music)), .event = onStudioEvent, }; diff --git a/src/sfx.c b/src/sfx.c index bc3a371..b8efdba 100644 --- a/src/sfx.c +++ b/src/sfx.c @@ -106,7 +106,7 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi static tic_sound_effect* getEffect(Sfx* sfx) { - return sfx->tic->cart.banks[0].sfx.data + sfx->index; + return sfx->tic->cart.bank.sfx.data + sfx->index; } 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) { - return &sfx->tic->cart.banks[0].sfx.waveform.envelopes[i]; + return &sfx->tic->cart.bank.sfx.waveform.envelopes[i]; } static tic_waveform* getWaveform(Sfx* sfx) @@ -1058,8 +1058,8 @@ void initSfx(Sfx* sfx, tic_mem* tic) .tab = SFX_ENVELOPES_TAB, .history = { - .envelope = history_create(&tic->cart.banks[0].sfx.data, sizeof tic->cart.banks[0].sfx.data), - .waveform = history_create(&tic->cart.banks[0].sfx.waveform, sizeof tic->cart.banks[0].sfx.waveform), + .envelope = history_create(&tic->cart.bank.sfx.data, sizeof tic->cart.bank.sfx.data), + .waveform = history_create(&tic->cart.bank.sfx.waveform, sizeof tic->cart.bank.sfx.waveform), }, .event = onStudioEvent, }; diff --git a/src/sprite.c b/src/sprite.c index 6c7dc2f..6366f36 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -33,12 +33,12 @@ static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y) { - return getSpritePixel(sprite->tic->cart.banks[0].tiles.data, 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) { - setSpritePixel(sprite->tic->cart.banks[0].tiles.data, 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) @@ -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 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++) - sprite->tic->api.sprite(sprite->tic, &sprite->tic->cart.banks[0].tiles, 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 by = getIndexPosY(sprite) + y - 1; @@ -1551,7 +1551,7 @@ void initSprite(Sprite* sprite, tic_mem* tic) .front = sprite->select.front, }, .mode = SPRITE_DRAW_MODE, - .history = history_create(&tic->cart.banks[0].tiles, TIC_SPRITES * sizeof(tic_tile)), + .history = history_create(&tic->cart.bank.tiles, TIC_SPRITES * sizeof(tic_tile)), .event = onStudioEvent, .overlap = overlap, }; diff --git a/src/studio.c b/src/studio.c index cff9da7..c8eb9e8 100644 --- a/src/studio.c +++ b/src/studio.c @@ -278,7 +278,7 @@ static struct void playSystemSfx(s32 id) { - const tic_sound_effect* effect = &studio.tic->config.banks[0].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); } @@ -2049,7 +2049,7 @@ static void renderCursor() SDL_ShowCursor(getConfig()->theme.cursor.sprite >= 0 ? SDL_DISABLE : SDL_ENABLE); if(getConfig()->theme.cursor.sprite >= 0) - blitCursor(studio.tic->config.banks[0].tiles.data[getConfig()->theme.cursor.sprite].data); + blitCursor(studio.tic->config.bank.tiles.data[getConfig()->theme.cursor.sprite].data); } static void useSystemPalette() @@ -2104,12 +2104,12 @@ static void renderStudio() case TIC_DIALOG_MODE: case TIC_MENU_MODE: case TIC_SURF_MODE: - sfx = &studio.tic->config.banks[0].sfx; - music = &studio.tic->config.banks[0].music; + sfx = &studio.tic->config.bank.sfx; + music = &studio.tic->config.bank.music; break; default: - sfx = &studio.tic->cart.banks[0].sfx; - music = &studio.tic->cart.banks[0].music; + sfx = &studio.tic->cart.bank.sfx; + music = &studio.tic->cart.bank.music; } studio.tic->api.tick_start(studio.tic, sfx, music); @@ -2283,7 +2283,7 @@ static void initTouchGamepad() if (!studio.renderer) return; - studio.tic->api.map(studio.tic, &studio.tic->config.banks[0].map, &studio.tic->config.banks[0].tiles, 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) { @@ -2310,7 +2310,7 @@ static void updateSystemFont() for(s32 i = 0; i < TIC_FONT_CHARS; i++) for(s32 y = 0; y < TIC_SPRITESIZE; y++) for(s32 x = 0; x < TIC_SPRITESIZE; x++) - if(tic_tool_peek4(&studio.tic->config.banks[0].sprites.data[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; } @@ -2335,7 +2335,7 @@ static void setWindowIcon() for(s32 j = 0, index = 0; j < Size; j++) for(s32 i = 0; i < Size; i++, index++) { - u8 color = getSpritePixel(studio.tic->config.banks[0].tiles.data, i/Scale, j/Scale); + u8 color = getSpritePixel(studio.tic->config.bank.tiles.data, i/Scale, j/Scale); pixels[index] = color == ColorKey ? 0 : pal[color]; } diff --git a/src/surf.c b/src/surf.c index 07b3605..83083fd 100644 --- a/src/surf.c +++ b/src/surf.c @@ -202,14 +202,14 @@ static void drawTopToolbar(Surf* surf, s32 x, s32 y) enum{Gap = 10, TipX = 150, SelectWidth = 54}; u8 colorkey = 0; - tic->api.sprite_ex(tic, &tic->config.banks[0].tiles, 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"; tic->api.text(tic, Label, TipX + Gap, y+3, tic_color_black); tic->api.text(tic, Label, TipX + Gap, y+2, tic_color_white); } - tic->api.sprite_ex(tic, &tic->config.banks[0].tiles, 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"; tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); @@ -244,7 +244,7 @@ static void drawBottomToolbar(Surf* surf, s32 x, s32 y) u8 colorkey = 0; - tic->api.sprite_ex(tic, &tic->config.banks[0].tiles, 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"; tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); @@ -355,7 +355,7 @@ static void drawBG(Surf* surf) for(s32 j = 0; j < Height + 1; j++) for(s32 i = 0; i < Width + 1; i++) if(counter++ % 2) - tic->api.sprite_ex(tic, &tic->config.banks[0].tiles, 34, i*Size - offset, j*Size - offset, 2, 2, 0, 0, 1, tic_no_flip, tic_no_rotate); + tic->api.sprite_ex(tic, &tic->config.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) diff --git a/src/tic.c b/src/tic.c index 3dc63e8..32e1d66 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1325,12 +1325,12 @@ static void initCover(tic_mem* tic) static void cart2ram(tic_mem* memory) { - memcpy(&memory->ram.tiles, &memory->cart.banks[0].tiles, sizeof(tic_tiles)); - memcpy(&memory->ram.sprites, &memory->cart.banks[0].sprites, sizeof(tic_tiles)); - memcpy(&memory->ram.map, &memory->cart.banks[0].map, sizeof(tic_tiles)); + memcpy(&memory->ram.tiles, &memory->cart.bank.tiles, sizeof(tic_tiles)); + memcpy(&memory->ram.sprites, &memory->cart.bank.sprites, sizeof(tic_tiles)); + memcpy(&memory->ram.map, &memory->cart.bank.map, sizeof(tic_tiles)); - memcpy(&memory->ram.sfx, &memory->cart.banks[0].sfx, sizeof(tic_sfx)); - memcpy(&memory->ram.music, &memory->cart.banks[0].music, sizeof(tic_music)); + memcpy(&memory->ram.sfx, &memory->cart.bank.sfx, sizeof(tic_sfx)); + memcpy(&memory->ram.music, &memory->cart.bank.music, sizeof(tic_music)); initCover(memory); } @@ -1595,14 +1595,14 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet switch(chunk.type) { - case CHUNK_TILES: LOAD_CHUNK(cart->banks[0].tiles); break; - case CHUNK_SPRITES: LOAD_CHUNK(cart->banks[0].sprites); break; - case CHUNK_MAP: LOAD_CHUNK(cart->banks[0].map); break; + case CHUNK_TILES: LOAD_CHUNK(cart->bank.tiles); break; + case CHUNK_SPRITES: LOAD_CHUNK(cart->bank.sprites); break; + case CHUNK_MAP: LOAD_CHUNK(cart->bank.map); break; case CHUNK_CODE: LOAD_CHUNK(cart->code); break; - case CHUNK_SOUND: LOAD_CHUNK(cart->banks[0].sfx.data); break; - case CHUNK_WAVEFORM: LOAD_CHUNK(cart->banks[0].sfx.waveform); break; - case CHUNK_MUSIC: LOAD_CHUNK(cart->banks[0].music.tracks.data); break; - case CHUNK_PATTERNS: LOAD_CHUNK(cart->banks[0].music.patterns.data); break; + case CHUNK_SOUND: LOAD_CHUNK(cart->bank.sfx.data); break; + case CHUNK_WAVEFORM: LOAD_CHUNK(cart->bank.sfx.waveform); break; + case CHUNK_MUSIC: LOAD_CHUNK(cart->bank.music.tracks.data); break; + case CHUNK_PATTERNS: LOAD_CHUNK(cart->bank.music.patterns.data); break; case CHUNK_PALETTE: if(palette) LOAD_CHUNK(cart->palette); @@ -1664,14 +1664,14 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) #define SAVE_CHUNK(id, from) saveChunk(buffer, id, &from, sizeof(from)) - buffer = SAVE_CHUNK(CHUNK_TILES, cart->banks[0].tiles); - buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->banks[0].sprites); - buffer = SAVE_CHUNK(CHUNK_MAP, cart->banks[0].map); + buffer = SAVE_CHUNK(CHUNK_TILES, cart->bank.tiles); + buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->bank.sprites); + buffer = SAVE_CHUNK(CHUNK_MAP, cart->bank.map); buffer = SAVE_CHUNK(CHUNK_CODE, cart->code); - buffer = SAVE_CHUNK(CHUNK_SOUND, cart->banks[0].sfx.data); - buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->banks[0].sfx.waveform); - buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->banks[0].music.patterns.data); - buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->banks[0].music.tracks.data); + buffer = SAVE_CHUNK(CHUNK_SOUND, cart->bank.sfx.data); + buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->bank.sfx.waveform); + buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->bank.music.patterns.data); + buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->bank.music.tracks.data); buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette); buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size); diff --git a/src/tic.h b/src/tic.h index c91dc8c..d02e7bf 100644 --- a/src/tic.h +++ b/src/tic.h @@ -337,7 +337,12 @@ typedef struct typedef struct { - tic_bank banks[TIC_BANKS]; + union + { + tic_bank bank; + tic_bank banks[TIC_BANKS]; + }; + tic_code code; tic_cover_image cover; tic_palette palette; diff --git a/src/world.c b/src/world.c index 89c7587..614a32a 100644 --- a/src/world.c +++ b/src/world.c @@ -105,13 +105,13 @@ void initWorld(World* world, tic_mem* tic, Map* map) for(s32 i = 0; i < TIC80_WIDTH * TIC80_HEIGHT; i++) { - u8 index = tic->cart.banks[0].map.data[i]; + u8 index = tic->cart.bank.map.data[i]; if(index) { SDL_memset(colors, 0, sizeof colors); - tic_tile* tile = &tic->cart.banks[0].tiles.data[index]; + tic_tile* tile = &tic->cart.bank.tiles.data[index]; for(s32 p = 0; p < TIC_SPRITESIZE * TIC_SPRITESIZE; p++) { From b13fc33aed2561c07a0d1f665ddec2b23fbdc77a Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Mon, 11 Dec 2017 11:59:14 +0300 Subject: [PATCH 6/7] no message --- src/console.c | 26 +++++++++++--------------- src/tic.c | 27 ++++++++++++++++----------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/console.c b/src/console.c index 61917e7..4a6280f 100644 --- a/src/console.c +++ b/src/console.c @@ -357,16 +357,15 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param) loadCart(console->tic, cart, data, size, true); tic_mem* tic = console->tic; - // TODO: should load to the currena bank switch(i) { case 0: memcpy(&tic->cart.bank.tiles, &cart->bank.tiles, sizeof(tic_tiles)*2); 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 3: memcpy(&tic->cart.code, &cart->code, sizeof cart->code); 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 4: memcpy(&tic->cart.bank.sfx, &cart->bank.sfx, sizeof(tic_sfx)); break; case 5: memcpy(&tic->cart.bank.music, &cart->bank.music, sizeof(tic_music)); break; - case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof(tic_palette)); break; + case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof(tic_palette)); break; } studioRomLoaded(); @@ -603,15 +602,14 @@ static char* saveBinarySection(char* ptr, const char* comment, const char* tag, typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection; static const BinarySection BinarySections[] = { - // TODO: fix banks loading here - {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, - {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.tiles), sizeof(tic_tile), true}, - {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.sprites), sizeof(tic_tile), true}, - {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, bank.map), TIC_MAP_WIDTH, true}, - {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, bank.sfx.waveform.envelopes), sizeof(tic_waveform), true}, - {"SFX", SFX_COUNT, offsetof(tic_cartridge, bank.sfx.data), sizeof(tic_sound_effect), true}, - {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, bank.music.patterns), sizeof(tic_track_pattern), true}, - {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, bank.music.tracks), sizeof(tic_track), true}, + {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, + {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.tiles), sizeof(tic_tile), true}, + {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank.sprites), sizeof(tic_tile), true}, + {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, bank.map), TIC_MAP_WIDTH, true}, + {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, bank.sfx.waveform.envelopes), sizeof(tic_waveform), true}, + {"SFX", SFX_COUNT, offsetof(tic_cartridge, bank.sfx.data), sizeof(tic_sound_effect), true}, + {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, bank.music.patterns), sizeof(tic_track_pattern), true}, + {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, bank.music.tracks), sizeof(tic_track), true}, }; static s32 saveProject(Console* console, void* buffer, const char* comment) @@ -1332,7 +1330,6 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v tic_rgb rgb = {c->r, c->g, c->b}; u8 color = tic_tool_find_closest_color(console->tic->cart.palette.colors, &rgb); - // TODO: should be current bank setSpritePixel(console->tic->cart.bank.tiles.data, x, y, color); } @@ -1355,7 +1352,6 @@ static void injectMap(Console* console, const void* buffer, s32 size) { enum {Size = sizeof(tic_map)}; - // TODO: should be current bank SDL_memset(&console->tic->cart.bank.map, 0, Size); SDL_memcpy(&console->tic->cart.bank.map, buffer, SDL_min(size, Size)); } diff --git a/src/tic.c b/src/tic.c index 32e1d66..61164cb 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1539,17 +1539,22 @@ static double api_time(tic_mem* memory) static void api_sync(tic_mem* tic, bool toCart) { - // TODO: fix this - // 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); - // } + 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 u32 api_btnp(tic_mem* tic, s32 index, s32 hold, s32 period) From 7a6dba1f24bad870bb5616c9089db205fd4232a0 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Mon, 11 Dec 2017 12:20:04 +0300 Subject: [PATCH 7/7] no message --- src/tic.c | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/tic.c b/src/tic.c index 61164cb..b3a7651 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1323,14 +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) { - memcpy(&memory->ram.tiles, &memory->cart.bank.tiles, sizeof(tic_tiles)); - memcpy(&memory->ram.sprites, &memory->cart.bank.sprites, sizeof(tic_tiles)); - memcpy(&memory->ram.map, &memory->cart.bank.map, sizeof(tic_tiles)); - - memcpy(&memory->ram.sfx, &memory->cart.bank.sfx, sizeof(tic_sfx)); - memcpy(&memory->ram.music, &memory->cart.bank.music, sizeof(tic_music)); + api_sync(memory, false); initCover(memory); } @@ -1537,26 +1552,6 @@ static double api_time(tic_mem* memory) 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.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 u32 api_btnp(tic_mem* tic, s32 index, s32 hold, s32 period) { tic_machine* machine = (tic_machine*)tic;