home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / MS_HANDL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  4.6 KB  |  255 lines

  1. /*********************
  2.  *
  3.  *  ms_handl.c - mouse driver functions.
  4.  *
  5.  *  Purpose: This file contains the driver routines for the Microsft mouse.
  6.  *
  7.  *  Blackstar C Function Library
  8.  *  (c) Copyright 1985,1989 Sterling Castle Software
  9.  *
  10.  *******/
  11.  
  12. #include <dos.h>
  13. #include "blackstr.h"
  14. #include "ms_head.h"
  15. #include "ms_defs.h"
  16.  
  17.  
  18. /********
  19.  *
  20.  *   ms_init() - initialize mouse
  21.  *
  22.  **/
  23.  
  24. int ms_init(void)
  25. {
  26.     if(!ms_stat())
  27.     return(FALSE);
  28.     else {
  29.     ms_shape(-1,-1,ms_mask);        /* set cursor */
  30.     ms_cset(0,0);                   /* set position */
  31.     ms_cson();
  32.     }
  33.     return(TRUE);
  34. }
  35.  
  36.  
  37. /********
  38.  *
  39.  *   mouse_(m1,m2,m3,m4,m5) - mouse function call
  40.  *
  41.  **/
  42.  
  43. int mouse_(int m1, int m2, int m3, int m4, int m5)
  44. {
  45.     union REGS inregs,outregs;
  46.     struct SREGS segs;
  47.     int oldes;
  48.  
  49.     segread(&segs);
  50.     inregs.x.ax = m1;
  51.     inregs.x.bx = m2;
  52.     inregs.x.cx = m3;
  53.     inregs.x.dx = m4;
  54.     oldes = segs.es;            /* save old es */
  55.     if(m5)
  56.     segs.es = m5;
  57.     else
  58.     segs.es = segs.cs;
  59.  
  60.     int86x(0x33, &inregs, &outregs, &segs);
  61.     segs.es = oldes;            /* restore es */
  62.     mouse1_ = outregs.x.ax;     /* set globals */
  63.     mouse2_ = outregs.x.bx;
  64.     mouse3_ = outregs.x.cx;
  65.     mouse4_ = outregs.x.dx;
  66.     return(mouse1_);
  67. }
  68.  
  69.  
  70. /********
  71.  *
  72.  *   ms_stat() - get mouse status
  73.  *
  74.  **/
  75.  
  76. int ms_stat(void)
  77. {
  78.     return(mouse_(0,0,0,0,0));
  79. }
  80.  
  81.  
  82. /********
  83.  *
  84.  *   ms_cson() - mouse cursor on
  85.  *
  86.  **/
  87.  
  88. void ms_cson(void)
  89. {
  90.     mouse_(1,0,0,0,0);
  91. }
  92.  
  93.  
  94. /********
  95.  *
  96.  *   ms_csof() - mouse cursor off
  97.  *
  98.  **/
  99.  
  100. void ms_csof(void)
  101. {
  102.     mouse_(2,0,0,0,0);
  103. }
  104.  
  105.  
  106. /********
  107.  *
  108.  *   ms_cget() - get mouse cursor position
  109.  *
  110.  **/
  111.  
  112. int ms_cget(void)
  113. {
  114.     mouse_(3,0,0,0,0);
  115.     mcol_ = mouse3_;
  116.     mrow_ = mouse4_;                /* update globals */
  117.     mlbut_ = mouse2_&0001;
  118.     mrbut_ = mouse2_&0002;
  119.     return(mouse2_);                /* return button status */
  120. }
  121.  
  122.  
  123. /********
  124.  *
  125.  *   ms_cset(col,row) - set mouse cursor to col,row
  126.  *
  127.  **/
  128.  
  129. void ms_cset(int col, int row)
  130. {
  131.     mouse_(4,0,col,row,0);
  132. }
  133.  
  134.  
  135. /********
  136.  *
  137.  *   ms_press() - get button presses
  138.  *
  139.  **/
  140.  
  141. int ms_press(void)
  142. {
  143.     mouse_(5,0,0,0,0);      /* check left button */
  144.     mlbut_ = mouse1_&1;     /* status in bit 0 for left button */
  145.     mlbutp_ = mouse2_;      /* # times pressed */
  146.     mlpcol_ = mouse3_;      /* column pressed */
  147.     mlprow_ = mouse4_;      /* row pressed    */
  148.     mouse_(5,1,0,0,0);      /* now do right button */
  149.     mrbut_ = mouse1_&2;     /* bit 1 for right button*/
  150.     mrbutp_ = mouse2_;
  151.     mrpcol_ = mouse3_;
  152.     mrprow_ = mouse4_;
  153.     return(mrbut_ | mlbut_);
  154. }
  155.  
  156.  
  157. /********
  158.  *
  159.  *   ms_rels() - get button releases
  160.  *
  161.  **/
  162.  
  163. int ms_rels(void)
  164. {
  165.     mouse_(6,0,0,0,0);      /* get left button first */
  166.     mlbut_ = mouse1_&1;
  167.     mlbutr_ = mouse2_;
  168.     mlrcol_ = mouse3_;
  169.     mlrrow_ = mouse4_;
  170.     mouse_(6,1,0,0,0);      /* now check right button */
  171.     mrbut_ = mouse1_&2;
  172.     mrbutr_ = mouse2_;
  173.     mrrcol_ = mouse3_;
  174.     mrrrow_ = mouse4_;
  175.     return(mlbutr_ | mrbutr_);      /* return release */
  176. }
  177.  
  178.  
  179. /********
  180.  *
  181.  *   ms_field(col1,row1,col2,row2) - set mouse field
  182.  *
  183.  **/
  184.  
  185. void ms_field(int col1, int row1, int col2, int row2)
  186. {
  187.     mouse_(7,0,col1,col2,0);                /* set horizontal */
  188.     mouse_(8,0,row1,row2,0);
  189. }
  190.  
  191.  
  192. /********
  193.  *
  194.  *   ms_motion() - get the mouse motion in mickeys
  195.  *
  196.  **/
  197.  
  198. int ms_motion(void)
  199. {
  200.     mouse_(11,0,0,0,0);
  201.     mhcnt_ = mouse3_;
  202.     mvcnt_ = mouse4_;
  203.     return(abs(mhcnt_) + abs(mvcnt_));      /* return motion */
  204. }
  205.  
  206.  
  207. /********
  208.  *
  209.  *   ms_shape(hhot,vhot,masks) - set cursor shape
  210.  *
  211.  **/
  212.  
  213. void ms_shape(int hhot, int vhot, int *masks)
  214. {
  215.     int seg,off;
  216.     struct SREGS segs;
  217.  
  218.     segread(&segs);
  219. #ifdef _I386
  220.     seg = segs.ds;        /* set to data segment */
  221.     off = sy_doff(masks);
  222. #else
  223.     if (sizeof(char *) == 4) {  /* large data */
  224.     seg = sy_dseg(masks);
  225.     off = sy_doff(masks);
  226.     }
  227.     else {
  228.     seg = segs.ds;          /* set to data segment */
  229.     off = sy_doff(masks);
  230.     }
  231. #endif
  232.     mouse_(9,hhot,vhot,off,seg);
  233. }
  234.  
  235.  
  236. /********
  237.  *
  238.  *   ms_intr(mask,routine,dseg) - set mouse interrupt service routine
  239.  *
  240.  **/
  241.  
  242. void ms_intr(int mask, int (*routine)(), int dseg)
  243. {
  244.     int seg,off;
  245.     int (*msint)();
  246.  
  247.     msint = ms_intsvc_;
  248.     seg = (short)sy_pseg(msint);
  249.     off = sy_poff(msint);
  250.     ms_seg_ = (short)sy_pseg(routine);
  251.     ms_off_ = sy_poff(routine);
  252.     ms_dseg_ = dseg;            /* save service routine data segment */
  253.     mouse_(12,0,mask,off,seg);
  254. }
  255.