[coreboot] r3499 - in trunk/payloads/libpayload: curses drivers include

svn at coreboot.org svn at coreboot.org
Mon Aug 11 22:34:29 CEST 2008


Author: jcrouse
Date: 2008-08-11 22:34:28 +0200 (Mon, 11 Aug 2008)
New Revision: 3499

Modified:
   trunk/payloads/libpayload/curses/tinycurses.c
   trunk/payloads/libpayload/drivers/serial.c
   trunk/payloads/libpayload/include/libpayload.h
Log:
Add support for line drawing characters and the alternate character set.
This enables using the ACS_ curses macros with libpayload.

The translation from ACS_ macros (or characters with attribute A_ALTCHARSET)
is done using one acs map for the video console, one for serial console
(xterm/vt100/vt220), and one fallback, from which an ASCII substitute is
taken if the device specific map doesn't contain an entry (ie NUL).

Signed-off-by: Ulf Jordan <jordan at chalmers.se>
Acked-by: Jordan Crouse <jordan.crouse at amd.com>



Modified: trunk/payloads/libpayload/curses/tinycurses.c
===================================================================
--- trunk/payloads/libpayload/curses/tinycurses.c	2008-08-11 17:19:10 UTC (rev 3498)
+++ trunk/payloads/libpayload/curses/tinycurses.c	2008-08-11 20:34:28 UTC (rev 3499)
@@ -2,6 +2,7 @@
  * This file is part of the libpayload project.
  *
  * Copyright (C) 2007 Uwe Hermann <uwe at hermann-uwe.de>
+ * Copyright (C) 2008 Ulf Jordan <jordan at chalmers.se>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -88,6 +89,69 @@
 SCREEN *SP;
 chtype acs_map[128];
 
+/* See terminfo(5). */
+chtype fallback_acs_map[128] =
+	{
+	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',
+	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',
+	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',
+	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',
+	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',
+	' ',	' ',	' ',	'>',	'<',	'^',	'v',	' ',
+	'#',	' ',	' ',	' ',	' ',	' ',	' ',	' ',
+	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',
+	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',
+	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',
+	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',
+	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',
+	'+',	':',	' ',	' ',	' ',	' ',	'\\',   '#',
+	'#',	'#',	'+',	'+',	'+',	'+',	'+',	'~',
+	'-',	'-',	'-',	'_',	'+',	'+',	'+',	'+',
+	'|',	'<',	'>',	'*',	'!',	'f',	'o',	' ',
+	};
+
+/* See acsc of vt100. */
+chtype serial_acs_map[128] =
+	{
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	'`',	'a',	0,	0,	0,	0,	'f',	'g',
+	0,	0,	'j',	'k',	'l',	'm',	'n',	'o',
+	'p',	'q',	'r',	's',	't',	'u',	'v',	'w',
+	'x',	'y',	'z',	'{',	'|',	'}',	'~',	0,
+	};
+
+/* See acsc of linux. */
+chtype console_acs_map[128] =
+	{
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	'\020', '\021', '\030', '\031',	0,
+	'\333',	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	'\004',	'\261',	0,	0,	0,	0,	'\370',	'\361',
+	'\260',	'\316',	'\331',	'\277',	'\332',	'\300',	'\305',	'~',
+	'\304',	'\304',	'\304',	'_',	'\303', '\264', '\301',	'\302',
+	'\263',	'\363',	'\362',	'\342',	'\330',	'\234',	'\376',	0,
+	};
+
 // FIXME: Ugly (and insecure!) hack!
 char sprintf_tmp[1024];
 
