Changeset 52c4264 in mainline for uspace/srv/hid/output/proto/vt100.c


Ignore:
Timestamp:
2012-08-17T12:23:52Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
267f235
Parents:
ae2c925 (diff), ad78054 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/output/proto/vt100.c

    rae2c925 r52c4264  
    3232#include <sys/types.h>
    3333#include <inttypes.h>
     34#include <errno.h>
    3435#include <stdio.h>
     36#include <unistd.h>
     37#include <malloc.h>
    3538#include <io/color.h>
    36 #include <malloc.h>
    37 #include <errno.h>
    3839#include "vt100.h"
    3940
    4041#define MAX_CONTROL  20
    41 
    42 #define BACKBUF_POS(state, x, y)  ((y) * ((state)->width) + (x))
    43 
    44 struct vt100_state {
    45         vt100_putchar_t putchar;
    46         vt100_control_puts_t control_puts;
    47        
    48         sysarg_t width;
    49         sysarg_t height;
    50        
    51         sysarg_t cur_col;
    52         sysarg_t cur_row;
    53        
    54         char_attrs_t cur_attrs;
    55        
    56         charfield_t backbuf[];
    57 };
    5842
    5943typedef enum {
     
    154138}
    155139
    156 vt100_state_t *vt100_state_create(sysarg_t width, sysarg_t height,
     140vt100_state_t *vt100_state_create(sysarg_t cols, sysarg_t rows,
    157141    vt100_putchar_t putchar_fn, vt100_control_puts_t control_puts_fn)
    158142{
    159         size_t sz = width * height * sizeof(charfield_t);
    160        
    161143        vt100_state_t *state =
    162             malloc(sizeof(vt100_state_t) + sz);
     144            malloc(sizeof(vt100_state_t));
    163145        if (state == NULL)
    164146                return NULL;
     
    167149        state->control_puts = control_puts_fn;
    168150       
    169         state->width = width;
    170         state->height = height;
     151        state->cols = cols;
     152        state->rows = rows;
    171153       
    172154        state->cur_col = (sysarg_t) -1;
     
    175157        state->cur_attrs.type = CHAR_ATTR_STYLE;
    176158        state->cur_attrs.val.style = STYLE_NORMAL;
    177        
    178         memset(state->backbuf, 0, sz);
    179159       
    180160        /* Initialize graphic rendition attributes */
     
    183163        vt100_sgr(state, SGR_BGCOLOR + CI_WHITE);
    184164        state->control_puts("\033[2J");
     165        state->control_puts("\033[?25l");
    185166       
    186167        return state;
    187168}
    188169
    189 void vt100_get_resolution(vt100_state_t *state, sysarg_t *width,
    190     sysarg_t *height)
    191 {
    192         *width = state->width;
    193         *height = state->height;
     170void vt100_state_destroy(vt100_state_t *state)
     171{
     172        free(state);
     173}
     174
     175void vt100_get_dimensions(vt100_state_t *state, sysarg_t *cols,
     176    sysarg_t *rows)
     177{
     178        *cols = state->cols;
     179        *rows = state->rows;
    194180}
    195181
     
    201187int vt100_claim(vt100_state_t *state)
    202188{
    203         for (sysarg_t row = 0; row < state->height; row++) {
    204                 vt100_set_pos(state, 0, row);
    205                 for (sysarg_t col = 0; col < state->width; col++) {
    206                         charfield_t *field = state->backbuf +
    207                             BACKBUF_POS(state, col, row);
    208                         vt100_set_sgr(state, field->attrs);
    209                         state->putchar(field->ch);
    210                 }
    211         }
    212        
    213         vt100_set_pos(state, state->cur_col, state->cur_row);
    214         vt100_set_sgr(state, state->cur_attrs);
    215        
    216189        return EOK;
    217190}
    218191
    219 void vt100_putchar(vt100_state_t *state, wchar_t ch)
    220 {
    221         charfield_t *field = state->backbuf +
    222             BACKBUF_POS(state, state->cur_col, state->cur_row);
    223         field->ch = ch;
    224         field->attrs = state->cur_attrs;
    225        
    226         state->putchar(ch);
    227         state->cur_col++;
    228        
    229         if (state->cur_col >= state->width) {
    230                 state->cur_row += state->cur_col / state->width;
    231                 state->cur_col %= state->width;
    232         }
    233 }
    234 
    235 void vt100_set_attr(vt100_state_t *state, char_attrs_t attrs)
    236 {
    237         if (!attrs_same(state->cur_attrs, attrs)) {
    238                 vt100_set_sgr(state, attrs);
    239                 state->cur_attrs = attrs;
    240         }
    241 }
    242 
    243192void vt100_goto(vt100_state_t *state, sysarg_t col, sysarg_t row)
    244193{
    245         if ((col >= state->width) || (row >= state->height))
     194        if ((col >= state->cols) || (row >= state->rows))
    246195                return;
    247196       
     
    253202}
    254203
     204void vt100_set_attr(vt100_state_t *state, char_attrs_t attrs)
     205{
     206        if (!attrs_same(state->cur_attrs, attrs)) {
     207                vt100_set_sgr(state, attrs);
     208                state->cur_attrs = attrs;
     209        }
     210}
     211
    255212void vt100_cursor_visibility(vt100_state_t *state, bool visible)
    256213{
     
    261218}
    262219
     220void vt100_putchar(vt100_state_t *state, wchar_t ch)
     221{
     222        state->putchar(ch == 0 ? ' ' : ch);
     223        state->cur_col++;
     224       
     225        if (state->cur_col >= state->cols) {
     226                state->cur_row += state->cur_col / state->cols;
     227                state->cur_col %= state->cols;
     228        }
     229}
     230
    263231/** @}
    264232 */
Note: See TracChangeset for help on using the changeset viewer.