1 |
greg |
2.1 |
#ifndef lint |
2 |
greg |
2.6 |
static const char RCSid[] = "$Id$"; |
3 |
greg |
2.1 |
#endif |
4 |
|
|
#include <i86.h> |
5 |
|
|
#include <graph.h> |
6 |
|
|
#include "driver.h" |
7 |
|
|
|
8 |
greg |
2.5 |
#define NULL 0 |
9 |
|
|
|
10 |
greg |
2.1 |
#define M_RIGHTBUTT 0x8 |
11 |
|
|
#define M_LEFTBUTT 0x2 |
12 |
|
|
#define M_MOTION 0x1 |
13 |
|
|
|
14 |
greg |
2.2 |
static int xdispsize, ydispsize; |
15 |
greg |
2.1 |
static int crad; |
16 |
|
|
#define right_button (mouse_event & M_RIGHTBUTT) |
17 |
|
|
#define left_button (mouse_event & M_LEFTBUTT) |
18 |
|
|
static int mouse_event = 0; |
19 |
|
|
static int mouse_xpos = -1; |
20 |
|
|
static int mouse_ypos = -1; |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
#pragma off (check_stack) |
24 |
|
|
static void _loadds far mouse_handler (int max, int mcx, int mdx) |
25 |
|
|
{ |
26 |
|
|
#pragma aux mouse_handler parm [EAX] [ECX] [EDX] |
27 |
|
|
mouse_event = max; |
28 |
|
|
mouse_xpos = mcx; |
29 |
greg |
2.3 |
mouse_ypos = mdx; |
30 |
greg |
2.1 |
} |
31 |
|
|
#pragma on (check_stack) |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
static void |
35 |
|
|
move_cursor(newx, newy) /* move cursor to new position */ |
36 |
|
|
int newx, newy; |
37 |
|
|
{ |
38 |
|
|
extern char *bmalloc(); |
39 |
|
|
static char *imp = NULL; |
40 |
|
|
static int curx = -1, cury = -1; |
41 |
greg |
2.2 |
#define xcmin (curx-crad<0 ? 0 : curx-crad) |
42 |
|
|
#define ycmin (cury-crad<0 ? 0 : cury-crad) |
43 |
|
|
#define xcmax (curx+crad>=xdispsize ? xdispsize-1 : curx+crad) |
44 |
|
|
#define ycmax (cury+crad>=ydispsize ? ydispsize-1 : cury+crad) |
45 |
greg |
2.1 |
|
46 |
|
|
if (imp == NULL && |
47 |
|
|
(imp = bmalloc(_imagesize(0,0,2*crad+1,2*crad+1))) == NULL) { |
48 |
|
|
eputs("out of memory in move_cursor"); |
49 |
|
|
quit(1); |
50 |
|
|
} |
51 |
|
|
if (curx >= 0 & cury >= 0) /* clear old cursor */ |
52 |
greg |
2.2 |
_putimage(xcmin, ycmin, imp, _GPSET); |
53 |
greg |
2.1 |
/* record new position */ |
54 |
|
|
curx = newx; cury = newy; |
55 |
|
|
if (curx < 0 | cury < 0) |
56 |
|
|
return; /* no cursor */ |
57 |
|
|
/* save under new cursor */ |
58 |
greg |
2.2 |
_getimage(xcmin, ycmin, xcmax, ycmax, imp); |
59 |
greg |
2.1 |
/* draw new cursor */ |
60 |
|
|
_setcolor(1); |
61 |
greg |
2.2 |
_rectangle(_GFILLINTERIOR, xcmin, cury-1, xcmax, cury+1); |
62 |
|
|
_rectangle(_GFILLINTERIOR, curx-1, ycmin, curx+1, ycmax); |
63 |
greg |
2.1 |
_setcolor(0); |
64 |
greg |
2.2 |
_moveto(xcmin+1, cury); |
65 |
|
|
_lineto(xcmax-1, cury); |
66 |
|
|
_moveto(curx, ycmin+1); |
67 |
|
|
_lineto(curx, ycmax-1); |
68 |
|
|
#undef xcmin |
69 |
|
|
#undef ycmin |
70 |
|
|
#undef xcmax |
71 |
|
|
#undef ycmax |
72 |
greg |
2.1 |
} |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
static int |
76 |
|
|
ms_getcur(xp, yp) /* get mouse cursor position */ |
77 |
|
|
int *xp, *yp; |
78 |
|
|
{ |
79 |
|
|
/* show cursor */ |
80 |
|
|
|
81 |
|
|
move_cursor(mouse_xpos, mouse_ypos); |
82 |
|
|
|
83 |
|
|
/* update cursor until button pressed */ |
84 |
|
|
|
85 |
|
|
do { |
86 |
|
|
mouse_event = 0; |
87 |
|
|
while( !mouse_event ) |
88 |
|
|
if (kbhit()) |
89 |
|
|
switch (getch()) { |
90 |
|
|
case MB1: |
91 |
|
|
mouse_event = M_LEFTBUTT; |
92 |
|
|
break; |
93 |
|
|
case MB2: |
94 |
|
|
case MB3: |
95 |
|
|
mouse_event = M_RIGHTBUTT; |
96 |
|
|
break; |
97 |
|
|
default: |
98 |
|
|
mouse_event = M_RIGHTBUTT | M_LEFTBUTT; |
99 |
|
|
break; |
100 |
|
|
} |
101 |
|
|
if (mouse_event & M_MOTION) |
102 |
|
|
move_cursor(mouse_xpos, mouse_ypos); |
103 |
|
|
} while (!(mouse_event & (M_RIGHTBUTT|M_LEFTBUTT))); |
104 |
|
|
|
105 |
|
|
/* clear cursor */ |
106 |
|
|
|
107 |
|
|
move_cursor(-1, -1); |
108 |
|
|
|
109 |
|
|
/* compute final position */ |
110 |
|
|
|
111 |
|
|
if (mouse_xpos < 0 | mouse_ypos < 0) |
112 |
|
|
return(ABORT); |
113 |
|
|
|
114 |
|
|
*xp = mouse_xpos; |
115 |
|
|
*yp = ydispsize-1 - mouse_ypos; |
116 |
|
|
|
117 |
|
|
switch (mouse_event) { |
118 |
|
|
case M_LEFTBUTT: |
119 |
|
|
case M_LEFTBUTT|M_MOTION: |
120 |
|
|
return(MB1); |
121 |
|
|
case M_RIGHTBUTT: |
122 |
|
|
case M_RIGHTBUTT|M_MOTION: |
123 |
|
|
return(MB2); |
124 |
|
|
} |
125 |
|
|
return(ABORT); |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
|
129 |
|
|
void |
130 |
|
|
ms_gcinit( dp ) |
131 |
|
|
struct driver *dp; |
132 |
|
|
{ |
133 |
|
|
struct SREGS sregs; |
134 |
|
|
union REGS inregs, outregs; |
135 |
|
|
int far *ptr; |
136 |
|
|
int (far *function_ptr)(); |
137 |
|
|
|
138 |
|
|
segread(&sregs); |
139 |
|
|
|
140 |
|
|
/* check for mouse driver */ |
141 |
|
|
|
142 |
|
|
inregs.w.ax = 0; |
143 |
|
|
int386 (0x33, &inregs, &outregs); |
144 |
|
|
if( outregs.w.ax != -1 ) { |
145 |
|
|
dp->getcur = NULL; |
146 |
|
|
return; |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
/* get relevant parameters */ |
150 |
|
|
|
151 |
greg |
2.2 |
xdispsize = dp->xsiz; |
152 |
greg |
2.1 |
ydispsize = dp->ysiz; |
153 |
|
|
crad = dp->ysiz/40; |
154 |
greg |
2.3 |
|
155 |
|
|
/* set screen limits */ |
156 |
|
|
|
157 |
|
|
inregs.w.ax = 0x7; /* horizontal resolution */ |
158 |
|
|
inregs.w.cx = 0; |
159 |
|
|
inregs.w.dx = xdispsize-1; |
160 |
|
|
int386x( 0x33, &inregs, &outregs, &sregs ); |
161 |
|
|
inregs.w.ax = 0x8; /* vertical resolution */ |
162 |
|
|
inregs.w.cx = 0; |
163 |
|
|
inregs.w.dx = ydispsize-1; |
164 |
|
|
int386x( 0x33, &inregs, &outregs, &sregs ); |
165 |
greg |
2.1 |
|
166 |
|
|
/* install watcher */ |
167 |
|
|
|
168 |
|
|
inregs.w.ax = 0xC; |
169 |
|
|
inregs.w.cx = M_RIGHTBUTT | M_LEFTBUTT | M_MOTION; |
170 |
|
|
function_ptr = mouse_handler; |
171 |
|
|
inregs.x.edx = FP_OFF( function_ptr ); |
172 |
|
|
sregs.es = FP_SEG( function_ptr ); |
173 |
|
|
int386x( 0x33, &inregs, &outregs, &sregs ); |
174 |
|
|
|
175 |
|
|
dp->getcur = ms_getcur; |
176 |
|
|
} |
177 |
greg |
2.4 |
|
178 |
|
|
void |
179 |
|
|
ms_gcdone( dp ) |
180 |
|
|
struct driver *dp; |
181 |
|
|
{ |
182 |
|
|
union REGS inregs, outregs; |
183 |
|
|
|
184 |
|
|
if (dp->getcur != ms_getcur) |
185 |
|
|
return; /* not installed */ |
186 |
|
|
|
187 |
|
|
dp->getcur = NULL; |
188 |
|
|
|
189 |
|
|
/* uninstall watcher */ |
190 |
|
|
|
191 |
|
|
inregs.w.ax = 0; |
192 |
|
|
int386 (0x33, &inregs, &outregs); |
193 |
|
|
} |
194 |
|
|
|