rem we are already in the destination directory, 
rem and ka.cnf points to the drive and directory we were installed from
indestdir
rem Make drive letter variables for the benefit of batch files launched by kav
getDriveLetter %HDroot%
set HDdrive %_1%
set CDroot %HDroot%
set CDdrive %HDdrive%
setSrcDir %HDroot%
rem set default values for a few things
set AutoMovie on
set mouseSensitivity 50
set ExtraMemory Automatic
set musicVolume 70
set Printing Detect
set PrinterPort LPT1
set digitizedSound on
set music on
rem Specify where all the text files used in setup live.
set _text insteng
set _yes y
set _no n
err_handler %_text%\errhand.txt
rem
textbox 1 1 80 25 blue
color back cyan
type %_text%\setup.txt 2 2 77 6 -center -border
rem ----------------- select card --------------------
:card
textbox 1 9 80 13 blue
menu %_text%\sound.mnu 20 11 40 12 %_text%\sound.tit %_text%\updown.leg
set soundDriver %_1%
set musicDriver %_2%
set musicType "%_3%"
set soundDevice "%_4%"
set _soundDevice2 "%_5%"
if "%soundDevice%" eq -
	set soundDevice "%_soundDevice2%"
endif
unset _dma
unset _irq
unset _ioPort
textbox 1 9 80 16 blue
switch %_1%
case escape:
	goto exit_unsaved
case sbdig.drv:
	detect_soundBlaster
	setSoundPort
	setMusicPort
case sbpdig.drv:
	detect_soundBlaster
	setSoundPort
	setMusicPort
case pasdig.drv:
	rem proaudio spectrum 16
	rem detect dma and sound blaster io/port settings from config.sys
	detect_spectrum
	set _sb_dma %_2%
	rem if using 16 bit dma, punt and drop back to soundblaster emulation
	if %_dma% > 4
		set soundDriver sbdig.drv
		rem Use value detect_spectrum read from config.sys for dma only
		detect_soundblaster
		set _dma %_sb_dma%
		setSoundPort
	endif
case default:
	rem Explicit defaults
	setSoundPort
	setMusicPort
endswitch
rem
if "%soundDevice%" eq none
	set digitizedSound off
	set music off
endif
type %_text%\settings.txt 1 25 80 1
rem ----------------- copy driver files ------------------
if %soundDriver% ne none
	copy drivers\%soundDriver% sound.drv
endif
if %soundDriver% eq none
	rm sound.drv
endif
if %musicDriver% ne none
	copy drivers\%musicDriver% music.drv
endif
if %musicDriver% eq none
	rm music.drv
endif
rem
rem ----------------- auto music & sound -----------------
rem getenv's argument is case sensitive; usually always uppercase,
rem but windir is lowercase.  That way you can't set it from commandline!
getenv windir
if "%_1%" ne "" 
	rem by golly they're in windows;
	rem don't use the PC Speaker because the driver isn't installed yet
	switch %soundDevice%
	case PCspeaker:
		beep
		goto loop
	case default:
	endswitch
	switch %musicType%
	case pcspkr.drv:
		beep
		goto loop
	case default:
	endswitch
endif
if %digitizedSound% ne off
	color back blue
	color text yellow blink
	type %_text%\psound.txt 20 21 40 1 -center
	color text white
	type %_text%\playing.txt 5 22 70 3 -center
	sound knowledg.voc
endif
if %musicType% ne none
	color back blue
	color text yellow blink
	type %_text%\pmusic.txt 20 21 40 1 -center
	color text white
	type %_text%\playing.txt 5 22 70 3 -center
	music kalogo.%musicType%
endif
:loop
rem ----------------- select function --------------------
color back white
color text black
textbox 1 25 80 1
type %_text%\settings.txt 1 25 80 1
color back cyan
color text white
textbox 1 9 80 16 blue
menu %_text%\main.mnu 20 11 40 9 %_text%\main.tit %_text%\updown.leg
switch %_1%
case exit:
	goto exit
case escape:
	goto card
case card:
	goto card
case music:
	if %musicType% ne none
		color back blue
		color text yellow blink
		type %_text%\pmusic.txt 20 21 40 1 -center
		color text white
		type %_text%\playing.txt 5 22 70 3 -center
		music kalogo.%musicType%
	endif
case sound:
	if %soundDriver% ne none
		color back blue
		color text yellow blink
		type %_text%\psound.txt 20 21 40 1 -center
		color text white
		type %_text%\playing.txt 5 22 70 3 -center
		sound knowledg.voc
	endif
case settings:
	goto settings
endswitch
goto loop
rem
rem ----------------- select i/o adr --------------------
:settings
textbox 1 9 80 16 blue
menu %_text%\io.mnu 20 11 40 12 %_text%\io.tit %_text%\updown.leg
textbox 1 9 80 16 blue
if %_1% eq escape
	goto loop
endif
set _ioPort %_1%
color back white
color text black
textbox 1 25 80 1
type %_text%\settings.txt 1 25 80 1
color back cyan
color text white
rem
rem ----------------- select IRQ --------------------
textbox 1 9 80 16 blue
menu %_text%\irq.mnu 20 11 40 12 %_text%\irq.tit %_text%\updown.leg
textbox 1 9 80 16 blue
if %_1% eq escape
	goto loop
endif
set _irq %_1%
color back white
color text black
textbox 1 25 80 1
type %_text%\settings.txt 1 25 80 1
color back cyan
color text white
rem
rem ----------------- select DMA --------------------
textbox 1 9 80 16 blue
menu %_text%\dma.mnu 20 11 40 10 %_text%\dma.tit %_text%\updown.leg
textbox 1 9 80 16 blue
if %_1% eq escape
	goto loop
endif
set _dma %_1%
rem ----- select done ----
rem copy temporary settings (_ioport, etc.) into real settings (SoundDevParams, etc).
setSoundPort
setMusicPort
goto loop
rem
:exit
rem ---------- set up sound files ---------
saveconfig
rem this section will change for each product!
rem copy the music archive for each zoomscape and kav.
if %musicType% ne none
	textbox 1 9 80 17 blue
	color back blue
	type %_text%\copying3.txt 1 15 80 1 -center
	color back cyan
	copy ka.%musicType% ka.mus
endif
rem ---------- check and modify config.sys ------------
detect_files
set _nfiles %_1%
rem detect_files actually opens files, so it may disagree with config.sys
rem always use files=20, but check for 17 open files
set _needfiles 17
set _setfiles 20
if %_nfiles% < %_needfiles% 
:addfiles
	textbox 1 9 80 17 blue
	type %_text%\files.txt 10 11 63 10 %_text%\files.tit %_text%\yesno.leg
	beep
	waitkey_noesc
	switch %_1%
	case %_yes%:
		set_files %_setfiles%
	case %_no%:
		rem do nothing
	case escape:
		rem do nothing
	case default:
		goto addfiles
	endswitch
	textbox 1 9 80 17 blue
endif
rem ---------- check windows, set up icons, dma, and realsound driver ---------
detect_windows_dir
set _windir %_1%
if %_windir% eq "none"
	goto no_windows
endif
:do_windows
	textbox 1 9 80 17 blue
	type %_text%\windows.txt 10 11 63 9 %_text%\windows.tit %_text%\yesno.leg
	beep
	waitkey_noesc
	switch %_1%
	case %_yes%:
		rem copy files needed by windows code
		copy kagroup.exe %_windir%\kagroup.exe
		copy kagroup.inf %_windir%\kagroup.inf -expand
		rem when setting up windows, only load device driver if needed
		rem perhaps this should be part of menu file rather than special
		rem case code.
		if "%soundDevice%" eq "PCSpeaker"
			copy drivers\vrsd.386 vrsd.386
			setup_windows %_windir% %HDRoot%\vrsd.386
		endif
		if "%soundDevice%" ne "PCSpeaker"
			rem rm vrsd.386
			setup_windows %_windir% 
		endif
	case %_no%:
		rem do nothing
	case escape:
		rem do nothing
	case default:
		goto do_windows
	endswitch
:no_windows
color back black
color text white
textbox 1 1 80 25 black
type %_text%\done.txt 1 1 80 25
rem waitkey
goto final_exit
:exit_unsaved
textbox 1 1 80 25 black
:final_exit
___ENDSCRIPT___

