Attribute VB_Name = "Pages"
'#Uses "Const.inc"
'#Uses "Global.inc"
'#Uses "Format.inc"
'#Uses "..\classes\InterruptClass.cls"
'#Uses "..\classes\ModuleClass.cls"
'#Uses "..\classes\ManualLinkClass.cls"
Option Explicit
'*****************************************************************************
' Module:
'        Pages.inc
'-----------------------------------------------------------------------------
' Description:
'          This module contains constants and global functions for
'          global pages (Interrupt, Notes ..)
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        3.0  ahe            28.07.00    final version for C161PI
'                                        - changes 'As ManualLinks' to
'                                          'As Object'
'
'             ahe            04.09.00    - changes PEC-frame
'                                          width from 8425 to 8450
'
'        ---------------------------------------------------------------------
'        4.0  ahe            23.05.01    final version for Pegasus
'                                         - changed Interrupt page
'                                         - changed PEC page
'                                         - changed Note page
'
'*****************************************************************************

'*****************************************************************************
' @Global Constants
'*****************************************************************************


'*****************************************************************************
' @Global Types
'*****************************************************************************
' this type is used for the manual links in the function LoadMenu and
' InitMenue
Type ManualLinkType
  sCaption As String     ' the caption AND key for the manual link
  bGroup As Boolean      ' specifies if a new group should be created (draws
                         ' a line about this link)
End Type

Dim bFirstTime As Boolean

'*****************************************************************************
' @Global Functions
'*****************************************************************************


