This bug is somehow related to the bug #472.
The console "plug" command plugs a device to a port without unplugging one that is already there.
That is mechanically impossible on the real MSX computer. The port will always stay idle for some time while one device is disconnected and a new one is connected. The lack of this disconnection step causes the autodetection algorithms to fail.
To reproduce the problem, run the same JOYTEST.COM utility that is attached to the bug #442, and try the following steps bellow:
1) Run Joytest v2.2 on MSX-DOS
2) open the openMSX console
3) type "plug joyporta mouse"
4) Move the mouse for some seconds to check that it's working, then leave it idle.
5) type "plug joyporta joymega"
The Joytest will fail to detect that the mouse was changed to a megadrive joypad and will keep showing "MSX mouse" as the device connected to the port. On a real MSX, it will always detect this change properly because the mechanical requirement of disconnecting/connecting devices.
You're right, on real hardware it's not possible to infinitely fast switch the device that's plugged into the MSX.
But I'm not sure what to do about this. If you want you can of course first execute the 'unplug' command before executing 'plug' with the new peripheral. But not requiring an explicit 'unplug' is very convenient. Alternatively we can artificially add some delay between the moment the 'plug' command is given and the moment the peripheral is actually inserted, but then this would be annoying for e.g. Tcl scripting.
The same (or similar) issue exists for swapping disks. And for disks there are already Tcl scripts that rely on the 'diska' command immediately inserting the disk (typically in combination with the 'diskmanipulator' command).
Humm. What about a small delay? (1/2 second seems enough) Would that be too annoying for TCL scripting?
Last edit: SD Snatcher 2013-07-17
It's certainly possible to add a small delay. But I'm hesitant to implement this for the following reasons:
Anyway, the specific problems are not that important. The summary is that it does add complexity and that there already is an easy workaround.
[I'm mostly guessing in this paragraph] I also wonder if this feature 'really' solves your problem. E.g. what if the mouse/joymega is already plugged before the joytest program starts? Shouldn't the prog be able to correctly detect the device in that situation? And how is that situation different from your original scenario. Or in other words: why does the detection algorithm depend on the history (while that same history is not available when joytest starts)?
Ok, I'll explain my side so we can try to find a compromise solution.
I'm currently developing a library to with the following objectives:
1) Help MSX gamers to use the joyport based devices transparently and with proper hot plug/unplug, or
2) To fix existing games as they panic if a Mouse (or any other device with a different protocol) is left connected to the joyport
3) To fix program/games that panic because the Mouse was disconnected and require a reset (like Graph Saurus)
Joytest is just the example application that will be given with the library.
On the MSX programmer side, it is implemented like this:
3-Line Handshake protocol, used by the rest of Sega Saturn joyport devices and the Megadrive Multi-Tap
The program starts on the "Standard Joystick/unconnected" state. This state reads normal MSX joysticks
On the openMSX side, what about having low-level (meant for scripts) and high-level (meant for users) commands? Something like:
Would that be a plausible solution? Maybe this approach could solve the disk problem you mentioned too.
The good thing with this approach is that it seems to give solutions for both the "Gamer" and the "openMSX Developer" use cases, which are very different.
btw, I always consider that openMSX have three main groups of different users with very different requirements. Please check if I captured this correctly:
1) Plain user/Gamers (just want an easy to use platform to play games/programs without worrying about the details. Don't want to waste time with configurations, command line parameters or investigating why a given MSX software or the emulator isn't working as expected)
2) MSX Developer (wants all possible details on the MSX inner working, and any features that help him to figure out bugs quickly. For him the emulator is just another developer tool, so he doesn't want to invest more time on it than on the MSX coding itself)
3) openMSX Developer (wants to deal only with openMSX code & scripts, with minimal Z80 coding. Treats the MSX programs (including the BIOS) as a black box surrounded by the emulator. He wants the emulator to be as fast as possible, easy to maintain and with good scripting support. Doesn't want its code to become inefficient or impossible to maintain.)