Save_GOS(): save the palette in CPC Plus "KIT" format

This commit is contained in:
Thomas Bernard 2019-12-21 18:11:44 +01:00
parent 20a2620ffc
commit 60c3f0b4ed
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -811,7 +811,7 @@ void Load_GOS(T_IO_Context* context)
if (!Read_word_le(file, &word))
{
File_error = 2;
return;
break;
}
context->Palette[i].R = ((word >> 4) & 0xF) * 0x11;
@ -829,7 +829,7 @@ void Load_GOS(T_IO_Context* context)
if (!Read_byte(file, &ink))
{
File_error = 2;
return;
break;
}
context->Palette[i] = context->Palette[ink];
}
@ -842,12 +842,11 @@ void Load_GOS(T_IO_Context* context)
void Save_GOS(T_IO_Context* context)
{
FILE* file;
int i;
unsigned char* output;
unsigned long outsize = 0;
unsigned char r1 = 0;
// TODO save KIT file for color palette
// TODO check picture dimensions (GOS is a fixed resolution format)
// For now, force the size
context->Width = 192;
@ -862,9 +861,12 @@ void Save_GOS(T_IO_Context* context)
if (!Write_bytes(file, output, outsize))
File_error = 1;
// Pad to expected size
// TODO: pad with 0s ?
if (!Write_bytes(file, output, 16384 - outsize))
File_error = 1;
fclose(file);
if (File_error)
return;
// convert and save page 2
// Advance context to second half of picture
@ -873,7 +875,10 @@ void Save_GOS(T_IO_Context* context)
output = raw2crtc(context, 0, 7, &outsize, &r1, 0, 0);
file = Open_file_write_with_alternate_ext(context, "GO2");
if (file == NULL)
{
File_error = 1;
return;
}
File_error = 0;
if (!Write_bytes(file, output, outsize))
File_error = 1;
@ -881,6 +886,20 @@ void Save_GOS(T_IO_Context* context)
if (!Write_bytes(file, output, 16384 - outsize))
File_error = 1;
fclose(file);
if (File_error)
return;
file = Open_file_write_with_alternate_ext(context, "KIT");
for (i = 0; i < 16 && File_error == 0; i++)
{
uint16_t word;
word = (context->Palette[i].R & 0xF0)
| ((context->Palette[i].G & 0xF0) << 4)
| (context->Palette[i].B >> 4);
if (!Write_word_le(file, word))
File_error = 2;
}
fclose(file);
}