/**************************************************************************
<MODULE NAME>
<FILENAME></FILENAME>
<HISTORY>
	<MODIFICATION>
		<DATE></DATE>
		<AUTHOR></AUTHOR>
		<DESCRIPTION>
		</DESCRIPTION>
	</MODIFICATION>
</HISTORY>
</MODULE NAME>
**************************************************************************/

/*******************************************************************/
/* MODULE DE GESTION DU FLASH EPROM                                */
/*          Simulation en m‚moire vive et sauvegarde sur disquette */
/*******************************************************************/

/**************************************************************************
INCLUDE FILE
**************************************************************************/
#include <stdio.h>
#include "..\comp\eeprom\eeprom.h"

#include <conio.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <stdlib.h>
#include <dos.h>
#include <memory.h>
#include <string.h>
#include "defs.h"
#include "lcd.h"
#include "erreur.h"
#include "eprom.h"

/**************************************************************************
LOCAL VARIABLES
Always start with « static »-keyword
**************************************************************************/
CEeprom* CEeprom::m_pcInst = NULL;

/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME>CEeprom</NAME>
	<TYPE> LOCAL  GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</ IO >
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
</METHOD>
**************************************************************************/
CEeprom::CEeprom()
{
	;
}


/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME>~CEeprom</NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO>IN | OUT | INOUT</ IO >
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
</METHOD>
**************************************************************************/
CEeprom::~CEeprom()
{
	;
}
/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME>DestroyInst</NAME>
	<TYPE>GLOBAL</TYPE>
	<DESCRIPTION>Destroy the instance on CEeprom</DESCRIPTION>
</METHOD>
**************************************************************************/
void CEeprom::DestroyInst(void)
{
	if(m_pcInst != NULL)
		delete m_pcInst; 
	m_pcInst=NULL;
}

/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/


/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION>
		 Initialise l'EPROM  
		 Parametre: taille de la memoire utilisee
		 Rend le test sur l'initialisation
	 </DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/

/***********************************************/
/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
boolean EpromWrite(unsigned char Valeur, long Emplacement)
/* 
	 Ecrit une valeur a une adresse de l'EPROM
	 Parametres: valeur a ecrire
		position de l'EPROM a ecrire
	 Rend le test sur l'ecriture            
*/
{
  unsigned char _huge *p;
  unsigned char _huge *q;
  unsigned char val, c, choix;
  int i, PLSCNT, Boucle, status;
  int Compt1, Compt2, Compt_Boucle; 
  
  Compt1 = 0; 
  PLSCNT = 0;
  do
    {
      Compt1++; 
      for (Compt2 = 0; Compt2 < (timing / 10);Compt2--,Compt2++,Compt2++);
    } while ((Eprom_Writed(Emplacement)) && (Compt1 < 20));

	
	if (Compt1 >= 20)
	 {
		Lcd_Affiche(0,0,Message_Point[2]);
		Lcd_Affiche(1,0,Message_Point[5]);
		status = Ram_Eprom_Load();
		if(status)
			Lcd_Affiche(0,0,Message_Point[6]);
		Lcd_Affiche(1,0," ");
		return(false);
	 }
	do
	 {
		p = EPROM_CONTROL;
		*p = 0x40;
		q = EPROM + (long)Emplacement;
		*q = Valeur;
		for (i = 0; i < timing ; i--,i++,i++); /* 2000  ns*/
		*p = 0xC0;
		for (i = 0; i < timing ; i--,i++,i++);
		val = *q;
		PLSCNT++;
	 } while ((val != Valeur) && (PLSCNT < 100));
	
	 p  = EPROM_CONTROL;
	 *p = 0x00;
	 if ((val != Valeur) || (PLSCNT >= 100))
		{ 
		  Lcd_Affiche(0,0,Message_Point[2]);
		  Lcd_Affiche(1,0,Message_Point[5]);
		  Ram_Eprom_Load();
		  if(status)
			 Lcd_Affiche(0,0,Message_Point[6]);
		  Lcd_Affiche(1,0," ");
		  return(false);
		}
  return(true);

} /* Eprom_Write */

