Initial. Don't... just don't ask.

This commit is contained in:
Ryan McGrath 2011-02-24 00:22:00 -08:00
commit 00bae13bba
586 changed files with 129057 additions and 0 deletions

73
gl/Makefile Normal file
View file

@ -0,0 +1,73 @@
#----------------------------------------------------------------------
# Makefile for SVGAlib GL routines.
#----------------------------------------------------------------------
# *** NO SERVICIBLE PARTS HERE!
# All options are in Makefile.cfg.
include ../Makefile.cfg
srcdir = ..
VPATH = $(srcdir)/gl
ifeq (a.out, $(TARGET_FORMAT))
DEFINES += -DSVGA_AOUT
endif
ifeq (y, $(NO_ASM))
DEFINES += -DNO_ASSEMBLY
endif
#----------------------------------------------------------------------
# Rules Section
#----------------------------------------------------------------------
MODULES = grlib.o driver.o line.o palette.o scale.o text.o font8x8.o \
cbitmap.o mem.o
all: libvgagl.a
.PHONY: all clean dep
libvgagl.so.$(VERSION): $(MODULES)
$(CC) -s -shared -Wl,-soname,libvgagl.so.$(MAJOR_VER) -o libvgagl.so.$(VERSION) \
$(MODULES)
libvgagl.a: $(MODULES)
rm -f libvgagl.a
$(AR) rcs libvgagl.a $(MODULES)
.c.o:
$(CC) $(CFLAGS) -c -o $*.o $<
.S.s:
$(CC) $(CFLAGS) -E $< >$@
.s.o:
$(CC) $(CFLAGS) -c -o $*.o $<
.c.s:
$(CC) $(CFLAGS) -S -o $*.s $<
.o:
$(CC) $(CFLAGS) $(LDFLAGS) -o $* $*.o $(LIBS)
chmod 4755 $*
$(MODULES): .depend.gl
dep:
rm -f .depend.gl
make depend
.depend.gl:
echo '# GL Module dependencies' >>.depend.gl
$(CC) $(INCLUDES) -MM $(patsubst %.o,$(srcdir)/gl/%.c,$(MODULES)) >>.depend.gl
clean:
rm -f .depend.gl *.bak *.o *~ libvgagl.a libvgagl.so.$(VERSION)
#
# include a dependency file if one exists
#
ifeq (.depend.gl,$(wildcard .depend.gl))
include .depend.gl
endif

186
gl/cbitmap.c Normal file
View file

@ -0,0 +1,186 @@
/* Framebuffer Graphics Libary for Linux, Copyright 1993 Harm Hanemaayer */
/* cbitmap.c Compiled bitmaps */
#include <stdio.h>
#include <stdlib.h>
#include <vga.h>
#include "inlstring.h" /* include inline string operations */
#include "vgagl.h"
#include "def.h"
void gl_compileboxmask(int w, int h, void *_dp1, void *_dp2)
{
/* Compiled format: <bytes_to_skip (0-254)><number_of_pixels (0-255)> */
/* <pixel_data>[<end_of_line(255)>]... */
uchar *dp1 = _dp1;
uchar *dp2 = _dp2;
int i;
for (i = 0; i < h; i++) {
int x = 0;
while (x < w) {
int count;
/* count zeroes */
count = 0;
while (x < w && *(dp1 + count) == 0 && count < 254) {
count++;
x++;
}
dp1 += count;
if (x < w) {
*dp2++ = count;
/* count nonzeroes */
count = 0;
while (x < w && *(dp1 + count) != 0 && count < 255) {
*(dp2 + count + 1) = *(dp1 + count);
count++;
x++;
}
*dp2 = count;
dp2 += count + 1;
dp1 += count;
}
}
*dp2++ = 0xff;
}
}
int gl_compiledboxmasksize(int w, int h, void *_dp1)
{
/* Compiled format: <bytes_to_skip (0-254)><number_of_pixels (0-255)> */
/* <pixel_data>[<end_of_line(255)>]... */
uchar *dp1 = _dp1;
int size = 0;
int i;
for (i = 0; i < h; i++) {
int x = 0;
while (x < w) {
int count;
/* count zeroes */
count = 0;
while (x < w && *(dp1 + count) == 0 && count < 254) {
count++;
x++;
}
size++;
dp1 += count;
/* count nonzeroes */
if (x < w) {
count = 0;
while (x < w && *(dp1 + count) != 0 && count < 255) {
count++;
x++;
}
size += count + 1;
dp1 += count;
}
}
size++;
}
return size;
}
static void gl_putboxmaskcompiledclip(int nx, int ny, int nw, int nh, int _x,
int _y, int w, int h, void *_dp)
{
/* Special case costly clipping */
uchar *dp = _dp;
uchar *vp, *vpline;
int y;
vpline = VBUF + _y * BYTEWIDTH + _x;
for (y = _y; y < ny + nh; y++) {
int x = _x;
vp = vpline;
for (;;) {
int count = *dp++;
if (count == 0xff)
break; /* end of line */
vp += count;
x += count;
count = *dp++;
/* __memcpy gives severe bug here */
if (y >= ny) {
if (x >= nx)
if (x + count > __clipx2 + 1) {
if (x <= __clipx2)
__memcpyb(vp, dp, __clipx2 - x + 1);
} else
__memcpyb(vp, dp, count);
else if (x + count > __clipx1) {
if (x + count > __clipx2 + 1)
__memcpyb(vp + __clipx1 - x,
dp + __clipx1 - x,
__clipx2 - __clipx1 + 1);
else
__memcpy(vp + __clipx1 - x,
dp + __clipx1 - x,
count - __clipx1 + x);
};
};
x += count;
vp += count;
dp += count;
}
vpline += BYTEWIDTH;
}
}
#define ADJUSTBITMAPBOX() \
nw = w; nh = h; nx = x; ny = y; \
if (nx + nw < __clipx1 || nx > __clipx2) \
return; \
if (ny + nh < __clipy1 || ny > __clipy2) \
return; \
if (nx < __clipx1) { /* left adjust */ \
nw += nx - __clipx1; \
nx = __clipx1; \
} \
if (ny < __clipy1) { /* top adjust */ \
nh += ny - __clipy1; \
ny = __clipy1; \
} \
if (nx + nw > __clipx2) /* right adjust */ \
nw = __clipx2 - nx + 1; \
if (ny + nh > __clipy2) /* bottom adjust */ \
nh = __clipy2 - ny + 1; \
void gl_putboxmaskcompiled(int x, int y, int w, int h, void *_dp)
{
/* no clipping */
uchar *dp = _dp;
uchar *vp, *vpline;
int i;
if (MODETYPE != CONTEXT_LINEAR && MODETYPE != CONTEXT_VIRTUAL) {
printf("vgagl: putboxmaskcompiled only supported in linear framebuffer\n");
return;
}
if (__clip) {
int nx, ny, nw, nh;
ADJUSTBITMAPBOX();
if (nw != w || nh != h) {
gl_putboxmaskcompiledclip(nx, ny, nw, nh, x, y, w, h,
dp);
return;
}
}
vpline = VBUF + y * BYTEWIDTH + x;
for (i = 0; i < h; i++) {
vp = vpline;
for (;;) {
int count = *dp++;
if (count == 0xff)
break; /* end of line */
vp += count;
count = *dp++;
/* __memcpy gives severe bug here */
__memcpyb(vp, dp, count);
vp += count;
dp += count;
}
vpline += BYTEWIDTH;
}
}

72
gl/def.h Normal file
View file

@ -0,0 +1,72 @@
#define uchar unsigned char
#define swap(x, y) { int temp = x; x = y; y = temp; }
#define swapb(x, y) { uchar temp = x; x = y; y = temp; }
#define max(x, y) ((x > y) ? x : y)
#define min(x, y) ((x > y) ? y : x)
#define outside(x, y) (x < __clipx1 || x > __clipx2 || y < __clipy1 \
|| y > __clipy2)
#define x_outside(x) (x < __clipx1 || x > __clipx2)
#define y_outside(y) (y < __clipy1 || y > __clipy2)
#define clipxleft(x) if (x < __clipx1) x = __clipx1;
#define clipxright(x) if (x > __clipx2) x = __clipx2;
#define clipytop(y) if (y < __clipy1) y = __clipy1;
#define clipybottom(y) if (y > __clipy2) y = __clipy2;
#define setpixel (*(__currentcontext.ff.driver_setpixel_func))
#define getpixel (*(__currentcontext.ff.driver_getpixel_func))
#define hline (*(__currentcontext.ff.driver_hline_func))
#define fillbox (*(__currentcontext.ff.driver_fillbox_func))
#define putbox (*(__currentcontext.ff.driver_putbox_func))
#define getbox (*(__currentcontext.ff.driver_getbox_func))
#define putboxmask (*(__currentcontext.ff.driver_putboxmask_func))
#define putboxpart (*(__currentcontext.ff.driver_putboxpart_func))
#define getboxpart (*(__currentcontext.ff.driver_getboxpart_func))
#define copybox (*(__currentcontext.ff.driver_copybox_func))
#define TEXT_TABSIZE 8
#ifdef DLL_CONTEXT_SHADOW
/* Library uses internal currentcontext for faster DLL library. */
#undef BYTESPERPIXEL
#undef BYTEWIDTH
#undef WIDTH
#undef HEIGHT
#undef VBUF
#undef MODETYPE
#undef MODEFLAGS
#undef BITSPERPIXEL
#undef COLORS
#undef __clip
#undef __clipx1
#undef __clipy1
#undef __clipx2
#undef __clipy2
extern GraphicsContext __currentcontext;
#define BYTESPERPIXEL (__currentcontext.bytesperpixel)
#define BYTEWIDTH (__currentcontext.bytewidth)
#define WIDTH (__currentcontext.width)
#define HEIGHT (__currentcontext.height)
#define VBUF (__currentcontext.vbuf)
#define MODETYPE (__currentcontext.modetype)
#define MODEFLAGS (__currentcontext.modeflags)
#define BITSPERPIXEL (__currentcontext.bitsperpixel)
#define COLORS (__currentcontext.colors)
#define __clip (__currentcontext.clip)
#define __clipx1 (__currentcontext.clipx1)
#define __clipy1 (__currentcontext.clipy1)
#define __clipx2 (__currentcontext.clipx2)
#define __clipy2 (__currentcontext.clipy2)
#else
#define __currentcontext currentcontext
#endif

1376
gl/driver.c Normal file

File diff suppressed because it is too large Load diff

104
gl/driver.h Normal file
View file

@ -0,0 +1,104 @@
void __svgalib_driver8_setpixel(int, int, int);
int __svgalib_driver8_getpixel(int, int);
void __svgalib_driver8_hline(int, int, int, int);
void __svgalib_driver8_fillbox(int, int, int, int, int);
void __svgalib_driver8_putbox(int, int, int, int, void *, int);
void __svgalib_driver8_getbox(int, int, int, int, void *, int);
void __svgalib_driver8_putboxmask(int, int, int, int, void *);
void __svgalib_driver8_putboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver8_getboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver8_copybox(int, int, int, int, int, int);
void __svgalib_driver16_setpixel(int, int, int);
int __svgalib_driver16_getpixel(int, int);
void __svgalib_driver16_hline(int, int, int, int);
void __svgalib_driver16_fillbox(int, int, int, int, int);
void __svgalib_driver16_putbox(int, int, int, int, void *, int);
void __svgalib_driver16_getbox(int, int, int, int, void *, int);
void __svgalib_driver16_putboxmask(int, int, int, int, void *);
void __svgalib_driver16_putboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver16_getboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver16_copybox(int, int, int, int, int, int);
void __svgalib_driver24_setpixel(int, int, int);
int __svgalib_driver24_getpixel(int, int);
void __svgalib_driver24_hline(int, int, int, int);
void __svgalib_driver24_fillbox(int, int, int, int, int);
void __svgalib_driver24_putbox(int, int, int, int, void *, int);
void __svgalib_driver24_getbox(int, int, int, int, void *, int);
void __svgalib_driver24_putboxmask(int, int, int, int, void *);
void __svgalib_driver24_putboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver24_getboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver24_copybox(int, int, int, int, int, int);
void __svgalib_driver24_putbox32(int, int, int, int, void *, int);
void __svgalib_driver32_setpixel(int, int, int);
int __svgalib_driver32_getpixel(int, int);
void __svgalib_driver32_hline(int, int, int, int);
void __svgalib_driver32_fillbox(int, int, int, int, int);
void __svgalib_driver32_putbox(int, int, int, int, void *, int);
void __svgalib_driver32_getbox(int, int, int, int, void *, int);
void __svgalib_driver32_putboxmask(int, int, int, int, void *);
void __svgalib_driver32_putboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver32_getboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver32_copybox(int, int, int, int, int, int);
void __svgalib_driver8p_setpixel(int, int, int);
int __svgalib_driver8p_getpixel(int, int);
void __svgalib_driver8p_hline(int, int, int, int);
void __svgalib_driver8p_fillbox(int, int, int, int, int);
void __svgalib_driver8p_putbox(int, int, int, int, void *, int);
void __svgalib_driver8p_getbox(int, int, int, int, void *, int);
void __svgalib_driver8p_putboxmask(int, int, int, int, void *);
void __svgalib_driver8p_putboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver8p_getboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver8p_copybox(int, int, int, int, int, int);
void __svgalib_driver16p_setpixel(int, int, int);
int __svgalib_driver16p_getpixel(int, int);
void __svgalib_driver16p_hline(int, int, int, int);
void __svgalib_driver16p_fillbox(int, int, int, int, int);
void __svgalib_driver16p_putbox(int, int, int, int, void *, int);
void __svgalib_driver16p_getbox(int, int, int, int, void *, int);
void __svgalib_driver16p_putboxmask(int, int, int, int, void *);
void __svgalib_driver16p_putboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver16p_getboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver16p_copybox(int, int, int, int, int, int);
void __svgalib_driver24p_setpixel(int, int, int);
int __svgalib_driver24p_getpixel(int, int);
void __svgalib_driver24p_hline(int, int, int, int);
void __svgalib_driver24p_fillbox(int, int, int, int, int);
void __svgalib_driver24p_putbox(int, int, int, int, void *, int);
void __svgalib_driver24p_getbox(int, int, int, int, void *, int);
void __svgalib_driver24p_putboxmask(int, int, int, int, void *);
void __svgalib_driver24p_putboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver24p_getboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver24p_copybox(int, int, int, int, int, int);
void __svgalib_driver32p_setpixel(int, int, int);
int __svgalib_driver32p_getpixel(int, int);
void __svgalib_driver32p_hline(int, int, int, int);
void __svgalib_driver32p_fillbox(int, int, int, int, int);
void __svgalib_driver32p_putbox(int, int, int, int, void *, int);
void __svgalib_driver32p_getbox(int, int, int, int, void *, int);
void __svgalib_driver32p_putboxmask(int, int, int, int, void *);
void __svgalib_driver32p_putboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver32p_getboxpart(int, int, int, int, int, int, void *, int, int);
void __svgalib_driver32p_copybox(int, int, int, int, int, int);
void __svgalib_driver8a_fillbox(int, int, int, int, int);
void __svgalib_driver8a_copybox(int, int, int, int, int, int);
void __svgalib_driverplanar256_nothing(void);
void __svgalib_driverplanar256_putbox(int, int, int, int, void *, int);
void __svgalib_driverplanar16_nothing(void);
/* Generic functions */
int __svgalib_driver_setread(GraphicsContext * gc, int i, void **vp);
int __svgalib_driver_setwrite(GraphicsContext * gc, int i, void **vp);
/* internal globals: */
extern void (*__svgalib_nonaccel_fillbox)(int, int, int, int, int);

137
gl/font8x8.c Normal file
View file

@ -0,0 +1,137 @@
/* binary image of font8x8 follows */
static unsigned char __font8x8[] =
{
0, 0, 0, 0, 0, 0, 0, 0, 126, 129, 165, 129, 189, 129, 126, 0, /* 0 to 15 */
126, 255, 219, 255, 195, 255, 126, 0, 54, 127, 127, 127, 62, 28, 8, 0, /* 16 to 31 */
8, 28, 62, 127, 62, 28, 8, 0, 28, 28, 8, 107, 127, 107, 8, 28, /* 32 to 47 */
8, 28, 62, 127, 62, 8, 28, 62, 0, 0, 24, 60, 60, 24, 0, 0, /* 48 to 63 */
255, 255, 231, 195, 195, 231, 255, 255, 0, 60, 102, 66, 66, 102, 60, 0, /* 64 to 79 */
255, 195, 153, 189, 189, 153, 195, 255, 15, 7, 13, 60, 102, 102, 102, 60, /* 80 to 95 */
60, 102, 102, 102, 60, 24, 126, 24, 48, 56, 60, 54, 52, 112, 240, 224, /* 96 to 111 */
127, 99, 127, 99, 99, 103, 230, 192, 24, 219, 126, 102, 102, 126, 219, 24, /* 112 to 127 */
64, 112, 124, 127, 124, 112, 64, 0, 1, 7, 31, 127, 31, 7, 1, 0, /* 128 to 143 */
24, 60, 126, 24, 24, 126, 60, 24, 102, 102, 102, 102, 102, 0, 102, 0, /* 144 to 159 */
63, 122, 122, 58, 10, 10, 10, 0, 30, 51, 28, 54, 54, 28, 102, 60, /* 160 to 175 */
0, 0, 0, 0, 126, 126, 126, 0, 24, 60, 126, 24, 126, 60, 24, 126, /* 176 to 191 */
24, 60, 126, 24, 24, 24, 24, 0, 24, 24, 24, 24, 126, 60, 24, 0, /* 192 to 207 */
0, 12, 14, 127, 14, 12, 0, 0, 0, 24, 56, 127, 56, 24, 0, 0, /* 208 to 223 */
0, 0, 96, 96, 96, 127, 0, 0, 0, 36, 102, 255, 102, 36, 0, 0, /* 224 to 239 */
0, 24, 60, 126, 255, 255, 0, 0, 0, 255, 255, 126, 60, 24, 0, 0, /* 240 to 255 */
0, 0, 0, 0, 0, 0, 0, 0, 24, 24, 24, 24, 24, 0, 24, 0, /* 256 to 271 */
102, 102, 102, 0, 0, 0, 0, 0, 108, 108, 254, 108, 254, 108, 108, 0, /* 272 to 287 */
16, 124, 208, 124, 22, 124, 16, 0, 0, 198, 204, 24, 48, 102, 198, 0, /* 288 to 303 */
56, 108, 56, 118, 220, 204, 118, 0, 24, 24, 48, 0, 0, 0, 0, 0, /* 304 to 319 */
12, 24, 48, 48, 48, 24, 12, 0, 48, 24, 12, 12, 12, 24, 48, 0, /* 320 to 335 */
0, 108, 56, 254, 56, 108, 0, 0, 0, 24, 24, 126, 24, 24, 0, 0, /* 336 to 351 */
0, 0, 0, 0, 0, 24, 24, 48, 0, 0, 0, 126, 0, 0, 0, 0, /* 352 to 367 */
0, 0, 0, 0, 0, 48, 48, 0, 0, 6, 12, 24, 48, 96, 192, 0, /* 368 to 383 */
60, 102, 110, 126, 118, 102, 60, 0, 12, 28, 60, 12, 12, 12, 12, 0, /* 384 to 399 */
60, 102, 6, 28, 48, 96, 126, 0, 60, 102, 6, 28, 6, 102, 60, 0, /* 400 to 415 */
28, 60, 108, 204, 254, 12, 12, 0, 126, 96, 96, 124, 6, 102, 60, 0, /* 416 to 431 */
60, 96, 96, 124, 102, 102, 60, 0, 126, 6, 6, 12, 24, 48, 48, 0, /* 432 to 447 */
60, 102, 102, 60, 102, 102, 60, 0, 60, 102, 102, 62, 6, 6, 60, 0, /* 448 to 463 */
0, 48, 48, 0, 0, 48, 48, 0, 0, 24, 24, 0, 0, 24, 24, 48, /* 464 to 479 */
12, 24, 48, 96, 48, 24, 12, 0, 0, 0, 126, 0, 0, 126, 0, 0, /* 480 to 495 */
48, 24, 12, 6, 12, 24, 48, 0, 60, 102, 6, 12, 24, 0, 24, 0, /* 496 to 511 */
60, 102, 110, 110, 108, 96, 60, 0, 24, 60, 102, 102, 126, 102, 102, 0, /* 512 to 527 */
124, 102, 102, 124, 102, 102, 124, 0, 60, 102, 96, 96, 96, 102, 60, 0, /* 528 to 543 */
124, 102, 102, 102, 102, 102, 124, 0, 126, 96, 96, 124, 96, 96, 126, 0, /* 544 to 559 */
126, 96, 96, 124, 96, 96, 96, 0, 60, 102, 96, 110, 102, 102, 60, 0, /* 560 to 575 */
102, 102, 102, 126, 102, 102, 102, 0, 60, 24, 24, 24, 24, 24, 60, 0, /* 576 to 591 */
6, 6, 6, 6, 102, 102, 60, 0, 102, 108, 120, 112, 120, 108, 102, 0, /* 592 to 607 */
96, 96, 96, 96, 96, 96, 126, 0, 198, 238, 254, 214, 198, 198, 198, 0, /* 608 to 623 */
102, 118, 126, 110, 102, 102, 102, 0, 60, 102, 102, 102, 102, 102, 60, 0, /* 624 to 639 */
124, 102, 102, 124, 96, 96, 96, 0, 60, 102, 102, 102, 102, 110, 60, 6, /* 640 to 655 */
124, 102, 102, 124, 102, 102, 102, 0, 60, 102, 96, 60, 6, 102, 60, 0, /* 656 to 671 */
126, 24, 24, 24, 24, 24, 24, 0, 102, 102, 102, 102, 102, 102, 60, 0, /* 672 to 687 */
102, 102, 102, 102, 102, 60, 24, 0, 198, 198, 198, 214, 254, 238, 198, 0, /* 688 to 703 */
102, 102, 60, 24, 60, 102, 102, 0, 102, 102, 102, 60, 24, 24, 24, 0, /* 704 to 719 */
126, 6, 12, 24, 48, 96, 126, 0, 60, 48, 48, 48, 48, 48, 60, 0, /* 720 to 735 */
0, 192, 96, 48, 24, 12, 6, 0, 60, 12, 12, 12, 12, 12, 60, 0, /* 736 to 751 */
24, 60, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, /* 752 to 767 */
24, 24, 12, 0, 0, 0, 0, 0, 0, 0, 60, 6, 62, 102, 62, 0, /* 768 to 783 */
96, 96, 96, 124, 102, 102, 124, 0, 0, 0, 60, 102, 96, 102, 60, 0, /* 784 to 799 */
6, 6, 6, 62, 102, 102, 62, 0, 0, 0, 60, 102, 126, 96, 62, 0, /* 800 to 815 */
28, 54, 48, 124, 48, 48, 48, 0, 0, 0, 62, 102, 102, 62, 6, 60, /* 816 to 831 */
96, 96, 124, 102, 102, 102, 102, 0, 24, 0, 24, 24, 24, 24, 24, 0, /* 832 to 847 */
12, 0, 12, 12, 12, 12, 108, 56, 96, 96, 102, 108, 120, 108, 102, 0, /* 848 to 863 */
48, 48, 48, 48, 48, 48, 24, 0, 0, 0, 236, 254, 214, 214, 198, 0, /* 864 to 879 */
0, 0, 124, 102, 102, 102, 102, 0, 0, 0, 60, 102, 102, 102, 60, 0, /* 880 to 895 */
0, 0, 124, 102, 102, 124, 96, 96, 0, 0, 62, 102, 102, 62, 6, 6, /* 896 to 911 */
0, 0, 124, 102, 96, 96, 96, 0, 0, 0, 62, 96, 60, 6, 124, 0, /* 912 to 927 */
48, 48, 124, 48, 48, 54, 28, 0, 0, 0, 102, 102, 102, 102, 62, 0, /* 928 to 943 */
0, 0, 102, 102, 102, 60, 24, 0, 0, 0, 198, 214, 254, 238, 68, 0, /* 944 to 959 */
0, 0, 102, 60, 24, 60, 102, 0, 0, 0, 102, 102, 102, 62, 6, 60, /* 960 to 975 */
0, 0, 126, 12, 24, 48, 126, 0, 28, 48, 48, 96, 48, 48, 28, 0, /* 976 to 991 */
24, 24, 24, 24, 24, 24, 24, 0, 56, 12, 12, 6, 12, 12, 56, 0, /* 992 to 1007 */
118, 220, 0, 0, 0, 0, 0, 0, 0, 0, 24, 60, 102, 102, 126, 0, /* 1008 to 1023 */
60, 102, 96, 96, 102, 60, 24, 48, 102, 0, 102, 102, 102, 102, 62, 0, /* 1024 to 1039 */
14, 0, 60, 102, 126, 96, 60, 0, 60, 102, 60, 6, 62, 102, 62, 0, /* 1040 to 1055 */
102, 0, 60, 6, 62, 102, 62, 0, 112, 0, 60, 6, 62, 102, 62, 0, /* 1056 to 1071 */
24, 24, 60, 6, 62, 102, 62, 0, 0, 0, 62, 96, 96, 62, 24, 48, /* 1072 to 1087 */
60, 102, 60, 102, 126, 96, 60, 0, 102, 0, 60, 102, 126, 96, 60, 0, /* 1088 to 1103 */
112, 0, 60, 102, 126, 96, 60, 0, 102, 0, 24, 24, 24, 24, 24, 0, /* 1104 to 1119 */
60, 102, 24, 24, 24, 24, 24, 0, 112, 0, 24, 24, 24, 24, 24, 0, /* 1120 to 1135 */
198, 56, 108, 198, 254, 198, 198, 0, 24, 24, 0, 60, 102, 126, 102, 0, /* 1136 to 1151 */
14, 0, 124, 96, 120, 96, 124, 0, 0, 0, 126, 26, 126, 216, 126, 0, /* 1152 to 1167 */
62, 120, 216, 222, 248, 216, 222, 0, 60, 102, 60, 102, 102, 102, 60, 0, /* 1168 to 1183 */
102, 0, 60, 102, 102, 102, 60, 0, 112, 0, 60, 102, 102, 102, 60, 0, /* 1184 to 1199 */
60, 102, 0, 102, 102, 102, 62, 0, 112, 0, 102, 102, 102, 102, 62, 0, /* 1200 to 1215 */
102, 0, 102, 102, 102, 62, 6, 60, 102, 60, 102, 102, 102, 102, 60, 0, /* 1216 to 1231 */
102, 0, 102, 102, 102, 102, 60, 0, 12, 12, 62, 96, 96, 62, 12, 12, /* 1232 to 1247 */
56, 108, 96, 240, 96, 102, 252, 0, 102, 102, 60, 24, 126, 24, 126, 24, /* 1248 to 1263 */
124, 102, 102, 124, 102, 111, 102, 99, 14, 27, 24, 60, 24, 24, 120, 48, /* 1264 to 1279 */
14, 0, 60, 6, 62, 102, 62, 0, 14, 0, 24, 24, 24, 24, 24, 0, /* 1280 to 1295 */
14, 0, 60, 102, 102, 102, 60, 0, 14, 0, 102, 102, 102, 102, 62, 0, /* 1296 to 1311 */
118, 220, 0, 124, 102, 102, 102, 0, 126, 0, 102, 118, 126, 110, 102, 0, /* 1312 to 1327 */
62, 102, 102, 62, 0, 126, 0, 0, 60, 102, 102, 60, 0, 126, 0, 0, /* 1328 to 1343 */
24, 0, 24, 48, 96, 102, 60, 0, 0, 0, 0, 126, 96, 96, 0, 0, /* 1344 to 1359 */
0, 0, 0, 126, 6, 6, 0, 0, 198, 204, 216, 62, 99, 198, 12, 31, /* 1360 to 1375 */
198, 204, 216, 54, 110, 214, 31, 6, 24, 0, 24, 24, 24, 24, 24, 0, /* 1376 to 1391 */
0, 54, 108, 216, 108, 54, 0, 0, 0, 216, 108, 54, 108, 216, 0, 0, /* 1392 to 1407 */
34, 136, 34, 136, 34, 136, 34, 136, 85, 170, 85, 170, 85, 170, 85, 170, /* 1408 to 1423 */
221, 119, 221, 119, 221, 119, 221, 119, 8, 8, 8, 8, 8, 8, 8, 8, /* 1424 to 1439 */
8, 8, 8, 8, 248, 8, 8, 8, 8, 8, 8, 248, 248, 8, 8, 8, /* 1440 to 1455 */
28, 28, 28, 28, 252, 28, 28, 28, 0, 0, 0, 0, 252, 28, 28, 28, /* 1456 to 1471 */
0, 0, 0, 248, 248, 8, 8, 8, 28, 28, 28, 252, 252, 28, 28, 28, /* 1472 to 1487 */
28, 28, 28, 28, 28, 28, 28, 28, 0, 0, 0, 252, 252, 28, 28, 28, /* 1488 to 1503 */
28, 28, 28, 252, 252, 0, 0, 0, 28, 28, 28, 28, 252, 0, 0, 0, /* 1504 to 1519 */
8, 8, 8, 248, 248, 0, 0, 0, 0, 0, 0, 0, 248, 8, 8, 8, /* 1520 to 1535 */
8, 8, 8, 8, 15, 0, 0, 0, 8, 8, 8, 8, 255, 0, 0, 0, /* 1536 to 1551 */
0, 0, 0, 0, 255, 8, 8, 8, 8, 8, 8, 8, 15, 8, 8, 8, /* 1552 to 1567 */
0, 0, 0, 0, 255, 0, 0, 0, 8, 8, 8, 8, 255, 8, 8, 8, /* 1568 to 1583 */
8, 8, 8, 15, 15, 8, 8, 8, 28, 28, 28, 28, 31, 28, 28, 28, /* 1584 to 1599 */
28, 28, 28, 31, 31, 0, 0, 0, 0, 0, 0, 31, 31, 28, 28, 28, /* 1600 to 1615 */
28, 28, 28, 255, 255, 0, 0, 0, 0, 0, 0, 255, 255, 28, 28, 28, /* 1616 to 1631 */
28, 28, 28, 31, 31, 28, 28, 28, 0, 0, 0, 255, 255, 0, 0, 0, /* 1632 to 1647 */
28, 28, 28, 255, 255, 28, 28, 28, 8, 8, 8, 255, 255, 0, 0, 0, /* 1648 to 1663 */
28, 28, 28, 28, 255, 0, 0, 0, 0, 0, 0, 255, 255, 8, 8, 8, /* 1664 to 1679 */
0, 0, 0, 0, 255, 28, 28, 28, 28, 28, 28, 28, 31, 0, 0, 0, /* 1680 to 1695 */
8, 8, 8, 15, 15, 0, 0, 0, 0, 0, 0, 15, 15, 8, 8, 8, /* 1696 to 1711 */
0, 0, 0, 0, 31, 28, 28, 28, 28, 28, 28, 28, 255, 28, 28, 28, /* 1712 to 1727 */
8, 8, 8, 255, 255, 8, 8, 8, 8, 8, 8, 8, 248, 0, 0, 0, /* 1728 to 1743 */
0, 0, 0, 0, 15, 8, 8, 8, 255, 255, 255, 255, 255, 255, 255, 255, /* 1744 to 1759 */
0, 0, 0, 0, 255, 255, 255, 255, 240, 240, 240, 240, 240, 240, 240, 240, /* 1760 to 1775 */
15, 15, 15, 15, 15, 15, 15, 15, 255, 255, 255, 255, 0, 0, 0, 0, /* 1776 to 1791 */
0, 0, 118, 204, 204, 204, 118, 0, 60, 102, 102, 124, 102, 102, 124, 96, /* 1792 to 1807 */
126, 102, 96, 96, 96, 96, 96, 0, 0, 0, 254, 108, 108, 108, 102, 0, /* 1808 to 1823 */
126, 102, 48, 24, 48, 102, 126, 0, 0, 0, 62, 108, 108, 108, 56, 0, /* 1824 to 1839 */
0, 0, 102, 102, 102, 102, 127, 192, 0, 0, 126, 216, 24, 24, 12, 0, /* 1840 to 1855 */
124, 56, 124, 214, 214, 124, 56, 124, 124, 198, 198, 254, 198, 198, 124, 0, /* 1856 to 1871 */
124, 198, 198, 198, 108, 108, 238, 0, 30, 48, 24, 60, 102, 102, 60, 0, /* 1872 to 1887 */
0, 0, 126, 219, 219, 126, 0, 0, 3, 6, 62, 107, 115, 62, 96, 192, /* 1888 to 1903 */
30, 48, 96, 126, 96, 48, 30, 0, 124, 198, 198, 198, 198, 198, 198, 0, /* 1904 to 1919 */
0, 126, 0, 126, 0, 126, 0, 0, 24, 24, 126, 24, 24, 0, 126, 0, /* 1920 to 1935 */
48, 24, 12, 24, 48, 0, 126, 0, 12, 24, 48, 24, 12, 0, 126, 0, /* 1936 to 1951 */
14, 27, 27, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 216, 216, 112, /* 1952 to 1967 */
24, 24, 0, 126, 0, 24, 24, 0, 0, 118, 220, 0, 118, 220, 0, 0, /* 1968 to 1983 */
60, 102, 102, 60, 0, 0, 0, 0, 0, 0, 0, 24, 24, 0, 0, 0, /* 1984 to 1999 */
0, 0, 0, 0, 24, 0, 0, 0, 30, 24, 24, 24, 24, 216, 120, 56, /* 2000 to 2015 */
120, 108, 108, 108, 108, 0, 0, 0, 56, 12, 24, 48, 60, 0, 0, 0, /* 2016 to 2031 */
0, 0, 60, 60, 60, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 2032 to 2047 */
};
unsigned char *gl_font8x8 = __font8x8;

