home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * ms_handl.c - mouse driver functions.
- *
- * Purpose: This file contains the driver routines for the Microsft mouse.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <dos.h>
- #include "blackstr.h"
- #include "ms_head.h"
- #include "ms_defs.h"
-
-
- /********
- *
- * ms_init() - initialize mouse
- *
- **/
-
- int ms_init(void)
- {
- if(!ms_stat())
- return(FALSE);
- else {
- ms_shape(-1,-1,ms_mask); /* set cursor */
- ms_cset(0,0); /* set position */
- ms_cson();
- }
- return(TRUE);
- }
-
-
- /********
- *
- * mouse_(m1,m2,m3,m4,m5) - mouse function call
- *
- **/
-
- int mouse_(int m1, int m2, int m3, int m4, int m5)
- {
- union REGS inregs,outregs;
- struct SREGS segs;
- int oldes;
-
- segread(&segs);
- inregs.x.ax = m1;
- inregs.x.bx = m2;
- inregs.x.cx = m3;
- inregs.x.dx = m4;
- oldes = segs.es; /* save old es */
- if(m5)
- segs.es = m5;
- else
- segs.es = segs.cs;
-
- int86x(0x33, &inregs, &outregs, &segs);
- segs.es = oldes; /* restore es */
- mouse1_ = outregs.x.ax; /* set globals */
- mouse2_ = outregs.x.bx;
- mouse3_ = outregs.x.cx;
- mouse4_ = outregs.x.dx;
- return(mouse1_);
- }
-
-
- /********
- *
- * ms_stat() - get mouse status
- *
- **/
-
- int ms_stat(void)
- {
- return(mouse_(0,0,0,0,0));
- }
-
-
- /********
- *
- * ms_cson() - mouse cursor on
- *
- **/
-
- void ms_cson(void)
- {
- mouse_(1,0,0,0,0);
- }
-
-
- /********
- *
- * ms_csof() - mouse cursor off
- *
- **/
-
- void ms_csof(void)
- {
- mouse_(2,0,0,0,0);
- }
-
-
- /********
- *
- * ms_cget() - get mouse cursor position
- *
- **/
-
- int ms_cget(void)
- {
- mouse_(3,0,0,0,0);
- mcol_ = mouse3_;
- mrow_ = mouse4_; /* update globals */
- mlbut_ = mouse2_&0001;
- mrbut_ = mouse2_&0002;
- return(mouse2_); /* return button status */
- }
-
-
- /********
- *
- * ms_cset(col,row) - set mouse cursor to col,row
- *
- **/
-
- void ms_cset(int col, int row)
- {
- mouse_(4,0,col,row,0);
- }
-
-
- /********
- *
- * ms_press() - get button presses
- *
- **/
-
- int ms_press(void)
- {
- mouse_(5,0,0,0,0); /* check left button */
- mlbut_ = mouse1_&1; /* status in bit 0 for left button */
- mlbutp_ = mouse2_; /* # times pressed */
- mlpcol_ = mouse3_; /* column pressed */
- mlprow_ = mouse4_; /* row pressed */
- mouse_(5,1,0,0,0); /* now do right button */
- mrbut_ = mouse1_&2; /* bit 1 for right button*/
- mrbutp_ = mouse2_;
- mrpcol_ = mouse3_;
- mrprow_ = mouse4_;
- return(mrbut_ | mlbut_);
- }
-
-
- /********
- *
- * ms_rels() - get button releases
- *
- **/
-
- int ms_rels(void)
- {
- mouse_(6,0,0,0,0); /* get left button first */
- mlbut_ = mouse1_&1;
- mlbutr_ = mouse2_;
- mlrcol_ = mouse3_;
- mlrrow_ = mouse4_;
- mouse_(6,1,0,0,0); /* now check right button */
- mrbut_ = mouse1_&2;
- mrbutr_ = mouse2_;
- mrrcol_ = mouse3_;
- mrrrow_ = mouse4_;
- return(mlbutr_ | mrbutr_); /* return release */
- }
-
-
- /********
- *
- * ms_field(col1,row1,col2,row2) - set mouse field
- *
- **/
-
- void ms_field(int col1, int row1, int col2, int row2)
- {
- mouse_(7,0,col1,col2,0); /* set horizontal */
- mouse_(8,0,row1,row2,0);
- }
-
-
- /********
- *
- * ms_motion() - get the mouse motion in mickeys
- *
- **/
-
- int ms_motion(void)
- {
- mouse_(11,0,0,0,0);
- mhcnt_ = mouse3_;
- mvcnt_ = mouse4_;
- return(abs(mhcnt_) + abs(mvcnt_)); /* return motion */
- }
-
-
- /********
- *
- * ms_shape(hhot,vhot,masks) - set cursor shape
- *
- **/
-
- void ms_shape(int hhot, int vhot, int *masks)
- {
- int seg,off;
- struct SREGS segs;
-
- segread(&segs);
- #ifdef _I386
- seg = segs.ds; /* set to data segment */
- off = sy_doff(masks);
- #else
- if (sizeof(char *) == 4) { /* large data */
- seg = sy_dseg(masks);
- off = sy_doff(masks);
- }
- else {
- seg = segs.ds; /* set to data segment */
- off = sy_doff(masks);
- }
- #endif
- mouse_(9,hhot,vhot,off,seg);
- }
-
-
- /********
- *
- * ms_intr(mask,routine,dseg) - set mouse interrupt service routine
- *
- **/
-
- void ms_intr(int mask, int (*routine)(), int dseg)
- {
- int seg,off;
- int (*msint)();
-
- msint = ms_intsvc_;
- seg = (short)sy_pseg(msint);
- off = sy_poff(msint);
- ms_seg_ = (short)sy_pseg(routine);
- ms_off_ = sy_poff(routine);
- ms_dseg_ = dseg; /* save service routine data segment */
- mouse_(12,0,mask,off,seg);
- }
-