~vcs-imports/qemu/git

« back to all changes in this revision

Viewing changes to console.c

  • Committer: ths
  • Date: 2007-09-16 21:08:06 UTC
  • Revision ID: git-v1:5fafdf24ef2c090c164d4dc89684b3f379dbdd87
find -type f | xargs sed -i 's/[\t ]$//g' # on most files


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3173 c046a42c-6fe2-441c-8c8c-71466251a162

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
 * THE SOFTWARE.
23
23
 */
24
 
#include "qemu-common.h"
25
 
#include "console.h"
26
 
#include "qemu-timer.h"
 
24
#include "vl.h"
27
25
 
28
26
//#define DEBUG_CONSOLE
29
27
#define DEFAULT_BACKSCROLL 512
30
28
#define MAX_CONSOLES 12
31
 
#define DEFAULT_MONITOR_SIZE "800x600"
32
29
 
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)
62
59
    int count, wptr, rptr;
63
60
} QEMUFIFO;
64
61
 
65
 
static int qemu_fifo_write(QEMUFIFO *f, const uint8_t *buf, int len1)
 
62
int qemu_fifo_write(QEMUFIFO *f, const uint8_t *buf, int len1)
66
63
{
67
64
    int l, len;
68
65
 
85
82
    return len1;
86
83
}
87
84
 
88
 
static int qemu_fifo_read(QEMUFIFO *f, uint8_t *buf, int len1)
 
85
int qemu_fifo_read(QEMUFIFO *f, uint8_t *buf, int len1)
89
86
{
90
87
    int l, len;
91
88
 
122
119
    vga_hw_update_ptr hw_update;
123
120
    vga_hw_invalidate_ptr hw_invalidate;
124
121
    vga_hw_screen_dump_ptr hw_screen_dump;
125
 
    vga_hw_text_update_ptr hw_text_update;
126
122
    void *hw;
127
123
 
128
124
    int g_width, g_height;
137
133
    TextAttributes t_attrib_default; /* default text attributes */
138
134
    TextAttributes t_attrib; /* currently active text attributes */
139
135
    TextCell *cells;
140
 
    int text_x[2], text_y[2], cursor_invalidate;
141
136
 
142
137
    enum TTYState state;
143
138
    int esc_params[MAX_ESC_PARAMS];
168
163
 
169
164
void vga_hw_screen_dump(const char *filename)
170
165
{
171
 
    TextConsole *previous_active_console;
172
 
 
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;
180
 
}
181
 
 
182
 
void vga_hw_text_update(console_ch_t *chardata)
183
 
{
184
 
    if (active_console && active_console->hw_text_update)
185
 
        active_console->hw_text_update(active_console->hw, chardata);
186
170
}
187
171
 
188
172
/* convert a RGBA color to a color index usable in graphic primitives */
226
210
{
227
211
    uint8_t *d, *d1;
228
212
    int x, y, bpp;
229
 
 
 
213
   
230
214
    bpp = (ds->depth + 7) >> 3;
231
215
    d1 = ds->data +
232
216
        ds->linesize * posy + bpp * posx;
525
509
            c++;
526
510
        }
527
511
    }
528
 
    qemu_free(s->cells);
 
512
    free(s->cells);
529
513
    s->cells = cells;
530
514
}
531
515
 
532
 
static inline void text_update_xy(TextConsole *s, int x, int y)
533
 
{
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);
538
 
}
539
 
 
540
516
static void update_xy(TextConsole *s, int x, int y)
541
517
{
542
518
    TextCell *c;
543
519
    int y1, y2;
544
520
 
545
521
    if (s == active_console) {
546
 
        if (!s->ds->depth) {
547
 
            text_update_xy(s, x, y);
548
 
            return;
549
 
        }
550
 
 
551
522
        y1 = (s->y_base + y) % s->total_height;
552
523
        y2 = y1 - s->y_displayed;
553
524
        if (y2 < 0)
569
540
 
570
541
    if (s == active_console) {
571
542
        int x = s->x;
572
 
 
573
 
        if (!s->ds->depth) {
574
 
            s->cursor_invalidate = 1;
575
 
            return;
576
 
        }
577
 
 
578
543
        if (x >= s->width) {
579
544
            x = s->width - 1;
580
545
        }
604
569
 
605
570
    if (s != active_console)
606
571
        return;
607
 
    if (!s->ds->depth) {
608
 
        s->text_x[0] = 0;
609
 
        s->text_y[0] = 0;
610
 
        s->text_x[1] = s->width - 1;
611
 
        s->text_y[1] = s->height - 1;
612
 
        s->cursor_invalidate = 1;
613
 
        return;
614
 
    }
615
572
 
616
573
    vga_fill_rect(s->ds, 0, 0, s->ds->width, s->ds->height,
617
574
                  color_table[0][COLOR_BLACK]);
634
591
{
635
592
    TextConsole *s;
636
593
    int i, y1;
637
 
 
 
594
   
638
595
    s = active_console;
639
596
    if (!s || (s->console_type == GRAPHIC_CONSOLE))
640
597
        return;
689
646
            c++;
690
647
        }
691
648
        if (s == active_console && s->y_displayed == s->y_base) {
692
 
            if (!s->ds->depth) {
693
 
                s->text_x[0] = 0;
694
 
                s->text_y[0] = 0;
695
 
                s->text_x[1] = s->width - 1;
696
 
                s->text_y[1] = s->height - 1;
697
 
                return;
698
 
            }
699
 
 
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];
1048
997
    if (s) {
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);
 
1004
                } else {
 
1005
                s->g_width = s->ds->width;
 
1006
                s->g_height = s->ds->height;
 
1007
                text_console_resize(s);
 
1008
            }
 
1009
            }
 
1010
            console_refresh(s);
 
1011
        } else {
 
1012
            vga_hw_invalidate();
 
1013
        }
