openmsx-control.html 10 KB

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