CuteMouse driver v1.9. Copyright (c) 1997-2002 Nagy Daniel
Release date: 2002-05-01


License:
--------

CuteMouse is released under the GPL license. For further information
please read the COPYING file.


Description:
------------

CuteMouse is a mouse driver which supports many mouse protocols, serial
and PS/2. It can search for serial mice at all COM ports or only at a
specified port.

An important CuteMouse feature is its small memory footprint: the TSR part
occupies less than 3.5K. CuteMouse can also install itself in upper memory
when available without requiring external utilities such as DOS 'lh'
command.

CuteMouse supports cursor drawing in all standard graphics and text modes
with any screen size. These are automatically detected whenever the video
mode or the screen size is changed or reset functions are called.

You can subscribe to the CuteMouse discussion group at the official
homepage http://cutemouse.sourceforge.net or by sending an empty letter to
<cutemouse-subscribe@yahoogroups.com>.

CuteMouse is part of the FreeDOS project at http://www.freedos.org


Details:
--------

CTMOUSE supports standard Mouse Systems, Microsoft and Logitech serial and
PS/2 protocols. When searching for a connected mouse, the PS/2 port is
checked first, then all COM ports are scanned. Option /S, whose syntax is
described in the help screen, disables PS/2 support and can specify the
COM port to be checked for a mouse connection and its IRQ line; option /P
disables serial protocols. If option /S is present in the command line,
but PS/2 support is also required, then option /P must also be present.

If COM port number is not specified with /S option, then CTMOUSE searches
all COM ports. If IRQ line is not specified with /S option, then the
default IRQ line value is IRQ4 for COM1/3 and IRQ3 for COM2/4. In the
future, when IRQ autodetection will be added, then there will be no
explicit assumption.

By default, a PS/2 mouse is searched for before a serial mouse, but option
/V reverses this. Option /V can be useful, for example, on notebooks with
a built-in PS/2 pointing device to enable use of a serial mouse, when
attached, by causing CTMOUSE to look for a serial mouse before checking
the PS/2 device. Using option /Y (see below) also may be required along
with /V. Note: option /V enables both serial and PS/2 protocols, so using
options /P and /S without arguments along with /V in the command line is
meaningless.

For serial mice, CTMOUSE searches all COM ports (or at the port specified
by option /S) for an attached Microsoft or Logitech mode mouse. If no such
mouse is found then CTMOUSE installs at the first existing (or specified)
COM port for a Mouse Systems mode, whether a mouse is there or not. (This
is because Mouse Systems protocol defines no detection sequence). Option
/Y in the command line disables Mouse Systems protocol support and
prevents driver installation if no Microsoft or Logitech mode mouse is
found. Note: option /Y forces serial mouse search, but, unlike option /S,
doesn't disable PS/2 support.

Both PS/2 and plain Microsoft protocols assume two button mice but option
/3 in the command line can be used to enable the middle button if one is
present.

WARNING: when the middle button of a plain Microsoft mouse is enabled,
pressing left or right button along with the middle button can cause
"middle button state triggering" - i.e. when the middle button is pressed
the driver thinks it is released and vice-versa. This is a peculiarity of
the Microsoft protocol and can't be changed. If button triggering occurs
simply press the left or right button along with the middle button once
again to clear the problem.

CTMOUSE supports 9 fixed resolution levels plus auto resolution, which
define the relationship between cursor and mouse movement - the higher the
resolution level, the further the cursor moves for a given mouse movement.
Resolution level 1 or small mouse movements at any resolution provides a
direct relationship between cursor and mouse movement, which enables
precise screen positioning even at the highest resolution levels. Larger
mouse movements and higher resolution levels are multiplied together to
determine the cursor movement, enabling rapid cursor movements across the
screen for relatively small mouse movements.

Auto resolution means dynamic resolution change, where the faster the
mouse moves, the greater the resolution by which the mouse movements are
multiplied, giving the cursor a nonlinear acceleration. Option /R, whose
syntax is described in the help screen, allows the preferred resolution
level to be specified for each direction.

If installing from low memory, CTMOUSE attempts to move itself into upper
memory (UMB) if there is a suitable free UMB block and option /W is not
used. With option /W any external utility can be used to install CTMOUSE
at a specific location. Subsequent CTMOUSE runs simply reset the resident
part to the new command line options, unless the mouse is not found or
option /B or /N is used.

