xref: /freebsd/lib/libvgl/simple.c (revision f5147e312f43a9050468de539aeafa072caa1a60)
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 "vgl.h"
37 
38 static byte VGLSavePaletteRed[256];
39 static byte VGLSavePaletteGreen[256];
40 static byte VGLSavePaletteBlue[256];
41 
42 #define ABS(a)		(((a)<0) ? -(a) : (a))
43 #define SGN(a)		(((a)<0) ? -1 : 1)
44 #define min(x, y)	(((x) < (y)) ? (x) : (y))
45 #define max(x, y)	(((x) > (y)) ? (x) : (y))
46 
47 static void
48 color2mem(u_long color, byte *b, int len)
49 {
50   switch (len) {
51   case 4:
52     b[3] = (color >> 24) & 0xff;
53     /* fallthrough */
54   case 3:
55     b[2] = (color >> 16) & 0xff;
56     /* fallthrough */
57   case 2:
58     b[1] = (color >> 8) & 0xff;
59     /* fallthrough */
60   case 1:
61   default:
62     b[0] = color & 0xff;
63     break;
64   }
65 
66   return;
67 }
68 
69 static u_long
70 mem2color(byte *b, int len)
71 {
72   u_long color = 0;
73 
74   switch (len) {
75   case 4:
76     color |= (b[3] & 0xff) << 24;
77     /* fallthrough */
78   case 3:
79     color |= (b[2] & 0xff) << 16;
80     /* fallthrough */
81   case 2:
82     color |= (b[1] & 0xff) << 8;
83     /* fallthrough */
84   case 1:
85   default:
86     color |= (b[0] & 0xff);
87     break;
88   }
89 
90   return color;
91 }
92 
93 void
94 VGLSetXY(VGLBitmap *object, int x, int y, u_long color)
95 {
96   int offset;
97   byte b[4];
98 
99   VGLCheckSwitch();
100   if (x>=0 && x<object->VXsize && y>=0 && y<object->VYsize) {
101     if (!VGLMouseFreeze(x, y, 1, 1, color)) {
102       switch (object->Type) {
103       case MEMBUF:
104       case VIDBUF8:
105         object->Bitmap[y*object->VXsize+x]=((byte)color);
106         break;
107       case VIDBUF8S:
108 	object->Bitmap[VGLSetSegment(y*object->VXsize+x)]=((byte)color);
109 	break;
110       case VIDBUF16:
111       case VIDBUF24:
112       case VIDBUF32:
113 	color2mem(color, b, object->PixelBytes);
114         bcopy(b, &object->Bitmap[(y*object->VXsize+x) * object->PixelBytes],
115 		object->PixelBytes);
116         break;
117       case VIDBUF16S:
118       case VIDBUF24S:
119       case VIDBUF32S:
120 	color2mem(color, b, object->PixelBytes);
121 	offset = VGLSetSegment((y*object->VXsize+x) * object->PixelBytes);
122 	bcopy(b, &object->Bitmap[offset], object->PixelBytes);
123 	break;
124       case VIDBUF8X:
125         outb(0x3c4, 0x02);
126         outb(0x3c5, 0x01 << (x&0x3));
127 	object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)] = ((byte)color);
128 	break;
129       case VIDBUF4S:
130 	offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8);
131 	goto set_planar;
132       case VIDBUF4:
133 	offset = y*VGLAdpInfo.va_line_width + x/8;
134 set_planar:
135         outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
136         outb(0x3ce, 0x00); outb(0x3cf, (byte)color & 0x0f);	/* set/reset */
137         outb(0x3ce, 0x01); outb(0x3cf, 0x0f);		/* set/reset enable */
138         outb(0x3ce, 0x08); outb(0x3cf, 0x80 >> (x%8));	/* bit mask */
139 	object->Bitmap[offset] |= (byte)color;
140       }
141     }
142     VGLMouseUnFreeze();
143   }
144 }
145 
146 u_long
147 VGLGetXY(VGLBitmap *object, int x, int y)
148 {
149   int offset;
150   byte b[4];
151 #if 0
152   int i;
153   u_long color;
154   byte mask;
155 #endif
156 
157   VGLCheckSwitch();
158   if (x<0 || x>=object->VXsize || y<0 || y>=object->VYsize)
159     return 0;
160   switch (object->Type) {
161     case MEMBUF:
162     case VIDBUF8:
163       return object->Bitmap[((y*object->VXsize)+x)];
164     case VIDBUF8S:
165       return object->Bitmap[VGLSetSegment(y*object->VXsize+x)];
166     case VIDBUF16:
167     case VIDBUF24:
168     case VIDBUF32:
169       bcopy(&object->Bitmap[(y*object->VXsize+x) * object->PixelBytes],
170 		b, object->PixelBytes);
171       return (mem2color(b, object->PixelBytes));
172     case VIDBUF16S:
173     case VIDBUF24S:
174     case VIDBUF32S:
175 	offset = VGLSetSegment((y*object->VXsize+x) * object->PixelBytes);
176 	bcopy(&object->Bitmap[offset], b, object->PixelBytes);
177 
178       return (mem2color(b, object->PixelBytes));
179     case VIDBUF8X:
180       outb(0x3ce, 0x04); outb(0x3cf, x & 0x3);
181       return object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)];
182     case VIDBUF4S:
183       offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8);
184       goto get_planar;
185     case VIDBUF4:
186       offset = y*VGLAdpInfo.va_line_width + x/8;
187 get_planar:
188 #if 1
189       return (object->Bitmap[offset]&(0x80>>(x%8))) ? 1 : 0;	/* XXX */
190 #else
191       color = 0;
192       mask = 0x80 >> (x%8);
193       for (i = 0; i < VGLModeInfo.vi_planes; i++) {
194 	outb(0x3ce, 0x04); outb(0x3cf, i);
195 	color |= (object->Bitmap[offset] & mask) ? (1 << i) : 0;
196       }
197       return color;
198 #endif
199   }
200   return 0;		/* XXX black? */
201 }
202 
203  /*
204   * Symmetric Double Step Line Algorithm by Brian Wyvill from
205   * "Graphics Gems", Academic Press, 1990.
206   */
207 
208 #define SL_SWAP(a,b)           {a^=b; b^=a; a^=b;}
209 #define SL_ABSOLUTE(i,j,k)     ( (i-j)*(k = ( (i-j)<0 ? -1 : 1)))
210 
211 void
212 plot(VGLBitmap * object, int x, int y, int flag, byte color)
213 {
214   /* non-zero flag indicates the pixels need swapping back. */
215   if (flag)
216     VGLSetXY(object, y, x, color);
217   else
218     VGLSetXY(object, x, y, color);
219 }
220 
221 
222 void
223 VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
224 {
225   int dx, dy, incr1, incr2, D, x, y, xend, c, pixels_left;
226   int sign_x, sign_y, step, reverse, i;
227 
228   dx = SL_ABSOLUTE(x2, x1, sign_x);
229   dy = SL_ABSOLUTE(y2, y1, sign_y);
230   /* decide increment sign by the slope sign */
231   if (sign_x == sign_y)
232     step = 1;
233   else
234     step = -1;
235 
236   if (dy > dx) {	/* chooses axis of greatest movement (make dx) */
237     SL_SWAP(x1, y1);
238     SL_SWAP(x2, y2);
239     SL_SWAP(dx, dy);
240     reverse = 1;
241   } else
242     reverse = 0;
243   /* note error check for dx==0 should be included here */
244   if (x1 > x2) {      /* start from the smaller coordinate */
245     x = x2;
246     y = y2;
247 /*  x1 = x1;
248     y1 = y1; */
249   } else {
250     x = x1;
251     y = y1;
252     x1 = x2;
253     y1 = y2;
254   }
255 
256 
257   /* Note dx=n implies 0 - n or (dx+1) pixels to be set */
258   /* Go round loop dx/4 times then plot last 0,1,2 or 3 pixels */
259   /* In fact (dx-1)/4 as 2 pixels are already plotted */
260   xend = (dx - 1) / 4;
261   pixels_left = (dx - 1) % 4;  /* number of pixels left over at the
262            * end */
263   plot(object, x, y, reverse, color);
264   if (pixels_left < 0)
265     return;      /* plot only one pixel for zero length
266            * vectors */
267   plot(object, x1, y1, reverse, color);  /* plot first two points */
268   incr2 = 4 * dy - 2 * dx;
269   if (incr2 < 0) {    /* slope less than 1/2 */
270     c = 2 * dy;
271     incr1 = 2 * c;
272     D = incr1 - dx;
273 
274     for (i = 0; i < xend; i++) {  /* plotting loop */
275       ++x;
276       --x1;
277       if (D < 0) {
278         /* pattern 1 forwards */
279         plot(object, x, y, reverse, color);
280         plot(object, ++x, y, reverse, color);
281         /* pattern 1 backwards */
282         plot(object, x1, y1, reverse, color);
283         plot(object, --x1, y1, reverse, color);
284         D += incr1;
285       } else {
286         if (D < c) {
287           /* pattern 2 forwards */
288           plot(object, x, y, reverse, color);
289           plot(object, ++x, y += step, reverse,
290               color);
291           /* pattern 2 backwards */
292           plot(object, x1, y1, reverse, color);
293           plot(object, --x1, y1 -= step, reverse,
294               color);
295         } else {
296           /* pattern 3 forwards */
297           plot(object, x, y += step, reverse, color);
298           plot(object, ++x, y, reverse, color);
299           /* pattern 3 backwards */
300           plot(object, x1, y1 -= step, reverse,
301               color);
302           plot(object, --x1, y1, reverse, color);
303         }
304         D += incr2;
305       }
306     }      /* end for */
307 
308     /* plot last pattern */
309     if (pixels_left) {
310       if (D < 0) {
311         plot(object, ++x, y, reverse, color);  /* pattern 1 */
312         if (pixels_left > 1)
313           plot(object, ++x, y, reverse, color);
314         if (pixels_left > 2)
315           plot(object, --x1, y1, reverse, color);
316       } else {
317         if (D < c) {
318           plot(object, ++x, y, reverse, color);  /* pattern 2  */
319           if (pixels_left > 1)
320             plot(object, ++x, y += step, reverse, color);
321           if (pixels_left > 2)
322             plot(object, --x1, y1, reverse, color);
323         } else {
324           /* pattern 3 */
325           plot(object, ++x, y += step, reverse, color);
326           if (pixels_left > 1)
327             plot(object, ++x, y, reverse, color);
328           if (pixels_left > 2)
329             plot(object, --x1, y1 -= step, reverse, color);
330         }
331       }
332     }      /* end if pixels_left */
333   }
334   /* end slope < 1/2 */
335   else {        /* slope greater than 1/2 */
336     c = 2 * (dy - dx);
337     incr1 = 2 * c;
338     D = incr1 + dx;
339     for (i = 0; i < xend; i++) {
340       ++x;
341       --x1;
342       if (D > 0) {
343         /* pattern 4 forwards */
344         plot(object, x, y += step, reverse, color);
345         plot(object, ++x, y += step, reverse, color);
346         /* pattern 4 backwards */
347         plot(object, x1, y1 -= step, reverse, color);
348         plot(object, --x1, y1 -= step, reverse, color);
349         D += incr1;
350       } else {
351         if (D < c) {
352           /* pattern 2 forwards */
353           plot(object, x, y, reverse, color);
354           plot(object, ++x, y += step, reverse,
355               color);
356 
357           /* pattern 2 backwards */
358           plot(object, x1, y1, reverse, color);
359           plot(object, --x1, y1 -= step, reverse,
360               color);
361         } else {
362           /* pattern 3 forwards */
363           plot(object, x, y += step, reverse, color);
364           plot(object, ++x, y, reverse, color);
365           /* pattern 3 backwards */
366           plot(object, x1, y1 -= step, reverse, color);
367           plot(object, --x1, y1, reverse, color);
368         }
369         D += incr2;
370       }
371     }      /* end for */
372     /* plot last pattern */
373     if (pixels_left) {
374       if (D > 0) {
375         plot(object, ++x, y += step, reverse, color);  /* pattern 4 */
376         if (pixels_left > 1)
377           plot(object, ++x, y += step, reverse,
378               color);
379         if (pixels_left > 2)
380           plot(object, --x1, y1 -= step, reverse,
381               color);
382       } else {
383         if (D < c) {
384           plot(object, ++x, y, reverse, color);  /* pattern 2  */
385           if (pixels_left > 1)
386             plot(object, ++x, y += step, reverse, color);
387           if (pixels_left > 2)
388             plot(object, --x1, y1, reverse, color);
389         } else {
390           /* pattern 3 */
391           plot(object, ++x, y += step, reverse, color);
392           if (pixels_left > 1)
393             plot(object, ++x, y, reverse, color);
394           if (pixels_left > 2) {
395             if (D > c)  /* step 3 */
396               plot(object, --x1, y1 -= step, reverse, color);
397             else  /* step 2 */
398               plot(object, --x1, y1, reverse, color);
399           }
400         }
401       }
402     }
403   }
404 }
405 
406 void
407 VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
408 {
409   VGLLine(object, x1, y1, x2, y1, color);
410   VGLLine(object, x2, y1, x2, y2, color);
411   VGLLine(object, x2, y2, x1, y2, color);
412   VGLLine(object, x1, y2, x1, y1, color);
413 }
414 
415 void
416 VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
417 {
418   int y;
419 
420   for (y=y1; y<=y2; y++) VGLLine(object, x1, y, x2, y, color);
421 }
422 
423 static inline void
424 set4pixels(VGLBitmap *object, int x, int y, int xc, int yc, u_long color)
425 {
426   if (x!=0) {
427     VGLSetXY(object, xc+x, yc+y, color);
428     VGLSetXY(object, xc-x, yc+y, color);
429     if (y!=0) {
430       VGLSetXY(object, xc+x, yc-y, color);
431       VGLSetXY(object, xc-x, yc-y, color);
432     }
433   }
434   else {
435     VGLSetXY(object, xc, yc+y, color);
436     if (y!=0)
437       VGLSetXY(object, xc, yc-y, color);
438   }
439 }
440 
441 void
442 VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color)
443 {
444   int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b;
445   int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b;
446 
447   while (dx<dy) {
448     set4pixels(object, x, y, xc, yc, color);
449     if (d>0) {
450       y--; dy-=asq2; d-=dy;
451     }
452     x++; dx+=bsq2; d+=bsq+dx;
453   }
454   d+=(3*(asq-bsq)/2-(dx+dy))/2;
455   while (y>=0) {
456     set4pixels(object, x, y, xc, yc, color);
457     if (d<0) {
458       x++; dx+=bsq2; d+=dx;
459     }
460     y--; dy-=asq2; d+=asq-dy;
461   }
462 }
463 
464 static inline void
465 set2lines(VGLBitmap *object, int x, int y, int xc, int yc, u_long color)
466 {
467   if (x!=0) {
468     VGLLine(object, xc+x, yc+y, xc-x, yc+y, color);
469     if (y!=0)
470       VGLLine(object, xc+x, yc-y, xc-x, yc-y, color);
471   }
472   else {
473     VGLLine(object, xc, yc+y, xc, yc-y, color);
474   }
475 }
476 
477 void
478 VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color)
479 {
480   int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b;
481   int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b;
482 
483   while (dx<dy) {
484     set2lines(object, x, y, xc, yc, color);
485     if (d>0) {
486       y--; dy-=asq2; d-=dy;
487     }
488     x++; dx+=bsq2; d+=bsq+dx;
489   }
490   d+=(3*(asq-bsq)/2-(dx+dy))/2;
491   while (y>=0) {
492     set2lines(object, x, y, xc, yc, color);
493     if (d<0) {
494       x++; dx+=bsq2; d+=dx;
495     }
496     y--; dy-=asq2; d+=asq-dy;
497   }
498 }
499 
500 void
501 VGLClear(VGLBitmap *object, u_long color)
502 {
503   int offset;
504   int len;
505   int i, total = 0;
506   byte b[4];
507 
508   VGLCheckSwitch();
509   VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color); /* XXX */
510   switch (object->Type) {
511   case MEMBUF:
512   case VIDBUF8:
513     memset(object->Bitmap, (byte)color, object->VXsize*object->VYsize);
514     break;
515 
516   case VIDBUF8S:
517     for (offset = 0; offset < object->VXsize*object->VYsize; ) {
518       VGLSetSegment(offset);
519       len = min(object->VXsize*object->VYsize - offset,
520 		VGLAdpInfo.va_window_size);
521       memset(object->Bitmap, (byte)color, len);
522       offset += len;
523     }
524     break;
525   case VIDBUF16:
526   case VIDBUF24:
527   case VIDBUF32:
528     color2mem(color, b, object->PixelBytes);
529     total = object->VXsize*object->VYsize*object->PixelBytes;
530     for (i = 0; i < total; i += object->PixelBytes)
531       bcopy(b, object->Bitmap + i, object->PixelBytes);
532     break;
533 
534   case VIDBUF16S:
535   case VIDBUF24S:
536   case VIDBUF32S:
537     color2mem(color, b, object->PixelBytes);
538     total = object->VXsize*object->VYsize*object->PixelBytes;
539     for (offset = 0; offset < total; ) {
540       VGLSetSegment(offset);
541       len = min(total - offset, VGLAdpInfo.va_window_size);
542       for (i = 0; i < len; i += object->PixelBytes)
543 	bcopy(b, object->Bitmap + offset + i, object->PixelBytes);
544       offset += len;
545     }
546     break;
547 
548   case VIDBUF8X:
549     /* XXX works only for Xsize % 4 = 0 */
550     outb(0x3c6, 0xff);
551     outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
552     memset(object->Bitmap, (byte)color, VGLAdpInfo.va_line_width*object->VYsize);
553     break;
554 
555   case VIDBUF4:
556   case VIDBUF4S:
557     /* XXX works only for Xsize % 8 = 0 */
558     outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
559     outb(0x3ce, 0x05); outb(0x3cf, 0x02);		/* mode 2 */
560     outb(0x3ce, 0x01); outb(0x3cf, 0x00);		/* set/reset enable */
561     outb(0x3ce, 0x08); outb(0x3cf, 0xff);		/* bit mask */
562     for (offset = 0; offset < VGLAdpInfo.va_line_width*object->VYsize; ) {
563       VGLSetSegment(offset);
564       len = min(object->VXsize*object->VYsize - offset,
565 		VGLAdpInfo.va_window_size);
566       memset(object->Bitmap, (byte)color, len);
567       offset += len;
568     }
569     outb(0x3ce, 0x05); outb(0x3cf, 0x00);
570     break;
571   }
572   VGLMouseUnFreeze();
573 }
574 
575 void
576 VGLRestorePalette()
577 {
578   int i;
579 
580   outb(0x3C6, 0xFF);
581   inb(0x3DA);
582   outb(0x3C8, 0x00);
583   for (i=0; i<256; i++) {
584     outb(0x3C9, VGLSavePaletteRed[i]);
585     inb(0x84);
586     outb(0x3C9, VGLSavePaletteGreen[i]);
587     inb(0x84);
588     outb(0x3C9, VGLSavePaletteBlue[i]);
589     inb(0x84);
590   }
591   inb(0x3DA);
592   outb(0x3C0, 0x20);
593 }
594 
595 void
596 VGLSavePalette()
597 {
598   int i;
599 
600   outb(0x3C6, 0xFF);
601   inb(0x3DA);
602   outb(0x3C7, 0x00);
603   for (i=0; i<256; i++) {
604     VGLSavePaletteRed[i] = inb(0x3C9);
605     inb(0x84);
606     VGLSavePaletteGreen[i] = inb(0x3C9);
607     inb(0x84);
608     VGLSavePaletteBlue[i] = inb(0x3C9);
609     inb(0x84);
610   }
611   inb(0x3DA);
612   outb(0x3C0, 0x20);
613 }
614 
615 void
616 VGLSetPalette(byte *red, byte *green, byte *blue)
617 {
618   int i;
619 
620   for (i=0; i<256; i++) {
621     VGLSavePaletteRed[i] = red[i];
622     VGLSavePaletteGreen[i] = green[i];
623     VGLSavePaletteBlue[i] = blue[i];
624   }
625   VGLCheckSwitch();
626   outb(0x3C6, 0xFF);
627   inb(0x3DA);
628   outb(0x3C8, 0x00);
629   for (i=0; i<256; i++) {
630     outb(0x3C9, VGLSavePaletteRed[i]);
631     inb(0x84);
632     outb(0x3C9, VGLSavePaletteGreen[i]);
633     inb(0x84);
634     outb(0x3C9, VGLSavePaletteBlue[i]);
635     inb(0x84);
636   }
637   inb(0x3DA);
638   outb(0x3C0, 0x20);
639 }
640 
641 void
642 VGLSetPaletteIndex(byte color, byte red, byte green, byte blue)
643 {
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 VGLSetBorder(byte color)
658 {
659   VGLCheckSwitch();
660   inb(0x3DA);
661   outb(0x3C0,0x11); outb(0x3C0, color);
662   inb(0x3DA);
663   outb(0x3C0, 0x20);
664 }
665 
666 void
667 VGLBlankDisplay(int blank)
668 {
669   byte val;
670 
671   VGLCheckSwitch();
672   outb(0x3C4, 0x01); val = inb(0x3C5); outb(0x3C4, 0x01);
673   outb(0x3C5, ((blank) ? (val |= 0x20) : (val &= 0xDF)));
674 }
675