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 53013 1999-11-08 11:37:46Z yokota $
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#define min(x, y) (((x) < (y)) ? (x) : (y))
42#define max(x, y) (((x) > (y)) ? (x) : (y))
43
44void
45VGLSetXY(VGLBitmap *object, int x, int y, byte color)
46{
47 int offset;
48
49 VGLCheckSwitch();
50 if (x>=0 && x<object->VXsize && y>=0 && y<object->VYsize) {
51 if (!VGLMouseFreeze(x, y, 1, 1, color)) {
52 switch (object->Type) {
53 case MEMBUF:
54 case VIDBUF8:
55 object->Bitmap[y*object->VXsize+x]=(color);
56 break;
57 case VIDBUF8S:
58 object->Bitmap[VGLSetSegment(y*object->VXsize+x)]=(color);
59 break;
60 case VIDBUF8X:
61 outb(0x3c4, 0x02);
62 outb(0x3c5, 0x01 << (x&0x3));
63 object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)] = (color);
64 break;
65 case VIDBUF4S:
66 offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8);
67 goto set_planar;
68 case VIDBUF4:
69 offset = y*VGLAdpInfo.va_line_width + x/8;
70set_planar:
71 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
72 outb(0x3ce, 0x00); outb(0x3cf, color & 0x0f); /* set/reset */
73 outb(0x3ce, 0x01); outb(0x3cf, 0x0f); /* set/reset enable */
74 outb(0x3ce, 0x08); outb(0x3cf, 0x80 >> (x%8)); /* bit mask */
75 object->Bitmap[offset] |= color;
76 }
77 }
78 VGLMouseUnFreeze();
79 }
80}
81
82byte
83VGLGetXY(VGLBitmap *object, int x, int y)
84{
85 int offset;
86#if 0
87 int i;
88 byte color;
89 byte mask;
90#endif
91
92 VGLCheckSwitch();
93 if (x<0 || x>=object->VXsize || y<0 || y>=object->VYsize)
94 return 0;
95 switch (object->Type) {
96 case MEMBUF:
97 case VIDBUF8:
98 return object->Bitmap[((y*object->VXsize)+x)];
99 case VIDBUF8S:
100 return object->Bitmap[VGLSetSegment(y*object->VXsize+x)];
101 case VIDBUF8X:
102 outb(0x3ce, 0x04); outb(0x3cf, x & 0x3);
103 return object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)];
104 case VIDBUF4S:
105 offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8);
106 goto get_planar;
107 case VIDBUF4:
108 offset = y*VGLAdpInfo.va_line_width + x/8;
109get_planar:
110#if 1
111 return (object->Bitmap[offset]&(0x80>>(x%8))) ? 1 : 0; /* XXX */
112#else
113 color = 0;
114 mask = 0x80 >> (x%8);
115 for (i = 0; i < VGLModeInfo.vi_planes; i++) {
116 outb(0x3ce, 0x04); outb(0x3cf, i);
117 color |= (object->Bitmap[offset] & mask) ? (1 << i) : 0;
118 }
119 return color;
120#endif
121 }
122 return 0;
123}
124
125void
126VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color)
127{
128 int d, x, y, ax, ay, sx, sy, dx, dy;
--- 119 unchanged lines hidden (view full) ---
248 }
249 y--; dy-=asq2; d+=asq-dy;
250 }
251}
252
253void
254VGLClear(VGLBitmap *object, byte color)
255{
256 int offset;
257 int len;
258
259 VGLCheckSwitch();
260 VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color);
261 switch (object->Type) {
262 case MEMBUF:
263 case VIDBUF8:
264 memset(object->Bitmap, color, object->VXsize*object->VYsize);
265 break;
266
267 case VIDBUF8S:
268 for (offset = 0; offset < object->VXsize*object->VYsize; ) {
269 VGLSetSegment(offset);
270 len = min(object->VXsize*object->VYsize - offset,
271 VGLAdpInfo.va_window_size);
272 memset(object->Bitmap, color, len);
273 offset += len;
274 }
275 break;
276
277 case VIDBUF8X:
278 /* XXX works only for Xsize % 4 = 0 */
279 outb(0x3c6, 0xff);
280 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
281 memset(object->Bitmap, color, VGLAdpInfo.va_line_width*object->VYsize);
282 break;
283
284 case VIDBUF4:
285 case VIDBUF4S:
286 /* XXX works only for Xsize % 8 = 0 */
287 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
288 outb(0x3ce, 0x05); outb(0x3cf, 0x02); /* mode 2 */
289 outb(0x3ce, 0x01); outb(0x3cf, 0x00); /* set/reset enable */
290 outb(0x3ce, 0x08); outb(0x3cf, 0xff); /* bit mask */
291 for (offset = 0; offset < VGLAdpInfo.va_line_width*object->VYsize; ) {
292 VGLSetSegment(offset);
293 len = min(object->VXsize*object->VYsize - offset,
294 VGLAdpInfo.va_window_size);
295 memset(object->Bitmap, color, len);
296 offset += len;
297 }
298 outb(0x3ce, 0x05); outb(0x3cf, 0x00);
299 break;
300 }
301 VGLMouseUnFreeze();
302}
303
304void
305VGLRestorePalette()
306{
--- 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 53013 1999-11-08 11:37:46Z yokota $
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#define min(x, y) (((x) < (y)) ? (x) : (y))
42#define max(x, y) (((x) > (y)) ? (x) : (y))
43
44void
45VGLSetXY(VGLBitmap *object, int x, int y, byte color)
46{
47 int offset;
48
49 VGLCheckSwitch();
50 if (x>=0 && x<object->VXsize && y>=0 && y<object->VYsize) {
51 if (!VGLMouseFreeze(x, y, 1, 1, color)) {
52 switch (object->Type) {
53 case MEMBUF:
54 case VIDBUF8:
55 object->Bitmap[y*object->VXsize+x]=(color);
56 break;
57 case VIDBUF8S:
58 object->Bitmap[VGLSetSegment(y*object->VXsize+x)]=(color);
59 break;
60 case VIDBUF8X:
61 outb(0x3c4, 0x02);
62 outb(0x3c5, 0x01 << (x&0x3));
63 object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)] = (color);
64 break;
65 case VIDBUF4S:
66 offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8);
67 goto set_planar;
68 case VIDBUF4:
69 offset = y*VGLAdpInfo.va_line_width + x/8;
70set_planar:
71 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
72 outb(0x3ce, 0x00); outb(0x3cf, color & 0x0f); /* set/reset */
73 outb(0x3ce, 0x01); outb(0x3cf, 0x0f); /* set/reset enable */
74 outb(0x3ce, 0x08); outb(0x3cf, 0x80 >> (x%8)); /* bit mask */
75 object->Bitmap[offset] |= color;
76 }
77 }
78 VGLMouseUnFreeze();
79 }
80}
81
82byte
83VGLGetXY(VGLBitmap *object, int x, int y)
84{
85 int offset;
86#if 0
87 int i;
88 byte color;
89 byte mask;
90#endif
91
92 VGLCheckSwitch();
93 if (x<0 || x>=object->VXsize || y<0 || y>=object->VYsize)
94 return 0;
95 switch (object->Type) {
96 case MEMBUF:
97 case VIDBUF8:
98 return object->Bitmap[((y*object->VXsize)+x)];
99 case VIDBUF8S:
100 return object->Bitmap[VGLSetSegment(y*object->VXsize+x)];
101 case VIDBUF8X:
102 outb(0x3ce, 0x04); outb(0x3cf, x & 0x3);
103 return object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)];
104 case VIDBUF4S:
105 offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8);
106 goto get_planar;
107 case VIDBUF4:
108 offset = y*VGLAdpInfo.va_line_width + x/8;
109get_planar:
110#if 1
111 return (object->Bitmap[offset]&(0x80>>(x%8))) ? 1 : 0; /* XXX */
112#else
113 color = 0;
114 mask = 0x80 >> (x%8);
115 for (i = 0; i < VGLModeInfo.vi_planes; i++) {
116 outb(0x3ce, 0x04); outb(0x3cf, i);
117 color |= (object->Bitmap[offset] & mask) ? (1 << i) : 0;
118 }
119 return color;
120#endif
121 }
122 return 0;
123}
124
125void
126VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color)
127{
128 int d, x, y, ax, ay, sx, sy, dx, dy;
--- 119 unchanged lines hidden (view full) ---
248 }
249 y--; dy-=asq2; d+=asq-dy;
250 }
251}
252
253void
254VGLClear(VGLBitmap *object, byte color)
255{
256 int offset;
257 int len;
258
259 VGLCheckSwitch();
260 VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color);
261 switch (object->Type) {
262 case MEMBUF:
263 case VIDBUF8:
264 memset(object->Bitmap, color, object->VXsize*object->VYsize);
265 break;
266
267 case VIDBUF8S:
268 for (offset = 0; offset < object->VXsize*object->VYsize; ) {
269 VGLSetSegment(offset);
270 len = min(object->VXsize*object->VYsize - offset,
271 VGLAdpInfo.va_window_size);
272 memset(object->Bitmap, color, len);
273 offset += len;
274 }
275 break;
276
277 case VIDBUF8X:
278 /* XXX works only for Xsize % 4 = 0 */
279 outb(0x3c6, 0xff);
280 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
281 memset(object->Bitmap, color, VGLAdpInfo.va_line_width*object->VYsize);
282 break;
283
284 case VIDBUF4:
285 case VIDBUF4S:
286 /* XXX works only for Xsize % 8 = 0 */
287 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
288 outb(0x3ce, 0x05); outb(0x3cf, 0x02); /* mode 2 */
289 outb(0x3ce, 0x01); outb(0x3cf, 0x00); /* set/reset enable */
290 outb(0x3ce, 0x08); outb(0x3cf, 0xff); /* bit mask */
291 for (offset = 0; offset < VGLAdpInfo.va_line_width*object->VYsize; ) {
292 VGLSetSegment(offset);
293 len = min(object->VXsize*object->VYsize - offset,
294 VGLAdpInfo.va_window_size);
295 memset(object->Bitmap, color, len);
296 offset += len;
297 }
298 outb(0x3ce, 0x05); outb(0x3cf, 0x00);
299 break;
300 }
301 VGLMouseUnFreeze();
302}
303
304void
305VGLRestorePalette()
306{
--- 97 unchanged lines hidden ---