'*****************************************************************************
' @bfunc   Public | OnLoadPageInterrupts | Boolean |
'
'-----------------------------------------------------------------------------
'          This function adds a page to the peripheral.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
'
'*****************************************************************************
Public Function OnLoadPageInterrupts(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageInterrupts = False

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

  OnLoadPageInterrupts = True
End Function


'*****************************************************************************
' @bfunc   Public | OnChangingPageInterrupts | Boolean |
'
'-----------------------------------------------------------------------------
'          This function makes all activities for the interrupt page in each
'          module function OnChangingPage.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
' @bparm   | Pagename | String | current page name
'
'*****************************************************************************
Public Function OnChangingPageInterrupts(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next
  OnChangingPageInterrupts = False

  Dim e As Collection

  Set e = ps.ExtenderCollection

  If (Not e("Interrupts").Loaded) And (Pagename = "Interrupts") Then
    e("Interrupts").Loaded = True
    If (Not ps.AddIRTab16("InterruptTable")) Then Exit Function
    If (Not ps.AddFrame("Interrupts_1", 0, 0, 0, 0, "Interrupts")) Then Exit Function
  End If

  OnChangingPageInterrupts = True
End Function


'*****************************************************************************
' @bfunc   Public | OnShowPageInterrupts | Boolean |
'
'-----------------------------------------------------------------------------
'          This function makes all activities for the interrupt page in each
'          module function OnShow.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
' @bparm   | Controlname | String | current control name
' @bparm   | v() | Variant | values for the controlls
' @bparm   | SeekName | String | name for searching in the interrupt list
' @bparm   | Pagename | String | current page name
'
'*****************************************************************************
Public Function OnShowPageInterrupts(ps As Peripherals, Controlname As String, v() As Variant, SeekName As String, Pagename As String) As Boolean
  On Error Resume Next
  OnShowPageInterrupts = False
  
    Dim r As ProjectData
    Dim p As Parameters
    Dim c As Collection
    Dim i As Integer
    Dim cp As DAvECollection
    Dim ir As InterruptClass
    Dim iOldChannel As Integer
    Dim iOldISRPosition As Integer
    Dim iChannel As Integer
    Dim iISRPosition As Integer

    Dim IntName As Variant
    Dim IntLevel As Variant
    Dim IntGroup As Variant
    Dim IntOldLevel As Variant
    Dim IntOldGroup As Variant

    Set r = ps.ProjectData
    Set p = ps.Parameters
    Set c = ps.ControlCollection
    Set cp = ObjectCollection("IRSOURCES")

    IntName = v(1)
    IntLevel = v(2)
    IntGroup = v(3)
    IntOldLevel = v(4)
    IntOldGroup = v(5)

    If (IntOldLevel = 14) Then
        iOldChannel = IntOldGroup
        iOldISRPosition = 0
    ElseIf (IntOldLevel = 12) Then
        iOldChannel = IntOldGroup
        iOldISRPosition = 1
    ElseIf (IntOldLevel = 10) Then
        iOldChannel = IntOldGroup
        iOldISRPosition = 2
    ElseIf (IntOldLevel = 8) Then
        iOldChannel = IntOldGroup
        iOldISRPosition = 3
    ElseIf (IntOldLevel = 15) Then
        iOldChannel = IntOldGroup + 4
        iOldISRPosition = 0
    ElseIf (IntOldLevel = 13) Then
        iOldChannel = IntOldGroup + 4
        iOldISRPosition = 1
    ElseIf (IntOldLevel = 11) Then
        iOldChannel = IntOldGroup + 4
        iOldISRPosition = 2
    ElseIf (IntOldLevel = 9) Then
        iOldChannel = IntOldGroup + 4
        iOldISRPosition = 3
    End If

    If (IntLevel = 14) Then
        iChannel = IntGroup
        iISRPosition = 0
    ElseIf (IntLevel = 12) Then
        iChannel = IntGroup
        iISRPosition = 1
    ElseIf (IntLevel = 10) Then
        iChannel = IntGroup
        iISRPosition = 2
    ElseIf (IntLevel = 8) Then
        iChannel = IntGroup
        iISRPosition = 3
    ElseIf (IntLevel = 15) Then
        iChannel = IntGroup + 4
        iISRPosition = 0
    ElseIf (IntLevel = 13) Then
        iChannel = IntGroup + 4
        iISRPosition = 1
    ElseIf (IntLevel = 11) Then
        iChannel = IntGroup + 4
        iISRPosition = 2
    ElseIf (IntLevel = 9) Then
        iChannel = IntGroup + 4
        iISRPosition = 3
    End If
  
    If (Controlname = "InterruptTable") Then
        r.v(cp(IntName).LevelName) = IntLevel
        r.v(cp(IntName).GroupName) = IntGroup

        If (IntOldLevel >= 8 And IntOldGroup <= 3) Then

            'ahe
            Call SetPECChannelToDefault(r, iOldChannel)
            'ahe

        End If

        If (IntLevel >= 8 And IntGroup <= 3) Then
            r.v("PEC_CHANNEL_" & iChannel & "_" & iISRPosition) = IntName
            If (r.v("PECC" & iChannel & "_PLEV") = iISRPosition) Then
                r.v("PEC_CHANNEL_" & iChannel) = IntName
            End If
        End If
        
    ElseIf (Pagename = "Interrupts") Then
        
        With c("InterruptTable")
            .Freeze
            .Clear
          For Each ir In cp
            If (r.v(ir.Enabled) = 1) Then
              .InterruptLevel = r.v(ir.LevelName)
              .GroupLevel = r.v(ir.GroupName)
              .Sourcename = ir.IntName
            End If
          Next ir
            .SeekList SeekName
            .Melt
        End With
    End If
  

  OnShowPageInterrupts = True
End Function

'*****************************************************************************
' @bfunc   Public | OnLoadPageInterrupts_32 | Boolean |
'
'-----------------------------------------------------------------------------
'          This function adds a page to the peripheral.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
'
'*****************************************************************************
Public Function OnLoadPageInterrupts_32(ps As Peripherals, iGPX As Integer) As Boolean
  On Error Resume Next
  OnLoadPageInterrupts_32 = False
  Dim sInt As String

  If (iGPX = 0) Then
      sInt = "Interrupts"
  Else
      sInt = "Int. Extension"
  End If

  If (Not ps.AddPage(sInt)) Then Exit Function
  OnLoadPageInterrupts_32 = True
End Function


'*****************************************************************************
' @bfunc   Public | OnChangingPageInterrupts_32 | Boolean |
'
'-----------------------------------------------------------------------------
'          This function makes all activities for the interrupt page in each
'          module function OnChangingPage.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
' @bparm   | Pagename | String | current page name
'
'*****************************************************************************
Public Function OnChangingPageInterrupts_32(ps As Peripherals, Pagename As String, iGPX As Integer) As Boolean
  On Error Resume Next
  OnChangingPageInterrupts_32 = False

  Dim r As ProjectData
  Dim e As Collection
  Dim sInt As String

  If (iGPX = 0) Then
      sInt = "Interrupts"
  Else
      sInt = "Int. Extension"
  End If

  Set r = ps.ProjectData

  Set e = ps.ExtenderCollection

  If (Not e(sInt).Loaded) And (Pagename = sInt) Then
    e(sInt).Loaded = True
    If (Not ps.AddIRTab32("InterruptTable" & iGPX)) Then Exit Function
    bFirstTime = True
  End If

  OnChangingPageInterrupts_32 = True
End Function


'*****************************************************************************
' @bfunc   Public | OnShowPageInterrupts_32 | Boolean |
'
'-----------------------------------------------------------------------------
'          This function makes all activities for the interrupt page in each
'          module function OnShow.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
' @bparm   | Controlname | String | current control name
' @bparm   | v() | Variant | values for the controlls
' @bparm   | SeekName | String | name for searching in the interrupt list
' @bparm   | Pagename | String | current page name
'
'*****************************************************************************
Public Function OnShowPageInterrupts_32(ps As Peripherals, Controlname As String, v() As Variant, SeekName As String, Pagename As String, iGPX As Integer) As Boolean
  On Error Resume Next
  OnShowPageInterrupts_32 = False
  
    Dim r As ProjectData
    Dim p As Parameters
    Dim c As Collection
    Dim cp As DAvECollection
    Dim ir As InterruptClass
    Dim vHighestLevel As Variant

    Dim iOldChannel As Integer
    Dim iOldISRPosition As Integer
    Dim iChannel As Integer
    Dim iISRPosition As Integer

    Dim IntName As Variant
    Dim IntLevel As Variant
    Dim IntGroup As Variant
    Dim IntOldLevel As Variant
    Dim IntOldGroup As Variant
    Dim f(1 To 4) As Integer
    Dim s(1 To 4) As String

    Dim sInt As String

    If (iGPX = 0) Then
        sInt = "Interrupts"
    Else
        sInt = "Int. Extension"
    End If


    Set r = ps.ProjectData
    Set p = ps.Parameters
    Set c = ps.ControlCollection
    Set cp = ObjectCollection("IRSOURCES")

    If (Pagename = sInt) Then


      IntName = v(1)
      IntLevel = v(2)
      IntGroup = v(3)
      IntOldLevel = v(4)
      IntOldGroup = v(5)

      If (IntOldLevel = 14) Then
          iOldChannel = IntOldGroup
          iOldISRPosition = 0
      ElseIf (IntOldLevel = 12) Then
          iOldChannel = IntOldGroup
          iOldISRPosition = 1
      ElseIf (IntOldLevel = 10) Then
          iOldChannel = IntOldGroup
          iOldISRPosition = 2
      ElseIf (IntOldLevel = 8) Then
          iOldChannel = IntOldGroup
          iOldISRPosition = 3
      ElseIf (IntOldLevel = 15) Then
          iOldChannel = IntOldGroup + 4
          iOldISRPosition = 0
      ElseIf (IntOldLevel = 13) Then
          iOldChannel = IntOldGroup + 4
          iOldISRPosition = 1
      ElseIf (IntOldLevel = 11) Then
          iOldChannel = IntOldGroup + 4
          iOldISRPosition = 2
      ElseIf (IntOldLevel = 9) Then
          iOldChannel = IntOldGroup + 4
          iOldISRPosition = 3
      End If

      If (IntLevel = 14) Then
          iChannel = IntGroup
          iISRPosition = 0
      ElseIf (IntLevel = 12) Then
          iChannel = IntGroup
          iISRPosition = 1
      ElseIf (IntLevel = 10) Then
          iChannel = IntGroup
          iISRPosition = 2
      ElseIf (IntLevel = 8) Then
          iChannel = IntGroup
          iISRPosition = 3
      ElseIf (IntLevel = 15) Then
          iChannel = IntGroup + 4
          iISRPosition = 0
      ElseIf (IntLevel = 13) Then
          iChannel = IntGroup + 4
          iISRPosition = 1
      ElseIf (IntLevel = 11) Then
          iChannel = IntGroup + 4
          iISRPosition = 2
      ElseIf (IntLevel = 9) Then
          iChannel = IntGroup + 4
          iISRPosition = 3
      End If
  
  
      '-------------------------------------------------------------------------
      ' page: Interrupts (action)
      '-------------------------------------------------------------------------
      If (Controlname = "InterruptTable" & iGPX) Then
          r.v(cp(IntName).LevelName) = IntLevel
          r.v(cp(IntName).GroupName) = IntGroup
          If (IntLevel = 0) Then
              r.v(cp(IntName).GPXName) = 0
          Else
              r.v(cp(IntName).GPXName) = iGPX
          End If
 
     
           
            If (IntOldLevel = 12) Then
               If iGPX = 0 Then
                   If r.v("BNK0_GPR" & IntOldGroup) = 0 And r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) > 0 Then
                   r.v("INT_USE_FAST" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1)) = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_GPX") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_ILVL") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_GLVL") = 0
                   Else
                    r.v("BNK0_GPR" & IntOldGroup) = 0
                   End If
                   r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) = 0
               Else
                   If r.v("BNK2_GPR" & IntOldGroup) = 0 And r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) > 0 Then
                   r.v("INT_USE_FAST" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1)) = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_GPX") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_ILVL") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_GLVL") = 0
                   Else
                    r.v("BNK2_GPR" & IntOldGroup) = 0
                   End If
                   r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) = 0
              End If
           End If


         If (IntOldLevel = 13) Then
               If iGPX = 0 Then
                   If r.v("BNK0_GPR" & (IntOldGroup + 4)) = 0 And r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) > 0 Then
                   r.v("INT_USE_FAST" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1)) = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_GPX") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_ILVL") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_GLVL") = 0
                   Else
                    r.v("BNK0_GPR" & (IntOldGroup + 4)) = 0
                   End If
                   r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) = 0
               Else
                   If r.v("BNK2_GPR" & (IntOldGroup + 4)) = 0 And r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) > 0 Then
                   r.v("INT_USE_FAST" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1)) = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_GPX") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_ILVL") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_GLVL") = 0
                   Else
                    r.v("BNK2_GPR" & (IntOldGroup + 4)) = 0
                   End If
                   r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) = 0
              End If
           End If
           
            If (IntOldLevel = 14) Then
               If iGPX = 0 Then
                   If r.v("BNK1_GPR" & IntOldGroup) = 0 And r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) > 0 Then
                   r.v("INT_USE_FAST" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1)) = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_GPX") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_ILVL") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_GLVL") = 0
                   
                   Else
                    r.v("BNK1_GPR" & IntOldGroup) = 0
                   End If
                   r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) = 0
               Else
                   If r.v("BNK3_GPR" & IntOldGroup) = 0 And r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) > 0 Then
                   r.v("INT_USE_FAST" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1)) = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_GPX") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_ILVL") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) - 1) & "CSP_GLVL") = 0
                   Else
                    r.v("BNK3_GPR" & IntOldGroup) = 0
                   End If
                   r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) = 0
              End If
           End If
           
           If (IntOldLevel = 15) Then
               If iGPX = 0 Then
                   If r.v("BNK1_GPR" & (IntOldGroup + 4)) = 0 And r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) > 0 Then
                   r.v("INT_USE_FAST" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1)) = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_GPX") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_ILVL") = 0
                   r.v("FINT" & (r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) - 1) & "CSP_GLVL") = 0
                   Else
                    r.v("BNK1_GPR" & (IntOldGroup + 4)) = 0
                   End If
                   r.v("INT_LEV" & IntOldLevel & "_GRP" & IntOldGroup) = 0
               Else
                   If r.v("BNK3_GPR" & (IntOldGroup + 4)) = 0 And r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) > 0 Then
                   r.v("INT_USE_FAST" & r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4) - 1)) = 0
                   r.v("FINT" & r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
                   r.v("FINT" & r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4) - 1) & "CSP_GPX") = 0
                   r.v("FINT" & r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4) - 1) & "CSP_ILVL") = 0
                   r.v("FINT" & r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4) - 1) & "CSP_GLVL") = 0
                   Else
                    r.v("BNK3_GPR" & (IntOldGroup + 4)) = 0
                   End If
                   r.v("INT_LEV" & IntOldLevel & "_GRP" & (IntOldGroup + 4)) = 0
              End If
           End If


