/*========================================================================= * IPT_Main.c : * Variables declaration and init function * * (c) Ubi Studios 1997 *=======================================================================*/ #include "IPT_CPA.h" #include "IPT_Hdl.h" #define D_IPT_Input_StructureDefine #define D_IPT_Input_VariableDefine #include "IPT_Main.h" #include "MemIPT.h" #include "ErrIPT.h" #include "IPT_Kwan.h" #include "IPT_KDef.h" #include "IPT_Str.h" #include "IPT_Scpt.h" #include "IPT_Hist.h" #include "IPT_Def.h" #include "IPT_Anal.h" #include "ACP_base.h" #include "GAM/ToolsCPA.h" #include "gam.h" #include "acp_driver.h" /*XB*/ #include /*End XB*/ #undef D_IPT_Input_StructureDefine #undef D_IPT_Input_VariableDefine /*************************************************************************/ void IPT_fn_vFirstInitInput() { Erm_M_InitErrMsg(IPT); Mmg_M_InitMmg(IPT); Mmg_fn_cCheckAlignmentValidity(); } /*************************************************************************/ void IPT_fn_vInitMemory(unsigned long _ulMemSize) { #if !defined(U64) Mmg_M_InitBlock(IPT,E_ucIPTMemoryBlock,_ulMemSize); #else /* !U64 */ #ifdef CHECK_MEMORY Mmg_M_InitSpecificBlock(IPT,E_ucIPTMemoryBlock,_ulMemSize, C_ulDefaultMaxNbStaticMalloc, 4, C_BlockWithFreeFlag | C_Check_AlignementFlag | C_Check_OverflowFlag); #else /* CHECK_MEMORY */ Mmg_M_InitSpecificBlock(IPT,E_ucIPTMemoryBlock,_ulMemSize, C_ulDefaultMaxNbStaticMalloc, 4, C_BlockWithoutFreeFlag | C_Check_AlignementFlag | C_Check_OverflowFlag); #endif /* CHECK_MEMORY */ #endif /* !U64 */ } /*************************************************************************/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ void IPT_fn_vInitInputWhenLoadSnapshot( HINSTANCE hInstance, HWND hWindow ) { long i; #if (!defined(U64)) /**** Init the Keyboard library ****/ if (fn_wKbInitKeyboard(IPT_C_ACP_HistoricSize,hInstance,hWindow)!=C_wKbError) { fn_wKbResetKeyboard(); /* Mark keyboard as active instead of Valide.*/ IPT_g_hInputStructure.p_ucValideAndActiveDevice[IPT_E_KeyboardDeviceEvent] = IPT_C_ActivateDevice; } else IPT_g_hInputStructure.p_ucValideAndActiveDevice[IPT_E_KeyboardDeviceEvent] = IPT_C_InvalideDevice; #endif /* !U64 */ /**** Init the Joystick library ****/ IPT_g_hInputStructure.ucOnePadActivate = IPT_C_InvalideDevice; IPT_g_hInputStructure.p_ucValideAndActiveDevice[IPT_E_Pad00DeviceEvent] = IPT_C_InvalideDevice; if (fn_wJoyInitGamePort(IPT_C_ACP_HistoricSize)!=C_wJoyError) { fn_wJoyResetGamePort(); for (i=0;ilState=-2;*/ IPT_g_hInputStructure.d_stEntryElementArray[i].lState=-2; } } /*************************************************************************/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ IPT_tdxHandleToEntryElement IPT_fn_hGetEntryActionHandleForOptions(char *_szKeyActionName) { unsigned long i; /* IPT_tdxHandleToEntryElement hEntryElement;*/ IPT_tdxHandleToEntryElement hAction = NULL; /* LST2_M_DynamicForEachElementOf(&IPT_g_hInputStructure.hEntryElement,hEntryElement,i)*/ /* {*/ /* if (hEntryElement->p_szEntryName!=NULL&&!stricmp(hEntryElement->p_szEntryName,_szKeyActionName))*/ for (i=0;ip_szActionName); else #endif /* U64*/ return(NULL); } /*************************************************************************/ #ifndef _FIRE_DEADCODE_U64_ unsigned char IPT_fn_bIsAValidEntryActionHandle(IPT_tdxHandleToEntryElement hKeyActionHandle) { /* unsigned char ucReturn = IPT_C_FALSE; #if !defined(U64) SCR_tdst_Link_Value *p_xIndex; if (hKeyActionHandle!=NULL) { p_xIndex=SCR_fnp_st_Link_SearchValue(&IPT_g_hInputStructure.stEntryLink,(unsigned long)hKeyActionHandle); if (p_xIndex!=NULL&&SCR_M_e_Link_GetState(p_xIndex)==SCR_ELS_Link_Initialized) ucReturn = IPT_C_TRUE; } #endif // U64 return(ucReturn); */ #if !defined(U64) unsigned long i; if (hKeyActionHandle!=NULL) { for (i=0;ibIsActivate=IPT_C_TRUE; _hEntryElement->lState = -2; } /*************************************************************************/ void IPT_fn_vDesactivateEntryElement(IPT_tdxHandleToEntryElement _hEntryElement) { _hEntryElement->bIsActivate=IPT_C_FALSE; _hEntryElement->lState = -2; } /*************************************************************************/ #ifndef _FIRE_DEADCODE_U64_ unsigned char IPT_fn_bGetActivationFlagOfEntryElement(IPT_tdxHandleToEntryElement _hEntryElement) { return(_hEntryElement->bIsActivate); } #endif /* _FIRE_DEADCODE_U64_ */ /*************************************************************************/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ char IPT_fn_cGetValidAsciiKey(char *p_szValideKey) { #if (!defined(U64)) short wKey = 0; char cKey = 0; wKey = INO_fn_wGetLastASCIICode(); cKey = (char)wKey; if (wKey==C_wKbError||strchr(p_szValideKey,cKey)==NULL) cKey = 0; return(cKey); #else return(0); #endif /* !U64 */ } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ /*************************************************************************/ #if !defined(RETAIL) || defined(FINAL_VERSION_FOR_TESTERS) void IPT_PrintUsedStaticMemory(void) { Mmg_M_PrintUsedStaticMemoryInModule(IPT); } #endif /* !defined(RETAIL) || defined(FINAL_VERSION_FOR_TESTERS) */ /**************************************************************************/ /*XB*/ #ifdef CHECK_MEMORY void IPT_CheckMemory(void) { Mmg_M_CheckMemory(IPT); } #endif /* CHECK_MEMORY */ /*End XB*/ /**************************************************************************/ /* XB 02/06/99 */ #ifndef FINAL_VERSION unsigned long IPT_fn_ulGetUsedStaticMemory(void) { return Mmg_M_GetUsedStaticMemory(IPT); } #endif /* FINAL_VERSION */ /* End XB 02/06/99 */ /*************************************************************************/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ unsigned char IPT_fn_bIsKeyboardControlAvailable(void) { unsigned char ucReturn = IPT_C_FALSE; if (IPT_g_hInputStructure.p_ucValideAndActiveDevice[IPT_E_KeyboardDeviceEvent]==IPT_C_ActivateDevice) ucReturn = IPT_C_TRUE; return(ucReturn); } /*************************************************************************/ unsigned char IPT_fn_bIsPaddleControlAvailable(void) { unsigned long i; unsigned char ucReturn = IPT_C_FALSE; for (i=IPT_E_Pad00DeviceEvent;i<=IPT_E_Pad15DeviceEvent;i++) { if (IPT_g_hInputStructure.p_ucValideAndActiveDevice[i]==IPT_C_ActivatePadDevice) ucReturn = IPT_C_TRUE; } return(ucReturn); } /*************************************************************************/ unsigned char IPT_fn_bIsJoystickControlAvailable(void) { unsigned long i; unsigned char ucReturn = IPT_C_FALSE; for (i=IPT_E_Pad00DeviceEvent;i<=IPT_E_Pad15DeviceEvent;i++) { if (IPT_g_hInputStructure.p_ucValideAndActiveDevice[i]==IPT_C_ActivateJoystickDevice) ucReturn = IPT_C_TRUE; } return(ucReturn); } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ /*************************************************************************/ void IPT_fn_vDesactiveJoystickAndPadControl(void) { unsigned long i; for (i=IPT_E_Pad00DeviceEvent;i<=IPT_E_Pad15DeviceEvent;i++) { if ( IPT_g_hInputStructure.p_ucValideAndActiveDevice[i]==IPT_C_ActivatePadDevice ||IPT_g_hInputStructure.p_ucValideAndActiveDevice[i]==IPT_C_ActivateJoystickDevice) { IPT_g_hInputStructure.p_ucValideAndActiveDevice[i]=IPT_C_ValideDevice; fn_wJoyRemoveActiveJoystick((short)(i-IPT_E_Pad00DeviceEvent)); } } } /*************************************************************************/ void IPT_fn_vActiveJoystickControl(void) { unsigned long i; for (i=IPT_E_Pad00DeviceEvent;i<=IPT_E_Pad15DeviceEvent;i++) { if (IPT_g_hInputStructure.p_ucValideAndActiveDevice[i]==IPT_C_ValideDevice) { IPT_g_hInputStructure.p_ucValideAndActiveDevice[i]=IPT_C_ActivateJoystickDevice; fn_wJoyAddActiveJoystick((short)(i-IPT_E_Pad00DeviceEvent)); } } } /*************************************************************************/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ void IPT_fn_vActivePaddleControl(void) { unsigned long i; for (i=IPT_E_Pad00DeviceEvent;i<=IPT_E_Pad15DeviceEvent;i++) { if (IPT_g_hInputStructure.p_ucValideAndActiveDevice[i]==IPT_C_ValideDevice) { IPT_g_hInputStructure.p_ucValideAndActiveDevice[i]=IPT_C_ActivatePadDevice; fn_wJoyAddActiveJoystick((short)(i-IPT_E_Pad00DeviceEvent)); } } } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ /*************************************************************************/ IPT_tdxHandleToEntryElement IPT_fn_hSearchElementInOptionWithKeyWord(signed short _swEntryType,signed short swPadNumber,signed short _swKeyValue) { unsigned long i; IPT_tdxHandleToEntryElement hEntryElement; IPT_tdxHandleToEntryElement hAction = NULL; IPT_tdxHandleToKeyWordElement hNextElement; for (i=0;ip_szEntryName!=NULL) { if (_swEntryType==IPT_E_KeyWord_KeyPressed) { hNextElement = &hEntryElement->d_stKeyWordElementArray[0]; if (hNextElement->u_ElementUnion.swKeyWord==IPT_E_KeyWord_KeyPressed) { hNextElement = &hEntryElement->d_stKeyWordElementArray[1]; if (hNextElement->u_ElementUnion.swKey==_swKeyValue) hAction = hEntryElement; } } else if (_swEntryType==IPT_E_KeyWord_JoystickOrPadPressed) { hNextElement = &hEntryElement->d_stKeyWordElementArray[0]; if (hNextElement->u_ElementUnion.swKeyWord==IPT_E_KeyWord_JoystickOrPadPressed) { hNextElement = &hEntryElement->d_stKeyWordElementArray[1]; if (hNextElement->u_ElementUnion.swPadNumber==swPadNumber) { hNextElement = &hEntryElement->d_stKeyWordElementArray[2]; if (hNextElement->u_ElementUnion.swKey==_swKeyValue) hAction = hEntryElement; } } } } } return(hAction); } /*************************************************************************/ /* replace an ActionValidated action inside another one */ unsigned char IPT_fn_bModifyIPTAction ( IPT_tdxHandleToEntryElement _hElementToChange, IPT_tdxHandleToEntryElement _hReplacingElement ) { long lI ; for ( lI = 0 ; lI < ( long ) _hElementToChange -> ulNumberOfKeyWordElement ; lI ++ ) if ( _hElementToChange -> d_stKeyWordElementArray [ lI ] . u_ElementUnion . swKeyWord == IPT_E_KeyWord_ActionValidated ) { _hElementToChange -> d_stKeyWordElementArray [ lI + 1 ] . u_ElementUnion . hEntryElement = _hReplacingElement ; return IPT_C_TRUE ; } return IPT_C_FALSE ; } /*************************************************************************/ unsigned char IPT_fn_bChangeIPTValue(IPT_tdxHandleToEntryElement _hElement,unsigned char ucWhichTest) { signed short swPadNumber; unsigned char ucReturn = IPT_C_FALSE; unsigned long i; unsigned char bFlag = FALSE; IPT_tdxHandleToEntryElement hExchangeEntry; IPT_tdxHandleToKeyWordElement hExchangeNextElement; IPT_tdxHandleToKeyWordElement hNextElement; /* hNextElement = LST2_M_DynamicGetFirstElement(&_hElement->hKeyWordList);*/ hNextElement = &_hElement->d_stKeyWordElementArray[0]; #if (!defined(U64)) if (hNextElement->u_ElementUnion.swKeyWord==IPT_E_KeyWord_KeyPressed) { /* hNextElement = LST2_M_DynamicGetNextElement(hNextElement);*/ hNextElement++; for (i=0;IPT_g_hScriptKeyValue[i].swKeyValue!=-1&&fn_wKbJustDown(IPT_g_hScriptKeyValue[i].swKeyValue)!=C_wKbTrue;i++); if (IPT_g_hScriptKeyValue[i].swKeyValue!=-1&&IPT_fn_p_szGetNameOfKeyName(IPT_g_hScriptKeyValue[i].swKeyValue,0)!=NULL) { hExchangeEntry = IPT_fn_hSearchElementInOptionWithKeyWord(IPT_E_KeyWord_KeyPressed,0,IPT_g_hScriptKeyValue[i].swKeyValue); if (ucWhichTest==IPT_C_Duplicate) bFlag = TRUE; else if (ucWhichTest==IPT_C_NoDuplicate) { if (hExchangeEntry==NULL||hExchangeEntry==_hElement) bFlag = TRUE; } else if (ucWhichTest==IPT_C_Exchange) { bFlag = TRUE; if (hExchangeEntry!=NULL&&hExchangeEntry!=_hElement) { /* hExchangeNextElement = LST2_M_DynamicGetNextElement(LST2_M_DynamicGetFirstElement(&hExchangeEntry->hKeyWordList));*/ hExchangeNextElement = &hExchangeEntry->d_stKeyWordElementArray[1]; hExchangeNextElement->u_ElementUnion.swKey = hNextElement->u_ElementUnion.swKey; } } if (bFlag) { hNextElement->u_ElementUnion.swKey = IPT_g_hScriptKeyValue[i].swKeyValue; ucReturn = IPT_C_TRUE; } } } else #endif /* !U64 */ if (hNextElement->u_ElementUnion.swKeyWord==IPT_E_KeyWord_JoystickOrPadPressed) { /* hNextElement = LST2_M_DynamicGetNextElement(hNextElement);*/ hNextElement++; swPadNumber = hNextElement->u_ElementUnion.swPadNumber; /* hNextElement = LST2_M_DynamicGetNextElement(hNextElement);*/ hNextElement++; for (i=IPT_E_PadFirstButton;i<=IPT_E_PadLastButton&&INO_fn_wJoystickButtonJustPressed(swPadNumber,IPT_g_ulPadAndJoyButtonFlag[i-IPT_E_PadFirstButton])!=C_wJoyTrue;i++); if (i<=IPT_E_PadLastButton) { hExchangeEntry = IPT_fn_hSearchElementInOptionWithKeyWord(IPT_E_KeyWord_JoystickOrPadPressed,swPadNumber,IPT_g_hScriptPadValue[i].swKeyValue); if (ucWhichTest==IPT_C_Duplicate) bFlag = TRUE; else if (ucWhichTest==IPT_C_NoDuplicate) { if (hExchangeEntry==NULL||hExchangeEntry==_hElement) bFlag = TRUE; } else if (ucWhichTest==IPT_C_Exchange) { bFlag = TRUE; if (hExchangeEntry!=NULL&&hExchangeEntry!=_hElement) { /* hExchangeNextElement = LST2_M_DynamicGetNextElement(LST2_M_DynamicGetNextElement(LST2_M_DynamicGetFirstElement(&hExchangeEntry->hKeyWordList)));*/ hExchangeNextElement = &hExchangeEntry->d_stKeyWordElementArray[2]; hExchangeNextElement->u_ElementUnion.swKey = hNextElement->u_ElementUnion.swKey; } } if (bFlag) { hNextElement->u_ElementUnion.swKey = IPT_g_hScriptPadValue[i].swKeyValue; ucReturn = IPT_C_TRUE; } } } return(ucReturn); } /*************************************************************************/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ char *IPT_fn_szGetStringOf(IPT_tdxHandleToEntryElement _hElement) { IPT_tdxHandleToKeyWordElement hNextElement; /*hNextElement = LST2_M_DynamicGetFirstElement(&_hElement->hKeyWordList);*/ hNextElement = &_hElement->d_stKeyWordElementArray[0];; if (hNextElement->u_ElementUnion.swKeyWord==IPT_E_KeyWord_KeyPressed) { /* hNextElement = LST2_M_DynamicGetNextElement(hNextElement);*/ hNextElement++; if (IPT_g_hInputStructure.ucKeyboardType==IPT_C_AZERTYKeyBoardType) return(IPT_fn_p_szGetNameOfKeyName(hNextElement->u_ElementUnion.swKey,0)); else return(IPT_fn_p_szGetNameOfKeyName(hNextElement->u_ElementUnion.swKey,1)); } else if (hNextElement->u_ElementUnion.swKeyWord==IPT_E_KeyWord_JoystickOrPadPressed) { /* hNextElement = LST2_M_DynamicGetNextElement(hNextElement);*/ /* hNextElement = LST2_M_DynamicGetNextElement(hNextElement);*/ hNextElement+=2; return(IPT_fn_p_szGetNameOfKeyName((unsigned short)(hNextElement->u_ElementUnion.swPadAction|0x8000),0)); } return NULL; } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ /*************************************************************************/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ IPT_tdxHandleToKeyWordElement IPT_fn_hAllocKeyWord(void) { IPT_tdxHandleToKeyWordElement hKeyWordElement; Mmg_M_SetModeAlloc4Ch(IPT,E_ucIPTMemoryBlock,C_ucMmgDefaultChannel); MMG_fn_vAddMemoryInfo(MMG_C_lTypeIPT,MMG_C_lSubTypeIPT,0); if ((hKeyWordElement = (IPT_tdxHandleToKeyWordElement)Mmg_fn_p_vAlloc4Ch(sizeof(struct IPT_tdstKeyWordElement_),C_ucMmgDefaultChannel))==NULL) { M_IPTFatalError(E_uwIPT_AllocNewKeyWord); } memset(hKeyWordElement,0,sizeof(struct IPT_tdstKeyWordElement_)); return(hKeyWordElement); } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ /*************************************************************************/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ char *IPT_fn_p_szGetNameOfKeyName(unsigned short uwKeyCode,unsigned char ucFrenchOrAmerican) { long i; char *szReturn = NULL; for (i=0;IPT_gd_hKeyAndPadDefine[i].uwBasedKey!=0xffff&&uwKeyCode!=IPT_gd_hKeyAndPadDefine[i].uwBasedKey;i++); if (IPT_gd_hKeyAndPadDefine[i].uwBasedKey!=0xffff) { if (ucFrenchOrAmerican==0) szReturn = IPT_gd_hKeyAndPadDefine[i].p_szFrenchKey; else if (ucFrenchOrAmerican==1) szReturn = IPT_gd_hKeyAndPadDefine[i].p_szAmericanKey; } return(szReturn); } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ /*************************************************************************/ ACP_tdxBool IPT_fn_bAJoypadConnected() { return ((IPT_g_hInputStructure.ucOnePadActivate == IPT_C_ActivateDevice)|| (fn_wJoyReadJoystick(C_wJoyReadConnected)!=C_wJoyError)); } /* LOL*/ #ifndef U64 /*************************************************************************/ ACP_tdxBool IPT_fn_bAKeyJustPressed() { unsigned short uwKeyCode; struct IPT_tdstScriptValue_ *p_hScriptKeyValue; struct IPT_tdstKeyAndPadDefine_ *p_stKeyAndPadDefine; p_hScriptKeyValue = &IPT_g_hScriptKeyValue[0]; while (p_hScriptKeyValue->swKeyValue!=-1) { uwKeyCode = p_hScriptKeyValue->swKeyValue; if (fn_wKbJustDown(uwKeyCode)==C_wKbTrue) { p_stKeyAndPadDefine = &IPT_gd_hKeyAndPadDefine[0]; while (p_stKeyAndPadDefine->uwBasedKey!=0xffff) { if (uwKeyCode==p_stKeyAndPadDefine->uwBasedKey) return TRUE; p_stKeyAndPadDefine++; } } p_hScriptKeyValue ++; } return FALSE; } #endif /*************************************************************************/ ACP_tdxBool IPT_fn_bAButtonPadJustPressed() { long i; i =IPT_E_PadFirstButton; while (i<=IPT_E_PadLastButton) { if (INO_fn_wJoystickButtonJustPressed(0,IPT_g_ulPadAndJoyButtonFlag[i-IPT_E_PadFirstButton])==C_wJoyTrue) return TRUE; i++; } return FALSE; } /*************************************************************************/ void *IPT_fn_p_vAlloc(unsigned long lSize) { void *p_vPointer; Mmg_M_SetModeAlloc4Ch(IPT,E_ucIPTMemoryBlock,C_ucMmgDefaultChannel); p_vPointer=(void*)Mmg_fn_p_vAlloc4Ch(lSize,C_ucMmgDefaultChannel); memset(p_vPointer,0,lSize); if (p_vPointer==NULL) M_IPTFatalError(E_uwIPTMemoryPlace); return (p_vPointer); } /**************************************************************************/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ void IPT_fn_vFree(void **p_vPointer) { Mmg_M_SetModeAlloc4Ch(IPT,E_ucIPTMemoryBlock,C_ucMmgDefaultChannel); Mmg_fn_vFree4Ch(*p_vPointer,C_ucMmgDefaultChannel); *p_vPointer = NULL; } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ /**************************************************************************/