Deleted Added
full compact
simple.c (66834) simple.c (70991)
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 *
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 66834 2000-10-08 21:34:00Z phk $
28 * $FreeBSD: head/lib/libvgl/simple.c 70991 2001-01-13 11:30:17Z nsouch $
29 */
30
31#include <signal.h>
32#include <sys/fbio.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
29 */
30
31#include <signal.h>
32#include <sys/fbio.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
44static void
45color2mem(u_long color, byte *b, int len)
46{
47 switch (len) {
48 case 4:
49 b[3] = (color >> 24) & 0xff;
50 /* fallthrough */
51 case 3:
52 b[2] = (color >> 16) & 0xff;
53 /* fallthrough */
54 case 2:
55 b[1] = (color >> 8) & 0xff;
56 /* fallthrough */
57 case 1:
58 default:
59 b[0] = color & 0xff;
60 break;
61 }
62
63 return;
64}
65
66static u_long
67mem2color(byte *b, int len)
68{
69 u_long color = 0;
70
71 switch (len) {
72 case 4:
73 color |= (b[3] & 0xff) << 24;
74 /* fallthrough */
75 case 3:
76 color |= (b[2] & 0xff) << 16;
77 /* fallthrough */
78 case 2:
79 color |= (b[1] & 0xff) << 8;
80 /* fallthrough */
81 case 1:
82 default:
83 color |= (b[0] & 0xff);
84 break;
85 }
86
87 return color;
88}
89
44void
90void
45VGLSetXY(VGLBitmap *object, int x, int y, byte color)
91VGLSetXY(VGLBitmap *object, int x, int y, u_long color)
46{
47 int offset;
92{
93 int offset;
94 byte b[4];
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:
95
96 VGLCheckSwitch();
97 if (x>=0 && x<object->VXsize && y>=0 && y<object->VYsize) {
98 if (!VGLMouseFreeze(x, y, 1, 1, color)) {
99 switch (object->Type) {
100 case MEMBUF:
101 case VIDBUF8:
55 object->Bitmap[y*object->VXsize+x]=(color);
102 object->Bitmap[y*object->VXsize+x]=((byte)color);
56 break;
57 case VIDBUF8S:
103 break;
104 case VIDBUF8S:
58 object->Bitmap[VGLSetSegment(y*object->VXsize+x)]=(color);
105 object->Bitmap[VGLSetSegment(y*object->VXsize+x)]=((byte)color);
59 break;
106 break;
107 case VIDBUF16:
108 case VIDBUF24:
109 case VIDBUF32:
110 color2mem(color, b, object->PixelBytes);
111 bcopy(b, &object->Bitmap[(y*object->VXsize+x) * object->PixelBytes],
112 object->PixelBytes);
113 break;
114 case VIDBUF16S:
115 case VIDBUF24S:
116 case VIDBUF32S:
117 color2mem(color, b, object->PixelBytes);
118 offset = VGLSetSegment((y*object->VXsize+x) * object->PixelBytes);
119 bcopy(b, &object->Bitmap[offset], object->PixelBytes);
120 break;
60 case VIDBUF8X:
61 outb(0x3c4, 0x02);
62 outb(0x3c5, 0x01 << (x&0x3));
121 case VIDBUF8X:
122 outb(0x3c4, 0x02);
123 outb(0x3c5, 0x01 << (x&0x3));
63 object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)] = (color);
124 object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)] = ((byte)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);
125 break;
126 case VIDBUF4S:
127 offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8);
128 goto set_planar;
129 case VIDBUF4:
130 offset = y*VGLAdpInfo.va_line_width + x/8;
131set_planar:
132 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
72 outb(0x3ce, 0x00); outb(0x3cf, color & 0x0f); /* set/reset */
133 outb(0x3ce, 0x00); outb(0x3cf, (byte)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 */
134 outb(0x3ce, 0x01); outb(0x3cf, 0x0f); /* set/reset enable */
135 outb(0x3ce, 0x08); outb(0x3cf, 0x80 >> (x%8)); /* bit mask */
75 object->Bitmap[offset] |= color;
136 object->Bitmap[offset] |= (byte)color;
76 }
77 }
78 VGLMouseUnFreeze();
79 }
80}
81
137 }
138 }
139 VGLMouseUnFreeze();
140 }
141}
142
82byte
143u_long
83VGLGetXY(VGLBitmap *object, int x, int y)
84{
85 int offset;
144VGLGetXY(VGLBitmap *object, int x, int y)
145{
146 int offset;
147 byte b[4];
86#if 0
87 int i;
148#if 0
149 int i;
88 byte color;
150 u_long 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)];
151 byte mask;
152#endif
153
154 VGLCheckSwitch();
155 if (x<0 || x>=object->VXsize || y<0 || y>=object->VYsize)
156 return 0;
157 switch (object->Type) {
158 case MEMBUF:
159 case VIDBUF8:
160 return object->Bitmap[((y*object->VXsize)+x)];
161 case VIDBUF8S:
162 return object->Bitmap[VGLSetSegment(y*object->VXsize+x)];
163 case VIDBUF16:
164 case VIDBUF24:
165 case VIDBUF32:
166 bcopy(&object->Bitmap[(y*object->VXsize+x) * object->PixelBytes],
167 b, object->PixelBytes);
168 return (mem2color(b, object->PixelBytes));
169 case VIDBUF16S:
170 case VIDBUF24S:
171 case VIDBUF32S:
172 offset = VGLSetSegment((y*object->VXsize+x) * object->PixelBytes);
173 bcopy(&object->Bitmap[offset], b, object->PixelBytes);
174
175 return (mem2color(b, object->PixelBytes));
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;

--- 5 unchanged lines hidden (view full) ---

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 }
176 case VIDBUF8X:
177 outb(0x3ce, 0x04); outb(0x3cf, x & 0x3);
178 return object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)];
179 case VIDBUF4S:
180 offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8);
181 goto get_planar;
182 case VIDBUF4:
183 offset = y*VGLAdpInfo.va_line_width + x/8;

