head	1.2;
access;
symbols;
locks
	yap:1.2; strict;
comment	@# @;


1.2
date	97.12.04.16.21.47;	author yap;	state Exp;
branches;
next	1.1;

1.1
date	97.11.10.18.56.52;	author yap;	state Exp;
branches;
next	;


desc
@@


1.2
log
@*** empty log message ***
@
text
@<html>
<title>
MOUSE INFO: V22.0201, Machine Organization I, Yap
</title>
<body bgcolor="EEEEEE">

<h4><font color=AA0000> <center>
<a name=top>
V22.0201.002, Machine Organization I, Professor Yap <br>
Fall 1997
</a>
</center></font> </h4>

<img src="http://cs.nyu.edu/~yap/gifs/lines/rainbowline.gif">

<h4><font color=AA00AA> <center>
	NOTES ON MOUSE and PORTS
</center></font> </h4>

	Some of the following information are derived from chapter 21
	in the book,
	<b>IBM PC Assembly language and Programming</b>
	by Peter Abel (4th Ed.) Prentice-Hall, Inc, 1998.

<p>
<hr>

<h3><font color=AA00AA>
CONTENTS
</font></h3>
<ul>
<li> <a href=#intro>Introduction</a>
<li> <a href=#msetable>Table of Mouse Interrupt Functions (INT 33h) </a>
<li> <a href=#cursor>Mouse Cursor</a>
<li> <a href=#bot>Bottom of page</a>
</ul>

<p>
<hr>

<h3><font color=AA00AA>
<a href=#intro>
INTRODUCTION  
</a>
</font></h3> 
<ul>
<li> INT 33h is used for manipulating the mouse.
	Note that the mouse is available in both graphics
	and text modes.
<li> IN/INS and OUT/OUTS are for accessing ports.
<li> The mouse in controlled by a software interface
	called a <b>mouse driver</b> which is usually
	installed by an entry in the file CONFIG.SYS
	or AUTOEXEC.BAT. (I have not found the corresponding
	location for this in WIN95 or WINNT.)
<li> Basic Terminology for mouse:
	<dl>
	<dt> pixel:<dd> smallest addressable element on screen.
		In text mode 03, there 8 pixels stored in
		a video byte.
	<dt> mouse pointer:<dd> in text mode, this is a flashing
		block, but in reverse video.  In graphics
		mode, this is an arrowhead.  In text mode,
		this is usually a blinking (character size) rectangle.
	<dt> mickey:<dd> a unit of measure for movement of mouse,
		approx. 1/200 of an inch.
	<dt> mickey count:<dd> number of mickeys the mouse ball rolls
		(either horizontally or vertically).  
		The mouse driver converts this to number
		of pixels.
	<dt> threshhold speed:<dd> the speed in mickeys/second
		that the mouse must move to double the
		speed of the pointer on the screen.
		Default is 64 mickeys/s.
	</dl> 
<li> Mouse interrupt have the form:
	<pre>
	mov ax,fcn	; fcn=mouse function number
	...
	int 33h
	</pre>
	Note that this is unlike other int's which
	use only the ah (not ax) register for specifying function
	number.
	The first mouse instruction a program issues should
	be fcn=00h.  This initializes the interface between
	the mouse driver and the program.  This is usually
	done only once.  Next it should issue fcn=01h, which
	cause the mouse pointer to appear.
	
<li> Mouse functions from int 33h:
	Here is function <b>fcn=0</b>, which initializes the mouse.
	It should be the first function to call if you
	ever use the mouse.
	<p>
	<b> RETURNS AX=0000h</b> if no mouse support available,
		<b>AX=FFFFh</b> otherwise.
	<br>
	<b> RETURNS BX=number of mouse buttons available</b> (if AX=FFFFh).
	<br> Other actions:
		<ul>
		<li> places mouse at center of screen
		<li> makes mouse invisible
		<li> sets mouse pointer display page to 0
		<li> sets mickey-to-pixel ratios
			(horizontal ratio is 8:8,
			vertical ratio is 16:8).  Thus the mouse
			pointer moves half as fast in the
			vertical direction.
		<li> sets hori. and vert. limits for pointers
			to their max and min values.
		<li> sets double-speed threshhold to 64 mickeys/s.
		<li> enables light pen emulation mode.
		</ul>
	In a <a href=#msetable>table</a>
	below we show some common functions (fcns),
	but see helppc for the complete list.
<li> Here is a <a href=../samples/mse-2.asm>program</a>
	that exercises the basic mouse functions,
</ul>

<p>
<hr>
<h3><font color=AA00AA>
MOUSE INTERRUPT FUNCTIONS  
</font></h3> 

<table border=3 bgcolor=#ffdaff>
<a name=msetable>
<caption>SUMMARY OF INT 33h FUNCTIONS</caption>
</a>
<tr bgcolor=99ff99>
	<th>Function Number</th>
	<th>Actions</th>