1054
1014
    }
1055
1015
}
1056
1016
 
1087
1047
    TextConsole *s = opaque;
1088
1048
    int len;
1089
1049
    uint8_t buf[16];
1090
 
 
 
1050
   
1091
1051
    len = qemu_chr_can_read(s->chr);
1092
1052
    if (len > s->out_fifo.count)
1093
1053
        len = s->out_fifo.count;
1154
1114
    }
1155
1115
}
1156
1116
 
1157
 
static void text_console_invalidate(void *opaque)
1158
 
{
1159
 
    TextConsole *s = (TextConsole *) opaque;
1160
 
 
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);
1164
 
        else {
1165
 
            s->g_width = s->ds->width;
1166
 
            s->g_height = s->ds->height;
1167
 
            text_console_resize(s);
1168
 
        }
1169
 
    }
1170
 
    console_refresh(s);
1171
 
}
1172
 
 
1173
 
static void text_console_update(void *opaque, console_ch_t *chardata)
1174
 
{
1175
 
    TextConsole *s = (TextConsole *) opaque;
1176
 
    int i, j, src;
1177
 
 
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;
1191
 
        s->text_x[1] = 0;
1192
 
        s->text_y[1] = 0;
1193
 
    }
1194
 
    if (s->cursor_invalidate) {
1195
 
        dpy_cursor(s->ds, s->x, s->y);
1196
 
        s->cursor_invalidate = 0;
1197
 
    }
1198
 
}
1199
 
 
1200
1117
static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
1201
1118
{
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,
1235
1151
                                  void *opaque)
1236
1152
{
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;
1247
1162
    return s;
1248
1163
}
1249
1164
 
1250
1165
int is_graphic_console(void)
1251
1166
{
1252
 
    return active_console && active_console->console_type == GRAPHIC_CONSOLE;
1253
 
}
1254
 
 
1255
 
int is_fixedsize_console(void)
1256
 
{
1257
 
    return active_console && active_console->console_type != TEXT_CONSOLE;
1258
 
}
1259
 
 
1260
 
void console_color_init(DisplayState *ds)
1261
 
{
1262
 
    int i, j;
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]));
1267
 
        }
1268
 
    }
 
1167
    return active_console->console_type == GRAPHIC_CONSOLE;
1269
1168
}
1270
1169
 
1271
1170
CharDriverState *text_console_init(DisplayState *ds, const char *p)
1272
1171
{
1273
1172
    CharDriverState *chr;
1274
1173
    TextConsole *s;
 
1174
    int i,j;
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);
1295
 
 
 
1195
   
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]));
 
1202
            }
 
1203
        }
1299
1204
    }
1300
1205
    s->y_displayed = 0;
1301
1206
    s->y_base = 0;
1322
1227
    s->g_width = width;
1323
1228
    s->g_height = height;
1324
1229
 
1325
 
    s->hw_invalidate = text_console_invalidate;
1326
 
    s->hw_text_update = text_console_update;
1327
 
    s->hw = s;
1328
 
 
1329
1230
    /* Set text attribute defaults */
1330
1231
    s->t_attrib_default.bold = 0;
1331
1232
    s->t_attrib_default.uline = 0;
1343
1244
 
1344
1245
    return chr;
1345
1246
}
1346
 
 
1347
 
void qemu_console_resize(QEMUConsole *console, int width, int height)
1348
 
{
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);
1355
 
        }
1356
 
    }
1357
 
}
1358
 
 
1359
 
void qemu_console_copy(QEMUConsole *console, int src_x, int src_y,
1360
 
                int dst_x, int dst_y, int w, int h)
1361
 
{
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);
1366
 
        else {
1367
 
            /* TODO */
1368
 
            console->ds->dpy_update(console->ds, dst_x, dst_y, w, h);
1369
 
        }
1370
 
    }
1371
 
}