Ok, if we can translate keyboards, midi, and tablets, why not translate a mouse.

So if I run this test program which will open a mouse device and basically pass through the EV_REL events, then I can have a mouse that's independent of the system mouse pointer.

It's VERY important to have it map the buttons BTN_DPAD_UP/DOWN/LEFT/RIGHT or the system will not treat it as a joystick and it will be invisible to mame.
If you map BTN_LEFT/RIGHT/MIDDLE the system will treat it as a regular mouse (not what we want).




Code
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/uinput.h>
#include <stdlib.h>

#define msleep(ms) usleep((ms)*1000)

// Translate a mouse opened in exclusive mode into virtual joystick events
// by Golden Child
//
// using examples from
//
// https://gist.github.com/matthewaveryusa/a721aad80ae89a5c69f7c964fa20fec1
// https://github.com/GrantEdwards/uinput-joystick-demo
// https://www.kernel.org/doc/html/v4.12/input/uinput.html
// https://blog.marekkraus.sk/c/linuxs-uinput-usage-tutorial-virtual-gamepad/

// hard code the keyboard to open in keyboard_to_open
// you can pass the path of the keyboard to open on the command line

 char keyboard_to_open[256] = "/dev/input/by-id/usb-0461_USB_Wired_Keyboard-event-kbd";


static void setup_abs(int fd, unsigned chan, int min, int max);  

// demo showing how to provide a joystick/gamepad instance from
// userspace.

int main(int argc, char* argv[])
{ sleep(1); // wait for a second
  int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
  
  if (fd < 0)
    {
      perror("open /dev/uinput");
      return 1;
    }

  ioctl(fd, UI_SET_EVBIT, EV_KEY); // enable button/key handling

int translatetable[] = { 

// IF I ENABLE THESE BUTTONS, SYSTEM TREATS IT AS A SYSTEM MOUSE
/*
BTN_LEFT, BTN_LEFT,
BTN_RIGHT, BTN_RIGHT,
BTN_MIDDLE, BTN_MIDDLE 
*/

// IF YOU ENABLE BTN_DPAD_UP/LEFT/DOWN/RIGHT  THE SYSTEM WILL TREAT IT AS A JOYSTICK
0x18, BTN_DPAD_UP,
0x19, BTN_DPAD_LEFT,
0x1a, BTN_DPAD_DOWN,
0x1b, BTN_DPAD_RIGHT,
BTN_LEFT, BTN_0,
BTN_RIGHT, BTN_1,
BTN_MIDDLE, BTN_2 

};

int translatetablelen = sizeof(translatetable) / sizeof (int);

int rcode; 


// tell uinput which BTN events we will generate
for (int i=0;i<translatetablelen;i+=2)     ioctl(fd, UI_SET_KEYBIT, translatetable[i+1]);

 char keyboard_name[256] = "Unknown";
 
 int keyboard_fd;

printf ("\nparameters %d\n",argc);
for (int i=0;i<argc;i++) printf("parameter %d = %s\n",i,argv[i]);
 if (argc > 1)
 	keyboard_fd = open(argv[1], O_RDONLY | O_NONBLOCK);  
else
    keyboard_fd = open(keyboard_to_open, O_RDONLY | O_NONBLOCK);  


  if ( keyboard_fd == -1 ) {
    printf("Failed to open keyboard.\n");
    exit(1);
  }
  rcode = ioctl(keyboard_fd, EVIOCGNAME(sizeof(keyboard_name)), keyboard_name);
  printf("Reading From : %s \n", keyboard_name);

  printf("Getting exclusive access: ");
  rcode = ioctl(keyboard_fd, EVIOCGRAB, 1);
  printf("%s\n", (rcode == 0) ? "SUCCESS" : "FAILURE");


for (int i=0;i<translatetablelen;i+=2)  printf("%d => %d\n",translatetable[i],translatetable[i+1]);

  printf("Press ESC to exit\n");
  struct input_event keyboard_event;

// if you hide the ABS part, it won't register as a joystick

  ioctl(fd, UI_SET_EVBIT, EV_ABS); // enable analog absolute position handling
  
  setup_abs(fd, ABS_X,  -512, 512);
  setup_abs(fd, ABS_Y,  -512, 512);
  setup_abs(fd, ABS_Z,  -32767, 32767);
  
  
// SETUP THE RELATIVE UINPUT AXES

  ioctl(fd, UI_SET_EVBIT, EV_REL); // enable relative event handling

  ioctl(fd, UI_SET_RELBIT, REL_X);
  ioctl(fd, UI_SET_RELBIT, REL_Y);
  ioctl(fd, UI_SET_RELBIT, REL_WHEEL_HI_RES);


  
  struct uinput_setup setup =
    {
     .name = "Userspace Joystick",
     .id =
     {
      .bustype = BUS_USB,
      .vendor  = 0x3,
      .product = 0x3,
      .version = 2,
     }
    };

  if (ioctl(fd, UI_DEV_SETUP, &setup))
    {
      perror("UI_DEV_SETUP");
      return 1;
    }
  
  if (ioctl(fd, UI_DEV_CREATE))
    {
      perror("UI_DEV_CREATE");
      return 1;
    }


int doquit=0; // must initialize variable or else it's nonzero
struct input_event button_event;
while (1) {      
      int readval;
      
      if ( readval = read(keyboard_fd, &keyboard_event, sizeof(keyboard_event)), readval != -1 ) 
        {
        if (keyboard_event.code == KEY_ESC && keyboard_event.type == EV_KEY) 
        {
        	doquit = 1;
        	printf("ESC pressed, exiting\n");
        }
      	if (keyboard_event.type == EV_KEY){
      		for (int i=0;i<translatetablelen;i+=2) if (keyboard_event.code == translatetable[i]) 
      					{
      					
      					if (keyboard_event.value != 2) {  // skip key repeat events
      					
						button_event.type = EV_KEY;
						button_event.code = translatetable[i+1];
						button_event.value = keyboard_event.value;
						
						  printf("readval=%d  ev type=%d  key in=%d  => button out=%d value=%d\n",
						  	readval,
						  	button_event.type,
						  	keyboard_event.code,
							button_event.code,
							button_event.value);
		
					  if(write(fd, &button_event, sizeof button_event) < 0)
							{
							  perror("write");
							  return 1;
							}
						
						// send SYNC event
						
						button_event.type = EV_SYN;
						button_event.code = 0;
						button_event.value = 0;

	
					  if(write(fd, &button_event, sizeof button_event) < 0)
							{
							  perror("write");
							  return 1;
							}
	
					  if(write(fd, &button_event, sizeof button_event) < 0)
							{
							  perror("write");
							  return 1;
							}
						break;
					}    						
					}						}
		else if (keyboard_event.type == EV_REL){ 							
	  					if (keyboard_event.value != 2) {  // skip key repeat events
      					
      					// copy event and pass it through
      					
						button_event.type = EV_REL;
						button_event.code = keyboard_event.code;
						button_event.value = keyboard_event.value;
						
						  printf("readval=%d  ev type=%d  key in=%d  => button out=%d value=%d\n",
						  	readval,
						  	button_event.type,
						  	keyboard_event.code,
							button_event.code,
							button_event.value);
		
					  if(write(fd, &button_event, sizeof button_event) < 0)
							{
							  perror("write");
							  return 1;
							}
						
						// send SYNC event
						
						button_event.type = EV_SYN;
						button_event.code = 0;
						button_event.value = 0;

	
					  if(write(fd, &button_event, sizeof button_event) < 0)
							{
							  perror("write");
							  return 1;
							}
	
					  if(write(fd, &button_event, sizeof button_event) < 0)
							{
							  perror("write");
							  return 1;
							}
						//break;
		
		}
		
		}
 	// if (readval <= 0) msleep(50); 
 	if (doquit) break;
    }
 	if (readval <= 0) msleep(50); // keep from taking a lot of cpu by going to sleep
}


  if(ioctl(fd, UI_DEV_DESTROY))
    {
      printf("UI_DEV_DESTROY");
      return 1;
    }

  close(fd);
  return 0;
}

