From f05524445914e31891ec227520d9bb3fe5857e2c Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 21 Jun 2017 17:39:00 +0200 Subject: improved VGA colors added basics of a desktop widget class --- src/drivers/video/vga.c | 29 ++++++++++++++++++++++++----- src/drivers/video/vga.h | 10 ++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/video/vga.c b/src/drivers/video/vga.c index 0d3c49a..5da642a 100644 --- a/src/drivers/video/vga.c +++ b/src/drivers/video/vga.c @@ -268,13 +268,32 @@ vga_color_t vga_make_RGB( int R, int G, int B ) return c; } -static uint8_t get_color_index( const vga_color_t c ) +const vga_color_t VGA_COLOR_BLACK = { 0x00, 0x00, 0x00 }; +const vga_color_t VGA_COLOR_BLUE = { 0x00, 0x00, 0xAA }; +const vga_color_t VGA_COLOR_GREEN = { 0x00, 0xAA, 0x00 }; +const vga_color_t VGA_COLOR_CYAN = { 0x00, 0xAA, 0xAA }; +const vga_color_t VGA_COLOR_RED = { 0xAA, 0x00, 0x00 }; +const vga_color_t VGA_COLOR_MAGENTA = { 0xAA, 0x00, 0xAA }; +const vga_color_t VGA_COLOR_BROWN = { 0xAA, 0x55, 0x00 }; +const vga_color_t VGA_COLOR_LIGHT_GREY = { 0xAA, 0xAA, 0xAA }; +const vga_color_t VGA_COLOR_WHITE = { 0xFF, 0xFF, 0xFF }; + +static bool is_same( const vga_color_t c1, const vga_color_t c2 ) { - // TODO: for now white and black, standard VGA palette entries? - if( c.R == 0x00 && c.G == 0x00 && c.B == 0x00 ) return 0x00; - if( c.R == 0x00 && c.G == 0x00 && c.B == 0xA8 ) return 0x01; - if( c.R == 0xFF && c.G == 0xFF && c.B == 0xFF ) return 0x3F; + return c1.R == c2.R && c1.G == c2.G && c1.B == c2.B; +} +static uint8_t get_color_index( const vga_color_t c ) +{ + if( is_same( c, VGA_COLOR_BLACK ) ) return 0x00; + if( is_same( c, VGA_COLOR_BLUE ) ) return 0x01; + if( is_same( c, VGA_COLOR_GREEN ) ) return 0x02; + if( is_same( c, VGA_COLOR_CYAN ) ) return 0x03; + if( is_same( c, VGA_COLOR_RED ) ) return 0x04; + if( is_same( c, VGA_COLOR_MAGENTA ) ) return 0x05; + if( is_same( c, VGA_COLOR_BROWN ) ) return 0x06; + if( is_same( c, VGA_COLOR_LIGHT_GREY ) ) return 0x07; + if( is_same( c, VGA_COLOR_WHITE ) ) return 0x3F; return 0x00; } diff --git a/src/drivers/video/vga.h b/src/drivers/video/vga.h index 86897c4..3b09c37 100644 --- a/src/drivers/video/vga.h +++ b/src/drivers/video/vga.h @@ -64,6 +64,16 @@ typedef struct { int B; } vga_color_t; +extern const vga_color_t VGA_COLOR_BLACK; +extern const vga_color_t VGA_COLOR_BLUE; +extern const vga_color_t VGA_COLOR_GREEN; +extern const vga_color_t VGA_COLOR_CYAN; +extern const vga_color_t VGA_COLOR_RED; +extern const vga_color_t VGA_COLOR_MAGENTA; +extern const vga_color_t VGA_COLOR_BROWN; +extern const vga_color_t VGA_COLOR_LIGHT_GREY; +extern const vga_color_t VGA_COLOR_WHITE; + vga_color_t vga_make_RGB( int R, int G, int B ); void vga_set_pixel( vga_t *vga, const int x, const int y, const vga_color_t color ); -- cgit v1.2.3-54-g00ecf