00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00044
00045
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, ®s, ®s);
00067 if (regs.x.ax == 0)
00068 OK = False;
00069 }
00070 if (!OK) {
00071 TurnOff();
00072 return;
00073
00074 }
00075 TurnOn();
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, ®s, ®s);
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, ®s, ®s);
00108 }
00109
00110
00111 unsigned MSMouse::Status (int &Mx, int &My)
00112
00113
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, ®s, ®s);
00124
00125 Mx = regs.x.cx;
00126 My = regs.x.dx;
00127
00128 if (TextMode) {
00129 Mx >>= 3;
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;
00158 int86(MsCall, ®s, ®s);
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, ®s, ®s);
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
00186 E = Status(Mx,My);
00187
00188
00189
00190
00191
00192 if (E == 0) {
00193 if (PressCnt(LeftButton) > 0)
00194 E = LMouseDown;
00195 else
00196 if (PressCnt (RightButton) > 0)
00197 E = RMouseDown;
00198
00199 else
00200 if (ReleaseCnt (LeftButton) > 0)
00201 E = LMouseUp;
00202
00203 else
00204 if (ReleaseCnt(RightButton) > 0)
00205 E = RMouseDown;
00206 else
00207 E = Idle;
00208 }
00209
00210 else {
00211
00212 if (E & LeftButton) {
00213
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, ®s, ®s);
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, ®s, ®s, &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, ®s, ®s);
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, ®s, ®s);
00346 }
00347
00348
00349 void MSMouse::Flush (void)
00350 {
00351 Message m;
00352 do {
00353 m = Event ();
00354 } while (m.code != Idle);
00355 }
00356