Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
'#Uses "Include.inc"

Option Explicit

'*****************************************************************************
' Module:
'        INT
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'INT'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        1.0  ahe            27.04.00     final version for C165UTAH
'
'        ----------------------------------------------------------------------
'        2.0  ahe            15.06.00     final version for C167CS
'
'        ----------------------------------------------------------------------
'        2.1  ahe            20.10.00     final version for C167CS
'                                         - no changes
'
'        ----------------------------------------------------------------------
'             ahe            26.10.00     final version for
'                                           C167CS
'                                           C161PI
'                                           C167CR/SR r2
'
'                                         - check EXISEL
'
'        ----------------------------------------------------------------------
'        7.0  ahe            24.04.01     final version for Pegasus
'
'        7.1  ahe            08.08.02     - neu interrupt pages
'        7.2  ste            20.12.02     XC167CI added
'        ----------------------------------------------------------------------
'             ste            24.11.03     new function _viSOFTBRKTrap added
'
'*****************************************************************************

'*****************************************************************************
'Description:
'        This function is called from DAvE just before the Peripherals
'        window is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnLoad(ps As Peripherals) As Boolean
    On Error GoTo OnLoadError

    OnLoad = False

    '-------------------------------------------------------------------------
    ' page: Interrupt
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupt(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: SourceControl
    '-------------------------------------------------------------------------
    If (Not OnLoadPageSourceControl(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: OnLoadPageEOPIC
    '-------------------------------------------------------------------------
    If (Not OnLoadPageEOPIC(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts_32(ps, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts_32(ps, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePEC(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFunctions(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnLoadPageParameters(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnLoadPageNotes(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' end of pages
    '-------------------------------------------------------------------------
    
    '-------------------------------------------------------------------------
    ' call function to initialize the menu
    '-------------------------------------------------------------------------
    If (Not InitMenu(ps, "INT\Dialog")) Then Exit Function

    OnLoad = True
    Exit Function

OnLoadError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE just before a page
'        is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnChangingPageError

    OnChangingPage = False
    Dim sVarPre As String
    Dim vIndex  As Variant

    vIndex = ps.Parameters.v("x")

    sVarPre = "INT" & vIndex

    
    '-------------------------------------------------------------------------
    'page: Interrupt
    '-------------------------------------------------------------------------
    If (Not OnChangingPageInterrupt(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: SourceControl
    '-------------------------------------------------------------------------
    If (Not OnChangingPageSourceControl(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: OnChangingPageEOPIC
    '-------------------------------------------------------------------------
    If (Not OnChangingPageEOPIC(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnChangingPageInterrupts_32(ps, Pagename, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnChangingPageInterrupts_32(ps, Pagename, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: PEC
    '-------------------------------------------------------------------------
    If (Not OnChangingPagePEC(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Functions
    '-------------------------------------------------------------------------
    If (Not OnChangingPageFunctions(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnChangingPageParameters(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Notes
    '-------------------------------------------------------------------------
    If (Not OnChangingPageNotes(ps, Pagename, sVarPre)) Then Exit Function


    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE in two cases:
'
'        1.
'            The contents of the peripherals window must be refreshed.
'            In this case the 'Controlname' parameter is a empty string
'            and the values array 'v()' contains nothing.
'
'        2.
'            A control on the peripherals has been changed.
'            In this case the 'Controlname' parameter contains the name
'            of the changed control and the values array 'v()' contains the
'            changed value(s).
'
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the changed control (for case 2)
'        v()             array with the changed values (for case 2)
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnShowError

    OnShow = False
    Dim sVarPre As String
    Dim vIndex  As Variant

    vIndex = ps.Parameters.v("x")

    sVarPre = "INT" & vIndex

    '-------------------------------------------------------------------------
    ' page: Interrupt
    '-------------------------------------------------------------------------
    If (Not OnShowPageInterrupt(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: SourceControl
    '-------------------------------------------------------------------------
    If (Not OnShowPageSourceControl(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: OnShowPageEOPIC
    '-------------------------------------------------------------------------
    If (Not OnShowPageEOPIC(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnShowPageInterrupts_32(ps, Controlname, v, sVarPre, Pagename, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnShowPageInterrupts_32(ps, Controlname, v, sVarPre, Pagename, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnShowPagePEC(ps, Controlname, v, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnShowPageFunctions(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function
       
    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnShowPageNotes(ps, Controlname, Pagename, sVarPre, v)) Then Exit Function


    OnShow = True
    Exit Function

OnShowError:
    ErrorBox "Can not show page.", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a button.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnClick(ps As Peripherals, Controlname As String) As Boolean
    On Error GoTo OnClickError

    OnClick = False

    Dim np As Peripherals

    '-------------------------------------------------------------------------
    ' buttons: PEC
    '-------------------------------------------------------------------------
    If (Not OnClickPagePEC(ps, Controlname)) Then Exit Function



    OnClick = True
    Exit Function

OnClickError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a menu entry.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Toolname        name of the entry
'        ToolId          id of the entry
'        Tooltext        additional text of the entry
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnMenuClick(ps As Peripherals, Toolname As String, ToolId As Long, Tooltext As String) As Boolean
    On Error GoTo OnMenuClickError

    OnMenuClick = False

    If (Not MenuClick(ps, Toolname, ToolId, Tooltext, "INT\Dialog")) Then Exit Function

    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
End Function
    


'-----------------------------------------------------------------------------
' local functions
'-----------------------------------------------------------------------------

'*****************************************************************************
' Module:
'        INT.INC
'-----------------------------------------------------------------------------
' Description:
'        This include file contains functions which are create controls for
'        the page 'Interrupt'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        0.0  DAvE Dialog    25.11.99    initial version
'             Editor
'
'
'*****************************************************************************


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'Interrupt'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageInterrupt(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageInterrupt = False

  If (Not ps.AddPage("Fast Ext. Interrupts")) Then Exit Function

  OnLoadPageInterrupt = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageInterrupt(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageInterrupt = False
  Dim i As Integer

  
  If (Not ps.ExtenderCollection("Fast Ext. Interrupts").Loaded) And (Pagename = "Fast Ext. Interrupts") Then
    ps.ExtenderCollection("Fast Ext. Interrupts").Loaded = True
  

    '-------------------------------
    ' frame: frmFEIxIC
    '-------------------------------
    If (Not ps.AddFrame("frmFEIxIC", 100, 100, 3000, 5000, _
      "Interrupt Control")) Then Exit Function
      For i = 0 To 5
        If (Not ps.AddCheck("chkFEI" & i & "IE", 200, 500 + i * 700, 2600, 300, _
          "Enable ext. interrupt " & i & " (" & "CC" & (i + 8) & "IE" & ")")) Then Exit Function
      Next i

    '-------------------------------
    ' frame: frmEXICON
    '-------------------------------
    If (Not ps.AddFrame("frmEXICON", 3200, 100, 5400, 5000, _
      "External Interrupt Edge Selection (EXICON)")) Then Exit Function
      For i = 0 To 5
        If (Not ps.AddCombo("cboEX_" & i, 1700, 500 + i * 700, 3500, 315)) Then Exit Function
        If (Not ps.AddLabel("lblEXICON_" & i, 0, 200, 450 + i * 700, 1575, 380, _
          "External interrupt " & i & " (EXI" & i & "ES)")) Then Exit Function
      Next i

  End If
  OnChangingPageInterrupt = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageInterrupt(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageInterruptError

  OnShowPageInterrupt = False

  Dim r         As ProjectData
  Dim c         As Object
  Dim e         As Object
  Dim i         As Integer
  Dim bDisabled As Boolean
  Dim sVarPre   As String
  Dim vIndex    As Variant
  Dim sPinName  As String

  vIndex = ps.Parameters.v("x")

  sVarPre = "INT" & vIndex

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

'ext. int no.s reduced to 6(0 to 5)

  If (Pagename = "Fast Ext. Interrupts") Then
    '-------------------------------------------------------------------------
    ' page: chkFEIxIE (action)
    '-------------------------------------------------------------------------
    For i = 0 To 5
      If (Controlname = "chkFEI" & i & "IE") Then
        If (v(1) = 1) Then
          r.v(sVarPre & "_Ex" & i & "_Use") = 1
          r.v("EXICON_EXI" & i & "ES") = 1
          Call EnableSRN(r, "INT", "CC1_CC" & (i + 8) & "IC", "Ex" & i)
          Call RequestAlternateInputPin(r, "EX" & i & "IN")
        Else
          r.v(sVarPre & "_Ex" & i & "_Use") = 0
          Call ReleaseAlternateInputPin(r, "EX" & i & "IN")
          r.v("EXICON_EXI" & i & "ES") = 0
          
          If (i < 4) Then
              r.v("EXISEL0_EXI" & i & "SS") = 0
          Else
              r.v("EXISEL1_EXI" & i & "SS") = 0
          End If
          
          Call DisableSRN(r, "INT", "CC1_CC" & (i + 8) & "IC", "Ex" & i)
        End If
      End If
    Next i
    
    '-------------------------------------------------------------------------
    ' page: cboEX_x (action)
    '-------------------------------------------------------------------------
    For i = 0 To 5
      
      'sPinName = " (" & GetPinName("EX" & i & "IN") & ")"
      sPinName = ""

      If (Controlname = "cboEX_" & i) Then
        Select Case (v(1))
                    Case ("Interrupt is disabled")
                         r.v("EXICON_EXI" & i & "ES") = 0

                    Case ("Interrupt on positive edge" & sPinName)
                         r.v("EXICON_EXI" & i & "ES") = 1

                    Case ("Interrupt on negative edge" & sPinName)
                         r.v("EXICON_EXI" & i & "ES") = 2

                    Case ("Interrupt on any edge" & sPinName)
                         r.v("EXICON_EXI" & i & "ES") = 3
        End Select
      End If
    Next i


    '-------------------------------------------------------------------------
    ' page: Interrupt (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: cboEX_x (show)
    '-------------------------------------------------------------------------
    For i = 0 To 5
    
      'sPinName = " (" & GetPinName("EX" & i & "IN") & ")"
      sPinName = ""
    
      With c("cboEX_" & i)
        bDisabled = (r.v(sVarPre & "_Ex" & i & "_Use") = 0 Or _
          Not (IsAlternateInputPinFree(r, "EX" & i & "IN")))
        .Enabled = Not (bDisabled)
        .Clear
    
       .AddItem "Interrupt is disabled"
       .AddItem "Interrupt on positive edge" & sPinName
       .AddItem "Interrupt on negative edge" & sPinName
       .AddItem "Interrupt on any edge" & sPinName
    
        .ListIndex = r.v("EXICON_EXI" & i & "ES")
      End With
    
      With e("cboEX_" & i)
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          If (Not (IsAlternateInputPinFree(r, "EX" & i & "IN"))) Then
            .DisabledTooltipText = .DisabledTooltipText & _
              GetDisabledAlternatePinTooltip(r, "EX" & i & "IN")
          End If
          If (r.v(sVarPre & "_Ex" & i & "_Use") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & _
              FormatDisabledToolTip("ext. interrupt " & i & _
              " is disabled (bit CC" & i & "IE = 0)")
          End If
        End If
      End With
    Next i
    
    
    '-------------------------------------------------------------------------
    ' control: lblEXICON_x (show)
    '-------------------------------------------------------------------------
    For i = 0 To 5
      With c("lblEXICON_" & i)
        bDisabled = (r.v(sVarPre & "_Ex" & i & "_Use") = 0 Or _
                     Not (IsAlternateInputPinFree(r, "EX" & i & "IN")))
        .Enabled = Not (bDisabled)
      End With
    
      With e("cboEX_" & i)
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          If (Not (IsAlternateInputPinFree(r, "EX" & i & "IN"))) Then
            .DisabledTooltipText = .DisabledTooltipText & _
              GetDisabledAlternatePinTooltip(r, "EX" & i & "IN")
          End If
          If (r.v(sVarPre & "_Ex" & i & "_Use") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & _
              FormatDisabledToolTip("ext. interrupt " & i & _
              " is disabled (bit CC" & i & "IE = 0)")
          End If
        End If
      End With
    Next i
    
    '-------------------------------------------------------------------------
    ' control: chkFEIxIE (show)
    '-------------------------------------------------------------------------
    For i = 0 To 5
      With c("chkFEI" & i & "IE")
        bDisabled = (r.v("CC1_CC" & (i + 8) & "_Use") = 1 Or _
          Not (IsAlternateInputPinFree(r, "EX" & i & "IN")))
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sVarPre & "_Ex" & i & "_Use") = 1)
      End With
    
      With e("chkFEI" & i & "IE")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          If (Not (IsAlternateInputPinFree(r, "EX" & i & "IN"))) Then
            .DisabledTooltipText = .DisabledTooltipText & _
              GetDisabledAlternatePinTooltip(r, "EX" & i & "IN")
          End If
          If (r.v("CC1_CC" & (i + 8) & "_Use") = 1) Then
            .DisabledTooltipText = .DisabledTooltipText & _
              FormatDisabledToolTip("CAPCOM1 channel " & i & " is used")
          End If
        End If
      End With
    Next i



  End If

  OnShowPageInterrupt = True
  Exit Function

OnShowPageInterruptError:
  ErrorBox "Can not show page.", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'SourceControl'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageSourceControl(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageSourceControl = False
  Dim r As ProjectData

  Set r = ps.ProjectData

  If (Not ps.AddPage("Source Control")) Then Exit Function

  OnLoadPageSourceControl = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageSourceControl(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageSourceControl = False
  Dim i As Integer
  Dim r As ProjectData

  Set r = ps.ProjectData

  
      If (Not ps.ExtenderCollection("Source Control").Loaded) And (Pagename = "Source Control") Then
        ps.ExtenderCollection("Source Control").Loaded = True
  

        '-------------------------------
        ' frame: frmEXISEL
        '-------------------------------
        If (Not ps.AddFrame("frmEXISEL", 100, 100, 8475, 5000, "External Interrupt Source Control (EXISEL)")) Then Exit Function
          For i = 0 To 5
            If (Not ps.AddCombo("cboEXI_" & i, 1700, 500 + i * 700, 6600, 315)) Then Exit Function
            If (Not ps.AddLabel("lblEXICONI_" & i, 0, 200, 550 + i * 700, 1500, 380, "External interrupt " & i)) Then Exit Function
          Next i


  End If
  OnChangingPageSourceControl = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageSourceControl(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageSourceControlError

  OnShowPageSourceControl = False

  Dim r         As ProjectData
  Dim c         As Object
  Dim e         As Object
  Dim i         As Integer
  Dim bDisabled As Boolean
  Dim sVarPre   As String
  Dim vIndex    As Variant
  Dim iReg      As Integer
  Dim saSource(0 To 5) As CourceControl
  Dim iAltB     As Integer

  vIndex = ps.Parameters.v("x")

  sVarPre = "INT" & vIndex

  For i = 0 To 5
      saSource(i).saCon(0) = GetPinName("EX" & i & "IN")
  Next i

  saSource(0).saCon(1) = "P1H.3"
  saSource(0).saCon(2) = "P1H.0"

'  If (DefGetValue("Name") = "XC161CJ" Or DefGetValue("Name") = "XC167CI") Then
'      saSource(1).saCon(1) = "P3.1"
'      saSource(1).saCon(2) = "P3.0"
'  Else
'      saSource(1).saCon(1) = "P3.1"
'      saSource(1).saCon(2) = ""
'  End If
  saSource(1).saCon(1) = "P3.1"
  saSource(1).saCon(2) = ""
  saSource(2).saCon(1) = "P3.11"
  saSource(2).saCon(2) = "P3.10"

  saSource(3).saCon(1) = "P3.13"
  saSource(3).saCon(2) = ""

  saSource(4).saCon(1) = "P9.2"
  saSource(4).saCon(2) = ""

  saSource(5).saCon(1) = "P9.0"
  saSource(5).saCon(2) = ""

'  If (DefGetValue("Name") = "XC161CJ" Or DefGetValue("Name") = "XC167CI") Then
'      saSource(6).saCon(1) = "P9.3/P7.7"
'      saSource(6).saCon(2) = "P9.1/P7.5"
'  Else
'      saSource(6).saCon(1) = "P9.3"
'      saSource(6).saCon(2) = "P9.1"
'  End If
'
'  If (DefGetValue("Name") = "XC161CJ" Or DefGetValue("Name") = "XC167CI") Then
'      saSource(7).saCon(1) = "P9.2/P7.6"
'      saSource(7).saCon(2) = "P9.0/P7.4"
'  Else
'      saSource(7).saCon(1) = "P9.2"
'      saSource(7).saCon(2) = "P9.0"
'  End If

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

      
      If (Pagename = "Source Control") Then
        '-------------------------------------------------------------------------
        ' control: chkFEIxIE (action)
        '-------------------------------------------------------------------------
        For i = 0 To 5

          If (i < 4) Then 'for EXISELx
              iReg = 0
          Else
              iReg = 1
          End If

          If (Controlname = "cboEXI_" & i) Then
            Select Case (v(1))
                        Case ("Input from pin " & saSource(i).saCon(0) & " (EX" & i & "IN)")
                             r.v("EXISEL" & iReg & "_EXI" & i & "SS") = 0

                        Case ("Input from pin " & saSource(i).saCon(1))
                             r.v("EXISEL" & iReg & "_EXI" & i & "SS") = 1

                        Case ("Input from pin " & saSource(i).saCon(2))
                             r.v("EXISEL" & iReg & "_EXI" & i & "SS") = 2

                        Case ("Input from pin " & saSource(i).saCon(0) & _
                              " (EX" & i & "IN) ORed with pin " & saSource(i).saCon(1))
                             r.v("EXISEL" & iReg & "_EXI" & i & "SS") = 3

                        Case ("Input from pin " & saSource(i).saCon(0) & _
                              " (EX" & i & "IN) ANDed with pin " & saSource(i).saCon(1))
                             r.v("EXISEL" & iReg & "_EXI" & i & "SS") = 4

                        Case ("Input from pin " & saSource(i).saCon(1) & _
                              " ORed with pin " & saSource(i).saCon(2))
                             r.v("EXISEL" & iReg & "_EXI" & i & "SS") = 5

                        Case ("Input from pin " & saSource(i).saCon(1) & _
                              " ANDed with pin " & saSource(i).saCon(2))
                             r.v("EXISEL" & iReg & "_EXI" & i & "SS") = 6

                        Case ("Input from pin " & saSource(i).saCon(0) & _
                              " (EX" & i & "IN) ORed with pin " & saSource(i).saCon(1) & _
                              " ORed with pin " & saSource(i).saCon(2))
                             r.v("EXISEL" & iReg & "_EXI" & i & "SS") = 7

            End Select
          End If
        Next i

        
        '-------------------------------------------------------------------------
        ' control: cboEXI_x (show)
        '-------------------------------------------------------------------------
        For i = 0 To 5
          With c("cboEXI_" & i)
            bDisabled = (r.v(sVarPre & "_Ex" & i & "_Use") = 0 Or _
                         Not (IsAlternateInputPinFree(r, "EX" & i & "IN")) Or _
                         r.v("EXICON_EXI" & i & "ES") = 0)
            .Enabled = Not (bDisabled)
            .Clear
            .AddItem "Input from pin " & saSource(i).saCon(0) & " (EX" & i & "IN)"
            
             iAltB = -CInt(saSource(i).saCon(2) = "") 'is there any Alternate Pin B?
             
             Select Case iAltB
                         Case 0
                             .AddItem "Input from pin " & saSource(i).saCon(1)
                             .AddItem "Input from pin " & saSource(i).saCon(2)
                             .AddItem "Input from pin " & saSource(i).saCon(0) & _
                                      " (EX" & i & "IN) ORed with pin " & saSource(i).saCon(1)
                             .AddItem "Input from pin " & saSource(i).saCon(0) & _
                                      " (EX" & i & "IN) ANDed with pin " & saSource(i).saCon(1)
                             .AddItem "Input from pin " & saSource(i).saCon(1) & _
                                      " ORed with pin " & saSource(i).saCon(2)
                             .AddItem "Input from pin " & saSource(i).saCon(1) & _
                                      " ANDed with pin " & saSource(i).saCon(2)
                             .AddItem "Input from pin " & saSource(i).saCon(0) & _
                                      " (EX" & i & "IN) ORed with pin " & saSource(i).saCon(1) & _
                                      " ORed with pin " & saSource(i).saCon(2)
                         
                         Case 1
                             .AddItem "Input from pin " & saSource(i).saCon(1)
                             .AddItem "Input from pin " & saSource(i).saCon(0) & _
                                      " (EX" & i & "IN) ORed with pin " & saSource(i).saCon(1)
                             .AddItem "Input from pin " & saSource(i).saCon(0) & _
                                      " (EX" & i & "IN) ANDed with pin " & saSource(i).saCon(1)
                         
                         Case Else
             End Select
'*************************************************************************************
'            If (saSource(i).saCon(1) = "" Or saSource(i).saCon(2) = "") Then
'                '
'            Else
'                .AddItem "Input from pin " & saSource(i).saCon(1)
'                .AddItem "Input from pin " & saSource(i).saCon(2)
'                .AddItem "Input from pin " & saSource(i).saCon(0) & _
'                         " (EX" & i & "IN) ORed with pin " & saSource(i).saCon(1)
'                .AddItem "Input from pin " & saSource(i).saCon(0) & _
'                         " (EX" & i & "IN) ANDed with pin " & saSource(i).saCon(1)
'                .AddItem "Input from pin " & saSource(i).saCon(1) & _
'                         " ORed with pin " & saSource(i).saCon(2)
'                .AddItem "Input from pin " & saSource(i).saCon(1) & _
'                         " ANDed with pin " & saSource(i).saCon(2)
'                .AddItem "Input from pin " & saSource(i).saCon(0) & _
'                         " (EX" & i & "IN) ORed with pin " & saSource(i).saCon(1) & _
'                         " ORed with pin " & saSource(i).saCon(2)
'            End If
'*************************************************************************************
            If (i < 4) Then
                If (r.v("EXISEL0_EXI" & i & "SS") = 3 Or r.v("EXISEL0_EXI" & i & "SS") = 4) Then
                    .ListIndex = r.v("EXISEL0_EXI" & i & "SS") - iAltB
                Else
                    .ListIndex = r.v("EXISEL0_EXI" & i & "SS")
                End If
            Else
                If (r.v("EXISEL1_EXI" & i & "SS") = 3 Or r.v("EXISEL1_EXI" & i & "SS") = 4) Then
                    .ListIndex = r.v("EXISEL1_EXI" & i & "SS") - iAltB
                Else
                    .ListIndex = r.v("EXISEL1_EXI" & i & "SS")
                End If
            End If

          End With

          With e("cboEXI_" & i)
            If (bDisabled) Then
              .DisabledTooltipText = TOOLTIP_DISABLED_IF
              If (Not (IsAlternateInputPinFree(r, "EX" & i & "IN"))) Then
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "EX" & i & "IN")
              End If
              If (r.v(sVarPre & "_Ex" & i & "_Use") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("ext. interrupt " & i & " is disabled (bit CC" & i & "IE = 0)")
              End If
              If (r.v("EXICON_EXI" & i & "ES") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("ext. interrupt " & i & " is disabled (bit EXI" & i & "ES = 0)")
              End If
            End If
          End With
        Next i

        '-------------------------------------------------------------------------
        ' control: lblEXICON_0 (show)
        '-------------------------------------------------------------------------
        For i = 0 To 5
          With c("lblEXICONI_" & i)
          bDisabled = (r.v(sVarPre & "_Ex" & i & "_Use") = 0 Or _
            Not (IsAlternateInputPinFree(r, "EX" & i & "IN")) Or _
                       r.v("EXICON_EXI" & i & "ES") = 0)
            .Enabled = Not (bDisabled)
          End With
        Next i

      End If


  OnShowPageSourceControl = True
  Exit Function

OnShowPageSourceControlError:
  ErrorBox "Can not show page.", Err.Description
  Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'EOPIC'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageEOPIC(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageEOPIC = False

  If (Not ps.AddPage("EOP Interrupt")) Then Exit Function

  OnLoadPageEOPIC = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageEOPIC(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageEOPIC = False
  
  If (Not ps.ExtenderCollection("EOP Interrupt").Loaded) And (Pagename = "EOP Interrupt") Then
    ps.ExtenderCollection("EOP Interrupt").Loaded = True
  

    '-------------------------------
    ' frame: frmEOPIC
    '-------------------------------
    If (Not ps.AddFrame("frmEOPIC", 100, 100, 4150, 1000, "End of PEC Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkEOPIE", 200, 350, 3800, 375, "Enable End of PEC interrupt (EOFIE)")) Then Exit Function

  End If
  OnChangingPageEOPIC = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageEOPIC(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageEOPICError

  OnShowPageEOPIC = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "EOP Interrupt") Then
    '-------------------------------------------------------------------------
    ' page: EOPIC (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkEOPIE (action)
        '---------------------------------------------------------------------
        Case "chkEOPIE"
            If (v(1) = 1) Then
                Call EnableSRN(r, "INT", "EOPIC", "EOP")
            Else
                Call DisableSRN(r, "INT", "EOPIC", "EOP")
            End If

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: EOPIC (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: chkEOPIE (show)
    '-------------------------------------------------------------------------
    With c("chkEOPIE")
        .Value = -CInt(r.v("EOPIC_IE") = 1)
    End With

  End If

  OnShowPageEOPIC = True
  Exit Function

OnShowPageEOPICError:
  ErrorBox "Can not show page.", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageFunctions(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageFunctions = False

  If (Not ps.AddPage("Functions")) Then Exit Function

  OnLoadPageFunctions = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageFunctions(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageFunctions = False

  Dim i As Integer
  Dim aFunctions(1 To 16) As String


  If (Not ps.ExtenderCollection("Functions").Loaded) And (Pagename = "Functions") Then
    ps.ExtenderCollection("Functions").Loaded = True

    '-------------------------------
    ' frame: fra_Init
    '-------------------------------
    If (Not ps.AddFrame("fra_Init", 100, 100, 4150, 700, CAPTION_FRA_USE_INIT)) Then Exit Function
      If (Not ps.AddCheck("chk_Init", 150, 275, 200, 275, "")) Then Exit Function
      If (Not ps.AddText("txt_Init", 400, 250, 3600, 325)) Then Exit Function

    '-------------------------------
    ' frame: fra_CFile
    '-------------------------------
    If (Not ps.AddFrame("fra_CFile", 4400, 100, 4150, 700, CAPTION_FRA_CFILE)) Then Exit Function
      If (Not ps.AddText("txt_CFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_CFile", 0, 200, 300, 1250, 275, CAPTION_LBL_CFILE)) Then Exit Function


    '-------------------------------
    ' frame: fraLibrary1
    '-------------------------------
    ' initialize the array
    For i = LBound(aFunctions) To UBound(aFunctions)
      aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = LBound(aFunctions)

    aFunctions(i) = "EnableInterrupt"
    i = i + 1
    aFunctions(i) = "DisableInterrupt"
    i = i + 1
    aFunctions(i) = "SetPecCount"
    i = i + 1
    aFunctions(i) = "SetPecSrcP"
    i = i + 1
    aFunctions(i) = "SetPecDesP"
    i = i + 1
    aFunctions(i) = "NMITrap"
    i = i + 1
    aFunctions(i) = "STKOFTrap"
    i = i + 1
    aFunctions(i) = "STKUFTrap"
    i = i + 1
    aFunctions(i) = "SOFTBRKTrap"
    i = i + 1
    aFunctions(i) = "ClassBTrap"
    i = i + 1
    aFunctions(i) = "ConfigureFastISR"
    i = i + 1
    aFunctions(i) = "EnableFastISR"
    i = i + 1
    aFunctions(i) = "DisableFastISR"
    i = i + 1

    If (Not ps.AddFrame("fraLibrary1", 100, 900, 4150, 4400, CAPTION_FRA_LIBRARY1)) Then Exit Function
      For i = LBound(aFunctions) To UBound(aFunctions)
        If Not (aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i


    '-------------------------------
    ' frame: fraLibrary2
    '-------------------------------
    ' initialize the array
    For i = LBound(aFunctions) To UBound(aFunctions)
      aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = LBound(aFunctions)
    aFunctions(i) = "Ex0"
    i = i + 1
    aFunctions(i) = "Ex1"
    i = i + 1
    aFunctions(i) = "Ex2"
    i = i + 1
    aFunctions(i) = "Ex3"
    i = i + 1
    aFunctions(i) = "Ex4"
    i = i + 1
    aFunctions(i) = "Ex5"
    i = i + 1
'    aFunctions(i) = "Ex6"
'    i = i + 1
'    aFunctions(i) = "Ex7"
'    i = i + 1
    aFunctions(i) = "EOP"
    i = i + 1

    If (Not ps.AddFrame("fraLibrary2", 4400, 900, 4150, 4400, CAPTION_FRA_LIBRARY2)) Then Exit Function
      For i = LBound(aFunctions) To UBound(aFunctions)
        If Not (aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i


  End If

  OnChangingPageFunctions = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageFunctions(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageFunctionsError

  OnShowPageFunctions = False
    
  Dim r         As ProjectData
  Dim c         As Collection
  Dim e         As Collection
  Dim bDisabled As Boolean
  Dim func      As FunctionClass
  Dim sName     As String
  Dim sRegPre   As String
  Dim sVarPre   As String
  Dim i         As Integer
  Dim d         As String
  Dim sFuncName As String
  Dim vIndex    As Variant

  vIndex = ps.Parameters.v("x")

  sVarPre = "INT" & vIndex

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass

  If (Pagename = "Functions") Then
    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    RefreshFunctionDescriptions(vIndex, func, r)

    If (Not UpdateFunction(sVarPre, ps, func, Controlname, v)) Then Exit Function

    ' this is a workaround for setting the var INT_NAME_SOFTBRKTrap for existing projects,
    ' because this var is added at a later time.
    If (r.v(sVarPre & "_NAME_SOFTBRKTrap") = "") Then
      r.v(sVarPre & "_NAME_SOFTBRKTrap") = sVarPre & "_viSOFTBRKTrap"
    End If

    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Set func = New FunctionClass
    RefreshFunctionDescriptions(vIndex, func, r)

    sName = sVarPre & "_NAME_Init"
    ' disable condition
    func.Disabled(sName) = False
    ' tooltip if control is disabled
    'func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_EnableInterrupt"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_DisableInterrupt"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_SetPecCount"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_SetPecSrcP"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_SetPecDesP"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

  For i = 0 To 5
    sName = sVarPre & "_NAME_Ex" & i
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, "CC1_CC" & (i + 8) & "IC", "Ex" & i)
  Next i

    sName = sVarPre & "_NAME_EOP"
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, "EOPIC", "EOP")

    sFuncName = "NMITrap"
    sName = sVarPre & "_NAME_" & sFuncName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFuncName = "STKOFTrap"
    sName = sVarPre & "_NAME_" & sFuncName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFuncName = "STKUFTrap"
    sName = sVarPre & "_NAME_" & sFuncName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFuncName = "SOFTBRKTrap"
    sName = sVarPre & "_NAME_" & sFuncName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFuncName = "ClassBTrap"
    sName = sVarPre & "_NAME_" & sFuncName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFuncName = "ConfigureFastISR"
    sName = sVarPre & "_NAME_" & sFuncName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFuncName = "DisableFastISR"
    sName = sVarPre & "_NAME_" & sFuncName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFuncName = "EnableFastISR"
    sName = sVarPre & "_NAME_" & sFuncName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    If (Not ShowFunction(sVarPre, ps, func, v)) Then Exit Function


  End If         ' if Pagename

  OnShowPageFunctions = True
  Exit Function

OnShowPageFunctionsError:
  ErrorBox "Can not show page", Err.Description
  Exit Function
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageParameters(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageParameters = False

  If (Not ps.AddPage("Parameters")) Then Exit Function

  OnLoadPageParameters = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageParameters(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageParameters = False

  If (Not ps.ExtenderCollection("Parameters").Loaded) And (Pagename = "Parameters") Then
    ps.ExtenderCollection("Parameters").Loaded = True

    '-------------------------------------------------------------------------
    ' frame: frmCAPCOMx_HFile
    '-------------------------------------------------------------------------
    If (Not ps.AddFrame("fra_HFile", 100, 100, 4150, 700, CAPTION_FRA_HFILE)) Then Exit Function
      If (Not ps.AddText("txt_HFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_HFile", 0, 200, 300, 1250, 300, CAPTION_LBL_HFILE)) Then Exit Function
    

  End If

  OnChangingPageParameters = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageParametersError
  OnShowPageParameters = False
    
  Dim r       As ProjectData
  Dim c       As Collection
  Dim e       As Collection
  Dim para    As ParameterClass
  Dim vIndex  As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sName   As String
  Dim d       As String
  Dim i       As Integer

  vIndex = ps.Parameters.v("x")
  sVarPre = "INT" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set para = New ParameterClass


  If (Pagename = "Parameters") Then

    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    RefreshParameterDescriptions(vIndex, para, r)

    If (Not UpdateParameter(sVarPre, ps, para, Controlname, v)) Then Exit Function


    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------

    Set para = New ParameterClass
    RefreshParameterDescriptions(vIndex, para, r)

'    sName = sIndex & "_PARA_T2"
'    ' disable condition
'    para.Disabled(sName) = True
'    ' tooltip if control is disabled
'    d = FormatDisabledTooltip("Fred ...")
'    para.DisabledToolTip(sName) = d

    If (Not ShowParameter(sVarPre, ps, para, v)) Then Exit Function

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

OnShowPageParametersError:
    ErrorBox "Can not show page", Err.Description
    Exit Function
End Function

