From edad38a5a2dca96f5bea513d11eccf1134046d47 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 15 Jun 2017 07:06:13 +0200 Subject: made framebuffer segment a member of vga_mode_t, computing it once when vga_set_mode is called (because it will not change after every pixel) --- src/drivers/video/vga.c | 65 ++++++++++++++++++++++++------------------------- src/drivers/video/vga.h | 1 + 2 files changed, 33 insertions(+), 33 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/video/vga.c b/src/drivers/video/vga.c index 75a47f4..e3427b4 100644 --- a/src/drivers/video/vga.c +++ b/src/drivers/video/vga.c @@ -131,7 +131,8 @@ static vga_mode_t modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x41, 0x00, 0x0F, 0x00, 0x00 - } + }, + NULL } }; @@ -161,34 +162,6 @@ static int get_matching_mode_idx( const vga_mode_t mode ) return -1; } -bool vga_set_mode( vga_t *vga, const vga_mode_t mode ) -{ - // do not allow unknown timings! - if( !vga_supports_mode( mode ) ) { - return false; - } - - vga_mode_t matching_mode = modes[get_matching_mode_idx( mode )]; - - write_registers( vga, matching_mode.regs ); - - vga->mode = mode; - - return true; -} - - -vga_color_t vga_make_RGB( int R, int G, int B ) -{ - vga_color_t c; - - c.R = R; - c.G = G; - c.B = B; - - return c; -} - static uint8_t *get_frame_buffer_segment( vga_t *vga ) { port8_write( &vga->graphics_controller_index_port, 0x06 ); @@ -220,6 +193,35 @@ static uint8_t *get_frame_buffer_segment( vga_t *vga ) return segment; } +bool vga_set_mode( vga_t *vga, const vga_mode_t mode ) +{ + // do not allow unknown timings! + if( !vga_supports_mode( mode ) ) { + return false; + } + + vga_mode_t matching_mode = modes[get_matching_mode_idx( mode )]; + + write_registers( vga, matching_mode.regs ); + + vga->mode = mode; + vga->mode.segment = get_frame_buffer_segment( vga ); + + return true; +} + + +vga_color_t vga_make_RGB( int R, int G, int B ) +{ + vga_color_t c; + + c.R = R; + c.G = G; + c.B = B; + + return c; +} + static uint8_t get_color_index( const vga_color_t c ) { // TODO: for now white and black, standard VGA palette entries? @@ -248,11 +250,8 @@ void vga_set_pixel( vga_t *vga, const int x, const int y, const vga_color_t colo uint8_t color_idx = get_color_index( color ); - uint8_t *segment = get_frame_buffer_segment( vga ); - - uint8_t *addr = segment + vga->mode.x * y + x; + uint8_t *addr = vga->mode.segment + vga->mode.x * y + x; -// printf( "%d %d 0x%X, 0x%X 0x%X\n", x, y, segment, addr, color_idx ); *addr = color_idx; } diff --git a/src/drivers/video/vga.h b/src/drivers/video/vga.h index 7c710c3..6f70afa 100644 --- a/src/drivers/video/vga.h +++ b/src/drivers/video/vga.h @@ -17,6 +17,7 @@ typedef struct { int y; int color_depth; uint8_t regs[NOF_MODE_REGS]; + uint8_t *segment; } vga_mode_t; typedef struct { -- cgit v1.2.3-54-g00ecf