;**************************************************
;
;$VER: MAC Emulation Installer v2.0 (29 Jun 1994)
;
; Title:
;    EMPLANT's MAC Emulation Software Installer
; 
; Description:
;    The Commodore Installer Script for EMPLANT's
;    MAC emulation module software.
;
; Installer script by Jim Drew
;
;**************************************************

(set true 1)
(set false 0)
(set quote "\"")
(set nothing "")
(set WB2 (< 2293760 (getversion "exec.library" (resident)))) ; true if under 2.0

(set mode 0)				;default to 32 bit mode

(set EMPLANT_dir (getassign "EMPLANT"))
(set c_dir (getassign "C"))
(set libs_dir (getassign "LIBS"))
(set fonts_dir (getassign "FONTS"))
(set devs_dir (getassign "DEVS"))
(set s_dir (getassign "S"))

(set Src_c "MacII:MAC_EMU/c/")
(set Src_s "MacII:MAC_EMU/s/")
(set Src_libs "MacII:MAC_EMU/libs/")
(set Src_fonts "MacII:MAC_EMU/fonts/")
(set Src_devs "MacII:MAC_EMU/devs/")
(set Src_main "MacII:MAC_EMU/")
(set Src_Launcher "MacII:MAC_EMU/Launcher/")
(set Src_docs "MacII:MAC_EMU/Documentation/")
(set Src_ROMS "MacII:MAC_EMU/ROM_Images/")
(set Src_Video "MacII:MAC_EMU/Video_Drivers/")
(set Src_Logo "MacII:MAC_EMU/Logos/")
(set Src_ExtIO "MacII:MAC_EMU/Ext_IO/")

(if  (<> EMPLANT_dir nothing)
     (if  (askbool
               (prompt "\n\n\nSome version of the MAC emulation software "
               "already exists in your drawer named: \n\n"
               quote EMPLANT_dir quote
               "\n\nDo you want the update installed over it?")
               (help
               "\n\n\nThe installer has determined that you already have a "
               "some version of the MAC emulation software installed "
               "on your system.  If this is wrong or you want the update "
               "installed elsewhere, select 'NO', otherwise select 'YES'."
               )
               (default 1)
          )
               (set is_update true) 

;else ask where to put software

               (
               (set is_update false)
               (set EMPLANT_dir
               (askdir
                    (prompt "Where would you like the updated software "
                    "installed?\n"
                    "'EMPLANT' will be automatically appended.")
                    (help @askdir-help)
                    (default @default-dest)
               )
               )

               (set EMPLANT_dir
               (tackon EMPLANT_dir "EMPLANT")
               )

               (makedir EMPLANT_dir
               (infos)
               )
          )
     )
)

; EMPLANT: was not previously assigned, so ask where to make it
(if  (= EMPLANT_dir nothing)
          (
          (set EMPLANT_dir
               (askdir
                    (prompt "Where would you like the software installed? "
                    "'EMPLANT' will be automatically appended.")
                    (help @askdir-help)
                    (default @default-dest)
               )
          )

          (set EMPLANT_dir
          (tackon EMPLANT_dir "EMPLANT")
          )

          (makedir EMPLANT_dir
          (infos)
          )
     )
)

          (set EMU_Dir
          (tackon EMPLANT_dir "MAC")
          )

          (makedir EMU_dir
          (infos)
          )

(set @default-dest EMU_dir)

(complete 5)

; ask user to locate SYS:C directory

(set c_dir
     (askdir
          (prompt "Please locate your C: directory.")
          (help @askdir-help)
          (default c_dir)
     )
)
   
(working omp "...Please Wait...")

