commanderx16 / x16-emulator

Emulator for the Commander X16 8-bit computer
383 stars 60 forks source link

Match mouse position in emulator window with host position #376

Open mist64 opened 2 years ago

mist64 commented 2 years ago

@MCPEmaniac:

At times I can't seem to move the mouse to certain portions of the screen. This occurs somewhat randomly and the inaccessible portion of the screen also seems somewhat random. I've noticed this in other applications posted to the download page of the official Commander X16 website as well as my own application. I noticed this problem can sometimes be solved by moving the mouse all the way the left, right, top, and bottom sides of the entire monitor screen and then moving the mouse back inside of the emulator window.

This is a limitation of the emulator. A physical mouse only sends horizontal and vertical move events, no absolute positions. Once the Windows/Mac/Linux mouse pointer is above the emulator window, the emulator sends these events to the X16 and its mouse driver, but it can't communicate from which side you entered the emulator window or where the mouse pointer would be in respect to the emulator window.

That said, the following hack would probably work for the emulator: Whenever the mouse enters the emulator window, it should send the following mouse events:

indigodarkwolf commented 2 years ago

If the emulator were somehow aware of the expected address in memory where the kernal stores the mouse pointer location, it could perform a compare between that and the mouse's current position over the emulator window, and send position deltas to try and catch up. This could even be apply scaling of the emulator window.

I could see this feeling like an overall improvement in behavior, though this would result in the emulator mouse always appearing to trail behind the OS mouse by at least 1 frame (possibly more on extreme movements). But it means the ROM would need to make the memory location of mouse pointers a fixed location that can't change between ROM versions and builds.

akumanatt commented 2 years ago

I think the best solution here is just to capture the mouse or implement separate tablet input device. The problem here is there's no way to guarantee that the emulated mouse will behave as you expected. What if it doesn't stick to the edge of the screen? What if it can't communicate back the current position because that memory location is used for something else in apps that doesn't use Kernal?

mist64 commented 2 years ago

A (systemic) problem with the emulator (which can be worked around for the most part*) does not warrant implementing a PS/2 table input driver in the ROM.

*The only use case that still be broken with the workaround above would be an application that uses the mouse for dx/dy input (e.g. the camera in a PC FPS game) as opposed to a mouse pointer.