994
gl/grlib.c Normal file
View file

@ -0,0 +1,994 @@
/* Framebuffer Graphics Libary for Linux, Copyright 1993 Harm Hanemaayer */
/* grlib.c Main module */
#include <stdlib.h>
#include <stdio.h>
#include <vga.h>
#include "inlstring.h" /* include inline string operations */
#include "vgagl.h"
#include "def.h"
#include "driver.h"
/* Global variables */
#ifdef DLL_CONTEXT_SHADOW
/* The current context variable is shadowed in a read-only variable for */
/* external use. */
GraphicsContext __currentcontext; /* Internal current context. */
GraphicsContext currentcontext; /* Copy for external use. */
#else
GraphicsContext currentcontext;
#endif
void (*__svgalib_nonaccel_fillbox)(int, int, int, int, int);
static int screenoffset = 0; /* Used by copy(box)toscreen. */
/* Framebuffer function pointers */
static framebufferfunctions ff8 =
{
__svgalib_driver8_setpixel,
__svgalib_driver8_getpixel,
__svgalib_driver8_hline,
__svgalib_driver8_fillbox,
__svgalib_driver8_putbox,
__svgalib_driver8_getbox,
__svgalib_driver8_putboxmask,
__svgalib_driver8_putboxpart,
__svgalib_driver8_getboxpart,
__svgalib_driver8_copybox
};
static framebufferfunctions ff16 =
{
__svgalib_driver16_setpixel,
__svgalib_driver16_getpixel,
__svgalib_driver16_hline,
__svgalib_driver16_fillbox,
__svgalib_driver16_putbox,
__svgalib_driver16_getbox,
__svgalib_driver16_putboxmask,
__svgalib_driver16_putboxpart,
__svgalib_driver16_getboxpart,
__svgalib_driver16_copybox
};
static framebufferfunctions ff24 =
{
__svgalib_driver24_setpixel,
__svgalib_driver24_getpixel,
__svgalib_driver24_hline,
__svgalib_driver24_fillbox,
__svgalib_driver24_putbox,
__svgalib_driver24_getbox,
__svgalib_driver24_putboxmask,
__svgalib_driver24_putboxpart,
__svgalib_driver24_getboxpart,
__svgalib_driver24_copybox
};
static framebufferfunctions ff32 =
{
__svgalib_driver32_setpixel,
__svgalib_driver32_getpixel,
__svgalib_driver32_hline,
__svgalib_driver32_fillbox,
__svgalib_driver32_putbox,
__svgalib_driver32_getbox,
__svgalib_driver32_putboxmask,
__svgalib_driver32_putboxpart,
__svgalib_driver32_getboxpart,
__svgalib_driver32_copybox
};
static framebufferfunctions ff8paged =
{
__svgalib_driver8p_setpixel,
__svgalib_driver8p_getpixel,
__svgalib_driver8p_hline,
__svgalib_driver8p_fillbox,
__svgalib_driver8p_putbox,
__svgalib_driver8p_getbox,
__svgalib_driver8p_putboxmask,
__svgalib_driver8p_putboxpart,
__svgalib_driver8p_getboxpart,
__svgalib_driver8p_copybox
};
static framebufferfunctions ff16paged =
{
__svgalib_driver16p_setpixel,
__svgalib_driver16p_getpixel,
__svgalib_driver16p_hline,
__svgalib_driver16p_fillbox,
__svgalib_driver16p_putbox,
__svgalib_driver16p_getbox,
__svgalib_driver16p_putboxmask,
__svgalib_driver16p_putboxpart,
__svgalib_driver16p_getboxpart,
__svgalib_driver16p_copybox
};
static framebufferfunctions ff24paged =
{
__svgalib_driver24p_setpixel,
__svgalib_driver24p_getpixel,
__svgalib_driver24p_hline,
__svgalib_driver24p_fillbox,
__svgalib_driver24p_putbox,
__svgalib_driver24p_getbox,
__svgalib_driver24p_putboxmask,
__svgalib_driver24p_putboxpart,
__svgalib_driver24p_getboxpart,
__svgalib_driver24p_copybox
};
static framebufferfunctions ff32paged =
{
__svgalib_driver32p_setpixel,
__svgalib_driver32p_getpixel,
__svgalib_driver32p_hline,
__svgalib_driver32p_fillbox,
__svgalib_driver32p_putbox,
__svgalib_driver32p_getbox,
__svgalib_driver32p_putboxmask,
__svgalib_driver32p_putboxpart,
__svgalib_driver32p_getboxpart,
__svgalib_driver32p_copybox
};
static framebufferfunctions ffplanar256 =
{
(void *) __svgalib_driverplanar256_nothing,
(void *) __svgalib_driverplanar256_nothing,
(void *) __svgalib_driverplanar256_nothing,
(void *) __svgalib_driverplanar256_nothing,
__svgalib_driverplanar256_putbox,
(void *) __svgalib_driverplanar256_nothing,
(void *) __svgalib_driverplanar256_nothing,
(void *) __svgalib_driverplanar256_nothing,
(void *) __svgalib_driverplanar256_nothing,
(void *) __svgalib_driverplanar256_nothing,
};
#if 0 /* Not yet used */
static framebufferfunctions ffplanar16 =
{
(void *) __svgalib_driverplanar16_nothing,
(void *) __svgalib_driverplanar16_nothing,
(void *) __svgalib_driverplanar16_nothing,
(void *) __svgalib_driverplanar16_nothing,
(void *) __svgalib_driverplanar16_nothing,
(void *) __svgalib_driverplanar16_nothing,
(void *) __svgalib_driverplanar16_nothing,
(void *) __svgalib_driverplanar16_nothing,
(void *) __svgalib_driverplanar16_nothing,
(void *) __svgalib_driverplanar16_nothing,
};
#endif
/* Initialization and graphics contexts */
#define SCREENSIZE(gc) ((gc).bytewidth * (gc).height)
static int colorbits(int c)
{
switch (c) {
default:
case 256:
return 8;
case 32768:
return 15;
case 65536:
return 16;
case 256 * 65536:
return 24;
}
}
int gl_setcontextvga(int m)
{
framebufferfunctions *ff;
vga_modeinfo *modeinfo;
int accelfuncs;
if (!vga_hasmode(m))
return -1;
modeinfo = vga_getmodeinfo(m);
/* Set graphics context */
WIDTH = modeinfo->width;
HEIGHT = modeinfo->height;
BYTESPERPIXEL = modeinfo->bytesperpixel;
COLORS = modeinfo->colors;
BITSPERPIXEL = colorbits(COLORS);
BYTEWIDTH = modeinfo->linewidth;
VBUF = vga_getgraphmem();
MODEFLAGS = 0;
__clip = 0;
ff = &(__currentcontext.ff);
if (modeinfo->flags & IS_MODEX) {
/* Pretend it's a regular (linear) context. */
BYTESPERPIXEL = 1;
BYTEWIDTH *= 4;
MODETYPE = CONTEXT_MODEX;
if (BYTEWIDTH * HEIGHT * 2 <= 256 * 1024)
MODEFLAGS |= MODEFLAG_PAGEFLIPPING_CAPABLE;
if (BYTEWIDTH * HEIGHT * 3 <= 256 * 1024)
MODEFLAGS |= MODEFLAG_TRIPLEBUFFERING_CAPABLE;
__currentcontext.ff = ffplanar256;
} else if (modeinfo->colors == 16) {
/* Pretend it's a regular one byte per pixel context. */
BYTESPERPIXEL = 1;
BYTEWIDTH *= 8;
MODETYPE = CONTEXT_PLANAR16;
if (BYTEWIDTH * HEIGHT <= 256 * 1024)
MODEFLAGS |= MODEFLAG_PAGEFLIPPING_CAPABLE;
if (BYTEWIDTH * HEIGHT * 3 / 2 <= 256 * 1024)
MODEFLAGS |= MODEFLAG_TRIPLEBUFFERING_CAPABLE;
} else if ((m == G320x200x256 && modeinfo->maxpixels <= 65536) ||
(modeinfo->flags & IS_LINEAR)
#if 1 /* svgalib doesn't VT-switch correctly with linear addressing. */
|| ((modeinfo->flags & CAPABLE_LINEAR)
/* Creepy. Try linear addressing only if the mode is set. */
&& vga_getcurrentmode() == m && (vga_setlinearaddressing() != -1))
#endif
) {
/* No banking. */
/* Get get the fb address in case we set linear addressing. */
VBUF = vga_getgraphmem();
MODETYPE = CONTEXT_LINEAR;
if (modeinfo->maxpixels >= WIDTH * HEIGHT * 2)
MODEFLAGS |= MODEFLAG_PAGEFLIPPING_CAPABLE;
if (modeinfo->maxpixels >= WIDTH * HEIGHT * 3)
MODEFLAGS |= MODEFLAG_TRIPLEBUFFERING_CAPABLE;
switch (BYTESPERPIXEL) {
case 1:
__currentcontext.ff = ff8;
break;
case 2:
__currentcontext.ff = ff16;
break;
case 3:
__currentcontext.ff = ff24;
break;
case 4:
__currentcontext.ff = ff32;
break;
}
if (modeinfo->flags & RGB_MISORDERED)
MODEFLAGS |= MODEFLAG_32BPP_SHIFT8;
} else {
/* Banked mode. */
MODETYPE = CONTEXT_PAGED;
if (modeinfo->maxpixels >= WIDTH * HEIGHT * 2)
MODEFLAGS |= MODEFLAG_PAGEFLIPPING_CAPABLE;
if (modeinfo->maxpixels >= WIDTH * HEIGHT * 3)
MODEFLAGS |= MODEFLAG_TRIPLEBUFFERING_CAPABLE;
if ((modeinfo->startaddressrange & 0x1ffff) == 0x10000) {
/* This hack is required for 320x200x256 page flipping */
/* on Trident, which doesn't work with bank boundary */
/* within the second page. */
MODEFLAGS |= MODEFLAG_FLIPPAGE_BANKALIGNED;
}
switch (BYTESPERPIXEL) {
case 1:
__currentcontext.ff = ff8paged;
break;
case 2:
__currentcontext.ff = ff16paged;
break;
case 3:
__currentcontext.ff = ff24paged;
break;
case 4:
__currentcontext.ff = ff32paged;
break;
}
if (modeinfo->flags & RGB_MISORDERED)
MODEFLAGS |= MODEFLAG_32BPP_SHIFT8;
}
if (vga_getcurrentmode() == m) {
accelfuncs = vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_ACCEL);
__svgalib_nonaccel_fillbox = __currentcontext.ff.driver_fillbox_func;
if (accelfuncs & ACCELFLAG_FILLBOX)
__currentcontext.ff.driver_fillbox_func =
__svgalib_driver8a_fillbox;
if (accelfuncs & ACCELFLAG_SCREENCOPY)
__currentcontext.ff.driver_copybox_func =
__svgalib_driver8a_copybox;
}
#ifdef DLL_CONTEXT_SHADOW
currentcontext = __currentcontext;
#endif
return 0;
}
int gl_setcontextvgavirtual(int m)
{
vga_modeinfo *modeinfo;
if (!vga_hasmode(m))
return -1;
modeinfo = vga_getmodeinfo(m);
/* Set graphics context */
WIDTH = modeinfo->width;
HEIGHT = modeinfo->height;
if (modeinfo->flags & IS_MODEX) {
/* Use a regular virtual screen for planar 256 color modes. */
BYTESPERPIXEL = 1;
BYTEWIDTH = modeinfo->linewidth * 4;
} else if (modeinfo->colors == 16) {
/* Use a regular one byte per pixel virtual screen for */
/* planar 16 color modes. */
BYTESPERPIXEL = 1;
BYTEWIDTH = modeinfo->linewidth * 8;
} else {
BYTESPERPIXEL = modeinfo->bytesperpixel;
BYTEWIDTH = modeinfo->linewidth;
}
COLORS = modeinfo->colors;
BITSPERPIXEL = colorbits(COLORS);
VBUF = malloc(SCREENSIZE(__currentcontext));
MODETYPE = CONTEXT_VIRTUAL;
MODEFLAGS = 0;
__clip = 0;
switch (BYTESPERPIXEL) {
case 1:
__currentcontext.ff = ff8;
break;
case 2:
__currentcontext.ff = ff16;
break;
case 3:
__currentcontext.ff = ff24;
break;
case 4:
__currentcontext.ff = ff32;
break;
}
#ifdef DLL_CONTEXT_SHADOW
currentcontext = __currentcontext;
#endif
return 0;
}
void gl_setcontextvirtual(int w, int h, int bpp, int bitspp, void *v)
{
WIDTH = w;
HEIGHT = h;
BYTESPERPIXEL = bpp;
BITSPERPIXEL = bitspp;
COLORS = 1 << bitspp;
BYTEWIDTH = WIDTH * BYTESPERPIXEL;
VBUF = v;
MODETYPE = CONTEXT_VIRTUAL;
MODEFLAGS = 0;
switch (BYTESPERPIXEL) {
case 1:
__currentcontext.ff = ff8;
break;
case 2:
__currentcontext.ff = ff16;
break;
case 3:
__currentcontext.ff = ff24;
break;
case 4:
__currentcontext.ff = ff32;
break;
}
__clip = 0;
#ifdef DLL_CONTEXT_SHADOW
currentcontext = __currentcontext;
#endif
}
GraphicsContext *
gl_allocatecontext()
{
return malloc(sizeof(GraphicsContext));
}
void gl_setcontext(GraphicsContext * gc)
{
__currentcontext = *gc;
#ifdef DLL_CONTEXT_SHADOW
currentcontext = *gc;
#endif
}
void gl_getcontext(GraphicsContext * gc)
{
*gc = __currentcontext;
}
void gl_freecontext(GraphicsContext * gc)
{
if (gc->modetype == CONTEXT_VIRTUAL)
free(gc->vbuf);
}
void gl_setcontextwidth(int w)
{
__currentcontext.width = currentcontext.width = w;
__currentcontext.bytewidth = currentcontext.bytewidth =
w * BYTESPERPIXEL;
}
void gl_setcontextheight(int h)
{
__currentcontext.height = currentcontext.height = h;
}
/* Clipping */
void gl_setclippingwindow(int x1, int y1, int x2, int y2)
{
__clip = 1;
__clipx1 = x1;
__clipy1 = y1;
__clipx2 = x2;
__clipy2 = y2;
}
void gl_enableclipping()
{
__clip = 1;
__clipx1 = 0;
__clipy1 = 0;
__clipx2 = WIDTH - 1;
__clipy2 = HEIGHT - 1;
}
void gl_disableclipping()
{
__clip = 0;
}
/* Primitive functions */
void gl_setpixel(int x, int y, int c)
{
if (__clip && outside(x, y))
return;
setpixel(x, y, c);
}
int gl_getpixel(int x, int y)
{
if (__clip && outside(x, y))
return -1;
return getpixel(x, y);
}
void gl_hline(int x1, int y, int x2, int c)
{
if (__clip) {
if (y_outside(y))
return;
clipxleft(x1);
clipxright(x2);
}
if (x1 > x2)
return;
hline(x1, y, x2, c);
}
#define ADJUSTBITMAPBOX() \
nw = w; nh = h; nx = x; ny = y; \
if (nx + nw < __clipx1 || nx > __clipx2) \
return; \
if (ny + nh < __clipy1 || ny > __clipy2) \
return; \
if (nx < __clipx1) { /* left adjust */ \
nw += nx - __clipx1; \
nx = __clipx1; \
} \
if (ny < __clipy1) { /* top adjust */ \
nh += ny - __clipy1; \
ny = __clipy1; \
} \
if (nx + nw > __clipx2) /* right adjust */ \
nw = __clipx2 - nx + 1; \
if (ny + nh > __clipy2) /* bottom adjust */ \
nh = __clipy2 - ny + 1; \
void gl_fillbox(int x, int y, int w, int h, int c)
{
if (__clip) {
if (x + w < __clipx1 || x > __clipx2)
return;
if (y + h < __clipy1 || y > __clipy2)
return;
if (x < __clipx1) {
w -= __clipx1 - x;
x = __clipx1;
}
if (y < __clipy1) {
h -= __clipy1 - y;
y = __clipy1;
}
if (x + w > __clipx2 + 1)
w = __clipx2 - x + 1;
if (y + h > __clipy2 + 1)
h = __clipy2 - y + 1;
}
if (w <= 0 || h <= 0)
return;
fillbox(x, y, w, h, c);
}
void gl_putboxpart(int x, int y, int w, int h, int ow, int oh, void *b,
int ox, int oy)
{
putboxpart(x, y, w, h, ow, oh, b, ox, oy);
}
void gl_putbox(int x, int y, int w, int h, void *b)
{
uchar *bp = b;
if (w <= 0 || h <= 0)
return;
if (__clip) {
int nx, ny, nw, nh;
ADJUSTBITMAPBOX();
if (nw <= 0 || nh <= 0)
return;
if (nw != w || nh != h) {
putboxpart(nx, ny, nw, nh, w, h, bp, nx - x, ny - y);
return;
}
}
putbox(x, y, w, h, bp, w);
}
static void emulate_putboxmask(int x, int y, int w, int h, void *b)
{
void *box;
GraphicsContext gc;
box = alloca(w * h * BYTESPERPIXEL);
gl_getbox(x, y, w, h, box); /* does clipping */
gl_getcontext(&gc); /* save context */
/* create context that is only the box */
gl_setcontextvirtual(w, h, BYTESPERPIXEL, BITSPERPIXEL, box);
gl_putboxmask(0, 0, w, h, b);
gl_setcontext(&gc); /* restore context */
gl_putbox(x, y, w, h, box);
}
void gl_putboxmask(int x, int y, int w, int h, void *b)
{
if (w <= 0 || h <= 0)
return;
if (__clip) {
if (x + w < __clipx1 || x > __clipx2)
return;
if (y + h < __clipy1 || y > __clipy2)
return;
if (x < __clipx1 || y < __clipy1
|| x + w > __clipx2 + 1 || y + h > __clipy2 + 1) {
/* clipping is not directly implemented */
emulate_putboxmask(x, y, w, h, b);
return;
}
}
if (MODETYPE == CONTEXT_PAGED)
/* paged primitive is not implemented */
emulate_putboxmask(x, y, w, h, b);
else
putboxmask(x, y, w, h, b);
}
void gl_getbox(int x, int y, int w, int h, void *b)
{
if (__clip) {
int nx, ny, nw, nh;
ADJUSTBITMAPBOX();
if (nw <= 0 || nh <= 0)
return;
if (nw != w || nh != h) {
getboxpart(nx, ny, nw, nh, w, h, b, nx - x, ny - y);
return;
}
}
getbox(x, y, w, h, b, w);
}
void gl_copybox(int x1, int y1, int w, int h, int x2, int y2)
{
/* Doesn't handle clipping. */
if (MODETYPE == CONTEXT_PAGED) {
/* Paged primitive is not implemented. */
void *box;
box = alloca(w * h * BYTESPERPIXEL);
getbox(x1, y1, w, h, box, w);
putbox(x2, y2, w, h, box, w);
return;
}
copybox(x1, y1, w, h, x2, y2);
}
/* Miscellaneous functions */
void gl_clearscreen(int c)
{
gl_fillbox(0, 0, WIDTH, HEIGHT, c);
}
int gl_rgbcolor(int r, int g, int b)
{
unsigned v;
switch (BITSPERPIXEL) {
case 8:
/* assumes RGB palette at index 0-255 */
/* bits 0-2 = blue (3 bits) */
/* 3-5 = green (3 bits) */
/* 6-7 = red (2 bits) */
return (r & 0xc0) + ((g & 0xe0) >> 2) + (b >> 5);
case 24:
case 32:
v = (r << 16) + (g << 8) + b;
if (MODEFLAGS & MODEFLAG_32BPP_SHIFT8)
return v << 8;
return v;
case 15:
return ((r & 0xf8) << 7) + ((g & 0xf8) << 2) + (b >> 3);
case 16:
return ((r & 0xf8) << 8) + ((g & 0xfc) << 3) + (b >> 3);
case 4:
/* Now this is real fun. Map to standard EGA palette. */
v = 0;
if (b >= 64)
v += 1;
if (g >= 64)
v += 2;
if (r >= 64)
v += 4;
if (b >= 192 || g >= 192 || r >= 192)
v += 8;
return v;
}
return -1;
}
void gl_setpixelrgb(int x, int y, int r, int g, int b)
{
/* Color components range from 0 to 255 */
if (__clip && outside(x, y))
return;
setpixel(x, y, gl_rgbcolor(r, g, b));
}
void gl_getpixelrgb(int x, int y, int *r, int *g, int *b)
{
unsigned c;
if (__clip && outside(x, y)) {
*r = *g = *b = -1;
return;
}
c = getpixel(x, y);
switch (BITSPERPIXEL) {
case 8:
*b = (c & (1 + 2 + 4)) << 5; /* bits 0-2 */
*g = (c & (8 + 16 + 32)) << 2; /* bits 3-5 */
*r = (c & (64 + 128)); /* bits 6-7 */
break;
case 32:
if (MODEFLAGS & MODEFLAG_32BPP_SHIFT8) {
*b = (c & 0xff00) >> 8;
*g = (c & 0xff0000) >> 16;
*r = c >> 24;
break;
}
case 24:
*b = c & 0xff;
*g = (c & 0xff00) >> 8;
*r = c >> 16;
break;
case 15:
*b = (c & (1 + 2 + 4 + 8 + 16)) << 3;
*g = (c & (32 + 64 + 128 + 256 + 512)) >> 2;
*r = (c & (1024 + 2048 + 4096 + 8192 + 16384)) >> 7;
break;
case 16:
*b = (c & (1 + 2 + 4 + 8 + 16)) << 3;
*g = (c & (32 + 64 + 128 + 256 + 512 + 1024)) >> 3;
*r = (c & (2048 + 4096 + 8192 + 16384 + 32768)) >> 8;
break;
case 4:
*b = (c & 1) * ((c & 8) ? 255 : 128);
*g = (c & 2) * ((c & 8) ? 255 : 128);
*r = (c & 4) * ((c & 8) ? 255 : 128);
break;
}
}
void gl_setdisplaystart(int x, int y)
{
vga_setdisplaystart(y * BYTEWIDTH + x * BYTESPERPIXEL);
}
/* Screen copying */
void gl_setscreenoffset(int o)
{
screenoffset = o;
}
int gl_enablepageflipping(GraphicsContext * gc)
{
if (gc->modeflags & MODEFLAG_PAGEFLIPPING_CAPABLE) {
gc->modeflags |= MODEFLAG_PAGEFLIPPING_ENABLED;
}
if (gc->modeflags & MODEFLAG_TRIPLEBUFFERING_CAPABLE) {
gc->modeflags &= ~(MODEFLAG_PAGEFLIPPING_ENABLED);
gc->modeflags |= MODEFLAG_TRIPLEBUFFERING_ENABLED;
}
gc->flippage = 0;
if (gc->modeflags & MODEFLAG_TRIPLEBUFFERING_ENABLED)
return 3;
if (gc->modeflags & MODEFLAG_PAGEFLIPPING_ENABLED)
return 2;
return 0;
}
void gl_copyscreen(GraphicsContext * gc)
{
int size;
void *svp, *dvp;
if (gc->modeflags & MODEFLAG_PAGEFLIPPING_ENABLED)
gc->flippage ^= 1;
if (gc->modeflags & MODEFLAG_TRIPLEBUFFERING_ENABLED)
gc->flippage = (gc->flippage + 1) % 3;
if (gc->modeflags & (MODEFLAG_PAGEFLIPPING_ENABLED |
MODEFLAG_TRIPLEBUFFERING_ENABLED)) {
/* Calculate screen offset in bytes. */
screenoffset = gc->bytewidth * HEIGHT * gc->flippage;
if (gc->modeflags & MODEFLAG_FLIPPAGE_BANKALIGNED)
screenoffset = ((screenoffset + 0xffff) & ~0xffff);
}
if (gc->modetype == CONTEXT_MODEX) {
vga_copytoplanar256(VBUF, BYTEWIDTH, screenoffset / 4,
gc->bytewidth / 4, WIDTH, HEIGHT);
goto end;
}
if (gc->modetype == CONTEXT_PLANAR16) {
if (WIDTH == 1024 && HEIGHT >= 512 &&
((screenoffset / 8) & 0xffff) == 0) {
/* Kludge to allow 1024x768x16 with page flipping. */
int page;
page = (screenoffset / 8) >> 16;
vga_setpage(page);
vga_copytoplanar16(VBUF, BYTEWIDTH, 0,
gc->bytewidth / 8, WIDTH, 512);
vga_setpage(page + 1);
vga_copytoplanar16(VBUF + WIDTH * 512, BYTEWIDTH,
0, gc->bytewidth / 8, WIDTH, HEIGHT - 512);
return;
}
if (WIDTH * HEIGHT >= 512 * 1024)
/* We don't handle banking. */
return;
vga_copytoplanar16(VBUF, BYTEWIDTH, screenoffset / 8,
gc->bytewidth / 8, WIDTH, HEIGHT);
goto end;
}
if (BYTESPERPIXEL == 4 && gc->bytesperpixel == 3) {
/* Special case. */
int soffset, doffset;
if (BYTEWIDTH / 4 != gc->bytewidth / 3) {
/* Even more special case for physical truecolor */
/* modes that have extra scanline padding. */
/* This has the effect of slowing down */
/* '3d' in some truecolor modes on ATI mach32. */
gl_copyboxtocontext(0, 0, WIDTH, HEIGHT, gc, 0, 0);
goto end;
}
soffset = 0;
doffset = screenoffset;
size = WIDTH * HEIGHT;
while (soffset / 4 < size) {
int schunk, dchunk;
int count;
schunk = __svgalib_driver_setread(&__currentcontext, soffset, &svp);
dchunk = __svgalib_driver_setwrite(gc, doffset, &dvp);
if (dchunk == 1) {
/* One byte left in segment. */
int pix;
pix = *(unsigned *) svp; /* 32-bit pixel */
*(unsigned char *) dvp = pix;
dchunk = __svgalib_driver_setwrite(gc, doffset + 1, &dvp);
*(unsigned short *) dvp = pix >> 8;
count = 1; /* 1 pixel handled. */
} else if (dchunk == 2) {
/* Two bytes left. */
int pix;
pix = *(unsigned *) svp; /* 32-bit pixel */
*(unsigned short *) dvp = pix;
dchunk = __svgalib_driver_setwrite(gc, doffset + 2, &dvp);
*(unsigned char *) dvp = pix >> 16;
count = 1; /* 1 pixel handled. */
} else {
count = min(min(schunk / 4, dchunk / 3),
size - (soffset / 4));
__svgalib_memcpy4to3(dvp, svp, count);
}
soffset += count * 4;
doffset += count * 3;
}
goto end;
}
if (BYTESPERPIXEL == 4 && gc->bytesperpixel == 4 &&
(gc->modeflags & MODEFLAG_32BPP_SHIFT8)) {
int soffset = 0;
int doffset = screenoffset;
size = SCREENSIZE(__currentcontext);
while (soffset < size) {
int schunk, dchunk;
int count;
schunk = __svgalib_driver_setread(&__currentcontext, soffset, &svp);
dchunk = __svgalib_driver_setwrite(gc, doffset, &dvp);
count = min(min(schunk, dchunk), (size - soffset));
__svgalib_memcpy32shift8(dvp, svp, count / 4);
soffset += count;
doffset += count;
}
} else {
int soffset = 0;
int doffset = screenoffset;
size = SCREENSIZE(__currentcontext);
while (soffset < size) {
int schunk, dchunk;
int count;
schunk = __svgalib_driver_setread(&__currentcontext, soffset, &svp);
dchunk = __svgalib_driver_setwrite(gc, doffset, &dvp);
count = min(min(schunk, dchunk), (size - soffset));
__memcpy(dvp, svp, count);
soffset += count;
doffset += count;
}
}
end:
if (gc->modeflags & (MODEFLAG_PAGEFLIPPING_ENABLED |
MODEFLAG_TRIPLEBUFFERING_ENABLED)) {
GraphicsContext save;
/* setdisplaystart will use BYTEWIDTH of the virtual screen, */
/* which is what we want since vga_setdisplaystart is */
/* defined in terms of pixel offset (except for hicolor */
/* modes, which are defined in terms of bytes). */
gl_getcontext(&save);
gl_setcontext(gc);
if (gc->modeflags & MODEFLAG_FLIPPAGE_BANKALIGNED)
vga_setdisplaystart(screenoffset);
else
gl_setdisplaystart(0, gc->height * gc->flippage);
gl_setcontext(&save);
/* For page flipping, it might be appropriate to add a */
/* waitverticalretrace here. */
}
screenoffset = 0;
}
void gl_copyboxtocontext(int x1, int y1, int w, int h, GraphicsContext * gc,
int x2, int y2)
{
/* This is now reasonably efficient if clipping is not enabled. */
void *buf;
GraphicsContext save;
gl_getcontext(&save);
if ((MODETYPE == CONTEXT_LINEAR || MODETYPE == CONTEXT_VIRTUAL) &&
(BYTESPERPIXEL == gc->bytesperpixel) &&
!__clip && !gc->clip) {
#ifdef DLL_CONTEXT_SHADOW
__currentcontext = *gc;
#else
gl_setcontext(gc);
#endif
/*
* Note: Using save.bytewidth / BYTESPERPIXEL is probably not an optimal hack here.
* it would be better to transfer save.bytewidth to putbox as it is what is really
* used there. However, putbox is used all over interpreting the last entry as a
* pixel count, so we keep it this way to avoid problems if some other place not
* updated by accident.
*/
putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h, save.vbuf +
y1 * save.bytewidth + x1 * BYTESPERPIXEL,
save.bytewidth / BYTESPERPIXEL);
goto end;
}
buf = alloca(w * h * BYTESPERPIXEL);
gl_getbox(x1, y1, w, h, buf);
#ifdef DLL_CONTEXT_SHADOW
__currentcontext = *gc;
#else
gl_setcontext(gc);
#endif
if (save.bytesperpixel == 4 && gc->bytesperpixel == 3) {
/* Special case conversion from 32-bit virtual screen to */
/* 24-bit truecolor framebuffer. */
if (gc->modetype == CONTEXT_PAGED || gc->clip) {
/* For paged modes or clipping, use another buffer. */
void *buf2;
buf2 = alloca(w * h * 3);
__svgalib_memcpy4to3(buf2, buf, w * h);
gl_putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h,
buf2);
} else
/* No clipping, linear. */
__svgalib_driver24_putbox32(x2, y2, w, h, buf, w);
} else /* Contexts assumed to have same pixel size. */
gl_putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h, buf);
end:
#ifdef DLL_CONTEXT_SHADOW
__currentcontext = save;
#else
gl_setcontext(&save);
#endif
}
void gl_copyboxfromcontext(GraphicsContext * gc, int x1, int y1, int w, int h,
int x2, int y2)
{
void *buf;
GraphicsContext save;
if ((gc->modetype == CONTEXT_LINEAR || gc->modetype == CONTEXT_VIRTUAL) &&
(BYTESPERPIXEL == gc->bytesperpixel) &&
!__clip && !gc->clip) {
/*
* see above on gc->bytewidth / BYTESPERPIXEL.
*/
putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h, gc->vbuf +
y1 * gc->bytewidth + x1 * BYTESPERPIXEL,
gc->bytewidth / BYTESPERPIXEL);
return;
}
gl_getcontext(&save);
#ifdef DLL_CONTEXT_SHADOW
__currentcontext = *gc;
#else
gl_setcontext(gc);
#endif
buf = alloca(w * h * BYTESPERPIXEL);
gl_getbox(x1, y1, w, h, buf);
#ifdef DLL_CONTEXT_SHADOW
__currentcontext = save;
#else
gl_setcontext(&save);
#endif
if (gc->bytesperpixel == 4 && save.bytesperpixel == 3) {
/* Special case conversion from 32-bit virtual screen to */
/* 24-bit truecolor framebuffer. */
if (save.modetype == CONTEXT_PAGED || save.clip) {
/* For paged modes or clipping, use another buffer. */
void *buf2;
buf2 = alloca(w * h * 3);
__svgalib_memcpy4to3(buf2, buf, w * h);
gl_putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h,
buf2);
} else
/* No clipping, linear. */
__svgalib_driver24_putbox32(x2, y2, w, h, buf, w);
} else /* Contexts assumed to have same pixel size. */
gl_putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h, buf);
}

