'#Uses "Include.inc"

Option Explicit
'*****************************************************************************
' Module:
'        CAPCOMx
'-----------------------------------------------------------------------------
' Description:
'        This file contains the 'Update' functions for the module.
'
'-----------------------------------------------------------------------------
' History:
'                 
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0   ahe         05.01.01     final version for S-Gold
'
'        ---------------------------------------------------------------------
'        3.0   ahe         02.05.01     final version for Pegasus
'
'        3.1   ahe         02.07.02     no changes
'        3.2   ste         18.12.02     no changes
'                          22.01.03     bits PDS and ORSEL deleted
'
'*****************************************************************************


'*****************************************************************************
'Description:
'        This function is called by the main module in order to reset or update
'        the project variables and register contents of this peripheral
'-----------------------------------------------------------------------------
'Parameters:
'        r                      reference to the project data variables
'        vIndex                 a parameter
'        lngUpdateDescriptor    identification of the update context
'                  0          = initialization for a new project
'                  1, 2, 3... = value that identifies which project settings have
'                               been changed (e.g. CPU-Type, CPU-Clock etc.)
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function UpdateProjectData(r As ProjectData, vIndex As Variant, lngUpdateDescriptor As Long) As Boolean
    On Error GoTo UpdateProjectDataError

    Dim sVarPre   As String
    Dim sCAPPre   As String
    Dim i         As Integer
    Dim iTmr_x    As Integer
    Dim iTmr_y    As Integer
    Dim iCh_low   As Integer
    Dim iCh_high  As Integer
    Dim sCCx      As String

    UpdateProjectData = False
    sVarPre = "CC" & vIndex
    sCCx = "CC" & vIndex & "_"
    sCAPPre = "CAP" & vIndex
    
    If (vIndex = 1) Then
        iCh_low = 0
        iCh_high = 7 + CH_HIGH
        iTmr_x = 0
        iTmr_y = 1
    Else
        iCh_low = 16
        iCh_high = 23 + CH_HIGH
        iTmr_x = 7
        iTmr_y = 8
    End If

    Select Case lngUpdateDescriptor
        Case 0 
            ' init reset values for registers
'
            ' init function, parameters and file names
            r.v(sVarPre & "_CFile")                   = sVarPre & ".C"
            r.v(sVarPre & "_HFile")                   = sVarPre & ".H"
            r.v(sVarPre & "_Notes")                   = ""
            r.v(sVarPre & "_NAME_Init")               = sVarPre & "_vInit"

            r.v(sVarPre & "_NAME_StartTmr")           = sVarPre & "_vStartTmr"
            r.v(sVarPre & "_NAME_StopTmr")            = sVarPre & "_vStopTmr"
            r.v(sVarPre & "_NAME_ClearTmr")           = sVarPre & "_vClearTmr"
            r.v(sVarPre & "_NAME_ReadTmr")            = sVarPre & "_uwReadTmr"
            r.v(sVarPre & "_NAME_LoadTmr")            = sVarPre & "_vLoadTmr"
            r.v(sVarPre & "_NAME_SetReload")          = sVarPre & "_vSetReload"
            r.v(sVarPre & "_NAME_SetCCxReg")          = sVarPre & "_vSetCCxReg"
            r.v(sVarPre & "_NAME_GetCCxReg")          = sVarPre & "_uwGetCCxReg"
            r.v(sVarPre & "_NAME_PortLock")           = sVarPre & "_vPortLock"
            r.v(sVarPre & "_NAME_PortUnlock")         = sVarPre & "_vPortUnlock"
            r.v(sVarPre & "_NAME_EnableSingleEvent")  = sVarPre & "_vEnableSingleEvent"
            r.v(sVarPre & "_NAME_SelectDoubleRegisterCompareMode") = sVarPre & "_vSelectDoubleRegisterCompareMode"
            r.v(sVarPre & "_NAME_SetCCxOUT")          = sVarPre & "_vSetCCxOUT"
            r.v(sVarPre & "_NAME_ResetCCxOUT")        = sVarPre & "_vResetCCxOUT"
            r.v(sVarPre & "_NAME_GetCCxOUT")          = sVarPre & "_ubGetCCxOUT"
            'r.v(sVarPre & "_NAME_SetPortDirectionOutput") = sVarPre & "_vSetPortDirectionOutput"
            'r.v(sVarPre & "_NAME_SetPortDirectionInput")  = sVarPre & "_vSetPortDirectionInput"

            r.v(sVarPre & "_NAME_Tmr" & iTmr_x)       = sVarPre & "_viTmr" & iTmr_x
            r.v(sVarPre & "_NAME_Tmr" & iTmr_y)       = sVarPre & "_viTmr" & iTmr_y

            r.v(sVarPre & "_PARA_TIMER_" & iTmr_x)    = sVarPre & "_TIMER_" & iTmr_x
            r.v(sVarPre & "_PARA_TIMER_" & iTmr_y)    = sVarPre & "_TIMER_" & iTmr_y

            
            For i = iCh_low To iCh_high
                r.v(sVarPre & "_NAME_CC" & i)         = sVarPre & "_viCC" & i
                r.v(sVarPre & "_PARA_CC_" & i)        = sVarPre & "_CC_" & i
            Next i


            '...

        Case 1

            '...
       'Case...
    End Select

    UpdateProjectData = True
    Exit Function

UpdateProjectDataError:
    ErrorBox "Error in function UpdateProjectData", Err.Description
    Exit Function
End Function

