delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/31/01:47:17

From: "Matthew Reiferson" <MReiferson AT aol DOT com>
Newsgroups: comp.os.msdos.djgpp,rec.games.programmer
Subject: DJGPP Mouse Routines
Date: Wed, 31 Dec 1997 00:33:00 -0500
Lines: 161
Organization: DSoft
NNTP-Posting-Host: 38.26.89.200
Message-ID: <34a9da82.0@news.usinternet.com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I wrote some mouse routines in C with DJGPP.  The problem I came across is
that I must divide the x value returned into REGS from a call to the
position of the mouse (to determine the x,y location of the cursor), but not
the y value.  I have an interrupt routine which keeps the 2 location
variables updated......here is the code.....maybe you can tell me what I am
doing wrong, oh it's in Mode13h so SCREEN_W and SCREEN_H are 320,200
respectively.

static _go32_dpmi_seginfo mouse_seginfo;
static _go32_dpmi_registers mouse_regs;
volatile int mouse_x = 0;
volatile int mouse_y = 0;
volatile int mouse_b = 0;
int mouse_installed = 0;

static void mouseint(_go32_dpmi_registers *r)
{
   mouse_b = r->x.bx;
   mouse_x = r->x.cx/2;
   mouse_y = r->x.dx;
}
END_OF_FUNCTION(mouseint);

int mouse_init(void)
{
   __dpmi_regs r;

   if(mouse_installed)
      return FAIL;
   if(mouse_detect())


      LOCK_VARIABLE(mouse_x);
      LOCK_VARIABLE(mouse_y);
      LOCK_VARIABLE(mouse_b);
      LOCK_FUNCTION(mouseint);

      mouse_seginfo.pm_offset = (int)mouseint;
      mouse_seginfo.pm_selector = _my_cs();
      _go32_dpmi_allocate_real_mode_callback_retf(&mouse_seginfo,
&mouse_regs);
      r.x.ax = 0x0C;
      r.x.cx = 0x7f;
      r.x.dx = mouse_seginfo.rm_offset;
      r.x.es = mouse_seginfo.rm_segment;
      __dpmi_int(0x33, &r);

      set_mouse_range(0, 0, SCREEN_W-1, SCREEN_H-1);
      set_mouse_speed(2, 2);
      position_mouse(SCREEN_W/2, SCREEN_H/2);
      mouse_installed = 1;
      add_exit_func(mouse_exit);
      return SUCCESS;
      }
   else
      {
      return FAIL;
      }
}

void mouse_exit(void)
{
   __dpmi_regs r;

   r.x.ax = 0x0C;
   r.x.cx = 0;
   r.x.dx = 0;
   r.x.es = 0;
   __dpmi_int(0x33, &r);

   r.x.ax = 15;
   r.x.cx = 8;
   r.x.dx = 16;
   __dpmi_int(0x33, &r);

   mouse_x = mouse_y = mouse_b = 0;
   _go32_dpmi_free_real_mode_callback(&mouse_seginfo);
   mouse_installed = 0;
   remove_exit_func(mouse_exit);
}

int mouse_detect(void)
{
   union REGS regs;

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

   return regs.x.ax;
}

void mouse_show(void)
{
   __dpmi_regs r;

   if(!mouse_installed)
      return;
   r.x.ax = 0x01;
   __dpmi_int(0x33, &r);
}

void mouse_hide(void)
{
   __dpmi_regs r;
   if(!mouse_installed)
      return;
   r.x.ax = 0x02;
   __dpmi_int(0x33, &r);
}

void position_mouse(int x, int y)
{
   __dpmi_regs r;

   if(!mouse_installed)
      return;

   r.x.ax = 4;
   r.x.cx = x;
   r.x.dx = y;
   __dpmi_int(0x33, &r);

   mouse_x = x;
   mouse_y = y;
}

void set_mouse_range(int x1, int y1, int x2, int y2)
{
   __dpmi_regs r;

   if (!mouse_installed)
      return;

   r.x.ax = 7;
   r.x.cx = x1;
   r.x.dx = x2;
   __dpmi_int(0x33, &r);         /* set horizontal range */

   r.x.ax = 8;
   r.x.cx = y1;
   r.x.dx = y2;
   __dpmi_int(0x33, &r);         /* set vertical range */

   r.x.ax = 3;
   __dpmi_int(0x33, &r);         /* check the position */
   mouse_x = r.x.cx;
   mouse_y = r.x.dx;
}

void set_mouse_speed(int xspeed, int yspeed)
{
   __dpmi_regs r;
   if (!mouse_installed)
      return;
   r.x.ax = 15;
   r.x.cx = xspeed;
   r.x.dx = yspeed;
   __dpmi_int(0x33, &r);
}


- Raw text -


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