| 1 |
<!DOCTYPE html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<link title="Purple" rel="stylesheet" href="manual-purple.css" |
| 6 |
type="text/css"> |
| 7 |
<link title="Minty" rel="alternate stylesheet" href= |
| 8 |
"manual-minty.css" type="text/css"> |
| 9 |
<link title="Plain" rel="alternate stylesheet" href="manual.css" |
| 10 |
type="text/css"> |
| 11 |
<title>Controlling openMSX from External Applications</title> |
| 12 |
</head> |
| 13 |
|
| 14 |
<body> |
| 15 |
<h1>Controlling openMSX from External Applications</h1> |
| 16 |
|
| 17 |
<h2>Introduction</h2> |
| 18 |
|
| 19 |
<p>Despite that openMSX now has an internal GUI that can control most of the |
| 20 |
emulator's functionality, it is still possible for debugger GUIs, launcher |
| 21 |
GUIs, etc., to be external programs that control openMSX. This document |
| 22 |
explains you how you can control openMSX from your own application.</p> |
| 23 |
|
| 24 |
<div class="note"> |
| 25 |
Note: This document was written for developers who are interested in writing their own application that |
| 26 |
controls openMSX, rather than normal end-users. |
| 27 |
</div> |
| 28 |
|
| 29 |
<div class="note"> |
| 30 |
Disclaimer: it is possible that some update events are still missing and it |
| 31 |
is also possible that the structure of the replies and commands change. We |
| 32 |
will do our best to be backwards compatible, though. |
| 33 |
</div> |
| 34 |
|
| 35 |
<h2>Connecting</h2> |
| 36 |
|
| 37 |
<p>There are multiple ways to connect to openMSX. The first (and oldest) way |
| 38 |
is using a pipe. Non-Windows systems use <code>stdio</code>, in Windows you can use a named pipe. |
| 39 |
To enable this, start openMSX like this:</p> |
| 40 |
|
| 41 |
<div class="commandline"> |
| 42 |
openmsx -control stdio |
| 43 |
</div> |
| 44 |
|
| 45 |
<p>or for Windows:</p> |
| 46 |
|
| 47 |
<div class="commandline"> |
| 48 |
openmsx -control pipe |
| 49 |
</div> |
| 50 |
|
| 51 |
<p>The second method is using a socket. Connecting on non-Windows systems |
| 52 |
is done with a UNIX domain socket. openMSX puts the socket in |
| 53 |
<code>/tmp/openmsx-<username>/socket.<pid></code>. The |
| 54 |
<code>/tmp/</code> dir can be overridden by environment variables |
| 55 |
<code>TMPDIR</code>, <code>TMP</code> or <code>TEMP</code> (in that order). |
| 56 |
</p> |
| 57 |
|
| 58 |
<p>On Windows (which does not support UNIX domain sockets), the socket is a |
| 59 |
normal TCP socket. The port number is random between 9938 and 9958. This is done |
| 60 |
to enforce applications to deal with multiple running openMSX processes. The |
| 61 |
port number will be put in the following text file:</p> |
| 62 |
|
| 63 |
<div class="commandline"> |
| 64 |
%USERPROFILE%\Documents and Settings\<username>\Local Settings\Temp\openmsx-default\socket.<pid> |
| 65 |
</div> |
| 66 |
|
| 67 |
<p>or, when <code>%USERPROFILE%</code> does not exist:</p> |
| 68 |
|
| 69 |
<p> |
| 70 |
<code>%TMPDIR%\openmsx-default</code>, or<br/> |
| 71 |
<code>%TMP%\openmsx-default</code>, or<br/> |
| 72 |
<code>%TEMP%\openmsx-default</code>, or as a last resort:<br/> |
| 73 |
<code>C:\WINDOWS\TEMP</code> |
| 74 |
</p> |
| 75 |
|
| 76 |
<p>After connecting, openMSX expects XML input on the channel and it will |
| 77 |
also give you output. This is explained in the next section.</p> |
| 78 |
|
| 79 |
<h2>Communication</h2> |
| 80 |
|
| 81 |
<p> |
| 82 |
After connecting, openMSX expects XML input on the channel (pipe or socket) |
| 83 |
and it will also give you output in XML format. The first output it gives is this: |
| 84 |
</p> |
| 85 |
|
| 86 |
<pre> |
| 87 |
<openmsx-output> |
| 88 |
</pre> |
| 89 |
|
| 90 |
<p>On non-Windows systems you can easily try it out by just starting openMSX |
| 91 |
via the <code>stdio</code> method, as explained above. You give XML |
| 92 |
commands via the keyboard in the terminal and openMSX will print its |
| 93 |
responses on the terminal as well. |
| 94 |
</p> |
| 95 |
|
| 96 |
<p>This first output is the opening tag (<code><openmsx-output></code>). |
| 97 |
All messages that are normally printed on stdout in the |
| 98 |
terminal from which you start openMSX are in a <code><log></code> tag. |
| 99 |
The level can be "info" or "warning" and the message is in the text node |
| 100 |
itself. |
| 101 |
</p> |
| 102 |
|
| 103 |
<p> |
| 104 |
When you want to start communicating back, you <em>always</em> have to start |
| 105 |
with the opening tag first: |
| 106 |
</p> |
| 107 |
|
| 108 |
<div class="commandline"> |
| 109 |
<openmsx-control> |
| 110 |
</div> |
| 111 |
|
| 112 |
<p> When starting openMSX with the <code>-control</code> option, it will not show a |
| 113 |
window: it starts with the 'none' renderer. So, a nice example (if you're |
| 114 |
still experimenting on the command line) would be to type this:</p> |
| 115 |
|
| 116 |
<div class="commandline"> |
| 117 |
<command>set renderer SDL</command> |
| 118 |
</div> |
| 119 |
|
| 120 |
<p> |
| 121 |
With the <code><command></code> tag you can give any openMSX console |
| 122 |
command to openMSX. The commands are documented in the <a class="external" |
| 123 |
href="commands.html">Console Commands Reference</a>. |
| 124 |
</p> |
| 125 |
|
| 126 |
<p> |
| 127 |
Every <code><command></code> will result in a reply from openMSX. In |
| 128 |
the above case it will be: |
| 129 |
</p> |
| 130 |
|
| 131 |
<pre> |
| 132 |
<reply result="ok">SDL</reply> |
| 133 |
</pre> |
| 134 |
|
| 135 |
<p> |
| 136 |
The order is maintained, i.e. the replies will be in the same order as |
| 137 |
the commands you gave to openMSX. In this reply example, you see that |
| 138 |
the command succeeded (result=ok) and it also gives you the actual result |
| 139 |
text that would be printed on the console. In this case, the value of |
| 140 |
the renderer setting. When a command fails, you get something like this: |
| 141 |
</p> |
| 142 |
|
| 143 |
<pre> |
| 144 |
<command>biep</command> |
| 145 |
<reply result="nok">invalid command name "biep" |
| 146 |
</reply> |
| 147 |
</pre> |
| 148 |
|
| 149 |
<p> |
| 150 |
"biep" is not a valid command, and openMSX tells you this via a "nok" reply |
| 151 |
with the error message in the text node. |
| 152 |
</p> |
| 153 |
|
| 154 |
<p> |
| 155 |
The next important thing is events. When you use this interface to control |
| 156 |
openMSX, you want to know when things change. For this, you can enable events |
| 157 |
for certain event classes. |
| 158 |
</p> |
| 159 |
|
| 160 |
<p>An example:</p> |
| 161 |
|
| 162 |
<div class="commandline"> |
| 163 |
<command>openmsx_update enable led</command> |
| 164 |
</div> |
| 165 |
|
| 166 |
<p> |
| 167 |
This command will enable updates about LED events. When a LED changes, you'll |
| 168 |
get messages such as: |
| 169 |
</p> |
| 170 |
|
| 171 |
<pre> |
| 172 |
<update type="led" machine="machine1" name="power">on</update> |
| 173 |
</pre> |
| 174 |
|
| 175 |
<p> |
| 176 |
<update> tags are openMSX's way of telling you that something |
| 177 |
changed. In this case, it is a LED update, for the machine with ID |
| 178 |
"machine1". The name of the LED is "power" and the value is in the text node: |
| 179 |
on. |
| 180 |
</p> |
| 181 |
|
| 182 |
<p>Here is a list of the currently available event types and when they are sent:</p> |
| 183 |
|
| 184 |
<table> |
| 185 |
<tr> |
| 186 |
<td><code>hardware</code></td> |
| 187 |
<td>hardware changes occurred, like a change of machine</td> |
| 188 |
</tr> |
| 189 |
<tr> |
| 190 |
<td><code>led</code></td> |
| 191 |
<td>LED status changed</td> |
| 192 |
</tr> |
| 193 |
<tr> |
| 194 |
<td><code>media</code></td> |
| 195 |
<td>media (disk images, cartridges, etc.) changed</td> |
| 196 |
</tr> |
| 197 |
<tr> |
| 198 |
<td><code>plug</code></td> |
| 199 |
<td>a pluggable got plugged or unplugged (empty value)</td> |
| 200 |
</tr> |
| 201 |
<tr> |
| 202 |
<td><code>setting</code></td> |
| 203 |
<td>the value of a setting changed</td> |
| 204 |
</tr> |
| 205 |
<tr> |
| 206 |
<td><code>setting-info</code></td> |
| 207 |
<td>the properties of a setting changed (e.g. number of options changed)</td> |
| 208 |
</tr> |
| 209 |
<tr> |
| 210 |
<td><code>status</code></td> |
| 211 |
<td>status changed, currently only pause and debug break status</td> |
| 212 |
</tr> |
| 213 |
<tr> |
| 214 |
<td><code>extension</code></td> |
| 215 |
<td>extensions changed (add/remove)</td> |
| 216 |
</tr> |
| 217 |
<tr> |
| 218 |
<td><code>sounddevice</code></td> |
| 219 |
<td>sounddevices changed (add/remove)</td> |
| 220 |
</tr> |
| 221 |
<tr> |
| 222 |
<td><code>connector</code></td> |
| 223 |
<td>connectors changed (add/remove)</td> |
| 224 |
</tr> |
| 225 |
</table> |
| 226 |
|
| 227 |
<h3>Update Examples</h3> |
| 228 |
|
| 229 |
<p>Someone changed machines from Boosted MSX2 to Toshiba HX-10 at run time:</p> |
| 230 |
|
| 231 |
<pre> |
| 232 |
<update type="hardware" name="machine2">add</update> |
| 233 |
<update type="hardware" machine="machine2" name="carta">add</update> |
| 234 |
<update type="hardware" machine="machine2" name="cartb">add</update> |
| 235 |
<update type="hardware" machine="machine2" name="cassetteplayer">add</update> |
| 236 |
<update type="hardware" machine="machine1" name="diskb">remove</update> |
| 237 |
<update type="hardware" machine="machine1" name="diska">remove</update> |
| 238 |
<update type="hardware" machine="machine1" name="carta">remove</update> |
| 239 |
<update type="hardware" machine="machine1" name="cartb">remove</update> |
| 240 |
<update type="hardware" machine="machine1" name="cartc">remove</update> |
| 241 |
<update type="hardware" machine="machine1" name="cassetteplayer">remove</update> |
| 242 |
<update type="hardware" name="machine1">remove</update> |
| 243 |
<update type="hardware" name="machine2">select</update> |
| 244 |
</pre> |
| 245 |
|
| 246 |
<p>CAPS LED went to OFF:</p> |
| 247 |
|
| 248 |
<pre> |
| 249 |
<update type="led" machine="machine2" name="caps">off</update> |
| 250 |
</pre> |
| 251 |
|
| 252 |
<p>A tape was inserted in the cassette player:</p> |
| 253 |
|
| 254 |
<pre> |
| 255 |
<update type="media" machine="machine2" name="cassetteplayer">/home/manuel/msx-soft/tapes/Zoids.zip</update> |
| 256 |
</pre> |
| 257 |
|
| 258 |
<p>The cassetteplayer got into play mode:</p> |
| 259 |
|
| 260 |
<pre> |
| 261 |
<update type="status" machine="machine2" name="cassetteplayer">play</update> |
| 262 |
</pre> |
| 263 |
|
| 264 |
<p>Someone plugged in a joystick:</p> |
| 265 |
|
| 266 |
<pre> |
| 267 |
<update type="plug" machine="machine2" name="joyporta">msxjoystick1</update> |
| 268 |
</pre> |
| 269 |
<p>And unplugged it again:</p> |
| 270 |
|
| 271 |
<pre> |
| 272 |
<update type="plug" machine="machine2" name="joyporta"></update> |
| 273 |
</pre> |
| 274 |
|
| 275 |
<p>The maxframeskip setting was set to 12:</p> |
| 276 |
|
| 277 |
<pre> |
| 278 |
<update type="setting" name="maxframeskip">12</update> |
| 279 |
</pre> |
| 280 |
|
| 281 |
<p>openMSX got paused:</p> |
| 282 |
|
| 283 |
|
| 284 |
<pre> |
| 285 |
<update type="status" name="paused">true</update> |
| 286 |
</pre> |
| 287 |
<p>openMSX entered a debug break state:</p> |
| 288 |
<pre> |
| 289 |
<update type="status" machine="machine1" name="cpu">suspended</update> |
| 290 |
</pre> |
| 291 |
<p>openMSX exited the debug break state:</p> |
| 292 |
<pre> |
| 293 |
<update type="status" machine="machine1" name="cpu">running</update> |
| 294 |
</pre> |
| 295 |
|
| 296 |
<p>A Philips NMS-1205 Music Module was inserted:</p> |
| 297 |
|
| 298 |
<pre> |
| 299 |
<update type="sounddevice" machine="machine2" name="Philips NMS 1205 Music Module MSX-Audio 8-bit DAC">add</update> |
| 300 |
<update type="connector" machine="machine2" name="audiokeyboardport">add</update> |
| 301 |
<update type="sounddevice" machine="machine2" name="Philips NMS 1205 Music Module MSX-Audio DAC">add</update> |
| 302 |
<update type="sounddevice" machine="machine2" name="Philips NMS 1205 Music Module MSX-Audio">add</update> |
| 303 |
<update type="extension" machine="machine2" name="Philips_NMS_1205">add</update> |
| 304 |
</pre> |
| 305 |
|
| 306 |
<p>And with this, you should have all info that you need to make any external |
| 307 |
application that can control openMSX.</p> |
| 308 |
|
| 309 |
<p>More real world examples can be found here:</p> |
| 310 |
|
| 311 |
<ul> |
| 312 |
<li>in the Contrib directory of openMSX (openmsx-control*)</li> |
| 313 |
<li>in the code of (the now deprecated) openMSX Catapult (C++ via pipe)</li> |
| 314 |
<li>in the code of the never released newer openMSX Catapult (Python, still via pipe)</li> |
| 315 |
<li>in the code of the (now deprecated) openMSX GUI Debugger (C++ via socket)</li> |
| 316 |
</ul> |
| 317 |
|
| 318 |
</body> |
| 319 |
</html> |