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

75
demos/Makefile Normal file
View file

@ -0,0 +1,75 @@
#----------------------------------------------------------------------
# Makefile for SVGAlib demo programs.
#
# This file is a part of SVGAlib.
#----------------------------------------------------------------------
include ../Makefile.cfg
srcdir = ..
VPATH = $(srcdir)/demos
#----------------------------------------------------------------------
# Compiler Section (overrides Makefile.cfg)
#----------------------------------------------------------------------
CFLAGS = $(WARN) $(OPTIMIZE) -I$(srcdir)/include -I$(srcdir)/gl $(DEBFLAGS)
ifeq (a.out, $(TARGET_FORMAT))
CFLAGS += -DSVGA_AOUT
endif
#----------------------------------------------------------------------
# Rules Section
#----------------------------------------------------------------------
PROGS = fun testgl speedtest mousetest vgatest scrolltest testlinear \
keytest testaccel accel forktest eventtest spin bg_test printftest \
joytest mjoytest bankspeed lineart linearspeed addmodetest \
svidtune linearfork cursor vgatweak buildcsr
# Determine what library (static or shared) we will be linking programs with
ifdef INSTALLSHAREDLIB
LIBS = -lvgagl -lvga
endif
ifndef LIBS
LIBS = ../staticlib/libvgagl.a ../staticlib/libvga.a -lm
LVGADEP = $(LIBS)
endif
all: $(PROGS)
.PHONY: all clean cleanbin dep
$(PROGS): $(LVGADEP)
.c:
$(CC) $(CFLAGS) $(LDFLAGS) -o $* $*.c $(LIBS)
rwpage: rwpage.pp
$(PC) -Rintel rwpage.pp
testaccel: testaccel.c
$(CC) $(CFLAGS) $(LDFLAGS) -o testaccel testaccel.c $(LIBS) -lm
accel: accel.c
$(CC) $(CFLAGS) $(LDFLAGS) -o accel accel.c $(LIBS) -lm
linearspeed: linearspeed.c memset.o
$(CC) $(CFLAGS) $(LDFLAGS) -o linearspeed linearspeed.c memset.o $(LIBS)
buildcsr: mkcur.o
$(CC) -o buildcsr $(LDFLAGS) mkcur.o -lvgagl -lvga
clean: cleanbin
rm -f .depend *.o *~ *.bak core
cleanbin:
rm -f $(PROGS) rwpage
#
# No dependencies required here.
#
dep:
.depend:

1018
demos/accel.c Normal file

File diff suppressed because it is too large Load diff

238
demos/addmodetest.c Normal file
View file

@ -0,0 +1,238 @@
/* From VGAlib, changed for svgalib */
/* partially copyrighted (C) 1993 by Hartmut Schirmer */
#include <stdio.h>
#include <unistd.h> /* for usleep( long ) */
#include <string.h>
#include <stdlib.h>
#include "vga.h"
static unsigned char line[2048 * 3];
static void testmode(int mode)
{
int xmax, ymax, i, x, y, yw, ys, c;
vga_modeinfo *modeinfo;
vga_setmode(mode);
modeinfo = vga_getmodeinfo(mode);
printf("Width: %d Height: %d Colors: %d\n",
modeinfo->width,
modeinfo->height,
modeinfo->colors);
printf("DisplayStartRange: %xh Maxpixels: %d Blit: %s\n",
modeinfo->startaddressrange,
modeinfo->maxpixels,
modeinfo->haveblit ? "YES" : "NO");
printf("Offset: %i Bytes Per Pixel: %d\n",
modeinfo->linewidth,
modeinfo->bytesperpixel);
#ifdef TEST_MODEX
if (modeinfo->colors == 256)
printf("Switching to ModeX ... %s\n",
(vga_setmodeX()? "done" : "failed"));
#endif
vga_screenoff();
xmax = vga_getxdim() - 1;
ymax = vga_getydim() - 1;
vga_setcolor(vga_white());
vga_drawline(0, 0, xmax, 0);
vga_drawline(xmax, 0, xmax, ymax);
vga_drawline(xmax, ymax, 0, ymax);
vga_drawline(0, ymax, 0, 0);
for (i = 0; i <= 15; i++) {
vga_setegacolor(i);
vga_drawline(10 + i * 5, 10, 90 + i * 5, 90);
}
for (i = 0; i <= 15; i++) {
vga_setegacolor(i);
vga_drawline(90 + i * 5, 10, 10 + i * 5, 90);
}
vga_screenon();
ys = 100;
yw = (ymax - 100) / 4;
switch (vga_getcolors()) {
case 256:
for (i = 0; i < 60; ++i) {
c = (i * 64) / 60;
vga_setpalette(i + 16, c, c, c);
vga_setpalette(i + 16 + 60, c, 0, 0);
vga_setpalette(i + 16 + (2 * 60), 0, c, 0);
vga_setpalette(i + 16 + (3 * 60), 0, 0, c);
}
line[0] = line[xmax] = 15;
line[1] = line[xmax - 1] = 0;
for (x = 2; x < xmax - 1; ++x)
line[x] = (((x - 2) * 60) / (xmax - 3)) + 16;
for (y = ys; y < ys + yw; ++y)
vga_drawscanline(y, line);
for (x = 2; x < xmax - 1; ++x)
line[x] += 60;
ys += yw;
for (y = ys; y < ys + yw; ++y)
vga_drawscanline(y, line);
for (x = 2; x < xmax - 1; ++x)
line[x] += 60;
ys += yw;
for (y = ys; y < ys + yw; ++y)
vga_drawscanline(y, line);
for (x = 2; x < xmax - 1; ++x)
line[x] += 60;
ys += yw;
for (y = ys; y < ys + yw; ++y)
vga_drawscanline(y, line);
break;
case 1 << 15:
case 1 << 16:
case 1 << 24:
for (x = 2; x < xmax - 1; ++x) {
c = ((x - 2) * 256) / (xmax - 3);
y = ys;
vga_setrgbcolor(c, c, c);
vga_drawline(x, y, x, y + yw - 1);
y += yw;
vga_setrgbcolor(c, 0, 0);
vga_drawline(x, y, x, y + yw - 1);
y += yw;
vga_setrgbcolor(0, c, 0);
vga_drawline(x, y, x, y + yw - 1);
y += yw;
vga_setrgbcolor(0, 0, c);
vga_drawline(x, y, x, y + yw - 1);
}
for (x = 0; x < 64; x++) {
for (y = 0; y < 64; y++) {
vga_setrgbcolor(x * 4 + 3, y * 4 + 3, 0);
vga_drawpixel(xmax / 2 - 160 + x, y + ymax / 2 - 80);
vga_setrgbcolor(x * 4 + 3, 0, y * 4 + 3);
vga_drawpixel(xmax / 2 - 32 + x, y + ymax / 2 - 80);
vga_setrgbcolor(0, x * 4 + 3, y * 4 + 3);
vga_drawpixel(xmax / 2 + 160 - 64 + x, y + ymax / 2 - 80);
vga_setrgbcolor(x * 4 + 3, y * 4 + 3, 255);
vga_drawpixel(xmax / 2 - 160 + x, y + ymax / 2 + 16);
vga_setrgbcolor(x * 4 + 3, 255, y * 4 + 3);
vga_drawpixel(xmax / 2 - 32 + x, y + ymax / 2 + 16);
vga_setrgbcolor(255, x * 4 + 3, y * 4 + 3);
vga_drawpixel(xmax / 2 + 160 - 64 + x, y + ymax / 2 + 16);
}
}
break;
default:
if (vga_getcolors() == 16) {
for (i = 0; i < xmax - 1; i++)
line[i] = (i + 2) % 16;
line[0] = line[xmax] = 15;
line[1] = line[xmax - 1] = 0;
}
if (vga_getcolors() == 2) {
for (i = 0; i <= xmax; i++)
line[i] = 0x11;
line[0] = 0x91;
}
for (i = 100; i < ymax - 1; i++)
vga_drawscanline(i, line);
break;
}
if (getchar() == 'd')
vga_dumpregs();
vga_setmode(TEXT);
}
int main(int argc, char *argv[])
{
int mode;
int tests=0xffffffff;
if(argc>1)tests=strtol(argv[1],NULL,0);
vga_init(); /* Initialize. */
if(tests&1){
vga_addtiming(45000,720,776,880,936,540,570,576,600,0);
vga_addtiming(36000,720,756,872,950,540,542,547,565,0);
mode=vga_addmode(720,540,1<<24,720*4,4);
printf("Mode=%i\n",mode);
if (vga_hasmode(mode))
testmode(mode);
else printf("Error: Video mode not supported by driver\n");
};
if(tests&2){
vga_addtiming(45000,720,776,880,936,720,750,756,800,0);
vga_addtiming(36000,720,756,872,950,720,723,729,750,0);
mode=vga_addmode(720,720,1<<24,720*4,4);
printf("Mode=%i\n",mode);
if (vga_hasmode(mode))
testmode(mode);
else printf("Error: Video mode not supported by driver\n");
};
if(tests&4){
vga_guesstiming(576,432,0,0);
mode=vga_addmode(576,432,1<<16,576*2,2);
printf("Mode=%i\n",mode);
if (vga_hasmode(mode))
testmode(mode);
else printf("Error: Video mode not supported by driver\n");
};
if(tests&8){
vga_guesstiming(576,431,1,0);
mode=vga_addmode(576,431,1<<16,576*2,2);
printf("Mode=%i\n",mode);
if (vga_hasmode(mode))
testmode(mode);
else printf("Error: Video mode not supported by driver\n");
};
if(tests&16){
vga_guesstiming(360,271,1,0);
mode=vga_addmode(360,271,1<<16,360*2,2);
printf("Mode=%i\n",mode);
if (vga_hasmode(mode))
testmode(mode);
else printf("Error: Video mode not supported by driver\n");
};
if(tests&32){
vga_guesstiming(360,270,1,0);
mode=vga_addmode(360,270,1<<16,360*2,2);
printf("Mode=%i\n",mode);
if (vga_hasmode(mode))
testmode(mode);
else printf("Error: Video mode not supported by driver\n");
};
if(tests&64){
vga_guesstiming(672,800,257,0);
mode=vga_addmode(672,800,1<<16,672*2,2);
printf("Mode=%i\n",mode);
if (vga_hasmode(mode))
testmode(mode);
else printf("Error: Video mode not supported by driver\n");
};
if(tests&128){
vga_guesstiming(712,800,257,0);
mode=vga_addmode(712,800,1<<16,712*2,2);
printf("Mode=%i\n",mode);
if (vga_hasmode(mode))
testmode(mode);
else printf("Error: Video mode not supported by driver\n");
};
return 0;
}

17
demos/arrow.h Normal file
View file

@ -0,0 +1,17 @@
unsigned int arrow[64] = {
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00200000, 0x00700000,
0x00380000, 0x00180000, 0x001c0000, 0x000e0000,
0x00070000, 0x00038000, 0x00018000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0xc0000000, 0xb0000000, 0x4c000000, 0x43000000,
0x20c00000, 0x20300000, 0x10080000, 0x10100000,
0x08300000, 0x08600000, 0x04e00000, 0x05f00000,
0x03380000, 0x00180000, 0x001c0000, 0x000e0000,
0x00070000, 0x00038000, 0x00018000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000};

169
demos/bankspeed.c Normal file
View file

@ -0,0 +1,169 @@
#include <stdlib.h>
#include <stdio.h>
#include <vga.h>
#include <vgagl.h>
#include <time.h>
#include <unistd.h>
/* The logo was drawn by John Remyn. */
/* Feel free to provide a more beautiful/official/thought provoking/cool */
/* logo to replace it. */
#define LOGOWIDTH 201
#define LOGOHEIGHT 85
int VGAMODE;
int VIRTUAL;
GraphicsContext *backscreen;
GraphicsContext *physicalscreen;
void *logobitmap;
void loadbitmap(char *filename, void *buf)
{
FILE *f;
f = fopen(filename, "rb");
if(f==NULL)return;
fread(buf, 1, 17095, f);
fclose(f);
}
void test(void)
{
int i, j;
if (VIRTUAL)
gl_setcontext(backscreen);
gl_clearscreen(0);
for (i = 0; i < 5; i++) {
gl_clearscreen(0);
for (j = 0; j < 100000; j++)
gl_setpixel(random() % WIDTH, random() % HEIGHT,
random() % COLORS);
}
if (VIRTUAL)
gl_copyscreen(physicalscreen);
}
void setcustompalette(void)
{
/* colors 0-31 are an RGB mix (bits 0 and 1 red, 2 green, 3 and 4 blue) */
/* 32-63 black to red */
/* 64-95 black to green */
/* 96-127 black to yellow */
/* 128-159 black to blue */
/* 160-191 black to magenta */
/* 192-223 black to cyan */
/* 224-255 black to white */
Palette pal;
int i;
for (i = 0; i < 256; i++) {
int r, g, b;
r = g = b = 0;
if ((i & 32) > 0)
r = (i & 31) << 1;
if ((i & 64) > 0)
g = (i & 31) << 1;
if ((i & 128) > 0)
b = (i & 31) << 1;
if (i < 32) {
r = (i & 3) << 4; /* 2 bits */
g = (i & 4) << 3; /* 1 bit */
b = (i & 24) << 1; /* 2 bits */
}
pal.color[i].red = r;
pal.color[i].green = g;
pal.color[i].blue = b;
}
gl_setpalette(&pal);
}
void logotest(void)
{
int h;
void *scaled;
/* Set logo palette. */
setcustompalette();
/* Create logo bitmap */
logobitmap = alloca(LOGOWIDTH * LOGOHEIGHT);
loadbitmap("linuxlogo.bitmap", logobitmap);
/* Allocate buffer for scaled bitmap. */
scaled = alloca(WIDTH * HEIGHT);
gl_clearscreen(0);
/* Stretch vertically. */
for (h = 0; h <= LOGOHEIGHT; h++) {
gl_scalebox(LOGOWIDTH, LOGOHEIGHT, logobitmap,
LOGOWIDTH, h, scaled);
gl_putbox(0, 0, LOGOWIDTH, h, scaled);
if (VIRTUAL)
gl_copyscreen(physicalscreen);
}
gl_clearscreen(0);
/* Scale to screen resolution. */
gl_scalebox(LOGOWIDTH, LOGOHEIGHT, logobitmap, WIDTH, HEIGHT, scaled);
gl_putbox(0, 0, WIDTH, HEIGHT, scaled);
gl_copyscreen(physicalscreen);
}
int main(void)
{
clock_t t1, t2;
vga_init();
t1=clock();
VGAMODE = vga_getdefaultmode();
if (VGAMODE == -1)
VGAMODE = G320x200x256; /* Default mode. */
if (!vga_hasmode(VGAMODE)) {
printf("Mode not available.\n");
exit(-1);
}
VIRTUAL = 0; /* No virtual screen. */
if (vga_getmodeinfo(VGAMODE)->colors == 16 ||
(vga_getmodeinfo(VGAMODE)->flags & IS_MODEX))
/* These modes are supported indirectly by vgagl. */
VIRTUAL = 1;
if (VIRTUAL) {
/* Create virtual screen. */
gl_setcontextvgavirtual(VGAMODE);
backscreen = gl_allocatecontext();
gl_getcontext(backscreen);
}
vga_setmode(VGAMODE);
gl_setcontextvga(VGAMODE); /* Physical screen context. */
physicalscreen = gl_allocatecontext();
gl_getcontext(physicalscreen);
if (COLORS == 256)
gl_setrgbpalette();
test();
/* Now do the same with clipping enabled. */
gl_clearscreen(0);
gl_setclippingwindow(WIDTH / 4, HEIGHT / 4, WIDTH - WIDTH / 4 - 1,
HEIGHT - HEIGHT / 4 - 1);
test();
gl_disableclipping();
if (COLORS == 256)
/* Show the logo if using 256 color mode. */
logotest();
if (VIRTUAL)
gl_freecontext(backscreen);
t2=clock();
printf("total:%1.2f sec\n",(1.0*t2-t1)/CLOCKS_PER_SEC);
vga_setmode(TEXT);
exit(0);
}

129
demos/bg_test.c Normal file
View file

@ -0,0 +1,129 @@
/* bg_test.c
Copyright (c) 1997 Michael Friman. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <vga.h>
#include <vgagl.h>
/*
If you really want to see background runin, add after
vga_setmode vga_runinbackground(1) in fun.
Remember to compile the svgalib with background.
*/
int go = 0;
int linear = 0;
void drawline(int x1, int y1, int x2, int y2)
{
if (linear)
{
gl_line(x1,y1,x2,y2,vga_white());
}
else
{
vga_drawline(x1,y1,x2,y2);
}
}
void set_go(void)
{
go=1;
return;
}
int main(int argc, char *argv[])
{
int x[2];
int y[2];
int counter;
int mode;
if ((argc > 2) || ((argc == 2) && (strcmp(argv[1], "linear") != 0)))
{
fputs("Usage: bg_test [linear]\n", stderr);
exit(2);
}
vga_init();
printf("This is small test for background runin.\n");
if (vga_runinbackground_version()==1 || vga_runinbackground_version()>=3)
{
printf("Background runin enabled. mode %d\n", vga_runinbackground_version());
}
else
{
printf("Svgalib is not background capable.\n");
printf("Test ended.\n");
return(0);
}
printf("Switch to another console when the box appears.\n");
printf("Press enter to continue or CTRL-c to stop.\n");
getchar();
mode = vga_getdefaultmode();
if (mode < 0)
mode = G320x200x256;
if (argc == 2)
{
if (vga_getmodeinfo(mode)->flags & CAPABLE_LINEAR)
{
vga_setlinearaddressing();
fputs("Linear mode set.\n", stderr);
linear = 1;
}
else
{
fputs("Linear mode unavailable.\n", stderr);
}
}
vga_setmode(mode);
if (linear)
gl_setcontextvga(mode);
vga_runinbackground(VGA_GOTOBACK,set_go);
vga_runinbackground(1);
x[0]=0;
y[0]=0;
x[1]=vga_getxdim()-1;
y[1]=vga_getydim()-1;
if (!linear)
vga_setcolor(vga_white());
counter=(y[1]/11)*5+1;
while(counter<=(y[1]/11)*6)
{
drawline((x[1]/11)*5,counter,(x[1]/11)*6,counter);
counter++;
}
/* Program won't go further without console switching. */
while(!go) usleep(1000);
drawline(x[0],y[0],x[1],y[0]);
drawline(x[1],y[0],x[1],y[1]);
drawline(x[1],y[1],x[0],y[1]);
drawline(x[0],y[1],x[0],y[0]);
drawline(x[0],y[0],x[1],y[1]);
drawline(x[1],y[0],x[0],y[1]);
while(!vga_getkey());
vga_setmode(TEXT);
printf("Ok.\n");
return(0);
}

50
demos/clut.xbm Normal file
View file

@ -0,0 +1,50 @@
#define clut_width 18
#define clut_height 233
static char clut_bits[] = {
0xe0,0x07,0x00,0xf8,0x0f,0x00,0xfc,0x1f,0x00,0x3e,0x1c,0x00,0x1e,0x30,0x00,
0x07,0x20,0x00,0x03,0x20,0x00,0x01,0x20,0x00,0x01,0x20,0x00,0x01,0x30,0x00,
0x03,0x10,0x00,0x1e,0x0c,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,
0x80,0x1f,0x00,0xc0,0x3f,0x00,0xc0,0x20,0x00,0x20,0x20,0x00,0x20,0x20,0x00,
0x20,0x18,0x00,0xe0,0x1f,0x00,0xc0,0x0f,0x00,0x80,0x07,0x00,0x00,0x00,0x00,
0x00,0x3e,0x00,0xf1,0x3f,0x00,0xff,0x3f,0x00,0xff,0x21,0x00,0x0f,0x10,0x00,
0x00,0x00,0x00,0x00,0x0f,0x00,0x80,0x1f,0x00,0xc0,0x3f,0x00,0xc0,0x20,0x00,
0x20,0x20,0x00,0x20,0x20,0x00,0x20,0x18,0x00,0xe0,0x1f,0x00,0xc0,0x0f,0x00,
0x80,0x07,0x00,0x00,0x00,0x00,0x20,0x3c,0x00,0xe0,0x3f,0x00,0xe0,0x3f,0x00,
0xe0,0x03,0x00,0x80,0x00,0x00,0x40,0x00,0x00,0xe0,0x00,0x00,0xe0,0x00,0x00,
0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x3e,0x00,0xf1,0x3f,0x00,0xff,0x3f,0x00,0xff,0x21,0x00,0x0f,0x10,0x00,
0x00,0x00,0x00,0x00,0x0f,0x00,0x80,0x1f,0x00,0xc0,0x3f,0x00,0xc0,0x20,0x00,
0x20,0x20,0x00,0x20,0x20,0x00,0x20,0x18,0x00,0xe0,0x1f,0x00,0xc0,0x0f,0x00,
0x80,0x07,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,0x80,0x1f,0x00,0xc0,0x3f,0x00,
0xc0,0x20,0x00,0x20,0x20,0x00,0x20,0x20,0x00,0x20,0x18,0x00,0xe0,0x1f,0x00,
0xc0,0x0f,0x00,0x80,0x07,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0xf1,0x3f,0x00,
0xff,0x3f,0x00,0xff,0x03,0x00,0x8f,0x00,0x00,0x40,0x0e,0x00,0x60,0x3e,0x00,
0xe0,0x3d,0x00,0xe0,0x31,0x00,0xc0,0x10,0x00,0x00,0x08,0x00,0x20,0x1e,0x00,
0xe0,0x3f,0x00,0xe0,0x3f,0x00,0xe0,0x31,0x00,0x00,0x10,0x00,0x00,0x08,0x00,
0x00,0x3e,0x00,0xe0,0x3f,0x00,0xe0,0x3f,0x00,0xe0,0x21,0x00,0x00,0x10,0x00,
0x00,0x00,0x02,0x00,0xc0,0x03,0x20,0xfe,0x03,0xe0,0xff,0x03,0xe0,0x3f,0x02,
0xe0,0x21,0x00,0x40,0x20,0x00,0x20,0x20,0x00,0x20,0x18,0x00,0xe0,0x1f,0x00,
0xc0,0x0f,0x00,0x80,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3e,0x00,0xe0,0x3f,0x00,
0xfc,0x3f,0x00,0xfc,0x21,0x00,0x3c,0x10,0x00,0x20,0x00,0x00,0x20,0x00,0x00,
0x00,0x0f,0x00,0x80,0x1f,0x00,0xc0,0x3f,0x00,0xc0,0x20,0x00,0x20,0x20,0x00,
0x20,0x10,0x00,0x40,0x1c,0x00,0xe0,0x3f,0x00,0xe0,0x3f,0x00,0xe0,0x23,0x00,
0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,0xf1,0x1f,0x00,0xff,0x3f,0x00,
0xff,0x21,0x00,0x4f,0x20,0x00,0x20,0x20,0x00,0x20,0x18,0x00,0xe0,0x1f,0x00,
0xc0,0x0f,0x00,0x80,0x07,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0xf1,0x3f,0x00,
0xff,0x3f,0x00,0xff,0x21,0x00,0x0f,0x10,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,
0x80,0x1f,0x00,0xc0,0x3f,0x00,0xc0,0x24,0x00,0x20,0x24,0x00,0x20,0x22,0x00,
0x20,0x13,0x00,0xe0,0x13,0x00,0xc0,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x0e,0x00,0xe0,0x1f,0x00,
0xe0,0x3f,0x00,0xe0,0x31,0x00,0x00,0x30,0x00,0x00,0x10,0x00,0x00,0x0e,0x00,
0xe0,0x1f,0x00,0xe0,0x3f,0x00,0xe0,0x31,0x00,0x00,0x30,0x00,0x00,0x10,0x00,
0x60,0x18,0x00,0xe0,0x0c,0x00,0xc0,0x03,0x00,0x00,0x00,0x00,0x20,0x3e,0x00,
0xe0,0x3f,0x00,0xe6,0x3f,0x00,0xe6,0x21,0x00,0x06,0x10,0x00,0x00,0x00,0x00,
0x00,0x0f,0x00,0x80,0x1f,0x00,0xc0,0x3f,0x00,0xc0,0x20,0x00,0x20,0x20,0x00,
0x20,0x20,0x00,0x20,0x10,0x00,0x40,0x1e,0x00,0xf1,0x3f,0x00,0xff,0x3f,0x00,
0xff,0x21,0x00,0x0f,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3e,0x00,
0xe0,0x3f,0x00,0xfc,0x3f,0x00,0xfc,0x21,0x00,0x3c,0x10,0x00,0x20,0x00,0x00,
0x20,0x00,0x00,0x00,0x3e,0x00,0xf1,0x3f,0x00,0xff,0x3f,0x00,0xff,0x01,0x00,
0x8f,0x00,0x00,0x40,0x00,0x00,0x60,0x3c,0x00,0xe0,0x3f,0x00,0xe0,0x3f,0x00,
0xc0,0x23,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0xc0,0x3c,0x00,
0xe0,0x3d,0x00,0xe0,0x19,0x00,0xc0,0x00,0x00};

231
demos/cursor.c Normal file
View file

