#include "SaiCPA.h"
#include "MmgSai.h"
#include "ErmSai.h"
#include "Sai_Enum.h"
#include "Sai_str.h"
#include "Sai_Pub.h"
#include "Sai_Priv.h"
#include "Sai_Save.h"
 
/**************************************************************************/
#ifndef U64 /* Oliv' - 07/07/1999 */
unsigned char SAI_fn_bInsertBoolInTable(void *_p_vValue, unsigned char ucMask, SAI_tdeFlags _eFlags)
{
#if defined(U64)
	/* write a short in SAI, with :*/
	/* high part (1 octet) == the mask (1,2,4 or 8 but not higher, because only 2 bits are available to save mask)*/
	/* low part (1 octet) == the octet that contains the bit, at its right position, and not masked*/
	unsigned short usValue;
	assert(ucMask <= 8);
	usValue = ucMask;
	usValue <<= 8;
	usValue |= ((*((unsigned char*)_p_vValue))&0xff);
	return(SAI_fn_bInsertAnElementInList(&SAI_g_stInternalStructure,_p_vValue,2,SAI_eType1,_eFlags));
#else
	return(SAI_fn_bInsertAnElementInList(&SAI_g_stInternalStructure,_p_vValue,ucMask,SAI_eType1,_eFlags));
#endif
}
#endif /* U64 */
/**************************************************************************/
unsigned char SAI_fn_bInsertCharInTable(void *_p_vValue, SAI_tdeFlags _eFlags)
{
 return(SAI_fn_bInsertAnElementInList(&SAI_g_stInternalStructure,_p_vValue,1,SAI_eType8,_eFlags));
}
/**************************************************************************/
unsigned char SAI_fn_bInsertShortInTable(void *_p_vValue, SAI_tdeFlags _eFlags)
{
 return(SAI_fn_bInsertAnElementInList(&SAI_g_stInternalStructure,_p_vValue,2,SAI_eType16,_eFlags));
}
/**************************************************************************/
unsigned char SAI_fn_bInsertLongInTable(void *_p_vValue, SAI_tdeFlags _eFlags)
{
 return(SAI_fn_bInsertAnElementInList(&SAI_g_stInternalStructure,_p_vValue,4,SAI_eType32,_eFlags));
}
/**************************************************************************/
unsigned char SAI_fn_bInsertFloatInTable(void *_p_vValue, SAI_tdeFlags _eFlags)
{
 return(SAI_fn_bInsertAnElementInList(&SAI_g_stInternalStructure,_p_vValue,4,SAI_eType32,_eFlags));
}
/**************************************************************************/
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
unsigned char SAI_fn_bInsertDoubleInTable(void *_p_vValue, SAI_tdeFlags _eFlags)
{
 return(SAI_fn_bInsertAnElementInList(&SAI_g_stInternalStructure,_p_vValue,8,SAI_eType64,_eFlags));
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
/**************************************************************************/
unsigned char SAI_fn_bInsertPointerInTable(void *_p_vValue, SAI_tdeFlags _eFlags)
{
 return(SAI_fn_bInsertAnElementInList(&SAI_g_stInternalStructure,_p_vValue,8,SAI_eTypePointer,_eFlags));
}
/**************************************************************************/
unsigned char SAI_fn_bInsertMTHRealInTable(void *_p_vValue, SAI_tdeFlags _eFlags)
{
 #if defined(MTH_RealIsFloat)
 return(SAI_fn_bInsertFloatInTable(_p_vValue,_eFlags));
 #elif defined(MTH_RealIsDouble)
 return(SAI_fn_bInsertDoubleInTable(_p_vValue,_eFlags));
 #elif defined(MTH_RealIsFixed16_16)
 return(SAI_fn_bInsertLongInTable(_p_vValue,_eFlags));
 #else
 #error Unknown MTH_tdxReal define
 #endif
}
/**************************************************************************/
unsigned char SAI_fn_bInsertMTHVectorInTable(void *_p_vValue, SAI_tdeFlags _eFlags)
{
 #if defined(MTH_RealIsFloat)
 return(SAI_fn_bInsertArrayInTable(_p_vValue,3*4,_eFlags));
 #elif defined(MTH_RealIsDouble)
 return(SAI_fn_bInsertArrayInTable(_p_vValue,3*8,_eFlags));
 #elif defined(MTH_RealIsFixed16_16)
 return(SAI_fn_bInsertArrayInTable(_p_vValue,3*8,_eFlags));
 #else
 #error Unknown MTH_tdxReal define
 #endif
}
/**************************************************************************/
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
unsigned char SAI_fn_bInsertMTHMatrixInTable(void *_p_vValue, SAI_tdeFlags _eFlags)
{
 #if defined(MTH_RealIsFloat)
 return(SAI_fn_bInsertArrayInTable(_p_vValue,9*4,_eFlags));
 #elif defined(MTH_RealIsDouble)
 return(SAI_fn_bInsertArrayInTable(_p_vValue,9*8,_eFlags));
 #elif defined(MTH_RealIsFixed16_16)
 return(SAI_fn_bInsertArrayInTable(_p_vValue,9*8,_eFlags));
 #else
 #error Unknown MTH_tdxReal define
 #endif
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
/**************************************************************************/
unsigned char SAI_fn_bRemoveValueFromTable(void *_p_vValue, SAI_tdeFlags _eFlags)
{
 return(SAI_fn_bFreeAnElementFromList(&SAI_g_stInternalStructure,_p_vValue,_eFlags));
}
/**************************************************************************/
void *SAI_fn_p_vGetTableValuePointerOf(void *_p_vValue, SAI_tdeFlags _eFlags)
{
 void *p_vReturn = NULL;
 SAI_tdxHandleToListEntry hListEntry;
 SAI_tdeFlags eIntarnalFlags;
 
 eIntarnalFlags=SAI_fn_eVerifyFlags(_eFlags);
 if ((hListEntry=fn_hSearchAnElementInList(&SAI_g_stInternalStructure,_p_vValue,eIntarnalFlags))!=NULL)
 {
  switch(hListEntry->eFlags&C_TypesFlags)
  {
#ifndef U64 /* Oliv' - 07/07/1999 */
   case SAI_eType1:
#endif /* U64 */
   case SAI_eType8:
    p_vReturn = (void *)&hListEntry->uData.ucCharData;
    break;
   case SAI_eType16:
    p_vReturn = (void *)&hListEntry->uData.uwShortData;
    break;
   case SAI_eType32:
    p_vReturn = (void *)&hListEntry->uData.ulLongData;
    break;
   case SAI_eType64:
    p_vReturn = (void *)&hListEntry->uData.i64Long64Data;
    break;
   case SAI_eTypePointer:
    p_vReturn = (void *)&hListEntry->uData.stPointerData.p_vPointer;
    break;
   case SAI_eTypeXX:
    p_vReturn = (void *)hListEntry->uData.stArrayData.p_ucPointer;
    break;
   default:
    p_vReturn = (void *)NULL;
    break;
  }
 }
 return(p_vReturn);
}
/**************************************************************************/
unsigned char SAI_fn_bInsertArrayInTable(void *_p_vValue, unsigned long _ulSize, SAI_tdeFlags _eFlags)
{
 return(SAI_fn_bInsertAnElementInList(&SAI_g_stInternalStructure,_p_vValue,_ulSize,SAI_eTypeXX,_eFlags));
}
/**************************************************************************/
unsigned char SAI_fn_bInitAllWhen(SAI_tdeFlags _eUserFlags)
{
 return(SAI_fn_bInitAllTableWhen(&SAI_g_stInternalStructure,_eUserFlags));
}
/**************************************************************************/
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
unsigned char SAI_fn_bInitOneValueWhen(void *_p_vValue, SAI_tdeFlags _eUserFlags)
{
 return(SAI_fn_bInitOneTableElementWhen(&SAI_g_stInternalStructure,_p_vValue,_eUserFlags));
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
/**************************************************************************/
unsigned char SAI_fn_ucPlayerSaveValues(char *_szFileName)
{
 return(SAI_fn_ucSaveAllGameTableValues(&SAI_g_stInternalStructure,_szFileName,SAI_ePlayerSaveTableValue|SAI_ePlayerSaveCurrentValue));
}
/**************************************************************************/
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
unsigned char SAI_fn_ucLevelSaveValues(char *_szFileName)
{
 return(SAI_fn_ucSaveAllGameTableValues(&SAI_g_stInternalStructure,_szFileName,SAI_eLevelSaveTableValue|SAI_eLevelSaveCurrentValue));
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
/**************************************************************************/
 
unsigned char SAI_fn_ucLoadPlayerValues(char *_szFileName)
{
 return SAI_fn_ucLoadAllGameTableValues( &SAI_g_stInternalStructure, _szFileName, SAI_ePlayerSaveTableValue|SAI_ePlayerSaveCurrentValue );
}
/**************************************************************************/
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
unsigned char SAI_fn_ucLoadLevelValues(char *_szFileName)
{
 return SAI_fn_ucLoadAllGameTableValues( &SAI_g_stInternalStructure, _szFileName, SAI_eLevelSaveTableValue|SAI_eLevelSaveCurrentValue );
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
