Add Truecolor 16 and 32bits support. Note that 24bits modes are not

supported since it's not easy to put 3 bytes accross 64Kb windows
of memory. This should not be such a problem with linear framebuffers.

There is no major interface modification except that the color type
becomes u_long instead of byte. So one just need to recompile his
application.

Approved by:	Soren Schmidt <sos@freebsd.dk>
This commit is contained in:
Nicolas Souchu 2001-01-13 11:30:17 +00:00
parent ea0187039a
commit 933d455fac
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=70991
4 changed files with 251 additions and 35 deletions

View file

@ -143,12 +143,31 @@ WriteVerticalLine(VGLBitmap *dst, int x, int y, int width, byte *line)
width -= i; width -= i;
} }
break; break;
case VIDBUF16S:
case VIDBUF24S:
case VIDBUF32S:
width = width * dst->PixelBytes;
pos = (dst->VXsize * y + x) * dst->PixelBytes;
while (width > 0) {
offset = VGLSetSegment(pos);
i = min(VGLAdpInfo.va_window_size - offset, width);
bcopy(line, dst->Bitmap + offset, i);
line += i;
pos += i;
width -= i;
}
break;
case VIDBUF8: case VIDBUF8:
case MEMBUF: case MEMBUF:
address = dst->Bitmap + dst->VXsize * y + x; address = dst->Bitmap + dst->VXsize * y + x;
bcopy(line, address, width); bcopy(line, address, width);
break; break;
case VIDBUF16:
case VIDBUF24:
case VIDBUF32:
address = dst->Bitmap + (dst->VXsize * y + x) * dst->PixelBytes;
bcopy(line, address, width * dst->PixelBytes);
break;
default: default:
} }
} }
@ -238,11 +257,31 @@ ReadVerticalLine(VGLBitmap *src, int x, int y, int width, byte *line)
width -= i; width -= i;
} }
break; break;
case VIDBUF16S:
case VIDBUF24S:
case VIDBUF32S:
width = width * src->PixelBytes;
pos = (src->VXsize * y + x) * src->PixelBytes;
while (width > 0) {
offset = VGLSetSegment(pos);
i = min(VGLAdpInfo.va_window_size - offset, width);
bcopy(src->Bitmap + offset, line, i);
line += i;
pos += i;
width -= i;
}
break;
case VIDBUF8: case VIDBUF8:
case MEMBUF: case MEMBUF:
address = src->Bitmap + src->VXsize * y + x; address = src->Bitmap + src->VXsize * y + x;
bcopy(address, line, width); bcopy(address, line, width);
break; break;
case VIDBUF16:
case VIDBUF24:
case VIDBUF32:
address = src->Bitmap + (src->VXsize * y + x) * src->PixelBytes;
bcopy(address, line, width * src->PixelBytes);
break;
default: default:
} }
} }

View file

