added cover saving

This commit is contained in:
BADIM-PC\Vadim 2017-11-11 16:57:39 +03:00
parent af7469a2d7
commit 9442d59243
2 changed files with 24 additions and 14 deletions

View File

@ -1651,8 +1651,6 @@ static const BinarySection BinarySections[] =
{"SFX", SFX_COUNT, offsetof(tic_cartridge, sound.sfx.data), sizeof(tic_sound_effect), 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}, {"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}, {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, sound.music.tracks), sizeof(tic_track), true},
// TODO: add cover
}; };
static CartSaveResult saveProject(Console* console, const char* name) static CartSaveResult saveProject(Console* console, const char* name)
@ -1675,6 +1673,8 @@ static CartSaveResult saveProject(Console* console, const char* name)
ptr = saveBinarySection(ptr, section->tag, section->count, (u8*)&tic->cart + section->offset, section->size, section->flip); ptr = saveBinarySection(ptr, section->tag, section->count, (u8*)&tic->cart + section->offset, section->size, section->flip);
} }
saveBinarySection(ptr, "COVER", 1, &tic->cart.cover, tic->cart.cover.size + sizeof(s32), true);
name = getProjectName(name); name = getProjectName(name);
s32 size = strlen(stream); s32 size = strlen(stream);
@ -1776,21 +1776,29 @@ static void loadBinarySection(const char* project, const char* tag, s32 count, v
{ {
const char* ptr = start; const char* ptr = start;
if(size > 0)
{
while(ptr < end) while(ptr < end)
{ {
char lineStr[] = "999"; static char lineStr[] = "999";
memcpy(lineStr, ptr + strlen("-- "), strlen(lineStr)); memcpy(lineStr, ptr + sizeof("-- ") - 1, sizeof lineStr - 1);
s32 index = SDL_atoi(lineStr); s32 index = SDL_atoi(lineStr);
if(index < count) if(index < count)
{ {
ptr += strlen("-- 999:"); ptr += sizeof("-- 999:") - 1;
str2buf(ptr, size*2, (u8*)dst + size*index, flip); str2buf(ptr, size*2, (u8*)dst + size*index, flip);
ptr += size*2 + 1; ptr += size*2 + 1;
} }
} }
} }
else
{
ptr += sizeof("-- 999:") - 1;
str2buf(ptr, end - ptr, (u8*)dst, flip);
}
}
} }
} }
@ -1822,6 +1830,8 @@ static bool loadProject(Console* console, const char* data, s32 size)
loadBinarySection(project, section->tag, section->count, (u8*)cart + section->offset, section->size, section->flip); loadBinarySection(project, section->tag, section->count, (u8*)cart + section->offset, section->size, section->flip);
} }
loadBinarySection(project, "COVER", 1, &cart->cover, -1, true);
SDL_memcpy(&tic->cart, cart, sizeof(tic_cartridge)); SDL_memcpy(&tic->cart, cart, sizeof(tic_cartridge));
SDL_free(cart); SDL_free(cart);

View File

@ -304,8 +304,8 @@ typedef struct
typedef struct typedef struct
{ {
u8 data [TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)];
s32 size; s32 size;
u8 data [TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)];
} tic_cover_image; } tic_cover_image;
typedef struct typedef struct