Older .cfg files in svn were saved incorrectly: the wrong size of chunk #5 (0x0101 instead of 0xE1) made it impossible to re-read the file in gfxcfg. gfxcfg can read and save gfx2.cfg. Upward compatibility is provided: - If new chunk types are added to the format, it only needs a re-compile. Older files can be read and saved. - If new keyboard shortcuts are added (134 currently), the older files can be read and the default shortcut will be used for missing keys. Fixed many endianness cases, hopefully Fixed LBM loading : bug in ASM->C conversion of Couleur_ILBM_line() Broke PCX loading : argh! git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@176 416bcca6-2ee7-4201-b75f-2eb2f807beb1
		
			
				
	
	
		
			119 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			119 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
 | 
						|
// Fonctions de lecture/ecriture fichier, gèrent les systèmes big-endian et
 | 
						|
// little-endian.
 | 
						|
 | 
						|
#include <SDL/SDL_endian.h>
 | 
						|
#include "struct.h"
 | 
						|
 | 
						|
word endian_magic16(word x)
 | 
						|
{
 | 
						|
  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
 | 
						|
    return x;
 | 
						|
  #else
 | 
						|
    return SDL_Swap16(x);
 | 
						|
  #endif
 | 
						|
}
 | 
						|
word endian_magic32(word x)
 | 
						|
{
 | 
						|
  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
 | 
						|
    return x;
 | 
						|
  #else
 | 
						|
    return SDL_Swap32(x);
 | 
						|
  #endif
 | 
						|
}
 | 
						|
 | 
						|
// Lit des octets
 | 
						|
// Renvoie -1 si OK, 0 en cas d'erreur
 | 
						|
int read_bytes(FILE *Fichier, void *Dest, size_t Taille)
 | 
						|
{
 | 
						|
  return fread(Dest, 1, Taille, Fichier) == Taille;
 | 
						|
}
 | 
						|
// Ecrit des octets
 | 
						|
// Renvoie -1 si OK, 0 en cas d'erreur
 | 
						|
int write_bytes(FILE *Fichier, void *Src, size_t Taille)
 | 
						|
{
 | 
						|
  return fwrite(Src, 1, Taille, Fichier) == Taille;
 | 
						|
}
 | 
						|
 | 
						|
// Lit un word (little-endian)
 | 
						|
// Renvoie -1 si OK, 0 en cas d'erreur
 | 
						|
int read_word_le(FILE *Fichier, word *Dest)
 | 
						|
{
 | 
						|
  if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word))
 | 
						|
    return 0;
 | 
						|
  #if SDL_BYTEORDER != SDL_LIL_ENDIAN
 | 
						|
    *Dest = SDL_Swap16(*Dest);
 | 
						|
  #endif
 | 
						|
  return -1;
 | 
						|
}
 | 
						|
// Ecrit un word (little-endian)
 | 
						|
// Renvoie -1 si OK, 0 en cas d'erreur
 | 
						|
int write_word_le(FILE *Fichier, word Mot)
 | 
						|
{
 | 
						|
  #if SDL_BYTEORDER != SDL_LIL_ENDIAN
 | 
						|
    Mot = SDL_Swap16(Mot);
 | 
						|
  #endif
 | 
						|
  return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word);
 | 
						|
}
 | 
						|
// Lit un word (big-endian)
 | 
						|
// Renvoie -1 si OK, 0 en cas d'erreur
 | 
						|
int read_word_be(FILE *Fichier, word *Dest)
 | 
						|
{
 | 
						|
  if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word))
 | 
						|
    return 0;
 | 
						|
  #if SDL_BYTEORDER != SDL_BIG_ENDIAN
 | 
						|
    *Dest = SDL_Swap16(*Dest);
 | 
						|
  #endif
 | 
						|
  return -1;
 | 
						|
}
 | 
						|
// Ecrit un word (big-endian)
 | 
						|
// Renvoie -1 si OK, 0 en cas d'erreur
 | 
						|
int write_word_be(FILE *Fichier, word Mot)
 | 
						|
{
 | 
						|
  #if SDL_BYTEORDER != SDL_BIG_ENDIAN
 | 
						|
    Mot = SDL_Swap16(Mot);
 | 
						|
  #endif
 | 
						|
  return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word);
 | 
						|
}
 | 
						|
// Lit un dword (little-endian)
 | 
						|
// Renvoie -1 si OK, 0 en cas d'erreur
 | 
						|
int read_dword_le(FILE *Fichier, dword *Dest)
 | 
						|
{
 | 
						|
  if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword))
 | 
						|
    return 0;
 | 
						|
  #if SDL_BYTEORDER != SDL_LIL_ENDIAN
 | 
						|
    *Dest = SDL_Swap32(*Dest);
 | 
						|
  #endif
 | 
						|
  return -1;
 | 
						|
}
 | 
						|
// Ecrit un dword (little-endian)
 | 
						|
// Renvoie -1 si OK, 0 en cas d'erreur
 | 
						|
int write_dword_le(FILE *Fichier, dword Mot)
 | 
						|
{
 | 
						|
  #if SDL_BYTEORDER != SDL_LIL_ENDIAN
 | 
						|
    Mot = SDL_Swap32(Mot);
 | 
						|
  #endif
 | 
						|
  return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword);
 | 
						|
}
 | 
						|
 | 
						|
// Lit un dword (big-endian)
 | 
						|
// Renvoie -1 si OK, 0 en cas d'erreur
 | 
						|
int read_dword_be(FILE *Fichier, dword *Dest)
 | 
						|
{
 | 
						|
  if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword))
 | 
						|
    return 0;
 | 
						|
  #if SDL_BYTEORDER != SDL_BIG_ENDIAN
 | 
						|
    *Dest = SDL_Swap32(*Dest);
 | 
						|
  #endif
 | 
						|
  return -1;
 | 
						|
}
 | 
						|
// Ecrit un dword (big-endian)
 | 
						|
// Renvoie -1 si OK, 0 en cas d'erreur
 | 
						|
int write_dword_be(FILE *Fichier, dword Mot)
 | 
						|
{
 | 
						|
  #if SDL_BYTEORDER != SDL_BIG_ENDIAN
 | 
						|
    Mot = SDL_Swap32(Mot);
 | 
						|
  #endif
 | 
						|
  return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword);
 | 
						|
}
 |