@ -39,6 +39,8 @@
#include <sys/consio.h> #include <sys/consio.h>
#include "vgl.h" #include "vgl.h"
/* XXX Direct Color 24bits modes unsupported */
#define min(x, y) (((x) < (y)) ? (x) : (y)) #define min(x, y) (((x) < (y)) ? (x) : (y))
#define max(x, y) (((x) > (y)) ? (x) : (y)) #define max(x, y) (((x) > (y)) ? (x) : (y))
@ -178,6 +180,25 @@ VGLInit(int mode)
case V_INFO_MM_VGAX: case V_INFO_MM_VGAX:
VGLDisplay->Type = VIDBUF8X; VGLDisplay->Type = VIDBUF8X;
break; break;
case V_INFO_MM_DIRECT:
VGLDisplay->PixelBytes = VGLModeInfo.vi_pixel_size;
switch (VGLDisplay->PixelBytes) {
case 2:
VGLDisplay->Type = VIDBUF16;
break;
#if notyet
case 3:
VGLDisplay->Type = VIDBUF24;
break;
#endif
case 4:
VGLDisplay->Type = VIDBUF32;
break;
default:
VGLEnd();
return -4;
}
break;
default: default:
VGLEnd(); VGLEnd();
return -4; return -4;
@ -224,10 +245,26 @@ VGLInit(int mode)
/* see if we are in the windowed buffer mode or in the linear buffer mode */ /* see if we are in the windowed buffer mode or in the linear buffer mode */
if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) { if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) {
if (VGLDisplay->Type == VIDBUF4) switch (VGLDisplay->Type) {
case VIDBUF4:
VGLDisplay->Type = VIDBUF4S; VGLDisplay->Type = VIDBUF4S;
else if (VGLDisplay->Type == VIDBUF8) break;
case VIDBUF8:
VGLDisplay->Type = VIDBUF8S; VGLDisplay->Type = VIDBUF8S;
break;
case VIDBUF16:
VGLDisplay->Type = VIDBUF16S;
break;
case VIDBUF24:
VGLDisplay->Type = VIDBUF24S;
break;
case VIDBUF32:
VGLDisplay->Type = VIDBUF32S;
break;
default:
VGLEnd();
return -8;
}
} }
VGLMode = mode; VGLMode = mode;
@ -308,13 +345,35 @@ VGLCheckSwitch()
VGLDisplay->Type = VIDBUF8S; VGLDisplay->Type = VIDBUF8S;
else else
VGLDisplay->Type = VIDBUF8; VGLDisplay->Type = VIDBUF8;
} else {
/* shouldn't be happening */
} }
break; break;
case V_INFO_MM_VGAX: case V_INFO_MM_VGAX:
VGLDisplay->Type = VIDBUF8X; VGLDisplay->Type = VIDBUF8X;
break; break;
case V_INFO_MM_DIRECT:
switch (VGLModeInfo.vi_pixel_size) {
case 2:
if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size)
VGLDisplay->Type = VIDBUF16S;
else
VGLDisplay->Type = VIDBUF16;
break;
case 3:
if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size)
VGLDisplay->Type = VIDBUF24S;
else
VGLDisplay->Type = VIDBUF24;
break;
case 4:
if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size)
VGLDisplay->Type = VIDBUF32S;
else
VGLDisplay->Type = VIDBUF32;
break;
default:
/* shouldn't be happening */
break;
}
default: default:
/* shouldn't be happening */ /* shouldn't be happening */
break; break;
@ -357,6 +416,12 @@ VGLCheckSwitch()
break; break;
case VIDBUF8: case VIDBUF8:
case VIDBUF8S: case VIDBUF8S:
case VIDBUF16:
case VIDBUF16S:
case VIDBUF24:
case VIDBUF24S:
case VIDBUF32:
case VIDBUF32S:
for (offset = 0; offset < VGLBufSize; offset += len) { for (offset = 0; offset < VGLBufSize; offset += len) {
VGLSetSegment(offset); VGLSetSegment(offset);
len = min(VGLBufSize - offset, VGLAdpInfo.va_window_size); len = min(VGLBufSize - offset, VGLAdpInfo.va_window_size);
@ -398,6 +463,12 @@ VGLCheckSwitch()
break; break;
case VIDBUF8: case VIDBUF8:
case VIDBUF8S: case VIDBUF8S:
case VIDBUF16:
case VIDBUF16S:
case VIDBUF24:
case VIDBUF24S:
case VIDBUF32:
case VIDBUF32S:
for (offset = 0; offset < VGLBufSize; offset += len) { for (offset = 0; offset < VGLBufSize; offset += len) {
VGLSetSegment(offset); VGLSetSegment(offset);
len = min(VGLBufSize - offset, VGLAdpInfo.va_window_size); len = min(VGLBufSize - offset, VGLAdpInfo.va_window_size);

View file

@ -41,10 +41,57 @@ static byte VGLSavePaletteBlue[256];
#define min(x, y) (((x) < (y)) ? (x) : (y)) #define min(x, y) (((x) < (y)) ? (x) : (y))
#define max(x, y) (((x) > (y)) ? (x) : (y)) #define max(x, y) (((x) > (y)) ? (x) : (y))
static void
color2mem(u_long color, byte *b, int len)
{
switch (len) {
case 4:
b[3] = (color >> 24) & 0xff;
/* fallthrough */
case 3:
b[2] = (color >> 16) & 0xff;
/* fallthrough */
case 2:
b[1] = (color >> 8) & 0xff;
/* fallthrough */
case 1:
default:
b[0] = color & 0xff;
break;
}
return;
}
static u_long
mem2color(byte *b, int len)
{
u_long color = 0;
switch (len) {
case 4:
color |= (b[3] & 0xff) << 24;
/* fallthrough */
case 3:
color |= (b[2] & 0xff) << 16;
/* fallthrough */
case 2:
color |= (b[1] & 0xff) << 8;
/* fallthrough */
case 1:
default:
color |= (b[0] & 0xff);
break;
}
return color;
}
void void
VGLSetXY(VGLBitmap *object, int x, int y, byte color) VGLSetXY(VGLBitmap *object, int x, int y, u_long color)
{ {
int offset; int offset;
byte b[4];
VGLCheckSwitch(); VGLCheckSwitch();
if (x>=0 && x<object->VXsize && y>=0 && y<object->VYsize) { if (x>=0 && x<object->VXsize && y>=0 && y<object->VYsize) {
@ -52,15 +99,29 @@ VGLSetXY(VGLBitmap *object, int x, int y, byte color)
switch (object->Type) { switch (object->Type) {
case MEMBUF: case MEMBUF:
case VIDBUF8: case VIDBUF8:
object->Bitmap[y*object->VXsize+x]=(color); object->Bitmap[y*object->VXsize+x]=((byte)color);
break; break;
case VIDBUF8S: case VIDBUF8S:
object->Bitmap[VGLSetSegment(y*object->VXsize+x)]=(color); object->Bitmap[VGLSetSegment(y*object->VXsize+x)]=((byte)color);
break;
case VIDBUF16:
case VIDBUF24:
case VIDBUF32:
color2mem(color, b, object->PixelBytes);
bcopy(b, &object->Bitmap[(y*object->VXsize+x) * object->PixelBytes],
object->PixelBytes);
break;
case VIDBUF16S:
case VIDBUF24S:
case VIDBUF32S:
color2mem(color, b, object->PixelBytes);
offset = VGLSetSegment((y*object->VXsize+x) * object->PixelBytes);
bcopy(b, &object->Bitmap[offset], object->PixelBytes);
break; break;
case VIDBUF8X: case VIDBUF8X:
outb(0x3c4, 0x02); outb(0x3c4, 0x02);
outb(0x3c5, 0x01 << (x&0x3)); outb(0x3c5, 0x01 << (x&0x3));
object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)] = (color); object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)] = ((byte)color);
break; break;
case VIDBUF4S: case VIDBUF4S:
offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8); offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8);
@ -69,23 +130,24 @@ VGLSetXY(VGLBitmap *object, int x, int y, byte color)
offset = y*VGLAdpInfo.va_line_width + x/8; offset = y*VGLAdpInfo.va_line_width + x/8;
set_planar: set_planar:
outb(0x3c4, 0x02); outb(0x3c5, 0x0f); outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
outb(0x3ce, 0x00); outb(0x3cf, color & 0x0f); /* set/reset */ outb(0x3ce, 0x00); outb(0x3cf, (byte)color & 0x0f); /* set/reset */
outb(0x3ce, 0x01); outb(0x3cf, 0x0f); /* set/reset enable */ outb(0x3ce, 0x01); outb(0x3cf, 0x0f); /* set/reset enable */
outb(0x3ce, 0x08); outb(0x3cf, 0x80 >> (x%8)); /* bit mask */ outb(0x3ce, 0x08); outb(0x3cf, 0x80 >> (x%8)); /* bit mask */
object->Bitmap[offset] |= color; object->Bitmap[offset] |= (byte)color;
} }
} }
VGLMouseUnFreeze(); VGLMouseUnFreeze();
} }
} }
byte u_long
VGLGetXY(VGLBitmap *object, int x, int y) VGLGetXY(VGLBitmap *object, int x, int y)
{ {
int offset; int offset;
byte b[4];
#if 0 #if 0
int i; int i;
byte color; u_long color;
byte mask; byte mask;
#endif #endif
@ -98,6 +160,19 @@ VGLGetXY(VGLBitmap *object, int x, int y)
return object->Bitmap[((y*object->VXsize)+x)]; return object->Bitmap[((y*object->VXsize)+x)];
case VIDBUF8S: case VIDBUF8S:
return object->Bitmap[VGLSetSegment(y*object->VXsize+x)]; return object->Bitmap[VGLSetSegment(y*object->VXsize+x)];
case VIDBUF16:
case VIDBUF24:
case VIDBUF32:
bcopy(&object->Bitmap[(y*object->VXsize+x) * object->PixelBytes],
b, object->PixelBytes);
return (mem2color(b, object->PixelBytes));
case VIDBUF16S:
case VIDBUF24S:
case VIDBUF32S:
offset = VGLSetSegment((y*object->VXsize+x) * object->PixelBytes);
bcopy(&object->Bitmap[offset], b, object->PixelBytes);
return (mem2color(b, object->PixelBytes));
case VIDBUF8X: case VIDBUF8X:
outb(0x3ce, 0x04); outb(0x3cf, x & 0x3); outb(0x3ce, 0x04); outb(0x3cf, x & 0x3);
return object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)]; return object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)];
@ -119,11 +194,11 @@ VGLGetXY(VGLBitmap *object, int x, int y)
return color; return color;
#endif #endif
} }
return 0; return 0; /* XXX black? */
} }
void void
VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color) VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
{ {
int d, x, y, ax, ay, sx, sy, dx, dy; int d, x, y, ax, ay, sx, sy, dx, dy;
@ -157,7 +232,7 @@ VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color)
} }
void void
VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color) VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
{ {
VGLLine(object, x1, y1, x2, y1, color); VGLLine(object, x1, y1, x2, y1, color);
VGLLine(object, x2, y1, x2, y2, color); VGLLine(object, x2, y1, x2, y2, color);
@ -166,7 +241,7 @@ VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color)
} }
void void
VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color) VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
{ {
int y; int y;
@ -174,7 +249,7 @@ VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color)
} }
void void
inline set4pixels(VGLBitmap *object, int x, int y, int xc, int yc, byte color) inline set4pixels(VGLBitmap *object, int x, int y, int xc, int yc, u_long color)
{ {
if (x!=0) { if (x!=0) {
VGLSetXY(object, xc+x, yc+y, color); VGLSetXY(object, xc+x, yc+y, color);
@ -192,7 +267,7 @@ inline set4pixels(VGLBitmap *object, int x, int y, int xc, int yc, byte color)
} }
void void
VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color) VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color)
{ {
int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b; int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b;
int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b; int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b;
@ -215,7 +290,7 @@ VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color)
} }
void void
inline set2lines(VGLBitmap *object, int x, int y, int xc, int yc, byte color) inline set2lines(VGLBitmap *object, int x, int y, int xc, int yc, u_long color)
{ {
if (x!=0) { if (x!=0) {
VGLLine(object, xc+x, yc+y, xc-x, yc+y, color); VGLLine(object, xc+x, yc+y, xc-x, yc+y, color);
@ -228,7 +303,7 @@ inline set2lines(VGLBitmap *object, int x, int y, int xc, int yc, byte color)
} }
void void
VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color) VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color)
{ {
int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b; int x = 0, y = b, asq = a*a, asq2 = a*a*2, bsq = b*b;
int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b; int bsq2 = b*b*2, d = bsq-asq*b+asq/4, dx = 0, dy = asq2*b;
@ -251,17 +326,19 @@ VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color)
} }
void void
VGLClear(VGLBitmap *object, byte color) VGLClear(VGLBitmap *object, u_long color)
{ {
int offset; int offset;
int len; int len;
int i, total = 0;
byte b[4];
VGLCheckSwitch(); VGLCheckSwitch();
VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color); VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color); /* XXX */
switch (object->Type) { switch (object->Type) {
case MEMBUF: case MEMBUF:
case VIDBUF8: case VIDBUF8:
memset(object->Bitmap, color, object->VXsize*object->VYsize); memset(object->Bitmap, (byte)color, object->VXsize*object->VYsize);
break; break;
case VIDBUF8S: case VIDBUF8S:
@ -269,7 +346,29 @@ VGLClear(VGLBitmap *object, byte color)
VGLSetSegment(offset); VGLSetSegment(offset);
len = min(object->VXsize*object->VYsize - offset, len = min(object->VXsize*object->VYsize - offset,
VGLAdpInfo.va_window_size); VGLAdpInfo.va_window_size);
memset(object->Bitmap, color, len); memset(object->Bitmap, (byte)color, len);
offset += len;
}
break;
case VIDBUF16:
case VIDBUF24:
case VIDBUF32:
color2mem(color, b, object->PixelBytes);
total = object->VXsize*object->VYsize*object->PixelBytes;
for (i = 0; i < total; i += object->PixelBytes)
bcopy(b, object->Bitmap + i, object->PixelBytes);
break;
case VIDBUF16S:
case VIDBUF24S:
case VIDBUF32S:
color2mem(color, b, object->PixelBytes);
total = object->VXsize*object->VYsize*object->PixelBytes;
for (offset = 0; offset < total; ) {
VGLSetSegment(offset);
len = min(total - offset, VGLAdpInfo.va_window_size);
for (i = 0; i < len; i += object->PixelBytes)
bcopy(b, object->Bitmap + offset + i, object->PixelBytes);
offset += len; offset += len;
} }
break; break;
@ -278,7 +377,7 @@ VGLClear(VGLBitmap *object, byte color)
/* XXX works only for Xsize % 4 = 0 */ /* XXX works only for Xsize % 4 = 0 */
outb(0x3c6, 0xff); outb(0x3c6, 0xff);
outb(0x3c4, 0x02); outb(0x3c5, 0x0f); outb(0x3c4, 0x02); outb(0x3c5, 0x0f);
memset(object->Bitmap, color, VGLAdpInfo.va_line_width*object->VYsize); memset(object->Bitmap, (byte)color, VGLAdpInfo.va_line_width*object->VYsize);
break; break;
case VIDBUF4: case VIDBUF4:
@ -292,7 +391,7 @@ VGLClear(VGLBitmap *object, byte color)
VGLSetSegment(offset); VGLSetSegment(offset);
len = min(object->VXsize*object->VYsize - offset, len = min(object->VXsize*object->VYsize - offset,
VGLAdpInfo.va_window_size); VGLAdpInfo.va_window_size);
memset(object->Bitmap, color, len); memset(object->Bitmap, (byte)color, len);
offset += len; offset += len;
} }
outb(0x3ce, 0x05); outb(0x3cf, 0x00); outb(0x3ce, 0x05); outb(0x3cf, 0x00);

