DOS Mouse INT33 System call Overview

MS DOS is non-graphical command line based operating system. However it supports mouse interfacing system calls. Mouse support is provided by an application called MOUSE.COM. Mouse is widely used in graphical applications and in games. DOS implements mouse interfacing subsystem through software interrupt INT 0x33 call. Below are the list of subroutines under this interrupt vector.

  • Mouse Cursor Control Functions
    1. INT 33,1 Show Mouse Cursor
    2. INT 33,2 Hide Mouse Cursor
    3. INT 33,4 Set Mouse Cursor Position
    4. INT 33,7 Set Mouse Horizontal Min/Max Position
    5. INT 33,8 Set Mouse Vertical Min/Max Position
    6. INT 33,9 Set Mouse Graphics Cursor
    7. INT 33,A Set Mouse Text Cursor
    8. INT 33,F Set Mouse Mickey Pixel Ratio
    9. INT 33,10 Mouse Conditional OFF
    10. INT 33,13 Set Mouse Double Speed Threshold
    11. INT 33,1A Set Mouse Sensitivity
    12. INT 33,1B Get Mouse Sensitivity
  • Mouse Driver Control / Feedback Functions
    1. INT 33,0 Mouse Reset/Get Mouse Installed Flag
    2. INT 33,15 Get Mouse Driver State and Memory Requirements
    3. INT 33,16 Save Mouse Driver State
    4. INT 33,17 Restore Mouse Driver State
    5. INT 33,1C Set Mouse Interrupt Rate (InPort only)
    6. INT 33,1F Disable Mouse Driver
    7. INT 33,20 Enable Mouse Driver
    8. INT 33,21 Reset Mouse Software
    9. INT 33,24 Get Driver Version, Mouse Type & IRQ Number
  • Mouse Button and Position Feedback Functions
    1. INT 33,3 Get Mouse Position and Button Status
    2. INT 33,5 Get Mouse Button Press Information
    3. INT 33,6 Get Mouse Button Release Information
    4. INT 33,B Read Mouse Motion Counters
  • Video Control and Feedback Functions
    1. INT 33,1D Set Mouse CRT Page
    2. INT 33,1E Get Mouse CRT Page
  • Mouse Interrupt Setup Functions
    1. INT 33,C Set Mouse User Defined Subroutine and Input Mask
    2. INT 33,14 Swap Interrupt Subroutines
  • Alternate Mouse Interrupt Setup Functions
    1. INT 33,18 Set Alternate Subroutine Call Mask and Address
    2. INT 33,19 Get User Alternate Interrupt Address
  • Light Pen Emulation Functions
    1. INT 33,D Mouse Light Pen Emulation On
    2. INT 33,E Mouse Light Pen Emulation Off
  • International Language Support Functions
    1. INT 33,22 Set Language for Messages
    2. INT 33,23 Get Language Number

Major Mouse INT33 System calls

Interrupt Service Purpose
0x33
 
0
 

 Reset mouse and get status
 Call with AX = 0
 Returns:  AX = FFFFh If mouse support is available
               Ax = 0 If mouse support is not available 

0x33 1

 Show mouse pointer
 Call with AX = 1 
 Returns: Nothing

0x33 2

 Hide mouse pointer
 Call with AX = 2
 Returns: Nothing

0x33 3

 Get mouse position and button status
 Call with AX = 3
 Returns: BX = mouse button status
 Bit   Significance
  0     button not pressed
  1     left button is pressed
  2     right button is pressed
  3     center button is pressed      
 CX = x coordinate
 DX = y coordinate

0x33 4

 Set mouse pointer position 
 Call with AX = 4
 CX = x coordinate
 DX = y coordinate
 Returns: Nothing

0x33 7

 Set horizontal limits for pointer
 Call with AX = 7
 CX = minimum x coordinate
 DX = maximum x coordinate
 Returns: Nothing

