[comp.lang.c] Turbo C 2.0 Mouse Cursor

everett@iisat.UUCP (Everett Coldwell) (05/22/89)

  I am attempting to write a Graphics system in Borland Turbo-C 2.0 that
will display the mouse cursor on the screen while the program is doing
other tasks.  Getting the cursor to be displayed in text mode is very
straight forward (INT 33, function 1), but attempts to have the cursor
displayed in graphics mode does not seem to be working.  By the way
I am using a Hercules graphics card.  In the past Dr Halo, Pagemaker,
etc have worked fine, so I know it is not my card.  Also I am using
a Logitech Serial mouse which has also worked fine in the past.  Before
the program is run the mouse driver is loaded.
 
  Below is the source code for my TC program (My first C program!).
This program will allow you to draw on the graphics screen with the
mouse when the left button is pressed down.  The TC graphics drivers
are assumed to be in the \TC subdirectory, and the mouse driver is
loaded before entering the TC environment.
 
  Any help, or sources of TC code that use the mouse would be
appreciated.
 
------------------------------------------------------------------------
 
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dos.h>
 
void mouse_initialize (int xmin, int xmax, int ymin, int ymax);
void mouse_data (int *x, int *y, int *buttons);
 
main()
{
 int xmax, ymax, xpos, ypos, buttons;
 int g_driver, g_mode, g_error;
 
 
   detectgraph(&g_driver, &g_mode);
   if (g_driver < 0)
   {
     printf("No graphics hardware detected !\n");
     exit(1);
   }
   printf("Detected graphics driver #%d, mode #%d\n", g_driver, g_mode);
 
   initgraph(&g_driver, &g_mode, "\\tc");
   g_error = graphresult();
   if (g_error < 0)
   {
     printf("initgraph error: %s.\n", grapherrormsg(g_error));
     exit(1);
   }
 
   xmax = getmaxx();
   ymax = getmaxy();
 
   mouse_initialize(0,xmax,0,ymax);
 
   while (!kbhit())
   {
     mouse_data (&xpos, &ypos, &buttons);
 
     putpixel (xpos, ypos, buttons);
/*   printf ("%1d %3d %3d\n", xpos, ypos, buttons);
*/    }
 
   closegraph();
 
}
 
 
/* ======================================================================= */
 
int dot_shift = 0;  /* 3=continuous, 2=2 dot seperation .. 0=8 dot sep */
 
void mouse_initialize (int xmin, int xmax, int ymin, int ymax)
{
 union REGS inr,outr;
 unsigned int bitmap[31];
 
/* --> Reset mouse and mouse driver <-- */
 
   inr.x.ax = 0;
   int86(0x33,&inr,&outr);             /* reset mouse and driver */
   if (outr.x.ax==0)
   {
      printf("\n\nMouse driver not installed\n");
      exit(1);
   }
   else
   {
/*    printf("Mouse driver found;  ");
      if (outr.x.bx) printf ("not ");
      printf ("two buttons\n");
*/ }
 
/* --> Set Mouse Range <-- */
 
   inr.x.cx = xmin << dot_shift;
   inr.x.dx = xmax << dot_shift;
   inr.x.ax = 7;
   int86(0x33,&inr,&outr);     /* set x mouse range */
 
   inr.x.cx = ymin << dot_shift;
   inr.x.dx = ymax << dot_shift;
   inr.x.ax = 8;
   int86(0x33,&inr,&outr);     /* set y mouse range */
 
 
/* --> set Mickey/Pixel ratio <-- */
 
   inr.x.cx = 1;
   inr.x.dx = 1;
   inr.x.ax = 0x0F;
   int86(0x33,&inr,&outr);
 
 
/* --> define graphics cursor bitmap <-- */
/* --> the strange bitmap pattern is just for test puposes <-- */
 
   bitmap[0]  = 0xff00;
   bitmap[1]  = 0xff00;
   bitmap[2]  = 0xff00;
   bitmap[3]  = 0xff00;
   bitmap[4]  = 0xff00;
   bitmap[5]  = 0xff00;
   bitmap[6]  = 0xff00;
   bitmap[7]  = 0xff00;
   bitmap[8]  = 0xff00;
   bitmap[9]  = 0xff00;
   bitmap[10] = 0xff00;
   bitmap[11] = 0xff00;
   bitmap[12] = 0xff00;
   bitmap[13] = 0xff00;
   bitmap[14] = 0xff00;
   bitmap[15] = 0xff00;
 
   bitmap[16] = 0x0420;
   bitmap[17] = 0x0810;
   bitmap[18] = 0x1008;
   bitmap[19] = 0x2004;
   bitmap[20] = 0x4002;
   bitmap[21] = 0x8001;
   bitmap[22] = 0x0420;
   bitmap[23] = 0x0810;
   bitmap[24] = 0x1008;
   bitmap[25] = 0x2004;
   bitmap[26] = 0x4002;
   bitmap[27] = 0x8001;
   bitmap[28] = 0x0420;
   bitmap[29] = 0x0810;
   bitmap[30] = 0x1008;
   bitmap[31] = 0x2004;
 
   inr.x.bx = 0;
   inr.x.cx = 0;
   inr.x.es = FP_SEG(bitmap);
   inr.x.dx = FP_OFF(bitmap);
   inr.x.ax = 0x09; /* define graphics cursor bitmap */
   int86(0x33,&inr,&outr);
}
 
 
/* ======================================================================= */
 
void mouse_data (int *x, int *y, int *buttons)
{
   union REGS inr,outr;
 
   inr.x.ax = 3;
   int86(0x33, &inr, &outr);     /* read mouse buttons, and x & y position */
   *x = outr.x.cx >> dot_shift;
   *y = outr.x.dx >> dot_shift;
   *buttons = outr.x.bx;          /* left=bit 1, right=bit 2, middle=bit 3 */
}

-- 
Everett Coldwell via International Information Service (IIS), Halifax, Canada
UUCP:        {uunet,utai,watmath}!dalcs!iisat!everett
Bitnet/Uucp: everett@iisat.uucp
Arpanet:     everett%iisat.uucp@uunet.uu.net