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