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

Option Explicit
'*****************************************************************************
' Module:
'        MAIN
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'MAIN'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0   ahe         27.04.00     final version
'        1.1   ahe         20.06.00     final version for C167CS
'
'        ---------------------------------------------------------------------
'        5.0   ahe         31.07.00     final version for C161CS/JC/JI
'                                       - change in CPU type
'                                       - change in #EA default value
'                                       - max CPU 20 MHz
'              ahe         10.08.00     - added C161CS/JC/JI-L
'                                       - changes actions for optEA_0 and optEA_1
'
'              ahe         15.08.00     - disabled condition for CSSEL
'
'              ahe         21.08.00     - disabled condition for BTYP's
'
'              ahe         13.09.00     - max CPU 25 MHz
'                                       - changes positioning
'
'              ahe         05.10.00     - added in oprEA_0
'                                         SYSCON_WRCFG = 0
'
'        ---------------------------------------------------------------------
'              ahe         25.10.00     final version for
'                                         C167CS
'                                         C161CS/JC/JI
'                                         C167CR/SR r2
'
'                                       - diferent Reset-Values for
'                                         # IDCHIP and XADRS5
'                                       - diferent CPU-TYPE
'                                       - ...
'
'        ---------------------------------------------------------------------
'        6.0   ahe         15.05.02     final version for Pegasus
'
'        6.1   ahe         05.06.02     if EA_EA = 0 then disable EBC
'
'              ahe         06.08.2002   - add items to PLLIDIV (3 and 4)
'                                       - add pages CPUCON1 und CPUCON2
'                                       - if set r.v("EA_EA") to 0 then set PLLCON to 0x2790
'
'        6.2   ahe         23.08.02     delete CPUCON2 page (requirement from Ursula Kelling)
'
'        6.3   ste         13.12.02     XC167CI added
'                                       if set r.v("EA_EA") to 0 then no changes for PLLCON
'                                       CPUCON2 initialization
'                          20.01.03     CPUCON1 initialization
'        6.4   ste         24.02.03     VECSEG for boot memory deleted (required by
'                                       Ursula Kelling)
'        ---------------------------------------------------------------------
'              ste         29.09.03     new contoller types added
'
'        ---------------------------------------------------------------------
'        7.0   vishwanatha 12.08.04     final version for XC164CM
'                                       - removed EBC related code lines
'                                       - ROM size reduced to 64kb
'                                       - changed reset values for
'                                         IDCHIP,IDMANUF,IDMEM,IDPROG
'                                       - peripheral clock prescalar added(CPPD)
'                                       - GetMaxFpd() added
'*****************************************************************************

'*****************************************************************************
'Description:
'        This function is called if a new project is created.
'
'        Only the dialog script of the MAIN module
'        contains this type of function.
'        The project variables will be initialized as follows:
'        1. Initialization of the "project settings" with default values
'        2. Calling of the Update-Functions of all peripheral modules
'           (The "project settings" must be valid at this time.)
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        vIndex          parameter for the module
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function Initialize(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo InitializeError

    Dim sMC_Name As String
    Dim iChannel As Integer
    Dim i As Integer

    sMC_Name = DefGetValue("Name")

    Initialize = False
            r.v("MAIN_NAME_UnlockProtecReg") = "MAIN_vUnlockProtecReg"
            r.v("MAIN_USE_UnlockProtecReg") = 1
            
            For iChannel = 0 To 7
                For i = 0 To 3
                    r.v("PEC_CHANNEL_" & iChannel & "_" & i) = "none"
                Next i
            Next iChannel
            
            r.sfr("CP") = &HFC00
            r.sfr("DPP1") = 1
            r.sfr("DPP2") = 2
            r.sfr("DPP3") = 3
            r.sfr("ONES") = &HFFFF
            r.sfr("SP") = &HFC00
            r.sfr("STKOV") = &HFA00
            r.sfr("STKUN") = &HFC00

            r.sfr("IDCHIP") = &H2381
            r.sfr("IDMANUF") = &H1820
            r.sfr("IDMEM") = &H3010
            r.sfr("IDPROG") = &H4040
            
            ' these values are recommended in the Errata Sheet
            If (r.Regs.SfrFind("CPUCON2")) Then
              r.sfr("CPUCON2") = &H8FBB
            End If
            If (r.Regs.SfrFind("CPUCON1")) Then
              r.sfr("CPUCON1") = &H7
            End If
            If (r.Regs.SfrFind("SYSCON3")) Then
              r.sfr("SYSCON3") = &H9FD0
            End If

            'r.v("RSTCFG_CLKCFG") = 7

            r.v("MAIN_COMPILER") = "Keil"
            r.v("MAIN_MEMORY") = "SMALL"

            If (sMC_Name = "XC164CM") Then
              r.v("MAIN_CPU_TYPE") = sMC_Name & "-8F20"
              r.v("MAIN_ROM_Type") = "Flash"
              r.v("MAIN_ROM_Size") = 64
            End If
            ' currently all types can use the same PLL initialization (20 MHz)
            r.v("MAIN_OSC") = 8
            r.sfr("PLLCON") = &H7814            'default as per spec 0x471F
            r.d("MAIN_CLK_CPU") = GetMaxFcpu(r) ' depends on "MAIN_CPU_TYPE"
            r.d("MAIN_CLK_PD") = GetMaxFpd(r) ' depends on "MAIN_CPU_TYPE"
            
            r.v("MAIN_CFile") = "MAIN.C"
            r.v("MAIN_HFile") = "MAIN.H"
            r.v("MAIN_NAME_Init") = "MAIN_vInit"
            r.v("MAIN_NAME_Main") = "main"


            r.v("PSW_IEN") = 1

    'UpdateMemoryModel(r)    ' request or release pins of the external bus

    'Initialize the variables/registers of all peripheral modules.
    'This has to be executed after initialization of the main variables/registers,
    'because some of these settings (i.e. CPU clock and external bus usage) are
    'also used as input values for the peripherals:
    If (Not UpdateAllPeripherals(r, INITIALIZATION)) Then Exit Function

    Initialize = True
    Exit Function

InitializeError:
    Errorbox "Error in function Initialize", Err.Description
    Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from DAvE just before the Project Settings
'        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: General
    '-------------------------------------------------------------------------
    If (Not OnLoadPageGeneral(ps)) Then Exit Function

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

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

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

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

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

    OnLoad = True
    Exit Function

OnLoadError:
    Errorbox "Error in function OnLoad", Err.Description
    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
    
    '-------------------------------------------------------------------------
    'page: General
    '-------------------------------------------------------------------------
    If (Not OnChangingPageGeneral(ps, Pagename)) Then Exit Function

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

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

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

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

    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Errorbox "Error in function OnChangingPage", Err.Description
    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

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

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

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

    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnShowPageNotes(ps, Controlname, Pagename, "MAIN", v)) Then Exit Function

    'If (Controlname <> "") Then
    '    'Some variables/registers of the peripheral modules depend on the
    '    'project settings, i.e. CPU clock and external bus usage.
    '    'Therefore these variables/registers are always updated when the
    '    'user changes any of the project settings:
    '    If (Not UpdateAllPeripherals(ps.ProjectData, UPDATE_CLOCK)) Then Exit Function
    'End If

    OnShow = True
    Exit Function

OnShowError:
    Errorbox "Error in function OnShow", 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 = True
    Exit Function

