21
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
#include "qemu-common.h"
26
#include "qemu-timer.h"
28
26
//#define DEBUG_CONSOLE
29
27
#define DEFAULT_BACKSCROLL 512
30
28
#define MAX_CONSOLES 12
31
#define DEFAULT_MONITOR_SIZE "800x600"
33
30
#define QEMU_RGBA(r, g, b, a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
34
31
#define QEMU_RGB(r, g, b) QEMU_RGBA(r, g, b, 0xff)
137
133
TextAttributes t_attrib_default; /* default text attributes */
138
134
TextAttributes t_attrib; /* currently active text attributes */
140
int text_x[2], text_y[2], cursor_invalidate;
142
137
enum TTYState state;
143
138
int esc_params[MAX_ESC_PARAMS];
169
164
void vga_hw_screen_dump(const char *filename)
171
TextConsole *previous_active_console;
173
previous_active_console = active_console;
174
active_console = consoles[0];
175
/* There is currently no way of specifying which screen we want to dump,
176
so always dump the first one. */
166
/* There is currently no was of specifying which screen we want to dump,
167
so always dump the dirst one. */
177
168
if (consoles[0]->hw_screen_dump)
178
169
consoles[0]->hw_screen_dump(consoles[0]->hw, filename);
179
active_console = previous_active_console;
182
void vga_hw_text_update(console_ch_t *chardata)
184
if (active_console && active_console->hw_text_update)
185
active_console->hw_text_update(active_console->hw, chardata);
188
172
/* convert a RGBA color to a color index usable in graphic primitives */
529
513
s->cells = cells;
532
static inline void text_update_xy(TextConsole *s, int x, int y)
534
s->text_x[0] = MIN(s->text_x[0], x);
535
s->text_x[1] = MAX(s->text_x[1], x);
536
s->text_y[0] = MIN(s->text_y[0], y);
537
s->text_y[1] = MAX(s->text_y[1], y);
540
516
static void update_xy(TextConsole *s, int x, int y)
545
521
if (s == active_console) {
547
text_update_xy(s, x, y);
551
522
y1 = (s->y_base + y) % s->total_height;
552
523
y2 = y1 - s->y_displayed;
605
570
if (s != active_console)
610
s->text_x[1] = s->width - 1;
611
s->text_y[1] = s->height - 1;
612
s->cursor_invalidate = 1;
616
573
vga_fill_rect(s->ds, 0, 0, s->ds->width, s->ds->height,
617
574
color_table[0][COLOR_BLACK]);
691
648
if (s == active_console && s->y_displayed == s->y_base) {
695
s->text_x[1] = s->width - 1;
696
s->text_y[1] = s->height - 1;
700
649
vga_bitblt(s->ds, 0, FONT_HEIGHT, 0, 0,
701
650
s->width * FONT_WIDTH,
702
651
(s->height - 1) * FONT_HEIGHT);
1047
996
s = consoles[index];
1049
998
active_console = s;
1050
if (s->console_type != TEXT_CONSOLE && s->g_width && s->g_height
1051
&& (s->g_width != s->ds->width || s->g_height != s->ds->height))
1052
dpy_resize(s->ds, s->g_width, s->g_height);
1053
vga_hw_invalidate();
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();
1157
static void text_console_invalidate(void *opaque)
1159
TextConsole *s = (TextConsole *) opaque;
1161
if (s->g_width != s->ds->width || s->g_height != s->ds->height) {
1162
if (s->console_type == TEXT_CONSOLE_FIXED_SIZE)
1163
dpy_resize(s->ds, s->g_width, s->g_height);
1165
s->g_width = s->ds->width;
1166
s->g_height = s->ds->height;
1167
text_console_resize(s);
1173
static void text_console_update(void *opaque, console_ch_t *chardata)
1175
TextConsole *s = (TextConsole *) opaque;
1178
if (s->text_x[0] <= s->text_x[1]) {
1179
src = (s->y_base + s->text_y[0]) * s->width;
1180
chardata += s->text_y[0] * s->width;
1181
for (i = s->text_y[0]; i <= s->text_y[1]; i ++)
1182
for (j = 0; j < s->width; j ++, src ++)
1183
console_write_ch(chardata ++, s->cells[src].ch |
1184
(s->cells[src].t_attrib.fgcol << 12) |
1185
(s->cells[src].t_attrib.bgcol << 8) |
1186
(s->cells[src].t_attrib.bold << 21));
1187
dpy_update(s->ds, s->text_x[0], s->text_y[0],
1188
s->text_x[1] - s->text_x[0], i - s->text_y[0]);
1189
s->text_x[0] = s->width;
1190
s->text_y[0] = s->height;
1194
if (s->cursor_invalidate) {
1195
dpy_cursor(s->ds, s->x, s->y);
1196
s->cursor_invalidate = 0;
1200
1117
static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
1202
1119
TextConsole *s;
1231
1148
TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
1232
1149
vga_hw_invalidate_ptr invalidate,
1233
1150
vga_hw_screen_dump_ptr screen_dump,
1234
vga_hw_text_update_ptr text_update,
1237
1153
TextConsole *s;
1242
1158
s->hw_update = update;
1243
1159
s->hw_invalidate = invalidate;
1244
1160
s->hw_screen_dump = screen_dump;
1245
s->hw_text_update = text_update;
1246
1161
s->hw = opaque;
1250
1165
int is_graphic_console(void)
1252
return active_console && active_console->console_type == GRAPHIC_CONSOLE;
1255
int is_fixedsize_console(void)
1257
return active_console && active_console->console_type != TEXT_CONSOLE;
1260
void console_color_init(DisplayState *ds)
1263
for (j = 0; j < 2; j++) {
1264
for (i = 0; i < 8; i++) {
1265
color_table[j][i] = col_expand(ds,
1266
vga_get_color(ds, color_table_rgb[j][i]));
1167
return active_console->console_type == GRAPHIC_CONSOLE;
1271
1170
CharDriverState *text_console_init(DisplayState *ds, const char *p)
1273
1172
CharDriverState *chr;
1274
1173
TextConsole *s;
1275
1175
unsigned width;
1276
1176
unsigned height;
1277
1177
static int color_inited;
1292
1192
s->out_fifo.buf = s->out_fifo_buf;
1293
1193
s->out_fifo.buf_size = sizeof(s->out_fifo_buf);
1294
1194
s->kbd_timer = qemu_new_timer(rt_clock, kbd_send_chars, s);
1296
1196
if (!color_inited) {
1297
1197
color_inited = 1;
1298
console_color_init(s->ds);
1198
for(j = 0; j < 2; j++) {
1199
for(i = 0; i < 8; i++) {
1200
color_table[j][i] = col_expand(s->ds,
1201
vga_get_color(s->ds, color_table_rgb[j][i]));
1300
1205
s->y_displayed = 0;
1322
1227
s->g_width = width;
1323
1228
s->g_height = height;
1325
s->hw_invalidate = text_console_invalidate;
1326
s->hw_text_update = text_console_update;
1329
1230
/* Set text attribute defaults */
1330
1231
s->t_attrib_default.bold = 0;
1331
1232
s->t_attrib_default.uline = 0;
1347
void qemu_console_resize(QEMUConsole *console, int width, int height)
1349
if (console->g_width != width || console->g_height != height
1350
|| !console->ds->data) {
1351
console->g_width = width;
1352
console->g_height = height;
1353
if (active_console == console) {
1354
dpy_resize(console->ds, width, height);
1359
void qemu_console_copy(QEMUConsole *console, int src_x, int src_y,
1360
int dst_x, int dst_y, int w, int h)
1362
if (active_console == console) {
1363
if (console->ds->dpy_copy)
1364
console->ds->dpy_copy(console->ds,
1365
src_x, src_y, dst_x, dst_y, w, h);
1368
console->ds->dpy_update(console->ds, dst_x, dst_y, w, h);