;************************
;* WinVICE GEMUS Script *
;*   (c) The GB Team    *
;*   16 December 2004   *
;************************
;
; PLEASE SET YOUR EMULATOR PROPERTIES AS FOLLOWS:
;
; Emulator File: XVIC.EXE
; Associated File (1): vice.ini
; Use Short Filenames: YES
; File Types:  D64;T64;G64;G41;TAP;CRT;P00;PRG
;
; This script was written for WinVICE v1.15 but
; may work with other versions too.
;
; Memory configuration is set through the key=value pair:
; memory=x
; where x is: none,all,3k,8k,16k,24k,"0,1,2,3,5" or "04,20,40,60,A0"
; as specified in the VICE manual section 7.2.2.2
; (Note: the Memory Expansion field can not be used by GEMUS)
;
; If the program requires a SYS call to start, then use:
; sys=x
; where x is the starting address as entered from BASIC
; and it will be displayed in a REM statement in the emulator
;
; Multipart cartridges must have the memory locations in the file names.
; The cartridge memory locations are set in the key=value pairs
; cart=A
; cart2=B
; where A and B are 2000,4000,6000,a000 or b000 (or 20,40,60,a0 or b0).
; Single carts may need to have a cart=A value set..

If GameType CONTAINS(d64||t64||g64||g41||tap||crt||prg)

	;set paths to file location for possible image swaps
	Set_INI_Value(1||VIC20||InitialDiskDir||%gamepath%)
	Set_INI_Value(1||VIC20||InitialTapeDir||%gamepath%)
	Set_INI_Value(1||VIC20||InitialCartDir||%gamepath%)
	Set_INI_Value(1||VIC20||InitialAutostartDir||%gamepath%)

	;autostart or 'manual load' the game image
	If Key_cart CONTAINS(*)
		If Key_cart CONTAINS(*20*)
			Add_CLP( -cart2 %gamepath%\*%cart_value%*.*)
		ElseIf Key_cart CONTAINS(*40*)
			Add_CLP( -cart4 %gamepath%\*%cart_value%*.*)
		ElseIf Key_cart CONTAINS(*60*)
			Add_CLP( -cart6 %gamepath%\*%cart_value%*.*)
		ElseIf Key_cart CONTAINS(*a0*)
			Add_CLP( -cartA %gamepath%\*%cart_value%*.*)
		ElseIf Key_cart CONTAINS(*b0*)
			Add_CLP( -cartB %gamepath%\*%cart_value%*.*)
		End If

		If Key_cart2 CONTAINS(*20*)
			Add_CLP( -cart2 %gamepath%\*%cart2_value%*.*)
		ElseIf Key_cart2 CONTAINS(*40*)
			Add_CLP( -cart4 %gamepath%\*%cart2_value%*.*)
		ElseIf Key_cart2 CONTAINS(*60*)
			Add_CLP( -cart6 %gamepath%\*%cart2_value%*.*)
		ElseIf Key_cart2 CONTAINS(*a0*)
			Add_CLP( -cartA %gamepath%\*%cart2_value%*.*)
		ElseIf Key_cart2 CONTAINS(*b0*)
			Add_CLP( -cartB %gamepath%\*%cart2_value%*.*)
		End If

		;autostart or 'manual load' the game image (with SYS call messages)
		If VersionComment CONTAINS(*load manually*)
			;check if a SYS call is needed to start
			If Key_sys CONTAINS(*)
				Add_CLP( -keybuf "REM LOAD MANUALLY THEN START WITH SYS%sys_value%%crlf%")
			Else
				Add_CLP( -keybuf "REM LOAD MANUALLY THEN SOFT RESET TO START%crlf%")
			End If
		Else
			;check if a SYS call is needed to start
			If Key_sys CONTAINS(*)
				Add_CLP( -keybuf "SYS%sys_value%%crlf%")
			End If
		End If

	Else

		;autostart or 'manual load' the game image (with SYS call messages)
		If ImageName CONTAINS(*)
			If VersionComment CONTAINS(*load manually*)
				;check if a SYS call is needed to start
				If Key_sys CONTAINS(*)
					Add_CLP( -keybuf "REM LOAD MANUALLY THENSTART WITH SYS%sys_value%%crlf%")
					Add_CLP2( -autoload "%gamepathfile%:%c64imagename%")
				Else
					Add_CLP( -keybuf "REM YOU MUST LOAD AND START MANUALLY%crlf%")
					Add_CLP2( -autoload "%gamepathfile%:%c64imagename%")
				End If
			Else
				;check if a SYS call is needed to start
				If Key_sys CONTAINS(*)
					Add_CLP( -keybuf "%crlfx2%%crlfx2%SYS%sys_value% PRESS ENTER%crlf%")
					Add_CLP2( -autoload "%gamepathfile%:%c64imagename%")
				Else
					Add_CLP2( -autostart "%gamepathfile%:%c64imagename%")
				End If
			End If
		Else
			If VersionComment CONTAINS(*load manually*)
				;check if a SYS call is needed to start
				If Key_sys CONTAINS(*)
					Add_CLP( -keybuf "REM LOAD MANUALLY THENSTART WITH SYS%sys_value%crlf%")
					Add_CLP2( -autoload "%gamepathfile%)
				Else
					Add_CLP( -keybuf "REM YOU MUST LOAD AND START MANUALLY%crlf%")
					Add_CLP2( -autoload "%gamepathfile%)
				End If
			Else
				;check if a SYS call is needed to start
				If Key_sys CONTAINS(*)
					Add_CLP( -keybuf "%crlf%%crlfx2%%crlfx2%%crlfx2%SYS%sys_value% PRESS ENTER%crlf%")
					Add_CLP2( -autoload "%gamepathfile%")
				Else
					Add_CLP2( -autostart "%gamepathfile%")
				End If
			End If
		End If
	End If

	;do we want a PAL or NTSC setup?
	If PalNTSC = NTSC
		Add_CLP( -ntsc)
	Else
		Add_CLP( -pal)
	End If

	;settings for expanded memory
	If Key_memory CONTAINS(*)
		Add_CLP( -memory %memory_value%)
	Else
		Add_CLP( -memory none)
	End If

	;set the game controls
	;0=None, 1=Numpad + RCtrl, 2=Keyset A, 3=Keyset B, 4+ are for real joysticks/pads;
	If %gamefile% CONTAINS(*)
		If Control = JoyPort2
			Add_CLP( -joydev2 4)
			If NumPlayers > 1
				Add_CLP( -joydev3 4)
			Else
				Add_CLP( -joydev2 4)
			End If
		ElseIf Control = JoyPort1
			Add_CLP( -joydev2 4)
			If NumPlayers > 1
				Add_CLP( -joydev2 4)
			Else
				Add_CLP( -joydev2 4)
			End If
		Else
			Add_CLP( -joydev1 4)
			Add_CLP( -joydev2 4)
		End If
	End If

	;unsupported game controls
	If Control = PaddlePort1
		Show_Message(This emulator does not have Paddle emulation.%crlfx2%This game may be uncontrollable/unplayable.)
	ElseIf Control = PaddlePort2
		Show_Message(This emulator does not have Paddle emulation.%crlfx2%This game may be uncontrollable/unplayable.)
	End If

	;give the user a warning message?
	If VersionComment CONTAINS(*use real C64*)
		Show_Message(This game may not work properly with this emulator.%crlfx2%See Version Comment for more info.)
	End If
	If VersionComment CONTAINS(*not 100%*||*not working*||*doesn't work*)
		Show_Message(This game may not work properly.)
	End If
	If VersionComment CONTAINS(*load manually*)
		Show_Message(You must load this game manually within the emulator.%crlfx2%Game file: %gamepathfile%)
	End If
	If VersionComment CONTAINS(*PET Emulator*)
		Show_Message(Use PET Emulator to run this game.)
	End If
	;-------------------
	;true drive emulation (vtde=yes is for VICE only, not CCS64)
	;set GEMUS key "vtde" to overrule database TrueDriveEmu settings
	If Key_vtde CONTAINS(yes||on||true||1)
		Add_CLP( -truedrive)
	ElseIf Key_vtde CONTAINS(no||no*||off|false||0)
		Add_CLP( +truedrive)
	ElseIf TrueDriveEmu = YES
		Add_CLP( -truedrive)
	Else
		Add_CLP( +truedrive)
	End If
	;---------------------
	;run the emulator
	Run_Emulator()

Else

	;invalid game file type
	Show_Message(GAME_NOT_SUPPORTED%crlfx2%Supported types: D64, T64, G64/G41, TAP, CRT, PRG, P00)

End If

