2 * Copyright (c) 1991-1997 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
33 #include <sys/types.h>
34 #include <sys/ioctl.h>
35 #include <sys/signal.h>
36 #include <sys/consio.h>
41 static byte StdAndMask
[MOUSE_IMG_SIZE
*MOUSE_IMG_SIZE
] = {
42 X
,X
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
43 X
,X
,X
,0,0,0,0,0,0,0,0,0,0,0,0,0,
44 X
,X
,X
,X
,0,0,0,0,0,0,0,0,0,0,0,0,
45 X
,X
,X
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0,0,0,0,0,0,0,
73 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
74 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
75 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
78 static VGLBitmap VGLMouseStdAndMask
=
79 VGLBITMAP_INITIALIZER(MEMBUF
, MOUSE_IMG_SIZE
, MOUSE_IMG_SIZE
, StdAndMask
);
80 static VGLBitmap VGLMouseStdOrMask
=
81 VGLBITMAP_INITIALIZER(MEMBUF
, MOUSE_IMG_SIZE
, MOUSE_IMG_SIZE
, StdOrMask
);
82 static VGLBitmap
*VGLMouseAndMask
, *VGLMouseOrMask
;
83 static byte map
[MOUSE_IMG_SIZE
*MOUSE_IMG_SIZE
];
84 static VGLBitmap VGLMouseSave
=
85 VGLBITMAP_INITIALIZER(MEMBUF
, MOUSE_IMG_SIZE
, MOUSE_IMG_SIZE
, map
);
86 static int VGLMouseVisible
= 0;
87 static int VGLMouseFrozen
= 0;
88 static int VGLMouseShown
= 0;
89 static int VGLMouseXpos
= 0;
90 static int VGLMouseYpos
= 0;
91 static int VGLMouseButtons
= 0;
96 byte buf
[MOUSE_IMG_SIZE
*MOUSE_IMG_SIZE
];
98 VGLBITMAP_INITIALIZER(MEMBUF
, MOUSE_IMG_SIZE
, MOUSE_IMG_SIZE
, buf
);
99 byte crtcidx
, crtcval
, gdcidx
, gdcval
;
102 if (!VGLMouseVisible
) {
104 crtcidx
= inb(0x3c4);
105 crtcval
= inb(0x3c5);
108 __VGLBitmapCopy(VGLDisplay
, VGLMouseXpos
, VGLMouseYpos
,
109 &VGLMouseSave
, 0, 0, MOUSE_IMG_SIZE
, MOUSE_IMG_SIZE
);
110 bcopy(VGLMouseSave
.Bitmap
, buffer
.Bitmap
, MOUSE_IMG_SIZE
*MOUSE_IMG_SIZE
);
111 for (pos
= 0; pos
< MOUSE_IMG_SIZE
*MOUSE_IMG_SIZE
; pos
++)
112 buffer
.Bitmap
[pos
]=(buffer
.Bitmap
[pos
]&~(VGLMouseAndMask
->Bitmap
[pos
])) |
113 VGLMouseOrMask
->Bitmap
[pos
];
114 __VGLBitmapCopy(&buffer
, 0, 0, VGLDisplay
,
115 VGLMouseXpos
, VGLMouseYpos
, MOUSE_IMG_SIZE
, MOUSE_IMG_SIZE
);
116 outb(0x3c4, crtcidx
);
117 outb(0x3c5, crtcval
);
124 VGLMousePointerHide()
126 byte crtcidx
, crtcval
, gdcidx
, gdcval
;
128 if (VGLMouseVisible
) {
130 crtcidx
= inb(0x3c4);
131 crtcval
= inb(0x3c5);
134 __VGLBitmapCopy(&VGLMouseSave
, 0, 0, VGLDisplay
,
135 VGLMouseXpos
, VGLMouseYpos
, MOUSE_IMG_SIZE
, MOUSE_IMG_SIZE
);
136 outb(0x3c4, crtcidx
);
137 outb(0x3c5, crtcval
);
144 VGLMouseMode(int mode
)
146 if (mode
== VGL_MOUSESHOW
) {
147 if (VGLMouseShown
== VGL_MOUSEHIDE
) {
148 VGLMousePointerShow();
149 VGLMouseShown
= VGL_MOUSESHOW
;
153 if (VGLMouseShown
== VGL_MOUSESHOW
) {
154 VGLMousePointerHide();
155 VGLMouseShown
= VGL_MOUSEHIDE
;
161 VGLMouseAction(int dummy
)
163 struct mouse_info mouseinfo
;
165 if (VGLMouseFrozen
) {
169 mouseinfo
.operation
= MOUSE_GETINFO
;
170 ioctl(0, CONS_MOUSECTL
, &mouseinfo
);
171 if (VGLMouseShown
== VGL_MOUSESHOW
)
172 VGLMousePointerHide();
173 VGLMouseXpos
= mouseinfo
.u
.data
.x
;
174 VGLMouseYpos
= mouseinfo
.u
.data
.y
;
175 VGLMouseButtons
= mouseinfo
.u
.data
.buttons
;
176 if (VGLMouseShown
== VGL_MOUSESHOW
)
177 VGLMousePointerShow();
181 VGLMouseSetImage(VGLBitmap
*AndMask
, VGLBitmap
*OrMask
)
183 if (VGLMouseShown
== VGL_MOUSESHOW
)
184 VGLMousePointerHide();
185 VGLMouseAndMask
= AndMask
;
186 VGLMouseOrMask
= OrMask
;
187 if (VGLMouseShown
== VGL_MOUSESHOW
)
188 VGLMousePointerShow();
192 VGLMouseSetStdImage()
194 if (VGLMouseShown
== VGL_MOUSESHOW
)
195 VGLMousePointerHide();
196 VGLMouseAndMask
= &VGLMouseStdAndMask
;
197 VGLMouseOrMask
= &VGLMouseStdOrMask
;
198 if (VGLMouseShown
== VGL_MOUSESHOW
)
199 VGLMousePointerShow();
203 VGLMouseInit(int mode
)
205 struct mouse_info mouseinfo
;
208 VGLMouseSetStdImage();
209 mouseinfo
.operation
= MOUSE_MODE
;
210 mouseinfo
.u
.mode
.signal
= SIGUSR2
;
211 if ((error
= ioctl(0, CONS_MOUSECTL
, &mouseinfo
)))
213 signal(SIGUSR2
, VGLMouseAction
);
214 mouseinfo
.operation
= MOUSE_GETINFO
;
215 ioctl(0, CONS_MOUSECTL
, &mouseinfo
);
216 VGLMouseXpos
= mouseinfo
.u
.data
.x
;
217 VGLMouseYpos
= mouseinfo
.u
.data
.y
;
218 VGLMouseButtons
= mouseinfo
.u
.data
.buttons
;
224 VGLMouseStatus(int *x
, int *y
, char *buttons
)
226 signal(SIGUSR2
, SIG_IGN
);
229 *buttons
= VGLMouseButtons
;
230 signal(SIGUSR2
, VGLMouseAction
);
231 return VGLMouseShown
;
235 VGLMouseFreeze(int x
, int y
, int width
, int hight
, byte color
)
237 if (!VGLMouseFrozen
) {
239 if (width
> 1 || hight
> 1) { /* bitmap */
240 if (VGLMouseShown
== 1) {
243 if (x
> VGLMouseXpos
)
244 overlap
= (VGLMouseXpos
+ MOUSE_IMG_SIZE
) - x
;
246 overlap
= (x
+ width
) - VGLMouseXpos
;
248 if (y
> VGLMouseYpos
)
249 overlap
= (VGLMouseYpos
+ MOUSE_IMG_SIZE
) - y
;
251 overlap
= (y
+ hight
) - VGLMouseYpos
;
253 VGLMousePointerHide();
259 x
>= VGLMouseXpos
&& x
< VGLMouseXpos
+ MOUSE_IMG_SIZE
&&
260 y
>= VGLMouseYpos
&& y
< VGLMouseYpos
+ MOUSE_IMG_SIZE
) {
261 VGLMouseSave
.Bitmap
[(y
-VGLMouseYpos
)*MOUSE_IMG_SIZE
+(x
-VGLMouseXpos
)] =
263 if (VGLMouseAndMask
->Bitmap
264 [(y
-VGLMouseYpos
)*MOUSE_IMG_SIZE
+(x
-VGLMouseXpos
)]) {
276 if (VGLMouseFrozen
> 1) {
282 if (VGLMouseShown
== VGL_MOUSESHOW
&& !VGLMouseVisible
)
283 VGLMousePointerShow();