; MKT:@(#) 64700-17534 A.00.08 64700 SW UTIL                            06Jan95                      
;
PROMPT  "Processing, please wait..."

data DFLT_PROD  "64700 SW UTIL" ;Software package name if no volume label

;Set up default values:
data DFLT_DRIVE "C:"            ;Drive to install software upon
data DFLT_DIR   "HP64700"       ;Top level directory for this software
data EXE_DIR	"BIN"           ;Sub-directory for executables
data TABLE_DIR	"TABLES"        ;Sub-directory for 64700tab
data LIB_DIR	"LIB" 	        ;Sub-directory for downloaded software
data UPDATE_DIR	"UPDATE"        ;Sub-directory for firmware

data SRC_BIN    "\HP64700\BIN"
data SRC_LIB    "\HP64700\LIB"
data SRC_ROOT   "\HP64700"
data SRC_TABLES "\HP64700\TABLES"
data SRC_UPDATE "\HP64700\UPDATE"
data TAB_FILE	"64700TAB"

;Get constant messages -
data MSG01 "!1 software installation aborted#!"
data MSG02 "Copying Files to !3"
data MSG04 "UNABLE TO ACCESS DISC DRIVE. CONTINUE? (Y/N)"
data MSG05 "Do you really want to abort? (Y/N)"
data MSG07 "Press any key when ready..."
data MSG09 "File copying routine interrupted, bad directory, or out of disc space#!"
data blankline "                                                                              ~"
data YES_KEY  "Y"
data YES_LOW  "y"
data NO_KEY   "N"
data NO_LOW   "n"

data in_brk 0		;Initially not in break routine!

;Main code block starts here:
  onbreak gosub break_key
  onerror gosub door_ajar
main
  whichdrive var009		;Remember where we started
  set var002   DFLT_DRIVE
  set dest_dir DFLT_DIR
  set cur_prod DFLT_PROD

  set var001 cur_prod
  echo on
  gosub new_page
  print "This is the installation program for your !1 software.~~"
  print "This program will guide you through the steps of the installation.~~"
  print "The software provided will reside in its own subdirectory on your disc.~"
  print "The default disc drive and directory for installation of these products is~"
  print "'" var002 "\" dest_dir "'.  All of your !1 software (flash ROM programming~"
  print "code and firmware) may be put into the same directory.  You will be given~"
  print "the option of changing the default drive and/or subdirectory for~"
  print "installation.~~"
  print "You may use the Cntl-C key combination to abort at any time.~~"
  print "Do you wish to continue this installation procedure? (Y/N)"
  gosub yesno
  if result != 2 goto abort

  gosub new_page
  gosub get_path

  ;Root directory has been set up and is ok.  Build sub-directories.
  set var004 var003	;Executables directory
  strcat var004 "\"
  strcat var004 EXE_DIR
  mkdir var004 status

  set var005 var003	;Tables directory
  strcat var005 "\"
  strcat var005 TABLE_DIR
  mkdir var005 status
 
  set var006 var003	;Lib directory
  strcat var006 "\"
  strcat var006 LIB_DIR
  mkdir var006 status

  set var007 var003	;Update directory
  strcat var007 "\"
  strcat var007 UPDATE_DIR
  mkdir var007 status

  gosub new_page
  print "Do you wish to install the firmware update utility? (Y/N)"
  gosub yesno
  print "~~"
  if result = 3 goto do_pf1
    ;Install progflash, npf, and lpf
    print "~"
    gosub new_page
    print "Installing firmware update utility.~~"

    ; Copy the files in the bin directory to dest.
    set var010 "PROGFLASH.EXE"	;set up to copy progflash
    set var011 SRC_BIN		;from bin directory of current disc to
    set var012 var004		;to destination
    gosub copy_file

    ; Copy the files in the lib directory to dest.
    set var010 "*.X"		;set up to copy npf, lpf
    set var011 SRC_LIB		;from lib directory of current disc to
    set var012 var006		;to destination
    gosub copy_file

    print "~Software installation complete.~"
    pause 3

do_pf1
  gosub new_page

  ;Check for 64700tab file
  set temp var005
  strcat temp "\"
  strcat temp TAB_FILE
  set result 2		;Yes for install config file
  set status 0
  exist temp status
  if status = -1 goto do_ei3
    print "~"
    print "The emulator device table file already exists.  This file specifies~"
    print "communication parameters (baud rate, etc.) for the emulator device.~"
    print "If you have not previously customized this  file for your hardware,~"
    print "it is suggested that you replace it with the default configuration.~"
    print "If you have doubts, it is suggested that you do not replace it.  Do~"
    print "you wish to replace the existing file with the default? (Y/N)"
    gosub yesno
    print "~~"
do_ei3
  if result != 2 goto do_ei5	;Don't do it
    set var010 TAB_FILE   ;set up to copy configuration file
    set var011 SRC_TABLES ;from tables directory of current disc to
    set var012 var005	  ;destination tables directory
    gosub copy_file
    pause 2

    print "~!17 installation complete.~"
    pause 3
do_ei5

  gosub new_page
  print "Firmware updates for HP647XX products are shipped on separate discs.~"
  print "They are packaged either with this product, or with the user~"
  print "interface for your emulator.  They allow you to update the firmware~"
  print "for products installed in an HP64700A.~~"
  print "Do you wish to install a firmware update? (Y/N)"
  gosub yesno
  print "~~"

  if result = 3 goto do_ps2
    ;Install the processor specific tables
    print "~"
    set var021 "Firmware Update"
    set var020 "1"	;Load up firmware disk 1

do_ps1
    gosub load_disc
    gosub new_page
    print "Installing firmware.~~"

    ; Copy the files in the tables directory to dest.
    set var010 "*.CFG"		;set up to copy config files
    set var011 SRC_UPDATE	;from tables directory of current disc to
    set var012 var007	;to destination
    gosub copy_file

    set var010 "*.X"		;set up to copy absolute files
    gosub copy_file

    print "~firmware installation complete.~"
    pause 3
    print "Do you wish to install another firmware update? (Y/N)"
    gosub yesno
    print "~~"
    if result = 3 goto do_ps2
    goto do_ps1

do_ps2
  cd "\"
  gosub new_page
  bell
  print "Please remove disc from drive !9:.  At this point you may wish to install~"
  print "other software that you have purchased.  To do so, place the first disc of~"
  print "that package into drive !9: and type 'install'.~~"
  print "To allow your software to run, your 'PATH' list must include the execution~"
  print "path '!4', the environment variable 'HP64700' must be set to~"
  print "the path '!3', the environment variable 'HPTABLES' must be set to~"
  print "the path '!5', and the '\config.sys' file must have a~"
  print "'FILES=' command for at least 20 concurrent files.  These variables should~"
  print "be set up at power on time.  To accomplish this, you will need to edit the~"
  print "files: '\AUTOEXEC.BAT' and '\CONFIG.SYS' on the hard disc you will boot~"
  print "from.  See your MS-DOS manual for examples of these files and the commands:~"
  print "'PATH', 'SET', and 'FILES'.  Use your favorite editor to update these files.~"
  print "The root directory of the 'MASTER APPLICATION DISC' contains example files~"
  print "named: AUTOEXEC.EX and CONFIG.EX for the default variable values.~~"
  print "Once you have completed installing all of your packages, and have edited the~"
  print "necessary files, please reset the computer to set up the required~"
  print "environment variables.  (Press: [CNTL]+[ALT]+[DEL] simultaneously to reset.)~"
  stop

new_page
  cls
  print "!1 software installation.  (C) 1990 Hewlett-Packard Co.~~~"
  return

load_disc ;Ask user to put prod var021 disc #var020 into drive var9
  print "~"
load_disc1
  set status 0
  print "Please put !21 disc !20 into drive !9:"
  gosub any_key
  print "~"
  return

get_path  ;Determine disc and directory to copy to
;Prompts user for drive and directory, creates dir if needed
;Inputs  - var002 = Default disc id
;          dest_dir = Default directory
;Outputs - var002 = Disc identifier for path (C:)
;          var003 = Full path to directory (C:\hp64700)
;          dest_dir= Root directory name on destination (\hp64700)
  cursor get_px,get_py
get_path1
  pos   get_px,get_py
  gosub get_drive
get_path2
  pos   get_px,get_py
  move  0,1
  print  blankline
  pos   get_px,get_py
  move  0,1
  print "Select destination path  = !2\"
  set status 0
  input 50 dest_dir dest_dir
  if status = -23 goto get_path2 ;Repeat if break and continue
  print "~"
  upshift dest_dir

  set var003 var002		;Build directory path
  strcat var003 "\"
  strcat var003 dest_dir

  gosub get_dir		;Check for previous existence of this directory
  if status = -1 goto get_path1
  gosub status_clear	;Clear any error message
  return

get_drive	;Prompt user for drive ID (ex: C:) return in var002
  print "Select destination drive = "
  cursor get_dx,get_dy
get_drive2
  pos get_dx,get_dy
  set status 0
  input 2 var002 var002
  if status = -23 goto get_drive2	;Repeat if break and continue
  upshift var002
  set errmsg "Improper drive specifier. Must be a letter followed by a colon."
  mid temp var002 2 1	;Verify presence of colon
  if temp = ":" goto get_drive3
    gosub status_bar
    goto get_drive2
get_drive3
  gosub status_clear
  set temp var002	;Check accessibility of this drive.
  strcat temp "\"
  exist temp status
  if status = 2  goto get_drive5
    set errmsg "Improper drive specifier"
    gosub status_bar
    goto get_drive2
get_drive5
  free var002 space_avail
  if space_avail >= SPACE_NEEDED goto get_drive7
    set errmsg "Not enough room on selected drive.  Select another or abort."
    gosub status_bar
    goto get_drive2
get_drive7
  print "~"
  return

get_dir		;Check & build directory if needed.  Will check for existence
		;of directory and do a makdir if needed, error messages will
		;be displayed if encountered.
		;Inputs - var003 = directory path name (Drive & name)
		;Output - status = 0 if Directory ok, -1 if not
  exist var003 status	;Check for previous existence of this directory
  if status != 1 goto get_dir2
    set errmsg "The specified path (!3) leads to a file, NOT a valid directory."
    gosub status_bar
    set status -1
    bell
    return
get_dir2
  if status != 2 goto get_dir4
    print "~"
    print "The  specified  directory  already  exists.    This  indicates  that  this~
	print "package,  or  another  64700 series package  may  have  already  been~
	print "installed.   No  harm  should  arise  from  installing  twice,  and adding~
	print "packages is fine,  but if you  thought  that this was the FIRST 64700~
	print "package  to  be  installed  on  this  machine,  you  may wish to stop this~
	print "procedure and investigate.~~"
    print "Do you wish to continue with this procedure? (Y/N)"
    gosub yesno
    print "~~"
    if result = 3 goto abort
    set status 0
    return
get_dir4
  if status != -1 goto get_dir9
    set errmsg "Creating directory (!3)"
    gosub status_bar
    pause 2	;give a sec to allow reading
    mkdir var003 status
    if status != -1 goto get_dir6
      set errmsg "Unable to create directory !3. Verify disc and name are valid."
      gosub status_bar
      bell
      return
get_dir6
  set status 0
  return
get_dir9
  bell
  set status -1
  return

copy_file	;Copy var010 file(s) from dir var011 to dir var012
  set status 0
  exist var011 status
  if status = 2 goto copy_file1
    print "~Directory !9:!11 not found~~"
    bell
    goto abort
copy_file1
  cd var011
  print "Copying !10 from !9:!11 to !12.~Copying file: "
copy_file2
  fcount 1
  set status 0
  copy var010 var012 status
  if status = -23 goto copy_file2
  if status = -24 goto copy_file2

  if status = 1 goto copy_file4
    print "~~Error while copying !10 from !9:!11 to !12~"
    print "Bad directory, file not found, disc error, or interrupted!~"
    bell
    goto abort
copy_file4
  print "~"
  return

break_key		;Executed in case of Cntl-C
  if in_brk = 1 return	;Second cntl-C, ignore
  set in_brk 1
  cursor x_brk,y_brk
  pos 0,19
  savline brk1
  print "~"
  savline brk2
  print "~"
  savline brk3
  box 23,19 60,21
  pos 25,20
  print MSG05
break_2
  echo off
  set status 0
  input 1 temp
  set result 0
  if temp  = YES_KEY set result 2
  if temp  = YES_LOW set result 2
  if temp  = NO_KEY set result 3
  if temp  = NO_LOW set result 3
  if result = 0 goto break_2
  echo on	
  pos 0,19
  print BRK1 "~"
  print BRK2 "~"
  print BRK3 "~"
  pos x_brk,y_brk
  if result = 2 goto abort
  set status -23
  set in_brk 0
  return

abort
  print "~~~"
  print MSG01 "~~~~"
  cd "\"
  stop

door_ajar 	;Sets status to -24 if door found open
  cursor x_aja,y_aja
  pos 0,19
  savline aja1
  print "~"
  savline aja2
  print "~"
  savline aja3
  box 23,19 70,21
  pos 25,20
  print MSG04
ajar_2
  echo off
  set status 0
  input 1 temp
  set result 0
  if temp  = YES_KEY set result 2
  if temp  = YES_LOW set result 2
  if temp  = NO_KEY set result 3
  if temp  = NO_LOW set result 3
  if result = 0 goto ajar_2
  echo on	
  pos 0,19
  print aja1 "~"
  print aja2 "~"
  print aja3 "~"
  pos x_aja,y_aja
  if result = 3 goto abort
  set status -24
  return

any_key
  cursor any_x,any_y
  pos 43,22
  print MSG07
  echo off
  set status 0
  input 1 dummy
  echo on
  if status = -23 goto any_key
  pos 1,22
  print blankline
  pos any_x,any_y
  return

status_bar
  cursor status_x,status_y
  pos 0,22
  print errmsg
  pos status_x,status_y
  return

status_clear
  cursor status_x,status_y
  pos 0,22
  print blankline
  pos status_x,status_y
  return

yesno		;Return result= 1-No input, 2-Yes, 3-No
  cursor yes_x,yes_y
  echo off
  set status 0
  input 1 temp
  pos yes_x,yes_y
  set result 0
  if status = -23 goto yesno
  if temp  = YES_KEY set result 2
  if temp  = YES_LOW set result 2
  if temp  = NO_KEY set result 3
  if temp  = NO_LOW set result 3
  if temp  = "" set result 1
  if result = 0 goto yesno
  echo on	
  return