When installing, CTMOUSE also ignores and hides any present mouse services
unless option /B is used. Option /U in command line can be used to unload
the resident part of CTMOUSE unless driver interrupts have been
intercepted by another program. After successful unloading, CTMOUSE
restores mouse services that were present at installation time.

Option /B in the command line cancels CTMOUSE execution if any (including
CTMOUSE itself) mouse services are already present. With option /B CTMOUSE
will not install itself above loaded mouse drivers and will not reset the
resident part to new command line options.

On the contrary, option /N forces to load new TSR even if CTMOUSE is
already loaded - without this option CTMOUSE will only reset loaded
resident part. In cases where mouse services are provided by any other
driver or are not present at all, CTMOUSE loads new TSR even without
option /N - see table below:

options		no services	other driver	loaded CTMOUSE
-------		-----------	------------	--------------
/B		load CTMOUSE	do nothing	do nothing
<default>	load CTMOUSE	load CTMOUSE	update resident part
/N		load CTMOUSE	load CTMOUSE	load new CTMOUSE

Option /N is useful for batch files, which load CTMOUSE at start and
unload it at the end.

For each event CTMOUSE returns an appropriate exit code which can be used
in "if errorlevel" statements in batch files:

    0 - PS/2, Microsoft or Logitech mouse found and CTMOUSE installed;
	unload successful;
	/? option used
    1 - CTMOUSE installed for Mouse Systems protocol;
	unload failed - CTMOUSE not installed
    2 - resident part switched to PS/2, Microsoft or Logitech protocol;
	unload failed - driver interrupts intercepted
    3 - resident part switched to Mouse Systems protocol
    4 - mouse services already present (returned for option /B only)
    5 - mouse not found;
	invalid option used

Along with options /B and /N, this enables creation of complex and
intelligent batch files. For example, the following batch can be used to
run a program that requires mouse services to be present:

	ctmouse/n/y>nul
	if errorlevel 5 echo Mouse not found!
	if errorlevel 5 goto end
	<program> %1 %2 %3 %4 %5 %6 %7 %8 %9
	ctmouse/u>nul
	:end

Option /B can be used to manually specify a mouse search sequence. In the
following example, CTMOUSE is installed by the first command that finds a
mouse and the following commands will have no affect on the resident part:

	ctmouse/b/s4/y>nul
	ctmouse/b/p/y>nul
	ctmouse/b/s2/y>nul

A help screen with all option descriptions can be obtained with the /?
command line option.

The CuteMouse package also includes utility to detect COM ports (COMTEST)
and serial protocol analyzer (PROTOCOL). PROTOCOL shows how mice work and
what they send to the computer for each action. PROTOCOL can even decipher
information sent by PnP mice. All output goes through DOS functions and
can be redirected to a file for subsequent analysis or sending to someone
else.


Compiling:
----------

To assemble the English version of the driver use TASM (or any compatible
assembler) and any linker that can produce a COM file from OBJ files:

	copy ctm-en.msg ctmouse.msg
	tasm /m @asmlib.cfg ctmouse.asm
	tlink /t /x ctmouse.obj,ctmouse.exe
	com2exe -s512 ctmouse.exe ctmouse.exe

To assemble the serial protocol analyzer:

	tasm /m @..\asmlib.cfg protocol.asm
	tlink /t /x protocol.obj

To compile or delete temporary files, the MAKE utility also can be used
(see makefile).


Known problems:
---------------

Symptom: if mouse is moved when Works 2.0 for DOS or Word 5.5 for DOS
redraws screen in graphics mode then some parts of screen are garbaged.
Cause: these programs don't hide mouse cursor while drawing on screen
and/or don't use EGA RIL API when changing video adapter registers.
Solution: correct these program's code; don't move mouse while screen is
being redrawn; future version of CuteMouse will probably read VGA adapter
registers directly.

Symptom: under Windows 3.1 after mouse reset (INT 33/0000) graphics mouse
cursor shifted by one pixel right/down. Cause: Windows traps INT 33 call
and for reset function additionally calls text and graphics cursor define
functions with [-1,-1] hot spot. Solution: call INT 33 not through 'INT'
instruction but through 'PUSHF/CALL FAR' sequence; probably there exists
some API which CuteMouse can use in future to interact with Windows
directly.

Symptom: sometime under Windows 3.1 graphics cursor has black box shape.
This also sometime happens after switching between tasks windows. Cause:
probably caused by Windows bug when Windows incorrectly redefine cursors
at the time of task switching. Solution: restart graphics application or
try to switch back and forth between tasks again; probably there exists
some API which CuteMouse can use in future to interact with Windows
directly.

