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 withough 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.
28 * $FreeBSD: src/lib/libvgl/mouse.c,v 1.3 1999/11/08 11:37:39 yokota Exp $
32 #include <sys/types.h>
33 #include <sys/ioctl.h>
34 #include <sys/signal.h>
35 #include <machine/console.h>
39 static byte StdAndMask[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE] = {
40 X,X,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
41 X,X,X,0,0,0,0,0,0,0,0,0,0,0,0,0,
42 X,X,X,X,0,0,0,0,0,0,0,0,0,0,0,0,
43 X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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
76 static VGLBitmap VGLMouseStdAndMask =
77 VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdAndMask);
78 static VGLBitmap VGLMouseStdOrMask =
79 VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdOrMask);
80 static VGLBitmap *VGLMouseAndMask, *VGLMouseOrMask;
81 static byte map[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE];
82 static VGLBitmap VGLMouseSave =
83 VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, map);
84 static int VGLMouseVisible = 0;
85 static int VGLMouseFrozen = 0;
86 static int VGLMouseShown = 0;
87 static int VGLMouseXpos = 0;
88 static int VGLMouseYpos = 0;
89 static int VGLMouseButtons = 0;
94 byte buf[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE];
96 VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, buf);
97 byte crtcidx, crtcval, gdcidx, gdcval;
100 if (!VGLMouseVisible) {
102 crtcidx = inb(0x3c4);
103 crtcval = inb(0x3c5);
106 __VGLBitmapCopy(VGLDisplay, VGLMouseXpos, VGLMouseYpos,
107 &VGLMouseSave, 0, 0, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
108 bcopy(VGLMouseSave.Bitmap, buffer.Bitmap, MOUSE_IMG_SIZE*MOUSE_IMG_SIZE);
109 for (pos = 0; pos < MOUSE_IMG_SIZE*MOUSE_IMG_SIZE; pos++)
110 buffer.Bitmap[pos]=(buffer.Bitmap[pos]&~(VGLMouseAndMask->Bitmap[pos])) |
111 VGLMouseOrMask->Bitmap[pos];
112 __VGLBitmapCopy(&buffer, 0, 0, VGLDisplay,
113 VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
114 outb(0x3c4, crtcidx);
115 outb(0x3c5, crtcval);
122 VGLMousePointerHide()
124 byte crtcidx, crtcval, gdcidx, gdcval;
126 if (VGLMouseVisible) {
128 crtcidx = inb(0x3c4);
129 crtcval = inb(0x3c5);
132 __VGLBitmapCopy(&VGLMouseSave, 0, 0, VGLDisplay,
133 VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE);
134 outb(0x3c4, crtcidx);
135 outb(0x3c5, crtcval);
142 VGLMouseMode(int mode)
144 if (mode == VGL_MOUSESHOW) {
145 if (VGLMouseShown == VGL_MOUSEHIDE) {
146 VGLMousePointerShow();
147 VGLMouseShown = VGL_MOUSESHOW;
151 if (VGLMouseShown == VGL_MOUSESHOW) {
152 VGLMousePointerHide();
153 VGLMouseShown = VGL_MOUSEHIDE;
159 VGLMouseAction(int dummy)
161 struct mouse_info mouseinfo;
163 if (VGLMouseFrozen) {
167 mouseinfo.operation = MOUSE_GETINFO;
168 ioctl(0, CONS_MOUSECTL, &mouseinfo);
169 if (VGLMouseShown == VGL_MOUSESHOW)
170 VGLMousePointerHide();
171 VGLMouseXpos = mouseinfo.u.data.x;
172 VGLMouseYpos = mouseinfo.u.data.y;
173 VGLMouseButtons = mouseinfo.u.data.buttons;
174 if (VGLMouseShown == VGL_MOUSESHOW)
175 VGLMousePointerShow();
179 VGLMouseSetImage(VGLBitmap *AndMask, VGLBitmap *OrMask)
181 if (VGLMouseShown == VGL_MOUSESHOW)
182 VGLMousePointerHide();
183 VGLMouseAndMask = AndMask;
184 VGLMouseOrMask = OrMask;
185 if (VGLMouseShown == VGL_MOUSESHOW)
186 VGLMousePointerShow();
190 VGLMouseSetStdImage()
192 if (VGLMouseShown == VGL_MOUSESHOW)
193 VGLMousePointerHide();
194 VGLMouseAndMask = &VGLMouseStdAndMask;
195 VGLMouseOrMask = &VGLMouseStdOrMask;
196 if (VGLMouseShown == VGL_MOUSESHOW)
197 VGLMousePointerShow();
201 VGLMouseInit(int mode)
203 struct mouse_info mouseinfo;
206 VGLMouseSetStdImage();
207 mouseinfo.operation = MOUSE_MODE;
208 mouseinfo.u.mode.signal = SIGUSR2;
209 if ((error = ioctl(0, CONS_MOUSECTL, &mouseinfo)))
211 signal(SIGUSR2, VGLMouseAction);
212 mouseinfo.operation = MOUSE_GETINFO;
213 ioctl(0, CONS_MOUSECTL, &mouseinfo);
214 VGLMouseXpos = mouseinfo.u.data.x;
215 VGLMouseYpos = mouseinfo.u.data.y;
216 VGLMouseButtons = mouseinfo.u.data.buttons;
222 VGLMouseStatus(int *x, int *y, char *buttons)
224 signal(SIGUSR2, SIG_IGN);
227 *buttons = VGLMouseButtons;
228 signal(SIGUSR2, VGLMouseAction);
229 return VGLMouseShown;
233 VGLMouseFreeze(int x, int y, int width, int hight, byte color)
235 if (!VGLMouseFrozen) {
237 if (width > 1 || hight > 1) { /* bitmap */
238 if (VGLMouseShown == 1) {
241 if (x > VGLMouseXpos)
242 overlap = (VGLMouseXpos + MOUSE_IMG_SIZE) - x;
244 overlap = (x + width) - VGLMouseXpos;
246 if (y > VGLMouseYpos)
247 overlap = (VGLMouseYpos + MOUSE_IMG_SIZE) - y;
249 overlap = (y + hight) - VGLMouseYpos;
251 VGLMousePointerHide();
257 x >= VGLMouseXpos && x < VGLMouseXpos + MOUSE_IMG_SIZE &&
258 y >= VGLMouseYpos && y < VGLMouseYpos + MOUSE_IMG_SIZE) {
259 VGLMouseSave.Bitmap[(y-VGLMouseYpos)*MOUSE_IMG_SIZE+(x-VGLMouseXpos)] =
261 if (VGLMouseAndMask->Bitmap
262 [(y-VGLMouseYpos)*MOUSE_IMG_SIZE+(x-VGLMouseXpos)]) {
274 if (VGLMouseFrozen > 1) {
280 if (VGLMouseShown == VGL_MOUSESHOW && !VGLMouseVisible)
281 VGLMousePointerShow();