344
gl/inlstring.h Normal file
View file

@ -0,0 +1,344 @@
/* Based on functions in linux/string.h */
#include <sys/types.h> /* for size_t */
#include "../src/ppcmemset.h"
#if defined (NO_ASSEMBLY)
#define __memcpy(dst,src,n) memcpy((dst),(src),(n))
#define __memcpy_conventional(dst,src,n) memcpy((dst),(src),(n))
#define __memcpyb(dst,src,n) memcpy((dst),(src),(n))
#define __memsetb(dst,c,n) memset((dst),(c),(n))
#define __memset(dst,c,n) memset((dst),(c),(n))
static inline void *__memset4(void *s, int c, size_t count) {
int i, *p=s;
for(i=0;i<count;i++)*p++=c;
return s;
}
static inline void *__memset2(void *s, short c, size_t count) {
short *p=s;
int i;
for(i=0;i<count;i++)*p++=c;
return s;
}
static inline void *__memset3(void *s, int c, size_t count) {
unsigned char *p=s;
int i;
for(i=0;i<count;i++) {
*p++=c&0xff;
*p++=(c>>8)&0xff;
*p++=(c>>16)&0xff;
}
return s;
}
#else
static inline void *
__memcpy_conventional(void *to, const void *from, size_t n)
{
int dummy1;
long dummy2, dummy3;
__asm__ __volatile__("cld\n\t"
"cmpl $0,%%edx\n\t"
"jle 2f\n\t"
"movl %%edi,%%ecx\n\t"
"andl $1,%%ecx\n\t"
"subl %%ecx,%%edx\n\t"
"rep ; movsb\n\t" /* 16-bit align destination */
"movl %%edx,%%ecx\n\t"
"shrl $2,%%ecx\n\t"
"jz 3f\n\t"
"rep ; movsl\n\t"
"3:\n\t"
"testb $1,%%dl\n\t"
"je 1f\n\t"
"movsb\n"
"1:\ttestb $2,%%dl\n\t"
"je 2f\n\t"
"movsw\n"
"2:\n"
: "=d"(dummy1), "=D"(dummy2), "=S"(dummy3) /* fake output */
: "0"(n), "1"((long) to), "2"((long) from)
: "cx"/***rjr***, "dx", "di", "si"***/
);
return (to);
}
static inline void *
__memcpyb(void *to, const void *from, size_t n)
{
int dummy1;
long dummy2, dummy3;
__asm__ __volatile__("cld\n\t"
"rep ; movsb\n\t"
: "=c"(dummy1), "=D"(dummy2), "=S"(dummy3) /* fake output */
: "0"(n), "1"((long) to), "2"((long) from)
/***rjr***: "cx", "di", "si"***/
);
return (to);
}
static inline void *
__memsetb(void *s, char c, size_t count)
{
__asm__("cld\n\t"
"rep\n\t"
"stosb"
: : "a"(c), "D"(s), "c"(count)
: "cx", "di");
return s;
}
static inline void *
__memset4(void *s, unsigned c, size_t count)
{
long dummy1;
int dummy2;
__asm__ __volatile__("cld\n\t"
"rep\n\t"
"stosl"
: "=D"(dummy1), "=c"(dummy2) /* fake outputs */
: "a"(c), "0"(s), "1"(count)
/***rjr***: "cx", "di"***/
);
return s;
}
static inline void *
__memset(void *s, char c, size_t count)
{
int dummy1;
long dummy2;
int dummy3;
__asm__ __volatile__(
"cld\n\t"
"cmpl $12,%%edx\n\t"
"jl 1f\n\t" /* if (count >= 12) */
"movzbl %%al,%%eax\n\t"
"movl %%eax,%%ecx\n\t"
"shll $8,%%ecx\n\t" /* c |= c << 8 */
"orl %%ecx,%%eax\n\t"
"movl %%eax,%%ecx\n\t"
"shll $16,%%ecx\n\t" /* c |= c << 16 */
"orl %%ecx,%%eax\n\t"
"movl %%edx,%%ecx\n\t"
"negl %%ecx\n\t"
"andl $3,%%ecx\n\t" /* (-s % 4) */
"subl %%ecx,%%edx\n\t" /* count -= (-s % 4) */
"rep ; stosb\n\t" /* align to longword boundary */
"movl %%edx,%%ecx\n\t"
"shrl $2,%%ecx\n\t"
"rep ; stosl\n\t" /* fill longwords */
"andl $3,%%edx\n" /* fill last few bytes */
"1:\tmovl %%edx,%%ecx\n\t" /* <= 12 entry point */
"rep ; stosb\n\t"
: "=a"(dummy1), "=D"(dummy2), "=d"(dummy3) /* fake outputs */
: "0"(c), "1"(s), "2"(count)
: /***rjr***"ax",*/ "cx"/*, "dx", "di"*/
);
return s;
}
static inline void *
__memset2(void *s, short c, size_t count)
/* count is in 16-bit pixels */
/* s is assumed to be 16-bit aligned */
{
int dummy1;
long dummy2;
int dummy3;
__asm__ __volatile__(
"cld\n\t"
"cmpl $12,%%edx\n\t"
"jl 1f\n\t" /* if (count >= 12) */
"movzwl %%ax,%%eax\n\t"
"movl %%eax,%%ecx\n\t"
"shll $16,%%ecx\n\t" /* c |= c << 16 */
"orl %%ecx,%%eax\n\t"
"movl %%edi,%%ecx\n\t"
"andl $2,%%ecx\n\t" /* s & 2 */
"jz 2f\n\t"
"decl %%edx\n\t" /* count -= 1 */
"movw %%ax,(%%edi)\n\t" /* align to longword boundary */
"addl $2,%%edi\n\t"
"2:\n\t"
"movl %%edx,%%ecx\n\t"
"shrl $1,%%ecx\n\t"
"rep ; stosl\n\t" /* fill longwords */
"andl $1,%%edx\n" /* one 16-bit word left? */
"jz 3f\n\t" /* no, finished */
"1:\tmovl %%edx,%%ecx\n\t" /* <= 12 entry point */
"rep ; stosw\n\t"
"3:\n\t"
: "=a"(dummy1), "=D"(dummy2), "=d"(dummy3) /* fake outputs */
: "0"(c), "1"(s), "2"(count)
: /***rjr***"ax",*/ "cx"/*, "dx", "di"*/
);
return s;
}
static inline void *
__memset3(void *s, int c, size_t count)
/* count is in 24-bit pixels (3 bytes per pixel) */
{
int dummy1;
long dummy2;
int dummy3;
__asm__ __volatile__(
"cmpl $8,%%edx\n\t"
/* "jmp 2f\n\t" *//* debug */
"jl 2f\n\t"
"movl %%eax,%%esi\n\t" /* esi = (low) BGR0 (high) */
"shll $24,%%eax\n\t" /* eax = 000B */
"orl %%eax,%%esi\n\t" /* esi = BGRB */
"movl %%esi,%%eax\n\t"
"shrl $8,%%eax\n\t" /* eax = GRB0 */
"movl %%eax,%%ecx\n\t"
"shll $24,%%ecx\n\t" /* ecx = 000G */
"orl %%ecx,%%eax\n\t" /* eax = GRBG */
"movl %%esi,%%ecx\n\t"
"shll $8,%%ecx\n\t" /* ecx = 0BGR */
"movb %%ah,%%cl\n\t" /* ecx = RBGR */
"cmpl $16,%%edx\n\t"
"jl 1f\n\t"
"jmp 5f\n\t"
".align 4,0x90\n\t"
"5:\n\t" /* loop unrolling */
"movl %%esi,(%%edi)\n\t" /* write BGRB */
"movl %%eax,4(%%edi)\n\t" /* write GRBG */
"movl %%ecx,8(%%edi)\n\t" /* write RBGR */
"movl %%esi,12(%%edi)\n\t"
"movl %%eax,16(%%edi)\n\t"
"movl %%ecx,20(%%edi)\n\t"
"movl %%esi,24(%%edi)\n\t"
"movl %%eax,28(%%edi)\n\t"
"movl %%ecx,32(%%edi)\n\t"
"movl %%esi,36(%%edi)\n\t"
"subl $16,%%edx\n\t" /* blend end-of-loop instr. */
"movl %%eax,40(%%edi)\n\t"
"movl %%ecx,44(%%edi)\n\t"
"addl $48,%%edi\n\t"
"cmpl $16,%%edx\n\t"
"jge 5b\n\t"
"andl %%edx,%%edx\n\t"
"jz 4f\n\t" /* finished */
"cmpl $4,%%edx\n\t"
"jl 2f\n\t" /* less than 4 pixels left */
"jmp 1f\n\t"
".align 4,0x90\n\t"
"1:\n\t"
"movl %%esi,(%%edi)\n\t" /* write BGRB */
"movl %%eax,4(%%edi)\n\t" /* write GRBG */
"movl %%ecx,8(%%edi)\n\t" /* write RBGR */
"addl $12,%%edi\n\t"
"subl $4,%%edx\n\t"
"cmpl $4,%%edx\n\t"
"jge 1b\n\t"
"2:\n\t"
"cmpl $0,%%edx\n\t" /* none left? */
"jle 4f\n\t" /* finished */
"mov %%ecx,%%eax\n\t"
"shrl $8,%%ecx\n\t" /* R in cl */
"3:\n\t" /* write last few pixels */
"movw %%cx,(%%edi)\n\t" /* write BG */
"movb %%al,2(%%edi)\n\t" /* write R */
"addl $3,%%edi\n\t"
"decl %%edx\n\t"
"jnz 3b\n\t"
"4:\n\t"
: "=a"(dummy1), "=D"(dummy2), "=d"(dummy3) /* fake outputs */
: "0"(c), "1"(s), "2"(count)
: /***rjr***"ax",*/ "cx", /*"dx",*/ "si"/*, "di"*/
);
return s;
}
/* Functions for which arguments must be passed in %ebx, %edx, and %ecx. */
#if 0 /* Why declare 'em? Just confuses the compiler and can't be called from C
anyway */
extern __memcpyasm_regargs(); /* nu_bytes >= 3 */
extern __memcpyasm_regargs_aligned(); /* nu_bytes >= 32 */
#endif
/* Always 32-bit align destination, even for a small number of bytes. */
static inline void *
__memcpy_aligndest(void *dest, const void *src, int n)
{
__asm__ __volatile__("cmpl $3, %%ecx\n\t"
"ja 1f\n\t"
"call * __memcpy_jumptable (, %%ecx, 4)\n\t"
"jmp 2f\n\t"
"1:call __memcpyasm_regargs\n\t"
"2:":
:"S"(dest), "d"(src), "c"(n)
:"ax", "0", "1", "2");
return dest;
}
/* Optimized version for 32-bit aligned destination. */
static inline void *
__memcpy_destaligned(void *dest, const void *src, int n)
{
__asm__ __volatile__("cmpl $32, %%ecx\n\t"
"ja 1f\n\t"
"call * __memcpy_jumptable (, %%ecx, 4)\n\t"
"jmp 2f\n\t"
"1:call __memcpyasm_regargs_aligned\n\t"
"2:\n\t":
:"S"(dest), "d"(src), "c"(n)
:"ax", "0", "1", "2");
return dest;
}
/* Balanced inline memcpy; 32-bit align destination if nu_bytes >= 20. */
static inline void *
__memcpy_balanced(void *dest, const void *src, int n)
{
__asm__ __volatile__("cmpl $19, %%ecx\n\t"
"ja 1f\n\t"
"call * __memcpy_jumptable (, %%ecx, 4)\n\t"
"jmp 2f\n\t"
"1:call __memcpyasm_regargs\n\t"
"2:\n\t"
:
:"S"((long) dest), "d"((long) src), "c"((long) n)
:"ax", "0", "1", "2");
return dest;
}
#define __memcpy __memcpy_conventional
#endif
/* Functions defined in mem.S or mem.c */
extern void __svgalib_memcpy4to3(void *dest, void *src, int n);
extern void __svgalib_memcpy32shift8(void *dest, void *src, int n);