OnClickError:
    Errorbox "Error in Function 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, "Main\Dialog")) 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 a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageGeneral(ps As Peripherals) As Boolean
  On Error GoTo ExitLabel
  OnLoadPageGeneral = False

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

  OnLoadPageGeneral = True
ExitLabel:
End Function

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

  OnChangingPageGeneral = False


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

    '-------------------------------
    ' frame: frmController_Type
    '-------------------------------
    If (Not ps.AddFrame("frmController_Type", 100, 100, 8450, 1650, "Controller Type")) Then Exit Function
        If (Not ps.AddCombo("cboType", 1050, 400, 1900, 315)) Then Exit Function
        If (Not ps.AddLabel("lblType", 0, 200, 450, 750, 300, "Type")) Then Exit Function
        If (Not ps.AddLabel("txtROM_Size", 1, 5000, 400, 900, 320, "")) Then Exit Function
        If (Not ps.AddLabel("lblROM_Size", 0, 3650, 450, 1050, 300, "ROM Size")) Then Exit Function
        If (Not ps.AddLabel("txtROM_Type", 1, 7000, 400, 1200, 320, "")) Then Exit Function
        If (Not ps.AddLabel("lblROM_Type", 0, 6050, 450, 925, 300, "ROM Type")) Then Exit Function
        If (Not ps.AddLabel("Max_CPU_Clock", 1, 5000, 1000, 900, 320, "")) Then Exit Function
        If (Not ps.AddLabel("lblMax_CPU_Clock", 0, 3650, 1050, 1250, 300, "Max. CPU Clock")) Then Exit Function

    '-------------------------------
    ' frame: frmMain_CFile
    '-------------------------------
    If (Not ps.AddFrame("frmMain_CFile", 100, 1800, 4175, 925, "Main Source File")) Then Exit Function
        If (Not ps.AddText("txtCFile", 1500, 350, 2400, 315)) Then Exit Function
        If (Not ps.AddLabel("lblCFile", 0, 200, 400, 1175, 300, "File name")) Then Exit Function

    '-------------------------------
    ' frame: frmMain_HFile
    '-------------------------------
    If (Not ps.AddFrame("frmMain_HFile", 4375, 1800, 4175, 925, "Main Header File")) Then Exit Function
        If (Not ps.AddText("txtHFile", 1500, 350, 2400, 315)) Then Exit Function
        If (Not ps.AddLabel("lblHFile", 0, 200, 400, 1075, 300, "File name")) Then Exit Function

    '-------------------------------
    ' frame: frmCompiler_Settings
    '-------------------------------
    If (Not ps.AddFrame("frmCompiler_Settings", 100, 2775, 8450, 1200, "Compiler Settings")) Then Exit Function
        If (Not ps.AddOption("optKeil", 200, 350, 1600, 300, "Keil")) Then Exit Function
        If (Not ps.AddOption("optTasking", 200, 750, 1800, 300, "Tasking")) Then Exit Function
        If (Not ps.AddCombo("cboMemory_Model", 5775, 350, 2400, 300)) Then Exit Function
        If (Not ps.AddLabel("lblMemory_Model", 0, 4475, 400, 1225, 300, "Memory Model:")) Then Exit Function

  End If

  OnChangingPageGeneral = True
