The general problem that we face is how to translate the real mouse movement into the emulated mouse movement. You might think at first that this is pretty easy; if the PC mouse is moved by a certain distance, just do the same in the emulation.
However, this does not work for multiple reasons.
- The emulation uses a special screen resolution that may be scaled by changing the emulation window size. Imagine that your host PC screen resolution is full HD (1920x1080); the emulated screen is 256x192 on the TI, or 512x212 on the Geneve. You most likely pulled the window borders to give you a larger display, but it still has the same emulated resolution. Now how is this supposed to be mapped into the emulation?
- The MAME framework has no idea of the resolution of the emulated screen and the screen mode. For instance, on the TI we could use text mode or graphics mode. When we move the mouse in text mode, this is a grid of 40x24 or 80x25 locations. In graphics mode, we can have the full 512x212 on the Geneve.
- The emulated system may have its own way of scaling the mouse movement. Imagine you write a program on the Geneve that uses the mouse, and you want to set the mouse speed. This is no problem; you simply get the mouse movement and calculate the effective movement from it by some factor. How could MAME possibly know that the mouse movement is scaled inside the emulated system? This is not only difficult, it is conceptually impossible.
So when you use the emulation in a window, it is just not possible to map the host mouse movement directly into the emulation so that the emulated mouse and the PC mouse run in sync. In other words, the mouse in the emulation will have its own speed, and if you have a mouse pointer in the emulation, it will not stay together with the host mouse pointer.
The figure on the left illustrates the problem. Suppose that you move a mouse pointer on your host desktop from left to right, crossing the emulation window. You may expect that the mouse movement is seamlessly translated into the emulation. However, we see that the emulation window does not use the same screen resolution as the host desktop, so a movement by 10 positions would seem like a much longer movement inside the emulation.
To make things a bit worse, we have to consider when the emulation is supposed to sample the host mouse movement. At every time, even when you are not using the emulation? Only when you focus the emulation window? - In MAME, the mouse movement is sampled when the host mouse pointer hovers over the emulation window. That means that you have to first move the host mouse pointer over the emulation window before its input is fed into the emulation. When you move the mouse, it is certainly not guaranteed that you reach all locations in the emulated screen before the mouse pointer leaves the emulation window.
The solution to these issues is simple and is also applied in many other emulations like VirtualBox or VMWare: The mouse must be captured. By this we mean that the host mouse pointer disappears, and only the emulated mouse seems to respond to the movements. This prevents the problem of activating or deactivating the mouse movement sampling, because it is always active as long as the mouse remains captured. When the emulation is stopped, the mouse is freed and returned to the host desktop system.
In MAME it is currently not supported to capture or to free the mouse during runtime. You can only specify that the mouse be captured when starting the emulation.