From 752ff17265f23d4fa9084368d2a90f66521a98e2 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 22 Jul 2017 16:14:14 +0200 Subject: separated video driver in a virtual video driver and a specific VGA video driver --- src/drivers/driver.c | 6 ++-- src/drivers/hdi/keyboard.c | 6 ++-- src/drivers/hdi/mouse.c | 6 ++-- src/drivers/net/network.c | 6 ++-- src/drivers/video/vga.c | 68 ++++++++++++++++++++++++++++------------------ src/drivers/video/vga.h | 15 +++++----- src/drivers/video/video.c | 44 +++++++++++++++++++++++++++--- src/drivers/video/video.h | 28 +++++++++++++++---- src/gui/desktop.c | 19 ++++++++----- src/gui/graphics_context.h | 4 +-- src/gui/text_widget.c | 3 +- src/gui/widget.c | 2 +- src/gui/window.c | 8 +++--- src/kernel/kernel.c | 23 ++++++++-------- 14 files changed, 155 insertions(+), 83 deletions(-) diff --git a/src/drivers/driver.c b/src/drivers/driver.c index 0bd8059..b38c11e 100644 --- a/src/drivers/driver.c +++ b/src/drivers/driver.c @@ -24,12 +24,12 @@ void driver_init( driver_t *driver, driver_type_t type, interrupt_t *interrupt, void driver_activate( void *obj ) { - kernel_panic( "Activating a generic driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void driver_deactivate( void *obj ) { - kernel_panic( "Deactivating a generic driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void driver_deinit( void *obj ) @@ -39,7 +39,7 @@ void driver_deinit( void *obj ) void driver_print_info( void *obj ) { - kernel_panic( "Printing info of a generic driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void driver_manager_init( driver_manager_t *manager ) diff --git a/src/drivers/hdi/keyboard.c b/src/drivers/hdi/keyboard.c index dd7ff65..9b9c337 100644 --- a/src/drivers/hdi/keyboard.c +++ b/src/drivers/hdi/keyboard.c @@ -30,15 +30,15 @@ void keyboard_deinit( void *obj ) void keyboard_activate( void *obj ) { - kernel_panic( "Activating generic keyboard driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void keyboard_deactivate( void *obj ) { - kernel_panic( "Deactivating generic keyboard driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void keyboard_print_info( void *obj ) { - kernel_panic( "Printing info of generic keyboard driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } diff --git a/src/drivers/hdi/mouse.c b/src/drivers/hdi/mouse.c index 85d4c82..a0b62f9 100644 --- a/src/drivers/hdi/mouse.c +++ b/src/drivers/hdi/mouse.c @@ -32,17 +32,17 @@ void mouse_deinit( void *obj ) void mouse_activate( void *obj ) { - kernel_panic( "Activating generic mouse driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void mouse_deactivate( void *obj ) { - kernel_panic( "Deactivating generic mouse driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void mouse_print_info( void *obj ) { - kernel_panic( "Printing info of generic mouse driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void mouse_set_resolution( void *obj, const uint32_t res_x, const uint32_t res_y ) diff --git a/src/drivers/net/network.c b/src/drivers/net/network.c index 2de245b..4cc40ac 100644 --- a/src/drivers/net/network.c +++ b/src/drivers/net/network.c @@ -25,12 +25,12 @@ void network_init( network_t *network, interrupt_t *interrupt, void *context ) void network_activate( void *obj ) { - kernel_panic( "Activating generic network driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void network_deactivate( void *obj ) { - kernel_panic( "Deactivating generic network driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void network_deinit( void *obj ) @@ -40,5 +40,5 @@ void network_deinit( void *obj ) void network_print_info( void *obj ) { - kernel_panic( "Printing info of generic network driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } diff --git a/src/drivers/video/vga.c b/src/drivers/video/vga.c index 75e96e6..456e539 100644 --- a/src/drivers/video/vga.c +++ b/src/drivers/video/vga.c @@ -20,7 +20,14 @@ static vga_vtable_t const vga_vtable = { video_register_mode, video_supports_mode, video_set_mode, - vga_switch_mode + vga_switch_mode, + vga_set_pixel, + vga_draw_rectangle, + vga_clear_screen, + vga_draw_char, + vga_wait_for_retrace, + vga_use_z_buffer, + vga_refresh } }; @@ -252,9 +259,9 @@ bool vga_switch_mode( void *obj, const video_mode_t *mode ) write_registers( vga, vga_mode->regs ); - vga->mode = (vga_mode_t *)mode; - vga->mode->segment = get_frame_buffer_segment( vga ); - vga->mode->segment_size = get_frame_buffer_segment_size( vga ); + vga_mode->segment = get_frame_buffer_segment( vga ); + vga_mode->segment_size = get_frame_buffer_segment_size( vga ); + vga->base.mode = mode; vga_use_z_buffer( vga, false ); @@ -291,55 +298,62 @@ static uint8_t get_color_index( const video_rgb_color_t c ) static bool params_ok( vga_t *vga, const int x, const int y ) { - if( x < 0 || x > vga->mode->base.x || y < 0 || y > vga->mode->base.y ) { + if( x < 0 || x > vga->base.mode->x || y < 0 || y > vga->base.mode->y ) { return false; } return true; } -void vga_set_pixel( vga_t *vga, const int x, const int y, const video_rgb_color_t color ) +void vga_set_pixel( void *obj, const int x, const int y, const video_rgb_color_t color ) { + vga_t *vga = (vga_t *)obj; + if( !params_ok( vga, x, y ) ) { kernel_panic( "Pixel coordinates are out of bounds: (%d, %d), resolution is only (%d, %d)", - x, y, vga->mode->base.x, vga->mode->base.y ); + x, y, vga->base.mode->x, vga->base.mode->y ); } uint8_t color_idx = get_color_index( color ); - uint8_t *addr = vga->base_addr + vga->mode->base.x * y + x; + uint8_t *addr = vga->base_addr + vga->base.mode->x * y + x; *addr = color_idx; } -void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, const int h, const video_rgb_color_t color ) +void vga_draw_rectangle( void *obj, const int x, const int y, const int w, const int h, const video_rgb_color_t color ) { + vga_t *vga = (vga_t *)obj; + if( !params_ok( vga, x, y ) ) { kernel_panic( "Rectangle start coordinates are out of bounds: (%d, %d), resolution is only (%d, %d)", - x, y, vga->mode->base.x, vga->mode->base.y ); + x, y, vga->base.mode->x, vga->base.mode->y ); } if( !params_ok( vga, x + w, y + h ) ) { kernel_panic( "Rectangle end coordinates are out of bounds: (%d, %d), resolution is only (%d, %d)", - x + w, y + h, vga->mode->base.x, vga->mode->base.y ); + x + w, y + h, vga->base.mode->x, vga->base.mode->y ); } uint8_t color_idx = get_color_index( color ); for( int yy = y; yy < y + h; yy++ ) { - uint8_t *addr = vga->base_addr + vga->mode->base.x * yy + x; + uint8_t *addr = vga->base_addr + vga->base.mode->x * yy + x; memset( addr, color_idx, w ); } } -void vga_clear_screen( vga_t *vga, const video_rgb_color_t color ) +void vga_clear_screen( void *obj, const video_rgb_color_t color ) { + vga_t *vga = (vga_t *)obj; + memset( vga->base_addr, get_color_index( color ), - vga->mode->base.x * vga->mode->base.y ); + vga->base.mode->x * vga->base.mode->y ); } -void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, const video_rgb_color_t background, const video_rgb_color_t foreground ) +void vga_draw_char( void *obj, const unsigned char c, const int x, const int y, const video_rgb_color_t background, const video_rgb_color_t foreground ) { + vga_t *vga = (vga_t *)obj; //const struct bitmap_font font = { @@ -367,42 +381,44 @@ void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, data[vga_font.Width-1-xx] = fg_color_idx; } } - uint8_t *addr = vga->base_addr + vga->mode->base.x * ( y + yy ) + x; + uint8_t *addr = vga->base_addr + vga->base.mode->x * ( y + yy ) + x; memcpy( addr, data, vga_font.Width ); } } -void vga_wait_for_retrace( vga_t *vga ) +void vga_wait_for_retrace( void *obj ) { + vga_t *vga = (vga_t *)obj; + while( port8_read( &vga->attribute_controller_reset_port ) & 0x08 ); while( !( port8_read( &vga->attribute_controller_reset_port ) & 0x08 ) ); } -void vga_use_z_buffer( vga_t *vga, bool use ) +void vga_use_z_buffer( void *obj, bool use ) { - if( vga->use_z_buffer == use ) { - return; - } - + vga_t *vga = (vga_t *)obj; + vga->use_z_buffer = use; if( vga->use_z_buffer ) { - vga->zbuffer = (uint8_t *)malloc( vga->mode->segment_size ); + vga->zbuffer = (uint8_t *)malloc( ((vga_mode_t *)(vga->base.mode))->segment_size ); vga->base_addr = &vga->zbuffer[0]; } else { if( vga->zbuffer != NULL ) { free( vga->zbuffer ); vga->zbuffer = NULL; } - vga->base_addr = vga->mode->segment; + vga->base_addr = ((vga_mode_t *)(vga->base.mode))->segment; } } -void vga_refresh( vga_t *vga ) +void vga_refresh( void *obj ) { + vga_t *vga = (vga_t *)obj; + if( vga->use_z_buffer ) { vga_wait_for_retrace( vga ); - memcpy( vga->mode->segment, vga->zbuffer, vga->mode->segment_size ); + memcpy( ((vga_mode_t *)(vga->base.mode))->segment, vga->zbuffer, ((vga_mode_t *)(vga->base.mode))->segment_size ); } } diff --git a/src/drivers/video/vga.h b/src/drivers/video/vga.h index 6934856..faafd8e 100644 --- a/src/drivers/video/vga.h +++ b/src/drivers/video/vga.h @@ -33,7 +33,6 @@ typedef struct { port8_t attribute_controller_read_port; port8_t attribute_controller_write_port; port8_t attribute_controller_reset_port; - vga_mode_t *mode; bool use_z_buffer; uint8_t *zbuffer; // stores either the address to the beginning of the segment @@ -53,12 +52,12 @@ void vga_print_info( void *obj ); bool vga_switch_mode( void *obj, const video_mode_t *mode ); -void vga_set_pixel( vga_t *vga, const int x, const int y, const video_rgb_color_t color ); -void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, const int h, const video_rgb_color_t color ); -void vga_clear_screen( vga_t *vga, const video_rgb_color_t color ); -void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, const video_rgb_color_t background, const video_rgb_color_t foreground ); -void vga_wait_for_retrace( vga_t *vga ); -void vga_use_z_buffer( vga_t *vga, bool use ); -void vga_refresh( vga_t *vga ); +void vga_set_pixel( void *, const int x, const int y, const video_rgb_color_t color ); +void vga_draw_rectangle( void *, const int x, const int y, const int w, const int h, const video_rgb_color_t color ); +void vga_clear_screen( void *, const video_rgb_color_t color ); +void vga_draw_char( void *, const unsigned char c, const int x, const int y, const video_rgb_color_t background, const video_rgb_color_t foreground ); +void vga_wait_for_retrace( void * ); +void vga_use_z_buffer( void *, bool use ); +void vga_refresh( void * ); #endif // VGA_H diff --git a/src/drivers/video/video.c b/src/drivers/video/video.c index ca57269..064a1f6 100644 --- a/src/drivers/video/video.c +++ b/src/drivers/video/video.c @@ -27,12 +27,12 @@ void video_init( video_t *video, interrupt_t *interrupt, void *context ) void video_activate( void *obj ) { - kernel_panic( "Activating generic video driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void video_deactivate( void *obj ) { - kernel_panic( "Deactivating generic video driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } void video_deinit( void *obj ) @@ -42,7 +42,7 @@ void video_deinit( void *obj ) void video_print_info( void *obj ) { - kernel_panic( "Printing info of generic video driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); } video_mode_t video_make_mode( const video_mode_type_t mode_type, const int x, const int y, const int color_depth ) @@ -114,7 +114,7 @@ bool video_set_mode( void *obj, const video_mode_t mode ) bool video_switch_mode( void *obj, const video_mode_t *mode ) { - kernel_panic( "Switching mode function of abstract video driver should not be called directly." ); + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); return false; } @@ -149,3 +149,39 @@ const video_rgb_color_t VIDEO_RGB_COLOR_WHITE = { 0xFF, 0xFF, 0xFF }; 0xD 0X3D 63,21,63 255,85,255 #ff55ff bright magenta 0xE 0x3E 63,63,21 255,255,85 #ffff55 yellow */ + +void video_set_pixel( void *obj, const int x, const int y, const video_rgb_color_t color ) +{ + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); +} + +void video_draw_rectangle( void *obj, const int x, const int y, const int w, const int h, const video_rgb_color_t color ) +{ + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); +} + +void video_clear_screen( void *obj, const video_rgb_color_t color ) +{ + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); +} + +void video_draw_char( void *obj, const unsigned char c, const int x, const int y, const video_rgb_color_t background, const video_rgb_color_t foreground ) +{ + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); +} + +void video_wait_for_retrace( void *obj ) +{ + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); +} + +void video_use_z_buffer( void *obj, bool use ) +{ + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); +} + +void video_refresh( void *obj ) +{ + kernel_panic( "Calling abstract method in file %s at line %d.", __FILE__, __LINE__ ); +} + diff --git a/src/drivers/video/video.h b/src/drivers/video/video.h index 6da8e60..8cfebb3 100644 --- a/src/drivers/video/video.h +++ b/src/drivers/video/video.h @@ -23,14 +23,28 @@ typedef struct { driver_t base; unsigned int nof_modes; const video_mode_t *modes[MAX_NOF_VIDEO_MODES]; + const video_mode_t *mode; } video_t; +typedef struct { + int R; + int G; + int B; +} video_rgb_color_t; + typedef struct { driver_vtable_t base; void (*register_mode)( void *obj, const video_mode_t *mode ); bool (*supports_mode)( void *obj, const video_mode_t mode ); bool (*set_mode)( void *obj, const video_mode_t mode ); bool (*switch_mode)( void *obj, const video_mode_t *mode ); + void (*set_pixel)( void *obj, const int x, const int y, const video_rgb_color_t color ); + void (*draw_rectangle)( void *obj, const int x, const int y, const int w, const int h, const video_rgb_color_t color ); + void (*clear_screen)( void *obj, const video_rgb_color_t color ); + void (*draw_char)( void *obj, const unsigned char c, const int x, const int y, const video_rgb_color_t background, const video_rgb_color_t foreground ); + void (*wait_for_retrace)( void *obj ); + void (*use_z_buffer)( void *obj, bool use ); + void (*refresh)( void *obj ); } video_vtable_t; void video_init( video_t *video, interrupt_t *interrupt, void *context ); @@ -46,12 +60,6 @@ bool video_supports_mode( void *obj, const video_mode_t mode ); bool video_set_mode( void *obj, const video_mode_t mode ); bool video_switch_mode( void *obj, const video_mode_t *mode ); -typedef struct { - int R; - int G; - int B; -} video_rgb_color_t; - extern const video_rgb_color_t VIDEO_RGB_COLOR_BLACK; extern const video_rgb_color_t VIDEO_RGB_COLOR_BLUE; extern const video_rgb_color_t VIDEO_RGB_COLOR_GREEN; @@ -64,4 +72,12 @@ extern const video_rgb_color_t VIDEO_RGB_COLOR_WHITE; video_rgb_color_t video_make_rgb_color( const int R, const int G, const int B ); +void video_set_pixel( void *obj, const int x, const int y, const video_rgb_color_t color ); +void video_draw_rectangle( void *obj, const int x, const int y, const int w, const int h, const video_rgb_color_t color ); +void video_clear_screen( void *obj, const video_rgb_color_t color ); +void video_draw_char( void *obj, const unsigned char c, const int x, const int y, const video_rgb_color_t background, const video_rgb_color_t foreground ); +void video_wait_for_retrace( void *obj ); +void video_use_z_buffer( void *obj, bool use ); +void video_refresh( void *obj ); + #endif // VIDEO_H diff --git a/src/gui/desktop.c b/src/gui/desktop.c index 33afed6..d560e8a 100644 --- a/src/gui/desktop.c +++ b/src/gui/desktop.c @@ -41,22 +41,27 @@ void desktop_draw( void *obj, graphics_context_t *context ) return; } - vga_clear_screen( context, desktop->base.base.background_color ); + ((video_vtable_t *)(context->base.vtable))->clear_screen( context, + desktop->base.base.background_color ); composite_widget_draw( obj, context ); for( int i = 0; i < 4; i++ ) { if( desktop->mouse_x > i ) { - vga_set_pixel( context, desktop->mouse_x - i, desktop->mouse_y, VIDEO_RGB_COLOR_WHITE ); + ((video_vtable_t *)(context->base.vtable))->set_pixel( context, + desktop->mouse_x - i, desktop->mouse_y, VIDEO_RGB_COLOR_WHITE ); } - if( desktop->mouse_x < context->mode->base.x - i ) { - vga_set_pixel( context, desktop->mouse_x + i, desktop->mouse_y, VIDEO_RGB_COLOR_WHITE ); + if( desktop->mouse_x < context->mode->x - i ) { + ((video_vtable_t *)(context->base.vtable))->set_pixel( context, + desktop->mouse_x + i, desktop->mouse_y, VIDEO_RGB_COLOR_WHITE ); } if( desktop->mouse_y > i ) { - vga_set_pixel( context, desktop->mouse_x, desktop->mouse_y - i, VIDEO_RGB_COLOR_WHITE ); + ((video_vtable_t *)(context->base.vtable))->set_pixel( context, + desktop->mouse_x, desktop->mouse_y - i, VIDEO_RGB_COLOR_WHITE ); } - if( desktop->mouse_y < context->mode->base.y - i ) { - vga_set_pixel( context, desktop->mouse_x, desktop->mouse_y + i, VIDEO_RGB_COLOR_WHITE ); + if( desktop->mouse_y < context->mode->y - i ) { + ((video_vtable_t *)(context->base.vtable))->set_pixel( context, + desktop->mouse_x, desktop->mouse_y + i, VIDEO_RGB_COLOR_WHITE ); } } diff --git a/src/gui/graphics_context.h b/src/gui/graphics_context.h index ba08273..65792d0 100644 --- a/src/gui/graphics_context.h +++ b/src/gui/graphics_context.h @@ -1,8 +1,8 @@ #ifndef GRAPHICS_CONTEXT_H #define GRAPHICS_CONTEXT_H -#include "vga.h" +#include "video.h" -typedef vga_t graphics_context_t; +typedef video_t graphics_context_t; #endif //GRAPHICS_CONTEXT_H diff --git a/src/gui/text_widget.c b/src/gui/text_widget.c index 3aa09cc..d9c96e0 100644 --- a/src/gui/text_widget.c +++ b/src/gui/text_widget.c @@ -45,7 +45,8 @@ void text_widget_draw( void *obj, graphics_context_t *context ) ((widget_t *)widget)->vtable->model_to_screen( widget, &x, &y ); for( const char *p = widget->s; *p != '\0'; p++ ) { - vga_draw_char( context, *p, x + w, y + h, + ((video_vtable_t *)(context->base.vtable))->draw_char( + context, *p, x + w, y + h, ((widget_t *)widget)->background_color, VIDEO_RGB_COLOR_WHITE ); w += 9; diff --git a/src/gui/widget.c b/src/gui/widget.c index 70e0dbc..cac4dfb 100644 --- a/src/gui/widget.c +++ b/src/gui/widget.c @@ -37,7 +37,7 @@ void widget_draw( void *obj, graphics_context_t *context ) widget->vtable->model_to_screen( widget, &x, &y ); - vga_draw_rectangle( context, x, y, widget->w, widget->h, + ((video_vtable_t *)(context->base.vtable))->draw_rectangle( context, x, y, widget->w, widget->h, widget->background_color ); } diff --git a/src/gui/window.c b/src/gui/window.c index 1cb1fb1..132dd89 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -39,14 +39,14 @@ void window_draw( void *obj, graphics_context_t *context ) if( ((widget_t *)widget)->x < 0 ) { ((widget_t *)widget)->x = 0; } - if( ((widget_t *)widget)->x > context->mode->base.x - ((widget_t *)widget)->w ) { - ((widget_t *)widget)->x = context->mode->base.x - ((widget_t *)widget)->w; + if( ((widget_t *)widget)->x > context->mode->x - ((widget_t *)widget)->w ) { + ((widget_t *)widget)->x = context->mode->x - ((widget_t *)widget)->w; } if( ((widget_t *)widget)->y < 0 ) { ((widget_t *)widget)->y = 0; } - if( ((widget_t *)widget)->y > context->mode->base.y - ((widget_t *)widget)->h ) { - ((widget_t *)widget)->y = context->mode->base.y - ((widget_t *)widget)->h; + if( ((widget_t *)widget)->y > context->mode->y - ((widget_t *)widget)->h ) { + ((widget_t *)widget)->y = context->mode->y - ((widget_t *)widget)->h; } composite_widget_draw( obj, context ); diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index d11d6c6..ae31e5a 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -21,7 +21,6 @@ #include "kernel.h" // TODO: move away from main! -#include "vga.h" #include "graphics_context.h" #include "widget.h" #include "composite_widget.h" @@ -46,7 +45,7 @@ typedef struct { driver_manager_t driver_manager; task_manager_t task_manager; memory_manager_t memory_manager; - vga_t *vga; + video_t *video; mode_t mode; keyboard_t *keyboard; mouse_t *mouse; @@ -148,7 +147,7 @@ void kernel_main( void ) // TODO: merge with the text mode vga_text_t object // TODO: introduce a graphics driver type, don't cast diretly here // TODO: also, what to do if there is more than one driver? - global_context.vga = (vga_t *)driver_manager_find_driver( &global_context.driver_manager, DRIVER_TYPE_VIDEO ); + global_context.video = (video_t *)driver_manager_find_driver( &global_context.driver_manager, DRIVER_TYPE_VIDEO ); puts( "Activating drivers" ); driver_manager_activate_all( &global_context.driver_manager ); @@ -330,9 +329,9 @@ static void refresh_screen( void ) interrupts_disable( ); // as vga_t is equals to the graphical context for now - ((widget_t *)&global_context.desktop)->vtable->draw( &global_context.desktop, global_context.vga ); + ((widget_t *)&global_context.desktop)->vtable->draw( &global_context.desktop, global_context.video ); - vga_refresh( global_context.vga ); + ((video_vtable_t *)( global_context.video->base.vtable))->refresh( global_context.video ); interrupts_enable( ); @@ -343,13 +342,13 @@ static void refresh_screen( void ) static void switch_to_graphics_mode( global_context_t *global_context ) { - vga_t *vga = global_context->vga; + video_t *video = global_context->video; vga_text_t *vga_text = &global_context->vga_text; mouse_t *mouse = global_context->mouse; desktop_t *desktop = &global_context->desktop; video_mode_t mode = video_make_mode( VIDEO_MODE_TYPE_GRAPHICS, 320, 200, 8 ); - if( ((video_vtable_t *)(vga->base.base.vtable))->set_mode( vga, mode ) ) { + if( ((video_vtable_t *)(video->base.vtable))->set_mode( video, mode ) ) { vga_text_save( vga_text ); desktop_init( desktop, 320, 200, VIDEO_RGB_COLOR_BLUE ); @@ -369,16 +368,16 @@ static void switch_to_graphics_mode( global_context_t *global_context ) } *p = '\0'; - window_init( &global_context->window3, (widget_t *)desktop, 55, 5, vga->mode->base.x - 65, 100, VIDEO_RGB_COLOR_CYAN ); + window_init( &global_context->window3, (widget_t *)desktop, 55, 5, video->mode->x - 65, 100, VIDEO_RGB_COLOR_CYAN ); ((composite_widget_vtable_t *)global_context->desktop.base.base.vtable)->add_child( desktop, (widget_t *)&global_context->window3 ); text_widget_init( &global_context->widget3, (widget_t *)&global_context->window3, 1, 1, global_context->window3.base.base.w - 2, global_context->window3.base.base.h - 2, VIDEO_RGB_COLOR_RED, s ); ((composite_widget_vtable_t *)global_context->window3.base.base.vtable)->add_child( (composite_widget_t *)&global_context->window3, (widget_t *)&global_context->widget3 ); - ((mouse_vtable_t *)(mouse->base.vtable))->set_resolution( mouse, vga->mode->base.x, vga->mode->base.y ); + ((mouse_vtable_t *)(mouse->base.vtable))->set_resolution( mouse, video->mode->x, video->mode->y ); // enable Z buffering - vga_use_z_buffer( global_context->vga, true ); + ((video_vtable_t *)(global_context->video->base.vtable))->use_z_buffer( global_context->video, true ); global_context->mode = MODE_GRAPHICS; } @@ -386,14 +385,14 @@ static void switch_to_graphics_mode( global_context_t *global_context ) static void switch_to_text_mode( global_context_t *global_context ) { - vga_t *vga = global_context->vga; + video_t *video = global_context->video; vga_text_t *vga_text = &global_context->vga_text; mouse_t *mouse = global_context->mouse; vga_text_restore( vga_text ); video_mode_t mode = video_make_mode( VIDEO_MODE_TYPE_TEXT, 640, 480, 4 ); - if( ((video_vtable_t *)(vga->base.base.vtable))->set_mode( vga, mode ) ) { + if( ((video_vtable_t *)(video->base.vtable))->set_mode( video, mode ) ) { vga_text_set_cursor( vga_text, vga_text->cursor_x, vga_text->cursor_y ); ((mouse_vtable_t *)(mouse->base.vtable))->set_resolution( mouse, vga_text->res_x, vga_text->res_y ); global_context->mode = MODE_TEXT; -- cgit v1.2.3-54-g00ecf