''''
''''
''''
''''
''''
''''
''''            If (IntOldLevel = 13) Then
''''               If IntOldGroup <= 3 Then
''''                   r.v("BNK0_GPR" & r.v(ir.GroupName)) = 0
''''                   r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & r.v(ir.GroupName)) = 0
''''
''''               Else
''''                    r.v("BNK2_GPR" & (r.v(ir.GroupName) + 4)) = 0
''''                    r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & (r.v(ir.GroupName) + 4)) = 0
''''
''''              End If
''''           End If
''''
''''           If (IntOldLevel = 14) Then
''''               If IntOldGroup <= 3 Then
''''                   r.v("BNK1_GPR" & r.v(ir.GroupName)) = 0
''''                   r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & r.v(ir.GroupName)) = 0
''''                 Else
''''
''''                      r.v("BNK3_GPR" & (r.v(ir.GroupName) + 4)) = 0
''''                      r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & (r.v(ir.GroupName) + 4)) = 0
''''
''''                  End If
''''                End If
''''
''''            If (IntOldLevel = 15) Then
''''               If IntOldGroup <= 3 Then
''''                  r.v("BNK1_GPR" & (r.v(ir.GroupName) + 4)) = 0
''''                  r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & r.v(ir.GroupName)) = 0
''''
''''               Else
''''
''''                r.v("BNK3_GPR" & (r.v(ir.GroupName) + 4)) = 0
''''                r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & (r.v(ir.GroupName) + 4)) = 0
''''
''''                  End If
''''                End If




          ' if old level and group was a PEC-channel
          If (IntOldLevel >= 8 And iGPX = 0) Then
              Call SetPECChannelToDefault(r, iOldChannel)
          End If

          ' if level and group are a PEC-channel
          If (IntLevel >= 8 And iGPX = 0) Then
              r.v("PEC_CHANNEL_" & iChannel & "_" & iISRPosition) = IntName
              If (r.v("PECC" & iChannel & "_PLEV") = iISRPosition) Then
                  r.v("PEC_CHANNEL_" & iChannel) = IntName
              End If
          End If

      End If

      '-------------------------------------------------------------------------
      ' page: Interrupts (show)
      '-------------------------------------------------------------------------
      f(1) = 16
      f(2) = 16
      f(3) = 16
      f(4) = 16

      s(1) = "Group " & iGPX * 4
      s(2) = "Group " & iGPX * 4 + 1
      s(3) = "Group " & iGPX * 4 + 2
      s(4) = "Group " & iGPX * 4 + 3


      With c("InterruptTable" & iGPX)
        .Freeze
        .Clear
        .Init s, f

        ' for each interrupt in the collection
        ' look if the interrupt is enabled, is so then
        ' set the properties
        vHighestLevel = 0
        For Each ir In cp
          If (r.v(ir.Enabled) = 1) Then
            'if level = 0
            If (r.v(ir.LevelName) = 0) Then
                .Level = r.v(ir.LevelName)
                .Group = r.v(ir.GroupName)
                .Sourcename = ir.IntName
            
            'if level > 0
            Else
                'only if GPX is OK
                If (r.v(ir.GPXName) = iGPX) Then
                    .Level = r.v(ir.LevelName)
                    If (r.v(ir.LevelName) > vHighestLevel) Then
                      vHighestLevel = r.v(ir.LevelName)
                    End If
                    .Group = r.v(ir.GroupName)
                    .Sourcename = ir.IntName
                End If
            End If

            
          End If
        Next ir
        .SeekList SeekName
        If (bFirstTime = True) Then
          .TopLevel = vHighestLevel
          bFirstTime = False
        End If
        .Melt
      End With
    End If

  OnShowPageInterrupts_32 = True
End Function

'*****************************************************************************
' @bfunc   Public | OnLoadPagePEC | Boolean |
'
'-----------------------------------------------------------------------------
'          This function adds a page to the peripheral.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
'
'*****************************************************************************
Public Function OnLoadPagePEC(ps As Peripherals) As Boolean
  OnLoadPagePEC = False

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

  OnLoadPagePEC = True
End Function