--- 5 unchanged lines hidden (view full) ---

189 mask = 0x80 >> (x%8);
190 for (i = 0; i < VGLModeInfo.vi_planes; i++) {
191 outb(0x3ce, 0x04); outb(0x3cf, i);
192 color |= (object->Bitmap[offset] & mask) ? (1 << i) : 0;
193 }
194 return color;
195#endif
196 }
122 return 0;
197 return 0; /* XXX black? */
123}
124
125void
198}
199
200void
126VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color)
201VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
127{
128 int d, x, y, ax, ay, sx, sy, dx, dy;
129
130 dx = x2-x1; ax = ABS(dx)<<1; sx = SGN(dx); x = x1;
131 dy = y2-y1; ay = ABS(dy)<<1; sy = SGN(dy); y = y1;
132
133 if (ax>ay) { /* x dominant */
134 d = ay-(ax>>1);

--- 17 unchanged lines hidden (view full) ---

152 x += sx; d -= ay;
153 }
154 y += sy; d += ax;
155 }
156 }
157}
158
159void
202{
203 int d, x, y, ax, ay, sx, sy, dx, dy;
204
205 dx = x2-x1; ax = ABS(dx)<<1; sx = SGN(dx); x = x1;
206 dy = y2-y1; ay = ABS(dy)<<1; sy = SGN(dy); y = y1;
207
208 if (ax>ay) { /* x dominant */
209 d = ay-(ax>>1);

--- 17 unchanged lines hidden (view full) ---

227 x += sx; d -= ay;
228 }
229 y += sy; d += ax;
230 }
231 }
232}
233
234void
160VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color)
235VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
161{
162 VGLLine(object, x1, y1, x2, y1, color);
163 VGLLine(object, x2, y1, x2, y2, color);
164 VGLLine(object, x2, y2, x1, y2, color);
165 VGLLine(object, x1, y2, x1, y1, color);
166}
167
168void
236{
237 VGLLine(object, x1, y1, x2, y1, color);
238 VGLLine(object, x2, y1, x2, y2, color);
239 VGLLine(object, x2, y2, x1, y2, color);
240 VGLLine(object, x1, y2, x1, y1, color);
241}
242
243void
169VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color)
244VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
170{
171 int y;
172
173 for (y=y1; y<=y2; y++) VGLLine(object, x1, y, x2, y, color);
174}
175
176void
245{
246 int y;
247
248 for (y=y1; y<=y2; y++) VGLLine(object, x1, y, x2, y, color);
249}
250
251void
177inline set4pixels(VGLBitmap *object, int x, int y, int xc, int yc, byte color)
252inline set4pixels(VGLBitmap *object, int x, int y, int xc, int yc, u_long color)
178{
179 if (x!=0) {
180 VGLSetXY(object, xc+x, yc+y, color);
181 VGLSetXY(object, xc-x, yc+y, color);
182 if (y!=0) {
183 VGLSetXY(object, xc+x, yc-y, color);
184 VGLSetXY(object, xc-x, yc-y, color);
185 }
186 }
187 else {
188 VGLSetXY(object, xc, yc+y, color);
189 if (y!=0)
190 VGLSetXY(object, xc, yc-y, color);
191 }
192}
193
194void
253{
254 if (x!=0) {
255 VGLSetXY(object, xc+x, yc+y, color);
256 VGLSetXY(object, xc-x, yc+y, color);
257 if (y!=0) {
258 VGLSetXY(object, xc+x, yc-y, color);
259 VGLSetXY(object, xc-x, yc-y, color);
260 }
261 }
262 else {
263 VGLSetXY(object, xc, yc+y, color);
264 if (y!=0)
265 VGLSetXY(object, xc, yc-y, color);
266 }
267}
268
269void
195VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color)
270VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color)
196{
197 int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b;
198 int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b;
199
200 while (dx<dy) {
201 set4pixels(object, x, y, xc, yc, color);
202 if (d>0) {
203 y--; dy-=asq2; d-=dy;

--- 6 unchanged lines hidden (view full) ---

210 if (d<0) {
211 x++; dx+=bsq2; d+=dx;
212 }
213 y--; dy-=asq2; d+=asq-dy;
214 }
215}
216
217void
271{
272 int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b;
273 int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b;
274
275 while (dx<dy) {
276 set4pixels(object, x, y, xc, yc, color);
277 if (d>0) {
278 y--; dy-=asq2; d-=dy;

--- 6 unchanged lines hidden (view full) ---

285 if (d<0) {
286 x++; dx+=bsq2; d+=dx;
287 }
288 y--; dy-=asq2; d+=asq-dy;
289 }
290}
291
292void
218inline set2lines(VGLBitmap *object, int x, int y, int xc, int yc, byte color)
293inline set2lines(VGLBitmap *object, int x, int y, int xc, int yc, u_long color)
219{
220 if (x!=0) {
221 VGLLine(object, xc+x, yc+y, xc-x, yc+y, color);
222 if (y!=0)
223 VGLLine(object, xc+x, yc-y, xc-x, yc-y, color);
224 }
225 else {
226 VGLLine(object, xc, yc+y, xc, yc-y, color);
227 }
228}
229
230void
294{
295 if (x!=0) {
296 VGLLine(object, xc+x, yc+y, xc-x, yc+y, color);
297 if (y!=0)
298 VGLLine(object, xc+x, yc-y, xc-x, yc-y, color);
299 }
300 else {
301 VGLLine(object, xc, yc+y, xc, yc-y, color);
302 }
303}
304
305void
231VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color)
306VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color)
232{
233 int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b;
234 int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b;
235
236 while (dx<dy) {
237 set2lines(object, x, y, xc, yc, color);
238 if (d>0) {
239 y--; dy-=asq2; d-=dy;

--- 6 unchanged lines hidden (view full) ---

246 if (d<0) {
247 x++; dx+=bsq2; d+=dx;
248 }
249 y--; dy-=asq2; d+=asq-dy;
250 }
251}
252
253void
307{
308 int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b;
309 int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b;
310
311 while (dx<dy) {
312 set2lines(object, x, y, xc, yc, color);
313 if (d>0) {
314 y--; dy-=asq2; d-=dy;

--- 6 unchanged lines hidden (view full) ---

321 if (d<0) {
322 x++; dx+=bsq2; d+=dx;
323 }
324 y--; dy-=asq2; d+=asq-dy;
325 }
326}
327
328void
254VGLClear(VGLBitmap *object, byte color)
329VGLClear(VGLBitmap *object, u_long color)
255{
256 int offset;
257 int len;
330{
331 int offset;
332 int len;
333 int i, total = 0;
334 byte b[4];
258
259 VGLCheckSwitch();
335
336 VGLCheckSwitch();
260 VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color);
337 VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color); /* XXX */
261 switch (object->Type) {
262 case MEMBUF:
263 case VIDBUF8:
338 switch (object->Type) {
339 case MEMBUF:
340 case VIDBUF8:
264 memset(object->Bitmap, color, object->VXsize*object->VYsize);
341 memset(object->Bitmap, (byte)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);
342 break;
343
344 case VIDBUF8S:
345 for (offset = 0; offset < object->VXsize*object->VYsize; ) {
346 VGLSetSegment(offset);
347 len = min(object->VXsize*object->VYsize - offset,
348 VGLAdpInfo.va_window_size);
272 memset(object->Bitmap, color, len);
349 memset(object->Bitmap, (byte)color, len);
273 offset += len;
274 }
275 break;
350 offset += len;
351 }
352 break;
353 case VIDBUF16:
354 case VIDBUF24:
355 case VIDBUF32:
356 color2mem(color, b, object->PixelBytes);
357 total = object->VXsize*object->VYsize*object->PixelBytes;
358 for (i = 0; i < total; i += object->PixelBytes)
359 bcopy(b, object->Bitmap + i, object->PixelBytes);
360 break;
276
361
362 case VIDBUF16S:
363 case VIDBUF24S:
364 case VIDBUF32S:
365 color2mem(color, b, object->PixelBytes);
366 total = object->VXsize*object->VYsize*object->PixelBytes;
367 for (offset = 0; offset < total; ) {
368 VGLSetSegment(offset);
369 len = min(total - offset, VGLAdpInfo.va_window_size);
370 for (i = 0; i < len; i += object->PixelBytes)
371 bcopy(b, object->Bitmap + offset + i, object->PixelBytes);
372 offset += len;
373 }
374 break;
375
277 case VIDBUF8X:
278 /* XXX works only for Xsize % 4 = 0 */
279 outb(0x3c6, 0xff);
280 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
376 case VIDBUF8X:
377 /* XXX works only for Xsize % 4 = 0 */
378 outb(0x3c6, 0xff);
379 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
281 memset(object->Bitmap, color, VGLAdpInfo.va_line_width*object->VYsize);
380 memset(object->Bitmap, (byte)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);
381 break;
382
383 case VIDBUF4:
384 case VIDBUF4S:
385 /* XXX works only for Xsize % 8 = 0 */
386 outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
387 outb(0x3ce, 0x05); outb(0x3cf, 0x02); /* mode 2 */
388 outb(0x3ce, 0x01); outb(0x3cf, 0x00); /* set/reset enable */
389 outb(0x3ce, 0x08); outb(0x3cf, 0xff); /* bit mask */
390 for (offset = 0; offset < VGLAdpInfo.va_line_width*object->VYsize; ) {
391 VGLSetSegment(offset);
392 len = min(object->VXsize*object->VYsize - offset,
393 VGLAdpInfo.va_window_size);
295 memset(object->Bitmap, color, len);
394 memset(object->Bitmap, (byte)color, len);
296 offset += len;
297 }
298 outb(0x3ce, 0x05); outb(0x3cf, 0x00);
299 break;
300 }
301 VGLMouseUnFreeze();
302}
303

--- 100 unchanged lines hidden ---
395 offset += len;
396 }
397 outb(0x3ce, 0x05); outb(0x3cf, 0x00);
398 break;
399 }
400 VGLMouseUnFreeze();
401}
402

--- 100 unchanged lines hidden ---