diff options
author | sos <sos@FreeBSD.org> | 1997-08-17 21:09:35 +0000 |
---|---|---|
committer | sos <sos@FreeBSD.org> | 1997-08-17 21:09:35 +0000 |
commit | dc4edce04f9cf3054b57276ca949e6ee9260cda2 (patch) | |
tree | a5f82cec8415948b535cc95a85fe36eccc201d9a /lib/libvgl | |
parent | 48abae6115c5ac6fba0407b546d3c6e31e7f4192 (diff) | |
download | FreeBSD-src-dc4edce04f9cf3054b57276ca949e6ee9260cda2.zip FreeBSD-src-dc4edce04f9cf3054b57276ca949e6ee9260cda2.tar.gz |
First import of my little "video graphic library".
See the manpage vgl.3 for more info.
A little example will follow shortly.
Diffstat (limited to 'lib/libvgl')
-rw-r--r-- | lib/libvgl/Makefile | 12 | ||||
-rw-r--r-- | lib/libvgl/bitmap.c | 229 | ||||
-rw-r--r-- | lib/libvgl/main.c | 226 | ||||
-rw-r--r-- | lib/libvgl/mouse.c | 284 | ||||
-rw-r--r-- | lib/libvgl/simple.c | 357 | ||||
-rw-r--r-- | lib/libvgl/text.c | 243 | ||||
-rw-r--r-- | lib/libvgl/vgl.3 | 279 | ||||
-rw-r--r-- | lib/libvgl/vgl.h | 119 |
8 files changed, 1749 insertions, 0 deletions
diff --git a/lib/libvgl/Makefile b/lib/libvgl/Makefile new file mode 100644 index 0000000..ebbc021 --- /dev/null +++ b/lib/libvgl/Makefile @@ -0,0 +1,12 @@ +LIB= vgl +SHLIB_MAJOR= 1 +SHLIB_MINOR= 0 +CFLAGS+=-Wall -I${.CURDIR} +SRCS= main.c simple.c bitmap.c text.c mouse.c +MAN3= vgl.3 + +beforeinstall: + ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/vgl.h \ + ${DESTDIR}/usr/include + +.include <bsd.lib.mk> diff --git a/lib/libvgl/bitmap.c b/lib/libvgl/bitmap.c new file mode 100644 index 0000000..ffadb79 --- /dev/null +++ b/lib/libvgl/bitmap.c @@ -0,0 +1,229 @@ +/*- + * Copyright (c) 1991-1997 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: bitmap.c,v 1.8 1997/08/15 12:32:59 sos Exp $ + */ + +#include <sys/types.h> +#include <signal.h> +#include "vgl.h" + +static byte VGLPlane[4][128]; +static byte mask[8] = {0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01}; +static int color2bit[16] = {0x00000000, 0x00000001, 0x00000100, 0x00000101, + 0x00010000, 0x00010001, 0x00010100, 0x00010101, + 0x01000000, 0x01000001, 0x01000100, 0x01000101, + 0x01010000, 0x01010001, 0x01010100, 0x01010101}; + +static void +WriteVerticalLine(VGLBitmap *dst, int x, int y, int width, byte *line) +{ + int i, pos, last, planepos, start_offset, end_offset, offset; + unsigned int word = 0; + byte *address; + + switch (dst->Type) { + case VIDBUF4: + address = dst->Bitmap + (dst->Xsize/8 * y) + x/8; + start_offset = (x & 0x07); + end_offset = (x + width) & 0x07; + offset = start_offset; + pos = 0; + planepos = 0; + while (pos < width) { + word = 0; + last = pos + 8 - offset; + while (pos < last && pos < width) + word = (word<<1) | color2bit[line[pos++]&0x0f]; + VGLPlane[0][planepos] = word; + VGLPlane[1][planepos] = word>>8; + VGLPlane[2][planepos] = word>>16; + VGLPlane[3][planepos] = word>>24; + planepos++; + offset = 0; + } + planepos--; + if (end_offset) { + word <<= (8 - end_offset); + VGLPlane[0][planepos] = word; + VGLPlane[1][planepos] = word>>8; + VGLPlane[2][planepos] = word>>16; + VGLPlane[3][planepos] = word>>24; + } + if (start_offset || end_offset) + width+=8; + for (i=0; i<4; i++) { + outb(0x3c4, 0x02); + outb(0x3c5, 0x01<<i); + outb(0x3ce, 0x04); + outb(0x3cf, i); + if (start_offset) + VGLPlane[i][0] |= *address & ~mask[start_offset]; + if (end_offset) + VGLPlane[i][planepos] |= *(address + planepos) & mask[end_offset]; + bcopy(&VGLPlane[i][0], address, width/8); + } + break; + case VIDBUF8X: + address = dst->Bitmap + ((dst->Xsize * y) + x)/2; + for (i=0; i<4; i++) { + outb(0x3c4, 0x02); + outb(0x3c5, 0x01<<i); + pos = i; + for (planepos=0; planepos<width/4; planepos++, pos+=4) + address[planepos] = line[pos]; + } + break; + case VIDBUF8: + case MEMBUF: + address = dst->Bitmap + (dst->Xsize * y) + x; + bcopy(line, address, width); + break; + + default: + } +} + +static void +ReadVerticalLine(VGLBitmap *src, int x, int y, int width, byte *line) +{ + int i, bit, pos, count, planepos, start_offset, end_offset, offset; + byte *address; + + switch (src->Type) { + case VIDBUF4: + address = src->Bitmap + (src->Xsize/8 * y) + x/8; + start_offset = (x & 0x07); + end_offset = (x + width) & 0x07; + offset = start_offset; + if (start_offset) + count = (width - (8 - start_offset)) / 8 + 1; + else + count = width / 8; + if (end_offset) + count++; + for (i=0; i<4; i++) { + outb(0x3ce, 0x04); + outb(0x3cf, i); + bcopy(address, &VGLPlane[i][0], count); + } + pos = 0; + planepos = 0; + while (pos < width) { + for (bit = (7-offset); bit >= 0 && pos < width; bit--, pos++) { + line[pos] = (VGLPlane[0][planepos] & (1<<bit) ? 1 : 0) | + ((VGLPlane[1][planepos] & (1<<bit) ? 1 : 0) << 1) | + ((VGLPlane[2][planepos] & (1<<bit) ? 1 : 0) << 2) | + ((VGLPlane[3][planepos] & (1<<bit) ? 1 : 0) << 3); + } + planepos++; + offset = 0; + } + break; + case VIDBUF8X: + address = src->Bitmap + ((src->Xsize * y) + x)/2; + for (i=0; i<4; i++) { + outb(0x3ce, 0x04); + outb(0x3cf, i); + pos = i; + for (planepos=0; planepos<width/4; planepos++, pos+=4) + line[pos] = address[planepos]; + } + break; + case VIDBUF8: + case MEMBUF: + address = src->Bitmap + (src->Xsize * y) + x; + bcopy(address, line, width); + break; + default: + } +} + +int +__VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, + VGLBitmap *dst, int dstx, int dsty, int width, int hight) +{ + int srcline, dstline; + + if (srcx>src->Xsize||srcy>src->Ysize||dsty>dst->Xsize||dsty>dst->Ysize) + return -1; + if (srcx < 0) { + width=width+srcx; dstx-=srcx; srcx=0; + } + if (srcy < 0) { + hight=hight+srcy; dsty-=srcy; srcy=0; + } + if (dstx < 0) { + width=width+dstx; srcx-=dstx; dstx=0; + } + if (dsty < 0) { + hight=hight+dsty; srcy-=dsty; dsty=0; + } + if (srcx+width > src->Xsize) + width=src->Xsize-srcx; + if (srcy+hight > src->Ysize) + hight=src->Ysize-srcy; + if (dstx+width > dst->Xsize) + width=dst->Xsize-dstx; + if (dsty+hight > dst->Ysize) + hight=dst->Ysize-dsty; + if (width < 0 || hight < 0) + return -1; + if (src->Type == MEMBUF) { + for (srcline=srcy, dstline=dsty; srcline<srcy+hight; srcline++, dstline++) { + WriteVerticalLine(dst, dstx, dstline, width, + (src->Bitmap+(srcline*src->Xsize)+srcx)); + } + } + else if (dst->Type == MEMBUF) { + for (srcline=srcy, dstline=dsty; srcline<srcy+hight; srcline++, dstline++) { + ReadVerticalLine(src, srcx, srcline, width, + (dst->Bitmap+(dstline*dst->Xsize)+dstx)); + } + } + else { + byte buffer[1024]; + for (srcline=srcy, dstline=dsty; srcline<srcy+hight; srcline++, dstline++) { + ReadVerticalLine(src, srcx, srcline, width, buffer); + WriteVerticalLine(dst, dstx, dstline, width, buffer); + } + } + return 0; +} + +int +VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, + VGLBitmap *dst, int dstx, int dsty, int width, int hight) +{ + int error; + + VGLMouseFreeze(dstx, dsty, width, hight, 0); + error = __VGLBitmapCopy(src, srcx, srcy, dst, dstx, dsty, width, hight); + VGLMouseUnFreeze(); + return error; +} + diff --git a/lib/libvgl/main.c b/lib/libvgl/main.c new file mode 100644 index 0000000..4334f4e --- /dev/null +++ b/lib/libvgl/main.c @@ -0,0 +1,226 @@ +/*- + * Copyright (c) 1991-1997 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: main.c,v 1.14 1997/08/15 12:32:59 sos Exp $ + */ + +#include <stdio.h> +#include <sys/types.h> +#include <sys/signal.h> +#include <sys/file.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <machine/console.h> +#include "vgl.h" + +VGLBitmap *VGLDisplay; + +static int VGLMode; +static int VGLOldMode; +static byte *VGLBuf; +static byte *VGLMem; +static int VGLSwitchPending; +static int VGLOnDisplay; + +void +VGLEnd() +{ +struct vt_mode smode; + +/* + while (!VGLOnDisplay) pause(); + VGLCheckSwitch();; +*/ + outb(0x3c4, 0x02); + outb(0x3c5, 0x0f); + bzero(VGLMem, 64*1024); + ioctl(0, _IO('S', VGLOldMode), 0); + ioctl(0, KDDISABIO, 0); + ioctl(0, KDSETMODE, KD_TEXT); + smode.mode = VT_AUTO; + ioctl(0, VT_SETMODE, &smode); + free(VGLBuf); + free(VGLDisplay); +} + +static void +VGLAbort() +{ + VGLEnd(); + exit(0); +} + +static void +VGLSwitch() +{ + if (!VGLOnDisplay) + VGLOnDisplay = 1; + else + VGLOnDisplay = 0; + VGLSwitchPending = 1; + signal(SIGUSR1, VGLSwitch); +} + +int +VGLInit(int mode) +{ + struct vt_mode smode; + struct winsize winsz; + int error; + + signal(SIGUSR1, VGLSwitch); + signal(SIGINT, VGLAbort); + signal(SIGSEGV, VGLAbort); + signal(SIGBUS, VGLAbort); + + VGLOnDisplay = 1; + VGLSwitchPending = 0; + + ioctl(0, CONS_GET, &VGLOldMode); + + VGLMem = (byte*)mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_FILE, + open("/dev/mem", O_RDWR), 0xA0000); + if (VGLMem <= (byte*)0) + return 1; + + VGLBuf = (byte*)malloc(256*1024); + if (VGLBuf == NULL) + return 1; + + VGLDisplay = (VGLBitmap*) malloc(sizeof(VGLBitmap)); + if (VGLDisplay == NULL) { + free(VGLBuf); + return 1; + } + + switch (mode) { + case SW_BG640x480: case SW_CG640x480: + VGLDisplay->Type = VIDBUF4; + break; + case SW_VGA_CG320: + VGLDisplay->Type = VIDBUF8; + break; + case SW_VGA_MODEX: + VGLDisplay->Type = VIDBUF8X; + break; + default: + VGLEnd(); + return 1; + } + + if ((error = ioctl(0, KDENABIO, 0))) + return error; + + ioctl(0, VT_WAITACTIVE, 0); + ioctl(0, KDSETMODE, KD_GRAPHICS); + if ((error = ioctl(0, mode, 0))) { + ioctl(0, KDSETMODE, KD_TEXT); + ioctl(0, KDDISABIO, 0); + return error; + } + + VGLMode = mode; + + outb(0x3c4, 0x02); + outb(0x3c5, 0x0f); + bzero(VGLMem, 64*1024); + + if (ioctl(0, TIOCGWINSZ, &winsz)) { + VGLEnd(); + return 1; + } + + VGLDisplay->Bitmap = VGLMem; + VGLDisplay->Xsize = winsz.ws_xpixel; + VGLDisplay->Ysize = winsz.ws_ypixel; + VGLSavePalette(); + + smode.mode = VT_PROCESS; + smode.waitv = 0; + smode.relsig = SIGUSR1; + smode.acqsig = SIGUSR1; + smode.frsig = SIGINT; + if (ioctl(0, VT_SETMODE, &smode) == -1) { + VGLEnd(); + return 1; + } + VGLTextSetFontFile((byte*)0); + return 0; +} + +void +VGLCheckSwitch() +{ + if (VGLSwitchPending) { + int i; + + VGLSwitchPending = 0; + if (VGLOnDisplay) { + ioctl(0, KDENABIO, 0); + ioctl(0, KDSETMODE, KD_GRAPHICS); + ioctl(0, VGLMode, 0); + outb(0x3c6, 0xff); + for (i=0; i<4; i++) { + outb(0x3c4, 0x02); + outb(0x3c5, 0x01<<i); + bcopy(&VGLBuf[i*64*1024], VGLMem, 64*1024); + } + VGLRestorePalette(); + ioctl(0, VT_RELDISP, VT_ACKACQ); + VGLDisplay->Bitmap = VGLMem; + switch (VGLMode) { + case SW_BG640x480: case SW_CG640x480: + VGLDisplay->Type = VIDBUF4; + break; + case SW_VGA_CG320: + VGLDisplay->Type = VIDBUF8; + break; + case SW_VGA_MODEX: + VGLDisplay->Type = VIDBUF8X; + break; + default: + VGLDisplay->Type = VIDBUF8; /* XXX */ + break; + } + } + else { + for (i=0; i<4; i++) { + outb(0x3ce, 0x04); + outb(0x3cf, i); + bcopy(VGLMem, &VGLBuf[i*64*1024], 64*1024); + } + ioctl(0, VGLOldMode, 0); + ioctl(0, KDSETMODE, KD_TEXT); + ioctl(0, KDDISABIO, 0); + ioctl(0, VT_RELDISP, VT_TRUE); + VGLDisplay->Bitmap = VGLBuf; + VGLDisplay->Type = MEMBUF; + } + } + while (!VGLOnDisplay) pause(); +} + diff --git a/lib/libvgl/mouse.c b/lib/libvgl/mouse.c new file mode 100644 index 0000000..6f54be6 --- /dev/null +++ b/lib/libvgl/mouse.c @@ -0,0 +1,284 @@ +/*- + * Copyright (c) 1991-1997 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: mouse.c,v 1.10 1997/08/15 12:32:59 sos Exp $ + */ + +#include <stdio.h> +#include <sys/types.h> +#include <sys/ioctl.h> +#include <sys/signal.h> +#include <machine/console.h> +#include "vgl.h" + +/* prototype for internal function */ +int __VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight); + +#define X 0xff +static byte StdAndMask[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE] = { + X,X,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + X,X,X,0,0,0,0,0,0,0,0,0,0,0,0,0, + X,X,X,X,0,0,0,0,0,0,0,0,0,0,0,0, + X,X,X,X,X,0,0,0,0,0,0,0,0,0,0,0, + X,X,X,X,X,X,0,0,0,0,0,0,0,0,0,0, + X,X,X,X,X,X,X,0,0,0,0,0,0,0,0,0, + X,X,X,X,X,X,X,X,0,0,0,0,0,0,0,0, + X,X,X,X,X,X,X,X,X,0,0,0,0,0,0,0, + X,X,X,X,X,X,X,0,0,0,0,0,0,0,0,0, + 0,0,0,X,X,X,X,0,0,0,0,0,0,0,0,0, + 0,0,0,X,X,X,X,X,0,0,0,0,0,0,0,0, + 0,0,0,0,X,X,X,X,0,0,0,0,0,0,0,0, + 0,0,0,0,X,X,X,X,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; +static byte StdOrMask[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,X,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,X,X,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,X,X,X,0,0,0,0,0,0,0,0,0,0,0,0, + 0,X,X,X,X,0,0,0,0,0,0,0,0,0,0,0, + 0,X,X,X,X,X,0,0,0,0,0,0,0,0,0,0, + 0,X,X,X,X,X,X,0,0,0,0,0,0,0,0,0, + 0,X,X,0,X,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,X,X,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,X,X,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,X,X,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,X,X,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; +#undef X +static VGLBitmap VGLMouseStdAndMask = + { MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdAndMask }; +static VGLBitmap VGLMouseStdOrMask = + { MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdOrMask }; +static VGLBitmap *VGLMouseAndMask, *VGLMouseOrMask; +static byte map[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE]; +static VGLBitmap VGLMouseSave = { MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, map}; +static int VGLMouseVisible = 0; +static int VGLMouseFrozen = 0; +static int VGLMouseShown = 0; +static int VGLMouseXpos = 0; +static int VGLMouseYpos = 0; +static int VGLMouseButtons = 0; + +void +VGLMousePointerShow() +{ + byte buf[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE]; + VGLBitmap buffer = { MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, buf }; + byte crtcidx, crtcval, gdcidx, gdcval; + int pos; + + if (!VGLMouseVisible) { + VGLMouseVisible = 1; + crtcidx = inb(0x3c4); + crtcval = inb(0x3c5); + gdcidx = inb(0x3ce); + gdcval = inb(0x3cf); + __VGLBitmapCopy(VGLDisplay, VGLMouseXpos, VGLMouseYpos, + &VGLMouseSave, 0, 0, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); + bcopy(VGLMouseSave.Bitmap, buffer.Bitmap, MOUSE_IMG_SIZE*MOUSE_IMG_SIZE); + for (pos = 0; pos < MOUSE_IMG_SIZE*MOUSE_IMG_SIZE; pos++) + buffer.Bitmap[pos]=(buffer.Bitmap[pos]&~(VGLMouseAndMask->Bitmap[pos])) | + VGLMouseOrMask->Bitmap[pos]; + __VGLBitmapCopy(&buffer, 0, 0, VGLDisplay, + VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); + outb(0x3c4, crtcidx); + outb(0x3c5, crtcval); + outb(0x3ce, gdcidx); + outb(0x3cf, gdcval); + } +} + +void +VGLMousePointerHide() +{ + byte crtcidx, crtcval, gdcidx, gdcval; + + if (VGLMouseVisible) { + VGLMouseVisible = 0; + crtcidx = inb(0x3c4); + crtcval = inb(0x3c5); + gdcidx = inb(0x3ce); + gdcval = inb(0x3cf); + __VGLBitmapCopy(&VGLMouseSave, 0, 0, VGLDisplay, + VGLMouseXpos, VGLMouseYpos, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE); + outb(0x3c4, crtcidx); + outb(0x3c5, crtcval); + outb(0x3ce, gdcidx); + outb(0x3cf, gdcval); + } +} + +void +VGLMouseMode(int mode) +{ + if (mode == VGL_MOUSESHOW) { + if (VGLMouseShown == VGL_MOUSEHIDE) { + VGLMousePointerShow(); + VGLMouseShown = VGL_MOUSESHOW; + } + } + else { + if (VGLMouseShown == VGL_MOUSESHOW) { + VGLMousePointerHide(); + VGLMouseShown = VGL_MOUSEHIDE; + } + } +} + +void +VGLMouseAction(int dummy) +{ + struct mouse_info mouseinfo; + + if (VGLMouseFrozen) { + VGLMouseFrozen++; + return; + } + mouseinfo.operation = MOUSE_GETINFO; + ioctl(0, CONS_MOUSECTL, &mouseinfo); + if (VGLMouseShown == VGL_MOUSESHOW) + VGLMousePointerHide(); + VGLMouseXpos = mouseinfo.u.data.x; + VGLMouseYpos = mouseinfo.u.data.y; + VGLMouseButtons = mouseinfo.u.data.buttons; + if (VGLMouseShown == VGL_MOUSESHOW) + VGLMousePointerShow(); +} + +void +VGLMouseSetImage(VGLBitmap *AndMask, VGLBitmap *OrMask) +{ + if (VGLMouseShown == VGL_MOUSESHOW) + VGLMousePointerHide(); + VGLMouseAndMask = AndMask; + VGLMouseOrMask = OrMask; + if (VGLMouseShown == VGL_MOUSESHOW) + VGLMousePointerShow(); +} + +void +VGLMouseSetStdImage() +{ + if (VGLMouseShown == VGL_MOUSESHOW) + VGLMousePointerHide(); + VGLMouseAndMask = &VGLMouseStdAndMask; + VGLMouseOrMask = &VGLMouseStdOrMask; + if (VGLMouseShown == VGL_MOUSESHOW) + VGLMousePointerShow(); +} + +int +VGLMouseInit(int mode) +{ + struct mouse_info mouseinfo; + int error; + + VGLMouseSetStdImage(); + mouseinfo.operation = MOUSE_MODE; + mouseinfo.u.mode.signal = SIGUSR2; + if ((error = ioctl(0, CONS_MOUSECTL, &mouseinfo))) + return error; + signal(SIGUSR2, VGLMouseAction); + mouseinfo.operation = MOUSE_GETINFO; + ioctl(0, CONS_MOUSECTL, &mouseinfo); + VGLMouseXpos = mouseinfo.u.data.x; + VGLMouseYpos = mouseinfo.u.data.y; + VGLMouseButtons = mouseinfo.u.data.buttons; + VGLMouseMode(mode); + return 0; +} + +int +VGLMouseStatus(int *x, int *y, char *buttons) +{ + signal(SIGUSR2, SIG_IGN); + *x = VGLMouseXpos; + *y = VGLMouseYpos; + *buttons = VGLMouseButtons; + signal(SIGUSR2, VGLMouseAction); + return VGLMouseShown; +} + +int +VGLMouseFreeze(int x, int y, int width, int hight, byte color) +{ + if (!VGLMouseFrozen) { + VGLMouseFrozen = 1; + if (width > 1 || hight > 1) { /* bitmap */ + if (VGLMouseShown == 1) { + int overlap; + + if (x > VGLMouseXpos) + overlap = (VGLMouseXpos + MOUSE_IMG_SIZE) - x; + else + overlap = (x + width) - VGLMouseXpos; + if (overlap > 0) { + if (y > VGLMouseYpos) + overlap = (VGLMouseYpos + MOUSE_IMG_SIZE) - y; + else + overlap = (y + hight) - VGLMouseYpos; + if (overlap > 0) + VGLMousePointerHide(); + } + } + } + else { /* bit */ + if (VGLMouseShown && + x >= VGLMouseXpos && x < VGLMouseXpos + MOUSE_IMG_SIZE && + y >= VGLMouseYpos && y < VGLMouseYpos + MOUSE_IMG_SIZE) { + VGLMouseSave.Bitmap[(y-VGLMouseYpos)*MOUSE_IMG_SIZE+(x-VGLMouseXpos)] = + (color); + if (VGLMouseAndMask->Bitmap + [(y-VGLMouseYpos)*MOUSE_IMG_SIZE+(x-VGLMouseXpos)]) { + return 1; + } + } + } + } + return 0; +} + +void +VGLMouseUnFreeze() +{ + if (VGLMouseFrozen > 1) { + VGLMouseFrozen = 0; + VGLMouseAction(0); + } + else { + VGLMouseFrozen = 0; + if (VGLMouseShown == VGL_MOUSESHOW && !VGLMouseVisible) + VGLMousePointerShow(); + } +} diff --git a/lib/libvgl/simple.c b/lib/libvgl/simple.c new file mode 100644 index 0000000..2b966e5 --- /dev/null +++ b/lib/libvgl/simple.c @@ -0,0 +1,357 @@ +/*- + * Copyright (c) 1991-1997 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: simple.c,v 1.8 1997/08/15 12:32:59 sos Exp $ + */ + +#include <signal.h> +#include <machine/console.h> +#include "vgl.h" + +static byte VGLSavePaletteRed[256]; +static byte VGLSavePaletteGreen[256]; +static byte VGLSavePaletteBlue[256]; + +#define ABS(a) (((a)<0) ? -(a) : (a)) +#define SGN(a) (((a)<0) ? -1 : 1) + + +void +VGLSetXY(VGLBitmap *object, int x, int y, byte color) +{ + VGLCheckSwitch(); + if (x>=0 && x<object->Xsize && y>=0 && y<object->Ysize) { + if (!VGLMouseFreeze(x, y, 1, 1, color)) { + switch (object->Type) { + case MEMBUF: + case VIDBUF8: + object->Bitmap[y*object->Xsize+x]=(color); + break; + case VIDBUF8X: + outb(0x3c4, 0x02); + outb(0x3c5, 0x01 << (x&0x3)); + object->Bitmap[(unsigned)(object->Xsize/2*y)+(x/4)] = (color); + break; + case VIDBUF4: + outb(0x3c4, 0x02); outb(0x3c5, 0x01); + outb(0x3ce, 0x04); outb(0x3cf, 0x00); + object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] = + ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) ) + | ((color & 0x01) ? (0x80>>(x%8)) : 0); + outb(0x3c4, 0x02); outb(0x3c5, 0x02); + outb(0x3ce, 0x04); outb(0x3cf, 0x01); + object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] = + ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) ) + | ((color & 0x02) ? (0x80>>(x%8)) : 0); + outb(0x3c4, 0x02); outb(0x3c5, 0x04); + outb(0x3ce, 0x04); outb(0x3cf, 0x02); + object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] = + ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) ) + | ((color & 0x04) ? (0x80>>(x%8)) : 0); + outb(0x3c4, 0x02); outb(0x3c5, 0x08); + outb(0x3ce, 0x04); outb(0x3cf, 0x03); + object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] = + ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) ) + | ((color & 0x08) ? (0x80>>(x%8)) : 0); + } + } + VGLMouseUnFreeze(); + } +} + +byte +VGLGetXY(VGLBitmap *object, int x, int y) +{ + VGLCheckSwitch(); + switch (object->Type) { + case MEMBUF: + case VIDBUF8: + return object->Bitmap[((y*object->Xsize)+x)]; + break; + case VIDBUF8X: + outb(0x3ce, 0x04); outb(0x3cf, x & 0x3); + return object->Bitmap[(unsigned)(object->Xsize/4*y)+(x/4)]; + break; + case VIDBUF4: + return (object->Bitmap[((y*object->Xsize/8)+x/8)]&(0x80>>(x%8))) ? 1 : 0; + break; + } + return 0; +} + +void +VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color) +{ + int d, x, y, ax, ay, sx, sy, dx, dy; + + dx = x2-x1; ax = ABS(dx)<<1; sx = SGN(dx); x = x1; + dy = y2-y1; ay = ABS(dy)<<1; sy = SGN(dy); y = y1; + + if (ax>ay) { /* x dominant */ + d = ay-(ax>>1); + for (;;) { + VGLSetXY(object, x, y, color); + if (x==x2) + break; + if (d>=0) { + y += sy; d -= ax; + } + x += sx; d += ay; + } + } + else { /* y dominant */ + d = ax-(ay>>1); + for (;;) { + VGLSetXY(object, x, y, color); + if (y==y2) + break; + if (d>=0) { + x += sx; d -= ay; + } + y += sy; d += ax; + } + } +} + +void +VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color) +{ + VGLLine(object, x1, y1, x2, y1, color); + VGLLine(object, x2, y1, x2, y2, color); + VGLLine(object, x2, y2, x1, y2, color); + VGLLine(object, x1, y2, x1, y1, color); +} + +void +VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color) +{ + int y; + + for (y=y1; y<=y2; y++) VGLLine(object, x1, y, x2, y, color); +} + +void +inline set4pixels(VGLBitmap *object, int x, int y, int xc, int yc, byte color) +{ + if (x!=0) { + VGLSetXY(object, xc+x, yc+y, color); + VGLSetXY(object, xc-x, yc+y, color); + if (y!=0) { + VGLSetXY(object, xc+x, yc-y, color); + VGLSetXY(object, xc-x, yc-y, color); + } + } + else { + VGLSetXY(object, xc, yc+y, color); + if (y!=0) + VGLSetXY(object, xc, yc-y, color); + } +} + +void +VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color) +{ + int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b; + int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b; + + while (dx<dy) { + set4pixels(object, x, y, xc, yc, color); + if (d>0) { + y--; dy-=asq2; d-=dy; + } + x++; dx+=bsq2; d+=bsq+dx; + } + d+=(3*(asq-bsq)/2-(dx+dy))/2; + while (y>=0) { + set4pixels(object, x, y, xc, yc, color); + if (d<0) { + x++; dx+=bsq2; d+=dx; + } + y--; dy-=asq2; d+=asq-dy; + } +} + +void +inline set2lines(VGLBitmap *object, int x, int y, int xc, int yc, byte color) +{ + if (x!=0) { + VGLLine(object, xc+x, yc+y, xc-x, yc+y, color); + if (y!=0) + VGLLine(object, xc+x, yc-y, xc-x, yc-y, color); + } + else { + VGLLine(object, xc, yc+y, xc, yc-y, color); + } +} + +void +VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color) +{ + int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b; + int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b; + + while (dx<dy) { + set2lines(object, x, y, xc, yc, color); + if (d>0) { + y--; dy-=asq2; d-=dy; + } + x++; dx+=bsq2; d+=bsq+dx; + } + d+=(3*(asq-bsq)/2-(dx+dy))/2; + while (y>=0) { + set2lines(object, x, y, xc, yc, color); + if (d<0) { + x++; dx+=bsq2; d+=dx; + } + y--; dy-=asq2; d+=asq-dy; + } +} + +void +VGLClear(VGLBitmap *object, byte color) +{ + VGLCheckSwitch(); + VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color); + switch (object->Type) { + case MEMBUF: + case VIDBUF8: + memset(object->Bitmap, color, object->Xsize*object->Ysize); + break; + case VIDBUF8X: + /* XXX works only for Xsize % 4 = 0 */ + outb(0x3c4, 0x02); outb(0x3c5, 0x0f); + memset(object->Bitmap, color, object->Xsize*object->Ysize/4); + break; + + case VIDBUF4: + /* XXX works only for Xsize % 8 = 0 */ + memset(object->Bitmap, color, object->Xsize/8*object->Ysize); + break; + } + VGLMouseUnFreeze(); +} + +void +VGLRestorePalette() +{ + int i; + + outb(0x3C6, 0xFF); + inb(0x3DA); + outb(0x3C8, 0x00); + for (i=0; i<256; i++) { + outb(0x3C9, VGLSavePaletteRed[i]); + inb(0x84); + outb(0x3C9, VGLSavePaletteGreen[i]); + inb(0x84); + outb(0x3C9, VGLSavePaletteBlue[i]); + inb(0x84); + } + inb(0x3DA); + outb(0x3C0, 0x20); +} + +void +VGLSavePalette() +{ + int i; + + outb(0x3C6, 0xFF); + inb(0x3DA); + outb(0x3C7, 0x00); + for (i=0; i<256; i++) { + VGLSavePaletteRed[i] = inb(0x3C9); + inb(0x84); + VGLSavePaletteGreen[i] = inb(0x3C9); + inb(0x84); + VGLSavePaletteBlue[i] = inb(0x3C9); + inb(0x84); + } + inb(0x3DA); + outb(0x3C0, 0x20); +} + +void +VGLSetPalette(byte *red, byte *green, byte *blue) +{ + int i; + + for (i=0; i<256; i++) { + VGLSavePaletteRed[i] = red[i]; + VGLSavePaletteGreen[i] = green[i]; + VGLSavePaletteBlue[i] = blue[i]; + } + VGLCheckSwitch(); + outb(0x3C6, 0xFF); + inb(0x3DA); + outb(0x3C8, 0x00); + for (i=0; i<256; i++) { + outb(0x3C9, VGLSavePaletteRed[i]); + inb(0x84); + outb(0x3C9, VGLSavePaletteGreen[i]); + inb(0x84); + outb(0x3C9, VGLSavePaletteBlue[i]); + inb(0x84); + } + inb(0x3DA); + outb(0x3C0, 0x20); +} + +void +VGLSetPaletteIndex(byte color, byte red, byte green, byte blue) +{ + VGLSavePaletteRed[color] = red; + VGLSavePaletteGreen[color] = green; + VGLSavePaletteBlue[color] = blue; + VGLCheckSwitch(); + outb(0x3C6, 0xFF); + inb(0x3DA); + outb(0x3C8, color); + outb(0x3C9, red); outb(0x3C9, green); outb(0x3C9, blue); + inb(0x3DA); + outb(0x3C0, 0x20); +} + +void +VGLSetBorder(byte color) +{ + VGLCheckSwitch(); + inb(0x3DA); + outb(0x3C0,0x11); outb(0x3C0, color); + inb(0x3DA); + outb(0x3C0, 0x20); +} + +void +VGLBlankDisplay(int blank) +{ + byte val; + + VGLCheckSwitch(); + outb(0x3C4, 0x01); val = inb(0x3C5); outb(0x3C4, 0x01); + outb(0x3C5, ((blank) ? (val |= 0x20) : (val &= 0xDF))); +} diff --git a/lib/libvgl/text.c b/lib/libvgl/text.c new file mode 100644 index 0000000..f598e47 --- /dev/null +++ b/lib/libvgl/text.c @@ -0,0 +1,243 @@ +/*- + * Copyright (c) 1991-1997 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: text.c,v 1.4 1997/08/13 19:34:23 sos Exp $ + */ + +#include <stdio.h> +#include "vgl.h" + +static VGLText *VGLTextFont = 0; + +extern byte VGLFont[]; + +int +VGLTextSetFontFile(char *filename) +{ +FILE *fd; + + if (VGLTextFont) { + if (VGLTextFont->BitmapArray) + free (VGLTextFont->BitmapArray); + free(VGLTextFont); + } + + if ((VGLTextFont=(VGLText*)malloc(sizeof(VGLText))) == (VGLText*)0) + return 1; + + if (filename==NULL) { + VGLTextFont->Width = 8; + VGLTextFont->Height = 8; + VGLTextFont->BitmapArray = VGLFont; + } + else { + if ((fd=fopen(filename, "r"))==(FILE*)0) + return 1; + fread(&VGLTextFont->Width, 1 , 1, fd); + fread(&VGLTextFont->Height, 1 , 1, fd); + VGLTextFont->BitmapArray = + (byte*)malloc(256*VGLTextFont->Width*VGLTextFont->Height); + fread(VGLTextFont->BitmapArray, 1, + (256*VGLTextFont->Width* VGLTextFont->Height), fd); + fclose(fd); + } + return 0; +} + +void +VGLBitmapPutChar(VGLBitmap *Object, int x, int y, byte ch, + byte fgcol, byte bgcol, int fill, int dir) +{ + int lin, bit; + + for(lin = 0; lin < VGLTextFont->Height; lin++) { + for(bit = 0; bit < VGLTextFont->Width; bit++) { + if (VGLTextFont->BitmapArray[((ch*VGLTextFont->Height)+lin)]&(1<<bit)) + switch (dir) { + case 0: + VGLSetXY(Object, (x+7-bit), (y+lin), fgcol); + break; + case 1: + VGLSetXY(Object, (x+lin), (y-7+bit), fgcol); + break; + case 2: + VGLSetXY(Object, (x-7+bit), (y-lin), fgcol); + break; + case 3: + VGLSetXY(Object, (x-lin), (y+7-bit), fgcol); + break; + case 4: + VGLSetXY(Object, (x+lin+7-bit), (y+lin+bit), fgcol); + break; + } + else if (fill) + switch (dir) { + case 0: + VGLSetXY(Object, (x+7-bit), (y+lin), bgcol); + break; + case 1: + VGLSetXY(Object, (x+lin), (y-7+bit), bgcol); + break; + case 2: + VGLSetXY(Object, (x-7+bit), (y-lin), bgcol); + break; + case 3: + VGLSetXY(Object, (x-lin), (y+7-bit), bgcol); + break; + case 4: + VGLSetXY(Object, (x+lin+7-bit), (y+lin+bit), bgcol); + break; + } + } + } +} + +void +VGLBitmapString(VGLBitmap *Object, int x, int y, char *str, + byte fgcol, byte bgcol, int fill, int dir) +{ + int pos; + + for (pos=0; pos<strlen(str); pos++) { + switch (dir) { + case 0: + VGLBitmapPutChar(Object, x+(pos*VGLTextFont->Width), y, + str[pos], fgcol, bgcol, fill, dir); + break; + case 1: + VGLBitmapPutChar(Object, x, y-(pos*VGLTextFont->Width), + str[pos], fgcol, bgcol, fill, dir); + break; + case 2: + VGLBitmapPutChar(Object, x-(pos*VGLTextFont->Width), y, + str[pos], fgcol, bgcol, fill, dir); + break; + case 3: + VGLBitmapPutChar(Object, x, y+(pos*VGLTextFont->Width), + str[pos], fgcol, bgcol, fill, dir); + break; + case 4: + VGLBitmapPutChar(Object, x+(pos*VGLTextFont->Width), + y-(pos*VGLTextFont->Width), + str[pos], fgcol, bgcol, fill, dir); + break; + } + } +} + +byte VGLFont[] = { +0,0,0,0,0,0,0,0,126,129,165,129,189,153,129,126,126,255,219,255,195,231, +255,126,108,254,254,254,124,56,16,0,16,56,124,254,124,56,16,0,56,124,56, +254,254,124,56,124,16,16,56,124,254,124,56,124,0,0,24,60,60,24,0,0,255, +255,231,195,195,231,255,255,0,60,102,66,66,102,60,0,255,195,153,189,189, +153,195,255,15,7,15,125,204,204,204,120,60,102,102,102,60,24,126,24,63, +51,63,48,48,112,240,224,127,99,127,99,99,103,230,192,153,90,60,231,231, +60,90,153,128,224,248,254,248,224,128,0,2,14,62,254,62,14,2,0,24,60,126, +24,24,126,60,24,102,102,102,102,102,0,102,0,127,219,219,123,27,27,27,0, +62,99,56,108,108,56,204,120,0,0,0,0,126,126,126,0,24,60,126,24,126,60,24, +255,24,60,126,24,24,24,24,0,24,24,24,24,126,60,24,0,0,24,12,254,12,24,0, +0,0,48,96,254,96,48,0,0,0,0,192,192,192,254,0,0,0,36,102,255,102,36,0,0, +0,24,60,126,255,255,0,0,0,255,255,126,60,24,0,0,0,0,0,0,0,0,0,0,48,120, +120,48,48,0,48,0,108,108,108,0,0,0,0,0,108,108,254,108,254,108,108,0,48, +124,192,120,12,248,48,0,0,198,204,24,48,102,198,0,56,108,56,118,220,204, +118,0,96,96,192,0,0,0,0,0,24,48,96,96,96,48,24,0,96,48,24,24,24,48,96,0, +0,102,60,255,60,102,0,0,0,48,48,252,48,48,0,0,0,0,0,0,0,48,48,96,0,0,0, +252,0,0,0,0,0,0,0,0,0,48,48,0,6,12,24,48,96,192,128,0,124,198,206,222,246, +230,124,0,48,112,48,48,48,48,252,0,120,204,12,56,96,204,252,0,120,204,12, +56,12,204,120,0,28,60,108,204,254,12,30,0,252,192,248,12,12,204,120,0,56, +96,192,248,204,204,120,0,252,204,12,24,48,48,48,0,120,204,204,120,204,204, +120,0,120,204,204,124,12,24,112,0,0,48,48,0,0,48,48,0,0,48,48,0,0,48,48, +96,24,48,96,192,96,48,24,0,0,0,252,0,0,252,0,0,96,48,24,12,24,48,96,0,120, +204,12,24,48,0,48,0,124,198,222,222,222,192,120,0,48,120,204,204,252,204, +204,0,252,102,102,124,102,102,252,0,60,102,192,192,192,102,60,0,248,108, +102,102,102,108,248,0,254,98,104,120,104,98,254,0,254,98,104,120,104,96, +240,0,60,102,192,192,206,102,62,0,204,204,204,252,204,204,204,0,120,48, +48,48,48,48,120,0,30,12,12,12,204,204,120,0,230,102,108,120,108,102,230, +0,240,96,96,96,98,102,254,0,198,238,254,254,214,198,198,0,198,230,246,222, +206,198,198,0,56,108,198,198,198,108,56,0,252,102,102,124,96,96,240,0,120, +204,204,204,220,120,28,0,252,102,102,124,108,102,230,0,120,204,224,112, +28,204,120,0,252,180,48,48,48,48,120,0,204,204,204,204,204,204,252,0,204, +204,204,204,204,120,48,0,198,198,198,214,254,238,198,0,198,198,108,56,56, +108,198,0,204,204,204,120,48,48,120,0,254,198,140,24,50,102,254,0,120,96, +96,96,96,96,120,0,192,96,48,24,12,6,2,0,120,24,24,24,24,24,120,0,16,56, +108,198,0,0,0,0,0,0,0,0,0,0,0,255,48,48,24,0,0,0,0,0,0,0,120,12,124,204, +118,0,224,96,96,124,102,102,220,0,0,0,120,204,192,204,120,0,28,12,12,124, +204,204,118,0,0,0,120,204,252,192,120,0,56,108,96,240,96,96,240,0,0,0,118, +204,204,124,12,248,224,96,108,118,102,102,230,0,48,0,112,48,48,48,120,0, +12,0,12,12,12,204,204,120,224,96,102,108,120,108,230,0,112,48,48,48,48, +48,120,0,0,0,204,254,254,214,198,0,0,0,248,204,204,204,204,0,0,0,120,204, +204,204,120,0,0,0,220,102,102,124,96,240,0,0,118,204,204,124,12,30,0,0, +220,118,102,96,240,0,0,0,124,192,120,12,248,0,16,48,124,48,48,52,24,0,0, +0,204,204,204,204,118,0,0,0,204,204,204,120,48,0,0,0,198,214,254,254,108, +0,0,0,198,108,56,108,198,0,0,0,204,204,204,124,12,248,0,0,252,152,48,100, +252,0,28,48,48,224,48,48,28,0,24,24,24,0,24,24,24,0,224,48,48,28,48,48, +224,0,118,220,0,0,0,0,0,0,0,16,56,108,198,198,254,0,0,0,0,0,0,0,0,0,0,0, +60,126,255,126,24,0,170,85,85,170,170,85,85,170,68,68,68,68,31,4,4,4,124, +64,64,64,31,16,16,16,56,68,68,56,30,17,20,19,64,64,64,124,31,16,16,16,56, +108,56,0,0,0,0,0,0,0,24,24,24,24,126,0,68,100,76,68,16,16,16,31,68,68,40, +16,31,4,4,4,24,24,24,24,248,0,0,0,0,0,0,0,248,24,24,24,0,0,0,0,31,24,24, +24,24,24,24,24,31,0,0,0,24,24,24,24,255,24,24,24,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,24,24,24, +24,31,24,24,24,24,24,24,24,248,24,24,24,24,24,24,24,255,0,0,0,0,0,0,0,255, +24,24,24,24,24,24,24,24,24,24,24,0,12,48,96,24,12,126,0,0,48,12,6,24,48, +126,0,0,0,3,62,54,54,108,0,0,0,4,126,16,126,64,0,0,28,48,48,48,48,126,0, +0,0,0,24,0,0,0,0,0,0,0,0,0,0,0,0,48,0,48,48,120,120,48,0,0,0,16,124,192, +192,124,16,0,56,96,96,240,96,252,0,0,195,60,102,102,60,195,0,0,204,204, +120,48,252,48,0,24,24,24,0,24,24,24,0,126,192,124,198,124,6,252,0,198,0, +0,0,0,0,0,0,124,130,186,162,186,130,124,0,28,6,30,34,31,63,0,0,0,51,102, +204,102,51,0,0,0,254,6,0,0,0,0,0,0,0,0,0,0,0,0,0,124,130,186,178,170,130, +124,0,254,0,0,0,0,0,0,0,56,108,56,0,0,0,0,0,0,16,124,16,0,124,0,0,28,54, +6,24,62,0,0,0,30,2,14,2,30,0,0,0,24,48,0,0,0,0,0,0,0,0,204,204,204,204, +118,192,126,202,202,126,10,10,10,0,0,0,0,24,0,0,0,0,0,0,0,0,0,0,24,48,6, +14,6,6,6,0,0,0,14,17,17,17,14,31,0,0,0,204,102,51,102,204,0,0,96,224,102, +108,51,103,15,3,96,224,102,108,54,106,4,14,240,32,150,108,51,103,15,3,48, +0,48,96,192,204,120,0,24,12,48,120,204,252,204,0,96,192,48,120,204,252, +204,0,120,132,48,120,204,252,204,0,102,152,48,120,204,252,204,0,204,0,48, +120,204,252,204,0,48,72,48,120,204,252,204,0,62,120,152,156,248,152,158, +0,60,102,192,192,192,102,28,48,48,24,254,98,120,98,254,0,24,48,254,98,120, +98,254,0,56,68,254,98,120,98,254,0,102,0,254,98,120,98,254,0,96,48,120, +48,48,48,120,0,24,48,120,48,48,48,120,0,120,132,120,48,48,48,120,0,204, +0,120,48,48,48,120,0,120,108,102,246,102,108,120,0,102,152,230,246,222, +206,198,0,48,24,124,198,198,198,124,0,24,48,124,198,198,198,124,0,56,68, +124,198,198,198,124,0,102,152,124,198,198,198,124,0,198,0,124,198,198,198, +124,0,0,198,108,56,56,108,198,0,6,124,206,154,178,230,120,192,96,48,204, +204,204,204,252,0,24,48,204,204,204,204,252,0,120,132,204,204,204,204,252, +0,204,0,204,204,204,204,252,0,24,48,204,204,120,48,120,0,96,120,108,120, +96,96,96,0,120,204,196,220,198,198,220,192,48,24,120,12,124,204,118,0,24, +48,120,12,124,204,118,0,120,132,120,12,124,204,118,0,102,152,120,12,124, +204,118,0,204,0,120,12,124,204,118,0,48,72,56,12,124,204,118,0,0,0,236, +50,126,176,110,0,0,0,60,102,192,102,28,48,48,24,120,204,252,192,120,0,24, +48,120,204,252,192,120,0,120,132,120,204,252,192,120,0,204,0,120,204,252, +192,120,0,96,48,0,112,48,48,120,0,24,48,0,112,48,48,120,0,112,136,0,112, +48,48,120,0,204,0,0,112,48,48,120,0,108,56,108,12,108,204,120,0,102,152, +248,204,204,204,204,0,96,48,0,124,198,198,124,0,24,48,0,124,198,198,124, +0,56,68,0,124,198,198,124,0,102,152,0,124,198,198,124,0,198,0,0,124,198, +198,124,0,0,0,24,0,126,0,24,0,0,0,6,124,222,246,124,192,96,48,0,204,204, +204,118,0,24,48,0,204,204,204,118,0,48,72,0,204,204,204,118,0,204,0,0,204, +204,204,118,0,24,48,204,204,204,124,12,248,224,120,108,102,108,120,224, +0,204,0,204,204,204,124,12,248 +}; diff --git a/lib/libvgl/vgl.3 b/lib/libvgl/vgl.3 new file mode 100644 index 0000000..dacfef6 --- /dev/null +++ b/lib/libvgl/vgl.3 @@ -0,0 +1,279 @@ +.\" Copyright (c) 1997 Søren Schmidt +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer, +.\" in this position and unchanged. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the author may not be used to endorse or promote products +.\" derived from this software withough specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $Id: vgl.3,v 1.2 1997/08/15 12:35:02 sos Exp $ + +.Dd August 13, 1997 +.Dt VGL 3 +.Os FreeBSD 3 +.Sh NAME +.Nm vgl +.Nd Video Graphics Library functions +.Sh SYNOPSIS +.Fd #include <vgl.h> + +.Sh DESCRIPTION +Libvgl is a library that enables the programmer access to the graphics +modes supported by the console driver (syscons). The library takes care of +programming the actual video hardware, and provides a number of simple +functions to do various graphic operations. There is also support for a +mouse via the standard mouse system in FreeBSD, see +.Fn moused +, including the ability to transparantly have a mousepointer superimposed on +the graphic image currently being worked on. +The library takes care of screenswitching by storing the current image in +memory before swithing to another virtual console, and restoring when the +user switches back. This allows several graphic applications at once, but +on different virtual consoles. + +Below is a short description of the various functions: + +.Sh AUTHOR +.An Søren Schmidt (sos@FreeBSD.org) + +.Sh FUNCTIONS + +.Ft int +.Fn VGLInit "int mode" + +Initialize the library and set up the graphic mode +.Em mode + + +.Ft void +.Fn VGLEnd "void" + +Terminate graphic mode, and restore the screenmode that was active before +.Fn VGLInit +was called. + + +.Ft void +.Fn VGLCheckSwitch "void" + +If the program goes into longer periods of processing without doing +any graphics output, calling this function occasionally will allow +the system to switch screens. + + +.Ft int +.Fn VGLTextSetFontFile "char *filename" + +Instruct the char/string functions to use the font in file +.Em filename +instead of the buildin font. + + +.Ft int +.Fn VGLMouseInit "int mode" + +Initialize the mouse. The optional onscreen mousepointer is shown if the +argument is +.Em VGL_SHOWMOUSE + + +.Ft void +.Fn VGLMouseMode "int mode" + +Either shows the mousepointer if the argument is +.Em VGL_SHOWMOUSE +, or hide the mousepointer if the argument is +.Em VGL_HIDEMOUSE + + +.Ft int +.Fn VGLMouseStatus "int *x" "int *y" "char *buttons" + +Returns the current mousepointer coordiantes and button state in +.Em x, y, buttons. The return value reflects if the mousepointer +is currently shown on screen or not. + + +.Ft void +.Fn VGLMouseSetImage "VGLBitmap *AndMask" "VGLBitmap *OrMask" + +With this function it is possible to change the image of the mousepointer +on screen. + + +.Ft void +.Fn VGLMouseSetStdImage "void" + +This function restores the mousepointer to the standard arrow. + + +.Ft void +.Fn VGLLine "VGLBitmap *object" "int x1" "int y1" "int x2" "int y2" "byte color" + +Draw a line from +.Em x1, y1 +to +.Em x2, y2 +in color +.Em color + + +.Ft void +.Fn VGLBox "VGLBitmap *object" "int x1" "int y1" "int x2" "int y2" "byte color" + +Draw a box with upper left hand corner at +.Em x1, y1 +and lower right hand corner at +.Em x2, y2 +in color +.Em color + + +.Ft void +.Fn VGLFilledBox "VGLBitmap *object" "int x1" "int y1" "int x2" "int y2" "byte color" + +Draw a filled (solid) box with upper left hand corner at +.Em x1, y1 +and lower right hand corner at +.Em x2, y2 +in color +.Em color + + +.Ft void +.Fn VGLEllipse "VGLBitmap *object" "int xc" "int yc" "int a" "int b" "byte color" + +Draw an ellipse centered at +.Em xc, yc +make it +.Em a +pixels wide, and +.Em b +pixels high in color +.Em color + + +.Ft void +.Fn VGLFilledEllipse "VGLBitmap *object" "int xc" "int yc" "int a" "int b" "byte color" + +Draw a filled (solid) ellipse centered at +.Em xc, yc +make it +.Em a +pixels wide, and +.Em b +pixels high in color +.Em color + + +.Ft int +.Fn VGLBitmapCopy "VGLBitmap *src" "int srcx" "int srcy" "VGLBitmap *dst" "int dstx" "int dsty" "int width" "int hight" + +Copy a rectangle of pixels from bitmap +.Em src +upper lefthand corner at +.Em srcx, srcy +to bitmap +.Em dst +at +.Em dstx, dsty +of the size +.Em width, hight + + +.Ft void +.Fn VGLBitmapPutChar "VGLBitmap *Object" "int x" "int y" "byte ch" "byte fgcol" "byte bgcol" "int fill" "int dir" + +Write the character +.Em ch +at position +.Em x, y +in foregroundcolor +.Em fgcol. +If +.Em fill +is != 0, use the color +.Em bgcol +as background otherwise the background is transparant. +The character is drawn in the direction specified by the argument +.Em dir + + +.Ft void +.Fn VGLBitmapString "VGLBitmap *Object" "int x" "int y" "char *str" "byte fgcol" "byte bgcol" "int fill" "int dir" + +Write the string +.Em str +at position +.Em x, y +in foregroundcolor +.Em fgcol. +If +.Em fill +is != 0, use the color +.Em bgcol +as background otherwise the background is transparant. +The string is drawn in the direction specified by the argument +.Em dir + +.Ft void +.Fn VGLClear "VGLBitmap *object" "byte color" + +Clears the entire bitmap to color +.Em color + + +.Ft void +.Fn VGLSetPalette "byte *red" "byte *green" "byte *blue" + +This function sets the palette used, the arguments +.Em red, green, blue +should point to byte arrays of 256 positions each. + + +.Ft void +.Fn VGLSetPaletteIndex "byte color" "byte red" "byte green" "byte blue" + +Set the palette index +.Em color +to the specified RGB value. + + +.Ft void +.Fn VGLSetBorder "byte color" + +Set the bordercolor to color +.Em color + + +.Ft void +.Fn VGLBlankDisplay "int blank" + +Blank the display if the argment +.Em blank +!= 0. This can be done to shut off the screen during diplay updates that +the use hould first see when its done. + + +.Sh HISTORY +The +.Nm +library appeared in FreeBSD 3.0 diff --git a/lib/libvgl/vgl.h b/lib/libvgl/vgl.h new file mode 100644 index 0000000..02994da --- /dev/null +++ b/lib/libvgl/vgl.h @@ -0,0 +1,119 @@ +/*- + * Copyright (c) 1991-1997 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: vgl.h,v 1.14 1997/08/17 20:46:55 sos Exp sos $ + */ + +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <machine/cpufunc.h> + +typedef unsigned char byte; +typedef struct { + byte Type; + int Xsize, Ysize; + byte *Bitmap; +} VGLBitmap; + +/* + * Defined Type's + */ +#define MEMBUF 0 +#define VIDBUF4 1 +#define VIDBUF8 2 +#define VIDBUF8X 3 +#define NOBUF 255 + +typedef struct VGLText { + byte Width, Height; + byte *BitmapArray; +} VGLText; + +typedef struct VGLObject { + int Id; + int Type; + int Status; + int Xpos, Ypos; + int Xhot, Yhot; + VGLBitmap *Image; + VGLBitmap *Mask; + int (*CallBackFunction)(); +} VGLObject; + +#define MOUSE_IMG_SIZE 16 +#define VGL_MOUSEHIDE 0 +#define VGL_MOUSESHOW 1 +#define VGL_MOUSEFREEZE 0 +#define VGL_MOUSEUNFREEZE 1 +#define VGL_DIR_RIGHT 0 +#define VGL_DIR_UP 1 +#define VGL_DIR_LEFT 2 +#define VGL_DIR_DOWN 3 + +extern VGLBitmap *VGLDisplay; + +/* + * Prototypes + */ +/* bitmap.c */ +int __VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight); +int VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight); +/* main.c */ +void VGLEnd(void); +int VGLInit(int mode); +void VGLCheckSwitch(void); +/* mouse.c */ +void VGLMousePointerShow(void); +void VGLMousePointerHide(void); +void VGLMouseMode(int mode); +void VGLMouseAction(int dummy); +void VGLMouseSetImage(VGLBitmap *AndMask, VGLBitmap *OrMask); +void VGLMouseSetStdImage(void); +int VGLMouseInit(int mode); +int VGLMouseStatus(int *x, int *y, char *buttons); +int VGLMouseFreeze(int x, int y, int width, int hight, byte color); +void VGLMouseUnFreeze(void); +/* simple.c */ +void VGLSetXY(VGLBitmap *object, int x, int y, byte color); +byte VGLGetXY(VGLBitmap *object, int x, int y); +void VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color); +void VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color); +void VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color); +void VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color); +void VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color); +void VGLClear(VGLBitmap *object, byte color); +void VGLRestorePalette(void); +void VGLSavePalette(void); +void VGLSetPalette(byte *red, byte *green, byte *blue); +void VGLSetPaletteIndex(byte color, byte red, byte green, byte blue); +void VGLSetBorder(byte color); +void VGLBlankDisplay(int blank); +/* text.c */ +int VGLTextSetFontFile(char *filename); +void VGLBitmapPutChar(VGLBitmap *Object, int x, int y, byte ch, byte fgcol, byte bgcol, int fill, int dir); +void VGLBitmapString(VGLBitmap *Object, int x, int y, char *str, byte fgcol, byte bgcol, int fill, int dir); |