#include "commun.h"

#define HAUTEUR_MENU        8
#define LARGEUR_MENU        16
u16 gblRepete, ancienRegTouches, TOUCHES, quitte_menu = 0, g_redessineMenu;

//const INFOS_MENU im_menu_start_racine;
s16 gblGamma = 13, gblAdvCamera = 0, gblDebogage = 0, gblRegionPal = 0, gblAntiRame = 2, gblDebogage2 = 1,
        gblTypeHUD = 0;
s16 gblDebugDeplSonic = 0, gblDebugRestart = 0, gblDebugFond = 1;
SONIC *gblSonic;

//s16 gblSonVolume=4, gblSonMusique=1, gblSonBruitages=1;
//Volume 100%: 8
u16 gblSonMusiqueVol = 4, gblSonBruitagesVol = 4, gblSonInterp = 0;

//#define PAS_DEBUG
const void *AdresseBaseMenu;
#define MEM_TOTAL                        6016
#define SPRITE_BASE_BLOCK        580

#define ALDROIT                                126
int txt_langue = 1;
char *textes[][2] =
{
        { "Default", "Defaut" },
        { "On", "Oui" },
        { "Off", "Non" },
        { "Always", "Toujours" },
        { "Moderate", "Modere" },
        { "Never", "Jamais" },
        { "Discrete", "Discret" },
        { "Normal", "Normal" },
        { "Temporal", "Temporel" },
        { "Inaccessible function!!", "Fonction inaccessible!!" },
};
#define TXT(x)        textes[TXT_##x][txt_langue]
enum textes
{
        TXT_DEFAUT                = 0,
        TXT_ON,
        TXT_OFF,
        TXT_TOUJOURS,
        TXT_MODERE,
        TXT_JAMAIS,
        TXT_DISCRET,
        TXT_NORMAL,
        TXT_TEMPORAIRE,
        TXT_INACCESSIBLE
};

void DessOptionDroite(int x, int y, char *str, int selectionne)
{
        char *str2 = str;
        while (*str2)
        {
                x -= txt_tailles[*str2 - 32];
                str2++;
        }

        if (selectionne)
        {
                DrawText(x, y, str, 2);
                DrawText(x + 1, y, str, 2);
        }
        else
                DrawText(x, y, str, 1);
}

void DessOption(int x, int y, char *str, int selectionne)
{
        if (selectionne)
        {
                DrawText(x, y, str, 2);
                DrawText(x + 1, y, str, 2);
        }
        else
                DrawText(x, y, str, 1);
}

void fctMenuStartGeneral(int touches, int message, int selection, int position)
{
        char str[100];
        if (message == 1)
        {
                if (touches == 0)
                {
                        if (txt_langue == 0)
                                DessOptionDroite(ALDROIT, position, "English", touches == selection);
                        else if (txt_langue == 1)
                                DessOptionDroite(ALDROIT, position, "Francais", touches == selection);
                }
        }

        if (message == 0)
        {
                if (touches & KEY_A || touches & KEY_LEFT || touches & KEY_RIGHT)
                {
                        if (selection == 0)
                                txt_langue = 1 - txt_langue;
                }
        }
}

const INFOS_MENU im_menu_start_general_en = { fctMenuStartGeneral, 1, { { "Language", "Modify the language" }, } };

const INFOS_MENU im_menu_start_general_fr = { fctMenuStartGeneral, 1, { { "Langue", "Modifier la langue" }, } };

const INFOS_MENU **im_menu_start_general[] = { &im_menu_start_general_en, &im_menu_start_general_fr, };

void fctMenuStartAffichage(int touches, int message, int selection, int position)
{
        char str[10];
        if (message == 1)
        {
                if (touches == 0)
                {
                        if (gblGamma == 18)
                                DessOptionDroite(ALDROIT, position, "GBA", touches == selection);
                        else if (gblGamma == 15)
                                DessOptionDroite(ALDROIT, position, "GBA SP", touches == selection);
                        else if (gblGamma == 13)
                                DessOptionDroite(ALDROIT, position, TXT(DEFAUT), touches == selection);
                        else if (gblGamma == 12)
                                DessOptionDroite(ALDROIT, position, "DS", touches == selection);
                        else if (gblGamma == 10)
                                DessOptionDroite(ALDROIT, position, "PC/TV", touches == selection);
                }
                else if (touches == 1)
                {
                        sprintf(str, "%i.%i", gblGamma / 10, gblGamma % 10);
                        DessOptionDroite(ALDROIT, position, str, touches == selection);
                }
                else if (touches == 2)
                        DessOptionDroite(ALDROIT, position, gblAdvCamera ? TXT(ON) : TXT(OFF), touches == selection);
                else if (touches == 3)
                {
                        if (gblRegionPal)
                                DessOptionDroite(ALDROIT, position, "PAL", touches == selection);
                        else
                                DessOptionDroite(ALDROIT, position, "NTSC", touches == selection);
                }

                if (touches == 4)
                        DessOptionDroite(ALDROIT, position, gblDebugFond ? TXT(ON) : TXT(OFF), touches == selection);
                else if (touches == 5)
                {
                        if (gblTypeHUD == 0)
                                DessOptionDroite(ALDROIT, position, TXT(NORMAL), touches == selection);
                        else if (gblTypeHUD == 1)
                                DessOptionDroite(ALDROIT, position, TXT(DISCRET), touches == selection);
                        else if (gblTypeHUD == 2)
                                DessOptionDroite(ALDROIT, position, TXT(TEMPORAIRE), touches == selection);
                }
                else if (touches == 6)
                {
                        if (gblAntiRame == 0)
                                DessOptionDroite(ALDROIT, position, TXT(JAMAIS), touches == selection);
                        else if (gblAntiRame == 1)
                                DessOptionDroite(ALDROIT, position, TXT(MODERE), touches == selection);
                        else if (gblAntiRame == 2)
                                DessOptionDroite(ALDROIT, position, TXT(TOUJOURS), touches == selection);
                }
                else if (touches == 7)
                        DessOptionDroite(ALDROIT, position, gblDebogage ? TXT(ON) : TXT(OFF), touches == selection);
        }

        if (message == 0)
        {
                if (touches & KEY_A || touches & KEY_LEFT || touches & KEY_RIGHT)
                {
                        if (selection == 2)
                                gblAdvCamera = !gblAdvCamera;
                        else if (selection == 3)
                                gblRegionPal = !gblRegionPal;
                        else if (selection == 4)
                        {
                                gblDebugFond = !gblDebugFond;
                                if (gblDebugFond)
                                        REG_DISPCNT |= BG1_ENABLE;
                                else
                                        REG_DISPCNT &= ~BG1_ENABLE;
                        }
                        else if (selection == 7)
                                gblDebogage = !gblDebogage;
                }

                if (selection == 5)
                {
                        if (touches & KEY_LEFT)
                                gblTypeHUD--;
                        else if (touches & KEY_RIGHT || touches & KEY_A)
                                gblTypeHUD++;
                        if (gblTypeHUD > 2)
                                gblTypeHUD = 0;
                        if (gblTypeHUD < 0)
                                gblTypeHUD = 2;
                }

                if (selection == 6)
                {
                        if (touches & KEY_LEFT)
                                gblAntiRame--;
                        else if (touches & KEY_RIGHT || touches & KEY_A)
                                gblAntiRame++;
                        if (gblAntiRame > 2)
                                gblAntiRame = 0;
                        if (gblAntiRame < 0)
                                gblAntiRame = 2;
                }

                if (selection == 1)
                {
                        if (touches & KEY_LEFT && gblGamma > 0)
                        {
                                gblGamma--;
                                coeffs = tblGamma[gblGamma];
                                RecreePalettes();
                        }

                        if (touches & KEY_RIGHT && gblGamma < 50)
                        {
                                gblGamma++;
                                coeffs = tblGamma[gblGamma];
                                RecreePalettes();
                        }
                }

                if (selection == 0)
                {
                        if (touches & KEY_LEFT)
                        {
                                if (gblGamma > 18)
                                        gblGamma = 18;
                                else if (gblGamma > 15)
                                        gblGamma = 15;
                                else if (gblGamma > 13)
                                        gblGamma = 13;
                                else if (gblGamma > 12)
                                        gblGamma = 12;
                                else if (gblGamma > 10)
                                        gblGamma = 10;
                                else
                                        gblGamma = 18;
                                coeffs = tblGamma[gblGamma];
                                RecreePalettes();
                        }

                        if (touches & KEY_RIGHT)
                        {
                                if (gblGamma < 10)
                                        gblGamma = 10;
                                else if (gblGamma < 12)
                                        gblGamma = 12;
                                else if (gblGamma < 13)
                                        gblGamma = 13;
                                else if (gblGamma < 15)
                                        gblGamma = 15;
                                else if (gblGamma < 18)
                                        gblGamma = 18;
                                else
                                        gblGamma = 10;
                                coeffs = tblGamma[gblGamma];
                                RecreePalettes();
                        }
                }
        }
}

