2 * QEMU graphical console
4 * Copyright (c) 2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 //#define DEBUG_CONSOLE
27 #define DEFAULT_BACKSCROLL 512
28 #define MAX_CONSOLES 12
30 #define QEMU_RGBA(r, g, b, a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
31 #define QEMU_RGB(r, g, b) QEMU_RGBA(r, g, b, 0xff)
33 typedef struct TextAttributes {
43 typedef struct TextCell {
45 TextAttributes t_attrib;
48 #define MAX_ESC_PARAMS 3
56 typedef struct QEMUFIFO {
59 int count, wptr, rptr;
62 int qemu_fifo_write(QEMUFIFO *f, const uint8_t *buf, int len1)
66 l = f->buf_size - f->count;
71 l = f->buf_size - f->wptr;
74 memcpy(f->buf + f->wptr, buf, l);
76 if (f->wptr >= f->buf_size)
85 int qemu_fifo_read(QEMUFIFO *f, uint8_t *buf, int len1)
93 l = f->buf_size - f->rptr;
96 memcpy(buf, f->buf + f->rptr, l);
98 if (f->rptr >= f->buf_size)
110 TEXT_CONSOLE_FIXED_SIZE
113 /* ??? This is mis-named.
114 It is used for both text and graphical consoles. */
116 console_type_t console_type;
118 /* Graphic console state. */
119 vga_hw_update_ptr hw_update;
120 vga_hw_invalidate_ptr hw_invalidate;
121 vga_hw_screen_dump_ptr hw_screen_dump;
124 int g_width, g_height;
128 int backscroll_height;
130 int x_saved, y_saved;
133 TextAttributes t_attrib_default; /* default text attributes */
134 TextAttributes t_attrib; /* currently active text attributes */
138 int esc_params[MAX_ESC_PARAMS];
141 CharDriverState *chr;
142 /* fifo for key pressed */
144 uint8_t out_fifo_buf[16];
145 QEMUTimer *kbd_timer;
148 static TextConsole *active_console;
149 static TextConsole *consoles[MAX_CONSOLES];
150 static int nb_consoles = 0;
152 void vga_hw_update(void)
154 if (active_console && active_console->hw_update)
155 active_console->hw_update(active_console->hw);
158 void vga_hw_invalidate(void)
160 if (active_console->hw_invalidate)
161 active_console->hw_invalidate(active_console->hw);
164 void vga_hw_screen_dump(const char *filename)
166 /* There is currently no was of specifying which screen we want to dump,
167 so always dump the dirst one. */
168 if (consoles[0]->hw_screen_dump)
169 consoles[0]->hw_screen_dump(consoles[0]->hw, filename);
172 /* convert a RGBA color to a color index usable in graphic primitives */
173 static unsigned int vga_get_color(DisplayState *ds, unsigned int rgba)
175 unsigned int r, g, b, color;
180 r = (rgba >> 16) & 0xff;
181 g = (rgba >> 8) & 0xff;
183 color = (rgb_to_index[r] * 6 * 6) +
184 (rgb_to_index[g] * 6) +
189 r = (rgba >> 16) & 0xff;
190 g = (rgba >> 8) & 0xff;
192 color = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3);
195 r = (rgba >> 16) & 0xff;
196 g = (rgba >> 8) & 0xff;
198 color = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
208 static void vga_fill_rect (DisplayState *ds,
209 int posx, int posy, int width, int height, uint32_t color)
214 bpp = (ds->depth + 7) >> 3;
216 ds->linesize * posy + bpp * posx;
217 for (y = 0; y < height; y++) {
221 for (x = 0; x < width; x++) {
222 *((uint8_t *)d) = color;
227 for (x = 0; x < width; x++) {
228 *((uint16_t *)d) = color;
233 for (x = 0; x < width; x++) {
234 *((uint32_t *)d) = color;
243 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
244 static void vga_bitblt(DisplayState *ds, int xs, int ys, int xd, int yd, int w, int h)
250 bpp = (ds->depth + 7) >> 3;
254 ds->linesize * ys + bpp * xs;
256 ds->linesize * yd + bpp * xd;
257 for (y = 0; y < h; y++) {
264 ds->linesize * (ys + h - 1) + bpp * xs;
266 ds->linesize * (yd + h - 1) + bpp * xd;
267 for (y = 0; y < h; y++) {
275 /***********************************************************/
276 /* basic char display */
278 #define FONT_HEIGHT 16
283 #define cbswap_32(__x) \
285 (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
286 (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
287 (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
288 (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) ))
290 #ifdef WORDS_BIGENDIAN
293 #define PAT(x) cbswap_32(x)
296 static const uint32_t dmask16[16] = {
315 static const uint32_t dmask4[4] = {
322 static uint32_t color_table[2][8];
335 static const uint32_t color_table_rgb[2][8] = {
337 QEMU_RGB(0x00, 0x00, 0x00), /* black */
338 QEMU_RGB(0xaa, 0x00, 0x00), /* red */
339 QEMU_RGB(0x00, 0xaa, 0x00), /* green */
340 QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
341 QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
342 QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
343 QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
344 QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
347 QEMU_RGB(0x00, 0x00, 0x00), /* black */
348 QEMU_RGB(0xff, 0x00, 0x00), /* red */
349 QEMU_RGB(0x00, 0xff, 0x00), /* green */
350 QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
351 QEMU_RGB(0x00, 0x00, 0xff), /* blue */
352 QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
353 QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
354 QEMU_RGB(0xff, 0xff, 0xff), /* white */
358 static inline unsigned int col_expand(DisplayState *ds, unsigned int col)
376 static void console_print_text_attributes(TextAttributes *t_attrib, char ch)
378 if (t_attrib->bold) {
383 if (t_attrib->uline) {
388 if (t_attrib->blink) {
393 if (t_attrib->invers) {
398 if (t_attrib->unvisible) {
404 printf(" fg: %d bg: %d ch:'%2X' '%c'\n", t_attrib->fgcol, t_attrib->bgcol, ch, ch);
408 static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
409 TextAttributes *t_attrib)
412 const uint8_t *font_ptr;
413 unsigned int font_data, linesize, xorcol, bpp;
415 unsigned int fgcol, bgcol;
418 printf("x: %2i y: %2i", x, y);
419 console_print_text_attributes(t_attrib, ch);
422 if (t_attrib->invers) {
423 bgcol = color_table[t_attrib->bold][t_attrib->fgcol];
424 fgcol = color_table[t_attrib->bold][t_attrib->bgcol];
426 fgcol = color_table[t_attrib->bold][t_attrib->fgcol];
427 bgcol = color_table[t_attrib->bold][t_attrib->bgcol];
430 bpp = (ds->depth + 7) >> 3;
432 ds->linesize * y * FONT_HEIGHT + bpp * x * FONT_WIDTH;
433 linesize = ds->linesize;
434 font_ptr = vgafont16 + FONT_HEIGHT * ch;
435 xorcol = bgcol ^ fgcol;
438 for(i = 0; i < FONT_HEIGHT; i++) {
439 font_data = *font_ptr++;
441 && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {
444 ((uint32_t *)d)[0] = (dmask16[(font_data >> 4)] & xorcol) ^ bgcol;
445 ((uint32_t *)d)[1] = (dmask16[(font_data >> 0) & 0xf] & xorcol) ^ bgcol;
451 for(i = 0; i < FONT_HEIGHT; i++) {
452 font_data = *font_ptr++;
454 && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {
457 ((uint32_t *)d)[0] = (dmask4[(font_data >> 6)] & xorcol) ^ bgcol;
458 ((uint32_t *)d)[1] = (dmask4[(font_data >> 4) & 3] & xorcol) ^ bgcol;
459 ((uint32_t *)d)[2] = (dmask4[(font_data >> 2) & 3] & xorcol) ^ bgcol;
460 ((uint32_t *)d)[3] = (dmask4[(font_data >> 0) & 3] & xorcol) ^ bgcol;
465 for(i = 0; i < FONT_HEIGHT; i++) {
466 font_data = *font_ptr++;
467 if (t_attrib->uline && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {
470 ((uint32_t *)d)[0] = (-((font_data >> 7)) & xorcol) ^ bgcol;
471 ((uint32_t *)d)[1] = (-((font_data >> 6) & 1) & xorcol) ^ bgcol;
472 ((uint32_t *)d)[2] = (-((font_data >> 5) & 1) & xorcol) ^ bgcol;
473 ((uint32_t *)d)[3] = (-((font_data >> 4) & 1) & xorcol) ^ bgcol;
474 ((uint32_t *)d)[4] = (-((font_data >> 3) & 1) & xorcol) ^ bgcol;
475 ((uint32_t *)d)[5] = (-((font_data >> 2) & 1) & xorcol) ^ bgcol;
476 ((uint32_t *)d)[6] = (-((font_data >> 1) & 1) & xorcol) ^ bgcol;
477 ((uint32_t *)d)[7] = (-((font_data >> 0) & 1) & xorcol) ^ bgcol;
484 static void text_console_resize(TextConsole *s)
486 TextCell *cells, *c, *c1;
487 int w1, x, y, last_width;
489 last_width = s->width;
490 s->width = s->g_width / FONT_WIDTH;
491 s->height = s->g_height / FONT_HEIGHT;
497 cells = qemu_malloc(s->width * s->total_height * sizeof(TextCell));
498 for(y = 0; y < s->total_height; y++) {
499 c = &cells[y * s->width];
501 c1 = &s->cells[y * last_width];
502 for(x = 0; x < w1; x++) {
506 for(x = w1; x < s->width; x++) {
508 c->t_attrib = s->t_attrib_default;
516 static void update_xy(TextConsole *s, int x, int y)
521 if (s == active_console) {
522 y1 = (s->y_base + y) % s->total_height;
523 y2 = y1 - s->y_displayed;
525 y2 += s->total_height;
526 if (y2 < s->height) {
527 c = &s->cells[y1 * s->width + x];
528 vga_putcharxy(s->ds, x, y2, c->ch,
530 dpy_update(s->ds, x * FONT_WIDTH, y2 * FONT_HEIGHT,
531 FONT_WIDTH, FONT_HEIGHT);
536 static void console_show_cursor(TextConsole *s, int show)
541 if (s == active_console) {
546 y1 = (s->y_base + s->y) % s->total_height;
547 y = y1 - s->y_displayed;
549 y += s->total_height;
551 c = &s->cells[y1 * s->width + x];
553 TextAttributes t_attrib = s->t_attrib_default;
554 t_attrib.invers = !(t_attrib.invers); /* invert fg and bg */
555 vga_putcharxy(s->ds, x, y, c->ch, &t_attrib);
557 vga_putcharxy(s->ds, x, y, c->ch, &(c->t_attrib));
559 dpy_update(s->ds, x * FONT_WIDTH, y * FONT_HEIGHT,
560 FONT_WIDTH, FONT_HEIGHT);
565 static void console_refresh(TextConsole *s)
570 if (s != active_console)
573 vga_fill_rect(s->ds, 0, 0, s->ds->width, s->ds->height,
574 color_table[0][COLOR_BLACK]);
576 for(y = 0; y < s->height; y++) {
577 c = s->cells + y1 * s->width;
578 for(x = 0; x < s->width; x++) {
579 vga_putcharxy(s->ds, x, y, c->ch,
583 if (++y1 == s->total_height)
586 dpy_update(s->ds, 0, 0, s->ds->width, s->ds->height);
587 console_show_cursor(s, 1);
590 static void console_scroll(int ydelta)
596 if (!s || (s->console_type == GRAPHIC_CONSOLE))
600 for(i = 0; i < ydelta; i++) {
601 if (s->y_displayed == s->y_base)
603 if (++s->y_displayed == s->total_height)
608 i = s->backscroll_height;
609 if (i > s->total_height - s->height)
610 i = s->total_height - s->height;
613 y1 += s->total_height;
614 for(i = 0; i < ydelta; i++) {
615 if (s->y_displayed == y1)
617 if (--s->y_displayed < 0)
618 s->y_displayed = s->total_height - 1;
624 static void console_put_lf(TextConsole *s)
630 if (s->y >= s->height) {
631 s->y = s->height - 1;
633 if (s->y_displayed == s->y_base) {
634 if (++s->y_displayed == s->total_height)
637 if (++s->y_base == s->total_height)
639 if (s->backscroll_height < s->total_height)
640 s->backscroll_height++;
641 y1 = (s->y_base + s->height - 1) % s->total_height;
642 c = &s->cells[y1 * s->width];
643 for(x = 0; x < s->width; x++) {
645 c->t_attrib = s->t_attrib_default;
648 if (s == active_console && s->y_displayed == s->y_base) {
649 vga_bitblt(s->ds, 0, FONT_HEIGHT, 0, 0,
650 s->width * FONT_WIDTH,
651 (s->height - 1) * FONT_HEIGHT);
652 vga_fill_rect(s->ds, 0, (s->height - 1) * FONT_HEIGHT,
653 s->width * FONT_WIDTH, FONT_HEIGHT,
654 color_table[0][s->t_attrib_default.bgcol]);
655 dpy_update(s->ds, 0, 0,
656 s->width * FONT_WIDTH, s->height * FONT_HEIGHT);
661 /* Set console attributes depending on the current escape codes.
662 * NOTE: I know this code is not very efficient (checking every color for it
663 * self) but it is more readable and better maintainable.
665 static void console_handle_escape(TextConsole *s)
669 for (i=0; i<s->nb_esc_params; i++) {
670 switch (s->esc_params[i]) {
671 case 0: /* reset all console attributes to default */
672 s->t_attrib = s->t_attrib_default;
675 s->t_attrib.bold = 1;
678 s->t_attrib.uline = 1;
681 s->t_attrib.blink = 1;
684 s->t_attrib.invers = 1;
687 s->t_attrib.unvisible = 1;
690 s->t_attrib.bold = 0;
693 s->t_attrib.uline = 0;
696 s->t_attrib.blink = 0;
699 s->t_attrib.invers = 0;
702 s->t_attrib.unvisible = 0;
704 /* set foreground color */
706 s->t_attrib.fgcol=COLOR_BLACK;
709 s->t_attrib.fgcol=COLOR_RED;
712 s->t_attrib.fgcol=COLOR_GREEN;
715 s->t_attrib.fgcol=COLOR_YELLOW;
718 s->t_attrib.fgcol=COLOR_BLUE;
721 s->t_attrib.fgcol=COLOR_MAGENTA;
724 s->t_attrib.fgcol=COLOR_CYAN;
727 s->t_attrib.fgcol=COLOR_WHITE;
729 /* set background color */
731 s->t_attrib.bgcol=COLOR_BLACK;
734 s->t_attrib.bgcol=COLOR_RED;
737 s->t_attrib.bgcol=COLOR_GREEN;
740 s->t_attrib.bgcol=COLOR_YELLOW;
743 s->t_attrib.bgcol=COLOR_BLUE;
746 s->t_attrib.bgcol=COLOR_MAGENTA;
749 s->t_attrib.bgcol=COLOR_CYAN;
752 s->t_attrib.bgcol=COLOR_WHITE;
758 static void console_clear_xy(TextConsole *s, int x, int y)
760 int y1 = (s->y_base + y) % s->total_height;
761 TextCell *c = &s->cells[y1 * s->width + x];
763 c->t_attrib = s->t_attrib_default;
768 static void console_putchar(TextConsole *s, int ch)
777 case '\r': /* carriage return */
780 case '\n': /* newline */
783 case '\b': /* backspace */
787 case '\t': /* tabspace */
788 if (s->x + (8 - (s->x % 8)) > s->width) {
792 s->x = s->x + (8 - (s->x % 8));
795 case '\a': /* alert aka. bell */
796 /* TODO: has to be implemented */
799 /* SI (shift in), character set 0 (ignored) */
802 /* SO (shift out), character set 1 (ignored) */
804 case 27: /* esc (introducing an escape sequence) */
805 s->state = TTY_STATE_ESC;
808 if (s->x >= s->width) {
813 y1 = (s->y_base + s->y) % s->total_height;
814 c = &s->cells[y1 * s->width + s->x];
816 c->t_attrib = s->t_attrib;
817 update_xy(s, s->x, s->y);
822 case TTY_STATE_ESC: /* check if it is a terminal escape sequence */
824 for(i=0;i<MAX_ESC_PARAMS;i++)
825 s->esc_params[i] = 0;
826 s->nb_esc_params = 0;
827 s->state = TTY_STATE_CSI;
829 s->state = TTY_STATE_NORM;
832 case TTY_STATE_CSI: /* handle escape sequence parameters */
833 if (ch >= '0' && ch <= '9') {
834 if (s->nb_esc_params < MAX_ESC_PARAMS) {
835 s->esc_params[s->nb_esc_params] =
836 s->esc_params[s->nb_esc_params] * 10 + ch - '0';
843 fprintf(stderr, "escape sequence CSI%d;%d%c, %d parameters\n",
844 s->esc_params[0], s->esc_params[1], ch, s->nb_esc_params);
846 s->state = TTY_STATE_NORM;
850 if (s->esc_params[0] == 0) {
851 s->esc_params[0] = 1;
853 s->y -= s->esc_params[0];
859 /* move cursor down */
860 if (s->esc_params[0] == 0) {
861 s->esc_params[0] = 1;
863 s->y += s->esc_params[0];
864 if (s->y >= s->height) {
865 s->y = s->height - 1;
869 /* move cursor right */
870 if (s->esc_params[0] == 0) {
871 s->esc_params[0] = 1;
873 s->x += s->esc_params[0];
874 if (s->x >= s->width) {
879 /* move cursor left */
880 if (s->esc_params[0] == 0) {
881 s->esc_params[0] = 1;
883 s->x -= s->esc_params[0];
889 /* move cursor to column */
890 s->x = s->esc_params[0] - 1;
897 /* move cursor to row, column */
898 s->x = s->esc_params[1] - 1;
902 s->y = s->esc_params[0] - 1;
908 switch (s->esc_params[0]) {
910 /* clear to end of screen */
911 for (y = s->y; y < s->height; y++) {
912 for (x = 0; x < s->width; x++) {
913 if (y == s->y && x < s->x) {
916 console_clear_xy(s, x, y);
921 /* clear from beginning of screen */
922 for (y = 0; y <= s->y; y++) {
923 for (x = 0; x < s->width; x++) {
924 if (y == s->y && x > s->x) {
927 console_clear_xy(s, x, y);
932 /* clear entire screen */
933 for (y = 0; y <= s->height; y++) {
934 for (x = 0; x < s->width; x++) {
935 console_clear_xy(s, x, y);
941 switch (s->esc_params[0]) {
944 for(x = s->x; x < s->width; x++) {
945 console_clear_xy(s, x, s->y);
949 /* clear from beginning of line */
950 for (x = 0; x <= s->x; x++) {
951 console_clear_xy(s, x, s->y);
955 /* clear entire line */
956 for(x = 0; x < s->width; x++) {
957 console_clear_xy(s, x, s->y);
963 console_handle_escape(s);
966 /* report cursor position */
967 /* TODO: send ESC[row;colR */
970 /* save cursor position */
975 /* restore cursor position */
981 fprintf(stderr, "unhandled escape character '%c'\n", ch);
990 void console_select(unsigned int index)
994 if (index >= MAX_CONSOLES)
999 if (s->console_type != GRAPHIC_CONSOLE) {
1000 if (s->g_width != s->ds->width ||
1001 s->g_height != s->ds->height) {
1002 if (s->console_type == TEXT_CONSOLE_FIXED_SIZE) {
1003 dpy_resize(s->ds, s->g_width, s->g_height);
1005 s->g_width = s->ds->width;
1006 s->g_height = s->ds->height;
1007 text_console_resize(s);
1012 vga_hw_invalidate();
1017 static int console_puts(CharDriverState *chr, const uint8_t *buf, int len)
1019 TextConsole *s = chr->opaque;
1022 console_show_cursor(s, 0);
1023 for(i = 0; i < len; i++) {
1024 console_putchar(s, buf[i]);
1026 console_show_cursor(s, 1);
1030 static void console_send_event(CharDriverState *chr, int event)
1032 TextConsole *s = chr->opaque;
1035 if (event == CHR_EVENT_FOCUS) {
1036 for(i = 0; i < nb_consoles; i++) {
1037 if (consoles[i] == s) {
1045 static void kbd_send_chars(void *opaque)
1047 TextConsole *s = opaque;
1051 len = qemu_chr_can_read(s->chr);
1052 if (len > s->out_fifo.count)
1053 len = s->out_fifo.count;
1055 if (len > sizeof(buf))
1057 qemu_fifo_read(&s->out_fifo, buf, len);
1058 qemu_chr_read(s->chr, buf, len);
1060 /* characters are pending: we send them a bit later (XXX:
1061 horrible, should change char device API) */
1062 if (s->out_fifo.count > 0) {
1063 qemu_mod_timer(s->kbd_timer, qemu_get_clock(rt_clock) + 1);
1067 /* called when an ascii key is pressed */
1068 void kbd_put_keysym(int keysym)
1071 uint8_t buf[16], *q;
1075 if (!s || (s->console_type == GRAPHIC_CONSOLE))
1079 case QEMU_KEY_CTRL_UP:
1082 case QEMU_KEY_CTRL_DOWN:
1085 case QEMU_KEY_CTRL_PAGEUP:
1086 console_scroll(-10);
1088 case QEMU_KEY_CTRL_PAGEDOWN:
1092 /* convert the QEMU keysym to VT100 key string */
1094 if (keysym >= 0xe100 && keysym <= 0xe11f) {
1097 c = keysym - 0xe100;
1099 *q++ = '0' + (c / 10);
1100 *q++ = '0' + (c % 10);
1102 } else if (keysym >= 0xe120 && keysym <= 0xe17f) {
1105 *q++ = keysym & 0xff;
1109 if (s->chr->chr_read) {
1110 qemu_fifo_write(&s->out_fifo, buf, q - buf);
1117 static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
1122 if (nb_consoles >= MAX_CONSOLES)
1124 s = qemu_mallocz(sizeof(TextConsole));
1128 if (!active_console || ((active_console->console_type != GRAPHIC_CONSOLE) &&
1129 (console_type == GRAPHIC_CONSOLE))) {
1133 s->console_type = console_type;
1134 if (console_type != GRAPHIC_CONSOLE) {
1135 consoles[nb_consoles++] = s;
1137 /* HACK: Put graphical consoles before text consoles. */
1138 for (i = nb_consoles; i > 0; i--) {
1139 if (consoles[i - 1]->console_type == GRAPHIC_CONSOLE)
1141 consoles[i] = consoles[i - 1];
1148 TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
1149 vga_hw_invalidate_ptr invalidate,
1150 vga_hw_screen_dump_ptr screen_dump,
1155 s = new_console(ds, GRAPHIC_CONSOLE);
1158 s->hw_update = update;
1159 s->hw_invalidate = invalidate;
1160 s->hw_screen_dump = screen_dump;
1165 int is_graphic_console(void)
1167 return active_console->console_type == GRAPHIC_CONSOLE;
1170 void console_color_init(DisplayState *ds)
1173 for (j = 0; j < 2; j++) {
1174 for (i = 0; i < 8; i++) {
1175 color_table[j][i] = col_expand(ds,
1176 vga_get_color(ds, color_table_rgb[j][i]));
1181 CharDriverState *text_console_init(DisplayState *ds, const char *p)
1183 CharDriverState *chr;
1187 static int color_inited;
1189 chr = qemu_mallocz(sizeof(CharDriverState));
1192 s = new_console(ds, (p == 0) ? TEXT_CONSOLE : TEXT_CONSOLE_FIXED_SIZE);
1198 chr->chr_write = console_puts;
1199 chr->chr_send_event = console_send_event;
1202 s->out_fifo.buf = s->out_fifo_buf;
1203 s->out_fifo.buf_size = sizeof(s->out_fifo_buf);
1204 s->kbd_timer = qemu_new_timer(rt_clock, kbd_send_chars, s);
1206 if (!color_inited) {
1208 console_color_init(s->ds);
1212 s->total_height = DEFAULT_BACKSCROLL;
1215 width = s->ds->width;
1216 height = s->ds->height;
1218 width = strtoul(p, (char **)&p, 10);
1221 width *= FONT_WIDTH;
1225 height = strtoul(p, (char **)&p, 10);
1228 height *= FONT_HEIGHT;
1233 s->g_height = height;
1235 /* Set text attribute defaults */
1236 s->t_attrib_default.bold = 0;
1237 s->t_attrib_default.uline = 0;
1238 s->t_attrib_default.blink = 0;
1239 s->t_attrib_default.invers = 0;
1240 s->t_attrib_default.unvisible = 0;
1241 s->t_attrib_default.fgcol = COLOR_WHITE;
1242 s->t_attrib_default.bgcol = COLOR_BLACK;
1244 /* set current text attributes to default */
1245 s->t_attrib = s->t_attrib_default;
1246 text_console_resize(s);
1248 qemu_chr_reset(chr);