Skip to content

Support of Microsoft Serial Mouse on /dev/ttyS1 #1260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
toncho11 opened this issue Feb 20, 2025 · 9 comments
Open

Support of Microsoft Serial Mouse on /dev/ttyS1 #1260

toncho11 opened this issue Feb 20, 2025 · 9 comments

Comments

@toncho11
Copy link

Hi,

Is it possible to add Microsoft Serial Mouse on /dev/ttyS1 ?
I am trying to use mouse in ELKS.

@copy
Copy link
Owner

copy commented Feb 20, 2025

v86 emulates a PS2 mouse, which seems to be supported by elks. I wouldn't mind supporting serial mouse too, but it's probably not very widely used.

@toncho11
Copy link
Author

No. This documentation is completely outdated.
There is experimental support for PS2 mouse on a serial line, not the bios PS2. But this is not the case in copy.sh, right?
So either Microsoft serial mouse or PS2 mouse on a serial line will be welcomed.

@toncho11
Copy link
Author

And why in https://copy.sh/v86/?profile=elks it does say Mouse: No on the right. It should provide PS2 mouse, right?

@SuperMaxusa
Copy link
Contributor

But this is not the case in copy.sh, right?

Do you mean that ELKS supports PS/2 protocol via serial port?

it does say Mouse: No on the right. It should provide PS2 mouse, right?

Yes, it reacts to PS/2 mouse initialization.

v86/src/browser/main.js

Lines 2233 to 2237 in 2996c08

emulator.add_listener("mouse-enable", function(is_enabled)
{
os_uses_mouse = is_enabled;
$("info_mouse_enabled").textContent = is_enabled ? "Yes" : "No";
});

@toncho11
Copy link
Author

toncho11 commented Feb 20, 2025

Yes, PS/2 protocol via serial port (not through the BIOS INT 33h).

@copy
Copy link
Owner

copy commented Feb 21, 2025

I wouldn't mind supporting this, but it's not a high priority.

@ghaerr
Copy link

ghaerr commented Feb 23, 2025

Hi @copy and @SuperMaxusa,

Do you mean that ELKS supports PS/2 protocol via serial port?

Yes. When ELKS is setup for PS/2 mouse, it executes the following code when reading from a serial port:

/*
 * Input routine for PS/2 mouse.
 * Returns nonzero when a new mouse state has been completed.
 */
static int
ParsePS2(int byte)
{
    switch (state) {
        case IDLE:
            if (byte & PS2_CTRL_BYTE) {
                buttons = byte & (PS2_LEFT_BUTTON|PS2_RIGHT_BUTTON);
                state = XSET;
            }
            break;

        case XSET:
            if(byte > 127)
                byte -= 256;
            xd = byte;
            state = YSET;
            break;

        case YSET:
            if(byte > 127)
                byte -= 256;
            yd = -byte;
            state = IDLE;
            return 1;
    }
    return 0;
}

In other words, it parses each byte of the 3-byte PS/2 mouse message read from serial. It could easily be upgraded to the 4-byte version for mice with scroll wheels or five buttons. It doesn't write anything to the mouse.

I wouldn't mind supporting this, but it's not a high priority.

That would be fantastic, thank you! Let me know if need any help from my end.

I recently ported Microwindows to ELKS, and everything is now running, multiple applications drawing in multiple windows, all running 16-bits, see the screenshot below. @toncho11 has tested this with copy/v86 and all is also running except the mouse. At this time, the ELKS kernel doesn't know anything about mice and implementing a hardware PS/2 mouse requires trapping IRQ 12 which isn't allowed for application programs... the Microwindows server performs all the mouse reading/decoding, all from serial on ELKS (and Linux). I would like to add hardware PS/2 mouse support to the ELKS kernel but its a bit complicated and requires more changes that it should. QEMU and 86Box allow serial mouse emulation but we really like how easily copy/v86 boots and runs an OS right from the web.

16-bit ELKS running Nano-X on QEMU
Image

Thank you!

@SuperMaxusa
Copy link
Contributor

Hello @ghaerr, nice to see you! Awesome work, looks really cool!

Let me know if need any help from my end.

I have experimented with ELKS and the serial port and I have a question: is it possible to change a default mouse port for ELKS (mouse utility) and Nano-X?

I tried to export MOUSE_PORT=/dev/ttys1 (on QEMU and v86) but it still uses ttys0 instead of ttys1. My ELKS version is v0.8.1.

In copy.sh/v86, COM0 is used by the terminal by default, so it would be better to use a different COM port.

Thanks!

@ghaerr
Copy link

ghaerr commented Feb 27, 2025

Hello @SuperMaxusa,

Thanks, it's been fun getting Nano-X back running 16-bit.

Yes, it's possible to change /bin/nano-X and /bin/mouse to use the second serial port as you mention using export MOUSE_PORT=/dev/ttyS1 (note the capital S not s). However, you should probably be running ELKS v0.9.0-dev, as there have been some changes made recently in this area. I've attached a ready-to-go 32M bootable ELKS image for you, with the mouse port set to /dev/ttyS1 in /etc/profile. (Login as root, then type "nxstart" to start nano-X).

In copy.sh/v86, COM0 is used by the terminal by default, so it would be better to use a different COM port.

Great, I prefer it that way myself, as in that configuration debug or informative messages will be displayed on /dev/ttyS0 which is routed to the host terminal session, while the mouse operates on /dev/ttyS1. With QEMU, there is otherwise no way to get debug messages to the terminal if the mouse is on /dev/ttyS0.

Internally, there is an ELKS hack that sets QEMU=1 at boot (for qemu only) when it is programmatically found that QEMU is running, and then the mouse port is set to /dev/ttyS1 automatically (unless overridden by MOUSE_PORT=). This aids in getting users running without having to otherwise separately specify MOUSE_PORT=/dev/ttyS1. For copy/v86, we'd just upload an image that has MOUSE_PORT= set and everything should run. I've done that on the attached HD32 image.

hd32-minix.img.zip

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants