/*******************************************************************/
/* MODULE DE GESTION DU FLASH EPROM                                */
/*          Simulation en mmoire vive et sauvegarde sur disquette */
/*******************************************************************/
#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 <time.h>
#include "defs.h"
#include "eprom.h"
#include "..\LibUrne\LibUrne.h"
/*************************************************************/

#define DataSize 1024

/*************************************************************/
char choix;
/**************************************************************/
extern char JETON_ETENDU[_JETON_ETENDU_MAX_BYTE+1];
extern szMessage *pszMessage_Point;
extern char Chemin_R[25], Chemin_D[25];
extern char System_Used[9];
extern char GCOLOR;
extern int iDiskId;
extern int iMAXDISK;
extern boolean bErrWrite;
extern boolean bErrRead;
extern boolean bErrWrite_Ram; 
extern boolean bErrRead_Ram;
extern boolean bRecount_Mode;
extern boolean bNoSupMode;

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

unsigned char _huge *MEMORY_EPROM;   /* data address  of the eprom in memory  */
unsigned char _huge *EPROM;          /* data address of the eprom  */
unsigned char _huge *EPROM_CONTROL;  /* register address of the eprom control*/
extern long  EPROM_TAILLE;                 /* EPROM size */

FILE *FEprom;

/***********************************************/
/*
   <FUNCTION>
		<NAME>Eprom_Init</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Initialize the eprom</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Eprom_Init(void)
{

  EPROM_TAILLE = (long)(1024L * (long)_EPROM_TAILLE);
  FP_SEG(EPROM_CONTROL) =EPROM_SEG;
  FP_OFF(EPROM_CONTROL) = 0x0;
  FP_SEG(EPROM) = EPROM_SEG;
  FP_OFF(EPROM) = 0x0;
  return(true);
} /* Eprom_Init */

/***********************************************/
/*
   <FUNCTION>
		<NAME>Eprom_Read</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Read the value of an eprom address</DESCRIPTION>
        <PARAMETER>
			<NAME>Valeur, Emplacement</NAME>
			<TYPE>unsigned char *, long</TYPE>
			<IO>INOUT,IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Eprom_Read(unsigned char *Valeur, long Emplacement)
{
  unsigned char _huge *p;
  unsigned char _huge *q;
  unsigned char val;

  if (Emplacement >= EPROM_TAILLE) return(false);
  p = EPROM_CONTROL;
  q = EPROM + (long)Emplacement;
  *p = 0x00;
  val = *q;
  if (val == 255) val = 0;
  *Valeur = val ;

  return(true);
} /* Eprom_Read */

/***********************************************/
/*
   <FUNCTION>
		<NAME>Eprom_Write</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Write a value at an eprom address</DESCRIPTION>
        <PARAMETER>
			<NAME>Valeur, Emplacement</NAME>
			<TYPE>unsigned char, long</TYPE>
			<IO>IN,IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION>On successful return true, on error return false</DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Eprom_Write(unsigned char Valeur, long Emplacement)
{
  unsigned char _huge *p;
  unsigned char _huge *q;
  unsigned char val, c, choix;
  char szMsgError[80], szFileName[12]; 
  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,pszMessage_Point[2]);
		Lcd_Affiche(1,0,pszMessage_Point[5]);
		
		Wait_Time(2);
		if(!bErrWrite_Ram && !bErrRead_Ram)
		  {
			  status = Ram_Eprom_Load();
			  if(status)
				 Lcd_Affiche(0,0,pszMessage_Point[6]);
			  Lcd_Affiche(1,0," ");
		  }
		else 
		  {
			bErrWrite = true;
			Lcd_Affiche(0,0," ");
			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,pszMessage_Point[2]);
		  Lcd_Affiche(1,0,pszMessage_Point[5]);
		  
		  Wait_Time(2);
		  if(!bErrWrite_Ram && !bErrRead_Ram)
		  {
			  status = Ram_Eprom_Load();
			  if(status)
				 Lcd_Affiche(0,0,pszMessage_Point[6]);
			  Lcd_Affiche(1,0," ");
		  }
		  else 
		  {
			bErrWrite = true;
			Lcd_Affiche(0,0," ");
			Lcd_Affiche(1,0," ");
		  }

		  return(false);
	 }
  return(true);

} /* Eprom_Write */

/***************************************************************************/
/*
   <FUNCTION>
		<NAME>Ram_Eprom_Load</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Load the FE_RAM file in the eprom</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>int</TYPE>
			<DESCRIPTION>On successful return true, on error return false</DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
int Ram_Eprom_Load()
{
 unsigned char _huge *p;
 unsigned char _huge *q;
 unsigned char val[DataSize], c;
 unsigned long Pos, Emplacement;
 int i, j, PLSCNT, status,boucle, iRes;
 char szMsgError[80]; 
 
 for(boucle = false; !boucle;)
 {
	 Lcd_Affiche(0,0,pszMessage_Point[8]);
	 Lcd_Affiche(1,0,pszMessage_Point[9]);
	 status =  Eprom_Flash();
	 
	 Wait_Time(2);      
	 if(!status) 
	 {  
		 Lcd_Affiche(0,0,pszMessage_Point[2]);
		 Lcd_Affiche(1,0,pszMessage_Point[10]);
		 choix = ' ';
		 while((choix != 'O') && (choix != 'J') && (choix != 'N'))
			choix = Getch(COLOR);
		 
		 Lcd_Affiche(0,0," ");
		 Lcd_Affiche(1,0," ");
		 
		 if ((choix == 'O') || (choix == 'J'))
		 { 
			 SUPPORT = 'R';
			 Ram_Disk_Load();                         
			 return(false);    
		 }
		 else
		 {
			 SUPPORT = 'N'; /*switch to the mode without recording*/ 
			 bNoSupMode = true;
			 Lcd_Affiche(0,0,pszMessage_Point[60]);
			 Lcd_Affiche(1,0,pszMessage_Point[14]);
			 Getch(COLOR);
			 return(false); 
		 }
	 }
	 else
	 {
	  
		FEram = open(Chemin_R,O_RDWR | O_BINARY);
		if (FEram == -1)
		{
			sprintf(szMsgError,"Error opening file %s in Ram_Eprom_Load function.\nFile source: %s\n", 
								Chemin_R, __FILE__);
			Erreur(szMsgError);
			SUPPORT = 'N'; /*switch to the mode without recording*/ 
			bNoSupMode = true;
			return(false); 
		}
		
		for(Pos = 0;Pos < (long)_EPROM_TAILLE;Pos++)
		{ 
			GCOLOR = _ON_RED;
			Light_LED(GCOLOR); 
			
			iRes = read(FEram,val,DataSize);
			if(iRes == -1 )
			{ 
				sprintf(szMsgError,"Error reading from the file %s in Ram_Disk_Load function.\nFile source: %s\n", 
								Chemin_R, __FILE__);
				Erreur(szMsgError);
				SUPPORT = 'N'; /*switch to the mode without recording*/
				bNoSupMode = true;
				close(FEram);
				GCOLOR = _ON_NO_LED;
				Light_LED(GCOLOR); 
				return(false);  
			}	
			  
			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,pszMessage_Point[11]);
					Lcd_Affiche(1,0,pszMessage_Point[10]);
					choix = ' ';
					while((choix != 'O') && (choix != 'J') && (choix != 'N'))
						choix = Getch(COLOR);

					Lcd_Affiche(0,0," ");
					Lcd_Affiche(1,0," ");

					if ((choix == 'O') || (choix == 'J') )
					{ 
						close(FEram); 
						SUPPORT = 'R';
						Ram_Disk_Load();   
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						return(false);    
					}
					else 
					{
						SUPPORT = 'N'; /*switch to the mode without recording*/ 
						bNoSupMode = true;
						Lcd_Affiche(0,0,pszMessage_Point[60]);
						Lcd_Affiche(1,0,pszMessage_Point[14]);
						Getch(COLOR);
						close(FEram);
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						return(false); 
					}	
					
				}
				else  
					boucle = true;
			}
		}
		close(FEram); 
	 }
 } 
 GCOLOR = _ON_GREEN;
 Light_LED(GCOLOR); 
 
 return(true);

} /* Ram_Eprom_Load */
/******************************************************************************/
/*
   <FUNCTION>
		<NAME>Disk_Eprom_Load</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Load the FE_DSK file in the eprom</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>int</TYPE>
			<DESCRIPTION>On successful return true, on error return false</DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
int	Disk_Eprom_Load()
{
 unsigned char _huge *p;
 unsigned char _huge *q;
 unsigned char val[DataSize], c;
 unsigned long Pos, Emplacement;
 int i, j, PLSCNT, status,boucle, iRes;
 char szMsgError[80]; 
 
 for(boucle = false; !boucle;)
 {
	 Lcd_Affiche(0,0,pszMessage_Point[8]);
	 Lcd_Affiche(1,0,pszMessage_Point[9]);
	 status =  Eprom_Flash();
	 
	 Wait_Time(2);      
	 if(!status) 
	 {  
		 Lcd_Affiche(0,0,pszMessage_Point[2]);
		 Lcd_Affiche(1,0,pszMessage_Point[7]);
		 return(false);
	 }
	 else
	 {
	  
		FEdsk = open(Chemin_D, O_RDONLY | O_BINARY);
		if (FEdsk == -1)
		{
		 	Lcd_Affiche(0,0,pszMessage_Point[4]);
			Lcd_Affiche(1,0,pszMessage_Point[7]);
			sprintf(szMsgError,"Error opening file %s in Disk_Eprom_Load function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
			Erreur(szMsgError);
			return(false); 
		}
		
		for(Pos = 0;Pos < (long)_EPROM_TAILLE;Pos++)
		{ 
			/* Leds */
			GCOLOR = _ON_RED;
			Light_LED(GCOLOR); 
			
			iRes = read(FEdsk,val,DataSize);
			if(iRes == -1)
			{ 
				Lcd_Affiche(0,0,pszMessage_Point[4]);
				Lcd_Affiche(1,0,pszMessage_Point[7]);
				sprintf(szMsgError,"Error reading from the file %s in Disk_Eprom_Load function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
				Erreur(szMsgError);
				close(FEdsk); 
				GCOLOR = _ON_NO_LED;
				Light_LED(GCOLOR); 
				return(false);  
			}	
			  
			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,pszMessage_Point[11]);
					Lcd_Affiche(1,0,pszMessage_Point[7]);
					close(FEdsk); 
					GCOLOR = _ON_NO_LED;
					Light_LED(GCOLOR); 
					return(false); 
				}
				else  
					boucle = true;
			}
		}
		close(FEdsk); 
	 }
 }
 GCOLOR = _ON_GREEN;
 Light_LED(GCOLOR); 
 return(true);

} /* Disk_Eprom_Load */

