www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/27/20:35:23

From: nj210337 AT stmail DOT staffs DOT ac DOT uk
Newsgroups: comp.os.msdos.djgpp
Subject: mouse problem!
Date: Thu, 27 May 1999 23:40:54 GMT
Organization: Deja.com - Share what you know. Learn what you don't.
Lines: 114
Message-ID: <7ikl66$gal$1@nnrp1.deja.com>
NNTP-Posting-Host: 194.80.159.97
X-Article-Creation-Date: Thu May 27 23:40:54 1999 GMT
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; TUCOWS)
X-Http-Proxy: 1.1 x25.deja.com:80 (Squid/1.1.22) for client 194.80.159.97
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

hi there.

i was hoping someone could help me with a mouse problem that i have. it
should be quite simple to solve, but i just cannot figure it out...

right, all i am trying to do is convert a "mouse reader" program that i
wrote in borland c++ for dos [16-bit] to djgpp.

i thought it would be simple, but it turned out to be a bit awkward. i
have
the mouse found and initialised ok, and the buttons are all read ok too.
moving the mouse right and down both seem fine as well. the problem
begins
when i try to move the mouse up or left [ie. when negative movement
numbers
are produced] - i just get useless HUGE numbers!!!

i'm pretty sure this has something to do with djgpp's 32-bit registers,
but
i'm damned if i know what... i've already changed the ".x." registers to
".w." like it says in the help system, but the problem persists.

i'd be amazingly grateful if someone could look over the source
code at the end of this mail and maybe point out to me where i've gone
wrong.

any help would be hugely appreciated!!!

thankyou,

thos.

thomas houghton / bsc hons computing science
staffordshire university [ stafford campus ]
e-mail : hj210289 AT stmail DOT staffs DOT ac DOT uk
e-mail : thos AT publiconline DOT co DOT uk
brightlight ! http://surf.to/brightlight
get those stupid monkeys away from me!


======================= code ===========================


#include <dos.h>
#include <conio.h>

/////////////////////////////////////////////////////////////////////
// looks for mouse and initialises it if found. returns 0 on failure, 1
on success.
int InitMouse(void)
{
 union REGS regs;

 regs.w.ax = 0;
 int86(0x33,&regs,&regs);

 if(!regs.w.ax) return 0;	//return 0 if no mouse is found
 else return 1;				//return 1 if mouse is found ok
}

/////////////////////////////////////////////////////////////////////
// stores the mouses xy movement in the passed int pointers
void GetMouseMov(int *xinc, int *yinc)
{
 union REGS regs;

 regs.w.ax = 0x0B;
 int86(0x33,&regs,&regs);

 *xinc = (int)regs.w.cx;
 *yinc = (int)regs.w.dx;
}

///////////////////////////////////////////////////////////////
int main(void)
{
 int x=160;
 int y=100;
 int xinc,yinc;
 //debug variables
 int highx,highy;
 int lowx=100000,lowy=100000;

 if(! InitMouse() ) return 1;

 while(!kbhit())
 {
    GetMouseMov(&xinc,&yinc);
    x += xinc;
	y += yinc;

	printf("%d,%d\n",x,y);

    //stupid debug code to record the high and low xy values
	if(xinc>highx) highx=xinc;
    if(yinc>highy) highy=yinc;
    if(xinc<lowx&&xinc>1000) lowx=xinc;
    if(yinc<lowy&&yinc>1000) lowy=yinc;
 }
 getch();

 printf("\nlo: %d,%d\n",lowx,lowy);
 printf("hi: %d,%d\n",highx,highy);
 getch();

 return 0;
}


====================== code ends =========================


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

- Raw text -


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