@echo off
	set crisisDrivePresent=false
	set crisisHelpFlag=false
	set crisisParamaterError=false
	set crisisDriveName=A:
	set crisisCopyOnly=false
	set crisisMakeRecovery=false
	set crisisMakeOEMDisk=false
	set crisisMakeFreeDosDisk=false
	set crisisMakeReadOnly=false

	cls

:cdParmLp
	if '%1'=='' goto cdParmCk
	for %%f in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if '%1'=='%%f:' goto cdDrvSet
	for %%f in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if '%1'=='%%f:' goto cdDrvSet
	if '%1'=='/C' goto cdCopyOnly
	if '%1'=='/c' goto cdCopyOnly
	if '%1'=='/R' goto cdMakeRecovery
	if '%1'=='/r' goto cdMakeRecovery
	if '%1'=='/O' goto cdMakeOEMDisk
	if '%1'=='/o' goto cdMakeOEMDisk
	if '%1'=='/F' goto cdMakeFreeDos
	if '%1'=='/f' goto cdMakeFreeDos
	if '%1'=='/X' goto cdMakeReadOnly
	if '%1'=='/x' goto cdMakeReadOnly
	if '%1'=='/?' goto cdFlgSet
	if '%1'=='-?' goto cdFlgSet
	goto cdParmBd


rem======================================================================
rem
rem  Set the Disk drive if specified.
rem
rem======================================================================
:cdDrvSet
	if not '%crisisDrivePresent%'=='false' echo.
	if not '%crisisDrivePresent%'=='false' echo -----     Warning - Extra Paramater "%1" Ignored

	if '%crisisDrivePresent%'=='false' set crisisDriveName=%1
	if '%crisisDrivePresent%'=='false' set crisisDrivePresent=true

	goto cdParmNx

rem======================================================================
rem
rem  Set the Disk Copy Only Flag
rem
rem======================================================================
:cdCopyOnly
	if '%crisisCopyOnly%'=='false' set crisisCopyOnly=true

	goto cdParmNx

rem======================================================================
rem
rem  Set the Disk Make Recovery Flag
rem
rem======================================================================
:cdMakeRecovery
	if '%crisisMakeRecovery%'=='false' set crisisMakeRecovery=true
	set crisisMakeFreeDosDisk=false

	goto cdParmNx

rem======================================================================
rem
rem  Set the Disk Make FreeDos Disk Flag
rem
rem======================================================================
:cdMakeFreeDos
	if '%crisisMakeFreeDosDisk%'=='false' set crisisMakeFreeDosDisk=true
	if '%crisisMakeFreeDosDisk%'=='false' goto cdParmNx
	
	set crisisMakeRecovery=false

	goto cdParmNx

rem======================================================================
rem
rem  Set the Disk Make OEM Disk Flag
rem
rem======================================================================
:cdMakeOEMDisk
	if '%crisisMakeOEMDisk%'=='false' set crisisMakeOEMDisk=true

	goto cdParmNx

rem======================================================================
rem
rem  Set the Disk Make Read-Only Media Flag
rem
rem======================================================================
:cdMakeReadOnly
	if '%crisisMakeReadOnly%'=='false' set crisisMakeReadOnly=true
	if '%crisisMakeReadOnly%'=='false' goto cdParmNx
	
	if '%crisisMakeRecovery%'=='true' set crisisMakeRecovery=false


	goto cdParmNx

rem======================================================================
rem
rem  Set the Disk update mode if specified.
rem
rem======================================================================
:cdFlgSet
	if not '%crisisHelpFlag%'=='false' echo.
	if not '%crisisHelpFlag%'=='false' echo -----     Warning - Extra Paramater "%1" Ignored

	if '%crisisHelpFlag%'=='false' set crisisHelpFlag=true

	goto cdParmNx


rem======================================================================
rem
rem  Display an error message for illegal parameters.
rem
rem======================================================================
:cdParmBd
	echo.
	echo -----     Error - Illegal Parameter "%1"

	set crisisParamaterError=true


rem======================================================================
rem
rem  Check for the next valid paramater.
rem
rem======================================================================
:cdParmNx
	shift

	goto cdParmLp


rem======================================================================
rem
rem  Prevent Disk creation if an error occured.
rem
rem======================================================================
:cdParmCk
	if '%crisisParamaterError%'=='true' goto cdParmSh


rem======================================================================
rem
rem  Display help screen if help is requested.
rem
rem======================================================================
	if '%crisisHelpFlag%'=='true' goto cdParmSh


rem======================================================================
rem
rem  Indicate that the disk will be formated.
rem
rem======================================================================
	if '%crisisCopyOnly%'=='true' goto cdCopyOnly
	if '%crisisMakeFreeDosDisk%'=='true' goto makefreedos
	
	cls

	echo.
	echo.
	echo          -----------------------------------------------------------
	echo.
	echo               The Disk in drive %crisisDriveName% is being formatted
	echo.
	echo          -----------------------------------------------------------
	echo.
	echo.

	if '%crisisMakeRecovery%'=='true' goto nosys
	
	format /q /s %crisisDriveName%
	goto checkresfmt

:nosys
	format /q %crisisDriveName%
	
:checkresfmt

        if ERRORLEVEL 5 goto cdNoProc
        if ERRORLEVEL 4 goto cdFtlFmt
        if ERRORLEVEL 3 goto cdFmtBrk

	goto noraww

:makefreedos	
	cls

	echo.
	echo.
	echo          -----------------------------------------------------------
	echo.
	echo               The Disk in drive %crisisDriveName% is being made
	echo.
	echo          -----------------------------------------------------------
	echo.
	echo.

	rawrite2 -f bootfd.dsk -d %crisisDriveName%
	
:noraww	
	
	echo.
	echo.Press any key to copy the utilities to the Disk...
	pause >nul
	goto cddocopy

:cdCopyOnly
	cls

	echo.
	echo.
	echo          -----------------------------------------------------------
	echo.
	echo               The Disk in drive %crisisDriveName% is being cleared
	echo.
	echo          -----------------------------------------------------------
	echo.
	echo.

	attrib -r -s -h %crisisDriveName%\*.*          >nul 2>nul
	attrib +r +s +h %crisisDriveName%\command.com  >nul 2>nul
	attrib +r +s +h %crisisDriveName%\io.sys       >nul 2>nul
	attrib +r +s +h %crisisDriveName%\msdos.sys    >nul 2>nul
	attrib +r +s +h %crisisDriveName%\kernel.sys   >nul 2>nul
	attrib +r +s +h %crisisDriveName%\drvspace.bin >nul 2>nul
	
	if exist %crisisDriveName%\*.* del %crisisDriveName%\*.* /q
	deldir %crisisDriveName%\97*
	deldir %crisisDriveName%\82*
	deldir %crisisDriveName%\082*
	
rem======================================================================
rem
rem  Copy the utility files to the boot disk in the required order.
rem
rem======================================================================
:cddocopy
	cls

	echo.
	echo.
	echo          -----------------------------------------------------------
	echo.
	echo               The necessary files are being copied to the Disk
	echo.
	echo          -----------------------------------------------------------
	echo.
	echo.

	if '%crisisMakeRecovery%' == 'false' goto normaldisk
	
	 call criscopy minidos.sys
	 if ERRORLEVEL 1 goto cdDiskError
	
	:normaldisk	
	
	call criscopy PHLASH.EXE PLATFORM.BIN BIOS.ROM
	if ERRORLEVEL 1 goto cdDiskError

	if not exist VGABIOS.EXE goto cdnovga

	 call criscopy VGABIOS.EXE
	 if ERRORLEVEL 1 goto cdDiskError

	:cdnovga

	if '%crisisMakeRecovery%' == 'false' goto cdmakeupdate
	
		makeboot %crisisDriveName%
		if ERRORLEVEL 1 goto cdMkBErr
		goto cdMakeMinidosOk
		
		
	:cdmakeupdate

rem assuming this is an update disk not a recover disk then we also need...

	call criscopy UPDATE.BAT GETPARTS.EXE CMPPARTS.EXE SETDENV.BAT CHKMODE.EXE
	if ERRORLEVEL 1 goto cdDiskError

	if '%crisisMakeReadOnly%' == 'true' goto makereadonly

	call criscopy /NORM CONFIG.SYS AUTOEXEC.BAT
	if ERRORLEVEL 1 goto cdDiskError
	goto otherfiles

	:makereadonly
		call criscopy /RDO CONFIG.SYS AUTOEXEC.BAT TDSK.EXE
		
	:otherfiles
	if not exist bb.bin goto cdNoBB
		
		call criscopy FORMBIOS.EXE PLATBB.BIN BB.BIN
		rem ...and the bootblock data directories and files
		call _mvbbd.bat

	:cdNoBB
	
Rem EMO Additions for OEM Support

	if not exist oemcust goto cdnocust
	
		call criscopy OEMCUST PLATOEM.BIN
		if ERRORLEVEL 1 goto cdDiskError

	:cdnocust
	
	if '%crisisMakeOEMDisk%'=='false' goto cdnooem

		call criscopy PLATFBD.BIN
		if ERRORLEVEL 1 goto cdDiskError

	:cdnooem

Rem Radisys Additions for prototype testing

	if not exist PSP goto cdnopsp

	 call criscopy psp
	 if ERRORLEVEL 1 goto cdDiskError

:cdnopsp

Rem Radisys Additions for prototype testing
	if not exist protmnu.bat goto cdnoprot

		call criscopy PROTMNU.BAT CHOOSE.EXE DISPBBT.BAT DISPBBM.BAT DISPBBP.BAT
		if ERRORLEVEL 1 goto cdDiskError

	:cdnoprot