@ -0,0 +1,231 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <vga.h>
#include <vgamouse.h>
#include <sys/fcntl.h>
#include <stdint.h>
int mode = G1024x768x64K;
uint32_t mag_glass_bits[] = {
0x3f8, 0x60c, 0x9e2, 0x1a13, 0x1401, 0x1401, 0x1001, 0x1001,
0x1001, 0x1003, 0x1802, 0x340c, 0x6ff8, 0xd800, 0xb000, 0xe000,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0x3f8, 0x60c, 0x9e2, 0x1a13, 0x1401, 0x1401, 0x1001, 0x1001,
0x1001, 0x1003, 0x1802, 0x340c, 0x6ff8, 0xd800, 0xb000, 0xe000,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
uint32_t mag_glass_filled[] = {
0x3f8, 0x60c, 0x9e2, 0x1a13, 0x1401, 0x1401, 0x1001, 0x1001,
0x1001, 0x1003, 0x1802, 0x340c, 0x6ff8, 0xd800, 0xb000, 0xe000,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0x3f8, 0x7fc, 0xffe, 0x1fff, 0x1fff, 0x1fff, 0x1fff, 0x1fff,
0x1fff, 0x1fff, 0x1ffe, 0x3ffc, 0x7ff8, 0xf800, 0xe000, 0xe000,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
uint32_t *c2;
static unsigned char line[2048*4];
static void drawpattern(void)
{
int xmax, ymax, i, x, y, yw, ys, c;
vga_modeinfo *modeinfo;
modeinfo = vga_getmodeinfo(mode);
xmax = vga_getxdim() - 1;
ymax = vga_getydim() - 1;
vga_setcolor(vga_white());
vga_drawline(0, 0, xmax, 0);
vga_drawline(xmax, 0, xmax, ymax);
vga_drawline(xmax, ymax, 0, ymax);
vga_drawline(0, ymax, 0, 0);
for (i = 0; i <= 15; i++) {
vga_setegacolor(i);
vga_drawline(10 + i * 5, 10, 90 + i * 5, 90);
}
for (i = 0; i <= 15; i++) {
vga_setegacolor(i);
vga_drawline(90 + i * 5, 10, 10 + i * 5, 90);
}
vga_screenon();
ys = 100;
yw = (ymax - 100) / 4;
switch (vga_getcolors()) {
case 256:
for (i = 0; i < 60; ++i) {
c = (i * 64) / 60;
vga_setpalette(i + 16, c, c, c);
vga_setpalette(i + 16 + 60, c, 0, 0);
vga_setpalette(i + 16 + (2 * 60), 0, c, 0);
vga_setpalette(i + 16 + (3 * 60), 0, 0, c);
}
line[0] = line[xmax] = 15;
line[1] = line[xmax - 1] = 0;
for (x = 2; x < xmax - 1; ++x)
line[x] = (((x - 2) * 60) / (xmax - 3)) + 16;
for (y = ys; y < ys + yw; ++y) /* gray */
vga_drawscanline(y, line);
for (x = 2; x < xmax - 1; ++x)
line[x] += 60;
ys += yw;
for (y = ys; y < ys + yw; ++y) /* red */
vga_drawscanline(y, line);
for (x = 2; x < xmax - 1; ++x)
line[x] += 60;
ys += yw;
for (y = ys; y < ys + yw; ++y) /* green */
vga_drawscanline(y, line);
for (x = 2; x < xmax - 1; ++x)
line[x] += 60;
ys += yw;
for (y = ys; y < ys + yw; ++y) /* blue */
vga_drawscanline(y, line);
break;
case 1 << 15:
case 1 << 16:
case 1 << 24:
for (x = 2; x < xmax - 1; ++x) {
c = ((x - 2) * 256) / (xmax - 3);
y = ys;
vga_setrgbcolor(c, c, c);
vga_drawline(x, y, x, y + yw - 1);
y += yw;
vga_setrgbcolor(c, 0, 0);
vga_drawline(x, y, x, y + yw - 1);
y += yw;
vga_setrgbcolor(0, c, 0);
vga_drawline(x, y, x, y + yw - 1);
y += yw;
vga_setrgbcolor(0, 0, c);
vga_drawline(x, y, x, y + yw - 1);
}
for (x = 0; x < 64; x++) {
for (y = 0; y < 64; y++) {
vga_setrgbcolor(x * 4 + 3, y * 4 + 3, 0);
vga_drawpixel(xmax / 2 - 160 + x, y + ymax / 2 - 80);
vga_setrgbcolor(x * 4 + 3, 0, y * 4 + 3);
vga_drawpixel(xmax / 2 - 32 + x, y + ymax / 2 - 80);
vga_setrgbcolor(0, x * 4 + 3, y * 4 + 3);
vga_drawpixel(xmax / 2 + 160 - 64 + x, y + ymax / 2 - 80);
vga_setrgbcolor(x * 4 + 3, y * 4 + 3, 255);
vga_drawpixel(xmax / 2 - 160 + x, y + ymax / 2 + 16);
vga_setrgbcolor(x * 4 + 3, 255, y * 4 + 3);
vga_drawpixel(xmax / 2 - 32 + x, y + ymax / 2 + 16);
vga_setrgbcolor(255, x * 4 + 3, y * 4 + 3);
vga_drawpixel(xmax / 2 + 160 - 64 + x, y + ymax / 2 + 16);
}
}
break;
default:
if (vga_getcolors() == 16) {
for (i = 0; i < xmax - 1; i++)
line[i] = (i + 2) % 16;
line[0] = line[xmax] = 15;
line[1] = line[xmax - 1] = 0;
}
if (vga_getcolors() == 2) {
for (i = 0; i <= xmax; i++)
line[i] = 0x11;
line[0] = 0x91;
}
for (i = 100; i < ymax - 1; i++)
vga_drawscanline(i, line);
break;
}
}
int main(int argc, char *argv[]) {
int i,s,j;
unsigned char *g;
vga_init();
vga_setmousesupport(1);
printf("%i\n",vga_initcursor(argc-1));
vga_setmode(mode);
vga_setlinearaddressing();
vga_setcursorposition(100,100);
c2=malloc(256);
j=1;
for(i=0;i<32;i++) {
*(c2+i)=j;
*(c2+32+i)=j;
j<<=1;
}
if(vga_getcolors()==256)
for (i = 0; i < 60; ++i) {
j = (i * 64) / 60;
vga_setpalette(i + 16, j, j, j);
vga_setpalette(i + 16 + 60, j, 0, 0);
vga_setpalette(i + 16 + (2 * 60), 0, j, 0);
vga_setpalette(i + 16 + (3 * 60), 0, 0, j);
}
vga_setcursorimage(0,0,0,0xff0000,(unsigned char *)c2);
vga_setcursorimage(1,0,0,0xffffff,(unsigned char *)mag_glass_bits);
vga_setcursorimage(2,0,0xff1080,0x0f0fff,(unsigned char *)mag_glass_filled);
vga_selectcursor(1);
vga_showcursor(1);
vga_showcursor(2);
g=vga_getgraphmem();
#if 1
drawpattern();
#else
for(j=0;j<256*1024;j++) {
if((j&0x3ff)==0x3ff)usleep(1000);
*(g+2*j)=0x00;
*(g+2*j+1)=(j*83/69)&0xff;
}
for(j=256*1024;j<384*1024;j++) {
if((j&0x3ff)==0x3ff)usleep(1000);
*(g+2*j)=0;
*(g+2*j+1)=0;
}
for(j=384*1024;j<512*1024;j++) {
// if((j&0x3ff)==0x3ff)usleep(1000);
*(g+2*j)=0xff;
*(g+2*j+1)=0x7f;
}
for(j=512*1024;j<2048*1024;j++) {
// if((j&0x3ff)==0x3ff)usleep(1000);
*(g+2*j)=((j>>9)&1)*(((~j)>>4)&0x1f);
*(g+2*j+1)=(1-((j>>9)&1)) * ((j>>2)&0x7c);
}
#endif
i=1;
vga_showcursor(3);
s=3;
while(!(mouse_getbutton()&4)) {
mouse_waitforupdate();
vga_setcursorposition(mouse_getx(),mouse_gety());
if(mouse_getbutton()&1) {
vga_selectcursor(i=(i+1)%3);
}
#if 1
if(mouse_getbutton()&2) {
vga_showcursor(s=(s+1)%4);
}
#else
if(mouse_getbutton()&2) {
vga_dumpregs();
}
#endif
}
vga_setmode(TEXT);
return 0;
}

17
demos/eightbpp.xbm Normal file
View file

@ -0,0 +1,17 @@
#define eightbpp_width 23
#define eightbpp_height 66
static char eightbpp_bits[] = {
0x00,0xf0,0x01,0x00,0xfc,0x01,0x78,0xfc,0x03,0xfe,0x07,0x03,0xfe,0x03,0x02,
0xe3,0x03,0x02,0xc1,0x07,0x02,0x81,0x0f,0x03,0x81,0xff,0x03,0xc3,0xff,0x01,
0x7f,0xfe,0x01,0x7e,0x78,0x00,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x70,0x00,0x01,0xff,0x01,0xf1,0xff,0x01,0xff,0xff,0x03,
0xff,0x03,0x03,0xff,0x00,0x02,0x8f,0x00,0x02,0x40,0x00,0x03,0xc0,0xc0,0x03,
0xc0,0xff,0x01,0x80,0xff,0x01,0x80,0xff,0x00,0x00,0x3e,0x40,0x00,0x00,0x40,
0x00,0x00,0x78,0x40,0x80,0x7f,0x40,0xf8,0x7f,0xc0,0xff,0x7f,0xc0,0xff,0x47,
0xc0,0xff,0x41,0xc0,0x07,0x03,0x80,0x00,0x02,0x40,0x00,0x02,0x40,0x00,0x03,
0xc0,0xc0,0x03,0xc0,0xff,0x01,0x80,0xff,0x01,0x80,0xff,0x00,0x00,0x3e,0x40,
0x00,0x00,0x40,0x00,0x00,0x78,0x40,0x80,0x7f,0x40,0xf8,0x7f,0xc0,0xff,0x7f,
0xc0,0xff,0x47,0xc0,0xff,0x41,0xc0,0x07,0x03,0x80,0x00,0x02,0x40,0x00,0x02,
0x40,0x00,0x03,0xc0,0xc0,0x03,0xc0,0xff,0x01,0x80,0xff,0x01,0x80,0xff,0x00,
0x00,0x3e,0x00};

258
demos/eventtest.c Normal file
View file

@ -0,0 +1,258 @@
/* Program to test the vga_waitevent function. */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <vga.h>
#include <vgagl.h>
#include <vgamouse.h>
#include <vgakeyboard.h>
#define USE_RAWKEYBOARD
static int newcolor(void)
{
if (BYTESPERPIXEL == 1)
return random() % 15 + 1;
return gl_rgbcolor(random() & 255, random() & 255, random() & 255);
}
static void ping(void)
{
putchar('\a');
fflush(stdout);
}
/* read data from fd. Write string if '\n' encountered */
void process_input(int fd)
{
static char textbuf[80], *data = textbuf;
char inbuf[80];
int len, i;
len = read(fd, inbuf, 80);
if (len <= 0)
return;
for (i = 0; i < len; i++) {
if (inbuf[i] == '\n') {
*data = 0;
gl_write(0, 10, textbuf);
ping();
data = textbuf;
} else {
*data++ = inbuf[i];
}
}
}
void child(int fd)
{
time_t last_time = 0, now;
FILE *output;
output = fdopen(fd, "w");
for (;;) { /* when parent dies we get killed by SIGPIPE */
now = time(NULL);
if (now / 5 > last_time) { /* a new minute started */
last_time = now / 5;
fputs(ctime(&now), output);
fputc('\n', output);
fflush(output);
}
sleep(1);
}
}
int main(void)
{
struct timeval timeout;
fd_set inputs;
char bitmap[16 * 16 * 4]; /* big enough for 10x10 bitmap in any mode */
int vgamode, color, pipefd[2], x, y, button, event, cursorsize = 5;
char loop = 1, drawcursor = 1;
#ifdef USE_RAWKEYBOARD
char space_pressed = 0;
#endif
puts("This is a demo showing the abilities of the new vga_waitevent() function\n"
"If something goes wrong it might hang your machine. Thus hit <ctrl>-C now\n"
"to bailout if in doubt.\n"
"Use mouse to move cursor. 1-9,0 to set the cursor size. Space to change the\n"
"cursor color. Left button to draw. Right button or 'Q' to bailout.\n"
"The cursor goes on/off every half second by usage of a timeout passed to\n"
"vga_waitevent. Every 5 secs a string from a child process (the time) arrives\n"
"asynchronously and is displayed by the frontend.");
#ifdef USE_RAWKEYBOARD
puts("\nBEWARE! This has been compiled to use the raw keyboard. A crash might\n"
"render the console unusable. (but shouldn't).");
#endif
fputs("\nHit <Enter> if brave enough, else ^C to bailout: ", stdout);
fflush(stdout);
getchar();
fflush(stdin); /* clear I/O buffer */
pipe(pipefd);
if (fork() == 0) { /* fork off b4 touching graphix to avoid side effects */
close(pipefd[0]); /* Important: close reading side, else it remains */
/* opened by child when parent exits and we don't get */
/* a SIGPIPE! */
child(pipefd[1]);
}
vga_init();
vgamode = vga_getdefaultmode();
if (vgamode == -1)
vgamode = G320x200x256;
if (!vga_hasmode(vgamode)) {
printf("Mode not available.\n");
exit(-1);
}
/* Enable automatic mouse setup at mode set. */
vga_setmousesupport(1);
vga_setmode(vgamode);
/* Disable wrapping (default). */
/* mouse_setwrap(MOUSE_NOWRAP); */
gl_setcontextvga(vgamode);
gl_enableclipping();
/* There might be some scrap data in the serial buffer
from the mouse. It will make vga_waitevent block
because it thinks the mouse wants to send data but
then no mouse packet arrives. */
color = newcolor();
x = 0;
y = 0;
gl_setwritemode(WRITEMODE_OVERWRITE | FONT_COMPRESSED);
gl_setfont(8, 8, gl_font8x8);
gl_setfontcolors(0, newcolor());
#ifdef USE_RAWKEYBOARD
if (keyboard_init()) {
printf("Could not initialize keyboard.\n");
exit(1);
}
#endif
while (loop) {
gl_getbox(x, y, 10, 10, bitmap);
if (drawcursor) {
gl_hline(x, y, x + cursorsize, color);
gl_hline(x, y + cursorsize, x + cursorsize, color);
gl_line(x, y, x, y + cursorsize, color);
gl_line(x + cursorsize, y, x + cursorsize, y + cursorsize, color);
}
FD_ZERO(&inputs);
FD_SET(pipefd[0], &inputs);
timeout.tv_sec = 0;
timeout.tv_usec = 500000; /* 0.5 second time out */
event = vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT,
&inputs, NULL, NULL, &timeout);
gl_putbox(x, y, 10, 10, bitmap);
if (timeout.tv_sec || timeout.tv_usec) {
/* No timeout. An actual event occured. Reset to visible
cursor. Note:
This is actually a bug as the cursor will get visible on time
updates. However, it's better this way for demo/test
purposes. */
drawcursor = 1;
} else {
drawcursor ^= 1;
}
if (FD_ISSET(pipefd[0], &inputs))
process_input(pipefd[0]);
if (event & VGA_MOUSEEVENT) {
x = mouse_getx();
y = mouse_gety();
button = mouse_getbutton();
if (button & MOUSE_LEFTBUTTON)
gl_fillbox(x, y, cursorsize + 1, cursorsize + 1, color);
if (button & MOUSE_RIGHTBUTTON)
loop = 0;
}
if (event & VGA_KEYEVENT) {
#ifdef USE_RAWKEYBOARD
if (keyboard_keypressed(SCANCODE_1))
cursorsize = 0;
if (keyboard_keypressed(SCANCODE_2))
cursorsize = 1;
if (keyboard_keypressed(SCANCODE_3))
cursorsize = 2;
if (keyboard_keypressed(SCANCODE_4))
cursorsize = 3;
if (keyboard_keypressed(SCANCODE_5))
cursorsize = 4;
if (keyboard_keypressed(SCANCODE_6))
cursorsize = 5;
if (keyboard_keypressed(SCANCODE_7))
cursorsize = 6;
if (keyboard_keypressed(SCANCODE_8))
cursorsize = 7;
if (keyboard_keypressed(SCANCODE_9))
cursorsize = 8;
if (keyboard_keypressed(SCANCODE_0))
cursorsize = 9;
if (keyboard_keypressed(SCANCODE_Q))
loop = 0;
if (keyboard_keypressed(SCANCODE_SPACE)) {
if (!space_pressed) {
color = newcolor();
space_pressed = 1;
}
} else {
space_pressed = 0;
}
#else
switch (vga_getch()) {
case '1':
cursorsize = 0;
break;
case '2':
cursorsize = 1;
break;
case '3':
cursorsize = 2;
break;
case '4':
cursorsize = 3;
break;
case '5':
cursorsize = 4;
break;
case '6':
cursorsize = 5;
break;
case '7':
cursorsize = 6;
break;
case '8':
cursorsize = 7;
break;
case '9':
cursorsize = 8;
break;
case '0':
cursorsize = 9;
break;
case ' ':
color = newcolor();
break;
case 'q':
case 'Q':
loop = 0;
break;
default:
ping();
break;
}
#endif
}
}
#ifdef USE_RAWKEYBOARD
keyboard_close(); /* Don't forget this! */
#endif
vga_setmode(TEXT);
exit(0);
}

54
demos/fish_monster.h Normal file
View file

@ -0,0 +1,54 @@
/* Hand edited by M. Weller by from an original XPM file */
#define fish_monster_w 33
#define fish_monster_h 33
/* width height ncolors chars_per_pixel */
static unsigned char fish_monster233[] =
{0x00, 0xf1, 0xf4, 0x07, 0xff, 0xc0};
static unsigned short fish_monster555[] =
{0x0000, 0x125f, 0x431c, 0x7c00, 0x7fff, 0x001f};
static unsigned short fish_monster565[] =
{0x0000, 0x249f, 0x861c, 0xf800, 0xffff, 0x001f};
static unsigned int fish_monster888[] =
{
0x00000000,
0x002900ff,
0x0080e0e0,
0x00ff0000,
0x00ffffff,
0x000000ff};
/* pixels */
static char *fish_monster =
"dddddddddddd```dddddd``ddddddd``d"
"ddddddddddd`eee``dddd`e``ddd``e`d"
"ddddddd``````aaee`ddd`e`e```e`e`d"
"ddddd```bbbbb```ee`dd`aae`e`eab`d"
"dddd`ddd`bb```bb``e`dd``aaeaa``dd"
"ddd`dd```b`dd``bbb``dddd`bbb`dddd"
"dd``dd```b`d```bbbb`ddddd`b`ddddd"
"dd`b````bbb```bbbbbb`dddd`b`ddddd"
"d`bbbbbbbbbbbbbbbbbbb`dd`bb`ddddd"
"d`````bbb````bbbbbbbbb``bbbb`dddd"
"`ccccc```cccc``bbbbbbbbbbbbb`dddd"
"`cccccccccccccc`bbbbbbbbbbbb`dddd"
"d````ccccc````cc`bbbbbbbbbbbb`ddd"
"d`d`d`````d`d``cc`bbbbbbbbbbb`ddd"
"d`d`d`d`d`d`d```c`bbbbb``bbbb`ddd"
"dd`d``d`d```````cc`bbbbba`bbb`ddd"
"dddddd```````````c`bbbb`ae`bb`ddd"
"dddddd```````````c`bbbba`e`bb`ddd"
"ddd`dd```````````c`bbb`ae``b`dddd"
"dd`d`````````````c`b`aa`ee`b`dddd"
"dd`d`d`d`````d``cc`bb`ee``bb`dddd"
"d````d`d`d`d`d`cc`bbbb```bb`ddddd"
"`ccc`````d`d``ccc`bbbbbbbbb`ddddd"
"`cccccccc```cccc`bbbbbbbbbb`ddddd"
"d```ccccccccccc`bbbbbbbbbb`dddddd"
"dd`b````ccccc``bbbbbbbbbbb`dddddd"
"dd`bbbbb`````bbbbbbbbbbbb`ddddddd"
"ddd`bbbbbbbbbbbbbbbbbbbb`dddddddd"
"dddd`bbbbbbbbbbbbbbbbb``ddddddddd"
"ddddd``bbbbbbbbbbbbb``ddddddddddd"
"ddddddd```bbbbbbb```ddddddddddddd"
"dddddddddd```````dddddddddddddddd"
"ddddddddddddddddddddddddddddddddd";

164
demos/forktest.c Normal file
View file

@ -0,0 +1,164 @@
/* Program to test the svgalib keyboard functions. */
/* and stress vga_safety_fork() */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#include <vga.h>
#include <vgagl.h>
#include <vgakeyboard.h>
#define zero_sa_mask(maskptr) memset(maskptr, 0, sizeof(sigset_t))
static char sig2release[] =
{SIGHUP, SIGINT, SIGQUIT, SIGILL,
SIGTRAP, SIGIOT, SIGBUS, SIGFPE,
SIGSEGV, SIGPIPE, SIGALRM, SIGTERM,
SIGXCPU, SIGXFSZ, SIGVTALRM,
SIGPROF, SIGPWR};
static int newcolor(void)
{
if (BYTESPERPIXEL == 1)
return random() % 15 + 1;
return gl_rgbcolor(random() & 255, random() & 255, random() & 255);
}
static void timeout(int sig)
{
keyboard_close();
vga_setmode(TEXT);
puts("Automatic termination after 60 seconds.");
exit(1);
}
void shutdown(void)
{
puts("Shutdown called!");
}
int main(void)
{
struct sigaction siga;
int vgamode, color, leftpressed;
int x, y;
printf("\nWARNING: This program will set the keyboard to RAW mode.\n"
"The keyboard routines in svgalib have not been tested\n"
"very much. There may be no recovery if something goes\n"
"wrong.\n\n"
"Press ctrl-c now to bail out, enter to continue.\n"
"In the test itself, use 'q' or Escape to quit.\n"
"It will also terminate after 60 seconds.\n"
"Use any cursor keys to move, keypad 0 or enter to change color.\n\n"
"\aWARNING, this version of keytest explicitly removes all svgalib\n"
"automatic restore funcs, s.t. when you kill it from the outside\n"
"only vga_safety_fork() can rescue you. Use this svgalib test tool\n"
"with EXTREME! care.\n"
);
getchar();
vga_safety_fork(shutdown); /* Does already enter a videomode */
vga_init();
/* Never do this in your code! */
siga.sa_flags = 0;
zero_sa_mask(&(siga.sa_mask));
for (x = 0; x < sizeof(sig2release); x++) {
siga.sa_handler = SIG_DFL;
sigaction(sig2release[x], &siga, NULL);
}
vgamode = vga_getdefaultmode();
if ((vgamode == -1) || (vga_getmodeinfo(vgamode)->bytesperpixel != 1))
vgamode = G320x200x256;
if (!vga_hasmode(vgamode)) {
printf("Mode not available.\n");
exit(1);
}
vga_setmode(vgamode);
gl_setcontextvga(vgamode);
gl_enableclipping();
signal(SIGALRM, timeout);
/* This installs the default handler, which is good enough for most */
/* purposes. */
if (keyboard_init()) {
printf("Could not initialize keyboard.\n");
exit(1);
}
/* Translate to 4 keypad cursor keys, and unify enter key. */
keyboard_translatekeys(TRANSLATE_CURSORKEYS | TRANSLATE_KEYPADENTER |
TRANSLATE_DIAGONAL);
/* (TRANSLATE_DIAGONAL seems to give problems.) Michael: No doesn't...
but might not do what you expect.. */
alarm(60); /* Terminate after 60 seconds for safety. */
x = WIDTH / 2;
y = HEIGHT / 2;
color = newcolor();
leftpressed = 0;
for (;;) {
/* Draw moving box. */
gl_fillbox(x, y, 5, 5, color);
/* Draw key status bar at top of screen. */
gl_putbox(0, 0, 128, 1, keyboard_getstate());
/* Wait about 1/100th of a second. */
/* Note that use of this function makes things less */
/* smooth because of timer latency. */
usleep(10000);
keyboard_update();
/* Move. */
if (keyboard_keypressed(SCANCODE_CURSORLEFT))
x--;
if (keyboard_keypressed(SCANCODE_CURSORRIGHT))
x++;
if (keyboard_keypressed(SCANCODE_CURSORUP))
y--;
if (keyboard_keypressed(SCANCODE_CURSORDOWN))
y++;
/* Boundary checks. */
if (x < 0)
x = 0;
if (x >= WIDTH)
x = WIDTH - 1;
if (y < 1)
y = 1;
if (y >= HEIGHT)
y = HEIGHT - 1;
/* Check for color change. */
if (keyboard_keypressed(SCANCODE_KEYPAD0) ||
keyboard_keypressed(SCANCODE_ENTER)) {
if (!leftpressed) {
color = newcolor();
leftpressed = 1;
}
} else
leftpressed = 0;
if (keyboard_keypressed(SCANCODE_Q) ||
keyboard_keypressed(SCANCODE_ESCAPE))
break;
}
keyboard_close(); /* Don't forget this! */
vga_setmode(TEXT);
exit(0);
}

533
demos/fun.c Normal file
View file

@ -0,0 +1,533 @@
/* Roaming-blobs-on-mars-collect-some-dust-on-a-tropical-island-and-go-pearl-
diving-before-population-goes-out-of-control. */
/* Each frame, a background virtual screen is copied to a virtual screen; */
/* sprites (well, pixels) are written on that virtual screen; and the */
/* virtual screen is copied to video memory. The background is updated as */
/* appropriate. This simple animation technique works well for 320x200 */
/* because it's so small. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <vga.h>
#include <vgagl.h>
/* This can be changed into any 256 color mode. */
/* For planar 256 color modes, enable page flipping. */
/* Even 16 color modes work (ugly colors). */
#define VGAMODE G800x600x256
//#define USE_PAGEFLIPPING
/* #define USE_SMALLOC */
/* This is the size of the animated window. */
#define MAPWIDTH 800
#define MAPHEIGHT 560
#define MAXMOVERS 2000
#define MAXCITIES 1000
#define NUMBEROFCITIES 20
#define NUMBEROFMOVERS 1400
#define MOVERTHRESHOLD 1400
#define MOVERLIFETIME 1000
#define COLORTIME 2000
#define randomn( n ) (random() % n)
#define red(x) (32 + x)
#define green(x) (64 + x)
#define yellow(x) (96 + x)
#define blue(x) (128 + x)
#define magenta(x) (160 + x)
#define cyan(x) (192 + x)
#define white(x) (224 + x)
/* Data types */
typedef struct {
int x;
int y;
} Position;
#define STAT_ACTIVE 1
typedef struct {
int stat;
int x;
int y;
int vx;
int vy;
int color;
int time;
} Mover;
typedef struct {
int x;
int y;
int pop;
int hit;
} City;
/* Global variables */
int map[MAPWIDTH][MAPHEIGHT];
/* Map encoding i: */
/* (0 - 0xffff Mover number i) */
/* 0x10000... Part of city (i - 0x10000) */
Mover mover[MAXMOVERS];
int nu_movers = 0;
City city[MAXCITIES];
int nu_cities = 0;
int mytime = 0; /* used to be "time" but collids w/libc function time() */
int pop = 0;
int framerate, framecount, frameclock;
GraphicsContext *physicalscreen;
GraphicsContext *backscreen;
GraphicsContext *background;
void error(char *s)
{
printf("%s\n", s);
vga_setmode(TEXT);
exit(0);
}
void setcustompalette(void)
{
/* colors 0-31 are a RGB mix (bits 0 and 1 red, 2 green, 3 and 4 blue) */
/* 32-63 black to red */
/* 64-95 black to green */
/* 96-127 black to yellow */
/* 128-159 black to blue */
/* 160-191 black to magenta */
/* 192-223 black to cyan */
/* 224-255 black to white */
Palette pal;
int i;
for (i = 0; i < 256; i++) {
int r, g, b;
r = g = b = 0;
if ((i & 32) > 0)
r = (i & 31) << 1;
if ((i & 64) > 0)
g = (i & 31) << 1;
if ((i & 128) > 0)
b = (i & 31) << 1;
if (i < 32) {
r = (i & 3) << 4; /* 2 bits */
g = (i & 4) << 3; /* 1 bit */
b = (i & 24) << 1; /* 2 bits */
}
pal.color[i].red = r;
pal.color[i].green = g;
pal.color[i].blue = b;
}
gl_setpalette(&pal);
}
void initfont(void)
{
void *font;
#ifdef USE_SMALLOC
font = smalloc(256 * 8 * 8 * BYTESPERPIXEL);
#else
font = malloc(256 * 8 * 8 * BYTESPERPIXEL);
#endif
gl_expandfont(8, 8, white(24), gl_font8x8, font);
gl_setfont(8, 8, font);
}
int fsize(FILE * f)
{
int oldpos, size;
oldpos = ftell(f);
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, oldpos, SEEK_SET);
return size;
}
void loadfile(char **buf, char *fname)
{
FILE *f;
int size;
f = fopen(fname, "rb");
size = fsize(f);
*buf = malloc(size);
fread(*buf, 1, size, f);
fclose(f);
}
/* Map */
void clearmap(void)
{
int x, y;
for (y = 0; y < MAPHEIGHT; y++)
for (x = 0; x < MAPWIDTH; x++)
map[x][y] = 0;
}
Position
findfreeposition(void)
{
int x, y;
Position p;
do {
x = randomn(MAPWIDTH);
y = randomn(MAPHEIGHT);
}
while (map[x][y] != 0);
p.x = x;
p.y = y;
return p;
}
/* Movers */
void initmovers(void)
{
int i;
for (i = 0; i < MAXMOVERS; i++)
mover[i].stat = 0;
}
int findfreemoverslot(void)
{
int i;
for (i = 0; i < MAXMOVERS; i++)
if (!(mover[i].stat & STAT_ACTIVE))
return i;
error("Mover table overflow");
return 0;
}
void addrandommover(void)
{
Position p = findfreeposition();
int i = findfreemoverslot();
int c;
mover[i].x = p.x;
mover[i].y = p.y;
do {
mover[i].vx = randomn(3) - 1;
mover[i].vy = randomn(3) - 1;
}
while (mover[i].vx == 0 && mover[i].vy == 0);
mover[i].stat = STAT_ACTIVE;
switch (randomn(4)) {
case 0:
c = blue(20);
break;
case 1:
c = green(20);
break;
case 2:
c = magenta(20);
break;
default:
c = cyan(20);
break;
}
mover[i].time = 0;
mover[i].color = c;
nu_movers++;
}
void killmover(int i)
{
mover[i].stat = 0;
nu_movers--;
}
void drawmover(int i)
{
gl_setpixel(mover[i].x, mover[i].y, mover[i].color);
}
/* Cities */
void initcities(void)
{
nu_cities = 0;
}
void addcity(int x, int y)
{
int i = nu_cities++;
map[x][y] = i + 0x10000;
city[i].x = x;
city[i].y = y;
city[i].pop = 1;
city[i].hit = 0;
}
int cityat(int x, int y)
{
if (map[x][y] >= 0x10000)
return map[x][y] - 0x10000;
else
return -1;
}
int citycolor(void)
{
static int colortable[5] =
{yellow(31), blue(31), white(31), green(31), cyan(31)};
return colortable[(mytime / COLORTIME) % 5]
- (mytime % COLORTIME) * 25 / COLORTIME;
}
void growcity(int cx, int cy, int x, int y, int ct)
{
/* add city unit at (x, y) adjacent to city unit (cx, cy) */
int c;
map[x][y] = ct + 0x10000;
c = citycolor();
gl_setpixel(x, y, c);
city[ct].pop++;
city[ct].hit = 20;
pop++;
}
/* Main components */
void createbackground(void)
{
/* Create fancy dark red background */
int x, y;
for (y = 0; y < MAPHEIGHT; y++)
for (x = 0; x < MAPWIDTH; x++) {
int i = 0;
int n = 0;
int c;
if (x > 0) {
i += gl_getpixel(x - 1, y) - red(0);
n++;
}
if (y > 0) {
i += gl_getpixel(x, y - 1) - red(0);
n++;
}
c = (i + randomn(16)) / (n + 1);
if (c > 9)
c = 9;
gl_setpixel(x, y, red(0) + c);
}
}
void drawbackground(void)
{
/* Build up background from map data */
int x, y;
gl_setcontext(background);
gl_clearscreen(0);
createbackground();
for (y = 0; y < MAPHEIGHT; y++)
for (x = 0; x < MAPWIDTH; x++) {
int c = cityat(x, y);
if (c != -1)
gl_setpixel(x, y, citycolor());
}
}
void createcities(void)
{
int i;
for (i = 0; i < NUMBEROFCITIES; i++) {
Position p = findfreeposition();
addcity(p.x, p.y);
}
}
void writestat(void)
{
char s[41];
int i, x, y;
int maxpopcity, maxpop;
sprintf(s, "Pop %7d Time %7d Rate %5d.%d", pop, mytime,
framerate / 10, framerate % 10);
gl_setwritemode(WRITEMODE_OVERWRITE);
gl_write(0, HEIGHT - 8, s);
maxpop = -1;
maxpopcity = 0;
for (i = 0; i < nu_cities; i++)
if (city[i].pop > maxpop) {
maxpop = city[i].pop;
maxpopcity = i;
}
gl_enableclipping();
gl_circle(city[maxpopcity].x, city[maxpopcity].y, 10,
blue(31));
gl_disableclipping();
gl_setwritemode(WRITEMODE_MASKED);
x = city[maxpopcity].x;
y = city[maxpopcity].y;
sprintf(s, "%d", maxpop);
/* clipping */
if (x + strlen(s) * 8 > MAPWIDTH)
x = MAPWIDTH - strlen(s) * 8;
if (y + 8 > MAPHEIGHT)
y = MAPHEIGHT - 8;
gl_write(x, y, s);
}
void drawscreen(void)
{
int i;
/* Copy background to backscreen. */
gl_setcontext(background);
gl_copyscreen(backscreen);
/* Now draw the objects in backscreen. */
gl_setcontext(backscreen);
for (i = 0; i < MAXMOVERS; i++)
if (mover[i].stat & STAT_ACTIVE) {
drawmover(i);
}
writestat();
/* Copy backscreen to physical screen. */
gl_copyscreen(physicalscreen);
}
void move(void)
{
int i;
gl_setcontext(background);
for (i = 0; i < MAXMOVERS; i++)
if (mover[i].stat & STAT_ACTIVE) {
int nx, ny;
int c;
if (++mover[i].time == MOVERLIFETIME) {
killmover(i);
continue;
}
for (;;) {
nx = mover[i].x + mover[i].vx;
ny = mover[i].y + mover[i].vy;
if (nx < 0 || nx >= MAPWIDTH) {
mover[i].vx = -mover[i].vx;
continue;
}
if (ny < 0 || ny >= MAPHEIGHT) {
mover[i].vy = -mover[i].vy;
continue;
}
break;
}
c = cityat(nx, ny);
if (c != -1) { /* found city */
killmover(i);
growcity(nx, ny, mover[i].x, mover[i].y, c);
continue; /* next mover */
}
mover[i].x = nx;
mover[i].y = ny;
}
if (pop >= MAPWIDTH * MAPHEIGHT * 255 / 256) {
/* start all over again */
printf("fun: new run.\n");
pop = 0;
mytime = 0;
clearmap();
initcities();
createcities();
drawbackground();
}
}
void createmovers(void)
{
int i;
for (i = 0; i < NUMBEROFMOVERS; i++)
addrandommover();
}
int main(void)
{
vga_init();
clearmap();
initmovers();
createcities();
createmovers();
vga_setmode(VGAMODE);
gl_setcontextvga(VGAMODE);
physicalscreen = gl_allocatecontext();
gl_getcontext(physicalscreen);
#ifdef USE_PAGEFLIPPING
/* Try to enable page flipping. */
printf("pf=%i\n", gl_enablepageflipping(physicalscreen));
#endif
setcustompalette();
/* initfont() here caused trouble with planar 256 color modes. */
gl_setcontextvgavirtual(VGAMODE);
backscreen = gl_allocatecontext();
gl_getcontext(backscreen);
#ifdef USE_SMALLOC
free(backscreen->vbuf);
backscreen->vbuf = smalloc(BYTEWIDTH * HEIGHT);
gl_setcontext(backscreen);
#endif
initfont();
gl_setcontextvgavirtual(VGAMODE);
background = gl_allocatecontext();
gl_getcontext(background);
#ifdef USE_SMALLOC
free(background->vbuf);
background->vbuf = smalloc(BYTEWIDTH * HEIGHT);
gl_setcontext(background);
#endif
drawbackground();
framerate = 0;
framecount = 0;
frameclock = clock();
for (;;) {
int i;
drawscreen();
move();
for (i = 0; i < 4; i++)
if (nu_movers < MOVERTHRESHOLD)
addrandommover();
mytime++;
/* Update frame rate every 3 seconds. */
framecount++;
if (clock() - frameclock >= CLOCKS_PER_SEC) {
framerate = framecount * CLOCKS_PER_SEC / (clock() - frameclock);
framecount = 0;
frameclock = clock();
}
}
#ifndef USE_SMALLOC
gl_freecontext(backscreen);
gl_freecontext(background);
#endif
vga_setmode(TEXT);
exit(0);
}