Symptom: when CuteMouse is installed then, unlike Microsoft Mouse driver
8.2, mouse doesn't work in windowed DOS box of Windows 3.1. Cause: most
probably Microsoft Mouse driver uses unpublished API to interact with
Windows. Solution: unknown at this moment.

Symptom: CuteMouse will fail to detect PS/2 mice under Windows 9x/ME.
Cause: it seems that Windows is unwilling to let a DOS application have
access to the PS/2 device services. Solution: unknown at present.


History:
--------

1.9	by Arkady V.Belousov <ark@mos.ru> (documentation proofreading by
	Frank Pruefer <fp666@t-online.de>)
	- Heavy source cleaning and optimization
	- INT 33/001A and 001B functions maked dummy because their descriptions
	  in RBIL 61 don't correspond with MS Mouse behavior and this causes
	  cursor slowdown in some applications (for example, SimCity 2000)
	- For /Sn/P option combination INT 33/0024 now returns proper IRQ#
	- Removed flushing mouse data stream when detecting mouse type (this
	  also prevents infinite loops in some cases under Windows)
	- Small mouse movements are now doubled also in auto resolution mode
	- Cursor redrawing routines now recall themselves if cursor was
	  moved by some interrupt handler when they work; this should avoid
	  differences between seen and real cursor status in some rare cases
	- LCR and MCR now preserved in UARTs for which no mouse is detected
	- Added additional check for PS/2 device presence (this prevents
	  big delay at startup in some cases under Windows)
	- Added support for 286 and 386 CPUs
	- Added external assembler library
	- Added Dutch, French, Latvian, Polish, Slovak and Spanish message
	  files
	- Added /N command line option to force load CuteMouse as new TSR
	- COMTEST utility improved (and may be used to integrate IRQ auto
	  detection into CuteMouse)

	by Donald G.Davis <dgdavis@nyx.net)
	- Added closing for all local file handles before exit (this prevents
	  leak from system handles pool when CTMOUSE called with redirected
	  output and stays TSR in low memory)

	by Jason Burgon <jason@jayman.demon.co.uk>
	- INT 33/0024 and 006D now report driver version 7.05 instead of 6.26
	- Implemented function INT 33/0031
	- CTMOUSE now handles INT 10/4F02 and some INT 10/11 video functions
	  and correctly recalculates screen size, for example, when screen
	  switched to 43/50 lines text mode

1.8	by Arkady V.Belousov <ark@mos.ru> (some ideas by Alain Mouette
	<alainm@pobox.com>, documentation proofreading by Mike Millen
	<mikemillen@ukgateway.net> and Frank Pruefer <fp666@t-online.de>)
	- Bugfixes, heavy optimizations, some features
	- PS/2 mice were not found on some machines
	- Serial mouse reset reinforced (previously mouse froze in some cases)
	- Serial and PS/2 modules combined into one executable
	- For Mouse Systems protocol CTMOUSE now installs at first existing
	  COM port, not at COM1 which may be absent
	- Added support for serial Microsoft wheel protocol, wheel
	  interpreted as third button
	- Auto resolution behavior corrected and is now default resolution
	- INT 33/001F now doesn't restore interrupts (and CTMOUSE doesn't
	  unload resident part) if INT 33 or INT 10 are intercepted by
	  another program
	- Cursor drawing much enhanced and bugfixed: finished INT 33/0010
	  support and video page change detection for graphics drawing;
	  single video registers handled in RIL more accurately; cursor
	  is drawn only when cursor shape is inside screen ranges
	- Some ill-behaved applications (like Norton Commander or Klondike
	  by Eduardo Martins) call INT 33/0001, 0009 and 000A in loops; to
	  prevent cursor flickering the cursor is now redrawn only if its
	  position or pattern is changed
	- Added workarounds for Pentium and PS/2 BIOS, Logitech MouseWare
	  Windows driver, Turbo Pascal IDE and Nicemouse utility
	  peculiarities
	- Messages for English extracted into separate message file
	- Added Brazilian, Portugese, German, Italian and Hungarian message
	  files
	- Ordered errorlevels returned for each event
	- Added /B command line option to cancel run if mouse services are
	  already present