/***************************************************************************/
/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
int RamEpromLoad()
/* 
	 Ecrit une valeur a une adresse de l'EPROM
	 Parametres: valeur a ecrire
		position de l'EPROM a ecrire
	 Rend le test sur l'ecriture            
*/
{
 unsigned char _huge *p;
 unsigned char _huge *q;
 unsigned char val[1024], c;
 unsigned long Pos, Emplacement;
 int i, j, PLSCNT, status,boucle;
 FILE *Fichier;  
 
 for(boucle = false; !boucle;)
  {
	 Lcd_Affiche(0,0,Message_Point[8]);
	 Lcd_Affiche(1,0,Message_Point[9]);
	 status =  Eprom_Flash();
	 Wait_Time(2);      
	 if(!status) 
	  {
		 Lcd_Affiche(0,0,Message_Point[2]);
		 Lcd_Affiche(1,0,Message_Point[10]);
		 choix = ' ';
		 while((choix != 'O') && (choix != 'N'))
												choix = Getch(COLOR);
		 if (choix == 'O')
		  { 
			 SUPPORT = 'R';
			 Ram_Disk_Load();                         
			 return(false);    
		  }
		 Lcd_Affiche(1,0," ");
	  }
	else
	 {
	  FEram = open(Chemin_R,O_RDWR | O_BINARY);
	  if (FEram == -1)
		{
		 Lcd_Affiche(0,0,Message_Point[3]);
		 Lcd_Affiche(1,0,Message_Point[7]);
		 Boucle_Erreur();
		}
	  for(Pos = 0;Pos < (long)_EPROM_TAILLE;Pos++)
		  { 
			  read(FEram,val,1024);
			  for(i = 0; i < 1024; i++)
				{
					PLSCNT = 0;
					Emplacement =(long)((long)Pos * 1024L) + (long)i;
					do
					{ 
					  p = EPROM_CONTROL;
					  *p = 0x40;
					  q = EPROM + (long)Emplacement;
					  *q = val[i];
					  for (j = 0; j < (timing / 80) ; j--,j++,j++); /* 25 ns */
					  *p = 0xC0;
					  for (j = 0; j < (timing / 80) ; j--,j++,j++);
					  c = *q;
					  PLSCNT++;
					} while ((val[i] != c) && (PLSCNT < 200));
				  p  = EPROM_CONTROL;
				  *p = 0x00;
				  if (PLSCNT >= 200)
					 { 
						Lcd_Affiche(0,0,Message_Point[11]);
						Lcd_Affiche(1,0,Message_Point[10]);
						choix = ' ';
						while((choix != 'O') && (choix != 'N'))
						choix = Getch(COLOR);
						if (choix == 'O')
						  { 
							close(FEram); 
							SUPPORT = 'R';
							Ram_Disk_Load();   /* */                      
							return(false);    
						  }
						Lcd_Affiche(1,0," ");
					 }
				  else  
					 boucle = true;
				}
		  }
		close(FEram); 
	 }
 } 

/*  EFFACE LE FICHIER SUR DISQUETTE PUISQU'IL EST BIEN CHARGE DANS L'EPROM */ 
 
 Fichier = fopen(Chemin_D,"wb");
 if (Fichier != NULL)  
  {
	  fclose(Fichier);
	  remove(Chemin_D);
  }
 
 return(true);

} /* Ram_Eprom_Load */
/***********************************************/
/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
boolean EpromWrited( long Emplacement)
/*
	Determine si l'emplacement de l'EPROM est occup‚
	Parametre: position de l'EPROM a tester
	Rend le test
*/
{                   
  unsigned char val;
  unsigned char _huge *p;
  unsigned char _huge *q;
  int test;

  p = EPROM_CONTROL;
  q = EPROM + (long)Emplacement;
  *p = 0x00;
  val = *q;
  test = (val != 255);
  return(test);

} /* Eprom_Writed */