View file

@ -40,6 +40,7 @@ typedef struct {
int VXsize, VYsize; int VXsize, VYsize;
int Xorigin, Yorigin; int Xorigin, Yorigin;
byte *Bitmap; byte *Bitmap;
int PixelBytes;
} VGLBitmap; } VGLBitmap;
#define VGLBITMAP_INITIALIZER(t, x, y, bits) \ #define VGLBITMAP_INITIALIZER(t, x, y, bits) \
@ -54,6 +55,12 @@ typedef struct {
#define VIDBUF8X 3 #define VIDBUF8X 3
#define VIDBUF8S 4 #define VIDBUF8S 4
#define VIDBUF4S 5 #define VIDBUF4S 5
#define VIDBUF16 6 /* Direct Color linear buffer */
#define VIDBUF24 7 /* Direct Color linear buffer */
#define VIDBUF32 8 /* Direct Color linear buffer */
#define VIDBUF16S 9 /* Direct Color segmented buffer */
#define VIDBUF24S 10 /* Direct Color segmented buffer */
#define VIDBUF32S 11 /* Direct Color segmented buffer */
#define NOBUF 255 #define NOBUF 255
typedef struct VGLText { typedef struct VGLText {
@ -122,14 +129,14 @@ int VGLMouseStatus(int *x, int *y, char *buttons);
int VGLMouseFreeze(int x, int y, int width, int hight, byte color); int VGLMouseFreeze(int x, int y, int width, int hight, byte color);
void VGLMouseUnFreeze(void); void VGLMouseUnFreeze(void);
/* simple.c */ /* simple.c */
void VGLSetXY(VGLBitmap *object, int x, int y, byte color); void VGLSetXY(VGLBitmap *object, int x, int y, u_long color);
byte VGLGetXY(VGLBitmap *object, int x, int y); u_long VGLGetXY(VGLBitmap *object, int x, int y);
void VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color); void VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color);
void VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color); void VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color);
void VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, byte color); void VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color);
void VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color); void VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color);
void VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, byte color); void VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color);
void VGLClear(VGLBitmap *object, byte color); void VGLClear(VGLBitmap *object, u_long color);
void VGLRestorePalette(void); void VGLRestorePalette(void);
void VGLSavePalette(void); void VGLSavePalette(void);
void VGLSetPalette(byte *red, byte *green, byte *blue); void VGLSetPalette(byte *red, byte *green, byte *blue);