How to : Create a better mouse driver

Written by : Peter Quiring

The mouse driver is good for text modes, CGA and maybe VGA but when it comes to hi-res VESA modes it's not usable, and unreliable. So you need to build your own mouse driver using a special mouse function.

Step 1: Make sure there is a mouse driver
  mov ax,0
  int 33h
  cmp ax,0
  jz no_mouse_driver
If ax is still zero after calling INT 33h then there is no mouse driver and you should quit with an error message if the program needs the mouse driver.

Step 2: Enable the call back thing
  mov ax,0ch
  push cs
  pop es
  mov dx,offset my_proc
  mov cx,flags   ;each bit is explained later
  int 33h
Now my_proc will be called when ever the mouse is moved.
flags: (if these bits are set then my_proc will be called if the condition occurs)
  bit   condition
   0   cursor pos has changed
   1   left button pressed
   2   left button released
   3   right button pressed
   4   right button released
   5-15 not used  (but I believe 2 more must be used if you have a 3 button mouse)
my_proc should look like this:
my_proc proc
  ;ax=condition that triggered call (same as flags above)
  ;bx=button state (bit 0=left; 1=right)
  ;cx=horizontal position
  ;dx=vertical position
  ;si=horizontal mouse count since last call (mickeys)
  ;di=vertical mouse count since last call (mickeys)
..... ;do what ever you need to update the mouse and record the button states
  retf  ;make sure to use ret far !
my_proc endp
Notes:

Step 3 : Disable call back.
  mov ax,0ch
  mov dx,0
  mov es,dx
  mov cx,0
  int 33h

To disable the call back set ES:DX and CX to zero and call INT 33h.
You must disable the call back before quiting or the mouse driver will crash
the system when calling a proc that no longer exists.

That's all it takes...
Now what I have shown here is how it is done in real mode. To do the same under PMODE depends on your DOS extender. Some extenders will extend int 33h and others do not. DOS/4GW, PMODE/W and WDOSX do so the code would look exactly the same as above except you should use ES:EDX.
Please refer to my DOS Extender's Descriptions page for more info on DOS extenders.


BACK
Copyright © 1995-2005 Nexus Systems Privacy
SourceForge.net Logo