/***********************************************/
/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
boolean EpromFlash()
/*
	Rend libre toutes les positions de l'EPROM
	Parametre: sans
	Rend le test sur le 'flashage'
*/
{
  unsigned char _huge *p;
  unsigned char _huge *q;
  unsigned char val;
  unsigned long emplacement;
  unsigned int  i, PLSCNT;
  unsigned long TAILLE_EPROM;
  TAILLE_EPROM = (long)((long)_EPROM_TAILLE * 1024L);
  
 for(emplacement = 0;emplacement < TAILLE_EPROM; emplacement++)
	{ 
	   if((emplacement % 400) == 0)
	     {
		if(GCOLOR ==_ON_GREEN)
			 GCOLOR = _ON_RED;
		else     
			GCOLOR = _ON_GREEN;
		Light_LED(GCOLOR);          
	     }
	  PLSCNT = 0;
	  do
		{ 
		  p = EPROM_CONTROL;
		  *p = 0x40;
		  q = EPROM + (long)emplacement;
		  *q = 0x00;
		  for (i = 0; i < (timing / 80) ; i--,i++,i++); /* 25 ns*/
		  *p = 0xC0;
		  for (i = 0; i < (timing / 80) ; i--,i++,i++);
		  val = *q;
		  PLSCNT++;
		 } while ((val != 0x00) && (PLSCNT < 1000));
		p = EPROM_CONTROL;
	  *p = 0x00;
	  if ((val != 0x00) || (PLSCNT >= 1000))
			return(false);
	}
 
  emplacement = 0;
  PLSCNT = 0;
  do 
	 {
		p = EPROM_CONTROL;
		*p = 0x20;
		for (i = 0; i < (timing / 10); i++, i--, i++); /* 200 ns */
		p = EPROM_CONTROL;
		*p = 0x20;
		for (i = 0; i < (timing / 10); i++, i--, i++);
		do
		  {
			 p = EPROM_CONTROL;
			 *p = 0xA0;
			 for (i = 0; i < (timing / 80); i++, i--, i++); /* 25 ns jj*/
			 q = EPROM + (long)emplacement;
			 val = *q;
			 if(val == 0xFF) emplacement++;
			 if((emplacement % 600) == 0)
				{
				  if(GCOLOR ==_ON_GREEN)
					GCOLOR = _ON_RED;
				  else     
					GCOLOR = _ON_GREEN;
				  Light_LED(GCOLOR);          
				}
		  } while ((val == 0xFF) && (emplacement < TAILLE_EPROM)); 
		PLSCNT++; 
	 } while ((val != 0xFF) && (PLSCNT < 4000));
	 
	 p = EPROM_CONTROL;
	 *p = 0x00;
	 if ((val != 0xFF) || (PLSCNT >= 4000))
			return(false);
	 else
			return(true);

} /* Eprom_Flash */
/***********************************************/
/****************************************************************************/
/*                           GESTION DE LA RAM                              */
/****************************************************************************/

/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
boolean RamRead(unsigned char *Valeur, long Emplacement)
/*
	 Lit la valeur d'une adresse de l'EPROM
	 Parametres: adresse sur valeur a lire
		position de l'EPROM a lire
	 Rend le test sur la lecture
*/
{
  unsigned char val;

  lseek(FEram,Emplacement,0);
  read(FEram,&val,1);
  if (val == 255) val = 0;
  *Valeur = val;
  return(true);
} /* Eprom_Read */

/****************************************************************************/

/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
boolean RamWrite(unsigned char Valeur, long Emplacement)
/*
	 Ecrit une valeur a une adresse de la Ram
	 Parametres: valeur a ecrire
		position de l'EPROM a ecrire
	 Rend le test sur l'ecriture
*/
{

  lseek(FEram,Emplacement,0);
  write(FEram,&Valeur,1);

  return(true);
} /* Eprom_Write */

/****************************************************************************/

