Removed struct packing everywhere, except RGB 24bit struct (and thus 768-byte palettes). This might fix some issue on Caanoo, where either the packing didn't work (and the struct had wrong size) or it worked and caused unaligned reads/writes.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1639 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2010-10-26 22:51:07 +00:00
parent e5272e74f7
commit fba72c9ebd
5 changed files with 41 additions and 46 deletions

View File

@ -217,7 +217,6 @@ void Save_IMG(T_IO_Context * context)
//////////////////////////////////// LBM //////////////////////////////////// //////////////////////////////////// LBM ////////////////////////////////////
#pragma pack(1)
typedef struct typedef struct
{ {
word Width; word Width;
@ -234,7 +233,6 @@ typedef struct
word X_screen; word X_screen;
word Y_screen; word Y_screen;
} T_LBM_Header; } T_LBM_Header;
#pragma pack()
byte * LBM_buffer; byte * LBM_buffer;
FILE *LBM_file; FILE *LBM_file;
@ -695,13 +693,9 @@ void Load_LBM(T_IO_Context * context)
if ( !File_error ) if ( !File_error )
{ {
Read_dword_be(LBM_file,&section_size); Read_dword_be(LBM_file,&section_size);
//swab((char *)&header.Width ,(char *)&context->Width,2);
//swab((char *)&header.Height,(char *)&context->Height,2);
context->Width = header.Width; context->Width = header.Width;
context->Height = header.Height; context->Height = header.Height;
//swab((char *)&header.X_screen,(char *)&Original_screen_X,2);
//swab((char *)&header.Y_screen,(char *)&Original_screen_Y,2);
Original_screen_X = header.X_screen; Original_screen_X = header.X_screen;
Original_screen_Y = header.Y_screen; Original_screen_Y = header.Y_screen;
@ -979,7 +973,6 @@ void Save_LBM(T_IO_Context * context)
// On corrige la largeur de l'image pour qu'elle soit multiple de 2 // On corrige la largeur de l'image pour qu'elle soit multiple de 2
real_width=context->Width+(context->Width&1); real_width=context->Width+(context->Width&1);
//swab((byte *)&real_width,(byte *)&header.Width,2);
header.Width=context->Width; header.Width=context->Width;
header.Height=context->Height; header.Height=context->Height;
header.X_org=0; header.X_org=0;
@ -1659,7 +1652,6 @@ void Save_BMP(T_IO_Context * context)
//////////////////////////////////// GIF //////////////////////////////////// //////////////////////////////////// GIF ////////////////////////////////////
#pragma pack(1)
typedef struct typedef struct
{ {
word Width; // Width of the complete image area word Width; // Width of the complete image area
@ -1678,7 +1670,6 @@ typedef struct
byte Indicator; // Misc image information byte Indicator; // Misc image information
byte Nb_bits_pixel; // Nb de bits par pixel byte Nb_bits_pixel; // Nb de bits par pixel
} T_GIF_IDB; // Image Descriptor Block } T_GIF_IDB; // Image Descriptor Block
#pragma pack()
typedef struct typedef struct
{ {
@ -2696,7 +2687,6 @@ void Save_GIF(T_IO_Context * context)
//////////////////////////////////// PCX //////////////////////////////////// //////////////////////////////////// PCX ////////////////////////////////////
#pragma pack(1)
typedef struct typedef struct
{ {
byte Manufacturer; // |_ Il font chier ces cons! Ils auraient pu byte Manufacturer; // |_ Il font chier ces cons! Ils auraient pu
@ -2718,7 +2708,6 @@ typedef struct
word Screen_Y; // | l'écran d'origine word Screen_Y; // | l'écran d'origine
byte Filler[54]; // Ca... J'adore! byte Filler[54]; // Ca... J'adore!
} T_PCX_Header; } T_PCX_Header;
#pragma pack()
T_PCX_Header PCX_header; T_PCX_Header PCX_header;

View File

@ -1824,7 +1824,7 @@ int Load_CFG(int reload_all)
if ((Handle=fopen(filename,"rb"))==NULL) if ((Handle=fopen(filename,"rb"))==NULL)
return ERROR_CFG_MISSING; return ERROR_CFG_MISSING;
if ( (file_size<(long)sizeof(cfg_header)) if ( (file_size<7)
|| (!Read_bytes(Handle, &cfg_header.Signature, 3)) || (!Read_bytes(Handle, &cfg_header.Signature, 3))
|| memcmp(cfg_header.Signature,"CFG",3) || memcmp(cfg_header.Signature,"CFG",3)
|| (!Read_byte(Handle, &cfg_header.Version1)) || (!Read_byte(Handle, &cfg_header.Version1))
@ -1865,7 +1865,7 @@ int Load_CFG(int reload_all)
case CHUNK_KEYS: // Touches case CHUNK_KEYS: // Touches
if (reload_all) if (reload_all)
{ {
for (index=0; index<(long)(Chunk.Size/sizeof(cfg_shortcut_info)); index++) for (index=0; index<(long)(Chunk.Size/6); index++)
{ {
if (!Read_word_le(Handle, &cfg_shortcut_info.Number) || if (!Read_word_le(Handle, &cfg_shortcut_info.Number) ||
!Read_word_le(Handle, &cfg_shortcut_info.Key) || !Read_word_le(Handle, &cfg_shortcut_info.Key) ||
@ -1918,7 +1918,7 @@ int Load_CFG(int reload_all)
} }
break; break;
case CHUNK_VIDEO_MODES: // Modes vidéo case CHUNK_VIDEO_MODES: // Modes vidéo
for (index=0; index<(long)(Chunk.Size/sizeof(cfg_video_mode)); index++) for (index=0; index<(long)(Chunk.Size/5); index++)
{ {
if (!Read_byte(Handle, &cfg_video_mode.State) || if (!Read_byte(Handle, &cfg_video_mode.State) ||
!Read_word_le(Handle, &cfg_video_mode.Width) || !Read_word_le(Handle, &cfg_video_mode.Width) ||

View File

@ -226,7 +226,6 @@ void Set_layer(T_IO_Context *context, byte layer);
// ================================================================= // =================================================================
// This is here and not in fileformats.c because the emergency save uses it... // This is here and not in fileformats.c because the emergency save uses it...
#pragma pack(1)
typedef struct typedef struct
{ {
byte Filler1[6]; byte Filler1[6];
@ -235,7 +234,6 @@ typedef struct
byte Filler2[118]; byte Filler2[118];
T_Palette Palette; T_Palette Palette;
} T_IMG_Header; } T_IMG_Header;
#pragma pack()
// Data for 24bit loading // Data for 24bit loading

View File

@ -367,7 +367,8 @@ void Load_PKM(T_IO_Context * context)
Compteur_de_donnees_packees=0; Compteur_de_donnees_packees=0;
Compteur_de_pixels=0; Compteur_de_pixels=0;
Taille_pack=(file_size)-sizeof(T_PKM_Header)-header.Jump; // Header size is 780
Taille_pack=(file_size)-780-header.Jump;
// Boucle de décompression: // Boucle de décompression:
while ( (Compteur_de_pixels<image_size) && (Compteur_de_donnees_packees<Taille_pack) && (!File_error) ) while ( (Compteur_de_pixels<image_size) && (Compteur_de_donnees_packees<Taille_pack) && (!File_error) )
@ -636,7 +637,6 @@ void Save_PKM(T_IO_Context * context)
//////////////////////////////////// CEL //////////////////////////////////// //////////////////////////////////// CEL ////////////////////////////////////
#pragma pack(1)
typedef struct typedef struct
{ {
word Width; // width de l'image word Width; // width de l'image
@ -655,7 +655,6 @@ typedef struct
word Y_offset; // Offset en Y de l'image word Y_offset; // Offset en Y de l'image
byte Filler2[16]; // ??? byte Filler2[16]; // ???
} T_CEL_Header2; } T_CEL_Header2;
#pragma pack()
// -- Tester si un fichier est au format CEL -------------------------------- // -- Tester si un fichier est au format CEL --------------------------------
@ -688,7 +687,7 @@ void Test_CEL(T_IO_Context * context)
// Vu que ce header n'a pas de signature, il va falloir tester la // Vu que ce header n'a pas de signature, il va falloir tester la
// cohérence de la dimension de l'image avec celle du fichier. // cohérence de la dimension de l'image avec celle du fichier.
size=file_size-sizeof(T_CEL_Header1); size=file_size-4;
if ( (!size) || ( (((header1.Width+1)>>1)*header1.Height)!=size ) ) if ( (!size) || ( (((header1.Width+1)>>1)*header1.Height)!=size ) )
{ {
// Tentative de reconnaissance de la signature des nouveaux fichiers // Tentative de reconnaissance de la signature des nouveaux fichiers
@ -973,7 +972,6 @@ void Save_CEL(T_IO_Context * context)
//////////////////////////////////// KCF //////////////////////////////////// //////////////////////////////////// KCF ////////////////////////////////////
#pragma pack(1)
typedef struct typedef struct
{ {
struct struct
@ -985,7 +983,6 @@ typedef struct
} color[16]; } color[16];
} Palette[10]; } Palette[10];
} T_KCF_Header; } T_KCF_Header;
#pragma pack()
// -- Tester si un fichier est au format KCF -------------------------------- // -- Tester si un fichier est au format KCF --------------------------------
@ -993,7 +990,7 @@ void Test_KCF(T_IO_Context * context)
{ {
char filename[MAX_PATH_CHARACTERS]; char filename[MAX_PATH_CHARACTERS];
FILE *file; FILE *file;
T_KCF_Header buffer; T_KCF_Header header1;
T_CEL_Header2 header2; T_CEL_Header2 header2;
int pal_index; int pal_index;
int color_index; int color_index;
@ -1002,13 +999,17 @@ void Test_KCF(T_IO_Context * context)
Get_full_filename(filename, context->File_name, context->File_directory); Get_full_filename(filename, context->File_name, context->File_directory);
if ((file=fopen(filename, "rb"))) if ((file=fopen(filename, "rb")))
{ {
if (File_length_file(file)==sizeof(T_KCF_Header)) if (File_length_file(file)==320)
{ {
Read_bytes(file,&buffer,sizeof(T_KCF_Header)); for (pal_index=0;pal_index<10 && !File_error;pal_index++)
for (color_index=0;color_index<16 && !File_error;color_index++)
if (!Read_byte(file,&header1.Palette[pal_index].color[color_index].Byte1) ||
!Read_byte(file,&header1.Palette[pal_index].color[color_index].Byte2))
File_error=1;
// On vérifie une propriété de la structure de palette: // On vérifie une propriété de la structure de palette:
for (pal_index=0;pal_index<10;pal_index++) for (pal_index=0;pal_index<10;pal_index++)
for (color_index=0;color_index<16;color_index++) for (color_index=0;color_index<16;color_index++)
if ((buffer.Palette[pal_index].color[color_index].Byte2>>4)!=0) if ((header1.Palette[pal_index].color[color_index].Byte2>>4)!=0)
File_error=1; File_error=1;
} }
else else
@ -1048,7 +1049,7 @@ void Load_KCF(T_IO_Context * context)
{ {
char filename[MAX_PATH_CHARACTERS]; char filename[MAX_PATH_CHARACTERS];
FILE *file; FILE *file;
T_KCF_Header buffer; T_KCF_Header header1;
T_CEL_Header2 header2; T_CEL_Header2 header2;
byte bytes[3]; byte bytes[3];
int pal_index; int pal_index;
@ -1062,11 +1063,16 @@ void Load_KCF(T_IO_Context * context)
if ((file=fopen(filename, "rb"))) if ((file=fopen(filename, "rb")))
{ {
file_size=File_length_file(file); file_size=File_length_file(file);
if (file_size==sizeof(T_KCF_Header)) if (file_size==320)
{ {
// Fichier KCF à l'ancien format // Fichier KCF à l'ancien format
for (pal_index=0;pal_index<10 && !File_error;pal_index++)
for (color_index=0;color_index<16 && !File_error;color_index++)
if (!Read_byte(file,&header1.Palette[pal_index].color[color_index].Byte1) ||
!Read_byte(file,&header1.Palette[pal_index].color[color_index].Byte2))
File_error=1;
if (Read_bytes(file,&buffer,sizeof(T_KCF_Header))) if (!File_error)
{ {
// Pre_load(context, ?); // Pas possible... pas d'image... // Pre_load(context, ?); // Pas possible... pas d'image...
@ -1078,9 +1084,9 @@ void Load_KCF(T_IO_Context * context)
for (color_index=0;color_index<16;color_index++) for (color_index=0;color_index<16;color_index++)
{ {
index=16+(pal_index*16)+color_index; index=16+(pal_index*16)+color_index;
context->Palette[index].R=((buffer.Palette[pal_index].color[color_index].Byte1 >> 4) << 4); context->Palette[index].R=((header1.Palette[pal_index].color[color_index].Byte1 >> 4) << 4);
context->Palette[index].B=((buffer.Palette[pal_index].color[color_index].Byte1 & 15) << 4); context->Palette[index].B=((header1.Palette[pal_index].color[color_index].Byte1 & 15) << 4);
context->Palette[index].G=((buffer.Palette[pal_index].color[color_index].Byte2 & 15) << 4); context->Palette[index].G=((header1.Palette[pal_index].color[color_index].Byte2 & 15) << 4);
} }
for (index=0;index<16;index++) for (index=0;index<16;index++)
@ -1167,7 +1173,7 @@ void Save_KCF(T_IO_Context * context)
{ {
char filename[MAX_PATH_CHARACTERS]; char filename[MAX_PATH_CHARACTERS];
FILE *file; FILE *file;
T_KCF_Header buffer; T_KCF_Header header1;
T_CEL_Header2 header2; T_CEL_Header2 header2;
byte bytes[3]; byte bytes[3];
int pal_index; int pal_index;
@ -1195,12 +1201,16 @@ void Save_KCF(T_IO_Context * context)
for (color_index=0;color_index<16;color_index++) for (color_index=0;color_index<16;color_index++)
{ {
index=16+(pal_index*16)+color_index; index=16+(pal_index*16)+color_index;
buffer.Palette[pal_index].color[color_index].Byte1=((context->Palette[index].R>>4)<<4) | (context->Palette[index].B>>4); header1.Palette[pal_index].color[color_index].Byte1=((context->Palette[index].R>>4)<<4) | (context->Palette[index].B>>4);
buffer.Palette[pal_index].color[color_index].Byte2=context->Palette[index].G>>4; header1.Palette[pal_index].color[color_index].Byte2=context->Palette[index].G>>4;
} }
if (! Write_bytes(file,&buffer,sizeof(T_KCF_Header))) // Write all
File_error=1; for (pal_index=0;pal_index<10 && !File_error;pal_index++)
for (color_index=0;color_index<16 && !File_error;color_index++)
if (!Write_byte(file,header1.Palette[pal_index].color[color_index].Byte1) ||
!Write_byte(file,header1.Palette[pal_index].color[color_index].Byte2))
File_error=1;
} }
else else
{ {
@ -2296,13 +2306,13 @@ int Save_C64_window(byte *saveWhat, byte *loadAddr)
Print_in_window(13,18,"Data:",MC_Dark,MC_Light); Print_in_window(13,18,"Data:",MC_Dark,MC_Light);
what=Window_set_dropdown_button(10,28,90,15,70,what_label[*saveWhat],1, 0, 1, LEFT_SIDE,0); what=Window_set_dropdown_button(10,28,90,15,70,what_label[*saveWhat],1, 0, 1, LEFT_SIDE,0);
Window_dropdown_clear_items(what); Window_dropdown_clear_items(what);
for (i=0; i<sizeof(what_label)/sizeof(char *); i++) for (i=0; i<sizeof(what_label)/sizeof(what_label[0]); i++)
Window_dropdown_add_item(what,i,what_label[i]); Window_dropdown_add_item(what,i,what_label[i]);
Print_in_window(113,18,"Address:",MC_Dark,MC_Light); Print_in_window(113,18,"Address:",MC_Dark,MC_Light);
addr=Window_set_dropdown_button(110,28,70,15,70,address_label[*loadAddr/32],1, 0, 1, LEFT_SIDE,0); addr=Window_set_dropdown_button(110,28,70,15,70,address_label[*loadAddr/32],1, 0, 1, LEFT_SIDE,0);
Window_dropdown_clear_items(addr); Window_dropdown_clear_items(addr);
for (i=0; i<sizeof(address_label)/sizeof(char *); i++) for (i=0; i<sizeof(address_label)/sizeof(address_label[0]); i++)
Window_dropdown_add_item(addr,i,address_label[i]); Window_dropdown_add_item(addr,i,address_label[i]);
Update_window_area(0,0,Window_width,Window_height); Update_window_area(0,0,Window_width,Window_height);

View File

@ -262,7 +262,6 @@ typedef struct
byte Mode; ///< Shade mode: Normal, Loop, or No-saturation see ::SHADE_MODES byte Mode; ///< Shade mode: Normal, Loop, or No-saturation see ::SHADE_MODES
} T_Shade; } T_Shade;
#pragma pack(1) // is it useful ?
/// Data for one fullscreen video mode in configuration file. Warning, this one is saved/loaded as binary. /// Data for one fullscreen video mode in configuration file. Warning, this one is saved/loaded as binary.
typedef struct typedef struct
{ {
@ -272,7 +271,7 @@ typedef struct
} T_Config_video_mode; } T_Config_video_mode;
/// Header for gfx2.cfg. Warning, this one is saved/loaded as binary. /// Header for gfx2.cfg
typedef struct typedef struct
{ {
char Signature[3]; ///< Signature for the file format. "CFG". char Signature[3]; ///< Signature for the file format. "CFG".
@ -282,24 +281,23 @@ typedef struct
byte Beta2; ///< Major beta version number (ex: 5) byte Beta2; ///< Major beta version number (ex: 5)
} T_Config_header; } T_Config_header;
#pragma pack()
/// Header for a config chunk in for gfx2.cfg. Warning, this one is saved/loaded as binary. /// Header for a config chunk in for gfx2.cfg
typedef struct typedef struct
{ {
byte Number; ///< Section identfier. Possible values are in enum ::CHUNKS_CFG byte Number; ///< Section identfier. Possible values are in enum ::CHUNKS_CFG
word Size; ///< Size of the configuration block that follows, in bytes. word Size; ///< Size of the configuration block that follows, in bytes.
} T_Config_chunk; } T_Config_chunk;
#pragma pack(1)
/// Configuration for one keyboard shortcut in gfx2.cfg. Warning, this one is saved/loaded as binary. /// Configuration for one keyboard shortcut in gfx2.cfg
typedef struct typedef struct
{ {
word Number; ///< Indicates the shortcut action. This is a number starting from 0, which matches ::T_Key_config.Number word Number; ///< Indicates the shortcut action. This is a number starting from 0, which matches ::T_Key_config.Number
word Key; ///< Keyboard shortcut: SDLK_something, or -1 for none word Key; ///< Keyboard shortcut: SDLK_something, or -1 for none
word Key2; ///< Alternate keyboard shortcut: SDLK_something, or -1 for none word Key2; ///< Alternate keyboard shortcut: SDLK_something, or -1 for none
} T_Config_shortcut_info; } T_Config_shortcut_info;
#pragma pack()
/// This structure holds all the settings saved and loaded as gfx2.ini. /// This structure holds all the settings saved and loaded as gfx2.ini.
typedef struct typedef struct