<text>
<p class="head">Using Emulators</p>

<h2><a name="1">1. Starting Emulators from <i>jGameBase</i></a></h2>

<p>There are three ways to start an emulator.</p>

<h3><a name="11">1.1 Start executable directly</a></h3>
<p>This is the simplest method of starting an emulator. While defining the emulator (Menu "Emulators") specify the executable of the emulator in the field "Command to execute". This command will be executed with the "fileToRun" as parameter.</p>

<h3><a name="12">1.2 Start via JavaScript</a></h3>
<p>This is the <u>preferred method</u> of starting an emulator. The script has to have the file extension ".sh" and has to reside in the databases "Scripts" directory. The first command line parameter passed to the script is the "fileToRun", but there are many JavaScript variables set. Your script will be prefixed by an include ("Includes/includes.sh)) containing some predefined functions that simplify writing an emulator script.</p>

<p><b>If you write scripts please send them to me so I can include them in the next version of </i>jGameBase</i></b></p>


<p><b>Example script</b>:<br>This script starts the emulator executable "c64" after checking that the file type (extension) is supported and changing the configuration file to use the correct joystick port:</p>

<p>

<pre class="hl"><span class="hl slc">//  PLEASE SET YOUR EMULATOR PROPERTIES AS FOLLOWS:</span>
<span class="hl slc">//  Emulator File: c64.js</span>
<span class="hl slc">//  Emulator configuration file: c64.cfg</span>
<span class="hl slc">//  File Types: &quot;d64;t64&quot;</span>

command <span class="hl sym">=</span> <span class="hl str">&quot;c64&quot;</span><span class="hl sym">;</span>
<span class="hl kwd">Add_CLP</span><span class="hl sym">(</span>command<span class="hl sym">);</span>

<span class="hl slc">// check the file types</span>
<span class="hl kwa">if</span> <span class="hl sym">(</span>itemType<span class="hl sym">.</span><span class="hl kwd">contains</span><span class="hl sym">(</span><span class="hl str">&quot;d64&quot;</span><span class="hl sym">,</span> <span class="hl str">&quot;t64&quot;</span><span class="hl sym">)) {</span>

	<span class="hl slc">// set the item controls</span>
	<span class="hl kwa">if</span> <span class="hl sym">(</span>itemControl <span class="hl sym">===</span> JOYPORT1<span class="hl sym">) {</span>
		<span class="hl slc">// set joystick 1 (&quot;input=1&quot; in the config file)</span>
		<span class="hl kwd">Set_CFG_Value</span><span class="hl sym">(</span>emulatorConfigFile<span class="hl sym">,</span> <span class="hl str">&quot;input&quot;</span><span class="hl sym">,</span> <span class="hl str">&quot;1&quot;</span><span class="hl sym">);</span>
	<span class="hl sym">}</span> <span class="hl kwa">else</span> <span class="hl sym">{</span>
		<span class="hl slc">// set joystick 2</span>
		<span class="hl kwd">Set_CFG_Value</span><span class="hl sym">(</span>emulatorConfigFile<span class="hl sym">,</span> <span class="hl str">&quot;input&quot;</span><span class="hl sym">,</span> <span class="hl str">&quot;2&quot;</span><span class="hl sym">);</span>
	<span class="hl sym">}</span>

	<span class="hl slc">// run the emulator</span>
	<span class="hl kwd">Run_Emulator</span><span class="hl sym">();</span>
<span class="hl sym">}</span> <span class="hl kwa">else</span> <span class="hl sym">{</span>
	<span class="hl slc">// invalid item file type</span>
	<span class="hl kwd">Show_Message</span><span class="hl sym">(</span>NOT_SUPPORTED <span class="hl sym">+</span> <span class="hl str">&quot;</span><span class="hl esc">\n\n</span><span class="hl str">Supported types: D64, T64&quot;</span><span class="hl sym">);</span>
<span class="hl sym">}</span>

</pre>
</p>

<h4><a name="121">1.2.1 Reference of predefined variables, objects and methods</a></h4>

<p>As mentioned above there are predefined variables, objects and methods to simplify writing JavaScript scripts. Please click <a href="symbols/_global_.html">here</a> for the complete reference.</p>

<p><b>As JavaScript can be difficult to debug, you best start by modifying an existing script.<br>
If you encounter problems check the jgamebase.log in the database directory.</b>
</p>

<h3><a name="13">1.3 Start via other script</a></h3>
<p>If no registered script engine for the script file extension is found in Java the script is started directly. This makes it possible to start scripts written in other scripting languages (e.g. BASH, Python, Lua or Ruby). The downside is that these scripts are often not as platform independent as JavaScript. The first command line parameter passed to the script is the "fileToRun", the environment variables set are the same as for JavaScript scripts, but there are no predefined includes.</p>

</text>


<column>
<p>
1. <a href="#1">Starting</a><br>
&nbsp;&nbsp;1.1 <a href="#11">Executable</a><br>
&nbsp;&nbsp;1.2 <a href="#12">JavaScript</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;1.2.1 <a href="#121">Reference</a><br>
&nbsp;&nbsp;1.3 <a href="#13">Other script</a><br><br>
</p>
</column>
