From b6f1311502f48a091dd51bd7443105963071af9a Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 16 Jun 2017 17:10:48 +0200 Subject: first character printed in graphics mode --- src/drivers/video/vga.c | 31 +++++++++++++++++++++++++++++++ src/drivers/video/vga.h | 1 + src/drivers/video/vga_font.c | 2 +- src/drivers/video/vga_font.h | 2 ++ 4 files changed, 35 insertions(+), 1 deletion(-) (limited to 'src/drivers') diff --git a/src/drivers/video/vga.c b/src/drivers/video/vga.c index c385bea..1ec7829 100644 --- a/src/drivers/video/vga.c +++ b/src/drivers/video/vga.c @@ -4,6 +4,8 @@ #include "kernel.h" +#include "vga_font.h" + #undef DEBUG static vga_vtable_t vga_vtable = { @@ -269,3 +271,32 @@ void vga_clear_screen( vga_t *vga, const vga_color_t color ) memset( vga->mode.segment, get_color_index( color ), vga->mode.x * vga->mode.y ); } + +void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, const vga_color_t background, const vga_color_t foreground ) +{ + +//const struct bitmap_font font = { + +/* .Width = 8, .Height = 16, + .Chars = 2899, + .Widths = __font_widths__, + .Index = __font_index__, + .Bitmap = __vga_font_bitmap__, +*/ + // assuming font width is 8 + int mask[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; + + // for now, the 34 entry, character height is 16, assuming A-Z + const unsigned char *bmap = &vga_font.Bitmap[(34+c-65)*16]; + + for( int xx = 0; xx < vga_font.Width; xx++ ) { + for( int yy = 0; yy < vga_font.Height; yy++ ) { + if( bmap[yy] & mask[xx] ) { + vga_set_pixel( vga, x + xx, y + yy, foreground ); + } else { + vga_set_pixel( vga, x + xx, y + yy, background ); + } + } + } +} + diff --git a/src/drivers/video/vga.h b/src/drivers/video/vga.h index 69b4591..8b7ebdc 100644 --- a/src/drivers/video/vga.h +++ b/src/drivers/video/vga.h @@ -63,5 +63,6 @@ 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 ); void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, const int h, const vga_color_t color ); void vga_clear_screen( vga_t *vga, const vga_color_t color ); +void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, const vga_color_t background, const vga_color_t foreground ); #endif // VGA_H diff --git a/src/drivers/video/vga_font.c b/src/drivers/video/vga_font.c index 8d5bc72..432f735 100644 --- a/src/drivers/video/vga_font.c +++ b/src/drivers/video/vga_font.c @@ -57996,7 +57996,7 @@ static const unsigned short __font_index__[] = { }; /// bitmap font structure -const struct bitmap_font font = { +const struct bitmap_font vga_font = { .Width = 8, .Height = 16, .Chars = 2899, .Widths = __font_widths__, diff --git a/src/drivers/video/vga_font.h b/src/drivers/video/vga_font.h index 7d17265..9c1ba1b 100644 --- a/src/drivers/video/vga_font.h +++ b/src/drivers/video/vga_font.h @@ -268,3 +268,5 @@ struct bitmap_font { #define XXXXXXX_ 0xFE #define XXXXXXXX 0xFF /// @} + +extern const struct bitmap_font vga_font; -- cgit v1.2.3-54-g00ecf