61
demos/joytest.c Normal file
View file

@ -0,0 +1,61 @@
/*
* joytest.c 1.0
* Cpoyright (C) 1998 Daniel Engström <daniel.engstrom@riksnett.no>
*
*/
/*
* This is a simple joystick test program and an example
* how to write programs using the vgajoystick library routines
*/
/*
* usage: joytest <number>
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <vgajoystick.h>
char *axe_name[] = { "X", "Y", "Z", };
int main (int argc, char **argv)
{
int joystick, axes, buttons, i;
if (argc != 2) {
fprintf(stderr, "usage: joytest <number>\n");
exit (1);
}
joystick = atoi(argv[1]);
if (joystick_init(joystick, JOY_CALIB_STDOUT) < 0)
exit(1);
axes = joystick_getnumaxes(joystick);
buttons = joystick_getnumbuttons(joystick);
printf("Joystick %d has %d axes and %d buttons.\n", joystick, axes, buttons);
if (axes > 3)
axes = 3;
printf("Press enter to start testing ... (interrupt to exit)\n");
getchar();
for(;;)
{
while(!joystick_update());
for (i = 0; i < buttons; i++)
printf("B%d: %s ", i, joystick_getbutton(joystick, i) ? "down" : "up ");
for (i = 0; i < axes; i++)
printf("%s: %4d ", axe_name[i], joystick_getaxis(joystick, i));
putchar('\n');
usleep(100);
}
joystick_close(joystick);
return 0;
}

130
demos/keytest.c Normal file
View file

@ -0,0 +1,130 @@
/* Program to test the svgalib keyboard functions. */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <vga.h>
#include <vgagl.h>
#include <vgakeyboard.h>
static int newcolor(void)
{
if (BYTESPERPIXEL == 1)
return random() % 15 + 1;
return gl_rgbcolor(random() & 255, random() & 255, random() & 255);
}
static void timeout(int sig)
{
keyboard_close();
vga_setmode(TEXT);
puts("Automatic termination after 60 seconds.");
exit(1);
}
int main(void)
{
int vgamode, color, leftpressed;
int x, y;
vga_init();
vgamode = vga_getdefaultmode();
if ((vgamode == -1) || (vga_getmodeinfo(vgamode)->bytesperpixel != 1))
vgamode = G320x200x256;
if (!vga_hasmode(vgamode)) {
printf("Mode not available.\n");
exit(1);
}
printf("\nWARNING: This program will set the keyboard to RAW mode.\n"
"The keyboard routines in svgalib have not been tested\n"
"very much. There may be no recovery if something goes\n"
"wrong.\n\n"
"Press ctrl-c now to bail out, enter to continue.\n"
"In the test itself, use 'q' or Escape to quit.\n"
"It will also terminate after 60 seconds.\n"
"Use any cursor keys to move, keypad 0 or enter to change color.\n");
getchar();
vga_setmode(vgamode);
gl_setcontextvga(vgamode);
gl_enableclipping();
signal(SIGALRM, timeout);
/* This installs the default handler, which is good enough for most */
/* purposes. */
if (keyboard_init()) {
printf("Could not initialize keyboard.\n");
exit(1);
}
/* Translate to 4 keypad cursor keys, and unify enter key. */
keyboard_translatekeys(TRANSLATE_CURSORKEYS | TRANSLATE_KEYPADENTER |
TRANSLATE_DIAGONAL);
/* (TRANSLATE_DIAGONAL seems to give problems.) Michael: No doesn't...
but might not do what you expect.. */
alarm(60); /* Terminate after 60 seconds for safety. */
x = WIDTH / 2;
y = HEIGHT / 2;
color = newcolor();
leftpressed = 0;
for (;;) {
/* Draw moving box. */
gl_fillbox(x, y, 5, 5, color);
/* Draw key status bar at top of screen. */
gl_putbox(0, 0, 128, 1, keyboard_getstate());
/* Wait about 1/100th of a second. */
/* Note that use of this function makes things less */
/* smooth because of timer latency. */
usleep(10000);
keyboard_update();
/* Move. */
if (keyboard_keypressed(SCANCODE_CURSORLEFT))
x--;
if (keyboard_keypressed(SCANCODE_CURSORRIGHT))
x++;
if (keyboard_keypressed(SCANCODE_CURSORUP))
y--;
if (keyboard_keypressed(SCANCODE_CURSORDOWN))
y++;
/* Boundary checks. */
if (x < 0)
x = 0;
if (x >= WIDTH)
x = WIDTH - 1;
if (y < 1)
y = 1;
if (y >= HEIGHT)
y = HEIGHT - 1;
/* Check for color change. */
if (keyboard_keypressed(SCANCODE_KEYPAD0) ||
keyboard_keypressed(SCANCODE_ENTER)) {
if (!leftpressed) {
color = newcolor();
leftpressed = 1;
}
} else
leftpressed = 0;
if (keyboard_keypressed(SCANCODE_Q) ||
keyboard_keypressed(SCANCODE_ESCAPE))
break;
}
keyboard_close(); /* Don't forget this! */
vga_setmode(TEXT);
exit(0);
}

165
demos/linearfork.c Normal file
View file

@ -0,0 +1,165 @@
/* Program to test the svgalib keyboard functions. */
/* and stress vga_safety_fork() */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#include <vga.h>
#include <vgagl.h>
#include <vgakeyboard.h>
#define zero_sa_mask(maskptr) memset(maskptr, 0, sizeof(sigset_t))
static char sig2release[] =
{SIGHUP, SIGINT, SIGQUIT, SIGILL,
SIGTRAP, SIGIOT, SIGBUS, SIGFPE,
SIGSEGV, SIGPIPE, SIGALRM, SIGTERM,
SIGXCPU, SIGXFSZ, SIGVTALRM,
SIGPROF, SIGPWR};
static int newcolor(void)
{
if (BYTESPERPIXEL == 1)
return random() % 15 + 1;
return gl_rgbcolor(random() & 255, random() & 255, random() & 255);
}
static void timeout(int sig)
{
keyboard_close();
vga_setmode(TEXT);
puts("Automatic termination after 60 seconds.");
exit(1);
}
void shutdown(void)
{
puts("Shutdown called!");
}
int main(void)
{
struct sigaction siga;
int vgamode, color, leftpressed;
int x, y;
printf("\nWARNING: This program will set the keyboard to RAW mode.\n"
"The keyboard routines in svgalib have not been tested\n"
"very much. There may be no recovery if something goes\n"
"wrong.\n\n"
"Press ctrl-c now to bail out, enter to continue.\n"
"In the test itself, use 'q' or Escape to quit.\n"
"It will also terminate after 60 seconds.\n"
"Use any cursor keys to move, keypad 0 or enter to change color.\n\n"
"\aWARNING, this version of keytest explicitly removes all svgalib\n"
"automatic restore funcs, s.t. when you kill it from the outside\n"
"only vga_safety_fork() can rescue you. Use this svgalib test tool\n"
"with EXTREME! care.\n"
);
getchar();
vga_safety_fork(shutdown); /* Does already enter a videomode */
vga_init();
/* Never do this in your code! */
siga.sa_flags = 0;
zero_sa_mask(&(siga.sa_mask));
for (x = 0; x < sizeof(sig2release); x++) {
siga.sa_handler = SIG_DFL;
sigaction(sig2release[x], &siga, NULL);
}
vgamode = vga_getdefaultmode();
if ((vgamode == -1) || (vga_getmodeinfo(vgamode)->bytesperpixel != 1))
vgamode = G640x480x256;
if (!vga_hasmode(vgamode)) {
printf("Mode not available.\n");
exit(1);
}
vga_setmode(vgamode);
vga_setlinearaddressing();
gl_setcontextvga(vgamode);
gl_enableclipping();
signal(SIGALRM, timeout);
/* This installs the default handler, which is good enough for most */
/* purposes. */
if (keyboard_init()) {
printf("Could not initialize keyboard.\n");
exit(1);
}
/* Translate to 4 keypad cursor keys, and unify enter key. */
keyboard_translatekeys(TRANSLATE_CURSORKEYS | TRANSLATE_KEYPADENTER |
TRANSLATE_DIAGONAL);
/* (TRANSLATE_DIAGONAL seems to give problems.) Michael: No doesn't...
but might not do what you expect.. */
alarm(60); /* Terminate after 60 seconds for safety. */
x = WIDTH / 2;
y = HEIGHT / 2;
color = newcolor();
leftpressed = 0;
for (;;) {
/* Draw moving box. */
gl_fillbox(x, y, 5, 5, color);
/* Draw key status bar at top of screen. */
gl_putbox(0, 0, 128, 1, keyboard_getstate());
/* Wait about 1/100th of a second. */
/* Note that use of this function makes things less */
/* smooth because of timer latency. */
usleep(10000);
keyboard_update();
/* Move. */
if (keyboard_keypressed(SCANCODE_CURSORLEFT))
x--;
if (keyboard_keypressed(SCANCODE_CURSORRIGHT))
x++;
if (keyboard_keypressed(SCANCODE_CURSORUP))
y--;
if (keyboard_keypressed(SCANCODE_CURSORDOWN))
y++;
/* Boundary checks. */
if (x < 0)
x = 0;
if (x >= WIDTH)
x = WIDTH - 1;
if (y < 1)
y = 1;
if (y >= HEIGHT)
y = HEIGHT - 1;
/* Check for color change. */
if (keyboard_keypressed(SCANCODE_KEYPAD0) ||
keyboard_keypressed(SCANCODE_ENTER)) {
if (!leftpressed) {
color = newcolor();
leftpressed = 1;
}
} else
leftpressed = 0;
if (keyboard_keypressed(SCANCODE_Q) ||
keyboard_keypressed(SCANCODE_ESCAPE))
break;
}
keyboard_close(); /* Don't forget this! */
vga_setmode(TEXT);
exit(0);
}

422
demos/linearspeed.c Normal file
View file

@ -0,0 +1,422 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <vga.h>
#include <vgagl.h>
#include <sys/time.h>
#define LINEAR_ADDRESSING
int VGAMODE, USEGL;
GraphicsContext *physicalscreen;
GraphicsContext *backscreen;
int fast=0;
void screen1(void)
{
int x, y;
for (y = 0; y < HEIGHT; y++)
for (x = 0; x < WIDTH; x++)
/* limited RGB palette in 256-color modes */
/* some color information is not used in */
/* 15-bit color modes */
gl_setpixelrgb(x, y,
x * 256 / WIDTH,
255 - x * 256 / WIDTH,
y * 256 / HEIGHT);
}
void configure(void)
{
int allowed[GLASTMODE + 1];
for (;;) {
int i;
int m;
for (i = G320x200x16; i <= GLASTMODE; i++) {
allowed[i] = 0;
if (vga_hasmode(i)) {
printf("%2d %s\n", i, vga_getmodename(i));
allowed[i] = 1;
}
}
printf("\nWhich mode? ");
scanf("%d", &m);
getchar();
printf("\n");
if (m >= G320x200x16 && m <= GLASTMODE) {
VGAMODE = m;
if (vga_getmodeinfo(m)->bytesperpixel >= 1)
USEGL = 1;
else
USEGL = 0;
break;
}
}
vga_setmode(VGAMODE);
#ifdef LINEAR_ADDRESSING
vga_setlinearaddressing();
#endif
if (USEGL) {
gl_setcontextvga(VGAMODE);
physicalscreen = gl_allocatecontext();
gl_getcontext(physicalscreen);
}
}
void blit(void)
{
gl_clearscreen(0x86);
vga_imageblt(vga_getgraphmem(), 0, WIDTH - 128, HEIGHT - 128,
WIDTH * BYTESPERPIXEL);
/* vga_bitblt(0, 100 * WIDTH * BYTESPERPIXEL, 50, 50, WIDTH * BYTESPERPIXEL);
vga_fillblt(100 * BYTESPERPIXEL, 50, 50, WIDTH * BYTESPERPIXEL, 0x86);
*/
}
#if 0
/* May help on well-designed motherboards. */
/* IT DOES MAKE A DIFFERENCE! REP STOSL IS SLOWER */
/* (CL-GD5434 VLB zero-wait writes -- 2/3 cycles); rep stos takes 4 */
#if 1
static inline void *
__memset(void *s, char c, size_t count)
{
__asm__(
"cld\n\t"
"cmpl $12,%%edx\n\t"
"jl 1f\n\t" /* if (count >= 12) */
"movzbl %%al,%%ax\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"
"cmpl $32,%%ecx\n\t" /* do loop unrolling for */
"jl 2f\n\t" /* chunks of 128 bytes */
"jmp 3f\n\t"
".align 4,0x90\n\t"
"3:\n\t"
"movl %%eax,(%%edi)\n\t"
"movl %%eax,4(%%edi)\n\t"
"movl %%eax,8(%%edi)\n\t"
"movl %%eax,12(%%edi)\n\t"
"movl %%eax,16(%%edi)\n\t"
"movl %%eax,20(%%edi)\n\t"
"movl %%eax,24(%%edi)\n\t"
"movl %%eax,28(%%edi)\n\t"
"movl %%eax,32(%%edi)\n\t"
"movl %%eax,36(%%edi)\n\t"
"movl %%eax,40(%%edi)\n\t"
"movl %%eax,44(%%edi)\n\t"
"movl %%eax,48(%%edi)\n\t"
"movl %%eax,52(%%edi)\n\t"
"movl %%eax,56(%%edi)\n\t"
"movl %%eax,60(%%edi)\n\t"
"movl %%eax,64(%%edi)\n\t"
"movl %%eax,68(%%edi)\n\t"
"movl %%eax,72(%%edi)\n\t"
"movl %%eax,76(%%edi)\n\t"
"movl %%eax,80(%%edi)\n\t"
"movl %%eax,84(%%edi)\n\t"
"movl %%eax,88(%%edi)\n\t"
"movl %%eax,92(%%edi)\n\t"
"movl %%eax,96(%%edi)\n\t"
"movl %%eax,100(%%edi)\n\t"
"movl %%eax,104(%%edi)\n\t"
"movl %%eax,108(%%edi)\n\t"
"subl $32,%%ecx\n\t"
"movl %%eax,112(%%edi)\n\t"
"movl %%eax,116(%%edi)\n\t"
"movl %%eax,120(%%edi)\n\t"
"movl %%eax,124(%%edi)\n\t"
"addl $128,%%edi\n\t"
"cmpl $32,%%ecx\n\t"
"jge 3b\n\t"
"2:\n\t"
"rep ; stosl\n\t" /* fill remaining longwords */
"andl $3,%%edx\n" /* fill last few bytes */
"1:\tmovl %%edx,%%ecx\n\t" /* <= 12 entry point */
"rep ; stosb\n\t"
: : "a"(c), "D"(s), "d"(count)
: "ax", "cx", "dx", "di");
return s;
}
#else /* 8-bit writes. */
static inline void *
__memset(void *s, char c, size_t count)
{
__asm__(
"cld\n\t"
"cmpl $12,%%edx\n\t"
"jl 1f\n\t" /* if (count >= 12) */
"movzbl %%al,%%ax\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"
"cmpl $32,%%ecx\n\t" /* do loop unrolling for */
"jl 2f\n\t" /* chunks of 128 bytes */
"jmp 3f\n\t"
".align 4,0x90\n\t"
"3:\n\t"
"movb %%al,(%%edi)\n\t"
"movb %%al,1(%%edi)\n\t"
"movb %%al,2(%%edi)\n\t"
"movl %%al,3(%%edi)\n\t"
"movl %%al,4(%%edi)\n\t"
"movl %%al,5(%%edi)\n\t"
"movl %%al,6(%%edi)\n\t"
"movl %%al,7(%%edi)\n\t"
"movl %%al,8(%%edi)\n\t"
"movl %%al,9(%%edi)\n\t"
"movl %%al,10(%%edi)\n\t"
"movl %%al,11(%%edi)\n\t"
"movl %%al,12(%%edi)\n\t"
"movl %%al,13(%%edi)\n\t"
"movl %%al,14(%%edi)\n\t"
"movl %%al,15(%%edi)\n\t"
"movl %%al,16(%%edi)\n\t"
"movl %%al,17(%%edi)\n\t"
"movl %%al,18(%%edi)\n\t"
"movl %%al,19(%%edi)\n\t"
"movl %%al,20(%%edi)\n\t"
"movl %%al,21(%%edi)\n\t"
"movl %%al,22(%%edi)\n\t"
"movl %%al,23(%%edi)\n\t"
"movl %%al,24(%%edi)\n\t"
"movl %%al,25(%%edi)\n\t"
"movl %%al,26(%%edi)\n\t"
"movl %%al,27(%%edi)\n\t"
"movl %%al,28(%%edi)\n\t"
"subl $8,%%ecx\n\t"
"movl %%al,29(%%edi)\n\t"
"movl %%al,30(%%edi)\n\t"
"movl %%al,31(%%edi)\n\t"
"addl $32,%%edi\n\t"
"cmpl $8,%%ecx\n\t"
"jge 3b\n\t"
"2:\n\t"
"rep ; stosl\n\t" /* fill remaining longwords */
"andl $3,%%edx\n" /* fill last few bytes */
"1:\tmovl %%edx,%%ecx\n\t" /* <= 12 entry point */
"rep ; stosb\n\t"
: : "a"(c), "D"(s), "d"(count)
: "ax", "cx", "dx", "di");
return s;
}
#endif
#define memset __memset
#endif
void speed(void)
{
int i;
int start_clock;
int finish_clock;
int diff_clock;
unsigned char *vgabase = vga_getgraphmem()+128*1024;
char *base;
struct timeval tv1, tv2;
#ifndef LINEAR_ADDRESSING
if (VGAMODE >= G640x480x256)
vga_setpage(0);
#endif
base=malloc(655360);
gettimeofday(&tv1, NULL);
for (i = 0; i < 500; i++) {
memset(vgabase, i & 255, 1048576);
}
gettimeofday(&tv2, NULL);
diff_clock = (tv2.tv_sec-tv1.tv_sec)*1000000+(tv2.tv_usec-tv1.tv_usec);
printf("memset video memory timing: %3d.%1ds, %dM/s\n", diff_clock / 1000000,
(diff_clock % 1000000), 500000000 / diff_clock);
if(fast)return;
start_clock = clock();
for (i = 0; i < 500; i++) {
memcpy(vgabase, base, 655360);
}
finish_clock = clock();
diff_clock = (finish_clock - start_clock)*10/CLOCKS_PER_SEC;
printf("memcpy to video memory timing: %3d.%1ds, %dK/s\n", diff_clock / 10,
(diff_clock % 10), 64*5000*10 / diff_clock);
start_clock = clock();
for (i = 0; i < 500; i++) {
memcpy(base, vgabase, 655360);
}
finish_clock = clock();
diff_clock = (finish_clock - start_clock)*10/CLOCKS_PER_SEC;
printf("memcpy from video memory timing: %3d.%1ds, %dK/s\n", diff_clock / 10,
(diff_clock % 10), 64*5000*10 / diff_clock);
start_clock = clock();
for (i = 0; i < 500; i++) {
unsigned char *j;
unsigned char *k;
unsigned char *l;
l=vgabase;
k=base;
j=base;
j+=655360;
while(k<j)*(l++)=*(k++);
}
finish_clock = clock();
diff_clock = (finish_clock - start_clock)*10/CLOCKS_PER_SEC;
printf("byte copy to video memory timing: %3d.%1ds, %dK/s\n", diff_clock / 10,
(diff_clock % 10), 64*5000*10 / diff_clock);
}
void sysmem_speed(void)
{
int i;
int start_clock;
int finish_clock;
int diff_clock;
char *base, *base2;
base=malloc(655360);
base2=malloc(655360);
start_clock = clock();
for (i = 0; i < 500; i++) {
memset(base, i & 255, 655360);
}
finish_clock = clock();
diff_clock = (finish_clock - start_clock)*10/CLOCKS_PER_SEC;
printf("System memory timing: %3d.%1ds, %dK/s\n", diff_clock / 10,
(diff_clock % 10), 64*5000*10 / diff_clock);
start_clock = clock();
for (i = 0; i < 500; i++) {
memcpy(base, base2, 655360);
}
finish_clock = clock();
diff_clock = (finish_clock - start_clock)*10/CLOCKS_PER_SEC;
printf("To System memcpy timing: %3d.%1ds, %dK/s\n", diff_clock / 10,
(diff_clock % 10), 64*5000*10 / diff_clock);
start_clock = clock();
for (i = 0; i < 500; i++) {
unsigned char *j;
unsigned char *k;
unsigned char *l;
l=base2;
k=base;
j=base;
j+=655360;
while(k<j)*(l++)=*(k++);
}
finish_clock = clock();
diff_clock = (finish_clock - start_clock)*10/CLOCKS_PER_SEC;
printf("To System mem copy timing: %3d.%1ds, %dK/s\n", diff_clock / 10,
(diff_clock % 10), 64*5000*10 / diff_clock);
}
int main(int argc, char *argv[])
{
if(argc>1)fast=1;
vga_init();
printf("This is a video memory speed tester. Note that the first "
"screen doesn't test\nanything (nor does the 3 second pause "
"that follows).\n\n");
configure();
if (COLORS == 256)
gl_setrgbpalette(); /* set RGB palette */
if (USEGL)
screen1();
sleep(2);
/* vga_screenoff(); */
speed();
if(!fast)sysmem_speed();
vga_setmode(TEXT);
exit(0);
}

