Index: uspace/srv/fb/fb.c
===================================================================
--- uspace/srv/fb/fb.c	(revision ab25d30856f5819a533ea101a69d3b2adf2e1fd2)
+++ uspace/srv/fb/fb.c	(revision 67c6c65134fea45ac6ebc039a0fa8721f3a003b6)
@@ -140,5 +140,7 @@
 static bool client_connected = false;  /**< Allow only 1 connection */
 
-static void draw_glyph(viewport_t *vport, bool cursor, unsigned int col,
+static void draw_glyph(unsigned int x, unsigned int y, bool cursor,
+    uint8_t *glyphs, uint8_t glyph);
+static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
     unsigned int row);
 
@@ -270,5 +272,5 @@
 	for (row = 0; row < vport->rows; row++) {
 		for (col = 0; col < vport->cols; col++) {
-			draw_glyph(vport, false, col, row);
+			draw_vp_glyph(vport, false, col, row);
 		}
 	}
@@ -310,4 +312,31 @@
 {
 	unsigned int row, col;
+	unsigned int x, y;
+	uint8_t glyph;
+
+	/*
+	 * Redraw.
+	 */
+
+	y = vport->y;
+	for (row = 0; row < vport->rows; row++) {
+		x = vport->x;
+		for (col = 0; col < vport->cols; col++) {
+			if ((row + lines >= 0) && (row + lines < vport->rows)) {
+				glyph = vport->backbuf[BB_POS(vport, col, row + lines)];
+
+				if (vport->backbuf[BB_POS(vport, col, row)] == glyph) {
+					x += FONT_WIDTH;
+					continue;
+				}
+			} else {
+				glyph = 0;
+			}
+
+			draw_glyph(x, y, false, vport->glyphs, glyph);
+			x += FONT_WIDTH;
+		}
+		y += FONT_SCANLINES;
+	}
 
 	/*
@@ -316,22 +345,12 @@
 
 	if (lines > 0) {
-		memcpy(vport->backbuf, vport->backbuf + vport->cols * lines,
+		memmove(vport->backbuf, vport->backbuf + vport->cols * lines,
 		    vport->cols * (vport->rows - lines));
 		memset(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)],
 		    0, vport->cols * lines);
 	} else {
-		memcpy(vport->backbuf - vport->cols * lines, vport->backbuf,
+		memmove(vport->backbuf - vport->cols * lines, vport->backbuf,
 		    vport->cols * (vport->rows + lines));
 		memset(vport->backbuf, 0, - vport->cols * lines);
-	}
-
-	/*
-	 * Redraw.
-	 */
-
-	for (row = 0; row < vport->rows; row++) {
-		for (col = 0; col < vport->cols; col++) {
-			draw_glyph(vport, false, col, row);
-		}
 	}
 }
@@ -516,5 +535,24 @@
 
 
-/** Draw glyph at given position relative to viewport 
+/** Draw a glyph.
+ *
+ * @param x	 x coordinate of top-left corner on screen.
+ * @param y	 y coordinate of top-left corner on screen.
+ * @param cursor Draw glyph with cursor
+ * @param glyphs Pointer to font bitmap.
+ * @param glyph  Code of the glyph to draw.
+ *
+ */
+static void draw_glyph(unsigned int x, unsigned int y, bool cursor,
+    uint8_t *glyphs, uint8_t glyph)
+{
+	unsigned int yd;
+	
+	for (yd = 0; yd < FONT_SCANLINES; yd++)
+		memcpy(&screen.fb_addr[FB_POS(x, y + yd)],
+		    &glyphs[GLYPH_POS(glyph, yd, cursor)], screen.glyphscanline);
+}
+
+/** Draw glyph at specified position in viewport. 
  *
  * @param vport  Viewport identification
@@ -524,15 +562,13 @@
  *
  */
-static void draw_glyph(viewport_t *vport, bool cursor, unsigned int col, unsigned int row)
+static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
+    unsigned int row)
 {
 	unsigned int x = vport->x + COL2X(col);
 	unsigned int y = vport->y + ROW2Y(row);
-	unsigned int yd;
-	
-	uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)];
-	
-	for (yd = 0; yd < FONT_SCANLINES; yd++)
-		memcpy(&screen.fb_addr[FB_POS(x, y + yd)],
-		    &vport->glyphs[GLYPH_POS(glyph, yd, cursor)], screen.glyphscanline);
+	uint8_t glyph;
+	
+	glyph = vport->backbuf[BB_POS(vport, col, row)];
+	draw_glyph(x, y, cursor, vport->glyphs, glyph);
 }
 
@@ -544,5 +580,5 @@
 {
 	if ((vport->cursor_active) && (vport->cursor_shown)) {
-		draw_glyph(vport, false, vport->cur_col, vport->cur_row);
+		draw_vp_glyph(vport, false, vport->cur_col, vport->cur_row);
 		vport->cursor_shown = false;
 	}
@@ -557,5 +593,5 @@
 	/* Do not check for cursor_shown */
 	if (vport->cursor_active) {
-		draw_glyph(vport, true, vport->cur_col, vport->cur_row);
+		draw_vp_glyph(vport, true, vport->cur_col, vport->cur_row);
 		vport->cursor_shown = true;
 	}
@@ -591,5 +627,5 @@
 	
 	vport->backbuf[BB_POS(vport, col, row)] = c;
-	draw_glyph(vport, false, col, row);
+	draw_vp_glyph(vport, false, col, row);
 	
 	vport->cur_col = col;
@@ -628,5 +664,5 @@
 		if (glyph != data[i].character) {
 			vport->backbuf[BB_POS(vport, col, row)] = data[i].character;
-			draw_glyph(vport, false, col, row);
+			draw_vp_glyph(vport, false, col, row);
 		}
 	}
