/*
 *   FILE:
 *      EXAMPLE1.DAT
 *
 *   DESCRIPTION:
 *      This sample script file shows the general format of a
 *      script file.  The new @ChDir and @ChDrive commands are
 *      also demonstrated in the @Finish/@EndFinish block.
 */

@DefineProject
    @Name     = "VTWD"        /* Product Textual Name */
    @Version  = "1.00"
    @Subdir   = "\\TWXDRV"  /* this is where files are put */
    @OutDrive = @WinDrive
    @Group    = "A"
@EndProject

@DefineVars
  @Qstring @Line = ""
  @QString @MemAddr = "D000-D7FF"
  @Integer @MemResp = 2
  @Integer @TypeResp = 2
  @Integer @Linenum = 1
  @Integer @Retval = 0
  @Integer @ExtCount = 0
@EndVars

@Display
   @Cls

    This program will install @Name Version @Version on your
    computer system and verify the integrity of the distribution
    disk(s). You may press the [Esc] key at any time to abort the
    installation.

    Each question has a default answer.  If the default answer is
    correct, press the ENTER key.  Otherwise, type the answer and
    then press the ENTER key.

    If you make a mistake while typing, press the BACKSPACE key
    and then retype the answer.

@Pause
@EndDisplay

@Display
   @Cls
      This software will be installed on the @OutDrive drive in the
      @SubDir directory.

      @OutDrive:@SubDir

   @Pause
@EndDisplay

/* Get address for card */
BADADDR:
@MemResp = 2
@GetInteger @MemResp
  @Cls
   Please select the number that corresponds to the address
   to be used by the emulation adaptor.  This is the memory
   address location where the emulator card communicates with
   the PC.  If this conflicts with another device, the emulator
   will not work.

          1. C800-CFFF
          2. D000-D7FF
          3. D800-DFFF
          4. E000-E7FF
          5. E800-EFFF

  @Prompt = "Enter value 1 - 5 (Deafult is 2)?"
@EndInteger

@If(@MemResp == 1)
  @MemAddr = "C800-CFFF"
@ElseIf(@MemResp == 2)
  @MemAddr = "D000-D7FF"
@ElseIf(@MemResp == 3)
  @MemAddr = "D800-DFFF"
@ElseIf(@MemResp == 4)
  @MemAddr = "E000-E7FF"
@ElseIf(@MemResp == 5)
  @MemAddr = "E800-EFFF"
@Else
  @GoTo BADADDR
@EndIf

BADTYPE:
@GetInteger @TypeResp
  @Cls
   Please select the number that corresponds to your cable type.

          2. Twinax
          3. Twisted Pair (balun)

  @Prompt = "Enter value 2 or 3 (Deafult is 2)?"
@EndInteger
@If((@TypeResp) != 2 && (@TypeResp !=3))
  @GoTo BADTYPE
@EndIf


@Display
    To use this software your computer must be rebooted.
    After installation please close Windows and reboot
    your computer.


    The install will now proceed. It could take up to 2 minutes
    depending on your system.

@Pause
@EndDisplay

/* check config.sys for EMM386 add exclude statment if possible */
@Retval = @Readln("@BootDrive:\\config.sys", "@@Line")
@Write("@BootDrive:\\CONFIG.TMP", "wt", "@Line\n")
LOOP:
  @Retval = @Readln( , "@@Line")
  @If(@Retval == -1)
    @If(@MemResp != 99)
      @Display
        @Cls

        EMM386 does not appear to be used. If you are using another
        memory manager please make sure the upper memory area used by
        the emulation adaptor is excluded. For example X=@MemAddr

        @Pause
      @EndDisplay
      @Delete("@BootDrive:\\CONFIG.TMP")
    @Else
      @ExtCount = 0
LOOP1:
      @If(@Exists("@BootDrive:\\CONFIG.@ExtCount"))
        @ExtCount = (@ExtCount + 1)
        @GoTo LOOP1
      @EndIf
      @Rename("@BootDrive:\\config.sys", "config.@ExtCount")
      @Rename("@BootDrive:\\config.tmp", "config.sys")
    @EndIF
    @GoTo CONTINUE
  @EndIf
  @If(@StrFind("@StrUpr("@Line")", "REM ") != 0)
    @If(@StrFind("@StrUpr("@Line")", "EMM386") >= 0)
      @If(@StrFind("@StrUpr("@Line")", "X=") >= 0)
        @GetString @Line
          The memory manager must exclude @MemAddr.  Insert
          X=@MemAddr into this line if it is not already there.  A new
          CONFIG.SYS file will be written to the disk.  The old one will
          be saved as CONFIG.00(0-9).
          @Prompt = "@Line"
        @EndString
        @Write(,,"@Line\n")
        @MemResp = 99           //flag emm386 found
      @Else
        @Write(,,"@Line")
        @Write(,," X=@MemAddr\n")
        @MemResp = 99           //flag emm386 found
      @EndIF
    @Else
      @Write(,,"@Line\n")
    @EndIf
  @Else
    @Write(,,"@Line\n")
  @EndIf
  @GoTo LOOP
CONTINUE:

@If("@GetINI("386enh","TwinaxType", "system.ini")" == "")
  @ExtCount = 0
SYSLOOP:
  @If(@Exists("@BootDrive:\\windows\\system.@ExtCount"))
    @ExtCount = (@ExtCount + 1)
    @GoTo SYSLOOP
  @EndIf
  @Copy("@BootDrive:\\windows\\system.ini",
     "@BootDrive:\\windows\\system.@ExtCount")  //save old ini
  @SetINI("386enh","IBMDefaultTwinax", "N", "system.ini")
  @SetINI("386enh","TwinaxAdaptorAddress",@StrMid("@MemAddr",0,4),"system.ini")
  @SetINI("386enh","TwinaxType", "@TypeResp", "system.ini")
  /* add driver to system.ini by rewriting file and adding line */
  @Retval = @Readln("@BootDrive:\\windows\\system.ini", "@@Line")
  @Write("@BootDrive:\\WINDOWS\\SYSTEM.TMP", "wt", "@Line\n")
SLOOP:
  @Retval = @Readln( , "@@Line")
  @If(@Retval != -1)
    @If(@StrFind("@Line", "TwinaxType") >= 0)
      @Write(,,"device=@Outdrive:@SubDir\\VTWD.386\n")  //add line for driver
    @EndIf
    @Write(,,"@Line\n")
    @GoTo SLOOP
  @Else
  //rename tmp file to system.ini
    @Delete("@BootDrive:\\windows\\system.ini")
    @Rename("@BootDrive:\\windows\\system.tmp", "system.ini")
  @EndIf
@Else
  @SetINI("386enh","IBMDefaultTwinax", "N", "system.ini")
  @SetINI("386enh","TwinaxAdaptorAddress", @StrMid("@MemAddr",0,4), "system.ini")
  @SetINI("386enh","TwinaxType", "@TypeResp", "system.ini")
@EndIf

@DefineDisk
   @Label = "VTWD Disk"
   @File 6809FAH.HEX @Out @SubDir\*.*
   @File VTWD.386 @Out @SubDir\*.*
   @File vdtwinx.386 @Out @SubDir\*.*
   @File fixibmca.bat @Out @SubDir\*.*
   @File vtdlcd.386 @Out @SubDir\*.*
   @File fixibmpc.bat @Out @SubDir\*.*

@EndDisk

@Finish


@EndFinish

/* end-of-file */
