'#Uses "..\classes\FunctionClass.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:
'        CAPCOMx
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'CAPCOMx'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'                 
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0   ahe         18.05.01     final version for XC164CS
'
'        1.1   ahe         05.06.02     no changes
'        1.2   ste         18.12.02     final version for XC167CI
'
'*****************************************************************************


'*****************************************************************************
'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: Control1
    '-------------------------------------------------------------------------
    If (Not OnLoadPageControl1(ps)) Then Exit Function

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

    '-------------------------------------------------------------------------
    ' end of pages
    '-------------------------------------------------------------------------
    
    '-------------------------------------------------------------------------
    ' call function to initialize the menu
    '-------------------------------------------------------------------------
    If (Not InitMenu(ps, "CC6\CC6_INERRUPT_NODE")) 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 = "CCU" & vIndex

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

    '-------------------------------------------------------------------------
    'page: OnChangingPageControl2
    '-------------------------------------------------------------------------
    If (Not OnChangingPageControl2 (ps, Pagename)) 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 = "CCU" & vIndex


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

    '-------------------------------------------------------------------------
    ' page: OnShowPageControl2
    '-------------------------------------------------------------------------
    If (Not OnShowPageControl2(ps, Controlname, Pagename, 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

  

    OnClick = True
    Exit Function

OnClickError:
    Errorbox "Can not Text in OnClick.", Err.Description
    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, "CC6\CC6_INERRUPT_NODE")) Then Exit Function

    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
