]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libvgl/simple.c
In VGLClear(), check for the overlap of the mouse cursor in the whole
[FreeBSD/FreeBSD.git] / lib / libvgl / simple.c
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1991-1997 Søren Schmidt
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer
12  *    in this position and unchanged.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33
34 #include <signal.h>
35 #include <sys/fbio.h>
36 #include <sys/kbio.h>
37 #include <sys/endian.h>
38 #include "vgl.h"
39
40 static int VGLBlank;
41 static byte VGLBorderColor;
42 static byte VGLSavePaletteRed[256];
43 static byte VGLSavePaletteGreen[256];
44 static byte VGLSavePaletteBlue[256];
45
46 #define ABS(a)          (((a)<0) ? -(a) : (a))
47 #define SGN(a)          (((a)<0) ? -1 : 1)
48 #define min(x, y)       (((x) < (y)) ? (x) : (y))
49 #define max(x, y)       (((x) > (y)) ? (x) : (y))
50
51 void
52 VGLSetXY(VGLBitmap *object, int x, int y, u_long color)
53 {
54   int offset, soffset, undermouse;
55
56   VGLCheckSwitch();
57   if (x>=0 && x<object->VXsize && y>=0 && y<object->VYsize) {
58     if (object == VGLDisplay) {
59       undermouse = VGLMouseFreezeXY(x, y);
60       VGLSetXY(&VGLVDisplay, x, y, color);
61     } else if (object->Type != MEMBUF)
62       return;           /* invalid */
63     else
64       undermouse = 0;
65     if (!undermouse) {
66       offset = (y * object->VXsize + x) * object->PixelBytes;
67       switch (object->Type) {
68       case VIDBUF8S:
69       case VIDBUF16S:
70       case VIDBUF32S:
71         offset = VGLSetSegment(offset);
72         /* FALLTHROUGH */
73       case MEMBUF:
74       case VIDBUF8:
75       case VIDBUF16:
76       case VIDBUF24:
77       case VIDBUF32:
78         color = htole32(color);
79         switch (object->PixelBytes) {
80         case 1:
81           memcpy(&object->Bitmap[offset], &color, 1);
82           break;
83         case 2:
84           memcpy(&object->Bitmap[offset], &color, 2);
85           break;
86         case 3:
87           memcpy(&object->Bitmap[offset], &color, 3);
88           break;
89         case 4:
90           memcpy(&object->Bitmap[offset], &color, 4);
91           break;
92         }
93         break;
94       case VIDBUF24S:
95         soffset = VGLSetSegment(offset);
96         color = htole32(color);
97         switch (VGLAdpInfo.va_window_size - soffset) {
98         case 1:
99           memcpy(&object->Bitmap[soffset], &color, 1);
100           soffset = VGLSetSegment(offset + 1);
101           memcpy(&object->Bitmap[soffset], (byte *)&color + 1, 2);
102           break;
103         case 2:
104           memcpy(&object->Bitmap[soffset], &color, 2);
105           soffset = VGLSetSegment(offset + 2);
106           memcpy(&object->Bitmap[soffset], (byte *)&color + 2, 1);
107           break;
108         default:
109           memcpy(&object->Bitmap[soffset], &color, 3);
110           break;
111         }
112         break;
113       case VIDBUF8X:
114         outb(0x3c4, 0x02);
115         outb(0x3c5, 0x01 << (x&0x3));
116         object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)] = ((byte)color);
117         break;
118       case VIDBUF4S:
119         offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8);
120         goto set_planar;
121       case VIDBUF4:
122         offset = y*VGLAdpInfo.va_line_width + x/8;
123 set_planar:
124         outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
125         outb(0x3ce, 0x00); outb(0x3cf, (byte)color & 0x0f);     /* set/reset */
126         outb(0x3ce, 0x01); outb(0x3cf, 0x0f);           /* set/reset enable */
127         outb(0x3ce, 0x08); outb(0x3cf, 0x80 >> (x%8));  /* bit mask */
128         object->Bitmap[offset] |= (byte)color;
129       }
130     }
131     if (object == VGLDisplay)
132       VGLMouseUnFreeze();
133   }
134 }
135
136 static u_long
137 __VGLGetXY(VGLBitmap *object, int x, int y)
138 {
139   int offset;
140   u_long color;
141
142   offset = (y * object->VXsize + x) * object->PixelBytes;
143   switch (object->PixelBytes) {
144   case 1:
145     memcpy(&color, &object->Bitmap[offset], 1);
146     return le32toh(color) & 0xff;
147   case 2:
148     memcpy(&color, &object->Bitmap[offset], 2);
149     return le32toh(color) & 0xffff;
150   case 3:
151     memcpy(&color, &object->Bitmap[offset], 3);
152     return le32toh(color) & 0xffffff;
153   case 4:
154     memcpy(&color, &object->Bitmap[offset], 4);
155     return le32toh(color);
156   }
157   return 0;             /* invalid */
158 }
159
160 u_long
161 VGLGetXY(VGLBitmap *object, int x, int y)
162 {
163   VGLCheckSwitch();
164   if (x<0 || x>=object->VXsize || y<0 || y>=object->VYsize)
165     return 0;
166   if (object == VGLDisplay)
167     object = &VGLVDisplay;
168   else if (object->Type != MEMBUF)
169     return 0;           /* invalid */
170   return __VGLGetXY(object, x, y);
171 }
172
173  /*
174   * Symmetric Double Step Line Algorithm by Brian Wyvill from
175   * "Graphics Gems", Academic Press, 1990.
176   */
177
178 #define SL_SWAP(a,b)           {a^=b; b^=a; a^=b;}
179 #define SL_ABSOLUTE(i,j,k)     ( (i-j)*(k = ( (i-j)<0 ? -1 : 1)))
180
181 void
182 plot(VGLBitmap * object, int x, int y, int flag, u_long color)
183 {
184   /* non-zero flag indicates the pixels need swapping back. */
185   if (flag)
186     VGLSetXY(object, y, x, color);
187   else
188     VGLSetXY(object, x, y, color);
189 }
190
191
192 void
193 VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
194 {
195   int dx, dy, incr1, incr2, D, x, y, xend, c, pixels_left;
196   int sign_x, sign_y, step, reverse, i;
197
198   dx = SL_ABSOLUTE(x2, x1, sign_x);
199   dy = SL_ABSOLUTE(y2, y1, sign_y);
200   /* decide increment sign by the slope sign */
201   if (sign_x == sign_y)
202     step = 1;
203   else
204     step = -1;
205
206   if (dy > dx) {        /* chooses axis of greatest movement (make dx) */
207     SL_SWAP(x1, y1);
208     SL_SWAP(x2, y2);
209     SL_SWAP(dx, dy);
210     reverse = 1;
211   } else
212     reverse = 0;
213   /* note error check for dx==0 should be included here */
214   if (x1 > x2) {      /* start from the smaller coordinate */
215     x = x2;
216     y = y2;
217 /*  x1 = x1;
218     y1 = y1; */
219   } else {
220     x = x1;
221     y = y1;
222     x1 = x2;
223     y1 = y2;
224   }
225
226
227   /* Note dx=n implies 0 - n or (dx+1) pixels to be set */
228   /* Go round loop dx/4 times then plot last 0,1,2 or 3 pixels */
229   /* In fact (dx-1)/4 as 2 pixels are already plotted */
230   xend = (dx - 1) / 4;
231   pixels_left = (dx - 1) % 4;  /* number of pixels left over at the
232            * end */
233   plot(object, x, y, reverse, color);
234   if (pixels_left < 0)
235     return;      /* plot only one pixel for zero length
236            * vectors */
237   plot(object, x1, y1, reverse, color);  /* plot first two points */
238   incr2 = 4 * dy - 2 * dx;
239   if (incr2 < 0) {    /* slope less than 1/2 */
240     c = 2 * dy;
241     incr1 = 2 * c;
242     D = incr1 - dx;
243
244     for (i = 0; i < xend; i++) {  /* plotting loop */
245       ++x;
246       --x1;
247       if (D < 0) {
248         /* pattern 1 forwards */
249         plot(object, x, y, reverse, color);
250         plot(object, ++x, y, reverse, color);
251         /* pattern 1 backwards */
252         plot(object, x1, y1, reverse, color);
253         plot(object, --x1, y1, reverse, color);
254         D += incr1;
255       } else {
256         if (D < c) {
257           /* pattern 2 forwards */
258           plot(object, x, y, reverse, color);
259           plot(object, ++x, y += step, reverse,
260               color);
261           /* pattern 2 backwards */
262           plot(object, x1, y1, reverse, color);
263           plot(object, --x1, y1 -= step, reverse,
264               color);
265         } else {
266           /* pattern 3 forwards */
267           plot(object, x, y += step, reverse, color);
268           plot(object, ++x, y, reverse, color);
269           /* pattern 3 backwards */
270           plot(object, x1, y1 -= step, reverse,
271               color);
272           plot(object, --x1, y1, reverse, color);
273         }
274         D += incr2;
275       }
276     }      /* end for */
277
278     /* plot last pattern */
279     if (pixels_left) {
280       if (D < 0) {
281         plot(object, ++x, y, reverse, color);  /* pattern 1 */
282         if (pixels_left > 1)
283           plot(object, ++x, y, reverse, color);
284         if (pixels_left > 2)
285           plot(object, --x1, y1, reverse, color);
286       } else {
287         if (D < c) {
288           plot(object, ++x, y, reverse, color);  /* pattern 2  */
289           if (pixels_left > 1)
290             plot(object, ++x, y += step, reverse, color);
291           if (pixels_left > 2)
292             plot(object, --x1, y1, reverse, color);
293         } else {
294           /* pattern 3 */
295           plot(object, ++x, y += step, reverse, color);
296           if (pixels_left > 1)
297             plot(object, ++x, y, reverse, color);
298           if (pixels_left > 2)
299             plot(object, --x1, y1 -= step, reverse, color);
300         }
301       }
302     }      /* end if pixels_left */
303   }
304   /* end slope < 1/2 */
305   else {        /* slope greater than 1/2 */
306     c = 2 * (dy - dx);
307     incr1 = 2 * c;
308     D = incr1 + dx;
309     for (i = 0; i < xend; i++) {
310       ++x;
311       --x1;
312       if (D > 0) {
313         /* pattern 4 forwards */
314         plot(object, x, y += step, reverse, color);
315         plot(object, ++x, y += step, reverse, color);
316         /* pattern 4 backwards */
317         plot(object, x1, y1 -= step, reverse, color);
318         plot(object, --x1, y1 -= step, reverse, color);
319         D += incr1;
320       } else {
321         if (D < c) {
322           /* pattern 2 forwards */
323           plot(object, x, y, reverse, color);
324           plot(object, ++x, y += step, reverse,
325               color);
326
327           /* pattern 2 backwards */
328           plot(object, x1, y1, reverse, color);
329           plot(object, --x1, y1 -= step, reverse,
330               color);
331         } else {
332           /* pattern 3 forwards */
333           plot(object, x, y += step, reverse, color);
334           plot(object, ++x, y, reverse, color);
335           /* pattern 3 backwards */
336           plot(object, x1, y1 -= step, reverse, color);
337           plot(object, --x1, y1, reverse, color);
338         }
339         D += incr2;
340       }
341     }      /* end for */
342     /* plot last pattern */
343     if (pixels_left) {
344       if (D > 0) {
345         plot(object, ++x, y += step, reverse, color);  /* pattern 4 */
346         if (pixels_left > 1)
347           plot(object, ++x, y += step, reverse,
348               color);
349         if (pixels_left > 2)
350           plot(object, --x1, y1 -= step, reverse,
351               color);
352       } else {
353         if (D < c) {
354           plot(object, ++x, y, reverse, color);  /* pattern 2  */
355           if (pixels_left > 1)
356             plot(object, ++x, y += step, reverse, color);
357           if (pixels_left > 2)
358             plot(object, --x1, y1, reverse, color);
359         } else {
360           /* pattern 3 */
361           plot(object, ++x, y += step, reverse, color);
362           if (pixels_left > 1)
363             plot(object, ++x, y, reverse, color);
364           if (pixels_left > 2) {
365             if (D > c)  /* step 3 */
366               plot(object, --x1, y1 -= step, reverse, color);
367             else  /* step 2 */
368               plot(object, --x1, y1, reverse, color);
369           }
370         }
371       }
372     }
373   }
374 }
375
376 void
377 VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
378 {
379   VGLLine(object, x1, y1, x2, y1, color);
380   VGLLine(object, x2, y1, x2, y2, color);
381   VGLLine(object, x2, y2, x1, y2, color);
382   VGLLine(object, x1, y2, x1, y1, color);
383 }
384
385 void
386 VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
387 {
388   int y;
389
390   for (y=y1; y<=y2; y++) VGLLine(object, x1, y, x2, y, color);
391 }
392
393 static inline void
394 set4pixels(VGLBitmap *object, int x, int y, int xc, int yc, u_long color)
395 {
396   if (x!=0) { 
397     VGLSetXY(object, xc+x, yc+y, color); 
398     VGLSetXY(object, xc-x, yc+y, color); 
399     if (y!=0) { 
400       VGLSetXY(object, xc+x, yc-y, color); 
401       VGLSetXY(object, xc-x, yc-y, color); 
402     } 
403   } 
404   else { 
405     VGLSetXY(object, xc, yc+y, color); 
406     if (y!=0) 
407       VGLSetXY(object, xc, yc-y, color); 
408   } 
409 }
410
411 void
412 VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color)
413 {
414   int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b;
415   int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b;
416
417   while (dx<dy) {
418     set4pixels(object, x, y, xc, yc, color);
419     if (d>0) {
420       y--; dy-=asq2; d-=dy;
421     }
422     x++; dx+=bsq2; d+=bsq+dx;
423   }
424   d+=(3*(asq-bsq)/2-(dx+dy))/2;
425   while (y>=0) {
426     set4pixels(object, x, y, xc, yc, color);
427     if (d<0) {
428       x++; dx+=bsq2; d+=dx;
429     }
430     y--; dy-=asq2; d+=asq-dy;
431   }
432 }
433
434 static inline void
435 set2lines(VGLBitmap *object, int x, int y, int xc, int yc, u_long color)
436 {
437   if (x!=0) { 
438     VGLLine(object, xc+x, yc+y, xc-x, yc+y, color); 
439     if (y!=0) 
440       VGLLine(object, xc+x, yc-y, xc-x, yc-y, color); 
441   } 
442   else { 
443     VGLLine(object, xc, yc+y, xc, yc-y, color); 
444   } 
445 }
446
447 void
448 VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color)
449 {
450   int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b;
451   int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b;
452
453   while (dx<dy) {
454     set2lines(object, x, y, xc, yc, color);
455     if (d>0) {
456       y--; dy-=asq2; d-=dy;
457     }
458     x++; dx+=bsq2; d+=bsq+dx;
459   }
460   d+=(3*(asq-bsq)/2-(dx+dy))/2;
461   while (y>=0) {
462     set2lines(object, x, y, xc, yc, color);
463     if (d<0) {
464       x++; dx+=bsq2; d+=dx;
465     }
466     y--; dy-=asq2; d+=asq-dy;
467   }
468 }
469
470 void
471 VGLClear(VGLBitmap *object, u_long color)
472 {
473   VGLBitmap src;
474   int i, len, mouseoverlap, offset;
475
476   VGLCheckSwitch();
477   if (object == VGLDisplay) {
478     VGLMouseFreeze();
479     mouseoverlap = VGLMouseOverlap(0, 0, object->VXsize, object->VYsize);
480     if (mouseoverlap)
481       VGLMousePointerHide();
482     VGLClear(&VGLVDisplay, color);
483   } else if (object->Type != MEMBUF)
484     return;             /* invalid */
485   switch (object->Type) {
486   case MEMBUF:
487   case VIDBUF8:
488   case VIDBUF8S:
489   case VIDBUF16:
490   case VIDBUF16S:
491   case VIDBUF24:
492   case VIDBUF24S:
493   case VIDBUF32:
494   case VIDBUF32S:
495     src.Type = MEMBUF;
496     src.Xsize = object->Xsize;
497     src.VXsize = object->VXsize;
498     src.Ysize = 1;
499     src.VYsize = 1;
500     src.Xorigin = 0;
501     src.Yorigin = 0;
502     src.Bitmap = alloca(object->VXsize * object->PixelBytes);
503     src.PixelBytes = object->PixelBytes;
504     color = htole32(color);
505     for (i = 0; i < object->VXsize; i++)
506       bcopy(&color, src.Bitmap + i * object->PixelBytes, object->PixelBytes);
507     for (i = 0; i < object->VYsize; i++)
508       __VGLBitmapCopy(&src, 0, 0, object, 0, i, object->VXsize, 1);
509     break;
510
511   case VIDBUF8X:
512     /* XXX works only for Xsize % 4 = 0 */
513     outb(0x3c6, 0xff);
514     outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
515     memset(object->Bitmap, (byte)color, VGLAdpInfo.va_line_width*object->VYsize);
516     break;
517
518   case VIDBUF4:
519   case VIDBUF4S:
520     /* XXX works only for Xsize % 8 = 0 */
521     outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
522     outb(0x3ce, 0x05); outb(0x3cf, 0x02);               /* mode 2 */
523     outb(0x3ce, 0x01); outb(0x3cf, 0x00);               /* set/reset enable */
524     outb(0x3ce, 0x08); outb(0x3cf, 0xff);               /* bit mask */
525     for (offset = 0; offset < VGLAdpInfo.va_line_width*object->VYsize; ) {
526       VGLSetSegment(offset);
527       len = min(object->VXsize*object->VYsize - offset,
528                 VGLAdpInfo.va_window_size);
529       memset(object->Bitmap, (byte)color, len);
530       offset += len;
531     }
532     outb(0x3ce, 0x05); outb(0x3cf, 0x00);
533     break;
534   }
535   if (object == VGLDisplay) {
536     if (mouseoverlap)
537       VGLMousePointerShow();
538     VGLMouseUnFreeze();
539   }
540 }
541
542 static inline u_long
543 VGLrgbToNative(uint16_t r, uint16_t g, uint16_t b)
544 {
545   int nr, ng, nb;
546
547   nr = VGLModeInfo.vi_pixel_fsizes[2];
548   ng = VGLModeInfo.vi_pixel_fsizes[1];
549   nb = VGLModeInfo.vi_pixel_fsizes[0];
550   return (r >> (16 - nr) << (ng + nb)) | (g >> (16 - ng) << nb) |
551          (b >> (16 - nb) << 0);
552 }
553
554 u_long
555 VGLrgb332ToNative(byte c)
556 {
557   uint16_t r, g, b;
558
559   /* 3:3:2 to 16:16:16 */
560   r = ((c & 0xe0) >> 5) * 0xffff / 7;
561   g = ((c & 0x1c) >> 2) * 0xffff / 7;
562   b = ((c & 0x03) >> 0) * 0xffff / 3;
563
564   return VGLrgbToNative(r, g, b);
565 }
566
567 void
568 VGLRestorePalette()
569 {
570   int i;
571
572   if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT)
573     return;
574   outb(0x3C6, 0xFF);
575   inb(0x3DA); 
576   outb(0x3C8, 0x00);
577   for (i=0; i<256; i++) {
578     outb(0x3C9, VGLSavePaletteRed[i]);
579     inb(0x84);
580     outb(0x3C9, VGLSavePaletteGreen[i]);
581     inb(0x84);
582     outb(0x3C9, VGLSavePaletteBlue[i]);
583     inb(0x84);
584   }
585   inb(0x3DA);
586   outb(0x3C0, 0x20);
587 }
588
589 void
590 VGLSavePalette()
591 {
592   int i;
593
594   if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT)
595     return;
596   outb(0x3C6, 0xFF);
597   inb(0x3DA);
598   outb(0x3C7, 0x00);
599   for (i=0; i<256; i++) {
600     VGLSavePaletteRed[i] = inb(0x3C9);
601     inb(0x84);
602     VGLSavePaletteGreen[i] = inb(0x3C9);
603     inb(0x84);
604     VGLSavePaletteBlue[i] = inb(0x3C9);
605     inb(0x84);
606   }
607   inb(0x3DA);
608   outb(0x3C0, 0x20);
609 }
610
611 void
612 VGLSetPalette(byte *red, byte *green, byte *blue)
613 {
614   int i;
615   
616   if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT)
617     return;
618   for (i=0; i<256; i++) {
619     VGLSavePaletteRed[i] = red[i];
620     VGLSavePaletteGreen[i] = green[i];
621     VGLSavePaletteBlue[i] = blue[i];
622   }
623   VGLCheckSwitch();
624   outb(0x3C6, 0xFF);
625   inb(0x3DA); 
626   outb(0x3C8, 0x00);
627   for (i=0; i<256; i++) {
628     outb(0x3C9, VGLSavePaletteRed[i]);
629     inb(0x84);
630     outb(0x3C9, VGLSavePaletteGreen[i]);
631     inb(0x84);
632     outb(0x3C9, VGLSavePaletteBlue[i]);
633     inb(0x84);
634   }
635   inb(0x3DA);
636   outb(0x3C0, 0x20);
637 }
638
639 void
640 VGLSetPaletteIndex(byte color, byte red, byte green, byte blue)
641 {
642   if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT)
643     return;
644   VGLSavePaletteRed[color] = red;
645   VGLSavePaletteGreen[color] = green;
646   VGLSavePaletteBlue[color] = blue;
647   VGLCheckSwitch();
648   outb(0x3C6, 0xFF);
649   inb(0x3DA);
650   outb(0x3C8, color); 
651   outb(0x3C9, red); outb(0x3C9, green); outb(0x3C9, blue);
652   inb(0x3DA);
653   outb(0x3C0, 0x20);
654 }
655
656 void
657 VGLRestoreBorder(void)
658 {
659   VGLSetBorder(VGLBorderColor);
660 }
661
662 void
663 VGLSetBorder(byte color)
664 {
665   if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT && ioctl(0, KDENABIO, 0))
666     return;
667   VGLCheckSwitch();
668   inb(0x3DA);
669   outb(0x3C0,0x11); outb(0x3C0, color); 
670   inb(0x3DA);
671   outb(0x3C0, 0x20);
672   VGLBorderColor = color;
673   if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT)
674     ioctl(0, KDDISABIO, 0);
675 }
676
677 void
678 VGLRestoreBlank(void)
679 {
680   VGLBlankDisplay(VGLBlank);
681 }
682
683 void
684 VGLBlankDisplay(int blank)
685 {
686   byte val;
687
688   if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT && ioctl(0, KDENABIO, 0))
689     return;
690   VGLCheckSwitch();
691   outb(0x3C4, 0x01); val = inb(0x3C5); outb(0x3C4, 0x01);
692   outb(0x3C5, ((blank) ? (val |= 0x20) : (val &= 0xDF)));
693   VGLBlank = blank;
694   if (VGLModeInfo.vi_mem_model == V_INFO_MM_DIRECT)
695     ioctl(0, KDDISABIO, 0);
696 }