Jspice3
msinterf.c
Go to the documentation of this file.
1 /*************************************************************************
2  MFB graphics and miscellaneous library for protected mode MSDOS.
3  Copyright (c) Stephen R. Whiteley 1992
4  Author: Stephen R. Whiteley
5  *************************************************************************/
6 
7 /* Microsoft mouse (or compatible) interface. */
8 
9 #include "mfb.h"
10 #include "mfbP.h"
11 #include <dos.h>
12 
13 
14 void
16 
17 /* initialize mouse pointing device */
18 {
19  union REGS r;
20 
21  if (!ms_hreset()) {
22  fprintf(stderr,"Error: Mouse driver not loaded.\n");
23  fprintf(stderr,"Using keyboard arrow keys. Hit any key to continue.\n");
24  (void)MFBGetchar();
26  MFBSetColor(0);
27  MFBFlood();
29  }
30  /* This driver is designed to work in "strange" super-VGA modes.
31  * The mouse driver thinks these are text mode, and quantizes the
32  * returned mouse position in units of 8. To avoid this, the logical
33  * screen size is multiplied by 8, and the return coordinates
34  * ( in ms_status() ) are divided by 8.
35  */
36 
37  /* set logical screen size */
38  r.x.ax = 7;
39  r.x.cx = 0;
40  r.x.dx = (pc.xsize-1) << 3;
41  int86(0x33,&r,&r);
42  r.x.ax = 8;
43  r.x.cx = 0;
44  r.x.dx = (pc.ysize-1) << 3;
45  int86(0x33,&r,&r);
46 
47  /* set mickeys/pixels ratio (1/8 default) */
48  r.x.ax = 0xf;
49  r.x.cx = 1;
50  r.x.dx = 2;
51 
52  /* move pointer to center of logical screen */
53  int86(0x33,&r,&r);
54  r.x.ax = 0x4;
55  r.x.cx = (pc.xsize-1) << 2;
56  r.x.dx = (pc.ysize-1) << 2;
57  int86(0x33,&r,&r);
58 }
59 
60 
61 void
63 
64 /* end mouse pointing device activity */
65 {
66  (void)ms_hreset();
67 }
68 
69 
70 int
72 /* reset mouse, return number of buttons, or 0 if error */
73 {
74  union REGS r;
75 
76  r.x.ax = 0x0;
77  int86(0x33,&r,&r);
78  if (r.x.ax == 0xffff)
79  return (r.x.bx);
80  return (0);
81 }
82 
83 
84 void
86 /* display mouse pointer */
87 {
88  union REGS r;
89 
90  /* don't use!
91  r.x.ax = 0x1;
92  int86(0x33,&r,&r);
93  */
94 }
95 
96 
97 void
99 /* hide mouse pointer */
100 {
101  union REGS r;
102 
103  r.x.ax = 0x2;
104  int86(0x33,&r,&r);
105 }
106 
107 
108 void
109 ms_status(x,y,b)
110 
111 /* get mouse position and button status */
112 int *x, *y, *b;
113 {
114  union REGS r;
115 
116  r.x.ax = 0x3;
117  int86(0x33,&r,&r);
118  /* physical screen = 1/8 logical screen */
119  *x = r.x.cx >> 3;
120  *y = r.x.dx >> 3;
121  *b = r.x.bx;
122 }
123 
124 
125 void
126 ms_point(x,y,k,b)
127 int *x, *y, *k, *b;
128 
129 {
130  int xx, yy, bb;
131  int xlst, ylst;
132 
133  ms_status(&xx,&yy,&bb);
134  yy = pc.ysize - yy - 1;
135  MFBDrawCursor(xx-8,yy+7);
136  for (;;) {
137  if (kbhit()) {
138  *k = 0xff & getch();
139  if (!*k)
140  *k = 256 + getch();
141  *b = 0;
142  break;
143  }
144  if (bb) {
145  *k = 0;
146  *b = bb;
147  break;
148  }
149  xlst = xx;
150  ylst = yy;
151  ms_status(&xx,&yy,&bb);
152  yy = pc.ysize - yy - 1;
153  if (xx == xlst && yy == ylst)
154  continue;
155  MFBEraseCursor(xlst-8,ylst+7);
156  MFBDrawCursor(xx-8,yy+7);
157  }
158  *x = xx;
159  *y = yy;
160  MFBEraseCursor(xx-8,yy+7);
161 }
int pointertype
Definition: mfbp.h:60
void MFBDrawCursor(int x, int y)
Definition: mfbmark.c:26
void ms_status(int *x, int *y, int *b)
Definition: msinterf.c:109
void ms_pointer_on()
Definition: msinterf.c:85
int ms_hreset()
Definition: msinterf.c:71
#define KBRD
Definition: mfbp.h:90
void ms_point(int *x, int *y, int *k, int *b)
Definition: msinterf.c:126
int ysize
Definition: mfbp.h:54
int MFBGetchar()
Definition: mfbopen.c:259
void MFBPointerInit()
Definition: mfbcursr.c:440
int MFBSetColor()
void ms_end()
Definition: msinterf.c:62
void MFBFlood()
Definition: mfbflood.c:21
int xsize
Definition: mfbp.h:53
void ms_start()
Definition: msinterf.c:15
struct mfbpc pc
Definition: mfbopen.c:14
void ms_pointer_off()
Definition: msinterf.c:98
void MFBEraseCursor(int x, int y)
Definition: mfbmark.c:48