const INFOS_MENU im_menu_start_affichage_en =
{
        fctMenuStartAffichage,
        8,
        { { "Screen type", "Select your screen in the list" }, { "Brightness", "Modify the gamma" }, { "Fast Camera",
                                "Improves the vision field" }, { "Timing", "Modifies the speed like in old Sonic games" }, {
                                        "Background", "Displays or not the background" }, { "HUD type", "Select the HUD type" }, {
                                                "Anti-rame", "Reduces slowdowns when lagging" }, { "Debug",
                                                        "Displays debuging informations" }, }
};

const INFOS_MENU im_menu_start_affichage_fr =
{
        fctMenuStartAffichage,
        8,
        { { "Type ecran", "Tient compte du type d'ecran" }, { "Luminosite", "Modifie la luminosite" }, { "Camera rapide",
                                "Augmente le champ de vision" }, { "Timing", "Modifie la vitesse comme les anciens Sonic" }, {
                                        "Arriere-plan", "Affiche ou non le fond d'ecran" }, { "Type HUD",
                                                "Selectionnez le type d'indicateur" }, { "Anti-rame",
                                                        "Attenue les ralentissements si le jeu rame" }, { "Debogage",
                                                                "Affiche les infos de debogage" }, }
};

const INFOS_MENU **im_menu_start_affichage[] = { &im_menu_start_affichage_en, &im_menu_start_affichage_fr, };

void fctMenuStartSon(int touches, int message, int selection, int position)
{
        char str[100];
        if (message == 1)
        {
                if (touches == 0)
                {
                        formatString(str, "%02i", gblSonMusiqueVol);
                        DessOptionDroite(ALDROIT, position, str, touches == selection);
                }
                else if (touches == 1)
                {
                        formatString(str, "%02i", gblSonBruitagesVol);
                        DessOptionDroite(ALDROIT, position, str, touches == selection);
                }
                else if (touches == 2)
                        DessOptionDroite(ALDROIT, position, gblSonInterp ? "On" : "Off", touches == selection);
        }

        if (message == 0)
        {
                if (touches & KEY_A || touches & KEY_LEFT || touches & KEY_RIGHT)
                {
                        if (selection == 2)
                                gblSonInterp = !gblSonInterp;
                }

                if (selection == 0)
                {
                        if (touches & KEY_LEFT && gblSonMusiqueVol > 0)
                                gblSonMusiqueVol--;
                        if ((touches & KEY_RIGHT || touches & KEY_A) && gblSonMusiqueVol < 16)
                                gblSonMusiqueVol++;
                }

                if (selection == 1)
                {
                        if (touches & KEY_LEFT && gblSonBruitagesVol > 0)
                                gblSonBruitagesVol--;
                        if ((touches & KEY_RIGHT || touches & KEY_A) && gblSonBruitagesVol < 16)
                                gblSonBruitagesVol++;
                }
        }
}

const INFOS_MENU im_menu_start_son_en =
{
        fctMenuStartSon,
        3,
        { { "Music", "Set the music volume" }, { "Sound effects", "Set the sound FX volume" }, { "Interpolation",
                                "Better quality but less dynamic" }, }
};

const INFOS_MENU im_menu_start_son_fr =
{
        fctMenuStartSon,
        3,
        { { "Musique", "Volume de la musique de fond" }, { "Bruitages", "Volume des bruitages" }, { "Interpolation",
                                "Meilleure qualite mais moins dynamique" }, }
};

const INFOS_MENU **im_menu_start_son[] = { &im_menu_start_son_en, &im_menu_start_son_fr, };