132
demos/lineart.c Normal file
View file

@ -0,0 +1,132 @@
/* A program to test any mode for linear. Default mode is G640x480x256 = 10
** or parameters may be used giving modes as integers.
** linp [mode mode ...]
** Don Secrest Oct. 1998
*/
#include <vga.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
static void screen(int mode)
{
int bpp,bott,endp,linlen,i,j,bii,col,p;
vga_modeinfo *minf;
unsigned char *vbuf;
int mem;
if(mode == 0)
{
printf("Usage:lineart [mode mode ...]\n\nwhere mode is an integer.\n");
return;
}
if(! vga_hasmode(mode)) {
printf("Invalid mode %d\n",mode);
return;
}
vga_setmode(mode);
minf = vga_getmodeinfo(mode);
if(! (minf->flags & CAPABLE_LINEAR)){
vga_setmode(TEXT);
printf("The mode %d is not capable of linear\n",mode);
return;
}
vga_setpage(0);
if(vga_setlinearaddressing() == -1) {
vga_setmode(TEXT);
printf("Could not set linear addressing for mode %d\n",mode);
return;
}
bpp = minf->bytesperpixel;
linlen = minf->width*bpp;
bott = linlen*17; /* pointer 17 pixels wide. */
endp = linlen*minf->height;
mem = minf->linewidth*minf->height;
/* Do random pixels */
vbuf = vga_getgraphmem();
printf("Memory mapped to %08x. Mode = %d.\n",(int) vbuf,mode);
memset(vbuf,0,mem); /* Clear out 2 megabytes of memory, */
for(i = 0;i < 100000;i++)
{
p = rand() % mem-2;
*(vbuf + p) = rand() & 0xff;
if(bpp > 1)
*(vbuf + p + 1) = rand() & 0xff;
if(bpp == 3)
*(vbuf + p + 2) = rand() & 0xff;
}
/* Place marker at top left and bottem right. */
for(i = 0;i < 44;i += bpp) {
*(vbuf + i) = 0x60;
*(vbuf + bott + i) = 0x60;
*(vbuf + endp - i) = 0x60;
bii = endp -1 -bott;
*(vbuf + bii -i) = 0x60;
if(bpp > 1) {
*(vbuf + i + 1) = 0x60;
*(vbuf + i + 1 + bott) = 0x60;
*(vbuf - i - 1 + endp) = 0x60;
*(vbuf - i - 1 + bii) = 0x60;
}
if(bpp == 3) {
*(vbuf + i + 2) = 0x60;
*(vbuf + i + 2 + bott) = 0x60;
*(vbuf - i - 2 + endp) = 0x60;
*(vbuf - i - 2 + bii) = 0x60;
}
col = (i == 0 || i >= 42)? 0x60:0;
for(j = 1;j < 17;j++) {
*(vbuf + i + linlen*j) = col;
*(vbuf - i + endp -1 - linlen*j) = col;
if(bpp > 1) {
*(vbuf + i + 1 + linlen*j) = col;
*(vbuf - i - 2 + endp - linlen*j) = col;
}
if(bpp == 3) {
*(vbuf + i + 2 + linlen*j) = col;
*(vbuf - i - 3 + endp - linlen*j) = col;
}
}
}
for(i = 5;i < 12;i += bpp)
for(j = 4;j < 12;j++) {
*(vbuf + i + linlen*j) = 0x3f;
*(vbuf + endp - i - bpp - linlen*j) = 0x3f;
}
getchar(); /* Wait for a key punch */
}
int
main(int argc,char *argv[])
{
int mode,c;
vga_init();
c=1;
if(argc == 1)
screen(10); /* G640x480x256 */
else
c = 0;
while(argc > 1)
{
argc--;
c++;
if(isdigit(*argv[c]))
mode = atoi(argv[c]);
else if(*argv[c] == 'G')
mode = vga_getmodenumber(argv[c]);
else
{
printf("Unknown mode %s\n",argv[c]);
continue;
}
screen(mode);
}
vga_setmode(TEXT);
return 0;
}

1
demos/linuxlogo.bitmap Normal file

File diff suppressed because one or more lines are too long

91
demos/memset.c Normal file
View file

@ -0,0 +1,91 @@
/* Set a block of memory to some byte value.
For Intel 80x86, x>=3.
Copyright (C) 1991, 1992, 1993, 1997, 1998 Free Software Foundation, Inc.
Contributed by Torbjorn Granlund (tege@sics.se).
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <string.h>
#ifdef __i386__
#if defined(__GNUC__)
#undef memset
#define op_t unsigned int
#define OPSIZ 4
void *
memset (void *dstpp, int c, size_t len)
{
int d0;
unsigned long int dstp = (unsigned long int) dstpp;
/* This explicit register allocation
improves code very much indeed. */
register op_t x asm("ax");
x = (unsigned char) c;
/* Clear the direction flag, so filling will move forward. */
asm volatile("cld");
/* This threshold value is optimal. */
if (len >= 12)
{
/* Fill X with four copies of the char we want to fill with. */
x |= (x << 8);
x |= (x << 16);
/* Adjust LEN for the bytes handled in the first loop. */
len -= (-dstp) % OPSIZ;
/* There are at least some bytes to set.
No need to test for LEN == 0 in this alignment loop. */
/* Fill bytes until DSTP is aligned on a longword boundary. */
asm volatile("rep\n"
"stosb" /* %0, %2, %3 */ :
"=D" (dstp), "=c" (d0) :
"0" (dstp), "1" ((-dstp) % OPSIZ), "a" (x) :
"memory");
/* Fill longwords. */
asm volatile("rep\n"
"stosl" /* %0, %2, %3 */ :
"=D" (dstp), "=c" (d0) :
"0" (dstp), "1" (len / OPSIZ), "a" (x) :
"memory");
len %= OPSIZ;
}
/* Write the last few bytes. */
asm volatile("rep\n"
"stosb" /* %0, %2, %3 */ :
"=D" (dstp), "=c" (d0) :
"0" (dstp), "1" (len), "a" (x) :
"memory");
return dstpp;
}
#else /* __GNUC__ */
#include <sysdeps/generic/memset.c>
#endif
#endif /* __i386__ */

291
demos/mjoytest.c Normal file
View file

@ -0,0 +1,291 @@
/* Program to test the svgalib joystick functions. */
/* Written by M. Weller <eowmob@exp-math.uni-essen.de> */
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <vga.h>
#include <vgagl.h>
#include <vgamouse.h>
#include <vgajoystick.h>
#include <vgakeyboard.h>
extern char *optarg;
extern int optind, opterr, optopt;
#define PENCILSIZE 5
struct {
int wx; /* xoffset to add to scaled joystick position to get cx */
int cx, cy; /* onscreen coords of pencil */
int jx, jy; /* current joystick status */
int tx; /* onscreen xcoord of text for joypos */
char bitmap[PENCILSIZE * PENCILSIZE * 4]; /* big enough in any screen mode */
int ox, oy; /* location of saved patch, ox < 0 for no data saved */
int color; /* drawing color */
int drawing; /* we are drawing (actually shadows button 1 state) */
int newpos; /* cx/cy changed, draw new pencil position */
} joypanel[2];
int wy, sx, sy, ty; /* wy, ty y coords of wx, tx. sx/sy are scale values:
* (jx * sx + 128) / 256 is pencil coords (add wx for screen
* coords). Same for y. */
int newcolor(void)
{
if (BYTESPERPIXEL == 1)
return random() % 15 + 1;
return gl_rgbcolor(random() & 255, random() & 255, random() & 255);
}
void draw_pencil(int i) {
char msg[100];
if (!joypanel[i].newpos)
return;
sprintf(msg, "x = %4d, y = %4d", joypanel[i].jx, joypanel[i].jy);
gl_write(joypanel[i].tx, ty, msg);
if (joypanel[i].ox >= 0)
gl_putbox(joypanel[i].ox, joypanel[i].oy, PENCILSIZE, PENCILSIZE, joypanel[i].bitmap);
/* If not drawing, save destination area */
if (!joypanel[i].drawing)
gl_getbox(joypanel[i].ox = joypanel[i].cx, joypanel[i].oy = joypanel[i].cy,
PENCILSIZE, PENCILSIZE, joypanel[i].bitmap);
else
joypanel[i].ox = -1;
gl_fillbox(joypanel[i].cx, joypanel[i].cy, PENCILSIZE, PENCILSIZE, joypanel[i].color);
joypanel[i].newpos = 0;
}
void init_screen(void) {
int white;
gl_clearscreen(0);
white = vga_white();
gl_line(0, 0, WIDTH - 2, 0, white);
gl_line(0, 0, 0, HEIGHT - 1, white);
gl_line(WIDTH/2, 0, WIDTH/2, HEIGHT - 1, white);
gl_line(WIDTH - 2, 0, WIDTH - 2 , HEIGHT - 1, white);
gl_line(0, 11, WIDTH - 2, 11, white);
gl_line(0, HEIGHT - 1, WIDTH - 2, HEIGHT - 1, white);
ty = 2;
sx = WIDTH / 2 - 3 - PENCILSIZE;
sy = HEIGHT - 6 - PENCILSIZE - 9;
wy = 2 + 8 + 3 + (((sy << 7) + 128) >> 8);
joypanel[0].color = white;
joypanel[0].drawing = 0;
joypanel[0].newpos = 1;
joypanel[0].ox = -1;
joypanel[0].tx = 2;
joypanel[0].jx = 0;
joypanel[0].jy = 0;
joypanel[0].wx = 2 + (((sx << 7) + 128) >> 8);
joypanel[0].cx = joypanel[0].wx;
joypanel[0].cy = wy;
draw_pencil(0);
joypanel[1].color = white;
joypanel[1].drawing = 0;
joypanel[1].newpos = 1;
joypanel[1].ox = -1;
joypanel[1].tx = WIDTH / 2 + 2;
joypanel[1].jx = 0;
joypanel[1].jy = 0;
joypanel[1].wx = joypanel[0].wx + joypanel[1].tx;
joypanel[1].cx = joypanel[0].cx + joypanel[1].tx;
joypanel[1].cy = wy;
draw_pencil(1);
}
void myhandler(int event, int number, char value, int joydev) {
#if 0
printf("%d: %d %d %d\n", joydev, event, number, (int)value);
#endif
switch(event) {
case JOY_EVENTBUTTONUP:
if (!number)
joypanel[joydev].drawing = 0;
else {
joypanel[joydev].color = newcolor();
joypanel[joydev].newpos = 1;
}
break;
case JOY_EVENTBUTTONDOWN:
if (!number)
joypanel[joydev].drawing = 1;
break;
case JOY_EVENTAXIS:
switch(number) {
case 0: /* x */
joypanel[joydev].jx = value;
joypanel[joydev].cx = joypanel[joydev].wx + ((((int)value) * sx + 128) / 256);
joypanel[joydev].newpos = 1;
break;
case 1:
joypanel[joydev].jy = value;
joypanel[joydev].cy = wy + ((((int)value) * sy + 128) / 256);
joypanel[joydev].newpos = 1;
break;
}
}
/* Note that any reserved events are ignored */
}
void usage(void) {
puts("Usage: mjoytest [-j <joystick number>] [svgalib mode]\n"
"\ttest multiple joystick support and joystick sharing.");
exit(1);
}
void mycalout(const char *msg) {
gl_printf(-1, -1, msg);
}
int main(int argc, char *argv[]) {
int vgamode = -1;
int which, joymask = 3;
struct timeval timeout;
while(EOF != (which = getopt(argc, argv, "j:m:"))) {
switch(which) {
case 'j':
if (!strcmp(optarg, "0"))
joymask = 1;
else if (!strcmp(optarg, "1"))
joymask = 1;
else
usage();
break;
case 'm':
vgamode = vga_getmodenumber(optarg);
if (vgamode < 0)
usage();
break;
default:
usage();
}
}
if (optind < argc) {
if (optind != 1 + argc)
usage();
if (vgamode >= 0)
usage();
vgamode = vga_getmodenumber(argv[optind]);
if (vgamode < 0)
usage();
}
vga_init();
if (vgamode < 0)
vgamode = vga_getdefaultmode();
if (vgamode < 0)
vgamode = G320x200x256;
if (!vga_hasmode(vgamode)) {
printf("Mode not available.\n");
exit(-1);
}
puts("In the demo, press\n"
"<1> to calibrate joystick 1.\n"
"<2> to calibrate joystick 2.\n"
"<c> to clear the screen (<1> & <2> do this too).\n"
"<q> to exit (<Ctrl>-C should work too.\n"
"Joystick button 1 enables drawing while pressed.\n"
"Joystick button 2 selects next color.\n"
"\nNow hit <Return> to start the demo.");
getchar();
fflush(stdin);
for (which = 0; which < 2; which++) {
if (!(joymask & (1 << which)))
continue;
errno = 0;
if (joystick_init(which, JOY_CALIB_STDOUT) < 0) {
if (errno)
printf("Unable to initialize joystick %d: %s.\n", which, strerror(errno));
else
printf("Unable to initialize joystick %d.\n", which);
}
}
joystick_sethandler(-1, myhandler);
vga_setmode(vgamode);
gl_setcontextvga(vgamode);
gl_setwritemode(FONT_COMPRESSED | WRITEMODE_OVERWRITE);
gl_setfontcolors(0, vga_white());
gl_setfont(8, 8, gl_font8x8);
init_screen();
for(;;) {
timeout.tv_sec = 0;
timeout.tv_usec = 10000;
which = vga_waitevent(VGA_KEYEVENT, NULL, NULL, NULL, &timeout);
if (which & VGA_KEYEVENT) {
switch(vga_getch()) {
case '1':
gl_printf(2, 2, "");
if (1 & joymask) {
vga_lockvc();
joystick_init(0, mycalout);
/* IMPORTANT, reenable ownhandler! */
joystick_sethandler(0, myhandler);
vga_unlockvc();
}
init_screen();
break;
case '2':
gl_printf(2, 2, "");
if (2 & joymask) {
vga_lockvc();
joystick_init(1, mycalout);
/* IMPORTANT, reenable ownhandler! */
joystick_sethandler(1, myhandler);
vga_unlockvc();
}
init_screen();
break;
case 'c':
case 'C':
init_screen();
break;
case 'q':
case 'Q':
goto leave_loop;
default:
putchar('\a');
fflush(stdout);
break;
}
}
which = joystick_update();
if (which & 1);
draw_pencil(0); /* It makes only sense to check for the newpos flag
* if something happened with the joystick at all */
if (which & 2);
draw_pencil(1);
}
leave_loop:
printf("Shutting down.\n");
vga_setmode(TEXT);
exit(0);
}

223
demos/mkcur.c Normal file
View file

@ -0,0 +1,223 @@
/* Make cursor mkcur.c A program to build a cursor. Started Jan 27, 2001 */
/* Don Secrest */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <vga.h>
#include <vgagl.h>
#include <vgamouse.h>
#include "arrow.h"
unsigned char *fnt=0;
static int software = 0,psiz;
static unsigned int sprt[64] = {0};
void usage(void)
{
puts("Usage:\n"
"buildcsr -p<sprite> -b<sprite> -m<mode> -s\n"
"\tDraw sprite by holding down the left mouse button.\n"
"\tDraw color 2 type 2 and use left button.\n"
"\tRight mouse button to erase pixels.\n"
"\t-p print out the sprite as a header file to be compiled\n"
"\t-b print out the sprite as a binary file to be read by a program\n"
"\t-m to use any mode. Default is vga_default mode or G640x480x256.\n"
"\t-s to use software cursor. Default is to use hardware cursor if it\n"
"\t exits."
);
exit(2);
};
void setcursor(int *arrow,int cursor, int color0, int color1)
{
static int init = 1;
if(init)
{
init = 0;
if(cursor != 0)
vga_setcursorimage(cursor,0,color0,color1,(void *)arrow);
else
{
vga_setmousesupport(1);
vga_initcursor(software);
}
}
vga_setcursorimage(cursor,0,color0,color1,(void *) arrow);
/* if(vga_selectcursor(0) == -1)
{
vga_setmode(TEXT);
printf("Cursor select failure.\n");
exit(1);
} */
vga_selectcursor(cursor);
mouse_setposition(0,0);
mouse_setxrange(-5,psiz - 1);
mouse_setyrange(0,psiz - 1);
return;
};
int main(int argc,char **argv)
{
int vgamode,opt,vmode=0,color1,color2,xmax,ymax,i,j,px,dx,colnum;
int colors;
char *nameb=0,*namep=0;
FILE *binfile=0,*progfile=0;
while(EOF !=(opt = getopt(argc,argv,"p:b:m:s")))
switch(opt){
case 'p':
namep = optarg;
break;
case 'b':
nameb = optarg;
break;
case 'm':
vmode = atoi(optarg);
break;
case 's':
software = 1;
break;
case ':':
printf("Missingh argument.\n");
usage();
case '?':
printf("Unknown argument, %c\n",optopt);
usage();
}
vga_init();
if(vmode)
vgamode = vmode;
else
vgamode = vga_getdefaultmode();
if(vgamode == -1)
vgamode = G640x480x256;
if(!vga_hasmode(vgamode)){
printf("Mode %d not available\n",vgamode);
exit(1);
}
vga_setmode(vgamode);
gl_setcontextvga(vgamode);
gl_enableclipping();
fnt = gl_font8x8;
gl_setfont(8,8,fnt);
gl_setwritemode(FONT_COMPRESSED + WRITEMODE_OVERWRITE);
gl_setfontcolors(0,vga_white());
colors = color1 = gl_rgbcolor(0,200,0);
color2 = gl_rgbcolor(100,0,100);
xmax = vga_getxdim();
ymax = vga_getydim();
colnum = vga_getcolors();
if(colnum == 256)
vga_setcolor(vga_white());
else
vga_setrgbcolor(255,255,255);
psiz = (xmax < ymax)?xmax:ymax;
i = (psiz -8)/32;
psiz = i*32 - 1;
j = (i*5)/6;
px = j;
dx = i;
setcursor(arrow,0,0xff0000,0x0000ff);
vga_drawline(0,0,psiz+1,0);
vga_drawline(psiz+1,0,psiz+1,psiz);
vga_drawline(psiz+1,psiz,0,psiz);
vga_drawline(0,psiz,0,0);
gl_printf(1,psiz+1,"Type n: new sprite, o: old, q: quit");
gl_fillbox(290,psiz+1,px,px,colors);
do
{
int evt,mx,my,button,key;
evt = vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT,NULL,NULL,NULL,NULL);
if(evt & VGA_KEYEVENT)
{
key = vga_getkey();
if(key == 'q' || key == 'Q')
break;
if(key == 'n')
{
setcursor(sprt,1,0xff0000,0x0000ff);
}
if(key == 'o')
{
setcursor(arrow,0,0xff0000,0x0000ff);
}
if(key == '2')
{
colors = color2;
gl_fillbox(290,psiz+1,px,px,colors);
}
if(key == '1')
{
colors = color1;
gl_fillbox(290,psiz+1,px,px,colors);
}
}
if(evt & VGA_MOUSEEVENT)
{
int x,y,add;
unsigned int loc;
button = 0;
mouse_update();
mx = mouse_getx();
my = mouse_gety();
button = mouse_getbutton();
vga_setcursorposition(mx,my);
vga_showcursor(1);
if(button)
{
vga_showcursor(2);
x = 1 + (mx/dx)*dx;
y = 1 + (my/dx)*dx;
gl_fillbox(x,y,px,px,colors);
add = y/dx +32;
loc = 1 << (31 - x/dx);
if(button & 4)
{
sprt[add] = sprt[add] | loc;
if(colors == color2)
sprt[add - 32] = sprt[add - 32] | loc;
}
else if(button & 1)
{
vga_showcursor(2);
x = 1 + (mx/dx)*dx;
y = 1 + (my/dx)*dx;
gl_fillbox(x,y,px,px,0);
sprt[add] = sprt[add] & (~loc); /* erase it. */
sprt[add - 32] = sprt[add - 32] & (~loc);
}
}
}
}while(1);
vga_setmode(TEXT);
if(namep)
{
if((progfile = fopen(namep,"w")))
{
fprintf(progfile,"unsigned int %s[64] = {\n",namep);
for(i = 0;i < 63;i++)
{
fprintf(progfile,"0x%08x, ",sprt[i]);
if((i+1)%4 == 0)
fprintf(progfile,"\n");
}
fprintf(progfile,"0x%08x};\n",sprt[63]);
}
else
printf("Unable to open file %s.\n",namep);
}
if(nameb)
{
if((binfile = fopen(nameb,"w")))
fwrite(sprt,4,64,binfile);
else
printf("Unable to open file %s.\n",nameb);
}
printf("psiz = %d, px = %d, dx = %d\n",psiz,px,dx);
return(0);
}

140
demos/mousetest.c Normal file
View file

@ -0,0 +1,140 @@
/* Program to test the svgalib mouse functions. */
/* Updated to use middle button and rx axis (for wheel mice)
by Brion Vibber <brion@pobox.com>, 5 July 1998 */
#include <stdlib.h>
#include <stdio.h>
#include <vga.h>
#include <vgagl.h>
#include <vgamouse.h>
#include <vgakeyboard.h>
/* Manually open and close mouse? */
#define MANUALLY_SETUP_MOUSE_NOT
static int newcolor(void)
{
if (BYTESPERPIXEL == 1)
return random() % 15 + 1;
return gl_rgbcolor(random() & 255, random() & 255, random() & 255);
}
int main(void)
{
int vgamode, color, leftpressed, middlepressed;
int x, y, rx, ox, oy, boxsize, button, wheel;
struct MouseCaps caps;
vga_init();
vgamode = vga_getdefaultmode();
if (vgamode == -1)
vgamode = G320x200x256;
if (!vga_hasmode(vgamode)) {
printf("Mode not available.\n");
exit(-1);
}
#ifndef MANUALLY_SETUP_MOUSE
/* Enable automatic mouse setup at mode set. */
vga_setmousesupport(1);
#endif
vga_setmode(vgamode);
/* Disable wrapping (default). */
/* mouse_setwrap(MOUSE_NOWRAP); */
gl_setcontextvga(vgamode);
gl_enableclipping();
#ifdef MANUALLY_SETUP_MOUSE
mouse_init("/dev/mouse", MOUSE_MICROSOFT, MOUSE_DEFAULTSAMPLERATE);
mouse_setxrange(0, WIDTH - 1);
mouse_setyrange(0, HEIGHT - 1);
mouse_setwrap(MOUSE_NOWRAP);
#endif
/* Check the mouse capabilities */
if(mouse_getcaps(&caps)) {
/* Failed! Old library version... Check the mouse type. */
switch(vga_getmousetype() & MOUSE_TYPE_MASK) {
case MOUSE_INTELLIMOUSE:
case MOUSE_IMPS2:
wheel = 1;
break;
default:
wheel = 0;
}
} else {
/* If this is a wheel mouse, interpret rx as a wheel */
wheel = ((caps.info & MOUSE_INFO_WHEEL) != 0);
}
/* To be able to test fake mouse events... */
if (keyboard_init()) {
printf("Could not initialize keyboard.\n");
exit(1);
}
/* Set the range for the wheel */
if(wheel)
mouse_setrange_6d(0,0, 0,0, 0, 0, -180,180, 0,0, 0,0, MOUSE_RXDIM);
color = newcolor();
leftpressed = middlepressed = x = y = rx = ox = oy = 0;
boxsize = 5;
for (;;) {
keyboard_update();
gl_fillbox(x, y, boxsize, boxsize, color);
mouse_update();
/* The RX axis represents the wheel on an wheel mouse */
mouse_getposition_6d(&x, &y, NULL, &rx, NULL, NULL);
if(wheel && rx) {
/* For clarity - wipe the old location out
so we can redraw with the new box size */
gl_fillbox(ox, oy, boxsize, boxsize, 0);
/* Interpret wheel turns; we care only about direction,
not amount, for our purposes */
boxsize += (rx / abs(rx));
(boxsize < 1)?(boxsize = 1):((boxsize > 10)?(boxsize = 10):0);
/* Zero the wheel position */
mouse_setposition_6d(0,0,0, 0,0,0, MOUSE_RXDIM);
}
ox = x; oy = y;
button = mouse_getbutton();
if (button & MOUSE_LEFTBUTTON) {
if (!leftpressed) {
color = newcolor();
leftpressed = 1;
}
} else
leftpressed = 0;
if (button & MOUSE_MIDDLEBUTTON) {
if (!middlepressed) {
/* Move the cursor to a random location */
mouse_setposition_6d(random() % WIDTH, random() % HEIGHT,0,
0,0,0,
MOUSE_2DIM);
middlepressed = 1;
}
} else
middlepressed = 0;
if (button & MOUSE_RIGHTBUTTON)
break;
}
#ifdef MANUALLY_SETUP_MOUSE
mouse_close();
#endif
vga_setmode(TEXT);
exit(0);
}

72
demos/printftest.c Normal file
View file

@ -0,0 +1,72 @@
/* Program to test the svgalib keyboard functions. */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <vga.h>
#include <vgagl.h>
#include <vgakeyboard.h>
void usage(void)
{
puts("Usage: printftest <x> <y>\n"
"\tread text from keyboard and display it on screen\n"
"\tat position (x, y).\n"
"\t<ctrl>-D for quit\n"
"\t<ctrl>-R for carriage return\n"
"\t<Return> for line feed\n"
"\t<Tab> for tab\n"
"\t<ctrl>-G for bell\n"
"\t<ctrl>-H for backspace (non overwriting)\n"
);
exit(2);
}
int main(int argc, char **argv)
{
int x, y;
char buffer[2];
int vgamode;
int key, retval = 0;
if (argc != 3)
usage();
if (1 != sscanf(argv[1], "%d%c", &x, buffer))
usage();
if (1 != sscanf(argv[2], "%d%c", &y, buffer))
usage();
vga_init();
vgamode = vga_getdefaultmode();
if (vgamode == -1)
vgamode = G320x200x256;
if (!vga_hasmode(vgamode)) {
printf("Mode not available.\n");
exit(1);
}
vga_setmode(vgamode);
gl_setcontextvga(vgamode);
gl_enableclipping();
gl_setfont(8, 8, gl_font8x8);
gl_setwritemode(FONT_COMPRESSED + WRITEMODE_OVERWRITE);
gl_setfontcolors(0, vga_white());
buffer[1] = 0;
for(;;) {
key = vga_getch();
if (key == 4)
break;
if (key == 18)
key = '\r';
buffer[0] = key;
gl_printf(x, y, "%s", buffer);
x = y = -1;
}
vga_setmode(TEXT);
exit(retval);
}

83
demos/rwpage.pp Normal file
View file

@ -0,0 +1,83 @@
PROGRAM ScrollTest;
Uses svgalib;
type
VideoMemType = array[0..65535] of byte;
var
i,mode,StartupMode : longint;
SeparateReadWriteWindows : boolean;
modeinfo : ^vga_modeinfo;
VideoMem : ^VideoMemType;
p : pointer;
Procedure DrawRectangle(x1,y1,x2,y2 : integer);
begin
vga_drawline(x1,y1,x2,y1);
vga_drawline(x1,y2,x2,y2);
vga_drawline(x1,y1,x1,y2);
vga_drawline(x2,y1,x2,y2);
end; {DrawRectangle}
Procedure Scroll;
{ copies first bank of screen to the last bank (for 1024x768x256 mode) }
var i : word;
begin
vga_setreadpage(0);
vga_setwritepage(11);
for i := 65535 downto 0 do VideoMem^[i] := VideoMem^[i];
end; {Scroll}
(*
Procedure Scroll; Assembler;
{ copies first bank of screen to the last bank (for 1024x768x256 mode) }
var popreturn : longint;
asm
mov esi,SegA000
mov edi,esi
mov eax,0
push eax
call vga_setreadpage {set read bank}
pop popreturn {tidy stack}
mov eax,11
push eax
call vga_setwritepage {set write bank}
pop popreturn {tidy stack}
mov ecx,16384
rep movsd {copy all of bank 0 to bank 11}
end; {Scroll}
*)
begin
mode := 12; {1024x768x256}
i := vga_init;
StartupMode := vga_getcurrentmode;
vga_setmode(mode);
gl_setcontextvga(mode);
p := vga_getgraphmem;
VideoMem := p;
modeinfo := vga_getmodeinfo(mode);
SeparateReadWriteWindows := (modeinfo^.flags and HAVE_RWPAGE <> 0);
if SeparateReadWriteWindows <> False then begin
vga_setcolor(14);
gl_fillbox(100,0,823,63,13);
DrawRectangle(100,0,923,63);
vga_setcolor(3);
vga_drawline(0,0,1023,767);
vga_drawline(1023,0,0,767);
for i := 0 to 5000000 do vga_drawpixel(10,10); {delay}
Scroll; {copy first 64 lines down to last 64 lines of screen}
for i := 0 to 5000000 do vga_drawpixel(10,10); {delay}
end;
vga_setmode(StartupMode);
writeln('SeparateReadWriteWindows = ',SeparateReadWriteWindows);
writeln('vgamode = ',mode);
end.

308
demos/scrolltest.c Normal file
View file

@ -0,0 +1,308 @@
/*
Animation/smooth scrolling demo, uses Mode X/page flipping and
linear virtual screen in system memory.
First method copies window to page-flipped Mode X-style video memory
for scrolling.
Linear addressing, and page flipping (no shearing) and triple
buffering, but relatively slow.
Second method uses Mode X-style hardware scrolling.
Limited logical screen size, page flipping if no scrolling, tricky and
slow animation, scrolling fast (page flipping with scrolling is very
tricky).
Third method copies window to linear "Mode 13h" video memory.
Linear addressing, no page flipping (scrolling looks bad), speed
depends on bus (fast on a good ISA card; very fast on VLB).
Some SVGA cards can support page-flipping in linear 320x200x256.
Adding animated objects is trivial with the virtual screen methods (1
and 3).
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <vga.h>
#include <vgagl.h>
/* Virtual screen size. */
/* Limited to 256K by hardware scrolling method (automatically clipped). */
/* Width must be multiple of 8. */
#define VWIDTH 640
#define VHEIGHT 400
/* Scrolling window size for system memory virtual screen demo. */
#define WINWIDTH 320
#define WINHEIGHT 200
/* Define this to use triple-buffering in first method. */
#define TRIPLEBUFFERING
unsigned char *vbuf;
void boxes(void)
{
int x, y;
for (x = 0; x <= VWIDTH - 8; x += 8)
for (y = 0; y <= VHEIGHT - 8; y += 8) {
int r, g, b;
/* Draw red tiles. */
r = rand() & 255;
b = 0;
g = 0;
if ((rand() & 15) == 15) { /* Add occasional */
r = 0; /* blue specks. */
b = rand() & 127;
}
gl_fillbox(x, y, 7, 7, gl_rgbcolor(r, g, b));
}
}
void demo1(void)
{
int x, y;
int targetx, targety;
int pageoffset[3] =
{
0,
320 * 240 / 4,
2 * 320 * 240 / 4
};
int writepage;
int count, startclock;
/* Window coordinate initially at center. */
x = VWIDTH / 2 - WINWIDTH / 2;
y = VHEIGHT / 2 - WINHEIGHT / 2;
targetx = x;
targety = y;
/* Page flipping initialization. */
vga_setdisplaystart(0); /* Display page 0, write to page 1. */
writepage = 1;
count = 0;
startclock = clock();
for (;;) {
/* Copy window to screen. */
vga_copytoplanar256(vbuf + y * WIDTH + x, WIDTH,
pageoffset[writepage], 80, WINWIDTH, WINHEIGHT);
/* Flip pages. */
vga_setdisplaystart(pageoffset[writepage] * 4);
#ifndef TRIPLEBUFFERING
/* Conventional double-buffering (page-flipping). */
vga_waitretrace();
writepage ^= 1;
#else
/* Triple buffering; no need to wait for vertical retrace. */
writepage = (writepage + 1) % 3;
#endif
if (x == targetx && y == targety) {
/* Create new target. */
targetx = rand() % (VWIDTH - WINWIDTH);
targety = rand() % (VHEIGHT - WINHEIGHT);
}
/* Move towards target. */
if (x < targetx)
x++;
if (x > targetx)
x--;
if (y < targety)
y++;
if (y > targety)
y--;
/* Boundary checks. */
if (x < 0)
x = 0;
if (x > VWIDTH - WINWIDTH)
x = VWIDTH - WINWIDTH;
if (y < 0)
y = 0;
if (y > VHEIGHT - WINHEIGHT)
y = VHEIGHT - WINHEIGHT;
if (vga_getkey())
break;
count++;
}
printf("Method 1: frame rate %ld\n", count * CLOCKS_PER_SEC
/ (clock() - startclock));
}
void demo2(void)
{
int x, y;
int targetx, targety;
int vwidth, vheight;
int count, startclock;
/* Make sure window fits in video memory. */
vwidth = VWIDTH;
if (vwidth > 640)
vwidth = 640;
vheight = VHEIGHT;
if (vheight > 400)
vheight = 400;
vga_setlogicalwidth(vwidth);
/* Copy virtual screen to logical screen in video memory. */
vga_copytoplanar256(vbuf, VWIDTH, 0, vwidth / 4,
vwidth, VHEIGHT);
/* Window coordinates initially at center. */
x = vwidth / 2 - WINWIDTH / 2;
y = vheight / 2 - WINHEIGHT / 2;
targetx = x;
targety = y;
count = 0;
startclock = clock();
for (;;) {
/* Set video memory window. */
vga_setdisplaystart((y * vwidth / 4) * 4 + x);
vga_waitretrace();
if (x == targetx && y == targety) {
/* Create new target. */
targetx = rand() % (vwidth - WINWIDTH);
targety = rand() % (vheight - WINHEIGHT);
}
/* Move towards target. */
if (x < targetx)
x++;
if (x > targetx)
x--;
if (y < targety)
y++;
if (y > targety)
y--;
/* Boundary checks. */
if (x < 0)
x = 0;
if (x > vwidth - WINWIDTH)
x = vwidth - WINWIDTH;
if (y < 0)
y = 0;
if (y > vheight - WINHEIGHT)
y = vheight - WINHEIGHT;
if (vga_getkey())
break;
count++;
}
printf("Method 2: frame rate %ld\n", count*CLOCKS_PER_SEC
/(clock() - startclock));
}
void demo3(void)
{
int x, y;
int targetx, targety;
int count, startclock;
GraphicsContext *virtualscreen;
GraphicsContext *physicalscreen;
/* Window coordinate initially at center. */
x = VWIDTH / 2 - WINWIDTH / 2;
y = VHEIGHT / 2 - WINHEIGHT / 2;
targetx = x;
targety = y;
virtualscreen = gl_allocatecontext();
gl_getcontext(virtualscreen);
gl_setcontextvga(G320x200x256);
physicalscreen = gl_allocatecontext();
gl_getcontext(physicalscreen);
gl_setcontext(virtualscreen);
count = 0;
startclock = clock();
for (;;) {
vga_waitretrace();
/* Copy window to screen. */
gl_copyboxtocontext(x, y, WINWIDTH, WINHEIGHT, physicalscreen,
0, 0);
if (x == targetx && y == targety) {
/* Create new target. */
targetx = rand() % (VWIDTH - WINWIDTH);
targety = rand() % (VHEIGHT - WINHEIGHT);
}
/* Move towards target. */
if (x < targetx)
x++;
if (x > targetx)
x--;
if (y < targety)
y++;
if (y > targety)
y--;
/* Boundary checks. */
if (x < 0)
x = 0;
if (x > VWIDTH - WINWIDTH)
x = VWIDTH - WINWIDTH;
if (y < 0)
y = 0;
if (y > VHEIGHT - WINHEIGHT)
y = VHEIGHT - WINHEIGHT;
if (vga_getkey())
break;
count++;
}
printf("Method 3: frame rate %ld\n", count * CLOCKS_PER_SEC
/ (clock() - startclock));
}
int main(void)
{
vga_init();
/* Create virtual screen. */
vbuf = malloc(VWIDTH * VHEIGHT);
gl_setcontextvirtual(VWIDTH, VHEIGHT, 1, 8, vbuf);
/* Set Mode X-style 320x240x256. */
vga_setmode(G320x240x256);
gl_setrgbpalette();
vga_clear();
boxes();
demo1();
demo2();
vga_setmode(G320x200x256); /* Set linear 320x200x256. */
gl_setrgbpalette();
demo3();
vga_setmode(TEXT);
exit(0);
}

17
demos/sixbpp.xbm Normal file
View file

@ -0,0 +1,17 @@
#define sixbpp_width 23
#define sixbpp_height 66
static char sixbpp_bits[] = {
0x80,0x3f,0x00,0xf0,0xff,0x01,0xfc,0xff,0x01,0xfe,0xff,0x03,0x7e,0x02,0x03,
0x0f,0x01,0x02,0x83,0x01,0x02,0x81,0x81,0x03,0x81,0xff,0x01,0x0d,0xff,0x01,
0x1f,0xff,0x00,0x1e,0x3e,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x70,0x00,0x01,0xff,0x01,0xf1,0xff,0x01,0xff,0xff,0x03,
0xff,0x03,0x03,0xff,0x00,0x02,0x8f,0x00,0x02,0x40,0x00,0x03,0xc0,0xc0,0x03,
0xc0,0xff,0x01,0x80,0xff,0x01,0x80,0xff,0x00,0x00,0x3e,0x40,0x00,0x00,0x40,
0x00,0x00,0x78,0x40,0x80,0x7f,0x40,0xf8,0x7f,0xc0,0xff,0x7f,0xc0,0xff,0x47,
0xc0,0xff,0x41,0xc0,0x07,0x03,0x80,0x00,0x02,0x40,0x00,0x02,0x40,0x00,0x03,
0xc0,0xc0,0x03,0xc0,0xff,0x01,0x80,0xff,0x01,0x80,0xff,0x00,0x00,0x3e,0x40,
0x00,0x00,0x40,0x00,0x00,0x78,0x40,0x80,0x7f,0x40,0xf8,0x7f,0xc0,0xff,0x7f,
0xc0,0xff,0x47,0xc0,0xff,0x41,0xc0,0x07,0x03,0x80,0x00,0x02,0x40,0x00,0x02,
0x40,0x00,0x03,0xc0,0xc0,0x03,0xc0,0xff,0x01,0x80,0xff,0x01,0x80,0xff,0x00,
0x00,0x3e,0x00};

312
demos/speedtest.c Normal file
View file

@ -0,0 +1,312 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <vga.h>
#include <vgagl.h>
/* #define LINEAR_ADDRESSING */
int VGAMODE, USEGL;
GraphicsContext *physicalscreen;
GraphicsContext *backscreen;
void screen1(void)
{
int x, y;
for (y = 0; y < HEIGHT; y++)
for (x = 0; x < WIDTH; x++)
/* limited RGB palette in 256-color modes */
/* some color information is not used in */
/* 15-bit color modes */
gl_setpixelrgb(x, y,
x * 256 / WIDTH,
255 - x * 256 / WIDTH,
y * 256 / HEIGHT);
}
void configure(void)
{
int allowed[GLASTMODE + 1];
for (;;) {
int i;
int m;
for (i = G320x200x16; i <= GLASTMODE; i++) {
allowed[i] = 0;
if (vga_hasmode(i)) {
printf("%2d %s\n", i, vga_getmodename(i));
allowed[i] = 1;
}
}
printf("\nWhich mode? ");
scanf("%d", &m);
getchar();
printf("\n");
if (m >= G320x200x16 && m <= GLASTMODE) {
VGAMODE = m;
if (vga_getmodeinfo(m)->bytesperpixel >= 1)
USEGL = 1;
else
USEGL = 0;
break;
}
}
vga_setmode(VGAMODE);
#ifdef LINEAR_ADDRESSING
vga_setlinearaddressing();
#endif
if (USEGL) {
gl_setcontextvga(VGAMODE);
physicalscreen = gl_allocatecontext();
gl_getcontext(physicalscreen);
}
}
void blit(void)
{
gl_clearscreen(0x86);
vga_imageblt(vga_getgraphmem(), 0, WIDTH - 128, HEIGHT - 128,
WIDTH * BYTESPERPIXEL);
/* vga_bitblt(0, 100 * WIDTH * BYTESPERPIXEL, 50, 50, WIDTH * BYTESPERPIXEL);
vga_fillblt(100 * BYTESPERPIXEL, 50, 50, WIDTH * BYTESPERPIXEL, 0x86);
*/
}
#if 0
/* May help on well-designed motherboards. */
/* IT DOES MAKE A DIFFERENCE! REP STOSL IS SLOWER */
/* (CL-GD5434 VLB zero-wait writes -- 2/3 cycles); rep stos takes 4 */
#if 1
static inline void *
__memset(void *s, char c, size_t count)
{
__asm__(
"cld\n\t"
"cmpl $12,%%edx\n\t"
"jl 1f\n\t" /* if (count >= 12) */
"movzbl %%al,%%ax\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"
"cmpl $32,%%ecx\n\t" /* do loop unrolling for */
"jl 2f\n\t" /* chunks of 128 bytes */
"jmp 3f\n\t"
".align 4,0x90\n\t"
"3:\n\t"
"movl %%eax,(%%edi)\n\t"
"movl %%eax,4(%%edi)\n\t"
"movl %%eax,8(%%edi)\n\t"
"movl %%eax,12(%%edi)\n\t"
"movl %%eax,16(%%edi)\n\t"
"movl %%eax,20(%%edi)\n\t"
"movl %%eax,24(%%edi)\n\t"
"movl %%eax,28(%%edi)\n\t"
"movl %%eax,32(%%edi)\n\t"
"movl %%eax,36(%%edi)\n\t"
"movl %%eax,40(%%edi)\n\t"
"movl %%eax,44(%%edi)\n\t"
"movl %%eax,48(%%edi)\n\t"
"movl %%eax,52(%%edi)\n\t"
"movl %%eax,56(%%edi)\n\t"
"movl %%eax,60(%%edi)\n\t"
"movl %%eax,64(%%edi)\n\t"
"movl %%eax,68(%%edi)\n\t"
"movl %%eax,72(%%edi)\n\t"
"movl %%eax,76(%%edi)\n\t"
"movl %%eax,80(%%edi)\n\t"
"movl %%eax,84(%%edi)\n\t"
"movl %%eax,88(%%edi)\n\t"
"movl %%eax,92(%%edi)\n\t"
"movl %%eax,96(%%edi)\n\t"
"movl %%eax,100(%%edi)\n\t"
"movl %%eax,104(%%edi)\n\t"
"movl %%eax,108(%%edi)\n\t"
"subl $32,%%ecx\n\t"
"movl %%eax,112(%%edi)\n\t"
"movl %%eax,116(%%edi)\n\t"
"movl %%eax,120(%%edi)\n\t"
"movl %%eax,124(%%edi)\n\t"
"addl $128,%%edi\n\t"
"cmpl $32,%%ecx\n\t"
"jge 3b\n\t"
"2:\n\t"
"rep ; stosl\n\t" /* fill remaining longwords */
"andl $3,%%edx\n" /* fill last few bytes */
"1:\tmovl %%edx,%%ecx\n\t" /* <= 12 entry point */
"rep ; stosb\n\t"
: : "a"(c), "D"(s), "d"(count)
: "ax", "cx", "dx", "di");
return s;
}
#else /* 8-bit writes. */
static inline void *
__memset(void *s, char c, size_t count)
{
__asm__(
"cld\n\t"
"cmpl $12,%%edx\n\t"
"jl 1f\n\t" /* if (count >= 12) */
"movzbl %%al,%%ax\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"
"cmpl $32,%%ecx\n\t" /* do loop unrolling for */
"jl 2f\n\t" /* chunks of 128 bytes */
"jmp 3f\n\t"
".align 4,0x90\n\t"
"3:\n\t"
"movb %%al,(%%edi)\n\t"
"movb %%al,1(%%edi)\n\t"
"movb %%al,2(%%edi)\n\t"
"movl %%al,3(%%edi)\n\t"
"movl %%al,4(%%edi)\n\t"
"movl %%al,5(%%edi)\n\t"
"movl %%al,6(%%edi)\n\t"
"movl %%al,7(%%edi)\n\t"
"movl %%al,8(%%edi)\n\t"
"movl %%al,9(%%edi)\n\t"
"movl %%al,10(%%edi)\n\t"
"movl %%al,11(%%edi)\n\t"
"movl %%al,12(%%edi)\n\t"
"movl %%al,13(%%edi)\n\t"
"movl %%al,14(%%edi)\n\t"
"movl %%al,15(%%edi)\n\t"
"movl %%al,16(%%edi)\n\t"
"movl %%al,17(%%edi)\n\t"
"movl %%al,18(%%edi)\n\t"
"movl %%al,19(%%edi)\n\t"
"movl %%al,20(%%edi)\n\t"
"movl %%al,21(%%edi)\n\t"
"movl %%al,22(%%edi)\n\t"
"movl %%al,23(%%edi)\n\t"
"movl %%al,24(%%edi)\n\t"
"movl %%al,25(%%edi)\n\t"
"movl %%al,26(%%edi)\n\t"
"movl %%al,27(%%edi)\n\t"
"movl %%al,28(%%edi)\n\t"
"subl $8,%%ecx\n\t"
"movl %%al,29(%%edi)\n\t"
"movl %%al,30(%%edi)\n\t"
"movl %%al,31(%%edi)\n\t"
"addl $32,%%edi\n\t"
"cmpl $8,%%ecx\n\t"
"jge 3b\n\t"
"2:\n\t"
"rep ; stosl\n\t" /* fill remaining longwords */
"andl $3,%%edx\n" /* fill last few bytes */
"1:\tmovl %%edx,%%ecx\n\t" /* <= 12 entry point */
"rep ; stosb\n\t"
: : "a"(c), "D"(s), "d"(count)
: "ax", "cx", "dx", "di");
return s;
}
#endif
#define memset __memset
#endif
void speed(void)
{
int i;
int start_clock;
int finish_clock;
int diff_clock;
unsigned char *vgabase = vga_getgraphmem();
#ifndef LINEAR_ADDRESSING
if (VGAMODE >= G640x480x256)
vga_setpage(0);
#endif
start_clock = clock();
for (i = 0; i < 5000; i++) {
memset(vgabase, i & 255, 65536);
}
finish_clock = clock();
diff_clock = (finish_clock - start_clock)*10/CLOCKS_PER_SEC;
printf("Timing: %3d.%1ds, %dK/s\n", diff_clock / 10,
(diff_clock % 10) , 64*5000*10 / diff_clock);
}
int main(void)
{
vga_init();
printf("This is a video memory speed tester. Note that the first "
"screen doesn't test\nanything (nor does the 3 second pause "
"that follows).\n\n");
configure();
if (COLORS == 256)
gl_setrgbpalette(); /* set RGB palette */
if (USEGL)
screen1();
sleep(2);
/* vga_screenoff(); */
speed();
vga_setmode(TEXT);
exit(0);
}

391
demos/spin.c Normal file
View file

