/* * QEMU graphical console * * Copyright (c) 2004 Fabrice Bellard * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "vl.h" //#define DEBUG_CONSOLE #define DEFAULT_BACKSCROLL 512 #define MAX_CONSOLES 12 #define QEMU_RGBA(r, g, b, a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) #define QEMU_RGB(r, g, b) QEMU_RGBA(r, g, b, 0xff) typedef struct TextAttributes { uint8_t fgcol:4; uint8_t bgcol:4; uint8_t bold:1; uint8_t uline:1; uint8_t blink:1; uint8_t invers:1; uint8_t unvisible:1; } TextAttributes; typedef struct TextCell { uint8_t ch; TextAttributes t_attrib; } TextCell; #define MAX_ESC_PARAMS 3 enum TTYState { TTY_STATE_NORM, TTY_STATE_ESC, TTY_STATE_CSI, }; typedef struct QEMUFIFO { uint8_t *buf; int buf_size; int count, wptr, rptr; } QEMUFIFO; int qemu_fifo_write(QEMUFIFO *f, const uint8_t *buf, int len1) { int l, len; l = f->buf_size - f->count; if (len1 > l) len1 = l; len = len1; while (len > 0) { l = f->buf_size - f->wptr; if (l > len) l = len; memcpy(f->buf + f->wptr, buf, l); f->wptr += l; if (f->wptr >= f->buf_size) f->wptr = 0; buf += l; len -= l; } f->count += len1; return len1; } int qemu_fifo_read(QEMUFIFO *f, uint8_t *buf, int len1) { int l, len; if (len1 > f->count) len1 = f->count; len = len1; while (len > 0) { l = f->buf_size - f->rptr; if (l > len) l = len; memcpy(buf, f->buf + f->rptr, l); f->rptr += l; if (f->rptr >= f->buf_size) f->rptr = 0; buf += l; len -= l; } f->count -= len1; return len1; } /* ??? This is mis-named. It is used for both text and graphical consoles. */ struct TextConsole { int text_console; /* true if text console */ DisplayState *ds; /* Graphic console state. */ vga_hw_update_p