Typing from outside the emulator

By stefz

Expert (81)

stefz's picture

05-09-2023, 13:34

Is it possible to send a text to be typed on an openMSX running machine from outside the emulator?

The reason is that I'm developing some stuff on an external environment and I constantly need to test my code. I have a script that automatically compiles my code and copy the binary file to a "DirAsDisk" directory, but it would be good to be able to add something to the script to automatically tell openMSX to execute the just compiled binary file. That would be just about sending a simple text and a \r to a running machine.

Login or register to post comments

By Manuel

Ascended (19678)

Manuel's picture

05-09-2023, 13:46

Yes, you could pass a command or script file that types something (see type command).

Or you include an autoexec.bas file which runs the program.

By stefz

Expert (81)

stefz's picture

05-09-2023, 14:03

Manuel wrote:

Or you include an autoexec.bas file which runs the program.

Hey Manuel, thanks for your answer.

Actually I'd like to keep the machine running, that's why I think autoexec.bas would not help me in this case – I would have to wait for the whole emulator boot cycle when I save/compile my code.

I see that I can open the console or create a script and use type as you said, but my intention was to tell openMSX to type (or run a script) from outside the emulator, so I could add this to the script that I run to compile my code every time I save it. I don't know if openMSX has some kind of API for doing that. I see that there is a -control option but I'm not sure if it could help me.

By stefz

Expert (81)

stefz's picture

05-09-2023, 14:07

To better explain, I don't want to touch the openMSX window, it will be running on another screen/monitor. I want to tell openMSX to type something in a running machine from a script that I run in my terminal.

By wouter_

Hero (535)

wouter_'s picture

05-09-2023, 14:52

Hi stefz,

Yes, openMSX has an API that allows to do such things.
No, there's not yet an application (using that API) that does exactly what you need.

But developing such an application shouldn't be too hard. You can use this example code as a starting point. Big caveat: this code has NOT been updated to work on windows, only Linux and macOS for now.

This code acts like an openMSX console: you can type commands and you see the result of those commands. But then in an external application instead of in openMSX itself. It implements full bidirectional communication with openMSX: send commands and receive the results.

I think, for your use case, you only need to send commands (from the command line, not from stdin). And you don't care about the results. That means you can drop the largest part of the example which deals with parsing the result.

By stefz

Expert (81)

stefz's picture

05-09-2023, 16:42

That's perfect. I use MacOS so I should have no issues.
I'll try that and post the results here. Thanks in advance.

By Manuel

Ascended (19678)

Manuel's picture

05-09-2023, 17:54

stefz wrote:
Manuel wrote:

Or you include an autoexec.bas file which runs the program.

Hey Manuel, thanks for your answer.

Actually I'd like to keep the machine running, that's why I think autoexec.bas would not help me in this case – I would have to wait for the whole emulator boot cycle when I save/compile my code.

With the proper tricks this can be very fast. You can tell openMSX to run at maximum speed for an amount of MSX time, after starting up.

By stefz

Expert (81)

stefz's picture

05-09-2023, 19:15

Manuel wrote:

With the proper tricks this can be very fast. You can tell openMSX to run at maximum speed for an amount of MSX time, after starting up.

That's good to know, I already managed to do what I wanted, but I will definitely use that when I need.

By stefz

Expert (81)

stefz's picture

05-09-2023, 19:17

Thank you guys. I made a little addition to the code to exit after running a single command, and it's working flawlessly.