;==================================================================
;==================================================================
;
; OemSetUp.Inf
;
; Function.
;  Installation Script for NDIS 3.0 (NT) XPoint Driver.
;
;
; Copyright (c) 1995, BaseBand Technologies.  All Rights Reserved.
;
;
; History.
;  06 February 1995    D. Ebert    BaseBand Technologies.
;                                  Created Module.
;  09 March 1995       D. Ebert    BaseBand Technologies.
;                                  Updated based on vendor comments.
;  19 March 1995       D. Ebert    BaseBand Technologies.
;                                  Updated for VNet.
;  01 May 1995         J. Ebert    BaseBand Technologies.
;                                  Updated for PCI.
;
;==================================================================
;==================================================================

;==================================================================
;==================================================================
; Data Section - Identify .INF Option Type.
;
[Identification]
    OptionType = NetAdapter

;==================================================================
;==================================================================
; Data Section - Identify Languages supported by the INF file.
;
[LanguagesSupported]
    ENG

;==================================================================
;==================================================================
; Data Section - Identify Platforms on which Option is Enabled.
;
[PlatformsSupported]
    PCI
    MCA

;==================================================================
;==================================================================
; Data Section - Provide Option Name.
;
[Options]
    QUADENET

;==================================================================
;==================================================================
; Data Section - Provide Option Text Description.
;
[OptionsTextENG]
    QUADENET = "IBM Ethernet Quad PeerMaster Adapter"

;==================================================================
;==================================================================
; Data Section - Install Disk Information.
;
[Source Media Descriptions]
    1 = "IBM PeerMaster Option Diskette"
    2 = "Windows NT Setup CD-ROM"

[Signature]
    FileType = MICROSOFT_DRVLIB_FILE
[GetSignature]
    read-syms Signature
    return $(FileType)

;==================================================================
;==================================================================
; Data Section - Files to be installed to Driver Directory.
;
[Files-Drvr]
    1, quadenet.sys, SIZE=60000
    1, mxmca4bt.bin, SIZE=90000
    1, mxmca4tn.bin, SIZE=90000
    1, mxpci4bt.bin, SIZE=90000

;==================================================================
;==================================================================
; Data Section - Dialog and help files to be installed in System Directory.
;
[Files-Dll]
    1, quadenet.dll,    SIZE=40000
    1, quadenet.hlp,    SIZE=80000

;==================================================================
;==================================================================
; Data Section - Dialog file to be installed in System Driver Directory.
;
[Files-PciDll]
    1, quadenet.dll,    SIZE=40000

;==================================================================
;==================================================================
; Data Section - Files to be installed to Driver Directory.
;
[Files-PciDrvr]
    1, quadpci.sys,      SIZE=60000

;==================================================================
;==================================================================
; Data Section - Detect file to be installed in System Directory.
;
[Files-NcDet]
    1, qdncdet.dll, SIZE=40000

;==================================================================
;==================================================================
; Data Section - Statistics dump file to be installed in System Directory.
;
[Files-Stats]
    1, qstats.exe, SIZE=40000

[Files-Inf]
    1, OEMSETUP.inf,  SIZE=70000, RENAME=$(!UG_Filename)

;==================================================================
;==================================================================
; Data Section - References to external files.
;
[FileConstants]
    UtilityInf      = "UTILITY.INF"
    ParamInf        = "NCPARAM.INF"
    SubroutineInf   = "SUBROUTN.INF"
    NetEventDLL     = "%SystemRoot%\System32\netevent.dll"
    IoLogMsgDLL     = "%SystemRoot%\System32\IoLogMsg.dll"

