diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2017-06-30 20:45:37 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2017-06-30 20:45:37 +0200 |
commit | 25228d8927af801667d4be2ea85ee517d1916fc7 (patch) | |
tree | aa5932cfec8b95acdf978e459c9850d1b4a11678 | |
parent | c1bbac52d78b2e3e93fa43a5a7b3907073493216 (diff) | |
download | abaos-25228d8927af801667d4be2ea85ee517d1916fc7.tar.gz abaos-25228d8927af801667d4be2ea85ee517d1916fc7.tar.bz2 |
almost got a complete mode switch (vga graphics back to text) working
some cleanup in VGA driver code
-rw-r--r-- | src/drivers/video/vga.c | 18 | ||||
-rw-r--r-- | src/kernel/kernel.c | 20 | ||||
-rw-r--r-- | src/kernel/vgatext.c | 13 | ||||
-rw-r--r-- | src/kernel/vgatext.h | 5 |
4 files changed, 27 insertions, 29 deletions
diff --git a/src/drivers/video/vga.c b/src/drivers/video/vga.c index 647456b..5a53870 100644 --- a/src/drivers/video/vga.c +++ b/src/drivers/video/vga.c @@ -375,26 +375,12 @@ void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, memset( data, bg_color_idx, sizeof( data ) ); for( int xx = 0; xx < vga_font.Width; xx++ ) { if( bmap[yy] & mask[xx] ) { - data[7-xx] = fg_color_idx; + data[vga_font.Width-1-xx] = fg_color_idx; } } uint8_t *addr = vga->base_addr + vga->mode.x * ( y + yy ) + x; - memcpy( addr, data, 8 ); + memcpy( addr, data, vga_font.Width ); } - -// amazingly slow -/* - 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 + 10 - xx, y + yy, foreground ); - } else { -// drawing only what's needed, the background is done by the widget -// vga_set_pixel( vga, x + 10 - xx, y + yy, background ); - } - } - } -*/ } void vga_wait_for_retrace( vga_t *vga ) diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 9bd3d98..501ab90 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -143,6 +143,8 @@ void kernel_main( void ) switch( global_context.mode ) { case MODE_TEXT: + // nothing to draw or refresh in text mode, the + // VGA card is doing that for us break; case MODE_GRAPHICS: @@ -150,12 +152,6 @@ void kernel_main( void ) // events originating especially from the mouse interrupts_disable( ); - // wait for VGA retrace, assume drawing the desktop - // is fast enough to finish in time (so we don't recheck - // for retrace), it Z-buffering, this is done in vga_refresh - // directly, no need to do it here -// vga_wait_for_retrace( &global_context.vga ); - // as vga_t is equals to the graphical context for now ((widget_vtable_t *)global_context.desktop.vtable)->draw( &global_context.desktop, &global_context.vga ); @@ -230,6 +226,8 @@ static void handle_keyboard_event( keyboard_event_t *event, void *context ) switch( global_context->mode ) { case MODE_TEXT: if( vga_set_mode( vga, vga_make_mode( VGA_MODE_TYPE_GRAPHICS, 320, 200, 8 ) ) ) { + vga_text_save( vga_text ); + desktop_init( &global_context->desktop, 320, 200, VGA_COLOR_BLUE ); window_init( &global_context->window1, (widget_t *)&global_context->desktop, 60, 90, 60, 70, VGA_COLOR_LIGHT_GREY ); @@ -258,13 +256,13 @@ static void handle_keyboard_event( keyboard_event_t *event, void *context ) // enable Z buffering vga_use_z_buffer( &global_context->vga, true ); - // draw on mode switch -// ((widget_vtable_t *)global_context->desktop.vtable)->draw( &global_context->desktop, &global_context->vga ); - global_context->mode = MODE_GRAPHICS; break; case MODE_GRAPHICS: + vga_text_restore( vga_text ); + vga_text_set_cursor( vga_text, vga_text->cursor_x, vga_text->cursor_y ); + if( vga_set_mode( vga, vga_make_mode( VGA_MODE_TYPE_TEXT, 640, 480, 4 ) ) ) { mouse_set_resolution( mouse, vga_text->res_x, vga_text->res_y ); global_context->mode = MODE_TEXT; @@ -336,10 +334,6 @@ static void handle_mouse_event( mouse_event_t *event, void *context ) break; } - // alternative way of redrawing on mouse event - // on qemu looses the mouse.. -// ((widget_vtable_t *)desktop->vtable)->draw( &global_context->desktop, &global_context->vga ); - break; } } diff --git a/src/kernel/vgatext.c b/src/kernel/vgatext.c index 76bfd46..232d91a 100644 --- a/src/kernel/vgatext.c +++ b/src/kernel/vgatext.c @@ -262,3 +262,16 @@ void vga_text_hide_mouse_cursor( vga_text_t *vga_text ) } } +void vga_text_save( vga_text_t *vga_text ) +{ + volatile uint8_t *VIDEO_MEMORY = (uint8_t *)0xA0000; + + memcpy( vga_text->buf, VIDEO_MEMORY, 2*65535 ); +} + +void vga_text_restore( vga_text_t *vga_text ) +{ + volatile uint8_t *VIDEO_MEMORY = (uint8_t *)0xA0000; + + memcpy( VIDEO_MEMORY, vga_text->buf, 2*65535 ); +} diff --git a/src/kernel/vgatext.h b/src/kernel/vgatext.h index 499e3d8..c0bfbdc 100644 --- a/src/kernel/vgatext.h +++ b/src/kernel/vgatext.h @@ -42,6 +42,9 @@ typedef struct { bool show_mouse_cursor; int mouse_cursor_x; int mouse_cursor_y; + // TODO: actually restore a proper, for now we + // remember the whole video area during mode switch + uint8_t buf[2*65535]; } vga_text_t; void vga_text_init( vga_text_t *vga_text ); @@ -64,5 +67,7 @@ void vga_text_inverse_colors_at( vga_text_t *vga_text, const int x, const int y void vga_text_show_mouse_cursor( vga_text_t *vga_text ); void vga_text_move_mouse_cursor( vga_text_t *vga_text, const int x, const int y ); void vga_text_hide_mouse_cursor( vga_text_t *vga_text ); +void vga_text_save( vga_text_t *vga_text ); +void vga_text_restore( vga_text_t *vga_text ); #endif /* VGA_TEXT_H */ |