546
gl/line.c Normal file
View file

@ -0,0 +1,546 @@
/* Framebuffer Graphics Libary for Linux, Copyright 1993 Harm Hanemaayer */
/* line.c Line drawing */
#include <stdlib.h>
#ifndef DO_NOT_USE_VGALIB
#include <vga.h>
#endif
#include "inlstring.h" /* include inline string operations */
#include "vgagl.h"
#include "def.h"
#include "driver.h"
static inline int muldiv64(int m1, int m2, int d)
{
return (float) m1 * (float) m2 / ((float) d);
}
#ifdef NO_ASSEMBLY
static inline int gl_regioncode (int x, int y)
{
int result = 0;
if (x < __clipx1)
result |= 1;
else if (x > __clipx2)
result |= 2;
if (y < __clipy1)
result |= 4;
else if (y > __clipy2)
result |= 8;
return result;
}
#else
#define INC_IF_NEG(y, result) \
{ \
__asm__("btl $31,%1\n\t" \
"adcl $0,%0" \
: "=r" ((int) result) \
: "rm" ((int) (y)), "0" ((int) result) \
); \
}
static inline int gl_regioncode (int x, int y)
{
int dx1, dx2, dy1, dy2;
int result;
result = 0;
dy2 = __clipy2 - y;
INC_IF_NEG (dy2, result);
result <<= 1;
dy1 = y - __clipy1;
INC_IF_NEG (dy1, result);
result <<= 1;
dx2 = __clipx2 - x;
INC_IF_NEG (dx2, result);
result <<= 1;
dx1 = x - __clipx1;
INC_IF_NEG (dx1, result);
return result;
}
#endif /* ! NO_ASSEMBLY */
#define line_start_paged(s) \
fp = y * bytesperrow + x * s; \
vga_setpage (fpp = (fp >> 16)); \
fp &= 0xFFFF;
#define line_start_linear(s) \
vp = (unsigned char *)VBUF + y * bytesperrow + x * s;
#define line_loop_paged_a(m,i,u,v) \
{ \
int d = ay - (ax >> 1); \
if ((x = abs (dx))) \
do { \
i; \
if (d m 0) { \
fp v; \
d -= ax; \
} \
fp u; \
d += ay; \
if (fp & 0xFFFF0000) { /* has it cross a page boundary ? */ \
fpp += fp >> 16; \
vga_setpage (fpp); \
} \
fp &= 0x0000FFFF; \
} while (--x); \
}
#define line_loop_linear_a(m,i,u,v) \
{ \
int d = ay - (ax >> 1); \
if ((x = abs (dx))) \
do { \
i; \
if (d m 0) { \
vp v; \
d -= ax; \
} \
vp u; \
d += ay; \
} while (--x); \
}
#define line_loop_paged_b(m,i,u,v) \
{ \
int d = ax - (ay >> 1); \
if ((y = abs (dy))) \
do { \
i; \
if (d m 0) { \
fp u; \
d -= ay; \
} \
fp v; \
d += ax; \
if (fp & 0xFFFF0000) { \
fpp += fp >> 16; \
vga_setpage (fpp); \
} \
fp &= 0x0000FFFF; \
} while (--y); \
}
#define line_loop_linear_b(m,i,u,v) \
{ \
int d = ax - (ay >> 1); \
if ((y = abs (dy))) \
do { \
i; \
if (d m 0) { \
vp u; \
d -= ay; \
} \
vp v; \
d += ax; \
} while (--y); \
}
/* Partly based on the work which was partly based on vgalib by Tommy Frandsen */
/* This is a lot faster now that setpixel is inlined */
void gl_line (int x1, int y1, int x2, int y2, int c)
{
int dx, dy, ax, ay, sx, sy, x, y;
int bytesperrow;
unsigned char *vp = NULL;
if (__clip)
/* Cohen & Sutherland algorithm */
for (;;) {
int r1 = gl_regioncode (x1, y1);
int r2 = gl_regioncode (x2, y2);
if (!(r1 | r2))
break; /* completely inside */
if (r1 & r2)
return; /* completely outside */
if (r1 == 0) {
swap (x1, x2); /* make sure first */
swap (y1, y2); /* point is outside */
r1 = r2;
}
if (r1 & 1) { /* left */
y1 += muldiv64 (__clipx1 - x1, y2 - y1, x2 - x1);
x1 = __clipx1;
} else if (r1 & 2) { /* right */
y1 += muldiv64 (__clipx2 - x1, y2 - y1, x2 - x1);
x1 = __clipx2;
} else if (r1 & 4) { /* top */
x1 += muldiv64 (__clipy1 - y1, x2 - x1, y2 - y1);
y1 = __clipy1;
} else if (r1 & 8) { /* bottom */
x1 += muldiv64 (__clipy2 - y1, x2 - x1, y2 - y1);
y1 = __clipy2;
}
}
dx = x2 - x1;
dy = y2 - y1;
ax = abs (dx) << 1;
ay = abs (dy) << 1;
sx = (dx >= 0) ? 1 : -1;
sy = (dy >= 0) ? 1 : -1;
x = x1;
y = y1;
#define insert_pixel_1 *((unsigned char *) vp) = c;
#define insert_pixel_2 *((unsigned short *) vp) = c;
#define insert_pixel_3 *((unsigned char *) vp) = c; \
*((unsigned char *) (vp + 1)) = (c>>8); \
*((unsigned char *) (vp + 2)) = (c>>16);
#define insert_pixel_4 *((unsigned int *) vp) = c;
bytesperrow = BYTEWIDTH;
if (MODETYPE == CONTEXT_VIRTUAL || MODETYPE == CONTEXT_LINEAR) {
switch BYTESPERPIXEL {
case 1:
line_start_linear(1);
if (ax > ay) {
if(sx > 0) {
line_loop_linear_a(>=,insert_pixel_1,++,+=bytesperrow*sy);
} else {
line_loop_linear_a(>,insert_pixel_1,--,+=bytesperrow*sy);
}
} else {
if(sy > 0) {
line_loop_linear_b(>=,insert_pixel_1,+=sx,+=bytesperrow);
} else {
line_loop_linear_b(>,insert_pixel_1,+=sx,-=bytesperrow);
}
}
insert_pixel_1;
break;
case 2:
line_start_linear(2);
if (ax > ay) {
if(sx > 0) {
line_loop_linear_a(>=,insert_pixel_2,+=2,+=bytesperrow*sy);
} else {
line_loop_linear_a(>,insert_pixel_2,-=2,+=bytesperrow*sy);
}
} else {
sx <<= 1;
if(sy > 0) {
line_loop_linear_b(>=,insert_pixel_2,+=sx,+=bytesperrow);
} else {
line_loop_linear_b(>,insert_pixel_2,+=sx,-=bytesperrow);
}
}
insert_pixel_2;
break;
case 3:
line_start_linear(3);
if (ax > ay) {
if(sx > 0) {
line_loop_linear_a(>=,insert_pixel_3,+=3,+=bytesperrow*sy);
} else {
line_loop_linear_a(>,insert_pixel_3,-=3,+=bytesperrow*sy);
}
} else {
sx *= 3;
if(sy > 0) {
line_loop_linear_b(>=,insert_pixel_3,+=sx,+=bytesperrow);
} else {
line_loop_linear_b(>,insert_pixel_3,+=sx,-=bytesperrow);
}
}
insert_pixel_3;
break;
case 4:
line_start_linear(4);
if (ax > ay) {
if(sx > 0) {
line_loop_linear_a(>=,insert_pixel_4,+=4,+=bytesperrow*sy);
} else {
line_loop_linear_a(>,insert_pixel_4,-=4,+=bytesperrow*sy);
}
} else {
sx <<= 2;
if(sy > 0) {
line_loop_linear_b(>=,insert_pixel_4,+=sx,+=bytesperrow);
} else {
line_loop_linear_b(>,insert_pixel_4,+=sx,-=bytesperrow);
}
}
insert_pixel_4;
break;
}
}
#ifndef DO_NOT_USE_VGALIB
#undef insert_pixel_1
#undef insert_pixel_2
#undef insert_pixel_3
#undef insert_pixel_4
#define insert_pixel_1 *((unsigned char *) (vp + fp)) = c;
#define insert_pixel_2 *((unsigned short *) (vp + fp)) = c;
#define insert_pixel_3 *((unsigned char *) (vp + fp)) = c; \
*((unsigned char *) (vp + fp + 1)) = (c>>8); \
*((unsigned char *) (vp + fp + 2)) = (c>>16);
#define insert_pixel_4 *((unsigned int *) (vp + fp)) = c;
if (MODETYPE == CONTEXT_PAGED) {
vp = (unsigned char *)VBUF;
switch BYTESPERPIXEL {
int fpp;
int fp;
case 1:
line_start_paged(1);
if (ax > ay) {
if(sx > 0) {
line_loop_paged_a(>=,insert_pixel_1,++,+=bytesperrow*sy);
} else {
line_loop_paged_a(>,insert_pixel_1,--,+=bytesperrow*sy);
}
} else {
if(sy > 0) {
line_loop_paged_b(>=,insert_pixel_1,+=sx,+=bytesperrow);
} else {
line_loop_paged_b(>,insert_pixel_1,+=sx,-=bytesperrow);
}
}
insert_pixel_1;
break;
case 2:
line_start_paged(2);
if (ax > ay) {
if(sx > 0) {
line_loop_paged_a(>=,insert_pixel_2,+=2,+=bytesperrow*sy);
} else {
line_loop_paged_a(>,insert_pixel_2,-=2,+=bytesperrow*sy);
}
} else {
sx <<= 1;
if(sy > 0) {
line_loop_paged_b(>=,insert_pixel_2,+=sx,+=bytesperrow);
} else {
line_loop_paged_b(>,insert_pixel_2,+=sx,-=bytesperrow);
}
}
insert_pixel_2;
break;
case 3:
line_start_paged(3);
if (ax > ay) {
if(sx > 0) {
line_loop_paged_a(>=,insert_pixel_3,+=3,+=bytesperrow*sy);
} else {
line_loop_paged_a(>,insert_pixel_3,-=3,+=bytesperrow*sy);
}
} else {
sx *= 3;
if(sy > 0) {
line_loop_paged_b(>=,insert_pixel_3,+=sx,+=bytesperrow);
} else {
line_loop_paged_b(>,insert_pixel_3,+=sx,-=bytesperrow);
}
}
insert_pixel_3;
break;
case 4:
line_start_paged(4);
if (ax > ay) {
if(sx > 0) {
line_loop_paged_a(>=,insert_pixel_4,+=4,+=bytesperrow*sy);
} else {
line_loop_paged_a(>,insert_pixel_4,-=4,+=bytesperrow*sy);
}
} else {
sx <<= 2;
if(sy > 0) {
line_loop_paged_b(>=,insert_pixel_4,+=sx,+=bytesperrow);
} else {
line_loop_paged_b(>,insert_pixel_4,+=sx,-=bytesperrow);
}
}
insert_pixel_4;
break;
}
}
if (!vp) {
if (ax > ay) {
int d = ay - (ax >> 1);
while (x != x2) {
setpixel (x, y, c);
if (d > 0 || (d == 0 && sx == 1)) {
y += sy;
d -= ax;
}
x += sx;
d += ay;
}
} else {
int d = ax - (ay >> 1);
while (y != y2) {
setpixel (x, y, c);
if (d > 0 || (d == 0 && sy == 1)) {
x += sx;
d -= ay;
}
y += sy;
d += ax;
}
}
setpixel (x, y, c);
}
#endif
}
static void gl_setcirclepixels(int x, int y, int sx, int sy, int c)
{
if (__clip) {
int z = max(x, y);
if (sx - z < __clipx1 || sx + z > __clipx2
|| sy - z < __clipy1 || sy + z > __clipy2) {
/* use setpixel clipping */
gl_setpixel(sx + x, sy + y, c);
gl_setpixel(sx - x, sy + y, c);
gl_setpixel(sx + x, sy - y, c);
gl_setpixel(sx - x, sy - y, c);
gl_setpixel(sx + y, sy + x, c);
gl_setpixel(sx - y, sy + x, c);
gl_setpixel(sx + y, sy - x, c);
gl_setpixel(sx - y, sy - x, c);
return;
}
}
setpixel(sx + x, sy + y, c);
setpixel(sx - x, sy + y, c);
setpixel(sx + x, sy - y, c);
setpixel(sx - x, sy - y, c);
setpixel(sx + y, sy + x, c);
setpixel(sx - y, sy + x, c);
setpixel(sx + y, sy - x, c);
setpixel(sx - y, sy - x, c);
}
void gl_circle(int sx, int sy, int r, int c)
{
int x, y, d;
if (r < 1) {
gl_setpixel(sx, sy, c);
return;
}
if (__clip)
if (sx + r < __clipx1 || sx - r > __clipx2
|| sy + r < __clipy1 || sy - r > __clipy2)
return;
x = 0;
y = r;
d = 1 - r;
gl_setcirclepixels(x, y, sx, sy, c);
while (x < y) {
if (d < 0)
d += x * 2 + 3;
else {
d += x * 2 - y * 2 + 5;
y--;
}
x++;
gl_setcirclepixels(x, y, sx, sy, c);
}
}
void gl_fillcircle(int sx, int sy, int r, int c)
{
int x = 0,
y = r,
d = 1 - r;
if (r < 1) {
gl_setpixel(sx, sy, c);
return;
}
if (__clip)
if (sx + r < __clipx1 || sx - r > __clipx2
|| sy + r < __clipy1 || sy - r > __clipy2)
return;
gl_hline(sx - x, sy + y, sx + x, c);
gl_hline(sx - x, sy - y, sx + x, c);
gl_hline(sx - y, sy + x, sx + y, c);
gl_hline(sx - y, sy - x, sx + y, c);
while (x < y)
{
if (d < 0)
{
d += x * 2 + 3;
} else {
d += x * 2 - y * 2 + 5;
y--;
}
x++;
gl_hline(sx - x, sy + y, sx + x, c);
gl_hline(sx - x, sy - y, sx + x, c);
gl_hline(sx - y, sy + x, sx + y, c);
gl_hline(sx - y, sy - x, sx + y, c);
}
}
void gl_bcircle(int sx, int sy, int r, int c, int fill)
{
int x = 0,
y = r,
d = 2 * (1 - r);
if (r < 1) {
gl_setpixel(sx, sy, c);
return;
}
if (__clip)
if (sx + r < __clipx1 || sx - r > __clipx2
|| sy + r < __clipy1 || sy - r > __clipy2)
return;
while (y >= 0)
{
if (fill == 0)
{
gl_setpixel(sx + x, sy + y, c);
gl_setpixel(sx + x, sy - y, c);
gl_setpixel(sx - x, sy + y, c);
gl_setpixel(sx - x, sy - y, c);
} else {
gl_hline(sx - x, sy + y, sx + x, c);
gl_hline(sx - x, sy - y, sx + x, c);
}
if ((d + y) > 0)
{
y--;
d -= (2 * y * WIDTH / HEIGHT) - 1;
}
if (x > d)
{
x++;
d += (2 * x) + 1;
}
}
}

