Add support for Graphos (Amstrad Plus) files.
This commit is contained in:
@@ -4683,6 +4683,154 @@ void Save_SCR(T_IO_Context * context)
|
||||
free (output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for GO1/GO2/KIT - Amstrad Plus Graphos
|
||||
*
|
||||
* This format is made of 3 files
|
||||
* .KIT hold the palette in "Kit4096" format. There are 16 colors each stored
|
||||
* as 12 bit RGB in RB0G order.
|
||||
* .GO1 and GO2 hold each half of the picture (top and bottom)
|
||||
* The file always cover the whole display of the Plus (196*272 or so)
|
||||
*/
|
||||
void Test_GOS(T_IO_Context * context, FILE * file)
|
||||
{
|
||||
FILE *file_oddeve;
|
||||
unsigned long file_size;
|
||||
file_size = File_length_file(file);
|
||||
if (file_size != 16512) {
|
||||
File_error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
file_oddeve = Open_file_read_with_alternate_ext(context, "GO2");
|
||||
if (file_oddeve == NULL) {
|
||||
File_error = 2;
|
||||
return;
|
||||
}
|
||||
file_size = File_length_file(file_oddeve);
|
||||
fclose(file_oddeve);
|
||||
if (file_size != 16512) {
|
||||
File_error = 3;
|
||||
return;
|
||||
}
|
||||
|
||||
file_oddeve = Open_file_read_with_alternate_ext(context, "KIT");
|
||||
if (file_oddeve == NULL) {
|
||||
File_error = 4;
|
||||
return;
|
||||
}
|
||||
file_size = File_length_file(file_oddeve);
|
||||
fclose(file_oddeve);
|
||||
if (file_size != 160) {
|
||||
File_error = 5;
|
||||
return;
|
||||
}
|
||||
|
||||
File_error = 0;
|
||||
}
|
||||
|
||||
|
||||
void Load_GOS(T_IO_Context* context)
|
||||
{
|
||||
FILE *file;
|
||||
long file_size;
|
||||
int i;
|
||||
int x, y;
|
||||
byte * pixel_data;
|
||||
|
||||
if (!(file = Open_file_read(context)))
|
||||
{
|
||||
File_error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
file_size=File_length_file(file);
|
||||
|
||||
if (CPC_check_AMSDOS(file, NULL, NULL)) {
|
||||
fseek(file, 128, SEEK_SET); // right after AMSDOS header
|
||||
}
|
||||
|
||||
context->Ratio = PIXEL_WIDE;
|
||||
Pre_load(context, 192, 272, file_size, FORMAT_GOS, context->Ratio, 0);
|
||||
context->Width = 192;
|
||||
context->Height = 272;
|
||||
|
||||
// load pixels
|
||||
pixel_data = GFX2_malloc(16384);
|
||||
memset(pixel_data, 0, 16384);
|
||||
Read_bytes(file, pixel_data, file_size);
|
||||
|
||||
i = 0;
|
||||
for (y = 0; y < 168; y++) {
|
||||
x = 0;
|
||||
while (x < 192) {
|
||||
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 & 0x40) >> 6 | (pixels & 0x04) >> 1 | (pixels & 0x10) >> 2 | (pixels & 0x01) << 3);
|
||||
i++;
|
||||
}
|
||||
|
||||
i += 0x800;
|
||||
if (i > 0x3FFF) {
|
||||
i -= 0x4000;
|
||||
} else {
|
||||
i -= 192 / 2;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
// load pixels from GO2
|
||||
file = Open_file_read_with_alternate_ext(context, "GO2");
|
||||
if (CPC_check_AMSDOS(file, NULL, NULL)) {
|
||||
fseek(file, 128, SEEK_SET); // right after AMSDOS header
|
||||
}
|
||||
Read_bytes(file, pixel_data, file_size);
|
||||
i = 0;
|
||||
for (y = 168; y < 272; y++) {
|
||||
x = 0;
|
||||
while (x < 192) {
|
||||
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 & 0x40) >> 6 | (pixels & 0x04) >> 1 | (pixels & 0x10) >> 2 | (pixels & 0x01) << 3);
|
||||
i++;
|
||||
}
|
||||
|
||||
i += 0x800;
|
||||
if (i > 0x3FFF) {
|
||||
i -= 0x4000;
|
||||
} else {
|
||||
i -= 192 / 2;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
file = Open_file_read_with_alternate_ext(context, "KIT");
|
||||
if (CPC_check_AMSDOS(file, NULL, NULL)) {
|
||||
fseek(file, 128, SEEK_SET); // right after AMSDOS header
|
||||
}
|
||||
|
||||
if (Config.Clear_palette)
|
||||
memset(context->Palette,0,sizeof(T_Palette));
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
uint16_t word;
|
||||
if (!Read_word_be(file, &word)) {
|
||||
fclose(file);
|
||||
File_error = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
context->Palette[i].R = ((word >> 8) & 0xF) * 0x11;
|
||||
context->Palette[i].G = ((word >> 0) & 0xF) * 0x11;
|
||||
context->Palette[i].B = ((word >> 12) & 0xF) * 0x11;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
File_error = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for CM5 - Amstrad CPC "Mode 5" picture
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user