summaryrefslogtreecommitdiff
path: root/src/kernel/kernel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/kernel.c')
-rw-r--r--src/kernel/kernel.c180
1 files changed, 100 insertions, 80 deletions
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index 5bc3b52..9a66e89 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -194,94 +194,111 @@ static void handle_keyboard_event( keyboard_event_t *event, void *context )
driver_manager_t *driver_manager = &global_context->driver_manager;
vga_t *vga = &global_context->vga;
mouse_t *mouse = &global_context->mouse;
+ //~ desktop_t *desktop = &global_context->desktop;
- vga_text_hide_mouse_cursor( vga_text );
-
- if( event->type == KEYBOARD_EVENT_TYPE_KEY_PRESSED ) {
- if( event->key == KEYBOARD_KEY_ASCII ) {
- if( event->ascii_key == '\n' ) {
- buf[pos] = '\0';
- pos = 0;
- puts( "" );
- if( strcmp( buf, "help" ) == 0 ) {
- puts( "halt - terminate os" );
- puts( "mem - show memory usage" );
- puts( "driver - show status of drivers" );
- puts( "proc - show process status" );
- puts( "clear - clear screen" );
- puts( "mode - switch between text/graphics mode" );
- } else if( strcmp( buf, "halt" ) == 0 ) {
- terminate = true;
- } else if( strcmp( buf, "mem" ) == 0 ) {
- // TODO: print memory usage
- } else if( strcmp( buf, "proc" ) == 0 ) {
- // TODO: print scheduler status
- } else if( strcmp( buf, "driver" ) == 0 ) {
- driver_manager_print_info_all( driver_manager );
- } else if( strcmp( buf, "clear" ) == 0 ) {
- vga_text_clear_screen( vga_text );
- } else if( strcmp( buf, "mode" ) == 0 ) {
- // TODO: move mode switches to and from graphics/text mode here,
- // for now when we enter the graphics mode we remain there
- 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 );
- ((composite_widget_vtable_t *)global_context->desktop.vtable)->add_child( &global_context->desktop, (widget_t *)&global_context->window1 );
-
- window_init( &global_context->window2, (widget_t *)&global_context->desktop, 130, 80, 60, 70, VGA_COLOR_GREEN );
- ((composite_widget_vtable_t *)global_context->desktop.vtable)->add_child( &global_context->desktop, (widget_t *)&global_context->window2 );
-
- char s[100];
-
- char *p = s;
- for( char c = ' '; c <= '~'; c++ ) {
- *p++ = c;
- }
- *p = '\0';
-
- window_init( &global_context->window3, (widget_t *)&global_context->desktop, 55, 5, vga->mode.x - 65, 100, VGA_COLOR_CYAN );
- ((composite_widget_vtable_t *)global_context->desktop.vtable)->add_child( &global_context->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, VGA_COLOR_RED, s );
- ((composite_widget_vtable_t *)global_context->window3.vtable)->add_child( (composite_widget_t *)&global_context->window3, (widget_t *)&global_context->widget3 );
-
- mouse_set_resolution( mouse, vga->mode.x, vga->mode.y );
- }
-
- // enable Z buffering
- vga_use_z_buffer( &global_context->vga, true );
-
- global_context->mode = MODE_GRAPHICS;
- break;
+ switch( global_context->mode ) {
- case MODE_GRAPHICS:
- vga_text_restore( vga_text );
+ case MODE_TEXT:
- if( vga_set_mode( vga, vga_make_mode( VGA_MODE_TYPE_TEXT, 640, 480, 4 ) ) ) {
- vga_text_set_cursor( vga_text, vga_text->cursor_x, vga_text->cursor_y );
- mouse_set_resolution( mouse, vga_text->res_x, vga_text->res_y );
- global_context->mode = MODE_TEXT;
+ vga_text_hide_mouse_cursor( vga_text );
+
+ if( event->type == KEYBOARD_EVENT_TYPE_KEY_PRESSED ) {
+ if( event->key == KEYBOARD_KEY_ASCII ) {
+ if( event->ascii_key == '\n' ) {
+ buf[pos] = '\0';
+ pos = 0;
+ puts( "" );
+ if( strcmp( buf, "help" ) == 0 ) {
+ puts( "halt - terminate os" );
+ puts( "mem - show memory usage" );
+ puts( "driver - show status of drivers" );
+ puts( "proc - show process status" );
+ puts( "clear - clear screen" );
+ puts( "mode - switch between text/graphics mode" );
+ } else if( strcmp( buf, "halt" ) == 0 ) {
+ terminate = true;
+ } else if( strcmp( buf, "mem" ) == 0 ) {
+ // TODO: print memory usage
+ } else if( strcmp( buf, "proc" ) == 0 ) {
+ // TODO: print scheduler status
+ } else if( strcmp( buf, "driver" ) == 0 ) {
+ driver_manager_print_info_all( driver_manager );
+ } else if( strcmp( buf, "clear" ) == 0 ) {
+ vga_text_clear_screen( vga_text );
+ } else if( strcmp( buf, "mode" ) == 0 ) {
+ // TODO: move mode switches to and from graphics/text mode here,
+ // for now when we enter the graphics mode we remain there
+ 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 );
+ ((composite_widget_vtable_t *)global_context->desktop.vtable)->add_child( &global_context->desktop, (widget_t *)&global_context->window1 );
+
+ window_init( &global_context->window2, (widget_t *)&global_context->desktop, 130, 80, 60, 70, VGA_COLOR_GREEN );
+ ((composite_widget_vtable_t *)global_context->desktop.vtable)->add_child( &global_context->desktop, (widget_t *)&global_context->window2 );
+
+ char s[100];
+
+ char *p = s;
+ for( char c = ' '; c <= '~'; c++ ) {
+ *p++ = c;
+ }
+ *p = '\0';
+
+ window_init( &global_context->window3, (widget_t *)&global_context->desktop, 55, 5, vga->mode.x - 65, 100, VGA_COLOR_CYAN );
+ ((composite_widget_vtable_t *)global_context->desktop.vtable)->add_child( &global_context->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, VGA_COLOR_RED, s );
+ ((composite_widget_vtable_t *)global_context->window3.vtable)->add_child( (composite_widget_t *)&global_context->window3, (widget_t *)&global_context->widget3 );
+
+ mouse_set_resolution( mouse, vga->mode.x, vga->mode.y );
+
+ // enable Z buffering
+ vga_use_z_buffer( &global_context->vga, true );
+
+ global_context->mode = MODE_GRAPHICS;
+ }
+
+ break;
+
+ case MODE_GRAPHICS:
+ vga_text_restore( vga_text );
+
+ if( vga_set_mode( vga, vga_make_mode( VGA_MODE_TYPE_TEXT, 640, 480, 4 ) ) ) {
+ vga_text_set_cursor( vga_text, vga_text->cursor_x, vga_text->cursor_y );
+ mouse_set_resolution( mouse, vga_text->res_x, vga_text->res_y );
+ global_context->mode = MODE_TEXT;
+ }
+
+ break;
}
- break;
+ } else {
+ printf( "ERR: Unknown pre-boot command '%s'\n", buf );
+ }
+ } else if( event->ascii_key == '\b' ) {
+ if( pos > 0 ) {
+ buf[--pos] = '\0';
+ printf( "\n%s", buf );
+ }
+ } else {
+ printf( "%c", event->ascii_key );
+ buf[pos++] = event->ascii_key;
}
- } else {
- printf( "ERR: Unknown pre-boot command '%s'\n", buf );
}
- } else if( event->ascii_key == '\b' ) {
- if( pos > 0 ) {
- buf[--pos] = '\0';
- printf( "\n%s", buf );
+ }
+ break;
+
+ case MODE_GRAPHICS:
+ if( event->type == KEYBOARD_EVENT_TYPE_KEY_PRESSED ) {
+ if( event->key == KEYBOARD_KEY_ASCII ) {
+ ((widget_vtable_t *)global_context->desktop.vtable)->on_key_down( &global_context->desktop, event->ascii_key );
}
- } else {
- printf( "%c", event->ascii_key );
- buf[pos++] = event->ascii_key;
}
- }
+ break;
}
}
@@ -292,7 +309,9 @@ static void handle_mouse_event( mouse_event_t *event, void *context )
desktop_t *desktop = &global_context->desktop;
switch( global_context->mode ) {
+
case MODE_TEXT:
+
switch( event->type ) {
case MOUSE_EVENT_TYPE_BUTTON_UP:
vga_text_hide_mouse_cursor( vga_text );
@@ -316,6 +335,7 @@ static void handle_mouse_event( mouse_event_t *event, void *context )
break;
case MODE_GRAPHICS:
+
switch( event->type ) {
case MOUSE_EVENT_TYPE_BUTTON_UP:
if( event->button == MOUSE_BUTTON_LEFT ) {