0x33 8

 Set vertical limits for pointer
 Call with AX = 8
 CX = minimum y coordinate
 DX = maximum y coordinate
 Returns: Nothing

DOS Mouse interfacing program

Let us see a basic mouse demo program to test all of the above services. We have created individual utility functions for accessing each service. Below programs make use of the following functions:

  1. detect_mouse() - Detect if mouse driver loaded in DOS.
  2. show_mouse() - In this function AX is set to "1". When this function is called in main() it displays the mouse pointer. The position of the pointer can be changed by using the mouse.
  3. hide_mouse() - In this function AX is set to "2".When this function is called in main() it hides the mouse pointer. This function is useful while drawing figures, first the mouse pointer is kept hidden, then the figure is been drawn and again the mouse pointer is been called.
  4. get_mouse_status() - In this function AX is set to "3". This function returns the position of the mouse pointer. It contains three parameters,they are xpos,ypos,click. xpos and ypos returns the position of x co-ordinate and y co-ordinate respectively. Click is the integer variable which returns the values 1,2,3 corresponding to the button pressed on the mouse and 0 for buttons being not pressed. If any key is pressed kbhit returns nonzero integer; if not it returns zero.
  5. set_mouse_pos() - In this function AX is set to "4". This function sets the mouse pointer to specific position . CX is been loaded by x co-ordinate of the mouse pointer and DX is been loaded with the y co-ordinate of the mouse pointer.
  6. set_mouse_x_boundary() - In this function AX is set to "7". This function sets horizontal boundary of mouse. CX is been loaded by lower x co-ordinate boundary of the mouse pointer and DX is been loaded with the higher x co-ordinate boundary.
  7. set_mouse_y_boundary()- In this function AX is set to "8". This function sets vertical boundary of mouse. CX is been loaded by lower y co-ordinate boundary of the mouse pointer and DX is been loaded with the higher y co-ordinate boundary.

DOS Text mode mouse interfacing program

This demo application checks if mouse driver is present or not. Once it gets a success it switches to VGA/graphics mode and calls mouse show function. It sets the mouse position to the middle of the screen and later retrieves

Source Code

#include<stdio.h>
#include<conio.h>
#include<dos.h>
union REGS in, out;
#define MOUSE_INTERRUPT 0x33
int detect_mouse(void)
{
10    in.x.ax = 0;
11    int86(MOUSE_INTERRUPT, &in, &out);
12    return out.x.ax;
13  }
14  int show_mouse(void)
15  {
16    in.x.ax = 1;
17    int86(MOUSE_INTERRUPT, &in, &out);
18    return 1;
19  }
20  void get_mouse_status(int *xpos, int *ypos, int *click)
21  {
22    in.x.ax = 3;
23    int86(MOUSE_INTERRUPT, &in, &out);
24    *click = out.x.bx;
25    *xpos = out.x.cx;
26    *ypos = out.x.dx;
27  }
28  int hide_mouse(void)
29  {
30    in.x.ax = 2;
31    int86(MOUSE_INTERRUPT, &in, &out);
32    return 1;
33  }
34 
35  int main(int argc, char *argv[])
36  {
37    int status;
38    int xpos, ypos, click;
39    int xpos_old, ypos_old, click_old;
40 
41    clrscr();
42    printf("\n\DOS Text Mode Mouse demo using INT 0x33");
43    status = detect_mouse();
44    if (status == 0 ) {
45      printf("Mouse support not available.\n");
46      return status;
47    }
48    printf("Mouse support available. Press any key to continue.\n");
49    getch();
50    clrscr();
51    show_mouse();
52    do {
53      get_mouse_status(&xpos, &ypos, &click);
54      if (xpos != xpos_old ||
55        ypos != ypos_old ||
56        click != click_old
57        )
58        {
59          xpos_old = xpos;
60          ypos_old = ypos;
61          click_old = click;
62          clrscr();
63          gotoxy(0, 0);
64          printf("Mouse position: X=%d, Y=%d, Z=%d", xpos, ypos, click);
65          show_mouse();
66        }
67    } while (!kbhit());
68    hide_mouse();
69    getch();
70    return 0;
71  }