#ifdef PAS_DEBUG
void FonctionInaccessible()
{
        u32 fond = 0x88888888, i;

        //Dessine le message de fond
        txt_adresse = AdresseBaseMenu + 32 * (LARGEUR_MENU * HAUTEUR_MENU);
        txt_hauteur = 2;
        txt_largeur = 30;
        _memset(AdresseBaseMenu + 32 * (LARGEUR_MENU * HAUTEUR_MENU), &fond, 32 * 30 * 2);
        if (gblLI->ei.using_bg3)
                PaletteNormale[0x1e8] = RGB(16, 0, 0);
        else
                PaletteNormale[0xf8] = RGB(16, 0, 0);
        DrawText(0, 0, TXT(INACCESSIBLE), 1);
        DrawText(1, 0, TXT(INACCESSIBLE), 1);
        for (i = 0; i < 60; i++)
                AttendVSync();
        if (gblLI->ei.using_bg3)
                PaletteNormale[0x1e8] = RGB(0, 0, 0);
        else
                PaletteNormale[0xf8] = RGB(0, 0, 0);
}
#endif
void fctMenuStartBeta(int touches, int message, int selection, int position)
{
        int i;
        if (message == 0)
        {
                if (touches & KEY_A)
                {
#ifdef PAS_DEBUG
                        if (selection != 3)
                        {
                                FonctionInaccessible();
                                return;
                        }
#endif
                        quitte_menu = 1;        //Mettre à zéro pour annuler
                        if (selection == 0)
                                gblDebugDeplSonic = 1;
                        else if (selection == 1)
                        {
                                for (i = 0; i < nbrePersos; i++)
                                        LiberePerso(i);
                                SaveState(gblSonic);
                                for (i = 0; i < nbrePersos; i++)
                                        RemetPerso(i);
                        }
                        else if (selection == 2)
                                gblSonic->bagues += 30;
                        else if (selection == 3)
                        {
                                if (gblSonic->dir < 0)
                                        gblSonic->vx = -vMUL(10);
                                else
                                        gblSonic->vx = vMUL(10);
                                Sonic_metEnBoule(gblSonic, 1);
                        }
                        else if (selection == 4)
                        {
                                nCurLevel++;
                                if (nCurLevel >= ExtNbreNiveaux)
                                        nCurLevel -= ExtNbreNiveaux;
                                gblDebugRestart = 1;
                        }

                        if (quitte_menu)
                                while (REG_KEYS & KEY_A);
                }
        }
}

const INFOS_MENU im_menu_start_beta_en =
{
        fctMenuStartBeta,
        5,
        { { "Move Sonic", "Don't release it anywhere!" }, { "Save", "Save the game" }, { "Obtain rings",
                                "Give 30 more rings" }, { "Spindash simulation", "Spindash simulation" }, { "Next level",
                                        "Go to the next level in the list" }, }
};

const INFOS_MENU im_menu_start_beta_fr =
{
        fctMenuStartBeta,
        5,
        { { "Deplacer Sonic", "Ne le mettez pas n'importe ou!" }, { "Sauvegarder", "Sauvegarde la partie" }, {
                                "Obtenir bagues", "Donne 30 bagues supplementaires" }, { "Simulation spindash",
                                        "Donne une grande poussee a Sonic" }, { "Niveau suivant",
                                                "Passe au niveau suivant dans la liste" }, }
};

const INFOS_MENU **im_menu_start_beta[] = { &im_menu_start_beta_en, &im_menu_start_beta_fr, };

void fctMenuStartRacine(int touches, int message, int selection, int position)
{
        if (message == 0)
        {
                if (touches & KEY_A)
                {
                        if (selection == 0)
                        {
                                GestionMenu(&im_menu_start_general);
                        }
                        else if (selection == 1)
                        {
affichage:
                                GestionMenu(&im_menu_start_affichage);
                        }
                        else if (selection == 2)
                        {
                                GestionMenu(&im_menu_start_son);
                        }
                        else if (selection == 3)
                                GestionMenu(&im_menu_start_beta);
                        else if (selection == 4)
                        {
                                gblDebugRestart = 1;
                                quitte_menu = 1;
                        }
                        else if (selection == 5)
                        {
                                gblDebugRestart = 1;
                                sauve_saved = 0;
                                nCurLevel = 0;
                                quitte_menu = 1;
                        }
                }
                else if (touches & KEY_L)
                {
                        goto affichage;
                }
                else if (touches & KEY_R)
                        GestionMenu(&im_menu_start_beta);
        }
}

const INFOS_MENU im_menu_start_racine_en =
{
        fctMenuStartRacine,
        6,
        { { "General options", "Modify general options" }, { "Display options", "Modify display options" }, {
                                "Sound options", "Modify sound options" }, { "Beta debug", "Beta-specific options for testing" }, {
                                        "Give up", "Give up and loose a life" }, { "Quit", "Quit the game" }, }
};

const INFOS_MENU im_menu_start_racine_fr =
{
        fctMenuStartRacine,
        6,
        { { "Options generales", "Modifier les options generales" }, { "Options d'affichage",
                                "Modifier les options d'affichage" }, { "Options sonores", "Modifier les options sonores" }, {
                                        "Debogage Beta", "Options specifiques pour la Beta test" }, { "Abandonner",
                                                "Abandonne et perd une vie" }, { "Quitter", "Quitter le jeu" }, }
};

