###   Build Script for Mark Twain 'FF' ROM   ###
#
#  Usage:  BuildFFROM
#
#
# ASSUMPTION:  All subdirectories containing GSFirmware source are in the
# directory containing this script file.
#
# The following Code permits this script to be executed from anywhere,
# and
# for subsidiary scripts to do anything they want to the directory prefixes
# WITHOUT messing up the overall build.
#
# CREDITS: Jim Mensch for the regular expression in the "evaluate" below


set myparent `files -f {Command}`
(evaluate "{myparent}" =~ /(([:]*:)+)1[:]*/ ) > Dev:Null
set myparent "{1}"

IF "{myparent}" == ""
	echo "*** ERROR: Script buildFFROM can NOT determine its home directory!"
	exit
END

set startTime `Date -n`

	directory {myparent}

 	echo " "
 	directory {myparent}SmartPort:
 	BuildProgram {Parameters} SmartPort

	echo " "
	directory {myparent}Applesoft:
	BuildProgram {Parameters} Applesoft

	echo " "
	directory {myparent}Monitor:
	BuildProgram {Parameters} Monitor

	echo " "
	directory {myparent}Diagnostics:
	BuildProgram {Parameters} Diagnostics

	echo " "
	directory {myparent}AD3.5Driver:
	BuildProgram {Parameters} AD35Driver

  	echo " "
  	directory {myparent}Serial:
  	BuildProgram {Parameters} Serial

 	echo " "
 	directory {myparent}ATALK:
	BuildProgram {Parameters} ATALK

echo " "

directory {myparent}
echo Combining the Mark Twain $FF ROM segments
date -a
echo Fill the ROM image with zeros...
filliigs {myparent}ROM:rom.ff -c -s $10000
echo Overlaying Diagnostics...
overlayiigs {myparent}bin:diag.bin {myparent}ROM:rom.ff -a $6400
echo Overlaying Monitor...
overlayiigs {myparent}bin:monitor.bin {myparent}ROM:rom.ff -a $7600
echo Overlaying Serial...
overlayiigs {myparent}bin:C1xx.bin {myparent}ROM:rom.ff -a $C100
overlayiigs {myparent}bin:C2xx.bin {myparent}ROM:rom.ff -a $C200
overlayiigs {myparent}bin:serial.bin {myparent}ROM:rom.ff -a $0000
echo Overlaying AppleTalk...
overlayiigs {myparent}bin:atpatch.bin {myparent}ROM:rom.ff -a $1C06
overlayiigs {myparent}bin:c7xx.bin {myparent}ROM:rom.ff -a $C700
echo Overlaying AD3.5Driver...
overlayiigs {myparent}bin:C5xx.bin {myparent}ROM:rom.ff -a $C500
overlayiigs {myparent}bin:Smartport.bin {myparent}ROM:rom.ff -a $5600
overlayiigs {myparent}bin:AD35drvr.bin {myparent}ROM:rom.ff -a $3400
echo Overlaying Applesoft...
overlayiigs {myparent}bin:Applesoft.bin {myparent}ROM:rom.ff -a $D000
##	echo Finishing up...
##  not in ROM 04 overlayiigs {myparent}bin:appleTwo0.bin {myparent}ROM:rom.ff -a $1000
##  not in ROM 04 overlayiigs {myparent}bin:appleTwo1.bin {myparent}ROM:rom.ff -a $1D00


### Now combine the two 64K pieces into one 128K piece ###
### The FE/FF image is reversed due to hardware design ##

Echo Combine the $FE and $FF banks...
duplicate {myparent}ROM:rom.ff {myparent}ROM:rom.fe.and.ff -y
overlayiigs {myparent}ROM:rom.fe {myparent}ROM:rom.fe.and.ff -a $10000
directory {myparent}

# This executes the tool that calculates and inserts the ROM checksum
# It assumes the input filename is rom.fe.and.ff AND
# it assumes that the $FF bank begins at $00000 and the $FE bank begins at $10000
{myparent}TSCsum {myparent}ROM
date -a

Echo Done!
set endTime `Date -n`

echo " "
echo '# '`Date -t` ----- Build Completed in 
	`Evaluate {endTime} - {startTime}` seconds.

directory {myparent}



