Load GO1/GO2 who have a CPC Old palette

This commit is contained in:
Thomas Bernard 2019-12-06 00:25:09 +01:00
parent 6353202623
commit 24c0bda8b4
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -4994,15 +4994,15 @@ void Test_GOS(T_IO_Context * context, FILE * file)
file_oddeve = Open_file_read_with_alternate_ext(context, "GO2"); file_oddeve = Open_file_read_with_alternate_ext(context, "GO2");
if (file_oddeve == NULL) { if (file_oddeve == NULL) {
File_error = 2; File_error = 2;
return; return;
} }
if (!CPC_check_AMSDOS(file_oddeve, NULL, &file_size)) if (!CPC_check_AMSDOS(file_oddeve, NULL, &file_size))
file_size = File_length_file(file_oddeve); file_size = File_length_file(file_oddeve);
fclose(file_oddeve); fclose(file_oddeve);
if (file_size < 16383 || file_size > 16384) { if (file_size < 16383 || file_size > 16384) {
File_error = 3; File_error = 3;
return; return;
} }
File_error = 0; File_error = 0;
@ -5043,20 +5043,20 @@ void Load_GOS(T_IO_Context* context)
i = 0; i = 0;
for (y = 0; y < 168; y++) { for (y = 0; y < 168; y++) {
x = 0; x = 0;
while (x < 192) { while (x < 192) {
byte pixels = pixel_data[i]; byte pixels = pixel_data[i];
Set_pixel(context, x++, y, (pixels & 0x80) >> 7 | (pixels & 0x08) >> 2 | (pixels & 0x20) >> 3 | (pixels & 0x02) << 2); Set_pixel(context, x++, y, (pixels & 0x80) >> 7 | (pixels & 0x08) >> 2 | (pixels & 0x20) >> 3 | (pixels & 0x02) << 2);
Set_pixel(context, x++, y, (pixels & 0x40) >> 6 | (pixels & 0x04) >> 1 | (pixels & 0x10) >> 2 | (pixels & 0x01) << 3); Set_pixel(context, x++, y, (pixels & 0x40) >> 6 | (pixels & 0x04) >> 1 | (pixels & 0x10) >> 2 | (pixels & 0x01) << 3);
i++; i++;
} }
i += 0x800; i += 0x800;
if (i > 0x3FFF) { if (i > 0x3FFF) {
i -= 0x4000; i -= 0x4000;
} else { } else {
i -= 192 / 2; i -= 192 / 2;
} }
} }
fclose(file); fclose(file);
@ -5069,32 +5069,34 @@ void Load_GOS(T_IO_Context* context)
Read_bytes(file, pixel_data, file_size); Read_bytes(file, pixel_data, file_size);
i = 0; i = 0;
for (y = 168; y < 272; y++) { for (y = 168; y < 272; y++) {
x = 0; x = 0;
while (x < 192) { while (x < 192) {
byte pixels = pixel_data[i]; byte pixels = pixel_data[i];
Set_pixel(context, x++, y, (pixels & 0x80) >> 7 | (pixels & 0x08) >> 2 | (pixels & 0x20) >> 3 | (pixels & 0x02) << 2); Set_pixel(context, x++, y, (pixels & 0x80) >> 7 | (pixels & 0x08) >> 2 | (pixels & 0x20) >> 3 | (pixels & 0x02) << 2);
Set_pixel(context, x++, y, (pixels & 0x40) >> 6 | (pixels & 0x04) >> 1 | (pixels & 0x10) >> 2 | (pixels & 0x01) << 3); Set_pixel(context, x++, y, (pixels & 0x40) >> 6 | (pixels & 0x04) >> 1 | (pixels & 0x10) >> 2 | (pixels & 0x01) << 3);
i++; i++;
} }
i += 0x800; i += 0x800;
if (i > 0x3FFF) { if (i > 0x3FFF) {
i -= 0x4000; i -= 0x4000;
} else { } else {
i -= 192 / 2; i -= 192 / 2;
} }
} }
fclose(file); fclose(file);
file = Open_file_read_with_alternate_ext(context, "KIT"); file = Open_file_read_with_alternate_ext(context, "KIT");
if (file == NULL) { if (file == NULL) {
// There is no palette, but that's fine, we can still load the pixels // There is no palette, but that's fine, we can still load the pixels
return; return;
} }
if (CPC_check_AMSDOS(file, NULL, NULL)) { if (CPC_check_AMSDOS(file, NULL, &file_size)) {
fseek(file, 128, SEEK_SET); // right after AMSDOS header fseek(file, 128, SEEK_SET); // right after AMSDOS header
} else {
file_size = File_length_file(file);
} }
if (Config.Clear_palette) if (Config.Clear_palette)
@ -5102,18 +5104,36 @@ void Load_GOS(T_IO_Context* context)
File_error = 0; File_error = 0;
for (i = 0; i < 16; i++) if (file_size == 32)
{ {
uint16_t word; for (i = 0; i < 16; i++)
if (!Read_word_le(file, &word))
{ {
File_error = 2; uint16_t word;
return; if (!Read_word_le(file, &word))
} {
File_error = 2;
return;
}
context->Palette[i].R = ((word >> 4) & 0xF) * 0x11; context->Palette[i].R = ((word >> 4) & 0xF) * 0x11;
context->Palette[i].G = ((word >> 8) & 0xF) * 0x11; context->Palette[i].G = ((word >> 8) & 0xF) * 0x11;
context->Palette[i].B = ((word >> 0) & 0xF) * 0x11; context->Palette[i].B = ((word >> 0) & 0xF) * 0x11;
}
}
else
{
// Setup the palette (amstrad hardware palette)
CPC_set_HW_palette(context->Palette + 0x40);
for (i = 0; i < 16; i++)
{
byte ink;
if (!Read_byte(file, &ink))
{
File_error = 2;
return;
}
context->Palette[i] = context->Palette[ink];
}
} }
fclose(file); fclose(file);