// enable and configure an absolute "position" analog channel

static void setup_abs(int fd, unsigned chan, int min, int max)
{
  if (ioctl(fd, UI_SET_ABSBIT, chan))
    perror("UI_SET_ABSBIT");
  
  struct uinput_abs_setup s =
    {
     .code = chan,
     .absinfo = { .minimum = min,  .maximum = max },
    };

  if (ioctl(fd, UI_ABS_SETUP, &s))
    perror("UI_ABS_SETUP");
}

Code
sudo ./mousetest /dev/input/by-id/usb-Logitech_Dell_Wireless_Mouse_WM413-event-mouse 

parameters 2
parameter 0 = ./mousetest
parameter 1 = /dev/input/by-id/usb-Logitech_Dell_Wireless_Mouse_WM413-event-mouse
Reading From : Logitech Dell Wireless Mouse WM413 
Getting exclusive access: SUCCESS
24 => 544
25 => 546
26 => 545
27 => 547
Press ESC to exit
readval=24  ev type=2  key in=0  => button out=0 value=5
readval=24  ev type=2  key in=0  => button out=0 value=7
readval=24  ev type=2  key in=1  => button out=1 value=1
readval=24  ev type=2  key in=0  => button out=0 value=9
readval=24  ev type=2  key in=0  => button out=0 value=9
readval=24  ev type=2  key in=0  => button out=0 value=7
readval=24  ev type=2  key in=1  => button out=1 value=-1
readval=24  ev type=2  key in=0  => button out=0 value=3
readval=24  ev type=2  key in=1  => button out=1 value=-1
...

And you can map the mouse in mame and it works:

[Linked Image from i.imgur.com]

You see it says "Joy1 R0 UserspaceJoystick" that I have mapped to Mouse X axis and "Joy1 R1 UserspaceJoystick" that I have mapped to the Mouse Y Axis.

Note that it is now totally independent of the regular system mouse pointer.

Mouse buttons come up as
Button 4/Left Button
Button 5/Right Button
Button 6/Middle Button

The only problem is that it doesn't "zero" the relative motion when you stop moving the mouse. It keeps going and won't stay still. I'll have to send a rel motion of 0 when it's idle.