drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / payloads / libpayload / curses / PDCurses / x11 / pdcscrn.c
blobb84b1c63c29a48086bed79fce1774070bd35c5d1
1 /* Public Domain Curses */
3 #include "pdcx11.h"
5 RCSID("$Id: pdcscrn.c,v 1.55 2008/07/14 04:24:52 wmcbrine Exp $")
7 /* COLOR_PAIR to attribute encoding table. */
9 short *xc_atrtab = (short *)NULL;
11 /* close the physical screen */
13 void PDC_scr_close(void)
15 PDC_LOG(("PDC_scr_close() - called\n"));
18 void PDC_scr_free(void)
20 XCursesExit();
22 xc_atrtab = (short *)NULL;
25 /* open the physical screen -- allocate SP, miscellaneous intialization */
27 int PDC_scr_open(int argc, char **argv)
29 extern bool sb_started;
31 PDC_LOG(("PDC_scr_open() - called\n"));
33 if ((XCursesInitscr(argc, argv) == ERR) || !SP)
34 return ERR;
36 SP->cursrow = SP->curscol = 0;
37 SP->orig_attr = FALSE;
38 SP->sb_on = sb_started;
39 SP->sb_total_y = 0;
40 SP->sb_viewport_y = 0;
41 SP->sb_cur_y = 0;
42 SP->sb_total_x = 0;
43 SP->sb_viewport_x = 0;
44 SP->sb_cur_x = 0;
46 return OK;
49 /* the core of resize_term() */
51 int PDC_resize_screen(int nlines, int ncols)
53 PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n",
54 nlines, ncols));
56 if (nlines || ncols || !SP->resized)
57 return ERR;
59 shmdt((char *)Xcurscr);
60 XCursesInstructAndWait(CURSES_RESIZE);
62 if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,
63 SP->XcurscrSize + XCURSESSHMMIN, 0700)) < 0)
65 perror("Cannot allocate shared memory for curscr");
66 kill(xc_otherpid, SIGKILL);
67 return ERR;
70 XCursesLINES = SP->lines;
71 XCursesCOLS = SP->cols;
73 PDC_LOG(("%s:shmid_Xcurscr %d shmkey_Xcurscr %d SP->lines %d "
74 "SP->cols %d\n", XCLOGMSG, shmid_Xcurscr,
75 shmkey_Xcurscr, SP->lines, SP->cols));
77 Xcurscr = (unsigned char*)shmat(shmid_Xcurscr, 0, 0);
78 xc_atrtab = (short *)(Xcurscr + XCURSCR_ATRTAB_OFF);
80 SP->resized = FALSE;
82 return OK;
85 void PDC_reset_prog_mode(void)
87 PDC_LOG(("PDC_reset_prog_mode() - called.\n"));
90 void PDC_reset_shell_mode(void)
92 PDC_LOG(("PDC_reset_shell_mode() - called.\n"));
95 void PDC_restore_screen_mode(int i)
99 void PDC_save_screen_mode(int i)
103 void PDC_init_pair(short pair, short fg, short bg)
105 xc_atrtab[pair * 2] = fg;
106 xc_atrtab[pair * 2 + 1] = bg;
109 int PDC_pair_content(short pair, short *fg, short *bg)
111 *fg = xc_atrtab[pair * 2];
112 *bg = xc_atrtab[pair * 2 + 1];
114 return OK;
117 bool PDC_can_change_color(void)
119 return TRUE;
122 int PDC_color_content(short color, short *red, short *green, short *blue)
124 XColor *tmp = (XColor *)(Xcurscr + XCURSCR_XCOLOR_OFF);
126 tmp->pixel = color;
128 XCursesInstructAndWait(CURSES_GET_COLOR);
130 *red = ((double)(tmp->red) * 1000 / 65535) + 0.5;
131 *green = ((double)(tmp->green) * 1000 / 65535) + 0.5;
132 *blue = ((double)(tmp->blue) * 1000 / 65535) + 0.5;
134 return OK;
137 int PDC_init_color(short color, short red, short green, short blue)
139 XColor *tmp = (XColor *)(Xcurscr + XCURSCR_XCOLOR_OFF);
141 tmp->pixel = color;
143 tmp->red = ((double)red * 65535 / 1000) + 0.5;
144 tmp->green = ((double)green * 65535 / 1000) + 0.5;
145 tmp->blue = ((double)blue * 65535 / 1000) + 0.5;
147 XCursesInstructAndWait(CURSES_SET_COLOR);
149 return OK;