Output

DOS int33 mouse in text mode

DOS graphic mode mouse interfacing program

This demo application checks if mouse driver is present or not. Once it gets a success it switches to VGA/graphics mode and calls mouse show function. It sets the mouse position to the middle of the screen and later retrieves
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
union REGS in,out;
#define MOUSE_INTERRUPT 0x33
int detect_mouse()
{
10      in.x.ax = 0;
11      int86(MOUSE_INTERRUPT, &in, &out);
12      return out.x.ax;
13  }
14  int show_mouse()
15  {
16      in.x.ax = 1;
17      int86(MOUSE_INTERRUPT, &in, &out);
18      return 1;
19  }
20  void get_mouse_status(int &xpos,int &ypos,int &click)
21  { 
22      in.x.ax=3;
23      int86(MOUSE_INTERRUPT, &in, &out);
24      click=out.x.bx;
25      xpos=out.x.cx;
26      ypos=out.x.dx;
27  }
28  int hide_mouse()
29  {
30      in.x.ax=2;
31      int86(MOUSE_INTERRUPT,&in,&out);
32      return 1;
33  }
34  void set_mouse_pos(int &xpos,int &ypos)
35  { 
36     in.x.ax=4;
37     in.x.cx=xpos;
38     in.x.dx=ypos;
39     int86(MOUSE_INTERRUPT,&in,&out);
40  }
41  void set_mouse_x_boundary(int x1, int x2)
42  {
43     i.x.ax = 7;
44     i.x.cx = x1;
45     i.x.dx = x2;
46     int86(MOUSE_INTERRUPT,&i,&o);
47  }
48  void set_mouse_y_boundary(int y1, int y2)
49  {
50     i.x.ax = 8;
51     i.x.cx = y1;
52     i.x.dx = y2;
53     int86(MOUSE_INTERRUPT,&i,&o);
54  }
55  int main(int argc, char *argv[])
56  {
57    int xpos, ypos, click;
58    int xpos_old, ypos_old, click_old;
59    int g=DETECT,m, x, y;
60    clrscr();
61    printf("\n\DOS Graphic Mouse demo using INT 0x33");
62    printf("\n\Press any key to detect the mouse driver");
63    if (!detect_mouse()) {
64      printf("\n\Mouse driver not loaded.");
65      printf("Execute MOUSE.COM and run this program.");
66      return -1;
67    }
68    printf("\n\Mouse driver detected. Press any key to continue.");
69    getch();
70    initgraph(&g, &m,"c:\\tc\\bgi");
71    gresult = graphresult();
72    if(gresult != 0){
73      printf("Graphics error %d %s\n", gresult, grapherrormsg(gresult));
74      return gresult;
75    }
76    xpos = 640/2;
77    ypos = 480/2;
78    set_mouse_x_boundary(10, 630);
79    set_mouse_y_boundary(10, 470);
80    set_mouse_pos(xpos, ypos);
81    show_mouse();
82    do {
83      get_mouse_status(&xpos, &ypos, &click);
84      if (xpos != xpos_old ||
85        ypos != ypos_old ||
86        click != click_old
87        )
88        {
89          xpos_old = xpos;
90          ypos_old = ypos;
91          click_old = click;
92          clrscr();
93          gotoxy(0, 0);
94          printf("Mouse position: X=%d, Y=%d, Z=%d", xpos, ypos, click);
95          show_mouse();
96        }
97    } while (!kbhit());
98    hide_mouse();
99    closegraph();
100    printf("\n\n\tPress any key to Exit");
101    getch();
102    return 0;
103  }
104 

Output

DOS int33 mouse in graphic mode

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

printf, scanf, ioctl, mmap, DOS low level IO access, DOS BIOS int86, sleep/delay, sound, nosound, DOS graphics, Turbo C graphics,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan