INT33 Mouse System call in DOS

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

Mouse programming library in C

Mouse programming library is a collection of APIs to interface mouse subsystem. These routines are implemented using C with the help of int86 calls.

Mouse detect system calls

Reset mouse and get status

Interrupt Service  
0x33      0
  
Argument:
  Call with AX = 0
 
Returns:
  AX = FFFFh If mouse support is available
  AX = 0 If mouse support is not available 

detect_mouse() - Detect if mouse driver loaded in DOS.

int detect_mouse(void)
{
  in.x.ax = 0;
  int86(0x33, &in, &out);
  return out.x.ax;
}

Show mouse pointer

Show mouse pointer

Interrupt Service  
0x33      1  

Argument:
  Call with AX = 1 
 
Returns:
  Nothing 

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.

int show_mouse(void)
{
  in.x.ax = 1;
  int86(0x33, &in, &out);
  return 1;
}

Hide mouse pointer

Hide mouse pointer

Interrupt Service
0x33      2  

Argument:
 Call with AX = 2
 
Returns:
  Nothing

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.

int hide_mouse(void)
{
  in.x.ax = 2;
  int86(MOUSE_INTERRUPT, &in, &out);
  return 1;
}

Get mouse position and button status

Get mouse position and button status

Interrupt Service
0x33    3  

Argument:
  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

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.

void get_mouse_status(int *xpos, int *ypos, int *click)
{
  in.x.ax = 3;
  int86(0x33, &in, &out);
  *click = out.x.bx;
  *xpos = out.x.cx;
  *ypos = out.x.dx;
}

Set mouse pointer position

Set mouse pointer position

Interrupt Service
0x33  4
  
Argument: 
 Call with AX = 4
 CX = x coordinate
 DX = y coordinate
 
Returns:
  Nothing

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.

void set_mouse_pos(int xpos, int ypos)
{
  in.x.ax = 4;
  in.x.cx = xpos;
  in.x.dx = ypos;
  int86(0x33, &in, &out);
}

Set horizontal limits for pointer

Set horizontal limits for pointer

Interrupt Service
0x33  7  
 
Argument:
 Call with AX = 7
 CX = minimum x coordinate
 DX = maximum x coordinate

Returns:
  Nothing

set_mouse_hlimits() - 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.

void set_mouse_hlimits(int min, int max)
{
  in.x.ax = 7;
  in.x.cx = min;
  in.x.dx = max;
  int86(0x33, &in, &out);
}

Set vertical limits for pointer

Set vertical limits for pointer

Interrupt Service
0x33  8  

Argument:
 Call with AX = 8
 CX = minimum y coordinate
 DX = maximum y coordinate

Returns:
  Nothing

set_mouse_vlimits()- 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.

void set_mouse_vlimits(int min, int max)
{
  in.x.ax = 8;
  in.x.cx = min;
  in.x.dx = max;
  int86(0x33, &in, &out);
}

Mouse interfacing C code

Let us see a basic mouse demo program to test all of the above interfaces. We can copy these routines in a file named as mouse_library.c and compile along with mouse.c file.

Text mode mouse 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)
{
  in.x.ax = 0;
  int86(MOUSE_INTERRUPT, &in, &out);
  return out.x.ax;
}
int show_mouse(void)
{
  in.x.ax = 1;
  int86(MOUSE_INTERRUPT, &in, &out);
  return 1;
}
void get_mouse_status(int *xpos, int *ypos, int *click)
{
  in.x.ax = 3;
  int86(MOUSE_INTERRUPT, &in, &out);
  *click = out.x.bx;
  *xpos = out.x.cx;
  *ypos = out.x.dx;
}
int hide_mouse(void)
{
  in.x.ax = 2;
  int86(MOUSE_INTERRUPT, &in, &out);
  return 1;
}

int main(int argc, char *argv[])
{
  int status;
  int xpos, ypos, click;
  int xpos_old, ypos_old, click_old;

  clrscr();
  printf("\n\DOS Text Mode Mouse demo using INT 0x33");
  status = detect_mouse();
  if (status == 0 ) {
    printf("Mouse support not available.\n");
    return status;
  }
  printf("Mouse support available. Press any key to continue.\n");
  getch();
  clrscr();
  show_mouse();
  do {
    get_mouse_status(&xpos, &ypos, &click);
    if (xpos != xpos_old ||
      ypos != ypos_old ||
      click != click_old
      )
      {
        xpos_old = xpos;
        ypos_old = ypos;
        click_old = click;
        clrscr();
        gotoxy(0, 0);
        printf("Mouse position: X=%d, Y=%d, Z=%d", xpos, ypos, click);
        show_mouse();
      }
  } while (!kbhit());
  hide_mouse();
  getch();
  return 0;
}

Output

DOS int33 mouse in text mode

Graphics mouse 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()
{
    in.x.ax = 0;
    int86(MOUSE_INTERRUPT, &in, &out);
    return out.x.ax;
}
int show_mouse()
{
    in.x.ax = 1;
    int86(MOUSE_INTERRUPT, &in, &out);
    return 1;
}
void get_mouse_status(int &xpos,int &ypos,int &click)
{ 
    in.x.ax=3;
    int86(MOUSE_INTERRUPT, &in, &out);
    click=out.x.bx;
    xpos=out.x.cx;
    ypos=out.x.dx;
}
int hide_mouse()
{
    in.x.ax=2;
    int86(MOUSE_INTERRUPT,&in,&out);
    return 1;
}
void set_mouse_pos(int &xpos,int &ypos)
{ 
   in.x.ax=4;
   in.x.cx=xpos;
   in.x.dx=ypos;
   int86(MOUSE_INTERRUPT,&in,&out);
}
void set_mouse_x_boundary(int x1, int x2)
{
   i.x.ax = 7;
   i.x.cx = x1;
   i.x.dx = x2;
   int86(MOUSE_INTERRUPT,&i,&o);
}
void set_mouse_y_boundary(int y1, int y2)
{
   i.x.ax = 8;
   i.x.cx = y1;
   i.x.dx = y2;
   int86(MOUSE_INTERRUPT,&i,&o);
}
int main(int argc, char *argv[])
{
  int xpos, ypos, click;
  int xpos_old, ypos_old, click_old;
  int g=DETECT,m, x, y;
  clrscr();
  printf("\n\DOS Graphic Mouse demo using INT 0x33");
  printf("\n\Press any key to detect the mouse driver");
  if (!detect_mouse()) {
    printf("\n\Mouse driver not loaded.");
    printf("Execute MOUSE.COM and run this program.");
    return -1;
  }
  printf("\n\Mouse driver detected. Press any key to continue.");
  getch();
  initgraph(&g, &m,"c:\\tc\\bgi");
  gresult = graphresult();
  if(gresult != 0){
    printf("Graphics error %d %s\n", gresult, grapherrormsg(gresult));
    return gresult;
  }
  xpos = 640/2;
  ypos = 480/2;
  set_mouse_x_boundary(10, 630);
  set_mouse_y_boundary(10, 470);
  set_mouse_pos(xpos, ypos);
  show_mouse();
  do {
    get_mouse_status(&xpos, &ypos, &click);
    if (xpos != xpos_old ||
      ypos != ypos_old ||
      click != click_old
      )
      {
        xpos_old = xpos;
        ypos_old = ypos;
        click_old = click;
        clrscr();
        gotoxy(0, 0);
        printf("Mouse position: X=%d, Y=%d, Z=%d", xpos, ypos, click);
        show_mouse();
      }
  } while (!kbhit());
  hide_mouse();
  closegraph();
  printf("\n\n\tPress any key to Exit");
  getch();
  return 0;
}

Output

DOS int33 mouse in graphic mode

About our authors: Team EQA

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

#