'*****************************************************************************
' @bfunc   Public | OnChangingPagePEC | Boolean |
'
'-----------------------------------------------------------------------------
'          This function makes all activities for the PEC page in each
'          module function OnChangingPage.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
' @bparm   | Pagename | String | current page name
'
'*****************************************************************************
Public Function OnChangingPagePEC(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next
  OnChangingPagePEC = False

  Dim i As Integer
  Dim e As Collection
  Dim asHelp(0 To 7) As String

  asHelp(0) = "Group = 0 and Level = 14/12/10/8"
  asHelp(1) = "Group = 1 and Level = 14/12/10/8"
  asHelp(2) = "Group = 2 and Level = 14/12/10/8"
  asHelp(3) = "Group = 3 and Level = 14/12/10/8"
  asHelp(4) = "Group = 0 and Level = 15/13/11/9"
  asHelp(5) = "Group = 1 and Level = 15/13/11/9"
  asHelp(6) = "Group = 2 and Level = 15/13/11/9"
  asHelp(7) = "Group = 3 and Level = 15/13/11/9"


  Set e = ps.ExtenderCollection

   If (Not e("PEC").Loaded) And (Pagename = "PEC") Then
    e("PEC").Loaded = True
    If (Not ps.AddFrame("PEC_Channels", 100, 100, 8450, 5150, "PEC Channels")) Then Exit Function
    For i = 0 To 7
      If (Not ps.AddButton("cmdPEC" & i, 200, 400 + i * 600, 2100, 400, "Configure PEC channel " & i)) Then Exit Function
      If (Not ps.AddLabel("lblPEClbl" & i, 0, 2450, 400 + i * 600, 2600, 400, "Interrupt source for " & vbCrLf & "" & asHelp(i))) Then Exit Function

      If (Not ps.AddCombo("cboISR" & i, 5200, 400 + i * 600, 2400, 315)) Then Exit Function

      'if (Not ps.AddLabel("lblPEC" & i,1 , 3800 , 450 + i * 600, 2000, 315)) Then Exit Function

    Next i
  End If

  OnChangingPagePEC = True
End Function


'*****************************************************************************
' @bfunc   Public | OnShowPagePEC | Boolean |
'
'-----------------------------------------------------------------------------
'          This function makes all activities for the PEC page in each
'          module function OnShow.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
' @bparm   | Controlname | String | current control name
' @bparm   | Pagename | String | current page name
'
'*****************************************************************************
Public Function OnShowPagePEC(ps As Peripherals, Controlname As String, v As Variant, Pagename As String) As Boolean
  On Error Resume Next
  OnShowPagePEC = False

  Dim r As ProjectData
  Dim c As Collection
  Dim i As Integer
  Dim iPosition As Integer
  Dim iChannel As Integer
  Dim cp As DAvECollection
  Dim sIntName As String

  Dim ir As InterruptClass


  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set cp = ObjectCollection("IRSOURCES")


  If (Pagename = "PEC") Then
      For iChannel = 0 To 7

          '---------------------------------------------------------------------
          ' control: cboISR (action)
          '---------------------------------------------------------------------
          If (Controlname = "cboISR" & iChannel) Then
              For i = 0 To 3
                  sIntName = r.v("PEC_CHANNEL_" & iChannel & "_" & i)
                  If (v(1) = sIntName) Then
                      If (sIntName = "none") Then
                          r.v("PECC" & iChannel & "_PLEV") = i
                          Call SetPECChannelToDefault(r, iChannel)
                          Exit For
                      Else
                          If (r.v(cp(sIntName).LevelName) = 15 Or _
                            r.v(cp(sIntName).LevelName) = 14) Then
                              r.v("PECC" & iChannel & "_PLEV") = 0
                          ElseIf (r.v(cp(sIntName).LevelName) = 13 Or _
                            r.v(cp(sIntName).LevelName) = 12) Then
                              r.v("PECC" & iChannel & "_PLEV") = 1
                          ElseIf (r.v(cp(sIntName).LevelName) = 11 Or _
                            r.v(cp(sIntName).LevelName) = 10) Then
                              r.v("PECC" & iChannel & "_PLEV") = 2
                          ElseIf (r.v(cp(sIntName).LevelName) = 9 Or _
                            r.v(cp(sIntName).LevelName) = 8) Then
                              r.v("PECC" & iChannel & "_PLEV") = 3
                          End If
                          r.v("PEC_CHANNEL_" & iChannel) = sIntName
                      End If
                  End If
              Next i
          End If

          '-------------------------------------------------------------------------
          ' control: cboISR (show)
          '-------------------------------------------------------------------------
          With c("cboISR" & iChannel)
              .Clear

              For i = 0 To 3
                  .AddItem r.v("PEC_CHANNEL_" & iChannel & "_" & i)
              Next i
              .ListIndex = r.v("PECC" & iChannel & "_PLEV")
              
          End With

      Next iChannel
  End If

  OnShowPagePEC = True
End Function


'*****************************************************************************
' @bfunc   Public | OnClickPagePEC | Boolean |
'
'-----------------------------------------------------------------------------
'          This function makes all activities for the PEC page in each
'          module function OnClick.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
' @bparm   | Controlname | String | current control name
'
'*****************************************************************************
Public Function OnClickPagePEC(p As Peripherals, Controlname As String) As Boolean
  On Error Resume Next
  OnClickPagePEC = False

  Dim i As Integer
  Dim np As Peripherals

  For i = 0 To 7
    If (Controlname = "cmdPEC" & i) Then
        Set np = New Peripherals
        np.Parameters.Add ("x")
        np.Parameters.v("x") = i
        np.Parameters.Add ("Channel")
        np.Parameters.v("Channel") = i
        np.Parameters.Add ("c")
        np.Parameters.v("c") = ""
        Set np.ProjectData = p.ProjectData
        np.Caption = "Configure PEC Channel " & i
        np.Scriptfile = DefGetPath("Scripts") & "\PEC\PEC.DAVE"
        np.Show
    End If
  Next i

  OnClickPagePEC = True
End Function


'*****************************************************************************
' @bfunc   Public | OnLoadPageNotes | Boolean |
'
'-----------------------------------------------------------------------------
'          This function adds a page to the peripheral.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
'
'*****************************************************************************
Public Function OnLoadPageNotes(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageNotes = False

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

  OnLoadPageNotes = True
End Function


'*****************************************************************************
' @bfunc   Public | OnChangingPageNotes | Boolean |
'
'-----------------------------------------------------------------------------
'          This function makes all activities for the Notes page in each
'          module function OnChangingPage.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
' @bparm   | PageName | String | current page name
' @bparm   | ModuleName | String | current module name
'
'*****************************************************************************
Public Function OnChangingPageNotes(ps As Peripherals, Pagename As String, ModuleName As String) As Boolean
  On Error Resume Next
  OnChangingPageNotes = False

  Dim i As Integer
  Dim e As Collection
  Dim s As String

  Set e = ps.ExtenderCollection

  If (Not e("Notes").Loaded) And (Pagename = "Notes") Then
    e("Notes").Loaded = True
    s = ModuleName & "_Notes"
    If (Not ps.AddFrame("fra" & s, 100, 100, 8450, 5200, "")) Then Exit Function
      If (Not ps.AddText("txt" & s, 1825, 600, 6000, 3780)) Then Exit Function
      If (Not ps.AddLabel("lbl" & s, 0, 200, 600, 1575, 380, "Insert Notes:")) Then Exit Function
  End If

  OnChangingPageNotes = True
End Function


'*****************************************************************************
' @bfunc   Public | OnShowPageNotes | Boolean |
'
'-----------------------------------------------------------------------------
'          This function makes all activities for the Notes page in each
'          module function OnShow.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
' @bparm   | Controlname | String | current control name
' @bparm   | Pagename | String | current page name
' @bparm   | ModuleName | String | current module name
' @bparm   | v() | Variant | values for the controlls
'
'*****************************************************************************
Public Function OnShowPageNotes(ps As Peripherals, Controlname As String, Pagename As String, ModuleName As String, v() As Variant) As Boolean
  On Error Resume Next
  OnShowPageNotes = False
  
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim i As Integer
  Dim s As String
  Dim n As String

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

  s = ModuleName & "_Notes"
  
  '------------------------------------------------------------------------------------
  ' page: Notes (action)
  '------------------------------------------------------------------------------------
  Select Case Controlname
      '--------------------------------------------------------------------------------
      ' control: txt.._Notes (action)
      '--------------------------------------------------------------------------------
      Case "txt" & s
           ' action on clicking the selected control
           OnShowPageNotes = True
           If (IsInputFormatOK(v(1), FORMAT_NOTES, c("lbl" & s).Caption, , )) Then
             r.v(s) = v(1)
           Else
               Exit Function
           End If
  End Select

  '------------------------------------------------------------------------------------
  ' page: Notes (show)
  '------------------------------------------------------------------------------------
  If (Pagename = "Notes") Then
    '----------------------------------------------------------------------------------
    ' control: lbl.._Notes (show)
    '----------------------------------------------------------------------------------
    ' action on showing the control
    With c("lbl" & s)
      .Enabled = True
    End With

'    With e("lbl" & s)
        ' tooltip if control is disabled
        ' tooltip if control is enabled
'    End With

    '----------------------------------------------------------------------------------
    ' control: txt.._Notes
    '----------------------------------------------------------------------------------
    ' action on showing the control
    With c("txt" & s)
      ' disable condition
      .Enabled = True
      ' show condition
      .Text = FormatTextOutput(r.v(s), "S")
    End With

    With e("txt" & s)
        ' tooltip if control is disabled
        ' tooltip if control is enabled
        n = "You can enter a comment in this field. The comment will " & _
            "appear in the generated document (*.rtf) and in the generated C-file. "
        .EnabledTooltipText = FormatNormalToolTip(n) & vbCrLf
        .EnabledTooltipText = .EnabledTooltipText & "Tip:" & vbCrLf
        n = "To insert a linefeed press CTRL + ENTER."
        .EnabledTooltipText = .EnabledTooltipText & FormatNormalToolTip(n)
    End With

  End If         ' if Pagename

  OnShowPageNotes = True
End Function



'*****************************************************************************
'Description:
'        This function initializes the menu of the Peripherals window.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        sScriptName     name of the script for which the menu should be added
'                        (e.g. "SSCx\Dialog")
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function InitMenu(ps As Peripherals, sScriptName As String) As Boolean
    On Error GoTo InitMenuError
    
    Dim ts As Tool
    Dim bs As Band
    Dim bsMain As Band
    Dim pic As Object
    Dim i As Long
    Dim l As Long
    Dim m As Object
    
    InitMenu = False
    Set m = ObjectCollection("MANUALLINKS")
    
    ' add toolbar band
    Set bsMain = ps.Menu.Bands.Add("MainBand")
    bsMain.Caption = "DAvE Tools"
    bsMain.Type = DDBTNormal
    bsMain.flags = DDBFFixed
    
    'close
    Set pic = LoadBitmap(DefGetPath("Icons") & "CLOSE.BMP")
    If (IsNull(pic)) Then Exit Function

    Set ts = bsMain.Tools.Add(1, "Close")
    ts.SetPicture Index:=0, Picture:=pic, Color:=QBColor(5)
    ts.ToolTipText = "Close this window"

    ' info
    Set pic = LoadBitmap(DefGetPath("Icons") & "INFO.BMP")
    If (IsNull(pic)) Then Exit Function

    Set ts = bsMain.Tools.Add(2, "Info")
    ts.SetPicture Index:=0, Picture:=pic, Color:=QBColor(5)
    ts.ControlType = DDTTButtonDropDown
    ts.SubBand = "Info"
    ts.ToolTipText = "Documentation"
    ts.BeginGroup = True
    Set bs = ps.Menu.Bands.Add("Info")
    bs.Type = DDBTPopup

    ' manuals
    Set pic = LoadBitmap(DefGetPath("Icons") & "DOC.BMP")
    If (IsNull(pic)) Then Exit Function

    For l = 1 To m.MenuCounter()
      If (m.ScriptName(l) = sScriptName) Then
        For i = 1 To m.LinkCounter(l)
          Set ts = bs.Tools.Add(i, "Doc")
          ts.Caption = m.LinkName(l, i)
          ts.Text = m.KeyName(l, i)
          ts.SetPicture Index:=0, Picture:=pic, Color:=QBColor(5)
                ts.BeginGroup = m.Group(l, i)
        Next i
        Exit For
      End If
    Next l

    ' help
    Set pic = LoadBitmap(DefGetPath("Icons") & "HELP.BMP")
    If (IsNull(pic)) Then Exit Function

    Set ts = bsMain.Tools.Add(3, "Help")
    ts.BeginGroup = True
    ts.SetPicture Index:=0, Picture:=pic, Color:=QBColor(5)
    ts.ToolTipText = "Help"

    ps.Menu.RecalcLayout
    
    InitMenu = True
    Exit Function

InitMenuError:
  Errorbox "Can not load the menu", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called 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
'        sScriptName     name of the script for which the menu should be added
'                        (e.g. "SSCx\Dialog")
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function MenuClick(ps As Peripherals, Toolname As String, ToolId As Long, Tooltext As String, sScriptName As String) As Boolean
    On Error GoTo MenuClickError
    Dim i As Long
    Dim l As Long
    Dim m As Object

    MenuClick = False
    Set m = ObjectCollection("MANUALLINKS")


    Select Case Toolname
        Case "Close"
            ps.Terminate
        Case "Info"
            UserMessage FormatMessageBoxText(MSG_DOCU_BUTTON)
        Case "Help"
            HelpContext 1008
        Case "Doc"
            For l = 1 To m.MenuCounter()
              If (m.ScriptName(l) = sScriptName) Then
                For i = 1 To m.LinkCounter(l)
                  If (Tooltext = m.KeyName(l, i)) Then
                    Call ShowDocument(m.DefSection(l, i), Tooltext)
                    Exit For
                  End If
                Next i
                Exit For
              End If
            Next l
    End Select

    MenuClick = True
    Exit Function

MenuClickError:
    Exit Function
End Function


'*****************************************************************************
' @bfunc   Public | OnLoadPageBankSelection | Boolean |
'
'-----------------------------------------------------------------------------
'          This function adds a page to the peripheral.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
'
'*****************************************************************************
Public Function OnLoadPageBankSelection(ps As Peripherals, iGPX As Integer) As Boolean
  On Error Resume Next
  OnLoadPageBankSelection = False
 

  Dim sPageName As String
  Dim r As ProjectData

  Set r = ps.ProjectData

  If (iGPX = 0) Then
    sPageName = "Bank Select"
  End If
  
  If (Not ps.AddPage(sPageName)) Then Exit Function

  OnLoadPageBankSelection = True
End Function

'*****************************************************************************
' @bfunc   Public | OnChangingPageBankSelection | Boolean |
'
'-----------------------------------------------------------------------------
'          This function makes all activities for the interrupt page in each
'          module function OnChangingPage.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
' @bparm   | Pagename | String | current page name
'
'*****************************************************************************
Public Function OnChangingPageBankSelection(ps As Object, Pagename As String, iGPX As Integer) As Boolean
  On Error Resume Next
  OnChangingPageBankSelection = False

  Dim sPageName As String
  Dim r As ProjectData

  Set r = ps.ProjectData

  If (iGPX = 0) Then
    sPageName = "Bank Select"
  End If

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

    If (Not ps.AddIRTab32("BANK" & iGPX)) Then Exit Function
    bFirstTime = True
    If (Not ps.AddFrame("frmBankDummy1" & iGPX, 6120, 200, 2500, 350, "")) Then Exit Function
    If (Not ps.AddLabel("lblBankDummy1" & iGPX, 0, 100, 120, 2000, 300, "Global Register Bank")) Then Exit Function
    If (Not ps.AddFrame("frmBankDummy" & iGPX, 0, 4450, 8600, 900, "")) Then Exit Function
    If (Not ps.AddLabel("lblBankDummy" & iGPX, 0, 100, 100, 8400, 650, "Note 1: For all int's (with priority > = 12) ,Local Reg Banks (1 or 2) can be assigned by dragging and dropping to the desired bank." & _
                            vbCrLf & "Note 2: Only 2 Fast Int's. can be assigned (with priority > = 12) at a time in the bottom 2 cells of Fast Interrupt group.")) Then Exit Function
    If (Not ps.AddFrame("frmBankDummy2" & iGPX, 0, 200, 800, 4200, "")) Then Exit Function
   
  
  End If

  OnChangingPageBankSelection = True
End Function

'*****************************************************************************
' @bfunc   Public | OnShowPageBankSelection | Boolean |
'
'-----------------------------------------------------------------------------
'          This function makes all activities for the interrupt page in each
'          module function OnShow.
'
'-----------------------------------------------------------------------------
' @rdesc   one of the following values
' @flag    False| if an error has been occured in the function
' @flag    True|  else
'
'-----------------------------------------------------------------------------
' @bparm   | ps | Peripherals | reference to this object
' @bparm   | Controlname | String | current control name
' @bparm   | v() | Variant | values for the controlls
' @bparm   | SeekName | String | name for searching in the interrupt list
' @bparm   | Pagename | String | current page name
'
'*****************************************************************************

Public Function OnShowPageBankSelection(ps As Peripherals, Controlname As String, v() As Variant, SeekName As String, Pagename As String, iGPX As Integer) As Boolean
  On Error Resume Next
  OnShowPageBankSelection = False
    Dim r As ProjectData
    Dim p As Parameters
    Dim c As Collection
    Dim cp As DAvECollection
    Dim ir As InterruptClass
    Dim vHighestLevel As Variant
    Dim d As String

    Dim iOldChannel As Integer
    Dim iOldISRPosition As Integer
    Dim iChannel As Integer
    Dim iISRPosition As Integer

    Dim IntName As Variant
    Dim IntLevel As Variant
    Dim IntGroup As Variant
    Dim IntOldLevel As Variant
    Dim IntOldGroup As Variant
    Dim f(1 To 3) As Integer
    Dim s(1 To 3) As String
    Dim Status As Boolean

    Dim sInt As String

    Dim i As Integer


    If (iGPX = 0) Then
        sInt = "Bank Select"
    End If
     
    

    Set r = ps.ProjectData
    Set p = ps.Parameters
    Set c = ps.ControlCollection
    Set cp = ObjectCollection("IRSOURCES")

    If (Pagename = sInt) Then

      d = "Fast interrupts are not supported for Tasking Viper." & vbCrLf & "It can be assigned to any local register bank from global register bank."
      
      IntName = v(1)
      IntLevel = v(2)
      IntGroup = v(3)
      IntOldLevel = v(4)
      IntOldGroup = v(5)

      If (IntOldLevel = 14) Then
          iOldChannel = IntOldGroup
          iOldISRPosition = 0
      ElseIf (IntOldLevel = 12) Then
          iOldChannel = IntOldGroup
          iOldISRPosition = 1
      ElseIf (IntOldLevel = 10) Then
          iOldChannel = IntOldGroup
          iOldISRPosition = 2
      ElseIf (IntOldLevel = 8) Then
          iOldChannel = IntOldGroup
          iOldISRPosition = 3
      ElseIf (IntOldLevel = 15) Then
          iOldChannel = IntOldGroup + 4
          iOldISRPosition = 0
      ElseIf (IntOldLevel = 13) Then
          iOldChannel = IntOldGroup + 4
          iOldISRPosition = 1
      ElseIf (IntOldLevel = 11) Then
          iOldChannel = IntOldGroup + 4
          iOldISRPosition = 2
      ElseIf (IntOldLevel = 9) Then
          iOldChannel = IntOldGroup + 4
          iOldISRPosition = 3
      End If

      If (IntLevel = 14) Then
          iChannel = IntGroup
          iISRPosition = 0
      ElseIf (IntLevel = 12) Then
          iChannel = IntGroup
          iISRPosition = 1
      ElseIf (IntLevel = 10) Then
          iChannel = IntGroup
          iISRPosition = 2
      ElseIf (IntLevel = 8) Then
          iChannel = IntGroup
          iISRPosition = 3
      ElseIf (IntLevel = 15) Then
          iChannel = IntGroup + 4
          iISRPosition = 0
      ElseIf (IntLevel = 13) Then
          iChannel = IntGroup + 4
          iISRPosition = 1
      ElseIf (IntLevel = 11) Then
          iChannel = IntGroup + 4
          iISRPosition = 2
      ElseIf (IntLevel = 9) Then
          iChannel = IntGroup + 4
          iISRPosition = 3
      End If
      '-------------------------------------------------------------------------
      ' page: Interrupts (action)
      '-------------------------------------------------------------------------
      
      If (Controlname = "BANK" & iGPX) Then
      
      If (r.v(cp(IntName).LevelName) = 12) Then
        If r.v(cp(IntName).GPXName) = 0 Then
             If v(2) = 0 Then 'global bank
                r.v("BNK0_GPR" & r.v(cp(IntName).GroupName)) = 0
             ElseIf (v(3) < 2) Then 'Local Bank (1 or 2)
                'r.v("BNK0_GPR" & r.v(cp(IntName).GroupName)) = v(3) + 2
                 If (IntOldGroup <> IntGroup) Then
                    If Not CheckFastInterruptPlacement(r, (r.v(cp(IntName).GroupName) + 4 * r.v(cp(IntName).GPXName)), v(3)) Then
                       r.v("BNK0_GPR" & r.v(cp(IntName).GroupName)) = v(3) + 2
                    Else
                       r.v("BNK0_GPR" & r.v(cp(IntName).GroupName)) = 0
                    End If
                 End If
                
             ElseIf (v(3) = 2) Then 'Fast Intrpt
                If (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
                  MsgBox d, "DAvE"
                Else
                r.v("BNK0_GPR" & r.v(cp(IntName).GroupName)) = 0
                r.v("INT_USE_FAST" & (v(2) - 1)) = 1
                r.v("FINT" & (v(2) - 1) & "CSP_EN") = 1 'Added by jag on 08.12.07
                r.v("FINT" & (v(2) - 1) & "CSP_GPX") = r.v(cp(IntName).GPXName)
                r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 0
                r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = r.v(cp(IntName).GroupName)
                End If
            End If
            If (v(3) = 2) And (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
                r.v("INT_USE_FAST" & (v(2) - 1)) = 0
                r.v("FINT" & (v(2) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
                r.v("FINT" & (v(2) - 1) & "CSP_GPX") = 0
                r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 0
                r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = 0
                r.v("BNK0_GPR" & r.v(cp(IntName).GroupName)) = 0
             r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = 0
            Else
               r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = v(2)
               
               If (r.v("BNK0_GPR" & r.v(cp(IntName).GroupName)) = 0) And (v(3) < 2) And (v(2) <> 0) Then
                  r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = 0
               End If
             
               
            End If
            
                
            If v(5) = 2 Then   'If old grp is fast intrpt
                r.v("INT_USE_FAST" & (v(4) - 1)) = 0
                r.v("FINT" & (v(4) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
                r.v("FINT" & (v(4) - 1) & "CSP_GPX") = 0
                r.v("FINT" & (v(4) - 1) & "CSP_ILVL") = 0
                r.v("FINT" & (v(4) - 1) & "CSP_GLVL") = 0
            End If
      Else 'GPX 1
      
       If v(2) = 0 Then 'global bank
          r.v("BNK2_GPR" & (r.v(cp(IntName).GroupName))) = 0 'v(3) + 2
       ElseIf (v(3) < 2) Then 'Local Bank (1 or 2)
          'r.v("BNK2_GPR" & r.v(cp(IntName).GroupName)) = v(3) + 2
           If (IntOldGroup <> IntGroup) Then
            If Not CheckFastInterruptPlacement(r, (r.v(cp(IntName).GroupName) + 4 * r.v(cp(IntName).GPXName)), v(3)) Then
               r.v("BNK2_GPR" & r.v(cp(IntName).GroupName)) = v(3) + 2
            Else
               r.v("BNK2_GPR" & r.v(cp(IntName).GroupName)) = 0
            End If
          End If
          
          
       ElseIf (v(3) = 2) Then 'Fast Intrpt
             If (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
             MsgBox d, "DAvE"
            Else
                r.v("BNK2_GPR" & (r.v(cp(IntName).GroupName))) = 0
                r.v("INT_USE_FAST" & (v(2) - 1)) = 1
                r.v("FINT" & (v(2) - 1) & "CSP_EN") = 1 'Added by jag on 08.12.07
                r.v("FINT" & (v(2) - 1) & "CSP_GPX") = r.v(cp(IntName).GPXName)
                r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 0
                r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = r.v(cp(IntName).GroupName)
            End If
       End If
       
        If (v(3) = 2) And (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
           r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = 0
           r.v("INT_USE_FAST" & (v(2) - 1)) = 0
            r.v("FINT" & (v(2) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
            r.v("FINT" & (v(2) - 1) & "CSP_GPX") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = 0
            r.v("BNK2_GPR" & (r.v(cp(IntName).GroupName))) = 0
        Else
           r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = v(2)
            
           If (r.v("BNK2_GPR" & r.v(cp(IntName).GroupName)) = 0) And (v(3) < 2) And (v(2) <> 0) Then
              r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = 0
           End If
           
        End If
        
           If v(5) = 2 Then   'If old grp is fast intrpt
              r.v("INT_USE_FAST" & (v(4) - 1)) = 0
              r.v("FINT" & (v(4) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
              r.v("FINT" & (v(4) - 1) & "CSP_GPX") = 0
              r.v("FINT" & (v(4) - 1) & "CSP_ILVL") = 0
              r.v("FINT" & (v(4) - 1) & "CSP_GLVL") = 0
            End If
       End If
       
     End If
     
     If (r.v(cp(IntName).LevelName) = 13) Then
     
       If r.v(cp(IntName).GPXName) = 0 Then
       
       If v(2) = 0 Then 'global bank
          r.v("BNK0_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
       ElseIf (v(3) < 2) Then 'Local Bank (1 or 2)
          'r.v("BNK0_GPR" & (r.v(cp(IntName).GroupName) + 4)) = v(3) + 2
          If (IntOldGroup <> IntGroup) Then
            If Not CheckFastInterruptPlacement(r, (r.v(cp(IntName).GroupName) + 4 * r.v(cp(IntName).GPXName)), v(3)) Then
               r.v("BNK0_GPR" & (r.v(cp(IntName).GroupName) + 4)) = v(3) + 2
            Else
               r.v("BNK0_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
            End If
          End If
          
          
          
       ElseIf (v(3) = 2) Then 'Fast Intrpt
        If (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
              MsgBox d, "DAvE"
        Else
           r.v("BNK0_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
           r.v("INT_USE_FAST" & (v(2) - 1)) = 1
           r.v("FINT" & (v(2) - 1) & "CSP_EN") = 1 'Added by jag on 08.12.07
           r.v("FINT" & (v(2) - 1) & "CSP_GPX") = r.v(cp(IntName).GPXName)
           r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 1
           r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = r.v(cp(IntName).GroupName)
        End If
       End If
       
           If (v(3) = 2) And (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
            r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = 0
            r.v("INT_USE_FAST" & (v(2) - 1)) = 0
            r.v("FINT" & (v(2) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
            r.v("FINT" & (v(2) - 1) & "CSP_GPX") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = 0
            r.v("BNK0_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
            Else
               r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = v(2)
               
               If (r.v("BNK0_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0) And (v(3) < 2) And (v(2) <> 0) Then
                   r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = 0
               End If
               
          End If
       
            
            If v(5) = 2 Then   'If old grp is fast intrpt
             r.v("INT_USE_FAST" & (v(4) - 1)) = 0
             r.v("FINT" & (v(4) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
             r.v("FINT" & (v(4) - 1) & "CSP_GPX") = 0
             r.v("FINT" & (v(4) - 1) & "CSP_ILVL") = 0
             r.v("FINT" & (v(4) - 1) & "CSP_GLVL") = 0
            End If
      Else 'GPX 1
      
       If v(2) = 0 Then 'global bank
          r.v("BNK2_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0 'v(3) + 2
       ElseIf (v(3) < 2) Then 'Local Bank (1 or 2)
          'r.v("BNK2_GPR" & (r.v(cp(IntName).GroupName) + 4)) = v(3) + 2
          If (IntOldGroup <> IntGroup) Then
            If Not CheckFastInterruptPlacement(r, (r.v(cp(IntName).GroupName) + 4 * r.v(cp(IntName).GPXName)), v(3)) Then
               r.v("BNK2_GPR" & (r.v(cp(IntName).GroupName) + 4)) = v(3) + 2
            Else
               r.v("BNK2_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
            End If
          End If
          
          
       ElseIf (v(3) = 2) Then 'Fast Intrpt
            If (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
             MsgBox d, "DAvE"
          Else
            r.v("BNK2_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
            r.v("INT_USE_FAST" & (v(2) - 1)) = 1
            r.v("FINT" & (v(2) - 1) & "CSP_EN") = 1 'Added by jag on 08.12.07
            r.v("FINT" & (v(2) - 1) & "CSP_GPX") = r.v(cp(IntName).GPXName)
            r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 1
            r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = r.v(cp(IntName).GroupName)
            End If
       End If
       
       If (v(3) = 2) And (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
            r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = 0
            r.v("INT_USE_FAST" & (v(2) - 1)) = 0
            r.v("FINT" & (v(2) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
            r.v("FINT" & (v(2) - 1) & "CSP_GPX") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = 0
            r.v("BNK2_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
            Else
            r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = v(2)
            
            If (r.v("BNK2_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0) And (v(3) < 2) And (v(2) <> 0) Then
               r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = 0
            End If
            
      End If
           
           If v(5) = 2 Then   'If old grp is fast intrpt
              r.v("INT_USE_FAST" & (v(4) - 1)) = 0
              r.v("FINT" & (v(4) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
              r.v("FINT" & (v(4) - 1) & "CSP_GPX") = 0
              r.v("FINT" & (v(4) - 1) & "CSP_ILVL") = 0
              r.v("FINT" & (v(4) - 1) & "CSP_GLVL") = 0
              
            End If
       End If
    End If

 
      If (r.v(cp(IntName).LevelName) = 14) Then
        If r.v(cp(IntName).GPXName) = 0 Then
       
       If v(2) = 0 Then 'global bank
          r.v("BNK1_GPR" & r.v(cp(IntName).GroupName)) = 0
       ElseIf (v(3) < 2) Then 'Local Bank (1 or 2)
          'r.v("BNK1_GPR" & r.v(cp(IntName).GroupName)) = v(3) + 2
          If (IntOldGroup <> IntGroup) Then
            If Not CheckFastInterruptPlacement(r, (r.v(cp(IntName).GroupName) + 4 * r.v(cp(IntName).GPXName)), v(3)) Then
               r.v("BNK1_GPR" & r.v(cp(IntName).GroupName)) = v(3) + 2
            Else
               r.v("BNK1_GPR" & r.v(cp(IntName).GroupName)) = 0
            End If
          End If
          
       ElseIf (v(3) = 2) Then 'Fast Intrpt
       If (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
             MsgBox d, "DAvE"
       Else
            r.v("BNK1_GPR" & r.v(cp(IntName).GroupName)) = 0
            r.v("INT_USE_FAST" & (v(2) - 1)) = 1
            
            r.v("FINT" & (v(2) - 1) & "CSP_EN") = 1 'Added by jag on 08.12.07
            
            r.v("FINT" & (v(2) - 1) & "CSP_GPX") = r.v(cp(IntName).GPXName)
            r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 2
            r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = r.v(cp(IntName).GroupName)
            End If
       End If
        If (v(3) = 2) And (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
            r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = 0
            r.v("INT_USE_FAST" & (v(2) - 1)) = 0
            r.v("FINT" & (v(2) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
            r.v("FINT" & (v(2) - 1) & "CSP_GPX") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = 0
             r.v("BNK1_GPR" & r.v(cp(IntName).GroupName)) = 0
            Else
            r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = v(2)
            
            If (r.v("BNK1_GPR" & r.v(cp(IntName).GroupName)) = 0) And (v(3) < 2) And (v(2) <> 0) Then
               r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = 0
            End If
            
       End If
            
            If v(5) = 2 Then   'If old grp is fast intrpt
             r.v("INT_USE_FAST" & (v(4) - 1)) = 0
             r.v("FINT" & (v(4) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
             r.v("FINT" & (v(4) - 1) & "CSP_GPX") = 0
             r.v("FINT" & (v(4) - 1) & "CSP_ILVL") = 0
             r.v("FINT" & (v(4) - 1) & "CSP_GLVL") = 0
            End If
      Else 'GPX 1
      
       If v(2) = 0 Then 'global bank
          r.v("BNK3_GPR" & (r.v(cp(IntName).GroupName))) = 0 'v(3) + 2
       ElseIf (v(3) < 2) Then 'Local Bank (1 or 2)
          'r.v("BNK3_GPR" & r.v(cp(IntName).GroupName)) = v(3) + 2
          If (IntOldGroup <> IntGroup) Then
            If Not CheckFastInterruptPlacement(r, (r.v(cp(IntName).GroupName) + 4 * r.v(cp(IntName).GPXName)), v(3)) Then
               r.v("BNK3_GPR" & r.v(cp(IntName).GroupName)) = v(3) + 2
            Else
               r.v("BNK3_GPR" & r.v(cp(IntName).GroupName)) = 0
            End If
          End If
       ElseIf (v(3) = 2) Then 'Fast Intrpt
       If (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
             MsgBox d, "DAvE"
       Else
            r.v("BNK3_GPR" & (r.v(cp(IntName).GroupName))) = 0
            r.v("INT_USE_FAST" & (v(2) - 1)) = 1
            r.v("FINT" & (v(2) - 1) & "CSP_EN") = 1 'Added by jag on 08.12.07
            r.v("FINT" & (v(2) - 1) & "CSP_GPX") = r.v(cp(IntName).GPXName)
            r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 2
            r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = r.v(cp(IntName).GroupName)
       End If
       End If
       
       If (v(3) = 2) And (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
           r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = 0
           r.v("INT_USE_FAST" & (v(2) - 1)) = 0
            r.v("FINT" & (v(2) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
            r.v("FINT" & (v(2) - 1) & "CSP_GPX") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = 0
            r.v("BNK3_GPR" & (r.v(cp(IntName).GroupName))) = 0
            Else
            r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = v(2)
            
            If (r.v("BNK3_GPR" & r.v(cp(IntName).GroupName)) = 0) And (v(3) < 2) And (v(2) <> 0) Then
               r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = 0
            End If
       End If
           
           If v(5) = 2 Then   'If old grp is fast intrpt
              r.v("INT_USE_FAST" & (v(4) - 1)) = 0
              r.v("FINT" & (v(4) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
              r.v("FINT" & (v(4) - 1) & "CSP_GPX") = 0
              r.v("FINT" & (v(4) - 1) & "CSP_ILVL") = 0
              r.v("FINT" & (v(4) - 1) & "CSP_GLVL") = 0
            End If
       End If
       
     End If
     
     
          If (r.v(cp(IntName).LevelName) = 15) Then
     
       If r.v(cp(IntName).GPXName) = 0 Then
       
       If v(2) = 0 Then 'global bank
          r.v("BNK1_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
       ElseIf (v(3) < 2) Then 'Local Bank (1 or 2)
          'r.v("BNK1_GPR" & (r.v(cp(IntName).GroupName) + 4)) = v(3) + 2
          If (IntOldGroup <> IntGroup) Then
            If Not CheckFastInterruptPlacement(r, (r.v(cp(IntName).GroupName) + 4 * r.v(cp(IntName).GPXName)), v(3)) Then
               r.v("BNK1_GPR" & (r.v(cp(IntName).GroupName) + 4)) = v(3) + 2
            Else
               r.v("BNK1_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
            End If
          End If
       ElseIf (v(3) = 2) Then 'Fast Intrpt
       If (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
             MsgBox d, "DAvE"
       Else
          r.v("BNK1_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
          r.v("INT_USE_FAST" & (v(2) - 1)) = 1
          r.v("FINT" & (v(2) - 1) & "CSP_EN") = 1 'Added by jag on 08.12.07
          r.v("FINT" & (v(2) - 1) & "CSP_GPX") = r.v(cp(IntName).GPXName)
          r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 3
          r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = r.v(cp(IntName).GroupName)
      End If
       End If
        If (v(3) = 2) And (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
           r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = 0
           r.v("INT_USE_FAST" & (v(2) - 1)) = 0
            r.v("FINT" & (v(2) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
            r.v("FINT" & (v(2) - 1) & "CSP_GPX") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = 0
            r.v("BNK1_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
            Else
            r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = v(2)
            
            If (r.v("BNK1_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0) And (v(3) < 2) And (v(2) <> 0) Then
               r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & r.v(cp(IntName).GroupName)) = 0
            End If
            
       End If
            
            If v(5) = 2 Then   'If old grp is fast intrpt
             r.v("INT_USE_FAST" & (v(4) - 1)) = 0
             r.v("FINT" & (v(4) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
             r.v("FINT" & (v(4) - 1) & "CSP_GPX") = 0
             r.v("FINT" & (v(4) - 1) & "CSP_ILVL") = 0
             r.v("FINT" & (v(4) - 1) & "CSP_GLVL") = 0
            End If
      Else 'GPX 1
      
       If v(2) = 0 Then 'global bank
          r.v("BNK3_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0 'v(3) + 2
       ElseIf (v(3) < 2) Then 'Local Bank (1 or 2)
          'r.v("BNK3_GPR" & (r.v(cp(IntName).GroupName) + 4)) = v(3) + 2
          If (IntOldGroup <> IntGroup) Then
            If Not CheckFastInterruptPlacement(r, (r.v(cp(IntName).GroupName) + 4 * r.v(cp(IntName).GPXName)), v(3)) Then
               r.v("BNK3_GPR" & (r.v(cp(IntName).GroupName) + 4)) = v(3) + 2
            Else
               r.v("BNK3_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
            End If
          End If
       ElseIf (v(3) = 2) Then 'Fast Intrpt
       If (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
             MsgBox d, "DAvE"
       Else
            r.v("BNK3_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
            r.v("INT_USE_FAST" & (v(2) - 1)) = 1
            r.v("FINT" & (v(2) - 1) & "CSP_EN") = 1 'Added by jag on 08.12.07
            r.v("FINT" & (v(2) - 1) & "CSP_GPX") = r.v(cp(IntName).GPXName)
            r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 3
            r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = r.v(cp(IntName).GroupName)
        End If
       End If
       
       If (v(3) = 2) And (InStr(r.v("MAIN_COMPILER"), "Tasking Viper")) Then
           r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = 0
           r.v("INT_USE_FAST" & (v(2) - 1)) = 0
            r.v("FINT" & (v(2) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
            r.v("FINT" & (v(2) - 1) & "CSP_GPX") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_ILVL") = 0
            r.v("FINT" & (v(2) - 1) & "CSP_GLVL") = 0
            r.v("BNK3_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0
            Else
            r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = v(2)
            
            If (r.v("BNK3_GPR" & (r.v(cp(IntName).GroupName) + 4)) = 0) And (v(3) < 2) And (v(2) <> 0) Then
               r.v("INT_LEV" & r.v(cp(IntName).LevelName) & "_GRP" & (r.v(cp(IntName).GroupName) + 4)) = 0
            End If
            
       End If
           
           If v(5) = 2 Then   'If old grp is fast intrpt
              r.v("INT_USE_FAST" & (v(4) - 1)) = 0
              r.v("FINT" & (v(4) - 1) & "CSP_EN") = 0 'Added by jag on 08.12.07
              r.v("FINT" & (v(4) - 1) & "CSP_GPX") = 0
              r.v("FINT" & (v(4) - 1) & "CSP_ILVL") = 0
              r.v("FINT" & (v(4) - 1) & "CSP_GLVL") = 0
            End If
       End If
       
     End If
        '------------------------------------- Assigning BNKSEL registers depending on BNKSEL variabls ---------------------------------------------------------------------------------------------------------------------------------------------------
        For i = 0 To 3
            r.v("INTBNK" & i) = 16384 * r.v("BNK" & i & "_GPR7") + 4096 * r.v("BNK" & i & "_GPR6") + 1024 * r.v("BNK" & i & "_GPR5") + 256 * r.v("BNK" & i & "_GPR4") + 64 * r.v("BNK" & i & "_GPR3") + 16 * r.v("BNK" & i & "_GPR2") + 4 * r.v("BNK" & i & "_GPR1") + r.v("BNK" & i & "_GPR0")
        Next i
        '------------------------------------- Assigning BNKSEL registers depending on BNKSEL variabls ---------------------------------------------------------------------------------------------------------------------------------------------------
      
      
      End If

      '-------------------------------------------------------------------------
      ' page: Interrupts (show)
      '-------------------------------------------------------------------------
      f(1) = 32
      f(2) = 32
      f(3) = 3
'      f(4) = 16

      s(1) = "Local Reg Bank " & (iGPX + 1)
      s(2) = "Local Reg Bank " & (iGPX + 1) + 1
      s(3) = "Fast Interrupts "


      With c("BANK" & iGPX)
        .Freeze
        .Clear
        .Init s, f

        ' for each interrupt in the collection
        ' look if the interrupt is enabled, is so then
        ' set the properties
        vHighestLevel = 0
        
        For Each ir In cp
          
          If (r.v(ir.Enabled) = 1) Then
            'if level = 0
            If (r.v(ir.LevelName) = 12) Then
               If r.v(ir.GPXName) = 0 Then
                    If r.v("BNK0_GPR" & r.v(ir.GroupName)) <> 0 Then
                       .Group = r.v("BNK0_GPR" & r.v(ir.GroupName)) - 2
                       Else
                       .Group = 2
                     End If
                    .Level = r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & r.v(ir.GroupName))
                    .Sourcename = ir.IntName
                    
                  Else
                   
                     If r.v("BNK2_GPR" & r.v(ir.GroupName)) <> 0 Then
                     .Group = r.v("BNK2_GPR" & (r.v(ir.GroupName))) - 2
                     Else
                     .Group = 2
                    End If
                    .Level = r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & (r.v(ir.GroupName) + 4))
                    .Sourcename = ir.IntName
                  End If
                End If
                
                
            If (r.v(ir.LevelName) = 13) Then
               If r.v(ir.GPXName) = 0 Then
                  If r.v("BNK0_GPR" & (r.v(ir.GroupName) + 4)) <> 0 Then
                       .Group = r.v("BNK0_GPR" & (r.v(ir.GroupName) + 4)) - 2
                  Else
                       .Group = 2
                  End If
                    .Level = r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & r.v(ir.GroupName))
                    .Sourcename = ir.IntName
               Else
                   
                    If r.v("BNK2_GPR" & (r.v(ir.GroupName) + 4)) <> 0 Then
                     .Group = r.v("BNK2_GPR" & (r.v(ir.GroupName) + 4)) - 2
                    Else
                     .Group = 2
                    End If
                    .Level = r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & (r.v(ir.GroupName) + 4))
                    .Sourcename = ir.IntName
               End If
            End If
    
           If (r.v(ir.LevelName) = 14) Then
               If r.v(ir.GPXName) = 0 Then
                  If r.v("BNK1_GPR" & r.v(ir.GroupName)) <> 0 Then
                       .Group = r.v("BNK1_GPR" & r.v(ir.GroupName)) - 2
                       Else
                       .Group = 2
                     End If
                    .Level = r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & r.v(ir.GroupName))
                    .Sourcename = ir.IntName
                  Else
                   
                     If r.v("BNK3_GPR" & (r.v(ir.GroupName))) <> 0 Then
                     .Group = r.v("BNK3_GPR" & (r.v(ir.GroupName))) - 2
                     Else
                     .Group = 2
                    End If
                    .Level = r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & (r.v(ir.GroupName) + 4))
                    .Sourcename = ir.IntName
                  End If
                End If
                
            If (r.v(ir.LevelName) = 15) Then
               If r.v(ir.GPXName) = 0 Then
                  If r.v("BNK1_GPR" & (r.v(ir.GroupName)) + 4) <> 0 Then
                       .Group = r.v("BNK1_GPR" & (r.v(ir.GroupName)) + 4) - 2
                       Else
                       .Group = 2
                     End If
                    .Level = r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & r.v(ir.GroupName))
                    .Sourcename = ir.IntName
                  Else
                   
                     If r.v("BNK3_GPR" & (r.v(ir.GroupName) + 4)) <> 0 Then
                     .Group = r.v("BNK3_GPR" & (r.v(ir.GroupName) + 4)) - 2
                     Else
                     .Group = 2
                    End If
                    .Level = r.v("INT_LEV" & r.v(ir.LevelName) & "_GRP" & (r.v(ir.GroupName) + 4))
                    .Sourcename = ir.IntName
                  End If
                End If
           
            
          End If
        Next ir
        
        .SeekList SeekName
        If (bFirstTime = True) Then
          .TopLevel = vHighestLevel
          bFirstTime = False
        End If
        .Melt
      End With
    End If

  OnShowPageBankSelection = True
End Function

Public Function CheckFastInterruptPlacement(r As ProjectData, GroupName As Integer, v As Variant) As Boolean
  On Error Resume Next
  CheckFastInterruptPlacement = False
  
  Dim d As String
  
  d = "Interrupt from Group  " & GroupName & " is already placed in this local reg bank."
  
  If (GroupName <= 3) Then
    If ((r.v("BNK0_GPR" & GroupName) <> 0) Or (r.v("BNK0_GPR" & (GroupName + 4)) <> 0) Or (r.v("BNK1_GPR" & GroupName) <> 0) Or (r.v("BNK1_GPR" & (GroupName + 4)) <> 0)) Then
        If (r.v("BNK0_GPR" & GroupName) = (v + 2)) Then
           MsgBox d, vbInformation, "DAvE"
           CheckFastInterruptPlacement = True
        ElseIf (r.v("BNK0_GPR" & (GroupName + 4)) = (v + 2)) Then
           MsgBox d, vbInformation, "DAvE"
           CheckFastInterruptPlacement = True
        ElseIf (r.v("BNK1_GPR" & GroupName) = (v + 2)) Then
           MsgBox d, vbInformation, "DAvE"
           CheckFastInterruptPlacement = True
        ElseIf (r.v("BNK1_GPR" & (GroupName + 4)) = (v + 2)) Then
           MsgBox d, vbInformation, "DAvE"
           CheckFastInterruptPlacement = True
        End If
        
    End If
    
  Else
  
    If ((r.v("BNK2_GPR" & (GroupName - 4)) <> 0) Or (r.v("BNK2_GPR" & GroupName) <> 0) Or (r.v("BNK3_GPR" & (GroupName - 4)) <> 0) Or (r.v("BNK3_GPR" & GroupName) <> 0)) Then
        If (r.v("BNK2_GPR" & (GroupName - 4)) = (v + 2)) Then
           MsgBox d, "DAvE"
           CheckFastInterruptPlacement = True
        ElseIf (r.v("BNK2_GPR" & GroupName) = (v + 2)) Then
           MsgBox d, "DAvE"
           CheckFastInterruptPlacement = True
        ElseIf (r.v("BNK3_GPR" & (GroupName - 4)) = (v + 2)) Then
           MsgBox d, "DAvE"
           CheckFastInterruptPlacement = True
        ElseIf (r.v("BNK3_GPR" & GroupName) = (v + 2)) Then
           MsgBox d, "DAvE"
           CheckFastInterruptPlacement = True
        End If
        
    End If
    
  End If
    
End Function