</tr>
<tr>
	<td> fcn=00h: initialize mouse </td>
	<td> (described above)</td>
</tr>
<tr>
	<td> fcn=01h: display mouse pointer</td>
	<td> no other input or outputs.</td>
</tr>
<tr>
	<td> fcn=02h: conceal mouse pointer</td>
	<td> no other input or outputs.
		Usage: usually, we issue this at the end of
		a program</td>
</tr>
<tr>
	<td> fcn=03h: get button status and pointer location.</td>
	<td> OUTPUTS: BX=status of buttons
		<ul>
		<li> bit 0=LeftButton
		<li> bit 1=RightButton
		<li> bit 2=CenterButton
		</ul>
			Bit=0 means button up, and bit=1 means
		button pressed.  Bits 3-15 reserved.
		<br>
		CX=x-coordinate, DX=y-coordinate.
		<br>
		The coordinates are in pixels, even if text mode.
		These values are always within the max and min
		limits of these coordinates.</td>
</tr>
<tr>
	<td> fcn=04h: set pointer location.</td>
	<td>
	INPUTS: CX=x-coord, DX=y-coord.  The coordinates
		are in pixels.</td>
</tr>
<tr>
	<td> fcn=05h: get button-press information</td>
	<td>
	INPUT: BX specifies button (0=left,1=right,2=center).
		<br>
		OUTPUT:
		<ul>
		<li> AX=bits 0 to 2 tells which bits are up or down.
		<li> BX=button press counter
		<li> CX=x-coord of last button press
		<li> DX=y-coord of last button press.
		</ul>
		The button press counter is reset to zero.</td>
</tr>
<tr>
	<td> fcn=06h: get button-release information</td>
	<td>
	analogous to fcn=04h.</td>
</tr>
<tr>
	<td> fcn=07h: set horizontal limits for pointer</td>
	<td>
	INPUT: CX=min x-coord, DX=max x-coord.
		These coordinates are in pixels.
		The operation also moves the pointer to within
		the new limits, if necessary.</td>
</tr>
<tr>
	<td> fcn=08h: set vertical limits for pointer</td>
	<td>
	Analogous to fcn=07h.
	</td>
</tr>
<tr>
	<td> fcn=09h: define graphics cursor</td>
	<td>
		INPUT:
		<ul>
		<li> BX=horizontal cursor hot spot
		<li> CX=vertical cursor hot spot
		<li> ES:DX=address of screen and cursor mask
		</ul>
		NOTE: (BX,CX)=(0,0) is the upper left corner.
		<br>
		OUTPUT: none.
		<br>
		See additiona information <a href=#cursor>below</a>.
	</td>
</tr>
<tr>
	<td> fcn=0bh: read mouse motion counters</td>
	<td> returns the horizontal and vertical mickey count
		since the last call to this function
		(the range of the counts are -32768 to +32,767).
		<b>OUTPUT: CX=horizontal count, DX=vertical count.</b>
	</td>
</tr>
<tr>
	<td> fcn=0ch: install interrupt handler for mouse events</td>
	<td>
		<b>INPUT ES:DX= address of handler routine</b>
		The procedure is a FAR procedure.
		On entry to the interrupt handler, push all registers and
		initialize the DS register to your data segment.
		Within the handler, use only BIOS, not DOS interrupts.
		On exit pop all registers.
		The mouse driver will initialize the following
		inputs for the procedure:
		<table bgcolor=ffffff>
		<tr>
			<td>AX=event mask (as defined below, except
			that those bits whose corresponding events occurred
		will be set)</td>
		</tr><tr>
			<td> BX=button state (bit 0=left,
			bit 1=right, bit 2=right) where
			if a bit is set corresponds to button down.
			</td>
		</tr><tr>
			<td>CX:DX=x-coord:y-coord </td>
		</tr><tr>
			<td>SI=last vertical mickey count</td>
		</tr><tr>
			<td>DI=last horizontal mickey count</td>
		</tr><tr>
			<td>DS=data segmet for mouse driver</td>
		</tr>
		</table>
		<b>INPUT CX=event mask</b>
		(indicating which events this handler is to address).
		<br>
		The correspondence between bits of the event mask and the
		events are as follows:
		<table bgcolor=ffffff>
		<tr>
			<td>0=mouse pointer moved</td>
			<td>4=right buttom released</td>
		</tr><tr>
			<td>1=left button pressed</td>
			<td>5=center buttom released</td>
		</tr><tr>
			<td>2=left button released</td>
			<td>6=center buttom released</td>
		</tr><tr>
			<td>3=right button pressed</td>
			<td> 7-15= reserved</td>
		</tr>
		</table>
	</td>
<tr>
</tr>
	<td>fcn=10h: set pointer exclusion area</td>
	<td>
		The pointer is not displayed outside a rectangular
		region defined as follows:
	   <b>INPUT CX:DX</b>=(x,y) coordinates of the upper left corner.
		<br>
	   <b>INPUT SI:DI</b>=(x,y) coordinates of the lower right corner. 
		<br>
	This exclusion rectangle is reset by functions fcn=00h or 01h.