1.73	by Arkady V.Belousov <ark@mos.ru> (many ideas by Alain Mouette
	<alainm@pobox.com>)
	- Serial mouse detection routine is now CPU speed independent
	  and also accepts PnP mice
	- Changed command line interface
	- Added mouse autosearch through all COM ports
	- Added support for Microsoft and PS/2 mice with 3 buttons
	- Added /W command line option to prevent loading TSR into UMB
	- Part of driver's PSP used for placing some driver data
	- Memory handling routines heavily optimized and debugged
	- Bugfixed and extended protocol analyzer possibilities

1.72	by Arkady V.Belousov <ark@mos.ru>
	- Bugfixes, optimizations, some features
	- Commented out video retrace waiting
	- Returned handling of PS/2 pointing device through BIOS
	  (thanks to Martin Eckel <martin.eckel@topmail.de>)
	- Reimplemented function INT 33/0010
	- Added autodetection for nonstandard screen sizes
	- Implemented functions INT 33/0023, 0027, 002A and 0032

1.71	by Arkady V.Belousov <ark@mos.ru>
	- Many bugfixes, huge optimizations, some features
	- Direct hardware handling for PS/2 mouse events

1.6	- Positioning bugfix for videomode 13h
	- Added protocol analyzer (debugging purposes only)

1.5	by Arkady V.Belousov <ark@mos.ru>
	- Many bugfixes, huge optimizations
	- Fixed memory allocation bugs

1.4	- Added self-load high capability
	- Horizontal and vertical speed can be different
	  (good for some games...)
	- Implemented functions INT 33/001A and 001B
	- Fixed some small bugs and a BIG bug

1.3	- Fixed some small bugs and added CTMOUSEP.COM for PS/2 mice

1.2a	- Fixed a bug in the Driver Disable function (1Fh)

1.2	- Added command line option to force IRQ number of COM port

1.1	- Added command line options to force a specific mode
	- Rewritten Mouse Systems initalization routine, now more Genius
	  mice with 3 buttons will work

1.0	- First public release


Credits:
--------

- Arkady V.Belousov <ark@mos.ru>: many bugfixes, optimizations and features
- Alain Mouette <alainm@pobox.com>: many ideas and message files
- Frank Pruefer <fp666@t-online.de>: documentation proofreading
- Jason Burgon <jason@jayman.demon.co.uk>: bugfixes, features, advices
  about interrupts handling consistency
- Joergen Ibsen / Jibz <jibz@hotmail.com>: author of aPACK (an excellent
  executable packing program); some advices about managing executables
- Matthias Paul <Matthias.Paul@post.rwth-aachen.de>
- Mike Millen <mikemillen@ukgateway.net>: documentation proofreading
- Robert Riebisch <riebisch@bercom-berlin.de>: mode 13h positioning bugfix
- Fernando Papa Budzyn: self-loadhigh capability
- Martin <nocash@work.de>: optimizations
- Paul Schubert: much faster PS/2 codes
- All who helped me with ideas and codes


Contacts:
---------

mailto:nagyd@users.sourceforge.net
http://cutemouse.sourceforge.net


Technical Notes:
---------------


Mouse driver services
---------------------

Functions implemented in CTMOUSE:

INT 33/0000 - MS MOUSE - Reset driver and read status
INT 33/0001 - MS MOUSE v1.0+ - Show mouse cursor
INT 33/0002 - MS MOUSE v1.0+ - Hide mouse cursor
INT 33/0003 - MS MOUSE v1.0+ - Get cursor position and buttons status
INT 33/0004 - MS MOUSE v1.0+ - Position mouse cursor
INT 33/0005 - MS MOUSE v1.0+ - Get button press data
INT 33/0006 - MS MOUSE v1.0+ - Get button release data
INT 33/0007 - MS MOUSE v1.0+ - Set horizontal cursor range
INT 33/0008 - MS MOUSE v1.0+ - Set vertical cursor range
INT 33/0009 - MS MOUSE v3.0+ - Define graphics cursor
INT 33/000A - MS MOUSE v3.0+ - Define text cursor
INT 33/000B - MS MOUSE v1.0+ - Get motion counters
INT 33/000C - MS MOUSE v1.0+ - Define User Interrupt Routine
INT 33/000F - MS MOUSE v1.0+ - Set mickeys/pixels ratios
INT 33/0010 - MS MOUSE v1.0+ - Define screen region for updating
INT 33/0014 - MS MOUSE v3.0+ - Exchange User Interrupt Routines
INT 33/0015 - MS MOUSE v6.0+ - Get driver storage requirements
INT 33/0016 - MS MOUSE v6.0+ - Save driver state
INT 33/0017 - MS MOUSE v6.0+ - Restore driver state
INT 33/001A - MS MOUSE v6.0+ - Set mouse sensitivity
INT 33/001B - MS MOUSE v6.0+ - Get mouse sensitivity
INT 33/001E - MS MOUSE v6.0+ - Get display page
INT 33/001F - MS MOUSE v6.0+ - Disable mouse driver
INT 33/0020 - MS MOUSE v6.0+ - Enable mouse driver
INT 33/0021 - MS MOUSE v6.0+ - Software reset
INT 33/0023 - MS MOUSE v6.0+ - Get language for messages
INT 33/0024 - MS MOUSE v6.26+ - Get software version, mouse type and IRQ
INT 33/0026 - MS MOUSE v6.26+ - Get maximum virtual screen coordinates
INT 33/0027 - MS MOUSE v7.01+ - Get screen/cursor masks and mickey counters
INT 33/002A - MS MOUSE v7.02+ - Get cursor hot spot
INT 33/0031 - MS MOUSE v7.05+ - Get current virtual cursor coordinates
INT 33/0032 - MS MOUSE v7.05+ - Get supported advanced functions flag
INT 33/004D - MS MOUSE - Get pointer to copyright string
INT 33/006D - MS MOUSE - Get pointer to version

Video functions implemented in CTMOUSE:

INT 10/F0 - EGA Register Interface Library - Read one register
INT 10/F1 - EGA Register Interface Library - Write one register
INT 10/F2 - EGA Register Interface Library - Read register range
INT 10/F3 - EGA Register Interface Library - Write register range
INT 10/F4 - EGA Register Interface Library - Read register set
INT 10/F5 - EGA Register Interface Library - Write register set
INT 10/F6 - EGA Register Interface Library - Revert registers to default
INT 10/F7 - EGA Register Interface Library - Define registers default
INT 10/FA - EGA Register Interface Library - Interrogate driver

The following functions are not implemented but they don't return
anything and can be counted as implemented:

INT 33/000D - MS MOUSE v1.0+ - Light pen emulation ON
INT 33/000E - MS MOUSE v1.0+ - Light pen emulation OFF
INT 33/0013 - MS MOUSE v5.0+ - Define double-speed threshold
INT 33/001C - MS MOUSE v6.0+ - Set interrupt rate
INT 33/001D - MS MOUSE v6.0+ - Set display page
INT 33/0022 - MS MOUSE v6.0+ - Set language for messages

The following functions are not implemented:

INT 10/04 - VIDEO - Get light pen position (except VGA)
INT 33/0011 - Genius Mouse 9.06 - Get number of buttons
INT 33/0012 - MS MOUSE - Set large graphics cursor block
INT 33/0018 - MS MOUSE v6.0+ - Set alternate User Interrupt Routine
INT 33/0019 - MS MOUSE v6.0+ - Get alternate User Interrupt Routine
INT 33/0025 - MS MOUSE v6.26+ - Get general driver information
INT 33/0028 - MS MOUSE v7.0+ - Set video mode
INT 33/0029 - MS MOUSE v7.0+ - Enumerate video modes
INT 33/002B - MS MOUSE v7.0+ - Load acceleration profiles
INT 33/002C - MS MOUSE v7.0+ - Get acceleration profiles
INT 33/002D - MS MOUSE v7.0+ - Select acceleration profile
INT 33/002E - MS MOUSE v8.10+ - Set acceleration profile names
INT 33/002F - MS MOUSE v7.02+ - Mouse hardware reset
INT 33/0030 - MS MOUSE v7.04+ - Get/Set BallPoint information
INT 33/0033 - MS MOUSE v7.05+ - Get switch settings and acceleration profile data
INT 33/0034 - MS MOUSE v8.0+ - Get initialization file
INT 33/0035 - MS MOUSE v8.10+ - LCD screen large pointer support


Details of driver operation
---------------------------

CTMOUSE displays the cursor only in standard video modes of CGA, EGA and
  VGA; Hercules Graphics/InColor Card or SVGA/VESA extended video modes
  are not supported but an application can display the cursor by itself in
  a user interrupt routine (may be installed by INT 33/000C function) or
  when idle. Remember to remove calls to INT 33/0001 (Show cursor) and
  define cursor movement limits (INT 33/0007 and INT 33/0008).