;==================================================================
;==================================================================
; Data Section - Binding and configuration information for the MAC.
;
[RegistryConstants]
    Manufacturer             = "IBM"
    SoftwareType             = "driver"
    ProductMajorVersion      = "3"
    ProductMinorVersion      = "5"
    ProductVersion           = $(ProductMajorVersion)"."$(ProductMinorVersion)

    ProductSoftwareName        = "QuadEnet"
    ProductSoftwareDescription = "IBM PeerMaster Adapter Driver"
    ProductSoftwareTitle       = "IBM PeerMaster Adapter Driver"
    ProductSoftwareImagePath   = "\SystemRoot\System32\drivers\quadenet.sys"
    NetRuleSoftwareType        = "quadenetSys ndisDriver quadenetDriver"
    NetRuleSoftwareUse         = $(SoftwareType)
    NetRuleSoftwareBindForm    = """quadenetSys"" yes no container"
    NetRuleSoftwareClass       = {"quadenetDriver basic"}
    NetRuleSoftwareBindable    = {"quadenetDriver quadenetAdapter non exclusive 100"}

    ProductHardwareName        = "QuadEnet"
    ProductHardwareDescription = "IBM Quad PeerMaster Adapter"
    ProductHardwareTitle       = "IBM Quad PeerMaster Adapter"
    NetRuleHardwareType        = "quadenet quadenetAdapter"
    NetRuleHardwareBindForm    = " yes yes container"
    NetRuleHardwareClass       = {"quadenetAdapter basic"}

    ProductKeyName           = $(!NTN_SoftwareBase)"\"$(Manufacturer)"\"$(ProductSoftwareName)"\CurrentVersion"
    ParamKeyName             = $(!NTN_ServiceBase)"\"$(ProductHardwareName)"\Parameters"

    CANNOT_FIND_ANY_MAC_PORTS  = "No MAC Driver ports available"
    CANNOT_FIND_ANY_VNET_PORTS = "No slots available to create a VNET"
    NO_VNET_PORTS              = "No slots available for VNET use"
    TOO_MANY_ADAPTERS          = "More than 8 Quad adapters"
    INVALID_REGISTRY_VSLOT     = "Invalid VSlot entry in registry"


    BncAdapter          = "Quad 10Base2 Adapter"
    TpAdapter           = "Quad 10BaseT Adapter"

;==================================================================
;==================================================================
; Data Section - Miscellanious useful junk.
;
[GeneralConstants]
    NoTitle            = 0
    KeyNull            = ""
    MAXIMUM_ALLOWED    = 33554432
    KeyProduct         = ""
    KeyParameters      = ""
    TRUE               = 1
    FALSE              = 0
    DriverPath         = $(!STF_NTPATH)\drivers
    AllHexDigits       = "0123456789abcdefABCDEF"
    AllDecimalDigits   = "0123456789"

;==================================================================
;==================================================================
; Data Section - Valid Hex Digits.
;
[HexDigits]
    Hex0 = 0
    Hex1 = 1
    Hex2 = 2
    Hex3 = 3
    Hex4 = 4
    Hex5 = 5
    Hex6 = 6
    Hex7 = 7
    Hex8 = 8
    Hex9 = 9
    HexA = A
    HexB = B
    HexC = C
    HexD = D
    HexE = E
    HexF = F

;==================================================================
;==================================================================
; Data Section - Valid Decimal Digits.
;
[DecimalDigits]
    Decimal0 = 0
    Decimal1 = 1
    Decimal2 = 2
    Decimal3 = 3
    Decimal4 = 4
    Decimal5 = 5
    Decimal6 = 6
    Decimal7 = 7
    Decimal8 = 8
    Decimal9 = 9

;==================================================================
;==================================================================
; Data Section - Input NetCard parameters.
;
[ReadSetupParameters]
    BusTypeInterface = $(!p:BusTypeInterface)
    BusNumber        = $(!p:BusNumber)
    Socket           = $(!p:Socket)
    SocketList       = $(!p:SocketList)
    NetworkAddress   = $(!p:NetworkAddress)
    WatchDogTimer    = $(!p:WatchDogTimer)
    TOnTimer         = $(!p:TOnTimer)
    TOffTimer        = $(!p:TOffTimer)
    BridgeAgeTimer   = $(!p:BridgeAgeTimer)
    PollLoopPasses   = $(!p:PollLoopPasses)
    MaxRetries       = $(!p:MaxRetries)
    FullMemoryWindow = $(!p:FullMemoryWindow)
    LinkTestEnabled  = $(!p:LinkTestEnabled)
    FifoThreshold    = $(!p:FifoThreshold)
    DownLoadFileBt   = $(!p:DownLoadFileBt)
    DownLoadFileTn   = $(!p:DownLoadFileTn)
    DownLoadFilePci  = $(!p:DownLoadFilePci)
    FlashNumber      = $(!p:FlashNumber)
    IsVnet           = $(!p:IsVnet)
    VSlot1           = $(!p:VSlot1)
    VSlot2           = $(!p:VSlot2)
    VSlot3           = $(!p:VSlot3)
    VSlot4           = $(!p:VSlot4)
    VSlot5           = $(!p:VSlot5)
    VSlot6           = $(!p:VSlot6)
    VSlot7           = $(!p:VSlot7)
    VSlot8           = $(!p:VSlot8)

;==================================================================
;==================================================================
; Data Section - Output NetCard parameters.
;
[ReturnSetupParameters]
    !p:BusTypeInterface = $(BusTypeInterface)
    !p:BusNumber        = $(BusNumber)
    !p:Socket           = $(Socket)
    !p:NetworkAddress   = $(NetworkAddress)
    !p:WatchDogTimer    = $(WatchDogTimer)
    !p:TOnTimer         = $(TOnTimer)
    !p:TOffTimer        = $(TOffTimer)
    !p:BridgeAgeTimer   = $(BridgeAgeTimer)
    !p:PollLoopPasses   = $(PollLoopPasses)
    !p:MaxRetries       = $(MaxRetries)
    !p:FullMemoryWindow = $(FullMemoryWindow)
    !p:LinkTestEnabled  = $(LinkTestEnabled)
    !p:FifoThreshold    = $(FifoThreshold)
    !p:DownLoadFileBt   = $(DownLoadFileBt)
    !p:DownLoadFileTn   = $(DownLoadFileTn)
    !p:DownLoadFilePci  = $(DownLoadFilePci)
    !p:FlashNumber      = $(FlashNumber)
    !p:IsVnet           = $(IsVnet)
    !p:VSlot1           = $(VSlot1)
    !p:VSlot2           = $(VSlot2)
    !p:VSlot3           = $(VSlot3)
    !p:VSlot4           = $(VSlot4)
    !p:VSlot5           = $(VSlot5)
    !p:VSlot6           = $(VSlot6)
    !p:VSlot7           = $(VSlot7)
    !p:VSlot8           = $(VSlot8)

;==================================================================
;==================================================================
; Data Section - NetCard parameter defaults.
;
[DefaultSetupParameters]
    BusTypeInterface = 3
    DownLoadFileBt   = "mxmca4bt.bin"
    DownLoadFileTn   = "mxmca4tn.bin"
    DownLoadFilePci  = "mxpci4bt.bin"


[DefaultMainParameters]
    NetworkAddress   = ""
    LinkTestEnabled  = 1
    WatchDogTimer    = 0
    FullMemoryWindow = 0
    BridgeAgeTimer   = 120
    PollLoopPasses   = 0xffffffff
    TOnTimer         = 0xffffffff
    TOffTimer        = 0xffffffff
    FifoThreshold    = 0xffffffff
    MaxRetries       = 0xffffffff
    IsVnet           = 0

[DefaultVSlots]
;; format = bus number,
;;          bus type (5 PCI, 3 MCA),
;;          slot number,
;;          full memory window,
;;          port 1 (0 not in use, 1 in use),
;;          port 2 (0 not in use, 1 in use),
;;          port 3 (0 not in use, 1 in use),
;;          port 4 (0 not in use, 1 in use),
;;          link test for port 1 (0 for disable, 1 for enable),
;;          link test for port 2 (0 for disable, 1 for enable),
;;          link test for port 3 (0 for disable, 1 for enable),
;;          link test for port 4 (0 for disable, 1 for enable),
;;          flash slot number for PCI
    VSlotX1          = "00,3,FF,00,0,0,0,0,1,1,1,1,F"
    VSlotX2          = "00,3,FF,00,0,0,0,0,1,1,1,1,F"
    VSlotX3          = "00,3,FF,00,0,0,0,0,1,1,1,1,F"
    VSlotX4          = "00,3,FF,00,0,0,0,0,1,1,1,1,F"
    VSlotX5          = "00,3,FF,00,0,0,0,0,1,1,1,1,F"
    VSlotX6          = "00,3,FF,00,0,0,0,0,1,1,1,1,F"
    VSlotX7          = "00,3,FF,00,0,0,0,0,1,1,1,1,F"
    VSlotX8          = "00,3,FF,00,0,0,0,0,1,1,1,1,F"
    BusList          = "0,0,0,0,0,0,0,0"

[ParameterRanges]
    WatchDogMin      = 0
    WatchDogMax      = 255
    BridgeAgeMin     = 0
    BridgeAgeMax     = 32000

;==================================================================
;==================================================================
; Data Section - NetCard media type.
;
[CardType]
    MediaType = 1

;==================================================================
;==================================================================
; Data Section - MCA Card Id's.
;
[McaCardIds]
    ETH_TP_ID_BYTE_1  = 109
    ETH_TP_ID_BYTE_2  = 143
    ETH_BNC_ID_BYTE_1 = 106
    ETH_BNC_ID_BYTE_2 = 143
    MCA_BUS_TYPE      = 3

;==================================================================
;==================================================================
; Data Section - PCI Card Id's.
;
[PciCardIds]
    ETH_ID_BYTE_1  = 17
    ETH_ID_BYTE_2  = 184
    ETH_DEVICE_ID  = 1  
    ETH_VENDOR_ID  = 4536
    PCI_BUS_TYPE   = 5

;==================================================================
;==================================================================
; Data Section - Dialog Resource Dll Information.
;
[DllInformation]
    DiskName = "IBM PeerMaster Option Diskette"
    DllName  = quadenet.dll
    HlpName  = quadenet.hlp
    MinID    = 50000
    MaxID    = 50006

;==================================================================
;==================================================================
; Data Section - Language-Specific dialog variables.
;
[DialogConstantsENG]
    LblContinue = "Continue"
    LblOK       = "OK"
    LblHelp     = "Help"
    LblExit     = "Cancel"
    LblCancel   = "Cancel"
    Continue    = "Continue"
    OK          = "OK"
    Help        = "Help"
    Exit        = "Cancel"
    Cancel      = "Cancel"

;==================================================================
;==================================================================
; Data Section - Progress dialog variables.
;
[FileConstantsENG]
    FunctionTitle       = "IBM Ethernet Quad PeerMaster Adapter Setup"
    ProCaption          = "Windows NT Setup"
    ProCancel           = "Cancel"
    ProCancelMsg        = "Windows NT Networking is not correctly installed.  " +
                          "Are you sure you want to cancel copying files?"
    ProCancelCap        = "Network Setup Message"
    ProText1            = "Copying:"
    ProText2            = "To:"
    ShellCodeErrorTitle = "IBM PeerMaster Adapter Setup Error"

;==================================================================
;==================================================================
; Data Section - File-Specific dialog variables.
;
[TemplatesCONFIGURE]
    DlgTemplate         = "XPDLG1"
    DlgTemplateBase     = "XPDLG1"
    HelpContext         = 50006
    HelpContextBase     = 50006

[TemplatesINSTALL]
    DlgTemplate         = "XPDLG"
    DlgTemplateBase     = "XPDLG"
    HelpContext         = 50000
    HelpContextBase     = 50000

[FileDependentDlgENG]
    DlgType             = "RadioCombination"
    DlgTemplateAdvanced = "XPADV"
    DlgTemplateVnet     = "XPVNET0"
    DlgTemplateVnet1    = "XPVNET1"
    DlgTemplateVnet2    = "XPVNET2"
    DlgTemplateVnet3    = "XPVNET3"
    Caption             = "IBM Ethernet Quad PeerMaster Adapter Setup"
    AdvancedCaption     = "IBM Ethernet Quad PeerMaster Adapter Advanced Setup"
    VnetCaption0        = "IBM Ethernet Quad PeerMaster Virtual Adapter Setup"
    VnetCaption1        = "IBM Ethernet Quad PeerMaster Virtual Adapter Port Setup"
    VnetCaption2        = "IBM Ethernet Quad PeerMaster Virtual Adapter Advanced Setup"
    VnetCaption3        = "IBM Ethernet Quad PeerMaster Virtual Adapter Advanced Port Setup"
    NotifyFields        = {NO}
    RCCtlFocusOn        = 403

    LblSocket           = "&Socket Id"
    LblNetworkAddress   = "&Network Address"
    LblLinkTest         = "&Link Test Enabled"
    LblFullMemory       = "&Full Memory Window Override"
    LblWatchDog         = "&Watch Dog Timer"
    LblBridgeAge        = "&Bridge Age Timer"
    LblAdvanced         = "&Advanced"
    LblVnet             = "Create &VNET"

    LblSlotSelect       = "Select Adapters to include in VNET"

    LblPortSelect       = "Select Ports to include in VNET"
    LblPort1            = "Port 1"
    LblPort2            = "Port 2"
    LblPort3            = "Port 3"
    LblPort4            = "Port 4"

    LblLinkTest1        = "Port &1 Link Test Enabled"
    LblLinkTest2        = "Port &2 Link Test Enabled"
    LblLinkTest3        = "Port &3 Link Test Enabled"
    LblLinkTest4        = "Port &4 Link Test Enabled"

    BusTypeString       = "Bus Type:"
    BusNumString        = "Bus:"
    SlotString          = "Slot:"
    PortString          = "Port:"

    HelpContextAdvanced = 50001
    HelpContextVnet     = 50002
    HelpContextVnet1    = 50003
    HelpContextVnet2    = 50004
    HelpContextVnet3    = 50005


;==================================================================
;==================================================================
; Data Section - VNET Slot Descriptions.
;
[SlotLabels]
    LblSlot1            = "Not Installed"
    LblSlot2            = "Not Installed"
    LblSlot3            = "Not Installed"
    LblSlot4            = "Not Installed"
    LblSlot5            = "Not Installed"
    LblSlot6            = "Not Installed"
    LblSlot7            = "Not Installed"
    LblSlot8            = "Not Installed"
    LblMca              = " (MCA) "
    LblPci              = " (PCI) "
    LblBus              = "Bus"
    LblSlot             = "Slot"

[PortDescription1]
    LblSlotDescription = $(LblSlot1)

[PortDescription2]
    LblSlotDescription = $(LblSlot2)

[PortDescription3]
    LblSlotDescription = $(LblSlot3)

[PortDescription4]
    LblSlotDescription = $(LblSlot4)

[PortDescription5]
    LblSlotDescription = $(LblSlot5)

[PortDescription6]
    LblSlotDescription = $(LblSlot6)

[PortDescription7]
    LblSlotDescription = $(LblSlot7)

[PortDescription8]
    LblSlotDescription = $(LblSlot8)

[ReadVSlot1]
    ValueList = $(VSlot1)

[ReadVSlot2]
    ValueList = $(VSlot2)

[ReadVSlot3]
    ValueList = $(VSlot3)

[ReadVSlot4]
    ValueList = $(VSlot4)

[ReadVSlot5]
    ValueList = $(VSlot5)
                        
[ReadVSlot6]
    ValueList = $(VSlot6)

[ReadVSlot7]
    ValueList = $(VSlot7)

[ReadVSlot8]
    ValueList = $(VSlot8)

[WriteVSlot1]
    VSlot1 = $(ValueList)

[WriteVSlot2]
    VSlot2 = $(ValueList)

[WriteVSlot3]
    VSlot3 = $(ValueList)

[WriteVSlot4]
    VSlot4 = $(ValueList)

[WriteVSlot5]
    VSlot5 = $(ValueList)

[WriteVSlot6]
    VSlot6 = $(ValueList)

[WriteVSlot7]
    VSlot7 = $(ValueList)

[WriteVSlot8]
    VSlot8 = $(ValueList)

[SetTemp1]
    VTemp1 = $(VTempX)

[SetTemp2]
    VTemp2 = $(VTempX)

[SetTemp3]
    VTemp3 = $(VTempX)

[SetTemp4]
    VTemp4 = $(VTempX)

[SetTemp5]
    VTemp5 = $(VTempX)

[SetTemp6]
    VTemp6 = $(VTempX)

[SetTemp7]
    VTemp7 = $(VTempX)

[SetTemp8]
    VTemp8 = $(VTempX)

[SetLabel1]
    LabelIndex1 = $(OldIndex)

[SetLabel2]
    LabelIndex2 = $(OldIndex)

[SetLabel3]
    LabelIndex3 = $(OldIndex)

[SetLabel4]
    LabelIndex4 = $(OldIndex)

[SetLabel5]
    LabelIndex5 = $(OldIndex)

[SetLabel6]
    LabelIndex6 = $(OldIndex)

[SetLabel7]
    LabelIndex7 = $(OldIndex)

[SetLabel8]
    LabelIndex8 = $(OldIndex)

;==================================================================
;==================================================================
; Data Section - Dialog Error Messages.
;
[DialogErrorStringsENG]
    InvalidNetAddress = "The Network Address specified is invalid.  Please consult the Help File for more information."
    InvalidWatchDog   = "The value specified for the Watch Dog Timer is invalid.  Please consult the Help File for more information."
    InvalidBridgeAge  = "The value specified for the Bridge Age Timer is invalid.  Please consult the Help File for more information."
    InvalidSlotNum    = "The flash slot number is not correctly programmed in the Pci card.  Run the DOS setup utility to enter correct value."
    AtLeastOneSlot    = "At least one Slot must be selected for inclusion in the VNET"
    AtLeastOnePort    = "At least one Port must be selected for inclusion in the VNET"

;==================================================================
;==================================================================
; Identify Major Options Supported by INF File.
;
; $($R0)  = Status.
; $($R1)  = .inf option type(s).
; $($R2)  = Installation media description.
;
[Identify]
    Read-Syms Identification

    shell "" DebugControl

    Set Status     = STATUS_SUCCESSFUL
    Set Identifier = $(OptionType)
    Set Media      = #("Source Media Descriptions", 1, 1)

    Return $(Status) $(Identifier) $(Media)

;==================================================================
;==================================================================
; Return INF File Supported Options.
;
; $($0)  =  Target Language.
; $($1)  =  Target Platform.
;
; $($R0) =  Status.
; $($R1) =  List of .inf options.
; $($R2) =  Description of .inf options.
;
[ReturnOptions]
    shell "" DebugControl

    Set OptionList     = {}
    Set OptionTextList = {}
    Set LanguageList   = ^(LanguagesSupported, 1)
    Set PlatformList   = ^(PlatformsSupported, 1)

    IfContains(i) $($0) Not-In $(LanguageList)
        Set Status = STATUS_NOLANGUAGE
    Else-IfStr(i) $($1) == ""
        Set Status = STATUS_SUCCESSFUL
    Else-IfContains(i) $($1) Not-In $(PlatformList)
        Set Status = STATUS_NOTSUPPORTED
    Else
        Set Status = STATUS_SUCCESSFUL
    EndIf

    IfStr(i) $(Status) == STATUS_SUCCESSFUL
        Set OptionList     = ^(Options, 1)
        Set OptionTextList = ^(OptionsText$($0), 1)
    EndIf

    Return $(Status) $(OptionList) $(OptionTextList)

;==================================================================
;==================================================================
; Install Option.
;
;
; $($0) =  Language to use
; $($1) =  OptionID to install
; $($2) =  SourceDirectory
; $($3) =  AddCopy  (YES | NO)
; $($4) =  DoCopy   (YES | NO)
; $($5) =  DoConfig (YES | NO)
;
; $($R0) = STATUS
;
;
[InstallOption]
    shell "" DebugControl

    Set Status   = STATUS_FAILED
    Set Option   = $($1)
    Set SrcDir   = $($2)
    Set AddCopy  = $($3)
    Set DoCopy   = $($4)
    Set DoConfig = $($5)

    Debug-Output "QuadEnet.Inf:  Option   = "$(Option)
    Debug-Output "QuadEnet.Inf:  AddCopy  = "$(AddCopy)
    Debug-Output "QuadEnet.Inf:  DoCopy   = "$(DoCopy)
    Debug-Output "QuadEnet.Inf:  DoConfig = "$(DoConfig)
    Debug-Output "QuadEnet.Inf:  Caller   = "$(!NTN_Origination)

    Read-Syms GeneralConstants
    Read-Syms FileConstants

    Set LanguageList = ^(LanguagesSupported, 1)

    IfContains(i) $($0) NOT-IN $(LanguageList)
        Return STATUS_NOLANGUAGE
    EndIf

    Set-Title  $(FunctionTitle)

    EndWait

    IfStr(i) $(!NTN_InstallMode)      == DeInstall
        Set StartLabel = RemoveAdapter
    Else-IfStr(i) $(!NTN_InstallMode) == Update
        Set StartLabel = UpgradeSoftware
    Else-IfStr(i) $(!NTN_InstallMode) == Bind
        Set StartLabel = BindAdapter
    Else-IfStr(i) $(!NTN_InstallMode) == Configure
        Set StartLabel = ConfigureAdapter
    Else
        Set StartLabel = InstallAdapter
    EndIf
                           
    GoTo $(StartLabel)

;==================================================================
;==================================================================
;  Install New MAC Adapter.
;
;  $($R0)  Status.
;
InstallAdapter =+
    Read-Syms RegistryConstants
    Read-Syms FileConstants
    Read-Syms GeneralConstants

    Debug-Output "QuadEnet.Inf: InstallAdapter"

    Set Mode = INSTALL

    Set OldVersionExisted = FALSE

    OpenRegKey $(!REG_H_LOCAL) "" $(ProductKeyName) $(MAXIMUM_ALLOWED) KeyProduct

    IfStr $(KeyProduct) != $(KeyNull)
        CloseRegKey $(KeyProduct)

        IfStr(i) $(!NTN_RegBase) == $(ProductKeyName)
           Shell $(UtilityInf) VerExistedDlg $(ProductSoftwareTitle) +
               $(ProductVersion)

           IfInt $(ShellCode) != $(!SHELL_CODE_OK)
               Shell "" DoShellErrorMessage "Utility.Inf, VerExistedDlg"
               Return STATUS_FAILED
           EndIf
        Else
           Set OldVersionExisted = TRUE
        EndIf
    EndIf

    IfStr(i) $(OldVersionExisted) == FALSE
        Set SrcDir = $($R1)
        Shell "" SetCopy $(DoCopy) $(AddCopy) $(SrcDir) "Install-Pci"
    EndIf
        

    Read-Syms SlotLabels
    Read-Syms DefaultVSlots
    Read-Syms McaCardIds
    Read-Syms PciCardIds

    Set FlashNumber = 15

    Split-String $(VSlotX1) "," VSlot1
    Split-String $(VSlotX2) "," VSlot2
    Split-String $(VSlotX3) "," VSlot3
    Split-String $(VSlotX4) "," VSlot4
    Split-String $(VSlotX5) "," VSlot5
    Split-String $(VSlotX6) "," VSlot6
    Split-String $(VSlotX7) "," VSlot7
    Split-String $(VSlotX8) "," VSlot8
    Split-String $(BusList) "," BusList

    Shell "" BuildSlotBus
    Set Status = $($R0)
    IfStr(i) $(Status) != "STATUS_SUCCESSFUL"
        return $(Status)
    EndIf

    Set SocketList = {}
    ForListDo $(SlotBusAvailable)
        Set BusType = *($($),1)
        Set BusNum  = *($($),2)
        Set SlotNum = *($($),3)

        Shell "" IsVnetCardAlreadyInstalled,           +
            $(BusType),                                +
            $(BusNum),                                 +
            $(SlotNum),                                +
            $(ProductHardwareDescription),             +
            $(ProductHardwareName)

        IfInt $($ShellCode) != $(!SHELL_CODE_OK)
            Shell "" DoShellErrorMessage "QuadEnet.Inf, IsNetCardAlreadyInstalled"
            Return STATUS_FAILED
        EndIf

        IfStr(i) $($R0) != "NO_ERROR"
            Shell "" DoRegistryErrorMessage $($R0)
            Return STATUS_FAILED
        EndIf

        IfStr(i) $($R1) != "YES"
            Set PortList   = { 1, 2, 3, 4 }
            ForListDo $(PortList)
                set PortNum = *($($),1)

                Shell "" IsNetCardAlreadyInstalled,            +
                    $(BusType),                                +
                    $(BusNum),                                 +
                    $(SlotNum), $(PortNum),                    +
                    $(ProductHardwareDescription),             +
                    $(ProductHardwareName)

                IfInt $($ShellCode) != $(!SHELL_CODE_OK)
                    Shell "" DoShelErrorMessage "QuadEnet.Inf, IsNetCardAlreadyInstalled"
                    Return STATUS_FAILED
                EndIf

                IfStr(i) $($R0) != "NO_ERROR"
                    Shell "" DoRegistryErrorMessage $($R0)
                    Return STATUS_FAILED
                EndIf

                IfStr(i) $($R1) != "YES"
                    Set SocketList = >($(SocketList), $(BusNum)","$(SlotNum)","$(PortNum)","$(BusType))
                EndIf
            EndForListDo
        EndIf
    EndForListDo

    Shell "" RefreshFlashList

    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        Shell "" DoShellErrorMessage "QuadEnet.Inf, RefreshFlashList"
        Return STATUS_FAILED
    EndIf

    IfStr(i) $($R0) != "NO_ERROR"
        Shell "" DoRegistryErrorMessage $($R0)
        Return STATUS_FAILED
    EndIf

    IfStr(i) $(SocketList) == {}
        Shell "" DoFatalMessage $(CANNOT_FIND_ANY_MAC_PORTS)
        Return STATUS_FAILED
    EndIf

    Read-Syms DefaultSetupParameters
    Read-Syms DefaultMainParameters

    Shell "" DebugConfiguration "InstallAdapter After Setting Defaults"

    Shell "" DoAdapterDialog
    Ifstr(i) $($R0) != STATUS_SUCCESSFUL
        Return $($R0)
    EndIf

    Shell "" AddComponents $(OldVersionExisted)
    IfStr(i) $($R0) != STATUS_SUCCESSFUL
        Return $($R0)
    EndIf

    Shell "" WriteAdapterParameters

    IfStr(i) $(OldVersionExisted) == FALSE
        IfStr(i) $(!p:DoCopy) == "YES"
            Shell $(UtilityInf) DoAskSource $(!STF_CWDDIR) $(SrcDir) YES

            IfInt $($ShellCode) != $(!SHELL_CODE_OK)
                Shell "" DoShellErrorMessage "Utility.Inf, DoAskSource"
                Return STATUS_FAILED
            Else-IfStr(i) $($R0) == STATUS_FAILED
                Shell "" DoRegistryErrorMessage ASK_SOURCE_FAIL
                Return STATUS_FAILED
            Else-IfStr(i) $($R0) == STATUS_USERCANCEL
                Return STATUS_USERCANCEL
            Else-IfStr(i) $($R0) != STATUS_SUCCESSFUL
                Shell "" DoShellErrorMessage "Utility.Inf, DoAskSource"
                Return STATUS_FAILED
            EndIf

            Set SrcDir = $($R1)
        EndIf

        Shell "" SetCopy $(DoCopy) $(AddCopy) $(SrcDir) "Install-Option"
  
    EndIf
    
    Return STATUS_SUCCESSFUL

;==================================================================
;==================================================================
;  Configure Existing Adapter.
;
;  $($R0)  Status.
;
ConfigureAdapter =+
    Read-Syms RegistryConstants
    Read-Syms FileConstants
    Read-Syms GeneralConstants

    Set Mode = CONFIGURE

    IfStr(i) $(ProductKeyName) == $(!NTN_RegBase)
        Shell "" DoRegistryErrorMessage CANNOT_CONFIGURE_SOFTWARE
        Return STATUS_SUCCESSFUL
    EndIf

    OpenRegKey $(!REG_H_LOCAL) "" $(!NTN_RegBase) $(MAXIMUM_ALLOWED) KeyProduct

    IfStr(i) $(KeyProduct) == $(KeyNull)
        Shell "" DoRegistryErrorMessage CANNOT_FIND_COMPONENT_SERVICE
        IfInt $($ShellCode) != $(!SHELL_CODE_OK)
            Shell "" DoShellErrorMessage "OpenRegKey"
            Return STATUS_FAILED
        EndIf
        Return STATUS_FAILED
    EndIf

    Shell $(UtilityInf) FindService $(KeyProduct)
    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        CloseRegKey $($R1)
        Shell "" DoShellErrorMessage "Utility.Inf, FindService"
        Return STATUS_FAILED
    EndIf
    IfStr(i) $($R0) != NO_ERROR
        CloseRegKey $($R1)
        Shell "" DoRegistryErrorMessage $($R0)
        Return STATUS_FAILED
    EndIf

    Set KeyParameters = $($R2)

    CloseRegKey $($R1)

    IfStr $(KeyParameters) == $(KeyNull)
        Shell "" DoRegistryErrorMessage CANNOT_FIND_COMPONENT_SERVICE
        Return STATUS_FAILED
    EndIf

    Set OldVersionExisted = TRUE
    Set NetworkAddress = ""

    Set ValueName = ""
    Set ValueData = ""
    Set ValueStr  = ""
    Set ValueList = {}

    EnumRegValue $(KeyParameters) ValueList

    ForListDo $(ValueList)
        Set ValueItem = $($)
        Set ValueName = *($(ValueItem),1)
        Set ValueData = *($(ValueItem),4)

        IfStr(i) $(ValueName)      == "SlotNumber"
            Set SlotNumber       = $(ValueData)
        Else-IfStr(i) $(ValueName) == "PortNumber"
            Set PortNumber       = $(ValueData)
        Else-IfStr(i) $(ValueName) == "BusType"
            Set BusTypeInterface = $(ValueData)
        Else-IfStr(i) $(ValueName) == "BusNumber"
            Set BusNumber        = $(ValueData)
        Else-IfStr(i) $(ValueName) == "NetworkAddress"
            Set NetworkAddress   = $(ValueData)
        Else-IfStr(i) $(ValueName) == "LinkTestEnabled"
            Set LinkTestEnabled  = $(ValueData)
        Else-IfStr(i) $(ValueName) == "DownLoadFileBt"
            Set DownLoadFileBt   = $(ValueData)
        Else-IfStr(i) $(ValueName) == "DownLoadFileTn"
            Set DownLoadFileTn   = $(ValueData)
        Else-IfStr(i) $(ValueName) == "DownLoadFilePci"
            Set DownLoadFilePci  = $(ValueData)
        Else-IfStr(i) $(ValueName) == "BridgeAgeTimer"
            Set BridgeAgeTimer   = $(ValueData)
        Else-IfStr(i) $(ValueName) == "WatchDogTimer"
            Set WatchDogTimer    = $(ValueData)
        Else-IfStr(i) $(ValueName) == "FullMemoryWindow"
            Set FullMemoryWindow = $(ValueData)
        Else-IfStr(i) $(ValueName) == "FlashNumber"
            Set FlashNumber      = $(ValueData)

        Else-IfStr(i) $(ValueName) == "TOnTimer"
            Set-DecToHex TOnTimer       = $(ValueData)
        Else-IfStr(i) $(ValueName) == "TOffTimer"
            Set-DecToHex TOffTimer      = $(ValueData)
        Else-IfStr(i) $(ValueName) == "FifoThreshold"
            Set-DecToHex FifoThreshold  = $(ValueData)
        Else-IfStr(i) $(ValueName) == "MaxRetries"
            Set-DecToHex MaxRetries     = $(ValueData)
        Else-IfStr(i) $(ValueName) == "PollLoopPasses"
            Set-DecToHex PollLoopPasses = $(ValueData)

        Else-IfStr(i) $(ValueName) == "IsVnet"
            Set IsVnet = $(ValueData)
        Else-IfStr(i) $(ValueName) == "VSlot1"
            Set VSlotX1          = $(ValueData)
        Else-IfStr(i) $(ValueName) == "VSlot2"
            Set VSlotX2          = $(ValueData)
        Else-IfStr(i) $(ValueName) == "VSlot3"
            Set VSlotX3          = $(ValueData)
        Else-IfStr(i) $(ValueName) == "VSlot4"
            Set VSlotX4          = $(ValueData)
        Else-IfStr(i) $(ValueName) == "VSlot5"
            Set VSlotX5          = $(ValueData)
        Else-IfStr(i) $(ValueName) == "VSlot6"
            Set VSlotX6          = $(ValueData)
        Else-IfStr(i) $(ValueName) == "VSlot7"
            Set VSlotX7          = $(ValueData)
        Else-IfStr(i) $(ValueName) == "VSlot8"
            Set VSlotX8          = $(ValueData)
        EndIf
    EndForListDo

    Split-String $(VSlotX1) $(AllHexDigits) VSlotX
    shell "" FixVslot
    Split-String $(VSlotX) "," VSlot1

    Split-String $(VSlotX2) $(AllHexDigits) VSlotX
    shell "" FixVslot
    Split-String $(VSlotX) "," VSlot2

    Split-String $(VSlotX3) $(AllHexDigits) VSlotX
    shell "" FixVslot
    Split-String $(VSlotX) "," VSlot3

    Split-String $(VSlotX4) $(AllHexDigits) VSlotX
    shell "" FixVslot
    Split-String $(VSlotX) "," VSlot4

    Split-String $(VSlotX5) $(AllHexDigits) VSlotX
    shell "" FixVslot
    Split-String $(VSlotX) "," VSlot5

    Split-String $(VSlotX6) $(AllHexDigits) VSlotX
    shell "" FixVslot
    Split-String $(VSlotX) "," VSlot6

    Split-String $(VSlotX7) $(AllHexDigits) VSlotX
    shell "" FixVslot
    Split-String $(VSlotX) "," VSlot7

    Split-String $(VSlotX8) $(AllHexDigits) VSlotX
    shell "" FixVslot
    Split-String $(VSlotX) "," VSlot8

    Set Socket     = $(BusNumber)","$(SlotNumber)","$(PortNumber)","$(BusTypeInterface)
    Set SocketList = $(Socket)

    Read-Syms SlotLabels
    Read-Syms McaCardIds
    Read-Syms PciCardIds


    Shell "" BuildSlotBus
    Set Status = $($R0)
    IfStr(i) $(Status) != "STATUS_SUCCESSFUL"
        return $(Status)
    EndIf

    Shell "" RefreshFlashList

    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        Shell "" DoShellErrorMessage "QuadEnet.Inf, RefreshFlashList"
        Return STATUS_FAILED
    EndIf

    IfStr(i) $($R0) != "NO_ERROR"
        Shell "" DoRegistryErrorMessage $($R0)
        Return STATUS_FAILED
    EndIf

    IfInt $(IsVnet) == 1
        Set CardsAvailable = {}
        shell "" BuildVnetAdapterList $(SlotBusAvailable)
        IfStr(i) $($R0) != STATUS_SUCCESSFUL
            return STATUS_FAILED
        EndIf
        shell "" RebuildVnetAdapterList $(SlotBusAvailable)
        IfStr(i) $($R0) != STATUS_SUCCESSFUL
            return STATUS_FAILED
        EndIf
        IfStr(i) $(CardsAvailable) == {}
            Shell "" DoShellErrorMessage $(NO_VNET_PORTS)
            return STATUS_FAILED
        EndIf
    EndIf

    Shell "" DebugConfiguration "ConfigureAdapter After Reading Registry"

    Shell "" DoAdapterDialog

    IfStr(i) $($R0) != STATUS_SUCCESSFUL
        Return $($R0)
    EndIf

    StartWait
    Shell "" WriteAdapterParameters
    EndWait
        
    Return STATUS_SUCCESSFUL

;==================================================================
;==================================================================
;  Bind Adapter - not relevant.
;
;  $($R0)  Status.
;
BindAdapter =+
    Shell "" DoFatalMessage "Binding: Sorry, not yet implemented."
    Return STATUS_FAILED

;==================================================================
;==================================================================
;  Remove Installed Adapter.
;
;  $($R0)  Status.
;
RemoveAdapter =+
    Read-Syms RegistryConstants
    Read-Syms FileConstants

    IfStr(i) $(ProductKeyName) == $(!NTN_RegBase)
        Shell $(UtilityInf) RemoveSoftwareComponent $(Manufacturer) +
            $(ProductSoftwareName)
        IfInt $($ShellCode) != $(!SHELL_CODE_OK)
            Shell "" DoShellErrorMessage "Utility.Inf, RemoveSoftwareComponent"
            Return STATUS_FAILED
        EndIf

        IfStr(i) $($R0) != NO_ERROR
            Shell "" DoRegistryErrorMessage $($R0)
            Return STATUS_FAILED
        EndIf
    Else
        Shell $(UtilityInf) RemoveHardwareComponent $(Manufacturer) +
            $(ProductSoftwareName) $(!NTN_RegBase)
        IfInt $($ShellCode) != $(!SHELL_CODE_OK)
            Shell "" DoShellErrorMessage "Utility.Inf, RemoveHardwareComponent"
            Return STATUS_FAILED
        EndIf

        IfStr(i) $($R0) != NO_ERROR
            Shell "" DoRegistryErrorMessage $($R0)
            Return STATUS_FAILED
        EndIf
    EndIf

    Return STATUS_SUCCESSFUL

;==================================================================
;==================================================================
;  Upgrade Adapter Software.
;
;  $($R0)  Status.
;
UpgradeSoftware =+
    Read-Syms RegistryConstants
    Read-Syms GeneralConstants

;;
;;  Determine that the registry contains the following entry:
;;      HKEY_LOCAL_MACHINE\SOFTWARE\IBM\IBMQuad\CurrentVersion\NetRules
;;
    Set IBMSoftwareName = $(!NTN_SoftwareBase)"\IBM\quadenet"
    Set KeyQuadEnet = ""
    OpenRegKey $(!REG_H_LOCAL) "" $(IBMSoftwareName) $(MAXIMUM_ALLOWED) KeyQuadEnet
    IfStr $(KeyQuadEnet) == $(KeyNull)
        Return STATUS_FAILED
    EndIf
    CloseRegKey $(KeyQuadEnet)

    Set IBMCurrentVersionName = $(IBMSoftwareName)"\CurrentVersion"
    Set KeyIBMVersion = ""
    OpenRegKey $(!REG_H_LOCAL) "" $(IBMCurrentVersionName) $(MAXIMUM_ALLOWED) KeyIBMVersion
    IfStr $(KeyIBMVersion) == $(KeyNull)
        Return STATUS_FAILED
    EndIf
    CloseRegKey $(KeyIBMVersion)

    Set IBMNetRule = $(IBMCurrentVersionName)"\NetRules"
    Set KeyIBMNetRule = ""
    OpenRegKey $(!REG_H_LOCAL) "" $(IBMNetRule) $(MAXIMUM_ALLOWED) KeyIBMNetRule
    IfStr $(KeyIBMNetRule) == $(KeyNull)
        Return STATUS_FAILED
    EndIf
    CloseRegKey $(KeyIBMNetRule)


    OpenRegKey $(!REG_H_LOCAL) "" $(ProductKeyName) $(MAXIMUM_ALLOWED) KeyProduct
    IfStr $(KeyProduct) != $(KeyNull)
        set DoCopy  = YES
        set AddCopy = YES
        Shell "" SetCopy $(DoCopy) $(AddCopy) $(SrcDir) "Install-Update"
        CloseRegKey $(KeyProduct)
    Else
        Return STATUS_FAILED
    EndIf
    Return STATUS_SUCCESSFUL

;==================================================================
;==================================================================
; Display Configuration for Debug.
;
;   $($0)   = Configuration CheckPoint Identifier.
;
[DebugConfiguration]
    Debug-Output "QuadEnet.Inf:  Configuration CheckPoint: "$($0)
    Debug-Output "QuadEnet.Inf:  IsVnet           = "$(!p:IsVnet)
    Debug-Output "QuadEnet.Inf:  SlotNumber       = "$(!p:SlotNumber)
    Debug-Output "QuadEnet.Inf:  PortNunber       = "$(!p:PortNumber)
    Debug-Output "QuadEnet.Inf:  BusType          = "$(!p:BusTypeInterface)
    Debug-Output "QuadEnet.Inf:  NetworkAddress   = "$(!p:NetworkAddress)
    Debug-Output "QuadEnet.Inf:  WatchDogTimer    = "$(!p:WatchDogTimer)
    Debug-Output "QuadEnet.Inf:  TOnTimer         = "$(!p:TOnTimer)
    Debug-Output "QuadEnet.Inf:  TOffTimer        = "$(!p:TOffTimer)
    Debug-Output "QuadEnet.Inf:  BridgeAgeTimer   = "$(!p:BridgeAgeTimer)
    Debug-Output "QuadEnet.Inf:  PollLoopPasses   = "$(!p:PollLoopPasses)
    Debug-Output "QuadEnet.Inf:  MaxRetries       = "$(!p:MaxRetries)
    Debug-Output "QuadEnet.Inf:  FullMemoryWindow = "$(!p:FullMemoryWindow)
    Debug-Output "QuadEnet.Inf:  LinkTestEnabled  = "$(!p:LinkTestEnabled)
    Debug-Output "QuadEnet.Inf:  FifoThreshold    = "$(!p:FifoThreshold)
    Debug-Output "QuadEnet.Inf:  FlashNumber      = "$(!p:FlashNumber)
    Debug-Output "QuadEnet.Inf:  VSlot1           = "$(!p:VSlot1)
    Debug-Output "QuadEnet.Inf:  VSlot2           = "$(!p:VSlot2)
    Debug-Output "QuadEnet.Inf:  VSlot3           = "$(!p:VSlot3)
    Debug-Output "QuadEnet.Inf:  VSlot4           = "$(!p:VSlot4)
    Debug-Output "QuadEnet.Inf:  VSlot5           = "$(!p:VSlot5)
    Debug-Output "QuadEnet.Inf:  VSlot6           = "$(!p:VSlot6)
    Debug-Output "QuadEnet.Inf:  VSlot7           = "$(!p:VSlot7)
    Debug-Output "QuadEnet.Inf:  VSlot8           = "$(!p:VSlot8)

    Return

;==================================================================
;==================================================================
; Display Warning Message.
;
; $($0)  = Text String.
;
; $($R0) = Action.
;
[DoWarningMessage]
    Read-Syms FileConstants

    Shell $(SubroutineInf) SetupMessage $(!STF_LANGUAGE) "WARNING" $($0)
    Return $($R1)

;==================================================================
;==================================================================
; Display NonFatal Error Message.
;
; $($0)  = Text String.
; $($1)  = Severity Level.
;
; $($R0) = Action.
;
[DoNonFatalMessage]
    Read-Syms FileConstants

    Set Severity = $($1)
    Set Error    = $($0)

    Shell $(SubroutineInf) SetupMessage $(!STF_LANGUAGE) $(Severity) $(Error)

    Return $($R1)

;==================================================================
;==================================================================
; Display Fatal Error Message.
;
; $($0) = Text String.
;
;
[DoFatalMessage] 
    Read-Syms FileConstants

    Set Error = $($0)

    IfStr(i) $(Error) == ""
        Shell $(UtilityInf) RegistryErrorString "SETUP_FAIL"
        IfInt $($ShellCode) != $(!SHELL_CODE_OK)
            Shell "" DoShellErrorMessage "Utility.Inf, RegistryErrorString"
            Return STATUS_FAILED
        EndIf
        Set Error = $($R0)
    EndIf
                                       
    Shell $(SubroutineInf) SetupMessage $(!STF_LANGUAGE) "FATAL" $(Error)

    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        Shell "" DoShellErrorMessage "Subroutine.Inf, SetupMessage"
        Return STATUS_FAILED
    EndIf

    Return

;==================================================================
;==================================================================
; Display Shell Error Message.
;
;   $($0)   = Text to be displayed
;                      
[DoShellErrorMessage]
    read-syms DialogConstants$(!STF_LANGUAGE)
    read-syms FileConstants$(!STF_LANGUAGE)

    Set DlgType      = "MessageBox"
    Set STF_MB_TITLE = $(ShellCodeErrorTitle)
    Set STF_MB_TEXT  = $($0)
    Set STF_MB_TYPE  = 1
    Set STF_MB_ICON  = 3
    Set STF_MB_DEF   = 1

    IfStr(i) $(STF_MB_TEXT) == ""
        set STF_MB_TEXT = "Unknown Error"
    EndIf

    ui start "Error Message"

    Return

;==================================================================
;==================================================================
; Check Hex String.
;
;   $($0)   = String to be checked.
;   $($1)   = Must-be length (= 0 then length must be at least
;             one, but the actual value not checked)
;                      
[CheckHex]
    Read-Syms GeneralConstants

    Set HexList = ^(HexDigits, 1)
    Split-String $($0) $(AllHexDigits) List
    QueryListSize ListSize $(List)

    IfInt $($1) != 0
        IfInt $(ListSize) != $($1)
            Return "FALSE"
        EndIf
    EndIf

    IfInt $(ListSize) == 0
        Return "FALSE"
    EndIf

    Set Index = 1

HexLoop =+
    Set HexChar = *($(List), $(Index))
    IfContains(i) $(HexChar) Not-In $(HexList)
        Return "FALSE"
    EndIf

    Set-Add Index = $(Index), 1
    IfInt $(Index) < $(ListSize)
        GoTo HexLoop
    EndIf

    Return "TRUE"

;==================================================================
;==================================================================
; Check Decimal Parameter String.
;
;   $($0)   = String to be checked.
;   $($1)   = Must-be length (= 0 then length must be at least
;             one, but the actual value not checked)
;   $($2)   = Minimum acceptable value
;   $($3)   = Maximum acceptable value
;   $($4)   = Error message to display if contstraints not met
;
;   $($R0)  = TRUE if all is well, else FALSE
;   $($R1)  = Return value from DoWarningMessage if value is bad
;
[CheckDecimalParameter]
    Read-Syms GeneralConstants

    Set TestString       = $($0)
    Set TestStringLength = $($1)
    Set Minimum          = $($2)
    Set Maximum          = $($3)
    Set BadString        = $($4)

    Set DecimalList = ^(DecimalDigits, 1)
    Split-String $(TestString) $(AllDecimalDigits) List
    QueryListSize ListSize $(List)

    IfInt $(TestStringLength) != 0
        IfInt $(ListSize) != $(TestStringLength)
            Shell "" DoWarningMessage $(BadString)
            Return "FALSE" $($R0)
        EndIf
    EndIf

    IfInt $(ListSize) == 0
        Shell "" DoWarningMessage $(BadString)
        Return "FALSE" $($R0)
    EndIf

    Set Index = 1

DecimalLoop =+
    Set DecimalChar = *($(List), $(Index))
    IfContains(i) $(DecimalChar) Not-In $(DecimalList)
        Shell "" DoWarningMessage $(BadString)
        Return "FALSE" $($R0)
    EndIf

    Set-Add Index = $(Index), 1
    IfInt $(Index) < $(ListSize)
        GoTo DecimalLoop
    EndIf

    IfInt $(TestString) < $(Minimum)
        Shell "" DoWarningMessage $(BadString)
        Return "FALSE" $($R0)
    EndIf

    IfInt $(TestString) > $(Maximum)
        Shell "" DoWarningMessage $(BadString)
        Return "FALSE" $($R0)
    EndIf

    Return "TRUE"

;==================================================================
;==================================================================
; Perform Adapter Configuration Dialog for MAC Driver.
;
;
;
[DoAdapterDialog]
    Read-Syms DllInformation
    Read-Syms FileDependentDlg$(!STF_LANGUAGE)
    Read-Syms Templates$(!p:Mode)
    Read-Syms DialogConstants$(!STF_LANGUAGE)
    Read-Syms FileConstants$(!STF_LANGUAGE)
    Read-Syms DialogErrorStrings$(!STF_LANGUAGE)
    Read-Syms GeneralConstants
    Read-Syms FileConstants
    Read-Syms ReadSetupParameters
    Read-Syms ParameterRanges
    Read-Syms McaCardIds
    Read-Syms PciCardIds
    Read-Syms SlotLabels

    Set SlotBusAvailable = $(!p:SlotBusAvailable)
    Set FlashList        = $(!p:FlashList)

    Set Item = *($(SocketList),1)
    Split-String $(Item) "," List
    ifstr(i) *($(List),7) == $(MCA_BUS_TYPE)
       Set NewSocket = $(BusNumString)*($(List), 1)" - "$(SlotString)*($(List), 3)" - "$(PortString)*($(List), 5)$(LblMca)
    else
       Set NewSocket = $(BusNumString)*($(List), 1)" - "$(SlotString)*($(List), 3)" - "$(PortString)*($(List), 5)$(LblPci)
    endif

    Set NewSocketList = {}

    ForListDo $(SocketList)
        Set Item = $($)
        Split-String $(Item) "," List
        ifstr(i) *($(List),7) == $(MCA_BUS_TYPE)
           Set NewItem = $(BusNumString)*($(List), 1)" - "$(SlotString)*($(List), 3)" - "$(PortString)*($(List), 5)$(LblMca)
        else
           Set NewItem = $(BusNumString)*($(List), 1)" - "$(SlotString)*($(List), 3)" - "$(PortString)*($(List), 5)$(LblPci)
        endif
        Set NewSocketList = >($(NewSocketList), $(NewItem))
    EndForListDo

    Set Combo1Out      = $(NewSocket)
    Set Combo1Save     = $(Combo1Out)
    Set Combo1List     = $(NewSocketList)
    Set Combo1ListSave = $(Combo1List)

    Set Combo2Out    = $(FullMemoryWindow)

    Set Combo2List = {}
    Set FullMemoryList  = 255
FullMemSet1 =+
    set Combo2List = >($(Combo2List), $(FullMemoryList))
    Set-Sub FullMemoryList = $(FullMemoryList), 1
    IfInt $(FullMemoryList) > 1
        GoTo FullMemSet1
    EndIf

    Set ListItemsIn  = {Combo1List, Combo2List}
    Set ListItemsOut = {Combo1Out, Combo2Out}

    Set ComboListItemsIn  = $(ListItemsIn)
    Set ComboListItemsOut = $(ListItemsOut)

    Set Path = $(!STF_WINDOWSSYSPATH)

    Split-String $(Path) "\" List
    QueryListSize ListSize $(List)

    IfStr(i) *($(List), $(ListSize)) != "\"
        Set Path = $(Path)"\"
    EndIf

    Set DllName = $(Path)$(DllName)
    Set HlpName = $(Path)$(HlpName)

    SetHelpFile $(HlpName) $(MinID) $(MaxID)

    LoadLibrary $(DiskName) $(DllName) DialogResourceHandle

    IfInt $(IsVnet) == 1
        GoTo DoVnetDialog
    EndIf

    EndWait

MainDialog =+
    Set EditFocusOn  = ""
    Set NewNetworkAddress = $(NetworkAddress)

    IfInt $(LinkTestEnabled) == 1
        set CheckItemsIn = { "ON" }
    Else
        set CheckItemsIn = { "OFF" }
    EndIf
    Set CheckItemsSave1 = $(CheckItemsIn)

RestartDialog =+
    Set ReInit = "YES"

RetryDialog =+
    Read-Syms RegistryConstants
    Read-Syms FileDependentDlg$(!STF_LANGUAGE)

    Set DlgTemplate  = $(DlgTemplateBase)
    Set HelpContext  = $(HelpContextBase)
    Set EditTextIn   = {$(NewNetworkAddress)}
    Set EditTextLim  = { 12 }

    Set Combo1Out    = $(Combo1Save)
    Set Combo1List   = $(Combo1ListSave)
    Set EditTextIn   = {$(NewNetworkAddress)}
    Set CheckItemsIn = $(CheckItemsSave1)
    ui start "InputDlg" $(DialogResourceHandle)
    Set Combo1Save        = $(Combo1Out)
    Set Combo1ListSave    = $(Combo1List)
    Set NewNetworkAddress = *($(EditTextOut),1)
    Set CheckItemsSave1   = $(CheckItemsOut)
    StartWait

    Set ReInit = "NO"

    Debug-Output "QuadEnet.Inf:  MainDlg, DLGEVENT = "$(DLGEVENT)

    IfStr(i) $(DLGEVENT) == "BACK"
        GoTo EndDialog
    EndIf

    IfStr(i) $(DLGEVENT) == "DLGBUTTON2"
        set CardsAvailable = {}
        shell "" RebuildVnetAdapterList $(SlotBusAvailable)
        IfStr(i) $($R0) != STATUS_SUCCESSFUL
            return STATUS_FAILED
        EndIf

        IfStr(i) $(CardsAvailable) == {}
            Shell "" DoShellErrorMessage $(CANNOT_FIND_ANY_VNET_PORTS)
            Return STATUS_FAILED
        EndIf

        ui pop 1
        GoTo DoVnetDialog
    EndIf


    Split-String $(Combo1Out) " - " ListX
    Split-String *($(ListX),5) ":" SlotNumX
    Set SlotNumX     = *($(SlotNumX),3)
    Set-Sub SlotNumX = $(SlotNumX), 1

    IfStr(i) $(FullMemoryWindow) == 0
        Set-Sub FullMemoryWindow = 255, $(SlotNumX)
    EndIf

    IfStr(i) $(DLGEVENT) == "DLGBUTTON1"
        ui pop 1
        Set ReturnLabel = DoneAdvanced
        GoTo DoAdvancedDialog
DoneAdvanced =+
        GoTo RestartDialog
    EndIf

    IfStr(i) *($(CheckItemsOut), 1) == "ON"
        Set LinkTestEnabled = 1
    Else
        Set LinkTestEnabled = 0
    EndIf

    Set NewNetworkAddress = *($(EditTextOut), 1)

    IfStr(i) $(NewNetworkAddress) != ""
        Shell "" CheckHex $(NewNetworkAddress) 12
        IfStr(i) $($R0) == "FALSE"
            Shell "" DoWarningMessage $(InvalidNetAddress)
            IfStr(i) $($R0) == "CANCEL"
                Set DLGEVENT = "BACK"
                GoTo EndDialog
            Else
                GoTo RetryDialog
            EndIf
        EndIf

        Split-String $(NewNetworkAddress) $(AllHexDigits) List
        Set Id = *($(List), 2)
        IfContains(i) $(Id) Not-In { 2, 6, A, E }
            Shell "" DoWarningMessage $(InvalidNetAddress)
            IfStr(i) $($R0) == "CANCEL"
                Set DLGEVENT = "BACK"
                GoTo EndDialog
            Else
                GoTo RetryDialog
            EndIf
        EndIf
    EndIf
    Set NetworkAddress = $(NewNetworkAddress)

EndDialog =+
    ui pop 1

    IfStr(i) $(DLGEVENT) != "CONTINUE"
        FreeLibrary $(DialogResourceHandle)
        Return STATUS_USERCANCEL
    EndIf

    Split-String $(Combo1Out) " - " List
    Split-String *($(List),1) ":" BusNum
    Set BusNum = *($(BusNum),3)
    Split-String *($(List),5) ":" SlotNum
    Set SlotNum = *($(SlotNum),3)
    Split-String *($(List),9) ":" PortNum
    Set PortNum = *($(PortNum),3)
    Set MyLabel = " "*($(List),11)" "
    ifstr(i) $(MyLabel) == $(LblMca)
        Set MyBusType = $(MCA_BUS_TYPE)
    else
        Set MyBusType = $(PCI_BUS_TYPE)
    endif
    Set Socket = $(BusNum)","$(SlotNum)","$(PortNum)","$(MyBusType)

    FreeLibrary $(DialogResourceHandle)

    ifstr(i) $(MyBusType) == $(PCI_BUS_TYPE)
        Set-HexToDec BusNumDec  = "0x"$(BusNum)
        Set-HexToDec SlotNumDec = "0x"$(SlotNum)
        shell "" UpdateFlash $(FlashNumber) $(BusNumDec) $(SlotNumDec)
        set FlashNumber = $(FlashX)
    endif
        
    Shell "" DebugConfiguration "DoAdapterDialog After Processing Dialog"

    Read-Syms ReturnSetupParameters
    Return STATUS_SUCCESSFUL

;==================================================================
;==================================================================
; Perform Adapter Configuration Dialog for VNET Driver.
;
;
;
DoVnetDialog =+
;    Read-Syms FileDependentDlg$(!STF_LANGUAGE)
    Read-Syms DefaultVSlots

    Set LblSlot1 = $(!p:LblSlot1)
    Set LblSlot2 = $(!p:LblSlot2)
    Set LblSlot3 = $(!p:LblSlot3)
    Set LblSlot4 = $(!p:LblSlot4)
    Set LblSlot5 = $(!p:LblSlot5)
    Set LblSlot6 = $(!p:LblSlot6)
    Set LblSlot7 = $(!p:LblSlot7)
    Set LblSlot8 = $(!p:LblSlot8)

    Set SaveIsVnet = $(IsVnet)
    Set IsVnet   = 1


;;
;; SlotX = SlotNumber, BusNumber, BusType
;;
    Set-HexToDec SlotNumber1 = "0x"*($(VSlot1),5)
    Set-HexToDec SlotNumber2 = "0x"*($(VSlot2),5)
    Set-HexToDec SlotNumber3 = "0x"*($(VSlot3),5)
    Set-HexToDec SlotNumber4 = "0x"*($(VSlot4),5)
    Set-HexToDec SlotNumber5 = "0x"*($(VSlot5),5)
    Set-HexToDec SlotNumber6 = "0x"*($(VSlot6),5)
    Set-HexToDec SlotNumber7 = "0x"*($(VSlot7),5)
    Set-HexToDec SlotNumber8 = "0x"*($(VSlot8),5)
    Set-HexToDec BusNumber1  = "0x"*($(VSlot1),1)
    Set-HexToDec BusNumber2  = "0x"*($(VSlot2),1)
    Set-HexToDec BusNumber3  = "0x"*($(VSlot3),1)
    Set-HexToDec BusNumber4  = "0x"*($(VSlot4),1)
    Set-HexToDec BusNumber5  = "0x"*($(VSlot5),1)
    Set-HexToDec BusNumber6  = "0x"*($(VSlot6),1)
    Set-HexToDec BusNumber7  = "0x"*($(VSlot7),1)
    Set-HexToDec BusNumber8  = "0x"*($(VSlot8),1)
    Set Slot1 = {$(SlotNumber1), $(BusNumber1), *($(VSlot1),3)}
    Set Slot2 = {$(SlotNumber2), $(BusNumber2), *($(VSlot2),3)}
    Set Slot3 = {$(SlotNumber3), $(BusNumber3), *($(VSlot3),3)}
    Set Slot4 = {$(SlotNumber4), $(BusNumber4), *($(VSlot4),3)}
    Set Slot5 = {$(SlotNumber5), $(BusNumber5), *($(VSlot5),3)}
    Set Slot6 = {$(SlotNumber6), $(BusNumber6), *($(VSlot6),3)}
    Set Slot7 = {$(SlotNumber7), $(BusNumber7), *($(VSlot7),3)}
    Set Slot8 = {$(SlotNumber8), $(BusNumber8), *($(VSlot8),3)}
    Set VSlotList    = { $(Slot1), $(Slot2), $(Slot3), $(Slot4), $(Slot5), $(Slot6), $(Slot7), $(Slot8) }

    shell "" CheckSlotList $(SlotBusAvailable) $(VSlotList)
    Set Status = $($R0)
    ifstr(i) $(Status) == "STATUS_FAILED"
        set IsVnet = $(SaveIsVnet)
        return STATUS_FAILED
    endif

    shell "" CreateSlotList $(SlotBusAvailable) $(VSlotList)
    Set NewSlotList = $(TempSlotList)
    shell "" CreateBoldCheck $(SlotBusAvailable) $(NewSlotList)

    Set CheckItemsIn = {}
    Set Index        = 1

    ForListDo $(CheckList)
        Set CheckEntry = *($($),1)
CheckLoop   =+
        IfInt $(CheckEntry) > $(Index)
            Set CheckItemsIn = >($(CheckItemsIn), OFF)
            Set-Add Index    = $(Index), 1
            GoTo CheckLoop
        Else
            Set CheckItemsIn = >($(CheckItemsIn), ON)
        EndIf
        Set-Add Index = $(Index), 1
    EndForListDo

AddCheck    =+
    IfInt $(Index) < 9
        Set CheckItemsIn = >($(CheckItemsIn), OFF)
        Set-Add Index = $(Index), 1
        GoTo AddCheck
    EndIf

    Set Index = 1
    Set CBOptionsGreyed = {}

    ForListDo $(BoldList)
        Set BoldEntry = *($($),1)
CheckGrey   =+
        IfInt $(BoldEntry) > $(Index)
            Set CBOptionsGreyed = >($(CBOptionsGreyed), $(Index))
            Set-Add Index       = $(Index), 1
            GoTo CheckGrey
        EndIf
        Set-Add Index = $(Index), 1
    EndForListDo

AddGrey    =+
    IfInt $(Index) < 9
        Set CBOptionsGreyed = >($(CBOptionsGreyed), $(Index))
        Set-Add Index = $(Index), 1
        GoTo AddGrey
    EndIf

        
    EndWait

MainVnetDialog =+
    Set EditFocusOn = ""

    Set VNetworkAddress    = $(NetworkAddress)
    Set VNewNetworkAddress = $(VNetworkAddress)
    Set CheckItemsSave2    = $(CheckItemsIn)
    Set CBOptionsSave      = $(CBOptionsGreyed)

RestartVnetDialog =+
    Set ReInit = "YES"

RetryVnetDialog =+
;    Read-Syms FileDependentDlg$(!STF_LANGUAGE)
    Set DlgTemplate     = $(DlgTemplateVnet)
    Set HelpContext     = $(HelpContextVnet)
    Set EditTextIn      = {$(VNewNetworkAddress)}
    Set EditTextLim     = { 12 }
    Set CheckItemsIn    = $(CheckItemsSave2)
    Set CBOptionsGreyed = $(CBOptionsSave)

    ui start "InputDlg" $(DialogResourceHandle)

    Set CheckItemsSave2    = $(CheckItemsOut)
    Set CBOptionsSave      = $(CBOptionsSave)
    Set VNewNetworkAddress = *($(EditTextOut),1)
    StartWait

    Set ReInit = "NO"

    Debug-Output "QuadEnet.Inf:  MainDlg, DLGEVENT = "$(DLGEVENT)

    IfStr(i) $(DLGEVENT) == "BACK"
        IfStr(i) $(!p:Mode) == INSTALL
            Set IsVnet = $(SaveIsVnet)
            ui pop 1
            GoTo RestartDialog
        Else
            GoTo EndVnetDialog
        EndIf
    EndIf

    IfStr(i) $(DLGEVENT) == "DLGBUTTON1"
        ui pop 1
        Set ReturnLabel = DoneAdvanced1
        GoTo DoAdvancedVnetDialog
DoneAdvanced1 =+
        GoTo RestartVnetDialog
    EndIf

    Set CheckItemsSave = $(CheckItemsOut)

    Set VNewNetworkAddress = *($(EditTextOut), 1)

    IfStr(i) $(VNewNetworkAddress) != ""
        Shell "" CheckHex $(VNewNetworkAddress) 12
        IfStr(i) $($R0) == "FALSE"
            Shell "" DoWarningMessage $(InvalidNetAddress)
            IfStr(i) $($R0) == "CANCEL"
                Set DLGEVENT = "BACK"
                Set IsVnet = $(SaveIsVnet)
                GoTo EndDialog
            Else
                GoTo RetryVnetDialog
            EndIf
        EndIf

        Split-String $(VNewNetworkAddress) $(AllHexDigits) List
        Set Id = *($(List), 2)
        IfContains(i) $(Id) Not-In { 2, 6, A, E }
            Shell "" DoWarningMessage $(InvalidNetAddress)
            IfStr(i) $($R0) == "CANCEL"
                Set DLGEVENT = "BACK"
                GoTo EndVnetDialog
            Else
                GoTo RetryVnetDialog
            EndIf
        EndIf
    EndIf

    Set CheckList = {}
    Set Index = 1
CheckListLoop =+
    IfStr(i) *($(CheckItemsOut), $(Index)) == "ON"
        Set CheckList = >($(CheckList),$(Index))
    EndIf
    Set-Add Index = $(Index),1
    IfInt $(Index) < 9
        GoTo CheckListLoop
    EndIf

    shell "" FixSlotList $(NewSlotList) $(CheckList)

;;
;; VTemp includes the slot, bus number, bus type, ports 1-4 and VSlotIndex
;;
    Set VTemp1 = "255,0,0,0,0,0,0,0"
    Set VTemp2 = "255,0,0,0,0,0,0,0"
    Set VTemp3 = "255,0,0,0,0,0,0,0"
    Set VTemp4 = "255,0,0,0,0,0,0,0"
    Set VTemp5 = "255,0,0,0,0,0,0,0"
    Set VTemp6 = "255,0,0,0,0,0,0,0"
    Set VTemp7 = "255,0,0,0,0,0,0,0"
    Set VTemp8 = "255,0,0,0,0,0,0,0"

    Set FoundOne  = FALSE
    Set Index     = 1
    ForListDo $(CheckList)
        Set OldIndex = *($($),1)
        Set SlotEntry  = *($(CheckedSlotList), $(Index))
        Set SlotNumber = *($(SlotEntry),1)
        Set BusNumber  = *($(SlotEntry),2)
        Set BusType    = *($(SlotEntry),3)
        Set SlotIndex  = *($(SlotEntry),4)
        Set Valid      = *($(SlotEntry),5)
        IfStr(i) $(Valid) == 1
            Read-Syms ReadVSlot$(SlotIndex)
            Set Port1 = *($(ValueList),9)
            Set Port2 = *($(ValueList),11)
            Set Port3 = *($(ValueList),13)
            Set Port4 = *($(ValueList),15)
        Else
            Set Port1 = 0
            Set Port2 = 0
            Set Port3 = 0
            Set Port4 = 0
        EndIf

        Set VTempX = $(SlotNumber)","$(BusNumber)","$(BusType)","$(Port1)","$(Port2)","$(Port3)","$(Port4)","$(SlotIndex)
        Read-Syms SetTemp$(SlotIndex)
        Read-Syms SetLabel$(SlotIndex)
        Set FoundOne  = TRUE
        Set-Add Index = $(Index),1
    EndForListDo

    IfStr(i) $(FoundOne) == FALSE
        Shell "" DoWarningMessage $(AtLeastOneSlot)
        IfStr(i) $($R0) == "CANCEL"
            Set DLGEVENT = "BACK"
            GoTo EndVnetDialog
        EndIf
        GoTo RetryVnetDialog
    EndIf

    Split-String $(VTemp1) "," VTemp1
    Split-String $(VTemp2) "," VTemp2
    Split-String $(VTemp3) "," VTemp3
    Split-String $(VTemp4) "," VTemp4
    Split-String $(VTemp5) "," VTemp5
    Split-String $(VTemp6) "," VTemp6
    Split-String $(VTemp7) "," VTemp7
    Split-String $(VTemp8) "," VTemp8

    ui pop 1

    IfStr(i) *($(VTemp1),15) != 0
        Set VTempX       = $(VTemp1)
        Set LabelIndex   = $(LabelIndex1)
        Set ReturnLabel  = VnetNext1
        GoTo VnetSlotDialog
    Else
        Split-String $(VSlotX1) "," VSlot1
    EndIf

VnetNext1 =+
    IfStr(i) *($(VTemp2),15) != 0
        Set VTempX       = $(VTemp2)
        Set LabelIndex   = $(LabelIndex2)
        Set ReturnLabel  = VnetNext2
        GoTo VnetSlotDialog
    Else
        Split-String $(VSlotX2) "," VSlot2
    EndIf

VnetNext2 =+
    IfStr(i) *($(VTemp3),15) != 0
        Set VTempX       = $(VTemp3)
        Set LabelIndex   = $(LabelIndex3)
        Set ReturnLabel  = VnetNext3
        GoTo VnetSlotDialog
    Else
        Split-String $(VSlotX3) "," VSlot3
    EndIf

VnetNext3 =+
    IfStr(i) *($(VTemp4),15) != 0
        Set VTempX       = $(VTemp4)
        Set LabelIndex   = $(LabelIndex4)
        Set ReturnLabel  = VnetNext4
        GoTo VnetSlotDialog
    Else
        Split-String $(VSlotX4) "," VSlot4
    EndIf

VnetNext4 =+
    IfStr(i) *($(VTemp5),15) != 0
        Set VTempX       = $(VTemp5)
        Set LabelIndex   = $(LabelIndex5)
        Set ReturnLabel  = VnetNext5
        GoTo VnetSlotDialog
    Else
        Split-String $(VSlotX5) "," VSlot5
    EndIf

VnetNext5 =+
    IfStr(i) *($(VTemp6),15) != 0
        Set VTempX       = $(VTemp6)
        Set LabelIndex   = $(LabelIndex6)
        Set ReturnLabel  = VnetNext6
        GoTo VnetSlotDialog
    Else
        Split-String $(VSlotX6) "," VSlot6
    EndIf

VnetNext6 =+
    IfStr(i) *($(VTemp7),15) != 0
        Set VTempX       = $(VTemp7)
        Set LabelIndex   = $(LabelIndex7)
        Set ReturnLabel  = VnetNext7
        GoTo VnetSlotDialog
    Else
        Split-String $(VSlotX7) "," VSlot7
    EndIf

VnetNext7 =+
    IfStr(i) *($(VTemp8),15) != 0
        Set VTempX       = $(VTemp8)
        Set LabelIndex   = $(LabelIndex8)
        Set ReturnLabel  = VnetNext8
        GoTo VnetSlotDialog
    Else
        Split-String $(VSlotX8) "," VSlot8
    EndIf

VnetNext8 =+
    Set VNetworkAddress = $(VNewNetworkAddress)
    Set NetworkAddress = $(VNetworkAddress)

EndVnetDialog =+
    ui pop 1

    IfStr(i) $(DLGEVENT) != "CONTINUE"
        FreeLibrary $(DialogResourceHandle)
        Set IsVnet = $(SaveIsVnet)
        Return STATUS_USERCANCEL
    EndIf

    FreeLibrary $(DialogResourceHandle)
    Shell "" DebugConfiguration "DoAdapterDialog After Processing Dialog"

    Read-Syms ReturnSetupParameters
    Return STATUS_SUCCESSFUL

;==================================================================
;==================================================================
;  Do Vnet Slot Dialog.
;
;
VnetSlotDialog =+
    Read-Syms PortDescription$(LabelIndex)

    Set VSlotIndex  = *($(VTempX),15)
    Set SlotNumber = *($(VTempX),1)
    Set List = { *($(VTempX), 7), *($(VTempX), 9), *($(VTempX), 11), *($(VTempX), 13) }
    Set CheckItemsIn = {}
    Set Index = 1

Loop1 =+
    IfInt *($(List),$(Index)) == 1
        Set CheckItemsIn = >($(CheckItemsIn), ON)
    Else
        Set CheckItemsIn = >($(CheckItemsIn), OFF)
    EndIf
    Set-Add Index = $(Index), 1
    IfInt $(Index) < 5
        GoTo Loop1
    EndIf

RestartSlotDialog =+
    Read-Syms ReadVSlot$(VSlotIndex)
    Set DlgTemplate  = $(DlgTemplateVnet1)
    Set HelpContext  = $(HelpContextVnet1)
    Set CBOptionsGreyed = {}
    ui start "InputDlg" $(DialogResourceHandle)

    Set ReInit = "NO"

    IfStr(i) $(DLGEVENT) == BACK
        ui pop 1
        GoTo RestartVnetDialog
    EndIf
    IfContains(i) "ON" Not-In $(CheckItemsOut)
        Shell "" DoWarningMessage $(AtLeastOnePort)
        IfStr(i) $($R0) == "CANCEL"
            GoTo RestartSlotDialog
        EndIf
        GoTo RestartSlotDialog
    EndIf
    ui pop 1

    Set SlotNumber        = *($(VTempX),1)
    Set BusNumber         = *($(VTempX),3)
    Set BusType           = *($(VTempX),5)
    Set Port1             = *($(VTempX),7)
    Set Port2             = *($(VTempX),9)
    Set Port3             = *($(VTempX),11)
    Set Port4             = *($(VTempX),13)
    Set FullMemoryWindow  = *($(ValueList),7)
    Set LT1               = *($(ValueList),17)
    Set LT2               = *($(ValueList),19)
    Set LT3               = *($(ValueList),21)
    Set LT4               = *($(ValueList),23)
    Set FlashV            = *($(ValueList),25)
    ifstr(i) $(FlashV) == F
        Set FlashV = 15
    endif

    ifstr(i) $(BusType) == $(PCI_BUS_TYPE)
        Set SlotNum = $(SlotNumber)
        Set BusNum  = $(BusNumber)

    endif

    Set BusNumDec     = $(BusNumber)
    Set-DecToHex Temp = $(BusNumber)
    Split-String $(Temp) "Xx" TempList
    Set BusNumber = *($(TempList),3)
    Split-String  $(BusNumber) $(AllHexDigits) TempList
    QueryListSize TempSize $(TempList)
    IfInt $(TempSize) == 1
        Set BusNumber = "0"$(BusNumber)
    EndIf

    IfStr(i) $(FullMemoryWindow) == 00
        Set-Sub SlotNumX           = $(SlotNumber), 1
        Set-Sub FullMemoryWindow   = 255, $(SlotNumX)
        Set-DecToHex FullMemX      = $(FullMemoryWindow)
        Split-String $(FullMemX) "Xx" FullMemList
        Set FullMemoryWindow       = *($(FullMemList),3)
    EndIf

    Set SlotNumDec    = $(SlotNumber)
    Set-DecToHex Temp = $(SlotNumber)
    Split-String $(Temp) "Xx" TempList
    Set SlotNumber = *($(TempList),3)
    Split-String  $(SlotNumber) $(AllHexDigits) TempList
    QueryListSize TempSize $(TempList)
    IfInt $(TempSize) == 1
        Set SlotNumber = "0"$(SlotNumber)
    EndIf

    IfStr(i) $(DLGEVENT) == DLGBUTTON1
        Set CheckItemsSave  = $(CheckItemsOut)
        Set DlgTemplate     = $(DlgTemplateVnet3)
        Set HelpContext     = $(HelpContextVnet3)
        Set CBOptionsGreyed = {}

        Set-HexToDec Combo1Out = "0x"$(FullMemoryWindow)

        Set Combo1List = {}
        Set FullMemoryList  = 255
FullMemSet2 =+
        set Combo1List = >($(Combo1List), $(FullMemoryList))
        Set-Sub FullMemoryList = $(FullMemoryList), 1
        IfInt $(FullMemoryList) > 1
            GoTo FullMemSet2
        EndIf

        Set ListItemsIn  = {Combo1List}
        Set ListItemsOut = {Combo1Out}

        Set ComboListItemsIn  = $(ListItemsIn)
        Set ComboListItemsOut = $(ListItemsOut)

        Set CheckItemsIn = {}

        IfStr(i) $(LT1)  == "0"
            Set CheckItemsIn = >($(CheckItemsIn), OFF)
        Else
            Set CheckItemsIn = >($(CheckItemsIn), ON)
        EndIf

        IfStr(i) $(LT2)  == "0"
            Set CheckItemsIn = >($(CheckItemsIn), OFF)
        Else
            Set CheckItemsIn = >($(CheckItemsIn), ON)
        EndIf

        IfStr(i) $(LT3)  == "0"
            Set CheckItemsIn = >($(CheckItemsIn), OFF)
        Else
            Set CheckItemsIn = >($(CheckItemsIn), ON)
        EndIf

        IfStr(i) $(LT4)  == "0"
            Set CheckItemsIn = >($(CheckItemsIn), OFF)
        Else
            Set CheckItemsIn = >($(CheckItemsIn), ON)
        EndIf

        ui start "InputDlg" $(DialogResourceHandle)

        ui pop 1

        IfStr(i) $(DLGEVENT) == BACK
            GoTo EndVnetSlotDialog
        EndIf

        Set-DecToHex TempString = $(Combo1Out)
        Split-String $(TempString) "Xx" TempList
        Set FullMemoryWindow    = *($(TempList),3)

        Set VList = $(BusNumber)","$(BusType)","$(SlotNumber)","$(FullMemoryWindow)

        Set Index = 1
SetPortList =+
        IfStr(i) *($(CheckItemsSave), $(Index)) == "ON"
            Set VList = $(VList)",1"
        Else
            Set VList = $(VList)",0"
        EndIf
        Set-Add Index = $(Index), 1
        IfInt $(Index) < 5
            GoTo SetPortList
        EndIf


        Set Index = 1
SetLT =+
        IfStr(i) *($(CheckItemsOut), $(Index)) == "ON"
            Set VList = $(VList)",1"
        Else
            Set VList = $(VList)",0"
        EndIf
        Set-Add Index = $(Index), 1
        IfInt $(Index) < 5
            GoTo SetLT
        EndIf

        ifstr(i) $(BusType) == $(PCI_BUS_TYPE)
            shell "" UpdateFlash $(FlashV) $(BusNumDec) $(SlotNumDec)
            set FlashV = $(FlashX)
        endif

        ifstr(i) $(FlashV) == 15
            set FlashV = F
        endif
        Set VList = $(VList)","$(FlashV)

        Split-String $(VList) "," ValueList
        Read-Syms WriteVSlot$(VSlotIndex)

EndVnetSlotDialog =+
        Set CheckItemsIn = $(CheckItemsSave)
        Set ReInit = "YES"
        GoTo RestartSlotDialog
    EndIf

    IfStr(i) *($(CheckItemsOut), 1) == "ON"
        Set Port1 = 1
    Else
        Set Port1 = 0
    EndIf

    IfStr(i) *($(CheckItemsOut), 2) == "ON"
        Set Port2 = 1
    Else
        Set Port2 = 0
    EndIf

    IfStr(i) *($(CheckItemsOut), 3) == "ON"
        Set Port3 = 1
    Else
        Set Port3 = 0
    EndIf

    IfStr(i) *($(CheckItemsOut), 4) == "ON"
        Set Port4 = 1
    Else
        Set Port4 = 0
    EndIf

    ifstr(i) $(BusType) == $(PCI_BUS_TYPE)
        shell "" UpdateFlash $(FlashV) $(BusNumDec) $(SlotNumDec)
        set FlashV = $(FlashX)
    endif

    ifstr(i) $(FlashV) == 15
        set FlashV = F
    endif

    Set VList = $(BusNumber)","$(BusType)","$(SlotNumber)","$(FullMemoryWindow)
    Set VList = $(VList)","$(Port1)","$(Port2)","$(Port3)","$(Port4)
    Set VList = $(VList)","$(LT1)","$(LT2)","$(LT3)","$(LT4)","$(FlashV)
    Split-String $(VList) "," ValueList
    Read-Syms WriteVSlot$(VSlotIndex)

    GoTo $(ReturnLabel)

;==================================================================
;==================================================================
; Do Advanced Dialog.
;
;
DoAdvancedDialog =+
    Set DlgTemplate  = $(DlgTemplateAdvanced)
    Set HelpContext  = $(HelpContextAdvanced)

    Set EditTextIn   = {$(WatchDogTimer)}
    Set EditTextLim  = { 5 }
    Set ReInit       = YES

RetryAdvanced =+
    Set Combo2Out    = $(FullMemoryWindow)
    ui  start "InputDlg" $(DialogResourceHandle)
    Set ReInit = NO

    IfStr(i) $(DLGEVENT) == "BACK"
        ui  pop 1
        GoTo RestartDialog
    EndIf

    Set NewWatchDogTimer  = *($(EditTextOut), 1)

    Shell "" CheckDecimalParameter $(NewWatchDogTimer) +
                                   0                   +
                                   $(WatchDogMin)      +
                                   $(WatchDogMax)      +
                                   $(InvalidWatchDog)

    IfStr(i) $($R0) == "FALSE"
        IfStr(i) $($R1) != "OK"
            ui pop  1
            GoTo RestartDialog
        Else
            GoTo RetryAdvanced
        EndIf
    EndIf
EndAdvanced =+
    ui pop 1
    Set WatchDogTimer    = $(NewWatchDogTimer)
    Set FullMemoryWindow = $(Combo2Out)
    GoTo $(ReturnLabel)

;==================================================================
;==================================================================
; Do Advanced VNET Dialog.
;
;
DoAdvancedVnetDialog =+
    Set DlgTemplate  = $(DlgTemplateVnet2)
    Set HelpContext  = $(HelpContextVnet2)

    Set EditTextIn   = {$(WatchDogTimer), $(BridgeAgeTimer)}
    Set EditTextLim  = { 5, 5 }
    Set ReInit       = YES

RetryVnetAdvanced =+
    ui  start "InputDlg" $(DialogResourceHandle)
    Set ReInit = NO

    IfStr(i) $(DLGEVENT) == "BACK"
        ui  pop 1
        GoTo RestartVnetDialog
    EndIf

    Set NewWatchDogTimer  = *($(EditTextOut), 1)
    Set NewBridgeAgeTimer = *($(EditTextOut), 2)

    Shell "" CheckDecimalParameter $(NewWatchDogTimer) +
                                   0                   +
                                   $(WatchDogMin)      +
                                   $(WatchDogMax)      +
                                   $(InvalidWatchDog)

    IfStr(i) $($R0) == "FALSE"
        IfStr(i) $($R1) != "OK"
            ui pop  1
            GoTo RestartVnetDialog
        Else
            GoTo RetryVnetAdvanced
        EndIf
    EndIf

    Shell "" CheckDecimalParameter $(NewBridgeAgeTimer) +
                                   0                    +
                                   $(BridgeAgeMin)      +
                                   $(BridgeAgeMax)      +
                                   $(InvalidBridgeAge)

    IfStr(i) $($R0) == "FALSE"
        IfStr(i) $($R1) != "OK"
            ui pop  1
            GoTo RestartVnetDialog
        Else
            GoTo RetryVnetAdvanced
        EndIf
    EndIf
EndAdvancedVnet =+
    ui pop 1
    Set WatchDogTimer    = $(NewWatchDogTimer)
    Set BridgeAgeTimer   = $(NewBridgeAgeTimer)
    GoTo $(ReturnLabel)

;==================================================================
;==================================================================
; Set up and Execute Copy.
;
;  $($0)    DoCopy             [YES|NO]
;  $($1)    AddCopy            [YES|NO]
;  $($2)    SrcDir             Source files location
;  $($3)    InstallSection     Name of section to execute.
;
;
[SetCopy]
    read-syms GeneralConstants
    read-syms FileConstants
    read-syms FileConstants$(!STF_LANGUAGE)

    set DoCopy         = $($0)
    set AddCopy        = $($1)
    set SrcDir         = $($2)
    set InstallSection = $($3)
    set Needcopy       = $(FALSE)

    Ifstr(i) $(DoCopy) == "YES"
        set NeedCopy = $(TRUE)
    Else-IfStr(i) $(AddCopy) == "YES"
        set NeedCopy = $(TRUE)
    Else
    EndIf

    set BuiltIn = "YES"
    IfStr(i) $(!NTN_Origination) == "NCPA"
        set BuiltIn = "NO"
    EndIf

    Shell $(UtilityInf), DoAskSource, $(!STF_CWDDIR), $(SrcDir) $(BuiltIn)

    Ifstr(i) $($R0) == STATUS_FAILED
        Shell $(UtilityInf) RegistryErrorString "ASK_SOURCE_FAIL"
        Shell "" FatalError $($R0)
        Return $(FALSE)
    Else-Ifstr(i) $($R0) == STATUS_USERCANCEL
        Return $(FALSE)
    EndIf

    Set SrcDir = $($R1)

    install $(InstallSection)

    IfStr(i) $(STF_INSTALL_OUTCOME) != STF_SUCCESS
        Shell $(UtilityInf) RegistryErrorString "UNABLE_COPY_FILE"
        Shell "" FatalError $($R0)
        Return $(FALSE)
    EndIf

    Return $(TRUE)


;==================================================================
;==================================================================
; Detect Current Date.
;
[CurrentDate]
    Now = {} ? $(!LIBHANDLE) GetSystemDate

;==================================================================
;==================================================================
; Install products for PCI installation.
;
[Install-Pci]
    Set STF_VITAL = ""

    IfStr(i) $(AddCopy) == "YES"
        AddSectionFilesToCopyList Files-PciDrvr $(SrcDir) $(!STF_WINDOWSSYSPATH)\drivers
        AddSectionFilesToCopyList Files-PciDll $(SrcDir) $(!STF_WINDOWSSYSPATH)
     EndIf

    IfStr(i) $(DoCopy) == "YES"
       Set !STF_NCPA_FLUSH_COPYLIST = TRUE
       CopyFilesInCopyList
    else
        LibraryProcedure STATUS,$(!LIBHANDLE), CopySingleFile $(SrcDir)\quadenet.dll $(!STF_WINDOWSSYSPATH)\quadenet.dll
    EndIf

    Exit

;==================================================================
;==================================================================
; Full Product Installation.
;
[Install-Option]
    Set STF_VITAL = ""

    IfStr(i) $(AddCopy) == "YES"
        AddSectionFilesToCopyList Files-Drvr $(SrcDir) $(!STF_WINDOWSSYSPATH)\drivers
        AddSectionFilesToCopyList Files-Dll $(SrcDir) $(!STF_WINDOWSSYSPATH)
        AddSectionFilesToCopyList Files-NcDet $(SrcDir) $(!STF_WINDOWSSYSPATH)
        AddSectionFilesToCopyList Files-Stats $(SrcDir) $(!STF_WINDOWSSYSPATH)
     EndIf

    IfStr(i) $(DoCopy) == "YES"
       Set !STF_NCPA_FLUSH_COPYLIST = TRUE
       CopyFilesInCopyList
    else
        LibraryProcedure STATUS,$(!LIBHANDLE), CopySingleFile $(SrcDir)\quadenet.dll $(!STF_WINDOWSSYSPATH)\quadenet.dll
        LibraryProcedure STATUS,$(!LIBHANDLE), CopySingleFile $(SrcDir)\quadenet.hlp $(!STF_WINDOWSSYSPATH)\quadenet.hlp
        LibraryProcedure STATUS,$(!LIBHANDLE), CopySingleFile $(SrcDir)\qdncdet.dll $(!STF_WINDOWSSYSPATH)\qdncdet.dll
    EndIf

    Exit

;==================================================================
;==================================================================
; Install Updated Source Files.
;
[Install-Update]
   Set STF_VITAL        = ""
   Set STF_OVERWRITE    = "VERIFYSOURCEOLDER"

   AddSectionFilesToCopyList Files-Drvr $(SrcDir) $(!STF_WINDOWSSYSPATH)\drivers
   AddSectionFilesToCopyList Files-Dll $(SrcDir) $(!STF_WINDOWSSYSPATH)
   AddSectionFilesToCopyList Files-NcDet $(SrcDir) $(!STF_WINDOWSSYSPATH)
   AddSectionFilesToCopyList Files-Stats $(SrcDir) $(!STF_WINDOWSSYSPATH)

   set !STF_NCPA_FLUSH_COPYLIST = TRUE
   CopyFilesInCopyList

   Exit

;==================================================================
;==================================================================
; Display Registry Interface Error Message.
;
; $($0)  = Error Index.
;
[DoRegistryErrorMessage]
    Read-Syms FileConstants

    Shell $(UtilityInf) RegistryErrorString $($0)

    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        Shell "" DoShellErrorMessage "Utility.Inf, RegistryErrorString"
    Else
        Shell "" DoShellErrorMessage $($R0)
    EndIf

    Return STATUS_FAILED

;==================================================================
;==================================================================
; Write MAC Adapter-Specific Parameters.
;
[WriteAdapterParameters]
    Read-Syms FileConstants
    Read-Syms RegistryConstants
    Read-Syms GeneralConstants
    Read-Syms CardType

    Read-Syms ReadSetupParameters

    Split-String $(Socket) "," List
    Set BusNumber        =  *($(List), 1)
    Set SlotNumber       =  *($(List), 3)
    Set PortNumber       =  *($(List), 5)
    Set BusTypeInterface =  *($(List), 7)

    Set-HexToDec TOnTimer       = $(TOnTimer)
    Set-HexToDec TOffTimer      = $(TOffTimer)
    Set-HexToDec FifoThreshold  = $(FifoThreshold)
    Set-HexToDec MaxRetries     = $(MaxRetries)
    Set-HexToDec PollLoopPasses = $(PollLoopPasses)

    Set VSlot1 = *($(VSlot1),1)*($(VSlot1),3)*($(VSlot1),5)*($(VSlot1),7)*($(VSlot1),9)*($(VSlot1),11)*($(VSlot1),13)*($(VSlot1),15)*($(VSlot1),17)*($(VSlot1),19)*($(VSlot1),21)*($(VSlot1),23)*($(VSlot1),25)*($(VSlot1),27)
    Set VSlot2 = *($(VSlot2),1)*($(VSlot2),3)*($(VSlot2),5)*($(VSlot2),7)*($(VSlot2),9)*($(VSlot2),11)*($(VSlot2),13)*($(VSlot2),15)*($(VSlot2),17)*($(VSlot2),19)*($(VSlot2),21)*($(VSlot2),23)*($(VSlot2),25)*($(VSlot2),27)
    Set VSlot3 = *($(VSlot3),1)*($(VSlot3),3)*($(VSlot3),5)*($(VSlot3),7)*($(VSlot3),9)*($(VSlot3),11)*($(VSlot3),13)*($(VSlot3),15)*($(VSlot3),17)*($(VSlot3),19)*($(VSlot3),21)*($(VSlot3),23)*($(VSlot3),25)*($(VSlot3),27)
    Set VSlot4 = *($(VSlot4),1)*($(VSlot4),3)*($(VSlot4),5)*($(VSlot4),7)*($(VSlot4),9)*($(VSlot4),11)*($(VSlot4),13)*($(VSlot4),15)*($(VSlot4),17)*($(VSlot4),19)*($(VSlot4),21)*($(VSlot4),23)*($(VSlot4),25)*($(VSlot4),27)
    Set VSlot5 = *($(VSlot5),1)*($(VSlot5),3)*($(VSlot5),5)*($(VSlot5),7)*($(VSlot5),9)*($(VSlot5),11)*($(VSlot5),13)*($(VSlot5),15)*($(VSlot5),17)*($(VSlot5),19)*($(VSlot5),21)*($(VSlot5),23)*($(VSlot5),25)*($(VSlot5),27)
    Set VSlot6 = *($(VSlot6),1)*($(VSlot6),3)*($(VSlot6),5)*($(VSlot6),7)*($(VSlot6),9)*($(VSlot6),11)*($(VSlot6),13)*($(VSlot6),15)*($(VSlot6),17)*($(VSlot6),19)*($(VSlot6),21)*($(VSlot6),23)*($(VSlot6),25)*($(VSlot6),27)
    Set VSlot7 = *($(VSlot7),1)*($(VSlot7),3)*($(VSlot7),5)*($(VSlot7),7)*($(VSlot7),9)*($(VSlot7),11)*($(VSlot7),13)*($(VSlot7),15)*($(VSlot7),17)*($(VSlot7),19)*($(VSlot7),21)*($(VSlot7),23)*($(VSlot7),25)*($(VSlot7),27)
    Set VSlot8 = *($(VSlot8),1)*($(VSlot8),3)*($(VSlot8),5)*($(VSlot8),7)*($(VSlot8),9)*($(VSlot8),11)*($(VSlot8),13)*($(VSlot8),15)*($(VSlot8),17)*($(VSlot8),19)*($(VSlot8),21)*($(VSlot8),23)*($(VSlot8),25)*($(VSlot8),27)

    Shell "" DebugConfiguration "WriteAdapterParameters Before Writing Registry"

    Set NewValueList = {{BusType,$(NoTitle),$(!REG_VT_DWORD),$(BusTypeInterface)},+
                        {BusNumber,$(NoTitle),$(!REG_VT_DWORD),$(BusNumber)},+
                        {MediaType,$(NoTitle),$(!REG_VT_DWORD),$(MediaType)},+
                        {SlotNumber,$(NoTitle),$(!REG_VT_DWORD),$(SlotNumber)},+
                        {NetworkAddress,$(NoTitle),$(!REG_VT_SZ),$(NetworkAddress)},+
                        {DownLoadFileBt,$(NoTitle),$(!REG_VT_SZ),$(DownLoadFileBt)},+
                        {DownLoadFileTn,$(NoTitle),$(!REG_VT_SZ),$(DownLoadFileTn)},+
                        {DownLoadFilePci,$(NoTitle),$(!REG_VT_SZ),$(DownLoadFilePci)},+
                        {TOnTimer,$(NoTitle),$(!REG_VT_DWORD),$(TOnTimer)},+
                        {TOffTimer,$(NoTitle),$(!REG_VT_DWORD),$(TOffTimer)},+
                        {FifoThreshold,$(NoTitle),$(!REG_VT_DWORD),$(FifoThreshold)},+
                        {MaxRetries,$(NoTitle),$(!REG_VT_DWORD),$(MaxRetries)},+
                        {LinkTestEnabled,$(NoTitle),$(!REG_VT_DWORD),$(LinkTestEnabled)},+
                        {WatchDogTimer,$(NoTitle),$(!REG_VT_DWORD),$(WatchDogTimer)},+
                        {BridgeAgeTimer,$(NoTitle),$(!REG_VT_DWORD),$(BridgeAgeTimer)},+
                        {PollLoopPasses,$(NoTitle),$(!REG_VT_DWORD),$(PollLoopPasses)},+
                        {FullMemoryWindow,$(NoTitle),$(!REG_VT_DWORD),$(FullMemoryWindow)},+
                        {PortNumber,$(NoTitle),$(!REG_VT_DWORD),$(PortNumber)},+
                        {FlashNumber,$(NoTitle),$(!REG_VT_DWORD),$(FlashNumber)},+
                        {IsVnet,$(NoTitle),$(!REG_VT_DWORD),$(IsVnet)},+
                        {VSlot1,$(NoTitle),$(!REG_VT_SZ),$(VSlot1)},+
                        {VSlot2,$(NoTitle),$(!REG_VT_SZ),$(VSlot2)},+
                        {VSlot3,$(NoTitle),$(!REG_VT_SZ),$(VSlot3)},+
                        {VSlot4,$(NoTitle),$(!REG_VT_SZ),$(VSlot4)},+
                        {VSlot5,$(NoTitle),$(!REG_VT_SZ),$(VSlot5)},+
                        {VSlot6,$(NoTitle),$(!REG_VT_SZ),$(VSlot6)},+
                        {VSlot7,$(NoTitle),$(!REG_VT_SZ),$(VSlot7)},+
                        {VSlot8,$(NoTitle),$(!REG_VT_SZ),$(VSlot8)}}


    Shell  $(UtilityInf) AddValueList $(!p:KeyParameters) $(NewValueList)

    IfStr(i) $(!STF_GUI_UNATTENDED) == "YES"
        Shell $(UtilityInf) AddDefaultNetCardParameters $(!p:KeyParameters)
    EndIf

    CloseRegKey $(!p:KeyParameters)

    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        Shell "" DoShellErrorMessage "CloseRegKey"
        Return STATUS_FAILED
    EndIf

    IfStr(i) $($R0) != NO_ERROR
        Shell "" DoRegistryErrorMessage $($R0)
        Return STATUS_FAILED
    EndIf

    Shell "" UpdateGlobalParams       +
        $(BusNumber)                  +
        $(SlotNumber)                 +
        $(ProductHardwareDescription) +
        $(ProductHardwareName)

    Return STATUS_SUCCESS

;==================================================================
;==================================================================
; Add required component keys to Registry.
;
; $($0) = OldVersionExisted  TRUE|FALSE
;
[AddComponents]
    Read-Syms RegistryConstants
    Read-Syms FileConstants
    Read-Syms GeneralConstants

    Detect CurrentDate

    Set OldVersionExisted = $($0)

    IfStr(i) $(OldVersionExisted) == FALSE
        Shell $(UtilityInf) AddSoftwareComponent $(Manufacturer) +
            $(ProductSoftwareName) +
            $(ProductSoftwareName) +
            $(ProductSoftwareTitle) $(STF_CONTEXTINFNAME) +
            $(ProductSoftwareImagePath) "kernel" "NDIS" {} "" +
            $(NetEventDLL)

        IfInt $($ShellCode) != $(!SHELL_CODE_OK)
            Shell "" DoShellErrorMessage "Utility.Inf, AddSoftwareComponent"
            Return STATUS_FAILED
        EndIf

        ;;
        ;;   At this point:
        ;;     $R1 contains the product version key handle;
        ;;     $R2 contains the NetRules subkey handle;
        ;;     $R3 contains the new Services key handle; and
        ;;     $R4 contains the Parameters key
        ;;     $R5 contains the Linkage Key
        ;;
        Set RegistryErrorIndex = $($R0)
        Set KeyProduct         = $($R1)
        Set SoftNetRulesKey    = $($R2)

        CloseRegKey $($R3)
        CloseRegKey $($R4)
        CloseRegKey $($R5)

        IfStr(i) $(RegistryErrorIndex) != NO_ERROR
            EndWait
            CloseRegKey $(KeyProduct)
            CloseRegKey $(SoftNetRulesKey)
            Shell "" DoRegistryErrorMessage $(RegistryErrorIndex)
            Return STATUS_FAILED
        EndIf

        Set NewValueList = {{SoftwareType,$(NoTitle),$(!REG_VT_SZ),$(SoftwareType)},+
                           {MajorVersion,$(NoTitle),$(!REG_VT_DWORD),$(ProductMajorVersion)},+
                           {MinorVersion,$(NoTitle),$(!REG_VT_DWORD),$(ProductMinorVersion)},+
                           {Title,$(NoTitle),$(!REG_VT_SZ),$(ProductSoftwareTitle)},+
                           {Description,$(NoTitle),$(!REG_VT_SZ),$(ProductSoftwareDescription)},+
                           {ServiceName,$(NoTitle),$(!REG_VT_SZ),$(ProductSoftwareName)},+
                           {InstallDate,$(NoTitle),$(!REG_VT_DWORD),*($(Now),1)}}

        Shell  $(UtilityInf) AddValueList $(KeyProduct) $(NewValueList)
        IfInt $($ShellCode) != $(!SHELL_CODE_OK)
            Shell "" DoShellErrorMessage "Utility.Inf, AddValueList"
            Return STATUS_FAILED
        EndIf

        Set RegistryErrorIndex = $($R0)

        IfStr(i) $(RegistryErrorIndex) != NO_ERROR
            EndWait
            CloseRegKey $(KeyProduct)
            CloseRegKey $(SoftNetRulesKey)
            Shell "" DoShellErrorMessage $(RegistryErrorIndex)
            Return STATUS_FAILED
        EndIf

        Set NewValueList = {{type,$(NoTitle),$(!REG_VT_SZ),$(NetRuleSoftwareType)},+
                            {use,$(NoTitle),$(!REG_VT_SZ),$(NetRuleSoftwareUse)}, +
                            {bindform,$(NoTitle),$(!REG_VT_SZ),$(NetRuleSoftwareBindForm)}, +
                            {class,$(NoTitle),$(!REG_VT_MULTI_SZ),$(NetRuleSoftwareClass)}, +
                            {bindable,$(NoTitle),$(!REG_VT_MULTI_SZ),$(NetRuleSoftwareBindable)}, +
                            {InfOption,$(NoTitle),$(!REG_VT_SZ),$(!p:Option)}}

        Shell  $(UtilityInf) AddValueList $(SoftNetRulesKey) $(NewValueList)
        IfInt $($ShellCode) != $(!SHELL_CODE_OK)
            Shell "" DoShellErrorMessage "Utility.Inf, AddValueList"
            Return STATUS_FAILED
        EndIf

        Set RegistryErrorIndex = $($R0)

        CloseRegKey $(KeyProduct)
        CloseRegKey $(SoftNetRulesKey)

        IfStr(i) $(RegistryErrorIndex) != NO_ERROR
            EndWait
            Shell "" DoRegistryErrorMessage $(RegistryErrorIndex)
            Return STATUS_FAILED
        EndIf
    EndIf

    ;;
    ;;  Create the HARDWARE\Netcard region and its
    ;;  corresponding service
    ;;
    Shell $(UtilityInf) AddHardwareComponent $(ProductHardwareName) $(STF_CONTEXTINFNAME),$(ProductKeyName)

    IfInt $($R4) != -1
        Set OEM_ABANDON_OPTIONS = >($(OEM_ABANDON_OPTIONS), $(!NTN_SoftwareBase)"\Microsoft\Windows NT\CurrentVersion\NetworkCards\"$($R4))
    EndIf

    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        Shell "" DoShellErrorMessage "Utility.Inf, AddHardwareComponent"
        Return STATUS_FAILED
    EndIf

    Set RegistryErrorIndex = $($R0)

    IfStr(i) $(RegistryErrorIndex) != NO_ERROR
        EndWait
        CloseRegKey $($R1)
        CloseRegKey $($R2)
        CloseRegKey $($R3)
        Shell "" DoRegistryErrorMessage $(RegistryErrorIndex)
        Return STATUS_FAILED
    EndIf

    ;;
    ;;   At this point:
    ;;     $R1  Registry key variable for HARDWARE\Netcard\(n)
    ;;     $R2  Registry key variable for HARDWARE\Netcard\(n)\\NetRules
    ;;     $R3  Registry key handle for <service>\Parameters key
    ;;     $R4  Adapter number assigned to adapter
    ;;     $R5  Service name generated by combining svc name with adapter number
    ;;
    Set !p:KeyParameters = $($R3)
    Set KeyAdapterRules  = $($R2)
    Set AdapterNumber    = $($R4)

    Set NewValueList = {{Manufacturer,$(NoTitle),$(!REG_VT_SZ),$(Manufacturer)},+
                       {Title,$(NoTitle),$(!REG_VT_SZ),"["$($R4)"] "$(ProductHardwareTitle)},+
                       {Description,$(NoTitle),$(!REG_VT_SZ),$(ProductHardwareDescription)},+
                       {ProductName,$(NoTitle),$(!REG_VT_SZ),$(ProductHardwareName)},+
                       {ServiceName,$(NoTitle),$(!REG_VT_SZ),$($R5)},+
                       {InstallDate,$(NoTitle),$(!REG_VT_DWORD),*($(Now),1)}}

    Shell  $(UtilityInf) AddValueList $($R1) $(NewValueList)

    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        Shell "" DoShellErrorMessage "Utility.Inf, AddValueList"
        Return STATUS_FAILED
    EndIf

    CloseRegKey $($R1)

    IfStr(i) $($R0) != NO_ERROR
        EndWait
        Shell "" DoRegistryErrorMessage $($R0)
        CloseRegKey $(!p:KeyParameters)
        CloseRegKey $(KeyAdapterRules)
        Return STATUS_FAILED
    EndIf

    Set TempProdName = """"$(ProductHardwareName)$(AdapterNumber)""""
    Set TempBindForm = $(TempProdName)$(NetRuleHardwareBindForm)

    Set NewValueList = {{type,$(NoTitle),$(!REG_VT_SZ),$(NetRuleHardwareType)},+
                        {bindform,$(NoTitle),$(!REG_VT_SZ),$(TempBindForm)}, +
                        {class,$(NoTitle),$(!REG_VT_MULTI_SZ),$(NetRuleHardwareClass)}, +
                        {InfOption,$(NoTitle),$(!REG_VT_SZ),$(!p:Option)}}

    Shell  $(UtilityInf) AddValueList $(KeyAdapterRules) $(NewValueList)
    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        Shell "" DoShellErrorMessage
        Return STATUS_FAILED "Utility.Inf, AddValueList"
    EndIf

    IfStr(i) $($R0) != NO_ERROR
        EndWait
        Shell "" DoRegistryErrorMessage $($R0)
        CloseRegKey $(!p:KeyParameters)
        CloseRegKey $(KeyAdapterRules)
        Return STATUS_FAILED
    EndIf

    CloseRegKey $(KeyAdapterRules)

    Return STATUS_SUCCESSFUL

[FatalError]
    read-syms FileConstants

    IfStr(i) $($0) == ""
        set Message = "Unknown Error"
    Else
        set Message = $($0)
    EndIf

    Shell $(SubroutineInf) SetupMessage $(!STF_LANGUAGE) FATAL $(Message)
    Return

;==================================================================
;==================================================================
; Set up global debug control.
;
[DebugControl]
    set !DebugOutputControl = 1
    return

;==================================================================
;==================================================================
; Determine if values in VSlot are illegal
;
;
;    ARGUMENTS:
;       $($0)    SlotBusAvailable
;
;       $($1)    VSlotList
;
;    RETURNS:    STATUS_SUCCESS or STATUS_FAILED
;
;
[CheckSlotList]
    Read-Syms RegistryConstants

    Set SlotBusAvailable = $($0)
    Set VSlotList        = $($1)

    ForListDo $(VSlotList)
        Set MySlot    = *($($),1)
        Set MyBusNum  = *($($),2)
        Set MyBusType = *($($),3)
        ifstr(i) $(MySlot) == "255"
            Set FoundIt = 1
            GoTo CheckResults
        endif

        Set FoundIt = 0
        ForListDo $(SlotBusAvailable)
            Set ConfigBusType = *($($),1)
            Set ConfigBusNum  = *($($),2)
            Set ConfigSlot    = *($($),3)

            ifstr(i) $(ConfigSlot) == $(MySlot)
                ifstr(i) $(ConfigBusType) == $(MyBusType)
                    ifstr(i) $(ConfigBusNum) == $(MyBusNum)
                        Set FoundIt = 1
                        GoTo CheckResults
                    endif
                endif
            endif
        EndForListDo
CheckResults =+
        IfInt $(FoundIt) == 0
            shell "" DoShellError $(INVALID_REGISTRY_VSLOT)
            return STATUS_FAILED
        endif
    EndForListDo

    return STATUS_SUCCESS

;==================================================================
;==================================================================
; Set up !p:TempSlotList
; TempSlotList has the following format:
:       {SlotNumber, BusNumber, BusType, VSlotListIndex, InVSlot}
;       VSlotListIndex = index in VSLotList for entry
;       InVSlot        = 0 if not valid entry in VSlotList
;                        1 if valid entry in VSlotList
;
;
;    $($0)    SlotBusAvailable
;
;    $($1)    SubList like VSlotList
;
;
[CreateSlotList]
    Set SlotBusAvailable = $($0)
    Set VSlotList        = $($1)

    Set LastFoundFF      = 0
    Set NewSlotList      = {}
    Set FoundFF          = 0

    ForListDo $(SlotBusAvailable)
        Set ConfigBusType = *($($), 1)
        Set ConfigBusNum  = *($($), 2)
        Set ConfigSlot    = *($($), 3)
        Set VSlotIndex    = 1
        Set FoundIndex    = 0

        ForListDo $(VSlotList)
            Set MySlot    = *($($), 1)
            Set MyBusNum  = *($($), 2)
            Set MyBusType = *($($), 3)

            Ifstr(i) $(MySlot) == "255"
                IfInt $(VSlotIndex) > $(LastFoundFF)
                    IfInt $(FoundFF) == 0
                        Set FoundFF = $(VSlotIndex)
                    EndIf
                EndIf
            Else
                IfInt $(MySlot) == $(ConfigSlot)
                    IfInt $(MyBusNum) == $(ConfigBusNum)
                        IfInt $(MyBusType) == $(ConfigBusType)
                            Set FoundIndex = $(VSlotIndex)
                        EndIf
                    EndIf
                EndIf
            EndIf
            Set-Add VSlotIndex = $(VSlotIndex), 1
        EndForListDo

        IfInt $(FoundIndex) == 0
            Set FoundIndex    = $(FoundFF)
            Set LastFoundFF   = $(FoundFF)
            Set FoundFF       = 0
            Set InVSlot       = 0
        Else
            Set InVSlot       = 1
        EndIf
        Set NewSlotList = >($(NewSlotList), {$(ConfigSlot), $(ConfigBusNum), $(ConfigBusType), $(FoundIndex), $(InVSlot)})
    EndForListDo
    Set !p:TempSlotList = $(NewSlotList)
    return

;==================================================================
;==================================================================
; Set up !p:BoldList and !p:CheckList
;
;
;    $($0)    SlotBusAvailable
;
;    $($1)    NewSlotList
;
;
[CreateBoldCheck]
    Read-Syms FileConstants

    Set SlotBusAvailable = $($0)
    Set NewSlotList      = $($1)

    Set CardsAvailable   = {}
    Shell "" RebuildVnetAdapterList $(SlotBusAvailable)
    Set BoldList         = $(CardsAvailable)
    Set CheckList        = {}
    Set Index            = 1

    ForListDo $(NewSlotList)
        Set InVSlot = *($($),5)
        IfInt $(InVSlot) == 1
            Set BoldList  = >($(BoldList), $(Index))
            Set CheckList = >($(CheckList), $(Index))
        EndIf
        Set-Add Index = $(Index), 1
    EndForListDo

    Shell $(UtilityInf) SortList $(BoldList) TRUE FALSE
    Set BoldList  = $($R0)
    Set NewBold   = {}
    Set LastEntry = 0

    ForListDo $(BoldList)
        Set Entry = *($($),1)
        IfInt $(LastEntry) != $(Entry)
            Set NewBold   = >($(NewBold), $(Entry))
            Set LastEntry = $(Entry)
        EndIf
    EndForListDo

    Set !p:BoldList  = $(NewBold)
    Set !p:CheckList = $(CheckList)

    return


;==================================================================
;==================================================================
; Set up !p:CheckedSlotList
; CheckedSlotList has the following format:
:       {SlotNumber, BusNumber, BusType, VSlotListIndex, InVSlot}
;       VSlotListIndex = index in VSLotList for entry
;       InVSlot        = 0 if not valid entry in VSlotList
;                        1 if valid entry in VSlotList
; Updates the index based on CheckedItems
;
;
;    $($0)    NewSlotList
;
;    $($1)    CheckedItems
;
;
[FixSlotList]
    Set NewSlotList  = $($0)
    Set CheckedItems = $($1)

    Set TotalEntries = 1
    ForListDo $(NewSlotList)
        Set-Add TotalEntries = $(TotalEntries),1
    EndForListDo

    Set NextIndex = 1
    Set MySlotList = {}

    ForListDo $(CheckedItems)
        Set MyIndex         = *($($),1)
        Set MyEntry         = *($(NewSlotList),$(MyIndex))
        Set MySlot          = *($(MyEntry),1)
        Set MyBusN          = *($(MyEntry),2)
        Set MyBusT          = *($(MyEntry),3)
        Set MyBusSlotIndex  = *($(MyEntry),4)
        Set MyInVSlot       = *($(MyEntry),5)

        IfInt $(MyInVSlot) == 1
            Set NewEntry = $(MyEntry)
            GoTo SetIt
        EndIf

        Set TempIndex = $(NextIndex)
LoopMore    =+
        IfInt $(TempIndex) < $(TotalEntries)
            IfInt $(TempIndex) == $(MyIndex)
                Set NewEntry  = $(MyEntry)
                Set NextIndex = $(TempIndex)
                Set-Add NextIndex = $(TempIndex),1
                GoTo SetIt
            Else
                Set TempEntry = *($(NewSlotList), $(TempIndex))
                Set TempVSlot = *($(TempEntry),5)
                IfInt $(TempVSlot) == 0
                    Set TempSlotIndex = *($(TempEntry),4)
                    Set NewEntry = {$(MySlot),$(MyBusN),$(MyBusT),$(TempSlotIndex),$(MyInVSlot)}
                    Set-Add NextIndex = $(TempIndex),1
                    GoTo SetIt
                EndIf
            EndIf
            Set-Add TempIndex = $(TempIndex),1
            GoTo LoopMore
        EndIf

SetIt       =+
        Set MySlotList = >($(MySlotList),$(NewEntry))
    EndForListDo

    Set !p:CheckedSlotList = $(MySlotList)
    return


;==================================================================
;==================================================================
; Set up !p:VSlotX as a list
;   the entries BusNumber, SlotNumber and FullMemory require 2 digits
;
;
[FixVslot]
    Set VSlotX    = $(!p:VSlotX)
    Set BusNum    = *($(VSlotX),1)*($(VSlotX),2)
    Set BusType   = *($(VSlotX),3)
    Set SlotNum   = *($(VSlotX),4)*($(VSlotX),5)
    Set FullMem   = *($(VSlotX),6)*($(VSlotX),7)
    Set Port1     = *($(VSlotX),8)
    Set Port2     = *($(VSlotX),9)
    Set Port3     = *($(VSlotX),10)
    Set Port4     = *($(VSlotX),11)
    Set LT1       = *($(VSlotX),12)
    Set LT2       = *($(VSlotX),13)
    Set LT3       = *($(VSlotX),14)
    Set LT4       = *($(VSlotX),15)
    Set FlashV    = *($(VSlotX),16)
    Set !p:VSlotX = $(BusNum)","$(BusType)","$(SlotNum)","$(FullMem)","$(Port1)","$(Port2)","$(Port3)","$(Port4)","$(LT1)","$(LT2)","$(LT3)","$(LT4)","$(FlashV)

    return


;==================================================================
;==================================================================
; Set up adapterlist for Pci bus.     
;
;
;    ARGUMENTS:
;       $($0)    low order ID byte for adapter
;
;       $($1)    high order ID byte for adapter
;
;    RETURNS:    $R0  List of bus and slot information
;                   {{bus0,slot0},{bus1,slot1},{bus2,slot2}...{busk,slotk}}
;
;
[OurFindPci]
    Read-Syms DllInformation
    Read-Syms FileConstants

    Set IdByte1     = $($0)
    Set IdByte2     = $($1)
    Set Result      = {}
    Set SrcDir      = $(!p:SrcDir)

    Set Path = $(!STF_WINDOWSSYSPATH)
    Split-String $(Path) "\" List
    QueryListSize ListSize $(List)

    IfStr(i) *($(List), $(ListSize)) != "\"
        Set Path = $(Path)"\"
    EndIf

    Set DllName = $(Path)$(DllName)
    LoadLibrary $(DiskName) $(DllName) DialogResourceHandle

    libraryProcedure Result $(DialogResourceHandle) FindPciCards $(IdByte1) $(IdByte2)
    FreeLibrary $(DialogResourceHandle)

    return $(Result)

;==================================================================
;==================================================================
; Set up slotbusavailable list for all adapter types.
; Format: {{BusType, BusNumber, SlotNumber},...}
;            both BusNumber and SlotNumber are decimal digits
;
;
;    ARGUEMENTS:
;
;    RETURNS:   STATUS_FAILED or STATUS_SUCCESSFUL
;               updates !p:SlotBusAvailable
;                       !p:LblSlot1
;                       !p:LblSlot2
;                       !p:LblSlot3
;                       !p:LblSlot4
;                       !p:LblSlot5
;                       !p:LblSlot6
;                       !p:LblSlot7
;                       !p:LblSlot8
;
;
[BuildSlotBus]
;;
;;  Obtain list containing the bus number and slot number for
;;  MCA cards with given ID (for 10BaseT)
;;
    Read-Syms SlotLabels
    Read-Syms McaCardIds
    Read-Syms PciCardIds
    Read-Syms FileConstants
    Read-Syms RegistryConstants
    Read-Syms GeneralConstants

    Shell $(UtilityInf), MCAFindBus, $(ETH_TP_ID_BYTE_1), $(ETH_TP_ID_BYTE_2)
    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        Shell "" DoShellErrorMessage "Utility.Inf, MCAFindBus"
        Return STATUS_FAILED
    EndIf
    IfStr(i) $($R0) != "NO_ERROR"
        Shell "" DoRegistryErrorMessage $($R0)
        Return STATUS_FAILED
    EndIf

;;
;;  Obtain SlotBusAvailable list with Bus Type, Bus Number and Slot Number
;;  for MCA Cards (10Base2)
;;
    Set AdapterList        = $($R1)
    Shell $(UtilityInf) SortList $(AdapterList) TRUE FALSE
    Set AdapterList        = $($R0)
    Set SlotBusAvailable   = {}
    Set SlotIndex          = 0
    shell "" BuildAdapterList $(AdapterList) $(TpAdapter) $(MCA_BUS_TYPE) $(LblMca)
    IfInt $(SlotIndex) > 8
        Shell "" DoFatalMessage $(TOO_MANY_ADAPTERS)
        Return STATUS_FAILED
    EndIf

;;
;;  Obtain list containing the bus number and slot number for
;;  MCA cards with given ID (for 10Base2)
;;
    Shell $(UtilityInf), MCAFindBus, $(ETH_BNC_ID_BYTE_1), $(ETH_BNC_ID_BYTE_2)
    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        Shell "" DoShellErrorMessage "Utility.Inf, MCAFindBus"
        Return STATUS_FAILED
    EndIf
    IfStr(i) $($R0) != "NO_ERROR"
        Shell "" DoRegistryErrorMessage $($R0)
        Return STATUS_FAILED
    EndIf

;;
;;  Modify SlotBusAvailable to include the list with Bus Type,
;;  Bus Number and Slot Number for MCA Cards (10Base2)
;;
    Set AdapterList        = $($R1)
    Shell $(UtilityInf) SortList $(AdapterList) TRUE FALSE
    Set AdapterList        = $($R0)
    shell "" BuildAdapterList $(AdapterList) $(BncAdapter) $(MCA_BUS_TYPE) $(LblMca)
    IfInt $(SlotIndex) > 8
        Shell "" DoFatalMessage $(TOO_MANY_ADAPTERS)
        Return STATUS_FAILED
    EndIf


;;
;;  Obtain list containing the bus number and slot number for
;;  PCI cards with given ID
;;
    Set SrcDir              = $(!p:SrcDir)
    Set AddCopy             = $(!p:AddCopy)
    Set DoCopy              = $(!p:DoCopy)
    Set OldVersionExisted   = $(!p:OldVersionExisted)

    Shell $(UtilityInf), GetPciInformation, $(ETH_VENDOR_ID), $(ETH_DEVICE_ID)
    IfInt $($ShellCode) != $(!SHELL_CODE_OK)
        Shell "" OurFindPci $(ETH_ID_BYTE_1) $(ETH_ID_BYTE_2)
    EndIf

;;
;;  Modify SlotBusAvailable to include the list with Bus Type,
;;  Bus Number and Slot Number for PCI Cards (10BaseT)
;;
    Set AdapterList        = $($R0)
    Shell $(UtilityInf) SortList $(AdapterList) TRUE FALSE
    Set AdapterList        = $($R0)
    shell "" BuildAdapterList $(AdapterList) $(TpAdapter) $(PCI_BUS_TYPE) $(LblPci)
    IfInt $(SlotIndex) > 8
        Shell "" DoFatalMessage $(TOO_MANY_ADAPTERS)
        Return STATUS_FAILED
    EndIf

    IfInt $(SlotIndex) == 0
        Shell "" DoShellErrorMessage $(CANNOT_FIND_ANY_MAC_PORTS)
        Return STATUS_FAILED
    EndIf

    Set !p:SlotBusAvailable = $(SlotBusAvailable)
    Set !p:LblSlot1         = $(LblSlot1)
    Set !p:LblSlot2         = $(LblSlot2)
    Set !p:LblSlot3         = $(LblSlot3)
    Set !p:LblSlot4         = $(LblSlot4)
    Set !p:LblSlot5         = $(LblSlot5)
    Set !p:LblSlot6         = $(LblSlot6)
    Set !p:LblSlot7         = $(LblSlot7)
    Set !p:LblSlot8         = $(LblSlot8)

    return STATUS_SUCCESSFUL


;==================================================================
;==================================================================
; If new flashnumber required, find one.
;
;    $($0)    OriginalFlashNumber
;
;    $($1)    Bus number
;
;    $($0)    Slot number
;
;    updates !p:FlashList, !p:FlashX
;
;
[UpdateFlash]
    Set FlashX   = $($0)
    Set BusNumX  = $($1)
    Set SlotNumX = $($2)
    ifstr(i) $(FlashX) != 15
        set !p:FlashX = $(FlashX)
        return
    endif

    Set FlashList = $(!p:FlashList)
    Set FlashX = 1

    ifstr(i) $(FlashList) == {}
        goto DoneFlashLoop
    endif

    ForListDo $(FlashList)
        Set BusNum   = *($($),1)
        Set SlotNum  = *($($),2)
        Set FlashNum = *($($),3)
        ifstr(i) $(BusNumX) == $(BusNum)
            ifstr(i) $(SlotNumX) == $(SlotNum)
                set FlashX = $(FlashNum)
                goto ReturnFlash
            endif
        endif
    EndForListDo

FlashLoop   =+
    ForListDo $(FlashList)
        Set FlashNum = *($($),3)
        ifstr(i) $(FlashNum) == $(FlashX)
            Set-Add FlashX = $(FlashX), 1
            goto FlashLoop
        endif
    EndForListDo

DoneFlashLoop   =+
    set Entry = {$(BusNumX),$(SlotNumX),$(FlashX)}
    set FlashList = >($(FlashList),$(Entry))

ReturnFlash     =+
    set !p:FlashList = $(FlashList)
    set !p:FlashX    = $(FlashX)

    return

;==================================================================
;==================================================================
; Set up adapterlist for adapter type.
;
;
;    $($0)    AdapterList
;
;    $($1)    AdapterType
;
;    $($2)    BusType, number is 5 (PCI) or 3 (MCA)
;
;    $($3)    BusTypeDesc, either (MCA) or (PCI)
;
;    updates !p:SlotIndex, !p:SlotBusAvailable, !p:LblSlot1,
;            !p:LblSlot2, !p:LblSlot3, !p:LblSlot4, !p:LblSlot5,
;            !p:LblSlot6, !p:LblSlot7, !p:LblSlot8
;
;
[BuildAdapterList]
    Set AdapterList = $($0)
    Set AdapterType = $($1)
    Set BusType     = $($2)
    Set BusTypeDesc = $($3)
    ifstr(i) $(AdapterList) == {}
        return
    Endif
    Set Index = $(!p:SlotIndex)
    ForListDo $(AdapterList)
        Set-Add Index = $(Index), 1
        Set !p:SlotIndex = $(Index)
        IfInt $(Index) > 8
            return
        EndIf
        Set BusNumber  = *($($),1)
        Set SlotNumber = *($($),2)

        Set !p:LblSlot$(Index)  = $(!p:LblBus)" "$(BusNumber)" "$(!p:LblSlot)" "$(SlotNumber)" "$(BusTypeDesc)" "$(AdapterType)
        Set !p:SlotBusAvailable = >($(!p:SlotBusAvailable), {$(BusType),$(BusNumber),$(SlotNumber)})
    EndForListDo

    return

;==================================================================
;==================================================================
; Set up adapterlist for vnet adapter type.
; Only include cards already configured as a Vnet adapter.
;
;
;    ARGUEMENTS:
;               $($0)    SlotBusAvailable
;
;    RETURNS:   STATUS_FAILED or STATUS_SUCCESSFUL
;               updates !p:CardsAvailable
;
;
[BuildVnetAdapterList]
    Read-Syms RegistryConstants

    Set SlotBusAvailable = $($0)
    Set Index = 1

    ForListDo $(SlotBusAvailable)
        Set BusType    = *($($),1)
        Set BusNumber  = *($($),2)
        Set SlotNumber = *($($),3)

        Shell "" IsVnetCardAlreadyInstalled,           +
            $(BusType),                                +
            $(BusNumber),                              +
            $(SlotNumber),                             +
            $(ProductHardwareDescription),             +
            $(ProductHardwareName)

        IfInt $($ShellCode) != $(!SHELL_CODE_OK)
            Shell "" DoShellErrorMessage "QuadEnet.Inf, IsNetCardAlreadyInstalled"
            Return STATUS_FAILED
        EndIf

        IfStr(i) $($R0) != "NO_ERROR"
            Shell "" DoRegistryErrorMessage $($R0)
            Return STATUS_FAILED
        EndIf

        IfStr(i) $($R1) == "YES"
            Set !p:CardsAvailable   = >($(!p:CardsAvailable), $(Index))
        EndIf
        
        Set-Add Index = $(Index), 1
    EndForListDo
 
    return STATUS_SUCCESSFUL

;==================================================================
;==================================================================
; Set up adapterlist for vnet adapter type, do not include existing
; Vnet adapters or MAC adapters.
;
;
;    ARGUEMENTS:
;               $($0)    SlotBusAvailable
;
;    RETURNS:   STATUS_FAILED or STATUS_SUCCESSFUL
;               updates !p:CardsAvailable
;
;
[RebuildVnetAdapterList]
    Read-Syms RegistryConstants

    Set SlotBusAvailable = $($0)
    Set Index = 1
    ForListDo $(SlotBusAvailable)
        set BusType    = *($($),1)
        set BusNumber  = *($($),2)
        set SlotNumber = *($($),3)

        Shell "" IsVnetCardAlreadyInstalled,           +
            $(BusType),                                +
            $(BusNumber),                              +
            $(SlotNumber),                             +
            $(ProductHardwareDescription),             +
            $(ProductHardwareName)

        IfInt $($ShellCode) != $(!SHELL_CODE_OK)
            Shell "" DoShellErrorMessage "QuadEnet.Inf, IsNetCardAlreadyInstalled"
            Return STATUS_FAILED
        EndIf

        IfStr(i) $($R0) != "NO_ERROR"
            Shell "" DoRegistryErrorMessage $($R0)
            Return STATUS_FAILED
        EndIf

        IfStr(i) $($R1) == "NO"
            Set NoMac = "YES"
            Set PortList   = { 1, 2, 3, 4 }
            ForListDo $(PortList)
                set PortNum = *($($),1)

                Shell "" IsNetCardAlreadyInstalled,            +
                    $(BusType),                                +
                    $(BusNumber),                              +
                    $(SlotNumber), $(PortNum),                 +
                    $(ProductHardwareDescription),             +
                    $(ProductHardwareName)

                IfInt $($ShellCode) != $(!SHELL_CODE_OK)
                    Shell "" DoShelErrorMessage "QuadEnet.Inf, IsNetCardAlreadyInstalled"
                    Return STATUS_FAILED
                EndIf

                IfStr(i) $($R0) != "NO_ERROR"
                    Shell "" DoRegistryErrorMessage $($R0)
                    Return STATUS_FAILED
                EndIf

                IfStr(i) $($R1) == "YES"
                    set NoMac = "NO"
                EndIf
            EndForListDo

            IfStr(i) $(NoMac) == "YES"
                Set !p:CardsAvailable = >($(!p:CardsAvailable), $(Index))
            EndIf
        EndIf
        Set-Add Index = $(Index),1
    EndForListDo
    return STATUS_SUCCESSFUL


;==================================================================
;==================================================================
; Next section copied from Utility.Inf and modified to handle
; individual ports.
;
;
;*************************************************************************
;
;     SECTION:   IsNetCardAlreadyInstalled
;
;     PURPOSE:   This subroutine is called by EISA and MCA net card
;                setup. Given the bus number and slot number, it will
;                return a boolean to idicate whether the card is
;                already installed or not.
;
;   ARGUMENTS:   $0   Bus Type  
;                $1   Bus Number 
;                $2   Slot Number
;                $3   Port Number
;                $4   Product Description
;                $5   Product Name
;
;    RETURNS:    $R0  Registry error code or zero if no error
;                $R1  "YES" - if the net card already installed
;                     "NO"  - if the net card is not in the registry
;
;  REFERENCES:  Nothing
;
;    MODIFIES:  Nothing
;
;*************************************************************************

[IsNetCardAlreadyInstalled]
    Read-Syms GeneralConstants

    Set CurrentControlSet  = "SYSTEM\CurrentControlSet"
    Set ServicesBaseName   = $(CurrentControlSet)"\Services"
    Set NetworkCardKeyName = $(!NTN_SoftwareBase)"\Microsoft\Windows NT\CurrentVersion\NetworkCards"

    set RegistryErrorIndex = "NO_ERROR"
    set AlreadyExisted     = "NO"

    set BusType     = $($0)
    set BusNum      = $($1)
    set SlotNum     = $($2)
    set PortNum     = $($3)
    set Description = $($4)
    set Product     = $($5)
    ifstr(i) $(SlotNum) == "255"
        GoTo IE_Return
    endif

    OpenRegKey $(!REG_H_LOCAL) "" $(NetworkCardKeyName) $(MAXIMUM_ALLOWED) IE_KeyNetcards

    Ifstr $(IE_KeyNetcards) == $(KeyNull)
       set RegistryErrorIndex = UNABLE_OPEN_NETWORKCARD_SECTION
       goto IE_Return
    EndIf

    EnumRegKey $(IE_KeyNetcards) IE_KeyNameList

    ;
    ; Compare all the NetworkCards entry and see whether they have the
    ; same title and productname.
    ;
    ForListDo  $(IE_KeyNameList)
        set IE_KeyName = *($($),1)
        OpenRegKey $(IE_KeyNetcards) "" $(IE_KeyName) $(MAXIMUM_ALLOWED) IE_Card

        Ifstr $(IE_Card) == $(KeyNull)
           set RegistryErrorIndex = UNABLE_OPEN_NETWORKCARD_SECTION
           goto IE_Return
        EndIf

        GetRegValue $(IE_Card),"Description", DescriptionInfo
        GetRegValue $(IE_Card),"ProductName", ProductNameInfo
        set CardDescription     = *($(DescriptionInfo), 4)
        set CardProductName     = *($(ProductNameInfo), 4)

        IfStr(i) $(CardDescription) == $(Description)
            IfStr(i) $(CardProductName) == $(Product)

                ;
                ; We find the same product type. make sure that it
                ; does not have the same bus number and slot number
                ;

                GetRegValue $(IE_Card), "ServiceName", ServiceNameInfo
                set ServiceName = *($(ServiceNameInfo), 4)

                OpenRegKey $(!REG_H_LOCAL) "" +
                   $(ServicesBaseName)"\"$(ServiceName)"\Parameters" +
                   $(MAXIMUM_ALLOWED) IE_KeyService

                Ifstr $(IE_KeyService) == $(KeyNull)
                   set RegistryErrorIndex = UNABLE_OPEN_NETWORKCARD_SECTION
                   goto IE_Return
                EndIf

                GetRegValue $(IE_KeyService), "BusType", BusTypeInfo
                GetRegValue $(IE_KeyService), "BusNumber", BusNumInfo
                GetRegValue $(IE_KeyService), "SlotNumber", SlotInfo
                GetRegValue $(IE_KeyService), "PortNumber", PortInfo
                set CardBusType = *($(BusTypeInfo), 4)
                set CardBusNum  = *($(BusNumInfo), 4)
                set CardSlotNum = *($(SlotInfo), 4)
                set CardPortNum = *($(PortInfo), 4)

                IfInt $(CardBusType) == $(BusType)
                    IfInt $(CardBusNum) == $(BusNum)
                        IfInt $(CardSlotNum) == $(SlotNum)
                            IfInt $(CardPortNum) == $(PortNum)
                                set AlreadyExisted = "YES"
                            EndIf
                        EndIf
                    EndIf
                EndIf

            EndIf
        EndIf
    EndForListDo

IE_Return =+
    return $(RegistryErrorIndex) $(AlreadyExisted)

;*************************************************************************
;  end of section  IsNetCardAlreadyInstalled
;*************************************************************************


;==================================================================
;==================================================================
; Update Global (Slot-Based) Parameters.
;
;
;   $0   Bus Number
;   $1   Slot Number
;   $2   Product Description
;   $3   Product Name
;
[UpdateGlobalParams]
    Read-Syms GeneralConstants
    Read-Syms ReadSetupParameters

    Set CurrentControlSet  = "SYSTEM\CurrentControlSet"
    Set ServicesBaseName   = $(CurrentControlSet)"\Services"
    Set NetworkCardKeyName = $(!NTN_SoftwareBase)"\Microsoft\Windows NT\CurrentVersion\NetworkCards"

    Set NewWatchDogTimer    = $(WatchDogTimer)
    Set NewFullMemoryWindow = $(FullMemoryWindow)

    set BusNum      = $($0)
    set SlotNum     = $($1)
    set Description = $($2)
    set Product     = $($3)

    OpenRegKey $(!REG_H_LOCAL) "" $(NetworkCardKeyName) $(MAXIMUM_ALLOWED) GP_KeyNetcards

    Ifstr $(GP_KeyNetcards) == $(KeyNull)
       Return UNABLE_OPEN_NETWORKCARD_SECTION
    EndIf

    EnumRegKey $(GP_KeyNetcards) GP_KeyNameList

    ;
    ; Compare all the NetworkCards entry and see whether they have the
    ; same title and productname.
    ;
    ForListDo  $(GP_KeyNameList)
        set GP_KeyName = *($($),1)
        OpenRegKey $(GP_KeyNetcards) "" $(GP_KeyName) $(MAXIMUM_ALLOWED) GP_Card

        Ifstr $(GP_Card) == $(KeyNull)
           Return UNABLE_OPEN_NETWORKCARD_SECTION
        EndIf

        GetRegValue $(GP_Card),"Description", DescriptionInfo
        GetRegValue $(GP_Card),"ProductName", ProductNameInfo
        set CardDescription     = *($(DescriptionInfo), 4)
        set CardProductName     = *($(ProductNameInfo), 4)

        IfStr(i) $(CardDescription) == $(Description)
            IfStr(i) $(CardProductName) == $(Product)

                ;
                ; We find the same product type. make sure that it
                ; does not have the same bus number and slot number
                ;

                GetRegValue $(GP_Card), "ServiceName", ServiceNameInfo
                set ServiceName = *($(ServiceNameInfo), 4)

                OpenRegKey $(!REG_H_LOCAL) "" +
                   $(ServicesBaseName)"\"$(ServiceName)"\Parameters" +
                   $(MAXIMUM_ALLOWED) GP_KeyService

                Ifstr $(GP_KeyService) == $(KeyNull)
                   Return UNABLE_OPEN_NETWORKCARD_SECTION
                EndIf

                GetRegValue $(GP_KeyService), "BusNumber", BusInfo
                GetRegValue $(GP_KeyService), "SlotNumber", SlotInfo
                set CardBusNum = *($(BusInfo), 4)
                set CardSlotNum = *($(SlotInfo), 4)

                IfInt $(CardBusNum) == $(BusNum)
                    IfInt $(CardSlotNum) == $(SlotNum)
                        SetRegValue $(GP_KeyService) {FullMemoryWindow,$(NoTitle),$(!REG_VT_DWORD),$(NewFullMemoryWindow)}
                        SetRegValue $(GP_KeyService) {WatchDogTimer,$(NoTitle),$(!REG_VT_DWORD),$(NewWatchDogTimer)}
                    EndIf
                EndIf
            EndIf
        EndIf
    EndForListDo

    return NO_ERROR

;==================================================================
;==================================================================
; Next section copied from Utility.Inf and modified to determine
; the Vnet slots.
;
;
;*************************************************************************
;
;     SECTION:   IsVnetCardAlreadyInstalled
;
;     PURPOSE:   This subroutine is called by EISA and MCA net card
;                setup. Given the bus number and slot number, it will
;                return a boolean to indicate whether the card is
;                already installed and is a Vnet adapter.
;
;   ARGUMENTS:   $0   Bus Type  
;                $1   Bus Number 
;                $2   Slot Number
;                $3   Product Description
;                $4   Product Name
;
;    RETURNS:    $R0  Registry error code or zero if no error
;                $R1  "YES" - if the net card already installed and is Vnet
;                     "NO"  - if the net card is not in the registry
;                             or is not a Vnet adapter.
;
;  REFERENCES:  Nothing
;
;    MODIFIES:  Nothing
;
;*************************************************************************

[IsVnetCardAlreadyInstalled]
    Read-Syms GeneralConstants

    Set CurrentControlSet  = "SYSTEM\CurrentControlSet"
    Set ServicesBaseName   = $(CurrentControlSet)"\Services"
    Set NetworkCardKeyName = $(!NTN_SoftwareBase)"\Microsoft\Windows NT\CurrentVersion\NetworkCards"

    set RegistryErrorIndex = "NO_ERROR"
    set AlreadyExisted     = "NO"

    set BusType     = $($0)
    set BusNum      = $($1)
    set SlotNum     = $($2)
    set Description = $($3)
    set Product     = $($4)

    Ifstr(i) $(SlotNum) == "255"
        GoTo IE_Return
    EndIf
    OpenRegKey $(!REG_H_LOCAL) "" $(NetworkCardKeyName) $(MAXIMUM_ALLOWED) IE_KeyNetcards

    Ifstr $(IE_KeyNetcards) == $(KeyNull)
       set RegistryErrorIndex = UNABLE_OPEN_NETWORKCARD_SECTION
       goto IE_Return
    EndIf

    EnumRegKey $(IE_KeyNetcards) IE_KeyNameList

    ;
    ; Compare all the NetworkCards entry and see whether they have the
    ; same title and productname.
    ;
    ForListDo  $(IE_KeyNameList)
        set IE_KeyName = *($($),1)
        OpenRegKey $(IE_KeyNetcards) "" $(IE_KeyName) $(MAXIMUM_ALLOWED) IE_Card

        Ifstr $(IE_Card) == $(KeyNull)
           set RegistryErrorIndex = UNABLE_OPEN_NETWORKCARD_SECTION
           goto IE_Return
        EndIf

        GetRegValue $(IE_Card),"Description", DescriptionInfo
        GetRegValue $(IE_Card),"ProductName", ProductNameInfo
        set CardDescription     = *($(DescriptionInfo), 4)
        set CardProductName     = *($(ProductNameInfo), 4)

        IfStr(i) $(CardDescription) == $(Description)
            IfStr(i) $(CardProductName) == $(Product)

                ;
                ; We find the same product type. make sure that it
                ; does not have the same bus number and slot number
                ;

                GetRegValue $(IE_Card), "ServiceName", ServiceNameInfo
                set ServiceName = *($(ServiceNameInfo), 4)

                OpenRegKey $(!REG_H_LOCAL) "" +
                   $(ServicesBaseName)"\"$(ServiceName)"\Parameters" +
                   $(MAXIMUM_ALLOWED) IE_KeyService

                Ifstr $(IE_KeyService) == $(KeyNull)
                   set RegistryErrorIndex = UNABLE_OPEN_NETWORKCARD_SECTION
                   goto IE_Return
                EndIf

                GetRegValue $(IE_KeyService), "IsVnet", VnetInfo
                set CardVnetNum = *($(VnetInfo), 4)

                IfInt $(CardVnetNum) == 1
                    GetRegValue $(IE_KeyService), "VSlot1", VSlotInfo1
                    GetRegValue $(IE_KeyService), "VSlot2", VSlotInfo2
                    GetRegValue $(IE_KeyService), "VSlot3", VSlotInfo3
                    GetRegValue $(IE_KeyService), "VSlot4", VSlotInfo4
                    GetRegValue $(IE_KeyService), "VSlot5", VSlotInfo5
                    GetRegValue $(IE_KeyService), "VSlot6", VSlotInfo6
                    GetRegValue $(IE_KeyService), "VSlot7", VSlotInfo7
                    GetRegValue $(IE_KeyService), "VSlot8", VSlotInfo8

                    Set CardVSlot1 = *($(VSlotInfo1), 4)
                    Split-String $(CardVSlot1) $(AllHexDigits) CardVSlot1
                    Set CardVBusNum   = *($(CardVSlot1), 1)*($(CardVSlot1), 2)
                    Set CardVBusType1 = *($(CardVSlot1), 3)
                    Set CardVSlot     = *($(CardVSlot1), 4)*($(CardVSlot1), 5)
                    Set-HexToDec CardVBusNum1 = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot1   = "0x"$(CardVSlot)

                    Set CardVSlot2 = *($(VSlotInfo2), 4)
                    Split-String $(CardVSlot2) $(AllHexDigits) CardVSlot2
                    Set CardVBusNum   = *($(CardVSlot2), 1)*($(CardVSlot2), 2)
                    Set CardVBusType2 = *($(CardVSlot2), 3)
                    Set CardVSlot     = *($(CardVSlot2), 4)*($(CardVSlot2), 5)
                    Set-HexToDec CardVBusNum2 = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot2   = "0x"$(CardVSlot)

                    Set CardVSlot3 = *($(VSlotInfo3), 4)
                    Split-String $(CardVSlot3) $(AllHexDigits) CardVSlot3
                    Set CardVBusNum   = *($(CardVSlot3), 1)*($(CardVSlot3), 2)
                    Set CardVBusType3 = *($(CardVSlot3), 3)
                    Set CardVSlot     = *($(CardVSlot3), 4)*($(CardVSlot3), 5)
                    Set-HexToDec CardVBusNum3 = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot3   = "0x"$(CardVSlot)

                    Set CardVSlot4 = *($(VSlotInfo4), 4)
                    Split-String $(CardVSlot4) $(AllHexDigits) CardVSlot4
                    Set CardVBusNum   = *($(CardVSlot4), 1)*($(CardVSlot4), 2)
                    Set CardVBusType4 = *($(CardVSlot4), 3)
                    Set CardVSlot     = *($(CardVSlot4), 4)*($(CardVSlot4), 5)
                    Set-HexToDec CardVBusNum4 = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot4   = "0x"$(CardVSlot)


                    Set CardVSlot5 = *($(VSlotInfo5), 4)
                    Split-String $(CardVSlot5) $(AllHexDigits) CardVSlot5
                    Set CardVBusNum   = *($(CardVSlot5), 1)*($(CardVSlot5), 2)
                    Set CardVBusType5 = *($(CardVSlot5), 3)
                    Set CardVSlot     = *($(CardVSlot5), 4)*($(CardVSlot5), 5)
                    Set-HexToDec CardVBusNum5 = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot5   = "0x"$(CardVSlot)

                    Set CardVSlot6 = *($(VSlotInfo6), 4)
                    Split-String $(CardVSlot6) $(AllHexDigits) CardVSlot6
                    Set CardVBusNum   = *($(CardVSlot6), 1)*($(CardVSlot6), 2)
                    Set CardVBusType6 = *($(CardVSlot6), 3)
                    Set CardVSlot     = *($(CardVSlot6), 4)*($(CardVSlot6), 5)
                    Set-HexToDec CardVBusNum6 = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot6   = "0x"$(CardVSlot)

                    Set CardVSlot7 = *($(VSlotInfo7), 4)
                    Split-String $(CardVSlot7) $(AllHexDigits) CardVSlot7
                    Set CardVBusNum   = *($(CardVSlot7), 1)*($(CardVSlot7), 2)
                    Set CardVBusType7 = *($(CardVSlot7), 3)
                    Set CardVSlot     = *($(CardVSlot7), 4)*($(CardVSlot7), 5)
                    Set-HexToDec CardVBusNum7 = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot7   = "0x"$(CardVSlot)

                    Set CardVSlot8 = *($(VSlotInfo8), 4)
                    Split-String $(CardVSlot8) $(AllHexDigits) CardVSlot8
                    Set CardVBusNum   = *($(CardVSlot8), 1)*($(CardVSlot8), 2)
                    Set CardVBusType8 = *($(CardVSlot8), 3)
                    Set CardVSlot     = *($(CardVSlot8), 4)*($(CardVSlot8), 5)
                    Set-HexToDec CardVBusNum8 = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot8   = "0x"$(CardVSlot)

                    IfInt $(CardVSlot1) == $(SlotNum)
                        IfInt $(CardVBusNum1) == $(BusNum)
                            IfInt $(CardVBusType1) == $(BusType)
                                set AlreadyExisted = "YES"
                                GoTo IE_Return
                            EndIf
                        EndIf
                    EndIf
                    IfInt $(CardVSlot2) == $(SlotNum)
                        IfInt $(CardVBusNum2) == $(BusNum)
                            IfInt $(CardVBusType2) == $(BusType)
                                set AlreadyExisted = "YES"
                                GoTo IE_Return
                            EndIf
                        EndIf
                    EndIf
                    IfInt $(CardVSlot3) == $(SlotNum)
                        IfInt $(CardVBusNum3) == $(BusNum)
                            IfInt $(CardVBusType3) == $(BusType)
                                set AlreadyExisted = "YES"
                                GoTo IE_Return
                            EndIf
                        EndIf
                    EndIf
                    IfInt $(CardVSlot4) == $(SlotNum)
                        IfInt $(CardVBusNum4) == $(BusNum)
                            IfInt $(CardVBusType4) == $(BusType)
                                set AlreadyExisted = "YES"
                                GoTo IE_Return
                            EndIf
                        EndIf
                    EndIf
                    IfInt $(CardVSlot5) == $(SlotNum)
                        IfInt $(CardVBusNum5) == $(BusNum)
                            IfInt $(CardVBusType5) == $(BusType)
                                set AlreadyExisted = "YES"
                                GoTo IE_Return
                            EndIf
                        EndIf
                    EndIf
                    IfInt $(CardVSlot6) == $(SlotNum)
                        IfInt $(CardVBusNum6) == $(BusNum)
                            IfInt $(CardVBusType6) == $(BusType)
                                set AlreadyExisted = "YES"
                                GoTo IE_Return
                            EndIf
                        EndIf
                    EndIf
                    IfInt $(CardVSlot7) == $(SlotNum)
                        IfInt $(CardVBusNum7) == $(BusNum)
                            IfInt $(CardVBusType7) == $(BusType)
                                set AlreadyExisted = "YES"
                                GoTo IE_Return
                            EndIf
                        EndIf
                    EndIf
                    IfInt $(CardVSlot8) == $(SlotNum)
                        IfInt $(CardVBusNum8) == $(BusNum)
                            IfInt $(CardVBusType8) == $(BusType)
                                set AlreadyExisted = "YES"
                                GoTo IE_Return
                            EndIf
                        EndIf
                    EndIf

                EndIf
            EndIf
        EndIf
    EndForListDo

IE_Return =+
    return $(RegistryErrorIndex) $(AlreadyExisted)

;==================================================================
;==================================================================
; Next section copied from Utility.Inf and modified to determine
; the flash numbers in use.
;
;
;*************************************************************************
;
;     SECTION:   RefreshFlashList
;
;     PURPOSE:   This subroutine is called to create a valid FlashList.
;                Given the product description and the productname,
;                it searches through the registry for a match and creates
;                a list of numbers already in use. 
;
;   ARGUMENTS:   none
;
;    RETURNS:    $R0  Registry error code or zero if no error
;
;    UPDATES:    !p:FlashList
;
;  REFERENCES:  Nothing
;
;    MODIFIES:  Nothing
;
;*************************************************************************

[RefreshFlashList]
    Read-Syms GeneralConstants
    Read-Syms RegistryConstants

    Set CurrentControlSet  = "SYSTEM\CurrentControlSet"
    Set ServicesBaseName   = $(CurrentControlSet)"\Services"
    Set NetworkCardKeyName = $(!NTN_SoftwareBase)"\Microsoft\Windows NT\CurrentVersion\NetworkCards"

    set RegistryErrorIndex = "NO_ERROR"

    set Description = $(ProductHardwareDescription)    
    set Product     = $(ProductHardwareName)    
    set FlashList   = {}
    set NewList     = {}

    Ifstr(i) $(SlotNum) == "255"
        GoTo IE_Return
    EndIf

    OpenRegKey $(!REG_H_LOCAL) "" $(NetworkCardKeyName) $(MAXIMUM_ALLOWED) IE_KeyNetcards

    Ifstr $(IE_KeyNetcards) == $(KeyNull)
       set RegistryErrorIndex = UNABLE_OPEN_NETWORKCARD_SECTION
       goto IE_Return
    EndIf


    EnumRegKey $(IE_KeyNetcards) IE_KeyNameList
    IfStr(i) $(IE_KeyNameList) == {}
        goto IE_Return1
    EndIf

    ;
    ; Compare all the NetworkCards entry and see whether they have the
    ; same title and productname.
    ;
    ForListDo  $(IE_KeyNameList)
        set IE_KeyName = *($($),1)
        OpenRegKey $(IE_KeyNetcards) "" $(IE_KeyName) $(MAXIMUM_ALLOWED) IE_Card

        Ifstr $(IE_Card) == $(KeyNull)
           set RegistryErrorIndex = UNABLE_OPEN_NETWORKCARD_SECTION
           goto IE_Return
        EndIf

        GetRegValue $(IE_Card),"Description", DescriptionInfo
        GetRegValue $(IE_Card),"ProductName", ProductNameInfo
        set CardDescription     = *($(DescriptionInfo), 4)
        set CardProductName     = *($(ProductNameInfo), 4)

        IfStr(i) $(CardDescription) == $(Description)
            IfStr(i) $(CardProductName) == $(Product)
                ;
                ; We found the same product type.
                ;

                GetRegValue $(IE_Card), "ServiceName", ServiceNameInfo
                set ServiceName = *($(ServiceNameInfo), 4)

                OpenRegKey $(!REG_H_LOCAL) "" +
                   $(ServicesBaseName)"\"$(ServiceName)"\Parameters" +
                   $(MAXIMUM_ALLOWED) IE_KeyService

                Ifstr $(IE_KeyService) == $(KeyNull)
                   set RegistryErrorIndex = UNABLE_OPEN_NETWORKCARD_SECTION
                   goto IE_Return
                EndIf

                GetRegValue $(IE_KeyService), "IsVnet", VnetInfo
                set CardVnetNum = *($(VnetInfo), 4)

                IfInt $(CardVnetNum) == 1
                    GetRegValue $(IE_KeyService), "VSlot1", VSlotInfo1
                    GetRegValue $(IE_KeyService), "VSlot2", VSlotInfo2
                    GetRegValue $(IE_KeyService), "VSlot3", VSlotInfo3
                    GetRegValue $(IE_KeyService), "VSlot4", VSlotInfo4
                    GetRegValue $(IE_KeyService), "VSlot5", VSlotInfo5
                    GetRegValue $(IE_KeyService), "VSlot6", VSlotInfo6
                    GetRegValue $(IE_KeyService), "VSlot7", VSlotInfo7
                    GetRegValue $(IE_KeyService), "VSlot8", VSlotInfo8

                    Set CardVSlot1 = *($(VSlotInfo1), 4)
                    Split-String $(CardVSlot1) $(AllHexDigits) CardVSlot1
                    Set CardVFlash   = *($(CardVSlot1), 16)
                    Set CardVBusNum   = *($(CardVSlot1), 1)*($(CardVSlot1), 2)
                    Set CardVSlot     = *($(CardVSlot1), 4)*($(CardVSlot1), 5)
                    Set-HexToDec CardVBusNum = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot   = "0x"$(CardVSlot)
                    ifstr(i) $(CardVFlash) != F
                        set Entry = {$(CardVBusNum),$(CardVSlot),$(CardVFlash)}
                        ifstr(i) $(NewList) == {}
                            set NewList = >($(NewList),$(Entry))
                        else
                            ForListDo $(NewList)
                                set ListEntry = $($)
                                ifstr(i) $(Entry) == $(ListEntry)
                                    goto NoPutListEntry1
                                endif
                            EndForListDo
                            set NewList = >($(NewList),$(Entry))
NoPutListEntry1  =+
                        endif                            
                    endif

                    Set CardVSlot2 = *($(VSlotInfo2), 4)
                    Split-String $(CardVSlot2) $(AllHexDigits) CardVSlot2
                    Set CardVFlash   = *($(CardVSlot2), 16)
                    Set CardVBusNum   = *($(CardVSlot2), 1)*($(CardVSlot2), 2)
                    Set CardVSlot     = *($(CardVSlot2), 4)*($(CardVSlot2), 5)
                    Set-HexToDec CardVBusNum = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot   = "0x"$(CardVSlot)
                    ifstr(i) $(CardVFlash) != F
                        set Entry = {$(CardVBusNum),$(CardVSlot),$(CardVFlash)}
                        ifstr(i) $(NewList) == {}
                            set NewList = >($(NewList),$(Entry))
                        else
                            ForListDo $(NewList)
                                set ListEntry = $($)
                                ifstr(i) $(Entry) == $(ListEntry)
                                    goto NoPutListEntry2
                                endif
                            EndForListDo
                            set NewList = >($(NewList),$(Entry))
NoPutListEntry2  =+
                        endif                            
                    endif

                    Set CardVSlot3 = *($(VSlotInfo3), 4)
                    Split-String $(CardVSlot3) $(AllHexDigits) CardVSlot3
                    Set CardVFlash   = *($(CardVSlot3), 16)
                    Set CardVBusNum   = *($(CardVSlot3), 1)*($(CardVSlot3), 2)
                    Set CardVSlot     = *($(CardVSlot3), 4)*($(CardVSlot3), 5)
                    Set-HexToDec CardVBusNum = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot   = "0x"$(CardVSlot)
                    ifstr(i) $(CardVFlash) != F
                        set Entry = {$(CardVBusNum),$(CardVSlot),$(CardVFlash)}
                        ifstr(i) $(NewList) == {}
                            set NewList = >($(NewList),$(Entry))
                        else
                            ForListDo $(NewList)
                                set ListEntry = $($)
                                ifstr(i) $(Entry) == $(ListEntry)
                                    goto NoPutListEntry3
                                endif
                            EndForListDo
                            set NewList = >($(NewList),$(Entry))
NoPutListEntry3  =+
                        endif                            
                    endif

                    Set CardVSlot4 = *($(VSlotInfo4), 4)
                    Split-String $(CardVSlot4) $(AllHexDigits) CardVSlot4
                    Set CardVFlash   = *($(CardVSlot4), 16)
                    Set CardVBusNum   = *($(CardVSlot4), 1)*($(CardVSlot4), 2)
                    Set CardVSlot     = *($(CardVSlot4), 4)*($(CardVSlot4), 5)
                    Set-HexToDec CardVBusNum = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot   = "0x"$(CardVSlot)
                    ifstr(i) $(CardVFlash) != F
                        set Entry = {$(CardVBusNum),$(CardVSlot),$(CardVFlash)}
                        ifstr(i) $(NewList) == {}
                            set NewList = >($(NewList),$(Entry))
                        else
                            ForListDo $(NewList)
                                set ListEntry = $($)
                                ifstr(i) $(Entry) == $(ListEntry)
                                    goto NoPutListEntry4
                                endif
                            EndForListDo
                            set NewList = >($(NewList),$(Entry))
NoPutListEntry4  =+
                        endif                            
                    endif


                    Set CardVSlot5 = *($(VSlotInfo5), 4)
                    Split-String $(CardVSlot5) $(AllHexDigits) CardVSlot5
                    Set CardVFlash   = *($(CardVSlot5), 16)
                    Set CardVBusNum   = *($(CardVSlot5), 1)*($(CardVSlot5), 2)
                    Set CardVSlot     = *($(CardVSlot5), 4)*($(CardVSlot5), 5)
                    Set-HexToDec CardVBusNum = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot   = "0x"$(CardVSlot)
                    ifstr(i) $(CardVFlash) != F
                        set Entry = {$(CardVBusNum),$(CardVSlot),$(CardVFlash)}
                        ifstr(i) $(NewList) == {}
                            set NewList = >($(NewList),$(Entry))
                        else
                            ForListDo $(NewList)
                                set ListEntry = $($)
                                ifstr(i) $(Entry) == $(ListEntry)
                                    goto NoPutListEntry5
                                endif
                            EndForListDo
                            set NewList = >($(NewList),$(Entry))
NoPutListEntry5  =+
                        endif                            
                    endif

                    Set CardVSlot6 = *($(VSlotInfo6), 4)
                    Split-String $(CardVSlot6) $(AllHexDigits) CardVSlot6
                    Set CardVFlash   = *($(CardVSlot6), 16)
                    Set CardVBusNum   = *($(CardVSlot6), 1)*($(CardVSlot6), 2)
                    Set CardVSlot     = *($(CardVSlot6), 4)*($(CardVSlot6), 5)
                    Set-HexToDec CardVBusNum = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot   = "0x"$(CardVSlot)
                    ifstr(i) $(CardVFlash) != F
                        set Entry = {$(CardVBusNum),$(CardVSlot),$(CardVFlash)}
                        ifstr(i) $(NewList) == {}
                            set NewList = >($(NewList),$(Entry))
                        else
                            ForListDo $(NewList)
                                set ListEntry = $($)
                                ifstr(i) $(Entry) == $(ListEntry)
                                    goto NoPutListEntry6
                                endif
                            EndForListDo
                            set NewList = >($(NewList),$(Entry))
NoPutListEntry6  =+
                        endif                            
                    endif

                    Set CardVSlot7 = *($(VSlotInfo7), 4)
                    Split-String $(CardVSlot7) $(AllHexDigits) CardVSlot7
                    Set CardVFlash   = *($(CardVSlot7), 16)
                    Set CardVBusNum   = *($(CardVSlot7), 1)*($(CardVSlot7), 2)
                    Set CardVSlot     = *($(CardVSlot7), 4)*($(CardVSlot7), 5)
                    Set-HexToDec CardVBusNum = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot   = "0x"$(CardVSlot)
                    ifstr(i) $(CardVFlash) != F
                        set Entry = {$(CardVBusNum),$(CardVSlot),$(CardVFlash)}
                        ifstr(i) $(NewList) == {}
                            set NewList = >($(NewList),$(Entry))
                        else
                            ForListDo $(NewList)
                                set ListEntry = $($)
                                ifstr(i) $(Entry) == $(ListEntry)
                                    goto NoPutListEntry7
                                endif
                            EndForListDo
                            set NewList = >($(NewList),$(Entry))
NoPutListEntry7  =+
                        endif                            
                    endif

                    Set CardVSlot8 = *($(VSlotInfo8), 4)
                    Split-String $(CardVSlot8) $(AllHexDigits) CardVSlot8
                    Set CardVFlash   = *($(CardVSlot8), 16)
                    Set CardVBusNum   = *($(CardVSlot8), 1)*($(CardVSlot8), 2)
                    Set CardVSlot     = *($(CardVSlot8), 4)*($(CardVSlot8), 5)
                    Set-HexToDec CardVBusNum = "0x"$(CardVBusNum)
                    Set-HexToDec CardVSlot   = "0x"$(CardVSlot)
                    ifstr(i) $(CardVFlash) != F
                        set Entry = {$(CardVBusNum),$(CardVSlot),$(CardVFlash)}
                        ifstr(i) $(NewList) == {}
                            set NewList = >($(NewList),$(Entry))
                        else
                            ForListDo $(NewList)
                                set ListEntry = $($)
                                ifstr(i) $(Entry) == $(ListEntry)
                                    goto NoPutListEntry8
                                endif
                            EndForListDo
                            set NewList = >($(NewList),$(Entry))
NoPutListEntry8  =+
                        endif                            
                    endif

                Else
                    GetRegValue $(IE_KeyService), "FlashNumber", FlashInfo
                    set FlashNumber = *($(FlashInfo), 4)
                    GetRegValue $(IE_KeyService), "BusNumber", BusInfo
                    GetRegValue $(IE_KeyService), "SlotNumber", SlotInfo
                    set CardBusNum  = *($(BusInfo), 4)
                    set CardSlotNum = *($(SlotInfo), 4)
                    Set-HexToDec CardBusNum    = "0x"$(CardBusNum)
                    Set-HexToDec CardSlotNum   = "0x"$(CardSlotNum)
                    ifstr(i) $(FlashNumber) != F
                        set Entry = {$(CardBusNum),$(CardSlotNum),$(FlashNumber)}
                        set NewList = >($(NewList),$(Entry))
                    endif

                EndIf
            EndIf
        EndIf
    EndForListDo

IE_Return1 =+
    set !p:FlashList = $(NewList)

IE_Return =+
    return $(RegistryErrorIndex)

;*************************************************************************
;  end of section  IsVnetCardAlreadyInstalled
;*************************************************************************


;*************************************************************************
; End of section copied from Utility.Inf and modified to handle
; individual ports.
;==================================================================
;==================================================================