/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
boolean RamWrited( long Emplacement)
/*
	Determine si l'emplacement de la Ram est occup‚
	Parametre: position de la Ram a tester
	Rend le test
*/
{                   
  unsigned char val;
  int test;

  lseek(FEram,Emplacement,0);
  read(FEram,&val,1);
  test = (val != 255);
  return(test);

} /* Eprom_Writed */


/****************************************************************************/

/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
int EpromRamLoad()
/*
	Sauve l'EPROM dans la Ram
*/
{
  unsigned char val[1024];
  unsigned char _huge *p;
  unsigned char _huge *q;
  unsigned long pos;
  int i;
  FILE *Fichier;

  Fichier = fopen(Chemin_R,"wb");
  if (Fichier == NULL)
	 {
		 Lcd_Affiche(0,0,Message_Point[3]);
		 Lcd_Affiche(1,0,Message_Point[7]);
		 Boucle_Erreur();
	 }
  fclose(Fichier); 

  FEram = open(Chemin_R, O_RDWR | O_BINARY);
  if (FEram == -1)
	 {
		 Lcd_Affiche(0,0,Message_Point[3]);
		 Lcd_Affiche(1,0,Message_Point[7]);
		 Boucle_Erreur();
	 }
	 
  Lcd_Affiche(0,0,Message_Point[12]);
  Lcd_Affiche(1,0," ");
  for (pos = 0; pos < (long)_EPROM_TAILLE; pos++)
	{
	  for (i = 0; i < 1024; i++)
		 {
			p = EPROM_CONTROL;
			q = EPROM + (long)((long)pos * 1024L) + (long)i;
			*p = 0x00;
			val[i] = *q;
		 }
	  write(FEram,val,i);
	}
 close(FEram);
 return(true);
 
}  /* Backup_Eprom vers ram */

/****************************************************************************/

/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
int DiskRamLoad()
/*
	Sauve le disque dans la Ram
*/
{
  unsigned char val[1024], str[20];
  unsigned long pos;
  int i;
  FILE *Fichier;

  Fichier = fopen(Chemin_R,"wb");
  if (Fichier == NULL)
	 {
		 Lcd_Affiche(0,0,Message_Point[3]);
		 Lcd_Affiche(1,0,Message_Point[7]);
		 Boucle_Erreur();
	 }
  fclose(Fichier);

  FEram = open(Chemin_R, O_RDWR | O_BINARY );
  if (FEram == -1)
	 {
		 Lcd_Affiche(0,0,Message_Point[3]);
		 Lcd_Affiche(1,0,Message_Point[7]);
		 Boucle_Erreur();
	 }
  
  FEdsk = open(Chemin_D, O_RDWR | O_BINARY);
  if (FEdsk == -1)
	 {
		 Lcd_Affiche(0,0,Message_Point[4]);
		 Lcd_Affiche(1,0,Message_Point[7]);
		 Boucle_Erreur();
	 }
	 
  Lcd_Affiche(0,0,Message_Point[12]);
  Lcd_Affiche(1,0," ");
  for (pos = 0; pos < (long)_EPROM_TAILLE; pos++)
	{
	  i = read(FEdsk,val,1024);
	  if(i < 1024)
		  { 
			 Lcd_Affiche(0,0,Message_Point[4]);
			 Lcd_Affiche(1,0,Message_Point[7]);
			 Boucle_Erreur();
		  }
	  write(FEram,val,i);
	}

 close(FEram);
 close(FEdsk);
 return(true);
 
}  /* Backup disk vers  ram */

/****************************************************************************/