/******************************************************************************/
/*
   <FUNCTION>
		<NAME>Eprom_Writed</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
			Determine if an eprom address contains a data
		</DESCRIPTION>
        <PARAMETER>
			<NAME>Emplacement</NAME>
			<TYPE>long</TYPE>
			<IO>IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION>return true or false</DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Eprom_Writed( long Emplacement)
{                   
  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 */

/***********************************************/
/*
   <FUNCTION>
		<NAME>Eprom_Flash</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Initialize the eprom</DESCRIPTION>
        <PARAMETER>
			<NAME>Emplacement</NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION>On successful return true, on error return false</DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Eprom_Flash()
{
  unsigned char _huge *p;
  unsigned char _huge *q;
  unsigned char val;
  unsigned long emplacement;
  unsigned int  i, PLSCNT;
  EPROM_TAILLE = (long)((long)_EPROM_TAILLE * 1024L);
 
 for(emplacement = 0;emplacement < EPROM_TAILLE; 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 < EPROM_TAILLE)); 
		PLSCNT++; 
	 } while ((val != 0xFF) && (PLSCNT < 4000));
	 
	 p = EPROM_CONTROL;
	 *p = 0x00;
	 if ((val != 0xFF) || (PLSCNT >= 4000))
			return(false);
	 else
			return(true);

} /* Eprom_Flash */
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Check_EPROM</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
		Check if the EPROM contains other characters than FF except inscription JITES
		</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Check_EPROM()
{
	unsigned char val;
	unsigned char _huge *p;
	unsigned char _huge *q;
	unsigned long lpos;
	int iCpt;

	Lcd_Affiche(0,0,pszMessage_Point[12]);
	Lcd_Affiche(1,0," ");
	for (lpos = 0; lpos < (long)_EPROM_TAILLE; lpos++)
	{
	    GCOLOR = _ON_RED;
		Light_LED(GCOLOR); 

		for (iCpt = 0; iCpt < 1024; iCpt++)
		{
			p = EPROM_CONTROL;
			q = EPROM + (long)((long)lpos * 1024L) + (long)iCpt;
			*p = 0x00;
			val = *q;
			if(lpos==0)
			{
				switch (iCpt)
				{
				case 400:
					if(val != 0x4A)
					{
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						return false;
					}
					break;

				case 401:
					if(val != 0x49)
					{
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						return false;
					}
					break;

				case 402:
					if(val != 0x54)
					{
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						return false;
					}
					break;
				case 403:
					if(val != 0x45)
					{
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						return false;
					}
					break;

				case 404:
					if(val != 0x53)
					{
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						return false;
					}
					break;

				default : 
					if(val != 0xFF)
					{
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						return false;
					}
				}
			}
			else
			{
				if(val != 0xFF)
				{
					GCOLOR = _ON_NO_LED;
					Light_LED(GCOLOR); 
					return false;
				}
			}
		}
	}
	GCOLOR = _ON_GREEN;
	Light_LED(GCOLOR); 
	return true;
}
/****************************************************************************/
/*                           RAM											*/
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Ram_Read</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Read the value of a ram address</DESCRIPTION>
        <PARAMETER>
			<NAME>Valeur, Emplacement</NAME>
			<TYPE>unsigned char *, long</TYPE>
			<IO>INOUT,IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Ram_Read(unsigned char *Valeur, long Emplacement)
{
  unsigned char val;
  int iRes; 

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

/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Ram_Write</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Write a value at a ram address</DESCRIPTION>
        <PARAMETER>
			<NAME>Valeur, Emplacement</NAME>
			<TYPE>unsigned char, long</TYPE>
			<IO>IN,IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Ram_Write(unsigned char Valeur, long Emplacement)
{
	int iRes;
	
	lseek(FEram,Emplacement,0);
	iRes = write(FEram,&Valeur,1);

	return(iRes);
} /* Eprom_Write */

/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Ram_Writed</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
			Determine if a ram address contains a data
		</DESCRIPTION>
        <PARAMETER>
			<NAME>Emplacement</NAME>
			<TYPE>long</TYPE>
			<IO>IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION>return true or false</DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Ram_Writed( long Emplacement)
{                   
  unsigned char val;
  int test, iRes;
  char szMsgError[80];

  lseek(FEram,Emplacement,0);
  iRes = read(FEram,&val,1);
  if(iRes == -1)
  {		
		sprintf(szMsgError,"Error reading from the file %s in Ram_Writed function.\nFile source: %s\n", 
								Chemin_R, __FILE__);
		Erreur(szMsgError);
		SUPPORT = 'N';
		bNoSupMode = true;
  }
  test = (val != 255);
  return(test);

} /* Eprom_Writed */


/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Eprom_Ram_Load</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Load the contents of the eprom in the ram</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
void Eprom_Ram_Load()
{
  unsigned char val[DataSize];
  unsigned char _huge *p;
  unsigned char _huge *q;
  unsigned long lpos;
  int iCpt, iRes;
  char szMsgError[80]; 
  FILE *Fichier;

  Fichier = fopen(Chemin_R,"wb");
  if (Fichier == NULL)
  {
		sprintf(szMsgError,"Error opening file %s in Eprom_Ram_Load function.\nFile source: %s\n", 
								Chemin_R, __FILE__);
		Erreur(szMsgError);
		SUPPORT = 'N'; /*switch to the mode without recording*/
		bNoSupMode = true;
  }
  else
  {
	Lcd_Affiche(0,0,pszMessage_Point[12]);
	Lcd_Affiche(1,0," ");
	for (lpos = 0; lpos < (long)_EPROM_TAILLE; lpos++)
	{
	     /* Leds */
		GCOLOR = _ON_RED;
		Light_LED(GCOLOR); 

		for (iCpt = 0; iCpt < 1024; iCpt++)
		{
			p = EPROM_CONTROL;
			q = EPROM + (long)((long)lpos * 1024L) + (long)iCpt;
			*p = 0x00;
			val[iCpt] = *q;
		}
	  
		iRes = fwrite(val, 1, DataSize, Fichier);
		if(iRes != DataSize)
		{
  			GCOLOR = _ON_NO_LED;
			Light_LED(GCOLOR); 
			sprintf(szMsgError,"Error writing to the file %s in Eprom_Ram_Load function.\nFile source: %s\n", 
								Chemin_R, __FILE__);
			Erreur(szMsgError);
			SUPPORT = 'N'; /*switch to the mode without recording*/
			bNoSupMode = true;
			break;
		}
	}
	fclose(Fichier);
	Lcd_Affiche(0,0," ");
  }
 GCOLOR = _ON_GREEN;
 Light_LED(GCOLOR); 
}  /* */
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Compare_Ram_Eprom</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Compares files FE_RAM and EPROM</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>int</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
int Compare_Ram_Eprom()
{
	unsigned char szBuffRam[DataSize+1], szBuffEPROM[DataSize+1];
	unsigned char _huge *p;
	unsigned char _huge *q;
	unsigned long lpos;
	int iCpt, iRes;
	char szMsgError[80]; 

	FEram = open(Chemin_R, O_RDONLY | O_BINARY);
	if (FEram == -1)
	{
		sprintf(szMsgError,"Error opening file %s in Compare_Ram_Eprom function.\nFile source: %s\n", 
						Chemin_R, __FILE__);
		Erreur(szMsgError);
		return -1;
	}

	
	Lcd_Affiche(0,0,pszMessage_Point[12]);
	Lcd_Affiche(1,0," ");
	for (lpos = 0; lpos < (long)_EPROM_TAILLE; lpos++)
	{
		/* Leds */
		GCOLOR = _ON_RED;
		Light_LED(GCOLOR); 

		iRes = read(FEram,szBuffRam,DataSize);
		if(iRes == -1)
		{ 
			GCOLOR = _ON_NO_LED;
			Light_LED(GCOLOR); 
			sprintf(szMsgError,"Error reading from the file %s in Compare_Ram_Eprom function.\nFile source: %s\n", 
						Chemin_R, __FILE__);
			Erreur(szMsgError);
			close(FEram);
			Lcd_Affiche(0,0," ");
			return -1;
		}

		for (iCpt = 0; iCpt < 1024; iCpt++)
		{
			p = EPROM_CONTROL;
			q = EPROM + (long)((long)lpos * 1024L) + (long)iCpt;
			*p = 0x00;
			szBuffEPROM[iCpt] = *q;
		}

		szBuffRam[DataSize] = '\0';
		szBuffEPROM[DataSize] = '\0';
		if(strcmp(szBuffRam,szBuffEPROM) != 0)
		{
			close(FEram);
			return 1;
		}

	}
	close(FEram);
	Lcd_Affiche(0,0," ");

	return 0;

}
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Backup_Eprom_Disk</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Backup the contents of the eprom in a file </DESCRIPTION>
        <PARAMETER>
			<NAME>pzFileName</NAME>
			<TYPE>char *</TYPE>
			<IO>IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
void Backup_Eprom_Disk(char *pzFileName)
{
  unsigned char val[DataSize];
  unsigned char _huge *p;
  unsigned char _huge *q;
  unsigned long lpos;
  int iCpt, iRes, iStatus, iCount;
  char szMsgError[80], szTempo[21]; 
  FILE *Fichier;

  iStatus = true;
  lpos = 0;
  iCount = 1;

  while(iStatus)
  {
	Fichier = fopen(pzFileName,"wb");
	if (Fichier == NULL)
	{
		sprintf(szMsgError,"Error opening file %s in Backup_Eprom_Disk function.\nFile source: %s\n", 
								pzFileName, __FILE__);
		Erreur(szMsgError);
	}
	else
	{
		Lcd_Affiche(0,0,pszMessage_Point[12]);
		Lcd_Affiche(1,0," ");
		for (lpos = 0; lpos < (long)_EPROM_TAILLE; lpos++)
		{
			/* Leds */
			GCOLOR = _ON_RED;
			Light_LED(GCOLOR); 

			for (iCpt = 0; iCpt < 1024; iCpt++)
			{
				p = EPROM_CONTROL;
				q = EPROM + (long)((long)lpos * 1024L) + (long)iCpt;
				*p = 0x00;
				val[iCpt] = *q;
			}
	  
			iRes = fwrite(val, 1, DataSize, Fichier);
			if(iRes != DataSize)
			{
  				GCOLOR = _ON_NO_LED;
				Light_LED(GCOLOR); 
				sprintf(szMsgError,"Error writing to the file %s in Backup_Eprom_Disk function.\nFile source: %s\n", 
								pzFileName, __FILE__);
				Erreur(szMsgError);
				break;
			}
		}
		fclose(Fichier);
		Lcd_Affiche(0,0," ");
	}
    
	if(lpos < (long)_EPROM_TAILLE) 
	{
		if (iCount < 3)
		{	
			Change_Disque(pszMessage_Point[126],true);
			iCount += 1;
		}
		else
		{
			sprintf(szTempo,pszMessage_Point[34],"EPROM");
			Lcd_Affiche(0,0,szTempo);
			iStatus = false;
		}
	}
	else
		iStatus = false;
  
  }
 GCOLOR = _ON_GREEN;
 Light_LED(GCOLOR); 
}  /* */

/***************************************************************************/
/*
   <FUNCTION>
		<NAME>Disk_Ram_Load</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Load the file FE_DSK in the RAM</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
void Disk_Ram_Load()
{
  unsigned long lpos;
  char szMsgError[80], szMsgTemp[21]; 
  int iRes, iStatus;
  unsigned char val[DataSize];
  FILE *Fichier;
  
  iStatus = true;
 
  Fichier = fopen(Chemin_R,"wb");
  if (Fichier == NULL)
  {
		 sprintf(szMsgError,"Error opening file %s in Disk_Ram_Load function.\nFile source: %s\n", 
								Chemin_R, __FILE__);
		 Erreur(szMsgError);
		 SUPPORT = 'N';
		 bNoSupMode = true;
  }
  else
  {
	 while(iStatus)
	 {
	    FEdsk = open(Chemin_D, O_RDONLY | O_BINARY);
		if (FEdsk == -1)
		{
			/*Check if disk has been replaced*/
			iRes = Disk_Num();
			if (iRes != iDiskId)
			{
				sprintf(szMsgTemp,pszMessage_Point[114],iDiskId);
				Change_Disque(szMsgTemp,true);
			}
			else
			{
				sprintf(szMsgError,"Error opening file %s in Disk_Ram_Load function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
				Erreur(szMsgError);
				/*switch to the mode without recording*/
				SUPPORT = 'N';
				bNoSupMode = true;
				iStatus = false;
			}
		}
		else
			iStatus = false;
	 }

	 if(SUPPORT != 'N')
	 {
		Lcd_Affiche(0,0,pszMessage_Point[12]);
		Lcd_Affiche(1,0," ");
		
		for (lpos = 0; lpos < (long)_EPROM_TAILLE; lpos++)
		{
		    /* Leds */ 
			GCOLOR = _ON_RED;
			Light_LED(GCOLOR);
			
			iRes = read(FEdsk,val,DataSize);
			if(iRes == -1)
			{ 
				GCOLOR = _ON_NO_LED;
				Light_LED(GCOLOR);
				sprintf(szMsgError,"Error reading from the file %s in Disk_Ram_Load function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
				Erreur(szMsgError);
				SUPPORT = 'N';
				bNoSupMode = true;
				break;
			}

			iRes = fwrite(val, 1, DataSize, Fichier);
			if(iRes != DataSize)
			{
  				GCOLOR = _ON_NO_LED;
				Light_LED(GCOLOR); 
				sprintf(szMsgError,"Error writing to the file %s in Disk_Ram_Load function.\nFile source: %s\n", 
								Chemin_R, __FILE__);
				Erreur(szMsgError);
				SUPPORT = 'N';
				bNoSupMode = true;
				break;
			}
		}
		Lcd_Affiche(0,0," ");
		fclose(Fichier);  
		close(FEdsk);
	 }
  }
  GCOLOR = _ON_GREEN;
  Light_LED(GCOLOR); 
}  /*Disk_Ram_Load */

/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Ram_Disk_Load</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Load the file FE_RAM in a file of the floppy </DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
void Ram_Disk_Load()
{
	unsigned char val[DataSize];
	unsigned long lpos;
	int iRes, iStatus, iCount ;
	char szMsgError[80]; 
	FILE *Fichier;
	
	iStatus = true;
	iCount = 1;
	lpos = 0;

	while(iStatus)
	{
		if((Fichier = fopen(Chemin_D, "wb")) == NULL) 
		{
			sprintf(szMsgError,"Error opening file %s in Ram_Disk_Load function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
			Erreur(szMsgError);
		}
		else
		{
			FEram = open(Chemin_R, O_RDWR | O_BINARY);
			if (FEram == -1)
			{
				sprintf(szMsgError,"Error opening file %s in Ram_Disk_Load function.\nFile source: %s\n", 
								Chemin_R, __FILE__);
				Erreur(szMsgError);
				SUPPORT = 'N';
				bNoSupMode = true;
				iStatus = false;
			}
			else
			{
				Lcd_Affiche(0,0,pszMessage_Point[12]);
				Lcd_Affiche(1,0," ");
				for (lpos = 0; lpos < (long)_EPROM_TAILLE; lpos++)
				{
					/* Leds */
					GCOLOR = _ON_RED;
					Light_LED(GCOLOR); 

					iRes = read(FEram,val,DataSize);
					if(iRes == -1)
					{ 
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						sprintf(szMsgError,"Error reading from the file %s in Ram_Disk_Load function.\nFile source: %s\n", 
								Chemin_R, __FILE__);
						Erreur(szMsgError);
						SUPPORT = 'N'; /*switch to the mode without recording*/
						bNoSupMode = true;
						break;
					}	
					else
					{
						iRes = fwrite(val, 1, DataSize, Fichier);
						if(iRes != DataSize)
						{
  							GCOLOR = _ON_NO_LED;
							Light_LED(GCOLOR); 
							sprintf(szMsgError,"Error writing to the file %s in Ram_Disk_Load function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
							Erreur(szMsgError);
							break;
						}
					}
				}
				close(FEram);
				Lcd_Affiche(0,0," ");
			}
			fclose(Fichier);
		}
		
		if((lpos < (long)_EPROM_TAILLE) && (SUPPORT != 'N'))
		{
			if (iCount < iMAXDISK)
			{	
				iRes = iDiskId;
				while(iRes == iDiskId)
				{	
					iRes = Change_Disque(pszMessage_Point[126],true);
				}
				
				iDiskId = iRes; /*get new disk id*/
				iCount += 1;
			}
			else
			{
				/*switch to the mode without recording*/
				SUPPORT = 'N';
				bNoSupMode = true;
				iStatus = false;
			}
		}
		else
			iStatus = false;
	}
	GCOLOR = _ON_GREEN;
	Light_LED(GCOLOR); 
}  /* */
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Compare_Ram_Disk</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Compares files FE_RAM and FE_DSK</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>int</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
int Compare_Ram_Disk()
{
	unsigned char szBuffRam[DataSize+1], szBuffDisk[DataSize+1];
	unsigned long lpos;
	int iRes;
	char szMsgError[80]; 

	FEram = open(Chemin_R, O_RDONLY | O_BINARY);
	if (FEram == -1)
	{
		sprintf(szMsgError,"Error opening file %s in Compare_Ram_Disk function.\nFile source: %s\n", 
						Chemin_R, __FILE__);
		Erreur(szMsgError);
		return -1;
	}

	FEdsk = open(Chemin_D, O_RDONLY | O_BINARY);
	if (FEdsk == -1)
	{
		sprintf(szMsgError,"Error opening file %s in Compare_Ram_Disk function.\nFile source: %s\n", 
						Chemin_D, __FILE__);
		Erreur(szMsgError);
		/* << 9.01b*/
		close(FEram);
		/* >>*/
		return -1;
	}

	Lcd_Affiche(0,0,pszMessage_Point[12]);
	Lcd_Affiche(1,0," ");
	for (lpos = 0; lpos < (long)_EPROM_TAILLE; lpos++)
	{
		/* Leds */
		GCOLOR = _ON_RED;
		Light_LED(GCOLOR); 

		iRes = read(FEram,szBuffRam,DataSize);
		if(iRes == -1)
		{ 
			GCOLOR = _ON_NO_LED;
			Light_LED(GCOLOR); 
			sprintf(szMsgError,"Error reading from the file %s in Compare_Ram_Disk function.\nFile source: %s\n", 
						Chemin_R, __FILE__);
			Erreur(szMsgError);
			close(FEram);
			/* << 9.01b*/
			close(FEdsk);
			/* >> */
			Lcd_Affiche(0,0," ");
			return -1;
		}

		iRes = read(FEdsk,szBuffDisk,DataSize);
		if(iRes == -1)
		{ 
			GCOLOR = _ON_NO_LED;
			Light_LED(GCOLOR); 
			sprintf(szMsgError,"Error reading from the file %s in Compare_Ram_Disk function.\nFile source: %s\n", 
						Chemin_D, __FILE__);
			Erreur(szMsgError);
			/* << 9.01b*/
			close(FEram);
			/* >> */
			close(FEdsk);
			Lcd_Affiche(0,0," ");
			return -1;
		}

		szBuffRam[DataSize] = '\0';
		szBuffDisk[DataSize] = '\0';
		if(strcmp(szBuffRam,szBuffDisk) != 0)
		{
			close(FEram);
			close(FEdsk);
			return 1;
		}

	}
	close(FEram);
	close(FEdsk);
	Lcd_Affiche(0,0," ");

	return 0;

}
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Backup_Ram_Disk</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Backup the contents of the FE_RAM in a file of the floppy</DESCRIPTION>
        <PARAMETER>
			<NAME>pzFileName</NAME>
			<TYPE>char *</TYPE>
			<IO>IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
void Backup_Ram_Disk(char *pzFileName)
{
	unsigned char val[DataSize];
	unsigned long lpos;
	int iRes, iStatus, iCount ;
	char szMsgError[80], szTempo[21]; 
	FILE *Fichier;

	iStatus = true;
	iCount = 1;
	lpos = 0;

	while(iStatus)
	{
		if((Fichier = fopen(pzFileName, "wb")) == NULL) 
		{
			sprintf(szMsgError,"Error opening file %s in Backup_Ram_Disk function.\nFile source: %s\n", 
								pzFileName, __FILE__);
			Erreur(szMsgError);
		}
		else
		{
			FEram = open(Chemin_R, O_RDWR | O_BINARY);
			if (FEram == -1)
			{
				sprintf(szMsgError,"Error opening file %s in Backup_Ram_Disk function.\nFile source: %s\n", 
								Chemin_R, __FILE__);
				Erreur(szMsgError);
				iStatus = false;
			}
			else
			{
				Lcd_Affiche(0,0,pszMessage_Point[12]);
				Lcd_Affiche(1,0," ");
				for (lpos = 0; lpos < (long)_EPROM_TAILLE; lpos++)
				{
					/* Leds */
					GCOLOR = _ON_RED;
					Light_LED(GCOLOR); 

					iRes = read(FEram,val,DataSize);
					if(iRes == -1)
					{ 
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						sprintf(szMsgError,"Error reading from the file %s in Backup_Ram_Disk function.\nFile source: %s\n", 
								Chemin_R, __FILE__);
						Erreur(szMsgError);
						break;
					}	
					else
					{
						iRes = fwrite(val, 1, DataSize, Fichier);
						if(iRes != DataSize)
						{
  							GCOLOR = _ON_NO_LED;
							Light_LED(GCOLOR); 
							sprintf(szMsgError,"Error writing to the file %s in Backup_Ram_Disk function.\nFile source: %s\n", 
								pzFileName, __FILE__);
							Erreur(szMsgError);
							break;
						}
					}
				}
				close(FEram);
				Lcd_Affiche(0,0," ");
			}
			fclose(Fichier);
		}
		
		if(lpos < (long)_EPROM_TAILLE) 
		{
			if (iCount < 3)
			{	
				Change_Disque(pszMessage_Point[126],true);
				iCount += 1;
			}
			else
			{
				sprintf(szTempo,pszMessage_Point[34],"RAM");
				Lcd_Affiche(0,0,szTempo);
				iStatus = false;
			}
		}
		else
			iStatus = false;
	}
	GCOLOR = _ON_GREEN;
	Light_LED(GCOLOR); 
}  /* */
/****************************************************************************/
/*                           DISK                                */
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Disk_Write</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Write a value at a position of the file FE_DSK on the floppy</DESCRIPTION>
        <PARAMETER>
			<NAME>Valeur, Emplacement</NAME>
			<TYPE>unsigned char, long</TYPE>
			<IO>IN,IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Disk_Write(unsigned char Valeur, long Emplacement)
{
  int iRes; 
 
  lseek(FEdsk,Emplacement,0);
  iRes = write(FEdsk,&Valeur,1);

  return(iRes);

} /* Disk_Write */
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Disk_Read</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Read a value from a floppy file</DESCRIPTION>
        <PARAMETER>
			<NAME>Valeur, Emplacement</NAME>
			<TYPE>unsigned char *, long</TYPE>
			<IO>INOUT,IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Disk_Read(unsigned char *Valeur, long Emplacement)
{
  unsigned char val;
  int iRes; 

  lseek(FEdsk,Emplacement,0);
  iRes = read(FEdsk,&val,1);
  if (val == 255) val = 0;
  *Valeur = val;
  return(iRes);
} 
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Check_DISK</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
		Compares if the election date contained in the token of the polling station
		registered in the file FE_DSK corresponding to the election date contained in 
		the token obtained from the file urne.tbl. Check if the file FE_dsk contains other 
		characters than FF when the token don't exists.
		</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Check_DISK()
{
	unsigned char val;
	int iRes, iCpt; 
	char szMsgError[80];
	char tab_Dat_Epr[7];
	char tab_Dat_Dsk[7];
	char Jeton_E[_JETON_ETENDU_MAX_BYTE+1];
	long lpos, Dat_Dsk, Dat_Epr;
	
	 Recupere_E_Var_String(_E_JETON_ETENDU, Jeton_E,_JETON_ETENDU_MAX_BYTE,false);
	 tab_Dat_Epr[0] = Jeton_E[13];   
	 tab_Dat_Epr[1] = Jeton_E[14];   
	 tab_Dat_Epr[2] = Jeton_E[11];   
	 tab_Dat_Epr[3] = Jeton_E[12];   
	 tab_Dat_Epr[4] = Jeton_E[9];   
	 tab_Dat_Epr[5] = Jeton_E[10];   
	 tab_Dat_Epr[6] = 0x00;   
     
	 tab_Dat_Dsk[0] = JETON_ETENDU[13];   
	 tab_Dat_Dsk[1] = JETON_ETENDU[14];   
	 tab_Dat_Dsk[2] = JETON_ETENDU[11];   
	 tab_Dat_Dsk[3] = JETON_ETENDU[12];   
	 tab_Dat_Dsk[4] = JETON_ETENDU[9];   
	 tab_Dat_Dsk[5] = JETON_ETENDU[10];   
	 tab_Dat_Dsk[6] = 0x00;   
	 
	 Dat_Dsk = atol(tab_Dat_Dsk);
	 Dat_Epr = atol(tab_Dat_Epr);
	if(( Dat_Epr < Dat_Dsk ) && ( Dat_Epr > 0))
		return false;

	Recupere_E_Variable(_E_FERMETURE, &FERMETURE, false);
	Recupere_E_Variable(_E_OUVERTURE, &OUVERTURE, false);
	if((strlen(Jeton_E) != 15) || (!FERMETURE && !OUVERTURE))
	{
		FEdsk = open(Chemin_D, O_RDWR | O_BINARY);
		if (FEdsk == -1)
		{
			sprintf(szMsgError,"Error opening file %s in Check_DISK function.\nFile source: %s\n", 
							Chemin_D, __FILE__);
			Erreur(szMsgError);
			return false;
		}
		else
		{
		
			Lcd_Affiche(0,0,pszMessage_Point[12]);
			Lcd_Affiche(1,0," ");
		
			for (lpos = 0; lpos < (long)_EPROM_TAILLE; lpos++)
			{
				 /* Leds */
				GCOLOR = _ON_RED;
				Light_LED(GCOLOR); 

				for (iCpt = 0; iCpt < 1024; iCpt++)
				{
					lseek(FEdsk,iCpt,0);
					iRes = read(FEdsk,&val,1);
					if(iRes == -1)
					{
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						sprintf(szMsgError,"Error reading from the file %s in Check_DISK function.\nFile source: %s\n", 
									Chemin_D, __FILE__);
						Erreur(szMsgError);
						return false;
					}
					else if(val != 0xFF)
					{
						GCOLOR = _ON_NO_LED;
						Light_LED(GCOLOR); 
						return false;
					}
				}
			}
			close(FEdsk);
		}
	}
	GCOLOR = _ON_GREEN;
	Light_LED(GCOLOR); 
	return true;
}

/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Disk_Writed</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
			Determine if a position of the file FE_DSK contains a data
		</DESCRIPTION>
        <PARAMETER>
			<NAME>Emplacement</NAME>
			<TYPE>long</TYPE>
			<IO>IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>boolean</TYPE>
			<DESCRIPTION>return true or false</DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
boolean Disk_Writed( long Emplacement)
{                
  unsigned char ucVal;
  int itest, iRes;
  char szMsgError[80];
  
  lseek(FEdsk,Emplacement,0);
  iRes = read(FEdsk,&ucVal,1);
  if(iRes == -1)
  {		
		sprintf(szMsgError,"Error opening file %s in Ram_Writed function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
		Erreur(szMsgError);
		SUPPORT = 'N';
		bNoSupMode = true;
  }
  itest = (ucVal != 255);
  return(itest);

} /*  */
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Init_Disk</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
			Create the file FE_DSK on the floppy
		</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
void Init_Disk()
{   
	char szMsgError[80], szBuf[DataSize]; 
    FILE *Fichier;
	long lpos;
	int iStatus, iRes, iCount;

    iStatus = true;
	iCount = 1;
	lpos = 0;

	if(access(Chemin_D, 0) == 0)
		remove(Chemin_D);

	while(iStatus)
	{
		if((Fichier = fopen(Chemin_D, "wb")) == NULL) 
		{
			sprintf(szMsgError,"Error opening file %s in Init_Disk function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
			Erreur(szMsgError);
		}
		else
		{
			Lcd_Affiche(0,0,pszMessage_Point[12]);
			Lcd_Affiche(1,0," ");
			
			memset(szBuf, 255, sizeof(szBuf));
			for (lpos = 0; lpos < (long)_EPROM_TAILLE; lpos++)
			{ 
				/* Leds */
				GCOLOR = _ON_RED;
				Light_LED(GCOLOR);

				iRes = fwrite(szBuf, 1, sizeof(szBuf) , Fichier);
				if(iRes != DataSize)
				{ 
					GCOLOR = _ON_NO_LED;
					Light_LED(GCOLOR); 
					sprintf(szMsgError,"Error writing to the file %s in Disk_Ram_Load function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
					Erreur(szMsgError);
					break;
				}
			}
			fclose(Fichier);
			Lcd_Affiche(0,0," ");
		}
	    
		if(lpos < (long)_EPROM_TAILLE) 
		{
			if (iCount < iMAXDISK)
			{	
				iRes = iDiskId;
				while(iRes == iDiskId)
				{
					iRes = Change_Disque(pszMessage_Point[126],true);
				}
				
				iDiskId = iRes; /*get new disk id*/
				iCount += 1;
			}
			else
			{
				/*switch to the mode without recording*/
				SUPPORT = 'N';
				bNoSupMode = true;
				iStatus = false;
			}
		}
		else
			iStatus = false;
	}

	if(SUPPORT == 'N')
	{
		Lcd_Affiche(0,0,pszMessage_Point[60]);
		Lcd_Affiche(1,0,pszMessage_Point[14]);
		Getch(COLOR);
	}

	GCOLOR = _ON_GREEN;
	Light_LED(GCOLOR);
}
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>Switch_Support</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
			Select the recording support
		</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
void Switch_Support()
{
  int status; 
  char choix;
  boolean bl_Indic;
  char Jeton_E[_JETON_ETENDU_MAX_BYTE+1];

  if((access(Chemin_D, 0) == 0) && !bRecount_Mode)
  {
		Lcd_Affiche(1,0,pszMessage_Point[13]);

		if(strcmp(System_Used,"JITES") == 0)
		{
			if(!FERMETURE)
			{
				SUPPORT = 'R';
				Recupere_E_Variable(_E_FERMETURE, &FERMETURE, false);
				if(SUPPORT != 'N')
					bl_Indic = true;
				else
					bl_Indic = false;

				SUPPORT = 'E';
				if(bl_Indic && !FERMETURE)
				{
					status = Test_Ep();
					if(status)
					{
						/*
							For this case, the election date is checked when 
							Test_Eprom() is called in main().
						*/
						Disk_Ram_Load();
						Ram_Eprom_Load();
					}
					else
					{
						Lcd_Affiche(0,0,pszMessage_Point[8]);
						Lcd_Affiche(1,0,pszMessage_Point[9]);
						status = Eprom_Flash();  
						Wait_Time(2);
						if(!status) 
						{  
							Lcd_Affiche(0,0,pszMessage_Point[2]);
							Lcd_Affiche(1,0,pszMessage_Point[10]);
							choix = ' ';
							while((choix != 'O') && (choix != 'J') && (choix != 'N'))
								choix = Getch(COLOR);
				 
							Lcd_Affiche(0,0," ");
							Lcd_Affiche(1,0," ");
				 
							if ((choix == 'O') || (choix == 'J'))
							{ 
								SUPPORT = 'R';
								/* << 9.01b */
								//Disk_Ram_Load();
								status = Check_DISK();
								if(status)
								{
									Disk_Ram_Load();
								}
								else
								{
									Init_Disk();
									Disk_Ram_Load();
								}
								/* >> */
							}
							else 
							{
								Lcd_Affiche(0,0,pszMessage_Point[7]);
								Boucle_Erreur();
							}
						}
						else
						{
							Eprom_Ram_Load();
							Encode_E_Var_String(400L,"JITES", 5);
							if((bErrRead_Ram || bErrWrite_Ram) && (bErrWrite || bErrRead))
							{
								Lcd_Affiche(0,0,pszMessage_Point[7]);
								Boucle_Erreur();
							}
							else if(bErrRead_Ram || bErrWrite_Ram)
								Eprom_Ram_Load();
							
						}
					}
				}

				remove(Chemin_D);
			}
			else
				Eprom_Ram_Load();
		}
		else
		{
			status = Check_DISK();
			if(status)
			{
				Disk_Ram_Load();
			}
			else
			{
				Init_Disk();
				Disk_Ram_Load();
			}
		}
		
  }
  else 
  {   
	  if(access(Chemin_D, 0) == 0)
		  remove(Chemin_D);

	  if(strcmp(System_Used,"JITES") != 0)
	  {
		  Init_Disk();
		  Disk_Ram_Load();
	  }
	  else 
	  {
		  if(bRecount_Mode)
		  {
			Lcd_Affiche(0,0,pszMessage_Point[8]);
			Lcd_Affiche(1,0,pszMessage_Point[9]);
			status = Eprom_Flash();  
			Wait_Time(2);
			if(!status) 
			{  
				Lcd_Affiche(0,0,pszMessage_Point[2]);
				Lcd_Affiche(1,0,pszMessage_Point[10]);
				choix = ' ';
				while((choix != 'O') && (choix != 'J') && (choix != 'N'))
					choix = Getch(COLOR);
	 
				Lcd_Affiche(0,0," ");
				Lcd_Affiche(1,0," ");
	 
				if ((choix == 'O') || (choix == 'J'))
				{ 
					SUPPORT = 'R';
					Disk_Ram_Load();
				}
				else 
				{
					Lcd_Affiche(0,0,pszMessage_Point[7]);
					Boucle_Erreur();
				}
			}
			else
			{
				Eprom_Ram_Load();
				Encode_E_Var_String(400L,"JITES", 5);
				if((bErrRead_Ram || bErrWrite_Ram) && (bErrWrite || bErrRead))
				{
					Lcd_Affiche(0,0,pszMessage_Point[7]);
					Boucle_Erreur();
				}
				else if(bErrRead_Ram || bErrWrite_Ram)
					Eprom_Ram_Load();
				
			}
		  }
		  else
			Eprom_Ram_Load();

	  }
  }
 
}  /* Switch_Support */

/***************************************************************************/
/*
   <FUNCTION>
		<NAME>Read_Vote</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
			Read the temporary file if it exists and compares the contents
			of the vote with that located at the same position in file FE_DSK.
		</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>int</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
int Read_Vote(char *pzVoteContent)
{	
	char szMsgError[80], szBuffer[76], /*<< 9.01c*/szPassword[16]/*>>*/; 
	sRecVote Buffer;
	int iRes, iHandle;
	/*<< 9.01c*/
	unsigned int iVoteSize;

	iVoteSize = C_VOTE_MAX_BYTE + _C_CRC_MAX_BYTE + _C_TEST_MAX_BYTE;
    /*>>*/
	iHandle = open(szCtrlFile, O_RDONLY | O_BINARY);
	if (iHandle == -1)
	{
		sprintf(szMsgError,"Error opening file %s in Read_Vote function.\nFile source %s\n",szCtrlFile, __FILE__);
		Erreur(szMsgError);
		iRes = -1;
	}
	else
	{
		iRes = read(iHandle,&Buffer,sizeof(Buffer));
		if(iRes == -1)
		{
			sprintf(szMsgError,"Error reading from the file %s in Read_Vote function.\nFile source %s\n",szCtrlFile, __FILE__);
			close(iHandle);
			Erreur(szMsgError);
		}
		else
		{
			/*<< 9.01c*/
			Generate_Password(szPassword,Buffer.lpos,false);
			Encrypt_Decrypt(Buffer.szContent,szPassword,iVoteSize);
			/*>>*/
			strcpy(pzVoteContent,Buffer.szContent);
			close(iHandle);

			FEdsk = open(Chemin_D, O_RDWR | O_BINARY);
			if (FEdsk == -1)
			{
				sprintf(szMsgError,"Error opening file %s in Read_Vote function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
				Erreur(szMsgError);
				iRes = -1;
			}
			else
			{
				lseek(FEdsk,Buffer.lpos,0);
				iRes = read(FEdsk,szBuffer,iVoteSize);
				if(iRes == -1)
				{
					sprintf(szMsgError,"Error reading from the file %s in Read_Vote function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
					Erreur(szMsgError);
				}
				else
				{
					/*<< 9.01c*/
					szBuffer[iVoteSize] = 0x00;
					Generate_Password(szPassword,Buffer.lpos,false);
					Encrypt_Decrypt(szBuffer,szPassword,iVoteSize);
					/*>>*/
					if(strcmp(szBuffer,Buffer.szContent) == 0)
						iRes = 1;
					else 
						iRes = 0;
				}
				close(FEdsk);
			}
		
		}
	}

	return iRes;
}
/***************************************************************************/
/*
   <FUNCTION>
		<NAME>Delete_Vote</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
			Remove the vote in the file FE_DSK
		</DESCRIPTION>
        <PARAMETER>
			<NAME>lPos, iSize, iHandle, pzFileName</NAME>
			<TYPE>long, int, int, char *</TYPE>
			<IO>IN,IN,IN,IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>int</TYPE>
			<DESCRIPTION>return true or false</DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
int Delete_Vote(long lPos, int iSize, int iHandle, char *pzFileName)
{
	int iRes, iCpt;
	char cVal, szBuf[75], szMsgError[80];
    
	memset(szBuf, 255, sizeof(szBuf));
	for (iCpt = 0, iRes = 1;(iCpt < iSize) && (iRes == 1); iCpt++)
	{
		lseek(iHandle,lPos++,0);
		cVal = szBuf[iCpt];
		iRes = write(iHandle,&cVal,1);
	}

	if(iRes != 1)
	{
		sprintf(szMsgError,"Error writing to the file %s in Delete_Vote function.\nFile source: %s\n", 
								pzFileName, __FILE__);
		Erreur(szMsgError);
		return false;
	}

	return true;
}

/*******************************************************************/
/*
   <FUNCTION>
		<NAME>Check_vote</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
			Read the temporary file if it exists and compares the content
			of the vote with that located at the same position in file FE_DSK.
			If the content of the vote are identical, the vote is removed on file FE_DSK
		</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO>IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>int</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
/*<< 9.01c*/
/*int Check_vote(char *pzVoteContent)*/
int Check_vote()
/*>>*/
{
	char szMsgError[80], szBuffer[75], /*<< 9.01c*/szPassword[16]/*>>*/; 
	sRecVote Buffer;
	int iRes, iHandle, iReturn;
	boolean bIndic;
	/*<< 9.01c*/
	unsigned int iVoteSize;
	

	iVoteSize = C_VOTE_MAX_BYTE + _C_CRC_MAX_BYTE + _C_TEST_MAX_BYTE;
   /*>>*/
	iHandle = open(szCtrlFile, O_RDONLY | O_BINARY);
	if(iHandle == -1)
	{
		sprintf(szMsgError,"Error opening file %s in Check_vote function.\nFile source %s\n",szCtrlFile, __FILE__);
		Erreur(szMsgError);
		iReturn = -1;
	}
	else
	{
		iRes = read(iHandle,&Buffer,sizeof(Buffer));
		if(iRes == -1)
		{
			sprintf(szMsgError,"Error reading from the file %s in Check_vote function.\nFile source %s\n",szCtrlFile, __FILE__);
			close(iHandle);
			Erreur(szMsgError);
			iReturn = -1;
		}
		else
		{
			close(iHandle);
			/*<< 9.01c*/
			Generate_Password(szPassword,Buffer.lpos,false);
			Encrypt_Decrypt(Buffer.szContent,szPassword,iVoteSize);
			/*if(strcmp(pzVoteContent,Buffer.szContent) == 0)
			{*/
			/*>>*/
			FEram = open(Chemin_R, O_RDWR | O_BINARY);
			if (FEram == -1)
			{
				sprintf(szMsgError,"Error opening file %s in Check_vote function.\nFile source: %s\n", 
							Chemin_R, __FILE__);
				Erreur(szMsgError);
				iReturn = -1;
			}
			else
			{
				lseek(FEram,Buffer.lpos,0);
				/*<< 9.01c*/
				/*iRes = read(FEram,szBuffer,strlen(Buffer.szContent));*/
				iRes = read(FEram,szBuffer,iVoteSize);
				/*>>*/
				if(iRes == -1)
				{
					sprintf(szMsgError,"Error reading from the file %s in Check_vote function.\nFile source: %s\n", 
							Chemin_R, __FILE__);
					Erreur(szMsgError);
					iReturn = -1;
				}
				else
				{
					/*<< 9.01c*/
					/*szBuffer[strlen(Buffer.szContent)] = '\0';*/
					szBuffer[iVoteSize] = 0x00;
					Generate_Password(szPassword,Buffer.lpos,false);
					Encrypt_Decrypt(szBuffer,szPassword,iVoteSize);
					/*>>*/
					if(strcmp(szBuffer,Buffer.szContent) == 0)
					{
						/*<< 9.01c*/
						/*bIndic = Delete_Vote(Buffer.lpos, strlen(Buffer.szContent),FEram,Chemin_R);*/
						bIndic = Delete_Vote(Buffer.lpos, iVoteSize,FEram,Chemin_R);
						/*>>*/
						if(bIndic)
							iReturn = 1;
						else
							iReturn = -1;
					}
					else
						iReturn = 0;
				}
				close(FEram);
			}

			if(iReturn != -1)
			{
				FEdsk = open(Chemin_D, O_RDWR | O_BINARY);
				if (FEdsk == -1)
				{
					sprintf(szMsgError,"Error opening file %s in Check_vote function.\nFile source: %s\n", 
									Chemin_D, __FILE__);
					Erreur(szMsgError);
					iReturn = -2;
				}
				else
				{
					lseek(FEdsk,Buffer.lpos,0);
					/*<< 9.01c*/
					/*iRes = read(FEdsk,szBuffer,strlen(Buffer.szContent));*/
					iRes = read(FEdsk,szBuffer,iVoteSize);
					/*>>*/
					if(iRes == -1)
					{
						sprintf(szMsgError,"Error reading from the file %s in Check_vote function.\nFile source: %s\n", 
									Chemin_D, __FILE__);
						Erreur(szMsgError);
						iReturn = -2;
					}
					else
					{
						/*<< 9.01c*/
						/*szBuffer[strlen(Buffer.szContent)] = '\0';*/
						szBuffer[iVoteSize] = 0x00;
						Generate_Password(szPassword,Buffer.lpos,false);
						Encrypt_Decrypt(szBuffer,szPassword,iVoteSize);
						/*>>*/
						if(strcmp(szBuffer,Buffer.szContent) == 0)
						{
							/*<< 9.01c*/
							/*bIndic = Delete_Vote(Buffer.lpos, strlen(Buffer.szContent),FEdsk,Chemin_D);*/
							bIndic = Delete_Vote(Buffer.lpos, iVoteSize,FEdsk,Chemin_D);
							/*>>*/
							if(bIndic)
								iReturn = 2;
							else
								iReturn = -2;
						}
						
					}
					close(FEdsk);
				}
			}
		
		}
	}

	return iReturn;
}
/***************************************************************************/
/*
   <FUNCTION>
		<NAME>Cancel_Vote</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
			Read the temporary file if it exists and compares the contents
			of the vote with that located at the same position in file FE_DSK.
			If the contents of the vote are identical, the vote is removed on file FE_DSK
		</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>int</TYPE>
			<DESCRIPTION>return true or false</DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
int Cancel_Vote()
{	
	char szMsgError[80], szBuffer[75], /*<< 9.01c*/szPassword[16]/*>>*/;
	sRecVote Buffer;
	int iRes, iHandle;
	boolean bIndic = true;
	/*<< 9.01c*/
	unsigned int iVoteSize;

	iVoteSize = C_VOTE_MAX_BYTE + _C_CRC_MAX_BYTE + _C_TEST_MAX_BYTE;
	/*>>*/
   
	iHandle = open(szCtrlFile, O_RDONLY | O_BINARY);
	if (iHandle == -1)
	{
		sprintf(szMsgError,"Error opening file %s in Cancel_Vote function.\nFile source %s\n",szCtrlFile, __FILE__);
		Erreur(szMsgError);
		bIndic = false;
	}
	else
	{
		iRes = read(iHandle,&Buffer,sizeof(Buffer));
		if(iRes == -1)
		{
			sprintf(szMsgError,"Error reading from the file %s in Cancel_Vote function.\nFile source %s\n",szCtrlFile, __FILE__);
			close(iHandle);
			Erreur(szMsgError);
			bIndic = false;
		}
		else
		{
			close(iHandle);
			/*<< 9.01c*/
			Generate_Password(szPassword,Buffer.lpos,false);
			Encrypt_Decrypt(Buffer.szContent,szPassword,iVoteSize);
			/*>>*/
			FEdsk = open(Chemin_D, O_RDWR | O_BINARY);
			if (FEdsk == -1)
			{
				sprintf(szMsgError,"Error opening file %s in Cancel_Vote function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
				Erreur(szMsgError);
				bIndic = false;
			}
			else
			{
				lseek(FEdsk,Buffer.lpos,0);
				/*<< 9.01c*/
				/*iRes = read(FEdsk,szBuffer,strlen(Buffer.szContent));*/
				iRes = read(FEdsk,szBuffer,iVoteSize);
				/*>>*/
				if(iRes == -1)
				{
					sprintf(szMsgError,"Error reading from the file %s in Cancel_Vote function.\nFile source: %s\n", 
								Chemin_D, __FILE__);
					Erreur(szMsgError);
					bIndic = false;
				}
				else
				{
					/*<< 9.01c*/
					/*szBuffer[strlen(Buffer.szContent)] = '\0';*/
					szBuffer[iVoteSize] = 0x00;
					Generate_Password(szPassword,Buffer.lpos,false);
					Encrypt_Decrypt(szBuffer,szPassword,iVoteSize);
					/*>>*/
					if(strcmp(szBuffer,Buffer.szContent) == 0)
					{
						/*<< 9.01c*/
						/*bIndic = Delete_Vote(Buffer.lpos, strlen(Buffer.szContent),FEdsk,Chemin_D);*/
						bIndic = Delete_Vote(Buffer.lpos, iVoteSize,FEdsk,Chemin_D);
						/*>>*/
					}
				}
				close(FEdsk);
			}
		
		}
	}

	return bIndic;
}
/******************************************************************/
/*
   <FUNCTION>
		<NAME>Down_Load_Ind</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
		Download file urne.ind from EPROM ou RAM and save it in the floppy
		</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
void Down_Load_Ind()
{
  unsigned char _huge *p, ucar;
  unsigned char _huge *q;
  unsigned char val[32];
  unsigned long pos;
  char szMsgError[80], szFileName[11]; 
  int i, j, status, Carry,ok, iRes;

	 status = false;
	 iRes = 0;
	 strcpy(szFileName,"a:urne.Ind");

	 while(!status)
	 {
		while((FEprom = fopen(szFileName, "wt")) == NULL) 
		   {  
		     Lcd_Affiche(0,0,pszMessage_Point[4]);
		     Lcd_Affiche(1,0,pszMessage_Point[7]);
			 sprintf(szMsgError,"Error opening file %s in Down_Load_Ind function\n",szFileName);
			 Erreur(szMsgError);
		   }

		if(SUPPORT == 'E')
		{
			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;
			   }
			val[i] = '\0';
			Carry = fwrite(val,i,1,FEprom);
		}

		if(SUPPORT == 'R')
		{
			  FEram = open(Chemin_R, O_RDWR | O_BINARY);
			  if (FEram == -1)
			  {
				Lcd_Affiche(0,0,pszMessage_Point[3]);
				Lcd_Affiche(1,0,pszMessage_Point[7]);
				sprintf(szMsgError,"Error opening file %s in Down_Load_Ind function.\nFile source: %s\n", 
										Chemin_R, __FILE__);
				Erreur(szMsgError);
				iRes = -1;
				status = true;
			  }
			  else
			  {
				 for (pos =(long)_E_PAR_PLACE,i = 0,ok = true; ok && (i < 31) ; pos++,i++)
				   {
					 lseek(FEram,pos,0);
					 iRes = read(FEram,&ucar,1);
					 if(iRes == -1)
					 {
						Lcd_Affiche(0,0,pszMessage_Point[3]);
						Lcd_Affiche(1,0,pszMessage_Point[7]);
						sprintf(szMsgError,"Error reading from the file %s in Down_Load_Ind function.\nFile source: %s\n", 
										Chemin_R, __FILE__);
						Erreur(szMsgError);
						status = true;
						break;
					 }
					 else
					 {
						 if(ucar != 0xFF)
							val[i] = ucar;
						 else
							 ok = false;
					 }
				   }
				 close(FEram);
	
				 if(iRes != -1)
				 {
					 val[i] = '\0';
					 Carry = fwrite(val,i,1,FEprom);
				 }
			  }
		}

		if((Carry != 1) && (iRes != -1))
		{
		  Lcd_Affiche(0,0,pszMessage_Point[4]);
		  Lcd_Affiche(1,0,pszMessage_Point[7]);
		  sprintf(szMsgError,"Error writing to the file %s in Down_Load_Ind function\n",szFileName);
		  Erreur(szMsgError);
		}
		else
		  status = true;
	}
	
	Carry = fwrite("\n",1,1,FEprom);
	if((Carry != 1) && (iRes != -1))
	  {
	   Lcd_Affiche(0,0,pszMessage_Point[4]);
	   Lcd_Affiche(1,0,pszMessage_Point[7]);
	   sprintf(szMsgError,"Error writing to the file %s in Down_Load_Ind function\n",szFileName);
	   Erreur(szMsgError);
	  }
	 fclose(FEprom);
}  




/*******************************************************************/
/*					END OF THE MODULE EPROM.C                      */
/*******************************************************************/
