3 * Copyright (C) 2008 Advanced Micro Devices, Inc.
4 * Copyright (C) 2008 Ulf Jordan <jordan@chalmers.se>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <libpayload-config.h>
31 #include <libpayload.h>
33 /* These are thinly veiled vt100 functions used by curses */
35 #define VT100_CLEAR "\e[H\e[J"
36 /* These defines will fail if you use bold and reverse at the same time.
37 * Switching off one of them will switch off both. tinycurses knows about
38 * this and does the right thing.
40 #define VT100_SBOLD "\e[1m"
41 #define VT100_EBOLD "\e[m"
42 #define VT100_SREVERSE "\e[7m"
43 #define VT100_EREVERSE "\e[m"
44 #define VT100_CURSOR_ADDR "\e[%d;%dH"
45 #define VT100_CURSOR_ON "\e[?25l"
46 #define VT100_CURSOR_OFF "\e[?25h"
47 /* The following smacs/rmacs are actually for xterm; a real vt100 has
48 enacs=\E(B\E)0, smacs=^N, rmacs=^O. */
49 #define VT100_SMACS "\e(0"
50 #define VT100_RMACS "\e(B"
51 /* A vt100 doesn't do color, setaf/setab below are from xterm-color. */
52 #define VT100_SET_COLOR "\e[3%d;4%dm"
54 static void serial_putcmd(const char *str
)
57 serial_putchar(*(str
++));
60 void serial_clear(void)
62 serial_putcmd(VT100_CLEAR
);
65 void serial_start_bold(void)
67 serial_putcmd(VT100_SBOLD
);
70 void serial_end_bold(void)
72 serial_putcmd(VT100_EBOLD
);
75 void serial_start_reverse(void)
77 serial_putcmd(VT100_SREVERSE
);
80 void serial_end_reverse(void)
82 serial_putcmd(VT100_EREVERSE
);
85 void serial_start_altcharset(void)
87 serial_putcmd(VT100_SMACS
);
90 void serial_end_altcharset(void)
92 serial_putcmd(VT100_RMACS
);
96 * Set the foreground and background colors on the serial console.
98 * @param fg Foreground color number.
99 * @param bg Background color number.
101 void serial_set_color(short fg
, short bg
)
105 snprintf(buffer
, sizeof(buffer
), VT100_SET_COLOR
, fg
, bg
);
106 serial_putcmd(buffer
);
109 void serial_set_cursor(int y
, int x
)
113 snprintf(buffer
, sizeof(buffer
), VT100_CURSOR_ADDR
, y
+ 1, x
+ 1);
114 serial_putcmd(buffer
);
117 void serial_cursor_enable(int state
)
120 serial_putcmd(VT100_CURSOR_ON
);
122 serial_putcmd(VT100_CURSOR_OFF
);