Rem Radisys Additions for checking oem block 1
	if not exist oemb1.bin goto cdnooemb1

		call criscopy platb1.bin oemb1.bin checkenv.bat
		if ERRORLEVEL 1 goto cdDiskError

	:cdnooemb1

	echo.
	echo.Press any key to exit the Disk creation utility...
	pause >nul

rem======================================================================
rem
rem  Signal that the Update Disk has been created.
rem
rem======================================================================
	cls

	echo.
	echo.
	echo          -----------------------------------------------------------
	echo.
	echo               Update diskette on drive %crisisDriveName% successfully created
	echo               Please remove the disk from drive %crisisDriveName%
	echo.
	echo          -----------------------------------------------------------
	echo.

	goto cdclearenv

rem======================================================================
rem
rem  Signal that the Disk has been created.
rem
rem======================================================================
:cdMakeMinidosOk        
	cls

	echo.
	echo.
	echo          -----------------------------------------------------------
	echo.
	echo               Recovery diskette on drive %crisisDriveName% successfully created
	echo               Please remove the disk from drive %crisisDriveName%
	echo.
	echo          -----------------------------------------------------------
	echo.

	goto cdclearenv
	
rem======================================================================
rem
rem  Clear the global variables used by the script file.
rem
rem======================================================================
:cdclearenv
	set crisisDrivePresent=
	if not '%crisisDrivePresent%'=='' goto cdEnvErr

	set crisisHelpFlag=
	if not '%crisisHelpFlag%'=='' goto cdEnvErr

	set crisisDriveName=
	if not '%crisisDriveName%'=='' goto cdEnvErr

	set crisisParamaterError=
	if not '%crisisParamaterError%'=='' goto cdEnvErr

rem======================================================================
rem
rem  Exit from the Disk creation script.
rem
rem======================================================================
	goto cdCrtExt


rem======================================================================
rem
rem  Indicate that the user interrupted the format process.
rem
rem======================================================================
:cdFmtBrk
	echo.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.
	echo Error - The user interrupted while formatting, the
	echo         Disk was not created.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.

	goto cdCrtExt


rem======================================================================
rem
rem  Indicate that there was a disk error during the format process.
rem
rem======================================================================
:cdFtlFmt
	echo.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.
	echo Error - A disk error occured while formatting, the
	echo         Disk was not created.  Check the disk
	echo         for errors or replace the disk with a new 1.44MB
	echo         disk, then try again.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.

	goto cdCrtExt


rem======================================================================
rem
rem  Indicate that the user waived the format process.
rem
rem======================================================================
:cdNoProc
	echo.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.
	echo Error - The user choose not to format the disk, the
	echo         Disk was not created.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.

	goto cdCrtExt

rem======================================================================
rem
rem  Indicate that there was a disk error during the copy process.
rem
rem======================================================================
:cdWrtErr
	echo.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.
	echo Error - A disk error occured while copying "%crisisCurrentFile%",
	echo         the Disk was not created.  Check the
	echo         disk for errors or replace the disk, then try
	echo         again.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.

	goto cdCrtExt

rem======================================================================
rem
rem  Desplay the environment variable allocation error message.
rem
rem======================================================================
:cdEnvErr
	echo.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.
	echo Error - System unable to assign environment variables,
	echo         Increase the main environment space, then try again.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.

	goto cdCrtExt


rem======================================================================
rem
rem  Desplay the boot sector error message.
rem
rem======================================================================
:cdMkBErr
	echo.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.
	echo Error - System unable to create the custom boot sector.
	echo         Check the disk for errors or replace the disk,
	echo         then try again.
	echo.
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo.

	goto cdCrtExt


rem======================================================================
rem
rem  Indicate the correct usage for the batch file.
rem
rem======================================================================
:cdParmSh
	echo.
	echo      #######################################################################
	echo      #                                                                     #
	echo      #     CRISDISK Usage:                                                 #
	echo      #                                                                     #
	echo      #        CRISDISK [DRIVE:] [/? or -?]                                 #
	echo      #                                                                     #
	echo      #           DRIVE    - The drive (A: or B:) where the disk will be    #
	echo      #                      created  (Default is A:)                       #
	echo      #                                                                     #
	echo      #           /? or -? - Display this help screen                       #
	echo      #           /C       - Do not format the disk just copy files.        #
	echo      #           /F       - Generate FreeDos boot disk			#
	echo      #           /O       - Make this an OEM update disk                   #
	echo      #           /R       - Create a recovery disk rather than update disk #
	echo      #           /X       - Disk for ReadOnly media			#
	echo      #                                                                     #
	echo      #######################################################################


rem======================================================================
rem
rem  Exit the batch file.
rem
rem======================================================================
:cdCrtExt
	echo.
	echo.Press any key to return to DOS...
	pause >nul
	echo.
	echo.
:cdDiskError
