config cart moved from tic_mem

This commit is contained in:
BADIM-PC\Vadim 2018-03-12 09:40:48 +03:00
parent dbcd4d74ef
commit fbf9daa68d
14 changed files with 42 additions and 43 deletions

View File

@ -240,7 +240,7 @@ static void readConfig(Config* config)
if(lua)
{
if(luaL_loadstring(lua, config->tic->config.bank0.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK)
if(luaL_loadstring(lua, config->cart.bank0.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK)
{
readConfigVideoLength(config, lua);
readConfigVideoScale(config, lua);
@ -251,7 +251,7 @@ static void readConfig(Config* config)
readTheme(config, lua);
}
if(luaL_loadstring(lua, config->tic->config.bank1.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK)
if(luaL_loadstring(lua, config->cart.bank1.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK)
{
readConfigCrtShader(config, lua);
}
@ -262,7 +262,7 @@ static void readConfig(Config* config)
static void update(Config* config, const u8* buffer, size_t size)
{
config->tic->api.load(&config->tic->config, buffer, size, true);
config->tic->api.load(&config->cart, buffer, size, true);
readConfig(config);
studioConfigChanged();
@ -272,6 +272,8 @@ static void setDefault(Config* config)
{
memset(&config->data, 0, sizeof(StudioConfig));
config->data.cart = &config->cart;
{
static const u8 DefaultBiosZip[] =
{
@ -296,7 +298,7 @@ static void saveConfig(Config* config, bool overwrite)
if(buffer)
{
s32 size = config->tic->api.save(&config->tic->config, buffer);
s32 size = config->tic->api.save(&config->cart, buffer);
fsSaveRootFile(config->fs, CONFIG_TIC_PATH, buffer, size, overwrite);
@ -312,7 +314,7 @@ static void reset(Config* config)
static void save(Config* config)
{
memcpy(&config->tic->config, &config->tic->cart, sizeof(tic_cartridge));
memcpy(&config->cart, &config->tic->cart, sizeof(tic_cartridge));
readConfig(config);
saveConfig(config, true);

View File

@ -32,6 +32,7 @@ struct Config
struct FileSystem* fs;
StudioConfig data;
tic_cartridge cart;
void(*save)(Config*);
void(*reset)(Config*);

View File

@ -361,7 +361,7 @@ static void loadCart(tic_mem* tic, tic_cartridge* cart, const u8* buffer, s32 si
tic->api.load(cart, buffer, size, palette);
if(!palette)
memcpy(cart->bank0.palette.data, tic->config.bank0.palette.data, sizeof(tic_palette));
memcpy(cart->bank0.palette.data, getConfig()->cart->bank0.palette.data, sizeof(tic_palette));
}
static bool loadRom(tic_mem* tic, const void* data, s32 size, bool palette)
@ -887,8 +887,6 @@ static bool loadBinarySection(const char* project, const char* comment, const ch
static bool loadProject(Console* console, const char* name, const char* data, s32 size, tic_cartridge* dst)
{
tic_mem* tic = console->tic;
char* project = (char*)malloc(size+1);
bool done = false;
@ -909,7 +907,7 @@ static bool loadProject(Console* console, const char* name, const char* data, s3
if(cart)
{
memset(cart, 0, sizeof(tic_cartridge));
memcpy(&cart->bank0.palette, &tic->config.bank0.palette.data, sizeof(tic_palette));
memcpy(&cart->bank0.palette, &getConfig()->cart->bank0.palette.data, sizeof(tic_palette));
const char* comment = projectComment(name);
char tag[16];
@ -3099,7 +3097,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
if(argc > 1)
{
memcpy(console->embed.file->bank0.palette.data, tic->config.bank0.palette.data, sizeof(tic_palette));
memcpy(console->embed.file->bank0.palette.data, getConfig()->cart->bank0.palette.data, sizeof(tic_palette));
u32 argp = 1;

View File

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

View File

@ -1086,7 +1086,7 @@ static void onStudioEvent(Map* map, StudioEvent event)
static void scanline(tic_mem* tic, s32 row, void* data)
{
if(row == 0)
memcpy(tic->ram.vram.palette.data, tic->config.bank0.palette.data, sizeof(tic_palette));
memcpy(tic->ram.vram.palette.data, getConfig()->cart->bank0.palette.data, sizeof(tic_palette));
}
static void overline(tic_mem* tic, void* data)

View File

@ -124,7 +124,7 @@ static void drawDialog(Menu* menu)
{
u8 chromakey = 14;
tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate);
tic->api.sprite_ex(tic, &getConfig()->cart->bank0.tiles, 0, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate);
}
}
@ -209,7 +209,7 @@ static void drawPlayerButtons(Menu* menu, s32 x, s32 y)
if(menu->gamepad.selected == index && menu->ticks % TIC_FRAMERATE < TIC_FRAMERATE / 2)
continue;
tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate);
tic->api.sprite_ex(tic, &getConfig()->cart->bank0.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate);
static const char* const Names[tic_keys_count] = {"...", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "minus", "equals", "leftbracket", "rightbracket", "backslash", "semicolon", "apostrophe", "grave", "comma", "period", "slash", "space", "tab", "return", "backspace", "delete", "insert", "pageup", "pagedown", "home", "end", "up", "down", "left", "right", "capslock", "ctrl", "shift", "alt", "escape", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12"};

View File

@ -1354,7 +1354,7 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index)
}
u8 color = Chroma;
tic->api.sprite(tic, &tic->config.bank0.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1);
tic->api.sprite(tic, &getConfig()->cart->bank0.tiles, music->tracker.patterns[index] ? On : Off, x, y, &color, 1);
}
static void drawTracker(Music* music, s32 x, s32 y)

View File

@ -1628,7 +1628,7 @@ static void onStudioEvent(Sprite* sprite, StudioEvent event)
static void scanline(tic_mem* tic, s32 row, void* data)
{
if(row == 0)
memcpy(tic->ram.vram.palette.data, tic->config.bank0.palette.data, sizeof(tic_palette));
memcpy(tic->ram.vram.palette.data, getConfig()->cart->bank0.palette.data, sizeof(tic_palette));
}
static void overline(tic_mem* tic, void* data)

View File

@ -293,7 +293,7 @@ tic_palette* getBankPalette()
void playSystemSfx(s32 id)
{
const tic_sample* effect = &impl.studio.tic->config.bank0.sfx.samples.data[id];
const tic_sample* effect = &impl.config->cart.bank0.sfx.samples.data[id];
impl.studio.tic->api.sfx_ex(impl.studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0);
}
@ -1481,7 +1481,7 @@ static void drawDesyncLabel(u32* frame)
enum{sx = TIC80_WIDTH-24, sy = 8, Cols = sizeof DesyncLabel[0]*BITS_IN_BYTE, Rows = COUNT_OF(DesyncLabel)};
const u32* pal = tic_palette_blit(&impl.studio.tic->config.bank0.palette);
const u32* pal = tic_palette_blit(&impl.config->cart.bank0.palette);
const u32* color = &pal[tic_color_red];
for(s32 y = 0; y < Rows; y++)
@ -1506,7 +1506,7 @@ static void recordFrame(u32* pixels)
if(impl.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2)
{
const u32* pal = tic_palette_blit(&impl.studio.tic->config.bank0.palette);
const u32* pal = tic_palette_blit(&impl.config->cart.bank0.palette);
drawRecordLabel(pixels, TIC80_WIDTH-24, 8, &pal[tic_color_red]);
}
@ -1562,8 +1562,8 @@ static void renderStudio()
case TIC_DIALOG_MODE:
case TIC_MENU_MODE:
case TIC_SURF_MODE:
sfx = &impl.studio.tic->config.bank0.sfx;
music = &impl.studio.tic->config.bank0.music;
sfx = &impl.config->cart.bank0.sfx;
music = &impl.config->cart.bank0.music;
break;
default:
sfx = &impl.studio.tic->cart.banks[impl.bank.index.sfx].sfx;
@ -1631,7 +1631,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(&impl.studio.tic->config.bank0.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1))
if(tic_tool_peek4(&impl.config->cart.bank0.sprites.data[i], TIC_SPRITESIZE*(y+1) - x-1))
impl.studio.tic->font.data[i*BITS_IN_BYTE+y] |= 1 << x;
}
@ -1760,7 +1760,7 @@ static void studioTick()
}
break;
default:
memcpy(&tic->ram.vram.palette, &tic->config.bank0.palette, sizeof(tic_palette));
memcpy(&tic->ram.vram.palette, &impl.config->cart.bank0.palette, sizeof(tic_palette));
break;
}

View File

@ -201,14 +201,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.bank0.tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
tic->api.sprite_ex(tic, &getConfig()->cart->bank0.tiles, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
{
static const char Label[] = "SELECT";
tic->api.text(tic, Label, TipX + Gap, y+3, tic_color_black);
tic->api.text(tic, Label, TipX + Gap, y+2, tic_color_white);
}
tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
tic->api.sprite_ex(tic, &getConfig()->cart->bank0.tiles, 13, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
{
static const char Label[] = "BACK";
tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black);
@ -244,7 +244,7 @@ static void drawBottomToolbar(Surf* surf, s32 x, s32 y)
u8 colorkey = 0;
tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
tic->api.sprite_ex(tic, &getConfig()->cart->bank0.tiles, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate);
{
static const char Label[] = "WEBSITE";
tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black);
@ -355,7 +355,7 @@ static void drawBG(Surf* surf)
for(s32 j = 0; j < Height + 1; j++)
for(s32 i = 0; i < Width + 1; i++)
if(counter++ % 2)
tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 34, i*Size - offset, j*Size - offset, 2, 2, 0, 0, 1, tic_no_flip, tic_no_rotate);
tic->api.sprite_ex(tic, &getConfig()->cart->bank0.tiles, 34, i*Size - offset, j*Size - offset, 2, 2, 0, 0, 1, tic_no_flip, tic_no_rotate);
}
static void replace(char* src, const char* what, const char* with)
@ -490,8 +490,6 @@ static void* requestCover(Surf* surf, const char* hash, s32* size)
static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size)
{
tic_mem* tic = surf->tic;
MenuItem* item = &surf->menu.items[surf->menu.pos];
item->cover = malloc(sizeof(tic_screen));
@ -508,7 +506,7 @@ static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size)
{
const gif_color* c = &image->palette[image->buffer[i]];
tic_rgb rgb = { c->r, c->g, c->b };
u8 color = tic_tool_find_closest_color(tic->config.bank0.palette.colors, &rgb);
u8 color = tic_tool_find_closest_color(getConfig()->cart->bank0.palette.colors, &rgb);
tic_tool_poke4(item->cover->data, i, color);
}
}

View File

@ -99,13 +99,13 @@ static void initSound()
}
}
static u8* getSpritePtr(tic_tile* tiles, s32 x, s32 y)
static const u8* getSpritePtr(const tic_tile* tiles, s32 x, s32 y)
{
enum { SheetCols = (TIC_SPRITESHEET_SIZE / TIC_SPRITESIZE) };
return tiles[x / TIC_SPRITESIZE + y / TIC_SPRITESIZE * SheetCols].data;
}
static u8 getSpritePixel(tic_tile* tiles, s32 x, s32 y)
static u8 getSpritePixel(const tic_tile* tiles, s32 x, s32 y)
{
return tic_tool_peek4(getSpritePtr(tiles, x, y), (x % TIC_SPRITESIZE) + (y % TIC_SPRITESIZE) * TIC_SPRITESIZE);
}
@ -117,12 +117,12 @@ static void setWindowIcon()
u32* pixels = SDL_malloc(Size * Size * sizeof(u32));
const u32* pal = tic_palette_blit(&platform.studio->tic->config.bank0.palette);
const u32* pal = tic_palette_blit(&platform.studio->config()->cart->bank0.palette);
for(s32 j = 0, index = 0; j < Size; j++)
for(s32 i = 0; i < Size; i++, index++)
{
u8 color = getSpritePixel(platform.studio->tic->config.bank0.tiles.data, i/Scale, j/Scale);
u8 color = getSpritePixel(platform.studio->config()->cart->bank0.tiles.data, i/Scale, j/Scale);
pixels[index] = color == ColorKey ? 0 : pal[color];
}
@ -165,7 +165,7 @@ static void updateGamepadParts()
static void initTouchGamepad()
{
platform.studio->tic->api.map(platform.studio->tic, &platform.studio->tic->config.bank0.map, &platform.studio->tic->config.bank0.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1);
platform.studio->tic->api.map(platform.studio->tic, &platform.studio->config()->cart->bank0.map, &platform.studio->config()->cart->bank0.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1);
if(!platform.gamepad.texture)
{
@ -182,7 +182,7 @@ static void initTouchGamepad()
const u8* in = platform.studio->tic->ram.vram.screen.data;
const u8* end = in + sizeof(platform.studio->tic->ram.vram.screen);
const u32* pal = tic_palette_blit(&platform.studio->tic->config.bank0.palette);
const u32* pal = tic_palette_blit(&platform.studio->config()->cart->bank0.palette);
const u32 Delta = ((TIC80_FULLWIDTH*sizeof(u32))/sizeof *out - TIC80_WIDTH);
s32 col = 0;
@ -784,7 +784,7 @@ static void renderCursor()
if(platform.studio->config()->theme.cursor.hand >= 0)
{
SDL_ShowCursor(SDL_DISABLE);
blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.hand].data);
blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.hand].data);
}
else
{
@ -798,7 +798,7 @@ static void renderCursor()
if(platform.studio->config()->theme.cursor.ibeam >= 0)
{
SDL_ShowCursor(SDL_DISABLE);
blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.ibeam].data);
blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.ibeam].data);
}
else
{
@ -812,7 +812,7 @@ static void renderCursor()
if(platform.studio->config()->theme.cursor.arrow >= 0)
{
SDL_ShowCursor(SDL_DISABLE);
blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.arrow].data);
blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.arrow].data);
}
else
{

View File

@ -74,6 +74,7 @@ typedef struct
bool crtMonitor;
const char* crtShader;
const tic_cartridge* cart;
} StudioConfig;

View File

@ -423,7 +423,7 @@ static void renderCursor()
if(platform.studio->config()->theme.cursor.hand >= 0)
{
SDL_ShowCursor(SDL_DISABLE);
blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.hand].data);
blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.hand].data);
}
else
{
@ -437,7 +437,7 @@ static void renderCursor()
if(platform.studio->config()->theme.cursor.ibeam >= 0)
{
SDL_ShowCursor(SDL_DISABLE);
blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.ibeam].data);
blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.ibeam].data);
}
else
{
@ -451,7 +451,7 @@ static void renderCursor()
if(platform.studio->config()->theme.cursor.arrow >= 0)
{
SDL_ShowCursor(SDL_DISABLE);
blitCursor(platform.studio->tic->config.bank0.tiles.data[platform.studio->config()->theme.cursor.arrow].data);
blitCursor(platform.studio->config()->cart->bank0.tiles.data[platform.studio->config()->theme.cursor.arrow].data);
}
else
{

View File

@ -173,7 +173,6 @@ struct tic_mem
{
tic_ram ram;
tic_cartridge cart;
tic_cartridge config;
tic_font font;
tic_api api;
tic_persistent persistent;