From 2facad3d8802ccc83bcfee902782a63ddf848bce Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 31 Aug 2006 22:00:50 -0700 Subject: [PATCH] Color table handling for the VESA console --- com32/lib/sys/vesa/drawtxt.c | 28 ++-------------- com32/lib/sys/vesacon_write.c | 74 +++++++++++++++++++++++++++---------------- 2 files changed, 49 insertions(+), 53 deletions(-) diff --git a/com32/lib/sys/vesa/drawtxt.c b/com32/lib/sys/vesa/drawtxt.c index 5910e08..0895744 100644 --- a/com32/lib/sys/vesa/drawtxt.c +++ b/com32/lib/sys/vesa/drawtxt.c @@ -26,33 +26,11 @@ * ----------------------------------------------------------------------- */ #include +#include #include "vesa.h" #include "video.h" /* - * Color map (ARGB) for the 16 PC colors. This can be overridden by the - * application, and do not have to match the traditional colors. - */ -uint32_t vesacon_color_map[16] = { - 0x00000000, /* black */ - 0x400000ff, /* dark blue */ - 0x4000ff00, /* dark green */ - 0x4000ffff, /* dark cyan */ - 0x40ff0000, /* dark red */ - 0x40ff00ff, /* dark purple */ - 0x80ff8000, /* brown */ - 0xc0ffffff, /* light grey */ - 0x40ffffff, /* dark grey */ - 0xc00000ff, /* bright blue */ - 0xc000ff00, /* bright green */ - 0xc000ffff, /* bright cyan */ - 0xc0ff0000, /* bright red */ - 0xc0ff00ff, /* bright purple */ - 0xffffff00, /* yellow */ - 0xffffffff, /* white */ -}; - -/* * Linear alpha blending. Useless for anything that's actually * depends on color accuracy (because of gamma), but it's fine for * what we want. @@ -127,8 +105,8 @@ static void vesacon_update_characters(int row, int col, int nrows, int ncols) chxbits = chbits; chxbits &= (cptr->sha & 0x02) ? 0xff : 0x00; chxbits ^= (cptr->sha & 0x01) ? 0xff : 0x00; - fgcolor = vesacon_color_map[cptr->attr & 0x0f]; - bgcolor = vesacon_color_map[cptr->attr >> 4]; + fgcolor = console_color_table[cptr->attr].argb_fg; + bgcolor = console_color_table[cptr->attr].argb_bg; cptr++; break; case FONT_WIDTH-1: diff --git a/com32/lib/sys/vesacon_write.c b/com32/lib/sys/vesacon_write.c index c09361a..cb0c587 100644 --- a/com32/lib/sys/vesacon_write.c +++ b/com32/lib/sys/vesacon_write.c @@ -48,6 +48,9 @@ enum ansi_state { st_init, /* Normal (no ESC seen) */ st_esc, /* ESC seen */ st_csi, /* CSI seen */ + st_soh, /* SOH seen */ + st_sohc, /* SOH # seen */ + st_sohc1, /* SOH # digit seen */ }; #define MAX_PARMS 16 @@ -75,7 +78,7 @@ struct term_state { static const struct term_state default_state = { .disabled = 0, - .attr = 0x07, /* Grey on black */ + .attr = 0, /* First color table entry */ .vtgraphics = 0, .intensity = 1, .underline = 0, @@ -438,33 +441,6 @@ static void vesacon_putchar(int ch) break; } } - - /* Turn into an attribute code */ - { - int bg = st.bg; - int fg; - - if ( st.underline ) - fg = 0x01; - else if ( st.intensity == 0 ) - fg = 0x08; - else - fg = st.fg; - - if ( st.reverse ) { - bg = fg & 0x07; - fg &= 0x08; - fg |= st.bg; - } - - if ( st.blink ) - bg ^= 0x08; - - if ( st.intensity == 2 ) - fg ^= 0x08; - - st.attr = (bg << 4) | fg; - } } break; case 's': @@ -480,6 +456,48 @@ static void vesacon_putchar(int ch) } } break; + + case st_soh: + if ( ch == '#' ) + st.state = st_sohc; + else + st.state = st_init; + break; + + case st_sohc: + { + int n = (unsigned char)ch - '0'; + if (n < 10) { + st.param[0] = n*10; + st.state = st_sohc1; + } else { + st.state = st_init; + } + } + break; + + case st_sohc1: + { + int n = (unsigned char)ch - '0'; + const char *p; + + if (n < 10) { + st.param[0] += n; + if (st.param[0] < console_color_table_size) { + /* Set the color table index */ + st.attr = st.param[0]; + + /* See if there are any other attributes we care about */ + st.state = st_csi; + for (p = console_color_table[st.param[0]]; *p; p++) + vesacon_putchar(*p); + vesacon_putchar('m'); + } + } + + st.state = st_init; + } + break; } /* If we fell off the end of the screen, adjust */ -- 2.7.4