delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/10/19:30:43

From: "Andy Fung" <tcdude AT concentric DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: My mouse code returns a wierd button value
Date: Sat, 10 Jan 1998 19:13:36 -0500
Organization: Concentric Internet Services
Lines: 150
Message-ID: <6992ta$og4@examiner.concentric.net>
NNTP-Posting-Host: ts009d31.hil-ny.concentric.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi,
I'm having trouble with a mouse class I wrote for Djgpp v2 C++. When I call
the interrupt to get the status of the buttons, I get a value of 327680 in
the button status. This only happens once in a while, but its getting pretty
frustrating. Please see the codes at the bottom to see if there are any
errors in it :)

#include <dos.h>
#include "mouse.h"
mouse::mouse (void) // the mouse constructor
{
init = 0;
buttons = 0;
visable = 0;
res_fix = 0;
x = 0;
y = 0;
set_res (320);
}
mouse::~mouse (void) // the mouse destructor
{
uninstall ();
}
int mouse::install (void) // installs the mouse
{
if (init)
return 1;
if (!reset ())
return 0;
init = 1;
return 1;
}
void mouse::uninstall (void) // uninstalls the mouse
{
if (!init)
return;
init = 0;
hide ();
}
int mouse::reset (void) // resets the mouse
{
union REGS regs;
regs.x.ax = 0x00;
int86 (0x33, &regs, &regs);
buttons = regs.x.bx;
if (!regs.x.ax)
return 0;
show();
visable = 1;
return 1;
}
void mouse::hide (void) // hides the mouse
{
union REGS regs;
if (!visable)
return;
regs.x.ax = 0x02;
int86(0x33, &regs, &regs);
visable = 0;
}
void mouse::show (void) // shows the mouse
{
union REGS regs;
if (visable)
return;
regs.x.ax = 0x01;
int86(0x33, &regs, &regs);
visable = 1;
}
void mouse::set_res (int width)
{
if (width >= 640) {
res_fix = 0;
return;
}
res_fix = 1;
res_divider = 640 / width;
}
int mouse::is_left (void) // checks if left button is pressed
{
update ();
if (buttons == 1 || buttons == 3)
return 1;
return 0;
}
int mouse::is_right (void) // checks if right button is pressed
{
update ();
if (buttons == 2 || buttons == 3)
return 1;
return 0;
}
int mouse::is_both (void)     // checks if both buttons is pressed
{
update ();
if (buttons == 3)
return 1;
return 0;
}
int mouse::is_either (void) // checks if any buttons is pressed
{
update ();
if (buttons)
return 1;
return 0;
}
int mouse::get_raw_key (void)  // gets the raw code from the mouse
{
update ();
return buttons;
}
int mouse::get_x (void) // gets the x coordinate of the mouse
{
update ();
return x;
}
int mouse::get_y (void) // gets the y coordinate of the mouse
{
update ();
return y;
}
void mouse::get_xy (int &ax, int &ay) // gets both coordinates (x and y)
{
update ();
ax = x;
ay = y;
}
void mouse::update (void) // updates the status of the mouse
{
union REGS regs;
regs.x.ax = 0x03;
int86 (0x33, &regs, &regs);
buttons = regs.x.bx;
x = regs.x.cx;
y = regs.x.dx;
if (res_fix)
x = (int)((double)x / (double)res_divider);
}
void mouse::set_xy (const int &ax, const int &ay)
{
union REGS regs;
regs.x.ax = 0x04;
regs.x.cx = ax;
regs.x.dx = ay;
int86 (0x33, &regs, &regs);
}




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019