Attribute VB_Name = "Module1"
'#Uses "..\classes\CC6FunctionClass.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\CC6Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
'#Uses "Include.inc"
'#Uses "8BitAdapter.inc"

Option Explicit

'*****************************************************************************
' Module:
'        CC6
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'CC6'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        0.1   als          20.11.04     initial version for XC866
'
'*****************************************************************************


'*****************************************************************************
'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("chkEINP0", 200, 300, 4000, 300, _
            "Enable interrupt node 0 (EINP0)")) Then Exit Function
        If (Not ps.AddCheck("chkEINP1", 200, 700, 4000, 300, _
            "Enable interrupt node 1 (EINP1)")) Then Exit Function
        If (Not ps.AddCheck("chkEINP2", 4400, 300, 4000, 300, _
            "Enable interrupt node 2 (EINP2)")) Then Exit Function
        If (Not ps.AddCheck("chkEINP3", 4400, 700, 4000, 300, _
            "Enable interrupt node 3 (EINP3)")) Then Exit Function

    sBit = "INPL_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 = "INPL_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 = "INPL_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 SharedInt As Integer
  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) = CORE_PREFIX & "IEN1_ECCIP0"
  saReg(1) = CORE_PREFIX & "IEN1_ECCIP1"
  saReg(2) = CORE_PREFIX & "IEN1_ECCIP2"
  saReg(3) = CORE_PREFIX & "IEN1_ECCIP3"

  saBit(0) = "INPL_INPCC60"
  saBit(1) = "INPL_INPCC61"
  saBit(2) = "INPL_INPCC62"

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

  If (Pagename = "Interrupt Control 1") Then
'      '-------------------------------------------------------------------------
'      ' page: Control (action)
'      '-------------------------------------------------------------------------
'      For i = 0 To 3
'          If (Controlname = "chkEINP" & i) Then
'              If (v(1) = 1) Then
'                 Call SelectNodeIsr(r, vIndex, CORE_PREFIX & "IEN1_ECCIP" & i)
'                 r.v(CORE_PREFIX & "IEN1_ECCIP" & i) = v(1)
'                 r.v("CCU6_USE_NodeI" & i) = v(1)
'              Else
'                 r.v(CORE_PREFIX & "IEN1_ECCIP" & i) = v(1)
'                 r.v("CCU6_USE_NodeI" & i) = v(1)
'                 Call DeselectNodeIsr(r, vIndex, CORE_PREFIX & "IEN1_ECCIP" & i)
'              End If
'          End If
'      Next i
    '-------------------------------------------------------------------------
      ' page: Control (action)
      '-------------------------------------------------------------------------
      For i = 0 To 3
       If (Controlname = "chkEINP" & i) Then
           If (IsCpuTypeOK(r)) Then
              If (v(1) = 1) Then
               If (i = 0) Then
                  If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR10_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                   End If
               ElseIf (i = 1) Then
                   If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR11_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                   End If
               ElseIf (i = 2) Then
                   If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR12_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                   End If
               ElseIf (i = 3) Then
                   If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR13_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                   End If
               End If
               Call SelectNodeIsr(r, vIndex, CORE_PREFIX & "IEN1_ECCIP" & i)
               r.v(CORE_PREFIX & "IEN1_ECCIP" & i) = v(1)
               r.v("CCU6_USE_NodeI" & i) = v(1)
              Else
                 r.v(CORE_PREFIX & "IEN1_ECCIP" & i) = v(1)
                 r.v("CCU6_USE_NodeI" & i) = v(1)
                 Call DeselectNodeIsr(r, vIndex, CORE_PREFIX & "IEN1_ECCIP" & i)
              End If
           Else
             If (v(1) = 1) Then
                 Call SelectNodeIsr(r, vIndex, CORE_PREFIX & "IEN1_ECCIP" & i)
                 r.v(CORE_PREFIX & "IEN1_ECCIP" & i) = v(1)
                 r.v("CCU6_USE_NodeI" & i) = v(1)
             Else
                r.v(CORE_PREFIX & "IEN1_ECCIP" & i) = v(1)
                r.v("CCU6_USE_NodeI" & i) = v(1)
                Call DeselectNodeIsr(r, vIndex, CORE_PREFIX & "IEN1_ECCIP" & i)
             End If
          End If
       End If
      Next i

      For ii = 0 To 2
          If (Controlname = "cbo" & saBit(ii)) Then
              For i = 0 To 3
                  If (v(1) = GetCboIsrNodeText(i)) Then
                      Call SetIsrNode(r, vIndex, saBit(ii), i)
                  End If
              Next i
          End If
      Next ii

    '-------------------------------------------------------------------------
    ' 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 interrupt node is enabled")
    End If
    
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmINPL_INPCC60").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmINPL_INPCC61").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmINPL_INPCC62").Caption, c, e, bDisabled, sDisabledTooltip, "")
    
    For i = 0 To 3
        '-------------------------------------------------------------------------
        ' control: chkx (show)
        '-------------------------------------------------------------------------
        With c("chkEINP" & i)
            .Value = -CInt(r.v(saReg(i)) = 1)
        End With
    Next i

    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 & saBit(ii)) = 0) Then
                        .ListIndex = 0
                    Else
                        For i = 0 To (r.v(sRegPre & 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 = "INPL_INPCHE"
    '-------------------------------
    ' frame: frmINPCHE
    '-------------------------------
    If (Not ps.AddFrame("frm" & sBit, 100, 100, 8475, 1000, _
        "Interrupt Node Pointer for the CHE, STR 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 = "INPH_INPERR"
    '-------------------------------
    ' frame: frmINPERR
    '-------------------------------
    If (Not ps.AddFrame("frm" & sBit, 100, 1150, 8475, 1000, _
        "Interrupt Node Pointer for TRPF, WHE, IDLE 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 = "INPH_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 = "INPH_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) = CORE_PREFIX & "IEN1_ECCIP0"
  saReg(1) = CORE_PREFIX & "IEN1_ECCIP1"
  saReg(2) = CORE_PREFIX & "IEN1_ECCIP2"
  saReg(3) = CORE_PREFIX & "IEN1_ECCIP3"

  saBit(3) = "INPL_INPCHE"
  saBit(4) = "INPH_INPERR"
  saBit(5) = "INPH_INPT12"
  saBit(6) = "INPH_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 interrupt 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 & saBit(ii)) = 0) Then
                        .ListIndex = 0
                    Else
                        For i = 0 To (r.v(sRegPre & 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

