1/*-
2 * Copyright (c) 1991-1997 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 11 unchanged lines hidden (view full) ---
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.
27 *
28 * $FreeBSD: head/lib/libvgl/simple.c 50476 1999-08-28 00:22:10Z peter $
29 */
30
31#include <signal.h>
32#include <machine/console.h>
33#include "vgl.h"
34
35static byte VGLSavePaletteRed[256];
36static byte VGLSavePaletteGreen[256];
37static byte VGLSavePaletteBlue[256];
38
39#define ABS(a) (((a)<0) ? -(a) : (a))
40#define SGN(a) (((a)<0) ? -1 : 1)
41
42
43void
44VGLSetXY(VGLBitmap *object, int x, int y, byte color)
45{
46 VGLCheckSwitch();
47 if (x>=0 && x<object->Xsize && y>=0 && y<object->Ysize) {
48 if (!VGLMouseFreeze(x, y, 1, 1, color)) {
49 switch (object->Type) {
50 case MEMBUF:
51 case VIDBUF8:
52 object->Bitmap[y*object->Xsize+x]=(color);
53 break;
54 case VIDBUF8X:
55 outb(0x3c4, 0x02);
56 outb(0x3c5, 0x01 << (x&0x3));
57 object->Bitmap[(unsigned)(object->Xsize/2*y)+(x/4)] = (color);
58 break;
59 case VIDBUF4:
60 outb(0x3c4, 0x02); outb(0x3c5, 0x01);
61 outb(0x3ce, 0x04); outb(0x3cf, 0x00);
62 object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] =
63 ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) )
64 | ((color & 0x01) ? (0x80>>(x%8)) : 0);
65 outb(0x3c4, 0x02); outb(0x3c5, 0x02);
66 outb(0x3ce, 0x04); outb(0x3cf, 0x01);
67 object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] =
68 ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) )
69 | ((color & 0x02) ? (0x80>>(x%8)) : 0);
70 outb(0x3c4, 0x02); outb(0x3c5, 0x04);
71 outb(0x3ce, 0x04); outb(0x3cf, 0x02);
72 object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] =
73 ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) )
74 | ((color & 0x04) ? (0x80>>(x%8)) : 0);
75 outb(0x3c4, 0x02); outb(0x3c5, 0x08);
76 outb(0x3ce, 0x04); outb(0x3cf, 0x03);
77 object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] =
78 ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) )
79 | ((color & 0x08) ? (0x80>>(x%8)) : 0);
80 }
81 }
82 VGLMouseUnFreeze();
83 }
84}
85
86byte
87VGLGetXY(VGLBitmap *object, int x, int y)
88{
89 VGLCheckSwitch();
90 switch (object->Type) {
91 case MEMBUF:
92 case VIDBUF8:
93 return object->Bitmap[((y*object->Xsize)+x)];
94 break;
95 case VIDBUF8X:
96 outb(0x3ce, 0x04); outb(0x3cf, x & 0x3);
97 return object->Bitmap[(unsigned)(object->Xsize/2*y)+(x/4)];
98 break;
99 case VIDBUF4:
100 return (object->Bitmap[((y*object->Xsize/8)+x/8)]&(0x80>>(x%8))) ? 1 : 0;
101 break;
102 }
103 return 0;
104}
105
106void
107VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color)
108{
109 int d, x, y, ax, ay, sx, sy, dx, dy;
--- 119 unchanged lines hidden (view full) ---
229 }
230 y--; dy-=asq2; d+=asq-dy;
231 }
232}
233
234void
235VGLClear(VGLBitmap *object, byte color)
236{
237 VGLCheckSwitch();
238 VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color);
239 switch (object->Type) {
240 case MEMBUF:
241 case VIDBUF8:
242 memset(object->Bitmap, color, object->Xsize*object->Ysize);
243 break;
244 case VIDBUF8X:
245 /* XXX works only for Xsize % 4 = 0 */
246 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
247 memset(object->Bitmap, color, object->Xsize*object->Ysize/4);
248 break;
249
250 case VIDBUF4:
251 /* XXX works only for Xsize % 8 = 0 */
252 memset(object->Bitmap, color, object->Xsize/8*object->Ysize);
253 break;
254 }
255 VGLMouseUnFreeze();
256}
257
258void
259VGLRestorePalette()
260{
--- 97 unchanged lines hidden ---
2 * Copyright (c) 1991-1997 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 11 unchanged lines hidden (view full) ---
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.
27 *
28 * $FreeBSD: head/lib/libvgl/simple.c 50476 1999-08-28 00:22:10Z peter $
29 */
30
31#include <signal.h>
32#include <machine/console.h>
33#include "vgl.h"
34
35static byte VGLSavePaletteRed[256];
36static byte VGLSavePaletteGreen[256];
37static byte VGLSavePaletteBlue[256];
38
39#define ABS(a) (((a)<0) ? -(a) : (a))
40#define SGN(a) (((a)<0) ? -1 : 1)
41
42
43void
44VGLSetXY(VGLBitmap *object, int x, int y, byte color)
45{
46 VGLCheckSwitch();
47 if (x>=0 && x<object->Xsize && y>=0 && y<object->Ysize) {
48 if (!VGLMouseFreeze(x, y, 1, 1, color)) {
49 switch (object->Type) {
50 case MEMBUF:
51 case VIDBUF8:
52 object->Bitmap[y*object->Xsize+x]=(color);
53 break;
54 case VIDBUF8X:
55 outb(0x3c4, 0x02);
56 outb(0x3c5, 0x01 << (x&0x3));
57 object->Bitmap[(unsigned)(object->Xsize/2*y)+(x/4)] = (color);
58 break;
59 case VIDBUF4:
60 outb(0x3c4, 0x02); outb(0x3c5, 0x01);
61 outb(0x3ce, 0x04); outb(0x3cf, 0x00);
62 object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] =
63 ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) )
64 | ((color & 0x01) ? (0x80>>(x%8)) : 0);
65 outb(0x3c4, 0x02); outb(0x3c5, 0x02);
66 outb(0x3ce, 0x04); outb(0x3cf, 0x01);
67 object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] =
68 ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) )
69 | ((color & 0x02) ? (0x80>>(x%8)) : 0);
70 outb(0x3c4, 0x02); outb(0x3c5, 0x04);
71 outb(0x3ce, 0x04); outb(0x3cf, 0x02);
72 object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] =
73 ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) )
74 | ((color & 0x04) ? (0x80>>(x%8)) : 0);
75 outb(0x3c4, 0x02); outb(0x3c5, 0x08);
76 outb(0x3ce, 0x04); outb(0x3cf, 0x03);
77 object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] =
78 ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) )
79 | ((color & 0x08) ? (0x80>>(x%8)) : 0);
80 }
81 }
82 VGLMouseUnFreeze();
83 }
84}
85
86byte
87VGLGetXY(VGLBitmap *object, int x, int y)
88{
89 VGLCheckSwitch();
90 switch (object->Type) {
91 case MEMBUF:
92 case VIDBUF8:
93 return object->Bitmap[((y*object->Xsize)+x)];
94 break;
95 case VIDBUF8X:
96 outb(0x3ce, 0x04); outb(0x3cf, x & 0x3);
97 return object->Bitmap[(unsigned)(object->Xsize/2*y)+(x/4)];
98 break;
99 case VIDBUF4:
100 return (object->Bitmap[((y*object->Xsize/8)+x/8)]&(0x80>>(x%8))) ? 1 : 0;
101 break;
102 }
103 return 0;
104}
105
106void
107VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color)
108{
109 int d, x, y, ax, ay, sx, sy, dx, dy;
--- 119 unchanged lines hidden (view full) ---
229 }
230 y--; dy-=asq2; d+=asq-dy;
231 }
232}
233
234void
235VGLClear(VGLBitmap *object, byte color)
236{
237 VGLCheckSwitch();
238 VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color);
239 switch (object->Type) {
240 case MEMBUF:
241 case VIDBUF8:
242 memset(object->Bitmap, color, object->Xsize*object->Ysize);
243 break;
244 case VIDBUF8X:
245 /* XXX works only for Xsize % 4 = 0 */
246 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
247 memset(object->Bitmap, color, object->Xsize*object->Ysize/4);
248 break;
249
250 case VIDBUF4:
251 /* XXX works only for Xsize % 8 = 0 */
252 memset(object->Bitmap, color, object->Xsize/8*object->Ysize);
253 break;
254 }
255 VGLMouseUnFreeze();
256}
257
258void
259VGLRestorePalette()
260{
--- 97 unchanged lines hidden ---