Some applications call INT 33/0001 (Show cursor), INT 33/0009 (Define
  graphics cursor) and INT 33/000A (Define text cursor) in loops. To
  prevent cursor flickering INT 33/0001 function redraws cursor only if it
  was hidden before and INT 33/0004 (Position cursor), INT 33/0009 and
  INT 33/000A functions redraw cursor only if its position or pattern
  has changed.

Unlike many other mouse drivers, CTMOUSE doesn't require call INT 33/0002
  (Hide cursor) or INT 33/0010 (Define region for updating) before writing
  to the screen in text mode because screen under cursor isn't restored if
  cursor is overwritten. However CTMOUSE can't correct all cases of cursor
  overwriting: when a character is written at the cursor position without
  an attribute, (through INT 10/0E (Teletype output) or INT 21), then it
  gets the cursor's attribute. Also, if cursor is overwritten by character
  with attribute which is equal to cursor's character/attribute then
  CTMOUSE restores the old character/attribute.

Unlike Microsoft's specification, CTMOUSE always displays cursor on the
  active video page and doesn't require call INT 33/001D (Set display
  page) at all; this function is, anyway, a dummy.

Below is a table of virtual screen size, cursor movement granularity and
  minimum/maximum size of region on the screen, occupied by cursor (actual
  for INT 33/0010) for each video mode:
				 min	 max
	mode	 screen  cell	shape	shape
	 *0	640x200  16x8	16x8	16x8
	 *1	640x200  16x8	16x8	16x8
	 *2	640x200   8x8	 8x8	 8x8
	 *3	640x200   8x8	 8x8	 8x8
	  4	640x200   2x1	16x16	24x16
	  5	640x200   2x1	16x16	24x16
	  6	640x200   1x1	16x16	24x16
	 *7	640x200   8x8	 8x8	 8x8
	 0Dh	640x200   2x1	32x16	48x16
	 0Eh	640x200   1x1	16x16	24x16
	 0Fh	640x350   1x1	16x16	24x16
	 10h	640x350   1x1	16x16	24x16
	 11h	640x480   1x1	16x16	24x16
	 12h	640x480   1x1	16x16	24x16
	 13h	640x200   2x1	32x16	32x16
	other	640x200   1x1	  -	  -

  * for text modes, the virtual screen size is given for standard screen
  sizes 40x25 and 80x25; for other screen sizes the corresponding virtual
  screen size is changed accordingly.

In standard text modes, CTMOUSE supports any screen size beside 40x25 and
  80x25. It sets virtual screen size as [screen width in characters]*8 by
  [screen height in characters]*8 (except video modes 0-1, where width is
  multiplied by 16) each time when the video mode or the screen size is
  changed or INT 33/0000 (Reset driver), INT 33/0020 (Enable driver) or
  INT 33/0021 (Software reset) are called.

CTMOUSE intercepts only INT 10/0 (Set video mode), INT 10/111x (Load and
  activate font) and INT 10/4F02 (Set VESA/SVGA video mode) functions. If
  screen size in text mode changed by other functions like INT 10/1Ch (VGA
  state save/restore) or by direct hardware programming, then INT 33/0000
  (Reset driver), INT 33/0020 (Enable driver) or INT 33/0021 (Software
  reset) must be called to renew virtual screen size. If INT 33/0020 only
  is called then INT 33/0007 (Set horizontal range) and INT 33/0008 (Set
  vertical range) also should be called with min=0 and max=[8*screen
  width-1,8*screen height-1] to enable the complete screen for cursor
  movement.

INT 33/0007 (Set horizontal range) and INT 33/0008 (Set vertical range)
  functions setup cursor movement area but cursor will be seen on the
  screen only in standard video modes and when cursor shape intersects
  with virtual screen coordinates.

All driver's coordinates (ranges, cursor positions, regions) interpreted
  as signed values, also as cursor hot spot or mickey counts.


Notes for mouse driver services
-------------------------------

For bitmapped graphics modes 4-6 and 0Dh-12h a peculiarity of INT 33/0010
  (Define region for updating) function should be noted: horizontal cursor
  position is always aligned by modulo 8 or 16 and cursor occupies 24 or
  48 positions, unlike mode 13h, where start position is unchanged and
  cursor occupies 32 positions; i.e. for left limit L and right limit R in
  modes 4-6, 0Eh-12h cursor will be hidden between (L-L%8)-16 and
  [R/8+1]*8-1 positions, in mode 0Dh cursor will be hidden between
  (L-L%16)-32 and [R/16+1]*16-1 positions and in mode 13h cursor will be
  hidden between L-32 and R positions.

