⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console.c.svn-base

📁 我们自己开发的一个OSEK操作系统!不知道可不可以?
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
#ifdef DEBUG_CONSOLE    printf("x: %2i y: %2i", x, y);    console_print_text_attributes(t_attrib, ch);#endif    if (t_attrib->invers) {        bgcol = color_table[t_attrib->bold][t_attrib->fgcol];        fgcol = color_table[t_attrib->bold][t_attrib->bgcol];    } else {        fgcol = color_table[t_attrib->bold][t_attrib->fgcol];        bgcol = color_table[t_attrib->bold][t_attrib->bgcol];    }    bpp = (ds->depth + 7) >> 3;    d = ds->data +        ds->linesize * y * FONT_HEIGHT + bpp * x * FONT_WIDTH;    linesize = ds->linesize;    font_ptr = vgafont16 + FONT_HEIGHT * ch;    xorcol = bgcol ^ fgcol;    switch(ds->depth) {    case 8:        for(i = 0; i < FONT_HEIGHT; i++) {            font_data = *font_ptr++;            if (t_attrib->uline                && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {                font_data = 0xFFFF;            }            ((uint32_t *)d)[0] = (dmask16[(font_data >> 4)] & xorcol) ^ bgcol;            ((uint32_t *)d)[1] = (dmask16[(font_data >> 0) & 0xf] & xorcol) ^ bgcol;            d += linesize;        }        break;    case 16:    case 15:        for(i = 0; i < FONT_HEIGHT; i++) {            font_data = *font_ptr++;            if (t_attrib->uline                && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {                font_data = 0xFFFF;            }            ((uint32_t *)d)[0] = (dmask4[(font_data >> 6)] & xorcol) ^ bgcol;            ((uint32_t *)d)[1] = (dmask4[(font_data >> 4) & 3] & xorcol) ^ bgcol;            ((uint32_t *)d)[2] = (dmask4[(font_data >> 2) & 3] & xorcol) ^ bgcol;            ((uint32_t *)d)[3] = (dmask4[(font_data >> 0) & 3] & xorcol) ^ bgcol;            d += linesize;        }        break;    case 32:        for(i = 0; i < FONT_HEIGHT; i++) {            font_data = *font_ptr++;            if (t_attrib->uline && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {                font_data = 0xFFFF;            }            ((uint32_t *)d)[0] = (-((font_data >> 7)) & xorcol) ^ bgcol;            ((uint32_t *)d)[1] = (-((font_data >> 6) & 1) & xorcol) ^ bgcol;            ((uint32_t *)d)[2] = (-((font_data >> 5) & 1) & xorcol) ^ bgcol;            ((uint32_t *)d)[3] = (-((font_data >> 4) & 1) & xorcol) ^ bgcol;            ((uint32_t *)d)[4] = (-((font_data >> 3) & 1) & xorcol) ^ bgcol;            ((uint32_t *)d)[5] = (-((font_data >> 2) & 1) & xorcol) ^ bgcol;            ((uint32_t *)d)[6] = (-((font_data >> 1) & 1) & xorcol) ^ bgcol;            ((uint32_t *)d)[7] = (-((font_data >> 0) & 1) & xorcol) ^ bgcol;            d += linesize;        }        break;    }}static void text_console_resize(TextConsole *s){    TextCell *cells, *c, *c1;    int w1, x, y, last_width;    last_width = s->width;    s->width = s->g_width / FONT_WIDTH;    s->height = s->g_height / FONT_HEIGHT;    w1 = last_width;    if (s->width < w1)        w1 = s->width;    cells = qemu_malloc(s->width * s->total_height * sizeof(TextCell));    for(y = 0; y < s->total_height; y++) {        c = &cells[y * s->width];        if (w1 > 0) {            c1 = &s->cells[y * last_width];            for(x = 0; x < w1; x++) {                *c++ = *c1++;            }        }        for(x = w1; x < s->width; x++) {            c->ch = ' ';            c->t_attrib = s->t_attrib_default;            c++;        }    }    qemu_free(s->cells);    s->cells = cells;}static void update_xy(TextConsole *s, int x, int y){    TextCell *c;    int y1, y2;    if (s == active_console) {        y1 = (s->y_base + y) % s->total_height;        y2 = y1 - s->y_displayed;        if (y2 < 0)            y2 += s->total_height;        if (y2 < s->height) {            c = &s->cells[y1 * s->width + x];            vga_putcharxy(s->ds, x, y2, c->ch,                          &(c->t_attrib));            dpy_update(s->ds, x * FONT_WIDTH, y2 * FONT_HEIGHT,                       FONT_WIDTH, FONT_HEIGHT);        }    }}static void console_show_cursor(TextConsole *s, int show){    TextCell *c;    int y, y1;    if (s == active_console) {        int x = s->x;        if (x >= s->width) {            x = s->width - 1;        }        y1 = (s->y_base + s->y) % s->total_height;        y = y1 - s->y_displayed;        if (y < 0)            y += s->total_height;        if (y < s->height) {            c = &s->cells[y1 * s->width + x];            if (show) {                TextAttributes t_attrib = s->t_attrib_default;                t_attrib.invers = !(t_attrib.invers); /* invert fg and bg */                vga_putcharxy(s->ds, x, y, c->ch, &t_attrib);            } else {                vga_putcharxy(s->ds, x, y, c->ch, &(c->t_attrib));            }            dpy_update(s->ds, x * FONT_WIDTH, y * FONT_HEIGHT,                       FONT_WIDTH, FONT_HEIGHT);        }    }}static void console_refresh(TextConsole *s){    TextCell *c;    int x, y, y1;    if (s != active_console)        return;    vga_fill_rect(s->ds, 0, 0, s->ds->width, s->ds->height,                  color_table[0][COLOR_BLACK]);    y1 = s->y_displayed;    for(y = 0; y < s->height; y++) {        c = s->cells + y1 * s->width;        for(x = 0; x < s->width; x++) {            vga_putcharxy(s->ds, x, y, c->ch,                          &(c->t_attrib));            c++;        }        if (++y1 == s->total_height)            y1 = 0;    }    dpy_update(s->ds, 0, 0, s->ds->width, s->ds->height);    console_show_cursor(s, 1);}static void console_scroll(int ydelta){    TextConsole *s;    int i, y1;    s = active_console;    if (!s || (s->console_type == GRAPHIC_CONSOLE))        return;    if (ydelta > 0) {        for(i = 0; i < ydelta; i++) {            if (s->y_displayed == s->y_base)                break;            if (++s->y_displayed == s->total_height)                s->y_displayed = 0;        }    } else {        ydelta = -ydelta;        i = s->backscroll_height;        if (i > s->total_height - s->height)            i = s->total_height - s->height;        y1 = s->y_base - i;        if (y1 < 0)            y1 += s->total_height;        for(i = 0; i < ydelta; i++) {            if (s->y_displayed == y1)                break;            if (--s->y_displayed < 0)                s->y_displayed = s->total_height - 1;        }    }    console_refresh(s);}static void console_put_lf(TextConsole *s){    TextCell *c;    int x, y1;    s->y++;    if (s->y >= s->height) {        s->y = s->height - 1;        if (s->y_displayed == s->y_base) {            if (++s->y_displayed == s->total_height)                s->y_displayed = 0;        }        if (++s->y_base == s->total_height)            s->y_base = 0;        if (s->backscroll_height < s->total_height)            s->backscroll_height++;        y1 = (s->y_base + s->height - 1) % s->total_height;        c = &s->cells[y1 * s->width];        for(x = 0; x < s->width; x++) {            c->ch = ' ';            c->t_attrib = s->t_attrib_default;            c++;        }        if (s == active_console && s->y_displayed == s->y_base) {            vga_bitblt(s->ds, 0, FONT_HEIGHT, 0, 0,                       s->width * FONT_WIDTH,                       (s->height - 1) * FONT_HEIGHT);            vga_fill_rect(s->ds, 0, (s->height - 1) * FONT_HEIGHT,                          s->width * FONT_WIDTH, FONT_HEIGHT,                          color_table[0][s->t_attrib_default.bgcol]);            dpy_update(s->ds, 0, 0,                       s->width * FONT_WIDTH, s->height * FONT_HEIGHT);        }    }}/* Set console attributes depending on the current escape codes. * NOTE: I know this code is not very efficient (checking every color for it * self) but it is more readable and better maintainable. */static void console_handle_escape(TextConsole *s){    int i;    for (i=0; i<s->nb_esc_params; i++) {        switch (s->esc_params[i]) {            case 0: /* reset all console attributes to default */                s->t_attrib = s->t_attrib_default;                break;            case 1:                s->t_attrib.bold = 1;                break;            case 4:                s->t_attrib.uline = 1;                break;            case 5:                s->t_attrib.blink = 1;                break;            case 7:                s->t_attrib.invers = 1;                break;            case 8:                s->t_attrib.unvisible = 1;                break;            case 22:                s->t_attrib.bold = 0;                break;            case 24:                s->t_attrib.uline = 0;                break;            case 25:                s->t_attrib.blink = 0;                break;            case 27:                s->t_attrib.invers = 0;                break;            case 28:                s->t_attrib.unvisible = 0;                break;            /* set foreground color */            case 30:                s->t_attrib.fgcol=COLOR_BLACK;                break;            case 31:                s->t_attrib.fgcol=COLOR_RED;                break;            case 32:                s->t_attrib.fgcol=COLOR_GREEN;                break;            case 33:                s->t_attrib.fgcol=COLOR_YELLOW;                break;            case 34:                s->t_attrib.fgcol=COLOR_BLUE;                break;            case 35:                s->t_attrib.fgcol=COLOR_MAGENTA;                break;            case 36:                s->t_attrib.fgcol=COLOR_CYAN;                break;            case 37:                s->t_attrib.fgcol=COLOR_WHITE;                break;            /* set background color */            case 40:                s->t_attrib.bgcol=COLOR_BLACK;                break;            case 41:                s->t_attrib.bgcol=COLOR_RED;                break;            case 42:                s->t_attrib.bgcol=COLOR_GREEN;                break;            case 43:                s->t_attrib.bgcol=COLOR_YELLOW;                break;            case 44:                s->t_attrib.bgcol=COLOR_BLUE;                break;            case 45:                s->t_attrib.bgcol=COLOR_MAGENTA;                break;            case 46:                s->t_attrib.bgcol=COLOR_CYAN;                break;            case 47:                s->t_attrib.bgcol=COLOR_WHITE;                break;        }    }}static void console_clear_xy(TextConsole *s, int x, int y){    int y1 = (s->y_base + y) % s->total_height;    TextCell *c = &s->cells[y1 * s->width + x];    c->ch = ' ';    c->t_attrib = s->t_attrib_default;    c++;    update_xy(s, x, y);}static void console_putchar(TextConsole *s, int ch){    TextCell *c;    int y1, i;    int x, y;    switch(s->state) {    case TTY_STATE_NORM:        switch(ch) {        case '\r':  /* carriage return */            s->x = 0;            break;        case '\n':  /* newline */            console_put_lf(s);            break;        case '\b':  /* backspace */            if (s->x > 0)                s->x--;            break;        case '\t':  /* tabspace */            if (s->x + (8 - (s->x % 8)) > s->width) {                s->x = 0;                console_put_lf(s);            } else {                s->x = s->x + (8 - (s->x % 8));            }            break;        case '\a':  /* alert aka. bell */            /* TODO: has to be implemented */            break;        case 14:            /* SI (shift in), character set 0 (ignored) */            break;        case 15:            /* SO (shift out), character set 1 (ignored) */            break;        case 27:    /* esc (introducing an escape sequence) */            s->state = TTY_STATE_ESC;            break;        default:            if (s->x >= s->width) {                /* line wrap */                s->x = 0;                console_put_lf(s);            }            y1 = (s->y_base + s->y) % s->total_height;            c = &s->cells[y1 * s->width + s->x];            c->ch = ch;            c->t_attrib = s->t_attrib;            update_xy(s, s->x, s->y);            s->x++;            break;        }        break;    case TTY_STATE_ESC: /* check if it is a terminal escape sequence */        if (ch == '[') {            for(i=0;i<MAX_ESC_PARAMS;i++)                s->esc_params[i] = 0;            s->nb_esc_params = 0;            s->state = TTY_STATE_CSI;        } else {            s->state = TTY_STATE_NORM;        }        break;    case TTY_STATE_CSI: /* handle escape sequence parameters */        if (ch >= '0' && ch <= '9') {            if (s->nb_esc_params < MAX_ESC_PARAMS) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -