Index: uspace/app/top/screen.c
===================================================================
--- uspace/app/top/screen.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/app/top/screen.c	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -280,4 +280,9 @@
 		screen_newline();
 	}
+	
+	while (row < rows) {
+		screen_newline();
+		row++;
+	}
 }
 
@@ -313,4 +318,9 @@
 		screen_newline();
 	}
+	
+	while (row < rows) {
+		screen_newline();
+		row++;
+	}
 }
 
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/lib/c/Makefile	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -79,4 +79,5 @@
 	generic/io/printf_core.c \
 	generic/io/console.c \
+	generic/io/screenbuffer.c \
 	generic/malloc.c \
 	generic/sysinfo.c \
Index: uspace/lib/c/generic/io/asprintf.c
===================================================================
--- uspace/lib/c/generic/io/asprintf.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/lib/c/generic/io/asprintf.c	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -61,5 +61,5 @@
 int asprintf(char **strp, const char *fmt, ...)
 {
-	struct printf_spec ps = {
+	printf_spec_t ps = {
 		asprintf_str_write,
 		asprintf_wstr_write,
Index: uspace/lib/c/generic/io/screenbuffer.c
===================================================================
--- uspace/lib/c/generic/io/screenbuffer.c	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
+++ uspace/lib/c/generic/io/screenbuffer.c	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup console
+ * @{
+ */
+/** @file
+ */
+
+#include <io/style.h>
+#include <io/screenbuffer.h>
+#include <malloc.h>
+#include <unistd.h>
+
+/** Store one character to screenbuffer.
+ *
+ * Its position is determined by scr->position_x
+ * and scr->position_y.
+ *
+ * @param scr Screenbuffer
+ * @param c   Stored character
+ *
+ */
+void screenbuffer_putchar(screenbuffer_t *scr, wchar_t ch)
+{
+	keyfield_t *field =
+	    get_field_at(scr, scr->position_x, scr->position_y);
+	
+	field->character = ch;
+	field->attrs = scr->attrs;
+}
+
+/** Initilize screenbuffer.
+ *
+ * Allocate space for screen content in accordance to given size.
+ *
+ * @param scr    Initialized screenbuffer
+ * @param size_x Width in characters
+ * @param size_y Height in characters
+ *
+ * @return Pointer to screenbuffer (same as scr parameter) or NULL
+ *
+ */
+screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, ipcarg_t size_x,
+    ipcarg_t size_y)
+{
+	scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
+	if (!scr->buffer)
+		return NULL;
+	
+	scr->size_x = size_x;
+	scr->size_y = size_y;
+	scr->attrs.t = at_style;
+	scr->attrs.a.s.style = STYLE_NORMAL;
+	scr->is_cursor_visible = 1;
+	
+	screenbuffer_clear(scr);
+	
+	return scr;
+}
+
+/** Clear screenbuffer.
+ *
+ * @param scr Screenbuffer
+ *
+ */
+void screenbuffer_clear(screenbuffer_t *scr)
+{
+	size_t i;
+	
+	for (i = 0; i < (scr->size_x * scr->size_y); i++) {
+		scr->buffer[i].character = ' ';
+		scr->buffer[i].attrs = scr->attrs;
+	}
+	
+	scr->top_line = 0;
+	scr->position_x = 0;
+	scr->position_y = 0;
+}
+
+/** Clear one buffer line.
+ *
+ * @param scr
+ * @param line One buffer line (not a screen line!)
+ *
+ */
+void screenbuffer_clear_line(screenbuffer_t *scr, ipcarg_t line)
+{
+	ipcarg_t x;
+	
+	for (x = 0; x < scr->size_x; x++) {
+		scr->buffer[x + line * scr->size_x].character = ' ';
+		scr->buffer[x + line * scr->size_x].attrs = scr->attrs;
+	}
+}
+
+/** Copy content buffer from screenbuffer to given memory.
+ *
+ * @param scr  Source screenbuffer
+ * @param dest Destination
+ *
+ */
+void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
+{
+	size_t i;
+	
+	for (i = 0; i < (scr->size_x * scr->size_y); i++)
+		dest[i] = scr->buffer[i];
+}
+
+/** Set new cursor position in screenbuffer.
+ *
+ * @param scr
+ * @param x
+ * @param y
+ *
+ */
+void screenbuffer_goto(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y)
+{
+	scr->position_x = x % scr->size_x;
+	scr->position_y = y % scr->size_y;
+}
+
+/** Set new style.
+ *
+ * @param scr
+ * @param fg_color
+ * @param bg_color
+ *
+ */
+void screenbuffer_set_style(screenbuffer_t *scr, uint8_t style)
+{
+	scr->attrs.t = at_style;
+	scr->attrs.a.s.style = style;
+}
+
+/** Set new color.
+ *
+ * @param scr
+ * @param fg_color
+ * @param bg_color
+ *
+ */
+void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color,
+    uint8_t bg_color, uint8_t flags)
+{
+	scr->attrs.t = at_idx;
+	scr->attrs.a.i.fg_color = fg_color;
+	scr->attrs.a.i.bg_color = bg_color;
+	scr->attrs.a.i.flags = flags;
+}
+
+/** Set new RGB color.
+ *
+ * @param scr
+ * @param fg_color
+ * @param bg_color
+ *
+ */
+void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color,
+    uint32_t bg_color)
+{
+	scr->attrs.t = at_rgb;
+	scr->attrs.a.r.fg_color = fg_color;
+	scr->attrs.a.r.bg_color = bg_color;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/io/vprintf.c
===================================================================
--- uspace/lib/c/generic/io/vprintf.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/lib/c/generic/io/vprintf.c	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -76,5 +76,5 @@
 int vfprintf(FILE *stream, const char *fmt, va_list ap)
 {
-	struct printf_spec ps = {
+	printf_spec_t ps = {
 		vprintf_str_write,
 		vprintf_wstr_write,
Index: uspace/lib/c/include/io/color.h
===================================================================
--- uspace/lib/c/include/io/color.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/lib/c/include/io/color.h	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -36,5 +36,5 @@
 #define LIBC_IO_COLOR_H_
 
-enum console_color {
+typedef enum {
 	COLOR_BLACK   = 0,
 	COLOR_BLUE    = 1,
@@ -48,5 +48,5 @@
 	CATTR_BRIGHT  = 8,
 	CATTR_BLINK   = 8
-};
+} console_color_t;
 
 #endif
Index: uspace/lib/c/include/io/console.h
===================================================================
--- uspace/lib/c/include/io/console.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/lib/c/include/io/console.h	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -44,10 +44,10 @@
 } console_ev_type_t;
 
-enum {
+typedef enum {
 	CONSOLE_CCAP_NONE = 0,
 	CONSOLE_CCAP_STYLE,
 	CONSOLE_CCAP_INDEXED,
 	CONSOLE_CCAP_RGB
-};
+} console_caps_t;
 
 /** Console event structure. */
Index: uspace/lib/c/include/io/keycode.h
===================================================================
--- uspace/lib/c/include/io/keycode.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/lib/c/include/io/keycode.h	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -51,5 +51,5 @@
  * they really are organized here by position, rather than by label.
  */
-enum keycode {
+typedef enum {
 
 	/* Main block row 1 */
@@ -199,5 +199,5 @@
 } keycode_t;
 
-enum keymod {
+typedef enum {
 	KM_LSHIFT      = 0x001,
 	KM_RSHIFT      = 0x002,
Index: uspace/lib/c/include/io/klog.h
===================================================================
--- uspace/lib/c/include/io/klog.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/lib/c/include/io/klog.h	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -33,10 +33,10 @@
  */
 
-#ifndef LIBC_STREAM_H_
-#define LIBC_STREAM_H_
+#ifndef LIBC_IO_KLOG_H_
+#define LIBC_IO_KLOG_H_
 
 #include <sys/types.h>
 
-extern size_t klog_write(const void *buf, size_t size);
+extern size_t klog_write(const void *, size_t);
 extern void klog_update(void);
 
Index: uspace/lib/c/include/io/printf_core.h
===================================================================
--- uspace/lib/c/include/io/printf_core.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/lib/c/include/io/printf_core.h	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -40,5 +40,5 @@
 
 /** Structure for specifying output methods for different printf clones. */
-typedef struct printf_spec {
+typedef struct {
 	/* String output function, returns number of printed characters or EOF */
 	int (*str_write)(const char *, size_t, void *);
@@ -51,5 +51,5 @@
 } printf_spec_t;
 
-int printf_core(const char *fmt, printf_spec_t *ps, va_list ap);
+extern int printf_core(const char *, printf_spec_t *, va_list);
 
 #endif
Index: uspace/lib/c/include/io/screenbuffer.h
===================================================================
--- uspace/lib/c/include/io/screenbuffer.h	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
+++ uspace/lib/c/include/io/screenbuffer.h	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup console
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_SCREENBUFFER_H__
+#define LIBC_SCREENBUFFER_H__
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <ipc/ipc.h>
+#include <bool.h>
+
+typedef enum {
+	at_style,
+	at_idx,
+	at_rgb
+} attr_type_t;
+
+typedef struct {
+	uint8_t style;
+} attr_style_t;
+
+typedef struct {
+	uint8_t fg_color;
+	uint8_t bg_color;
+	uint8_t flags;
+} attr_idx_t;
+
+typedef struct {
+	uint32_t bg_color;  /**< background color */
+	uint32_t fg_color;  /**< foreground color */
+} attr_rgb_t;
+
+typedef union {
+	attr_style_t s;
+	attr_idx_t i;
+	attr_rgb_t r;
+} attr_val_t;
+
+typedef struct {
+	attr_type_t t;
+	attr_val_t a;
+} attrs_t;
+
+/** One field on screen. It contain one character and its attributes. */
+typedef struct {
+	wchar_t character;  /**< Character itself */
+	attrs_t attrs;      /**< Character attributes */
+} keyfield_t;
+
+/** Structure for buffering state of one virtual console.
+ */
+typedef struct {
+	keyfield_t *buffer;      /**< Screen content - characters and
+	                              their attributes (used as a circular buffer) */
+	ipcarg_t size_x;         /**< Number of columns  */
+	ipcarg_t size_y;         /**< Number of rows */
+	
+	/** Coordinates of last printed character for determining cursor position */
+	ipcarg_t position_x;
+	ipcarg_t position_y;
+	
+	attrs_t attrs;           /**< Current attributes. */
+	size_t top_line;         /**< Points to buffer[][] line that will
+	                              be printed at screen as the first line */
+	bool is_cursor_visible;  /**< Cursor state - default is visible */
+} screenbuffer_t;
+
+/** Returns keyfield for position on screen
+ *
+ * Screenbuffer->buffer is cyclic buffer so we
+ * must couted in index of the topmost line.
+ *
+ * @param scr Screenbuffer
+ * @param x   Position on screen
+ * @param y   Position on screen
+ *
+ * @return Keyfield structure with character and its attributes on x, y
+ *
+ */
+static inline keyfield_t *get_field_at(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y)
+{
+	return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x;
+}
+
+/** Compares two sets of attributes.
+ *
+ * @param s1 First style
+ * @param s2 Second style
+ *
+ * @return Nonzero on equality
+ *
+ */
+static inline bool attrs_same(attrs_t a1, attrs_t a2)
+{
+	if (a1.t != a2.t)
+		return false;
+	
+	switch (a1.t) {
+	case at_style:
+		return (a1.a.s.style == a2.a.s.style);
+	case at_idx:
+		return (a1.a.i.fg_color == a2.a.i.fg_color)
+		    && (a1.a.i.bg_color == a2.a.i.bg_color)
+		    && (a1.a.i.flags == a2.a.i.flags);
+	case at_rgb:
+		return (a1.a.r.fg_color == a2.a.r.fg_color)
+		    && (a1.a.r.bg_color == a2.a.r.bg_color);
+	}
+	
+	return false;
+}
+
+extern void screenbuffer_putchar(screenbuffer_t *, wchar_t);
+extern screenbuffer_t *screenbuffer_init(screenbuffer_t *, ipcarg_t, ipcarg_t);
+
+extern void screenbuffer_clear(screenbuffer_t *);
+extern void screenbuffer_clear_line(screenbuffer_t *, ipcarg_t);
+extern void screenbuffer_copy_buffer(screenbuffer_t *, keyfield_t *);
+extern void screenbuffer_goto(screenbuffer_t *, ipcarg_t, ipcarg_t);
+extern void screenbuffer_set_style(screenbuffer_t *, uint8_t);
+extern void screenbuffer_set_color(screenbuffer_t *, uint8_t, uint8_t, uint8_t);
+extern void screenbuffer_set_rgb_color(screenbuffer_t *, uint32_t, uint32_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/io/style.h
===================================================================
--- uspace/lib/c/include/io/style.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/lib/c/include/io/style.h	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -36,10 +36,10 @@
 #define LIBC_IO_STYLE_H_
 
-enum console_style {
+typedef enum {
 	STYLE_NORMAL   = 0,
 	STYLE_EMPHASIS = 1,
 	STYLE_INVERTED = 2,
 	STYLE_SELECTED = 3
-};
+} console_style_t;
 
 #endif
Index: uspace/srv/hid/console/Makefile
===================================================================
--- uspace/srv/hid/console/Makefile	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/srv/hid/console/Makefile	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -33,5 +33,4 @@
 GENERIC_SOURCES = \
 	console.c \
-	screenbuffer.c \
 	keybuffer.c \
 	gcons.c
Index: uspace/srv/hid/console/console.c
===================================================================
--- uspace/srv/hid/console/console.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/srv/hid/console/console.c	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -54,9 +54,11 @@
 #include <vfs/vfs.h>
 #include <fibril_synch.h>
+#include <io/style.h>
+#include <io/screenbuffer.h>
 
 #include "console.h"
 #include "gcons.h"
 #include "keybuffer.h"
-#include "screenbuffer.h"
+
 
 #define NAME       "console"
@@ -827,5 +829,5 @@
 	async_serialize_start();
 	gcons_redraw_console();
-	set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
+	set_style(STYLE_NORMAL);
 	screen_clear();
 	curs_goto(0, 0);
Index: pace/srv/hid/console/screenbuffer.c
===================================================================
--- uspace/srv/hid/console/screenbuffer.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ 	(revision )
@@ -1,194 +1,0 @@
-/*
- * Copyright (c) 2006 Josef Cejka
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup console
- * @{
- */
-/** @file
- */
-
-#include <io/style.h>
-#include <malloc.h>
-#include <unistd.h>
-#include "screenbuffer.h"
-
-/** Store one character to screenbuffer.
- *
- * Its position is determined by scr->position_x
- * and scr->position_y.
- *
- * @param scr Screenbuffer
- * @param c   Stored character
- *
- */
-void screenbuffer_putchar(screenbuffer_t *scr, wchar_t ch)
-{
-	keyfield_t *field =
-	    get_field_at(scr, scr->position_x, scr->position_y);
-	
-	field->character = ch;
-	field->attrs = scr->attrs;
-}
-
-/** Initilize screenbuffer.
- *
- * Allocate space for screen content in accordance to given size.
- *
- * @param scr    Initialized screenbuffer
- * @param size_x Width in characters
- * @param size_y Height in characters
- *
- * @return Pointer to screenbuffer (same as scr parameter) or NULL
- *
- */
-screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, ipcarg_t size_x,
-    ipcarg_t size_y)
-{
-	scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
-	if (!scr->buffer)
-		return NULL;
-	
-	scr->size_x = size_x;
-	scr->size_y = size_y;
-	scr->attrs.t = at_style;
-	scr->attrs.a.s.style = STYLE_NORMAL;
-	scr->is_cursor_visible = 1;
-	
-	screenbuffer_clear(scr);
-	
-	return scr;
-}
-
-/** Clear screenbuffer.
- *
- * @param scr Screenbuffer
- *
- */
-void screenbuffer_clear(screenbuffer_t *scr)
-{
-	size_t i;
-	
-	for (i = 0; i < (scr->size_x * scr->size_y); i++) {
-		scr->buffer[i].character = ' ';
-		scr->buffer[i].attrs = scr->attrs;
-	}
-	
-	scr->top_line = 0;
-	scr->position_x = 0;
-	scr->position_y = 0;
-}
-
-/** Clear one buffer line.
- *
- * @param scr
- * @param line One buffer line (not a screen line!)
- *
- */
-void screenbuffer_clear_line(screenbuffer_t *scr, ipcarg_t line)
-{
-	ipcarg_t x;
-	
-	for (x = 0; x < scr->size_x; x++) {
-		scr->buffer[x + line * scr->size_x].character = ' ';
-		scr->buffer[x + line * scr->size_x].attrs = scr->attrs;
-	}
-}
-
-/** Copy content buffer from screenbuffer to given memory.
- *
- * @param scr  Source screenbuffer
- * @param dest Destination
- *
- */
-void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
-{
-	size_t i;
-	
-	for (i = 0; i < (scr->size_x * scr->size_y); i++)
-		dest[i] = scr->buffer[i];
-}
-
-/** Set new cursor position in screenbuffer.
- *
- * @param scr
- * @param x
- * @param y
- *
- */
-void screenbuffer_goto(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y)
-{
-	scr->position_x = x % scr->size_x;
-	scr->position_y = y % scr->size_y;
-}
-
-/** Set new style.
- *
- * @param scr
- * @param fg_color
- * @param bg_color
- *
- */
-void screenbuffer_set_style(screenbuffer_t *scr, uint8_t style)
-{
-	scr->attrs.t = at_style;
-	scr->attrs.a.s.style = style;
-}
-
-/** Set new color.
- *
- * @param scr
- * @param fg_color
- * @param bg_color
- *
- */
-void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color,
-    uint8_t bg_color, uint8_t flags)
-{
-	scr->attrs.t = at_idx;
-	scr->attrs.a.i.fg_color = fg_color;
-	scr->attrs.a.i.bg_color = bg_color;
-	scr->attrs.a.i.flags = flags;
-}
-
-/** Set new RGB color.
- *
- * @param scr
- * @param fg_color
- * @param bg_color
- *
- */
-void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color,
-    uint32_t bg_color)
-{
-	scr->attrs.t = at_rgb;
-	scr->attrs.a.r.fg_color = fg_color;
-	scr->attrs.a.r.bg_color = bg_color;
-}
-
-/** @}
- */
Index: pace/srv/hid/console/screenbuffer.h
===================================================================
--- uspace/srv/hid/console/screenbuffer.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ 	(revision )
@@ -1,157 +1,0 @@
-/*
- * Copyright (c) 2006 Josef Cejka
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup console
- * @{
- */
-/** @file
- */
-
-#ifndef SCREENBUFFER_H__
-#define SCREENBUFFER_H__
-
-#include <stdint.h>
-#include <sys/types.h>
-#include <ipc/ipc.h>
-#include <bool.h>
-
-#define DEFAULT_FOREGROUND  0x000000  /**< default console foreground color */
-#define DEFAULT_BACKGROUND  0xf0f0f0  /**< default console background color */
-
-typedef struct {
-	uint8_t style;
-} attr_style_t;
-
-typedef struct {
-	uint8_t fg_color;
-	uint8_t bg_color;
-	uint8_t flags;
-} attr_idx_t;
-
-typedef struct {
-	uint32_t bg_color;  /**< background color */
-	uint32_t fg_color;  /**< foreground color */
-} attr_rgb_t;
-
-typedef struct {
-	enum {
-		at_style,
-		at_idx,
-		at_rgb
-	} t;
-	union {
-		attr_style_t s;
-		attr_idx_t i;
-		attr_rgb_t r;
-	} a;
-} attrs_t;
-
-/** One field on screen. It contain one character and its attributes. */
-typedef struct {
-	wchar_t character;  /**< Character itself */
-	attrs_t attrs;      /**< Character attributes */
-} keyfield_t;
-
-/** Structure for buffering state of one virtual console.
- */
-typedef struct {
-	keyfield_t *buffer;      /**< Screen content - characters and
-	                              their attributes (used as a circular buffer) */
-	ipcarg_t size_x;         /**< Number of columns  */
-	ipcarg_t size_y;         /**< Number of rows */
-	
-	/** Coordinates of last printed character for determining cursor position */
-	ipcarg_t position_x;
-	ipcarg_t position_y;
-	
-	attrs_t attrs;           /**< Current attributes. */
-	size_t top_line;         /**< Points to buffer[][] line that will
-	                              be printed at screen as the first line */
-	bool is_cursor_visible;  /**< Cursor state - default is visible */
-} screenbuffer_t;
-
-/** Returns keyfield for position on screen
- *
- * Screenbuffer->buffer is cyclic buffer so we
- * must couted in index of the topmost line.
- *
- * @param scr Screenbuffer
- * @param x   Position on screen
- * @param y   Position on screen
- *
- * @return Keyfield structure with character and its attributes on x, y
- *
- */
-static inline keyfield_t *get_field_at(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y)
-{
-	return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x;
-}
-
-/** Compares two sets of attributes.
- *
- * @param s1 First style
- * @param s2 Second style
- *
- * @return Nonzero on equality
- *
- */
-static inline int attrs_same(attrs_t a1, attrs_t a2)
-{
-	if (a1.t != a2.t)
-		return 0;
-	
-	switch (a1.t) {
-	case at_style:
-		return (a1.a.s.style == a2.a.s.style);
-	case at_idx:
-		return (a1.a.i.fg_color == a2.a.i.fg_color)
-		    && (a1.a.i.bg_color == a2.a.i.bg_color)
-		    && (a1.a.i.flags == a2.a.i.flags);
-	case at_rgb:
-		return (a1.a.r.fg_color == a2.a.r.fg_color)
-		    && (a1.a.r.bg_color == a2.a.r.bg_color);
-	}
-	
-	return 0;
-}
-
-extern void screenbuffer_putchar(screenbuffer_t *, wchar_t);
-extern screenbuffer_t *screenbuffer_init(screenbuffer_t *, ipcarg_t, ipcarg_t);
-
-extern void screenbuffer_clear(screenbuffer_t *);
-extern void screenbuffer_clear_line(screenbuffer_t *, ipcarg_t);
-extern void screenbuffer_copy_buffer(screenbuffer_t *, keyfield_t *);
-extern void screenbuffer_goto(screenbuffer_t *, ipcarg_t, ipcarg_t);
-extern void screenbuffer_set_style(screenbuffer_t *, uint8_t);
-extern void screenbuffer_set_color(screenbuffer_t *, uint8_t, uint8_t, uint8_t);
-extern void screenbuffer_set_rgb_color(screenbuffer_t *, uint32_t, uint32_t);
-
-#endif
-
-/** @}
- */
Index: uspace/srv/hid/fb/ega.c
===================================================================
--- uspace/srv/hid/fb/ega.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/srv/hid/fb/ega.c	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -52,8 +52,8 @@
 #include <io/style.h>
 #include <io/color.h>
+#include <io/screenbuffer.h>
 #include <sys/types.h>
 
 #include "ega.h"
-#include "../console/screenbuffer.h"
 #include "main.h"
 
@@ -260,5 +260,5 @@
 	size_t intersize = 0;
 	keyfield_t *interbuf = NULL;
-
+	
 	if (client_connected) {
 		ipc_answer_0(iid, ELIMIT);
Index: uspace/srv/hid/fb/fb.c
===================================================================
--- uspace/srv/hid/fb/fb.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/srv/hid/fb/fb.c	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -59,9 +59,9 @@
 #include <stdio.h>
 #include <byteorder.h>
+#include <io/screenbuffer.h>
 
 #include "font-8x16.h"
 #include "fb.h"
 #include "main.h"
-#include "../console/screenbuffer.h"
 #include "ppm.h"
 
Index: uspace/srv/hid/fb/serial_console.c
===================================================================
--- uspace/srv/hid/fb/serial_console.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/srv/hid/fb/serial_console.c	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -31,7 +31,7 @@
 /**
  * @defgroup serial Serial console
- * @brief    Serial console services (putc, puts, clear screen, cursor goto,...)
+ * @brief Serial console services (putc, puts, clear screen, cursor goto,...)
  * @{
- */ 
+ */
 
 /** @file
@@ -47,6 +47,6 @@
 #include <io/style.h>
 #include <str.h>
-
-#include "../console/screenbuffer.h"
+#include <io/screenbuffer.h>
+
 #include "main.h"
 #include "serial_console.h"
@@ -54,12 +54,16 @@
 #define MAX_CONTROL 20
 
-static void serial_sgr(const unsigned int mode);
-void serial_putchar(wchar_t ch);
-
-static unsigned int scr_width;
-static unsigned int scr_height;
-static bool color = true;	/** True if producing color output. */
-static bool utf8 = false;	/** True if producing UTF8 output. */
+static ipcarg_t scr_width;
+static ipcarg_t scr_height;
+static bool color = true;    /**< True if producing color output. */
+static bool utf8 = false;    /**< True if producing UTF8 output. */
 static putc_function_t putc_function;
+
+static ipcarg_t lastcol = 0;
+static ipcarg_t lastrow = 0;
+static attrs_t cur_attr = {
+	.t = at_style,
+	.a.s.style = STYLE_NORMAL
+};
 
 /* Allow only 1 connection */
@@ -67,35 +71,35 @@
 
 enum sgr_color_index {
-	CI_BLACK	= 0,
-	CI_RED		= 1,
-	CI_GREEN	= 2,
-	CI_BROWN	= 3,
-	CI_BLUE		= 4,
-	CI_MAGENTA	= 5,
-	CI_CYAN		= 6,
-	CI_WHITE	= 7,
+	CI_BLACK   = 0,
+	CI_RED     = 1,
+	CI_GREEN   = 2,
+	CI_BROWN   = 3,
+	CI_BLUE    = 4,
+	CI_MAGENTA = 5,
+	CI_CYAN    = 6,
+	CI_WHITE   = 7
 };
 
 enum sgr_command {
-	SGR_RESET	= 0,
-	SGR_BOLD	= 1,
-	SGR_BLINK	= 5,
-	SGR_REVERSE	= 7,
-	SGR_NORMAL_INT	= 22,
-	SGR_BLINK_OFF	= 25,
+	SGR_RESET       = 0,
+	SGR_BOLD        = 1,
+	SGR_BLINK       = 5,
+	SGR_REVERSE     = 7,
+	SGR_NORMAL_INT  = 22,
+	SGR_BLINK_OFF   = 25,
 	SGR_REVERSE_OFF = 27,
-	SGR_FGCOLOR	= 30,
-	SGR_BGCOLOR	= 40
+	SGR_FGCOLOR     = 30,
+	SGR_BGCOLOR     = 40
 };
 
 static int color_map[] = {
-	[COLOR_BLACK]	= CI_BLACK,
-	[COLOR_BLUE]	= CI_RED,
-	[COLOR_GREEN]	= CI_GREEN,
-	[COLOR_CYAN]	= CI_CYAN,
-	[COLOR_RED]	= CI_RED,
+	[COLOR_BLACK]   = CI_BLACK,
+	[COLOR_BLUE]    = CI_RED,
+	[COLOR_GREEN]   = CI_GREEN,
+	[COLOR_CYAN]    = CI_CYAN,
+	[COLOR_RED]     = CI_RED,
 	[COLOR_MAGENTA] = CI_MAGENTA,
-	[COLOR_YELLOW]	= CI_BROWN,
-	[COLOR_WHITE]	= CI_WHITE
+	[COLOR_YELLOW]  = CI_BROWN,
+	[COLOR_WHITE]   = CI_WHITE
 };
 
@@ -106,29 +110,26 @@
 }
 
-void serial_putchar(wchar_t ch)
-{
-	char buf[STR_BOUNDS(1)];
-	size_t offs;
-	size_t i;
-
+static void serial_putchar(wchar_t ch)
+{
 	if (utf8 != true) {
 		if (ch >= 0 && ch < 128)
 			(*putc_function)((uint8_t) ch);
-		else 
+		else
 			(*putc_function)('?');
+		
 		return;
 	}
-
-	offs = 0;
+	
+	size_t offs = 0;
+	char buf[STR_BOUNDS(1)];
 	if (chr_encode(ch, buf, &offs, STR_BOUNDS(1)) == EOK) {
+		size_t i;
 		for (i = 0; i < offs; i++)
 			(*putc_function)(buf[i]);
-	} else {
+	} else
 		(*putc_function)('?');
-	}
-
-}
-
-void serial_goto(const unsigned int col, const unsigned int row)
+}
+
+void serial_goto(const ipcarg_t col, const ipcarg_t row)
 {
 	if ((col > scr_width) || (row > scr_height))
@@ -138,4 +139,94 @@
 	snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1);
 	serial_puts(control);
+}
+
+/** ECMA-48 Set Graphics Rendition. */
+static void serial_sgr(const unsigned int mode)
+{
+	char control[MAX_CONTROL];
+	snprintf(control, MAX_CONTROL, "\033[%um", mode);
+	serial_puts(control);
+}
+
+static void serial_set_style(console_style_t style)
+{
+	switch (style) {
+	case STYLE_EMPHASIS:
+		if (color) {
+			serial_sgr(SGR_RESET);
+			serial_sgr(SGR_FGCOLOR + CI_RED);
+			serial_sgr(SGR_BGCOLOR + CI_WHITE);
+		}
+		serial_sgr(SGR_BOLD);
+		break;
+	case STYLE_INVERTED:
+		if (color) {
+			serial_sgr(SGR_RESET);
+			serial_sgr(SGR_FGCOLOR + CI_WHITE);
+			serial_sgr(SGR_BGCOLOR + CI_BLACK);
+			serial_sgr(SGR_NORMAL_INT);
+		} else
+			serial_sgr(SGR_REVERSE);
+		break;
+	case STYLE_SELECTED:
+		if (color) {
+			serial_sgr(SGR_RESET);
+			serial_sgr(SGR_FGCOLOR + CI_WHITE);
+			serial_sgr(SGR_BGCOLOR + CI_RED);
+			serial_sgr(SGR_NORMAL_INT);
+		} else {
+			serial_sgr(SGR_BOLD);
+			serial_sgr(SGR_REVERSE);
+		}
+		break;
+	default:
+		if (color) {
+			serial_sgr(SGR_RESET);
+			serial_sgr(SGR_FGCOLOR + CI_BLACK);
+			serial_sgr(SGR_BGCOLOR + CI_WHITE);
+		}
+		serial_sgr(SGR_NORMAL_INT);
+	}
+}
+
+static void serial_set_idx(uint8_t fgcolor, uint8_t bgcolor,
+    uint8_t flags)
+{
+	if (color) {
+		serial_sgr(SGR_RESET);
+		serial_sgr(SGR_FGCOLOR + color_map[fgcolor]);
+		serial_sgr(SGR_BGCOLOR + color_map[bgcolor]);
+	} else {
+		if (fgcolor < bgcolor)
+			serial_sgr(SGR_RESET);
+		else
+			serial_sgr(SGR_REVERSE);
+	}	
+}
+
+static void serial_set_rgb(uint32_t fgcolor, uint32_t bgcolor)
+{
+	serial_sgr(SGR_RESET);
+	
+	if (fgcolor < bgcolor)
+		serial_sgr(SGR_REVERSE_OFF);
+	else
+		serial_sgr(SGR_REVERSE);
+}
+
+static void serial_set_attrs(attrs_t *a)
+{
+	switch (a->t) {
+	case at_style:
+		serial_set_style(a->a.s.style);
+		break;
+	case at_rgb:
+		serial_set_rgb(a->a.r.fg_color, a->a.r.bg_color);
+		break;
+	case at_idx:
+		serial_set_idx(a->a.i.fg_color, a->a.i.bg_color,
+		    a->a.i.flags);
+		break;
+	}
 }
 
@@ -148,9 +239,11 @@
 		serial_sgr(SGR_BGCOLOR + CI_WHITE);
 	}
-
+	
 	serial_puts("\033[2J");
-}
-
-void serial_scroll(int i)
+	
+	serial_set_attrs(&cur_attr);
+}
+
+void serial_scroll(ssize_t i)
 {
 	if (i > 0) {
@@ -165,14 +258,6 @@
 }
 
-/** ECMA-48 Set Graphics Rendition. */
-static void serial_sgr(const unsigned int mode)
-{
-	char control[MAX_CONTROL];
-	snprintf(control, MAX_CONTROL, "\033[%um", mode);
-	serial_puts(control);
-}
-
 /** Set scrolling region. */
-void serial_set_scroll_region(unsigned last_row)
+void serial_set_scroll_region(ipcarg_t last_row)
 {
 	char control[MAX_CONTROL];
@@ -191,5 +276,5 @@
 }
 
-void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h)
+void serial_console_init(putc_function_t putc_fn, ipcarg_t w, ipcarg_t h)
 {
 	scr_width = w;
@@ -198,63 +283,5 @@
 }
 
-static void serial_set_style(int style)
-{
-	if (style == STYLE_EMPHASIS) {
-		if (color) {
-			serial_sgr(SGR_RESET);
-			serial_sgr(SGR_FGCOLOR + CI_RED);
-			serial_sgr(SGR_BGCOLOR + CI_WHITE);
-		}
-		serial_sgr(SGR_BOLD);
-	} else {
-		if (color) {
-			serial_sgr(SGR_RESET);
-			serial_sgr(SGR_FGCOLOR + CI_BLACK);
-			serial_sgr(SGR_BGCOLOR + CI_WHITE);
-		}
-		serial_sgr(SGR_NORMAL_INT);
-	}
-}
-
-static void serial_set_idx(unsigned fgcolor, unsigned bgcolor,
-    unsigned flags)
-{
-	if (color) {
-		serial_sgr(SGR_RESET);
-		serial_sgr(SGR_FGCOLOR + color_map[fgcolor]);
-		serial_sgr(SGR_BGCOLOR + color_map[bgcolor]);
-	} else {
-		if (fgcolor < bgcolor)
-			serial_sgr(SGR_RESET);
-		else
-			serial_sgr(SGR_REVERSE);
-	}	
-}
-
-static void serial_set_rgb(uint32_t fgcolor, uint32_t bgcolor)
-{
-	if (fgcolor < bgcolor)
-		serial_sgr(SGR_REVERSE_OFF);
-	else
-		serial_sgr(SGR_REVERSE);
-}
-
-static void serial_set_attrs(const attrs_t *a)
-{
-	switch (a->t) {
-	case at_style:
-		serial_set_style(a->a.s.style);
-		break;
-	case at_rgb:
-		serial_set_rgb(a->a.r.fg_color, a->a.r.bg_color);
-		break;
-	case at_idx:
-		serial_set_idx(a->a.i.fg_color,
-		    a->a.i.bg_color, a->a.i.flags);
-		break;
-	default:
-		break;
-	}
-}
+
 
 /** Draw text data to viewport.
@@ -262,38 +289,35 @@
  * @param vport Viewport id
  * @param data  Text data.
- * @param x	Leftmost column of the area.
- * @param y	Topmost row of the area.
- * @param w	Number of rows.
- * @param h	Number of columns.
- */
-static void draw_text_data(keyfield_t *data, unsigned int x,
-    unsigned int y, unsigned int w, unsigned int h)
-{
-	unsigned int i, j;
-	keyfield_t *field;
-	attrs_t *a0, *a1;
-
+ * @param x     Leftmost column of the area.
+ * @param y     Topmost row of the area.
+ * @param w     Number of rows.
+ * @param h     Number of columns.
+ *
+ */
+static void draw_text_data(keyfield_t *data, ipcarg_t x, ipcarg_t y,
+    ipcarg_t w, ipcarg_t h)
+{
 	serial_goto(x, y);
-	a0 = &data[0].attrs;
-	serial_set_attrs(a0);
-
+	ipcarg_t i;
+	ipcarg_t j;
+	
+	attrs_t *a0 = &data[0].attrs;
+	
 	for (j = 0; j < h; j++) {
-		if (j > 0 && w != scr_width)
+		if ((j > 0) && (w != scr_width))
 			serial_goto(x, j);
-
+		
 		for (i = 0; i < w; i++) {
-			field = &data[j * w + i];
-
-			a1 = &field->attrs;
-			if (!attrs_same(*a0, *a1))
+			attrs_t *a1 = &data[j * w + i].attrs;
+			
+			if (!attrs_same(*a0, *a1)) {
 				serial_set_attrs(a1);
-			serial_putchar(field->character);
-			a0 = a1;
+				a0 = a1;
+			}
+			
+			serial_putchar(data[j * w + i].character);
 		}
 	}
 }
-
-unsigned int lastcol = 0;
-unsigned int lastrow = 0;
 
 /**
@@ -302,18 +326,6 @@
 void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall)
 {
-	int retval;
-	ipc_callid_t callid;
-	ipc_call_t call;
 	keyfield_t *interbuf = NULL;
 	size_t intersize = 0;
-
-	wchar_t c;
-	unsigned int col;
-	unsigned int row;
-	unsigned int w;
-	unsigned int h;
-	int i;
-
-	attrs_t cur_attr;
 	
 	if (client_connected) {
@@ -324,7 +336,4 @@
 	client_connected = 1;
 	ipc_answer_0(iid, EOK);
-
-	cur_attr.t = at_style;
-	cur_attr.a.s.style = STYLE_NORMAL;
 	
 	/* Clear the terminal, set scrolling region
@@ -335,9 +344,23 @@
 	
 	while (true) {
-		callid = async_get_call(&call);
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		wchar_t c;
+		ipcarg_t col;
+		ipcarg_t row;
+		ipcarg_t w;
+		ipcarg_t h;
+		attrs_t attr;
+		ssize_t rows;
+		
+		int retval;
+		
 		switch (IPC_GET_METHOD(call)) {
 		case IPC_M_PHONE_HUNGUP:
 			client_connected = 0;
 			ipc_answer_0(callid, EOK);
+			
+			/* Exit thread */
 			return;
 		case IPC_M_SHARE_OUT:
@@ -350,4 +373,5 @@
 				continue;
 			}
+			
 			retval = EINVAL;
 			break;
@@ -357,12 +381,15 @@
 			w = IPC_GET_ARG3(call);
 			h = IPC_GET_ARG4(call);
+			
 			if (!interbuf) {
 				retval = EINVAL;
 				break;
 			}
+			
 			if ((col + w > scr_width) || (row + h > scr_height)) {
 				retval = EINVAL;
 				break;
 			}
+			
 			draw_text_data(interbuf, col, row, w, h);
 			lastcol = col + w;
@@ -374,6 +401,8 @@
 			col = IPC_GET_ARG2(call);
 			row = IPC_GET_ARG3(call);
+			
 			if ((lastcol != col) || (lastrow != row))
 				serial_goto(col, row);
+			
 			lastcol = col + 1;
 			lastrow = row;
@@ -401,35 +430,40 @@
 			break;
 		case FB_SET_STYLE:
-			cur_attr.t = at_style;
-			cur_attr.a.s.style = IPC_GET_ARG1(call);
-			cur_attr.a.i.bg_color = IPC_GET_ARG2(call);
+			attr.t = at_style;
+			attr.a.s.style = IPC_GET_ARG1(call);
 			serial_set_attrs(&cur_attr);
-
 			retval = 0;
 			break;
 		case FB_SET_COLOR:
-			cur_attr.t = at_idx;
-			cur_attr.a.i.fg_color = IPC_GET_ARG1(call);
-			cur_attr.a.i.bg_color = IPC_GET_ARG2(call);
-			cur_attr.a.i.flags = IPC_GET_ARG3(call);
+			attr.t = at_idx;
+			attr.a.i.fg_color = IPC_GET_ARG1(call);
+			attr.a.i.bg_color = IPC_GET_ARG2(call);
+			attr.a.i.flags = IPC_GET_ARG3(call);
 			serial_set_attrs(&cur_attr);
-
 			retval = 0;
 			break;
 		case FB_SET_RGB_COLOR:
-			cur_attr.t = at_rgb;
-			cur_attr.a.i.fg_color = IPC_GET_ARG1(call);
-			cur_attr.a.i.bg_color = IPC_GET_ARG2(call);
+			attr.t = at_rgb;
+			attr.a.r.fg_color = IPC_GET_ARG1(call);
+			attr.a.r.bg_color = IPC_GET_ARG2(call);
 			serial_set_attrs(&cur_attr);
-
 			retval = 0;
 			break;
 		case FB_SCROLL:
-			i = IPC_GET_ARG1(call);
-			if ((i > (int) scr_height) || (i < -((int) scr_height))) {
-				retval = EINVAL;
-				break;
+			rows = IPC_GET_ARG1(call);
+			
+			if (rows >= 0) {
+				if ((ipcarg_t) rows > scr_height) {
+					retval = EINVAL;
+					break;
+				}
+			} else {
+				if ((ipcarg_t) (-rows) > scr_height) {
+					retval = EINVAL;
+					break;
+				}
 			}
-			serial_scroll(i);
+			
+			serial_scroll(rows);
 			serial_goto(lastcol, lastrow);
 			retval = 0;
@@ -451,5 +485,4 @@
 		case FB_SCREEN_RECLAIM:
 			serial_clrscr();
-			serial_set_attrs(&cur_attr);
 			retval = 0;
 			break;
Index: uspace/srv/hid/fb/serial_console.h
===================================================================
--- uspace/srv/hid/fb/serial_console.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
+++ uspace/srv/hid/fb/serial_console.h	(revision 369a5f8a1a86047b7259dfe2c89e8b6f05751cbb)
@@ -29,7 +29,7 @@
 /**
  * @defgroup serial Serial console
- * @brief    Serial console services (putc, puts, clear screen, cursor goto,...)
+ * @brief Serial console services (putc, puts, clear screen, cursor goto,...)
  * @{
- */ 
+ */
 
 /** @file
@@ -43,14 +43,13 @@
 typedef void (*putc_function_t)(char);
 
-void serial_puts(const char *str);
-void serial_goto(const unsigned int col, const unsigned int row);
-void serial_clrscr(void);
-void serial_scroll(int i);
-void serial_cursor_disable(void);
-void serial_cursor_enable(void);
-void serial_set_scroll_region(unsigned height);
-void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h);
-void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall);
-
+extern void serial_puts(const char *);
+extern void serial_goto(const ipcarg_t, const ipcarg_t);
+extern void serial_clrscr(void);
+extern void serial_scroll(ssize_t);
+extern void serial_cursor_disable(void);
+extern void serial_cursor_enable(void);
+extern void serial_set_scroll_region(ipcarg_t);
+extern void serial_console_init(putc_function_t, ipcarg_t, ipcarg_t);
+extern void serial_client_connection(ipc_callid_t, ipc_call_t *);
 
 #endif