/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
int RamDiskLoad()
/*
	Sauve la Ram sur disque
*/
{
  unsigned char val[1024];
  unsigned long pos;
  int i, status, Carry;
  FILE *Fichier;

 status = true;

 while(status) 
       {
	   while((Fichier = fopen(Chemin_D, "wb")) == NULL) 
			Change_Disque(Message_Point[19]);
	   fclose(Fichier);

	   while((FEdsk = open(Chemin_D, O_RDWR | O_BINARY)) == -1) 
			Change_Disque(Message_Point[19]);
  
	   FEram = open(Chemin_R, O_RDWR | O_BINARY);
	   if (FEram == -1)
	     {
		Lcd_Affiche(0,0,Message_Point[3]);
		Lcd_Affiche(1,0,Message_Point[7]);
		Boucle_Erreur();
	     }
	 
	   Lcd_Affiche(1,0,Message_Point[12]);
	   Lcd_Affiche(1,0," ");
	   for (pos = 0; pos < (long)_EPROM_TAILLE; pos++)
	      {
		i = read(FEram,val,1024);
		Carry = write(FEdsk,val,i);
		if(Carry < i)
		  {
		    Change_Disque(Message_Point[19]);
		    status = false;
		    break;
		  }
		else
		  status = false;
	      }
	   close(FEram);
	   close(FEdsk);
       }
return(true);
 
}  /* Backup disk vers  ram */
/****************************************************************************/
/*                           GESTION DU DISK                                */
/****************************************************************************/

/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
boolean DskWrite(unsigned char Valeur, long Emplacement)
/*
	 Ecrit une valeur a une adresse du DISK
	 Parametres: valeur a ecrire
		position de l'EPROM a ecrire
	 Rend le test sur l'ecriture
*/
{
  int status;

  lseek(FEdsk,Emplacement,0);
  status = write(FEdsk,&Valeur,1);

  return(status);

} /* Disk_Write */

/****************************************************************************/
/*                    TRANSFERT DES DONNEES ENTRE SUPPORTS                  */
/****************************************************************************/

/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
int WitchSupport()
/*
	Sur quel support nous allons travailler ?
*/
{
  int status;

  FEdsk = open(Chemin_D, O_RDONLY | O_BINARY);
  if(FEdsk != -1)
	 {
		close(FEdsk);
		status = Test_Ep();
		if(status)
		 {
		    Lcd_Affiche(1,0,Message_Point[13]);
		    Disk_Ram_Load();
		    Ram_Eprom_Load();
		    return(0); 
		 }
		else
		 {
		   Disk_Ram_Load();
		   SUPPORT = 'R';
		   return(0); 
		 }
	 }
	
	Eprom_Ram_Load();
	return(true);
 
}  /* Backup_Eprom vers ram */

/*******************************************************************/

/**************************************************************************
<METHOD>
	<CLASS>CEeprom</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION>
		Descendre les parametres de l'eprom.
	</DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
void DownLoadInd(void)
{
  unsigned char _huge *p;
  unsigned char _huge *q;
  unsigned char val[32];
  unsigned long pos;
  int i, j, status, Carry,ok;

 status = false;

 while(status == false)
	{
		while((FEprom = fopen("a:urne.Ind", "wt")) == NULL) 
		   {  
		     Lcd_Affiche(0,0,Message_Point[3]);
		     Lcd_Affiche(1,0,Message_Point[7]);
		   }
		for (pos =(long)_E_PAR_PLACE,i = 0,ok = true; ok && (i < 31) ; pos++,i++)
		   {
		     p = EPROM_CONTROL;
		     q = EPROM + (long)pos;
		     *p = 0x00;
		     if(*q != 0xFF)
			    val[i] = *q;
		     else
			     ok = false;
		   }
		Carry = fwrite(val,i,1,FEprom);
		if(!Carry)
		   {
		      Lcd_Affiche(0,0,Message_Point[3]);
		      Lcd_Affiche(1,0,Message_Point[7]);
		      while(1);
		    }
		else
		  status = true;
		i++;
	 }
	Carry = fwrite("\n",1,1,FEprom);
	if(!Carry)
	  {
	   Lcd_Affiche(0,0,Message_Point[3]);
	   Lcd_Affiche(1,0,Message_Point[7]);
	   while(1);
	  }
	 fclose(FEprom);
}  
/*******************************************************************/
/*  FIN DU MODULE DE GESTION DU FLASH EPROM                         /
/*******************************************************************/
