Excerpt from

Laboratory Manual to Accompany 8086/8088, 80186, 80286, 80386, 80486, and Pentium Microprocessors

© 1995 by Barry B. Brey

EXPERIMENT FOURTEEN

USING THE MOUSE

INTRODUCTION

One of the newer I/O devices to take the personal computer market by storm in the past few years if the mouse. The mouse is an I/O device that replaces the cumbersome arrow keys on a keyboard for graphical and text style programs. A trackball is a variation of this device that functions and is programmed identically to a mouse except it is fixed, where the mouse rolls along a surface.

This experiment shows how to add the mouse to applications through a series of macros that enable and allow the mouse to function and keep track of the mouse position.

OBJECTIVES

  1. Develop macros that detect the mouse and enable it for applications.
  2. Develop macros that track the position of the mouse and indicate if a button has been pressed.
  3. Use the mouse in a simple example program.

PROCEDURE

This experiment tests for the presence of the mouse, reads the mouse position, and tests the mouse buttons. Once completed, this experiment allows the inclusion of mouse software in virtually any application.

Is a mouse present?

The mouse is accessed through the INT 33H instruction. Before the mouse can be used in a program, it must be known if the mouse is connected to the system and if it is enabled and functioning. To detect the presence of the mouse and enable it for use the following steps are required:

  1. Test interrupt vector 33H to see if it contains a number other than zero. A zero usually is often in the memory vector when the mouse driver has not been installed in the system.
  2. If the vector is not zero, check to see if the vector points to an IRET (CFH) instruction. Some operating systems store a vector that points to an IRET instruction to indicate that the vector is unused.
  3. If the vector is not zero and it doesn't point to an IRET instruction, place a zero into AX followed by the mouse function call, INT 33H. If a zero is returned in AX, there is no mouse, otherwise the mouse is present.

A macro is ideal to test to see if the mouse is present. Such a macro (_MP) appears in Example 14-1. The _MP macro detects a mouse and ends with carry = 0 if a mouse is present. If a mouse is not present, a message is displayed and carry = 1.

Example 14-1
_MP       MACRO                                ;is mouse present?
          LOCAL      M1,M2,M3
          PUSH       ES                        ;;save ES
          MOV        AX,3533H                  ;;read vector 33H
          INT        21H
          MOV        AX,ES
          OR         AX,BX                     ;;test for ES:BX = 0
          JZ         M2                        ;;if not, end macro
          CMP        BYTE PTR [BX],0CFH
          JZ         M2                        ;;if not, end macro
          MOV        AX,0                      ;;start mouse
          INT        33H
          OR         AX,AX
          JZ         M2                        ;;no mouse
          CLC                                  ;;if mouse, carry = 0
          JMP        M3
M1        DB         13,10,'*** NO MOUSE PRESENT ***$'
M2:       PUSH       DS
          MOV        AX,CS
          MOV        DS,AX
          _STRING    M1                        ;;show no mouse
          POP        DS
          STC                                  ;;if no mouse, carry = 1
M3:       POP        ES
          ENDM

return to publication list