aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2006-08-27 16:04:13 -0700
committerH. Peter Anvin <hpa@zytor.com>2006-08-27 16:04:13 -0700
commitb76cbd9c17c8001bdba243dffe6df0199b2cf049 (patch)
treebd4ed8474429c19b53182d820852d5b48a65197a
parenta9d5646f3018b47c5f01a5c2428bc0c7a4877649 (diff)
downloadsyslinux-b76cbd9c17c8001bdba243dffe6df0199b2cf049.tar.gz
syslinux-b76cbd9c17c8001bdba243dffe6df0199b2cf049.tar.xz
syslinux-b76cbd9c17c8001bdba243dffe6df0199b2cf049.zip
More work on the VESA graphics console
-rwxr-xr-xcom32/lib/sys/vesa/alphatbl.pl48
-rw-r--r--com32/lib/sys/vesa/initvesa.c149
-rw-r--r--com32/lib/sys/vesa/vesa.h100
-rw-r--r--com32/lib/sys/vesa/video.h39
4 files changed, 336 insertions, 0 deletions
diff --git a/com32/lib/sys/vesa/alphatbl.pl b/com32/lib/sys/vesa/alphatbl.pl
new file mode 100755
index 00000000..e49ff3e6
--- /dev/null
+++ b/com32/lib/sys/vesa/alphatbl.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+#
+# Compute the alpha-blending table for 256 possible (R, G, B) value
+# compared with the 4-bit intensity value from the character attribute
+#
+
+#
+# Configurable parameters...
+#
+@text_intensity = (0.0, 0.3333, 0.6667, 1.0);
+$text_alpha = 0.5;
+$input_gamma = 1.7;
+$text_gamma = 1.7;
+$output_gamma = 1.7;
+
+sub ungamma($$) {
+ my($v, $gamma) = @_;
+
+ return $v**$gamma;
+}
+
+sub gamma($$) {
+ my($v, $gamma) = @_;
+ return $v**(1/$gamma);
+}
+
+print "unsigned char __vesacon_alpha_tbl[256][4] = {\n";
+
+for ($i = 0; $i <= 255; $i++) {
+ $ival = ungamma($i/255, $input_gamma);
+
+ $intro = "\t{";
+
+ for ($j = 0; $j < 4; $j++) {
+ $v = ($ival*(1-$text_alpha)) +
+ ungamma($text_intensity[$j], $text_gamma)*$text_alpha;
+
+ $d = int(gamma($v,$output_gamma)*255+0.5);
+
+ $d = 0 if ($d < 0);
+ $d = 255 if ($d > 255);
+
+ printf "%s%3d", $intro, $d;
+ $intro = ', ';
+ }
+ print "},\n";
+}
+print "};\n";
diff --git a/com32/lib/sys/vesa/initvesa.c b/com32/lib/sys/vesa/initvesa.c
new file mode 100644
index 00000000..43b34985
--- /dev/null
+++ b/com32/lib/sys/vesa/initvesa.c
@@ -0,0 +1,149 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 1999-2006 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * initvesa.c
+ *
+ * Query the VESA BIOS and select a 640x480x32 mode with local mapping
+ * support, if one exists.
+ */
+
+#include <inttypes.h>
+#include <com32.h>
+#include <string.h>
+#include "vesa.h"
+#include "video.h"
+
+struct vesa_general_info __vesa_general_info;
+struct vesa_mode_info __vesa_mode_info;
+
+uint8_t __vesacon_graphics_font[FONT_MAX_CHARS][FONT_MAX_HEIGHT];
+uint32_t __vesacon_background[VIDEO_Y_SIZE][VIDEO_X_SIZE];
+uint32_t __vesacon_shadowfb[VIDEO_Y_SIZE][VIDEO_X_SIZE];
+
+static void unpack_font(uint8_t *dst, uint8_t *src, int height)
+{
+ int i;
+
+ for (i = 0; i < FONT_MAX_CHARS; i++) {
+ memcpy(dst, src, height);
+ memset(dst+height, 0, 32-height);
+
+ dst += 32;
+ src += height;
+ }
+}
+
+static int vesacon_set_mode(void)
+{
+ com32sys_t rm;
+ uint8_t *rom_font;
+ uint16_t mode, *mode_ptr;
+ struct vesa_general_info *gi;
+ struct vesa_mode_info *mi;
+
+ /* Allocate space in the bounce buffer for these structures */
+ gi = &((struct vesa_info *)__com32.cs_bounce)->gi;
+ mi = &((struct vesa_info *)__com32.cs_bounce)->mi;
+
+ memset(&rm, 0, sizeof rm);
+
+ gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */
+ rm.eax.w[0] = 0x4F00; /* Get SVGA general information */
+ rm.edi.w[0] = OFFS(gi);
+ rm.es = SEG(gi);
+ __intcall(0x10, &rm, &rm);
+
+ if ( rm.eax.w[0] != 0x004F )
+ return 1; /* Function call failed */
+ if ( gi->signature != VESA_MAGIC )
+ return 2; /* No magic */
+ if ( gi->version < 0x0200 ) {
+ return 3; /* VESA 2.0 not supported */
+ }
+
+ /* Search for a 640x480 32-bit linear frame buffer mode */
+ mode_ptr = CVT_PTR(gi->video_mode_ptr);
+
+ for(;;) {
+ if ((mode = *mode_ptr++) == 0xFFFF)
+ return 4; /* No mode found */
+
+ rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */
+ rm.ecx.w[0] = mode;
+ rm.edi.w[0] = OFFS(mi);
+ rm.es = SEG(mi);
+ __intcall(0x10, &rm, &rm);
+
+ /* Must be a supported mode */
+ if ( rm.eax.w[0] != 0x004f )
+ continue;
+ /* Must be an LFB color graphics mode supported by the hardware */
+ if ( (mi->mode_attr & 0x0099) != 0x0099 )
+ continue;
+ /* Must be 640x480, 32 bpp */
+ if ( mi->h_res != VIDEO_X_SIZE || mi->v_res != VIDEO_Y_SIZE ||
+ mi->bpp != 32 )
+ continue;
+ /* Must either be a packed-pixel mode or a direct color mode
+ (depending on VESA version ) */
+ if ( mi->memory_layout != 4 && /* Packed pixel */
+ (mi->memory_layout != 6 || mi->rpos != 24 ||
+ mi->gpos != 16 || mi->bpos != 0) )
+ continue;
+
+ /* Hey, looks like we found something we can live with */
+ break;
+ }
+
+ /* Download the BIOS-provided font */
+ rm.eax.w[0] = 0x1130; /* Get Font Information */
+ rm.ebx.w[0] = 0x0600; /* Get 8x16 ROM font */
+ __intcall(0x10, &rm, &rm);
+ rom_font = MK_PTR(rm.es, rm.ebp.w[0]);
+ unpack_font(graphics_font, rom_font, 16);
+
+ /* Now set video mode */
+ rm.eax.w[0] = 0x4F02; /* Set SVGA video mode */
+ rm.ebx.w[0] = mode | 0xC000; /* Don't clear video RAM, use linear fb */
+ __intcall(0x10, &rm, &rm);
+ if ( rm.eax.w[0] != 0x004F ) {
+ rm.eax.w[0] = 0x0003; /* Set regular text mode */
+ __intcall(0x10, &rm, NULL);
+ return 9; /* Failed to set mode */
+ }
+
+ /* Copy established state out of the bounce buffer */
+ memcpy(&__vesa_info, __com32.cs_bounce, sizeof __vesa_info);
+
+ return 0;
+}
+
+int __vesacon_init(void)
+{
+ return vesacon_set_mode();
+}
diff --git a/com32/lib/sys/vesa/vesa.h b/com32/lib/sys/vesa/vesa.h
new file mode 100644
index 00000000..55e64b4d
--- /dev/null
+++ b/com32/lib/sys/vesa/vesa.h
@@ -0,0 +1,100 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 1999-2006 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#ifndef LIB_SYS_VESA_H
+#define LIB_SYS_VESA_H
+
+#include <inttypes.h>
+#include <com32.h>
+
+/* VESA General Information table */
+struct vesa_general_info {
+ uint32_t signature; /* Magic number = "VESA" */
+ uint16_t version;
+ far_ptr_t vendor_string;
+ uint8_t capabilities[4];
+ far_ptr_t video_mode_ptr;
+ uint32_t total_memory;
+
+ uint16_t oem_software_rev;
+ far_ptr_t oem_vendor_name_ptr;
+ far_ptr_t oem_product_name_ptr;
+ far_ptr_t oem_product_rev_ptr;
+
+ uint8_t reserved[222];
+ uint8_t oem_data[256];
+} __attribute__((packed));
+
+#define VESA_MAGIC ('V' + ('E' << 8) + ('S' << 16) + ('A' << 24))
+#define VBE2_MAGIC ('V' + ('B' << 8) + ('E' << 16) + ('2' << 24))
+
+struct vesa_mode_info {
+ uint16_t mode_attr;
+ uint8_t win_attr[2];
+ uint16_t win_grain;
+ uint16_t win_size;
+ uint16_t win_seg[2];
+ far_ptr_t win_scheme;
+ uint16_t logical_scan;
+
+ uint16_t h_res;
+ uint16_t v_res;
+ uint8_t char_width;
+ uint8_t char_height;
+ uint8_t memory_planes;
+ uint8_t bpp;
+ uint8_t banks;
+ uint8_t memory_layout;
+ uint8_t bank_size;
+ uint8_t image_planes;
+ uint8_t page_function;
+
+ uint8_t rmask;
+ uint8_t rpos;
+ uint8_t gmask;
+ uint8_t gpos;
+ uint8_t bmask;
+ uint8_t bpos;
+ uint8_t resv_mask;
+ uint8_t resv_pos;
+ uint8_t dcm_info;
+
+ uint8_t *lfb_ptr; /* Linear frame buffer address */
+ uint8_t *offscreen_ptr; /* Offscreen memory address */
+ uint16_t offscreen_size;
+
+ uint8_t reserved[206];
+} __attribute__((packed));
+
+struct vesa_info {
+ struct vesa_general_info gi;
+ struct vesa_mode_info mi;
+};
+
+extern struct vesa_info __vesa_info;
+
+#endif /* LIB_SYS_VESA_H */
diff --git a/com32/lib/sys/vesa/video.h b/com32/lib/sys/vesa/video.h
new file mode 100644
index 00000000..acbbc109
--- /dev/null
+++ b/com32/lib/sys/vesa/video.h
@@ -0,0 +1,39 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2006 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#ifndef LIB_SYS_VESA_VIDEO_H
+#define LIB_SYS_VESA_VIDEO_H
+
+#define FONT_MAX_CHARS 256
+#define FONT_MAX_HEIGHT 32
+
+#define VIDEO_X_SIZE 640
+#define VIDEO_Y_SIZE 480
+
+extern uint8_t graphics_font[FONT_MAX_CHARS][FONT_MAX_HEIGHT];
+
+#endif /* LIB_SYS_VESA_VIDEO_H */