To set update region via INT 33/0010 in terms of character positions you
  must compute arguments as CX=left*W, DX=top*8, SI=(right+1)*W-1 and
  DI=(bottom+1)*W-1, where W=16 for modes 0-1, 4-5, 0Dh and 13h and W=8
  for all other modes.

Size of buffer, required to save driver state by INT 33/0016, in CTMOUSE
  is less than 180 bytes; exact buffer size is returned by INT 33/0015
  (Get driver storage requirements).

INT 33/0016 (Save driver state) and INT 33/0017 (Restore driver state)
  functions save and restore user defined variables (mickeys per 8 pixels,
  user interrupt routine call mask and address), cursor definition (cursor
  type, text and graphics shape, visibility, position, ranges and update
  region) and mouse access state (mickeys mouse moved, buttons press and
  release status since last access). These functions don't affect driver
  state (disabled flag, resolution level), mouse definition (mouse type,
  buttons count, IO address and interrupt), video mode definition (maximum
  virtual screen coordinates, EGA RIL register values) and dummy variables
  (lightpen emulation status and double speed threshold).

When the video mode after INT 10/0 or INT 10/4F02 or screen size after
  INT 10/111x is changed, CTMOUSE hides cursor so that it can be shown by
  next INT 33/0001, recalculates screen sizes, sets cursor ranges to
  virtual screen sizes and centers cursor.

INT 33/0000 (Reset driver) and INT 33/0021 (Software reset) functions hide
  cursor (so that it can be shown by next INT 33/0001), recalculate screen
  sizes, set cursor ranges to screen sizes, center cursor and clear mickey
  counts, user interrupt routine call mask and button press/release data.
  In addition, horizontal mickeys per 8 pixels ratio is set to 8, vertical
  mickeys per 8 pixels ratio is set to 16, software text mode cursor is
  set with reverse video shape (screen mask 77FFh, cursor mask 7700h) and
  graphics mode cursor shape is set to arrow with zero hot spot.

INT 33/001F (Disable driver) function hides cursor so that it can be shown
  by next INT 33/0001, disables mouse, restores IRQ interrupt (for serial
  mouse) and returns in ES:BX the old INT 33 interrupt handler address. If
  INT 33 or INT 10 interrupt was intercepted by another program then on
  exit AX will contain -1, else if INT 10 interrupt handler was not
  restored yet then it will be restored.

INT 33/0020 (Enable driver) function installs IRQ handler (if serial mouse
  is active) and INT 10 handler (if it is not yet installed), enables
  mouse interrupts, recalculates screen sizes, sets cursor ranges to
  screen sizes and centers cursor.

CTMOUSE supports INT 33/0022 and 0023 (Set/get language for messages)
  functions, but only for English.

When you have to deal with RIL, keep in mind that RIL is unprotected from
  wrong user input - RIL functions should be called only in standard video
  modes and on EGA or later video adapters, and RIL doesn't check if group
  index, register number or count of registers are valid.


Asynchronous execution and User Interrupt Routine (UIR)
------------------------------------------------------

UIR installed via INT 33/000C (Define UIR) or INT 33/0014 (Exchange UIRs)
  must use far RET (not IRET) for return and it is not required to keep
  any register value except SS:SP.

Mouse interrupt handler (IH) redraws cursor on the screen only when the
  called UIR returns to IH. If new mouse events occur before UIR returns
  to IH, then IH will not redraw cursor and call UIR again (i.e. UIR is
  not required to be re-enterable). However, mouse events themselves
  will be parsed and reflected in driver state, so driver state (cursor
  position, buttons state) may be changed before UIR returns. Therefore,
  UIR should be aware of a possible difference between initial arguments
  and values returned by driver functions.

Driver functions will not hide or redraw cursor if they are called while
  cursor hidding or drawing routines in the driver are already working.
  This means that cursor will not be redrawn by requests from UIR or any
  other general purpose hardware interrupt handler, if they are executed
  while cursor redrawing was in progress (this will look like cursor on
  the screen freezes). But hidding or drawing routines will be called
  again when they finish their first request if new request comes in
  from interrupt handlers while they are working.