@ -0,0 +1,391 @@
/*
spin.c - A simple (or not quite so) app to test the SpaceOrb by rotating
a shape of a given number of sides.
Copyright (C) 1997 Eric Sharkey, Jason Lyons, Brett Viren
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
---- end copyleft notice ----
This program is FREE!!! However, if you feel that nothing is free and you
refuse to use something someone else made unless paid for, you can send a
donation to me (Jason Lyons). For information on this, E-MAIL me at
jason_l@hotmail.com.
This graphical test program was originally written by Jason Lyons and
later hacked to bits by Eric Sharkey, but this program would not be
possible without Brett's efforts. Be sure to thank him!
The original code for the SpaceOrb in Unix/Linux was written by Brett Viren
(Brett.Viren@sunysb.edu) on his free time (ie, not when on the pay
clock of SUNY@Stony Brook). Do with it what you will, as long as
you abide by the GPL.
I think by now all of Brett's code has been removed from this demo
and incorporated into svgalib itself, but he's still responsible for
starting this whole thing.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vga.h>
#include <vgagl.h>
#include <vgamouse.h>
#include <malloc.h>
#include "spintables.h"
#define DONT_MANUALLY_SETUP_MOUSE
#define NODEBUG
#define GMODE 5
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 200
#define SCREEN_DEPTH 100
#ifndef ROTATION_ONLY
/* Note: 6-D protocol assumes x is left/right, y is in/out, and z is up/down, */
/* which is logical for a three d environment, but for this demo all plotting */
/* is done with x/y only, so we remap y onto z and vice versa here by */
/* defining y as coordinate 2 and z as coordinate 1 */
#define SCR_XCTR t[0]
#define SCR_YCTR t[2]
#define SCR_ZCTR (((float) t[1])/((float) SCREEN_DEPTH))
#else
#define SCR_XCTR (SCREEN_WIDTH/2)
#define SCR_YCTR (SCREEN_HEIGHT/2)
#define SCR_ZCTR 1
#endif
#define SCREEN_SIZE (SCREEN_WIDTH*SCREEN_HEIGHT)
#define LAYERS 6
#define MAX_NUM_SIDES 20
#define MAX_NUM_POINTS MAX_NUM_SIDES*LAYERS
#define HORIZONTAL 0
typedef unsigned short WORD;
typedef unsigned char BYTE;
typedef unsigned int DWORD;
typedef struct {
float x, y, z;
} POINT3D;
int CurrentColor=12;
int Depth[LAYERS] = { -45, -35, -10, +10, +35, +45 };
int Radius[LAYERS] = { 5, 50, 75, 75, 50, 5 };
int InitGraph(int mode);
void InitPoints(POINT3D *Points, int sides);
void SetColor(char c);
char GetColor(void);
void SetPixel(int x, int y, char c);
void line(int x1, int y1, int x2, int y2);
void Update(void);
void Clear(void);
void RotateX(POINT3D *dest, POINT3D src, int a);
void RotateY(POINT3D *dest, POINT3D src, int a);
void RotateZ(POINT3D *dest, POINT3D src, int a);
GraphicsContext *screen;
char *buf;
int main(void)
{
int scale=100, a, b, c;
POINT3D *Points;
int sides;
int NUM_POINTS;
int t[3], r[3], oldbutton=0, button=0;
#ifdef MANUALLY_SETUP_MOUSE
char orbdev[1024] = "/dev/ttyS0";
#endif
printf("\n\n Welcome to SPIN\n\n");
printf(" Spin is a graphical rotation program for Linux which uses the SVGA library.\n");
printf("It's purpose is to demonstrate the new six dimensional mouse driver support.\n");
printf("So far this driver only supports the Spaceball series of controllers including\n");
printf("the Spaceball Avenger and SpaceOrb 360. Spin may be used with any mouse type\n");
printf("but two dimensional mice will only be able to move the image in two dimensions.\n\n");
printf("Spin was originally written by Jason Lyons, based on the SpaceOrb readout code\n");
printf("developed by Brett Viren and others. Eric Sharkey incorporated Brett's code\n");
printf("into svgalib and adapted spin accordingly.\n\n");
printf("Button Functions:\n");
printf(" A - Decrease Sensitivity (Right Mouse Button)\n");
printf(" B - Change color (Middle Mouse Button)\n");
printf(" C - Increase Sensitivity (Left Mouse Button)\n");
printf(" D - Increase Number of Sides\n");
printf(" E - Decrease Number of Sides\n");
printf(" F - Quit (CTRL-C)\n");
printf(" Reset button toggles orientation (default is vertical) \n\n");
printf("Warning: Default sensitivity optimized for spaceball.\n");
printf("Most mice will need to increase this setting.\n");
printf("\nHow many sides to start with (MAX %d) ? ",MAX_NUM_SIDES);
scanf("%d", &c);
if(c == 0) exit(1);
else if(c < 0) printf("\nCannot draw a negative number of sides.\n"), exit(1);
else if(c > MAX_NUM_SIDES) printf("\nCannot draw with more sides than %d.\n",MAX_NUM_SIDES), exit(1);
sides = c;
NUM_POINTS = sides*LAYERS;
Points = (POINT3D *)calloc(MAX_NUM_POINTS, sizeof(POINT3D));
InitPoints(Points,sides);
printf("Initializing mouse\n");
#ifdef MANUALLY_SETUP_MOUSE
if (mouse_init(orbdev,MOUSE_SPACEBALL,MOUSE_DEFAULTSAMPLERATE)) {
printf("mouse_init failed");
return -1;
} else {
printf("mouse_init successful\n");
}
#else
vga_setmousesupport(1);
#endif
if(!InitGraph(GMODE)) return 0;
mouse_setscale(scale);
mouse_setrange_6d(0,SCREEN_WIDTH,1,SCREEN_DEPTH,0,SCREEN_HEIGHT,-2,2,-2,2,-2,2,63);
mouse_setwrap(MOUSE_ROT_INFINITESIMAL);
mouse_setposition_6d(SCREEN_WIDTH/2,SCREEN_DEPTH/2,SCREEN_HEIGHT/2,0,0,0,63);
while(1)
{
mouse_update();
mouse_getposition_6d(&t[0],&t[1],&t[2],&r[0],&r[1],&r[2]);
#ifdef DEBUG
printf("%d %d %d\n",t[0],t[1],t[2]);
#endif
oldbutton = button;
button = mouse_getbutton();
if ((button & MOUSE_RIGHTBUTTON)&&!(oldbutton & MOUSE_RIGHTBUTTON)) {
scale += 5;
mouse_setscale(scale);
}
if ((button & MOUSE_LEFTBUTTON)&&!(oldbutton & MOUSE_LEFTBUTTON)) {
if (scale==1) {
printf("\007");
fflush(stdout);
} else {
if (scale>6)
scale -=5;
else
scale--;
mouse_setscale(scale);
}
}
if ((button & MOUSE_MIDDLEBUTTON)&&!(oldbutton & MOUSE_MIDDLEBUTTON))
CurrentColor = random() % 15 + 1;
if ((button & MOUSE_FOURTHBUTTON)&&!(oldbutton & MOUSE_FOURTHBUTTON)) {
if (sides>1) {
sides--;
NUM_POINTS = sides*LAYERS;
InitPoints(Points,sides);
} else {
printf("\007");
fflush(stdout);
}
}
if ((button & MOUSE_FIFTHBUTTON)&&!(oldbutton & MOUSE_FIFTHBUTTON)) {
if (sides<MAX_NUM_SIDES) {
sides++;
NUM_POINTS = sides*LAYERS;
InitPoints(Points,sides);
} else {
printf("\007");
fflush(stdout);
}
}
if (button & MOUSE_SIXTHBUTTON)
{
vga_setmode(0);
free(buf);
free(Points);
return 0;
}
for(a = 0; a < NUM_POINTS; a++) {
RotateX(&Points[a],Points[a],r[0]);
RotateY(&Points[a],Points[a],r[2]);
RotateZ(&Points[a],Points[a],r[1]);
Points[a].x *= SCR_ZCTR;
Points[a].y *= SCR_ZCTR;
Points[a].z *= SCR_ZCTR;
Points[a].x += SCR_XCTR;
Points[a].y += SCR_YCTR;
}
for(a = 0; a < LAYERS; a++)
{
for(b = 0; b < sides-1; b++)
{
/* Connect the points on each layer */
line(Points[a*sides+(b+1)].x,Points[a*sides+(b+1)].y,
Points[a*sides+b].x,Points[a*sides+b].y);
/* Connect between layers */
if(a < (LAYERS - 1))
{
line(Points[(a+1)*sides+b].x,Points[(a+1)*sides+b].y,
Points[a*sides+b].x,Points[a*sides+b].y);
}
}
line(Points[a*sides+b].x,Points[a*sides+b].y,
Points[a*sides+0].x,Points[a*sides+0].y);
if(a < (LAYERS - 1))
{
line(Points[a*sides+b].x,Points[a*sides+b].y,
Points[(a+1)*sides+b].x,Points[(a+1)*sides+b].y);
}
}
for(a = 0; a < NUM_POINTS; a++) {
Points[a].x -= SCR_XCTR;
Points[a].y -= SCR_YCTR;
Points[a].x /= SCR_ZCTR;
Points[a].y /= SCR_ZCTR;
Points[a].z /= SCR_ZCTR;
}
Update();
Clear();
}
free(buf);
free(Points);
}
void SetColor(char c) { CurrentColor = c; }
char GetColor() { return CurrentColor; }
void SetPixel(int x, int y, char c)
{
if(x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT)
buf[y*SCREEN_WIDTH+x] = c;
}
void Clear() { memset((char *)buf, 0, SCREEN_SIZE); }
void Update()
{
memcpy((char *)screen->vbuf, (char *)buf, SCREEN_SIZE);
}
void InitPoints(POINT3D *Points, int sides)
{
int a, b, c;
for(a = 0; a < LAYERS; a++)
{
for(b = 0; b < sides; b++)
{
c=(b*360)/sides;
Points[a*sides+b].x = cosine[c] * Radius[a];
Points[a*sides+b].y = sine[c] * Radius[a];
Points[a*sides+b].z = Depth[a];
}
}
}
int InitGraph(int mode)
{
buf = (char *)malloc(SCREEN_SIZE);
if(!buf) return 0;
if(!vga_hasmode(mode)) return 0;
vga_setmode(mode);
gl_setcontextvga(mode);
screen = gl_allocatecontext();
gl_getcontext(screen);
gl_setcontextvgavirtual(mode);
gl_setcontext(screen);
return 1;
}
void RotateX(POINT3D *dest, POINT3D src, int a)
{
while (a<0) a+=360;
dest->x = src.x;
dest->y = src.y * cosine[a] + src.z * sine[a];
dest->z = -1 * src.y * sine[a] + src.z * cosine[a];
}
void RotateY(POINT3D *dest, POINT3D src, int a)
{
while (a<0) a+=360;
dest->x = -1 * src.z * sine[a] + src.x * cosine[a];
dest->y = src.y;
dest->z = src.z * cosine[a] + src.x * sine[a];
}
void RotateZ(POINT3D *dest, POINT3D src, int a)
{
while (a<0) a+=360;
dest->x = src.x * cosine[a] + src.y * sine[a];
dest->y = -1 * src.x * sine[a] + src.y * cosine[a];
dest->z = src.z;
}
void line(int x1, int y1, int x2, int y2)
{
int dx, dy;
int sx, sy;
int ax, ay;
int x, y, c=CurrentColor;
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;
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 sy = (dy >= 0) ? 1 : -1;
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);
}

724
demos/spintables.h Normal file
View file

@ -0,0 +1,724 @@
float sine[360] = {
0.000000,
0.017449,
0.034893,
0.052326,
0.069743,
0.087139,
0.104509,
0.121846,
0.139147,
0.156405,
0.173616,
0.190773,
0.207873,
0.224909,
0.241877,
0.258771,
0.275587,
0.292318,
0.308961,
0.325509,
0.341958,
0.358303,
0.374539,
0.390661,
0.406664,
0.422544,
0.438294,
0.453911,
0.469390,
0.484726,
0.499914,
0.514951,
0.529830,
0.544548,
0.559100,
0.573482,
0.587689,
0.601718,
0.615563,
0.629221,
0.642687,
0.655957,
0.669028,
0.681895,
0.694554,
0.707002,
0.719235,
0.731248,
0.743039,
0.754604,
0.765939,
0.777040,
0.787905,
0.798530,
0.808912,
0.819048,
0.828934,
0.838568,
0.847947,
0.857067,
0.865927,
0.874522,
0.882852,
0.890912,
0.898702,
0.906217,
0.913457,
0.920419,
0.927100,
0.933499,
0.939614,
0.945442,
0.950983,
0.956234,
0.961195,
0.965862,
0.970235,
0.974313,
0.978094,
0.981578,
0.984762,
0.987647,
0.990230,
0.992513,
0.994493,
0.996170,
0.997544,
0.998614,
0.999381,
0.999843,
1.000000,
0.999853,
0.999401,
0.998645,
0.997586,
0.996222,
0.994555,
0.992585,
0.990313,
0.987739,
0.984865,
0.981691,
0.978217,
0.974446,
0.970379,
0.966015,
0.961358,
0.956408,
0.951166,
0.945635,
0.939816,
0.933711,
0.927322,
0.920650,
0.913698,
0.906468,
0.898961,
0.891181,
0.883130,
0.874810,
0.866223,
0.857372,
0.848261,
0.838891,
0.829266,
0.819388,
0.809261,
0.798887,
0.788270,
0.777413,
0.766320,
0.754992,
0.743436,
0.731652,
0.719646,
0.707421,
0.694980,
0.682328,
0.669468,
0.656404,
0.643141,
0.629681,
0.616030,
0.602191,
0.588169,
0.573967,
0.559591,
0.545045,
0.530332,
0.515459,
0.500428,
0.485244,
0.469913,
0.454439,
0.438827,
0.423081,
0.407206,
0.391207,
0.375089,
0.358857,
0.342515,
0.326069,
0.309524,
0.292885,
0.276156,
0.259344,
0.242452,
0.225487,
0.208453,
0.191355,
0.174199,
0.156991,
0.139734,
0.122435,
0.105098,
0.087730,
0.070335,
0.052918,
0.035485,
0.018042,
0.000593,
-0.016857,
-0.034301,
-0.051734,
-0.069152,
-0.086549,
-0.103919,
-0.121258,
-0.138560,
-0.155820,
-0.173032,
-0.190192,
-0.207293,
-0.224332,
-0.241302,
-0.258199,
-0.275017,
-0.291751,
-0.308397,
-0.324949,
-0.341401,
-0.357750,
-0.373990,
-0.390116,
-0.406123,
-0.422006,
-0.437761,
-0.453383,
-0.468867,
-0.484208,
-0.499401,
-0.514442,
-0.529327,
-0.544051,
-0.558609,
-0.572996,
-0.587210,
-0.601244,
-0.615096,
-0.628760,
-0.642233,
-0.655510,
-0.668587,
-0.681461,
-0.694128,
-0.706583,
-0.718823,
-0.730844,
-0.742642,
-0.754215,
-0.765557,
-0.776667,
-0.787540,
-0.798174,
-0.808564,
-0.818708,
-0.828603,
-0.838245,
-0.847633,
-0.856762,
-0.865630,
-0.874235,
-0.882573,
-0.890643,
-0.898442,
-0.905967,
-0.913216,
-0.920187,
-0.926878,
-0.933286,
-0.939411,
-0.945249,
-0.950800,
-0.956061,
-0.961031,
-0.965708,
-0.970091,
-0.974179,
-0.977971,
-0.981464,
-0.984659,
-0.987554,
-0.990148,
-0.992440,
-0.994431,
-0.996118,
-0.997503,
-0.998583,
-0.999360,
-0.999832,
-1.000000,
-0.999863,
-0.999422,
-0.998676,
-0.997627,
-0.996273,
-0.994616,
-0.992657,
-0.990395,
-0.987832,
-0.984967,
-0.981803,
-0.978340,
-0.974579,
-0.970522,
-0.966168,
-0.961521,
-0.956581,
-0.951349,
-0.945828,
-0.940019,
-0.933923,
-0.927544,
-0.920881,
-0.913939,
-0.906718,
-0.899221,
-0.891450,
-0.883408,
-0.875097,
-0.866519,
-0.857677,
-0.848575,
-0.839213,
-0.829597,
-0.819728,
-0.809609,
-0.799243,
-0.788635,
-0.777786,
-0.766700,
-0.755381,
-0.743832,
-0.732056,
-0.720058,
-0.707840,
-0.695406,
-0.682761,
-0.669908,
-0.656851,
-0.643594,
-0.630141,
-0.616497,
-0.602664,
-0.588648,
-0.574453,
-0.560082,
-0.545542,
-0.530835,
-0.515966,
-0.500941,
-0.485763,
-0.470436,
-0.454967,
-0.439359,
-0.423618,
-0.407747,
-0.391752,
-0.375638,
-0.359410,
-0.343072,
-0.326630,
-0.310088,
-0.293452,
-0.276726,
-0.259916,
-0.243027,
-0.226064,
-0.209032,
-0.191937,
-0.174783,
-0.157576,
-0.140321,
-0.123023,
-0.105688,
-0.088320,
-0.070926,
-0.053510,
-0.036077,
-0.018634,
};
float cosine[360] = {
1.000000,
0.999848,
0.999391,
0.998630,
0.997565,
0.996196,
0.994524,
0.992549,
0.990272,
0.987693,
0.984813,
0.981634,
0.978156,
0.974380,
0.970307,
0.965939,
0.961276,
0.956321,
0.951075,
0.945539,
0.939715,
0.933605,
0.927211,
0.920534,
0.913578,
0.906343,
0.898832,
0.891047,
0.882991,
0.874666,
0.866075,
0.857220,
0.848104,
0.838730,
0.829100,
0.819218,
0.809087,
0.798709,
0.788088,
0.777227,
0.766129,
0.754798,
0.743237,
0.731450,
0.719440,
0.707212,
0.694767,
0.682112,
0.669248,
0.656181,
0.642914,
0.629451,
0.615796,
0.601954,
0.587929,
0.573725,
0.559346,
0.544796,
0.530081,
0.515205,
0.500171,
0.484985,
0.469652,
0.454175,
0.438561,
0.422812,
0.406935,
0.390934,
0.374814,
0.358580,
0.342237,
0.325789,
0.309242,
0.292602,
0.275872,
0.259058,
0.242165,
0.225198,
0.208163,
0.191064,
0.173908,
0.156698,
0.139440,
0.122141,
0.104804,
0.087435,
0.070039,
0.052622,
0.035189,
0.017745,
0.000296,
-0.017153,
-0.034597,
-0.052030,
-0.069448,
-0.086844,
-0.104214,
-0.121552,
-0.138854,
-0.156113,
-0.173324,
-0.190483,
-0.207583,
-0.224621,
-0.241590,
-0.258485,
-0.275302,
-0.292035,
-0.308679,
-0.325229,
-0.341680,
-0.358027,
-0.374265,
-0.390389,
-0.406394,
-0.422275,
-0.438028,
-0.453647,
-0.469128,
-0.484467,
-0.499658,
-0.514697,
-0.529579,
-0.544299,
-0.558854,
-0.573239,
-0.587450,
-0.601481,
-0.615329,
-0.628990,
-0.642460,
-0.655733,
-0.668808,
-0.681678,
-0.694341,
-0.706792,
-0.719029,
-0.731046,
-0.742841,
-0.754409,
-0.765748,
-0.776854,
-0.787723,
-0.798352,
-0.808738,
-0.818878,
-0.828769,
-0.838407,
-0.847790,
-0.856915,
-0.865778,
-0.874379,
-0.882713,
-0.890778,
-0.898572,
-0.906092,
-0.913336,
-0.920303,
-0.926989,
-0.933393,
-0.939512,
-0.945346,
-0.950892,
-0.956148,
-0.961113,
-0.965785,
-0.970163,
-0.974246,
-0.978032,
-0.981521,
-0.984710,
-0.987600,
-0.990189,
-0.992477,
-0.994462,
-0.996144,
-0.997523,
-0.998599,
-0.999370,
-0.999837,
-1.000000,
-0.999858,
-0.999412,
-0.998661,
-0.997606,
-0.996248,
-0.994586,
-0.992621,
-0.990354,
-0.987786,
-0.984916,
-0.981747,
-0.978279,
-0.974513,
-0.970450,
-0.966092,
-0.961439,
-0.956494,
-0.951258,
-0.945732,
-0.939918,
-0.933817,
-0.927433,
-0.920766,
-0.913818,
-0.906593,
-0.899091,
-0.891316,
-0.883269,
-0.874953,
-0.866371,
-0.857525,
-0.848418,
-0.839052,
-0.829431,
-0.819558,
-0.809435,
-0.799065,
-0.788452,
-0.777600,
-0.766510,
-0.755187,
-0.743634,
-0.731854,
-0.719852,
-0.707630,
-0.695193,
-0.682545,
-0.669688,
-0.656628,
-0.643368,
-0.629911,
-0.616263,
-0.602428,
-0.588408,
-0.574210,
-0.559837,
-0.545293,
-0.530584,
-0.515712,
-0.500684,
-0.485503,
-0.470175,
-0.454703,
-0.439093,
-0.423349,
-0.407476,
-0.391480,
-0.375364,
-0.359133,
-0.342794,
-0.326349,
-0.309806,
-0.293168,
-0.276441,
-0.259630,
-0.242740,
-0.225775,
-0.208743,
-0.191646,
-0.174491,
-0.157283,
-0.140027,
-0.122729,
-0.105393,
-0.088025,
-0.070630,
-0.053214,
-0.035781,
-0.018338,
-0.000889,
0.016560,
0.034004,
0.051438,
0.068856,
0.086254,
0.103625,
0.120964,
0.138267,
0.155527,
0.172740,
0.189901,
0.207003,
0.224043,
0.241014,
0.257913,
0.274732,
0.291468,
0.308115,
0.324668,
0.341123,
0.357473,
0.373715,
0.389843,
0.405852,
0.421738,
0.437495,
0.453119,
0.468605,
0.483948,
0.499144,
0.514188,
0.529076,
0.543802,
0.558363,
0.572754,
0.586970,
0.601007,
0.614862,
0.628529,
0.642005,
0.655286,
0.668367,
0.681244,
0.693914,
0.706373,
0.718617,
0.730641,
0.742444,
0.754020,
0.765367,
0.776480,
0.787358,
0.797995,
0.808389,
0.818538,
0.828437,
0.838084,
0.847475,
0.856609,
0.865482,
0.874091,
0.882434,
0.890508,
0.898311,
0.905841,
0.913095,
0.920071,
0.926766,
0.933180,
0.939309,
0.945152,
0.950708,
0.955974,
0.960949,
0.965631,
0.970020,
0.974112,
0.977909,
0.981407,
0.984607,
0.987507,
0.990106,
0.992404,
0.994399,
0.996092,
0.997482,
0.998567,
0.999349,
0.999826,
};

180
demos/svidtune.c Normal file
View file

@ -0,0 +1,180 @@
/* Program to test the svgalib keyboard functions. */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <vga.h>
#include <vgagl.h>
#include <vgakeyboard.h>
void usage(void)
{
puts("Usage: svidtune [mode]\n"
);
exit(2);
}
int main(int argc, char **argv)
{
int x=-1,xmax,ymax;
char buffer[2];
int vgamode;
int key, retval = 0;
int pixelClock;
int HDisplay;
int HSyncStart;
int HSyncEnd;
int HTotal;
int VDisplay;
int VSyncStart;
int VSyncEnd;
int VTotal;
int flags;
float hsf,vsf;
char flagstring[256];
if (argc > 2)
usage();
if(argc==2){
if(!sscanf(argv[1], "%d", &x))
usage();
};
vga_init();
if(x==-1)vgamode = vga_getdefaultmode(); else vgamode=x;
if (vgamode == -1)
vgamode = G640x480x256;
if (!vga_hasmode(vgamode)) {
printf("Mode not available.\n");
exit(1);
}
vga_setmode(vgamode);
gl_setcontextvga(vgamode);
gl_enableclipping();
gl_setfont(8, 8, gl_font8x8);
gl_setwritemode(FONT_COMPRESSED + WRITEMODE_OVERWRITE);
gl_setfontcolors(0, vga_white());
buffer[1] = 0;
for(;!buffer[1];) {
vga_getcurrenttiming(&pixelClock,
&HDisplay,
&HSyncStart,
&HSyncEnd,
&HTotal,
&VDisplay,
&VSyncStart,
&VSyncEnd,
&VTotal,
&flags);
sprintf(flagstring,"%s%s%s%s%s%s",
flags&1?"+hsync ":"",
flags&2?"-hsync ":"",
flags&4?"+vsync ":"",
flags&8?"-vsync ":"",
flags&16?"interlaced ":"",
flags&32?"doublescan":"");
hsf=pixelClock*1000.0/HTotal;
vsf=hsf/VTotal;
if(flags&32)vsf=vsf/2;
gl_printf(500,500,"îúï æéå-àá");
gl_printf(10,5, "Clock:%i", pixelClock);
gl_printf(10,25, "HDisplay:%i", HDisplay);
gl_printf(10,45, "HSyncStart:%i", HSyncStart);
gl_printf(10,65, "HSyncEnd:%i", HSyncEnd);
gl_printf(10,85, "HTotal:%i", HTotal);
gl_printf(10,105, "VDisplay:%i", VDisplay);
gl_printf(10,125, "VSyncStart:%i", VSyncStart);
gl_printf(10,145, "VSyncEnd:%i", VSyncEnd);
gl_printf(10,165, "VTotal:%i", VTotal);
gl_printf(10,185, "flags:%i = %s", flags,flagstring);
gl_printf(10,205, "Horz freq:%.3f kHz", hsf/1000);
gl_printf(10,215, "Vert freq:%.2f Hz", vsf);
if(VDisplay>270){
gl_printf(10,235, "Up, Down, Left, Right, Wider, Narrower, lOnger, Shorter");
gl_printf(10,258, "'p' - prints current modeline to stdout, 'P' - to config file ");
};
xmax = vga_getxdim() - 1;
ymax = vga_getydim() - 1;
vga_setcolor(vga_white());
vga_drawline(0, 0, xmax, 0);
vga_drawline(xmax, 0, xmax, ymax);
vga_drawline(xmax, ymax, 0, ymax);
vga_drawline(0, ymax, 0, 0);
key = vga_getch();
switch(key) {
case 4:
case 'q':
buffer[1]=1;
break;
case 'l':
vga_changetiming(0,0,8,8,0,0,0,0,0,0);
break;
case 'r':
vga_changetiming(0,0,-8,-8,0,0,0,0,0,0);
break;
case 'u':
vga_changetiming(0,0,0,0,0,0,1,1,0,0);
break;
case 'd':
vga_changetiming(0,0,0,0,0,0,-1,-1,0,0);
break;
case 'w':
vga_changetiming(0,0,-4,-4,-8,0,0,0,0,0);
break;
case 'n':
vga_changetiming(0,0,4,4,8,0,0,0,0,0);
break;
case 's':
vga_changetiming(0,0,0,0,0,0,1,1,2,0);
break;
case 'o':
vga_changetiming(0,0,0,0,0,0,-1,-1,-2,0);
break;
case 'p':
fprintf(stderr,"Modeline %c%ix%i@%.0f%c %.3f %i %i %i %i %i %i %i %i %s\n",'"',xmax+1,ymax+1,vsf,'"',
pixelClock/1000.0,
HDisplay,
HSyncStart,
HSyncEnd,
HTotal,
VDisplay,
VSyncStart,
VSyncEnd,
VTotal,
flagstring);
break;
case 'P':{
FILE *f;
f=fopen("/etc/vga/libvga.config","a");
fprintf(f,"Modeline %c%ix%i@%.0f%c %.3f %i %i %i %i %i %i %i %i %s\n",'"',xmax+1,ymax+1,vsf,'"',
pixelClock/1000.0,
HDisplay,
HSyncStart,
HSyncEnd,
HTotal,
VDisplay,
VSyncStart,
VSyncEnd,
VTotal,
flagstring);
fclose(f);
};
break;
};
}
vga_setmode(TEXT);
exit(retval);
}