481
gl/mem.S Normal file
View file

@ -0,0 +1,481 @@
#define __ASSEMBLY__
#include <linux/linkage.h>
#ifndef SYMBOL_NAME
#define SYMBOL_NAME(name) _ ## name
#endif
#ifndef ENTRY
#define ENTRY(name) .align 4; .globl _ ## name ## ; _ ## name ## :
#endif
.file "mem.S"
/* This file contains unrolled memcpy functions. */
/* Prototype: memcpy4to3( void *dest, void *src, int n ) */
/* Copies pixels from 4-byte-per-pixel screen to 3-byte-per-pixel screen,
*/
/* discarding the last byte of each pixel. */
/* Only uses 32-bit aligned word accesses. */
/* Instructions have been shuffled a bit for possible avoidance of */
/* pipeline hazards. */
.text
ENTRY(memcpy4to3)
pushl %ebp
movl %esp,%ebp
pushl %edi
pushl %esi
pushl %ebx
pushl %ecx
movl 8(%ebp),%edi /* destination address */
movl 12(%ebp),%esi /* source address */
movl 16(%ebp),%ecx /* number of pixels */
/* Handle chunks of 8 pixels. */
1: cmpl $8,%ecx
jl 2f
movl (%esi),%eax /* pixel 0 */
movl 4(%esi),%ebx /* pixel 1 */
shll $8,%eax /* BGR0 in 8-31 */
shrd $8,%ebx,%eax /* BGR0 in 0-23, B1 in 24-31 */
movl %eax,(%edi) /* write word */
shll $8,%ebx /* GR1 in 16-31 */
movl 8(%esi),%eax /* pixel 2 */
shrd $16,%eax,%ebx /* GR1 in 0-15, BG2 in 16-31 */
movl %ebx,4(%edi) /* write word */
shll $8,%eax /* move R2 into 24-31 */
movl 12(%esi),%ebx /* pixel 3 */
shrd $24,%ebx,%eax /* R2 in 0-7, BGR3 in 8-31 */
movl %eax,8(%edi) /* write word */
movl 16(%esi),%eax /* pixel 4 */
shll $8,%eax /* BGR4 in 8-31 */
movl 20(%esi),%ebx /* pixel 5 */
shrd $8,%ebx,%eax /* BGR4 in 0-23, B5 in 24-31 */
movl %eax,12(%edi) /* write word */
shll $8,%ebx /* GR5 in 16-31 */
movl 24(%esi),%eax /* pixel 6 */
shrd $16,%eax,%ebx /* GR5 in 0-15, BG6 in 16-31 */
movl %ebx,16(%edi) /* write word */
subl $8,%ecx /* blended end-of-loop instruction */
shll $8,%eax /* move R6 into 24-31 */
movl 28(%esi),%ebx /* pixel 7 */
shrd $24,%ebx,%eax /* R6 in 0-7, BGR7 in 8-31 */
addl $32,%esi /* blended end-of-loop instruction */
movl %eax,20(%edi) /* write word */
addl $24,%edi
jmp 1b
2: /* Do the remaining pixels. */
andl %ecx,%ecx
jz 4f /* none left */
3: movl (%esi),%eax
movw %eax,(%edi)
shrl $16,%eax
movb %al,2(%edi)
addl $4,%esi
addl $3,%edi
decl %ecx
jnz 3b
4:
popl %ecx
popl %ebx
popl %esi
popl %edi
popl %ebp
ret
/* Prototype: memcpy32shift8( void *dest, void *src, int n ) */
/* Copies pixels from 4-byte-per-pixel screen organized as BGR0 to */
/* 0BGR 4-byte-per-pixel screen. */
/* Used by copyscreen for ATI mach32 32-bit truecolor modes. */
.text
ENTRY(memcpy32shift8)
pushl %ebp
movl %esp,%ebp
pushl %edi
pushl %esi
pushl %ecx
pushl %ebx
movl 8(%ebp),%edi /* destination address */
movl 12(%ebp),%esi /* source address */
movl 16(%ebp),%ecx /* number of pixels */
/* Handle chunks of 8 pixels. */
1: cmpl $8,%ecx
jl 2f
movl (%esi),%eax
shll $8,%eax
movl %eax,(%edi)
movl 4(%esi),%edx
shll $8,%edx
movl %edx,4(%edi)
movl 8(%esi),%eax
shll $8,%eax
movl %eax,8(%edi)
movl 12(%esi),%edx
shll $8,%edx
movl %edx,12(%edi)
movl 16(%esi),%eax
shll $8,%eax
movl %eax,16(%edi)
movl 20(%esi),%edx
shll $8,%edx
movl %edx,20(%edi)
movl 24(%esi),%eax
subl $8,%ecx
shll $8,%eax
movl %eax,24(%edi)
movl 28(%esi),%edx
addl $32,%esi
shll $8,%edx
movl %edx,28(%edi)
addl $32,%edi
jmp 1b
2: andl %ecx,%ecx
jz 4f
3: movl (%esi),%eax
shll $8,%eax
movl %eax,(%edi)
addl $4,%esi
addl $4,%edi
decl %ecx
jnz 3b
4:
popl %ebx
popl %ecx
popl %esi
popl %edi
popl %ebp
ret
/* Optimized memcpy. */
/* Performance on par with inlined 32-bit aligned rep movsl on slow */
/* motherboard. */
/* Hypothesized to be fast on motherboards that handle writes efficiently */
/* and suffer with slow rep movsl microcode in 486/Pentium. */
/* (esp. Cyrix 486DX WB, Headland HTK 486 chipset, Pentium). */
/* Arguments passed in registers: */
/* destination address in %esi */
/* source address in %edx */
/* count in %ecx */
#define MOVEBYTE(n) movb n(%edx),%al; movb %al,n(%esi)
#define MOVESHORT(n) movw n(%edx),%ax; movw %ax,n(%esi)
#define MOVEWORD(n) movl n(%edx),%eax; movl %eax,n(%esi)
ENTRY(_memcpy_jumptable)
.long copy0
.long copy1, copy2, copy3, copy4
.long copy5, copy6, copy7, copy8
.long copy9, copy10, copy11, copy12
.long copy13, copy14, copy15, copy16
.long copy17, copy18, copy19, copy20
.long copy21, copy22, copy23, copy24
.long copy25, copy26, copy27, copy28
.long copy29, copy30, copy31, copy32
jumptable2:
.long align0, align1, align2, align3
ENTRY(_memcpyasm_regargs)
/* This is only valid if nu_bytes >= 3. */
/* Align destination to 32-bit boundary */
movl %esi,%eax
andl $3,%eax
jmp *jumptable2(,%eax,4)
align1: MOVESHORT(0)
MOVEBYTE(2)
addl $3,%edx
addl $3,%esi
subl $3,%ecx
jmp copyaligned
align3: MOVEBYTE(0)
incl %edx
incl %esi
decl %ecx
jmp copyaligned
align2: MOVESHORT(0)
addl $2,%edx
addl $2,%esi
subl $2,%ecx
align0:
copyaligned:
cmpl $32,%ecx
ja copyunrolled
/* <= 32 bytes. */
/* Copy remaining bytes (0-32). */
jmp *SYMBOL_NAME(_memcpy_jumptable)(,%ecx,4)
.align 4,0x90
/* memcpyasm_regargs_aligned is only called if nu_bytes > 32. */
ENTRY(_memcpyasm_regargs_aligned)
copyunrolled:
/* Copy chunks of 32 bytes. */
/* End-of-loop increment instructions blended in. */
addl $32,%esi /*P ok */
movl (%edx),%eax
movl %eax,(0-32)(%esi) /*P ok */
movl 4(%edx),%eax
movl %eax,(4-32)(%esi) /*P ok */
movl 8(%edx),%eax
movl %eax,(8-32)(%esi) /*P ok */
movl 12(%edx),%eax
movl %eax,(12-32)(%esi) /*P ok */
movl 16(%edx),%eax
addl $32,%edx /*P ok */
movl %eax,(16-32)(%esi)
subl $32,%ecx /*P ok */
movl (20-32)(%edx),%eax
movl %eax,(20-32)(%esi) /*P ok */
movl (24-32)(%edx),%eax
movl %eax,(24-32)(%esi) /*P ok */
movl (28-32)(%edx),%eax
movl %eax,(28-32)(%esi) /*P ok */
cmpl $32,%ecx
jge copyunrolled /*P fail */
/* Copy remaining bytes (less than 32). */
jmp *SYMBOL_NAME(_memcpy_jumptable)(,%ecx,4)
#define END ret
copy0: END
copy1: MOVEBYTE(0)
END
copy2: MOVESHORT(0)
END
copy3: MOVESHORT(0)
MOVEBYTE(2)
END
copy4: MOVEWORD(0)
END
copy5: MOVEWORD(0)
MOVEBYTE(4)
END
copy6: MOVEWORD(0)
MOVESHORT(4)
END
copy7: MOVEWORD(0)
MOVESHORT(4)
MOVEBYTE(6)
END
copy8: MOVEWORD(0)
MOVEWORD(4)
END
copy9: MOVEWORD(0)
MOVEWORD(4)
MOVEBYTE(8)
END
copy10: MOVEWORD(0)
MOVEWORD(4)
MOVESHORT(8)
END
copy11: MOVEWORD(0)
MOVEWORD(4)
MOVESHORT(8)
MOVEBYTE(10)
END
copy12: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
END
copy13: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEBYTE(12)
END
copy14: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVESHORT(12)
END
copy15: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVESHORT(12)
MOVEBYTE(14)
END
copy16: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
END
copy17: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEBYTE(16)
END
copy18: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVESHORT(16)
END
copy19: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVESHORT(16)
MOVEBYTE(18)
END
copy20: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
END
copy21: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVEBYTE(20)
END
copy22: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVESHORT(20)
END
copy23: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVESHORT(20)
MOVEBYTE(22)
END
copy24: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVEWORD(20)
END
copy25: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVEWORD(20)
MOVEBYTE(24)
END
copy26: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVEWORD(20)
MOVESHORT(24)
END
copy27: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVEWORD(20)
MOVESHORT(24)
MOVEBYTE(26)
END
copy28: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVEWORD(20)
MOVEWORD(24)
END
copy29: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVEWORD(20)
MOVEWORD(24)
MOVEBYTE(28)
END
copy30: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVEWORD(20)
MOVEWORD(24)
MOVESHORT(28)
END
copy31: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVEWORD(20)
MOVEWORD(24)
MOVESHORT(28)
MOVEBYTE(30)
END
copy32: MOVEWORD(0)
MOVEWORD(4)
MOVEWORD(8)
MOVEWORD(12)
MOVEWORD(16)
MOVEWORD(20)
MOVEWORD(24)
MOVEWORD(28)
END

