MOUSE INFO: V22.0201, Machine Organization I, Yap

####
V22.0201.002, Machine Organization I, Professor Yap
Fall 1997

####
NOTES ON MOUSE and PORTS

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

### CONTENTS

- Introduction
- Table of Mouse Interrupt Functions (INT 33h)
- Mouse Cursor
- Bottom of page

### INTRODUCTION

- INT 33h is used for manipulating the mouse. Note that the mouse is available in both graphics and text modes.
- IN/INS and OUT/OUTS are for accessing ports.
- The mouse in controlled by a software interface called a mouse driver 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.)
- Basic Terminology for mouse:
  pixel:
    smallest addressable element on screen. In text mode 03, there 8 pixels stored in a video byte.
  mouse pointer:
    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.
  mickey:
    a unit of measure for movement of mouse, approx. 1/200 of an inch.
  mickey count:
    number of mickeys the mouse ball rolls (either horizontally or vertically). The mouse driver converts this to number of pixels.
  threshhold speed:
    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.
- Mouse interrupt have the form:

      	mov ax,fcn	; fcn=mouse function number
      	...
      	int 33h

  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.
- Mouse functions from int 33h: Here is function fcn=0, which initializes the mouse. It should be the first function to call if you ever use the mouse.

  RETURNS AX=0000h if no mouse support available, AX=FFFFh otherwise.
  RETURNS BX=number of mouse buttons available (if AX=FFFFh).
  Other actions:

  - places mouse at center of screen
  - makes mouse invisible
  - sets mouse pointer display page to 0
  - 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.
  - sets hori. and vert. limits for pointers to their max and min values.
  - sets double-speed threshhold to 64 mickeys/s.
  - enables light pen emulation mode.
  In a table below we show some common functions (fcns), but see helppc for the complete list.
- Here is a program that exercises the basic mouse functions,

### MOUSE INTERRUPT FUNCTIONS

SUMMARY OF INT 33h FUNCTIONS
Function Number | Actions
--- | ---
fcn=00h: initialize mouse | (described above)
fcn=01h: display mouse pointer | no other input or outputs.
fcn=02h: conceal mouse pointer | no other input or outputs. Usage: usually, we issue this at the end of a program
fcn=03h: get button status and pointer location. | OUTPUTS: BX=status of buttons bit 0=LeftButton bit 1=RightButton bit 2=CenterButton Bit=0 means button up, and bit=1 means button pressed. Bits 3-15 reserved. CX=x-coordinate, DX=y-coordinate. The coordinates are in pixels, even if text mode. These values are always within the max and min limits of these coordinates.
fcn=04h: set pointer location. | INPUTS: CX=x-coord, DX=y-coord. The coordinates are in pixels.
fcn=05h: get button-press information | INPUT: BX specifies button (0=left,1=right,2=center). OUTPUT: AX=bits 0 to 2 tells which buttons are currently pressed. This is similar to output BX in fcn=3. BX=button press counter -- the number of button presses since last call to this function. CX,DX= X- and Y-coord of last button press The button press counter is reset to zero.
fcn=06h: get button-release information | analogous to fcn=04h.
fcn=07h: set horizontal limits for pointer | 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.
fcn=08h: set vertical limits for pointer | Analogous to fcn=07h.
fcn=09h: define graphics cursor | INPUT: BX=horizontal cursor hot spot CX=vertical cursor hot spot ES:DX=address of screen and cursor mask NOTE: (BX,CX)=(0,0) is the upper left corner. OUTPUT: none. See additiona information below.
fcn=0bh: read mouse motion counters | returns the horizontal and vertical mickey count since the last call to this function (the range of the counts are -32768 to +32,767). OUTPUT: CX=horizontal count, DX=vertical count.
fcn=0ch: install interrupt handler for mouse events | OUTPUT: none. INPUT ES:DX= address of handler routine 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:
AX=event mask (the bits refer to events as defined below, except here, the bits which are set correspond to the events that caused this interrupt to be called).
BX=button state (bit 0=left, bit 1=right, bit 2=right) where if a bit is set corresponds to button down.
CX:DX=x-coord:y-coord
SI=last vertical mickey count
DI=last horizontal mickey count
DS=data segmet for mouse driver
INPUT CX=event mask (indicating which events this handler is to address). The correspondence between bits of the event mask and the events are as follows:
0=mouse pointer moved | 4=right buttom released
1=left button pressed | 5=center buttom released
2=left button released | 6=center buttom released
3=right button pressed | 7-15= reserved
SEE ALSO: fcn=14h
fcn=10h: set pointer exclusion area | The pointer is not displayed outside a rectangular region defined as follows: INPUT CX:DX=(x,y) coordinates of the upper left corner. INPUT SI:DI=(x,y) coordinates of the lower right corner. This exclusion rectangle is reset by functions fcn=00h or 01h. fcn=13h: set double-speed threshhold | DX=new threshhold value (default 64 mickeys/second). See also fcn=1ah.
fcn=14h: swap interrupt subroutines | Analogous to fcn=0ch above. INPUT ES:DX=far pointer to user interrupt routine. INPUT CX=new interrupt mask. OUTPUT ES:DXfar pointer to previous user interrupt routine. OUTPUT CX=previous interrupt mask. The interrupt routines receives arguments in AX,BX,CX,DX,DI,SI,DS as described under fcn=0ch.
fcn=1ah: set mouse sensitivity. | INPUTS: BX=horizontal sensitivity, CX=vertical sensitivity, DX=threshhold. 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.
fcn=1bh: get mouse sensitivity. | OUTPUTS: BX, CX, DX. These are used just as in fcn=1ah above.
fcn=1dh: set display page for mouse pointer. | INPUT: BX=video page number. Note that each page has its own mouse pointer (location). The page for video display is set with int 10h, fcn=05h.
fcn=1eh: get display page for mouse pointer. | OUTPUT: BX=current video page number.
fcn=24h: get installed mouse information. | OUTPUT BH:BL=major:minor version number. OUTPUT CH=mouse type, where 1=bus mouse, 2=serial mouse, 3=inport mouse, 4=ps/2 mouse, 5=hp mouse.

### MOUSE CURSOR

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.

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:

            SCREEN MASK     CURSOR MASK     RESULTING SCREEN BIT
                0               0                   0
                0               1                   1
                1               0               unchanged
                1               1                inverted

The definition of the DEFAULT graphics cursor is given as follows:

                    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

GO TO THE TOP