//Dimensions de la map du niveau
extern int TABLE_X, TABLE_Y;
#define TABLE_X_MAX 4096
#define TABLE_Y_MAX 1024

//Macros
#define ABS(x)                (((x) > 0) ? (x) : (-(x)))
#define max(x, y)        (((x) > (y)) ? (x) : (y))
#define min(x, y)        (((x) < (y)) ? (x) : (y))

extern int nFrame, nTimer, premFois;
extern unsigned short *EWRAM_DATA indexMap[2][TABLE_Y_MAX + 1];
extern int nLignes;

//extern unsigned char EWRAM_DATA tableauMap[TABLE_Y_MAX][TABLE_X_MAX/8];
extern unsigned short *EWRAM_DATA indexTemp[2][TABLE_Y_MAX + 1];
extern unsigned short EWRAM_DATA indexVal[2][TABLE_Y_MAX + 1];
extern unsigned char EWRAM_DATA sdUsed[2048];

extern EWRAM_DATA OBJATTR MonOAM[128];
extern OBJAFFINE* rotData;
extern PERSO persos[LIMITE_PERSOS + 2] EWRAM_DATA;

extern u16 id_perso[LIMITE_PERSOS + 2] EWRAM_DATA;

#define numberof(o)			(sizeof(o) / sizeof(*(o)))
#define Exec(a, b...) \
        ( \
{ \
        pRoutineLointaine = (void *)(a); pRoutineLointaine(b); \
} \
        )
#define ExecFct(a, b...) \
        ( \
{ \
        pFctLointaine = (void *)(a); pFctLointaine(b); \
} \
        )
extern void (*pRoutineLointaine) ();
extern u32 (*pFctLointaine) ();

//#define LIT_TABLEAU(x,y)  (tableauMap[y][(x)>>3]&(1<<((x)&7)))
//#define SET_TABLEAU(x,y)  (tableauMap[y][(x)>>3]|=(1<<((x)&7)))
//#define CLR_TABLEAU(x,y)  (tableauMap[y][(x)>>3]&=~(1<<((x)&7)))
extern unsigned short EWRAM_DATA PaletteNormale[512], PaletteEau[512];
extern int niveau_reel;
extern int scrlX, scrlY;
extern const LEVEL_INFO *gblLI;

extern void RecreePalettes();
extern int nCurLevel;
extern SONIC EWRAM_DATA copie_sonic;

extern int fadeLength;
extern void HUD_drawInt_Pal31(u32 x, u32 y, u32 chiffres, u32 valeur);
extern void AlphaBlendPalette(unsigned short *dst, const unsigned short *src, u32 taille, u32 couleur, u32 alpha);
extern u16 Pause, gblScore, gblTemps, gblTempsBloque;
extern void NiveauSuivant();
extern void GoldDrawChiffre(u32 x, u32 y, u32 numero);
extern void GoldDrawText(u32 x, u32 y, u32 align, const char *texte);
extern u16 gblGameState;
enum game_states { STATE_INGAME, STATE_FINNIVEAU };

#define TEMPS(m, s) (3600 * (m) + 60 * (s))
extern u32 nbSpritesAvantObjets;
extern int rand();
#define mod32(x, y) modulo(30, x, y)
#define mod16(x, y) modulo(14, x, y)
#define div32(x, y) division(30, x, y)
#define div16(x, y) division(14, x, y)

#define REG_WAITCNT		*(volatile u16 *)0x04000204