23
gl/mem.c Normal file
View file

@ -0,0 +1,23 @@
#include <stdio.h>
/*
* Copies pixels from 4-byte-per-pixel screen to 3-byte-per-pixel screen,
*
* discarding the last byte of each pixel. Only uses 32-bit aligned word
* accesses. Instructions have been shuffled a bit for possible
* avoidance of pipeline hazards.
*/
void __svgalib_memcpy4to3(void *dest, void *src, int n)
{
printf("libgl: __svgalib_memcpy4to3 not done yet\n");
}
/*
* Copies pixels from 4-byte-per-pixel screen organized as BGR0 to
* 0BGR 4-byte-per-pixel screen.
* Used by copyscreen for ATI mach32 32-bit truecolor modes.
*/
void __svgalib_memcpy32shift8(void *dest, void *src, int n)
{
printf("libgl: __svgalib_memcpy32shift8 not done yet\n");
}

71
gl/palette.c Normal file
View file

@ -0,0 +1,71 @@
/* Framebuffer Graphics Libary for Linux, Copyright 1993 Harm Hanemaayer */
/* palette.c Palette functions (wrapper over vgalib) */
#include <stdlib.h>
#include <vga.h>
#include "vgagl.h"
#include "def.h"
/* 256-color palette functions */
/* There was a horrible bug here in 0.8x -- green and blue were swapped... */
void gl_getpalettecolor(int c, int *r, int *g, int *b)
{
vga_getpalette(c, r, g, b);
}
void gl_setpalettecolor(int c, int r, int g, int b)
{
vga_setpalette(c, r, g, b);
}
void gl_setpalettecolors(int s, int n, void *_dp)
{
uchar *dp = _dp;
int i;
for (i = s; i < s + n; i++) {
unsigned char r, g, b;
r = *(dp++);
g = *(dp++);
b = *(dp++);
vga_setpalette(i, r, g, b);
}
}
void gl_getpalettecolors(int s, int n, void *_dp)
{
uchar *dp = _dp;
int i;
for (i = s; i < s + n; i++) {
int r, g, b;
vga_getpalette(i, &r, &g, &b);
*(dp++) = (unsigned char) r;
*(dp++) = (unsigned char) g;
*(dp++) = (unsigned char) b;
}
}
void gl_getpalette(void *p)
{
gl_getpalettecolors(0, 256, p);
}
void gl_setpalette(void *p)
{
gl_setpalettecolors(0, 256, p);
}
void gl_setrgbpalette()
{
int i;
Palette pal;
for (i = 0; i < 256; i++) {
pal.color[i].blue = (i & 7) * (64 / 8); /* 3 bits */
pal.color[i].green = ((i & 56) >> 3) * (64 / 8); /* 3 bits */
pal.color[i].red = ((i & 192) >> 6) * (64 / 4); /* 2 bits */
}
gl_setpalette(&pal);
}

197
gl/scale.c Normal file
View file

@ -0,0 +1,197 @@
/* Framebuffer Graphics Libary for Linux, Copyright 1993 Harm Hanemaayer */
/* scale.c Scaling routine */
#include <stdlib.h>
#include <vga.h>
#include "inlstring.h" /* include inline string operations */
#include "vgagl.h"
#include "def.h"
static inline int muldiv64(float m1, float m2, float d)
{
return m1 * m2 / d;
}
/* This is a DDA-based algorithm. */
/* Iteration over target bitmap. */
void gl_scalebox(int w1, int h1, void *_dp1, int w2, int h2, void *_dp2)
{
uchar *dp1 = _dp1;
uchar *dp2 = _dp2;
int xfactor;
int yfactor;
if (w2 == 0 || h2 == 0)
return;
xfactor = muldiv64(w1, 65536, w2); /* scaled by 65536 */
yfactor = muldiv64(h1, 65536, h2); /* scaled by 65536 */
switch (BYTESPERPIXEL) {
case 1:
{
int y, sy;
sy = 0;
for (y = 0; y < h2;) {
int sx = 0;
uchar *dp2old = dp2;
int x;
x = 0;
while (x < w2 - 8) {
*(dp2 + x) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 1) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 2) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 3) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 4) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 5) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 6) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 7) = *(dp1 + (sx >> 16));
sx += xfactor;
x += 8;
}
while (x < w2) {
*(dp2 + x) = *(dp1 + (sx >> 16));
sx += xfactor;
x++;
}
dp2 += w2;
y++;
while (y < h2) {
int l;
int syint = sy >> 16;
sy += yfactor;
if ((sy >> 16) != syint)
break;
/* Copy identical lines. */
l = dp2 - dp2old;
__memcpy(dp2, dp2old, l);
dp2old = dp2;
dp2 += l;
y++;
}
dp1 = _dp1 + (sy >> 16) * w1;
}
}
break;
case 2:
{
int y, sy;
sy = 0;
for (y = 0; y < h2;) {
int sx = 0;
uchar *dp2old = dp2;
int x;
x = 0;
/* This can be greatly optimized with loop */
/* unrolling; omitted to save space. */
while (x < w2) {
*(unsigned short *) (dp2 + x * 2) =
*(unsigned short *) (dp1 + (sx >> 16) * 2);
sx += xfactor;
x++;
}
dp2 += w2 * 2;
y++;
while (y < h2) {
int l;
int syint = sy >> 16;
sy += yfactor;
if ((sy >> 16) != syint)
break;
/* Copy identical lines. */
l = dp2 - dp2old;
__memcpy(dp2, dp2old, l);
dp2old = dp2;
dp2 += l;
y++;
}
dp1 = _dp1 + (sy >> 16) * w1 * 2;
}
}
break;
case 3:
{
int y, sy;
sy = 0;
for (y = 0; y < h2;) {
int sx = 0;
uchar *dp2old = dp2;
int x;
x = 0;
/* This can be greatly optimized with loop */
/* unrolling; omitted to save space. */
while (x < w2) {
*(unsigned short *) (dp2 + x * 3) =
*(unsigned short *) (dp1 + (sx >> 16) * 3);
*(unsigned char *) (dp2 + x * 3 + 2) =
*(unsigned char *) (dp1 + (sx >> 16) * 3 + 2);
sx += xfactor;
x++;
}
dp2 += w2 * 3;
y++;
while (y < h2) {
int l;
int syint = sy >> 16;
sy += yfactor;
if ((sy >> 16) != syint)
break;
/* Copy identical lines. */
l = dp2 - dp2old;
__memcpy(dp2, dp2old, l);
dp2old = dp2;
dp2 += l;
y++;
}
dp1 = _dp1 + (sy >> 16) * w1 * 3;
}
}
break;
case 4:
{
int y, sy;
sy = 0;
for (y = 0; y < h2;) {
int sx = 0;
uchar *dp2old = dp2;
int x;
x = 0;
/* This can be greatly optimized with loop */
/* unrolling; omitted to save space. */
while (x < w2) {
*(unsigned *) (dp2 + x * 4) =
*(unsigned *) (dp1 + (sx >> 16) * 4);
sx += xfactor;
x++;
}
dp2 += w2 * 4;
y++;
while (y < h2) {
int l;
int syint = sy >> 16;
sy += yfactor;
if ((sy >> 16) != syint)
break;
/* Copy identical lines. */
l = dp2 - dp2old;
__memcpy(dp2, dp2old, l);
dp2old = dp2;
dp2 += l;
y++;
}
dp1 = _dp1 + (sy >> 16) * w1 * 4;
}
}
break;
}
}