758
demos/testaccel.c Normal file
View file

@ -0,0 +1,758 @@
/* Program to test all accelerator functions and the 8 bit
per color color lookup functions. */
/* written by Michael Weller (eowmob@exp-math.uni-essen.de) */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include "vga.h"
#include "clut.xbm"
#include "sixbpp.xbm"
#include "eightbpp.xbm"
#include "fish_monster.h"
#define RED(i) (0)
#define GREEN(i) (0)
#define BLUE(i) (i)
#define LOGO_NAME "linuxlogo.bitmap"
#define LOGO_WIDTH 201
#define LOGO_HEIGHT 85
#undef BITFRAME
typedef struct {
int n;
int pels;
int width;
int offset;
/*
int xmin[n];
int xmax[n]; */
} hlinelst;
/*Adjust hlist for new xcoord */
inline void adj_hlilst(hlinelst * lst, register int x)
{
register int i, *ptr;
i = x;
x -= lst->offset;
lst->offset = i;
i = (lst->n) << 1;
ptr = (int *) (((char *) lst) + sizeof(hlinelst));
while (i--)
*ptr++ += x;
}
inline int sizhlilst(int n)
{
return sizeof(hlinelst) + (sizeof(int) * (n < 1 ? 2 : (n << 1)));
}
inline int isqr(int i)
{
return i * i;
}
int waitmode = 1;
void my_wait(void)
{
if (waitmode)
vga_getch();
else
sleep(1);
}
void setcol(vga_modeinfo * modeinfo)
{
int i;
if (modeinfo->colors == 256)
for (i = 0; i < 256; i++)
vga_setpalette(i, (i & 7) * 0x9, ((i >> 3) & 7) * 0x9, ((i >> 6) & 3) * 0x15);
else if (modeinfo->colors < 256)
for (i = 0; i < 16; i++)
vga_setegacolor(i);
}
int colorcol(int column, int width, int xmax)
{
int color;
color = ((column << 8) - column) / xmax;
if (width != 8)
color &= 0xfc;
return color;
}
void drawtwidth(vga_modeinfo * modeinfo, char *bits, int x, int y, int tw, int th, int width)
{
unsigned char color;
int i, j, k, xmax, offset;
tw = (tw + 7) >> 3;
th <<= 1;
th += x;
xmax = vga_getxdim() - 1;
y *= modeinfo->linewidth;
for (i = x; i < th; i++) {
color = colorcol(xmax - i, width, xmax);
offset = y + i;
if ((i - x) & 1)
bits -= tw;
j = tw;
while (j--) {
k = 1;
do {
if (*bits & k) {
vga_setpage(offset >> 16);
graph_mem[offset & 0xffff] = color;
}
offset += modeinfo->linewidth;
if (*bits & k) {
vga_setpage(offset >> 16);
graph_mem[offset & 0xffff] = color;
}
offset += modeinfo->linewidth;
k <<= 1;
}
while (k & 0xff);
bits++;
}
}
}
void drawwidth(int mode, vga_modeinfo * modeinfo, int line, int height, int width)
{
unsigned char color;
int i, xmax, j, offset;
xmax = vga_getxdim() - 1;
for (i = 0; i < xmax; i++) {
color = colorcol(i, width, xmax);
offset = line * (modeinfo->linewidth) + i;
j = height;
while (j--) {
vga_setpage(offset >> 16);
graph_mem[offset & 0xffff] = color;
offset += modeinfo->linewidth;
}
}
j = clut_width + sixbpp_width;
j = height - j - j;
j /= 3;
drawtwidth(modeinfo, clut_bits, (xmax - 2 * clut_height) >> 1, j + line, clut_width, clut_height, width);
j += j + clut_width;
if (width == 6)
drawtwidth(modeinfo, sixbpp_bits, (xmax - 2 * sixbpp_height) >> 1, j + line, sixbpp_width, sixbpp_height, width);
else
drawtwidth(modeinfo, eightbpp_bits, (xmax - 2 * eightbpp_height) >> 1, j + line, eightbpp_width, eightbpp_height, width);
}
void testwidth(int mode, vga_modeinfo * modeinfo)
{
int ymax, i, old_flags;
ymax = vga_getydim();
if (vga_getxdim() < 640)
puts(" Warning: Resolution too small, displayed text is\n"
" probably scrambled.\n");
if (vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_FLAGS) & VGA_CLUT8) {
old_flags = vga_ext_set(VGA_EXT_SET, VGA_CLUT8);
for (i = 0; i < 256; i++)
vga_setpalette(i, RED(i), GREEN(i), BLUE(i));
puts(" Has support for CLUT width 8 bit");
drawwidth(mode, modeinfo, 0, ymax >> 1, 6);
drawwidth(mode, modeinfo, ymax >> 1, ymax >> 1, 8);
my_wait();
vga_clear();
vga_ext_set(VGA_EXT_RESET, old_flags);
} else {
for (i = 0; i < 256; i++)
vga_setpalette(i, RED(i) >> 2, GREEN(i) >> 2, BLUE(i) >> 2);
puts(" No support for CLUT width 8 bit");
drawwidth(mode, modeinfo, 0, ymax, 6);
my_wait();
}
}
void testfill(vga_modeinfo * modeinfo)
{
clock_t clk;
unsigned long pels = 0;
int xmax, ymax, lw, i, start, lim, x, y, w, h, mask;
lw = modeinfo->linewidth;
setcol(modeinfo);
vga_clear();
ymax = vga_getydim();
xmax = vga_getxdim();
srand(time(0));
clk = clock();
mask = modeinfo->colors - 1;
lim = ((xmax < ymax) ? xmax : ymax) >> 1;
for (i = 0, start = 0; i < lim; i++, start += lw + modeinfo->bytesperpixel) {
vga_fillblt(start, xmax - (i << 1), ymax - (i << 1), lw, mask & i);
pels += (xmax - (i << 1)) * (ymax - (i << 1));
}
for (i = 0; i < 10000; i++) {
x = rand() % xmax;
y = rand() % ymax;
w = rand() % (xmax - x);
h = rand() % (ymax - y);
switch (modeinfo->bytesperpixel) {
case 2:
x <<= 1;
break;
case 3:
x += (x << 1);
break;
case 4:
x <<= 2;
break;
}
vga_fillblt(x + y * lw, w, h, lw, mask & rand());
pels += w * h;
}
clk = clock() - clk;
printf(" Has FillBlt: %11lu Pixels in %.2f seconds -> %.2f Megapels\n",
pels, ((double) clk) / CLOCKS_PER_SEC, (pels / 1.0e6) / (((double) clk) / CLOCKS_PER_SEC));
my_wait();
}
void getlogo(void *blitimage, vga_modeinfo * modeinfo)
{
int i;
FILE *fd;
fd = fopen(LOGO_NAME, "r");
if (!fd) {
read_err:
perror("Problems reading linuxlogo.bitmap");
exit(2);
}
if (1 != fread(blitimage, LOGO_WIDTH * LOGO_HEIGHT, 1, fd))
goto read_err;
fclose(fd);
switch (modeinfo->bytesperpixel) {
/* Nothing todo for 256 colors! */
case 2:
{
unsigned char *bmp = (void *) blitimage;
unsigned short *bmpsh = (void *) blitimage;
bmp += LOGO_WIDTH * LOGO_HEIGHT;
bmpsh += LOGO_WIDTH * LOGO_HEIGHT;
i = LOGO_WIDTH * LOGO_HEIGHT;
if (modeinfo->colors == 32768) {
while (i--) {
bmp--;
*--bmpsh = ((((unsigned short) *bmp) & 7) << 12) |
((((unsigned short) *bmp) & 0x38) << 4) |
((((unsigned short) *bmp) & 0xc0) >> 3);
}
} else {
while (i--) {
bmp--;
*--bmpsh = ((((unsigned short) *bmp) & 7) << 13) |
((((unsigned short) *bmp) & 0x38) << 5) |
((((unsigned short) *bmp) & 0xc0) >> 3);
}
}
}
break;
case 3:
{
unsigned char *bmp = (void *) blitimage;
unsigned char *bmp3 = (void *) blitimage;
bmp += LOGO_WIDTH * LOGO_HEIGHT;
bmp3 += 3 * LOGO_WIDTH * LOGO_HEIGHT;
i = LOGO_WIDTH * LOGO_HEIGHT;
while (i--) {
bmp--;
*--bmp3 = ((((unsigned int) *bmp) & 7) << 5);
*--bmp3 = ((((unsigned int) *bmp) & 0x38) << 2);
*--bmp3 = ((((unsigned int) *bmp) & 0xc0));
}
}
break;
case 4:
{
unsigned char *bmp = (void *) blitimage;
unsigned int *bmpi = (void *) blitimage;
bmp += LOGO_WIDTH * LOGO_HEIGHT;
bmpi += LOGO_WIDTH * LOGO_HEIGHT;
i = LOGO_WIDTH * LOGO_HEIGHT;
if (modeinfo->flags & RGB_MISORDERED) {
while (i--) {
bmp--;
*--bmpi = ((((unsigned int) *bmp) & 7) << 29) |
((((unsigned int) *bmp) & 0x38) << 18) |
((((unsigned int) *bmp) & 0xc0) << 8);
}
} else {
while (i--) {
bmp--;
*--bmpi = ((((unsigned int) *bmp) & 7) << 21) |
((((unsigned int) *bmp) & 0x38) << 10) |
((((unsigned int) *bmp) & 0xc0));
}
}
}
break;
}
}
void testbit(vga_modeinfo * modeinfo)
{
clock_t clk;
unsigned long pels = 0, *blitimage;
int xmax, ymax, lw, i, x, y, dx, dy, nx, ny;
if ((modeinfo->bytesperpixel != 1) && (modeinfo->bytesperpixel != 2)) {
puts(" Has BitBlt, but no test code for this pixelwidth implemented.");
return;
}
ymax = vga_getydim();
xmax = vga_getxdim();
lw = modeinfo->linewidth;
if ((xmax < 210) || (ymax < 90)) {
puts(" Has BitBlt, but no test code for this small resolution implemented.");
return;
}
setcol(modeinfo);
vga_clear();
pels = 0;
blitimage = alloca(modeinfo->bytesperpixel * LOGO_WIDTH * LOGO_HEIGHT);
getlogo(blitimage, modeinfo);
if (modeinfo->bytesperpixel == 1) {
unsigned char *ptr = (void *) blitimage;
for (y = 1; y <= LOGO_HEIGHT; y++)
for (x = 1; x <= LOGO_WIDTH; x++) {
vga_setcolor((int) *ptr++);
vga_drawpixel(x, y);
}
} else {
unsigned short *ptr = (void *) blitimage;
for (y = 1; y <= LOGO_HEIGHT; y++)
for (x = 1; x <= LOGO_WIDTH; x++) {
vga_setcolor((int) *ptr++);
vga_drawpixel(x, y);
}
}
#ifdef BITFRAME
vga_setcolor(200);
vga_drawline(0, 0, 0, LOGO_HEIGHT + 1);
vga_drawline(0, 0, LOGO_WIDTH + 1, 0);
vga_drawline(LOGO_WIDTH + 1, 0, LOGO_WIDTH + 1, LOGO_HEIGHT + 1);
vga_drawline(0, LOGO_HEIGHT + 1, LOGO_WIDTH + 1, LOGO_HEIGHT + 1);
#endif
x = 0;
y = 0;
dx = 1;
dy = 1;
clk = clock();
for (i = 0; i < 10000; i++) {
nx = x + dx;
ny = y + dy;
if ((nx + LOGO_WIDTH + 2 > xmax) || (nx < 0)) {
dx = -dx;
nx = x + dx;
}
if ((ny + LOGO_HEIGHT + 2 > ymax) || (ny < 0)) {
dy = -dy;
ny = y + dy;
}
if (modeinfo->bytesperpixel == 2) {
vga_bitblt((x + y * (lw >> 1)) << 1,
(nx + ny * (lw >> 1)) << 1,
LOGO_WIDTH + 2, LOGO_HEIGHT + 2, lw);
} else {
vga_bitblt(x + y * lw, nx + ny * lw, LOGO_WIDTH + 2, LOGO_HEIGHT + 2, lw);
}
pels += (LOGO_WIDTH + 2) * (LOGO_HEIGHT + 2);
x = nx;
y = ny;
}
clk = clock() - clk;
printf(" Has BitBlt: %12lu Pixels in %.2f seconds -> %.2f Megapels\n",
pels, ((double) clk) / CLOCKS_PER_SEC, (pels / 1.0e6) / (((double) clk) / CLOCKS_PER_SEC));
my_wait();
}
void testimage(vga_modeinfo * modeinfo)
{
clock_t clk;
unsigned long pels = 0, *blitimage;
int xmax, ymax, lw, i, x, y;
if ((modeinfo->bytesperpixel < 1) || (modeinfo->bytesperpixel > 4)) {
puts(" Has ImageBlt, but no test code for this pixelwidth implemented.");
return;
}
ymax = vga_getydim();
xmax = vga_getxdim();
lw = modeinfo->linewidth;
if ((xmax < 210) || (ymax < 90)) {
puts(" Has ImageBlt, but no test code for this small resolution implemented.");
return;
}
/* Prepare a simple test pattern for testuse: */
switch (modeinfo->bytesperpixel) {
default:
{
/* 8bpp: */
register unsigned char *ptr, *pt_fish = fish_monster;
blitimage = alloca(fish_monster_w * fish_monster_h);
ptr = (unsigned char *) blitimage;
for (i = 0; i < (fish_monster_w * fish_monster_h); i++)
*ptr++ = fish_monster233[(*pt_fish++) - '`'];
}
break;
case 2:
{
register unsigned char *pt_fish = fish_monster;
register unsigned short *ptr, *coltab;
blitimage = alloca(sizeof(unsigned short) * fish_monster_w * fish_monster_h);
ptr = (unsigned short *) blitimage;
if (modeinfo->colors == 32768)
coltab = fish_monster555;
else
coltab = fish_monster565;
for (i = 0; i < (fish_monster_w * fish_monster_h); i++)
*ptr++ = coltab[(*pt_fish++) - '`'];
}
break;
case 3:
{
register unsigned char *pt_fish = fish_monster;
register unsigned char *ptr, *coltab;
blitimage = alloca(3 * fish_monster_w * fish_monster_h);
ptr = (unsigned char *) blitimage;
coltab = (unsigned char *) fish_monster888;
for (i = 0; i < (fish_monster_w * fish_monster_h); i++) {
*ptr++ = coltab[(((*pt_fish) - '`') << 2)];
*ptr++ = coltab[(((*pt_fish) - '`') << 2) + 1];
*ptr++ = coltab[(((*pt_fish++) - '`') << 2) + 2];
}
}
break;
case 4:
{
register unsigned char *pt_fish = fish_monster;
register unsigned int *ptr, *coltab;
blitimage = alloca(sizeof(unsigned int) * fish_monster_w * fish_monster_h);
ptr = (unsigned int *) blitimage;
coltab = fish_monster888;
if (modeinfo->flags & RGB_MISORDERED) {
for (i = 0; i < (fish_monster_w * fish_monster_h); i++)
*ptr++ = (coltab[(*pt_fish++) - '`'] << 8);
} else {
for (i = 0; i < (fish_monster_w * fish_monster_h); i++)
*ptr++ = coltab[(*pt_fish++) - '`'];
}
}
break;
}
setcol(modeinfo);
vga_clear();
srand(time(0));
for (i = 0; i < 10000; i++) {
x = rand() % (xmax - fish_monster_w);
y = rand() % (ymax - fish_monster_h);
if (modeinfo->bytesperpixel > 1)
x *= modeinfo->bytesperpixel;
vga_imageblt(blitimage, x + y * lw, fish_monster_w, fish_monster_h, lw);
pels += fish_monster_w * fish_monster_h;
}
pels = 0;
blitimage = alloca(modeinfo->bytesperpixel * LOGO_WIDTH * LOGO_HEIGHT);
getlogo(blitimage, modeinfo);
clk = clock();
for (i = 0; i < 1000; i++) {
x = rand() % (xmax - LOGO_WIDTH);
y = rand() % (ymax - LOGO_HEIGHT);
if (modeinfo->bytesperpixel > 1)
x *= modeinfo->bytesperpixel;
vga_imageblt(blitimage, x + y * lw, LOGO_WIDTH, LOGO_HEIGHT, lw);
pels += LOGO_WIDTH * LOGO_HEIGHT;
}
clk = clock() - clk;
printf(" Has ImageBlt: %10lu Pixels in %.2f seconds -> %.2f Megapels\n",
pels, ((double) clk) / CLOCKS_PER_SEC, (pels / 1.0e6) / (((double) clk) / CLOCKS_PER_SEC));
my_wait();
}
void hlinesquare(hlinelst * des, register int n)
{
register int *xmin, *xmax;
if (n < 1)
n = 1;
des->n = n;
des->width = n;
des->offset = 0;
des->pels = n * n;
xmin = (int *) ((char *) des + sizeof(hlinelst));
xmax = xmin + n;
while (n--) {
*xmin++ = 0;
*xmax++ = des->width - 1;
}
}
void hlinedisk(hlinelst * des, register int n)
{
register int *xmin, *xmax, radsq, rad, x;
if (!(n & 1))
n--;
if (n < 1)
n = 1;
des->n = n;
des->width = n;
des->offset = 0;
des->pels = n * n;
rad = (n >> 1);
radsq = rad * rad;
xmin = (int *) ((char *) des + sizeof(hlinelst));
xmax = xmin + n;
while (n--) {
x = sqrt(radsq - isqr(n - rad));
*xmin++ = rad - x;
*xmax++ = rad + x;
}
}
void hlinecaro(hlinelst * des, register int n)
{
register int *xmin, *xmax, i, j;
if (!(n & 1))
n--;
if (n < 1)
n = 1;
des->n = n;
des->width = n;
des->offset = 0;
des->pels = (n * n) / 2;
xmin = (int *) ((char *) des + sizeof(hlinelst));
xmax = xmin + n;
i = 1 + (n >> 1);
j = 0;
while (i--) {
*xmin++ = (n >> 1) - j;
*xmax++ = (n >> 1) + j;
j++;
}
i = (n >> 1);
j -= 2;
while (i--) {
*xmin++ = (n >> 1) - j;
*xmax++ = (n >> 1) + j;
j--;
}
}
void testhline(vga_modeinfo * modeinfo)
{
#define SHAPES 9
clock_t clk;
unsigned long pels = 0;
hlinelst *shape[SHAPES], *curs;
int xmax, ymax, lw, i, x, y, mask;
setcol(modeinfo);
vga_clear();
ymax = vga_getydim();
xmax = vga_getxdim();
lw = modeinfo->linewidth;
mask = modeinfo->colors - 1;
srand(time(0));
i = 0;
shape[i] = alloca(sizhlilst(ymax / 2));
hlinesquare(shape[i++], ymax / 2);
shape[i] = alloca(sizhlilst(ymax / 4));
hlinesquare(shape[i++], ymax / 4);
shape[i] = alloca(sizhlilst(ymax / 8));
hlinesquare(shape[i++], ymax / 8);
shape[i] = alloca(sizhlilst(ymax / 2));
hlinecaro(shape[i++], ymax / 2);
shape[i] = alloca(sizhlilst(ymax / 4));
hlinecaro(shape[i++], ymax / 4);
shape[i] = alloca(sizhlilst(ymax / 8));
hlinecaro(shape[i++], ymax / 8);
shape[i] = alloca(sizhlilst(ymax / 2));
hlinedisk(shape[i++], ymax / 2);
shape[i] = alloca(sizhlilst(ymax / 4));
hlinedisk(shape[i++], ymax / 4);
shape[i] = alloca(sizhlilst(ymax / 8));
hlinedisk(shape[i++], ymax / 8);
clk = clock();
for (i = 0; i < 1000; i++) {
curs = shape[rand() % SHAPES];
x = rand() % (xmax - (curs->width));
y = rand() % (ymax - (curs->n));
adj_hlilst(curs, x);
pels += curs->pels;
vga_hlinelistblt(y, curs->n,
(int *) (((char *) curs) + sizeof(hlinelst)),
(int *) (((char *) curs) + sizeof(hlinelst) + (curs->n) * sizeof(int)),
lw, mask & rand());
}
clk = clock() - clk;
clk++;
printf(" Has HlineLst: %10lu Pixels in %.2f seconds -> %.2f Megapels\n",
pels, ((double) clk) / CLOCKS_PER_SEC, (pels / 1.0e6) / (((double) clk) / CLOCKS_PER_SEC));
my_wait();
}
void testmode(int mode)
{
vga_modeinfo *modeinfo;
printf("Testing mode %2d: %s...", mode, vga_getmodename(mode));
if (!vga_hasmode(mode)) {
puts(" not available");
return;
}
puts("");
vga_setmode(mode);
modeinfo = vga_getmodeinfo(mode);
if ((modeinfo->colors == 256) && !(modeinfo->flags & IS_MODEX)) {
testwidth(mode, modeinfo);
} else
puts(" Dacwidth test not applicable.");
if (modeinfo->haveblit & HAVE_BITBLIT)
testbit(modeinfo);
if (modeinfo->haveblit & HAVE_FILLBLIT)
testfill(modeinfo);
if (modeinfo->haveblit & HAVE_IMAGEBLIT)
testimage(modeinfo);
if (modeinfo->haveblit & HAVE_HLINELISTBLIT)
testhline(modeinfo);
vga_setmode(TEXT);
}
void usage(void)
{
puts("Usage: testaccel [-nowait] {all|[mode [mode [mode...]]]}\n"
"\ttests accelerated features and extended options in\n"
"\tall or the given modes.\n"
"\tAll standard svgalib ways of writing modenames are understood.\n"
"\tIf no parameters are given the defaultmode or G640x480x256 is\n"
"\tused.\n"
"\tIf -nowait is given, don't wait for a keypress after each test.");
exit(2);
}
int main(int argc, char *argv[])
{
int mode;
vga_init();
puts(
"Note: Timings include main cpu calculations (random numbers and such\n"
" things). Thus they are esp. for lower resolutions much too slow!");
if ((argc > 1) && !strcmp(argv[1], "-nowait")) {
argc--;
argv++;
waitmode = 0;
}
if ((argc == 2) && !strcmp(argv[1], "all")) {
int flag = 0;
for (mode = 1; mode <= GLASTMODE; mode++)
if (vga_hasmode(mode)) {
flag = 1;
testmode(mode);
}
if (!flag)
puts("testaccel: Not any graphicsmode available!");
} else if (argc > 1) {
for (mode = 1; mode < argc; mode++)
if (vga_getmodenumber(argv[mode]) < 0) {
printf("testaccel: Parameter %s is not a valid graphicsmode.\n", argv[mode]);
usage();
}
for (mode = 1; mode < argc; mode++)
testmode(vga_getmodenumber(argv[mode]));
} else {
mode = vga_getdefaultmode();
if (mode < 0)
mode = G640x480x256;
if (vga_hasmode(mode))
testmode(mode);
else
puts("testaccel: could not set defaultmode or G640x480x256!");
}
return 0;
}

230
demos/testgl.c Normal file
View file

