[P
  [A ]
  [B

    /FileName 'S3_SERCON100S_FPGA_V1_0.HX2' def
	
    'PackInst' import
	
    /PackInst:OnMessageCallback PackInst:InitNew
    /log [B 'LogTxt' exch PackInst:OnMessageCallback ] def
	
	/TalkIntf PIVar:TalkIntf def
				
	/WriteWordToElo [B
		TalkIntf.WriteMemory
	] def
	
	/ReadMemory [B 
		TalkIntf.ReadMemory     
		TalkIntf.GetResult 0 eq 
		[B TalkIntf.GetData ]
		[B 'TalkError: ' TalkIntf.GetResult cvs add raisese ] ifelse
	] def
      
        'Download: ' FileName extfilename add log
        /Data FileName loadobj def
        'Start Download?' 'C' 'YA' msgdlg [B
          
          'Y' [B
			/ModuleType  $A3000000 ReadMemory def            
			ModuleType $40 eq [B
				'Programming FPGA...' log     	
				/JTAG_START_EXECUTION $A5A5 def
				/JTAG_Execute $C0000200 def
				JTAG_Execute JTAG_START_EXECUTION WriteWordToElo						
				Data FileName PackInst:DownloadHX2File
			]
			[B
			  'Download aborted: Wrong Module Type!' log
			] ifelse 
          ]

          'A' [B
            /Msg 'Download aborted by user'
            /SuppressAbortMsg #1
            2 cdict raise
          ]

        ][B
        ] case
		
		PackInst:Exit
		
  ] [B
    /Dict exch def
    Dict /SuppressAbortMsg known [B
      Dict.Msg log
      PIVar:LogMemo.Remain
    ] [B
      Dict.Msg log
      'Download aborted' log
      PIVar:LogMemo.Remain
    ] ifelse
  ] tryexcept

  [A ]
  
]