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
24 #include "qemu-common.h"
25 #include "ui/console.h"
26 #include "qemu/timer.h"
27 #include "qmp-commands.h"
28 #include "char/char.h"
30 //#define DEBUG_CONSOLE
31 #define DEFAULT_BACKSCROLL 512
32 #define MAX_CONSOLES 12
33 #define CONSOLE_CURSOR_PERIOD 500
35 #define QEMU_RGBA(r, g, b, a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
36 #define QEMU_RGB(r, g, b) QEMU_RGBA(r, g, b, 0xff)
38 typedef struct TextAttributes
{
48 typedef struct TextCell
{
50 TextAttributes t_attrib
;
53 #define MAX_ESC_PARAMS 3
61 typedef struct QEMUFIFO
{
64 int count
, wptr
, rptr
;
67 static int qemu_fifo_write(QEMUFIFO
*f
, const uint8_t *buf
, int len1
)
71 l
= f
->buf_size
- f
->count
;
76 l
= f
->buf_size
- f
->wptr
;
79 memcpy(f
->buf
+ f
->wptr
, buf
, l
);
81 if (f
->wptr
>= f
->buf_size
)
90 static int qemu_fifo_read(QEMUFIFO
*f
, uint8_t *buf
, int len1
)
98 l
= f
->buf_size
- f
->rptr
;
101 memcpy(buf
, f
->buf
+ f
->rptr
, l
);
103 if (f
->rptr
>= f
->buf_size
)
115 TEXT_CONSOLE_FIXED_SIZE
120 console_type_t console_type
;
123 /* Graphic console state. */
124 vga_hw_update_ptr hw_update
;
125 vga_hw_invalidate_ptr hw_invalidate
;
126 vga_hw_screen_dump_ptr hw_screen_dump
;
127 vga_hw_text_update_ptr hw_text_update
;
129 int g_width
, g_height
;
131 /* Text console state */
135 int backscroll_height
;
137 int x_saved
, y_saved
;
140 TextAttributes t_attrib_default
; /* default text attributes */
141 TextAttributes t_attrib
; /* currently active text attributes */
143 int text_x
[2], text_y
[2], cursor_invalidate
;
145 bool cursor_visible_phase
;
146 QEMUTimer
*cursor_timer
;
154 int esc_params
[MAX_ESC_PARAMS
];
157 CharDriverState
*chr
;
158 /* fifo for key pressed */
160 uint8_t out_fifo_buf
[16];
161 QEMUTimer
*kbd_timer
;
164 static DisplayState
*display_state
;
165 static QemuConsole
*active_console
;
166 static QemuConsole
*consoles
[MAX_CONSOLES
];
167 static int nb_consoles
= 0;
169 void vga_hw_update(void)
171 if (active_console
&& active_console
->hw_update
)
172 active_console
->hw_update(active_console
->hw
);
175 void vga_hw_invalidate(void)
177 if (active_console
&& active_console
->hw_invalidate
)
178 active_console
->hw_invalidate(active_console
->hw
);
181 void qmp_screendump(const char *filename
, Error
**errp
)
183 QemuConsole
*previous_active_console
;
186 previous_active_console
= active_console
;
187 cswitch
= previous_active_console
&& previous_active_console
->index
!= 0;
189 /* There is currently no way of specifying which screen we want to dump,
190 so always dump the first one. */
194 if (consoles
[0] && consoles
[0]->hw_screen_dump
) {
195 consoles
[0]->hw_screen_dump(consoles
[0]->hw
, filename
, cswitch
, errp
);
197 error_setg(errp
, "device doesn't support screendump");
201 console_select(previous_active_console
->index
);
205 void vga_hw_text_update(console_ch_t
*chardata
)
207 if (active_console
&& active_console
->hw_text_update
)
208 active_console
->hw_text_update(active_console
->hw
, chardata
);
211 /* convert a RGBA color to a color index usable in graphic primitives */
212 static unsigned int vga_get_color(DisplayState
*ds
, unsigned int rgba
)
214 unsigned int r
, g
, b
, color
;
216 switch(ds_get_bits_per_pixel(ds
)) {
219 r
= (rgba
>> 16) & 0xff;
220 g
= (rgba
>> 8) & 0xff;
222 color
= (rgb_to_index
[r
] * 6 * 6) +
223 (rgb_to_index
[g
] * 6) +
228 r
= (rgba
>> 16) & 0xff;
229 g
= (rgba
>> 8) & 0xff;
231 color
= ((r
>> 3) << 10) | ((g
>> 3) << 5) | (b
>> 3);
234 r
= (rgba
>> 16) & 0xff;
235 g
= (rgba
>> 8) & 0xff;
237 color
= ((r
>> 3) << 11) | ((g
>> 2) << 5) | (b
>> 3);
247 static void vga_fill_rect (DisplayState
*ds
,
248 int posx
, int posy
, int width
, int height
, uint32_t color
)
253 bpp
= (ds_get_bits_per_pixel(ds
) + 7) >> 3;
254 d1
= ds_get_data(ds
) +
255 ds_get_linesize(ds
) * posy
+ bpp
* posx
;
256 for (y
= 0; y
< height
; y
++) {
260 for (x
= 0; x
< width
; x
++) {
261 *((uint8_t *)d
) = color
;
266 for (x
= 0; x
< width
; x
++) {
267 *((uint16_t *)d
) = color
;
272 for (x
= 0; x
< width
; x
++) {
273 *((uint32_t *)d
) = color
;
278 d1
+= ds_get_linesize(ds
);
282 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
283 static void vga_bitblt(DisplayState
*ds
, int xs
, int ys
, int xd
, int yd
, int w
, int h
)
289 bpp
= (ds_get_bits_per_pixel(ds
) + 7) >> 3;
292 s
= ds_get_data(ds
) +
293 ds_get_linesize(ds
) * ys
+ bpp
* xs
;
294 d
= ds_get_data(ds
) +
295 ds_get_linesize(ds
) * yd
+ bpp
* xd
;
296 for (y
= 0; y
< h
; y
++) {
298 d
+= ds_get_linesize(ds
);
299 s
+= ds_get_linesize(ds
);
302 s
= ds_get_data(ds
) +
303 ds_get_linesize(ds
) * (ys
+ h
- 1) + bpp
* xs
;
304 d
= ds_get_data(ds
) +
305 ds_get_linesize(ds
) * (yd
+ h
- 1) + bpp
* xd
;
306 for (y
= 0; y
< h
; y
++) {
308 d
-= ds_get_linesize(ds
);
309 s
-= ds_get_linesize(ds
);
314 /***********************************************************/
315 /* basic char display */
317 #define FONT_HEIGHT 16
322 #define cbswap_32(__x) \
324 (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
325 (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
326 (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
327 (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) ))
329 #ifdef HOST_WORDS_BIGENDIAN
332 #define PAT(x) cbswap_32(x)
335 static const uint32_t dmask16
[16] = {
354 static const uint32_t dmask4
[4] = {
361 static uint32_t color_table
[2][8];
363 #ifndef CONFIG_CURSES
376 static const uint32_t color_table_rgb
[2][8] = {
378 QEMU_RGB(0x00, 0x00, 0x00), /* black */
379 QEMU_RGB(0xaa, 0x00, 0x00), /* red */
380 QEMU_RGB(0x00, 0xaa, 0x00), /* green */
381 QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
382 QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
383 QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
384 QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
385 QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
388 QEMU_RGB(0x00, 0x00, 0x00), /* black */
389 QEMU_RGB(0xff, 0x00, 0x00), /* red */
390 QEMU_RGB(0x00, 0xff, 0x00), /* green */
391 QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
392 QEMU_RGB(0x00, 0x00, 0xff), /* blue */
393 QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
394 QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
395 QEMU_RGB(0xff, 0xff, 0xff), /* white */
399 static inline unsigned int col_expand(DisplayState
*ds
, unsigned int col
)
401 switch(ds_get_bits_per_pixel(ds
)) {
417 static void console_print_text_attributes(TextAttributes
*t_attrib
, char ch
)
419 if (t_attrib
->bold
) {
424 if (t_attrib
->uline
) {
429 if (t_attrib
->blink
) {
434 if (t_attrib
->invers
) {
439 if (t_attrib
->unvisible
) {
445 printf(" fg: %d bg: %d ch:'%2X' '%c'\n", t_attrib
->fgcol
, t_attrib
->bgcol
, ch
, ch
);
449 static void vga_putcharxy(DisplayState
*ds
, int x
, int y
, int ch
,
450 TextAttributes
*t_attrib
)
453 const uint8_t *font_ptr
;
454 unsigned int font_data
, linesize
, xorcol
, bpp
;
456 unsigned int fgcol
, bgcol
;
459 printf("x: %2i y: %2i", x
, y
);
460 console_print_text_attributes(t_attrib
, ch
);
463 if (t_attrib
->invers
) {
464 bgcol
= color_table
[t_attrib
->bold
][t_attrib
->fgcol
];
465 fgcol
= color_table
[t_attrib
->bold
][t_attrib
->bgcol
];
467 fgcol
= color_table
[t_attrib
->bold
][t_attrib
->fgcol
];
468 bgcol
= color_table
[t_attrib
->bold
][t_attrib
->bgcol
];
471 bpp
= (ds_get_bits_per_pixel(ds
) + 7) >> 3;
472 d
= ds_get_data(ds
) +
473 ds_get_linesize(ds
) * y
* FONT_HEIGHT
+ bpp
* x
* FONT_WIDTH
;
474 linesize
= ds_get_linesize(ds
);
475 font_ptr
= vgafont16
+ FONT_HEIGHT
* ch
;
476 xorcol
= bgcol
^ fgcol
;
477 switch(ds_get_bits_per_pixel(ds
)) {
479 for(i
= 0; i
< FONT_HEIGHT
; i
++) {
480 font_data
= *font_ptr
++;
482 && ((i
== FONT_HEIGHT
- 2) || (i
== FONT_HEIGHT
- 3))) {
485 ((uint32_t *)d
)[0] = (dmask16
[(font_data
>> 4)] & xorcol
) ^ bgcol
;
486 ((uint32_t *)d
)[1] = (dmask16
[(font_data
>> 0) & 0xf] & xorcol
) ^ bgcol
;
492 for(i
= 0; i
< FONT_HEIGHT
; i
++) {
493 font_data
= *font_ptr
++;
495 && ((i
== FONT_HEIGHT
- 2) || (i
== FONT_HEIGHT
- 3))) {
498 ((uint32_t *)d
)[0] = (dmask4
[(font_data
>> 6)] & xorcol
) ^ bgcol
;
499 ((uint32_t *)d
)[1] = (dmask4
[(font_data
>> 4) & 3] & xorcol
) ^ bgcol
;
500 ((uint32_t *)d
)[2] = (dmask4
[(font_data
>> 2) & 3] & xorcol
) ^ bgcol
;
501 ((uint32_t *)d
)[3] = (dmask4
[(font_data
>> 0) & 3] & xorcol
) ^ bgcol
;
506 for(i
= 0; i
< FONT_HEIGHT
; i
++) {
507 font_data
= *font_ptr
++;
508 if (t_attrib
->uline
&& ((i
== FONT_HEIGHT
- 2) || (i
== FONT_HEIGHT
- 3))) {
511 ((uint32_t *)d
)[0] = (-((font_data
>> 7)) & xorcol
) ^ bgcol
;
512 ((uint32_t *)d
)[1] = (-((font_data
>> 6) & 1) & xorcol
) ^ bgcol
;
513 ((uint32_t *)d
)[2] = (-((font_data
>> 5) & 1) & xorcol
) ^ bgcol
;
514 ((uint32_t *)d
)[3] = (-((font_data
>> 4) & 1) & xorcol
) ^ bgcol
;
515 ((uint32_t *)d
)[4] = (-((font_data
>> 3) & 1) & xorcol
) ^ bgcol
;
516 ((uint32_t *)d
)[5] = (-((font_data
>> 2) & 1) & xorcol
) ^ bgcol
;
517 ((uint32_t *)d
)[6] = (-((font_data
>> 1) & 1) & xorcol
) ^ bgcol
;
518 ((uint32_t *)d
)[7] = (-((font_data
>> 0) & 1) & xorcol
) ^ bgcol
;
525 static void text_console_resize(QemuConsole
*s
)
527 TextCell
*cells
, *c
, *c1
;
528 int w1
, x
, y
, last_width
;
530 last_width
= s
->width
;
531 s
->width
= s
->g_width
/ FONT_WIDTH
;
532 s
->height
= s
->g_height
/ FONT_HEIGHT
;
538 cells
= g_malloc(s
->width
* s
->total_height
* sizeof(TextCell
));
539 for(y
= 0; y
< s
->total_height
; y
++) {
540 c
= &cells
[y
* s
->width
];
542 c1
= &s
->cells
[y
* last_width
];
543 for(x
= 0; x
< w1
; x
++) {
547 for(x
= w1
; x
< s
->width
; x
++) {
549 c
->t_attrib
= s
->t_attrib_default
;
557 static inline void text_update_xy(QemuConsole
*s
, int x
, int y
)
559 s
->text_x
[0] = MIN(s
->text_x
[0], x
);
560 s
->text_x
[1] = MAX(s
->text_x
[1], x
);
561 s
->text_y
[0] = MIN(s
->text_y
[0], y
);
562 s
->text_y
[1] = MAX(s
->text_y
[1], y
);
565 static void invalidate_xy(QemuConsole
*s
, int x
, int y
)
567 if (s
->update_x0
> x
* FONT_WIDTH
)
568 s
->update_x0
= x
* FONT_WIDTH
;
569 if (s
->update_y0
> y
* FONT_HEIGHT
)
570 s
->update_y0
= y
* FONT_HEIGHT
;
571 if (s
->update_x1
< (x
+ 1) * FONT_WIDTH
)
572 s
->update_x1
= (x
+ 1) * FONT_WIDTH
;
573 if (s
->update_y1
< (y
+ 1) * FONT_HEIGHT
)
574 s
->update_y1
= (y
+ 1) * FONT_HEIGHT
;
577 static void update_xy(QemuConsole
*s
, int x
, int y
)
582 if (s
== active_console
) {
583 if (!ds_get_bits_per_pixel(s
->ds
)) {
584 text_update_xy(s
, x
, y
);
588 y1
= (s
->y_base
+ y
) % s
->total_height
;
589 y2
= y1
- s
->y_displayed
;
591 y2
+= s
->total_height
;
592 if (y2
< s
->height
) {
593 c
= &s
->cells
[y1
* s
->width
+ x
];
594 vga_putcharxy(s
->ds
, x
, y2
, c
->ch
,
596 invalidate_xy(s
, x
, y2
);
601 static void console_show_cursor(QemuConsole
*s
, int show
)
606 if (s
== active_console
) {
609 if (!ds_get_bits_per_pixel(s
->ds
)) {
610 s
->cursor_invalidate
= 1;
617 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
618 y
= y1
- s
->y_displayed
;
620 y
+= s
->total_height
;
622 c
= &s
->cells
[y1
* s
->width
+ x
];
623 if (show
&& s
->cursor_visible_phase
) {
624 TextAttributes t_attrib
= s
->t_attrib_default
;
625 t_attrib
.invers
= !(t_attrib
.invers
); /* invert fg and bg */
626 vga_putcharxy(s
->ds
, x
, y
, c
->ch
, &t_attrib
);
628 vga_putcharxy(s
->ds
, x
, y
, c
->ch
, &(c
->t_attrib
));
630 invalidate_xy(s
, x
, y
);
635 static void console_refresh(QemuConsole
*s
)
640 if (s
!= active_console
)
643 if (s
->ds
->have_text
) {
646 s
->text_x
[1] = s
->width
- 1;
647 s
->text_y
[1] = s
->height
- 1;
648 s
->cursor_invalidate
= 1;
651 if (s
->ds
->have_gfx
) {
652 vga_fill_rect(s
->ds
, 0, 0, ds_get_width(s
->ds
), ds_get_height(s
->ds
),
653 color_table
[0][COLOR_BLACK
]);
655 for (y
= 0; y
< s
->height
; y
++) {
656 c
= s
->cells
+ y1
* s
->width
;
657 for (x
= 0; x
< s
->width
; x
++) {
658 vga_putcharxy(s
->ds
, x
, y
, c
->ch
,
662 if (++y1
== s
->total_height
) {
666 console_show_cursor(s
, 1);
667 dpy_gfx_update(s
, 0, 0, ds_get_width(s
->ds
), ds_get_height(s
->ds
));
671 static void console_scroll(int ydelta
)
677 if (!s
|| (s
->console_type
== GRAPHIC_CONSOLE
))
681 for(i
= 0; i
< ydelta
; i
++) {
682 if (s
->y_displayed
== s
->y_base
)
684 if (++s
->y_displayed
== s
->total_height
)
689 i
= s
->backscroll_height
;
690 if (i
> s
->total_height
- s
->height
)
691 i
= s
->total_height
- s
->height
;
694 y1
+= s
->total_height
;
695 for(i
= 0; i
< ydelta
; i
++) {
696 if (s
->y_displayed
== y1
)
698 if (--s
->y_displayed
< 0)
699 s
->y_displayed
= s
->total_height
- 1;
705 static void console_put_lf(QemuConsole
*s
)
711 if (s
->y
>= s
->height
) {
712 s
->y
= s
->height
- 1;
714 if (s
->y_displayed
== s
->y_base
) {
715 if (++s
->y_displayed
== s
->total_height
)
718 if (++s
->y_base
== s
->total_height
)
720 if (s
->backscroll_height
< s
->total_height
)
721 s
->backscroll_height
++;
722 y1
= (s
->y_base
+ s
->height
- 1) % s
->total_height
;
723 c
= &s
->cells
[y1
* s
->width
];
724 for(x
= 0; x
< s
->width
; x
++) {
726 c
->t_attrib
= s
->t_attrib_default
;
729 if (s
== active_console
&& s
->y_displayed
== s
->y_base
) {
730 if (!ds_get_bits_per_pixel(s
->ds
)) {
733 s
->text_x
[1] = s
->width
- 1;
734 s
->text_y
[1] = s
->height
- 1;
738 vga_bitblt(s
->ds
, 0, FONT_HEIGHT
, 0, 0,
739 s
->width
* FONT_WIDTH
,
740 (s
->height
- 1) * FONT_HEIGHT
);
741 vga_fill_rect(s
->ds
, 0, (s
->height
- 1) * FONT_HEIGHT
,
742 s
->width
* FONT_WIDTH
, FONT_HEIGHT
,
743 color_table
[0][s
->t_attrib_default
.bgcol
]);
746 s
->update_x1
= s
->width
* FONT_WIDTH
;
747 s
->update_y1
= s
->height
* FONT_HEIGHT
;
752 /* Set console attributes depending on the current escape codes.
753 * NOTE: I know this code is not very efficient (checking every color for it
754 * self) but it is more readable and better maintainable.
756 static void console_handle_escape(QemuConsole
*s
)
760 for (i
=0; i
<s
->nb_esc_params
; i
++) {
761 switch (s
->esc_params
[i
]) {
762 case 0: /* reset all console attributes to default */
763 s
->t_attrib
= s
->t_attrib_default
;
766 s
->t_attrib
.bold
= 1;
769 s
->t_attrib
.uline
= 1;
772 s
->t_attrib
.blink
= 1;
775 s
->t_attrib
.invers
= 1;
778 s
->t_attrib
.unvisible
= 1;
781 s
->t_attrib
.bold
= 0;
784 s
->t_attrib
.uline
= 0;
787 s
->t_attrib
.blink
= 0;
790 s
->t_attrib
.invers
= 0;
793 s
->t_attrib
.unvisible
= 0;
795 /* set foreground color */
797 s
->t_attrib
.fgcol
=COLOR_BLACK
;
800 s
->t_attrib
.fgcol
=COLOR_RED
;
803 s
->t_attrib
.fgcol
=COLOR_GREEN
;
806 s
->t_attrib
.fgcol
=COLOR_YELLOW
;
809 s
->t_attrib
.fgcol
=COLOR_BLUE
;
812 s
->t_attrib
.fgcol
=COLOR_MAGENTA
;
815 s
->t_attrib
.fgcol
=COLOR_CYAN
;
818 s
->t_attrib
.fgcol
=COLOR_WHITE
;
820 /* set background color */
822 s
->t_attrib
.bgcol
=COLOR_BLACK
;
825 s
->t_attrib
.bgcol
=COLOR_RED
;
828 s
->t_attrib
.bgcol
=COLOR_GREEN
;
831 s
->t_attrib
.bgcol
=COLOR_YELLOW
;
834 s
->t_attrib
.bgcol
=COLOR_BLUE
;
837 s
->t_attrib
.bgcol
=COLOR_MAGENTA
;
840 s
->t_attrib
.bgcol
=COLOR_CYAN
;
843 s
->t_attrib
.bgcol
=COLOR_WHITE
;
849 static void console_clear_xy(QemuConsole
*s
, int x
, int y
)
851 int y1
= (s
->y_base
+ y
) % s
->total_height
;
852 TextCell
*c
= &s
->cells
[y1
* s
->width
+ x
];
854 c
->t_attrib
= s
->t_attrib_default
;
858 /* set cursor, checking bounds */
859 static void set_cursor(QemuConsole
*s
, int x
, int y
)
867 if (y
>= s
->height
) {
878 static void console_putchar(QemuConsole
*s
, int ch
)
887 case '\r': /* carriage return */
890 case '\n': /* newline */
893 case '\b': /* backspace */
897 case '\t': /* tabspace */
898 if (s
->x
+ (8 - (s
->x
% 8)) > s
->width
) {
902 s
->x
= s
->x
+ (8 - (s
->x
% 8));
905 case '\a': /* alert aka. bell */
906 /* TODO: has to be implemented */
909 /* SI (shift in), character set 0 (ignored) */
912 /* SO (shift out), character set 1 (ignored) */
914 case 27: /* esc (introducing an escape sequence) */
915 s
->state
= TTY_STATE_ESC
;
918 if (s
->x
>= s
->width
) {
923 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
924 c
= &s
->cells
[y1
* s
->width
+ s
->x
];
926 c
->t_attrib
= s
->t_attrib
;
927 update_xy(s
, s
->x
, s
->y
);
932 case TTY_STATE_ESC
: /* check if it is a terminal escape sequence */
934 for(i
=0;i
<MAX_ESC_PARAMS
;i
++)
935 s
->esc_params
[i
] = 0;
936 s
->nb_esc_params
= 0;
937 s
->state
= TTY_STATE_CSI
;
939 s
->state
= TTY_STATE_NORM
;
942 case TTY_STATE_CSI
: /* handle escape sequence parameters */
943 if (ch
>= '0' && ch
<= '9') {
944 if (s
->nb_esc_params
< MAX_ESC_PARAMS
) {
945 int *param
= &s
->esc_params
[s
->nb_esc_params
];
946 int digit
= (ch
- '0');
948 *param
= (*param
<= (INT_MAX
- digit
) / 10) ?
949 *param
* 10 + digit
: INT_MAX
;
952 if (s
->nb_esc_params
< MAX_ESC_PARAMS
)
957 fprintf(stderr
, "escape sequence CSI%d;%d%c, %d parameters\n",
958 s
->esc_params
[0], s
->esc_params
[1], ch
, s
->nb_esc_params
);
960 s
->state
= TTY_STATE_NORM
;
964 if (s
->esc_params
[0] == 0) {
965 s
->esc_params
[0] = 1;
967 set_cursor(s
, s
->x
, s
->y
- s
->esc_params
[0]);
970 /* move cursor down */
971 if (s
->esc_params
[0] == 0) {
972 s
->esc_params
[0] = 1;
974 set_cursor(s
, s
->x
, s
->y
+ s
->esc_params
[0]);
977 /* move cursor right */
978 if (s
->esc_params
[0] == 0) {
979 s
->esc_params
[0] = 1;
981 set_cursor(s
, s
->x
+ s
->esc_params
[0], s
->y
);
984 /* move cursor left */
985 if (s
->esc_params
[0] == 0) {
986 s
->esc_params
[0] = 1;
988 set_cursor(s
, s
->x
- s
->esc_params
[0], s
->y
);
991 /* move cursor to column */
992 set_cursor(s
, s
->esc_params
[0] - 1, s
->y
);
996 /* move cursor to row, column */
997 set_cursor(s
, s
->esc_params
[1] - 1, s
->esc_params
[0] - 1);
1000 switch (s
->esc_params
[0]) {
1002 /* clear to end of screen */
1003 for (y
= s
->y
; y
< s
->height
; y
++) {
1004 for (x
= 0; x
< s
->width
; x
++) {
1005 if (y
== s
->y
&& x
< s
->x
) {
1008 console_clear_xy(s
, x
, y
);
1013 /* clear from beginning of screen */
1014 for (y
= 0; y
<= s
->y
; y
++) {
1015 for (x
= 0; x
< s
->width
; x
++) {
1016 if (y
== s
->y
&& x
> s
->x
) {
1019 console_clear_xy(s
, x
, y
);
1024 /* clear entire screen */
1025 for (y
= 0; y
<= s
->height
; y
++) {
1026 for (x
= 0; x
< s
->width
; x
++) {
1027 console_clear_xy(s
, x
, y
);
1034 switch (s
->esc_params
[0]) {
1037 for(x
= s
->x
; x
< s
->width
; x
++) {
1038 console_clear_xy(s
, x
, s
->y
);
1042 /* clear from beginning of line */
1043 for (x
= 0; x
<= s
->x
; x
++) {
1044 console_clear_xy(s
, x
, s
->y
);
1048 /* clear entire line */
1049 for(x
= 0; x
< s
->width
; x
++) {
1050 console_clear_xy(s
, x
, s
->y
);
1056 console_handle_escape(s
);
1059 /* report cursor position */
1060 /* TODO: send ESC[row;colR */
1063 /* save cursor position */
1068 /* restore cursor position */
1073 #ifdef DEBUG_CONSOLE
1074 fprintf(stderr
, "unhandled escape character '%c'\n", ch
);
1083 void console_select(unsigned int index
)
1087 if (index
>= MAX_CONSOLES
)
1089 if (active_console
) {
1090 active_console
->g_width
= ds_get_width(active_console
->ds
);
1091 active_console
->g_height
= ds_get_height(active_console
->ds
);
1093 s
= consoles
[index
];
1095 DisplayState
*ds
= s
->ds
;
1097 if (active_console
&& active_console
->cursor_timer
) {
1098 qemu_del_timer(active_console
->cursor_timer
);
1102 DisplaySurface
*surface
;
1103 surface
= qemu_create_displaysurface(s
->g_width
, s
->g_height
);
1104 dpy_gfx_replace_surface(s
, surface
);
1106 if (ds
->have_text
) {
1107 dpy_text_resize(s
, s
->width
, s
->height
);
1109 if (s
->cursor_timer
) {
1110 qemu_mod_timer(s
->cursor_timer
,
1111 qemu_get_clock_ms(rt_clock
) + CONSOLE_CURSOR_PERIOD
/ 2);
1113 vga_hw_invalidate();
1117 static int console_puts(CharDriverState
*chr
, const uint8_t *buf
, int len
)
1119 QemuConsole
*s
= chr
->opaque
;
1122 s
->update_x0
= s
->width
* FONT_WIDTH
;
1123 s
->update_y0
= s
->height
* FONT_HEIGHT
;
1126 console_show_cursor(s
, 0);
1127 for(i
= 0; i
< len
; i
++) {
1128 console_putchar(s
, buf
[i
]);
1130 console_show_cursor(s
, 1);
1131 if (s
->ds
->have_gfx
&& s
->update_x0
< s
->update_x1
) {
1132 dpy_gfx_update(s
, s
->update_x0
, s
->update_y0
,
1133 s
->update_x1
- s
->update_x0
,
1134 s
->update_y1
- s
->update_y0
);
1139 static void kbd_send_chars(void *opaque
)
1141 QemuConsole
*s
= opaque
;
1145 len
= qemu_chr_be_can_write(s
->chr
);
1146 if (len
> s
->out_fifo
.count
)
1147 len
= s
->out_fifo
.count
;
1149 if (len
> sizeof(buf
))
1151 qemu_fifo_read(&s
->out_fifo
, buf
, len
);
1152 qemu_chr_be_write(s
->chr
, buf
, len
);
1154 /* characters are pending: we send them a bit later (XXX:
1155 horrible, should change char device API) */
1156 if (s
->out_fifo
.count
> 0) {
1157 qemu_mod_timer(s
->kbd_timer
, qemu_get_clock_ms(rt_clock
) + 1);
1161 /* called when an ascii key is pressed */
1162 void kbd_put_keysym(int keysym
)
1165 uint8_t buf
[16], *q
;
1169 if (!s
|| (s
->console_type
== GRAPHIC_CONSOLE
))
1173 case QEMU_KEY_CTRL_UP
:
1176 case QEMU_KEY_CTRL_DOWN
:
1179 case QEMU_KEY_CTRL_PAGEUP
:
1180 console_scroll(-10);
1182 case QEMU_KEY_CTRL_PAGEDOWN
:
1186 /* convert the QEMU keysym to VT100 key string */
1188 if (keysym
>= 0xe100 && keysym
<= 0xe11f) {
1191 c
= keysym
- 0xe100;
1193 *q
++ = '0' + (c
/ 10);
1194 *q
++ = '0' + (c
% 10);
1196 } else if (keysym
>= 0xe120 && keysym
<= 0xe17f) {
1199 *q
++ = keysym
& 0xff;
1200 } else if (s
->echo
&& (keysym
== '\r' || keysym
== '\n')) {
1201 console_puts(s
->chr
, (const uint8_t *) "\r", 1);
1207 console_puts(s
->chr
, buf
, q
- buf
);
1209 if (s
->chr
->chr_read
) {
1210 qemu_fifo_write(&s
->out_fifo
, buf
, q
- buf
);
1217 static void text_console_invalidate(void *opaque
)
1219 QemuConsole
*s
= (QemuConsole
*) opaque
;
1220 if (!ds_get_bits_per_pixel(s
->ds
) && s
->console_type
== TEXT_CONSOLE
) {
1221 s
->g_width
= ds_get_width(s
->ds
);
1222 s
->g_height
= ds_get_height(s
->ds
);
1223 text_console_resize(s
);
1228 static void text_console_update(void *opaque
, console_ch_t
*chardata
)
1230 QemuConsole
*s
= (QemuConsole
*) opaque
;
1233 if (s
->text_x
[0] <= s
->text_x
[1]) {
1234 src
= (s
->y_base
+ s
->text_y
[0]) * s
->width
;
1235 chardata
+= s
->text_y
[0] * s
->width
;
1236 for (i
= s
->text_y
[0]; i
<= s
->text_y
[1]; i
++)
1237 for (j
= 0; j
< s
->width
; j
++, src
++)
1238 console_write_ch(chardata
++, s
->cells
[src
].ch
|
1239 (s
->cells
[src
].t_attrib
.fgcol
<< 12) |
1240 (s
->cells
[src
].t_attrib
.bgcol
<< 8) |
1241 (s
->cells
[src
].t_attrib
.bold
<< 21));
1242 dpy_text_update(s
, s
->text_x
[0], s
->text_y
[0],
1243 s
->text_x
[1] - s
->text_x
[0], i
- s
->text_y
[0]);
1244 s
->text_x
[0] = s
->width
;
1245 s
->text_y
[0] = s
->height
;
1249 if (s
->cursor_invalidate
) {
1250 dpy_text_cursor(s
, s
->x
, s
->y
);
1251 s
->cursor_invalidate
= 0;
1255 static QemuConsole
*new_console(DisplayState
*ds
, console_type_t console_type
)
1260 if (nb_consoles
>= MAX_CONSOLES
)
1262 s
= g_malloc0(sizeof(QemuConsole
));
1263 if (!active_console
|| ((active_console
->console_type
!= GRAPHIC_CONSOLE
) &&
1264 (console_type
== GRAPHIC_CONSOLE
))) {
1268 s
->console_type
= console_type
;
1269 if (console_type
!= GRAPHIC_CONSOLE
) {
1270 s
->index
= nb_consoles
;
1271 consoles
[nb_consoles
++] = s
;
1273 /* HACK: Put graphical consoles before text consoles. */
1274 for (i
= nb_consoles
; i
> 0; i
--) {
1275 if (consoles
[i
- 1]->console_type
== GRAPHIC_CONSOLE
)
1277 consoles
[i
] = consoles
[i
- 1];
1278 consoles
[i
]->index
= i
;
1287 static void qemu_alloc_display(DisplaySurface
*surface
, int width
, int height
,
1288 int linesize
, PixelFormat pf
, int newflags
)
1292 qemu_pixman_image_unref(surface
->image
);
1293 surface
->image
= NULL
;
1295 surface
->format
= qemu_pixman_get_format(&pf
);
1296 assert(surface
->format
!= 0);
1297 surface
->image
= pixman_image_create_bits(surface
->format
,
1300 assert(surface
->image
!= NULL
);
1302 surface
->flags
= newflags
| QEMU_ALLOCATED_FLAG
;
1303 #ifdef HOST_WORDS_BIGENDIAN
1304 surface
->flags
|= QEMU_BIG_ENDIAN_FLAG
;
1308 DisplaySurface
*qemu_create_displaysurface(int width
, int height
)
1310 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1311 int linesize
= width
* 4;
1313 trace_displaysurface_create(surface
, width
, height
);
1314 qemu_alloc_display(surface
, width
, height
, linesize
,
1315 qemu_default_pixelformat(32), 0);
1319 DisplaySurface
*qemu_create_displaysurface_from(int width
, int height
, int bpp
,
1320 int linesize
, uint8_t *data
,
1323 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1325 trace_displaysurface_create_from(surface
, width
, height
, bpp
, byteswap
);
1327 surface
->pf
= qemu_different_endianness_pixelformat(bpp
);
1329 surface
->pf
= qemu_default_pixelformat(bpp
);
1332 surface
->format
= qemu_pixman_get_format(&surface
->pf
);
1333 assert(surface
->format
!= 0);
1334 surface
->image
= pixman_image_create_bits(surface
->format
,
1336 (void *)data
, linesize
);
1337 assert(surface
->image
!= NULL
);
1339 #ifdef HOST_WORDS_BIGENDIAN
1340 surface
->flags
= QEMU_BIG_ENDIAN_FLAG
;
1346 void qemu_free_displaysurface(DisplaySurface
*surface
)
1348 if (surface
== NULL
) {
1351 trace_displaysurface_free(surface
);
1352 qemu_pixman_image_unref(surface
->image
);
1356 void register_displaychangelistener(DisplayState
*ds
,
1357 DisplayChangeListener
*dcl
)
1359 trace_displaychangelistener_register(dcl
, dcl
->ops
->dpy_name
);
1361 QLIST_INSERT_HEAD(&ds
->listeners
, dcl
, next
);
1362 gui_setup_refresh(ds
);
1363 if (dcl
->ops
->dpy_gfx_switch
) {
1364 dcl
->ops
->dpy_gfx_switch(dcl
, ds
->surface
);
1368 void unregister_displaychangelistener(DisplayChangeListener
*dcl
)
1370 DisplayState
*ds
= dcl
->ds
;
1371 trace_displaychangelistener_unregister(dcl
, dcl
->ops
->dpy_name
);
1372 QLIST_REMOVE(dcl
, next
);
1373 gui_setup_refresh(ds
);
1376 void dpy_gfx_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1378 DisplayState
*s
= con
->ds
;
1379 struct DisplayChangeListener
*dcl
;
1380 int width
= pixman_image_get_width(s
->surface
->image
);
1381 int height
= pixman_image_get_height(s
->surface
->image
);
1387 w
= MIN(w
, width
- x
);
1388 h
= MIN(h
, height
- y
);
1390 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1391 if (dcl
->ops
->dpy_gfx_update
) {
1392 dcl
->ops
->dpy_gfx_update(dcl
, x
, y
, w
, h
);
1397 void dpy_gfx_replace_surface(QemuConsole
*con
,
1398 DisplaySurface
*surface
)
1400 DisplayState
*s
= con
->ds
;
1401 DisplaySurface
*old_surface
= s
->surface
;
1402 struct DisplayChangeListener
*dcl
;
1404 s
->surface
= surface
;
1405 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1406 if (dcl
->ops
->dpy_gfx_switch
) {
1407 dcl
->ops
->dpy_gfx_switch(dcl
, surface
);
1410 qemu_free_displaysurface(old_surface
);
1413 void dpy_refresh(DisplayState
*s
)
1415 struct DisplayChangeListener
*dcl
;
1416 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1417 if (dcl
->ops
->dpy_refresh
) {
1418 dcl
->ops
->dpy_refresh(dcl
);
1423 void dpy_gfx_copy(QemuConsole
*con
, int src_x
, int src_y
,
1424 int dst_x
, int dst_y
, int w
, int h
)
1426 DisplayState
*s
= con
->ds
;
1427 struct DisplayChangeListener
*dcl
;
1428 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1429 if (dcl
->ops
->dpy_gfx_copy
) {
1430 dcl
->ops
->dpy_gfx_copy(dcl
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1432 dcl
->ops
->dpy_gfx_update(dcl
, dst_x
, dst_y
, w
, h
);
1437 void dpy_text_cursor(QemuConsole
*con
, int x
, int y
)
1439 DisplayState
*s
= con
->ds
;
1440 struct DisplayChangeListener
*dcl
;
1441 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1442 if (dcl
->ops
->dpy_text_cursor
) {
1443 dcl
->ops
->dpy_text_cursor(dcl
, x
, y
);
1448 void dpy_text_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1450 DisplayState
*s
= con
->ds
;
1451 struct DisplayChangeListener
*dcl
;
1452 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1453 if (dcl
->ops
->dpy_text_update
) {
1454 dcl
->ops
->dpy_text_update(dcl
, x
, y
, w
, h
);
1459 void dpy_text_resize(QemuConsole
*con
, int w
, int h
)
1461 DisplayState
*s
= con
->ds
;
1462 struct DisplayChangeListener
*dcl
;
1463 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1464 if (dcl
->ops
->dpy_text_resize
) {
1465 dcl
->ops
->dpy_text_resize(dcl
, w
, h
);
1470 void dpy_mouse_set(QemuConsole
*con
, int x
, int y
, int on
)
1472 DisplayState
*s
= con
->ds
;
1473 struct DisplayChangeListener
*dcl
;
1474 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1475 if (dcl
->ops
->dpy_mouse_set
) {
1476 dcl
->ops
->dpy_mouse_set(dcl
, x
, y
, on
);
1481 void dpy_cursor_define(QemuConsole
*con
, QEMUCursor
*cursor
)
1483 DisplayState
*s
= con
->ds
;
1484 struct DisplayChangeListener
*dcl
;
1485 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1486 if (dcl
->ops
->dpy_cursor_define
) {
1487 dcl
->ops
->dpy_cursor_define(dcl
, cursor
);
1492 bool dpy_cursor_define_supported(QemuConsole
*con
)
1494 DisplayState
*s
= con
->ds
;
1495 struct DisplayChangeListener
*dcl
;
1496 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1497 if (dcl
->ops
->dpy_cursor_define
) {
1504 static void dumb_display_init(void)
1506 DisplayState
*ds
= g_malloc0(sizeof(DisplayState
));
1510 if (is_fixedsize_console()) {
1511 width
= active_console
->g_width
;
1512 height
= active_console
->g_height
;
1514 ds
->surface
= qemu_create_displaysurface(width
, height
);
1516 register_displaystate(ds
);
1519 /***********************************************************/
1520 /* register display */
1522 void register_displaystate(DisplayState
*ds
)
1532 DisplayState
*get_displaystate(void)
1534 if (!display_state
) {
1535 dumb_display_init ();
1537 return display_state
;
1540 QemuConsole
*graphic_console_init(vga_hw_update_ptr update
,
1541 vga_hw_invalidate_ptr invalidate
,
1542 vga_hw_screen_dump_ptr screen_dump
,
1543 vga_hw_text_update_ptr text_update
,
1549 ds
= (DisplayState
*) g_malloc0(sizeof(DisplayState
));
1550 s
= new_console(ds
, GRAPHIC_CONSOLE
);
1551 s
->hw_update
= update
;
1552 s
->hw_invalidate
= invalidate
;
1553 s
->hw_screen_dump
= screen_dump
;
1554 s
->hw_text_update
= text_update
;
1557 ds
->surface
= qemu_create_displaysurface(640, 480);
1559 register_displaystate(ds
);
1563 int is_graphic_console(void)
1565 return active_console
&& active_console
->console_type
== GRAPHIC_CONSOLE
;
1568 int is_fixedsize_console(void)
1570 return active_console
&& active_console
->console_type
!= TEXT_CONSOLE
;
1573 void console_color_init(DisplayState
*ds
)
1576 for (j
= 0; j
< 2; j
++) {
1577 for (i
= 0; i
< 8; i
++) {
1578 color_table
[j
][i
] = col_expand(ds
,
1579 vga_get_color(ds
, color_table_rgb
[j
][i
]));
1584 static void text_console_set_echo(CharDriverState
*chr
, bool echo
)
1586 QemuConsole
*s
= chr
->opaque
;
1591 static void text_console_update_cursor(void *opaque
)
1593 QemuConsole
*s
= opaque
;
1595 s
->cursor_visible_phase
= !s
->cursor_visible_phase
;
1596 vga_hw_invalidate();
1597 qemu_mod_timer(s
->cursor_timer
,
1598 qemu_get_clock_ms(rt_clock
) + CONSOLE_CURSOR_PERIOD
/ 2);
1601 static void text_console_do_init(CharDriverState
*chr
, DisplayState
*ds
)
1604 static int color_inited
;
1608 chr
->chr_write
= console_puts
;
1610 s
->out_fifo
.buf
= s
->out_fifo_buf
;
1611 s
->out_fifo
.buf_size
= sizeof(s
->out_fifo_buf
);
1612 s
->kbd_timer
= qemu_new_timer_ms(rt_clock
, kbd_send_chars
, s
);
1615 if (!color_inited
) {
1617 console_color_init(s
->ds
);
1621 s
->total_height
= DEFAULT_BACKSCROLL
;
1624 if (s
->console_type
== TEXT_CONSOLE
) {
1625 s
->g_width
= ds_get_width(s
->ds
);
1626 s
->g_height
= ds_get_height(s
->ds
);
1630 qemu_new_timer_ms(rt_clock
, text_console_update_cursor
, s
);
1632 s
->hw_invalidate
= text_console_invalidate
;
1633 s
->hw_text_update
= text_console_update
;
1636 /* Set text attribute defaults */
1637 s
->t_attrib_default
.bold
= 0;
1638 s
->t_attrib_default
.uline
= 0;
1639 s
->t_attrib_default
.blink
= 0;
1640 s
->t_attrib_default
.invers
= 0;
1641 s
->t_attrib_default
.unvisible
= 0;
1642 s
->t_attrib_default
.fgcol
= COLOR_WHITE
;
1643 s
->t_attrib_default
.bgcol
= COLOR_BLACK
;
1644 /* set current text attributes to default */
1645 s
->t_attrib
= s
->t_attrib_default
;
1646 text_console_resize(s
);
1652 s
->t_attrib
.bgcol
= COLOR_BLUE
;
1653 len
= snprintf(msg
, sizeof(msg
), "%s console\r\n", chr
->label
);
1654 console_puts(chr
, (uint8_t*)msg
, len
);
1655 s
->t_attrib
= s
->t_attrib_default
;
1658 qemu_chr_generic_open(chr
);
1663 static CharDriverState
*text_console_init(ChardevVC
*vc
)
1665 CharDriverState
*chr
;
1668 unsigned height
= 0;
1670 chr
= g_malloc0(sizeof(CharDriverState
));
1672 if (vc
->has_width
) {
1674 } else if (vc
->has_cols
) {
1675 width
= vc
->cols
* FONT_WIDTH
;
1678 if (vc
->has_height
) {
1679 height
= vc
->height
;
1680 } else if (vc
->has_rows
) {
1681 height
= vc
->rows
* FONT_HEIGHT
;
1684 if (width
== 0 || height
== 0) {
1685 s
= new_console(NULL
, TEXT_CONSOLE
);
1687 s
= new_console(NULL
, TEXT_CONSOLE_FIXED_SIZE
);
1697 s
->g_height
= height
;
1699 chr
->chr_set_echo
= text_console_set_echo
;
1703 static VcHandler
*vc_handler
= text_console_init
;
1705 CharDriverState
*vc_init(ChardevVC
*vc
)
1707 return vc_handler(vc
);
1710 void register_vc_handler(VcHandler
*handler
)
1712 vc_handler
= handler
;
1715 void text_consoles_set_display(DisplayState
*ds
)
1719 for (i
= 0; i
< nb_consoles
; i
++) {
1720 if (consoles
[i
]->console_type
!= GRAPHIC_CONSOLE
) {
1721 text_console_do_init(consoles
[i
]->chr
, ds
);
1726 void qemu_console_resize(QemuConsole
*s
, int width
, int height
)
1729 s
->g_height
= height
;
1730 if (is_graphic_console()) {
1731 DisplaySurface
*surface
;
1732 surface
= qemu_create_displaysurface(width
, height
);
1733 dpy_gfx_replace_surface(s
, surface
);
1737 void qemu_console_copy(QemuConsole
*con
, int src_x
, int src_y
,
1738 int dst_x
, int dst_y
, int w
, int h
)
1740 if (is_graphic_console()) {
1741 dpy_gfx_copy(con
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1745 DisplaySurface
*qemu_console_surface(QemuConsole
*console
)
1747 return console
->ds
->surface
;
1750 DisplayState
*qemu_console_displaystate(QemuConsole
*console
)
1755 PixelFormat
qemu_different_endianness_pixelformat(int bpp
)
1759 memset(&pf
, 0x00, sizeof(PixelFormat
));
1761 pf
.bits_per_pixel
= bpp
;
1762 pf
.bytes_per_pixel
= DIV_ROUND_UP(bpp
, 8);
1763 pf
.depth
= bpp
== 32 ? 24 : bpp
;
1767 pf
.rmask
= 0x000000FF;
1768 pf
.gmask
= 0x0000FF00;
1769 pf
.bmask
= 0x00FF0000;
1781 pf
.rmask
= 0x0000FF00;
1782 pf
.gmask
= 0x00FF0000;
1783 pf
.bmask
= 0xFF000000;
1784 pf
.amask
= 0x00000000;
1804 PixelFormat
qemu_default_pixelformat(int bpp
)
1808 memset(&pf
, 0x00, sizeof(PixelFormat
));
1810 pf
.bits_per_pixel
= bpp
;
1811 pf
.bytes_per_pixel
= DIV_ROUND_UP(bpp
, 8);
1812 pf
.depth
= bpp
== 32 ? 24 : bpp
;
1816 pf
.bits_per_pixel
= 16;
1817 pf
.rmask
= 0x00007c00;
1818 pf
.gmask
= 0x000003E0;
1819 pf
.bmask
= 0x0000001F;
1831 pf
.rmask
= 0x0000F800;
1832 pf
.gmask
= 0x000007E0;
1833 pf
.bmask
= 0x0000001F;
1845 pf
.rmask
= 0x00FF0000;
1846 pf
.gmask
= 0x0000FF00;
1847 pf
.bmask
= 0x000000FF;
1859 pf
.rmask
= 0x00FF0000;
1860 pf
.gmask
= 0x0000FF00;
1861 pf
.bmask
= 0x000000FF;
1878 static void qemu_chr_parse_vc(QemuOpts
*opts
, ChardevBackend
*backend
,
1883 backend
->vc
= g_new0(ChardevVC
, 1);
1885 val
= qemu_opt_get_number(opts
, "width", 0);
1887 backend
->vc
->has_width
= true;
1888 backend
->vc
->width
= val
;
1891 val
= qemu_opt_get_number(opts
, "height", 0);
1893 backend
->vc
->has_height
= true;
1894 backend
->vc
->height
= val
;
1897 val
= qemu_opt_get_number(opts
, "cols", 0);
1899 backend
->vc
->has_cols
= true;
1900 backend
->vc
->cols
= val
;
1903 val
= qemu_opt_get_number(opts
, "rows", 0);
1905 backend
->vc
->has_rows
= true;
1906 backend
->vc
->rows
= val
;
1910 static void register_types(void)
1912 register_char_driver_qapi("vc", CHARDEV_BACKEND_KIND_VC
,
1916 type_init(register_types
);