End Function
    


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

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

  OnLoadPageControl1 = False

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

  OnLoadPageControl1 = 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 OnChangingPageControl1(ps As Object, Pagename As String) As Boolean
  On Error Resume Next
  Dim sBit As String

  OnChangingPageControl1 = False
  
  If (Not ps.ExtenderCollection("Interrupt Control 1").Loaded) And (Pagename = "Interrupt Control 1") Then
    ps.ExtenderCollection("Interrupt Control 1").Loaded = True
  
    '-------------------------------
    ' frame: frmTxIE
    '-------------------------------
    If (Not ps.AddFrame("frmIC",100,100, 8475, 1200, _
        "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkIC", 200, 300, 4000, 300, _
            "Enable other interrupts / node I0 (IE)")) Then Exit Function
        If (Not ps.AddCheck("chkEIC", 200, 700, 4000, 300, _
            "Enable emergency interrupts / node I1 (IE)")) Then Exit Function
        If (Not ps.AddCheck("chkT12IC", 4400, 300, 4000, 300, _
            "Enable T12 interrupts / node I2 (IE)")) Then Exit Function
        If (Not ps.AddCheck("chkT13IC", 4400, 700, 4000, 300, _
            "Enable T13 interrupts / node I3 (IE)")) Then Exit Function

    sBit = "INPCC60"
    '-------------------------------
    ' frame: frmINPCC60
    '-------------------------------
    If (Not ps.AddFrame("frm" & sBit,100,1350, 8475, 1000, _
        "Interrupt Node Pointer for Channel 0 Interrupts (" & sBit & ")")) Then Exit Function
        If (Not ps.AddCombo("cbo" & sBit, 1525, 400, 5000, 315)) Then Exit Function
        If (Not ps.AddLabel("lbl" & sBit, 0, 200, 450, 1225, 330, _
            "Node selection")) Then Exit Function

    sBit = "INPCC61"
    '-------------------------------
    ' frame: frmINPCC60
    '-------------------------------
    If (Not ps.AddFrame("frm" & sBit,100,2400, 8475, 1000, _
        "Interrupt Node Pointer for Channel 1 Interrupts (" & sBit & ")")) Then Exit Function
        If (Not ps.AddCombo("cbo" & sBit, 1525, 400, 5000, 315)) Then Exit Function
        If (Not ps.AddLabel("lbl" & sBit, 0, 200, 450, 1225, 330, _
            "Node selection")) Then Exit Function

    sBit = "INPCC62"
    '-------------------------------
    ' frame: frmINPCC60
    '-------------------------------
    If (Not ps.AddFrame("frm" & sBit,100, 3450, 8475, 1000, _
        "Interrupt Node Pointer for Channel 2 Interrupts (" & sBit & ")")) Then Exit Function
        If (Not ps.AddCombo("cbo" & sBit, 1525, 400, 5000, 315)) Then Exit Function
        If (Not ps.AddLabel("lbl" & sBit, 0, 200, 450, 1225, 330, _
            "Node selection")) Then Exit Function



  End If
  OnChangingPageControl1 = 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 OnShowPageControl1(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageControl1Error

  OnShowPageControl1 = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim sRegPre As String
  Dim sVarPre As String
  Dim vIndex As Variant
  Dim bDisabled As Boolean
  Dim sDisabledTooltip As String
  Dim i AS Integer
  Dim saReg(0 To 3) As String
  Dim iCounter As Integer
  Dim saBit(0 To 2) as String
  Dim ii As Integer

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

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

  saReg(0) = sRegPre & "IC_IE"
  saReg(1) = sRegPre & "EIC_IE"
  saReg(2) = sRegPre & "T12IC_IE"
  saReg(3) = sRegPre & "T13IC_IE"

  saBit(0) = "INPCC60"
  saBit(1) = "INPCC61"
  saBit(2) = "INPCC62"

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

  If (Pagename = "Interrupt Control 1") Then
    '-------------------------------------------------------------------------
    ' page: Control (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkT12IC (action)
        '---------------------------------------------------------------------
        Case "chkT12IC"
            If (v(1) = 1) Then
               'only here
               Call SelectNodeIsr(r, vIndex, "T12IC")
               'only here

               Call EnableSRN(r, sVarPre, sRegPre & "T12IC", "NodeI2")
            Else
               Call DisableSRN(r, sVArPre, sRegPre & "T12IC", "NodeI2")

               'only here
               Call DeselectNodeIsr(r, vIndex, "T12IC")
               'only here

            End If

        '---------------------------------------------------------------------
        ' control: chkT12IC (action)
        '---------------------------------------------------------------------
        Case "chkT13IC"
            If (v(1) = 1) Then
               'only here
               Call SelectNodeIsr(r, vIndex, "T13IC")
               'only here

               Call EnableSRN(r, sVarPre, sRegPre & "T13IC", "NodeI3")
            Else
               Call DisableSRN(r, sVArPre, sRegPre & "T13IC", "NodeI3")

               'only here
               Call DeselectNodeIsr(r, vIndex, "T13IC")
               'only here
            End If

        '---------------------------------------------------------------------
        ' control: chkT12IC (action)
        '---------------------------------------------------------------------
        Case "chkEIC"
            If (v(1) = 1) Then
               'only here
               Call SelectNodeIsr(r, vIndex, "EIC")
               'only here
               Call EnableSRN(r, sVarPre, sRegPre & "EIC", "NodeI1")
            Else
               Call DisableSRN(r, sVArPre, sRegPre & "EIC", "NodeI1")

               'only here
               Call DeselectNodeIsr(r, vIndex, "EIC")
               'only here
            End If

        '---------------------------------------------------------------------
        ' control: chkT12IC (action)
        '---------------------------------------------------------------------
        Case "chkIC"
            If (v(1) = 1) Then
               'only here
               Call SelectNodeIsr(r, vIndex, "IC")
               'only here

               Call EnableSRN(r, sVarPre, sRegPre & "IC", "NodeI0")
            Else
               Call DisableSRN(r, sVArPre, sRegPre & "IC", "NodeI0")

               'only here
               Call DeselectNodeIsr(r, vIndex, "IC")
               'only here
            End If

        '---------------------------------------------------------------------
        ' control: cboINPCC60 (action)
        '---------------------------------------------------------------------
        Case "cboINPCC60"
            For i = 0 To 3
                If (v(1) = GetCboIsrNodeText(i)) Then
                    Call SetIsrNode(r, vIndex, "INPCC60", i)
                End If
            Next i

        '---------------------------------------------------------------------
        ' control: cboINPCC61 (action)
        '---------------------------------------------------------------------
        Case "cboINPCC61"
            For i = 0 To 3
                If (v(1) = GetCboIsrNodeText(i)) Then
                    Call SetIsrNode(r, vIndex, "INPCC61", i)
                End If
            Next i

        '---------------------------------------------------------------------
        ' control: cboINPCC62 (action)
        '---------------------------------------------------------------------
        Case "cboINPCC62"
            For i = 0 To 3
                If (v(1) = GetCboIsrNodeText(i)) Then
                    Call SetIsrNode(r, vIndex, "INPCC62", i)
                End If
            Next i


      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Control (show)
    '-------------------------------------------------------------------------
    bDisabled = (IsModuleClockDisabled(r, vIndex))
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmIC").Caption, c, e, bDisabled, sDisabledTooltip, "")
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                AllIsrDisabled(r, vIndex))
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    If (AllIsrDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & _
          FormatDisabledTooltip("no inerrupt node is enabled")
    End If
    
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmINPCC60").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmINPCC61").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmINPCC62").Caption, c, e, bDisabled, sDisabledTooltip, "")
    
    '-------------------------------------------------------------------------
    ' control: chkT12IC (show)
    '-------------------------------------------------------------------------
    With c("chkT12IC")
        .Value = -Cint(r.v(sRegPre & "T12IC_IE") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkT13IC (show)
    '-------------------------------------------------------------------------
    With c("chkT13IC")
        .Value = -Cint(r.v(sRegPre & "T13IC_IE") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkEIC (show)
    '-------------------------------------------------------------------------
    With c("chkEIC")
        .Value = -Cint(r.v(sRegPre & "EIC_IE") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkIC (show)
    '-------------------------------------------------------------------------
    With c("chkIC")
        .Value = -Cint(r.v(sRegPre & "IC_IE") = 1)
    End With

    For ii = 0 To 2
        '-------------------------------------------------------------------------
        ' control: cboxx (show)
        '-------------------------------------------------------------------------
        With c("cbo" & saBit(ii))
            .Clear
            If (bDisabled) Then
                .AddItem GetCboIsrNodeText(0)
                .ListIndex = 0
            Else

                i = 0
                iCounter = 0
                If (r.v(saReg(i)) = 1) Then 
                    .AddItem GetCboIsrNodeText(0)
                    iCounter = iCounter + 1
                End If
                i = i + 1

                If (r.v(saReg(i)) = 1) Then 
                    .AddItem GetCboIsrNodeText(1)
                    iCounter = iCounter + 1
                End If
                i = i + 1

                If (r.v(saReg(i)) = 1) Then 
                    .AddItem GetCboIsrNodeText(2)
                    iCounter = iCounter + 1
                End If
                i = i + 1

                If (r.v(saReg(i)) = 1) Then 
                    .AddItem GetCboIsrNodeText(3)
                    iCounter = iCounter + 1
                End If
            
                If (iCounter > 0) Then
                    iCounter = 0
                    If (r.v(sRegPre & "INP_" & saBit(ii)) = 0) Then 
                        .ListIndex = 0
                    Else
                        For i = 0 To (r.v(sRegPre & "INP_" & saBit(ii)) - 1)
                            If (r.v(saReg(i)) = 1) Then
                                iCounter = iCounter + 1
                            End If
                        Next i
                        .ListIndex = iCounter
                    End If
                End If

            End If

        End With

    Next ii
   
   


  End If

  OnShowPageControl1 = True
  Exit Function

OnShowPageControl1Error:
  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 'Control1'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageControl2(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageControl2 = False

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

  OnLoadPageControl2 = 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 OnChangingPageControl2(ps As Object, Pagename As String) As Boolean
  On Error Resume Next
  Dim sBit As String

  OnChangingPageControl2 = False
  
  If (Not ps.ExtenderCollection("Interrupt Control 2").Loaded) And (Pagename = "Interrupt Control 2") Then
    ps.ExtenderCollection("Interrupt Control 2").Loaded = True
  
    sBit = "INPCHE"
    '-------------------------------
    ' frame: frmINPCHE
    '-------------------------------
    If (Not ps.AddFrame("frm" & sBit,100,100, 8475, 1000, _
        "Interrupt Node Pointer for the CHE Interrupt (" & sBit & ")")) Then Exit Function
        If (Not ps.AddCombo("cbo" & sBit, 1525, 400, 5000, 315)) Then Exit Function
        If (Not ps.AddLabel("lbl" & sBit, 0, 200, 450, 1225, 330, _
            "Node selection")) Then Exit Function

    sBit = "INPERR"
    '-------------------------------
    ' frame: frmINPERR
    '-------------------------------
    If (Not ps.AddFrame("frm" & sBit,100,1150, 8475, 1000, _
        "Interrupt Node Pointer for Error Interrupts (" & sBit & ")")) Then Exit Function
        If (Not ps.AddCombo("cbo" & sBit, 1525, 400, 5000, 315)) Then Exit Function
        If (Not ps.AddLabel("lbl" & sBit, 0, 200, 450, 1225, 330, _
            "Node selection")) Then Exit Function

    sBit = "INPT12"
    '-------------------------------
    ' frame: frmINPT12
    '-------------------------------
    If (Not ps.AddFrame("frm" & sBit,100,2200, 8475, 1000, _
        "Interrupt Node Pointer for T12 Interrupts (" & sBit & ")")) Then Exit Function
        If (Not ps.AddCombo("cbo" & sBit, 1525, 400, 5000, 315)) Then Exit Function
        If (Not ps.AddLabel("lbl" & sBit, 0, 200, 450, 1225, 330, _
            "Node selection")) Then Exit Function

    sBit = "INPT13"
    '-------------------------------
    ' frame: frmINPT13
    '-------------------------------
    If (Not ps.AddFrame("frm" & sBit,100, 3250, 8475, 1000, _
        "Interrupt Node Pointer for T13 Interrupts (" & sBit & ")")) Then Exit Function
        If (Not ps.AddCombo("cbo" & sBit, 1525, 400, 5000, 315)) Then Exit Function
        If (Not ps.AddLabel("lbl" & sBit, 0, 200, 450, 1225, 330, _
            "Node selection")) Then Exit Function



  End If
  OnChangingPageControl2 = 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 OnShowPageControl2(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageControl2Error

  OnShowPageControl2 = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim sRegPre As String
  Dim sVarPre As String
  Dim vIndex As Variant
  Dim bDisabled As Boolean
  Dim sDisabledTooltip As String
  Dim i AS Integer
  Dim saReg(0 To 3) As String
  Dim iCounter As Integer
  Dim saBit(3 To 6) as String
  Dim ii As Integer

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

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

  saReg(0) = sRegPre & "IC_IE"
  saReg(1) = sRegPre & "EIC_IE"
  saReg(2) = sRegPre & "T12IC_IE"
  saReg(3) = sRegPre & "T13IC_IE"

  saBit(3) = "INPCHE"
  saBit(4) = "INPERR"
  saBit(5) = "INPT12"
  saBit(6) = "INPT13"

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

  If (Pagename = "Interrupt Control 2") Then
    '-------------------------------------------------------------------------
    ' page: Control (action)
    '-------------------------------------------------------------------------
    For ii = 3 To 6
        Select Case (Controlname)
            '---------------------------------------------------------------------
            ' control: cboINPCHE (action)
            '---------------------------------------------------------------------
            Case "cbo" & saBit(ii)
                For i = 0 To 3
                    If (v(1) = GetCboIsrNodeText(i)) Then
                        Call SetIsrNode(r, vIndex, saBit(ii), i)
                    End If
                Next i


          Case Else
        End Select

    Next ii

    '-------------------------------------------------------------------------
    ' page: Control (show)
    '-------------------------------------------------------------------------
    bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                AllIsrDisabled(r, vIndex))
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    If (AllIsrDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & _
          FormatDisabledTooltip("no inerrupt node is enabled")
    End If
    
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frm" & saBit(3)).Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frm" & saBit(4)).Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frm" & saBit(5)).Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frm" & saBit(6)).Caption, c, e, bDisabled, sDisabledTooltip, "")
    
    For ii = 3 To 6
        '-------------------------------------------------------------------------
        ' control: cboxx (show)
        '-------------------------------------------------------------------------
        With c("cbo" & saBit(ii))
            .Clear
            If (bDisabled) Then
                .AddItem GetCboIsrNodeText(0)
                .ListIndex = 0
            Else

                i = 0
                iCounter = 0
                If (r.v(saReg(i)) = 1) Then 
                    .AddItem GetCboIsrNodeText(0)
                    iCounter = iCounter + 1
                End If
                i = i + 1

                If (r.v(saReg(i)) = 1) Then 
                    .AddItem GetCboIsrNodeText(1)
                    iCounter = iCounter + 1
                End If
                i = i + 1

                If (r.v(saReg(i)) = 1) Then 
                    .AddItem GetCboIsrNodeText(2)
                    iCounter = iCounter + 1
                End If
                i = i + 1

                If (r.v(saReg(i)) = 1) Then 
                    .AddItem GetCboIsrNodeText(3)
                    iCounter = iCounter + 1
                End If
            
                If (iCounter > 0) Then
                    iCounter = 0
                    If (r.v(sRegPre & "INP_" & saBit(ii)) = 0) Then 
                        .ListIndex = 0
                    Else
                        For i = 0 To (r.v(sRegPre & "INP_" & saBit(ii)) - 1)
                            If (r.v(saReg(i)) = 1) Then
                                iCounter = iCounter + 1
                            End If
                        Next i
                        .ListIndex = iCounter
                    End If
                End If

            End If

        End With

    Next ii
   

  End If

  OnShowPageControl2 = True
  Exit Function

OnShowPageControl2Error:
  Errorbox "Can not show page.", Err.Description
  Exit Function
End Function

