Category : Files from Magazines
Archive   : CGAZ2-4.ZIP
Filename : MOUSE.C

 
Output of file : MOUSE.C contained in archive : CGAZ2-4.ZIP
/******************** MOUSE.C *********************
* Program to display mouse primitives according *
* to Microsoft Mouse driver. Small memory model *
* (c) 1988 Nigel Cort. All Rights Reserved. *
**************************************************/

/* Verified under Datalight, Ecosoft, Lattice, Microsoft, Turbo C */

#include
#include /* Include dos.h first under Lattice */

#ifdef min /* Some compilers retain min and max */
#undef min /* as macros. Here they are just variables. */
#undef max
#endif

union REGS inregs, outregs;
struct SREGS segregs; /* Called SREG under Ecosoft */

#define NO_MOUSE 0 /* No Mouse Driver Found */
#define SHOW 1 /* Service to show cursor */
#define HIDE 2 /* Service to hide cursor */

#define LEFT 1 /* Left Button */
#define RIGHT 2 /* Right Button */
#define CENTER 4 /* Center Button */

#define HORIZ 1 /* Cursor Directions */
#define VERT 2

int int_flag = 0; /*interrupt flag */

int check_mouse () /* Returns # of buttons on mouse. */
{ /* A return of 0 = no mouse installed.*/
inregs.x.ax = 0;
int86 (0x33, &inregs, &outregs);
if (!outregs.x.ax) /* AX = 0 -> no, AX = -1 -> yes */
return (NO_MOUSE);
else
return (outregs.x.bx); /* BX holds the number of buttons */
}

void display_m_cursor (mode) /* Toggle the display of mouse cursor */
int mode;
{
inregs.x.ax = mode;
int86 (0x33, &inregs, &outregs);
}

int check_position (p_x, p_y) /* Checks buttons pressed and posi- */
int *p_x, /* tion of mouse. It is passed ptrs */
*p_y; /* to update coordinates and returns*/
{ /* a binary sum of buttons pressed. */
inregs.x.ax = 3;
int86 (0x33, &inregs, &outregs);
*p_x = outregs.x.cx;
*p_y = outregs.x.dx;

return (outregs.x.bx);
}

void position_m_cursor (x, y) /* Position mouse curosr at x, y. */
int x, y; /* See text for discussion of units. */
{
inregs.x.ax = 4;
inregs.x.cx = x;
inregs.x.dx = y;
int86 (0x33, &inregs, &outregs);
}

void get_press (button, p_x, p_y, p_presses) /* Get # of presses and pos.*/
int button; /* Left 0, Ctr 4, Right 2 */
int *p_x, *p_y,
*p_presses; /* # presses since last call*/
{
inregs.x.ax = 5;
inregs.x.bx = button;
int86 (0x33, &inregs, &outregs);

*p_x = outregs.x.cx;
*p_y = outregs.x.dx;
*p_presses = outregs.x.bx;
}

void get_release (button, p_x, p_y, p_presses) /* Get # of presses and pos.*/
int button; /* Left 0, Ctr 4, Right 2 */
int *p_x, *p_y,
*p_presses; /* Releases since last call */
{
inregs.x.ax = 6;
inregs.x.bx = button;
int86 (0x33, &inregs, &outregs);

*p_x = outregs.x.cx;
*p_y = outregs.x.dx;
*p_presses = outregs.x.bx;
}

void limit_cursor (direction, min, max) /* Limit cursor's range of motion */
int direction, /* Vertical or horizontal */
min, max; /* Bounds. See text for units*/
{
inregs.x.cx = min;
inregs.x.dx = max;

switch (direction)
{
case (HORIZ):
inregs.x.ax = 7;
break;
case (VERT):
inregs.x.ax = 8;
break;
default: /* If it's not horiz or vert*/
return; /* it's an error; so get out*/
}

int86 (0x33, &inregs, &outregs);
}


void graphic_cursor (hot_x, hot_y, mask) /* Define gr. cursor and hot spot*/
int hot_x, hot_y; /* Coordinates of hot spot */
unsigned long (*mask) []; /* Ptr to array of unsigned */
{ /* longs (double words) */
inregs.x.ax = 9;
inregs.x.bx = hot_x;
inregs.x.cx = hot_y;
inregs.x.dx = mask;
int86 (0x33, &inregs, &outregs);
}

void text_cursor (type, b1, b2) /* Sets text cursor type & look */
int type; /* Hardware or software */
unsigned int b1, b2; /* Cursor parms */
{
inregs.x.ax = 10;
inregs.x.bx = type; /* soft = 0; hard = 1; */
inregs.x.cx = b1; /* scan lines if type = 1, */
inregs.x.dx = b2; /* else they are masks. */
int86 (0x33, &inregs, &outregs);
}

void get_mickeys (x, y) /* Get motion in mickeys since */
int *x, *y; /* the last call. Mickey = 1/200"*/
{

inregs.x.ax = 11;
int86 (0x33, &inregs, &outregs);
*x = outregs.x.cx; /* left is < 0; right > 0 */
*y = outregs.x.dx; /* down is < 0; right > 0 */
}


/*********** Programming Notes *************

Service 3: Buttons is 0 until a button action occurs
Buttons: L = 1, C = 4, R = 2;
Service 5 & 6 : Buttons Left = 0, Center = 2, Right = 1;

********************************************/

main () /* A simple driver for the mouse routines */
{
int i = 0;
int x, y, b, press;

static unsigned long masks [32] = /* Graphics masks */
{
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, /* Screen Mask */
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,

0x8000, 0xE000, 0xF800, 0xD800, /* Cursor Mask */
0x0C00, 0x0600, 0x0300, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000
};

if ((i = check_mouse()) == 0)
{
puts ("No mouse found");
exit (-1);
}
else
printf ("Mouse with %d buttons found\n", i);

puts ("Cursor is visible");
display_m_cursor (SHOW);
getchar(); /* Get user's acknoledgement */

text_cursor (1, 12, 13); /* Text mode underscore cursor */
position_m_cursor (200, 80);
puts ("Now cursor is at 200, 80 and text mode");
getchar();

while (!kbhit()) /* Display changing locations */
{ /* as the mouse is moved. */
b = check_position (&x, &y);
printf ("Buttons: %d,mouse at %d column and %d row\r", b, x, y);
}

for (i = 0; i < 3; i++) /* Show mouse location when */
{ /* buttons were pressed. */
get_press (i, &x, &y, &press);
printf ("Button: %d, X: %d, Y: %d, Presses: %d\n",
i, x, y, press);
}

for (i = 0; i < 3; i++) /* Show mouse location when */
{ /* buttons were released. */
get_release (i, &x, &y, &press);
printf ("Button: %d, X: %d, Y: %d, Releases: %d\n",
i, x, y, press);
}

limit_cursor (HORIZ, 0, 80); /* Limit mouse cursor travel */
limit_cursor (VERT, 0, 80);
puts ("Cursor is limited to 80 x 80 and full");
text_cursor (0, 0x77FF, 0x7700); /* Make the cursor a block */

get_mickeys (&x, &y);
getchar(); getche(); /* Ecosoft doesnot use getche()*/
/* so call getcher twice. */

get_mickeys (&x, &y);
printf ("Mickeys since last call: %d, y: %d\n", x, y);
puts ("Cursor is now hidden");
display_m_cursor (HIDE);
getchar();
}



  3 Responses to “Category : Files from Magazines
Archive   : CGAZ2-4.ZIP
Filename : MOUSE.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/