Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

msmouse.c

Go to the documentation of this file.
00001 /*************************************************************************
00002 *   FILE: msmouse.c
00003 * AUTHOR: Weiskamp, Heiny, Flamig
00004 * DATE: 18 April 1993
00005 * PURPOSE:
00006 *   MSMouse functions to interface with Microsoft mouse driver
00007 **************************************************************************
00008 *     REVISION HISTORY
00009 *
00010 *  Rev  Date    Analyst
00011 *
00012 *    0  ??    Weiskamp, Heiny, Flamig
00013 *       Designed.
00014 *    1  16 Apr 1993   Wilson T, Steven W
00015 *       Added 640x480 support, a few additional features.
00016 *    2  18 Apr 1993 CAL
00017 *       Added support for my message-passing protocols.
00018 **************************************************************************/
00019 
00020 #include <dos.h>
00021 #include <stdlib.h>
00022 #include "msmouse.h"
00023 
00024 const int MsCall  = 0x33;
00025 const int Iret    = 0xcf;
00026 
00027 // Initializes mouse to a know state.  Mouse is not turned on yet
00028 MSMouse::MSMouse(void)
00029 {
00030   OK    = False;
00031   MouseOff  = True;
00032 }
00033 
00034 MSMouse::MSMouse (VideoModeType VideoMode)
00035 {
00036   OK = False;  MouseOff = True;
00037   Setup (VideoMode);
00038 }
00039 
00040 
00041 /***************************************************************************
00042  *
00043  *  Returns true if a mouse driver is installed. This function makes sure
00044  *    the interrupt vector location serviced by the mouse is pointing to
00045  *    something-hopefully the mouse driver.
00046  *
00047  ***************************************************************************/
00048 
00049 
00050 bool MSMouse::DriverExists(void)
00051 {
00052   void far *address;
00053   address = getvect(MsCall);
00054   return (bool) ((address != NULL) &&
00055           (*(unsigned char far *)address != Iret));
00056 }
00057 
00058 
00059 void MSMouse::Setup(VideoModeType VideoMode)
00060 {
00061   REGS regs;
00062 
00063   OK = DriverExists();
00064   if (OK) {
00065     regs.x.ax = 0;
00066     int86(MsCall, &regs, &regs);
00067     if (regs.x.ax == 0)
00068       OK = False;
00069   }
00070   if (!OK) {  // Mouse initialization failed. Set
00071     TurnOff();  // the mouse state off and return.
00072     return;
00073 
00074   }
00075   TurnOn();   // Set the mouse state on
00076 
00077   if (VideoMode == TextScrn) TextMode = True; else TextMode = False;
00078   if (VideoMode == LowResGr) LowRes = True; else LowRes = False;
00079   if (VideoMode == HighResGr) HighRes = True; else HighRes = False;
00080 
00081   OldX = 0;  OldY = 0;
00082   X = 0;   Y = 0;
00083   Dx = 0;  Dy = 0;
00084   Move (0,0);
00085 
00086   SetSpeed2();
00087 }
00088 
00089 
00090 void MSMouse::Hide(void)
00091 {
00092   REGS regs;
00093 
00094   if (!Operating())
00095     return;
00096   regs.x.ax = 2;
00097   int86(MsCall, &regs, &regs);
00098 }
00099 
00100 void MSMouse::Show(void)
00101 {
00102   REGS regs;
00103 
00104   if (!Operating())
00105     return;
00106   regs.x.ax = 1;
00107   int86 (MsCall, &regs, &regs);
00108 }
00109 
00110 
00111 unsigned MSMouse::Status (int &Mx, int &My)
00112 // This general function returns the location of the mouse in Mx, My
00113 // and the current status of the buttons in the function
00114 {
00115   REGS regs;
00116 
00117   if (!Operating()) {
00118     Mx = My = 0;
00119     return 0;
00120   }
00121 
00122   regs.x.ax = 3;
00123   int86(MsCall, &regs, &regs);
00124 
00125   Mx = regs.x.cx;
00126   My = regs.x.dx;
00127 
00128   if (TextMode)  {
00129     Mx >>= 3;  // Adjusts for text coordinates
00130     My >>= 3;
00131   }
00132 
00133   if (LowRes)
00134     Mx >>= 1;
00135 
00136   return regs.x.bx;
00137 }
00138 
00139 
00140 unsigned MSMouse::ButtonStatus(void)
00141 {
00142   int Mx, My;
00143 
00144   if (!Operating())
00145     return 0;
00146   else
00147     return Status(Mx, My);
00148 }
00149 
00150 int MSMouse::PressCnt(unsigned ButtonMask)
00151 {
00152   REGS regs;
00153   if (!Operating())
00154     return 0;
00155 
00156   regs.x.ax = 5;
00157   regs.x.bx = ButtonMask >> 1; // Button selector
00158   int86(MsCall, &regs, &regs);
00159 
00160   return regs.x.bx;
00161 }
00162 
00163 int MSMouse::ReleaseCnt(unsigned ButtonMask)
00164 {
00165   REGS regs;
00166 
00167   if (!Operating())
00168     return 0;
00169 
00170   regs.x.ax = 6;
00171   regs.x.bx = ButtonMask >> 1;
00172   int86(MsCall, &regs, &regs);
00173 
00174   return regs.x.bx;
00175 }
00176 
00177 Message MSMouse::Event (void)
00178 {
00179   unsigned E;
00180   int Mx, My;
00181 
00182   if (!Operating())
00183     return NullMsg;
00184 
00185   // Get current status of buttons
00186   E = Status(Mx,My);
00187 
00188   // No mouse button downm, but maybe there was a button press that was
00189   // missed.  If not, check to see whether a buttton release was missed.
00190   // Favor the left button
00191 
00192   if (E == 0)  {
00193     if (PressCnt(LeftButton) > 0)
00194       E = LMouseDown;
00195   else
00196     if (PressCnt (RightButton) > 0)
00197       E = RMouseDown;
00198   // Maybe left one was just released
00199   else
00200     if (ReleaseCnt (LeftButton) > 0)
00201       E = LMouseUp;
00202   // Maybe rightr one was just released
00203   else
00204     if (ReleaseCnt(RightButton) > 0)
00205       E = RMouseDown;
00206   else
00207     E = Idle;
00208   }
00209 
00210   else { // a mouse button is down
00211   // was left already down?!?!??!
00212   if (E & LeftButton) {
00213   //not down
00214     if (PressCnt(LeftButton) > 0)
00215       E = LMouseDown;
00216     else
00217       E = LMouseStillDown;
00218   }
00219   else
00220     if (PressCnt(RightButton) > 0)
00221       E = RMouseDown;
00222   else
00223     E = RMouseStillDown;
00224   }
00225 
00226   return Message (MouseMsg, E, Mx, My);
00227 }
00228 
00229 Message MSMouse::WaitForAnyEvent (void)
00230 {
00231   Message msg;
00232 
00233   if (!Operating()) return NullMsg;
00234 
00235   do {
00236     msg = Event();
00237   } while (msg.code == Idle);
00238 
00239   return msg;
00240 }
00241 
00242 
00243 Message MSMouse::WaitForEvent (Message& msg)
00244 {
00245   Message try;
00246 
00247   if (!Operating()) return NullMsg;
00248 
00249   do {
00250      try = Event ();
00251   } while (try.code != msg.code);
00252 
00253   return try;
00254 }
00255 
00256 
00257 bool MSMouse::Moved(void)
00258 {
00259   if (!Operating())
00260     return False;
00261   OldX = X;
00262   OldY = Y;
00263   Status(X,Y);
00264   Dx = X - OldX;
00265   Dy = Y - OldY;
00266 
00267   return (bool) ((Dx != 0) || (Dy != 0));
00268 }
00269 
00270 void MSMouse::Move(int Mx, int My)
00271 {
00272   REGS regs;
00273 
00274   if (!Operating())
00275     return;
00276 
00277   regs.x.ax = 4;
00278   regs.x.cx = Mx;
00279   regs.x.dx = My;
00280 
00281   if (TextMode) {
00282     regs.x.cx <<= 3;
00283     regs.x.dx <<= 3;
00284   }
00285 
00286   if (LowRes)
00287     regs.x.cx <<= 1;
00288   if (HighRes)
00289     regs.x.cx <<= 1;
00290 
00291   int86 (MsCall, &regs, &regs);
00292 }
00293 
00294 void MSMouse::TurnOn(void)
00295 {
00296   if (OK && MouseOff) {
00297     MouseOff = False;
00298     Show();
00299   }
00300 }
00301 
00302 void MSMouse::TurnOff(void)
00303 {
00304   if (OK && !MouseOff) {
00305     Hide();
00306     MouseOff = True;
00307   }
00308 }
00309 
00310 void MSMouse::SetGCursor(const MouseCursor &NewCursor)
00311 {
00312   REGS regs;
00313   SREGS sregs;
00314 
00315   if (!Operating())
00316     return;
00317 
00318   regs.x.ax = 9;
00319   regs.x.bx = NewCursor.HotSpot.X;
00320   regs.x.cx = NewCursor.HotSpot.Y;
00321   regs.x.dx = FP_OFF(NewCursor.ScreenMask);
00322   sregs.es = FP_SEG(NewCursor.ScreenMask);
00323 
00324   int86x(MsCall, &regs, &regs, &sregs);
00325 }
00326 
00327 void MSMouse::SetMouseCursor(int Mx, int My)
00328 {
00329   REGS regs;
00330 
00331   regs.x.ax = 0x4;
00332   regs.x.cx = Mx;
00333   regs.x.dx = My;
00334 
00335   int86(MsCall, &regs, &regs);
00336 }
00337 
00338 void MSMouse::SetSpeed2()
00339 {
00340   REGS regs;
00341 
00342   regs.x.ax = 0x13;
00343   regs.x.dx = THRESHOLD;
00344 
00345   int86(MsCall, &regs, &regs);
00346 }
00347 
00348 
00349 void MSMouse::Flush (void)
00350 {
00351   Message m;
00352   do {
00353     m = Event ();
00354   } while (m.code != Idle);
00355 }
00356 

Generated on Sun Jul 6 23:07:15 2003 for Scotland Yard by doxygen1.2.15