@@ -213,11 +277,14 @@
 /** Note: Must _not_ be called twice! */
 WINDOW *initscr(void)
 {
-	int x, y;
+	int x, y, i;
 
 	// newterm(name, stdout, stdin);
 	// def_prog_mode();
 
+	for (i = 0; i < 128; i++)
+	  acs_map[i] = (chtype) i | A_ALTCHARSET;
+
 	if (curses_flags & F_ENABLE_SERIAL) {
 		serial_clear();
 	}
@@ -409,12 +476,12 @@
 	// NCURSES_CH_T wch;
 	// SetChar2(wch, ch);
 
-	win->_line[win->_cury].text[win->_curx].chars[0] = ch;
+	win->_line[win->_cury].text[win->_curx].chars[0] =
+		((ch) & (chtype)A_CHARTEXT);
 
-	/* Use the window attributes - perhaps we also pull attributes from
-	   the ch itself, I don't know */
-
 	win->_line[win->_cury].text[win->_curx].attr = WINDOW_ATTRS(win);
+	win->_line[win->_cury].text[win->_curx].attr |=
+		((ch) & (chtype)A_ATTRIBUTES);
 	win->_curx++;	// FIXME
 
 	// if (win && (waddch_nosync(win, wch) != ERR)) {
@@ -595,10 +662,14 @@
 {
 	// FIXME.
 	int serial_is_bold = 0;
+	int serial_is_altcharset = 0;
 
 	int x, y;
+	chtype ch;
+	int need_altcharset;
 
 	serial_end_bold();
+	serial_end_altcharset();
 
 	for (y = 0; y <= win->_maxy; y++) {
 
@@ -614,6 +685,7 @@
 				((int)color_pairs[PAIR_NUMBER(attr)]) << 8;
 
 			if (curses_flags & F_ENABLE_SERIAL) {
+				ch = win->_line[y].text[x].chars[0];
 
 				if (attr & A_BOLD) {
 					if (!serial_is_bold) {
@@ -628,10 +700,28 @@
 					}
 				}
 
-				serial_putchar(win->_line[y].text[x].chars[0]);
+				need_altcharset = 0;
+				if (attr & A_ALTCHARSET) {
+					if (serial_acs_map[ch & 0x7f]) {
+						ch = serial_acs_map[ch & 0x7f];
+						need_altcharset = 1;
+					} else
+						ch = fallback_acs_map[ch & 0x7f];
+				}
+				if (need_altcharset && !serial_is_altcharset) {
+					serial_start_altcharset();
+					serial_is_altcharset = 1;
+				}
+				if (!need_altcharset && serial_is_altcharset) {
+					serial_end_altcharset();
+					serial_is_altcharset = 0;
+				}
+
+				serial_putchar(ch);
 			}
 
 			if (curses_flags & F_ENABLE_CONSOLE) {
+				ch = win->_line[y].text[x].chars[0];
 
 				/* Handle some of the attributes. */
 				if (attr & A_BOLD)
@@ -643,6 +733,12 @@
 					c = (c >> 4) & 0xf00;
 					c |= tmp << 12;
 				}
+				if (attr & A_ALTCHARSET) {
+					if (console_acs_map[ch & 0x7f])
+						ch = console_acs_map[ch & 0x7f];
+					else
+						ch = fallback_acs_map[ch & 0x7f];
+				}
 
 				/*
 				 * FIXME: Somewhere along the line, the
@@ -650,7 +746,7 @@
 				 * For now grab just the 8 bit character,
 				 * but this will break wide characters!
 				 */
-				c |= (chtype) (win->_line[y].text[x].chars[0] & 0xff);
+				c |= (chtype) (ch & 0xff);
 				video_console_putc(win->_begy + y, win->_begx + x, c);
 			}
 		}

Modified: trunk/payloads/libpayload/drivers/serial.c
===================================================================
--- trunk/payloads/libpayload/drivers/serial.c	2008-08-11 17:19:10 UTC (rev 3498)
+++ trunk/payloads/libpayload/drivers/serial.c	2008-08-11 20:34:28 UTC (rev 3499)
@@ -2,6 +2,7 @@
  * This file is part of the libpayload project.
  *
  * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ * Copyright (C) 2008 Ulf Jordan <jordan at chalmers.se>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -105,6 +106,10 @@
 #define VT100_SBOLD       "\e[1m"
 #define VT100_EBOLD       "\e[m"
 #define VT100_CURSOR_ADDR "\e[%d;%dH"
+/* The following smacs/rmacs are actually for xterm; a real vt100 has
+   enacs=\E(B\E)0, smacs=^N, rmacs=^O.  */
+#define VT100_SMACS       "\e(0"
+#define VT100_RMACS       "\e(B"
 
 static void serial_putcmd(char *str)
 {
@@ -127,6 +132,16 @@
 	serial_putcmd(VT100_EBOLD);
 }
 
+void serial_start_altcharset(void)
+{
+	serial_putcmd(VT100_SMACS);
+}
+
+void serial_end_altcharset(void)
+{
+	serial_putcmd(VT100_RMACS);
+}
+
 void serial_set_cursor(int y, int x)
 {
 	char buffer[32];

Modified: trunk/payloads/libpayload/include/libpayload.h
===================================================================
--- trunk/payloads/libpayload/include/libpayload.h	2008-08-11 17:19:10 UTC (rev 3498)
+++ trunk/payloads/libpayload/include/libpayload.h	2008-08-11 20:34:28 UTC (rev 3499)
@@ -105,6 +105,8 @@
 void serial_clear(void);
 void serial_start_bold(void);
 void serial_end_bold(void);
+void serial_start_altcharset(void);
+void serial_end_altcharset(void);
 void serial_set_cursor(int y, int x);
 
 /* drivers/speaker.c */





More information about the coreboot mailing list