Mail Archives: djgpp/1999/06/18/11:00:44
From: | Mark Collinson <mark DOT collinson AT unn DOT ac DOT uk>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Mouse programming
|
Date: | Fri, 18 Jun 1999 15:22:46 +0100
|
Organization: | University of Northumbria at Newcastle
|
Lines: | 120
|
Message-ID: | <376A5636.9E45ABA1@unn.ac.uk>
|
NNTP-Posting-Host: | monkey.unn.ac.uk
|
Mime-Version: | 1.0
|
X-Mailer: | Mozilla 4.51 [en] (WinNT; I)
|
X-Accept-Language: | en
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Greeting all,
I am using djgpp to program my mouse in C++. I have attempted to create
a C++ class to do all mouse driver communication. Unfortunately the code
does not seem to work efficiently enough for the mouse to behave
smoothly. I have provide the code below.
Can someone please provide me with a solution or some advice as to how
to improve this code. I am relatively new to C++ so any help would be
gratefully received.
Thanks in advance,
Mark.
#include <iostream.h>
#include <dos.h>
#define mousecall int86(0x33, &inregs, &outregs);
const int LEFT=0, RIGHT=1, BOTH=2, EITHER=3;
const int SOFTCURSOR=0, HARDCURSOR=1;
union REGS inregs, outregs;
class mouse {
public:
mouse();
void init();
int numberofbtns() const;
int detected() const;
int visible() const;
void showcursor();
void hidecursor();
void getstatus();
int btnstatus() const;
int x() const;
int y() const;
private:
int exists;
int btncount;
int cursor_displayed;
int btnstate;
int btnclicks;
int column;
int row;
int hmovement;
int vmovement;
};
mouse::mouse() {
init();
}
void mouse::init() {
inregs.x.ax=0;
mousecall;
exists=(outregs.x.ax!=0);
btncount=outregs.x.bx;
}
int mouse::numberofbtns() const {
return btncount;
}
int mouse::detected() const {
return exists;
}
int mouse::visible() const {
return cursor_displayed;
}
void mouse::showcursor() {
inregs.x.ax=0x01;
mousecall;
cursor_displayed=1;
}
void mouse::hidecursor() {
inregs.x.ax=0x02;
mousecall;
cursor_displayed=0;
}
void mouse::getstatus() {
/* Update private variable members */
inregs.x.ax=0x03;
mousecall;
btnstate=outregs.x.bx;
column=outregs.x.cx;
row=outregs.x.dx;
}
int mouse::btnstatus() const {
return btnstate;
}
int mouse::x() const {
return column;
}
int mouse::y() const {
return row;
}
int main() {
mouse rodent;
cout << rodent.detected() << endl;
cout << rodent.numberofbtns() << endl;
rodent.showcursor();
do {
rodent.getstatus();
} while (rodent.btnstatus()==0);
rodent.hidecursor();
return(0);
}
- Raw text -