home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / mouse / tcmouse / mousertn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-14  |  7.3 KB  |  266 lines

  1. /* MOUSERTN.C
  2.  
  3.    Routines for accessing a mouse from Turbo C.
  4.    Calling program should #include <dos.h> and "mouse.h".
  5.  
  6.    Author: Rodney Loos, Compuserve ID 75756,1446
  7.    These routines released into the public domain,
  8.    feel free to distribute them, use and improve them as you see fit.
  9.  
  10.    These routines are mainly implementations straight from the mouse users
  11.    guide.  They provide access to the Microsoft mouse driver routines.
  12.    The source should compile under any memory model.  I have only tested it
  13.    under small and large models.
  14.  
  15. */
  16.  
  17. #include <dos.h>
  18. #include "mouse.h"
  19. /*
  20. typedef struct {
  21.         int m1,m2,m3,m4;
  22.         } mparams;*/  /* parameters for mouse calls */
  23.  
  24. mparams *tail, mp;
  25.  
  26. void mouse(mparams *p)
  27. {
  28.  union REGS mousreg;
  29.  
  30.  mousreg.x.ax = p->m1;
  31.  mousreg.x.bx = p->m2;
  32.  mousreg.x.cx = p->m3;
  33.  mousreg.x.dx = p->m4;
  34.  int86(0x33,&mousreg,&mousreg);  /* call the mouse interrupt */
  35.  p->m1 = mousreg.x.ax;
  36.  p->m2 = mousreg.x.bx;
  37.  p->m3 = mousreg.x.cx;
  38.  p->m4 = mousreg.x.dx;
  39. }
  40.  
  41.  
  42. /* Microsoft mouse function 0 */
  43. int mouse_init(void)   /* Function returns 0 if mouse software not installed */
  44. {
  45.  union REGS mreg;
  46.  struct SREGS segs;
  47.  
  48.  tail=∓
  49.  if (_osmajor < 2 )
  50.      return(0);  /* need Dos 2.0 or higher to use these mouse routines */
  51.  tail->m1=tail->m2=tail->m3=tail->m4=0; /* initialize variables to 0 */
  52.  if (_osmajor >= 3)
  53.      mouse(tail); /* status returned in tail->m1, if 0 then not installed */
  54.  else{  /* its version 2 */
  55.      mreg.h.ah = 0x35; /* Function to get interrupt vector */
  56.      mreg.h.al = 0x33; /* mouse interrupt number */
  57.      intdosx(&mreg,&mreg,&segs);
  58.     if (segs.es == 0 && mreg.x.bx == 0)
  59.         tail->m1=0; /* if vector points to 0000:0000, mouse not in */
  60.     else
  61.         mouse(tail); /* initialize mouse */
  62.  }
  63.  return(tail->m1);
  64. }
  65.  
  66.  
  67. void show_cursor(void)  /* Msoft mouse function 1 */
  68. {
  69.  tail->m1=1;
  70.  mouse(tail);
  71. }
  72.  
  73.  
  74. void hide_cursor(void)  /* Msoft mouse function 2 */
  75. {
  76.  tail->m1=2;
  77.  mouse(tail);
  78. }
  79.  
  80.  
  81. void get_status(int *button, int *curx, int *cury)  /* mouse function 3 */
  82. /* Function returns the status and postion of the mouse */
  83. {
  84.  tail->m1=3;
  85.  mouse(tail);
  86.  *button=tail->m2;
  87.  *curx=tail->m3;
  88.  *cury=tail->m4;
  89. }
  90.  
  91.  
  92. void pos_mouse(int x, int y)  /*  mouse function 4 */
  93. /* Function to place the mouse at x,y */
  94. {
  95.  tail->m1=4;
  96.  tail->m3=x;
  97.  tail->m4=y;
  98.  mouse(tail);
  99. }
  100.  
  101.  
  102. void b_press(int btn, int *bnow, int *bcount, int *x, int *y) /* function #5 */
  103. /* Function to get information about individual button presses */
  104. {
  105.  tail->m1=5;
  106.  tail->m2=btn;
  107.  mouse(tail);
  108.  *bnow=tail->m1; /* status of button now */
  109.  *bcount=tail->m2; /* number of times pressed since last call to function */
  110.  *x=tail->m3; /* current horizontal position */
  111.  *y=tail->m4; /* current vertical position */
  112. }
  113.  
  114.  
  115. /* Microsoft mouse function 7 */
  116. void sethbounds(int l, int r) /* set left and right boundaries */
  117. {
  118.  tail->m1 = 7;
  119.  tail->m3 = l;
  120.  tail->m4 = r;
  121.  mouse(tail);
  122. }
  123.  
  124.  
  125. /* mouse function 8 */
  126. void setvbounds(int t, int b) /*set top and bottom bounds */
  127. {
  128.  tail->m1 = 8;
  129.  tail->m3 = t;
  130.  tail->m4 = b;
  131.  mouse(tail);
  132. }
  133.  
  134.  
  135. /* mouse function 9 */
  136. void setgraphics(int hspot, int vspot, void far *cmask)
  137. /* Function sets a graphics cursor,
  138.    should now work with all models, but must use "mouse.h"  to prototype
  139.    the pointer to cmask as a far pointer */
  140. {
  141.  struct SREGS msregs;
  142.  union REGS mousreg;
  143.  unsigned maskseg,maskoff;
  144.  
  145.  maskseg = FP_SEG(cmask);
  146.  maskoff = FP_OFF(cmask);
  147.  mousreg.x.ax=9;
  148.  mousreg.x.bx=hspot; /* horizontal hot spot of cursor */
  149.  mousreg.x.cx=vspot; /* vertical hot spot of cursor */
  150.  mousreg.x.dx=maskoff; /* offset of mask  */
  151.  segread(&msregs); /* copy the current segment registers to msregs */
  152.  msregs.es=maskseg; /*  segment address of cursor mask */
  153.  int86x(0x33,&mousreg,&mousreg,&msregs);
  154. }
  155.  
  156.  
  157. void setspeed(int x, int y) /*  function 15 */
  158. /* function to set the mickey to pixel ratio */
  159. {
  160.  tail->m1 = 15; /* function # */
  161.  tail->m3 = x;  /* horizontal mickey/pixel ratio */
  162.  tail->m4 = y;  /* vertical mickey/pixel ratio   */
  163.  mouse(tail);
  164. }
  165.  
  166.  
  167.  
  168. /* mouse function call #6, get button releases */
  169. void b_release( int btn, int *bnow, int *bcount, int *x, int *y)
  170. {
  171.   tail->m1 = 6;  /* mouse call #6 */
  172.   tail->m2 = btn; /* which button to check, 0=left,1=right */
  173.   mouse(tail);
  174.   *bnow = tail->m1;   /* status of button now */
  175.   *bcount = tail->m2; /* number of button releases since last call      */
  176.                 /* to this function                               */
  177.   *x = tail->m3;      /* horizontal position at last button release     */
  178.   *y = tail->m4;      /* vertical position at last release              */
  179. }
  180.  
  181.  
  182. /* mouse function 10, set cursor mode.  Sets cursor to text or software
  183.    mode, and type of cursor                                              */
  184. void settext(int cursor,int scrnmask,int cursmask)
  185. {
  186.   tail->m1 = 10; /* mouse call #10 */
  187.   tail->m2 = cursor;    /* if 0, use software cursor; 1, use hardware cursor */
  188.   tail->m3 = scrnmask;    /* if software cursor, defines screen mask         */
  189.               /* if hardware cursor, defines scan line start       */
  190.   tail->m4 = cursmask;    /* if software cursor, defines cursor mask,          */
  191.               /* if hardware cursor, defines scan line stop.       */
  192.   mouse(tail);
  193. }
  194.  
  195.  
  196. /* mouse function 19, set the threshold speed for doubling the cursor's
  197.    movements
  198. */
  199. void set_threshold(int x)
  200. {
  201.   tail->m1 = 19;    /* function 19 */
  202.   tail->m4 = x;        /* speed threshold */
  203.   mouse(tail);
  204. }
  205.  
  206.  
  207.  
  208. /* function 12 defines a subroutine to be executed conditionally
  209.    by the mouse software
  210. */
  211. void set_subroutine(int mask,void (far * func)(void))
  212. {
  213.   _ES = FP_SEG(func);    /* segment of function */
  214.   _DX = FP_OFF(func);    /* offset of function  */
  215.   _CX = mask;        /* condition call mask */
  216.   _AX = 12;        /* mouse function 12   */
  217.   geninterrupt(0x33);    /* mouse function call */
  218.       /*****  note: the subroutine called must do a far return.
  219.                 on entry to the subroutine,
  220.                 ax contains the condition mask,
  221.                 bx contains the button state,
  222.                 cx contains the horizontal cursor coordinate,
  223.                 dx contains the vertical cursor coordinate.
  224.        *******/
  225. }
  226.  
  227.  
  228.  
  229. /* reads the motion of the mouse */
  230. void motion(int *x,int *y)
  231. {
  232.    tail->m1 = 11;  /* mouse function #11 */
  233.    mouse(tail);
  234.    *x = tail->m3;  /* horizontal distance since last call */
  235.    *y = tail->m4;  /* vertical distance since last call   */
  236. }
  237.  
  238.  
  239. /* this function switches the light pen emulation mode on or off.
  240.    I don't know of any c programs that use the light pen emulation,
  241.    but this function is just provided for completeness.
  242.    Light pen emulation mode is on by default after mouse initialization.
  243.    A zero parameter turns it on, any other value turns it off.
  244. */
  245. void light_pen(int sw)
  246. {
  247.   tail->m1 = (sw ? 13 : 14 );
  248.   mouse(tail);
  249. }
  250.  
  251.  
  252.  
  253. /* This function hides the mouse if it is in the region when this function
  254.    is called.  Afterwards your program must call show_cursor
  255.    to show the cursor again.
  256. */
  257. void conditional_off(int x1,int y1,int x2,int y2)
  258. {
  259.   _SI = x2;    /* lower x screen coordinates */
  260.   _DI = y2;    /* lower y screen coordinates */
  261.   _AX = 16;    /* mouse function 16          */
  262.   _CX = x1;    /* upper x screen coordinates */
  263.   _DX = y1;    /* upper y screen coordinates */
  264.   geninterrupt(0x33); /* mouse interrupt */
  265. }
  266.