3700edb55887ff1991bb686aac34bd0fdce82c04
[coreboot.git] / payloads / libpayload / curses / PDCurses-3.4 / x11 / pdcdisp.c
1 /* Public Domain Curses */
2
3 #include "pdcx11.h"
4
5 RCSID("$Id: pdcdisp.c,v 1.46 2008/07/14 04:24:52 wmcbrine Exp $")
6
7 #include <string.h>
8
9 #ifdef CHTYPE_LONG
10
11 # define A(x) ((chtype)x | A_ALTCHARSET)
12
13 chtype acs_map[128] =
14 {
15     A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9), A(10),
16     A(11), A(12), A(13), A(14), A(15), A(16), A(17), A(18), A(19),
17     A(20), A(21), A(22), A(23), A(24), A(25), A(26), A(27), A(28),
18     A(29), A(30), A(31), ' ', '!', '"', '#', '$', '%', '&', '\'', '(',
19     ')', '*',
20
21 # ifdef PDC_WIDE
22     0x2192, 0x2190, 0x2191, 0x2193,
23 # else
24     '>', '<', '^', 'v',
25 # endif
26
27     '/',
28
29 # ifdef PDC_WIDE
30     0x2588,
31 # else
32     A(0),
33 # endif
34
35     '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
36     '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
37     'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
38     'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
39
40 # ifdef PDC_WIDE
41     0x2666, 0x2592,
42 # else
43     A(1), A(2),
44 # endif
45
46     'b', 'c', 'd', 'e',
47
48 # ifdef PDC_WIDE
49     0x00b0, 0x00b1, 0x2591, 0x00a4, 0x2518, 0x2510, 0x250c, 0x2514,
50     0x253c, 0x23ba, 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524,
51     0x2534, 0x252c, 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3,
52     0x00b7,
53 # else
54     A(7), A(8), '#', 0xa4, A(11), A(12), A(13), A(14), A(15), A(16), 
55     A(17), A(18), A(19), A(20), A(21), A(22), A(23), A(24), A(25), 
56     A(26), A(27), A(28), A(29), A(30), 0xb7,
57 # endif
58
59     A(127)
60 };
61
62 # undef A
63
64 #endif
65
66 int PDC_display_cursor(int oldrow, int oldcol, int newrow, int newcol,
67                        int visibility)
68 {
69     char buf[30];
70     int idx, pos;
71
72     PDC_LOG(("%s:PDC_display_cursor() - called: NEW row %d col %d, vis %d\n",
73              XCLOGMSG, newrow, newcol, visibility));
74
75     if (visibility == -1)
76     {
77         /* Only send the CURSES_DISPLAY_CURSOR message, no data */
78
79         idx = CURSES_DISPLAY_CURSOR;
80         memcpy(buf, &idx, sizeof(int));
81         idx = sizeof(int);
82     }
83     else
84     {
85         idx = CURSES_CURSOR;
86         memcpy(buf, &idx, sizeof(int));
87
88         idx = sizeof(int);
89         pos = oldrow + (oldcol << 8);
90         memcpy(buf + idx, &pos, sizeof(int));
91
92         idx += sizeof(int);
93         pos = newrow + (newcol << 8);
94         memcpy(buf + idx, &pos, sizeof(int));
95
96         idx += sizeof(int);
97     }
98
99     if (XC_write_socket(xc_display_sock, buf, idx) < 0)
100         XCursesExitCursesProcess(1, "exiting from PDC_display_cursor");
101
102     return OK;
103 }
104
105 /* position hardware cursor at (y, x) */
106
107 void PDC_gotoyx(int row, int col)
108 {
109     PDC_LOG(("PDC_gotoyx() - called: row %d col %d\n", row, col));
110
111     PDC_display_cursor(SP->cursrow, SP->curscol, row, col, SP->visibility);
112 }
113
114 /* update the given physical line to look like the corresponding line in
115    curscr */
116
117 void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
118 {
119     PDC_LOG(("PDC_transform_line() - called: line %d\n", lineno));
120
121     XC_get_line_lock(lineno);
122
123     memcpy(Xcurscr + XCURSCR_Y_OFF(lineno) + (x * sizeof(chtype)), srcp,
124            len * sizeof(chtype));
125
126     *(Xcurscr + XCURSCR_START_OFF + lineno) = x;
127     *(Xcurscr + XCURSCR_LENGTH_OFF + lineno) = len;
128
129     XC_release_line_lock(lineno);
130
131     XCursesInstructAndWait(CURSES_REFRESH);
132 }