2 * This file is part of the libpayload project.
4 * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
5 * Copyright (C) 2008 Ulf Jordan <jordan@chalmers.se>
6 * Copyright (C) 2008 coresystems GmbH
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * This is a tiny implementation of the (n)curses library intended to be
34 * used in embedded/firmware/BIOS code where no libc or operating system
35 * environment is available and code size is very important.
38 * - Small object code.
40 * - Doesn't require a libc (no glibc/uclibc/dietlibc/klibc/newlib).
41 * - Works without any other external libraries or header files.
42 * - Works without an underlying operating system.
43 * - Doesn't use files, signals, syscalls, ttys, library calls, etc.
44 * - Doesn't do any dynamic memory allocation (no malloc() and friends).
45 * - All data structures are statically allocated.
46 * - Supports standard VGA console (80x25) and serial port console.
47 * - This includes character output and keyboard input over serial.
48 * - Supports beep() through a minimal PC speaker driver.
51 * - Only implements a small subset of the (n)curses functions.
52 * - Only implements very few sanity checks (for smaller code).
53 * - Thus: Don't do obviously stupid things in your code.
54 * - Doesn't implement the 'form', 'panel', and 'menu' extensions.
55 * - Only implements C bindings (no C++, Ada95, or others).
56 * - Doesn't include wide character support.
61 #undef _XOPEN_SOURCE_EXTENDED
62 #define _XOPEN_SOURCE_EXTENDED 1
66 /* Statically allocate all structures (no malloc())! */
67 static WINDOW window_list[MAX_WINDOWS];
68 static int window_count = 1;
71 static struct ldat ldat_list[MAX_WINDOWS][SCREEN_Y];
72 static int ldat_count = 0;
74 /* One item bigger than SCREEN_X to reserve space for a NUL byte. */
75 static NCURSES_CH_T linebuf_list[SCREEN_Y * MAX_WINDOWS][SCREEN_X + 1];
76 static int linebuf_count = 0;
79 int COLORS; /* Currently unused? */
80 int COLOR_PAIRS = 255;
93 /* See terminfo(5). */
94 chtype fallback_acs_map[128] =
96 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
97 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
98 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
99 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
100 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
101 ' ', ' ', ' ', '>', '<', '^', 'v', ' ',
102 '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
103 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
104 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
105 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
106 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
107 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
108 '+', ':', ' ', ' ', ' ', ' ', '\\', '#',
109 '#', '#', '+', '+', '+', '+', '+', '~',
110 '-', '-', '-', '_', '+', '+', '+', '+',
111 '|', '<', '>', '*', '!', 'f', 'o', ' ',
114 #ifdef CONFIG_SERIAL_CONSOLE
115 #ifdef CONFIG_SERIAL_ACS_FALLBACK
116 chtype serial_acs_map[128];
118 /* See acsc of vt100. */
119 chtype serial_acs_map[128] =
121 0, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 0, 0, 0, 0,
123 0, 0, 0, 0, 0, 0, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 0, 0, 0, 0,
128 0, 0, 0, 0, 0, 0, 0, 0,
129 0, 0, 0, 0, 0, 0, 0, 0,
130 0, 0, 0, 0, 0, 0, 0, 0,
131 0, 0, 0, 0, 0, 0, 0, 0,
132 0, 0, 0, 0, 0, 0, 0, 0,
133 '`', 'a', 0, 0, 0, 0, 'f', 'g',
134 0, 0, 'j', 'k', 'l', 'm', 'n', 'o',
135 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
136 'x', 'y', 'z', '{', '|', '}', '~', 0,
141 #ifdef CONFIG_VIDEO_CONSOLE
142 /* See acsc of linux. */
143 chtype console_acs_map[128] =
145 0, 0, 0, 0, 0, 0, 0, 0,
146 0, 0, 0, 0, 0, 0, 0, 0,
147 0, 0, 0, 0, 0, 0, 0, 0,
148 0, 0, 0, 0, 0, 0, 0, 0,
149 0, 0, 0, 0, 0, 0, 0, 0,
150 0, 0, 0, '\020', '\021', '\030', '\031', 0,
151 '\333', 0, 0, 0, 0, 0, 0, 0,
152 0, 0, 0, 0, 0, 0, 0, 0,
153 0, 0, 0, 0, 0, 0, 0, 0,
154 0, 0, 0, 0, 0, 0, 0, 0,
155 0, 0, 0, 0, 0, 0, 0, 0,
156 0, 0, 0, 0, 0, 0, 0, 0,
157 '\004', '\261', 0, 0, 0, 0, '\370', '\361',
158 '\260', '\316', '\331', '\277', '\332', '\300', '\305', '~',
159 '\304', '\304', '\304', '_', '\303', '\264', '\301', '\302',
160 '\263', '\363', '\362', '\343', '\330', '\234', '\376', 0,
164 // FIXME: Ugly (and insecure!) hack!
165 char sprintf_tmp[1024];
168 int curses_flags = (F_ENABLE_CONSOLE | F_ENABLE_SERIAL);
170 /* Return bit mask for clearing color pair number if given ch has color */
171 #define COLOR_MASK(ch) (~(attr_t)((ch) & A_COLOR ? A_COLOR : 0))
173 /* Compute a rendition of the given char correct for the current context. */
174 static inline NCURSES_CH_T render_char(WINDOW *win, NCURSES_CH_T ch)
180 /* Make render_char() visible while still allowing us to inline it below. */
181 NCURSES_CH_T _nc_render(WINDOW *win, NCURSES_CH_T ch)
183 return render_char(win, ch);
187 * Implementations of most functions marked 'implemented' in include/curses.h:
190 // int baudrate(void) {}
193 /* TODO: Flash the screen if beeping fails? */
194 speaker_tone(1760, 500); /* 1760 == note A6 */
197 // bool can_change_color(void) {}
198 int cbreak(void) { /* TODO */ return 0; }
199 /* D */ int clearok(WINDOW *win, bool flag) { win->_clear = flag; return OK; }
200 // int color_content(short color, short *r, short *g, short *b) {}
203 #ifdef CONFIG_SERIAL_CONSOLE
204 if (curses_flags & F_ENABLE_SERIAL) {
205 serial_cursor_enable(on);
208 #ifdef CONFIG_VIDEO_CONSOLE
209 if (curses_flags & F_ENABLE_CONSOLE) {
210 video_console_cursor_enable(on);
216 // int def_prog_mode(void) {}
217 // int def_shell_mode(void) {}
218 // int delay_output(int) {}
219 // void delscreen(SCREEN *) {}
220 int delwin(WINDOW *win)
222 /* TODO: Don't try to delete stdscr. */
223 /* TODO: Don't delete parent windows before subwindows. */
225 // if (win->_flags & _SUBWIN)
226 // touchwin(win->_parent);
227 // else if (curscr != 0)
230 // return _nc_freewin(win);
233 WINDOW *derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
239 /* Make sure window fits inside the original one. */
240 if (begy < 0 || begx < 0 || orig == 0 || num_lines < 0
244 if (begy + num_lines > orig->_maxy + 1
245 || begx + num_columns > orig->_maxx + 1)
249 num_lines = orig->_maxy + 1 - begy;
251 if (num_columns == 0)
252 num_columns = orig->_maxx + 1 - begx;
254 if (orig->_flags & _ISPAD)
258 //// if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy,
259 //// orig->_begx + begx, flags)) == 0)
264 WINDOW_ATTRS(win) = WINDOW_ATTRS(orig);
265 win->_nc_bkgd = orig->_nc_bkgd;
267 for (i = 0; i < num_lines; i++)
268 win->_line[i].text = &orig->_line[begy++].text[begx];
274 int doupdate(void) { /* TODO */ return(0); }
275 // WINDOW * dupwin (WINDOW *) {}
276 /* D */ int echo(void) { SP->_echo = TRUE; return OK; }
284 // _nc_screen_wrap();
285 // _nc_mvcur_wrap(); /* wrap up cursor addressing */
286 // return reset_shell_mode();
289 // char erasechar (void) {}
290 // void filter (void) {}
291 // int flash(void) {}
292 int flushinp(void) { /* TODO */ return 0; }
293 // WINDOW *getwin (FILE *) {}
294 bool has_colors (void) { return(TRUE); }
295 // bool has_ic (void) {}
296 // bool has_il (void) {}
297 // void idcok (WINDOW *, bool) {}
298 // int idlok (WINDOW *, bool) {}
299 void immedok(WINDOW *win, bool flag) { win->_immed = flag; }
300 /** Note: Must _not_ be called twice! */
301 WINDOW *initscr(void)
305 // newterm(name, stdout, stdin);
308 for (i = 0; i < 128; i++)
309 acs_map[i] = (chtype) i | A_ALTCHARSET;
310 #ifdef CONFIG_SERIAL_CONSOLE
311 if (curses_flags & F_ENABLE_SERIAL) {
315 #ifdef CONFIG_VIDEO_CONSOLE
316 if (curses_flags & F_ENABLE_CONSOLE) {
317 /* Clear the screen and kill the cursor */
319 video_console_clear();
320 video_console_cursor_enable(0);
326 stdscr = newwin(SCREEN_Y, SCREEN_X + 1, 0, 0);
327 // TODO: curscr, newscr?
333 // int intrflush (WINDOW *,bool) {}
334 /* D */ bool isendwin(void) { return ((SP == NULL) ? FALSE : SP->_endwin); }
335 // bool is_linetouched (WINDOW *,int) {}
336 // bool is_wintouched (WINDOW *) {}
337 // NCURSES_CONST char * keyname (int) {}
338 int keypad (WINDOW *win, bool flag) { /* TODO */ return 0; }
339 // char killchar (void) {}
340 /* D */ int leaveok(WINDOW *win, bool flag) { win->_leaveok = flag; return OK; }
341 // char *longname (void) {}
342 // int meta (WINDOW *,bool) {}
343 // int mvcur (int,int,int,int) {}
344 // int mvderwin (WINDOW *, int, int) {}
345 int mvprintw(int y, int x, const char *fmt, ...)
350 if (move(y, x) == ERR)
354 code = vwprintw(stdscr, fmt, argp);
359 // int mvscanw (int,int, NCURSES_CONST char *,...) {}
360 // int mvwin (WINDOW *,int,int) {}
361 int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
366 if (wmove(win, y, x) == ERR)
370 code = vwprintw(win, fmt, argp);
375 // int mvwscanw (WINDOW *,int,int, NCURSES_CONST char *,...) {}
376 // int napms (int) {}
377 // WINDOW *newpad (int,int) {}
378 // SCREEN *newterm (NCURSES_CONST char *,FILE *,FILE *) {}
379 WINDOW *newwin(int num_lines, int num_columns, int begy, int begx)
383 /* Use next statically allocated window. */
384 // TODO: Error handling.
386 WINDOW *win = &window_list[window_count++];
388 // bool is_pad = (flags & _ISPAD);
394 win->_maxy = num_lines - 1;
395 win->_maxx = num_columns - 1;
398 // win->_yoffset = SP->_topstolen;
400 win->_line = ldat_list[ldat_count++];
402 /* FIXME: Is this right? Should the window attributes be normal? */
403 win->_color = PAIR_NUMBER(0);
404 win->_attrs = A_NORMAL;
406 for (i = 0; i < num_lines; i++)
408 (NCURSES_CH_T *)&linebuf_list[linebuf_count++];
412 /* D */ int nl(void) { SP->_nl = TRUE; return OK; }
413 /* D */ int noecho(void) { SP->_echo = FALSE; return OK; }
414 /* D */ int nonl(void) { SP->_nl = FALSE; return OK; }
415 // void noqiflush (void) {}
416 // int noraw (void) {}
417 /* D */ int notimeout (WINDOW *win, bool f) { win->_notimeout = f; return OK; }
418 // int overlay (const WINDOW*,WINDOW *) {}
419 // int overwrite (const WINDOW*,WINDOW *) {}
420 // int pair_content (short,short*,short*) {}
421 // int pechochar (WINDOW *, const chtype) {}
422 // int pnoutrefresh (WINDOW*,int,int,int,int,int,int) {}
423 // int prefresh (WINDOW *,int,int,int,int,int,int) {}
424 int printw(const char *fmt, ...)
430 code = vwprintw(stdscr, fmt, argp);
435 // int putwin (WINDOW *, FILE *) {}
436 // void qiflush (void) {}
438 // int resetty (void) {}
439 // int reset_prog_mode (void) {}
440 // int reset_shell_mode (void) {}
441 // int ripoffline (int, int (*)(WINDOW *, int)) {}
442 // int savetty (void) {}
443 // int scanw (NCURSES_CONST char *,...) {}
444 // int scr_dump (const char *) {}
445 // int scr_init (const char *) {}
446 /* D */ int scrollok(WINDOW *win, bool flag) { win->_scroll = flag; return OK; }
447 // int scr_restore (const char *) {}
448 // int scr_set (const char *) {}
449 // SCREEN *set_term (SCREEN *) {}
450 // int slk_attroff (const chtype) {}
451 // int slk_attron (const chtype) {}
452 // int slk_attrset (const chtype) {}
453 // attr_t slk_attr (void) {}
454 // int slk_attr_set (const attr_t,short,void*) {}
455 // int slk_clear (void) {}
456 // int slk_color (short) {}
457 // int slk_init (int) {}
458 /* D */ char *slk_label(int n)
461 // if (SP == NULL || SP->_slk == NULL || n < 1 || n > SP->_slk->labcnt)
463 return SP->_slk->ent[n - 1].ent_text;
465 // int slk_noutrefresh (void) {}
466 // int slk_refresh (void) {}
467 // int slk_restore (void) {}
468 // int slk_set (int,const char *,int) {}
469 // int slk_touch (void) {}
471 // WINDOW *subpad (WINDOW *, int, int, int, int) {}
472 WINDOW *subwin(WINDOW *w, int l, int c, int y, int x)
474 return derwin(w, l, c, y - w->_begy, x - w->_begx);
476 // int syncok (WINDOW *, bool) {}
477 // chtype termattrs (void) {}
478 // char *termname (void) {}
479 // int typeahead (int) {}
480 int ungetch(int ch) { /* TODO */ return ERR; }
481 // void use_env (bool) {}
482 // int vidattr (chtype) {}
483 // int vidputs (chtype, int (*)(int)) {}
484 int vwprintw(WINDOW *win, const char *fmt, va_list argp)
486 vsprintf((char *)&sprintf_tmp, fmt, argp);
488 /* TODO: Error handling? */
489 return waddstr(win, (char *)&sprintf_tmp);
491 // int vwscanw (WINDOW *, NCURSES_CONST char *,va_list) {}
492 int waddch(WINDOW *win, const chtype ch)
496 // SetChar2(wch, ch);
498 if (win->_line[win->_cury].firstchar == _NOCHANGE ||
499 win->_line[win->_cury].firstchar > win->_curx)
500 win->_line[win->_cury].firstchar = win->_curx;
502 win->_line[win->_cury].text[win->_curx].chars[0] =
503 ((ch) & (chtype)A_CHARTEXT);
505 win->_line[win->_cury].text[win->_curx].attr = WINDOW_ATTRS(win);
506 win->_line[win->_cury].text[win->_curx].attr |=
507 ((ch) & (chtype)A_ATTRIBUTES);
509 if (win->_line[win->_cury].lastchar == _NOCHANGE ||
510 win->_line[win->_cury].lastchar < win->_curx)
511 win->_line[win->_cury].lastchar = win->_curx;
513 win->_curx++; // FIXME
515 // if (win && (waddch_nosync(win, wch) != ERR)) {
516 // _nc_synchook(win);
522 // int waddchnstr (WINDOW *,const chtype *,int) {}
523 int waddnstr(WINDOW *win, const char *astr, int n)
526 const char *str = astr;
534 if (win->_line[win->_cury].firstchar == _NOCHANGE ||
535 win->_line[win->_cury].firstchar > win->_curx)
536 win->_line[win->_cury].firstchar = win->_curx;
538 while ((n-- > 0) && (*str != '\0')) {
539 // while (*str != '\0') {
540 win->_line[win->_cury].text[win->_curx].chars[0] = *str++;
541 win->_line[win->_cury].text[win->_curx].attr = WINDOW_ATTRS(win)
543 win->_curx++; // FIXME
546 // SetChar(ch, UChar(*str++), A_NORMAL);
547 // if (_nc_waddch_nosync(win, ch) == ERR) {
553 if (win->_line[win->_cury].lastchar == _NOCHANGE ||
554 win->_line[win->_cury].lastchar < win->_curx)
555 win->_line[win->_cury].lastchar = win->_curx;
559 int wattr_on(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
562 win->_color = PAIR_NUMBER(at);
563 // toggle_attr_on(WINDOW_ATTRS(win), at);
566 int wattr_off(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
570 // toggle_attr_off(WINDOW_ATTRS(win), at);
573 // int wbkgd (WINDOW *, chtype) {}
574 void wbkgdset(WINDOW *win, chtype ch) { /* TODO */ }
576 int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs,
577 chtype tl, chtype tr, chtype bl, chtype br)
581 for(y = 0; y <= win->_maxy; y++) {
584 mvwaddch(win, y, 0, tl);
586 for(x = 1; x < win->_maxx; x++)
587 mvwaddch(win, y, x, ts);
589 mvwaddch(win, y, win->_maxx, tr);
591 else if (y == win->_maxy) {
592 mvwaddch(win, y, 0, bl);
594 for(x = 1; x < win->_maxx; x++)
595 mvwaddch(win, y, x, bs);
597 mvwaddch(win, y, win->_maxx, br);
600 mvwaddch(win, y, 0, ls);
601 mvwaddch(win, y, win->_maxx, rs);
608 // int wchgat (WINDOW *, int, attr_t, short, const void *) {}
609 /* D */ int wclear(WINDOW *win)
611 if (werase(win) == ERR)
616 // int wclrtobot (WINDOW *) {}
617 int wclrtoeol(WINDOW *win) { /* TODO */ return(*(int *)0); }
618 int wcolor_set(WINDOW *win, short color_pair_number, void *opts)
620 if (!opts && (color_pair_number >= 0)
621 && (color_pair_number < COLOR_PAIRS)) {
622 SET_WINDOW_PAIR(win, color_pair_number);
623 if_EXT_COLORS(win->_color = color_pair_number);
628 // void wcursyncup (WINDOW *) {}
629 // int wdelch (WINDOW *) {}
630 // int wechochar (WINDOW *, const chtype) {}
631 int werase(WINDOW *win)
634 for (y = 0; y <= win->_maxy; y++) {
635 for (x = 0; x <= win->_maxx; x++) {
636 win->_line[y].text[x].chars[0] = ' ';
637 win->_line[y].text[x].attr = WINDOW_ATTRS(win);
639 // Should we check instead?
640 win->_line[y].firstchar = 0;
641 win->_line[y].lastchar = win->_maxx;
645 // int wgetnstr (WINDOW *,char *,int) {}
646 int whline(WINDOW *win, chtype ch, int n)
648 NCURSES_SIZE_T start, end;
649 struct ldat *line = &(win->_line[win->_cury]);
654 if (end > win->_maxx)
657 CHANGED_RANGE(line, start, end);
661 //// SetChar2(wch, ACS_HLINE);
663 //// SetChar2(wch, ch);
665 wch.chars[0] = ((ch) & (chtype)A_CHARTEXT);
666 wch.attr = ((ch) & (chtype)A_ATTRIBUTES);
667 wch = _nc_render(win, wch);
669 while (end >= start) {
670 line->text[end] = wch;
674 //// _nc_synchook(win);
678 /* D */ chtype winch(WINDOW *win)
681 // return (CharOf(win->_line[win->_cury].text[win->_curx]) |
682 // AttrOf(win->_line[win->_cury].text[win->_curx]));
685 // int winchnstr (WINDOW *, chtype *, int) {}
686 // int winnstr (WINDOW *, char *, int) {}
687 // int winsch (WINDOW *, chtype) {}
688 // int winsdelln (WINDOW *,int) {}
689 // int winsnstr (WINDOW *, const char *,int) {}
690 /* D */ int wmove(WINDOW *win, int y, int x)
692 if (!LEGALYX(win, y, x))
694 win->_curx = (NCURSES_SIZE_T) x;
695 win->_cury = (NCURSES_SIZE_T) y;
696 win->_flags &= ~_WRAPPED;
697 win->_flags |= _HASMOVED;
701 #define SWAP_RED_BLUE(c) \
702 (((c) & 0x4400) >> 2) | ((c) & 0xAA00) | (((c) & 0x1100) << 2)
703 int wnoutrefresh(WINDOW *win)
705 #ifdef CONFIG_SERIAL_CONSOLE
707 int serial_is_bold = 0;
708 int serial_is_reverse = 0;
709 int serial_is_altcharset = 0;
710 int serial_cur_pair = 0;
718 #ifdef CONFIG_SERIAL_CONSOLE
720 serial_end_altcharset();
723 for (y = 0; y <= win->_maxy; y++) {
725 if (win->_line[y].firstchar == _NOCHANGE)
728 /* Position the serial cursor */
730 #ifdef CONFIG_SERIAL_CONSOLE
731 if (curses_flags & F_ENABLE_SERIAL)
732 serial_set_cursor(win->_begy + y, win->_begx +
733 win->_line[y].firstchar);
736 for (x = win->_line[y].firstchar; x <= win->_line[y].lastchar; x++) {
737 attr_t attr = win->_line[y].text[x].attr;
740 ((int)color_pairs[PAIR_NUMBER(attr)]) << 8;
742 #ifdef CONFIG_SERIAL_CONSOLE
743 if (curses_flags & F_ENABLE_SERIAL) {
744 ch = win->_line[y].text[x].chars[0];
747 if (!serial_is_bold) {
752 if (serial_is_bold) {
755 /* work around serial.c
758 serial_is_reverse = 0;
763 if (attr & A_REVERSE) {
764 if (!serial_is_reverse) {
765 serial_start_reverse();
766 serial_is_reverse = 1;
769 if (serial_is_reverse) {
770 serial_end_reverse();
771 serial_is_reverse = 0;
772 /* work around serial.c
781 if (attr & A_ALTCHARSET) {
782 if (serial_acs_map[ch & 0x7f]) {
783 ch = serial_acs_map[ch & 0x7f];
786 ch = fallback_acs_map[ch & 0x7f];
788 if (need_altcharset && !serial_is_altcharset) {
789 serial_start_altcharset();
790 serial_is_altcharset = 1;
792 if (!need_altcharset && serial_is_altcharset) {
793 serial_end_altcharset();
794 serial_is_altcharset = 0;
797 if (serial_cur_pair != PAIR_NUMBER(attr)) {
798 pair_content(PAIR_NUMBER(attr),
800 serial_set_color(fg, bg);
801 serial_cur_pair = PAIR_NUMBER(attr);
808 #ifdef CONFIG_VIDEO_CONSOLE
809 c = SWAP_RED_BLUE(c);
811 if (curses_flags & F_ENABLE_CONSOLE) {
812 ch = win->_line[y].text[x].chars[0];
814 /* Handle some of the attributes. */
819 if (attr & A_REVERSE) {
820 unsigned char tmp = (c >> 8) & 0xf;
821 c = (c >> 4) & 0xf00;
824 if (attr & A_ALTCHARSET) {
825 if (console_acs_map[ch & 0x7f])
826 ch = console_acs_map[ch & 0x7f];
828 ch = fallback_acs_map[ch & 0x7f];
832 * FIXME: Somewhere along the line, the
833 * character value is getting sign-extented.
834 * For now grab just the 8 bit character,
835 * but this will break wide characters!
837 c |= (chtype) (ch & 0xff);
838 video_console_putc(win->_begy + y, win->_begx + x, c);
842 win->_line[y].firstchar = _NOCHANGE;
843 win->_line[y].lastchar = _NOCHANGE;
846 #ifdef CONFIG_SERIAL_CONSOLE
847 if (curses_flags & F_ENABLE_SERIAL)
848 serial_set_cursor(win->_begy + win->_cury, win->_begx + win->_curx);
851 #ifdef CONFIG_VIDEO_CONSOLE
852 if (curses_flags & F_ENABLE_CONSOLE)
853 video_console_set_cursor(win->_begx + win->_curx, win->_begy + win->_cury);
858 int wprintw(WINDOW *win, const char *fmt, ...)
864 code = vwprintw(win, fmt, argp);
870 int wredrawln (WINDOW *win, int beg_line, int num_lines)
874 for (i = beg_line; i < beg_line + num_lines; i++) {
875 win->_line[i].firstchar = 0;
876 win->_line[i].lastchar = win->_maxx;
882 int wrefresh(WINDOW *win)
885 return wnoutrefresh(win);
891 curscr->_clear = TRUE;
892 // code = doupdate();
893 } else if ((code = wnoutrefresh(win)) == OK) {
895 newscr->_clear = TRUE;
896 // code = doupdate();
898 * Reset the clearok() flag in case it was set for the special
899 * case in hardscroll.c (if we don't reset it here, we'll get 2
900 * refreshes because the flag is copied from stdscr to newscr).
901 * Resetting the flag shouldn't do any harm, anyway.
908 // int wscanw (WINDOW *, NCURSES_CONST char *,...) {}
909 int wscrl(WINDOW *win, int n)
919 for (y = 0; y <= (win->_maxy - n); y++) {
920 win->_line[y].firstchar = win->_line[y + n].firstchar;
921 win->_line[y].lastchar = win->_line[y + n].lastchar;
922 for (x = 0; x <= win->_maxx; x++) {
923 if ((win->_line[y].text[x].chars[0] != win->_line[y + n].text[x].chars[0]) ||
924 (win->_line[y].text[x].attr != win->_line[y + n].text[x].attr)) {
925 if (win->_line[y].firstchar == _NOCHANGE)
926 win->_line[y].firstchar = x;
928 win->_line[y].lastchar = x;
930 win->_line[y].text[x].chars[0] = win->_line[y + n].text[x].chars[0];
931 win->_line[y].text[x].attr = win->_line[y + n].text[x].attr;
936 for (y = (win->_maxy+1 - n); y <= win->_maxy; y++) {
937 for (x = 0; x <= win->_maxx; x++) {
938 if ((win->_line[y].text[x].chars[0] != ' ') ||
939 (win->_line[y].text[x].attr != A_NORMAL)) {
940 if (win->_line[y].firstchar == _NOCHANGE)
941 win->_line[y].firstchar = x;
943 win->_line[y].lastchar = x;
945 win->_line[y].text[x].chars[0] = ' ';
946 win->_line[y].text[x].attr = A_NORMAL;
951 // _nc_scroll_window(win, n, win->_regtop, win->_regbottom, win->_nc_bkgd);
952 // _nc_synchook(win);
956 int wsetscrreg(WINDOW *win, int top, int bottom)
958 if (top >= 0 && top <= win->_maxy && bottom >= 0 &&
959 bottom <= win->_maxy && bottom > top) {
960 win->_regtop = (NCURSES_SIZE_T) top;
961 win->_regbottom = (NCURSES_SIZE_T) bottom;
966 // void wsyncdown (WINDOW *) {}
967 // void wsyncup (WINDOW *) {}
968 /* D */ void wtimeout(WINDOW *win, int delay) { win->_delay = delay; }
969 /* D */ int wtouchln(WINDOW *win, int y, int n, int changed)
973 // if ((n < 0) || (y < 0) || (y > win->_maxy))
976 for (i = y; i < y + n; i++) {
979 win->_line[i].firstchar = changed ? 0 : _NOCHANGE;
980 win->_line[i].lastchar = changed ? win->_maxx : _NOCHANGE;
984 // int wvline (WINDOW *,chtype,int) {}
985 // int tigetflag (NCURSES_CONST char *) {}
986 // int tigetnum (NCURSES_CONST char *) {}
987 // char *tigetstr (NCURSES_CONST char *) {}
988 // int putp (const char *) {}
989 // #if NCURSES_TPARM_VARARGS
990 // char *tparm (NCURSES_CONST char *, ...) {}
992 // char *tparm (NCURSES_CONST char *, long,long,long,long,long,long,long,long,long) {}
993 // char *tparm_varargs (NCURSES_CONST char *, ...) {}