When bit 0 ("call if mouse moves") is set in the UIR call mask then UIR
  will be called when any mickey count is changed. Note: cursor position
  usually changes less often than mickey counts because mickeys per 8
  pixels ratios can reduce mickeys change to zero and cursor position
  change can be hidden by granulation (in text modes cursor positions are
  always factor of 8 or 16; in some graphics modes X cursor positions are
  always factor of two).


Used BIOS variables
-------------------

0:449h	bits 0-6 used to determine the current video mode (when driver
	enabled by INT 33/0020 or video mode changed)
0:44Ah	screen width in text columns (used to compute offset in video
	memory in text video modes)
0:44Eh	offset in video segment of active video memory page
0:462h	current video page (returned by INT 33/001E)
0:463h	used to compute CRTC base and Feature Control video ports addresses
	(when driver enabled by INT 33/0020 or video mode changed)
0:46Ch	timer used in mouse detection routine to make timing
0:487h	bits 5-6 used to determine RAM size on video adapter (when driver
	enabled by INT 33/0020 or video mode changed)
0:488h	bits 0-3 used to get video configuration switches (when driver
	enabled by INT 33/0020 or video mode changed)
0:4A8h	used to get default video registers values for RIL (when driver
	enabled by INT 33/0020 or video mode changed)


Used interrupts
---------------

INT 10/01	setup text-mode hardware cursor shape, when hardware
		cursor selected
INT 10/1A00	get DCC to check VGA presence
INT 15/C200	enable/disable PS/2 pointing device
INT 15/C203	set resolution of PS/2 pointing device [when PS/2 checking]
INT 15/C205	initialize PS/2 pointing device [when PS/2 checking]
INT 15/C207	set handler for PS/2 pointing device
INT 21/09	output all strings to standard output
INT 21/25	install interrupt handlers for INT 33, INT 10 and IRQ
		handler, also restore those interrupts
INT 21/26	create new PSP for driver image in the UMB [when trying	to
		install driver high]
INT 21/31	remain TSR when driver not copied to other UMB segment
INT 21/35	save old INT 33, INT 10 and IRQ handlers addresses
INT 21/48	allocate UMB memory [when trying to install driver high]
INT 21/49	free memory used by environment and by unloaded TSR
INT 21/4C	terminate program with nonzero errorlevel if some error
		found or with zero errorlevel when no errors
INT 21/58	modify memory allocation strategy [when trying to install
		driver high]
INT 2F/4310	get XMS driver entry [when trying to install driver high]
INT 33/001F	disable previous mouse driver, if one is present
INT 33/0020	enable previous mouse driver after unloading CuteMouse
INT 33/004D	check if installed driver is CuteMouse


Techniques used
---------------

1. Two writes to adjacent I/O ports are combined into one write "out dx,ax"
   (used for most video registers, divisor latch of COM port, etc).

2. For interrupt handler's address comparision only segment of address is
   used, because usually different programs reside in different segments
   and no one program is pointed to by zero segment.

3. CuteMouse uses a lot of self-modifying code and many variables are
   placed in the code instructions; most of code modification is grouped
   in the setupdriver and softreset_21 procedures.

4. To use free part of PSP and thus minimize memory footprint, CuteMouse
   source includes corresponding "ORG" statement before uninitialized
   variables, for which only offsets are computed and no data is generated.
   Note: in TASM 3.1, a structure instance with "DUP(?)" generates data
   (fixed in TASM 4.1), so buttpress and buttrelease arrays are defined
   without "DUP" as series of BUTTLASTSTATE structure insertions instead.

5. CuteMouse is written using TASM and makes use some of TASM features:
   for example, multiple "push" and "pop" in one line ("push ax bx") and
   shifts with an immediate value >1 ("shl ax,2"), which are converted
   into several opcodes valid for 8086/8088 CPUs (i.e. for shifts, TASM
   simply duplicates them - "shl ax,1/shl ax,1"), because there is no
   ".186" or higher statement.

6. Often instructions with shorter opcode but slightly different behavior
   than assumed instruction are used to minimize code; each such use is
   marked by "OPTIMIZE" comment. In addition, instructions for which
   functions are performed by previous code remain in the source as
   comments; this is done for greater readability and to ease code
   carrying.

7. To ease code pipelining in CPU, instructions which manipulate common
   registers or other resources are interspersed with other kinds of
   instructions whenever possible. For example:

	mov ax,cx		mov ax,cx
	add ax,bx		neg dx
	neg dx			add ax,bx

   here second variant is preferred.