(copyfiles
     (prompt "Select file(s) to be copied into your C: directory:")
     (help "\n\n\n\n\nThis will copy RsrvMemIII to your C: "
     "directory.\n\n\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_c)
     (dest c_dir)
     (pattern "#?MEM#?")
     (confirm)
)
   
(complete 10)

; ask user to locate LIBS: directory

(set libs_dir
     (askdir
          (prompt "Please locate your LIBS: directory.")
          (help @askdir-help)
          (default libs_dir)
          (newpath)
     )
)

(working omp "...Please Wait...")

(copyfiles
     (prompt "Select file(s) to be copied into your LIBS: directory:")
     (help "\n\n\n\n\nThis will copy the EMPLANT, SYBIL, and "
     "JAM libraries into your system's LIBS: directory.\n\n\n\n\n\n\n"
     @copylib-help)
     (source Src_libs)
     (dest libs_dir)
     (pattern "(#?.library#?)")
     (confirm)
)

(complete 20)

; ask user to locate DEVS: directory

(set devs_dir
     (askdir
          (prompt "Please locate your DEVS: directory")
          (help @askdir-help)
          (default devs_dir)
     )
)
 
(working omp "...Please Wait...")  

(copyfiles
     (prompt "Select file(s) to be copied into your DEVS: directory:")
     (help "\n\n\n\n\nThis will copy the device drivers for the use "
     "with EMPLANT's various I/O ports.\n\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_devs)
     (dest DEVS_dir)
     (pattern "#?")
     (confirm)
)

(complete 30)

; ask user to locate FONTS: directory

(set Fonts_dir
     (askdir
          (prompt "Please locate your FONTS: directory")
          (help @askdir-help)
          (default fonts_dir)
          (newpath)
     )
)

(working omp "...Please Wait...")

(copyfiles
     (prompt "Select file(s) to be copied into your FONTS: directory:")
     (help "\n\n\n\n\nThis will copy over any fonts needed for the "
     "emulation.\n\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_fonts)
     (dest fonts_dir)
     (pattern "(SCAIV#?)")
     (fonts)
     (confirm)
)

(complete 40)

(working omp "...Please Wait...")

; Copy utilities
   
(set EMPLANT_dir
     (copyfiles
          (prompt "Select files to be copied to the EMPLANT: directory:")
          (help "\n\n\n\n\nThis will copy all of the utilities for the "
          "EMPLANT hardware and the MAC emulation.\n\n\n\n\n\n\n"
          @copyfiles-help)
          (source Src_main)
          (dest EMPLANT_dir)
          (pattern "(Conv#?|Diag#?|Dump#?|HardFile#?|ROMINFO|InitRet#?|MAC_HDSetup#?|VBRMover#?)")
          (confirm)
     )
)

(complete 50)

; Copy over the MAC EMULATION programs

(working omp "...Please Wait...")
   
(set EMU_dir
     (copyfiles
          (prompt "Select files to be copied to the EMPLANT:MAC/ directory:")
          (help "\n\n\n\n\n\nThis will copy the MAC emulation's main "
          "programs.\n\n\n\n\n\n\n"
          @copyfiles-help)
          (source Src_main)
          (dest EMU_dir)
          (pattern "(MacII|HardKickMMU|SoftKickMMU)")
          (confirm)
     )
)

;copy AppIcon

(copyfiles
     (source Src_Main)
     (dest EMU_dir)
     (pattern "(EMP_AppIcon.info)")
)

;create Launcher directory

(set Launcher_dir
(tackon EMU_dir "Launcher")
)
   
(makedir Launcher_dir)

(copyfiles
     (source Src_Launcher)
     (dest Launcher_dir)
     (pattern "(launcher.info)")
)

(complete 55)

;create Video_Drivers directory
   
(set VideoDrvr_dir
(cat EMU_dir)
)
(set VideoDrvr_dir
(tackon VideoDrvr_dir "Video_Drivers")
)

(makedir VideoDrvr_dir
(infos)
)

(working omp "...Please Wait...")

(copyfiles
     (prompt "Select file(s) to be copied into your Video_Drivers directory:")
     (help "\n\n\n\n\nThis will copy the video drivers to the proper "
     "directory.  ALL MAC video drivers must reside in your "
     "'\EMPLANT:MAC/Video_Drivers\' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_video)
     (dest VideoDrvr_dir)
     (pattern "(#?)")
     (confirm)
)

(complete 60)

;create ExtIO directory

(set ExtIODrvr_dir
(cat EMU_dir)
)
(set ExtIODrvr_dir
(tackon ExtIODrvr_dir "Ext_IO")
)
 
(makedir ExtIODrvr_dir
(infos)
)

(working omp "...Please Wait...")

(copyfiles
(prompt "Select file(s) to be copied into your Ext_IO directory:")
     (help "\n\n\n\n\nThis will copy the external I/O drivers to the proper "
     "directory.  ALL MAC external I/O drivers must reside in your "
     "'\EMPLANT:MAC/Ext_IO\' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_ExtIO)
     (dest ExtIODrvr_dir)
     (pattern "(#?)")
     (confirm)
)

(complete 65)

;create Logos directory

(set Logos_dir
(cat EMU_dir)
)
(set Logos_dir
(tackon Logos_dir "Logos")
)
 
(makedir Logos_dir
(infos)
)

(working omp "...Please Wait...")

(copyfiles
     (prompt "Select file(s) to be copied into your Logos directory:")
     (help "\n\n\n\n\nThis will copy the boot logos to the proper "
     "directory.  ALL MAC logos must reside in your "
     "'\EMPLANT:MAC/Logos\' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_logo)
     (dest logos_dir)
     (pattern "(#?logo#?)")
     (confirm)
)

(complete 70)

;create Documentation directory

(set Docs_dir
(cat EMU_dir)
)
(set Docs_dir
(tackon Docs_dir "Documentation")
)

(makedir Docs_dir
(infos)
)

(working omp "...Please Wait...")

(copyfiles
     (prompt "Select file(s) to be copied Documentation directory:")
     (help "\n\n\n\nThis will copy various documentation and "
     "IFF pictures to your documentation directory.  ALL MAC emulation "
     "documentation should reside in your "
     "'\EMPLANT:MAC/Documenation\' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_docs)
     (dest Docs_dir)
     (pattern "#?")
     (confirm)
)

(complete 75)

;create ROM_Images directory

(set ROM_dir
(cat EMU_dir)
)
(set ROM_dir
(tackon ROM_dir "ROM_Images")
)

(makedir ROM_dir
(infos)
)

(working omp "...Please Wait...")

(copyfiles
     (prompt "Select ROM Image(s) and Related Files:")
     (help "\n\n\n\n\nThis will copy your ROM image(s) from your "
     "original installation (if applicable).  ALL ROM image files "
     "must be in your '\EMPLANT:MAC/ROM_Images\' directory.\n\n\n\n\n\n"
     @copyfiles-help)
     (source Src_ROMS)
     (dest ROM_dir)
     (pattern "#?")
     (confirm)
)

(complete 80)


; add custom EMPLANT setup caller to Startup-Sequence if 'AssignEMPLANT'
; does not exist yet

(if  (not (exists "s:AssignEMPLANT"))
     (if  (askbool
               (prompt "\nIn order for MAC emulation to work correctly, "
               "the FIRST line in your STARTUP-SEQUENCE must be\n\n"
               "'execute >NIL: s:SetupEMPLANT'\n\n"
               "and the LAST line of your USER-STARTUP must be:\n\n"
               "'execute >NIL: s:AssignEMPLANT'\n\n"
               "These lines can be automatically added by this installer "
               "script.  Do you wish to proceed?\n\n")
               (help @askbool-help)
               )

               (
                    (if (= @pretend 0)
                    (
                        (
                        (if  (not  (exists "s:user-startup"))
                             (textfile
                             (dest "s:user-startup")
                             (append ";user-startup \n\n")
                         )
                    )
                    (textfile
                    (dest "ram:startup-sequence")
                    (append ";BEGIN EMPLANT \n")
                    (append "execute >NIL: s:SetupEMPLANT \n")
                    (append ";END EMPLANT \n")
                    (include "s:startup-sequence")
                    )
                    (rename "s:startup-sequence" "s:startup-sequence.old")
                    (copyfiles
                    (help @copyfiles-help)
                    (source "ram:startup-sequence")
                    (dest "s:")
                    )
                    (delete "ram:startup-sequence")

                    (textfile
                    (dest "ram:user-startup")
                    (include "s:user-startup")
                    (append ";BEGIN EMPLANT \n")
                    (append "execute >NIL: s:AssignEMPLANT \n")
                    (append ";END EMPLANT \n")
                    )
                    (rename "s:user-startup" "s:user-startup.old")
                    (copyfiles
                    (help @copyfiles-help)
                    (source "ram:user-startup")
                    (dest "s:")
                    )
                    (delete "ram:user-startup")
               )
          )
          )
     )
     )
)

;create mini-script files
      
(delete "s:SetupEMPLANT")
(textfile
(dest "s:SetupEMPLANT")
(append "RsrvMemIII >NIL: \n")
)
(delete "s:AssignEMPLANT")
(textfile
(dest "s:AssignEMPLANT")
(append "Assign EMPLANT: " EMPLANT_dir "\n")
)

(complete 85)

(message "\n\n\n\n\n\n"
"Installation of emulation software is complete.  You must now setup "
"the emulation's launcher program for your particular machine."
)

(set filename EMU_dir)

(set machine
     (askchoice
          (prompt "Select the model of Amiga you are using:")
          (help "\n\n\n\n\nSelect the model that closest matches your "
          "system.  If you have an A4000/030 with an MMU added, select "
          "\Amiga 4000/040\.\n\n\n\n\n\n\n\n"
          @askchoice-help)
               (choices "Amiga 2000 + accelerator w/MMU"
               "Amiga 3000 w/HardKick ROMs"
               "Amiga 3000 w/SoftKick ROMs"
               "Amiga 4000/040"
               "Amiga 4000/030"
               "Other Amiga w/o MMU"
               "I don't want to use the MMU!")
          (default 3)
     )
)

(complete 90)

(if  (< machine 4)
     (set mode
          (askchoice
               (prompt "Select the addressing mode for the emulation to use:")
               (help "\nIt is highly recommend that you use this emulation "
               "only with Apple's System 7.1 or later software.  This "
               "requires that the emulation is setup in '32 bit mode'.\n\n"
               "You should only use '24 bit' mode if you are going to be "
               "using any version from System 6 thru System 7.0.1.\n\n"
               "24 bit mode may be required for some older applications."
               "\n\n\n\n\n"
               @askchoice-help)
               (choices "32 bit (System 7.1 and later)"
               "24 bit (System 7.01 and earlier)")
               (default 0)
          )
     )
)

(complete 95)

(if  (< machine 4)
     (if  (<> machine 2)
          (
          (set type "HardKickMMU")
          (set icon_name "HardLaunch_")
          (set flags
               (askoptions
                    (prompt "Setup Launch script options for:\n"
                    "Any Amiga with an MMU & KickStart in ROM")
                    (help "The following features are available with "
                    "the HardLaunch_MAC script:\n\n"
                    "QUIET:\n\n"
                    "Turns off the screen flash when HardLaunch_MAC is "
                    "started up (those of you using long 'beep' samples "
                    "in Preferences will want to select this option.\n\n\n"
                    "\n\n\n\n\n\nREMAP:\n\n"
                    "It is possible to map the EMPLANT's hardware at the "
                    "same memory location as a real MAC's hardware, increasing "
                    "emulation compatibility.  This option may conflict with "
                    "some Zorro III memory boards.\n\n\n"
                    "\n\n\n\n\nFASTROM:\n\n"
                    "The Amiga's Kickstart ROM can be mapped into FAST memory, "
                    "which will result in an overall performance boost to the "
                    "Amiga and EMPLANT's MAC emulation.  This option is highly "
                    "recommended!\n\n\n\n\n"
                    "\n\n\nNOCOPYBACK:\n\n"
                    "Although we know of no programs to date that require this "
                    "option, it exists in case an application can not handle "
                    "the CopyBack mode of the 68040 processor.  It puts the "
                    "processor into 'write-through' mode.\n\n\n\n\n\n\n\n"
                    @askoptions-help)
                    (choices
                    "QUIET      - No screen flash on startup"
                    "REMAP      - Remaps EMPLANT hardware"
                    "FASTROM    - Remaps KickStart into FAST memory"
                    "NOCOPYBACK - Turns off CopyBack mode for 68040s"
                    )
                    (default 6)
               )
          )
          )

;else machine is softkicked
          (
          (set type "SoftKickMMU")
          (set icon_name "SoftLaunch_")
          (set flags
               (askoptions
                    (prompt "Setup Launch script options for:\n"
                    "SoftKick'd A3000")
                    (help "The following features are available with "
                    "the SoftLaunch_MAC script:\n\n"
                    "QUIET:\n\n"
                    "Turns off the screen flash when SoftLaunch_MAC is "
                    "started up (those of you using long 'beep' samples "
                    "in Preferences will want to select this option.\n\n\n"
                    "\n\n\n\n\n\nREMAP:\n\n"
                    "It is possible to map the EMPLANT's hardware at the "
                    "same memory location as a real MAC's hardware, increasing "
                    "emulation compatibility.  This option may conflict with "
                    "some Zorro III memory boards.\n\n\n\n\n\n\n"
                    @askoptions-help)
                    (choices
                    "QUIET      - No screen flash on startup"
                    "REMAP      - Remaps EMPLANT hardware"
                    )
                    (default 2)
                    )
               )
          )
          )

     (
     (set type "NoMMU")
     (set icon_name "EC_Launch_")

     (Message "\n\nA T T E N T I O N ! ! !\n\n\n\n"
     "Since your system will not be using an MMU, it is "
     "recommended that you use the 'QD' video drivers."
     "\n\n")
     )
)

(if  (= mode 0)
     (
     (set icon_name
     (cat icon_name "MAC")
     )
     )
)

(if  (= mode 1)
     (
     (set icon_name
     (cat icon_name "24")
     )
     )
)

(set filename
(tackon filename icon_name)
)

(complete 99)

(set iconify
     (askchoice
          (prompt "Select Startup Option:\n")
          (help "\n\n\nWhen the " icon_name " script file is executed, "
          "the emulation will startup and normally stay at the Emulation "
          "Setup Screen.\n\n"
          "It is possible to skip the setup screen and immediately run "
          "the emulation, and even iconify it at the same time.\n\n\n\n"
          @askchoice-help)
               (choices "Skip Emulation Setup"
               "Skip Emulation Setup & Iconify"
               "Don't Skip Emulation Setup"
               (default 2)
               )
     )
)

;delete file if it once existed.

(delete filename)

(textfile
(dest filename)
(if  (= type "HardKickMMU")
     (append "\n"
     "IF EXISTS " type "\n\n"
     "c:echo " quote "Setting up MMU mirroring system for ROM based machines...." quote "\n\n"
     ";Attention!!  HardKickMMU has 5 different options:\n\n"
     "; -f    Turns on the FASTROM option (remaps KickStart into FAST memory).\n"
     "; -w    Turns off CopyBack mode (turns on write-through, 68040 owners only).\n"
     "; -h    Remaps the EMPLANT hardware to appear at the same memory location\n"
     ";       that the MAC's hardware appears.\n"
     "; -t    Maps 4K pages with MMU for video display refreshing, does not\n"
     ";       mirror memory.  WILL NOT WORK IN 24 BIT MODE!!\n"
     "; -q    Supress screen flash, also known as DisplayBeep().\n\n"
     ";       You can use either upper or lower case letters (ie. -f or -F).\n"
     ";       Options may be in any order.\n\n"
     "HardKickMMU "
     )
     )

(if  (= type "SoftKickMMU")
     (append "\n"
     "IF EXISTS " type "\n\n"
     "c:echo " quote "Setting up MMU mirroring system for SuperKickstart machines...." quote "\n\n"
     ";Attention!!  SoftKickMMU has 2 different options:\n\n"
     "; -h    Remaps the EMPLANT hardware to appear at the same memory location\n"
     ";       that the MAC's hardware appears.\n"
     "; -q    Supress screen flash, also known as DisplayBeep().\n\n"
     ";       You can use either upper or lower case letters (ie. -h or -H).\n"
     ";       Options may be in any order.\n\n"
     "SoftKickMMU "
     )
     )

     (if  (IN flags 0)
     (append "-q ")
     )

     (if  (IN flags 1)
     (append "-h ")
     )

     (if  (IN flags 2)
     (append "-f ")
     )

     (if  (IN flags 3)
     (append "-w ")
     )

     (if  (< machine 4)
          (if  (= mode 0)
          (append "-t ")
          )
     )

     (append "\n\n"
     "c:echo " quote " " quote "\n"
     "c:echo " quote "Running emulation configuration menu...." quote "\n\n"
     "RUN >NIL: <NIL: MACII "
     )

     (if  (= iconify 0)
     (append "-s ")
     )

     (if  (= iconify 1)
     (append "-i ")
     )
     (append "\n\n")
)

(copyfiles
     (source launcher_dir)
     (dest EMU_dir)
     (pattern "Launcher.info")
)

(set oldname
(tackon EMU_dir "launcher.info")
)

(set filename
(cat filename ".info")
)

(rename oldname filename)

(complete 100)

(message "\n\n\n\n"
"A T T E N T I O N ! ! !\n\n"
"You must turn off the power to your Amiga before attempting "
"to run the emulation.  Simply rebooting will NOT work, you "
"MUST physically turn off of the Amiga with its power switch. "
"No exceptions."
)          

(exit)
