Solved

Mouse Routines for DOS

Posted on 1998-01-19
2
244 Views
Last Modified: 2010-05-18
I need a set of routines to access the mouse through DOS.  I already have one, but it has problems with mode 13h.  I need a routine that works with mode 13h, it DOES NOT have to be compatible with any other screen modes.

Thanks in advance!
0
Comment
Question by:Egore
2 Comments
 
LVL 16

Expert Comment

by:imladris
ID: 1257030
Are you referring to something other than the standard DOS mouse calls? If so, could you specify the required functionality?

0
 

Accepted Solution

by:
andersh012098 earned 100 total points
ID: 1257031
Here are some very basic mouse routines.
I haven't written any error checking but if initmouse() doesn't return 0 everything should work just fine.
Remember that in mode 13h you have to divide the mouse X coordinate with 2 too get the correct screen X coordinate. (This is due to historical reasons)
I haven't made any comments because the code is so simple. It just calls diffrent functions on interrupt 33h.
To use this first call initmouse() and check so it doesn't return 0. Then call showmouse() to make the mouse vissible on the screen.
To get the status of the mouse just call getmouse with four integers and you'll get X and Y coordinate of the mouse and the status of the left and right mouse buttons.
I haven't included support for 3 buttons because I don't have one to test if it works... You can write it ourself if you want to. In initmouse() BX will contain the number of mouse buttons and in getmouse ((_BX & 4) == 4) will get the status of the center button.

int initmouse()
{
   asm {
      mov ax,0
      int 33h
   }
   return _AX;
}

void showmouse()
{
   asm {
      mov ax,1
      int 33h
   }
}

void hidemouse()
{
   asm {
      mov ax,2
      int 33h
   }
}

void getmouse(int& x,int &y,int left_button_down,int right_button_down)
{
   asm {
      mov ax,3
      int 33h
   }
   x = _CX;
   y = _DX;
   left_button_down = ((_BX & 1) == 1);
   right_button_down = ((_BX & 2) == 2);
}

void setmouse(int x,int y)
{
   asm {
      mov ax,4
      mov cx,x
      mov dx,y
      int 33h
   }
}

void setxlimits(int minx,int maxx)
{
   asm {
      mov ax,7
      mov cx,minx
      mov dx,maxx
      int 33h
   }
}

void setylimits(int miny,int maxy)
{
   asm {
      mov ax,8
      mov cx,miny
      mov dx,maxy
      int 33h
   }
}

Hope that you can get it to work correctly.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now