Mail Archives: djgpp/1998/10/21/17:15:25
From: | jsc AT lds DOT co DOT uk
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Aaargh! My mouse function is still not working!!!
|
Date: | Wed, 21 Oct 1998 21:04:01 GMT
|
Organization: | Deja News - The Leader in Internet Discussion
|
Lines: | 157
|
Message-ID: | <70li81$qqf$1@nnrp1.dejanews.com>
|
NNTP-Posting-Host: | 194.73.88.153
|
X-Article-Creation-Date: | Wed Oct 21 21:04:01 1998 GMT
|
X-Http-User-Agent: | Mozilla/2.0 (compatible; MSIE 3.0; Windows 95)
|
X-Http-Proxy: | 1.0 x13.dejanews.com:80 (Squid/1.1.22) for client 194.73.88.153
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
I'm sorry to trouble everyone YET again, but I still can't get the dang thing
to work. Here's the code again if you missed - can some kind soul please
comile it and tell me if it works. Note - I am comiling with gcc mouse.c
-omouse.exe is this correct or am I missing something vitally important? Whay
are all the other functions working but this one gives a memory fault upon
pressing of the left mouse button? Note - it only gives the fault if the
Plot_Pixel function tries to access the x and y pointers (from the mouse). If
I let it plot a pixel at, say, 20, 30 with a colour of 3, it works perfectly
when the button is pressed - there must me something wrong with the pointer.
It's really bugging me. I am having a lot of trouble with Djgpp at the
moment and it's not been very encouraging to me - it's almost driving me away
because I can't get some basic things like a mouse function to work. I'm also
having trouble accessing the SVGA buffer, but more of that later. Please,
please, please help! I am absolutely desperate now. Nothing is working as I
want it really. Thank you very much (and thanks for all your previous
suggestions). Code follows... #include <dos.h> #include <bios.h> #include
<stdio.h> #include <math.h> #include <conio.h>
#define far
#define MOUSE_LB 0x01 /* mouse left button */
#define MOUSE_RB 0x02 /* mouse right button */
#define MOUSE_CB 0x04 /* mouse center button */
void InitGraphics(void)
{
union REGS regs;
regs.x.ax = 0x13;
int86(0x10, ®s,®s);
return;
}
void ExitGraphics(void)
{
union REGS regs;
regs.x.ax = 0x3;
int86(0x10, ®s,®s);
}
void Plot_Pixel(int x, int y, int colour)
{
_farpokeb(_dos_ds, 0xa0000 + ((y<<8) + (y<<6))+ x, colour);
}
int mouse_detect(void)
{
union REGS regs;
regs.x.ax = 0x0;
int86(0x33, ®s, ®s);
return regs.x.ax;
}
void mouse_show(void)
{
union REGS regs;
regs.x.ax = 0x01;
int86(0x33, ®s, ®s);
}
void mouse_hide(void)
{
union REGS regs;
regs.x.ax = 0x02;
int86(0x33, ®s, ®s);
}
unsigned char mouse_button(unsigned char button)
{
union REGS regs;
regs.x.ax = 0x3;
int86(0x33, ®s, ®s);
return (regs.x.bx & button);
}
void mouse_abs_pos(short *x, short *y)
{
union REGS regs;
regs.x.ax = 0x03;
int86(0x33, ®s, ®s);
*x = regs.x.cx;
*y = regs.x.dx;
return;
}
int mouse_rel_pos(short *x, short *y)
{
union REGS regs;
regs.x.ax = 0xb;
int86(0x33, ®s, ®s);
*x = regs.x.cx;
*y = regs.x.dx;
return (*x|*y);
}
int main(void)
{
int buttons,num_buttons;
int colour=1;
short x;
short y;
// put the computer into graphics mode
InitGraphics();
// initialize mouse
mouse_detect();
// show the mouse
mouse_show();
while(!kbhit())
{
mouse_abs_pos(&x,&y);
//mouse_rel_pos(&x,&y);
if(mouse_button(MOUSE_LB))
{
Plot_Pixel((int)&x, (int)&y, colour);
}
if(mouse_button(MOUSE_RB))
{
if (++colour>15) colour=0;
}
}
ExitGraphics();
return(0);
} // end main
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
- Raw text -