'#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 "..\EBC\Include.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
'
'*****************************************************************************

'*****************************************************************************
'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") = &H2001
            r.sfr("IDMANUF") = &H1820
            r.sfr("IDMEM") = &H3020
            r.sfr("IDPROG") = &H4040
            
            ' this values are recommend 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") = &H0007
            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 = "XC167CI") Then
              r.v("MAIN_CPU_TYPE")        = sMC_Name & "-16F40"
              r.v("MAIN_ROM_Type") = "Flash"
              r.v("MAIN_ROM_Size") = 128
            ElseIf (sMC_Name = "XC161CJ") Then
              r.v("MAIN_CPU_TYPE")        = sMC_Name & "-16F"
              r.v("MAIN_ROM_Type") = "Flash"
              r.v("MAIN_ROM_Size") = 128
            ElseIf (sMC_Name = "XC164CS") Then
              r.v("MAIN_CPU_TYPE")        = sMC_Name & "-16F"
              r.v("MAIN_ROM_Type") = "Flash"
              r.v("MAIN_ROM_Size") = 128
            End If
            ' currently all types can use the same PLL initialisation (20 MHz)
            r.v("MAIN_OSC") = 8
            r.sfr("PLLCON") = &H7814
            r.d("MAIN_CLK_CPU") = GetMaxFcpu(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("EBCMOD0_SAPEN") = 2
            r.v("RSTCFG_SALSEL") = 3
              Call RequestAlternateInputPin(r, "A16")
              Call RequestAlternateInputPin(r, "A17")
            
            r.v("EBCMOD0_CSPEN") = 3
            r.v("RSTCFG_CSSEL") = 1 
              Call RequestAlternateInputPin(r, "CS1_n")
              Call RequestAlternateInputPin(r, "CS0_n")
            
            ' this was set in EBC Ini
            'r.v("EA_EA") = 1 ' start from external memory (currently valid for all types)

            r.v("RSTCFG_WRC") = 1
            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: StartupConfiguration
    '-------------------------------------------------------------------------
    If (Not OnLoadPageStartupConfiguration(ps)) Then Exit Function

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

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

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

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

    '-------------------------------------------------------------------------
    ' End of pages
    '-------------------------------------------------------------------------
    
	'msgbox "rag :Before initmenu"
    ' 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: StartupConfiguration
    '-------------------------------------------------------------------------
    If (Not OnChangingPageStartupConfiguration (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: OnChangingPageMainCPUCON2
    '-------------------------------------------------------------------------
    'If (Not OnChangingPageMainCPUCON2 (ps, Pagename)) Then Exit Function

    ' page: ...

    '-------------------------------------------------------------------------
    '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: StartupConfiguration
    '-------------------------------------------------------------------------
    If (Not OnShowPageStartupConfiguration(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: OnShowPageMainCPUCON2
    '-------------------------------------------------------------------------
    'If (Not OnShowPageMainCPUCON2(ps, Controlname, Pagename, v)) Then Exit Function
 
    ' page: ...
       
    '-------------------------------------------------------------------------
    ' 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 to high
            ' this is shown in the dialog.

            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 & "-8R20" Or v(1) = sMC_Name & "-8R40") Then
                r.v("MAIN_CPU_TYPE") = v(1)
                r.v("MAIN_ROM_Type") = "ROM"
                r.v("MAIN_ROM_Size") = 64
            End If
            If (v(1) = sMC_Name & "-16F20" Or v(1) = sMC_Name & "-16F40" Or v(1) = sMC_Name & "-16F") Then
                r.v("MAIN_CPU_TYPE") = v(1)
                r.v("MAIN_ROM_Type") = "Flash"
                r.v("MAIN_ROM_Size") = 128
            End If
            If (v(1) = sMC_Name & "-16R20" Or v(1) = sMC_Name & "-16R40") Then
                r.v("MAIN_CPU_TYPE") = v(1)
                r.v("MAIN_ROM_Type") = "ROM"
                r.v("MAIN_ROM_Size") = 128
            End If
            If (v(1) = sMC_Name & "-32F20" Or v(1) = sMC_Name & "-32F40") Then
                r.v("MAIN_CPU_TYPE") = v(1)
                r.v("MAIN_ROM_Type") = "Flash"
                r.v("MAIN_ROM_Size") = 256
            End If
            r.d("MAIN_CLK_CPU") = GetMaxFcpu(r) ' depends on "MAIN_CPU_TYPE"

        '---------------------------------------------------------------------
        ' 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 = "XC161CJ") Then
          .AddItem sMC_Name & "-16F"     ' only for compatiblity with previous versions
          .AddItem sMC_Name & "-16F20"
          .AddItem sMC_Name & "-16F40"
          .AddItem sMC_Name & "-32F20"
          If (r.v("MAIN_CPU_TYPE") = sMC_Name & "-16F") Then
              .ListIndex = 0
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-16F20") Then
              .ListIndex = 1
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-16F40") Then
              .ListIndex = 2
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-32F20") Then
              .ListIndex = 3
          End If
      End If

      If (sMC_Name = "XC164CS") Then
          .AddItem sMC_Name & "-16F"     ' only for compatiblity with previous versions
          .AddItem sMC_Name & "-8F20"
          .AddItem sMC_Name & "-8F40"
          .AddItem sMC_Name & "-8R20"
          .AddItem sMC_Name & "-8R40"
          .AddItem sMC_Name & "-16F20"
          .AddItem sMC_Name & "-16F40"
          .AddItem sMC_Name & "-16R20"
          .AddItem sMC_Name & "-16R40"
          .AddItem sMC_Name & "-32F20"
          If (r.v("MAIN_CPU_TYPE") = sMC_Name & "-16F") Then
              .ListIndex = 0
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-8F20") Then
              .ListIndex = 1
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-8F40") Then
              .ListIndex = 2
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-8R20") Then
              .ListIndex = 3
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-8R40") Then
              .ListIndex = 4
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-16F20") Then
              .ListIndex = 5
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-16F40") Then
              .ListIndex = 6
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-16R20") Then
              .ListIndex = 7
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-16R40") Then
              .ListIndex = 8
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-32F20") Then
              .ListIndex = 9
          End If
      End If

      If (sMC_Name = "XC167CI") Then
          .AddItem sMC_Name & "-16F20"
          .AddItem sMC_Name & "-16F40"
          .AddItem sMC_Name & "-32F20"
          If (r.v("MAIN_CPU_TYPE") = sMC_Name & "-16F20") Then
              .ListIndex = 0
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-16F40") Then
              .ListIndex = 1
          ElseIf (r.v("MAIN_CPU_TYPE") = sMC_Name & "-32F20") Then
              .ListIndex = 2
          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
'          "Bypass PLL is aktiv; the PLL 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
'          "Bypass PLL is aktiv; the PLL 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
'          "PLL 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
'          "PLL 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


  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
			'errorbox "Listindex=" & 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

      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


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

  OnLoadPageStartupConfiguration = False

  If (Not ps.AddPage("Startup Configuration")) Then Exit Function

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

  OnChangingPageStartupConfiguration = False
  Dim r As ProjectData

  Set r = ps.ProjectData
  
  If (Not ps.ExtenderCollection("Startup Configuration").Loaded) And (Pagename = "Startup Configuration") Then
    ps.ExtenderCollection("Startup Configuration").Loaded = True
  

    '-------------------------------
    ' frame: External_Access_Control
    '-------------------------------
    If (Not ps.AddFrame("External_Access_Control",100,100, 4175, 1225, "External Access Control")) Then Exit Function
        If (Not ps.AddOption("optEA_0", 200, 300, 3100, 380, "Fetch code from internal ROM             (#EA = high during reset)")) Then Exit Function
        If (Not ps.AddOption("optEA_1", 200, 800, 3000, 380, "Fetch code from external ROM        (#EA = low during reset)")) Then Exit Function

    '-------------------------------
    ' frame: Write_Configuration_WRC
    '-------------------------------
    If (Not ps.AddFrame("frmWRC",100,1425, 4175, 1225, "Write Configuration (WRC)")) Then Exit Function
        If (Not ps.AddOption("optWRC_0", 200, 300, 3900, 380, "Pin #WR and #BHE operate as #WRL and #WRH signals (P0H.0 = low during reset)")) Then Exit Function
        If (Not ps.AddOption("optWRC_1", 200, 800, 3900, 380, "Pin #WR and #BHE operate as #WR and #BHE signals (P0H.0 = high during reset)")) Then Exit Function

    '-------------------------------
    ' frame: Bustype_after_Reset
    '-------------------------------
    If (Not ps.AddFrame("Bustype_after_Reset",4375,100, 4175, 2550, "Bustype after Reset")) Then Exit Function
        If (Not ps.AddOption("optBTYP_0", 200, 400, 3900, 380, "8-bit Demultiplexed Bus                                     (P0L.7 = low, P0L.6 = low during reset)")) Then Exit Function
        If (Not ps.AddOption("optBTYP_1", 200, 900, 3900, 380, "8-bit Multiplexed Bus                                         (P0L.7 = low, P0L.6 = high during reset)")) Then Exit Function
        If (Not ps.AddOption("optBTYP_2", 200, 1400, 3900, 380, "16-bit Demultiplexed Bus                                   (P0L.7 = high, P0L.6 = low during reset)")) Then Exit Function
        If (Not ps.AddOption("optBTYP_3", 200, 1900, 3900, 380, "16-bit Multiplexed Bus                                       (P0L.7 = high, P0L.6 = high during reset)")) Then Exit Function

    '-------------------------------
    ' frame: Segment_Address_Lines_SALSEL
    '-------------------------------
    If (Not ps.AddFrame("frmSALSEL",100,2750, 4175, 2550, "Segment Address Lines (SALSEL)")) Then Exit Function
        If (Not ps.AddOption("optSALSEL_1", 200, 400, 3250, 380, "No segment address lines (64 KByte)      (P0H.3 = high, P0H.4 = low during reset)")) Then Exit Function
        If (Not ps.AddOption("optSALSEL_3", 200, 900, 3900, 380, "2-bit segment address: A17..A16 (256 KByte) (P0H.3 = high, P0H.4 = high during reset)")) Then Exit Function
        If (Not ps.AddOption("optSALSEL_0", 200, 1400, 3900, 380, "4-bit segment address: A19..A16 (1 MByte)     (P0H.3 = low, P0H.4 = low during reset)")) Then Exit Function
        If (Not ps.AddOption("optSALSEL_2", 200, 1900, 3900, 380, "8-bit segment address: A23..A16 (16 MByte)   (P0H.3 = low, P0H.4 = high during reset)")) Then Exit Function

    '-------------------------------
    ' frame: Chip_Select_Lines_CSSEL
    '-------------------------------
    If (Not ps.AddFrame("Chip_Select_Lines_CSSEL",4375,2750, 4175, 2550, "Chip Select Lines (CSSEL)")) Then Exit Function
        If (Not ps.AddOption("optCSSEL_2", 200, 400, 3900, 380, "None                                                                (P0H.1 = low, P0H.2 = high during reset)")) Then Exit Function
        If (Not ps.AddOption("optCSSEL_1", 200, 900, 3900, 380, "Two:    #CS1..#CS0                                      (P0H.1 = high, P0H.2 = low during reset)")) Then Exit Function
        If (Not ps.AddOption("optCSSEL_0", 200, 1400, 3900, 380, "Three:  #CS2..#CS0                                      (P0H.1 = low, P0H.2 = low during reset)")) Then Exit Function
        
        If (r.Exist("MuxFor_CS4_n") = True) Then
            If (Not ps.AddOption("optCSSEL_3", 200, 1900, 3900, 380, "Five:    #CS4..#CS0                                      (P0H.1 = high, P0H.2 = high during reset)")) Then Exit Function
        End If

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

  OnShowPageStartupConfiguration = False

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

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

  If (Pagename = "Startup Configuration") Then
    '-------------------------------------------------------------------------
    ' page: StartupConfiguration (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optEA_0 (action)
        '---------------------------------------------------------------------
        Case "optEA_0"
             r.v("EA_EA") = 0
             ' warum ist dieser Code hier implementiert
             'r.sfr("PLLCON") = &H2790
             'r.v("SYSCON1_CPSYS") = 0
             'If (Not UpdateAllPeripherals(r, UPDATE_CLOCK)) Then 
             '    Exit Function
             'End If


             r.v("EBCMOD0_BYTDIS") = 1
             r.v("EBCMOD0_WRCFG") = 0
             
             If (GetPinFunction(r, "WRH_n") = 2) Then
               Call ReleaseAlternateOutputPin(r, "WRH_n")
             End If
             If (GetPinFunction(r, "BHE_n") = 2) Then
               Call ReleaseAlternateOutputPin(r, "BHE_n")
             End If

             'r.v("BUSCON0_ALECTL0") = 0
             'r.v("SYSCON_ROMEN") = 1
             'r.v("SYSCON_ROMS1") = 0
             '
             Call ReleasePinInterfaceP0L(r) 
             
             If (r.v("RSTCFG_BUSTYP") = 1 Or r.v("RSTCFG_BUSTYP") = 3) Then
               Call ReleasePinInterfaceP0H(r)
             End If
             
             If (r.v("RSTCFG_BUSTYP") = 0) Then
               Call ReleasePinInterfaceP1L(r)
               Call ReleasePinInterfaceP1H(r)
             End If
             
             If (r.v("RSTCFG_BUSTYP") = 2) Then
               Call ReleasePinInterfaceP1H(r)
               Call ReleasePinInterfaceP1L(r)
               Call ReleasePinInterfaceP0H(r)
             End If
             
             r.v("RSTCFG_BUSTYP") = 0 'only here
             r.sfr("FCONCS0") = 0

             'disable EBC
             Call DisableEBC(r)


        '---------------------------------------------------------------------
        ' control: optEA_1 (action)
        '---------------------------------------------------------------------
        Case "optEA_1"
             r.v("EA_EA") = 1
             r.v("EBCMOD0_EBCDIS") = 0
             r.v("EBCMOD0_BYTDIS") = 0
             If (r.v("EBCMOD0_WRCFG") = 0) Then
               Call RequestAlternateOutputPin(r, "BHE_n")
             Else
               Call RequestAlternateOutputPin(r, "WRH_n")
             End If

             If (r.v("FCONCS0_ENCS0") = 1) Then
                 Call ReleasePinInterfaceP0L(r)
             
                 If (r.v("FCONCS0_BTYP0") = 1 Or r.v("FCONCS0_BTYP0") = 3) Then
                   Call ReleasePinInterfaceP0H(r)
                 End If
             
                 If (r.v("FCONCS0_BTYP0") = 0) Then
                   Call ReleasePinInterfaceP1L(r)
                   Call ReleasePinInterfaceP1H(r)
                 End If
             
                 If (r.v("FCONCS0_BTYP0") = 2) Then
                   Call ReleasePinInterfaceP1H(r)
                   Call ReleasePinInterfaceP1L(r)
                   Call ReleasePinInterfaceP0H(r)
                 End If
             End If
             
             
             Call SelectPinInterfaceP0H(r, 1)
             Call SelectPinInterfaceP0L(r, 1)
             
             r.v("RSTCFG_BUSTYP") = 3 'only here
             r.v("FCONCS0_BTYP0") = 3 'only here
             r.v("FCONCS0_ENCS0") = 1
             

        '---------------------------------------------------------------------
        ' control: optWRC_0 (action)
        '---------------------------------------------------------------------
        Case "optWRC_0"
             r.v("RSTCFG_WRC") = 0

        '---------------------------------------------------------------------
        ' control: optWRC_1 (action)
        '---------------------------------------------------------------------
        Case "optWRC_1"
             r.v("RSTCFG_WRC") = 1

        '---------------------------------------------------------------------
        ' control: optBTYP_0 (action)
        '---------------------------------------------------------------------
        Case "optBTYP_0"
            Call Select_Pin_Interface_For_EBC(r, 0, 0)
            r.v("RSTCFG_BUSTYP") = 0
            r.v("FCONCS0_BTYP0") = 0
        
        '---------------------------------------------------------------------
        ' control: optBTYP_1 (action)
        '---------------------------------------------------------------------
        Case "optBTYP_1"
            Call Select_Pin_Interface_For_EBC(r, 0, 1)
            r.v("RSTCFG_BUSTYP") = 1
            r.v("FCONCS0_BTYP0") = 1

        '---------------------------------------------------------------------
        ' control: optBTYP_2 (action)
        '---------------------------------------------------------------------
        Case "optBTYP_2"
            Call Select_Pin_Interface_For_EBC(r, 0, 2)
            r.v("RSTCFG_BUSTYP") = 2
            r.v("FCONCS0_BTYP0") = 2

        '---------------------------------------------------------------------
        ' control: optBTYP_3 (action)
        '---------------------------------------------------------------------
        Case "optBTYP_3"
            Call Select_Pin_Interface_For_EBC(r, 0, 3)
            r.v("RSTCFG_BUSTYP") = 3
            r.v("FCONCS0_BTYP0") = 3

        '---------------------------------------------------------------------
        ' control: optSALSEL_1 (action)
        '---------------------------------------------------------------------
        Case "optSALSEL_1"
             If (r.v("RSTCFG_SALSEL") = 0) Then
               Call ReleaseAlternateInputPin(r, "A16")
               Call ReleaseAlternateInputPin(r, "A17")
               Call ReleaseAlternateInputPin(r, "A18")
               Call ReleaseAlternateInputPin(r, "A19")
             End If
             If (r.v("RSTCFG_SALSEL") = 2) Then
               Call ReleaseAlternateInputPin(r, "A16")
               Call ReleaseAlternateInputPin(r, "A17")
               Call ReleaseAlternateInputPin(r, "A18")
               Call ReleaseAlternateInputPin(r, "A19")
               Call ReleaseAlternateInputPin(r, "A20")
               Call ReleaseAlternateInputPin(r, "A21")
               Call ReleaseAlternateInputPin(r, "A22")
               Call ReleaseAlternateInputPin(r, "A23")
             End If
             If (r.v("RSTCFG_SALSEL") = 3) Then
               Call ReleaseAlternateInputPin(r, "A16")
               Call ReleaseAlternateInputPin(r, "A17")
             End If

             r.v("RSTCFG_SALSEL") = 1
             r.v("EBCMOD0_SAPEN") = 0

        '---------------------------------------------------------------------
        ' control: optSALSEL_3 (action)
        '---------------------------------------------------------------------
        Case "optSALSEL_3"
             If (r.v("RSTCFG_SALSEL") = 0) Then
               Call ReleaseAlternateInputPin(r, "A18")
               Call ReleaseAlternateInputPin(r, "A19")
             End If
             If (r.v("RSTCFG_SALSEL") = 2) Then
               Call ReleaseAlternateInputPin(r, "A18")
               Call ReleaseAlternateInputPin(r, "A19")
               Call ReleaseAlternateInputPin(r, "A20")
               Call ReleaseAlternateInputPin(r, "A21")
               Call ReleaseAlternateInputPin(r, "A22")
               Call ReleaseAlternateInputPin(r, "A23")
             End If

             If (r.v("RSTCFG_SALSEL") = 1) Then
               Call RequestAlternateInputPin(r, "A16")
               Call RequestAlternateInputPin(r, "A17")
             End If

             r.v("RSTCFG_SALSEL") = 3
             r.v("EBCMOD0_SAPEN") = 2

        '---------------------------------------------------------------------
        ' control: optSALSEL_0 (action)
        '---------------------------------------------------------------------
        Case "optSALSEL_0"
             If (r.v("RSTCFG_SALSEL") = 2) Then
               Call ReleaseAlternateInputPin(r, "A20")
               Call ReleaseAlternateInputPin(r, "A21")
               Call ReleaseAlternateInputPin(r, "A22")
               Call ReleaseAlternateInputPin(r, "A23")
             End If
             If (r.v("RSTCFG_SALSEL") = 1) Then
               Call RequestAlternateInputPin(r, "A16")
               Call RequestAlternateInputPin(r, "A17")
               Call RequestAlternateInputPin(r, "A18")
               Call RequestAlternateInputPin(r, "A19")
             End If
             If (r.v("RSTCFG_SALSEL") = 3) Then
               Call RequestAlternateInputPin(r, "A18")
               Call RequestAlternateInputPin(r, "A19")
             End If
    
             r.v("RSTCFG_SALSEL") = 0
             r.v("EBCMOD0_SAPEN") = 4

        '---------------------------------------------------------------------
        ' control: optSALSEL_2 (action)
        '---------------------------------------------------------------------
        Case "optSALSEL_2"
             Call RequestAlternateInputPin(r, "A20")
             Call RequestAlternateInputPin(r, "A21")
             Call RequestAlternateInputPin(r, "A22")
             Call RequestAlternateInputPin(r, "A23")
             If (r.v("RSTCFG_SALSEL") = 1) Then
               Call RequestAlternateInputPin(r, "A16")
               Call RequestAlternateInputPin(r, "A17")
               Call RequestAlternateInputPin(r, "A18")
               Call RequestAlternateInputPin(r, "A19")
             End If
             If (r.v("RSTCFG_SALSEL") = 3) Then
               Call RequestAlternateInputPin(r, "A18")
               Call RequestAlternateInputPin(r, "A19")
             End If
             r.v("RSTCFG_SALSEL") = 2
             r.v("EBCMOD0_SAPEN") = 8

        '---------------------------------------------------------------------
        ' control: optCSSEL_2 (action)
        '---------------------------------------------------------------------
        Case "optCSSEL_2"
             Call ReleaseAlternateInputPin(r, "CS0_n")
             Call ReleaseAlternateInputPin(r, "CS1_n")
             If (r.v("RSTCFG_CSSEL") = 0) Then
               Call ReleaseAlternateInputPin(r, "CS2_n")
             End If
             If (r.v("RSTCFG_CSSEL") = 3) Then
               Call ReleaseAlternateInputPin(r, "CS2_n")
               Call ReleaseAlternateInputPin(r, "CS3_n")
               Call ReleaseAlternateInputPin(r, "CS4_n")
             End If
             
             r.v("RSTCFG_CSSEL") = 2
             r.v("EBCMOD0_CSPEN") = 0

        '---------------------------------------------------------------------
        ' control: optCSSEL_1 (action)
        '---------------------------------------------------------------------
        Case "optCSSEL_1"
             If (r.v("RSTCFG_CSSEL") = 0) Then
               Call ReleaseAlternateInputPin(r, "CS2_n")
             End If
             If (r.v("RSTCFG_CSSEL") = 3) Then
               Call ReleaseAlternateInputPin(r, "CS2_n")
               Call ReleaseAlternateInputPin(r, "CS3_n")
               Call ReleaseAlternateInputPin(r, "CS4_n")
             End If
             If (r.v("RSTCFG_CSSEL") = 2) Then
               Call RequestAlternateInputPin(r, "CS0_n")
               Call RequestAlternateInputPin(r, "CS1_n")
             End If
             r.v("RSTCFG_CSSEL") = 1
             r.v("EBCMOD0_CSPEN") = 2

        '---------------------------------------------------------------------
        ' control: optCSSEL_0 (action)
        '---------------------------------------------------------------------
        Case "optCSSEL_0"
             If (r.v("RSTCFG_CSSEL") = 3) Then
               Call ReleaseAlternateInputPin(r, "CS3_n")
               Call ReleaseAlternateInputPin(r, "CS4_n")
             End If
             If (r.v("RSTCFG_CSSEL") = 1) Then
               Call RequestAlternateInputPin(r, "CS2_n")
             End If
             If (r.v("RSTCFG_CSSEL") = 2) Then
               Call RequestAlternateInputPin(r, "CS0_n")
               Call RequestAlternateInputPin(r, "CS1_n")
               Call RequestAlternateInputPin(r, "CS2_n")
             End If
             r.v("RSTCFG_CSSEL") = 0
             r.v("EBCMOD0_CSPEN") = 3


        '---------------------------------------------------------------------
        ' control: optCSSEL_3 (action)
        '---------------------------------------------------------------------
        Case "optCSSEL_3"
             If (r.v("RSTCFG_CSSEL") = 2) Then
               Call RequestAlternateInputPin(r, "CS4_n")
               Call RequestAlternateInputPin(r, "CS3_n")
               Call RequestAlternateInputPin(r, "CS2_n")
               Call RequestAlternateInputPin(r, "CS1_n")
               Call RequestAlternateInputPin(r, "CS0_n")
             End If
             If (r.v("RSTCFG_CSSEL") = 1) Then
               Call RequestAlternateInputPin(r, "CS4_n")
               Call RequestAlternateInputPin(r, "CS3_n")
               Call RequestAlternateInputPin(r, "CS2_n")
             End If
             If (r.v("RSTCFG_CSSEL") = 0) Then
               Call RequestAlternateInputPin(r, "CS3_n")
               Call RequestAlternateInputPin(r, "CS4_n")
             End If
             r.v("RSTCFG_CSSEL") = 3
             r.v("EBCMOD0_CSPEN") = 5


      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: StartupConfiguration (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: optEA_0 (show)
    '-------------------------------------------------------------------------
    With c("optEA_0")
      bDisabled = (r.v("MAIN_ROM_Size") = 0)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("EA_EA") = 0)
    End With

    With e("optEA_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("MAIN_ROM_Size") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("ROM size is 0 K")
        End If
      Else
        'tooltip if enabled
      End If
    End With

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

    With e("optEA_1")
      If (bDisabled) Then
        .DisabledTooltipText = ""
      Else
        'tooltip if enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optWRC_0 (show)
    '-------------------------------------------------------------------------
    With c("optWRC_0")
      bDisabled = (r.v("EA_EA") = 0)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_WRC") = 0)
    End With

    With e("optWRC_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("EA_EA") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipIfInternROM(r)
        End If
      Else
        'tooltip if enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optWRC_1 (show)
    '-------------------------------------------------------------------------
    With c("optWRC_1")
      bDisabled = (r.v("EA_EA") = 0)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_WRC") = 1)
    End With

    With e("optWRC_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("EA_EA") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipIfInternROM(r)
        End If
      Else
        'tooltip if enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optBTYP_0 (show)
    '-------------------------------------------------------------------------
    With c("optBTYP_0")
      bDisabled = (r.v("EA_EA") = 0 Or _
                  Not(IsPinInterfaceFree(r, "A", 0, 7)) Or Not(IsPinInterfaceFree(r, "A", 8, 15)))
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_BUSTYP") = 0)
    End With

    With e("optBTYP_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("EA_EA") = 0) Then  
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("fetch code from internal ROM (#EA = high during reset)")
        End If
        If (Not(IsPinInterfaceFree(r, "A", 0, 7))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipPinInterfaceDisabled(r, "A", 0, 7)
        End If
        If (Not(IsPinInterfaceFree(r, "A", 8, 15))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipPinInterfaceDisabled(r, "A", 8, 15)
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: optBTYP_1 (show)
    '-------------------------------------------------------------------------
    With c("optBTYP_1")
      bDisabled = (r.v("EA_EA") = 0 Or Not(IsPinInterfaceFree(r, "AD", 8, 15)))
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_BUSTYP") = 1)
    End With

    With e("optBTYP_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("EA_EA") = 0) Then  
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("fetch code from internal ROM (#EA = high during reset)")
        End If
        If (Not(IsPinInterfaceFree(r, "AD", 8, 15))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipPinInterfaceDisabled(r, "AD", 8, 15)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optBTYP_2 (show)
    '-------------------------------------------------------------------------
    With c("optBTYP_2")
      bDisabled = (r.v("EA_EA") = 0 Or _
                   Not(IsPinInterfaceFree(r, "AD", 8, 15)) Or _
                   Not(IsPinInterfaceFree(r, "A", 0, 7)) Or Not(IsPinInterfaceFree(r, "A", 8, 15)))
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_BUSTYP") = 2)
    End With

    With e("optBTYP_2")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("EA_EA") = 0) Then  
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("fetch code from internal ROM (#EA = high during reset)")
        End If
        If (Not(IsPinInterfaceFree(r, "A", 0, 7))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipPinInterfaceDisabled(r, "A", 0, 7)
        End If
        If (Not(IsPinInterfaceFree(r, "A", 8, 15))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipPinInterfaceDisabled(r, "A", 8, 15)
        End If
        If (Not(IsPinInterfaceFree(r, "AD", 8, 15))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipPinInterfaceDisabled(r, "AD", 8, 15)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optBTYP_3 (show)
    '-------------------------------------------------------------------------
    With c("optBTYP_3")
      bDisabled = (r.v("EA_EA") = 0 Or Not(IsPinInterfaceFree(r, "AD", 8, 15)))
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_BUSTYP") = 3)
    End With

    With e("optBTYP_3")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("EA_EA") = 0) Then  
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("fetch code from internal ROM (#EA = high during reset)")
        End If
        If (Not(IsPinInterfaceFree(r, "AD", 8, 15))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipPinInterfaceDisabled(r, "AD", 8, 15)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSALSEL_1 (show)
    '-------------------------------------------------------------------------
    With c("optSALSEL_1")
      ' .Enabled = r.v("TEST_VAR_USED")
      .Value = -CInt(r.v("RSTCFG_SALSEL") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: optSALSEL_3 (show)
    '-------------------------------------------------------------------------
    With c("optSALSEL_3")
      bDisabled = (Not(IsAlternateInputPinFree(r, "A16")) = True Or _
                   Not(IsAlternateInputPinFree(r, "A17")) = True)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_SALSEL") = 3)
    End With

    With e("optSALSEL_3")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        For i = 16 To 17
          If (Not(IsAlternateInputPinFree(r, "A" & i)) = True) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "A" & i)
          End If
        Next i
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSALSEL_0 (show)
    '-------------------------------------------------------------------------
    With c("optSALSEL_0")
      bDisabled = (Not(IsAlternateInputPinFree(r, "A16")) = True Or _
                   Not(IsAlternateInputPinFree(r, "A17")) = True Or _
                   Not(IsAlternateInputPinFree(r, "A18")) = True Or _
                   Not(IsAlternateInputPinFree(r, "A19")) = True)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_SALSEL") = 0)
    End With

    With e("optSALSEL_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        For i = 16 To 19
          If (Not(IsAlternateInputPinFree(r, "A" & i)) = True) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "A" & i)
          End If
        Next i
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSALSEL_2 (show)
    '-------------------------------------------------------------------------
    With c("optSALSEL_2")
      bDisabled = (Not(IsAlternateInputPinFree(r, "A16")) = True Or _
                   Not(IsAlternateInputPinFree(r, "A17")) = True Or _
                   Not(IsAlternateInputPinFree(r, "A18")) = True Or _
                   Not(IsAlternateInputPinFree(r, "A19")) = True Or _
                   Not(IsAlternateInputPinFree(r, "A20")) = True Or _
                   Not(IsAlternateInputPinFree(r, "A21")) = True Or _
                   Not(IsAlternateInputPinFree(r, "A22")) = True Or _
                   Not(IsAlternateInputPinFree(r, "A23")) = True)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_SALSEL") = 2)
    End With

    With e("optSALSEL_2")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        For i = 16 To 23
          If (Not(IsAlternateInputPinFree(r, "A" & i)) = True) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "A" & i)
          End If
        Next i
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optCSSEL_2 (show)
    '-------------------------------------------------------------------------
    With c("optCSSEL_2")
      bDisabled = False
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_CSSEL") = 2)
    End With

    With e("optCSSEL_2")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optCSSEL_1 (show)
    '-------------------------------------------------------------------------
    With c("optCSSEL_1")
      bDisabled = (Not(IsAlternateInputPinFree(r, "CS0_n")) = True Or _
                   Not(IsAlternateInputPinFree(r, "CS1_n")) = True)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_CSSEL") = 1)
    End With

    With e("optCSSEL_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        For i = 0 To 1
          If (Not(IsAlternateInputPinFree(r, "CS" & i & "_n")) = True) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CS" & i & "_n")
          End If
        Next i
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optCSSEL_0 (show)
    '-------------------------------------------------------------------------
    With c("optCSSEL_0")
      bDisabled = (Not(IsAlternateInputPinFree(r, "CS0_n")) = True Or _
                   Not(IsAlternateInputPinFree(r, "CS1_n")) = True Or _
                   Not(IsAlternateInputPinFree(r, "CS2_n")) = True)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("RSTCFG_CSSEL") = 0)
    End With

    With e("optCSSEL_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        For i = 0 To 2
          If (Not(IsAlternateInputPinFree(r, "CS" & i & "_n")) = True) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CS" & i & "_n")
          End If
        Next i
      End If
    End With

    If (r.Exist("MuxFor_CS4_n") = True) Then
        '-------------------------------------------------------------------------
        ' control: optCSSEL_3 (show)
        '-------------------------------------------------------------------------
        With c("optCSSEL_3")
          bDisabled = (Not(IsAlternateInputPinFree(r, "CS0_n")) = True Or _
                       Not(IsAlternateInputPinFree(r, "CS1_n")) = True Or _
                       Not(IsAlternateInputPinFree(r, "CS2_n")) = True Or _
                       Not(IsAlternateInputPinFree(r, "CS3_n")) = True Or _
                       Not(IsAlternateInputPinFree(r, "CS4_n")) = True)
          .Enabled = Not(bDisabled)
          .Value = -CInt(r.v("RSTCFG_CSSEL") = 3)
        End With

        With e("optCSSEL_3")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            For i = 0 To 4
              If (Not(IsAlternateInputPinFree(r, "CS" & i & "_n")) = True) Then
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CS" & i & "_n")
              End If
            Next i
          End If
        End With
    End If


  End If

  OnShowPageStartupConfiguration = True
  Exit Function

OnShowPageStartupConfigurationError:
  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

