I remember it was quite short code to read mouse position in C in DOS. Mouse was connected by serial RS232 interface. I used this technique in DOS in Turbo C with BGI interface.
https://ic.unicamp.br/~ducatte/mc404/Lampiao/docs/dosints.pdf
I dont have this code anymore but look this link above I think I used interrupt 33 but it was almost 30 years ago. (INT 33h)
here is example code
#include <dos.h> // Or a similar header for interrupt functions
void main() {
int mouse_installed;
int x, y, buttons;
// Initialize the mouse driver
_AX = 0;
geninterrupt(0x33); // Call INT 33h
mouse_installed = _AX; // Check the return value in AX
if (mouse_installed) {
// Turn the mouse on
_AX = 1;
geninterrupt(0x33);
// Get the mouse position and button status
_AX = 3;
geninterrupt(0x33);
buttons = _BX; // Get button info
x = _CX; // Get X-coordinate
y = _DX; // Get Y-coordinate
printf("Mouse is installed. Cursor at %d,%d, button %d\n", x, y, buttons);
// Turn the mouse off (optional)
_AX = 2;
geninterrupt(0x33);
} else {
printf("Mouse driver not found.\n");
}
}