
/*******************************************************************/
/* DEBUT DU MODULE ERREUR.C                                        */
/*******************************************************************/

#include <conio.h>
#include <io.h>
#include <fcntl.h>
#include <dos.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <bios.h>
#include <time.h>
#include "defs.h"
#include "..\LibUrne\LibUrne.h"
#include "erreur.h"

#define IGNORE 0
#define RETRY  1
#define ABORT  2
#define BREAK  3
/*******************************************************************/
extern szMessage *pszMessage_Point;
extern char System_Used[9];
/*******************************************************************/
/*
   <FUNCTION>
		<NAME>Boucle_Erreur</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Error loop</DESCRIPTION>
        <PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO></IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/

void Boucle_Erreur()
{
  Battery_Off();
  while(1);
} /* Boucle_Erreur */

/*******************************************************************/
/*
   <FUNCTION>
		<NAME>Change_Disque</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>
		Display a message to change floppy and return disk number
		</DESCRIPTION>
        <PARAMETER>
			<NAME>pzMessage, bInd</NAME>
			<TYPE>char *, boolean</TYPE>
			<IO>IN,IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE>int</TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
int Change_Disque(char *pzMessage, boolean bInd)
{
  char szTempo[65];
  int iNum;

  if(bInd)
  {
	  if(strcmp(System_Used,"JITES") == 0)
	  {
		Lcd_Affiche(0,0, pzMessage);
		Lcd_Affiche(1,0,pszMessage_Point[14]);
	  }
	  else
	  {
		sprintf(szTempo,"%s %s",pzMessage,pszMessage_Point[14]);
		Video_Affiche(OG,szTempo);
	  }
  }
  else
  {
	 if(strcmp(System_Used,"JITES") == 0)
	 {
		Lcd_Affiche(0,0, pzMessage);
		Lcd_Affiche(1,0, " ");
		Wait_Time(4);
		Lcd_Affiche(0,0, pszMessage_Point[126]);
		Lcd_Affiche(1,0,pszMessage_Point[14]);
	 }
	 else
	 {
		sprintf(szTempo,"%s - %s %s",pzMessage,pszMessage_Point[126],pszMessage_Point[14]);
		Video_Affiche(OG,szTempo);
	 }		
  }
	  
  Getch(COLOR);
  
  iNum = Disk_Num() ;
  while(iNum == 0)
  {
	if(strcmp(System_Used,"JITES") == 0)
	{
		Lcd_Affiche(0,0, pszMessage_Point[122]);
		Lcd_Affiche(1,0, " ");
		Wait_Time(4);
		Lcd_Affiche(0,0, pszMessage_Point[126]);
		Lcd_Affiche(1,0,pszMessage_Point[14]);
	}
	else
	{
		sprintf(szTempo,"%s - %s %s",pszMessage_Point[122],pszMessage_Point[126],pszMessage_Point[14]);
		Video_Affiche(OG,szTempo);
	}	

	Getch(COLOR);
	iNum = Disk_Num() ;
  }

    
  if(strcmp(System_Used,"JITES") == 0)
  {   
	  Lcd_Affiche(0,0,pszMessage_Point[15]);
	  Lcd_Affiche(1,0,pszMessage_Point[16]);
  }
  else
  {
		Video_Affiche(OG," ");
  }

  return iNum;

} /* */

/***********************************************/
/*
   <FUNCTION>
		<NAME>Wait_Time</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Timer defined in second</DESCRIPTION>
        <PARAMETER>
			<NAME>sec</NAME>
			<TYPE>char *</TYPE>
			<IO>IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/

void Wait_Time(int sec)
{
    time_t debut, fin;

    time(&debut);
    time(&fin);
    while (difftime(fin, debut) < sec) time(&fin);

} /* Wait_Time */

/*******************************************************************/
/*
   <FUNCTION>
		<NAME>error_win</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Use in the hardware error handler function</DESCRIPTION>
        <PARAMETER>
			<NAME>numerror</NAME>
			<TYPE>int</TYPE>
			<IO>IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
int error_win(int numerror)
{
 int retval = RETRY;
 /*<< 9.01c*/
 char szTempo[65];
 /*>>*/
 
 while(1)
   {
     switch(numerror)
        {
          case 0 :
               if(strcmp(System_Used,"JITES") == 0)
			   {
				   Lcd_Affiche(0,0,pszMessage_Point[17]);
                   Lcd_Affiche(1,0,pszMessage_Point[14]);
                   Getch(COLOR);
                   Lcd_Affiche(0,0,pszMessage_Point[15]);
                   Lcd_Affiche(1,0,pszMessage_Point[16]);
			   } 
			   /*<< 9.01c*/
			   else
			   {
				   sprintf(szTempo,"%s %s",pszMessage_Point[17],pszMessage_Point[14]);
				   Video_Affiche(OG,szTempo);
				   Getch(COLOR);
				   Video_Affiche(OG,"");
			   }
			   /*>>*/
			   break;

          case 2 :
               if(strcmp(System_Used,"JITES") == 0)
			   {
				   Lcd_Affiche(0,0,pszMessage_Point[18]);
                   Lcd_Affiche(1,0,pszMessage_Point[14]);
                   Getch(COLOR);
                   Lcd_Affiche(0,0,pszMessage_Point[15]);
                   Lcd_Affiche(1,0,pszMessage_Point[16]);
			   }
			   /*<< 9.01c*/
			   else
			   {
				   sprintf(szTempo,"%s %s",pszMessage_Point[18],pszMessage_Point[14]);
				   Video_Affiche(OG,szTempo);
				   Getch(COLOR);
				   Video_Affiche(OG,"");
			   }
			   /*>>*/
			   break;

          default: 
			  retval = BREAK;
        }
      return(retval);
  }
}
/****************************************************************************/
/*
   <FUNCTION>
		<NAME>error_win</NAME>
        <TYPE>LOCAL</TYPE>
		<DESCRIPTION>Hardware error handler function</DESCRIPTION>
        <PARAMETER>
			<NAME>errval, ax, bp, si</NAME>
			<TYPE>int, int, int, int</TYPE>
			<IO>IN,IN,IN,IN</IO>
			<DESCRIPTION></DESCRIPTION>
		</PARAMETER>
		<RETURN>
			<TYPE></TYPE>
			<DESCRIPTION></DESCRIPTION>
		</RETURN>
   </FUNCTION>
*/
#pragma argsused
int handler(int errval, int ax, int bp, int si)
{
	int iErrCode;
	if(ax < 0)
		hardretn(ABORT);
	iErrCode = _DI & 0x00FF;
	hardresume(error_win(iErrCode));
	return ABORT;

}  
/****************************************************************************/