</tr>
<tr>
	<td>fcn=13h: set double-speed threshhold</td>
	<td> DX=new threshhold value (default 64 mickeys/second).
		See also fcn=1ah.
	</td>
</tr>
<tr>
	<td>fcn=1ah: set mouse sensitivity.</td>
	<td><b>INPUTS: BX=horizontal sensitivity,
		CX=vertical sensitivity, 
		DX=threshhold</b>.  Sensitivity is
		measured in terms of number of mickeys per 8 pixels.
		Default for BX, CX is 8 and 16, respectively.
		See also fcn=0fh,13h,1bh.
	</td>
</tr>
<tr>
	<td>fcn=1bh: get mouse sensitivity.</td>
	<td><b>OUTPUTS: BX, CX, DX</b>.  These are
		used just as in fcn=1ah above.
	</td>
</tr>
<tr>
	<td>fcn=1dh: set display page for mouse pointer.</td>
	<td><b>INPUT: BX=video page number</b>.  Note that each
		page has its own mouse pointer (location).
		The page for video display is set with
		int 10h, fcn=05h.
	</td>
</tr>
<tr>
	<td>fcn=1eh: get display page for mouse pointer.</td>
	<td><b>OUTPUT: BX=current video page number</b>.
	</td>
</tr>
<tr>
	<td>fcn=24h: get installed mouse information.</td>
	<td>
		<b>OUTPUT BH:BL=major:minor version number</b>.
		<b>OUTPUT CH=mouse type</b>, where
		1=bus mouse, 2=serial mouse, 3=inport mouse,
		4=ps/2 mouse, 5=hp mouse.
	</td>
</tr>
		
</table>

<p>
<hr>
<h3><font color=AA00AA>
<a name=cursor>
MOUSE CURSOR
</a>
</font> </h3>

	The mouse cursor is defined using INT 33h,
	Function 9 (see table above).
        The graphics cursor is displayed as an array of pixels,
        either 16x16 or 8x8, depending on display mode.
        This cursor is defined by two 16x16 array of bits,
        called the SCREEN MASK and CURSOR MASK.  For medium
        resolution, 2 bits of the masks are taken at a time,
        corresponding to 4 possible colors.
	<p> 
        The SCREEN MASK is AND'ed with the display screen.
        The CURSOR MASK is OR'ed with the result.  Thus we
        have the following behaviour:
	<pre> 
        SCREEN MASK     CURSOR MASK     RESULTING SCREEN BIT
            0               0                   0
            0               1                   1
            1               0               unchanged
            1               1                inverted
 	</pre>
	        The definition of the DEFAULT graphics cursor is
        given as follows:
 
	<pre>
                mov ax, 9
                mov bx, -1      ; default hot spot is past arrow tip
                mov cx, -1
                mov dx, offset default
                                ; we assume ES is properly set up already
                int 33h
                ;
                default:
                ; screen mask ---
                  db    0011111111111111b
                  db    0001111111111111b
                  db    0000111111111111b
                  db    0000011111111111b
                ;
                  db    0000001111111111b
                  db    0000000111111111b
                  db    0000000011111111b
                  db    0000000001111111b
                ;
                  db    0000000000111111b
                  db    0000000111111111b
                  db    0001000011111111b
                  db    0011000011111111b
                ;
                  db    1111100001111111b
                  db    1111100001111111b
                  db    1111110000111111b
                  db    1111111111111111b
                ;
                ; cursor mask ---
                  db    0000000000000000b
                  db    0100000000000000b
                  db    0110000000000000b
                  db    0111000000000000b
                ;
                  db    0111100000000000b
                  db    0111110000000000b
                  db    0111111000000000b
                  db    0111111100000000b
                ;
                  db    0111111110000000b
                  db    0111111111000000b
                  db    0111110000000000b
                  db    0100011000000000b
                ;  
                  db    0000011000000000b
                  db    0000001100000000b
                  db    0000001100000000b
                  db    0000000000000000b
	</pre>


<p>
<hr>
<a name=bot>
<a href=#top>
GO TO THE TOP
</a>
</a>
</body>
</html>
@


1.1
log
@Initial revision
@
text
@d3 1
a3 2
V22.0201, Machine Organization I, Yap:
Notes on Mouse and Ports
d8 2
a9 1
V22.0201.002, Machine Organization I <br>
d11 1
d16 1
a16 1
<h3><font color=AA00AA> <center>
d18 1
a18 1
</center></font> </h3>
d20 1
a20 1
	The following are information derived from chapter 21
d25 6
d32 15
d48 2
d63 2
a64 1
		mode, this is an arrowhead.
d124 4
d130 1
a130 1
<caption><h2> SUMMARY OF MOUSE FUNCTIONS</h2> </caption>
d207 16
d341 90
@
