reman3/Rayman_X/cpa/tempgrp/IPT/IPT_Save.c

149 lines
4.9 KiB
C

/*=========================================================================
* IPT_Save.c :
* Input options saved
*
* (c) Ubi Studios 1997
*=======================================================================*/
#include "IPT_CPA.h"
#include "IPT_Hdl.h"
#include "MemIPT.h"
#include "ErrIPT.h"
#include "IPT_Def.h"
#include "IPT_Hdl.h"
#define D_IPT_Input_StructureDefine
#include "IPT_KDef.h"
#include "IPT_Str.h"
#undef D_IPT_Input_StructureDefine
#include "IPT_Main.h"
#include "IPT_Scpt.h"
extern signed char g_cJoystickXmin;
extern signed char g_cJoystickXmax;
extern signed char g_cJoystickYmin;
extern signed char g_cJoystickYmax;
#ifndef U64
extern signed char g_cJoystickXcenter;
extern signed char g_cJoystickYcenter;
#endif
/*************************************************************************/
unsigned char IPT_fn_bSaveOptionsInFile(FILE *p_stFile)
{
unsigned char ucReturn = IPT_C_TRUE;
unsigned long i;
IPT_tdxHandleToEntryElement hEntryElement;
IPT_tdxHandleToKeyWordElement hNextElement;
unsigned char uc8bits;
uc8bits = IPT_fn_bIsKeyboardControlAvailable();
fwrite(&uc8bits,sizeof(char),1,p_stFile);
uc8bits = IPT_fn_bIsPaddleControlAvailable();
fwrite(&uc8bits,sizeof(char),1,p_stFile);
uc8bits = IPT_fn_bIsJoystickControlAvailable();
fwrite(&uc8bits,sizeof(char),1,p_stFile);
for (i=0;i<IPT_g_hInputStructure.ulNumberOfEntryElement;i++)
{
hEntryElement = &IPT_g_hInputStructure.d_stEntryElementArray[i];
if (hEntryElement->p_szEntryName!=NULL)
{
uc8bits = strlen(hEntryElement->p_szEntryName)+1;
fwrite(&uc8bits,sizeof(char),1,p_stFile);
fwrite(hEntryElement->p_szEntryName,sizeof(char),uc8bits,p_stFile);
hNextElement = &hEntryElement->d_stKeyWordElementArray[0];
if (hNextElement->u_ElementUnion.swKeyWord==IPT_E_KeyWord_KeyPressed)
{
hNextElement = &hEntryElement->d_stKeyWordElementArray[1];
fwrite(&hNextElement->u_ElementUnion.swKey,sizeof(short),1,p_stFile);
}
else if (hNextElement->u_ElementUnion.swKeyWord==IPT_E_KeyWord_JoystickOrPadPressed)
{
hNextElement = &hEntryElement->d_stKeyWordElementArray[1];
fwrite(&hNextElement->u_ElementUnion.swPadNumber,sizeof(short),1,p_stFile);
hNextElement = &hEntryElement->d_stKeyWordElementArray[2];
fwrite(&hNextElement->u_ElementUnion.swPadAction,sizeof(short),1,p_stFile);
}
}
}
uc8bits = 0xff;
fwrite(&uc8bits,sizeof(char),1,p_stFile);
/* Save joystick calibration */
fwrite( &g_cJoystickXmin, sizeof(signed char), 1, p_stFile );
fwrite( &g_cJoystickXmax, sizeof(signed char), 1, p_stFile );
fwrite( &g_cJoystickYmin, sizeof(signed char), 1, p_stFile );
fwrite( &g_cJoystickYmax, sizeof(signed char), 1, p_stFile );
#ifndef U64
fwrite( &g_cJoystickXcenter, sizeof(signed char), 1, p_stFile );
fwrite( &g_cJoystickYcenter, sizeof(signed char), 1, p_stFile );
#endif
return(ucReturn);
}
/*************************************************************************/
unsigned char IPT_fn_bLoadOptionsFromFile(FILE *p_stFile)
{
unsigned char ucReturn = IPT_C_TRUE;
IPT_tdxHandleToEntryElement hEntryElement;
IPT_tdxHandleToKeyWordElement hNextElement;
unsigned char uc8bits;
char szActionName[255];
IPT_fn_vDesactiveJoystickAndPadControl();
fread(&uc8bits,sizeof(char),1,p_stFile);
fread(&uc8bits,sizeof(char),1,p_stFile);
if (uc8bits)
{
IPT_fn_vDesactiveJoystickAndPadControl();
IPT_fn_vActivePaddleControl();
}
fread(&uc8bits,sizeof(char),1,p_stFile);
if (uc8bits)
{
IPT_fn_vDesactiveJoystickAndPadControl();
IPT_fn_vActiveJoystickControl();
}
fread(&uc8bits,sizeof(char),1,p_stFile);
while(uc8bits!=0xff)
{
fread(szActionName,sizeof(char),uc8bits,p_stFile);
hEntryElement=IPT_fn_hGetEntryActionHandleForOptions(szActionName);
hNextElement = &hEntryElement->d_stKeyWordElementArray[0];
if (hNextElement->u_ElementUnion.swKeyWord==IPT_E_KeyWord_KeyPressed)
{
hNextElement = &hEntryElement->d_stKeyWordElementArray[1];
fread(&hNextElement->u_ElementUnion.swKey,sizeof(short),1,p_stFile);
}
else if (hNextElement->u_ElementUnion.swKeyWord==IPT_E_KeyWord_JoystickOrPadPressed)
{
hNextElement = &hEntryElement->d_stKeyWordElementArray[1];
fread(&hNextElement->u_ElementUnion.swPadNumber,sizeof(short),1,p_stFile);
hNextElement = &hEntryElement->d_stKeyWordElementArray[2];
fread(&hNextElement->u_ElementUnion.swPadAction,sizeof(short),1,p_stFile);
}
fread(&uc8bits,sizeof(char),1,p_stFile);
}
/* Read joystick calibration */
fread( &g_cJoystickXmin, sizeof(signed char), 1, p_stFile );
fread( &g_cJoystickXmax, sizeof(signed char), 1, p_stFile );
fread( &g_cJoystickYmin, sizeof(signed char), 1, p_stFile );
fread( &g_cJoystickYmax, sizeof(signed char), 1, p_stFile );
#ifndef U64
fread( &g_cJoystickXcenter, sizeof(signed char), 1, p_stFile );
fread( &g_cJoystickYcenter, sizeof(signed char), 1, p_stFile );
#endif
return(ucReturn);
}
/*************************************************************************/