OXYGENHUB
◆ main openmsx / doc / manual / openmsx-control.html
10.5 KiB · HTML · last changed chore(): initial commit 1 month ago source blame history raw
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-&lt;username&gt;/socket.&lt;pid&gt;</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\&lt;username&gt;\Local Settings\Temp\openmsx-default\socket.&lt;pid&gt;
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
&lt;openmsx-output&gt;
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>&lt;openmsx-output&gt;</code>).
97
  All messages that are normally printed on stdout in the
98
  terminal from which you start openMSX are in a <code>&lt;log&gt;</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
  &lt;openmsx-control&gt;
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
  &lt;command&gt;set renderer SDL&lt;/command&gt;
118
  </div>
119
120
  <p>
121
  With the <code>&lt;command&gt;</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>&lt;command&gt;</code> will result in a reply from openMSX. In
128
  the above case it will be:
129
  </p>
130
131
<pre>
132
&lt;reply result="ok"&gt;SDL&lt;/reply&gt;
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
&lt;command&gt;biep&lt;/command&gt;
145
&lt;reply result="nok"&gt;invalid command name "biep"
146
&lt;/reply&gt;
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
  &lt;command&gt;openmsx_update enable led&lt;/command&gt;
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
&lt;update type="led" machine="machine1" name="power"&gt;on&lt;/update&gt;
173
</pre>
174
175
  <p>
176
  &lt;update&gt; 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
&lt;update type="hardware" name="machine2"&gt;add&lt;/update&gt;
233
&lt;update type="hardware" machine="machine2" name="carta"&gt;add&lt;/update&gt;
234
&lt;update type="hardware" machine="machine2" name="cartb"&gt;add&lt;/update&gt;
235
&lt;update type="hardware" machine="machine2" name="cassetteplayer"&gt;add&lt;/update&gt;
236
&lt;update type="hardware" machine="machine1" name="diskb"&gt;remove&lt;/update&gt;
237
&lt;update type="hardware" machine="machine1" name="diska"&gt;remove&lt;/update&gt;
238
&lt;update type="hardware" machine="machine1" name="carta"&gt;remove&lt;/update&gt;
239
&lt;update type="hardware" machine="machine1" name="cartb"&gt;remove&lt;/update&gt;
240
&lt;update type="hardware" machine="machine1" name="cartc"&gt;remove&lt;/update&gt;
241
&lt;update type="hardware" machine="machine1" name="cassetteplayer"&gt;remove&lt;/update&gt;
242
&lt;update type="hardware" name="machine1"&gt;remove&lt;/update&gt;
243
&lt;update type="hardware" name="machine2"&gt;select&lt;/update&gt;
244
</pre>
245
246
  <p>CAPS LED went to OFF:</p>
247
248
<pre>
249
&lt;update type="led" machine="machine2" name="caps"&gt;off&lt;/update&gt;
250
</pre>
251
252
  <p>A tape was inserted in the cassette player:</p>
253
254
<pre>
255
&lt;update type="media" machine="machine2" name="cassetteplayer"&gt;/home/manuel/msx-soft/tapes/Zoids.zip&lt;/update&gt;
256
</pre>
257
258
  <p>The cassetteplayer got into play mode:</p>
259
260
<pre>
261
&lt;update type="status" machine="machine2" name="cassetteplayer"&gt;play&lt;/update&gt;
262
</pre>
263
264
  <p>Someone plugged in a joystick:</p>
265
266
<pre>
267
&lt;update type="plug" machine="machine2" name="joyporta"&gt;msxjoystick1&lt;/update&gt;
268
</pre>
269
  <p>And unplugged it again:</p>
270
271
<pre>
272
&lt;update type="plug" machine="machine2" name="joyporta"&gt;&lt;/update&gt;
273
</pre>
274
275
  <p>The maxframeskip setting was set to 12:</p>
276
277
<pre>
278
&lt;update type="setting" name="maxframeskip"&gt;12&lt;/update&gt;
279
</pre>
280
281
  <p>openMSX got paused:</p>
282
283
284
<pre>
285
&lt;update type="status" name="paused"&gt;true&lt;/update&gt;
286
</pre>
287
  <p>openMSX entered a debug break state:</p>
288
<pre>
289
&lt;update type="status" machine="machine1" name="cpu"&gt;suspended&lt;/update&gt;
290
</pre>
291
  <p>openMSX exited the debug break state:</p>
292
<pre>
293
&lt;update type="status" machine="machine1" name="cpu"&gt;running&lt;/update&gt;
294
</pre>
295
296
  <p>A Philips NMS-1205 Music Module was inserted:</p>
297
298
<pre>
299
&lt;update type="sounddevice" machine="machine2" name="Philips NMS 1205 Music Module MSX-Audio 8-bit DAC"&gt;add&lt;/update&gt;
300
&lt;update type="connector" machine="machine2" name="audiokeyboardport"&gt;add&lt;/update&gt;
301
&lt;update type="sounddevice" machine="machine2" name="Philips NMS 1205 Music Module MSX-Audio DAC"&gt;add&lt;/update&gt;
302
&lt;update type="sounddevice" machine="machine2" name="Philips NMS 1205 Music Module MSX-Audio"&gt;add&lt;/update&gt;
303
&lt;update type="extension" machine="machine2" name="Philips_NMS_1205"&gt;add&lt;/update&gt;
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>