328
gl/text.c Normal file
View file

@ -0,0 +1,328 @@
/* Framebuffer Graphics Libary for Linux, Copyright 1993 Harm Hanemaayer */
/* text.c Text writing and fonts */
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <vga.h>
#include "inlstring.h" /* include inline string operations */
#include "vgagl.h"
#include "def.h"
/* Text/font functions */
static int font_width = 8;
static int font_height = 8;
static char *font_address;
static int font_charactersize = 64;
static int font_writemode = WRITEMODE_OVERWRITE;
static int compressed_font_bg = 0;
static int compressed_font_fg = 15;
static void writecompressed(int x, int y, int n, unsigned char *s);
void gl_colorfont(int fw, int fh, int fg, void *_dp)
{
uchar *dp = _dp;
int i;
i = fw * fh * 256;
switch (BYTESPERPIXEL) {
case 1:
while (i > 0) {
if (*dp)
*dp = fg;
dp++;
i--;
}
break;
case 2:
while (i > 0) {
if (*(ushort *) dp)
*(ushort *) dp = fg;
dp += 2;
i--;
}
break;
case 3:
while (i > 0) {
if (*(ushort *) dp || *(dp + 2)) {
*(ushort *) dp = fg;
*(dp + 2) = fg >> 16;
}
dp += 3;
i--;
}
break;
case 4:
while (i > 0) {
if (*(int *) dp)
*(int *) dp = fg;
dp += 4;
i--;
}
break;
}
}
void gl_setfont(int fw, int fh, void *font)
{
font_width = fw;
font_height = fh;
font_charactersize = font_width * font_height * BYTESPERPIXEL;
font_address = font;
}
void gl_setwritemode(int m)
{
font_writemode = m;
}
void gl_writen(int x, int y, int n, char *s)
{
/* clipping in putbox */
int i;
if (font_writemode & FONT_COMPRESSED) {
writecompressed(x, y, n, s);
return;
}
if (!(font_writemode & WRITEMODE_MASKED)) {
for (i=0; i<n; i++) {
gl_putbox(x + i * font_width, y, font_width,
font_height, font_address +
(unsigned char) s[i] * font_charactersize);
}
} else { /* masked write */
for (i=0; i<n; i++) {
gl_putboxmask(x + i * font_width, y, font_width,
font_height, font_address +
(unsigned char) s[i] * font_charactersize);
}
}
}
void gl_write(int x, int y, char *s)
{
int n;
for (n=0; s[n]; n++);
gl_writen(x, y, n, s);
}
#ifndef SVGA_AOUT
static int gl_nprintf(int sx, int sy, size_t bufs, const char *fmt, va_list args)
{
unsigned char *buf;
static int x = 0, y = 0, x_start = 0;
int n;
buf = alloca(bufs);
n = vsnprintf(buf, bufs, fmt, args);
if (n < 0)
return n; /* buffer did not suffice, return and retry */
if ((sx >= 0) && (sy >= 0)) {
x = x_start = sx;
y = sy;
}
for (; *buf; buf++)
switch (*buf) {
case '\a': /* badly implemented */
fputc('\a', stdout);
fflush(stdout);
break;
case '\b':
x -= font_width;
if (x < x_start) {
x = WIDTH + (x_start % font_width);
while(x + font_width > WIDTH)
x -= font_width;
if (y >= font_height)
y -= font_height;
}
break;
case '\n':
newline:
y += font_height;
if (y + font_height > HEIGHT)
y %= font_height;
case '\r':
x = x_start;
break;
case '\t':
x += ((TEXT_TABSIZE - ((x - x_start) / font_width) % TEXT_TABSIZE) * font_width);
goto chk_wrap;
break;
case '\v':
y += font_height;
if (y + font_height > HEIGHT)
y %= font_height;
break;
default:
gl_writen(x, y, 1, buf);
x += font_width;
chk_wrap:
if (x + font_width > WIDTH)
goto newline;
}
return n;
}
int gl_printf(int x, int y, const char *fmt, ...)
{
size_t bufs = BUFSIZ;
int result;
va_list args;
va_start(args, fmt);
/* Loop until buffer size suffices */
do {
result = gl_nprintf(x, y, bufs, fmt, args);
bufs <<= 1;
} while(result < 0);
va_end(args);
return result;
}
#endif
void gl_expandfont(int fw, int fh, int fg, void *_f1, void *_f2)
{
/* Convert bit-per-pixel font to byte(s)-per-pixel font */
uchar *f1 = _f1;
uchar *f2 = _f2;
int i, x, y, b = 0; /* keep gcc happy with b = 0 - MW */
for (i = 0; i < 256; i++) {
for (y = 0; y < fh; y++)
for (x = 0; x < fw; x++) {
if (x % 8 == 0)
b = *f1++;
if (b & (128 >> (x % 8))) /* pixel */
switch (BYTESPERPIXEL) {
case 1:
*f2 = fg;
f2++;
break;
case 2:
*(ushort *) f2 = fg;
f2 += 2;
break;
case 3:
*(ushort *) f2 = fg;
*(f2 + 2) = fg >> 16;
f2 += 3;
break;
case 4:
*(uint *) f2 = fg;
f2 += 4;
} else /* no pixel */
switch (BYTESPERPIXEL) {
case 1:
*f2 = 0;
f2++;
break;
case 2:
*(ushort *) f2 = 0;
f2 += 2;
break;
case 3:
*(ushort *) f2 = 0;
*(f2 + 2) = 0;
f2 += 3;
break;
case 4:
*(uint *) f2 = 0;
f2 += 4;
}
}
}
}
static void expandcharacter(int bg, int fg, int c, unsigned char *bitmap)
{
int x, y;
unsigned char *font;
int b = 0; /* keep gcc happy with b = 0 - MW */
font = font_address + c * (font_height * ((font_width + 7) / 8));
for (y = 0; y < font_height; y++)
for (x = 0; x < font_width; x++) {
if (x % 8 == 0)
b = *font++;
if (b & (128 >> (x % 8))) /* pixel */
switch (BYTESPERPIXEL) {
case 1:
*bitmap = fg;
bitmap++;
break;
case 2:
*(ushort *) bitmap = fg;
bitmap += 2;
break;
case 3:
*(ushort *) bitmap = fg;
*(bitmap + 2) = fg >> 16;
bitmap += 3;
break;
case 4:
*(uint *) bitmap = fg;
bitmap += 4;
} else /* background pixel */
switch (BYTESPERPIXEL) {
case 1:
*bitmap = bg;
bitmap++;
break;
case 2:
*(ushort *) bitmap = bg;
bitmap += 2;
break;
case 3:
*(ushort *) bitmap = bg;
*(bitmap + 2) = bg >> 16;
bitmap += 3;
break;
case 4:
*(uint *) bitmap = bg;
bitmap += 4;
}
}
}
/* Write using compressed font. */
static void writecompressed(int x, int y, int n, unsigned char *s)
{
unsigned char *bitmap;
int i;
bitmap = alloca(font_width * font_height * BYTESPERPIXEL);
if (!(font_writemode & WRITEMODE_MASKED)) {
for (i=0; i<n; i++) {
expandcharacter(compressed_font_bg,
compressed_font_fg, s[i], bitmap);
gl_putbox(x + i * font_width, y, font_width,
font_height, bitmap);
}
} else { /* masked write */
for (i=0; i<n; i++) {
expandcharacter(0, compressed_font_fg, s[i], bitmap);
gl_putboxmask(x + i * font_width, y, font_width,
font_height, bitmap);
}
}
}
void gl_setfontcolors(int bg, int fg)
{
compressed_font_bg = bg;
compressed_font_fg = fg;
}

187
gl/vgagl.h Normal file
View file

@ -0,0 +1,187 @@
/* Graphics Library headerfile */
#ifndef VGAGL_H
#define VGAGL_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Graphics context */
#define CONTEXT_VIRTUAL 0x0
#define CONTEXT_PAGED 0x1
#define CONTEXT_LINEAR 0x2
#define CONTEXT_MODEX 0x3
#define CONTEXT_PLANAR16 0x4
#define MODEFLAG_PAGEFLIPPING_CAPABLE 0x01
#define MODEFLAG_TRIPLEBUFFERING_CAPABLE 0x02
#define MODEFLAG_PAGEFLIPPING_ENABLED 0x04
#define MODEFLAG_TRIPLEBUFFERING_ENABLED 0x08
#define MODEFLAG_FLIPPAGE_BANKALIGNED 0x10
/*
* The next two can never occur together, thus we use the same flag
* (as svgalib does).
*/
#define MODEFLAG_32BPP_SHIFT8 0x20
#define MODEFLAG_24BPP_REVERSED 0x20
typedef struct {
void (*driver_setpixel_func) (int, int, int);
int (*driver_getpixel_func) (int, int);
void (*driver_hline_func) (int, int, int, int);
void (*driver_fillbox_func) (int, int, int, int, int);
void (*driver_putbox_func) (int, int, int, int, void *, int);
void (*driver_getbox_func) (int, int, int, int, void *, int);
void (*driver_putboxmask_func) (int, int, int, int, void *);
void (*driver_putboxpart_func) (int, int, int, int, int, int, void *,
int, int);
void (*driver_getboxpart_func) (int, int, int, int, int, int, void *,
int, int);
void (*driver_copybox_func) (int, int, int, int, int, int);
} framebufferfunctions;
typedef struct {
unsigned char modetype; /* virtual, paged, linear, mode X */
unsigned char modeflags; /* or planar16 */
unsigned char dummy;
unsigned char flippage;
int width; /* width in pixels */
int height; /* height in pixels */
int bytesperpixel; /* bytes per pixel (1, 2, 3, or 4) */
int colors; /* number of colors */
int bitsperpixel; /* bits per pixel (8, 15, 16 or 24) */
int bytewidth; /* length of a scanline in bytes */
char *vbuf; /* address of framebuffer */
int clip; /* clipping enabled? */
int clipx1; /* top-left coordinate of clip window */
int clipy1;
int clipx2; /* bottom-right coordinate of clip window */
int clipy2;
framebufferfunctions ff;
} GraphicsContext;
extern GraphicsContext currentcontext;
#define BYTESPERPIXEL (currentcontext.bytesperpixel)
#define BYTEWIDTH (currentcontext.bytewidth)
#define WIDTH (currentcontext.width)
#define HEIGHT (currentcontext.height)
#define VBUF (currentcontext.vbuf)
#define MODETYPE (currentcontext.modetype)
#define MODEFLAGS (currentcontext.modeflags)
#define BITSPERPIXEL (currentcontext.bitsperpixel)
#define COLORS (currentcontext.colors)
#define __clip (currentcontext.clip)
#define __clipx1 (currentcontext.clipx1)
#define __clipy1 (currentcontext.clipy1)
#define __clipx2 (currentcontext.clipx2)
#define __clipy2 (currentcontext.clipy2)
/* Configuration */
int gl_setcontextvga(int m);
int gl_setcontextvgavirtual(int m);
void gl_setcontextvirtual(int w, int h, int bpp, int bitspp, void *vbuf);
void gl_setcontextwidth(int w);
void gl_setcontextheight(int h);
GraphicsContext *gl_allocatecontext(void);
void gl_setcontext(GraphicsContext * gc);
void gl_getcontext(GraphicsContext * gc);
void gl_freecontext(GraphicsContext * gc);
/* Line drawing */
void gl_setpixel(int x, int y, int c);
void gl_setpixelrgb(int x, int y, int r, int g, int b);
int gl_getpixel(int x, int y);
void gl_getpixelrgb(int x, int y, int *r, int *g, int *b);
int gl_rgbcolor(int r, int g, int b);
void gl_hline(int x1, int y, int x2, int c);
void gl_line(int x1, int y1, int x2, int y2, int c);
void gl_circle(int x, int y, int r, int c);
void gl_fillcircle(int sx, int sy, int r, int c);
void gl_bcircle(int sx, int sy, int r, int c, int fill);
/* Box (bitmap) functions */
void gl_fillbox(int x, int y, int w, int h, int c);
void gl_getbox(int x, int y, int w, int h, void *dp);
void gl_putbox(int x, int y, int w, int h, void *dp);
void gl_putboxpart(int x, int y, int w, int h, int bw, int bh, void *b,
int xo, int yo);
void gl_putboxmask(int x, int y, int w, int h, void *dp);
void gl_copybox(int x1, int y1, int w, int h, int x2, int y2);
void gl_copyboxtocontext(int x1, int y1, int w, int h, GraphicsContext * gc,
int x2, int y2);
void gl_copyboxfromcontext(GraphicsContext * gc, int x1, int y1, int w, int h,
int x2, int y2);
/* The following functions only work in 256-color modes: */
void gl_compileboxmask(int w, int h, void *sdp, void *ddp);
int gl_compiledboxmasksize(int w, int h, void *sdp);
void gl_putboxmaskcompiled(int x, int y, int w, int h, void *dp);
/* Miscellaneous */
void gl_clearscreen(int c);
void gl_scalebox(int w1, int h1, void *sb, int w2, int h2, void *db);
void gl_setdisplaystart(int x, int y);
void gl_enableclipping(void);
void gl_setclippingwindow(int x1, int y1, int x2, int y2);
void gl_disableclipping(void);
/* Screen buffering */
void gl_copyscreen(GraphicsContext * gc);
void gl_setscreenoffset(int o);
int gl_enablepageflipping(GraphicsContext * gc);
/* Text */
/* Writemode flags. */
#define WRITEMODE_OVERWRITE 0
#define WRITEMODE_MASKED 1
#define FONT_EXPANDED 0
#define FONT_COMPRESSED 2
void gl_expandfont(int fw, int fh, int c, void *sfdp, void *dfdp);
void gl_setfont(int fw, int fh, void *fdp);
void gl_colorfont(int fw, int fh, int c, void *fdp);
void gl_setwritemode(int wm);
void gl_write(int x, int y, char *s);
void gl_writen(int x, int y, int n, char *s);
void gl_setfontcolors(int bg, int fg);
/* gl_printf is only available in ELF libraries!! */
int gl_printf(int x, int y, const char *fmt,...);
extern unsigned char *gl_font8x8; /* compressed 8x8 font */
/* 256-color Palette */
typedef struct {
struct {
unsigned char red; /* 6-bit values */
unsigned char green;
unsigned char blue;
} color[256];
} Palette;
void gl_setpalettecolor(int c, int r, int b, int g);
void gl_getpalettecolor(int c, int *r, int *b, int *g);
void gl_setpalettecolors(int s, int n, void *dp);
void gl_getpalettecolors(int s, int n, void *dp);
void gl_setpalette(void *p);
void gl_getpalette(void *p);
void gl_setrgbpalette(void);
#ifdef __cplusplus
}
#endif
#endif