const INFOS_MENU **im_menu_start_racine[] = { &im_menu_start_racine_en, &im_menu_start_racine_fr, };

void DessineMenu(const INFOS_MENU *im, int selection, int scrolling)
{
        u32 fond = 0x88888888, i;
        CopieDMA((void *) fond_menu_tiles, AdresseBaseMenu, sizeof(fond_menu_tiles) >> 1, DMA_16im);

        //Paramétrage du buffer texte
        txt_adresse = AdresseBaseMenu;
        txt_hauteur = HAUTEUR_MENU;
        txt_largeur = LARGEUR_MENU;

        //Dessin des éléments du menu
        for (i = 0; i < 4; i++)
        {
                if (i + scrolling >= im->nbOptions)
                        break;

                //      gblPosition=14+i*12;
                im->fctGestion(i + scrolling, 1, selection, 14 + i * 12);
                DessOption(5, 14 + i * 12, im->els[i + scrolling].nom, (selection == i + scrolling));
        }

        //Dessine le message de fond
        txt_adresse = AdresseBaseMenu + 32 * (LARGEUR_MENU * HAUTEUR_MENU);
        txt_hauteur = 2;
        txt_largeur = 30;
        _memset(AdresseBaseMenu + 32 * (LARGEUR_MENU * HAUTEUR_MENU), &fond, 32 * 30 * 2);
        DrawText(0, 0, im->els[selection].description, 1);
}

void GestionMenu(const INFOS_MENU **iim)
{
	int selection = 0, repete = 0, scrolling = 0;
	INFOS_MENU *im;
	quitte_menu = 0;

	g_redessineMenu = true;

	while (1)
	{
		im = iim[txt_langue];
		if (!quitte_menu)
		{
			AttendVSync();
			if (g_redessineMenu)
				DessineMenu(im, selection, scrolling);
			g_redessineMenu = false;
		}

		TOUCHES = (REG_KEYS) &~ancienRegTouches;
		ancienRegTouches = REG_KEYS;
		if (TOUCHES)
			repete = 0;                        //Changement de touche -> désactive la répétition pour le moment
		else
			repete++;                        //Aucun changement de touche? Si ça continue, on enclenchera la répétition des touches
		if (repete > 30 && repete % 8 == 0)
			TOUCHES = REG_KEYS & 0x03f0;

		// N'importe quelle de ces touches peut impliquer un changement, alors on redessine le menu
		if (TOUCHES & (KEY_DOWN | KEY_UP | KEY_LEFT | KEY_RIGHT | KEY_A | KEY_B))
			g_redessineMenu = true;

		if (quitte_menu || TOUCHES & KEY_B)
			return;
		if (TOUCHES & KEY_START)
		{
			quitte_menu = 1;
			return;
		}

		if (TOUCHES & KEY_DOWN)
			selection++;
		if (TOUCHES & KEY_UP)
			selection--;
		if (selection < 0)
			selection += im->nbOptions;
		if (selection >= im->nbOptions)
			selection -= im->nbOptions;
		if (im->nbOptions > 4)
		{
			if (selection - scrolling >= 3)
				scrolling = selection - 2;
			if (selection - scrolling <= 0)
				scrolling = selection - 1;
			if (scrolling < 0)
				scrolling = 0;
			if (scrolling + 4 > im->nbOptions)
				scrolling = im->nbOptions - 4;
		}

		if (!quitte_menu)
			im->fctGestion(TOUCHES, 0, selection, 0);

		if (gblTypeHUD == 2)
		{
			int nbObj = objetsUtilises, nbSpr = nSprGba, nbTile = n_tile;
			SPRITE_GBA tmpSprGBA = sprGba[nSprGba];

			//Pour le HUD
			AfficheHUD(gblSonic, 1);
			CopieSprites();
			CopieDMA(MonOAM, OAM, 1024 >> 2, DMA_32im);
			nSprGba = nbSpr;
			objetsUtilises = nbObj;
			n_tile = nbTile;
			sprGba[nSprGba] = tmpSprGBA;
		}
	}
}

