Index: uspace/srv/fb/ega.c
===================================================================
--- uspace/srv/fb/ega.c	(revision 5a5abf111dd95f45e19bd46d011a797a476735b5)
+++ uspace/srv/fb/ega.c	(revision 198a9efff7fb5190fcd2f9a787b7239ceba755cb)
@@ -73,6 +73,4 @@
 #define INVERTED_COLOR		ega_inverted_color
 
-#define EGA_STYLE(fg,bg) ((fg) > (bg) ? NORMAL_COLOR : INVERTED_COLOR)
-
 /* Allow only 1 connection */
 static int client_connected = 0;
@@ -83,4 +81,6 @@
 
 static unsigned int style;
+
+static unsigned attr_to_ega_style(const attrs_t *a);
 
 static void clrscr(void)
@@ -157,8 +157,5 @@
 	for (i = 0; i < scr_width * scr_height; i++) {
 		scr_addr[i * 2] = data[i].character;
-		/* FIXME
-		scr_addr[i * 2 + 1] = EGA_STYLE(data[i].style.fg_color,
-		    data[i].style.bg_color);
-		*/
+		scr_addr[i * 2 + 1] = attr_to_ega_style(&data[i].attrs);
 	}
 }
@@ -189,4 +186,48 @@
 }
 
+static int style_to_ega_style(int style)
+{
+	unsigned int ega_style;
+
+	switch (style) {
+	case STYLE_NORMAL:
+		ega_style = INVERTED_COLOR;
+		break;
+	case STYLE_EMPHASIS:
+		ega_style = INVERTED_COLOR | 4;
+		break;
+	default:
+		return INVERTED_COLOR;
+	}
+
+	return ega_style;
+}
+
+static unsigned int color_to_ega_style(int fg_color, int bg_color, int attr)
+{
+	unsigned int style;
+
+	style = (fg_color & 7) | ((bg_color & 7) << 4);
+	if (attr & CATTR_BRIGHT)
+		style = style | 0x08;
+
+	return style;
+}
+
+static unsigned int rgb_to_ega_style(uint32_t fg, uint32_t bg)
+{
+	return (fg > bg) ? NORMAL_COLOR : INVERTED_COLOR;
+}
+
+static unsigned attr_to_ega_style(const attrs_t *a)
+{
+	switch (a->t) {
+	case at_style: return style_to_ega_style(a->a.s.style);
+	case at_rgb: return rgb_to_ega_style(a->a.r.fg_color, a->a.r.bg_color);
+	case at_idx: return color_to_ega_style(a->a.i.fg_color,
+	    a->a.i.bg_color, a->a.i.flags);
+	default: return INVERTED_COLOR;
+	}
+}
 
 static void ega_client_connection(ipc_callid_t iid, ipc_call_t *icall)
@@ -197,5 +238,6 @@
 	char c;
 	unsigned int row, col;
-	int bgcolor,fgcolor;
+	int bg_color, fg_color, attr;
+	uint32_t bg_rgb, fg_rgb;
 	keyfield_t *interbuf = NULL;
 	size_t intersize = 0;
@@ -280,23 +322,18 @@
 			break;
 		case FB_SET_STYLE:
-			retval = 0;
-			switch (IPC_GET_ARG1(call)) {
-			case STYLE_NORMAL: style = INVERTED_COLOR; break;
-			case STYLE_EMPHASIS: style = INVERTED_COLOR | 4; break;
-			default: retval = EINVAL;
-			}
+			style = style_to_ega_style(IPC_GET_ARG1(call));
+			retval = 0;
 			break;
 		case FB_SET_COLOR:
-			fgcolor = IPC_GET_ARG1(call);
-			bgcolor = IPC_GET_ARG2(call);
-			style = (fgcolor & 7) | ((bgcolor & 7) << 4);
-			if (IPC_GET_ARG3(call) & CATTR_BRIGHT)
-				style = style | 0x08;
+			fg_color = IPC_GET_ARG1(call);
+			bg_color = IPC_GET_ARG2(call);
+			attr = IPC_GET_ARG3(call);
+			style = color_to_ega_style(fg_color, bg_color, attr);
 			retval = 0;
 			break;
 		case FB_SET_RGB_COLOR:
-			fgcolor = IPC_GET_ARG1(call);
-			bgcolor = IPC_GET_ARG2(call);
-			style = EGA_STYLE(fgcolor, bgcolor);
+			fg_rgb = IPC_GET_ARG1(call);
+			bg_rgb = IPC_GET_ARG2(call);
+			style = rgb_to_ega_style(fg_rgb, bg_rgb);
 			retval = 0;
 			break;
@@ -336,9 +373,10 @@
 	scr_width = sysinfo_value("fb.width");
 	scr_height = sysinfo_value("fb.height");
-	if(sysinfo_value("fb.blinking"))
-	{
-			ega_normal_color &= 0x77;
-			ega_inverted_color &= 0x77;
-	}
+
+	if(sysinfo_value("fb.blinking")) {
+		ega_normal_color &= 0x77;
+		ega_inverted_color &= 0x77;
+	}
+
 	style = NORMAL_COLOR;
 