ExitLabel:
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 OnShowPageGeneral(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageGeneralError
  OnShowPageGeneral = False
     
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim sMC_Name As String

  sMC_Name = DefGetValue("Name")

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

  If (Pagename = "General") Then
    '-------------------------------------------------------------------------
    ' page: General (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: cboType (action)
        '---------------------------------------------------------------------
        Case "cboType"
            ' Note:
            ' update the "EA_EA" setting (fetch code from internal or external memory) is
'            ' only necessary if switching from a ROM Type to a ROMless Type

            ' Note:
            ' the Clock System was not changed because if the clock is too high
            ' this is shown in the dialog.
            If (Ask(MSG_CHANGE_CONTROLLER)) Then
                If (v(1) = sMC_Name & "-8F20" Or v(1) = sMC_Name & "-8F40") Then
                    r.v("MAIN_CPU_TYPE") = v(1)
                    r.v("MAIN_ROM_Type") = "Flash"
                    r.v("MAIN_ROM_Size") = 64
                End If
                If (v(1) = sMC_Name & "-4F20" Or v(1) = sMC_Name & "-4F40") Then
                    r.v("MAIN_CPU_TYPE") = v(1)
                    r.v("MAIN_ROM_Type") = "Flash"
                    r.v("MAIN_ROM_Size") = 32
                End If
                r.d("MAIN_CLK_CPU") = GetMaxFcpu(r) ' depends on "MAIN_CPU_TYPE"
            End If

        '---------------------------------------------------------------------
        ' control: txtCFile (action)
        '---------------------------------------------------------------------
        Case "txtCFile"
             If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblCFile").Caption, , )) Then
               r.v("MAIN_CFile") = v(1)
             Else
                 Exit Function
             End If

        '---------------------------------------------------------------------
        ' control: txtMAIN_HFile (action)
        '---------------------------------------------------------------------
        Case "txtHFile"
             If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblHFile").Caption, , )) Then
               r.v("MAIN_HFile") = v(1)
             Else
                 Exit Function
             End If


        '---------------------------------------------------------------------
        ' control: optKeil (action)
        '---------------------------------------------------------------------
        Case "optKeil"
             r.v("MAIN_COMPILER") = "Keil"
             r.v("MAIN_MEMORY") = "SMALL"

        '---------------------------------------------------------------------
        ' control: optTasking (action)
        '---------------------------------------------------------------------
        Case "optTasking"
             r.v("MAIN_COMPILER") = "Tasking"
             r.v("MAIN_MEMORY") = "SMALL"

        '---------------------------------------------------------------------
        ' control: cboMemory_Model (action)
        '---------------------------------------------------------------------
        Case "cboMemory_Model"
              If (v(1) = "TINY") Then
                r.v("MAIN_MEMORY") = "TINY"
              End If
              If (v(1) = "SMALL") Then
                r.v("MAIN_MEMORY") = "SMALL"
              End If
              If (v(1) = "COMPACT") Then
                r.v("MAIN_MEMORY") = "COMPACT"
              End If
              If (v(1) = "HCOMPACT") Then
                r.v("MAIN_MEMORY") = "HCOMPACT"
              End If
              If (v(1) = "MEDIUM") Then
                r.v("MAIN_MEMORY") = "MEDIUM"
              End If
              If (v(1) = "LARGE") Then
                r.v("MAIN_MEMORY") = "LARGE"
              End If
              If (v(1) = "HLARGE") Then
                r.v("MAIN_MEMORY") = "HLARGE"
              End If

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: General (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: cboType (show)
    '-------------------------------------------------------------------------
    With c("cboType")
      .Enabled = True
      .Clear
      
      If (sMC_Name = "XC164CM") Then
          .AddItem sMC_Name & "-8F20"
          .AddItem sMC_Name & "-8F40"
          .AddItem sMC_Name & "-4F20"
          .AddItem sMC_Name & "-4F40"
          If (r.v("MAIN_CPU_TYPE") = sMC_Name & "-8F20") Then
              .ListIndex = 0
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-8F40") Then
              .ListIndex = 1
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-4F20") Then
              .ListIndex = 2
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-4F40") Then
              .ListIndex = 3
          End If
      End If

    End With

    '-------------------------------------------------------------------------
    ' control: lblType (show)
    '-------------------------------------------------------------------------
    With c("lblType")
    End With

    '-------------------------------------------------------------------------
    ' control: txtROM_Size (show)
    '-------------------------------------------------------------------------
    With c("txtROM_Size")
      .Caption = r.v("MAIN_ROM_Size") & " KByte"
    End With

    '-------------------------------------------------------------------------
    ' control: lblROM_Size (show)
    '-------------------------------------------------------------------------
    With c("lblROM_Size")
    End With

    '-------------------------------------------------------------------------
    ' control: txtROM_Type (show)
    '-------------------------------------------------------------------------
    With c("txtROM_Type")
      .Caption = r.v("MAIN_ROM_Type")
    End With

    '-------------------------------------------------------------------------
    ' control: lblROM_Type (show)
    '-------------------------------------------------------------------------
    With c("lblROM_Type")
    End With

    '-------------------------------------------------------------------------
    ' control: Max_CPU_Clock (show)
    '-------------------------------------------------------------------------
    With c("Max_CPU_Clock")
      .Caption = r.d("MAIN_CLK_CPU") & " MHz"
    End With

    '-------------------------------------------------------------------------
    ' control: lblMax_CPU_Clock (show)
    '-------------------------------------------------------------------------
    With c("lblMax_CPU_Clock")
    End With

    '-------------------------------------------------------------------------
    ' control: txtCFile (show)
    '-------------------------------------------------------------------------
    With c("txtCFile")
      .Text = r.v("MAIN_CFile")
    End With

    '-------------------------------------------------------------------------
    ' control: lblCFile (show)
    '-------------------------------------------------------------------------
    With c("lblCFile")
    End With

    '-------------------------------------------------------------------------
    ' control: txtHFile (show)
    '-------------------------------------------------------------------------
    With c("txtHFile")
      .Text = r.v("MAIN_HFile")
    End With

    '-------------------------------------------------------------------------
    ' control: lblHFile (show)
    '-------------------------------------------------------------------------
    With c("lblHFile")
    End With

    '-------------------------------------------------------------------------
    ' control: optKeil (show)
    '-------------------------------------------------------------------------
    With c("optKeil")
      bDisabled = False
       .Enabled = Not (bDisabled)
      .Value = -CInt(r.v("MAIN_COMPILER") = "Keil")
    End With

    '-------------------------------------------------------------------------
    ' control: optTasking (show)
    '-------------------------------------------------------------------------
    With c("optTasking")
      bDisabled = False
       .Enabled = Not (bDisabled)
      .Value = -CInt(r.v("MAIN_COMPILER") = "Tasking")
    End With

    '-------------------------------------------------------------------------
    ' control: cboMemory_Model (show)
    '-------------------------------------------------------------------------
    With c("cboMemory_Model")
      .Enabled = True
      .Clear
      If (r.v("MAIN_COMPILER") = "Keil") Then
          .AddItem "TINY"
          .AddItem "SMALL"
          .AddItem "COMPACT"
          .AddItem "HCOMPACT"
          .AddItem "MEDIUM"
          .AddItem "LARGE"
          .AddItem "HLARGE"
      Else
          .AddItem "TINY"
          .AddItem "SMALL"
          .AddItem "MEDIUM"
          .AddItem "LARGE"
      End If

      If (r.v("MAIN_COMPILER") = "Keil") Then
          If (r.v("MAIN_MEMORY") = "TINY") Then
            .ListIndex = 0
          End If
          If (r.v("MAIN_MEMORY") = "SMALL") Then
            .ListIndex = 1
          End If
          If (r.v("MAIN_MEMORY") = "COMPACT") Then
            .ListIndex = 2
          End If
          If (r.v("MAIN_MEMORY") = "HCOMPACT") Then
            .ListIndex = 3
          End If
          If (r.v("MAIN_MEMORY") = "MEDIUM") Then
            .ListIndex = 4
          End If
          If (r.v("MAIN_MEMORY") = "LARGE") Then
            .ListIndex = 5
          End If
          If (r.v("MAIN_MEMORY") = "HLARGE") Then
            .ListIndex = 6
          End If
      Else
          If (r.v("MAIN_MEMORY") = "TINY") Then
            .ListIndex = 0
          End If
          If (r.v("MAIN_MEMORY") = "SMALL") Then
            .ListIndex = 1
          End If
          If (r.v("MAIN_MEMORY") = "MEDIUM") Then
            .ListIndex = 2
          End If
          If (r.v("MAIN_MEMORY") = "LARGE") Then
            .ListIndex = 3
          End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblMemory_Model (show)
    '-------------------------------------------------------------------------
    With c("lblMemory_Model")
    End With


  End If         ' if Pagename

  OnShowPageGeneral = True
  Exit Function

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

  OnLoadPageSystemClock = False

  If (Not ps.AddPage("System Clock")) Then Exit Function

  OnLoadPageSystemClock = 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 OnChangingPageSystemClock(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageSystemClock = False
  
  If (Not ps.ExtenderCollection("System Clock").Loaded) And (Pagename = "System Clock") Then
    ps.ExtenderCollection("System Clock").Loaded = True
  

    '-------------------------------
    ' frame: frmPLLCTRL
    '-------------------------------
    If (Not ps.AddFrame("frmPLLCTRL", 100, 100, 4150, 2375, _
      "PLL Operation Control (PLLCTRL)")) Then Exit Function
        If (Not ps.AddOption("optPLLCTRL_0", 200, 350, 3900, 400, _
          "Bypass PLL clock multiplier; the VCO is off")) Then Exit Function
        If (Not ps.AddOption("optPLLCTRL_1", 200, 800, 3900, 400, _
          "Bypass PLL clock multiplier; the VCO is running")) Then Exit Function
        If (Not ps.AddOption("optPLLCTRL_2", 200, 1250, 3900, 400, _
          "VCO clock used, input clock switched off")) Then Exit Function
        If (Not ps.AddOption("optPLLCTRL_3", 200, 1700, 3900, 400, _
          "VCO clock used, input clock connected")) Then Exit Function

    '-------------------------------
    ' frame: frmOSC
    '-------------------------------
    If (Not ps.AddFrame("frmOSC", 4400, 100, 4150, 800, "Input Frequency")) Then Exit Function
        If (Not ps.AddText("txtOSC", 1800, 300, 1000, 300)) Then Exit Function
        If (Not ps.AddLabel("lblOSC", 0, 800, 350, 850, 335, _
          "fosc [MHz]")) Then Exit Function

    '-------------------------------
    ' frame: frmPLLVB
    '-------------------------------
    If (Not ps.AddFrame("frmPLLVB", 4400, 950, 4150, 1525, _
      "PLL VCO Band Control (PLLVB)")) Then Exit Function
        If (Not ps.AddOption("optPLLVB_0", 200, 250, 3500, 375, _
          "VCO output frequency 100 .. 150 MHz")) Then Exit Function
        If (Not ps.AddOption("optPLLVB_1", 200, 650, 3500, 380, _
          "VCO output frequency 150 .. 200 MHz")) Then Exit Function
        If (Not ps.AddOption("optPLLVB_2", 200, 1050, 3500, 380, _
          "VCO output frequency 200 .. 250 MHz")) Then Exit Function

    '-------------------------------
    ' frame: frmPLLIDIV
    '-------------------------------
    If (Not ps.AddFrame("frmPLLIDIV", 100, 2500, 4150, 1000, _
      "PLL Input Divider (PLLIDIV)")) Then Exit Function
        If (Not ps.AddCombo("cboPLLIDIV", 200, 400, 1450, 315)) Then Exit Function
        If (Not ps.AddLabel("lblIN", 0, 2000, 450, 825, 345, _
          "fin [MHz]")) Then Exit Function
        If (Not ps.AddLabel("txtIN", 1, 2950, 400, 1000, 315, "")) Then Exit Function

    '-------------------------------
    ' frame: frmPLLMUL
    '-------------------------------
    If (Not ps.AddFrame("frmPLLMUL", 4400, 2500, 4150, 1000, _
      "PLL Multiplication Factor (PLLMUL)")) Then Exit Function
        If (Not ps.AddCombo("cboPLLMUL", 200, 400, 1450, 315)) Then Exit Function
        If (Not ps.AddLabel("lblVCO", 0, 2000, 450, 825, 345, _
          "fvco [MHz]")) Then Exit Function
        If (Not ps.AddLabel("txtVCO", 1, 2950, 400, 1000, 315, "")) Then Exit Function

    '-------------------------------
    ' frame: frmPLLODIV
    '-------------------------------
    If (Not ps.AddFrame("frmPLLODIV", 100, 3550, 4150, 1000, _
      "PLL Output Divider (PLLODIV)")) Then Exit Function
        If (Not ps.AddCombo("cboPLLODIV", 200, 400, 1450, 315)) Then Exit Function
        If (Not ps.AddLabel("lblPLL", 0, 2000, 450, 850, 310, _
          "fpll [MHz]")) Then Exit Function
        If (Not ps.AddLabel("txtPLL", 1, 2950, 400, 1000, 315, "")) Then Exit Function

    '-------------------------------
    ' frame: frmCPSYS
    '-------------------------------
    If (Not ps.AddFrame("frmCPSYS", 4400, 3550, 4150, 1000, _
      "Clock Prescaler for System (CPSYS)")) Then Exit Function
        If (Not ps.AddLabel("lblCPU", 0, 2000, 450, 850, 335, _
          "fcpu [MHz]")) Then Exit Function
        If (Not ps.AddLabel("txtCPU", 1, 2950, 400, 1000, 315, "")) Then Exit Function
        If (Not ps.AddCombo("cboCPSYS", 200, 400, 1450, 315)) Then Exit Function

    '-------------------------------
    ' frame: frmCPPD
    '-------------------------------
'    If (Not ps.AddFrame("frmCPPD", 100, 4600, 4150, 800, _
'      "Clock Prescaler for PD+ bus (CPPD)")) Then Exit Function
'        If (Not ps.AddCombo("cboCPPD", 200, 300, 1450, 315)) Then Exit Function
'        If (Not ps.AddLabel("lblPD", 0, 2000, 350, 850, 335, _
'          "fpd [MHz]")) Then Exit Function
'        If (Not ps.AddLabel("txtPD", 1, 2950, 300, 1000, 315, "")) Then Exit Function
  End If
  OnChangingPageSystemClock = 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 OnShowPageSystemClock(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageSystemClockError

  OnShowPageSystemClock = False

  Dim r           As ProjectData
  Dim c           As Object
  Dim e           As Object
  Dim i           As Integer
  Dim vTemp       As Variant
  Dim bDisabled   As Boolean

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

  If (Pagename = "System Clock") Then
    '-------------------------------------------------------------------------
    ' page: SystemClock (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optPLLCTRL_0 (action)
        '---------------------------------------------------------------------
        Case "optPLLCTRL_0"
            vTemp = r.v("PLLCON_PLLCTRL")
            r.v("PLLCON_PLLCTRL") = 0
            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("PLLCON_PLLCTRL") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: optPLLCTRL_1 (action)
        '---------------------------------------------------------------------
        Case "optPLLCTRL_1"
            vTemp = r.v("PLLCON_PLLCTRL")
            r.v("PLLCON_PLLCTRL") = 1
            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("PLLCON_PLLCTRL") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: optPLLCTRL_2 (action)
        '---------------------------------------------------------------------
        Case "optPLLCTRL_2"
            vTemp = r.v("PLLCON_PLLCTRL")
            r.v("PLLCON_PLLCTRL") = 2
            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("PLLCON_PLLCTRL") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: optPLLCTRL_3 (action)
        '---------------------------------------------------------------------
        Case "optPLLCTRL_3"
            vTemp = r.v("PLLCON_PLLCTRL")
            r.v("PLLCON_PLLCTRL") = 3
            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("PLLCON_PLLCTRL") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: txtOSC (action)
        '---------------------------------------------------------------------
        Case "txtOSC"
            vTemp = r.v("MAIN_OSC")
            If (IsInputFormatOK(v(1), "F", c("lblOSC").Caption, GetMinFosc(r), GetMaxFosc(r))) Then
                r.v("MAIN_OSC") = v(1)
            Else
                Exit Function
            End If

            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("MAIN_OSC") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: optPLLVB_0 (action)
        '---------------------------------------------------------------------
        Case "optPLLVB_0"
            vTemp = r.v("PLLCON_PLLVB")
            r.v("PLLCON_PLLVB") = 0
            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("PLLCON_PLLVB") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: optPLLVB_1 (action)
        '---------------------------------------------------------------------
        Case "optPLLVB_1"
            vTemp = r.v("PLLCON_PLLVB")
            r.v("PLLCON_PLLVB") = 1
            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("PLLCON_PLLVB") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: optPLLVB_2 (action)
        '---------------------------------------------------------------------
        Case "optPLLVB_2"
            vTemp = r.v("PLLCON_PLLVB")
            r.v("PLLCON_PLLVB") = 2
            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("PLLCON_PLLVB") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: cboPLLIDIV (action)
        '---------------------------------------------------------------------
        Case "cboPLLIDIV"
            vTemp = r.v("PLLCON_PLLIDIV")
            r.v("PLLCON_PLLIDIV") = c("cboPLLIDIV").ListIndex
            'If (v(1) = "fin = fosc / 1") Then
            '    r.v("PLLCON_PLLIDIV") = 0
            'ElseIf (v(1) = "fin = fosc / 2") Then
            '    r.v("PLLCON_PLLIDIV") = 1
            'End If
            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("PLLCON_PLLIDIV") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: cboPLLMUL (action)
        '---------------------------------------------------------------------
        Case "cboPLLMUL"
            vTemp = r.v("PLLCON_PLLMUL")
            For i = 8 To 32
                If (v(1) = "fvco = fin * " & i) Then
                    r.v("PLLCON_PLLMUL") = i - 1
                    Exit For
                End If
            Next i
            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("PLLCON_PLLMUL") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: cboPLLODIV (action)
        '---------------------------------------------------------------------
        Case "cboPLLODIV"
            vTemp = r.v("PLLCON_PLLODIV")
            If (r.v("PLLCON_PLLCTRL") = 3) Then
                For i = 1 To 16
                    If (v(1) = "fpll = fvco / " & i) Then
                        r.v("PLLCON_PLLODIV") = i - 1
                        Exit For
                    End If
                Next i
            Else
                For i = 1 To 16
                    If (v(1) = "fpll = fin / " & i) Then
                        r.v("PLLCON_PLLODIV") = i - 1
                        Exit For
                    End If
                Next i
            End If
            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("PLLCON_PLLODIV") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: cboCPSYS (action)
        '---------------------------------------------------------------------
        Case "cboCPSYS"
            vTemp = r.v("SYSCON1_CPSYS")
            For i = 1 To 2
                If (v(1) = "fcpu = fpll / " & i) Then
                    r.v("SYSCON1_CPSYS") = i - 1
                End If
            Next i
            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
                r.v("SYSCON1_CPSYS") = vTemp
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: cboCPPD (action)
        '---------------------------------------------------------------------
'        Case "cboCPPD"
'            vTemp = r.v("SYSCON1_CPPD")
'            For i = 1 To 2
'                If (v(1) = "fpd = fcpu / " & i) Then
'                    r.v("SYSCON1_CPPD") = i - 1
'                End If
'            Next i
'            If (Not UpdateAllPeripherals(r, UPDATE_CLOCK, True)) Then
'                r.v("SYSCON1_CPPD") = vTemp
'                Exit Function
'            End If
'      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: SystemClock (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: optPLLCTRL_0 (show)
    '-------------------------------------------------------------------------
    With c("optPLLCTRL_0")
        bDisabled = False
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v("PLLCON_PLLCTRL") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optPLLCTRL_1 (show)
    '-------------------------------------------------------------------------
    With c("optPLLCTRL_1")
        bDisabled = False
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v("PLLCON_PLLCTRL") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: optPLLCTRL_2 (show)
    '-------------------------------------------------------------------------
    With c("optPLLCTRL_2")
        bDisabled = True
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v("PLLCON_PLLCTRL") = 2)
    End With

    With e("optPLLCTRL_2")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            .DisabledTooltipText = .DisabledTooltipText & _
              FormatDisabledTooltip("this setting is not possible")
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optPLLCTRL_3 (show)
    '-------------------------------------------------------------------------
    With c("optPLLCTRL_3")
        bDisabled = False
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v("PLLCON_PLLCTRL") = 3)
    End With

    '-------------------------------------------------------------------------
    ' control: txtOSC (show)
    '-------------------------------------------------------------------------
    With c("txtOSC")
        bDisabled = False
        .Enabled = Not (bDisabled)
        .Text = Format(r.v("MAIN_OSC"), "0.000")
    End With

    '-------------------------------------------------------------------------
    ' control: lblOSC (show)
    '-------------------------------------------------------------------------
    With c("lblOSC")
    End With


    '-------------------------------------------------------------------------
    ' control: optPLLVB_0 (show)
    '-------------------------------------------------------------------------
    With c("optPLLVB_0")
        bDisabled = (r.v("PLLCON_PLLCTRL") = 0)
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v("PLLCON_PLLVB") = 0)
    End With

    With e("optPLLVB_0")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (r.v("PLLCON_PLLCTRL") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("VCO is off")
            End If
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optPLLVB_1 (show)
    '-------------------------------------------------------------------------
    With c("optPLLVB_1")
        'bDisabled = (r.v("PLLCON_PLLCTRL") = 0)
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v("PLLCON_PLLVB") = 1)
    End With

    With e("optPLLVB_1")
        If (bDisabled) Then
            .DisabledTooltipText = e("optPLLVB_0").DisabledTooltipText
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optPLLVB_2 (show)
    '-------------------------------------------------------------------------
    With c("optPLLVB_2")
        'bDisabled = (r.v("PLLCON_PLLCTRL") = 0)
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v("PLLCON_PLLVB") = 2)
    End With

    With e("optPLLVB_2")
        If (bDisabled) Then
            .DisabledTooltipText = e("optPLLVB_0").DisabledTooltipText
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: cboPLLIDIV (show)
    '-------------------------------------------------------------------------
    With c("cboPLLIDIV")
        bDisabled = False
        .Enabled = Not (bDisabled)

        .Clear
        .AddItem "fin = fosc / 1"
        .AddItem "fin = fosc / 2"
        .AddItem "fin = fosc / 3"
        .AddItem "fin = fosc / 4"
        .ListIndex = r.v("PLLCON_PLLIDIV")
    End With

    '-------------------------------------------------------------------------
    ' control: lblIN (show)
    '-------------------------------------------------------------------------
    With c("lblIN")
    End With

    '-------------------------------------------------------------------------
    ' control: txtIN (show)
    '-------------------------------------------------------------------------
    With c("txtIN")
        .Caption = Get_FIN(r)
    End With

    '-------------------------------------------------------------------------
    ' control: cboPLLMUL (show)
    '-------------------------------------------------------------------------
    With c("cboPLLMUL")
        bDisabled = (r.v("PLLCON_PLLCTRL") = 0)
        .Enabled = Not (bDisabled)

        .Clear
        For i = 8 To 32
            .AddItem "fvco = fin * " & i
        Next i
        .ListIndex = r.v("PLLCON_PLLMUL") - 7
    End With

    With e("cboPLLMUL")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (r.v("PLLCON_PLLCTRL") = 0) Then
                
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("PLL is off")
            End If
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblVCO (show)
    '-------------------------------------------------------------------------
    With c("lblVCO")
    End With

    '-------------------------------------------------------------------------
    ' control: txtVCO (show)
    '-------------------------------------------------------------------------
    With c("txtVCO")
        If (r.v("PLLCON_PLLCTRL") = 0) Then
            .Caption = CALCULATION_NOT_POSSIBLE
        Else
            .Caption = Get_FVCO(r)
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: cboPLLODIV (show)
    '-------------------------------------------------------------------------
    With c("cboPLLODIV")
        bDisabled = False
        .Enabled = Not (bDisabled)

        .Clear
        If (r.v("PLLCON_PLLCTRL") = 3) Then
            For i = 1 To 16
                .AddItem "fpll = fvco / " & i
            Next i
        Else
            For i = 1 To 16
                .AddItem "fpll = fin / " & i
            Next i
        End If
        .ListIndex = r.v("PLLCON_PLLODIV")
    End With

    '-------------------------------------------------------------------------
    ' control: txtPLL (show)
    '-------------------------------------------------------------------------
    With c("txtPLL")
        .Caption = Get_FPLL(r)
    End With

    '-------------------------------------------------------------------------
    ' control: lblPLL (show)
    '-------------------------------------------------------------------------
    With c("lblPLL")
    End With

    '-------------------------------------------------------------------------
    ' control: cboCPSYS (show)
    '-------------------------------------------------------------------------
    With c("cboCPSYS")
        bDisabled = False
        .Enabled = Not (bDisabled)

        .Clear
        For i = 1 To 2
            .AddItem "fcpu = fpll / " & i
        Next i
        .ListIndex = r.v("SYSCON1_CPSYS")
    End With

    '-------------------------------------------------------------------------
    ' control: lblCPU (show)
    '-------------------------------------------------------------------------
    With c("lblCPU")
    End With

    '-------------------------------------------------------------------------
    ' control: txtCPU (show)
    '-------------------------------------------------------------------------
    With c("txtCPU")
        .Caption = Get_FCPU(r)
    End With

    '-------------------------------------------------------------------------
    ' control: cboCPSYS (show)
    '-------------------------------------------------------------------------
'    With c("cboCPPD")
'        bDisabled = True
'        .Enabled = Not (bDisabled)
'
'        .Clear
'        For i = 1 To 2
'            .AddItem "fpd = fcpu / " & i
'        Next i
'        .ListIndex = r.v("SYSCON1_CPPD")
'    End With
'
'    With e("cboCPPD")
'        If (bDisabled) Then
'            .DisabledTooltipText = TOOLTIP_DISABLED_IF
'            .DisabledTooltipText = .DisabledTooltipText & _
'                                    FormatDisabledTooltip("Fcpu = Fpd")
'        End If
'    End With
    '-------------------------------------------------------------------------
    ' control: lblCPU (show)
    '-------------------------------------------------------------------------
 '   With c("lblPD")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblCPU
 '   End With

    '-------------------------------------------------------------------------
    ' control: txtCPU (show)
    '-------------------------------------------------------------------------
'    With c("txtPD")
'        .Caption = Get_FPD(r)
'    End With
  End If

  OnShowPageSystemClock = True
  Exit Function

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

  OnLoadPageGlobalSettings = False

  If (Not ps.AddPage("Global Settings")) Then Exit Function

  OnLoadPageGlobalSettings = 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 OnChangingPageGlobalSettings(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageGlobalSettings = False
  
  If (Not ps.ExtenderCollection("Global Settings").Loaded) And (Pagename = "Global Settings") Then
    ps.ExtenderCollection("Global Settings").Loaded = True
  

    '-------------------------------
    ' frame: frmIEN
    '-------------------------------
    If (Not ps.AddFrame("frmIEN", 100, 100, 4375, 1000, "Global Interrupt Enable")) Then Exit Function
        If (Not ps.AddCheck("chkIEN", 200, 400, 2300, 300, "Enable global interrupt (IEN)")) Then Exit Function

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

  OnShowPageGlobalSettings = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean

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

  If (Pagename = "Global Settings") Then
    '-------------------------------------------------------------------------
    ' page: GlobalSettings (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkIEN (action)
        '---------------------------------------------------------------------
        Case "chkIEN"
             r.v("PSW_IEN") = v(1)

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: GlobalSettings (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: chkIEN (show)
    '-------------------------------------------------------------------------
    With c("chkIEN")
      bDisabled = False
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v("PSW_IEN") = 1)
    End With

    With e("chkIEN")
      If (bDisabled) Then
        'tooltip if disabled
      Else
        'tooltip if enabled
      End If
    End With

  End If

  OnShowPageGlobalSettings = True
  Exit Function

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

  OnLoadPageMainCPUCON1 = False

  If (Not ps.AddPage("CPUCON1 / VECSEG")) Then Exit Function

  OnLoadPageMainCPUCON1 = 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 OnChangingPageMainCPUCON1(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageMainCPUCON1 = False
  
  If (Not ps.ExtenderCollection("CPUCON1 / VECSEG").Loaded) And (Pagename = "CPUCON1 / VECSEG") Then
    ps.ExtenderCollection("CPUCON1 / VECSEG").Loaded = True
  

    '-------------------------------
    ' frame: frmVECSC
    '-------------------------------
    If (Not ps.AddFrame("frmVECSC", 100, 100, 4100, 1100, "Scaling factor of Vector Table (VECSC)")) Then Exit Function
        If (Not ps.AddCombo("cboVECSC", 200, 450, 3700, 315)) Then Exit Function

    '-------------------------------
    ' frame: frmWDTCTL
    '-------------------------------
    If (Not ps.AddFrame("frmWDTCTL", 4400, 100, 4150, 1100, "WDT Configuration (WDTCTL)")) Then Exit Function
        If (Not ps.AddOption("optWDTCTL_0", 200, 250, 3450, 380, "DISWDT executable until End of Init")) Then Exit Function
        If (Not ps.AddOption("optWDTCTL_1", 200, 600, 3450, 380, "DISWDT/ENWDT always executable")) Then Exit Function

    '-------------------------------
    ' frame: frmSGTDIS
    '-------------------------------
    If (Not ps.AddFrame("frmSGTDIS", 100, 1300, 4100, 1100, "Segmentation Control")) Then Exit Function
        If (Not ps.AddCheck("chkSGTDIS", 200, 400, 3550, 380, "Disable segmentation (SGTDIS)")) Then Exit Function

    '-------------------------------
    ' frame: frmINTSCXT
    '-------------------------------
    If (Not ps.AddFrame("frmINTSCXT", 4400, 1300, 4150, 1100, "Interruptibility of Switch Context (INTSCXT)")) Then Exit Function
        If (Not ps.AddOption("optINTSCXT_0", 200, 250, 3650, 380, "Switch context is not interruptible")) Then Exit Function
        If (Not ps.AddOption("optINTSCXT_1", 200, 600, 3650, 400, "Switch context is interruptible")) Then Exit Function

    '-------------------------------
    ' frame: frmBP
    '-------------------------------
    If (Not ps.AddFrame("frmBP", 100, 2500, 4100, 900, "Branch Prediction Unit Control")) Then Exit Function
        If (Not ps.AddCheck("chkBP", 200, 300, 3250, 380, "Enable branch prediction (BP)")) Then Exit Function

    '-------------------------------
    ' frame: frmZCJ
    '-------------------------------
    If (Not ps.AddFrame("frmZCJ", 4400, 2500, 4150, 900, "Zero Cycle Jump function Control")) Then Exit Function
        If (Not ps.AddCheck("chkZCJ", 200, 300, 3400, 380, "Enable zero cycle jump function (ZCJ)")) Then Exit Function

    '-------------------------------
    ' frame: frmVECSEG
    '-------------------------------
    If (Not ps.AddFrame("frmVECSEG", 100, 3500, 4100, 1500, "Vector Segment Pointer (VECSEG)")) Then Exit Function
        If (Not ps.AddOption("optVECSEG_0", 200, 250, 3050, 350, "Start from internal program memory")) Then Exit Function
        'If (Not ps.AddOption("optVECSEG_1", 200, 600, 3050, 350, "Start from boot memory")) Then Exit Function
        If (Not ps.AddOption("optVECSEG_2", 200, 600, 3050, 350, "Start from external memory")) Then Exit Function
        If (Not ps.AddLabel("lblVECSEG", 0, 250, 1100, 1300, 300, "VECSEG")) Then Exit Function
        If (Not ps.AddText("txtVECSEG", 1850, 1050, 1000, 315)) Then Exit Function

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

  OnShowPageMainCPUCON1 = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim sRegName As String

  sRegName = "CPUCON1_"

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

  If (Pagename = "CPUCON1 / VECSEG") Then
    '-------------------------------------------------------------------------
    ' page: MainCPUCON1 (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkSGTDIS (action)
        '---------------------------------------------------------------------
        Case "chkSGTDIS"
            r.v(sRegName & "SGTDIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkBP (action)
        '---------------------------------------------------------------------
        Case "chkBP"
            r.v(sRegName & "BP") = v(1)

        '---------------------------------------------------------------------
        ' control: chk2 (action)
        '---------------------------------------------------------------------
        Case "chkZCJ"
            r.v(sRegName & "ZCJ") = v(1)

        '---------------------------------------------------------------------
        ' control: optINTSCXT_0 (action)
        '---------------------------------------------------------------------
        Case "optINTSCXT_0"
            r.v(sRegName & "INTSCXT") = 0

        '---------------------------------------------------------------------
        ' control: optINTSCXT_1 (action)
        '---------------------------------------------------------------------
        Case "optINTSCXT_1"
            r.v(sRegName & "INTSCXT") = 1

        '---------------------------------------------------------------------
        ' control: opt2 (action)
        '---------------------------------------------------------------------
        Case "optWDTCTL_0"
            r.v(sRegName & "WDTCTL") = 0

        '---------------------------------------------------------------------
        ' control: opt3 (action)
        '---------------------------------------------------------------------
        Case "optWDTCTL_1"
            r.v(sRegName & "WDTCTL") = 1

        '---------------------------------------------------------------------
        ' control: cbo0 (action)
        '---------------------------------------------------------------------
        Case "cboVECSC"
            r.v(sRegName & "VECSC") = c("cboVECSC").ListIndex
            
        '---------------------------------------------------------------------
        ' control: optVECSEG_0 (action)
        '---------------------------------------------------------------------
        Case "optVECSEG_0"
            r.sfr("VECSEG") = &HC0

        '---------------------------------------------------------------------
        ' control: optVECSEG_1 (action)
        '---------------------------------------------------------------------
        'Case "optVECSEG_1"
        '    r.sfr("VECSEG") = &HBF

        '---------------------------------------------------------------------
        ' control: optVECSEG_2 (action)
        '---------------------------------------------------------------------
        Case "optVECSEG_2"
            r.sfr("VECSEG") = 0

        '---------------------------------------------------------------------
        ' control: txtVECSEG (action)
        '---------------------------------------------------------------------
        Case "txtVECSEG"
            If (IsInputFormatOK(v(1), "H2", c("lblVECSEG").Caption, 0, &HFF)) Then
                r.sfr("VECSEG") = v(1)
            Else
                Exit Function
            End If

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: MainCPUCON1 (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: chkSGTDIS (show)
    '-------------------------------------------------------------------------
    With c("chkSGTDIS")
        .Value = -CInt(r.v(sRegName & "SGTDIS") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkBP (show)
    '-------------------------------------------------------------------------
    With c("chkBP")
        .Value = -CInt(r.v(sRegName & "BP") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chk2 (show)
    '-------------------------------------------------------------------------
    With c("chkZCJ")
        .Value = -CInt(r.v(sRegName & "ZCJ") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: optINTSCXT_0 (show)
    '-------------------------------------------------------------------------
    With c("optINTSCXT_0")
        .Value = -CInt(r.v(sRegName & "INTSCXT") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optINTSCXT_1 (show)
    '-------------------------------------------------------------------------
    With c("optINTSCXT_1")
        .Value = -CInt(r.v(sRegName & "INTSCXT") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: opt2 (show)
    '-------------------------------------------------------------------------
    With c("optWDTCTL_0")
        .Value = -CInt(r.v(sRegName & "WDTCTL") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: opt3 (show)
    '-------------------------------------------------------------------------
    With c("optWDTCTL_1")
        .Value = -CInt(r.v(sRegName & "WDTCTL") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: cbo0 (show)
    '-------------------------------------------------------------------------
    With c("cboVECSC")
        .Clear
        .AddItem "Space between two vectors is 2 words"
        .AddItem "Space between two vectors is 4 words"
        .AddItem "Space between two vectors is 8 words"
        .AddItem "Space between two vectors is 16 words"
        .ListIndex = r.v(sRegName & "VECSC")
    End With

    '-------------------------------------------------------------------------
    ' control: optVECSEG_0 (show)
    '-------------------------------------------------------------------------
    With c("optVECSEG_0")
        .Value = -CInt(r.sfr("VECSEG") = &HC0)
    End With

    '-------------------------------------------------------------------------
    ' control: optVECSEG_1 (show)
    '-------------------------------------------------------------------------
    'With c("optVECSEG_1")
    '    .Value = -CInt(r.sfr("VECSEG") = &HBF)
    'End With

    '-------------------------------------------------------------------------
    ' control: optVECSEG_2 (show)
    '-------------------------------------------------------------------------
    With c("optVECSEG_2")
        .Value = -CInt(r.sfr("VECSEG") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: lblVECSEG (show)
    '-------------------------------------------------------------------------
    With c("lblVECSEG")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblVECSEG
    End With

    '-------------------------------------------------------------------------
    ' control: txtVECSEG (show)
    '-------------------------------------------------------------------------
    With c("txtVECSEG")
        .Text = FormatTextOutput(r.sfr("VECSEG"), "H2")
    End With

  End If

  OnShowPageMainCPUCON1 = True
  Exit Function

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

  OnLoadPageMainCPUCON2 = False

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

  OnLoadPageMainCPUCON2 = 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 OnChangingPageMainCPUCON2(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageMainCPUCON2 = False
  
  If (Not ps.ExtenderCollection("CPUCON2").Loaded) And (Pagename = "CPUCON2") Then
    ps.ExtenderCollection("CPUCON2").Loaded = True
  

    '-------------------------------
    ' frame: frmFIFOFED
    '-------------------------------
    If (Not ps.AddFrame("frmFIFOFED", 100, 100, 4100, 850, "FIFO Fed Configuration (FIFOFED)")) Then Exit Function
        If (Not ps.AddCombo("cboFIFOFED", 200, 350, 3650, 315)) Then Exit Function

    '-------------------------------
    ' frame: frmFIFODEPTH
    '-------------------------------
    If (Not ps.AddFrame("frmFIFODEPTH", 4400, 100, 4150, 850, "FIFO Depth Configuration (FIFODEPTH)")) Then Exit Function
        If (Not ps.AddCombo("cboFIFODEPTH", 200, 350, 3800, 315)) Then Exit Function

    '-------------------------------
    ' frame: frmBYPPF
    '-------------------------------
    If (Not ps.AddFrame("frmBYPPF", 100, 1050, 2750, 850, "Prefetch Bypass Control")) Then Exit Function
        If (Not ps.AddCheck("chkBYPPF", 200, 250, 2400, 450, "Bypass path from prefetch to decode available (BYPPF)")) Then Exit Function

    '-------------------------------
    ' frame: frmBYPF
    '-------------------------------
    If (Not ps.AddFrame("frmBYPF", 3000, 1050, 2750, 850, "Fetch Bypass Control")) Then Exit Function
        If (Not ps.AddCheck("chkBYPF", 200, 250, 2300, 450, "Bypass path from fetch to decode available (BYPF)")) Then Exit Function

    '-------------------------------
    ' frame: frmSTEN
    '-------------------------------
    If (Not ps.AddFrame("frmSTEN", 5900, 1050, 2650, 850, "Stall Instruction Enable")) Then Exit Function
        If (Not ps.AddCheck("chkSTEN", 200, 300, 2200, 380, "Enabled stall instruction (STEN)")) Then Exit Function

    '-------------------------------
    ' frame: frmLFIC
    '-------------------------------
    If (Not ps.AddFrame("frmLFIC", 100, 2000, 2750, 850, "Linear Follower Instruction Cache")) Then Exit Function
        If (Not ps.AddCheck("chkLFIC", 200, 250, 2300, 380, "Enable linear follower instruction cache (LFIC)")) Then Exit Function

    '-------------------------------
    ' frame: frmOVRUN
    '-------------------------------
    If (Not ps.AddFrame("frmOVRUN", 3000, 2000, 2750, 850, "Pipeline control")) Then Exit Function
        If (Not ps.AddCheck("chkOVRUN", 200, 250, 2250, 400, "Overrun of pipeline bubbles allowed (OVRUN)")) Then Exit Function

    '-------------------------------
    ' frame: frmRETST
    '-------------------------------
    If (Not ps.AddFrame("frmRETST", 5900, 2000, 2650, 850, "Enable return Stack")) Then Exit Function
        If (Not ps.AddCheck("chkRETST", 200, 250, 1975, 380, "Enable return stack (RETST)")) Then Exit Function

    '-------------------------------
    ' frame: frmDAID
    '-------------------------------
    If (Not ps.AddFrame("frmDAID", 100, 2900, 8450, 1300, "Atomic Injection Deny Control (DAID)")) Then Exit Function
        If (Not ps.AddOption("optDAID_0", 200, 300, 8050, 350, "Injection requests on atomic sequences are denied to allow reprioritization by the interrupt controller")) Then Exit Function
        If (Not ps.AddOption("optDAID_1", 200, 700, 8050, 450, "Injection requests on atomic sequences are processed as soon as the atomic sequence is finished; no reprioritization")) Then Exit Function

    '-------------------------------
    ' frame: frmEIOIAEN
    '-------------------------------
    If (Not ps.AddFrame("frmEIOIAEN", 100, 4250, 4100, 850, "Early IO Injection Acknowledge")) Then Exit Function
        If (Not ps.AddCheck("chkEIOIAEN", 200, 250, 3600, 450, "Injection acknowledge by destructive read guaranteed (EIOIAEN)")) Then Exit Function

    '-------------------------------
    ' frame: frmSL
    '-------------------------------
    If (Not ps.AddFrame("frmSL", 4400, 4250, 4150, 850, "Short Loop Mode Control")) Then Exit Function
        If (Not ps.AddCheck("chkSL", 200, 300, 3700, 380, "Enable short loop mode (SL)")) Then Exit Function

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

  OnShowPageMainCPUCON2 = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim sRegName As String
  Dim i As Integer

  sRegName = "CPUCON2_"

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

  If (Pagename = "CPUCON2") Then
    '-------------------------------------------------------------------------
    ' page: MainCPUCON2 (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: cboFIFODEPTH (action)
        '---------------------------------------------------------------------
        Case "cboFIFODEPTH"
            r.v(sRegName & "FIFODEPTH") = c("cboFIFODEPTH").ListIndex

        '---------------------------------------------------------------------
        ' control: cboFIFOFED (action)
        '---------------------------------------------------------------------
        Case "cboFIFOFED"
            r.v(sRegName & "FIFOFED") = c("cboFIFOFED").ListIndex
            If (c("cboFIFOFED").ListIndex = 0) Then
                r.v(sRegName & "FIFODEPTH") = 0
            End If

        '---------------------------------------------------------------------
        ' control: chkBYPPF (action)
        '---------------------------------------------------------------------
        Case "chkBYPPF"
            r.v(sRegName & "BYPPF") = v(1)

        '---------------------------------------------------------------------
        ' control: chkBYPF (action)
        '---------------------------------------------------------------------
        Case "chkBYPF"
            r.v(sRegName & "BYPF") = v(1)

        '---------------------------------------------------------------------
        ' control: chkEIOIAEN (action)
        '---------------------------------------------------------------------
        Case "chkEIOIAEN"
            r.v(sRegName & "EIOIAEN") = v(1)

        '---------------------------------------------------------------------
        ' control: chkSTEN (action)
        '---------------------------------------------------------------------
        Case "chkSTEN"
            r.v(sRegName & "STEN") = v(1)

        '---------------------------------------------------------------------
        ' control: chkLFIC (action)
        '---------------------------------------------------------------------
        Case "chkLFIC"
            r.v(sRegName & "LFIC") = v(1)

        '---------------------------------------------------------------------
        ' control: chkOVRUN (action)
        '---------------------------------------------------------------------
        Case "chkOVRUN"
            r.v(sRegName & "OVRUN") = v(1)

        '---------------------------------------------------------------------
        ' control: chkRETST (action)
        '---------------------------------------------------------------------
        Case "chkRETST"
            r.v(sRegName & "RETST") = v(1)

        '---------------------------------------------------------------------
        ' control: optDAID_0 (action)
        '---------------------------------------------------------------------
        Case "optDAID_0"
            r.v(sRegName & "DAID") = 0

        '---------------------------------------------------------------------
        ' control: optDAID_1 (action)
        '---------------------------------------------------------------------
        Case "optDAID_1"
            r.v(sRegName & "DAID") = 1

        '---------------------------------------------------------------------
        ' control: chkSL (action)
        '---------------------------------------------------------------------
        Case "chkSL"
            r.v(sRegName & "SL") = v(1)

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: MainCPUCON2 (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: cboFIFOFED (show)
    '-------------------------------------------------------------------------
    With c("cboFIFOFED")
        .Clear
        .AddItem "FIFO disabled"
        .AddItem "FIFO filled with up to 1 instruction per cycle"
        .AddItem "FIFO filled with up to 2 instruction per cycle"
        .AddItem "FIFO filled with up to 3 instruction per cycle"
        .ListIndex = r.v(sRegName & "FIFOFED")
    End With

    '-------------------------------------------------------------------------
    ' control: cboFIFODEPTH (show)
    '-------------------------------------------------------------------------
    With c("cboFIFODEPTH")
        bDisabled = r.v(sRegName & "FIFOFED") = 0
        .Enabled = Not (bDisabled)
        .Clear
        .AddItem "No FIFO"
        .AddItem "1 FIFO entry"
        For i = 2 To 8
             .AddItem i & " FIFO entries"
        Next i
        .ListIndex = r.v(sRegName & "FIFODEPTH")
    End With

    With e("cboFIFODEPTH")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v(sRegName & "FIFOFED") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & _
              FormatDisabledTooltip("FIFO is disabled")
        End If
      Else
        'tooltip if enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkBYPPF (show)
    '-------------------------------------------------------------------------
    With c("chkBYPPF")
        .Value = -CInt(r.v(sRegName & "BYPPF") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkBYPF (show)
    '-------------------------------------------------------------------------
    With c("chkBYPF")
        .Value = -CInt(r.v(sRegName & "BYPF") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkEIOIAEN (show)
    '-------------------------------------------------------------------------
    With c("chkEIOIAEN")
        .Value = -CInt(r.v(sRegName & "EIOIAEN") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkSTEN (show)
    '-------------------------------------------------------------------------
    With c("chkSTEN")
        .Value = -CInt(r.v(sRegName & "STEN") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkLFIC (show)
    '-------------------------------------------------------------------------
    With c("chkLFIC")
        .Value = -CInt(r.v(sRegName & "LFIC") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkOVRUN (show)
    '-------------------------------------------------------------------------
    With c("chkOVRUN")
        .Value = -CInt(r.v(sRegName & "OVRUN") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkRETST (show)
    '-------------------------------------------------------------------------
    With c("chkRETST")
        .Value = -CInt(r.v(sRegName & "RETST") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: optDAID_0 (show)
    '-------------------------------------------------------------------------
    With c("optDAID_0")
        .Value = -CInt(r.v(sRegName & "DAID") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optDAID_1 (show)
    '-------------------------------------------------------------------------
    With c("optDAID_1")
        .Value = -CInt(r.v(sRegName & "DAID") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkSL (show)
    '-------------------------------------------------------------------------
    With c("chkSL")
        .Value = -CInt(r.v(sRegName & "SL") = 1)
    End With

  End If

  OnShowPageMainCPUCON2 = True
  Exit Function

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