void MenuStartSprites(ECRAN *ecr)
{
        u32 fond = 0x88888888, zero = 0;

        //Fait planter si on se trouve 1 écran au-dessus de l'eau
        //   AttendVSync();
        _memset(AdresseBaseMenu, &fond, MEM_TOTAL);
        CopieDMA((void *) fond_menu_tiles, AdresseBaseMenu, sizeof(fond_menu_tiles) >> 1, DMA_16im);

        //   _memset(AdresseBaseMenu,&zero,32);
        int i;
        for (i = 0; i < 128 / 8; i++)
        {
                CreeObjetStandardEx
                (
                        56 + ecr->scrlX + i * 8,
                        48 + ecr->scrlY,
                        1,
                        0,
                        0,
                        0,
                        SPRITE_BASE_BLOCK + i * 8,
                        14,
                        TAILLE_8x32
                );
                CreeObjetStandardEx
                (
                        56 + ecr->scrlX + i * 8,
                        48 + ecr->scrlY + 32,
                        1,
                        0,
                        0,
                        0,
                        SPRITE_BASE_BLOCK + 4 + i * 8,
                        14,
                        TAILLE_8x32
                );
        }

        for (i = 0; i < 30; i++)
        {
                CreeObjetStandardEx
                (
                        ecr->scrlX + i * 8,
                        149 + ecr->scrlY,
                        1,
                        0,
                        0,
                        0,
                        SPRITE_BASE_BLOCK + 16 * 8 + i * 2,
                        14,
                        TAILLE_8x16
                );
        }

        CopieDMA(MonOAM, OAM, 1024 >> 2, DMA_32im);

        //   REG_DISPCNT&=~VIDEO_BG3_ENABLED;
        //Désactivation du BG3
        //   REG_COLEV = (16) + (6 << 8);
        GestionMenu(&im_menu_start_racine);

        //   REG_DISPCNT|=VIDEO_BG3_ENABLED;
        //   REG_COLEV = (16) + (8 << 8);
}

//Ecr pas utilisé!!!
void MenuStartBG3(ECRAN *ecr)
{
        u32 fond = 0x88888888, zero = 0;

        //Fait planter si on se trouve 1 écran au-dessus de l'eau
        //   AttendVSync();
        _memset(AdresseBaseMenu, &fond, MEM_TOTAL);
        CopieDMA((void *) fond_menu_tiles, AdresseBaseMenu, sizeof(fond_menu_tiles) >> 1, DMA_16im);
        _memset(AdresseBaseMenu, &zero, 32);

        _memset((void *)SCREEN_BASE_BLOCK(28), &zero, (256 * 256 * 2) / (8 * 8));
        Texte_init(7, 6, LARGEUR_MENU, HAUTEUR_MENU, (void *)SCREEN_BASE_BLOCK(28), 1);
        Texte_init(0, 19, 30, 2, (void *)SCREEN_BASE_BLOCK(28), LARGEUR_MENU * HAUTEUR_MENU + 1);

        //Active le BG3
        REG_DISPCNT |= BG3_ENABLE;
        REG_BG3VOFS = 3;

        //   REG_COLEV = (16) + (6 << 8);
        GestionMenu(&im_menu_start_racine);
        REG_BG3VOFS = 0;

        //   REG_COLEV = (16) + (8 << 8);
}

void MenuStart(ECRAN *ecr)
{
	if (gblLI->ei.using_bg3)
	{
		AdresseBaseMenu = (void *) (OBJ_BASE_ADR + 32 * SPRITE_BASE_BLOCK);
		MenuStartSprites(ecr);
	}
	else
	{
		AdresseBaseMenu = (void *) CHAR_BASE_BLOCK(3) + 32;
		MenuStartBG3(ecr);
	}
}

void GestionDebug(SONIC *s)
{
        int i, qte;
        if (gblDebugDeplSonic)
        {
                if (REG_KEYS & KEY_B)
                        qte = 15;
                else if (REG_KEYS & KEY_L)
                        qte = 1;
                else
                        qte = 4;
                for (i = 0; i < qte; i++)
                {
                        if (REG_KEYS & KEY_RIGHT)
                                s->x++;
                        if (REG_KEYS & KEY_LEFT)
                                s->x--;
                        if (REG_KEYS & KEY_UP)
                                s->y--;
                        if (REG_KEYS & KEY_DOWN)
                                s->y++;
                }

                s->controle = CNT_SCROLLING;
                if (TOUCHES & KEY_A)
                {
                        gblDebugDeplSonic = 0;
                        gblSonic->saut = 100;
                        gblSonic->croche = 0;
                        ActiveControle(s, CNT_TOUS);
                }
        }
}