@ -0,0 +1,230 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <vga.h>
#include <vgagl.h>
/* The logo was drawn by John Remyn. */
/* Feel free to provide a more beautiful/official/thought provoking/cool */
/* logo to replace it. */
#define LOGOWIDTH 201
#define LOGOHEIGHT 85
int VGAMODE;
int VIRTUAL;
int timescale=1;
GraphicsContext *backscreen;
GraphicsContext *physicalscreen;
void *logobitmap;
void loadbitmap(char *filename, void *buf)
{
FILE *f;
f = fopen(filename, "rb");
if(f==NULL)return;
fread(buf, 1, 17085, f);
fclose(f);
}
void test(void)
{
int i, j;
unsigned char *bitmap;
GraphicsContext *savedcontext;
if (VIRTUAL)
gl_setcontext(backscreen);
gl_clearscreen(0);
for (i = 0; i < 5; i++) {
gl_clearscreen(0);
for (j = 0; j < 20000*timescale; j++)
gl_setpixel(random() % WIDTH, random() % HEIGHT,
random() % COLORS);
}
if (VIRTUAL)
gl_copyscreen(physicalscreen);
gl_clearscreen(0);
for (i = 0; i < 5000*timescale; i++) {
int x, y;
x = random() % (WIDTH - 1);
y = random() % (HEIGHT - 1);
gl_fillbox(x, y, random() % (WIDTH - x), random()
% (HEIGHT - y), random() % COLORS);
}
if (VIRTUAL)
gl_copyscreen(physicalscreen);
gl_clearscreen(0);
for (i = 0; i < 4000*timescale; i++)
gl_line(random() % WIDTH, random() % HEIGHT,
random() % WIDTH, random() % HEIGHT,
random() % COLORS);
if (VIRTUAL)
gl_copyscreen(physicalscreen);
/* Create bitmap. */
bitmap = malloc(64 * 64 * BYTESPERPIXEL);
/* Create temporary graphics context to create bitmap in. */
savedcontext = gl_allocatecontext();
gl_getcontext(savedcontext);
gl_setcontextvirtual(64, 64, BYTESPERPIXEL, BITSPERPIXEL, bitmap);
/* The rgb functions can be used to create nice bitmaps easily for */
/* hicolor/truecolor modes. The 256 color 'emulated' truecolor */
/* looks less impressive. */
for (i = 0; i < 32; i++)
for (j = 0; j < 32; j++) {
int c;
c = 255 - (i + j) * 4;
gl_setpixelrgb(31 - i, 31 - j, c, 0, 0);
gl_setpixelrgb(32 + i, 31 - j, c, c, 0);
gl_setpixelrgb(31 - i, 32 + j, c, 0, c);
gl_setpixelrgb(32 + i, 32 + j, c, c, c);
}
/* Restore previous context. */
gl_setcontext(savedcontext);
gl_clearscreen(0);
for (i = 0; i < 4000*timescale; i++) {
int x, y;
x = random() % (WIDTH - 64 + 1);
y = random() % (HEIGHT - 64 + 1);
gl_putbox(x, y, 64, 64, bitmap);
}
free(bitmap);
if (VIRTUAL)
gl_copyscreen(physicalscreen);
}
void setcustompalette(void)
{
/* colors 0-31 are an RGB mix (bits 0 and 1 red, 2 green, 3 and 4 blue) */
/* 32-63 black to red */
/* 64-95 black to green */
/* 96-127 black to yellow */
/* 128-159 black to blue */
/* 160-191 black to magenta */
/* 192-223 black to cyan */
/* 224-255 black to white */
Palette pal;
int i;
for (i = 0; i < 256; i++) {
int r, g, b;
r = g = b = 0;
if ((i & 32) > 0)
r = (i & 31) << 1;
if ((i & 64) > 0)
g = (i & 31) << 1;
if ((i & 128) > 0)
b = (i & 31) << 1;
if (i < 32) {
r = (i & 3) << 4; /* 2 bits */
g = (i & 4) << 3; /* 1 bit */
b = (i & 24) << 1; /* 2 bits */
}
pal.color[i].red = r;
pal.color[i].green = g;
pal.color[i].blue = b;
}
gl_setpalette(&pal);
}
void logotest(void)
{
int h;
void *scaled;
/* Set logo palette. */
setcustompalette();
/* Create logo bitmap */
logobitmap = alloca(LOGOWIDTH * LOGOHEIGHT);
loadbitmap("linuxlogo.bitmap", logobitmap);
/* Allocate buffer for scaled bitmap. */
scaled = alloca(WIDTH * HEIGHT);
gl_clearscreen(0);
/* Stretch vertically. */
for (h = 0; h <= LOGOHEIGHT; h++) {
gl_scalebox(LOGOWIDTH, LOGOHEIGHT, logobitmap,
LOGOWIDTH, h, scaled);
gl_putbox(0, 0, LOGOWIDTH, h, scaled);
if (VIRTUAL)
gl_copyscreen(physicalscreen);
usleep(10000);
}
gl_clearscreen(0);
/* Scale to screen resolution. */
gl_scalebox(LOGOWIDTH, LOGOHEIGHT, logobitmap, WIDTH, HEIGHT, scaled);
gl_putbox(0, 0, WIDTH, HEIGHT, scaled);
gl_copyscreen(physicalscreen);
}
int main(int argc, char *argv[])
{
vga_init();
if(argc>=2) {
timescale=atoi(argv[1]);
if(timescale<1)timescale=1;
}
VGAMODE = vga_getdefaultmode();
if (VGAMODE == -1)
VGAMODE = G320x200x256; /* Default mode. */
if (!vga_hasmode(VGAMODE)) {
printf("Mode not available.\n");
exit(-1);
}
VIRTUAL = 0; /* No virtual screen. */
if (vga_getmodeinfo(VGAMODE)->colors == 16 ||
(vga_getmodeinfo(VGAMODE)->flags & IS_MODEX))
/* These modes are supported indirectly by vgagl. */
VIRTUAL = 1;
if (VIRTUAL) {
/* Create virtual screen. */
gl_setcontextvgavirtual(VGAMODE);
backscreen = gl_allocatecontext();
gl_getcontext(backscreen);
}
vga_setmode(VGAMODE);
gl_setcontextvga(VGAMODE); /* Physical screen context. */
physicalscreen = gl_allocatecontext();
gl_getcontext(physicalscreen);
if (COLORS == 256)
gl_setrgbpalette();
if(argc==3)sleep(2);
test();
/* Now do the same with clipping enabled. */
gl_clearscreen(0);
gl_setclippingwindow(WIDTH / 4, HEIGHT / 4, WIDTH - WIDTH / 4 - 1,
HEIGHT - HEIGHT / 4 - 1);
test();
gl_disableclipping();
if (COLORS == 256)
/* Show the logo if using 256 color mode. */
logotest();
getchar();
if (VIRTUAL)
gl_freecontext(backscreen);
vga_setmode(TEXT);
exit(0);
}

124
demos/testlinear.c Normal file
View file

@ -0,0 +1,124 @@
/*
Simple test program for Cirrus linear addressing/color expansion.
vgagl can take advantage of it (linear addressing).
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vga.h>
#include <time.h>
#include "../src/libvga.h"
#define USE_LINEAR_ADDRESSING
/* #define USE_BY16_ADDRESSING */
unsigned char *vbuf;
#if 0
/* This function is Cirrus specific and has nothing to do with linear
* addressing. */
void by8test(void)
{
int i;
int startclock, diffclock;
/* Enable extended write modes and BY8/16 addressing. */
outb(0x3ce, 0x0b);
#ifdef USE_BY16_ADDRESSING
outb(0x3cf, inb(0x3cf) | 0x16);
#else
outb(0x3cf, inb(0x3cf) | 0x06);
#endif
/* Set extended write mode 4. */
outb(0x3ce, 0x05);
outb(0x3cf, (inb(0x3cf) & 0xf8) | 4);
/* Set pixel mask register (coincides with VGA plane mask register). */
outw(0x3c4, 0xff02);
startclock = clock();
for (i = 0; i < 248; i++) {
outw(0x3ce, 0x01 + (i << 8)); /* Set foreground color. */
#ifdef USE_BY16_ADDRESSING
outw(0x3ce, 0x11 + (i << 8)); /* Set high byte. */
memset(vbuf, 0xff, 640 * 480 / 16);
#else
memset(vbuf, 0xff, 640 * 480 / 8);
#endif
}
diffclock = clock() - startclock;
printf("Color expansion framebuffer fill speed: %dK/s\n",
640 * 480 * 248 / diffclock / 10);
}
#endif
int main(int argc, char *argv[])
{
int i,j;
if (!(argc == 2 && strcmp(argv[1], "--force") == 0))
if (!(vga_getmodeinfo(vga_getdefaultmode())->flags & CAPABLE_LINEAR)) {
printf("Linear addressing not supported for this chipset.\n");
exit(1);
}
vga_init();
vga_setmode(vga_getdefaultmode());
vga_setpage(0);
#ifdef USE_LINEAR_ADDRESSING
if (vga_setlinearaddressing() == -1) {
vga_setmode(TEXT);
printf("Could not set linear addressing.\n");
exit(-1);
}
#endif
/* Should not mess with bank register after this. */
vbuf = vga_getgraphmem();
printf("vbuf mapped at %08lx.\n", (unsigned long) vbuf);
getchar();
#ifdef USE_LINEAR_ADDRESSING
memset(vbuf, 0x88, 640 * 480);
sleep(1);
memset(vbuf, 0, 640 * 480);
for (i = 0; i < 100000; i++)
*(vbuf + (rand() & 0xfffff)) = rand();
#endif
#if 0
if (vga_getcurrentchipset() == CIRRUS)
/* Show the bandwidth of the extended write modes of the */
/* Cirrus chip. */
by8test();
#endif
getchar();
for(i = 0;i < 44;i++){
*(vbuf + i) = 0x1c;
*(vbuf + 640*17 + i) = 0x1c;
*(vbuf + 640*480 - i) = 0x1c;
*(vbuf + 640*480 - 1 - 640*17 - i) = 0x1c;
for(j = 1;j < 17;j++){
*(vbuf + 640*j + i) = (i == 0 || i == 43)? 0x1c:0;
*(vbuf + 640*480 - 1 - 640*j - i) = (i == 0 || i == 43)? 0x1c:0;
}
}
for(i = 3;i < 10;i++)
for(j = 4;j < 10;j++){
*(vbuf + i + 640*j) = 0x3f;
*(vbuf + 640*480 -1 -640*j - i) = 0x3f;
}
getchar();
vga_setmode(TEXT);
return 0;
}

294
demos/vgatest.c Normal file
View file

@ -0,0 +1,294 @@
/* From VGAlib, changed for svgalib */
/* partially copyrighted (C) 1993 by Hartmut Schirmer */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> /* for usleep( long ) */
#include <string.h>
#include "vga.h"
static unsigned char line[2048 * 3];
static void
drawSquares(int const xmax, int const ymax)
{
unsigned int const center_x = xmax/2;
/* The column just to the left of the center (assuming
even number of columns)
*/
unsigned int const center_y = ymax/2;
/* The line just above the center (assuming
even number of lines)
*/
int x;
for (x = 0; x < 64; x++) {
int y;
for (y = 0; y < 64; y++) {
/* Top 3 squares */
vga_setrgbcolor(x * 4 + 3, y * 4 + 3, 0);
vga_drawpixel(center_x - 32 - 32 - 64 + x, center_y - 80 + y);
vga_setrgbcolor(x * 4 + 3, 0, y * 4 + 3);
vga_drawpixel(center_x - 32 + x, center_y - 80 + y);
vga_setrgbcolor(0, x * 4 + 3, y * 4 + 3);
vga_drawpixel(center_x + 32 + 32 + x, center_y - 80 + y);
/* Bottom 3 squares */
vga_setrgbcolor(x * 4 + 3, y * 4 + 3, 255);
vga_drawpixel(center_x - 32 - 32 - 64 + x, center_y + 16 + y);
vga_setrgbcolor(x * 4 + 3, 255, y * 4 + 3);
vga_drawpixel(center_x - 32 + x, center_y + 16 + y);
vga_setrgbcolor(255, x * 4 + 3, y * 4 + 3);
vga_drawpixel(center_x + 32 + 32 + x, center_y + 16 + y);
}
}
}
static void testmode(int mode)
{
int xmax, ymax, i, x, y, yw, ys, c;
vga_modeinfo *modeinfo;
vga_setmode(mode);
modeinfo = vga_getmodeinfo(mode);
printf("Width: %d Height: %d Colors: %d\n",
modeinfo->width,
modeinfo->height,
modeinfo->colors);
printf("DisplayStartRange: %xh Maxpixels: %d Blit: %s\n",
modeinfo->startaddressrange,
modeinfo->maxpixels,
modeinfo->haveblit ? "YES" : "NO");
#ifdef TEST_MODEX
if (modeinfo->colors == 256)
printf("Switching to ModeX ... %s\n",
(vga_setmodeX()? "done" : "failed"));
#endif
vga_screenoff();
xmax = vga_getxdim() - 1;
ymax = vga_getydim() - 1;
vga_setcolor(vga_white());
vga_drawline(0, 0, xmax, 0);
vga_drawline(xmax, 0, xmax, ymax);
vga_drawline(xmax, ymax, 0, ymax);
vga_drawline(0, ymax, 0, 0);
/* Draw crosses */
for (i = 0; i <= 15; i++) {
vga_setegacolor(i);
vga_drawline(10 + i * 5, 10, 89 + i * 5, 89);
}
for (i = 0; i <= 15; i++) {
vga_setegacolor(i);
vga_drawline(89 + i * 5, 10, 10 + i * 5, 89);
}
vga_screenon();
ys = 100;
yw = (ymax - 100) / 4;
switch (vga_getcolors()) {
case 256:
/* Draw horizontal color bands using palette */
for (i = 0; i < 60; ++i) {
c = (i * 64) / 60;
vga_setpalette(i + 16, c, c, c);
vga_setpalette(i + 16 + 60, c, 0, 0);
vga_setpalette(i + 16 + (2 * 60), 0, c, 0);
vga_setpalette(i + 16 + (3 * 60), 0, 0, c);
}
line[0] = line[xmax] = 15;
line[1] = line[xmax - 1] = 0;
for (x = 2; x < xmax - 1; ++x)
line[x] = (((x - 2) * 60) / (xmax - 3)) + 16;
for (y = ys; y < ys + yw; ++y) /* gray */
vga_drawscanline(y, line);
for (x = 2; x < xmax - 1; ++x)
line[x] += 60;
ys += yw;
for (y = ys; y < ys + yw; ++y) /* red */
vga_drawscanline(y, line);
for (x = 2; x < xmax - 1; ++x)
line[x] += 60;
ys += yw;
for (y = ys; y < ys + yw; ++y) /* green */
vga_drawscanline(y, line);
for (x = 2; x < xmax - 1; ++x)
line[x] += 60;
ys += yw;
for (y = ys; y < ys + yw; ++y) /* blue */
vga_drawscanline(y, line);
break;
case 1 << 15:
case 1 << 16:
case 1 << 24:
/* Draw horizontal color bands in RGB */
for (x = 2; x < xmax - 1; ++x) {
c = ((x - 2) * 255) / (xmax - 4);
y = ys;
vga_setrgbcolor(c, c, c);
vga_drawline(x, y, x, y + yw - 1);
y += yw;
vga_setrgbcolor(c, 0, 0);
vga_drawline(x, y, x, y + yw - 1);
y += yw;
vga_setrgbcolor(0, c, 0);
vga_drawline(x, y, x, y + yw - 1);
y += yw;
vga_setrgbcolor(0, 0, c);
vga_drawline(x, y, x, y + yw - 1);
}
drawSquares(xmax, ymax);
break;
default:
/* Draw vertical color bars */
if (vga_getcolors() == 16) {
for (i = 0; i < xmax - 1; i++)
line[i] = (i + 2) % 16;
line[0] = line[xmax] = 15;
line[1] = line[xmax - 1] = 0;
}
if (vga_getcolors() == 2) {
for (i = 0; i <= xmax; i++)
line[i] = 0x11;
line[0] = 0x91;
}
for (i = 100; i < ymax - 1; i++)
vga_drawscanline(i, line);
break;
}
if (getchar() == 'd')
vga_dumpregs();
}
int main(int argc, char *argv[])
{
int mode, mode2;
int i, high;
vga_init(); /* Initialize. */
mode = -1;
mode2= -1;
if(argc==2) {
mode = atoi(argv[1]);
} else if(argc==3) {
mode = atoi(argv[1]);
mode2= atoi(argv[2]);
}
if (mode == -1) {
printf("Choose one of the following video modes: \n");
high = 0;
for (i = 1; i <= vga_lastmodenumber(); i++)
if (vga_hasmode(i)) {
vga_modeinfo *info;
char expl[100];
const char *cols = NULL;
*expl = '\0';
info = vga_getmodeinfo(i);
switch (info->colors) {
case 2:
cols = "2";
strcpy(expl, "1 bitplane, monochrome");
break;
case 16:
cols = "16";
strcpy(expl, "4 bitplanes");
break;
case 256:
if (i == G320x200x256)
strcpy(expl, "packed-pixel");
else if (i == G320x240x256
|| i == G320x400x256
|| i == G360x480x256)
strcpy(expl, "Mode X");
else
strcpy(expl,
"packed-pixel, banked");
break;
case 1 << 15:
cols = "32K";
strcpy(expl, "5-5-5 RGB, blue at LSB, banked");
break;
case 1 << 16:
cols = "64K";
strcpy(expl, "5-6-5 RGB, blue at LSB, banked");
break;
case 1 << 24:
cols = "16M";
if (info->bytesperpixel == 3) {
if (info->flags & RGB_MISORDERED)
strcpy(expl, "8-8-8 BGR, red byte first, banked");
else
strcpy(expl, "8-8-8 RGB, blue byte first, banked");
} else if (info->flags & RGB_MISORDERED)
strcpy(expl, "8-8-8 RGBX, 32-bit pixels, X byte first, banked");
else
strcpy(expl, "8-8-8 XRGB, 32-bit pixels, blue byte first, banked");
break;
}
if (info->flags & IS_INTERLACED) {
if (*expl != '\0')
strcat(expl, ", ");
strcat(expl, "interlaced");
}
if (info->flags & IS_DYNAMICMODE) {
if (*expl != '\0')
strcat(expl, ", ");
strcat(expl, "dynamically loaded");
}
high = i;
printf("%5d: %dx%d, ",
i, info->width, info->height);
if (cols == NULL)
printf("%d", info->colors);
else
printf("%s", cols);
printf(" colors ");
if (*expl != '\0')
printf("(%s)", expl);
printf("\n");
}
printf("Enter mode number (1-%d): ", high);
scanf("%d", &mode);
getchar();
printf("\n");
if (mode < 1 || mode > GLASTMODE) {
printf("Error: Mode number out of range \n");
exit(-1);
}
}
if (vga_hasmode(mode)) {
testmode(mode);
if(mode2!=-1 && vga_hasmode(mode2)) {
testmode(mode2);
}
} else {
printf("Error: Video mode not supported by driver\n");
exit(-1);
}
vga_setmode(TEXT);
return 0;
}

131
demos/vgatweak.c Normal file
View file

@ -0,0 +1,131 @@
/* From VGAlib, changed for svgalib */
/* partially copyrighted (C) 1993 by Hartmut Schirmer */
#include <stdio.h>
#include <unistd.h> /* for usleep( long ) */
#include <string.h>
#include "vga.h"
static unsigned char line[2048 * 3];
static void testmode(int mode)
{
int xmax, ymax, i, yw, ys;
unsigned char buf[60];
vga_modeinfo *modeinfo;
vga_setmode(mode);
modeinfo = vga_getmodeinfo(mode);
printf("Width: %d Height: %d Colors: %d\n",
modeinfo->width,
modeinfo->height,
modeinfo->colors);
printf("DisplayStartRange: %xh Maxpixels: %d Blit: %s\n",
modeinfo->startaddressrange,
modeinfo->maxpixels,
modeinfo->haveblit ? "YES" : "NO");
vga_screenoff();
xmax = vga_getxdim() - 1;
ymax = vga_getydim() - 1;
vga_setcolor(vga_white());
vga_drawline(0, 0, xmax, 0);
vga_drawline(xmax, 0, xmax, ymax);
vga_drawline(xmax, ymax, 0, ymax);
vga_drawline(0, ymax, 0, 0);
for (i = 0; i <= 15; i++) {
vga_setegacolor(i);
vga_drawline(10 + i * 5, 10, 90 + i * 5, 90);
}
for (i = 0; i <= 15; i++) {
vga_setegacolor(i);
vga_drawline(90 + i * 5, 10, 10 + i * 5, 90);
}
vga_screenon();
ys = 100;
yw = (ymax - 100) / 4;
for (i = 0; i < xmax - 1; i++)
line[i] = (i + 2) % 16;
line[0] = line[xmax] = 15;
line[1] = line[xmax - 1] = 0;
for (i = 100; i < ymax - 1; i++)
vga_drawscanline(i, line);
if (getchar() == 'd')
vga_dumpregs();
vga_getcrtcregs(buf);
buf[0]=0x4d;
buf[1]=0x3f;
buf[2]=0x3f;
buf[3]=0x80;
buf[4]=0x41;
buf[5]=0x10;
vga_setcrtcregs(buf);
for(i=0;i<20;i++) {
vga_setdisplaystart(i);
usleep(200000);
vga_waitretrace();
}
vga_getch();
vga_setmode(TEXT);
}
int main(void)
{
int mode;
int i, high;
vga_init(); /* Initialize. */
mode = 4;
if (mode == -1) {
printf("Choose one of the following video modes: \n");
high = 0;
for (i = 1; i <= vga_lastmodenumber(); i++)
if (vga_hasmode(i)) {
vga_modeinfo *info;
char expl[100];
char *cols = NULL;
*expl = '\0';
info = vga_getmodeinfo(i);
cols = "16";
strcpy(expl, "4 bitplanes");
high = i;
printf("%5d: %dx%d, ",
i, info->width, info->height);
if (cols == NULL)
printf("%d", info->colors);
else
printf("%s", cols);
printf(" colors ");
if (*expl != '\0')
printf("(%s)", expl);
printf("\n");
}
}
if (vga_hasmode(mode))
testmode(mode);
else {
printf("Error: Video mode not supported by driver\n");
exit(-1);
}
return 0;
}

45
demos/wizard.xbm Normal file
View file

@ -0,0 +1,45 @@
#define wizard_width 67
#define wizard_height 55
static unsigned char wizard_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xc0, 0xff, 0x07, 0x00, 0x80, 0x7f, 0x00, 0x00, 0x00, 0xe0,
0xff, 0x07, 0x00, 0x40, 0x80, 0x00, 0x00, 0x00, 0xf0, 0xfd, 0x0f, 0x00,
0xa0, 0x24, 0x01, 0x00, 0x00, 0x78, 0xfc, 0x1f, 0x00, 0xd0, 0xb2, 0x01,
0x00, 0x00, 0x18, 0xf8, 0x3f, 0x00, 0xc8, 0x9a, 0x00, 0x00, 0x00, 0x08,
0xae, 0x3f, 0x00, 0x64, 0xfd, 0x00, 0x00, 0x00, 0x80, 0xff, 0x3f, 0x00,
0xf8, 0xbf, 0x00, 0x00, 0x00, 0x40, 0xff, 0x9f, 0x1f, 0x20, 0xfe, 0x00,
0x00, 0x80, 0xff, 0x00, 0xe0, 0x67, 0x20, 0x9c, 0x00, 0x00, 0xe0, 0xe0,
0xff, 0xff, 0x80, 0x30, 0x4c, 0x00, 0x00, 0xd0, 0x87, 0xff, 0x07, 0x3e,
0x39, 0x44, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x80, 0xff, 0x38, 0x23, 0x00,
0x00, 0xf8, 0xff, 0x00, 0xf0, 0xff, 0x9c, 0x11, 0x00, 0x00, 0xe0, 0xff,
0xff, 0xff, 0x3f, 0xdc, 0x08, 0x00, 0x00, 0x00, 0x3c, 0xdb, 0xe4, 0x0e,
0xde, 0x04, 0x00, 0x00, 0x00, 0x7f, 0x8c, 0x71, 0xfe, 0xdf, 0x0c, 0x00,
0x00, 0xf0, 0xf7, 0x87, 0xbf, 0xfd, 0xee, 0x0c, 0x00, 0x00, 0xf8, 0xfb,
0xcf, 0x3f, 0xfb, 0xee, 0x0e, 0x00, 0x00, 0xff, 0xaf, 0x7b, 0x07, 0x3e,
0xd5, 0x1f, 0x00, 0xe0, 0x80, 0x57, 0xfd, 0x14, 0xae, 0xe7, 0x1e, 0x00,
0x10, 0x0b, 0x3e, 0x74, 0x05, 0x9d, 0xcd, 0x1f, 0x00, 0xc8, 0x00, 0x5c,
0x04, 0x81, 0x1f, 0x87, 0x1e, 0x00, 0x6c, 0x60, 0x18, 0x00, 0x00, 0x6e,
0xf0, 0x1f, 0x00, 0x74, 0x30, 0x72, 0x01, 0x80, 0xbf, 0xec, 0x1e, 0x00,
0x74, 0x00, 0x33, 0x00, 0x10, 0xff, 0xff, 0x1f, 0x00, 0xf6, 0x80, 0xb1,
0x05, 0xa0, 0xff, 0xff, 0x1e, 0x00, 0xf6, 0xf8, 0xf9, 0x80, 0xe8, 0xff,
0xff, 0x0f, 0x00, 0x66, 0x77, 0x7d, 0x13, 0xca, 0xff, 0x7f, 0x0f, 0x00,
0x7e, 0x37, 0xfb, 0xbb, 0xde, 0xff, 0xff, 0x0f, 0x00, 0x76, 0x32, 0xfd,
0xbf, 0xff, 0xff, 0xbd, 0x07, 0x00, 0x46, 0x92, 0xfe, 0xff, 0xff, 0xff,
0xbf, 0x07, 0x00, 0x3e, 0xe4, 0xfb, 0xff, 0xff, 0xff, 0xfd, 0x03, 0x00,
0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0x03, 0x00, 0xfc, 0xef, 0xfb,
0xff, 0xef, 0xff, 0xfb, 0x03, 0x00, 0xfc, 0xef, 0xff, 0xff, 0xff, 0x7f,
0xb7, 0x01, 0x00, 0xf8, 0x6f, 0xff, 0xfd, 0xff, 0xfe, 0x1f, 0x00, 0x00,
0xf8, 0x6f, 0xff, 0xff, 0xef, 0xff, 0x02, 0x00, 0x00, 0xf8, 0xbf, 0xff,
0xfd, 0xff, 0xfb, 0x07, 0x00, 0x00, 0xf0, 0x97, 0xff, 0xff, 0xdf, 0xef,
0x1f, 0x00, 0x00, 0xe0, 0xe3, 0xf7, 0xde, 0xff, 0xff, 0x3f, 0x00, 0x00,
0x00, 0xf8, 0xdf, 0xff, 0xff, 0xdf, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xef, 0xff, 0xff, 0x03, 0x00, 0xe0, 0x1f, 0xf8, 0xdf, 0xff, 0x7d,
0xc0, 0x07, 0x00, 0xf0, 0x4f, 0xf4, 0xef, 0xf7, 0x9b, 0x90, 0x00, 0x00,
0x00, 0x83, 0xef, 0xff, 0xfd, 0xef, 0x0b, 0x01, 0x00, 0x00, 0xd5, 0x80,
0xff, 0xff, 0x00, 0x5e, 0x03, 0x00, 0x80, 0x38, 0x00, 0x78, 0x00, 0x00,
0x70, 0x04, 0x00, 0x80, 0x08, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x04, 0x00,
0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00};

45
demos/wizardmsk.xbm Normal file
View file

@ -0,0 +1,45 @@
#define wizardmsk_width 67
#define wizardmsk_height 55
static unsigned char wizardmsk_bits[] = {
0x00, 0x00, 0xc0, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
0xff, 0x0f, 0x00, 0xc0, 0xff, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x1f, 0x00,
0xe0, 0xff, 0x01, 0x00, 0x00, 0xf8, 0xff, 0x3f, 0x00, 0xf0, 0xff, 0x03,
0x00, 0x00, 0xfc, 0xff, 0x3f, 0x00, 0xf8, 0xff, 0x03, 0x00, 0x00, 0xfe,
0xff, 0x7f, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00,
0xfe, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0x03,
0x00, 0x00, 0xff, 0xff, 0xff, 0xbf, 0xff, 0xff, 0x03, 0x00, 0xc0, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x03, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03,
0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0xfe, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03,
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff,
0xff, 0x7f, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00,
0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0xf8, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x3f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x1f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x07, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00,
0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0xfc, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x3f, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00,
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0xfc, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x3f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00,
0xf0, 0xff, 0xc1, 0xff, 0xff, 0x01, 0xff, 0x1f, 0x00, 0xe0, 0x7f, 0x00,
0xfc, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00};