code loads from all the banks on the game start

This commit is contained in:
BADIM-PC\Vadim 2017-12-14 14:53:47 +03:00
parent 2242873d88
commit ebd40d5e74
11 changed files with 44 additions and 35 deletions

1
.gitignore vendored
View File

@ -92,3 +92,4 @@ build/windows/tic80/Release Pro/
build/windows/zlib/Debug Pro/ build/windows/zlib/Debug Pro/
build/windows/zlib/Release Pro/ build/windows/zlib/Release Pro/
build/windows/example/Release Pro/ build/windows/example/Release Pro/
build/windows/example/Debug Pro/

View File

@ -170,7 +170,7 @@ static void readConfig(Config* config)
if(lua) if(lua)
{ {
if(luaL_loadstring(lua, config->tic->config.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK) if(luaL_loadstring(lua, config->tic->config.bank.code.data) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK)
{ {
readConfigVideoLength(config, lua); readConfigVideoLength(config, lua);
readConfigVideoScale(config, lua); readConfigVideoScale(config, lua);
@ -185,7 +185,7 @@ static void readConfig(Config* config)
static void update(Config* config, const u8* buffer, size_t size) static void update(Config* config, const u8* buffer, size_t size)
{ {
config->tic->api.load((tic_cartridge*)&config->tic->config, sizeof(tic_bank), buffer, size, true); config->tic->api.load(&config->tic->config, buffer, size, true);
readConfig(config); readConfig(config);
studioConfigChanged(); studioConfigChanged();

View File

@ -303,10 +303,10 @@ static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s
static void loadCart(tic_mem* tic, tic_cartridge* cart, const u8* buffer, s32 size, bool palette) static void loadCart(tic_mem* tic, tic_cartridge* cart, const u8* buffer, s32 size, bool palette)
{ {
tic->api.load(cart, sizeof(tic_cartridge), buffer, size, palette); tic->api.load(cart, buffer, size, palette);
if(!palette) if(!palette)
memcpy(cart->bank.palette.data, tic->config.palette.data, sizeof(tic_palette)); memcpy(cart->bank.palette.data, tic->config.bank.palette.data, sizeof(tic_palette));
} }
static bool loadRom(tic_mem* tic, const void* data, s32 size, bool palette) static bool loadRom(tic_mem* tic, const void* data, s32 size, bool palette)
@ -734,7 +734,7 @@ static bool loadProject(Console* console, const char* name, const char* data, s3
if(cart) if(cart)
{ {
SDL_memset(cart, 0, sizeof(tic_cartridge)); SDL_memset(cart, 0, sizeof(tic_cartridge));
SDL_memcpy(&cart->bank.palette, &tic->config.palette.data, sizeof(tic_palette)); SDL_memcpy(&cart->bank.palette, &tic->config.bank.palette.data, sizeof(tic_palette));
const char* comment = projectComment(name); const char* comment = projectComment(name);
@ -2886,7 +2886,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
if(argc > 1) if(argc > 1)
{ {
memcpy(console->embed.file->bank.palette.data, tic->config.palette.data, sizeof(tic_palette)); memcpy(console->embed.file->bank.palette.data, tic->config.bank.palette.data, sizeof(tic_palette));
u32 argp = 1; u32 argp = 1;

View File

@ -170,7 +170,7 @@ static void drawDialog(Dialog* dlg)
{ {
u8 chromakey = 14; 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.bank.tiles, 2, rect.x+6, rect.y-4, 2, 2, &chromakey, 1, 1, tic_no_flip, tic_no_rotate);
} }
{ {

View File

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

View File

@ -1327,7 +1327,7 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index)
} }
u8 color = Chroma; u8 color = Chroma;
tic->api.sprite(tic, &tic->config.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) static void drawTracker(Music* music, s32 x, s32 y)

View File

@ -342,7 +342,7 @@ tic_palette* getBankPalette()
void playSystemSfx(s32 id) void playSystemSfx(s32 id)
{ {
const tic_sound_effect* effect = &studio.tic->config.sfx.data[id]; const tic_sound_effect* effect = &studio.tic->config.bank.sfx.data[id];
studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0); studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0);
} }
@ -1976,7 +1976,7 @@ static void transparentBlit(u32* out, s32 pitch)
{ {
const u8* in = studio.tic->ram.vram.screen.data; const u8* in = studio.tic->ram.vram.screen.data;
const u8* end = in + sizeof(studio.tic->ram.vram.screen); const u8* end = in + sizeof(studio.tic->ram.vram.screen);
const u32* pal = tic_palette_blit(&studio.tic->config.palette); const u32* pal = tic_palette_blit(&studio.tic->config.bank.palette);
const u32 Delta = (pitch/sizeof *out - TIC80_WIDTH); const u32 Delta = (pitch/sizeof *out - TIC80_WIDTH);
s32 col = 0; s32 col = 0;
@ -2053,7 +2053,7 @@ static void recordFrame(u32* pixels)
if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2) if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2)
{ {
const u32* pal = tic_palette_blit(&studio.tic->config.palette); const u32* pal = tic_palette_blit(&studio.tic->config.bank.palette);
drawRecordLabel(pixels, TIC80_FULLWIDTH, TIC80_WIDTH-24, 8, &pal[tic_color_red]); drawRecordLabel(pixels, TIC80_FULLWIDTH, TIC80_WIDTH-24, 8, &pal[tic_color_red]);
} }
@ -2214,12 +2214,12 @@ static void renderCursor()
SDL_ShowCursor(getConfig()->theme.cursor.sprite >= 0 ? SDL_DISABLE : SDL_ENABLE); SDL_ShowCursor(getConfig()->theme.cursor.sprite >= 0 ? SDL_DISABLE : SDL_ENABLE);
if(getConfig()->theme.cursor.sprite >= 0) if(getConfig()->theme.cursor.sprite >= 0)
blitCursor(studio.tic->config.tiles.data[getConfig()->theme.cursor.sprite].data); blitCursor(studio.tic->config.bank.tiles.data[getConfig()->theme.cursor.sprite].data);
} }
static void useSystemPalette() static void useSystemPalette()
{ {
memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.palette.data, sizeof(tic_palette)); memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.bank.palette.data, sizeof(tic_palette));
} }
static void drawPopup() static void drawPopup()
@ -2269,8 +2269,8 @@ static void renderStudio()
case TIC_DIALOG_MODE: case TIC_DIALOG_MODE:
case TIC_MENU_MODE: case TIC_MENU_MODE:
case TIC_SURF_MODE: case TIC_SURF_MODE:
sfx = &studio.tic->config.sfx; sfx = &studio.tic->config.bank.sfx;
music = &studio.tic->config.music; music = &studio.tic->config.bank.music;
break; break;
default: default:
sfx = getBankSfx(); sfx = getBankSfx();
@ -2453,7 +2453,7 @@ static void initTouchGamepad()
if (!studio.renderer) if (!studio.renderer)
return; 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.bank.map, &studio.tic->config.bank.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1);
if(!studio.gamepad.texture) if(!studio.gamepad.texture)
{ {
@ -2480,7 +2480,7 @@ static void updateSystemFont()
for(s32 i = 0; i < TIC_FONT_CHARS; i++) for(s32 i = 0; i < TIC_FONT_CHARS; i++)
for(s32 y = 0; y < TIC_SPRITESIZE; y++) for(s32 y = 0; y < TIC_SPRITESIZE; y++)
for(s32 x = 0; x < TIC_SPRITESIZE; x++) for(s32 x = 0; x < TIC_SPRITESIZE; x++)
if(tic_tool_peek4(&studio.tic->config.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; studio.tic->font.data[i*BITS_IN_BYTE+y] |= 1 << x;
} }
@ -2501,12 +2501,12 @@ static void setWindowIcon()
u32* pixels = SDL_malloc(Size * Size * sizeof(u32)); u32* pixels = SDL_malloc(Size * Size * sizeof(u32));
const u32* pal = tic_palette_blit(&studio.tic->config.palette); const u32* pal = tic_palette_blit(&studio.tic->config.bank.palette);
for(s32 j = 0, index = 0; j < Size; j++) for(s32 j = 0, index = 0; j < Size; j++)
for(s32 i = 0; i < Size; i++, index++) for(s32 i = 0; i < Size; i++, index++)
{ {
u8 color = getSpritePixel(studio.tic->config.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]; pixels[index] = color == ColorKey ? 0 : pal[color];
} }

View File

@ -202,14 +202,14 @@ static void drawTopToolbar(Surf* surf, s32 x, s32 y)
enum{Gap = 10, TipX = 150, SelectWidth = 54}; enum{Gap = 10, TipX = 150, SelectWidth = 54};
u8 colorkey = 0; u8 colorkey = 0;
tic->api.sprite_ex(tic, &tic->config.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"; static const char Label[] = "SELECT";
tic->api.text(tic, Label, TipX + Gap, y+3, tic_color_black); tic->api.text(tic, Label, TipX + Gap, y+3, tic_color_black);
tic->api.text(tic, Label, TipX + Gap, y+2, tic_color_white); tic->api.text(tic, Label, TipX + Gap, y+2, tic_color_white);
} }
tic->api.sprite_ex(tic, &tic->config.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"; static const char Label[] = "BACK";
tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black);
@ -244,7 +244,7 @@ static void drawBottomToolbar(Surf* surf, s32 x, s32 y)
u8 colorkey = 0; u8 colorkey = 0;
tic->api.sprite_ex(tic, &tic->config.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"; static const char Label[] = "WEBSITE";
tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black); tic->api.text(tic, Label, TipX + Gap + SelectWidth, y +3, tic_color_black);
@ -355,7 +355,7 @@ static void drawBG(Surf* surf)
for(s32 j = 0; j < Height + 1; j++) for(s32 j = 0; j < Height + 1; j++)
for(s32 i = 0; i < Width + 1; i++) for(s32 i = 0; i < Width + 1; i++)
if(counter++ % 2) if(counter++ % 2)
tic->api.sprite_ex(tic, &tic->config.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) static void replace(char* src, const char* what, const char* with)
@ -508,7 +508,7 @@ static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size)
{ {
const gif_color* c = &image->palette[image->buffer[i]]; const gif_color* c = &image->palette[image->buffer[i]];
tic_rgb rgb = { c->r, c->g, c->b }; tic_rgb rgb = { c->r, c->g, c->b };
u8 color = tic_tool_find_closest_color(tic->config.palette.colors, &rgb); u8 color = tic_tool_find_closest_color(tic->config.bank.palette.colors, &rgb);
tic_tool_poke4(item->cover->data, i, color); tic_tool_poke4(item->cover->data, i, color);
} }
} }
@ -538,7 +538,7 @@ static void loadCover(Surf* surf)
if(hasExt(item->name, PROJECT_LUA_EXT)) if(hasExt(item->name, PROJECT_LUA_EXT))
surf->console->loadProject(surf->console, item->name, data, size, cart); surf->console->loadProject(surf->console, item->name, data, size, cart);
else else
tic->api.load(cart, sizeof(tic_cartridge), data, size, true); tic->api.load(cart, data, size, true);
if(cart->cover.size) if(cart->cover.size)
updateMenuItemCover(surf, cart->cover.data, cart->cover.size); updateMenuItemCover(surf, cart->cover.data, cart->cover.size);

View File

@ -1472,12 +1472,20 @@ static void api_tick(tic_mem* memory, tic_tick_data* data)
if(!machine->state.initialized) if(!machine->state.initialized)
{ {
enum{CodeSize = sizeof(tic_code) * TIC_BANKS};
char* code = malloc(sizeof(tic_code)); char* code = malloc(CodeSize);
if(code) if(code)
{ {
memcpy(code, machine->memory.cart.bank.code.data, sizeof(tic_code)); memset(code, 0, CodeSize);
for(s32 i = TIC_BANKS - 1; i >= 0; i--)
{
const char* bankCode = memory->cart.banks[i].code.data;
if(strlen(bankCode))
strcat(code, bankCode);
}
if(data->preprocessor) if(data->preprocessor)
data->preprocessor(data->data, code); data->preprocessor(data->data, code);
@ -1579,10 +1587,10 @@ static u32 api_btnp(tic_mem* tic, s32 index, s32 hold, s32 period)
return ((~previous.data) & machine->memory.ram.vram.input.gamepad.data) & (1 << index); return ((~previous.data) & machine->memory.ram.vram.input.gamepad.data) & (1 << index);
} }
static void api_load(tic_cartridge* cart, s32 cartSize, const u8* buffer, s32 size, bool palette) static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palette)
{ {
const u8* end = buffer + size; const u8* end = buffer + size;
memset(cart, 0, cartSize); memset(cart, 0, sizeof(tic_cartridge));
if(palette) if(palette)
{ {

View File

@ -108,7 +108,7 @@ TIC80_API void tic80_load(tic80* tic, void* cart, s32 size)
} }
{ {
tic80->memory->api.load(&tic80->memory->cart, sizeof(tic_cartridge), cart, size, true); tic80->memory->api.load(&tic80->memory->cart, cart, size, true);
tic80->memory->api.reset(tic80->memory); tic80->memory->api.reset(tic80->memory);
} }
} }

View File

@ -106,7 +106,7 @@ typedef struct
void (*sync) (tic_mem* memory, const char* section, s32 bank, bool toCart); void (*sync) (tic_mem* memory, const char* section, s32 bank, bool toCart);
u32 (*btnp) (tic_mem* memory, s32 id, s32 hold, s32 period); u32 (*btnp) (tic_mem* memory, s32 id, s32 hold, s32 period);
void (*load) (tic_cartridge* rom, s32 cartSize, const u8* buffer, s32 size, bool palette); void (*load) (tic_cartridge* rom, const u8* buffer, s32 size, bool palette);
s32 (*save) (const tic_cartridge* rom, u8* buffer); s32 (*save) (const tic_cartridge* rom, u8* buffer);
void (*tick_start) (tic_mem* memory, const tic_sfx* sfx, const tic_music* music); void (*tick_start) (tic_mem* memory, const tic_sfx* sfx, const tic_music* music);
@ -120,7 +120,7 @@ struct tic_mem
{ {
tic_ram ram; tic_ram ram;
tic_cartridge cart; tic_cartridge cart;
tic_bank config; tic_cartridge config;
tic_input_method input; tic_input_method input;
tic_script_lang script; tic_script_lang script;
tic_font font; tic_font font;